akhauriyash/Code-Regression huggingface dataset:
while True:
	h, w = map(int, raw_input().split())
	if h + w == 0: break
	b = [list(raw_input()) for i in range(h)]
	x = y = 0
	while True:
		a = b[y][x]
		b[y][x] = 0
		if a == ">": x += 1
		elif a == "<": x -= 1
		elif a == "v": y += 1
		elif a == "^": y -= 1
		elif a == ".": print x,y; break
		else: print "LOOP"; break

Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<bool> visit(100001,false);
    vector<int> wa(100001,0);
    int ac=0;
    for(int i=0;i<m;i++){
        int p;
        string s;
        cin>>p>>s;
        if(!visit[p]){
            if(s=="AC"){
                ac++;
                visit[p]=true;
            }else{
                wa[p]++;
            }
        }
    }
    int wa_sum=0;
    for(int i=0;i<100001;i++){
        if(visit[i]){
            wa_sum += wa[i];
        }
    }
    cout<<ac<<" "<<wa_sum<<endl;
    return 0;
}


Measured memory_bytes: 640
import math

A, B, N = map(int, input().split(' '))

# 答えが最大になるｘ
if math.floor(N / B) > 0:
    ans_x = B - 1
else:
    ans_x = N

l = math.floor((A * ans_x) / B)
r = A * math.floor(ans_x / B)

ans = l - r

print(ans)


Measured memory_bytes: 9016
n = int(input())
now_t,now_x,now_y = 0,0,0
for i in range(n):
  t,x,y = map(int,input().split())
  time = t-now_t
  distance = abs(x-now_x)+abs(y-now_y)
  if distance <= time and (time-distance)%2 == 0:
    now_t,now_x,now_y = t,x,y
  else:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 9048
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const M : usize = 1000000007;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut result = 0;
    let mut a = a;
    for k in 0..60 {
        let base = 2usize.pow(k);
        let mut count = 0;
        for i in 0..n {
            if a[i] % 2 == 1 {
                count += 1;
            }
            a[i] /= 2;
        }
        result = (result + ((count * (n - count) % M) * (base % M) % M)) % M;
    }
    println!("{}", result);
}


Measured memory_bytes: 8444
n,m=[int(x) for x in input().rstrip().split()]
A=[int(x) for x in input().rstrip().split()]
now=[]
bc=[]
for i in range(m):
  BC=[int(x) for x in input().rstrip().split()]
  bc.append(BC)
bc=sorted(bc,key=lambda x:x[1],reverse=True)

d=[]
for b,c in bc:
    d.extend([c]*b)
    if n<=len(d):
      break
A+=d
A.sort(reverse=True)
print(sum(A[:n]))


Measured memory_bytes: 29632
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int sum = 0;
	
	rep(i, 2) {
		if (a > b) {
			sum += a;
			a -= 1;
		}
		else if (a <= b) {
			sum += b;
			b -= 1;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

int main(){
    int n=0, i=0, d=0;
    cin >> n;

    int roll[n][2];

    for(i=0; i<n; i++){
        cin >> roll[i][0] >> roll[i][1];
    }

    for(i=0; i<n; i++){
        if(roll[i][0]==roll[i][1]){
            d++;
        }
        else{
            d=0;
        }
        if(d==3){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 3636
#include <cstdio>
#define maxn 100010
int cnt[2][maxn],M[2],Q[2],m[2],q[2],n;
int main(){
	scanf("%d",&n); 
	for(int i=1,x,p;i<=n;i++){
		scanf("%d",&x);
		p=i%2;
		cnt[p][x]++;
		if(M[p]<cnt[p][x]) M[p]=cnt[p][x],Q[p]=x;
	}
	if(Q[0]!=Q[1]){
		printf("%d\n",n-M[0]-M[1]);
		return 0;
	}
	for(int i=1;i<=100000;i++) {
		if(m[0]<cnt[0][i]&&i!=Q[0]) m[0]=cnt[0][i],q[0]=i;
		if(m[1]<cnt[1][i]&&i!=Q[1]) m[1]=cnt[1][i],q[1]=i;
	}
	if(M[0]-m[0]>M[1]-m[1]) printf("%d\n",n-M[0]-m[1]);
	else printf("%d\n",n-m[0]-M[1]);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,q;
ll a[100005],b,c;
ll N[100005];
ll ans;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ans+=a[i];
        N[a[i]]++;
    }
    cin>>q;
    while(q--){
        cin>>b>>c;
        ans-=(N[b]*b+N[c]*c);
        N[c]+=N[b];
        ans+=(N[c]*c);
        N[b]=0;
        cout<<ans<<endl;
    }


}



Measured memory_bytes: 5092
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		
		while(true){
			int n=Integer.parseInt(in.next());
			if(n==0)break;

			List<Integer> A=new ArrayList<>(), B=new ArrayList<>();

			int j=1,s=1;
			while(s<=n){
				A.add(s);
				if(s%2==1)B.add(s);
				j++;
				s=j*(j+1)*(j+2)/6;
			}

			int DP[]=new int[n+1],INF=2000000000;
			for(int i=1;i<=n;i++)DP[i]=INF;

			for(int i=0;i<A.size();i++){
				int t=A.get(i);
				for(int k=0;k+t<=n;k++){
					DP[k+t]=Math.min(DP[k]+1, DP[k+t]);
				}
			}
			
			out.print(DP[n]+" ");
			
			for(int i=1;i<=n;i++)DP[i]=INF;
			
			for(int i=0;i<B.size();i++){
				int t=B.get(i);
				for(int k=0;k+t<=n;k++){
					DP[k+t]=Math.min(DP[k+t], DP[k]+1);
				}
			}
			
			out.println(DP[n]);
			
		}
		
		out.flush();
	}

}



Measured memory_bytes: 60504
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	
	static ArrayList<Pair>[] adjList;
	static boolean[] vis;
	static int[] color;
	
	public static void dfs(int u) {
		vis[u] = true;
		
		for(Pair p : adjList[u]) {
			if(!vis[p.v]) {
				color[p.v] = p.w % 2 == 0 ? color[u] : 1 - color[u];
				dfs(p.v);
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		adjList = new ArrayList[n];
		for(int i = 0; i < adjList.length; i++)
			adjList[i] = new ArrayList<Pair>();
		
		for(int i = 0; i < n - 1; i++) {
			int u = sc.nextInt(), v = sc.nextInt(), w = sc.nextInt();
			adjList[u - 1].add(new Pair(v - 1, w));
			adjList[v - 1].add(new Pair(u - 1, w));
		}
		
		vis = new boolean[n];
		color = new int[n];
		
		dfs(0);
		for(int i = 0; i < color.length; i++)
			System.out.println(color[i]);
	}
	
	public static class Pair implements Comparable<Pair>{
		int v, w;
		
		public Pair(int v) {
			this.v = v;
		}
		
		public Pair(int v, int w) {
			this(v);
			this.w = w;
		}
		
		public int compareTo(Pair p) {
			if(this.w == p.w)
				return this.v - p.v;
			return this.w - p.w;
		}
	}
}


Measured memory_bytes: 114196
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include <bits/stdc++.h>

using namespace std;

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

const ll maxn =9e5+100;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}


vector<vector<int> > connect;
vector<int> visited;
int n;

void dfs(int start,int c){
	stack<int> st;
	st.push(start);
	while(!st.empty()){
		int k = st.top();
		visited[k] = c;
		st.pop();
		for(int i=0;i<connect[k].size();++i){
			int tmp = connect[k][i];
			if(visited[tmp]==-1){
				st.push(tmp);
			}
		}
	}
}

int main(){
    migmig
	int m,k;
	cin >> n >> m >> k;
	connect.resize(n);
	visited.resize(n);
	vector<int> friends(n,0);
	vector<int> block(n,0);
	vector<int> cs;
	for(int i=0;i<m;++i){
		int s,t;
		cin >> s >> t;
		connect[s-1].push_back(t-1);
		connect[t-1].push_back(s-1);
		friends[s-1]++;
		friends[t-1]++;
	}
	int c = 0;
	for(int i=0;i<n;++i)visited[i] = -1;
	for(int i=0;i<n;++i){
		if(visited[i] == -1){
			dfs(i,c);
			c++;
		}
	}
	cs.resize(c,0);
	for(int i=0;i<n;++i){
		cs[visited[i]]++;
	}
	for(int i=0;i<k;++i){
		int s,t;
		cin >> s >> t;
		if(visited[s-1]==visited[t-1]){
			block[s-1]++;
			block[t-1]++;
		}
	}
	for(int i=0;i<n;++i){
		cout << cs[visited[i]] - 1 - friends[i] - block[i];
		if(i!=n-1)cout << " ";
	}
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 8312
#include<bits/stdc++.h>
#define qtr ios::sync_with_stdio(0); cin.tie(0);
#define int long long
using namespace std;

int32_t main(){ qtr
	int n, m;
	cin >> n >> m;
	vector<int> weight(n), value(n);
	for(int i = 0; i < n; i++){
		cin >> weight[i] >> value[i];
	}
	int sum = accumulate(value.begin(), value.end(), 0);
	vector<vector<int>> dp(2, vector<int>(sum+1, INT_MAX));
	dp[0][0] = dp[1][0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= sum; j++){
			if(j < value[i]) dp[i%2][j] = dp[(i+1)%2][j];
			else dp[i%2][j] = min(dp[(i+1)%2][j], dp[(i+1)%2][j-value[i]] + weight[i]);
		}
	}
	/*for(int i = 0; i < 2; i++){
		for(int j = 0; j < sum; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	int ans = 0;
	for(int i = sum; i >= 0; i--){
		if(min(dp[0][i],dp[1][i]) <= m){
			ans = i;
			break;	
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5536
'use strict'

function main(input) {

  input = input.split('\n')
  input[0] = input[0].split(' ').map(v => ~~v)
  const h = input[0][0]
  const w = input[0][1]

  let tmp = '#'.repeat(w + 2) + '\n'
  for (let i = 1; i <= h; i++) {
    tmp += '#' + input[i] + '#\n'
  }
  tmp += '#'.repeat(w + 2)

  console.log(tmp)

}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
import itertools
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))

aaa = tuple(p)
bbb = tuple(q)
pm = list(itertools.permutations(set(p)))
a = pm.index(aaa) + 1
b = pm.index(bbb) + 1
print(abs(a-b))

Measured memory_bytes: 45040
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, m;
    cin >> n >> m;

    int64_t l = 1, r = n;
    for (auto _ : irange(0L, m)) {
        int64_t ll, rr;
        cin >> ll >> rr;
        l = max(l, ll);
        r = min(r, rr);
    }

    cout << max(r - l + 1, 0L) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
	int n;
	cin >> n;

	vector<int> a(n);

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

	sort(ALL(a), greater<int>());

	int alice, bob;
	alice = bob = 0;

	REP(i, n){
		if (i % 2) bob += a[i];
		else alice += a[i];
	}

	cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
	double a, b, c, d;
	double S, L, h;
	cin >> a >> b >> c;

	h = b * sin(M_PI * c/180);
	S = h * a / 2.0;

	if(c >= 90){
		d = sqrt(pow(b * abs(cos(M_PI * c/180)) + a ,2.0) + pow(h,2.0));
	}else{
		if(a > b){
			d = sqrt(pow(a - b * cos(M_PI * c/180) ,2.0) + pow(h,2.0));
		}else{
			d = sqrt(pow(b * cos(M_PI * c/180) - a ,2.0) + pow(h,2.0));
		}
	}
	L = a + b + d;

	cout << fixed << setprecision(11);
	cout << S << endl;
	cout << L << endl;
	cout << h << endl;

	return 0;
}


Measured memory_bytes: 3656
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let mut n: i32 = sc.read();
    let k: i32 = sc.read();
    let mut ans = 1;
    while n > 0 {
        match ans <= k {
            true =>  ans *= 2,
            false => ans += k,
        }
        n -= 1;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
bool vis[26];
char str[100010];

int main(void) {
    while(~scanf("%s", str)) {
        memset(vis, 0, sizeof(vis));
        for(int i = 0; str[i]; ++i) {
            int idx = str[i] - 'a';
            if(!vis[idx]) vis[idx] = true;
        }
        bool flag = 0;
        for(int i = 0; i < 26; ++i) {
            if(!vis[i]) {
                putchar(i + 'a');
                puts("");
                flag = true;
                break;
            }
        }
        if(!flag) puts("None");
    }
}


Measured memory_bytes: 384
%:pragma GCC optimize("Ofast", "inline")
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
   
typedef long long lo;
   
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}

int n, K, x[23333], id[23333];
vector <pair <int,int> > vec;
int main(void) {
  read(n); read(K);
  rep (i, n) read(x[i]), vec.push_back(make_pair(x[i], i));
  sort(vec.begin(), vec.end());
  int pre = 0;
  vector <int> ans;
  rep (turn, K + 1) {
    for (int i = n - 1; i >= 0; i--)
      if (vec[i].second != pre) {
	if (--vec[i].first < 0) return cout << -1 << "\n", 0;
	ans.push_back(vec[i].second);
      }
    pre = ans.back();
    sort(vec.begin(), vec.end());
  }
  cout << ans.size() << "\n";
  for (int i : ans) cout << i << " "; cout << "\n";
  
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    
    int X, Y, Z;
    X = sc.nextInt();
    Y = sc.nextInt();
    Z = sc.nextInt();
    System.out.print(Z + " ");
    System.out.print(X + " ");
    System.out.print(Y + " ");
  }
}
    
      
    

Measured memory_bytes: 21588
n,k = map(int,input().split())
l = [0]*n
# print(k)

for i in range(k):
    for j in range(1):
        _ = input()
        tl = list(map(int,input().split()))
        for t in tl:
            l[t-1]+=1
        # print(i,j)
ans = 0
for i in l:
    if i ==0:
        ans +=1

print(ans)

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

long long asd[100005][5];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int z;
	cin>>z;
	for(int q=1;q<=z;q++)
	{
		for(int w=1;w<=3;w++)
		{
			cin>>asd[q][w];
		}
	}
	long long ans=-10;
	for(int q=1;q<=z;q++)
	{
		for(int w=1;w<=3;w++)
		{
			if(w==1)asd[q][w]=max(asd[q][w]+asd[q-1][2],asd[q][w]+asd[q-1][3]);
			else if(w==2)asd[q][w]=max(asd[q][w]+asd[q-1][1],asd[q][w]+asd[q-1][3]);
			else asd[q][w]=max(asd[q][w]+asd[q-1][1],asd[q][w]+asd[q-1][2]);
			ans=max(ans,asd[q][w]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    final String LINE_SPR = System.getProperty("line.separator");
    final int BIG_MOD = 1000000007;

    void run() throws Exception {
        int nt = ni();
        for(int t = 0; t < nt; t++) {
            String[] nums = ns().split(" ");
            int a = Integer.parseInt(nums[0]);
            int b = Integer.parseInt(nums[1]);
            int c = Integer.parseInt(nums[2]);
            if(a * a + b * b == c * c || b * b + c * c == a * a
                    || c * c + a * a == b * b)
                System.out.println("YES");
            else
                System.out.println("NO");
        }

    }


    /*
     * Templates
     */
    void dumpObjArr(Object[] arr, int n) {
        for(int i = 0; i < n; i++) {
            System.out.print(arr[i]);
            if(i < n - 1)
                System.out.print(" ");
        }
        System.out.println("");
    }

    void dumpObjArr2(Object[][] arr, int m, int n) {
        for(int j = 0; j < m; j++) 
            dumpObjArr(arr[j], n);
    }

    int ni() throws Exception {
        return Integer.parseInt(br.readLine().trim());
    }

    long nl() throws Exception {
        return Long.parseLong(br.readLine().trim());
    }

    String ns() throws Exception {
        return br.readLine();
    }

    boolean isPrime(int n) {
        for(int i=2;i<n;i++) {
            if(n%i==0)
                return false;
        }
        return true;
    }

    int getPrime(int n) {
        List<Integer> primes = new ArrayList<Integer>();
        primes.add(2);
        int count = 1;

        int x = 1;
        while(primes.size() < n) {
            x+=2;
            int m = (int)Math.sqrt(x);
            for(int p : primes) {
                if(p > m) {
                    primes.add(x);
                    break;
                }

                if(x % p == 0) 
                    break;
            }
        }

        return primes.get(primes.size() - 1);
    }

    void gcjPrint(String str, int t) {
        System.out.println("Case #" + t + ": " + str);
    }

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

Measured memory_bytes: 20180
#include <stdio.h>

int main(int argc, char **argv){
	int a,b;
	scanf("%d %d",&a, &b);
	if( a < b ){
		printf("a < b\n");
	} else if ( a > b ){
		printf("a > b\n");
	} else {
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
/*input
CSS
CSR
*/

#include<bits/stdc++.h>
#define ll long long int
#define nl cout<<"\n"
using namespace std;


int main()
{
  string s,t;
  cin>>s;
  cin>>t;
  int c=0;
  if(s[0]==t[0])
    c++;
  if(s[1]==t[1])
    c++;
  if(s[2]==t[2])
    c++;
  cout<<c;
return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
A = [int(input()) for _ in range(N)]
d = defaultdict(int)

for i in range(N):
  d[A[i]] += 1

ans = 0
for key, val in d.items():
  if val % 2 == 1:
    ans += 1
    
print(ans)

Measured memory_bytes: 16640
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output


def chkprint(*args):
    names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))

# Binary converter


def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]

# --------------------------------------------


dp = None


def main():
    N = int(input())
    X = li_input()

    sX = sorted(X)
    med = sX[len(sX) // 2]
    med_min = sX[len(sX) // 2 - 1]

    for x in X:
        if x < med:
            print(med)
        else:
            print(med_min)


main()


Measured memory_bytes: 27260
#include <iostream>
#include <map>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

void init(int *par, int *rank_, int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rank_[i] = 0;
    }
}

int find(int *par, int *rank_, int x) {
    if (par[x] == x)
        return x;
    else 
        return par[x] = find(par, rank_, par[x]);
}

void unite(int *par, int *rank_, int x, int y) {
    x = find(par, rank_, x), y = find(par, rank_, y);
    if (x == y)
        return;
    else {
        if (rank_[x] < rank_[y])
            par[x] = y;
        else {
            par[y] = x;
            if (rank_[x] == rank_[y])
                rank_[x]++;
        }
    }
}

bool same(int *par, int *rank_, int x, int y) {
    return find(par, rank_, x) == find(par, rank_, y);
}

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    int *par_k, *par_l, *rank_k, *rank_l;
    par_k = new int[n];
    par_l = new int[n];
    rank_k = new int[n];
    rank_l = new int[n];
    init(par_k, rank_k, n);
    init(par_l, rank_l, n);
    int a, b;
    for (ll i = 0; i < k; i++) {
        cin >> a >> b;
        unite(par_k, rank_k, a-1, b-1);
    }
    for (ll i = 0; i < l; i++) {
        cin >> a >> b;
        unite(par_l, rank_l, a-1, b-1);
    }

    vector<pair<int, int> > com(n);
    map<pair<int, int>, int> m;
    for (int i = 0; i < n; i++) {
        com[i].first = find(par_k, rank_k, i);
        com[i].second = find(par_l, rank_l, i);
        m[com[i]]++;
    }
    for (int i = 0; i < n; i++)
        cout << m[com[i]] << " ";
    cout << endl;
    
    return 0;
}

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

int n, w;
long long int dp[110][100010];
int a[110];
int b[110];

long long int rek(int x, int y) {
	if (x == n) return 0;
	
	long long int &ret = dp[x][y];
	if (ret != -1) return ret;
	
	ret = rek(x+1, y);
	if (y+a[x] <= w) {
		ret = max(ret, rek(x+1, y+a[x]) + b[x]);
	}
	
	return ret;
}

int main () {
	
	cin >> n >> w;
	memset(dp, -1, sizeof dp);
	for (int i = 0; i < n; i ++) {
		cin >> a[i] >> b[i];
	}
	
	
	cout << rek(0, 0);
	
	return 0;
}

Measured memory_bytes: 86144
program hrn;
 var
  a:array[0..86]of int64;
  i,n:longint;
 begin
  a[0]:=2;a[1]:=1;
  read(n);
  for i:=2 to n do a[i]:=a[i-1]+a[i-2];
  writeln(a[n]);
 end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define all_acc(x) (x).begin(), (x).end(), 0LL
#define int long long
#define absSort(v) sort(a.begin(), a.end(), [](int i, int j) -> bool { return abs(i) < abs(j); });
using namespace std;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ll = long long;
double pi=3.14159265359;

//出力するよ
void output(vector<int> s)
{
    int n = s.size();
    for (int i = 0; i < n; i++)
    {
        if (i != 0)
            cout << " ";
        cout << s[i]; //<<endl;
    }
    cout << endl;
}

int MOD = pow(10, 9) + 7;

//各要素で最低操作回数を数える
pair<int,int> count(vector<int> a,vector<int> b){
    int n=a.size();
    int a_cnt=0,b_cnt=0;
    for(int i=0;i<n;i++){
        if(a[i]>b[i]){
            b_cnt+=(a[i]-b[i]);
        }
        if(a[i]<b[i]){
            if((b[i]-a[i])%2==0){
                a_cnt+=(b[i]-a[i])/2;
            }else{
                a_cnt+=(b[i]-a[i])/2 +1;
            }
        }
    }

    return make_pair(a_cnt,b_cnt);
}

signed main(){
    int n;cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];

    //和を計算しておく
    int sum_a=accumulate(all(a),0LL);
    int sum_b=accumulate(all(b),0LL);

    //aの和の方が大きいと、確実に無理
    if(sum_a>sum_b) cout<<"No"<<endl;
    else{
        //aの最低操作回数とbの最低操作回数を得る。これが操作回数を超えなければ良い。
        pair<int,int> cnt=count(a,b);
        if(cnt.first>sum_b-sum_a) cout<<"No"<<endl;
        else if(cnt.second>sum_b-sum_a) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 3880
fun main(args: Array<String>) {
    var (x, y) = readIntList()

    if ((x + y) % 3 != 0) {
        println(0)
        return
    }
    val n = (x + y) / 3
    x -= n
    y -= n
    if (x < 0 || y < 0) {
        println(0)
        return
    }
    val mod = 1_000_000_007L
    val comb = CombinationModPrime(x + y, mod)
    println(comb.operate(x + y, x))
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun Long.modPow(t: Long, mod: Long): Long {
    if (t == 0L) return 1L
    var a = this.modPow(t shr 1, mod)
    a *= a
    a %= mod
    if (t and 1 == 1L) {
        a *= this
        a %= mod
    }
    return a
}

// mod pの逆元 (pは素数)
fun Long.modInverse(mod: Long) = this.modPow(mod - 2L, mod)

class CombinationModPrime(private val n: Int, private val mod: Long) {
    private val fact = Array(n + 1) { 0L }
    private val ifact = Array(n + 1) { 0L }

    init {
        fact[0] = 1
        for (i in 1..n) {
            val tmp = fact[i - 1] * i.toLong()
            fact[i] = tmp % mod
        }
        ifact[n] = fact[n].modInverse(mod)
        for (i in n downTo 1) {
            val tmp = ifact[i].toLong() * i.toLong()
            ifact[i - 1] = tmp % mod
        }
    }

    fun operate(n: Int, k: Int): Int {
        if (k < 0 || k > n) return 0
        var tmp = fact[n] * ifact[k]
        tmp %= mod
        tmp *= ifact[n - k]
        tmp %= mod
        return tmp.toInt()
    }
}

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

int main() {
  int N, A, B, X;
    cin >> N >> A >> B;
  X = N * A;
    if (X > B || X == B ) {
      cout << B << endl;
    }
    if (X < B) {
      cout << X << endl;
    }  
}

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

int N;
int X[110], Y[110], H[110];

int main(){
	cin >> N;
	for (int i = 1; i <= N; i++){
		cin >> X[i] >> Y[i] >> H[i];
	}
	for (int i = 0; i <= 100; i++)
		for (int j = 0; j <= 100; j++){
			int H_ = 0;
			for (int k = 1; k <= N; k++)
				if (H[k] > 0){
					H_ = H[k] + abs(i - X[k]) + abs(j - Y[k]);
					break;
				}
			for (int k = 1; k <= N; k++)
				if (max(H_ - abs(i - X[k]) - abs(j - Y[k]), 0) != H[k]){
					H_ = 0;
					break;
				}
			if (H_ == 0)
				continue;
			cout << i << ' ' << j << ' ' << H_ << endl;
		}
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();
            var A = int.Parse(ss[0]);
            var B = int.Parse(ss[1]);

            var AB = A + B;
            Console.WriteLine(AB < 10 ? AB.ToString() : "error");
        }
    }
}

Measured memory_bytes: 11092
n , m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
#i, j はBの左端
for i in range(n-m+1):
    for j in range(n-m+1):
        ans = True
        for k in range(m):
            if a[i + k][j:j+m] != b[k]:
                ans = False
        if ans == True:
            break
    else:
        continue
    break

if ans == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
N = int(input())
H = [0]+list(map(int, input().split()))

cnt = 0
max_step = 0
for i in range(1, N):
    if H[i]>=H[i+1]:
        cnt+=1
    else:
        if max_step < cnt:
            max_step = cnt
        cnt = 0

if max_step < cnt:
    max_step = cnt
print(max_step)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(long long i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0;

    map<ll, ll> mp;
    rep(i, n) {
        ll v = a[i] - i;
        mp[v]++;
    }
    rep(i, n) {
        ll v = -a[i] - i;
        ans += mp[v];
    }
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 27392
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) puts("Yes");
    else puts("No");
}


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

int main(){
    string s, t;
    cin >> s >> t;
    if(s == t){
        cout << "Yes" << endl;
        return 0;
    }
    int size = s.size();
    bool b = false;
    for(int i = 0; i < size; i++){
        char v = s[0];
        for(int j = 0; j < size - 1; j++){
             s[j] = s[j+1];
        }
        s[size-1] = v;
        if(s == t) b = true;
    }
    if(b == true){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/* 十 聖イシドールスよ、迷えるプログラマを導き給え！ 十 */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

#define rep(i, n) for(int i=0; i < n; i++)

const long long INF = 1LL << 60;

int main()
{
	int K;
	std::cin >> K;
 
	std::vector<int> checker( 1000001, -1 );
 
	// 1回目は決め打ち	ほかの項と出し方が違うので
	checker[1] = 7 % K;
 
	// 1周してしまうまではすべて別の数が出てくる。出てくる数の種類は最大でもK-1種類なので、
	// K回目まで行けば必ず1週する
	for( int cntup = 2; cntup <= K; cntup++ )
	{
		checker[cntup] = ( checker[cntup-1] * 10 + 7 ) % K;	// mod前を保持するとすぐオーバーフローする 
		//printf( "%d:%d\n", cntup, checker[cntup] );
	}
 
	rep( ans, 1000001 )
	{
		if( checker[ans] == 0 )
		{
			std::cout << ans << std::endl;
			return 0;
		}
		else
		{
			continue;
		}
	}
 
	std::cout << -1 << std::endl;
 
    return 0;
}


Measured memory_bytes: 7216
s=input()
t=input()

t1=0
l1={}
sl=[]
for i in s:
  if i in l1:
    sl.append(l1[i])
  else:
    l1[i]=t1
    sl.append(t1)
    t1+=1

t2=0
l2={}
tl=[]
for i in t:
  if i in l2:
    tl.append(l2[i])
  else:
    l2[i]=t2
    tl.append(t2)
    t2+=1
print("Yes" if sl==tl else "No")

Measured memory_bytes: 81704
#include<iostream>
#include<string>
#include<map>
#include<string.h>
#include<vector>
#include<set>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<cstdio>
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define pb push_back

int main()
{
	int a,b;
 	cin>>a>>b;
  if(a<=8 && b<=8)
  {
  	cout<<"Yay!"<<endl;
 	}
 	else
 		cout<<":("<<endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
int p[10] ;
int combination(int n ,int m ,vector<int>* v , string ans = "" ){
		if(n == 0){
			for(int i = 0 ; i < m ; i++){
				int temp = 0 ;
				for(auto j : v[i]) temp += (ans[j]-'0') ;
				if(temp%2 != p[i]) return 0 ; 
			}
			return 1 ;
		}
		return combination(n-1,m,v,ans+"0") + combination(n-1,m,v,ans+"1") ;
}
 
int main() {
	int n , m ;
	cin >> n >> m ;
	vector<int> v[m] ;
	for(int i = 0 ; i < m ; i++){
		int k ; cin >> k;
		for(int j = 0 ; j < k ; j++){
			int x ; cin >> x ; x-- ;
			v[i].push_back(x) ;
		}
	}
	for(int i = 0 ; i < m ; i++) cin >> p[i] ;
	cout << combination(n,m,v) ;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
// headers {{{
using namespace std;
// using namespace rel_ops;
 
typedef long long int64;
typedef unsigned long long uint64;
const double pi=acos(-1.0);
const double eps=1e-11;
const int INF=0x7FFFFFFF;
template<class T> inline bool checkmin(T &a,T b){return b<a?a=b,1:0;}
template<class T> inline bool checkmax(T &a,T b){return b>a?a=b,1:0;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define mem(a,b) memset(a, b, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ff first
#define ss second
#ifdef LOCAL
#define dbg(args...) printf(args); //##__VA_ARGS__
#define dout cout
#define out(x) (cout<<#x<<": "<<x<<endl)
template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}
#else
#define dbg(...)
#define dout if(true);else cout
#define out(...)
#define show(...)
#endif
// }}}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    int N;
    while (cin >> N) {
        N++;
        vector<int64> a(N), mx(N), infi(N);
        rep(i, N) cin >> a[i];
        if (a[0] > 1) { cout << -1 << endl; continue; }
        bool valid = true;
        mx[0] = 1;
        for (int i = 1; i < N; i++) {
            if (mx[i-1] <= a[i-1]) valid = false;
            mx[i] = (mx[i-1] - a[i-1])*2;
            if (mx[i] > 1e17) mx[i] = 1e17;
        }
        if (mx[N-1] < a[N-1]) valid = false;
        int64 ans = 0;
        int64 nodes = 0;
        for (int i = N-1; i>=0; i--) {
            nodes += a[i];
            if (nodes > mx[i]) nodes = mx[i];
            ans += nodes;
        }
        if (!valid) cout << -1 << endl;
        else cout << ans << endl;
    }
    return 0;
}



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

int main(void)
{
    int n, k;
    cin >> n >> k;

    if ((n / 2.0 + 1 )> k) {
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define forn(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define ford(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define int long long
#define ii pair<int,int>
#define ar array
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define sz(x) ((int)(x).size())
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;
//const int N = 3e5+7 ;
int get(vector<int>& a){
    int mx = -1e9 , mn = 1e9 ;
    for(int z : a){
        mx= max(mx,z) ;
        mn= min(mn,z) ;
    }
    return mx-mn ;
}
int maxAbsValExpr(vector<int>& arr1, vector<int>& arr2) {
    int ans = -1e9 ;
    int n = arr1.size() ;
    for(int x : {-1,1}){
        for(int y : {-1,-1}){
            vector<int> a(n) ;
            for(int i = 0 ; i < n ; i++){
                a[i] = x*arr1[i]+y*arr2[i] ;
            }
            ans = max(ans,get(a)) ;
        }
    }
    return ans ;
}


void solve(){
    int n ;
    cin >> n ;
    vector<int> a(n);
    vector<int> b(n) ;
    forn(i,n) cin >> a[i] >> b[i] ; 
    cout << maxAbsValExpr(a,b) ;

}


int32_t main(){
    FAST_IO ;
    int t = 1 ;
//    cin >> t ;
    while(t--){
        solve() ;
    }
}


Measured memory_bytes: 7940
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#define ll                 long long    
#define vi                 vector<ll >
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define int                long long                        
#define pb                 push_back                                                     
#define mii                map<ll ,ll >
#define rep(i, a, b)       for(ll  i=a;i<b;i++)
#ifdef LOCAL
#define dbg(args...)       { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
#define dbg(args...)
#endif
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define hell               1000000007
// #define hell               (ll)998244353
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define mp                 make_pair
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define inf                3223372036854775807
#define endl               '\n' 
#define PI                  3.14159265
#define N                  (int) 1e6 + 5
ll n, m, k, a[N];


int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    #ifdef LOCAL
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ll tests = 1;
    // cin >> tests;
    rep(test, 1, tests+1)
    {
        cin >> n;
        int ff = (999 + n) / 1000;
        cout << ff * 1000 - n;
    }
    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int K;
  cin >> K;
  long long int ans = 0;
  for(int i = 0; i <= K;i++){
    for(int j = 0; j  <= K; j++){
      if(i + j > K) continue;
      int k = K - i - j;
      long long int tmp = a*pow(2,k) + b*pow(2,i) + c*pow(2,j);
      ans = max(ans,tmp);
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        string s, t;
        cin >> s >> t;

        int mn = t.size();
        for (int i = 0; i + t.size() <= s.size(); i++) {
            int cnt = 0;
            for (int j = 0, k = i; j < t.size(); j++, k++) {
                if (s[k] != t[j])
                    cnt++;
            }
            mn = min(mn, cnt);
        }

        cout << mn  << '\n';
    }
    
    return 0;
}



Measured memory_bytes: 3612
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define MOD 1000000007
using namespace std;

bool comp(pll a, pll b){
	if(a.first == b.first){
		return a.second < b.second;
	}
	return a.first > b.first;
}
ll dp[2001][2001];
ll solve(pll a[], int st, int en, int left){
	if(st > en)
		return 0;
	if(dp[st][left] != -1){
		return dp[st][left];
	}
	ll so = a[st].first * llabs(left - a[st].second) + solve(a, st + 1, en, left + 1);
	int right = en - (st - left);
	ll so2 = a[st].first * llabs(right - a[st].second) + solve(a, st + 1, en, left);
	
	return dp[st][left] = max(so, so2);
}

int main() {
	FASTIO
	ll n;
	cin >> n;
	pll a[n];
	rep(i, 0, n){
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a, a + n, comp);
	rep(i, 0, n){
		rep(j, 0, n){
			dp[i][j] = -1;
		}
	}
	cout << solve(a, 0, n - 1, 0);
	return 0;
}




Measured memory_bytes: 35212
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  cout<<(k%2==0?a-b:b-a)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#define chkmin(a,b) ((a)<(b)?(a):(b))
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~(i)))
int t=1,S=200201,T,n,inf=1e9,ans;
struct node
{
	int u,v,cap,next;
}e[200010];
typedef int arr[300010];
arr dis,head,gap,a,b,c,d;
void add(int x,int y,int z)
{
	e[++t].v=y;
	e[t].cap=z;
	e[t].next=head[x];
	head[x]=t;
}
int dfs(int u,int flow)
{
    if(u==T)return flow;
    int v,up,maxcap=flow;
    for(register int i=head[u];i;i=e[i].next)
    {
        v=e[i].v;
        if(dis[u]==dis[v]+1&&e[i].cap)
        {
            up=dfs(v,chkmin(maxcap,e[i].cap));
            e[i].cap-=up,e[i^1].cap+=up;
            if(!(maxcap-=up))return flow;
        }
    }if(!(--gap[dis[u]]))dis[S]=T+1;
    ++gap[++dis[u]];
    return flow-maxcap;
}
void isap()
{for(gap[0]=T+1;dis[S]<T+1;)ans+=dfs(S,inf);}
int main()
{
	T=200202;
	scanf("%d",&n);	
	f(i,1,n)scanf("%d%d",&a[i],&b[i]),add(S,a[i]*1000+b[i],1),add(a[i]*1000+b[i],S,0);
	f(i,1,n)scanf("%d%d",&c[i],&d[i]),add(c[i]*1000+d[i],T,1),add(T,c[i]*1000+d[i],0);
	f(i,1,n)
	 f(j,1,n)
	  if(a[i]<c[j]&&b[i]<d[j])add(a[i]*1000+b[i],c[j]*1000+d[j],1),add(c[j]*1000+d[j],a[i]*1000+b[i],0);//,printf("%d %d\n",a[i]*1000+b[i],c[j]*1000+d[j]);
	isap();
	printf("%d\n",ans);
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=100005;
int n,m;
int head[MAXN];
struct node
{
    int from;
    int to;
    int next;
}edge[MAXN<<1];
int edge_cnt;
void add_edge(int fr,int to)
{
    edge[++edge_cnt].from=fr;
    edge[edge_cnt].to=to;
    edge[edge_cnt].next=head[fr];
    head[fr]=edge_cnt;
}
int col[MAXN];
bool flag;
void dfs(int x)
{
    for(int i=head[x];i;i=edge[i].next)
    {
        int u=edge[i].to;
        if(col[u]==-1)
        {
            col[u]=col[x]^1;
            dfs(u);
        }
        else if(col[x]==col[u]) flag=1;
    }
}
bool check()
{
    for(int i=1;i<=n;i++) col[i]=-1;
    for(int i=1;i<=n;i++)
    {
        if(col[i]==-1)
        {
            col[i]=0;
            dfs(i);
        }
    }
    return !flag;
}
long long ans;
signed main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        scanf("%lld%lld",&u,&v);
        add_edge(u,v),add_edge(v,u);
    }
    if(check()) 
    {
        int temp=0;
        for(int i=1;i<=n;i++) 
        {
            if(col[i]) temp++;
        }
        ans=temp*(n-temp)-m;
    }
    else ans=n*(n-1)/2-m;
    cout<<ans<<endl;
    // system("pause");
    return 0;
}

Measured memory_bytes: 10816
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

using ll = long long;
using ull = unsigned long long;
//constexpr ll N = 2e5;
//ll a[N];

//constexpr int max = 2147483647;


int main()
{
	string s;
	cin >> s;

	if (s == "ABC")
		cout << "ARC";
	else
		cout << "ABC";
	
	
	return 0;
}

Measured memory_bytes: 3104