akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18;

int binary_search(long long arr[], int n, long long key) {
  int left = -1;
  int right = n;

  while ( right - left > 1 ) {
    int mid = left + (right - left) / 2;
    if ( arr[mid] >= key ) { right = mid; } else { left = mid; }
  }

  return right;
}

int main() {
  int a, b, q;
  cin >> a >> b >> q;
  long long s[a], t[b], x[q];
  for ( int i = 0; i < a; i++ ) { cin >> s[i]; }
  for ( int i = 0; i < b; i++ ) { cin >> t[i]; }

  while ( q-- > 0 ) {
    long long x;
    cin >> x;
    int s_pos = binary_search(s, a, x);
    int t_pos = binary_search(t, b, x);
    long long ans = INF;
    long long len;
    // right_shrine -> right_temple
    if ( s_pos < a && t_pos < b ) {
      len = abs(x - s[s_pos]) + abs(s[s_pos] - t[t_pos]);
      ans = min(len, ans);
    }
    // right_shrine -> left_temple
    if ( s_pos < a && t_pos-1 >= 0 ) {
      len = abs(x - s[s_pos]) + abs(s[s_pos] - t[t_pos-1]);
      ans = min(len, ans);
    }
    // left_shrine -> right_temple
    if ( s_pos-1 >= 0 && t_pos < b ) {
      len = abs(x - s[s_pos-1]) + abs(s[s_pos-1] - t[t_pos]);
      ans = min(len, ans);
    }
    // left_shrine -> left_temple
    if ( s_pos-1 >= 0 && t_pos-1 >= 0 ) {
      len = abs(x - s[s_pos-1]) + abs(s[s_pos-1] - t[t_pos-1]);
      ans = min(len, ans);
    }
    // right_temple -> right_shrine
    if ( t_pos < b && s_pos < a ) {
      len = abs(x - t[t_pos]) + abs(t[t_pos] - s[s_pos]);
      ans = min(len, ans);
    }
    // right_temple -> left_shrine
    if ( t_pos < b && s_pos-1 >= 0 ) {
      len = abs(x - t[t_pos]) + abs(t[t_pos] - s[s_pos-1]);
      ans = min(len, ans);
    }
    // left_temple -> right_shrine
    if ( t_pos-1 >= 0 && s_pos < a ) {
      len = abs(x - t[t_pos-1]) + abs(t[t_pos-1] - s[s_pos]);
      ans = min(len, ans);
    }
    // left_temple -> left_shrine
    if ( t_pos-1 >= 0 && s_pos-1 >= 0 ) {
      len = abs(x - t[t_pos-1]) + abs(t[t_pos-1] - s[s_pos-1]);
      ans = min(len, ans);
    }
    cout << ans << endl;
  }

  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 55;
int p[N];

int find(int v){
	return (p[v] == -1)?v:(p[v] = find(p[v]));
}

bool combine(int u, int v){
	u = find(u);
	v = find(v);
	if(u == v)return false;
	p[v] = u;
	return true;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m;
	cin>>n>>m;
	vector<int> a(m), b(m);
	for(int i = 0; i < m; i++){
		cin>>a[i]>>b[i];
	}
	int ans = 0;
	for(int i = 0; i < m; i++){
		memset(p, -1, sizeof(p));
		int cnt = 0;
		for(int j = 0; j < m; j++){
			if(i == j)continue;
			if(combine(a[j], b[j]))cnt++;
		}
		if(cnt + 1 != n)ans++;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int func(string s, string t){

	int ans = 0;
	for(char c='a';c<='z';++c){
		bool founds = false, foundt=false;
		REP(i,s.length()){
			if(s[i] == c) founds = true;
		}
		REP(i,t.length()){
			if(t[i] == c) foundt = true;
		}
		if(founds and foundt) ans++;
	}

	return ans;

}


int main(void){

	
	int N; cin >> N;
	string S; cin >> S;

	int ans = 0;
	for(int i=0;i<=N;++i){
		int tmp = func(S.substr(0,i), S.substr(i));
		ans = max(ans, tmp);
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
//C - Traveling Salesman around Lake

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int k, n;

    cin >> k >> n;

    int a[n];
    int dist[n];
    
    for(int i=0; i<n; i++){
        cin >> a[i];
    }


    for(int i=0; i<n-1; i++){
        dist[i] = a[i+1] - a[i];
    }

    dist[n-1] = k - a[n-1] + a[0];

    int maxDist = 0;
    for(int i=0; i<n; i++){
        if (maxDist < dist[i]) maxDist = dist[i];
    }

    bool flag = false;
    long long ans = 0;
    for(int i=0; i<n; i++){
        if ((dist[i] == maxDist) && (flag == false)) {
            flag = true;
        }else{
            ans += dist[i];
        }
    }
    

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
using namespace std;
const int N=100005;
const int MOD=998244353;
int n;
int d[N];
int cnt[N];
long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD,b>>=1;
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&d[i]);
		cnt[d[i]]++;
	}
	if(cnt[0]!=1||d[1]!=0)
	{
		printf("0");
		return 0;
	}
	long long ans=1;
	for(int i=1;i<=n-1;i++)
	{
		if(cnt[i]&&!cnt[i-1])
		{
			printf("0");
			return 0;
		}
		ans=ans*ksm(cnt[i-1],cnt[i])%MOD;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4524
use std::collections::*;

const MOD: i64 = 1000_000_007;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn dfs(s: i64, x: i64, memo: &mut HashMap<i64, HashMap<i64, i64>>) -> i64 {
    if s == 0 {
        return 1;
    }
    if memo.contains_key(&s) && memo[&s].contains_key(&x) {
        return memo[&s][&x];
    }
    let mut ret = dfs(s / 2, x / 2, memo);
    ret += dfs((s - 1) / 2, (x - 1) / 2, memo);
    ret %= MOD;
    if s >= 2 {
        ret += dfs((s - 2) / 2, x / 2, memo);
        ret %= MOD;
    }
    if !memo.contains_key(&s) {
        memo.insert(s, HashMap::new());
    }
    memo.get_mut(&s).unwrap().insert(x, ret);
    ret
}

fn main() {
    let n = read::<i64>();
    let mut memo = HashMap::new();
    println!("{}", dfs(n, n, &mut memo));
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  int odd = 0;
  int four = 0;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    if(a % 2 == 1)odd++;
    else if(a % 4 == 0)four++;
  }
  if((n == odd + four && odd <= four + 1) || (odd <= four))cout << "Yes" << endl;
  else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 4011
#define mod 1000000007

int n, m, k, i, j, cf, NN, MM;
ll dp[maxN][maxN], ans;
bool ok = true;


int main()
{
  //  freopen("test.in","r",stdin);

    scanf("%d%d%d", &n, &m, &k);

    dp[0][0] = 1;
    for (i = 0; ok; i++) {
        ok = false;

        for (j = 0; j <= i * (k - 1); j++) {
            if (dp[i][j] == 0) continue;
            dp[i][j] %= mod;
            ok = true;

            for (cf = 0; cf < k; cf++) {
                NN = j + cf;
                MM = i * (k - 1) - j + (k - 1 - cf);

                if (NN > n || MM > m - 1) continue;
                dp[i + 1][NN] += dp[i][j];
                if (NN % (k - 1) == n % (k - 1))
                    if (MM % (k - 1) == (m - 1) % (k - 1))
                        if (cf != 0)
                            ans = (ans + dp[i][j]) % mod;
            }
        }
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 47488
#include<stdio.h>

const int INF = 1001001001;

char choco[10][1000];
int cnt[10][1000] = {0};
int now[10] = {0};

void now_refresh(int g){
	int i;

	for(i=0; i<g; i++){
		now[i] = 0;
	}
}

int add(int g, int j, int k){
	int i;

	for(i=0; i<g; i++){
		now[i] += cnt[i][j];
	}
	for(i=0; i<g; i++){
		if(now[i] > k){
			return 0;
		}
	}

	return 1;
}

int main(){
	int h, w, k;
	int i, j;
	int div;
	int ans = INF;

	scanf("%d %d %d", &h, &w, &k);
	for(i=0; i<h; i++){
		scanf("%s", choco[i]);
	}

	for(div=0; div<(1<<(h-1)); div++){
		int g = 0;
		int id[10] = {0};
		for(i=0; i<h; i++){
			id[i] = g;
			if(div>>i & 1){
				++g;
			}
		}
		++g;

		for(i=0; i<g; i++){
			for(j=0; j<w; j++){
				cnt[i][j] = 0;
			}
		}

		/* 横方向に分割した後の各列のホワイトチョコレートの数 */
		for(i=0; i<h; i++){
			for(j=0; j<w; j++){
				cnt[id[i]][j] += (int)(choco[i][j] - '0');
			}
		}
		int ok = 1;
		for(i=0; i<g; i++){
			for(j=0; j<w; j++){
				if(cnt[i][j] > k){
					ok = 0;
				}
			}
		}
		if(!ok){
			continue;
		}

		int num = g-1;
		now_refresh(g);
		for(j=0; j<w; j++){
			if(!add(g, j, k)){
				num++;
				now_refresh(g);
				add(g, j, k);
			}
		}

		ans = (num < ans) ? num : ans;
	}

	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_left


def comb(n, k):
    if n < 0 or n < k or k < 0:
        return 0
    return fac[n] * ifac[k] * ifac[n - k] % mod


n, k, *a = map(int, read().split())
a.sort()
mod = 10 ** 9 + 7
max_n = 2 * 10 ** 5 + 1
ans = 0
fac = [1] * max_n
inv = [1] * max_n
ifac = [1] * max_n
for i in range(2, max_n):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    ifac[i] = ifac[i - 1] * inv[i] % mod
for i, aa in enumerate(a):
    ans += aa * (comb(i, k - 1) - comb(n - 1 - i, k - 1))
    ans %= mod
print(ans)


Measured memory_bytes: 31248
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
cnt = defaultdict(int)

for i in range(n):
    cnt[a[i]] += 1
flag = True

if 0 in cnt.keys():
    del cnt[0]

for i in range(n - 1, 0, -2):
    if cnt[i] != 2:
        flag = False
        break 
print((2 ** (n // 2)) % (10 ** 9 + 7) if flag else 0)

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

int main(){
    int a, b;
    cin >> a >> b;
    
    if(a > b) cout << "a > b" << endl;
    else if(a < b) cout << "a < b" << endl;
    else cout << "a == b" << endl;
    
    return 0;
}


Measured memory_bytes: 3056
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int main()
{
    int n,h,w;
    cin >> h >> w;
    cin >> n;
    vector<P> a;
    rep(i,n){
        int in;
        cin >> in;
        a.pb(mp(in,i+1));
    }
    sort(all(a));

    vector<vector<int> > outputs;
    vi output;
    rep(i,n){
        int loop = a[i].fi;
        rep(l,loop){
            if((int)output.size() == w){
                outputs.pb(output);
                output.clear();
            }
            output.pb(a[i].se);
        }
    }
    outputs.pb(output);

    rep(i, (int)outputs.size()){
        if(i%2 == 1) reverse(all(outputs[i]));
        rep(j, (int)outputs[i].size()){
            cout << outputs[i][j];
            if(j != outputs[i].size()-1) cout << " ";
            else cout << endl;
        }
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)

void solve(long long N, long long R)
{
  if (N >= 10)
  {
    cout << R << endl;
  }
  else
  {
    cout << R + 100 * (10 - N) << endl;
  }
}

int main()
{
  long long N;
  scanf("%lld", &N);
  long long R;
  scanf("%lld", &R);
  solve(N, R);
  return 0;
}


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

//省略形
#define rep(i,n) for(auto i=0; i<n ; ++i)
#define REP(i,a,b) for(auto i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//よく使う定数
const int INF = 1e9;
const int MOD = 1e9+7;
//逆元
const int INV = 1e9+5;

//UnionFindTree
struct union_find{
  vector<int> data;
  union_find(int size) : data(size , -1) { }

  void merge(int x , int y){
    x = root(x); y = root(y);
    if(x == y) return;
    if(data[y] < data[x]) swap(x , y);
    data[x] += data[y];
    data[y] = x;
    return; 
  }

  bool same(int x , int y){
    x = root(x) , y = root(y);
    return x == y;
  }

  int root(int x){
    return data[x] < 0 ? x : (data[x] = root(data[x]));
  }

  int size(int x){
    return -data[root(x)];
  }
};

//プロトタイプ宣言
void faster(void);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);
template <class T>
T modpow(T , T , T);

//メモ
//最大公約数:__gcd　|　最小公倍数:__lcm


int main(){
  faster();
  int a,b;
  cin >> a >> b;
  for(int i=1;i<1251;i++){
    if((int)(i*0.08)==a && (int)(i*0.1)==b){
      cout << i;
      return 0;
    }
  }
  cout << -1;
}


























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//繰り返し自乗法
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 

//繰り返し自乗法(剰余)
template <class T>
T modpow(T x , T y , T mod){
  if(y == 0) return 1;
  if(y%2 == 1){
    ll temp = modpow(x,y-1,mod);
    return temp*x%mod;
  }
  else{
    ll temp = pow_mod(x,y/2,mod);
    return temp*temp%mod;
  }
}



Measured memory_bytes: 256
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))

class BITmax:
  ini = 0
  def __init__(s, num):
    s.N = 1
    while s.N <= num:
      s.N *= 2
    s.T = [s.ini] * s.N
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, t, x):
    k = t
    s.T[k - 1] = max(s.T[k - 1], x)
    k += k & -k
    while k <= s.N:
      s.T[k - 1] = max(s.T[k - 1], x)
      k += k & -k
  def getV(s, x):
    ans = s.T[x - 1]
    x -= x & -x
    while x != 0:
      ans = max(ans, s.T[x - 1])
      x -= x & -x
    return ans

class BITmin:
  ini = N
  def __init__(s, num):
    s.N = 1
    while s.N <= num:
      s.N *= 2
    s.T = [s.ini] * s.N
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, t, x):
    k = t
    s.T[k - 1] = min(s.T[k - 1], x)
    k += k & -k
    while k <= s.N:
      s.T[k - 1] = min(s.T[k - 1], x)
      k += k & -k
  def getV(s, x):
    ans = s.T[x - 1]
    x -= x & -x
    while x != 0:
      ans = min(ans, s.T[x - 1])
      x -= x & -x
    return ans

MA = BITmax(N)
MI = BITmin(N)

La = [0] * N
Li = [0] * N

for i in range(K - 1):
  t = N - i
  MA.update(t, P[t - 1])
  MI.update(t, P[t - 1])
for i in range(K - 2, N):
  t = N - i
  MA.update(t, P[t - 1])
  MI.update(t, P[t - 1])
  La[t - 1] = MA.getV(t + K - 2)
  Li[t - 1] = MI.getV(t + K - 2)

T = [0] * N
cnt = 0
t = 0
for i in range(1, N):
  if P[i] > P[i - 1]:
    cnt += 1
    if cnt >= K - 1:
      T[i - K + 1] = 1
      t += 1
  else:
    cnt = 0

if t != 0:
  t -= 1

for i in range(N - K):
  if T[i] == 1:
    continue
  if Li[i + 1] > P[i] and La[i + 1] < P[i + K]:
    t += 1

print(N - K - t + 1)

Measured memory_bytes: 96716
def insertionSort(A):
    for i in range(1,len(A)):
        print(" ".join([str(i) for i in A]))
        tmp = A[i]
        j = i-1
        while j >= 0 and A[j] > tmp:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = tmp


n = int(input())
a = [int(i) for i in input().split()]


insertionSort(a)
print(" ".join([str(i) for i in a]))



Measured memory_bytes: 5608
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    if (N % 10 == 3)
    {
        cout << "bon" << endl;
    }
    else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8)
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{

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

		//１つ目はすごろくのマス
		int masu = sc.nextInt();

		//マス分の数字を取得
		List<Integer> masuList = new ArrayList<Integer>();
		for(int i=0; i<masu; i++) {
			masuList.add(sc.nextInt());
		}

		//出た目リスト作成
		List<Integer> meList = new ArrayList<Integer>();
		int memory = 0;
		for(int k=0; k<masu; k++) {
			memory++;

			//0でリストに入れる
			if(masuList.get(k) == 0) {
				meList.add(memory);
				memory = 0;
			}else if(k == masu -1) {//最後の処理
				meList.add(memory+1);
			}
		}

		//一番大きい数字を取り出す
		int ret = 0;
		for(int l=0; l<meList.size(); l++) {
			if(ret<meList.get(l)) {
				ret = meList.get(l);
			}
		}

		//結果出力
		System.out.println(ret);//スタートマスをプラス
		sc.close();
	}
}


Measured memory_bytes: 26340
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    map<int, int> A, B;
    
    rep(i, N){
        int a;
        cin >> a;
        A[a]++;
    }
    int M;
    
    cin >> M;
    vector<int> BB(M);
    rep(i, M){
        int b;
        cin >> b;
        B[b]++;
        BB[i] = b;
    }
    
    rep(i, M){
        if(B[BB[i]] > A[BB[i]]){
            output("NO");
            return 0;
        }
    }
    output("YES");
    
    
    return 0;
}


Measured memory_bytes: 19840
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

long long int graph[2500][2500];

int main()
{
	int n, m, p;
	cin >> n >> m >> p;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(i == j) continue;
			graph[i][j] = mod;
		}
	}

	vector<pair<pair<int, int>, int> > v;
	for(int i = 0; i < m; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		c -= p;
		c = -c;
		v.push_back(make_pair(make_pair(a, b), c));
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			int a = (v[j].first).first;
			int b = (v[j].first).second;
			int c = v[j].second;
			if(graph[0][a] != mod) graph[0][b] = min(graph[0][b], graph[0][a] + c);
		}
	}

	vector<bool> negative(n, false);

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			int a = (v[j].first).first;
			int b = (v[j].first).second;
			int c = v[j].second;
			if(graph[0][a] == mod) continue;
			if(graph[0][b] > graph[0][a] + c){
				graph[0][b] = graph[0][a] + c;
				negative[b] = true;
			}
			if(negative[a]) negative[b] = true;
		}
	}

	if(negative[n - 1]) cout << -1 << endl;
	else if(graph[0][n - 1] > 0) cout << 0 << endl;
	else cout << -graph[0][n - 1] << endl;
}

Measured memory_bytes: 49280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll n, k;
    cin >> n >> k;
    VL a(n);
    rep(i, 0, n) {
        cin >> a[i];
    }
    ll l = 0, r = 1e9+1;
    while(r - l > 1){
        ll m = l + (r - l) / 2;
        ll cnt = 0;
        bool f = true;
        rep(i, 0, n){
            if(a[i] < m) ;
            else if(a[i] % m == 0) cnt += a[i] / m - 1;
            else cnt += a[i] / m;
        }
        if(cnt <= k) r = m;
        else l = m;
        //cerr << m << cnt << endl;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 4788
X, N = map(int,input().split())

nyuryoku = []

try:
    while True:
        p = list(map(int,input().split()))
        if p == '':
            break
        nyuryoku.append(p)

except EOFError:
    pass

# for p in nyuryoku:
#     print(p)

# p = list(map(int,input().split()))
# print(X)
# print(p)

L = []
for i in range(1, 100):
    for j in ['-', '']:
        # print(j, i)
        a = (j + str(i))
        # print(int(a))
        L.append(a)
# print(L)

if N == 0:
    print(X)
elif X not in p:
    print(X)
else:
    for i in L:
        if (X + int(i)) not in p:
            print(X + int(i))
            break

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

long long gcd(long long a,long long b){
    a=std::abs(a);
    b=std::abs(b);
    if(a>b)std::swap(a,b);
    if(a==0){
        return b;
    }
    
    long long r=a%b;
    while(r){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

signed main(void){
    int T;
    cin >> T;
    REP(_,T){
        int A,B,C,D;
        cin >> A >> B >> C >> D;
        if(A<B){cout << "No" << endl;continue;}
        if(D<B){cout << "No" << endl;continue;}
        if(C>=B){cout << "Yes" << endl;continue;}
        int g = gcd(B,D);
        int h = B - g + (A%g);
        if(h>C){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(obj) (obj).begin(), (obj).end()

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++){
    cin >> A[i]; 
  }
  sort(ALL(A));
  int intMax = 10E6+1;
  vector<bool> hyo(intMax, true);

  for (int i=0; i<N; i++){
    if(i>0){
      if(A[i] == A[i-1]){
        hyo[A[i]] = false;
      }
    }
    if(hyo[A[i]]){
      for (int j=2; j*A[i]<=intMax; j++){
        hyo[j*A[i]] = false;
      }
    }
  }
  int count = 0;
  for(int i=0; i<N; i++){
    if(hyo[A[i]] == true) count++;
  }

  cout << count << endl;
  // int count = 0;
  // while ((int)A.size() != 0){
  //   if((int)A.size() == 1){
  //     count++;
  //   }else if(A[0] != A[1]){
  //     count++;
  //   }
  //   for (int i=(int)A.size()-1; i>=0; i--){
  //     if(A[i]%A[0] == 0){
  //       A.erase(A.begin() + i);
  //     }
  //   }
  //   //for(auto a: A){
  //   //  cout << a << " ";
  //   //}
  //   //cout <<count << endl;
  // }

  // cout << count << endl;

}


Measured memory_bytes: 5312
#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int cnt[2][4] = {};
  double v[2];
  while (cin >> v[0] >> v[1]) {
    for (int i = 0; i < 2; i++) {
      if (v[i] >= 1.1) cnt[i][0]++;
      else if (v[i] >= 0.6) cnt[i][1]++;
      else if (v[i] >= 0.2) cnt[i][2]++;
      else cnt[i][3]++;
    }
  }

  for (int i = 0; i < 4; i++) {
    cout << cnt[0][i] << " " << cnt[1][i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <map>
using namespace std;

map<int, int> ma,mb;

int main(){
	int n,m,d[200001],t[200001];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>d[i];
		ma[d[i]]++;
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>t[i];
		mb[t[i]]++;
	}
	for(int i=0;i<m;i++){
		int x=t[i];
		if(mb[x]>ma[x]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 20608
from itertools import groupby, chain, islice
 
def pairs(t):
    a = True
    while a:
        a =[sum(1 for _ in g) for k, g in islice(t, 2)]
        if a:
            yield sum(x * (x - 1) // 2 for x in a) + max(a)
 
s = input()
t = groupby(s)
d = [(0, ())]
if s[0] == '>':
    t = chain(d, t)
if s[-1] == '<':
    t = chain(t, d)
print(sum(pairs(t)))


Measured memory_bytes: 4468
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int a, b, c, d;
	scanf("%1d%1d%1d%1d", &a, &b, &c, &d);
	if(a + b + c + d == 7)
	{
		printf("%d+%d+%d+%d=7\n", a, b, c, d);
		goto end;
	}
	if(a - b - c - d == 7)
	{
		printf("%d-%d-%d-%d=7\n", a, b, c, d);
		goto end;
	}

	if(a + b - c - d == 7)
	{
		printf("%d+%d-%d-%d=7\n", a, b, c, d);
		goto end;
	}
	if(a - b + c - d == 7)
	{
		printf("%d-%d+%d-%d=7\n", a, b, c, d);
		goto end;
	}
	if(a - b - c + d == 7)
	{
		printf("%d-%d-%d+%d=7\n", a, b, c, d);
		goto end;
	}
	if(a + b + c - d == 7)
	{
		printf("%d+%d+%d-%d=7\n", a, b, c, d);
		goto end;
	}
	if(a - b + c + d == 7)
	{
		printf("%d-%d+%d+%d=7\n", a, b, c, d);
		goto end;
	}
	if(a + b - c + d == 7)
	{
		printf("%d+%d-%d+%d=7\n", a, b, c, d);
		goto end;
	}
end:;
}

Measured memory_bytes: 128
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
# f=[0for _ in range(k+1)]
# for i in range(k+1):
#     for j in range(n):
#         f[i]+=a[j]^i
# f.sort(key=lambda x:-x)
a.sort(key=lambda x:-x)
powSize=math.ceil(math.log(k+1)/math.log(2))
digitCnt=[0for _ in range(powSize)]
for i in range(n):
    for j in range(powSize):
        if ( a[i]&(1<<j) )>0:
            digitCnt[j]+=1
ansNum=[0]
for i in range(powSize-1,-1,-1):
    if 2*digitCnt[i]<n: # digitCnt[i]<n-digitCnt[i]
        for j in range(len(ansNum)):
            ansNum[j]+=(1<<i)
            if ansNum[j]>k:
                if ( ansNum[j]&(1<<(i+1)) )>0:
                    ansNum.append(ansNum[j]-(1<<(i+1)))
                ansNum[j]-=(1<<i)
    # print(i,ansNum)

# ansNum=[0for _ in range(powSize)]
# for i in range(powSize):
#     ansNum[i]=( k&(((1<<powSize)-1)<<(i+1)) )
#     for j in range(i):
#         if 2*digitCnt[j]<n:
#             ansNum[i]+=(1<<j)

ans=[0for _ in range(len(ansNum))]
for i in range(n):
    for j in range(len(ansNum)):
        if ansNum[j]<=k:
            ans[j]+=(a[i]^ansNum[j])
# print(a[0],powSize)
# print(digitCnt)
# print(ansNum,ans)
ans.sort(key=lambda x:-x)
print(ans[0])


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

int main(){
  int n,x,X;
  cin>>n>>x;
  vector<long> k(n);
  for(int i=0;i<n;i++){
    cin>>X;
    if (X-x<0){
      k[i] = -(X-x);
    }else{
      k[i] = X-x;
    }
  }
  long f=k[0];
  for(int i=0;i<n-1;i++){
    f = __gcd(f,k[i+1]);
  }
  cout<<f<<endl;
  return 0;
}


Measured memory_bytes: 1024
N = int(input()) 
ans=''
for i in range(1, 99):
    if N <= 26 ** i:
        N -= 1
        #print(i)
        for j in range(i):
            ans += chr(ord('a') + N % 26) 
            N //= 26      
        break 
    else:
        #print('sideB', N)
        N -= 26 ** i 
print(ans[::-1]) # reversed

Measured memory_bytes: 9140
import collections

N = int(input())
nlist = []
for i in range(N):
    nlist.append(input())

M = int(input())
mlist = []
for i in range(M):
    mlist.append(input())

for i in mlist:
    if i in nlist:
        nlist.remove(i)

nlist = collections.Counter(nlist).most_common()

if nlist==[]:
    print(0)
    exit()

print(nlist[0][1])

Measured memory_bytes: 65512
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[366][5],d,f,g,h,i,j;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		for(j=0;j<4;j++)
			scanf("%d",&s[i][j]);
		d=s[i][0]*s[i][2]+s[i][1]*s[i][3];
		if(s[i][2]<5) f=5;
		else f=s[i][2];
		if(s[i][3]<2) g=2;
		else g=s[i][3];
		if(d>(s[i][0]*f+s[i][1]*g)*0.8)	d=(s[i][0]*f+s[i][1]*g)*0.8;
		printf("%d\n",d);
	}
	return 0;
}

Measured memory_bytes: 2740
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 998244353
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

int t, n, dp[4][220]; string s;
ll A[220];

int solve() {
  cin>>n;
  rep(i,n) cin>>A[i];
  cin>>s;

  const int nbits = 60;
  vector<ll> basis(nbits);

  for(int i = n-1;i >= 0;i--) {
    rep(j, nbits) {
      if((A[i] & (1LL << j)) == 0) continue;
      if(basis[j] == 0) {
        if(s[i] == '0') {
          basis[j] = A[i];break;
        }
        return 1;
      }
      A[i] ^= basis[j];
    }
  }

  return 0;
}

int main() {

 //freopen("input.in","r",stdin);
 //freopen("output.out","w",stdout);

  cin>>t;
  while(t--) {
    cout << solve() << endl;
  }

  return 0;
}


Measured memory_bytes: 3556
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値配列用 integer ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        int n = Integer.parseInt(br.readLine().trim());
        int oldx = 0;
        int oldey = 0;
        int oldt = 0;
        for (int i=0;i<n;i++){
            int [] inputval = inputval();
            int t = inputval[0] - oldt;
            int x = inputval[1];
            int y = inputval[2];
            int dist = Math.abs(x-oldx)+Math.abs(y-oldey);
            if (dist > t || (t-dist) % 2 !=0){
                System.out.println("No");
                return;
            }
            oldx = x;
            oldey = y;
            oldt = inputval[0];

        }

        System.out.println("Yes");
    }

}



Measured memory_bytes: 46400
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n: i32 = read_as_vec()[0];
    let a = read_as_string();
    let b = read_as_string();
    let c = read_as_string();
    let mut counter = 0;
    for ((ac, bc), cc) in
        a.chars().zip(b.chars()).zip(c.chars()){
            if ac == bc && bc != cc{
                counter += 1;
            }else if bc == cc && ac != bc{
                counter += 1;
            }else if ac == cc && bc != cc{
                counter += 1;
            }else if ac != bc && bc != cc && ac != cc{
                counter +=2;
            }
        }

    println!("{}", counter);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  rep(i,M)
    cin >> L.at(i) >> R.at(i);
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  if(L.at(M-1)>R.at(0))
    cout << "0" << endl;
  else
    cout << R.at(0)-L.at(M-1)+1 << endl;

}


Measured memory_bytes: 1024
x1,y1,x2,y2=map(int,input().split(" "))
tei=x2-x1
taka=y2-y1
x3=x2-taka
y3=y2+tei
x4=x3-tei
y4=y3-taka
print(x3,y3,x4,y4)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    int ans = 0;
    int next = 1;
    rep(i, n)
    {
        if (a[i] == next)
        {
            ans++;
            next++;
        }
    }
    if (next == 1)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << n - ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{

// }}}


signed main()
{
    i64 L, R;
    cin >> L >> R;

    i64 ans = LINF;

    const i64 lll = L % 2019;

    for (i64 i = L; i <= R; ++i) {
        i64 x = i % 2019;
        if (i != L && x == lll) break;
        for (i64 j = i+1; j <= R; ++j) {
            i64 y = j % 2019;
            if (j != L && y == lll) break;

            chmin(ans, x * y % 2019);
        }
    }

    cout << (ans) << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	cnta := 0
	for i :=0 ;i<len(s); i++ {
		if string(s[i]) == "1" {
			cnta++
		}
	}
	if len(s)-cnta >= cnta {
		fmt.Println(2*cnta)
	} else if len(s)-cnta < cnta {
		fmt.Println(2*(len(s)-cnta))
	}
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
typedef unsigned int UINT;
using namespace std;

void Buy(int & have, const int a)
{
    have -= a;
}

void BuyAsAble(int & have, const int a)
{
    int count = have / a;
    Buy(have, count*a);
}

int main(void) {
    int X, A, B;
    cin >> X >> A >> B;
    Buy(X, A);
    BuyAsAble(X, B);
    cout << X << endl;
    return 0;
    }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int a, b;

    while (true) {
      a = scanner.nextInt();
      b = scanner.nextInt();
      if (a == 0 && b == 0) break;
      for (int i = 0; i < a; ++i) {
        for (int j = 0; j < b; ++j) System.out.printf("#");
        System.out.println();
      }
      System.out.println();
    }
  }
}


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

typedef struct Node {
  int x;
  struct Node *prev;
  struct Node *next;
} Node;

Node *head, *tail;

void dump() {
  int l = 0;
  Node *p = head;
  while (p != NULL) {
    if (l == 0)  printf("%d",  p->x);
    else printf(" %d", p->x);
    ++l;
    p = p->next;
  }
  printf("\n");
}

void insert(int x) {
  Node *nod = malloc(sizeof(Node));;
  nod->x = x;
  nod->prev = NULL;
  nod->next = NULL;

  if (head == NULL) {
    head = nod;
    tail = nod;
  } else {
    nod->next = head;
    head->prev = nod;
    head = nod;
  }
}

void delete(int x) {
  Node *p = head;
  int flg = 0;

  while (flg == 0 && p != NULL) {
    if (p->x == x) {
      Node *c = p;
      if (c->prev != NULL) {
        p->prev->next = c->next;
      } else {
        head = c->next;
      }

      if (c->next != NULL) {
        p->next->prev = c->prev;
      } else {
        tail = c->prev;
      }
      flg = 1;
    } else {
      p = p->next;
    }
  }
}

void deleteFirst() {
  if (head == tail) {
    head = NULL;
    tail = NULL;
  } else if (head != NULL) {
    if (head->next != NULL) head->next->prev = NULL;
    head = head->next;
  }
}

void deleteLast() {
  if (head == tail) {
    head = NULL;
    tail = NULL;
  } else if (tail != NULL) {
    if (tail->prev != NULL) tail->prev->next = NULL;
    tail = tail->prev;
  }
}

int main(int argc, char **argv) {

  int n;
  scanf("%d\n", &n);

  int i;
  int x;
  char buf[256];
  char tmp[256];
  for (i = 0; i < n; ++i) {
    fgets(buf, 256, stdin);

    if (buf[0] == 'i' || buf[6] == ' ') {
      sscanf(buf, "%s %d", tmp, &x);

      if (buf[0] == 'i') insert(x);
      else               delete(x);
    } else if (buf[6] == 'F') {
      deleteFirst();
    } else if (buf[6] == 'L') {
      deleteLast();
    }
  }

  dump();

  return 0;
}



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

struct Dinic {
  struct Edge{ int to, cap, rev; };
  int n, init;
  vector<vector<Edge>> g;
  vector<int> itr, level;

  Dinic() {}
  Dinic(int n, int INF = 1e9) : n(n), g(n), init(INF) {}

  void addEdge(int u, int v, int c) {
    int szU = g[u].size();
    int szV = g[v].size();
    g[u].push_back({v, c, szV});
    g[v].push_back({u, 0, szU - 1});
  }
  void bfs(int s) {
    level = vector<int>(n, -1);
    queue<int, deque<int>> que({s});
    level[s] = 0;
    while (!que.empty()) {
      int u = que.front(); que.pop();
      for (auto&& e : g[u]) {
        int v = e.to;
        if (level[v] < 0 && e.cap > 0) {
          level[v] = level[u] + 1;
          que.push(v);
        }
      }
    }
  }
  int dfs(int u, int t, int c) {
    if (u == t) return c;
    for (int& i = itr[u]; i < g[u].size(); ++i) {
      Edge& e = g[u][i];
      int v = e.to;
      if (level[u] < level[v] && e.cap > 0) {
        int f = dfs(v, t, min(c, e.cap));
        if (f > 0) {
          e.cap -= f;
          g[v][e.rev].cap += f;
          return f;
        }
      }
    }
    return 0;
  }
  int build(int s, int t) {
    int flow = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0) break;
      itr = vector<int>(n, 0);
      int f;
      while ((f = dfs(s, t, init)) > 0) flow += f;
    }
    return flow;
  }
};

int main() {
  int n0, n1, m; cin >> n0 >> n1 >> m;
  int n = n0 + n1;
  int s = n, t = s + 1;
  Dinic f(n + 2);
  for (int i = 0; i < n0; ++i) f.addEdge(s, i, 1);
  for (int i = 0; i < n1; ++i) f.addEdge(n0 + i, t, 1);
  while (m--) {
    int x, y; cin >> x >> y;
    f.addEdge(x, n0 + y, 1);
  }
  cout << f.build(s, t) << endl;
  return 0;
}



Measured memory_bytes: 3268
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
using namespace std;

int main() {
  int n, a;
  cin >> n >> a;
  int ans = n*n - a;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int m = sc.NextInt();
        int[] a = sc.IntArray();
        long sum = 0;
        for (int i = 0; i < m; i++)
        {
            sum += a[i];
        }

        if (n >= sum)
        {
            Console.WriteLine(n - sum);
        }
        else
        {
            Console.WriteLine("-1");
        }
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 29288
n = gets.to_i

puts 0
$stdout.flush
l_seat = gets.chomp
l = 0
r = n

20.times do
  mid = (l + r) / 2

  puts mid
  $stdout.flush
  mid_seat = gets.chomp
  exit if mid_seat == 'Vacant'

  if (mid - l).even? ^ (l_seat != mid_seat)
    l = mid
    l_seat = mid_seat
  else
    r = mid + 1
  end
end


Measured memory_bytes: 14272
public class Main {
    public static void main(String[] args) {

        java.util.Scanner sc = new java.util.Scanner(System.in);
        int n = sc.nextInt();

        int taro_point = 0, hanako_point = 0;
        String taro_card, hanako_card;
        for (int i = 0; i < n; i ++) {
            taro_card = sc.next();
            hanako_card = sc.next();
            if (taro_card.compareToIgnoreCase(hanako_card) > 0) { taro_point += 3; }
            if (taro_card.compareToIgnoreCase(hanako_card) == 0) { hanako_point ++; taro_point ++; }
            if (taro_card.compareToIgnoreCase(hanako_card) < 0) { hanako_point += 3; }
        }
        System.out.println(taro_point + " " + hanako_point);
    }
}

Measured memory_bytes: 30036
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int n;
pii a[111111],b[111111];

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	n=read();
	FOR(i,0,111111){
		a[i]=b[i]={0,i};
	}
	FOR(i,0,n){
		int x=read();
		if(i%2)a[x].first++;
		else b[x].first++;
	}
	sort(a,a+111111);
	reverse(a,a+111111);
	sort(b,b+111111);
	reverse(b,b+111111);
	int ans=inf;
	FOR(i,0,2)FOR(j,0,2){
		if(a[i].second!=b[j].second)Umin(ans,n-a[i].first-b[j].first);
	}
	Tone(ans)
	
	
	return 0;
}


Measured memory_bytes: 2048