100% found this document useful (1 vote)
11 views

Competitive Programming 4 Book 1 4th Edition Steven Halim pdf download

The document provides information about the 4th edition of 'Competitive Programming 4 Book 1' by Steven Halim, including links for downloading the book and other related eBooks. It contains various sections covering competitive programming, data structures, problem-solving paradigms, and tips for success in programming contests. Additionally, it includes a detailed table of contents outlining the topics covered in the book.

Uploaded by

gokcekadzaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
11 views

Competitive Programming 4 Book 1 4th Edition Steven Halim pdf download

The document provides information about the 4th edition of 'Competitive Programming 4 Book 1' by Steven Halim, including links for downloading the book and other related eBooks. It contains various sections covering competitive programming, data structures, problem-solving paradigms, and tips for success in programming contests. Additionally, it includes a detailed table of contents outlining the topics covered in the book.

Uploaded by

gokcekadzaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Competitive Programming 4 Book 1 4th Edition

Steven Halim pdf download

https://ebookmeta.com/product/competitive-
programming-4-book-1-4th-edition-steven-halim/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Competitive Programming 4 Book 1 Steven Halim

https://ebookmeta.com/product/competitive-
programming-4-book-1-steven-halim/

Competitive Programming 4 The Lower Bound of


Programming Contests in the 2020s 4th Edition Steven
Halim

https://ebookmeta.com/product/competitive-programming-4-the-
lower-bound-of-programming-contests-in-the-2020s-4th-edition-
steven-halim-2/

Competitive Programming 4 The Lower Bound of


Programming Contests in the 2020s 4th Edition Steven
Halim

https://ebookmeta.com/product/competitive-programming-4-the-
lower-bound-of-programming-contests-in-the-2020s-4th-edition-
steven-halim/

Love Other Inconveniences 1st Edition Catherine Cloud

https://ebookmeta.com/product/love-other-inconveniences-1st-
edition-catherine-cloud/
Collapsing Structures and Public Mismanagement 1st
Edition Wolfgang Seibel

https://ebookmeta.com/product/collapsing-structures-and-public-
mismanagement-1st-edition-wolfgang-seibel/

Ethos Logos and Perspective Studies in Late Byzantine


Rhetoric First Edition Florin Leonte

https://ebookmeta.com/product/ethos-logos-and-perspective-
studies-in-late-byzantine-rhetoric-first-edition-florin-leonte/

Advanced Deep Learning for Engineers and Scientists: A


Practical Approach (EAI/Springer Innovations in
Communication and Computing) Kolla Bhanu Prakash
(Editor)
https://ebookmeta.com/product/advanced-deep-learning-for-
engineers-and-scientists-a-practical-approach-eai-springer-
innovations-in-communication-and-computing-kolla-bhanu-prakash-
editor/

Ride Me A Curvy Girl Military MC Romance Men of Valor


MC 1st Edition Fern Fraser

https://ebookmeta.com/product/ride-me-a-curvy-girl-military-mc-
romance-men-of-valor-mc-1st-edition-fern-fraser-2/

Applied Mathematics Class XI 3rd Edition Neeraj Raj


Jain M L Aggarwal

https://ebookmeta.com/product/applied-mathematics-class-xi-3rd-
edition-neeraj-raj-jain-m-l-aggarwal/
CC Certified in Cybersecurity Study Guide Sybex Study
Guide 1st Edition Chapple

https://ebookmeta.com/product/cc-certified-in-cybersecurity-
study-guide-sybex-study-guide-1st-edition-chapple/
This is the 100% identical eBook (PDF) version of CP4 Book 1
that was released on 19 July 2020
Please read https://cpbook.net/errata
for the latest known updates to this PDF
c Steven, Felix, Suhendry

ii
Contents

Forewords for CP4 vii

Testimonials of CP1/2/3 xiii

Preface for CP4 xv

Authors’ Profiles xxvii

Abbreviations xxix

1 Introduction 1
1.1 Competitive Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 The Competitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.1 International Olympiad in Informatics (IOI) . . . . . . . . . . . . . . 3
1.2.2 International Collegiate Programming Contests (ICPC) . . . . . . . . 4
1.2.3 Other Programming Contests . . . . . . . . . . . . . . . . . . . . . . 6
1.3 Tips to be Competitive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3.1 Tip 1: Type Code Faster! . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3.2 Tip 2: Quickly Identify Problem Types . . . . . . . . . . . . . . . . . 8
1.3.3 Tip 3: Do Algorithm Analysis . . . . . . . . . . . . . . . . . . . . . . 10
1.3.4 Tip 4: Master Programming Languages . . . . . . . . . . . . . . . . . 15
1.3.5 Tip 5: Master the Art of Testing Code . . . . . . . . . . . . . . . . . 18
1.3.6 Tip 6: Practice and More Practice . . . . . . . . . . . . . . . . . . . 21
1.3.7 Tip 7: Team Work (for ICPC) . . . . . . . . . . . . . . . . . . . . . . 22
1.4 Getting Started: The Easy Problems . . . . . . . . . . . . . . . . . . . . . . 23
1.4.1 Anatomy of a Programming Contest Problem . . . . . . . . . . . . . 23
1.4.2 Typical Input/Output Routines . . . . . . . . . . . . . . . . . . . . . 23
1.4.3 Time to Start the Journey . . . . . . . . . . . . . . . . . . . . . . . . 26
1.4.4 Getting Our First Accepted (AC) Verdict . . . . . . . . . . . . . . . 27
1.5 Basic String Processing Skills . . . . . . . . . . . . . . . . . . . . . . . . . . 31
1.6 The Ad Hoc Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.7 Solutions to Non-Starred Exercises . . . . . . . . . . . . . . . . . . . . . . . 41
1.8 Chapter Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

2 Data Structures and Libraries 53


2.1 Overview and Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
2.2 Linear DS with Built-in Libraries . . . . . . . . . . . . . . . . . . . . . . . . 55
2.2.1 Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.2.2 Special Sorting Problems . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.2.3 Bitmask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.2.4 Big Integer (Python & Java) . . . . . . . . . . . . . . . . . . . . . . . 66

iii
CONTENTS c Steven, Felix, Suhendry

2.2.5 Linked Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . 69


2.2.6 Special Stack-based Problems . . . . . . . . . . . . . . . . . . . . . . 71
2.3 Non-Linear DS with Built-in Libraries . . . . . . . . . . . . . . . . . . . . . 78
2.3.1 Binary Heap (Priority Queue) . . . . . . . . . . . . . . . . . . . . . . 78
2.3.2 Hash Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
2.3.3 Balanced Binary Search Tree (bBST) . . . . . . . . . . . . . . . . . . 84
2.3.4 Order Statistics Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
2.4 DS with Our Own Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
2.4.1 Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
2.4.2 Union-Find Disjoint Sets . . . . . . . . . . . . . . . . . . . . . . . . . 99
2.4.3 Fenwick (Binary Indexed) Tree . . . . . . . . . . . . . . . . . . . . . 104
2.4.4 Segment Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
2.5 Solution to Non-Starred Exercises . . . . . . . . . . . . . . . . . . . . . . . . 124
2.6 Chapter Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

3 Problem Solving Paradigms 129


3.1 Overview and Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
3.2 Complete Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
3.2.1 Iterative Complete Search . . . . . . . . . . . . . . . . . . . . . . . . 131
3.2.2 Recursive Complete Search . . . . . . . . . . . . . . . . . . . . . . . . 135
3.2.3 Complete Search Tips . . . . . . . . . . . . . . . . . . . . . . . . . . 139
3.2.4 Complete Search in Programming Contests . . . . . . . . . . . . . . . 143
3.3 Divide and Conquer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
3.3.1 Interesting Usages of Binary Search . . . . . . . . . . . . . . . . . . . 148
3.3.2 Ternary Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
3.3.3 Divide and Conquer in Programming Contests . . . . . . . . . . . . . 153
3.4 Greedy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
3.4.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
3.4.2 Greedy Algorithm in Programming Contests . . . . . . . . . . . . . . 161
3.5 Dynamic Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
3.5.1 DP Illustration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
3.5.2 Classical Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
3.5.3 Non-Classical Examples . . . . . . . . . . . . . . . . . . . . . . . . . 184
3.5.4 Dynamic Programming in Programming Contests . . . . . . . . . . . 187
3.6 Solution to Non-Starred Exercises . . . . . . . . . . . . . . . . . . . . . . . . 190
3.7 Chapter Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191

4 Graph 193
4.1 Overview and Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
4.2 Graph Traversal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
4.2.1 Overview and Motivation . . . . . . . . . . . . . . . . . . . . . . . . 195
4.2.2 Depth First Search (DFS) . . . . . . . . . . . . . . . . . . . . . . . . 195
4.2.3 Breadth First Search (BFS) . . . . . . . . . . . . . . . . . . . . . . . 197
4.2.4 Finding Connected Components (Undirected Graph) . . . . . . . . . 198
4.2.5 Flood Fill (Implicit 2D Grid Graph) . . . . . . . . . . . . . . . . . . 199
4.2.6 Topological Sort (Directed Acyclic Graph) . . . . . . . . . . . . . . . 200
4.2.7 Bipartite Graph Check (Undirected Graph) . . . . . . . . . . . . . . 202
4.2.8 Cycle Check (Directed Graph) . . . . . . . . . . . . . . . . . . . . . . 203
4.2.9 Finding Articulation Points and Bridges (Undirected Graph) . . . . . 205
4.2.10 Finding Strongly Connected Components (Directed Graph) . . . . . . 208

iv
CONTENTS c Steven, Felix, Suhendry

4.2.11 Graph Traversal in Programming Contests . . . . . . . . . . . . . . . 211


4.3 Minimum Spanning Tree (MST) . . . . . . . . . . . . . . . . . . . . . . . . . 215
4.3.1 Overview and Motivation . . . . . . . . . . . . . . . . . . . . . . . . 215
4.3.2 Kruskal’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
4.3.3 Prim’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
4.3.4 Other Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
4.3.5 MST in Programming Contests . . . . . . . . . . . . . . . . . . . . . 221
4.4 Single-Source Shortest Paths (SSSP) . . . . . . . . . . . . . . . . . . . . . . 223
4.4.1 Overview and Motivation . . . . . . . . . . . . . . . . . . . . . . . . 223
4.4.2 On Unweighted Graph: BFS . . . . . . . . . . . . . . . . . . . . . . . 223
4.4.3 On Weighted Graph: Dijkstra’s . . . . . . . . . . . . . . . . . . . . . 227
4.4.4 On Small Graph (with Negative Cycle): Bellman-Ford . . . . . . . . 234
4.4.5 SSSP in Programming Contests . . . . . . . . . . . . . . . . . . . . . 237
4.5 All-Pairs Shortest Paths (APSP) . . . . . . . . . . . . . . . . . . . . . . . . 241
4.5.1 Overview and Motivation . . . . . . . . . . . . . . . . . . . . . . . . 241
4.5.2 Floyd-Warshall Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 242
4.5.3 Other Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
4.5.4 APSP in Programming Contests . . . . . . . . . . . . . . . . . . . . . 246
4.6 Special Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
4.6.1 Directed Acyclic Graph . . . . . . . . . . . . . . . . . . . . . . . . . . 249
4.6.2 Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
4.6.3 Bipartite Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
4.6.4 Eulerian Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
4.6.5 Special Graphs in Programming Contests . . . . . . . . . . . . . . . . 263
4.7 Solution to Non-Starred Exercises . . . . . . . . . . . . . . . . . . . . . . . . 267
4.8 Chapter Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270

Bibliography 276

v
CONTENTS c Steven, Felix, Suhendry

vi
Forewords for CP4

Bill Poucher
Introduction
In 1970, the Texas A&M UPE Honor Society hosted the first university competitive pro-
gramming competition in the history of the ICPC. The first Finals was held in 1977 in
Atlanta in conjunction with the Winter Meeting of the ACM Computer Science Conference.
The ICPC International Collegiate Programming Contest hosted regional competitions at
643 sites in 104 countries for 59 000 team members and their 5043 coaches from over 3400
universities that span the globe. The top 135 teams of three will advance to the ICPC World
Finals in Moscow hosted by MIPT scheduled for June 2021.
ICPC alumni number over 400,000 worldwide, many playing key roles in building the
global digital community for many decades. The ICPC is the root of competitive program-
ming that reaches out through the global digital community to persons from all cultures and
in increasingly-younger generations.
The UVa Online Judge opened the doors for online competition and access to ICPC prob-
lems under the direction of Professor Miguel Ángel Revilla. Three of the star-studded team
are Steven Halim, Felix Halim, and Suhendry E↵endy, authors of Competitive Programming
4, Book 1 and Book 2. Their work will be honored at the ICPC World Finals in Moscow
hosted by MIPT with a special award from the ICPC Foundation.

Competitive Programming
What is competitive programming and why should you get involved? First and foremost, it’s
a mind sport. It more fully develops your algorithmic reasoning skills and bridges the gap
between theory and application in bite-sized chunks. Full participation develops problem-
solving intuition and competence. Get ready for the Digital Renaissance that will shape
your world in the coming decades. To understand the landscape, it is important to shape
your mind beyond a swarm of buzzwords. Do it as a team sport.

How do we get started?


Start with Competitive Programming 4, Book 1 and Book 2. Start with Book 1 first :). The
authors are seasoned competitive programming experts who have dedicated decades of work
to help at all levels of the sport.
In parallel, engage in a culture that develops habits excellence. You are the first genera-
tion that has never been disconnected. Being connected is best when we bind our strengths
together in common cause. Do that and prepare to meet the challenges that will define your
generation.
Life needs you. We are born to compete. We compete best when we compete together, in
good faith, in goodwill, and with good deeds. When you come to college, consider the ICPC

vii
FOREWORDS Bill Poucher

and the new program ICPC University Commons that will provide a spectrum of activities
that happen outside of the classroom. You can visit https://icpc.global for details.

Why get started?


Is developing your problem-solving skills important? Yes. Is preparing for a future engaged
in the global digital community important? Yes. Is following T.S. Elliot’s advice that to
fully develop you must go too far? Yes. Do that in competitive programming. Be careful of
pursuits that are not reversible.
Is competitive programming practical? Aristotle asserted that there is nothing more
practical than engaging in mental activities and reflections which have their goal in them-
selves and take pace for their own sake. Let me recommend that you engage your spirit in
building a more beautiful world. In the immense scope of life, abundant small kindnesses
make a di↵erence. Find friends with common interest and embrace this cycle:

Repeat for a lifetime: Study; Practice; Rehearse; Dress Rehearse; Perform.

It works for athletes.


It works for musicians.
It works for all performance arts.
It will work for you.

Best, Bill
Dr. William B. “Bill” Poucher, Ph.D., ACM Fellow
Professor of Computer Science, Baylor University
Executive Director, ICPC International Collegiate Programming Contest
President, ICPC Foundation
July 13th, 2020.

viii
FOREWORDS Miguel Revilla Rodrı́guez

Miguel Revilla Rodrı́guez


Almost 20 years ago (on November 11th , 2003, to be precise), my father (Miguel Ángel
Revilla) received an e-mail with the following message:

“I should say in a simple word that with the UVa Site, you have given birth to
a new CIVILIZATION and with the books you write (he meant “Programming
Challenges: The Programming Contest Training Manual” [53], coauthored with
Steven Skiena), you inspire the soldiers to carry on marching. May you live long
to serve the humanity by producing super-human programmers.”

What, in my father’s words, was “clearly an exaggeration”, caused some thinking. And it’s
not a secret that thoughts can easily lead to dreams. His dream was to create a community
around the project he had started, as part of is teaching job at the University of Valladolid,
Spain, that gathered people from all around the world working together towards the same
ideal, the same quest. With a little searching, on the primitive Internet of the first years of
our century, a whole online community of excellent users and tools, built around the UVa
site, came to light.
The website Methods to Solve 1 , created by a very young student from Indonesia, was one
of the most impressive among them. There was the result of the hard work of a real genius
of algorithms and computer science. The seed was planted to believe that the dream could
come true. Moreover, it was not only that the leaves of that growing tree were a perfect
match, but the root of both projects were exactly the same: to serve the humanity. That
young student, the author of the e-mail and the website that put my father to dream, was
Steven Halim. Later he would discover that Steven was not alone in his quest, as his younger
brother, Felix, shared his view, his interests, and his extraordinary capabilities.
After 15 years of fruitful collaboration and, more important, friendship with Steven and
Felix, my father sadly passed away in 2018. His work, and his dreams, now belong to us,
the next generation. This book is the living proof that the dream has become true.
“I can’t imagine a better complement for the UVa Online Judge”, are my father’s words.
Now, with this fourth version of Competitive Programming in my hands, I can add that I
can’t imagine the very existence of the Online Judge without this book. Both projects have
grown in parallel and are, no doubt, perfect complements and companions to each other.
By practicing and mastering most programming exercises in this book, the reader can learn
how to solve hundreds of tasks and find a place in the top 500 best Online Judge coders.
You have in your hands over 2000 (yes, two thousand!) selected, classified, and carefully
commented problems from the Online Judge.
The authors, in the past two decades, have grown from contestants, to coaches and,
finally, masters in the art of competitive programming. They perfectly know every curve
and crossroad in that long path, and they can put themselves in the skins of the young
IOI contestant, the ICPC newcomer or the seasoned coach, speaking to each in their own
language. This book is, for that very reason, the perfect reading for all of them. No matter
if you are starting as a competitive programmer in your local IOI, or are coaching in the
next ICPC World Finals, no doubt this IS the book for you.

1
Please visit https://cpbook.net/methodstosolve

ix
FOREWORDS Miguel Revilla Rodrı́guez

I love movies, I adore classic movies, and I know that what I’m watching is a masterpiece,
when, after the film ends, I can’t wait to start all over again. In Steven and Felix own words
“the book is not meant to be read once, but several times”. And you will find that same
feeling, not only because the authors recommend it, but because you will be anxious to read
and re-read it as, like in the greatest movies, you will find something new and amazing each
time. This book is, by that logic, a masterpiece.
I also have the great honor of being the Spanish language translator of this book. Trans-
lating requires a very meticulous process of converting the words while keeping the spirit.
You have to think as the author would think, and have to perfectly understand not only
what the author is saying, but also what the author is meaning. It is a handcrafting exer-
cise. Having gone forth and back through this text hundreds of times, I have enjoyed every
concept, every new idea, and every tip, not only by what is written in it, but also by what
it wants to achieve. The quest of making better programmers and, behind that, the quest
of serving humanity. This book is, indeed, a truly masterpiece.
Once you’ve read this book several times, you will realize how much a better programmer
you are but, believe it or not, you will realize that you are also a happier person.
Miguel Revilla Rodrı́guez (Miguel Jr)
Online Judge Manager
https://onlinejudge.org
July 1st, 2020, Valladolid.

x
FOREWORDS Fredrik Niemelä

Fredrik Niemelä
I got my first physical copy of this book from Steven at IOI 2012 in Italy. Like so many other
computer scientists, he has a great sense of humor, and named it “Competitive Programming:
Increasing the Lower Bound of Programming Contests.” It was the second edition of the
book and already twice the size of the first edition. Packed with practical advice, it was well-
suited to get beginners started and had useful material for the more seasoned algorithmist.
Steven and Felix’s vision for their book was to teach everybody how to program (As
Gusteau from Ratatouille would put it: “Tout le monde peut programmer”). I had a similar
vision, but instead of writing a book, we created Kattis. “Competitive Programming” and
Kattis share this motivating principle: to make learning computer science and programming
accessible for everyone. In that sense, they are like two of many pieces in the same puzzle.
Kattis is an online tool for teaching computer science and programming, which relies on
a curated library of programming tasks. I managed to convince Steven that he should try
using Kattis for some of his teaching activities. Over the years he has moved from using
Kattis, to pushing us to improve Kattis, to adding high-quality content to Kattis.
From years of teaching algorithms and using similar systems that preceded Kattis, we
learned that the quality of the problems, and their absolute correctness, are paramount for
learning outcomes. So, this is where we put extra e↵ort into Kattis. (If you ever felt that
it’s too much work to add problems to Kattis, this is why). What we did back then is now
standard practice—both the ICPC and IOI use the same kinds of methods for their finals.
In this fourth edition (more than twice as large as the second edition!), Steven and Felix,
now joined by co-author Suhendry, are using problems from Kattis. We are honored to be
included. Finally, our puzzle pieces are directly connected, and I am very excited about
that.
I hope you will find this book informative and helpful and that you will spend the time
it asks of you. You will not be disappointed.
Fredrik Niemelä
Founder of Kattis
ICPC Contest System Director
IOI Technical Committee Founding Member
https://www.kattis.com
July 11th, 2020.

xi
FOREWORDS Brian Christopher Dean

Brian Christopher Dean


I’ve had the privilege to be part of the competitive programming world for more than three
decades, during which time I’ve seen the field grow substantially in terms of its impact
on modern computing. As director of the USA Computing Olympiad and coach of my
University’s ICPC teams, I have seen firsthand how competitive programming has become a
key part of the global computing talent pipeline - both academia and industry are now filled
with present-day superstars who were formerly superstars in competitive programming.
Just as the world of competitive programming has shown tremendous growth in scope,
depth, and relevance, so too has this text, now in its fourth edition. Earlier editions of
this book provided what I consider to be the gold standard for both an introduction and a
thorough reference to the algorithmic concepts most prevalent in competitive programming.
The same remains true for this edition.
Competitive programming can be a daunting undertaking for the novice student - learn-
ing to code is plenty challenging by itself, and on top of this we add a layer of ”standard”
algorithms and data structures and then another layer of problem-solving insight and tricks.
This text helps the introductory student navigate these challenges in several ways, by its
thoughtful organization, extensive practice exercises, and by articulating ideas both in clear
prose and code. Competitive programming can also be a daunting prospect for the advanced
student due to its rapid pace of evolution - techniques can go from cutting-edge to common-
place in a matter of just a few years, and one must demonstrate not only proficiency but
true mastery of a formidable and ever-expanding body of algorithmic knowledge. With its
comprehensive algorithmic coverage and its extensive listing of ⇡ 3458 categorized problems,
this text provides the advanced student with years of structured practice that will lead to a
high baseline skill level.
I think this is a book that belongs in the library of anyone serious about computing, not
just those training for their first or their hundredth programming competition. Ideas from
competitive programming can help one develop valuable skills and insight - both in theory
and implementation - that can be brought to bear on a wide range of modern computing
problems of great importance in practice. Algorithmic problem solving is, after all, truly
the heart and soul of computer science! These types of problems are often used in job
interviews for a good reason, since they indicate the type of prospective employee who has
a skill set that is broadly applicable and that can adapt gracefully to changes in underlying
technologies and standards. Studying the concepts in this text is an excellent way to sharpen
your skills at problem solving and coding, irrespective of whether you intend to use them in
competition or in your other computational pursuits.
I’ve thoroughly enjoyed reading successive drafts
of this updated work shared with me by the au-
thors at recent IOIs, and I commend the authors on
the impressive degree to which they have been able
extend the scope, clarity, and depth of an already-
remarkable text.
Brian Christopher Dean
Professor and Chair
Division of Computer Science, School of Computing
Clemson University, Clemson, SC, USA
Director, USA Computing Olympiad
July 5th, 2020
http://www.usaco.org/

xii
Testimonials of CP1/2/3

“Competitive Programming 3 has contributed immensely to my understanding of data


structures & algorithms. Steven & Felix have created an incredible book that thoroughly
covers every aspect of competitive programming, and have included plenty of practice
problems to make sure each topic sinks in. Practicing with CP3 has helped me nail job
interviews at Google, and I can’t thank Steven & Felix enough!”
— Troy Purvis, Software Engineer @ Google.
“Steven and Felix are passionate about competitive programming. Just as importantly,
they are passionate about helping students become better programmers. CP3 is the result:
a dauntless dive into the data structures, algorithms, tips, and secrets used by competitive
programmers around the world. Yet, when the dust settles on the book, the strongest
sillage is likely to be one of confidence—that, yes, this stu↵ is challenging, but that you can
do it.” — Dr. Daniel Zingaro, Associate Professor Teaching Stream,
University of Toronto Mississauga.
“CP-Book helped us to train many generations of ICPC and IOI participants for Bolivia.
It’s the best source to start and reach a good level to be a competitive programmer.” —
Jhonatan Castro, ICPC coach and Bolivia IOI Team coach,
Universidad Mayor de San Andrés, La Paz, Bolivia.
“Reading CP3 has been a major contributor to my growth, not just as a competitive
programmer, but also as a computer scientist. My entire approach to problem solving has
been improved by doing the exercises in the book; my passion for the art of problem
solving, especially in contest environments, has been intensified. I now mentor several
students using this book as a guide. It is an invaluable resource to anyone who wants to be
a better problem solver.” — Ryan Austin Fernandez, Assistant Professor,
De La Salle University, Manila, Philippines.
“I rediscovered CP3 book on 2017-2019 when I come back to Peru after my master in
Brazil, I enjoyed, learned and solved many problems, more than during my undergraduate,
coaching and learning together in small group of new students that are interesting in
competitive programming. It kept me in a constantly competition with them, at the end
they have solved more problems than me.” — Luciano Arnaldo Romero Calla,
PhD Student, University of Zurich.
“CP1 helped my preparation during national team training and selection for participating
the IOI. When I took the competitive programming course in NUS, CP2 book is
extensively used for practice and homework. The good balance between the programming
and theoretic exercises for deeper understanding in the book makes CP book a great book
to be used for course references, as well as for individual learning. Even at the top
competitive programming level, experts can still learn topics they have not learnt before
thanks to the rare miscellaneous topics at the end of the book.”
— Jonathan Irvin Gunawan, Software Engineer, Google.

xiii
TESTIMONIALS Various Book Readers

“Dr. Steven Halim is one of the best professors I have had in NUS. His intuitive
visualizations and clear explanations of highly complex algorithms make it significantly
easier for us to grasp difficult concepts. Even though I was never fully into Competitive
Programming, his book and his teaching were vital in helping me in job interviews and
making me a better coder. Highly recommend CP4 to anyone looking to impress in
software engineering job interviews.” — Patrick Cho, Machine Learning Scientist, Tesla.

“Flunked really hard at IOI 2017, missing medal cuto↵ by 1 place. Then at the beginning
of 2018 Steven Halim gave me a draft copy of CP3.1 / CP4 and I ended up getting a gold
medal!” — Joey Yu, Student, University of Waterloo, SWE Intern at Rippling,
IOI 2018 Gold Medalist.

“As a novice self-learner, CP-book helped me to learn the topics in both fun and
challenging ways. As an avid and experienced CP-er, CP-book helped me to find a
plentiful and diverse problems. As a trainer, CP-book helped me to plan ahead the
materials and tactical strategies or tricks in competition for the students. As the person
ever in those three di↵erent levels, I must e↵ortlessly say CP-book is a must-have to being
a CP master!” — Ammar Fathin Sabili, PhD Student, National University of Singapore.

“I’ve been in CP for three years. A rookie number for all the competitive programmers out
there. I have a friend (still chatting with him today) who introduced me to this book. He’s
my roommate on our National Training Camp for IOI 2018’s selection. I finally get a grab
of this book in early 2019. To be honest I’m not the ‘Adhoc’ and good at ‘Math’ type of
CP-er. I love data structures, graph (especially trees) And this CP3 book. Is a leap of
knowledge. No joke. I met Dr Felix when I was training in BINUS, I also met Dr Steven
when I competed in Singapore’s NOI and one of my unforgettable moment is, this legend
book got signed by its two authors. Even tho the book is full of marks and stains, truly
one of my favorite. Kudos for taking me to this point of my life.”
— Hocky Yudhiono, Student, University of Indonesia.

“I bought CP3 on 7th April 2014 on my birthday as a gift for myself and it has been the
most worth-it 30USD spent by me on any educational material. In the later years, I was
able to compete in IOI and ICPC WF. I think CP3 played a very big factor in igniting the
interest and providing a strong technical foundation about all the essential topics required
in CP.” — Sidhant Bansal, Student, National University of Singapore.

“I have always wanted to get involved in competitive programming, but I didn’t know how
and where to get started. I was introduced to this book while taking Steven’s companion
course (CS3233) in NUS as an exchange student, and I found the book to be really helpful
in helping me to learn competitive programming. It comes with a set of Kattis exercises as
well. This book provides a structured content for competitive programming, and can be
really useful to anyone ranging from beginners to experts. Just like CLRS for algorithms,
CP is THE book for competitive programming.” — Jay Ching Lim,
Student, University of Waterloo.

“My memories about CP3 is me reading it in many places, the bus, my room, the library,
the contest floor...not much time had passed since I start in competitive programming
reading CP3 until I got qualified to an ICPC World Final.”
— Javier Eduardo Ojeda Jorge, ICPC World Finalist, Universidad Mayor de San Simón,
Software Engineer at dParadig, Chile

xiv
Preface for CP4

This Competitive Programming book, 4th edition (CP4) is a must have for every compet-
itive programmer. Mastering the contents of this book is a necessary (but admittedly not
sufficient) condition if one wishes to take a leap forward from being just another ordinary
coder to being among one of the world’s finest competitive programmers.
Typical readers of Book 1 (only) of CP4 would include:

1. Secondary or High School Students who are competing in the annual International
Olympiad in Informatics (IOI) [31] (including the National or Provincial Olympiads)
as Book 1 covers most of the current IOI Syllabus [16],
2. Casual University students who are using this book as supplementary material for
typical Data Structures and Algorithms courses,
3. Anyone who wants to prepare for typical fundamental data structure/algorithm part
of a job interview at top IT companies.

Typical readers of both Book 1 + Book 2 of CP4 would include:

1. University students who are competing in the annual International Collegiate Program-
ming Contest (ICPC) [57] Regional Contests (including the World Finals) as Book 2
covers much more Computer Science topics that have appeared in the ICPCs,
2. Teachers or Coaches who are looking for comprehensive training materials [21],
3. Anyone who loves solving problems through computer programs. There are numerous
programming contests for those who are no longer eligible for ICPC, including Google
CodeJam, Facebook Hacker Cup, TopCoder Open, CodeForces contest, Internet Prob-
lem Solving Contest (IPSC), etc.

Prerequisites
This book is not written for novice programmers so that we can write much more about
Competitive Programming instead of repeating the basic programming methodology con-
cepts that are widely available in other Computer Science textbooks. This book is aimed
at readers who have at least basic knowledge in programming methodology, are familiar
with at least one of these programming languages (C/C++, Java, Python, or OCaml) but
preferably more than one programming language, have passed (or currently taking) a basic
data structures and algorithms course and a discrete mathematics course (both are typically
taught in year one of Computer Science university curricula or in the NOI/IOI training
camps), and understand simple algorithmic analysis (at least the big-O notation). In the
next subsections, we will address the di↵erent potential readers of this book.

xv
Another Random Scribd Document
with Unrelated Content
And it appearing to me to be particularly essential to the interests of
this country, that an observance of the order and prohibition should
be obtained, I do hereby call upon all civil and military officers, who
now are, or hereafter may be appointed, to use their best endeavors
for detecting and bringing to justice every person who shall violate
the same. And, whereas, it appears to me to be expedient that
government should receive information of all characters, foreigners
and others, coming into the Territory, I do hereby order and direct
that any person arriving at this, or any of the military posts of the
United States within the same, should present himself to the
commanding officer of the troops in two hours next after his arrival;
and the inhabitants are hereby forbidden to entertain such
characters, whether whites, Indians, or negroes, without immediate
information thereof to the said commanding officers.
Given under my hand and seal at the town of Post Vincennes, and
county of Knox, this 28th day of June, A. D. 1790, and of the
Independence of the United States, the fourteenth.
(Signed,) Winthrop Sargent.

June 29, 1790.—It is to be considered as a standing order hereafter,


that no person enrolled in the militia shall leave the village or
stations, for a longer absence than twenty-four hours, without
informing him (Mayor Hamtramck) or the commanding officer for the
time being, of their intention. And all intelligence or discoveries of
Indians, to be immediately reported.
(Signed,) Winthrop Sargent.

XVII.—Report on certain letters from the President to Mr.


Gouverneur Morris, and from Mr. Morris to the President,
relative to our difficulties with England—1790.
December 15, 1790.

The Secretary of State having had under consideration the two


letters of October 13th, 1789, from the President of the United
States, to Mr. Gouverneur Morris; and those of Mr. Morris to the
President, of January 22d, April 7th, 13th, May 1st, 29th, July 3d,
August 16th, and September 18th, referred to him by the President,
makes the following report thereon:
The President's letter of January 22d, authorized Mr. Morris to enter
into conference with the British ministers in order to discover their
sentiments on the following subjects:
1. Their retention of the western posts contrary to the treaty of
peace.
2. Indemnification for the negroes carried off against the stipulations
of the same treaty.
3. A treaty for the regulation of the commerce between the two
countries.
4. The exchange of a minister.
The letters of Mr. Morris before mentioned, state the
communications, oral and written, which have passed between him
and the ministers; and from these the Secretary of State draws the
following inferences:
1. That the British court is decided not to surrender the posts in any
event; and that they will urge as a pretext that though our courts of
justice are now open to British subjects, they were so long shut after
the peace as to have defeated irremedially the recovery of debts in
many cases. They suggest, indeed, the idea of an indemnification on
our part. But probably were we disposed to admit their right to
indemnification, they would take care to set it so high as to insure a
disagreement.
2. That as to indemnification for the negroes, their measures for
concealing them were in the first instance so efficacious, as to
reduce our demand for them, so far as we can support it by direct
proof, to be very small indeed. Its smallness seems to have kept it
out of discussion. Were other difficulties removed, they would
probably make none of this article.
3. That they equivocate on every proposal of a treaty of commerce,
and authorize in their communications with Mr. Morris the same
conclusions which have been drawn from those they had had from
time to time with Mr. Adams, and those through Mayor Beckwith; to
wit, that they do not mean to submit their present advantages in
commerce to the risk which might attend a discussion of them,
whereon some reciprocity could not fail to be demanded. Unless,
indeed, we would agree to make it a treaty of alliance as well as
commerce, so as to undermine our obligations with France. This
method of stripping that rival nation of its alliances, they tried
successfully with Holland, endeavored at it with Spain, and have
plainly and repeatedly suggested to us. For this they would probably
relax some of the rigors they exercise against our commerce.
4. That as to a minister, their Secretary for foreign affairs is disposed
to exchange one, but meets with opposition in his cabinet, so as to
render the issue uncertain.
From the whole of which, the Secretary of State is of opinion that
Mr. Morris' letters remove any doubts which might have been
entertained as to the intentions and dispositions of the British
cabinet.
That it would be dishonorable to the United States, useless and even
injurious, to renew the propositions for a treaty of commerce, or for
the exchange of a minister; and that these subjects should now
remain dormant, till they shall be brought forward earnestly by
them.
That the demands of the posts, and of indemnification for the
negroes, should not be again made till we are in readiness to do
ourselves the justice which may be refused.
That Mr. Morris should be informed that he has fulfilled the object of
his agency to the satisfaction of the President, inasmuch as he has
enabled him to judge of the real views of the British cabinet, and
that it is his pleasure that the matters committed to him be left in
the situation in which the letter shall find them.
That a proper compensation be given to Mr. Morris for his services
herein, which having been begun on the 22d of January, and ended
the 18th of September, comprehend a space of near eight months;
that the allowance to an agent may be properly fixed anywhere
between the half and the whole of what is allowed to a Chargé
d'affaires; which, according to the establishment of the United States
at the time of this appointment, was at the rate of $3,000 a year;
consequently, that such a sum of between one and two thousand
dollars be allowed him as the President shall deem proper, on a view
of the interference which this agency may have had with Mr. Morris'
private pursuits in Europe.

XVIII.—Report relative to the Mediterranean trade.

December 28, 1790.

The Secretary of State, to whom was referred by the House of


Representatives so much of the speech of the President of the
United States to both Houses of Congress, as relates to the trade of
the United States in the Mediterranean, with instructions to report
thereupon to the House, has had the same under consideration, and
thereupon makes the following report:
The loss of the records of the custom houses in several of the
States, which took place about the commencement and during the
course of the late war, has deprived us of official information, as to
the extent of our commerce and navigation in the Mediterranean
sea. According to the best which may be obtained from other
sources meriting respect, it may be concluded that about one-sixth
of the wheat and flour exported from the United States, and about
one-fourth in value of their dried and pickled fish, and some rice,
found their best markets in the Mediterranean ports; that these
articles constituted the principal part of what we sent into that sea;
that that commerce loaded outwards from eighty to one hundred
ships, annually, of twenty thousand tons, navigated by about twelve
hundred seamen. It was abandoned early in the war. And after the
peace which ensued, it was obvious to our merchants, that their
adventures into that sea would be exposed to the depredations of
the piratical States on the coast of Barbary. Congress, too, was very
early attentive to this danger, and by a commission of the 12th of
May, 1784, authorized certain persons, named ministers
plenipotentiary for that purpose, to conclude treaties of peace and
amity with the Barbary powers. And it being afterwards found more
expedient that the negotiations should be carried on at the
residences of those powers. Congress, by a farther commission,
bearing date the 11th of March, 1785, empowered the same
ministers plenipotentiary to appoint agents to repair to the said
powers at their proper residences, and there to negotiate such
treaties. The whole expenses were limited to eighty thousand
dollars. Agents were accordingly sent to Morocco and Algiers.
Before the appointment of the one to Morocco, it was known that a
cruiser of that State had taken a vessel of the United States; and
that the emperor, on the friendly interposition of the court of Madrid
had liberated the crew, and made restitution of the vessel and cargo,
as far as their condition admitted. This was a happy presage of the
liberal treaty he afterwards concluded with our agent, still under the
friendly mediation of Spain, and at an expense of between nine and
ten thousand dollars only. On his death, which has taken place not
long since, it becomes necessary, according to their usage, to obtain
immediately a recognition of the treaty by his successor, and
consequently, to make provision for the expenses which may attend
it. The amount of the former furnishes one ground of estimate; but
the character and dispositions of the successor, which are unknown
here, may influence it materially. The friendship of this power is
important, because our Atlantic as well as Mediterranean trade is
open to his annoyance, and because we carry on a useful commerce
with his nation.
The Algerines had also taken two vessels of the United States, with
twenty-one persons on board, whom they retained as slaves. On the
arrival of the agent sent to that regency, the dey refused utterly to
treat of peace on any terms, and demanded 59,496 dollars for the
ransom of our captives. This mission therefore proved ineffectual.
While these negotiations were on foot at Morocco and Algiers, an
ambassador from Tripoli arrived in London. The ministers
plenipotentiary of the United States met him in person. He
demanded for the peace of that State, thirty thousand guineas; and
undertook to engage that of Tunis for a like sum. These demands
were beyond the limits of Congress, and of reason, and nothing was
done. Nor was it of importance, as, Algiers remaining hostile, the
peace of Tunis and Tripoli was of no value, and when that of the
former should be obtained, theirs would soon follow.
Our navigation, then, into the Mediterranean, has not been resumed
at all since the peace. The sole obstacle has been the unprovoked
war of Algiers; and the sole remedy must be to bring that war to an
end, or to palliate its effects. Its effects may, perhaps, be palliated
by insuring our ships and cargoes destined for that sea, and by
forming a convention with the regency, for the ransom of our
seamen, according to a fixed tariff. That tariff will, probably, be high,
and the rate of insurance so settled, in the long run, as to pay for
the vessels and cargoes captured, and something more. What
proportion will be captured nothing but experience can determine.
Our commerce differs from that of most of the nations with whom
the predatory States are in habits of war. Theirs is spread all over
the face of the Mediterranean, and therefore must be sought for all
over its face. Ours must all enter at a strait only five leagues wide;
so that their cruisers, taking a safe and commanding position near
the strait's mouth, may very effectually inspect whatever enters it.
So safe a station, with a certainty of receiving for their prisoners a
good and stated price, may tempt their cupidity to seek our vessels
particularly. Nor is it certain that our seamen could be induced to
engage in that navigation, though with the security of Algerine faith
that they would be liberated on the payment of a fixed sum. The
temporary deprivation of liberty, perhaps chains, the danger of the
pest, the perils of the engagement preceding their surrender, and
possible delays of the ransom, might turn elsewhere the choice of
men, to whom all the rest of the world is open. In every case, these
would be embarrassments which would enter into the merchants'
estimate, and endanger the preference of foreign bottoms not
exposed to them. And upon the whole, this expedient does not fulfil
our wish of a complete re-establishment of our commerce in that
sea.
A second plan might be to obtain peace by purchasing it. For this we
have the example of rich and powerful nations, in this instance
counting their interest more than their honor. If, conforming to their
example, we determine to purchase a peace, it is proper to inquire
what a peace may cost. This being merely a matter of conjecture,
we can only compare together such opinions as have been obtained,
and from them form one for ourselves.
Mr. Wolf, a respectable Irishman, who had resided very long at
Algiers, thought a peace might be obtained from that regency, and
the redemption of our captives included, for sixty or seventy
thousand pounds sterling.[25] His character and opinion both merited
respect. Yet his estimate being the lowest of all who have hazarded
an opinion on this subject, one is apt to fear his judgment might
have been biassed by the hope he entertained that the United States
would charge him with this negotiation.
Captain O'Brien, one of our captives, who had been in Algiers four
years and a half at the date of his last letter, a very sensible man,
and to whom we are indebted for very minute information, supposes
that peace alone, might be bought for that sum, that is to say, for
three hundred and twenty-two thousand dollars.
The Tripoline ambassador, before mentioned, thought that peace
could be made with the three smaller powers for ninety thousand
pounds sterling, to which were to be added the expenses of the
mission and other incidental expenses. But he could not answer for
Algiers; they would demand more. The ministers plenipotentiary,
who conferred with him, had judged that as much must be paid to
Algiers as to the other three powers together; and consequently,
that according to this measure, the peace of Algiers would cost from
an hundred to an hundred and twenty-five thousand pounds
sterling; or from four hundred and sixty to five hundred and seventy-
five thousand dollars.
The latter sum seemed to meet the ideas of the Count de
Vergennes, who, from a very long residence at Constantinople, was
a good judge of what related to the porte, or its dependencies.
A person whose name is not free to be mentioned here, a native of
the continent of Europe, who had long lived, and still lives at Algiers,
with whom the minister plenipotentiary of the United States, at
Paris, had many and long conversations, and found his information
full, clear, and consistent, was of opinion the peace of Algiers could
not be bought by the United States for less than one million of
dollars. And when that is paid, all is not done. On the death of a dey,
(and the present one is between seventy and eighty years of age,)
respectable presents must be made to the successor, that he may
recognize the treaty and very often he takes the liberty of altering it.
When a consul is sent or changed, new presents must be made. If
these events leave a considerable interval, occasion must be made
of renewing presents. And with all this they must see that we are in
condition to chastise an infraction of the treaty; consequently some
marine force must be exhibited in their harbor from time to time.
The late peace of Spain with Algiers is said to have cost from three
to five millions of dollars. Having received the money, they take the
vessels of that nation on the most groundless pretexts; counting,
that the same force which bound Spain to so hard a treaty, may
break it with impunity.
Their treaty with France, which had expired, was about two years
ago renewed for fifty years. The sum given at the time of renewal is
not known. But presents are to be repeated every ten years, and a
tribute of one hundred thousand dollars to be annually paid. Yet
perceiving that France, embarrassed at home with her domestic
affairs, was less capable of acting abroad, they took six vessels of
that nation in the course of the last year, and retain the captives,
forty-four in number, in slavery.
It is the opinion of Captain O'Brien, that those nations are best
treated who pay a smaller sum in the beginning, and an annual
tribute afterwards. In this way he informs us that the Dutch, Danes,
Swedes, and Venetians pay to Algiers, from twenty-four to thirty
thousand dollars a year, each; the two first in naval stores, the two
last chiefly in money. It is supposed, that the peace of the Barbary
States costs Great Britain about sixty thousand guineas, or two
hundred and eighty thousand dollars a year. But it must be noted
that these facts cannot be authentically advanced; as from a
principle of self-condemnation, the governments keep them from the
public eye as much as possible.
Nor must we omit finally to recollect, that the Algerines, attentive to
reserve always a sufficient aliment for their piracies, will never
extend their peace beyond certain limits, and consequently, that we
may find ourselves in the case of those nations to whom they refuse
peace at any price.
The third expedient is to repel force by force. Several statements are
hereto annexed of the naval force of Algiers, taken in 1785, 1786,
1787, 1788, and 1789, differing in small degrees, but concurring in
the main. From these it results that they have usually had about
nine chebecs, from ten to thirty-six guns, and four galleys, which
have been reduced by losses to six chebecs and four galleys. They
have a forty-gun frigate on the stocks, and expect two cruisers from
the grand seignior. The character of their vessels is, that they are
sharp built and swift, but so light as not to stand the broadside of a
good frigate. Their guns are of different calibres, unskilfully pointed
and worked. The vessels illy manœuvred, but crowded with men,
one third Turks, the rest Moors, of determined bravery, and resting
their sole hopes on boarding. But two of these vessels belong to the
government, the rest being private property. If they come out of the
harbor together, they separate immediately in quest of prey; and it is
said they were never known to act together in any instance. Nor do
they come out at all, when they know there are vessels cruising for
them. They perform three cruises a year, between the middle of April
and November, when they unrig and lay up for the winter. When not
confined within the straits, they rove northwardly to the channel,
and westwardly to the westward islands.
They are at peace at present, with France, Spain, England, Venice,
the United Netherlands, Sweden, and Denmark; and at war with
Russia, Austria, Portugal, Naples, Sardinia, Genoa, and Malta.
Should the United States propose to vindicate their commerce by
arms, they would, perhaps, think it prudent to possess a force equal
to the whole of that which may be opposed to them. What that
equal force would be, will belong to another department to say.
At the same time it might never be necessary to draw out the whole
at once, nor perhaps any proportion of it, but for a small part of the
year; as it is reasonable to presume that a concert of operation
might be arranged among the powers at war with the Barbary
States, so as that, each performing a tour of given duration, and in
given order, a constant cruise during the eight temperate months of
every year, may be kept up before the harbor of Algiers, till the
object of such operations be completely obtained. Portugal has
singly, for several years past, kept up such a cruise before the straits
of Gibraltar, and by that means has confined the Algerines closely
within. But two of their vessels have been out of the straits in the
last five years. Should Portugal effect a peace with them, as has
been apprehended for some time, the Atlantic will immediately
become the principal scene of their piracies; their peace with Spain
having reduced the profits of their Mediterranean cruises below the
expenses of equipment.
Upon the whole, it rests with Congress to decide between war,
tribute, and ransom, as the means of re-establishing our
Mediterranean commerce. If war, they will consider how far our own
resources shall be called forth, and how far they will enable the
Executive to engage, in the forms of the constitution, the co-
operation of other powers. If tribute or ransom, it will rest with them
to limit and provide the amount; and with the Executive, observing
the same constitutional forms, to take arrangements for employing it
to the best advantage.

No. 1.—Extract of a letter from Richard O'Brien, one of the American


captives at Algiers, to Congress. Algiers, December 26, 1789.
"It was the opinion of Mr. John Wolf, who resided many years in this
city, that the United States of America may obtain a peace for one
hundred years with this regency, for the sum of sixty or seventy
thousand pounds sterling, and the redemption of fifteen Americans
included. Mr. Wolf was the British chargé des affaires in Algiers, and
was much the friend of America, but he is no more.
"I have now been four years and a half in captivity, and I have much
reason to think, that America may obtain a peace with Algiers for the
sum of sixty-five or seventy thousand pounds, considering the
present state of Algiers. That this regency would find it their interest
to take two or three American cruisers in part payment for making a
peace; and also would take masts, yards, plank, scantling, tar, pitch,
and turpentine, and Philadelphia iron, as a part payment; all to be
regulated at a certain fixed price by treaty."
No. 2.—Extract of a letter from the Honorable John Adams, Minister
Plenipotentiary for the United States at London, to the Honorable
John Jay, Secretary for Foreign Affairs. London, February 22, 1786
"On Monday evening another conference was held with the Tripolitan
ambassador. When he began to explain himself concerning his
demands, he said they would be different according to the duration
of the treaty. If that were perpetual, they would be greater; if for a
term of years, less; his advice was that it should be perpetual. Once
signed by the bashaw, dey, and other officers, it would be
indissoluble and binding forever upon all their successors. But if a
temporary treaty were made, it might be difficult and expensive to
revive it. For a perpetual treaty, such as they now had with Spain, a
sum of thirty thousand guineas must be paid upon the delivery of
the articles signed by the dey and other officers. If it were agreed
to, he would send his secretary by land to Marseilles, and from
thence, by water, to Tripoli, who should bring it back by the same
route, signed by the dey, &c. He had proposed so small a sum in
consideration of the circumstances, but declared it was not half of
what had been lately paid them by Spain. If we chose to treat upon
a different plan, he would make a treaty perpetual upon the
payment of twelve thousand five hundred guineas for the first year,
and three thousand guineas annually, until the thirty thousand
guineas were paid. It was observed that these were large sums, and
vastly beyond expectation; but his excellency answered, that they
never made a treaty for less. Upon the arrival of a prize, the dey and
other officers are entitled, by their laws, to large shares, by which
they might make greater profits than those sums amounted to, and
they never would give up this advantage for less.
"He was told, that although there was full power to treat, the
American ministers were limited to a much smaller sum; so that it
would be impossible to do anything until we wrote to Congress and
know their pleasure. Colonel Smith was present at this, as he had
been at the last conference, and agreed to go to Paris, to
communicate all to Mr. Jefferson, and persuade him to come here,
that we may join in farther conferences, and transmit the result to
Congress.
"The ambassador believed that Tunis and Morocco would treat upon
the same terms, but could not answer for Algiers. They would
demand more. When Mr. Jefferson arrives, we shall insist upon
knowing the ultimatum, and transmit it to Congress.
"Congress will perceive that one hundred and twenty thousand
guineas will be indispensable to conclude with the four powers at
this rate, besides a present to the ambassadors, and their incidental
charges. Besides this, a present of five hundred guineas is made,
upon the arrival of a consul in each State. No man wishes more
fervently that the expense could be less, but the fact cannot be
altered, and the truth ought not to be concealed.
"It may be reasonably concluded that this great affair cannot be
finished for much less than two hundred thousand pounds sterling."

No. 3.—Extract of a Letter from the Honorable Thomas Jefferson,


Minister Plenipotentiary for the United States at Paris, to the
Honorable John Jay, Secretary for foreign Affairs. Paris, May 23,
1786.
"Letters received both from Madrid and Algiers, while I was in
London, having suggested that treaties with the States of Barbary
would be much facilitated by a previous one with the Ottoman Porte,
it was agreed between Mr. Adams and myself, that on my return I
should consult, on this subject, the Count De Vergennes, whose long
residence at Constantinople rendered him the best judge of its
expediency. Various circumstances have put it out of my power to
consult him till to-day. I stated to him the difficulties we were likely
to meet with at Algiers, and asked his opinion, what would be the
probable expense of a diplomatic mission to Constantinople, and
what its effects at Algiers. He said that the expense would be very
great; for that presents must be made at that court, and every one
would be gaping after them; and that it would not procure us a
peace at Algiers one penny the cheaper. He observed that the
Barbary States acknowledged a sort of vassalage to the Porte, and
availed themselves of that relation when anything was to be gained
by it; but that whenever it subjected them to the demand from the
Porte, they totally disregarded it; that money was the sole agent. He
cited the present example of Spain, which, though having a treaty
with the Porte, would probably be obliged to buy a peace at Algiers,
at the expense of upwards of six millions of livres. I told him we had
calculated, from the demands and information of the Tripoline
ambassador at London, that to make peace with the four Barbary
States would cost us between two and three hundred thousand
guineas, if bought with money.
"The sum did not seem to exceed his expectations. I mentioned to
him, that considering the uncertainty of a peace, when bought,
perhaps Congress might think it more eligible to establish a cruise of
frigates in the Mediterranean, and even blockade Algiers. He
supposed it would require ten vessels, great and small. I observed to
him that M. De Massiac had formerly done it with five; he said it was
true, but that vessels of relief would be necessary. I hinted to him
that I thought the English capable of administering aid to the
Algerines. He seemed to think it impossible, on account of the
scandal it would bring on them. I asked him what had occasioned
the blockade by M. De Massiac, he said an infraction of their treaty
by the Algerines."

No. 4.—Extract of a Letter from Richard O'Brien to the Hon. Thomas


Jefferson. Algiers, April 28, 1787.
"It seems the Neapolitan ambassador had obtained a truce with this
regency for three months; and the ambassador wrote his court of his
success; but about the 1st of April, when the cruisers were fitting
out, the ambassador went to the dey, and hoped the dey would give
the necessary orders to the captains of his cruisers not to take the
Neapolitan vessels. The dey said the meaning of the truce was not
to take the Neapolitan cruisers, but if his chebecks should meet the
Neapolitan merchantmen to take them and send them for Algiers.
The ambassador said, the Neapolitan cruisers would not want a pass
on those terms. The dey said, if his chebecks should meet either
men of war or merchant vessels, to take them; so gave orders
accordingly. The Algerines sailed the 9th instant, and are gone, I
believe, off the coast of Italy. This shows there is very little
confidence to be put in the royal word. No principle of national
honor will bind those people; and I believe not much confidence to
be put in them in treaties. The Algerines are not inclinable to a
peace with the Neapolitans. I hear of no negotiation. When the two
frigates arrive with the money for the ransom of the slaves, I believe
they are done with the Neapolitans."

Extract of a Letter from Richard O'Brien to the Hon. Thomas


Jefferson. Algiers, June 13, 1789.
"The cruisers had orders to take the Danes; but I believe Denmark,
suspecting that on account of their alliance with Russia, that the
grand seignior would order the regency of Algiers to make war
against the Danes; accordingly, the Danes have evacuated the
Mediterranean seas, until the affairs of Europe are more settled. The
Danish ship with the tribute is shortly expected. She is worth fifty
thousand dollars; so that the Algerines will not make known publicly
their intention of breaking with Denmark, until this ship arrives with
the tribute. I am very sure that Mr. Robindar is very sensible of the
intention of those sea-robbers, the terror and scourge of the
Christians. The reason the Algerines have not committed any
depredations on the English, is, that the cruisers have not met with
any of them richly loaded; for if they had met a rich ship from
London for Livorna, they would certainly have brought her into port,
and said that such ship was loaded for the enemy of Algiers at
Livorna; but if that was not a sufficient excuse, hove overboard or
clipt the pass.
"Consul Logie has been treated with much contempt by the Algerine
ministry; and you may depend, that when the dey goes to his long
home, that his successor will not renew the peace with Great Britain,
without a large sum of money is paid, and very valuable presents.
This I well know; the whole ministry says, that the peace with the
English is very old, and that the English must conform to the custom
of other nations, in giving the government here money and presents.
In fact, the Algerines are trying their endeavors to find some nation
to break the peace with them. I think, if they had treated the English
in such a manner as they have the French, that the English would
resent it."

Extract of a Letter from Richard O'Brien to the Hon. Thomas


Jefferson. Algiers, June 13, 1789.
"What dependence or faith could be given to a peace with the
Algerines, considering their present haughtiness, and with what
contempt and derision do they treat all nations; so that, in my
opinion, until the Algerines more strictly adhere to the treaties they
have already made, it would be impolitic in any nation to try to make
a peace here; for I see they take more from the nations they are at
peace with, than from those they are at declared war with. The
Portuguese, I hope, will keep the Algerines inside the straits; for only
consider the bad consequence of the Algerines going into the mar
Grandi. Should the Portuguese make a sudden peace with this
regency, the Algerines would immediately go out of the straits, and
of course, take many an American."

No. 5.—Extract of a Letter from the Hon. John Adams, Esq., Minister
Plenipotentiary of the United States at the Court of Great Britain, to
the Hon. John Jay, Esq., Secretary for Foreign Affairs. February 16,
1786.
"The American commerce can be protected from these Africans only
by negotiation, or by war. If presents should be exacted from us, as
ample as those which are given by England, the expense may
amount to sixty thousand pounds sterling a year, an enormous sum
to be sure; but infinitely less than the expense of fighting. Two
frigates of 30 guns each would cost as much to fit them for the sea,
besides the accumulating charges of stores, provisions, pay, and
clothing. The powers of Europe generally send a squadron of men of
war with their ministers, and offer battle at the same time that they
propose treaties and promise presents."

No. 6.—Several statements of the Marine force of Algiers.—Public


and private
May 20, 1786.—Mr. Lamb says it consists of
9 Chebecs from 36 to 8 guns; manned, the largest
10 Row Galleys with 400 men, and so in proportion.

May 27, 1787.—Mr. Randall furnishes two statements, viz.:


A more general one— 1 Setye of 34 guns.
2 Setye of 32 guns.
1 Setye of 26 guns.
1 Setye of 24 guns.
1 Chebec of 20 guns
1 Chebec of 18 guns.
1 Chebec of 10 guns.
8
4 half-galleys, carrying from 120 to 130 Moors.
3 galliots of 70, 60, and 50 Moors.
A more particular one as follows:
1 of 32 viz. 2 24 nines, 6 and 450
guns, eighteens, fours, men.
1 of 28 viz. 2 twelves, 24 nines, 2 and 400
guns, sixes, men.
1 of 24 viz. 20 fours, and 350
guns, men.
1 of 20 viz. 20 sixes, and 300
guns, men.
2 of 18 viz. 18 sixes, and 260
guns, men.
1 of 16 viz. 16 sixes, and 250
guns, men.
2 small
craft.
9
55 gun-boats, carrying 1 twelve pounder each, for defence of
the harbor.
June 8, 1786.—A letter from the three American captains, O'Brien,
Coffin, and Stephens, state them
as 1 of 32
1 of 30
3 of 24
3 of 18
1 of 12
9 and 55 gun-boats.
September 25, 1787.—Captain O'Brien furnishes the following
statement
1 of 30 guns, 400 men, 106 feet length, straight keel.
1 of 26 guns, 320 men, 96 feet length, straight keel.
2 of 22 guns, 240 men, 80 feet length, straight keel.
1 of 22 guns, 240 men, 75 feet length, straight keel.
1 of 22 guns, 240 men, 70 feet length, straight keel.
1 of 18 guns, 200 men, 70 feet length, straight keel.
1 of 16 guns, 180 men, 64 feet length, straight keel.
1 of 12 guns, 150 men, 50 feet length, straight keel.
9
Galleys 1 of 4 guns, 70 men, 40 feet length, straight keel.
2 of 2 guns, 46 men, 32 feet length, straight keel.
1 of 2 guns, 40 men, 32 feet length, straight keel.
February 5, 1788.—Statement by the inhabitants of Algiers, spoken
of in the report.

9 vessels from 36 down to 20 guns.


4 or 5 smaller.

About this date the Algerines lost two or three vessels, stranded or
taken.
December, 1789.—Captain O'Brien furnishes the latest statement.
1 ship of 24 guns, received lately from France.
5 large cruisers.
6 3 galleys, and 60 gun-boats.

In the fall of 1789, they laid the keel of a 40 gun frigate, and they
expect two cruisers from the grand seignior.

No. 7.—Translation of a Letter from Count D'Estaing to the Hon.


Thomas Jefferson, Esq. Paris, May 17, 1784.
Sir,—In giving you an account of an opinion of Mr. Massiac, and
which absolutely corresponds with my own, I cannot too much
observe how great a difference may take place in the course of forty
years between the means which he required and those which
political circumstances, that I cannot ascertain, may exact.
This Secretary of State, afterwards vice-Admiral, had the modesty,
when a captain, to propose a means for the reduction of Algiers, less
brilliant to himself, but more sure and economical than the one
government was about to adopt. They wanted him to undertake a
bombardment; he proposed a simple blockade. All the force he
requested was a single man-of-war, two strong frigates, and two
sloops-of-war.
I am convinced, that by blocking up Algiers by cross-anchoring, and
with a long tow, that is to say, with several cables spliced to each
other, and with iron chains, one might, if necessary, always remain
there, and there is no Barbarian power thus confined, which would
not sue for peace.
During the war before last the English remained, even in winter, at
anchor before Morbian, on the coast of Brittany, which is a much
more dangerous coast. Expeditious preparation for sailing of the
vessels which form the blockade, which should be of a sufficient
number to prevent anything from entering or going out, while the
rest remain at their stations, the choice of these stations, skilful
manœuvres, strict watch during the night, every precaution against
the element which every seaman ought to be acquainted with; also,
against the enemy to prevent the sudden attack of boats, and to
repel them in case they should make an attack by boats prepared for
the purpose, frequent refreshments for the crews, relieving the men,
an unshaken constancy and exactness in service, are the means,
which in my opinion, would render the event indubitable.
Bombardments are but transitory. It is, if I may so express myself,
like breaking glass windows with guineas. None have produced
effect against the barbarians. Even an imperfect blockade, were one
to have the patience and courage to persist therein, would occasion
a perpetual evil, it would be insupportable in the long run. To obtain
the end proposed no advantage ought to be lost. If several powers
would come to a good understanding, and pursue a plan formed on
the principles of humanity; if they were not counteracted by others,
it would require but a few years to compel the barbarians to cease
being pirates; they would become merchants in spite of themselves.
It is needless to observe, that the unsuccessful attempts of Spain,
and those under which the republic of Venice, perhaps, hides other
views, have increased the strength as well as the self-love of all the
barbarians. We are assured that the Algerines have fitted out
merchantmen with heavy cannon. This would render it necessary to
block the place with two ships, so that one of the two might remain
moored near the bar, while the other might prepare to support such
of the frigates as should give chase. But their chebecs, even their
frigates, and all their vessels, although overcharged with men, are
moreover so badly armed and manœuvred that assistance from
without would be most to be feared.
Your excellency has told me the only true means of bringing to
terms the only people who can take a pleasure in disturbing our
commerce. You see, I speak as an American citizen; this title, dear
to my heart, the value of which I justly prize, affords me the happy
opportunity of offering, still more particularly, the homage, the
sincere attachment, and the respect with which I have the honor to
be, &c.
Estaing.

XIX.—Report on the Algerine Prisoners.

December 28, 1790.

The Secretary of State, having had under consideration the situation


of the citizens of the United States in captivity at Algiers, makes the
following report thereupon to the President of the United States:
When the House of Representatives, at their late session, were
pleased to refer to the Secretary of State, the petition of our citizens
in captivity at Algiers, there still existed some expectation that
certain measures, which had been employed to effect their
redemption, the success of which depended on their secrecy, might
prove effectual. Information received during the recess of Congress
has so far weakened those expectations, as to make it now a duty to
lay before the President of the United States, a full statement of
what has been attempted for the relief of these our suffering
citizens, as well before, as since he came into office, that he may be
enabled to decide what further is to be done.
On the 25th of July, 1785, the schooner Maria, Captain Stevens,
belonging to a Mr. Foster, of Boston, was taken off Cape St. Vincents,
by an Algerine corsair; and, five days afterwards, the ship Dauphin,
Captain O'Brien, belonging to Messieurs Irvins of Philadelphia, was
taken by another Algerine, about fifty leagues westward of Lisbon.
These vessels, with their cargoes and crews, twenty-one persons in
number, were carried into Algiers.
Congress had some time before commissioned ministers
plenipotentiary for entering into treaties of amity and commerce with
the Barbary Powers, and to send to them proper agents for
preparing such treaties. An agent was accordingly appointed for
Algiers, and his instructions prepared, when the Ministers
Plenipotentiary received information of these captures. Though the
ransom of captives was not among the objects expressed in their
commissions, because at their dates the case did not exist, yet they
thought it their duty to undertake that ransom, fearing that the
captives might be sold and dispersed through the interior and distant
countries of Africa, if the previous orders of Congress should be
waited for. They therefore added a supplementary instruction to the
agent to negotiate their ransom. But, while acting thus without
authority, they thought themselves bound to offer a price so
moderate as not to be disapproved. They therefore restrained him to
two hundred dollars a man; which was something less than had
been just before paid for about three hundred French captives, by
the Mathurins, a religious order of France, instituted in ancient times
for the redemption of Christian captives from the infidel Powers. On
the arrival of the agent at Algiers, the dey demanded fifty-nine
thousand four hundred and ninety-six dollars for the twenty-one
captives, and could be brought to abate but little from that demand.
The agent, therefore, returned in 1786, without having effected
either peace or ransom.
In the beginning of the next year, 1787, the Minister Plenipotentiary
of the United States at Paris procured an interview with the general
of the religious order of Mathurins, before mentioned, to engage him
to lend his agency, at the expense of the United States, for the
redemption of their captive citizens. He proffered at once all the
services he could render, with the liberality and the zeal which
distinguish his character. He observed, that he had agents on the
spot, constantly employed in seeking out and redeeming the
captives of their own country; that these should act for us, as for
themselves; that nothing could be accepted for their agency; and
that he would only expect that the price of redemption should be
ready on our part, so as to cover the engagement into which he
should enter. He added, that, by the time all expenses were paid,
their last redemption had amounted to near two thousand five
hundred livres a man, and that he could by no means flatter us that
they could redeem our captives as cheap as their own. The pirates
would take advantage of its being out of their ordinary line. Still he
was in hopes they would not be much higher.
The proposition was then submitted to Congress, that is to say, in
February, 1787, and on the 19th of September, in the same year,
their Minister Plenipotentiary at Paris received their orders to
embrace the offers of the Mathurins. This he immediately notified to
the general, observing, however, that he did not desire him to enter
into any engagements till a sufficient sum to cover them should be
actually deposited in Paris. The general wished that the whole might
be kept rigorously secret, as, should the barbarians suspect him to
be acting for the United States, they would demand such sums as he
could never agree to give, even with our consent, because it would
injure his future purchases from them. He said he had information
from his agent at Algiers, that our captives received so liberal a daily
allowance as to evince that it came from a public source. He
recommended that this should be discontinued; engaging that he
would have an allowance administered to them, much short indeed
of what they had hitherto received, but such as was given to his own
countrymen, quite sufficient for physical necessities, and more likely
to prepare the opinion, that as they were subsisted by his charity,
they were to be redeemed by it also. These ideas, suggested to him
by the danger of raising his market, were approved by the Minister
Plenipotentiary; because, this being the first instance of a
redemption by the United States, it would form a precedent,
because a high price given by us might induce these pirates to
abandon all other nations in pursuit of Americans; whereas, the
contrary would take place, could our price of redemption be fixed at
the lowest point.
To destroy, therefore, every expectation of a redemption by the
United States, the bills of the Spanish consul at Algiers, who had
made the kind advances before spoken of for the sustenance of our
captives, were not answered. On the contrary, a hint was given that
these advances had better be discontinued, as it was not known that
they would be reimbursed. It was necessary even to go further, and
to suffer the captives themselves and their friends to believe for
awhile, that no attention was paid to them, no notice taken of their
letters. They are still under this impression. It would have been
unsafe to trust them with a secret, the disclosure of which might
forever prevent their redemption, by raising the demands of the
captors to sums which a due regard for our seamen, still in freedom,
would forbid us to give. This was the most trying of all
circumstances, and drew from them the most afflicting reproaches.
It was a twelvemonth afterwards before the money could be
deposited in Paris, and the negotiation be actually put into train. In
the meantime the general had received information from Algiers of a
very considerable change of prices there. Within the last two or
three years the Spaniards, the Neapolitans, and the Russians, had
redeemed at exorbitant sums. Slaves were become scarce, and
would hardly be sold at any price. Still he entered on the business
with an assurance of doing the best in his power; and he was
authorized to offer as far as three thousand livres, or five hundred
and fifty-five dollars a man. He wrote immediately to consult a
confidential agent at Marseilles, on the best mode of carrying this
business into effect; from whom he received the answer No. 2,
hereto annexed.
Nothing further was known of his progress or prospects, when the
House of Representatives were pleased, at their last session, to refer
the petition of our captives at Algiers to the Secretary of State. The
preceding narrative shows that no report could have then been
made without risking the object, of which some hopes were still
entertained. Later advices, however, from the chargé des affaires of
the United States, at Paris, informs us, that these measures, though
not yet desperate, are not to be counted on. Besides the exorbitance
of price, before feared, the late transfer of the lands and revenues of
the clergy in France to the public, by withdrawing the means, seems
to have suspended the proceedings of the Mathurins in the purposes
of their institution.
It is time, therefore, to look about for something more promising,
without relinquishing, in the meanwhile, the chance of success
through them. Endeavors to collect information, which have been
continued a considerable time, as to the ransoms which would
probably be demanded from us, and those actually paid by other
nations, enable the Secretary of State to lay before the President the
following short view, collected from original papers now in his
possession, or from information delivered to him personally. Passing
over the ransoms of the Mathurins, which are kept far below the
common level by special circumstances:
In 1786, the dey of Algiers demanded from our agent $59,496 for
twenty-one captives, which was $2,833 a man. The agent flattered
himself they could be ransomed for $1,200 apiece. His secretary
informed us, at the same time, that Spain had paid $1,600.
In 1787, the Russians redeemed at $1,546 a man.
In 1788, a well-informed inhabitant of Algiers assured the Minister
Plenipotentiary of the United States at Paris, that no nation had
redeemed, since the Spanish treaty, at less than from £250 to £300
sterling, the medium of which is $1,237. Captain O'Brien, at the
same date, thinks we must pay $1,800, and mentions a Savoy
captain, just redeemed at $4,074.
In 1789, Mr. Logie, the English consul at Algiers, informed a person
who wished to ransom one of our common sailors, that he would
cost from £450 to £500 sterling, the mean of which is $2,137. In
December of the same year, Captain O'Brien thinks our men will now
cost $2,290 each, though a Jew merchant believes he could get
them for $2,264.
In 1790, July 9th, a Mr. Simpson, of Gibraltar, who, at some
particular request, had taken pains to find for what sum our captives
could be redeemed, finds that the fourteen will cost $34,79,228,
which is $2,485 a man. At the same date, one of them, a Scotch
boy, a common mariner, was actually redeemed at 8,000 livres,
equal to $1,481, which is within nineteen dollars of the price
Simpson states for common men; and the chargé des affaires of the
United States at Paris is informed that the whole may be redeemed
at that rate, adding fifty per cent. on the captains, which would
bring it to $1,571 a man.
It is found then that the prices are 1,200, 1,237, 1,481, 1,546,
1,571, 1,600, 1,800, 2,137, 2,264, 2,485, 2,833, and 2,920 dollars a
man, not noticing that of $4,074, because it was for a captain.
In 1786, there were 2,200 captives in Algiers, which, in 1789, had
been reduced by death or ransom to 655. Of ours six have died, and
one has been ransomed by his friends.
From these facts and opinions, some conjecture may be formed of
the terms on which the liberty of our citizens may be obtained.
But should it be thought better to repress force by force, another
expedient for their liberation may perhaps offer. Captures made on
the enemy may perhaps put us into possession of some of their
mariners, and exchange be substituted for ransom. It is not indeed a
fixed usage with them to exchange prisoners. It is rather their

You might also like