akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc169/tasks/abc169_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

VPL factorize(ll n) {
  VPL res;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;

    auto r = PL(i, 0);

    while (n % i == 0) {
      n /= i;
      r.second++;
    }

    res.push_back(r);
  }

  // sqrt(n) 以上の素因数は高々一つ
  if (n != 1) res.emplace_back(n, 1);

  return res;
}

void solve() {
  ll N;
  cin >> N;

  VPL fs = factorize(N);

  ll res = 0;

  for (auto p : fs) {
    ll num = p.fi;
    ll pow = p.se;

    rep1(i, pow) {
      unless(pow - i >= 0) break;
      pow -= i;
      ++res;
    }
  }

  cout << res << "\n";
}


Measured memory_bytes: 3596
// Bismillahir Rahmanir Rahim
// AtCoder-c

#include<bits/stdc++.h>
using namespace std;
int a[200010];
int ans[200010];
 
 int main(){
   int n; cin>>n;
   for(int i = 1; i < n;  ++i)
    cin>>a[i];
   for(int i = 1; i < n; ++i)
     ans[a[i]]++;
     
    for(int i = 1; i <= n ; ++i)
      cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 5124
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 105;
string S[N];
bool cmp(string a, string b) {
    return a < b;
}
int main() {
    int n,l;
    cin >> n >> l;
    for(int i = 1; i <= n; ++i) {
        cin >> S[i];
    }
    sort(S+1,S+1+n,cmp);
    for(int i = 1; i <= n; ++i)
        cout << S[i];
    cout << '\n';
return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int w,h,r,x,y;
    w = scan.nextInt();
    h = scan.nextInt();
    x = scan.nextInt();
    y = scan.nextInt();
    r = scan.nextInt();
    if (x+r <= w && x-r >= 0 && y+r <= h && y-r >= 0){
      System.out.println("Yes");
    }  else {
      System.out.println("No");
    }
    scan.close();
  }
}


Measured memory_bytes: 26408
N=int(input())
S=input()
minimum=3*pow(10, 5)
east=[0]
for i in range(1,N+1):
    if S[i-1]=='E':
        east.append(east[i-1]+1)
    else:
        east.append(east[i-1])
for i in range(N):
    candidate = i-east[i]+(east[N]-east[i+1])
    minimum = min(candidate, minimum)
print(minimum)

Measured memory_bytes: 15520
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pub push_back
#define all(in) in.begin(),in.end()

using ll = long long; // typedef long long ll; と同意
using ull = unsigned long long;
using namespace std;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    sx--; sy--; gx--; gy--;

    vector<string> map(h);
  	rep(i,h) cin >> map[i];

    vector<vector<int>> data(h,vector<int>(w,1<<30));
    queue<pair<int,int>> que;

    data[sx][sy] = 0;
    que.push(make_pair(sx,sy));

    int dx[4] = {0,1,0,-1};
    int dy[4] = {1,0,-1,0};

    while(que.size()){
        pair<int,int> p = que.front(); que.pop();
        int x = p.first;
        int y = p.second;
        rep(i,4){
            rep(j,k){
                int nx = x + (j+1)*dx[i];
                int ny = y + (j+1)*dy[i];
                if(nx<0 || nx>=h || ny<0 || ny>=w || map[nx][ny]=='@') break;
                int newdata = data[x][y] + 1;
                if(data[nx][ny] > newdata){
                    data[nx][ny] = newdata;
                    que.push(make_pair(nx,ny));
                }else if(data[nx][ny] < newdata) break;
            }
        }
    }
    int ans2 = data[gx][gy];
    if(ans2 == (1<<30)) cout << -1 << endl;
    else cout << ans2 << endl;
}



Measured memory_bytes: 12140
#include <stdio.h>
#include <stdlib.h>

#define N_MAX 100000



typedef struct _Node {
	int id;
	int depth;
	int kindId;
	int chldnum;
	int *chldtop;
} Node;

const char Kind[3][14] = { "root","leaf","internal node" };

Node *A[N_MAX];

int Parent[N_MAX];

Node *allocNode() {
	Node *node = (Node*)malloc(sizeof(Node));
	node->chldnum = 0;
	node->chldtop = NULL;
	return node;
}

void setTree(Node *node, int depth) {
	int i;
	if (node == NULL) return;
	node->depth = depth;
	if (depth == 0) node->kindId = 0;
	else if (node->chldnum == 0) node->kindId = 1;
	else node->kindId = 2;

	for (i = 0; i < node->chldnum; i++) {
		setTree(A[*(node->chldtop + i)], depth + 1);
	}
}

void dump(int n) {
	int i, j;
	for (i = 0; i < n; i++) {
		printf("node %d: ", A[i]->id);
		printf("parent = %d, ", Parent[i]);
		printf("depth = %d, ", A[i]->depth);
		printf("%s, ", Kind[A[i]->kindId]);
		printf("[");
		for (j = 0; j < A[i]->chldnum; j++) {
			if (j > 0) printf(", ");
			printf("%d",*(A[i]->chldtop+j));
		}
		printf("]\n");
	}	
}

void terminate(int n) {
	int i;
	for (i = 0; i < n; i++) {
		if (A[i]->chldnum > 0) free(A[i]->chldtop);
		free(A[i]);
	}
}

int main() {
	int i, j, n;
	Node *node;

	scanf("%d", &n);
	for (i = 0; i < n; i++) Parent[i] = -1;
	for (i = 0; i < n; i++) {
		node = allocNode();
		scanf("%d", &(node->id));
		scanf("%d", &(node->chldnum));
		if (node->chldnum > 0) {
			node->chldtop = (int*)malloc(sizeof(int) * node->chldnum);
			for (j = 0; j < node->chldnum; j++) {
				scanf("%d", node->chldtop + j);
				Parent[*(node->chldtop + j)] = node->id;
			}
		}
		A[node->id] = node;
	}

	i = 0;
	while (Parent[i] != -1) i++;

	setTree(A[i],0);

	dump(n);

	terminate(n);

	return 0;
}


Measured memory_bytes: 6556
########10進法からn進法への変換関数部分##############
def format(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
############################

######## 10進法からn進法への変換関数(m桁埋める)部分 ##############
def format0(X, n, m):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    if len(out) < m:
        out = "0" * (m - len(out)) + out
    return out
############################
n,m=map(int,input().split())
if m == 0:
  print(0)
  exit()
xyz = [list(map(int,input().split())) for i in range(n)]
a=[]
for i in range(8):
  i = format0(i,2,3)
  if i == "000":
    li = [-i[0]-i[1]-i[2] for i in xyz]
  elif i == "001":
    li = [-i[0]-i[1]+i[2] for i in xyz]
  elif i == "010":
    li = [-i[0]+i[1]-i[2] for i in xyz]
  elif i == "011":
    li = [-i[0]+i[1]+i[2] for i in xyz]
  elif i == "100":
    li = [i[0]-i[1]-i[2] for i in xyz]
  elif i == "101":
    li = [i[0]-i[1]+i[2] for i in xyz]
  elif i == "110":
    li = [i[0]+i[1]-i[2] for i in xyz]
  else:
    li = [i[0]+i[1]+i[2] for i in xyz]
  li.sort()
  li = li[-m:]
  a.append(sum(li))
print(max(a))


Measured memory_bytes: 3372
#include <iostream>
#include <stack>
using namespace std;

struct pos{
    int x;
    int y;
};

int main(){
    int w, h;
    while(cin >> w >> h, w != 0 && h != 0){
        int field[52][52] = {{0}};
        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                cin >> field[i][j];
            }
        }

        stack<pos> st;
        int island = 0;
        int dx[] = {-1,  0, 1, 0, -1,  1, 1, -1};
        int dy[] = {0 , -1, 0, 1, -1, -1, 1,  1};
        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                //島を探す
                if(field[i][j] == 1){
                    pos p;
                    p.y = i;
                    p.x = j;
                    st.push(p);
                    field[i][j] = 0;
                    while(!st.empty()){
                        pos stTop = st.top();
                        st.pop();
                        for(int k = 0; k < 8; k++){
                            p = stTop;
                            p.y += dy[k];
                            p.x += dx[k];
                            if(field[p.y][p.x] == 1){
                                st.push(p);
                                field[p.y][p.x] = 0;
                            }
                        }
                    }
                    island++;
                }

            }
        }

        cout << island << endl;
    }
}

Measured memory_bytes: 1240
n,d = map(int,input().split())
x = [tuple(map(int,input().split())) for i in range(n)]
c = 0
for i in range(n-1):
  for j in range(i+1,n):
    di = 0
    for k in range(d):
      di += (x[i][k]-x[j][k])**2
    if (di ** 0.5) % 1 == 0.0:
      c += 1
print(c)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
  string S;
  cin >> S;
  ll N = S.size();
  vector<ll> cnt(26,0);
  rep(i,N){
    cnt[S[i]-'a']++;
  }
  ll ans = N*(N-1)/2;
  ans++;
  rep(i,26){
    ans -= cnt[i]*(cnt[i]-1)/2;
  } 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;
import java.util.StringTokenizer;

public class Main
{

    public Main() throws IOException
    {

    }

    private void solve() throws IOException
    {
        long n = nextLong();
        long x = n;
        int cnt = 0;
        int last = 0;
        while (x > 0)
        {
            cnt++;
            x /= 10;
        }
        long cur = 1;
        for (int i = 0; i < cnt - 1; i++) cur = cur * 10 + 9;
        for (int first_dig = 9; first_dig >= 0; first_dig--)
        {
            cur = first_dig;
            for (int i = 0; i < cnt - 1; i++) cur = cur * 10 + 9;
            if (cur <= n)
            {
                out.println(first_dig + (cnt - 1) * 9);
                return;
            }
        }
    }

    public static void main(String[] args) throws IOException
    {
        new Main().run();
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);
    String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }

    private void run() throws IOException
    {
        solve();
        out.close();
    }

}

Measured memory_bytes: 21332
def line(grad, x, y):
	return [grad, y - grad * x]
 
def intersection(a, b, c, d):
	return [-(b-d)/(a-c), -(b-d)/(a-c)*a+b]
 
n = input()
for i in range(n):
	x1, y1, x2, y2, x3, y3 = map(float, raw_input().split())
	a, b = line(-1 / ((y1 - y2) / (x1 - x2 + 0.000000001) + 0.000000001), (x1 + x2) / 2, (y1 + y2) / 2)
	c, d = line(-1 / ((y3 - y2) / (x3 - x2 + 0.000000001) + 0.000000001), (x3 + x2) / 2, (y3 + y2) / 2)
	px, py = intersection(a, b, c, d)
	print "%.3f %.3f %.3f" % (px, py, ((px - x1)**2 + (py - y1)**2)**0.5)

Measured memory_bytes: 6684
N, K = map(int, input().split())
A = list(map(int, input().split()))
sorted(A)
DP = [-1] * (K+1)
for i in range(K+1):
    if i < A[0]:
        DP[i] = False
    else:
        for j in A:
            if i - j <= 0:
                DP[i] = False
            if not DP[i-j]:
                DP[i] = True
                break
            DP[i] = False
if DP[K]:
    print('First')
else:
    print('Second')


Measured memory_bytes: 44004
while True:
    H, W = map(int, raw_input().split())
    if (H+W) == 0:
        break
    print_dot = "#" + ('.'*(W-2)) + "#"
    print "#"*W
    for h in range(1, (H-1)):
        print print_dot
    print "#"*W
    print ""

Measured memory_bytes: 6324
a = int(input())
b = list(map(int, input().split()))
b.insert(0, 0)
b.append(0)
d = 0
while True:
    for i in range(1, len(b)):
        if b[i] != 0 and b[i-1] == 0:
            for j in range(i, len(b)):
                if b[j] == 0 and b[j-1] != 0:
                    d += 1
                    for k in range(i, j):
                        b[k] -= 1
                    break
    if sum(b) == 0:
        break
print(d)


Measured memory_bytes: 3064
use std::io::*;

fn main() {
    let a = read();
    let b = read();

    if a == b {
        println!("H");
    } else {
        println!("D");
    }
}

// fn read_v() -> Vec<char> {
//     let s = stdin();
//     //    let mut s = BufReader::new(s.lock());
//     let b = s.bytes()
//         .map(|c| c.unwrap() as char)
//         .take_while(|c| !c.is_whitespace())
//         .collect();
//     b
// }

// fn read_t() -> (u32, u32) {
//     let mut s = String::new();
//     stdin().read_line(&mut s).expect("failed read_t");
//     let mut i = s.split_whitespace().map(|c| c.parse().ok().unwrap());
//     (i.next().unwrap(), i.next().unwrap())
// }

fn read() -> char {
    let s = stdin();
    //    let mut s = BufReader::new(s.lock());
    let b = s.bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<Vec<char>>();
    b[0]
    // b.parse().ok().expect("read() failed")
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX 100005
#define mod (int)(1e18+7)
#define sp fixed<<setprecision(12)
using namespace std;

/*
vector<int> primes;
bool is_prime[MAX];
void sieve(){
    is_prime[0]=is_prime[1]=true;
    for(int i=4;i<MAX;i+=2){
        is_prime[i]=true;
    }
    for(int i=3;i*i<MAX;i+=2){
        if(!is_prime[i]){
            for(int j=i*i;j<MAX;j+=i){
                is_prime[j]=true;
            }
        }
    }
    
}

int power(int a,int n,int p){
    int res=1;
    while(n){
        if(n&1){
            res=(res*a)%p;
            n--;
        }else{
            a=(a*a)%p;
            n/=2;
        }
    }
    return res;
}

const int N=(1e4)+7;
vector<int> graph[N];
bool vis[N];
bool col[N];
bool dfs(int cur,int c){
    vis[cur]=1;
    col[cur]=c;
    for(auto x:graph[cur]){
        if(!vis[x]){
            if(dfs(x,c^1)==false)
                return false;
        }else if(col[x]==col[cur]) return false;
    }
    return true;
}
*/

void solve(){
    int n;
    cin>>n;
    if(n%1000==0) cout<<"0\n";
    else{
        cout<<(((n+999)/1000)*1000)-n<<"\n";
    }
}

int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;

    int t=1;
    //cin>>t;
    //int it=1;
    while(t--){
        solve(); 
        //it++;  
    }

    return 0;
    
}

Measured memory_bytes: 3648
import java.util.Scanner;
import java.util.function.Function;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    Scanner sc = new Scanner(System.in);

    void solve() {
        int r, c;
        int[][] input, output;
        r = sc.nextInt();
        c = sc.nextInt();
        input = new int[r][];
        for (int i = 0; i < r; ++i) {
            input[i] = new int[c];
            for (int j = 0; j < c; ++j) {
                input[i][j] = sc.nextInt();
            }
        }

        output = new int[r + 1][c + 1];
        int sum = 0;
        for (int i = 0; i < r; ++i) {
            for (int j = 0; j < c; ++j) {
                output[i][j] = input[i][j];
                sum += input[i][j];
            }
        }

        //h sum
        for (int i = 0; i < r; ++i) {
            int hsum = 0;
            for (int j = 0; j < c; ++j) {
                hsum += output[i][j];
            }
            output[i][c] = hsum;
        }

        //v sum
        for (int j = 0; j < c; ++j) {
            int vsum = 0;
            for (int i = 0; i < r; ++i) {
                vsum += output[i][j];
            }
            output[r][j] = vsum;
        }

        //sum
        output[r][c] = sum;

        for (int i = 0; i <= r; ++i) {
            for (int j = 0; j < c; ++j) {
                System.out.print(output[i][j] + " ");
            }
            System.out.println(output[i][c]);
        }

    }
}


Measured memory_bytes: 41816
import math
a,b,x=map(int,input().split())

if x<=a*a*b/2:
    c=x*2/(a*b)
    theta=math.atan(c/b)
    theta*=360/(2*math.pi)
    theta=90-theta
else:
    c=(b-x/(a*a))*2
    theta=math.atan(c/a)
    theta*=360/(2*math.pi)
print(theta)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forn(i,a,n) for(int i =a;i < n; i++)
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main(){__
	string s,t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	vector<vi> dp(n+1,vi(m+1));
	for(int i = 1; i <=n; i++){
		for(int j =1; j <= m; j++){
			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			if(s[i-1] == t[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
			}
		}
	}
	int i = n, j = m;
	string ans = "";
	while(i != 0 || j != 0){
		if(s[i-1] == t[j-1]){
			ans+= s[i-1];
			i--;
			j--;
		}
		else{
			if(i-1 >= 0 && dp[i-1][j] == dp[i][j]){
				i--;
			}
			else if(j-1 >= 0 && dp[i][j-1] == dp[i][j]){
				j--;
			}
			else{
				assert(0);
			}
		}
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;
}


Measured memory_bytes: 35584
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        ArrayList<Boolean> list = new ArrayList<>();
        long total = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == 'A') {
                list.add(true);
            } else if (arr[i] == 'B' && i < arr.length - 1 && arr[i + 1] == 'C') {
                list.add(false);
                i++;
            } else {
                total += getCount(list);
                list.clear();
            }
        }
        total += getCount(list);
        System.out.println(total);
    }
    
    static long getCount(ArrayList<Boolean> list) {
        int count = 0;
        long sum = 0;
        for (int i = 0; i < list.size(); i++) {
            if (!list.get(i)) {
                sum += i - count;
                count++;
            }
        }
        return sum;
    }
}


Measured memory_bytes: 28324
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

immutable inf = 10L^^16;
alias Edge = Tuple!(int, "to", long, "flow", long, "cap", int, "rev");

void main() {
    int n, m;
    scan(n, m);

    auto adj = new Edge[][](n, 0);

    void addEdge(int u, int v, long cap) {
        adj[u] ~= Edge(v, 0, cap, adj[v].length.to!int);
        adj[v] ~= Edge(u, 0, 0, adj[u].length.to!int - 1);
    }

    foreach (i ; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        addEdge(u, v, c);
    }

    long ans = Dinic(adj, 0, n - 1);

    writeln(ans);
}

long Dinic(Edge[][] adj, int s, int t) {
    int n = adj.length.to!int;
    int[] level = new int[](n);
    int[] prog = new int[](n);
    auto q = Queue!(int)(n);

    bool bfs() {
        level[] = -1;
        level[s] = 0;
        q.clear();
        q.push(s);

        while (!q.empty) {
            auto u = q.front;
            q.pop;

            foreach (e ; adj[u]) {
                if (level[e.to] == -1 && e.cap - e.flow > 0) {
                    level[e.to] = level[u] + 1;
                    q.push(e.to);
                }
            }
        }

        return level[t] != -1;
    }

    long dfs(int u, long f) {
        if (u == t) return f;

        for (; prog[u] < adj[u].length; prog[u]++) {
            auto e = &adj[u][prog[u]];

            if (level[u] + 1 == level[e.to] && e.flow < e.cap) {
                long d = dfs(e.to, min(f, e.cap - e.flow));

                if (d > 0) {
                    e.flow += d;
                    adj[e.to][e.rev].flow -= d;
                    return d;
                }
            }
        }

        return 0;
    }

    long F;

    while (bfs()) {
        prog[] = 0;

        while (true) {
            auto df = dfs(s, inf);

            if (df) F += df;
            else break;
        }
    }

    return F;
}


struct Queue(T) {
    private {
        int N, head, tail;
        T[] data;
    }

    this (int n) {
        N = n + 1;
        data = new T[](N);
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return (tail + 1) % N == head;
    }

    T front() {
        return data[head];
    }

    void push(T x) {
        assert(!full);
        data[tail++] = x;
        tail %= N;
    }

    void pop() {
        assert(!empty);
        head++;
        head %= N;
    }

    void clear() {
        head = tail = 0;
    }
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 2636
#include<bits/stdc++.h>
using namespace std;  
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)  
#define fn1 for( int i =1;i<=n; i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;  
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  IOS;
  int T=1;
  // cin >> T;
  while(T--){
    int n;
    cin >> n;
    string s;
    cin >>s;
    int i =0 ,ans=0, j = s.size()-1;
    while(i<j){
      while(i<j&&s[i]=='R')i++;
      while(i<j&&s[j]=='W')j--;
      if(i<j){
        ans++;
        swap(s[i],s[j]);
      }
    }
    cout <<ans;
  
  
  }
  return 0;
}


Measured memory_bytes: 3772
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

int a[3][110];

ll nl, nm;

int
main(void){  
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, 2) REP(j, n) cin >> a[i][j];

  REP(j, n-1) a[0][j+1] += a[0][j];
  a[1][0] += a[0][0];

  FOR(j, 1, n){
    a[1][j] += max(a[0][j], a[1][j-1]);
  }

  cout << a[1][n-1] << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define true 1
#define false 0
#define MAX 1000000000
typedef long long ll;
typedef unsigned char Uchar; 

int main(void){

int i,j;
ll a,b,c,d;
  
scanf("%lld %lld %lld %lld",&a,&b,&c,&d);

//  printf("%lld,%lld,%lld,%lld",a,b,c,d);
  ll s[5];
  s[0] = a * c;
  s[1] = a * d;
  s[2] = b * c;
  s[3] = b * d;
  
  ll max = s[0];
  for(i=1;i<4;i++){
    if(max < s[i])	max = s[i];
//    printf("%lld,",s[i]);
  }
  
printf("%lld",max);

return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n), S(n+1, 0), X(n+1, 0);
    for (auto &&i : v) scanf("%lld", &i);
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        S[i+1] = S[i] + v[i];
        X[i+1] = X[i] ^ v[i];
    }
    for (int i = 0; i < n; ++i) {
        int ok = i+1, ng = n+1;
        while(abs(ok-ng) > 1){
            int mid = (ok+ng)/2;
            if((S[mid] - S[i]) == (X[mid] ^ X[i])) ok = mid;
            else ng = mid;
        }
        ans += ok - i;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>

using namespace std;

char nums[10]={'0','1','2','3','4','5','6','7','8','9'};
char alphsl[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};



void solve(){
    
    string s;
    cin>>s;
    
    int cnt=0, maxy=0;
    for(int i=0; i<s.length(); i++){
        if(s[i]=='S'){
            
            cnt=0;
            
        }
        else cnt++;
       maxy=max(maxy, cnt);
    }
    cout<<maxy<<endl;
    
}


int main(){
    
    
    solve();
}


Measured memory_bytes: 3592
/**
*    created: 11.07.2020 21:01:47
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int ans = 0;
    rep(i,n) {
        int a;
        cin >> a;
        if ((i+1) % 2 == 1 && a % 2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int N, wc=0;
    cin >> N;
    vector<int> p(N);
    vector<int> cop(N);
    for(int i=0; i<N; i++) {
        cin >> p[i];
    }
    for(int j=0; j<N; j++) {
        cop[j] = j+1;
    }

    for(int i=0; i<N; i++) {
        if(p[i] != cop[i]) wc++;
    }
    if(wc == 2 || wc == 0) cout << "YES" << endl;
    else cout << "NO" << endl; 


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;


void solve(long long A, long double B){
    cout<<ll(A * B)<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long double B;
    scanf("%Lf",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 3832
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    // マージソートとクイックソートの結果を比べる
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}


Measured memory_bytes: 4032
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

bool check[55556];
vector<ll> prime;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    check[0] = true;
    check[1] = true;
    rep(i,55556)rep(j,55556){
        if(i == 1) continue;
        if(j == 1) continue;
        if(i*j > 55555) break;
        check[i*j] = true;
    }
    rep(i,55556) if(check[i] == false && i%10 == 1) prime.pb(i);

    ll N; cin >> N ;
    rep(i,N)cout << prime[i] << " ";
    cout << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;



ll solve(void);
ll gcd(ll x, ll y);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

ll mulmod(ll x, ll y)
{
	return (x * y) % mod;
}

ll submod(ll x, ll y)
{
	return (x - y + 100 * mod) % mod;
}

ll power(ll n, ll r)
{
	if ( r == 0 ) { return 1; }
	if ( r == 1 ) { return n; }
	if ( n == 0 ) { return 0; }
	if ( n == 1 ) { return 1; }

	if (r % 2 == 0)
	{
		ll y = power(n, r/2);
		return mulmod(y, y);
	}
	else
	{
		ll y = power(n, (r-1)/2);
		return n * mulmod(y, y) % mod;
	}
}

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

vector<ll> perm;
vector<ll> inv;
void init_inv(ll m)
{
	perm.resize(m);
	inv.resize(m);
	
	perm[0] = 1;
	inv[0] = 1;

	for (ll i = 1; i < m; i++)
	{
		perm[i] = mulmod(perm[i-1], i);
	}
	
	for (ll i = 1; i < m; i++)
	{
		inv[i] = power(perm[i], mod - 2);
	}
}

ll ncr(ll n, ll r)
{
	// n (n-1) ... (n-r)
	if ( r == n || r == 0 ) { return 1; }

	ll ans = 1;
	//for (ll i = 0; i < r; i++)
	//	ans = mulmod(ans, n - i);

	// return mulmod(ans, inv[r]);
	return mulmod(perm[n], mulmod(inv[n-r], inv[r]));
}

ll solve(void)
{
	ll n, m;
	cin >> n >> m;

	vector<ll> cnt(n, 0);
	vector<bool> isAc(n, false);

	for (ll i = 0; i < m; i++) {
		ll pi;
		string si;
		cin >> pi >> si;
		pi --;

		isAc[pi] = (isAc[pi] | (si[0] == 'A'));
		if(isAc[pi] == false && si[0] == 'W') { cnt[pi] ++; }
	}

	ll ans = 0, accnt = 0;
	for (ll i = 0; i < n; i++) {
		ans += (isAc[i] ? cnt[i] : 0);
		accnt += (isAc[i] ? 1 : 0);
	}


	cout << accnt << " " << ans << endl;

	return 0;
}



Measured memory_bytes: 1024
using System;

namespace _168.B
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            Console.WriteLine(
                s.Length <= k 
                    ? s 
                    : $"{s.Substring(0, k)}...");
        }
    }
}

Measured memory_bytes: 17604
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

ll l, r;

void solve()
{
    ll ans = 2018;
    if(r >= l+2019){
        ans = 0;
    }else{
        l %= 2019;
        r %= 2019;
        FOR(i, l, r+1){
            FOR(j, i+1, r+1){
                ans = min(ans, i*j%2019);
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> l >> r;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	w := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&w[i])
	}
	result := 1
	for i := 1; i < n; i++ {
		if w[i][0] != w[i-1][len(w[i-1])-1] {
			result = 0
		}
		for j := 0; j < i; j++ {
			if w[i] == w[j] {
				result = 0
			}
		}
		if result == 0 {
			break
		}
	}
	if result == 1 {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a+b==15){
    cout << "+" << endl;
  }
  else if(a*b==15){
    cout << "*" << endl;
  }
  else{
    cout << "x" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

#define int long long int 

int32_t main()
{
   int n,m,k;
   cin>>n>>m>>k;
   set<int> s;
   for(int i=0;i<k;i++)
   {
      
      s.insert(n);
      s.insert(m);
      m--;
      n++;
      if(n>m)
      break;
   }  
   for(auto i:s)
   cout<<i<<endl;
}

Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<algorithm>
 
using namespace std;
 
int main(void){
  int h;
  vector<int>hill;
 
  for(int i=0;i<10;i++){
    cin >> h;
    hill.push_back(h);
  }
 
  sort(hill.begin(),hill.end(),greater<int>());
 
  for(int i=0;i<3;i++)
    cout << hill[i] << endl;
 
  return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>
int main(void){
int k,a,b;
  scanf("%d%d%d",&k,&a,&b);
  for(int i=a;i<=b;i++){
	if(i%k==0){printf("OK");
               return 0;
              }
  }
  printf("NG");
  return 0;
}


Measured memory_bytes: 1728
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

int main(){
    for (;;) {
        int n;
        cin >> n;
        if(!n)break;
        int g[n][5];
        for (int i=0; i<n; i++) {
            for (int j=0; j<5; j++) {
                cin >> g[i][j];
            }
        }
        int ans = 0;
        int ansb=-1;
        while (ans != ansb) {
            ansb = ans;
            for (int i=0; i<n; i++) {
                vector<int> hoge(5,0);
                int ch=0;
                for (int j=0; j<3; j++) {
                    for (int k=0;k<j; k++) {
                        hoge[k]=g[i][k];
                    }
                    int p=j;
                    ch=0;
                    while (p+1<=5 and g[i][p]==g[i][p+1]) {
                        ch++;
                        hoge[p]=0;
                        p++;
                    }
                    if (ch<=1) {
                        hoge = {0,0,0,0,0};
                        continue;
                    }
                    if (ch>=2) {
                        if(p<4)hoge[p]=0;
                        for (int k=p+1; k<=5; k++) {
                            hoge[k]=g[i][k];
                        }
                        break;
                    }
                }
                if(ch>=2){
                    for (int j=0; j<5; j++) {
                        ans += g[i][j]-hoge[j];
                        g[i][j]=hoge[j];
                    }
                }
            }
            for (int i=0; i<5; i++) {
                for (int j=n-2; j>=0; j--) {
                    int p = j;
                    while (p+1<n and g[p+1][i]==0) {
                        p++;
                    }
                    if(p==j)continue;
                    if (p==n) {
                        g[p-1][i]=g[j][i];
                        g[j][i]=0;
                    }else{
                        g[p][i]=g[j][i];
                        g[j][i]=0;
                    }
                }
            }
        }
        cout << ans <<endl;
    }
    
    
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;
int a[N], s[N];

int gcd(int x, int y)
{
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}

void solve(int test)
{
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  s[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    s[i] = gcd(a[i], s[i + 1]);
  }
  int g = a[0];
  int ans = s[1];
  for (int i = 1; i < n; ++i) {
    if (i == n - 1) {
      ans = max(ans, g);
    }
    else {
      ans = max(ans, gcd(g, s[i + 1]));
    }
    g = gcd(g, a[i]);
  }
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;
class Main {
  final static int INF = 1001001001;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    // 入力データを変数に格納する
    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int[][] a = new int[12][12];
    int[] c = new int[n];
    for (int i = 0; i < n; i++) {
      c[i] = sc.nextInt();
      for (int j = 0; j < m; j++) {
        a[i][j] = sc.nextInt();
      }
    }
    sc.close();

    // 回答=コストの最小値なので最小値比較のために大きな数値で初期化しておく。
    int ans = INF;

    // 全ての組み合わせパターンをチェックする
    for (int s = 0; s < 1<<n; s++) {
      int cost = 0;         // このs番目の組み合わせのコスト
      int[] d = new int[m]; // このs番目の組み合わせでの各アルゴリズムの理解度

      // ２進数で各ビットが1になっているかどうか調べる
      for (int i = 0; i < n; i++) {

        // 右からi番目のビットが1になっていれば、購入する参考書としてコストとアルゴリズムを加算する
        if ( (s & 1<<i) == 1<<i) {
          // コストを足す
          cost += c[i];

          // 各アルゴリズムの理解度に足す
          for (int j = 0; j < m; j++) {
            d[j] += a[i][j];
          }
        }
      }

      // 全てのアルゴリズムの理解度がxを超えているかチェックする
      boolean ok = true;
      for (int j = 0; j < m; j++) {
        if (d[j] < x) ok = false; // １つでもx未満があれば。
      }
      // チェックOKであれば、そのコストが最小値を更新するかどうか。
      if (ok) ans = Math.min(ans, cost);

    }

    // 全てのアルゴリズムの理解度がxを超えるパターンが１つもない場合はansがINFのままになってる
    if (ans == INF) System.out.println(-1);
    else System.out.println(ans);

  }
}

Measured memory_bytes: 37544
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(m), y(m);
    rep(i,m) {
        cin >> p[i] >> y[i];
        p[i]--;
    }
    vector<vector<int>> vals(n);
    rep(i,m) vals[p[i]].push_back(y[i]);

    rep(i,n) sort(all(vals[i]));
    
    rep(i,m){
        int v = p[i];
        printf("%06d", v+1);
        int id = lower_bound(vals[v].begin(), vals[v].end(), y[i])- vals[v].begin();
        printf("%06d\n", id+1);
    }

}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  int res = 0;
  V<char> cs{'0', '3', '5', '7'};
  for (int i = 0; i < 1 << 20; ++i) {
    string s(10, ' ');
    int t = i;
    for (int j = 0; j < 10; ++j) {
      s[j] = cs[t % 4];
      t /= 4;
    }
    bool f = true;
    if (count(begin(s), end(s), '3') == 0) f = false;
    if (count(begin(s), end(s), '5') == 0) f = false;
    if (count(begin(s), end(s), '7') == 0) f = false;
    for (int j = 0; j < 9; ++j) if (s[j] != '0' and s[j + 1] == '0') f = false;
    if (!f) continue;
    if (stoll(s, nullptr, 10) <= n){
      ++res;
      // cerr << s << '\n';
    }
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
 
int main(){
    string s; cin >> s;
    ll left=-1,right=0;
    rep(i,s.size()){
        if(left == -1 && s[i]=='A') left = i;
        if(s[i]=='Z') right = max(right,i);
    }
    cout << right - left + 1 << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll c[2005][2005];
const int mod = 1e9+7;
void init()
{
  c[0][0] = 1;
  for (int i = 0; i <= 2000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i + 1][j] = (c[i+1][j] + c[i][j]) % mod;
      c[i + 1][j + 1] = (c[i+1][j+1] + c[i][j]) % mod;
    }
  }
}

int main()
{
    int n,k;
    init();
    cin >> n >> k;
    for(int i=1;i<=k;i++){
        ll ans = (c[n-k+1][i] * c[k-1][i-1]) % mod;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 30208
#include<stdio.h>
#include<stdlib.h>
int main(){

  int *S, *T,n,N,C,i,j;
  
  scanf("%d",&n);
  S = (int *)malloc(sizeof(int)*n);
  
  for(i=0; i<=n-1; i++){
    scanf("%d",&S[i]);
  }
  
  scanf("%d",&N);
  T = (int *)malloc(sizeof(int)*N);
  for(i=0; i<=N-1; i++){
    scanf("%d",&T[i]);
  }
  
  C=0;
  
  for(j=0; j<=N-1; j++){
    for(i=0; i<=n-1; i++){
      if(S[i]==T[j]){
	C++;
	break;
      }
    }
  }
  
  printf("%d\n",C);
  
  return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N,x,y;
  cin>>N>>x>>y;
  --x,--y;
  vector<vector<int>> dp(N,vector<int>(N,0));
  for(int i=0;i<N;++i){
    for(int j=i+1;j<N;++j){
      if(j<=x) dp[i][j]=j-i;
      else if(i>=y) dp[i][j]=j-i;
      else if(i<=x && j<=y) dp[i][j]=min(j-i,(x-i)+1+(y-j));
      else if(i<=x && j>y) dp[i][j]=(x-i)+1+(j-y);
      else if(i>x && j<=y) dp[i][j]=min(j-i,(i-x)+1+(y-j));
      else if(i>x && j>y) dp[i][j]=min(j-i,(i-x)+1+(j-y));
    }
  }

  map<int,int> m;
  for(int i=0;i<N;++i){
    for(int j=i+1;j<N;++j){
      ++m[dp[i][j]];
    }
  }
  for(int i=1;i<N;++i) cout<<m[i]<<endl;
}


Measured memory_bytes: 16000