akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <numeric>

using namespace std;

void all_non_negative(const vector<long long>& as){
    cout << accumulate(as.begin() + 1, as.end(), 0) - as.front() << endl;
    long long tmp = as.front();
    for(int i = 1; i < as.size() - 1; ++i){
        cout << tmp << ' ' << as.at(i) << endl;
        tmp -= as.at(i);
    }
    cout << as.back() << ' ' << tmp << endl;
}

void all_negative(const vector<long long>& as){
    cout << as.back() - accumulate(as.begin(), as.end() - 1, 0) << endl;
    long long tmp = as.back();
    for(int i = 0; i < as.size() - 1; ++i){
        cout << tmp << ' ' << as.at(i) << endl;
        tmp -= as.at(i);
    }
}

void mixed(const vector<long long>& as){
    long long ans = 0;
    for(auto x : as){ ans += abs(x); }
    cout << ans << endl;

    int zero_idx = lower_bound(as.begin(), as.end(), 0) - as.begin();
    long long tmp1 = as.back();
    for(int i = 1; i < zero_idx; ++i){
        cout << tmp1 << ' ' << as.at(i) << endl;
        tmp1 -= as.at(i);
    }
    long long tmp2 = as.front();
    for(int i = zero_idx; i < as.size() - 1; ++i){
        cout << tmp2 << ' ' << as.at(i) << endl;
        tmp2 -= as.at(i);
    }
    cout << tmp1 << ' ' << tmp2 << endl;
}

int main(){
    int n;
    cin >> n;
    vector<long long> as;
    as.resize(n);
    for(int i = 0; i < n; ++i){
        cin >> as.at(i);
    }
    sort(as.begin(), as.end());
    if(as.at(0) >= 0){
        all_non_negative(as);
    }else if(as.back() < 0){
        all_negative(as);
    }else{
        mixed(as);
    }
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} 


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

i64 N; cin >> N;
map<string, int> m;
rep(i, 0, N){
    string S; cin >> S;
    ++m[S];
}
int maxi = 0;
for(pair<string, int> p: m) maxi = max(maxi, p.second);
VS s;
for(pair<string, int> p: m) 
    if (p.second  == maxi) s.push_back(p.first);

sort(ALL(s));
for(string x: s) cout << x << "\n";


return 0;
}
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 25584
#include <iostream>
using namespace std;
int main(void){
    int n,t;
    cin >> n >> t;
    int d[n+1][3];
    int mi = 1001;
    for(int i=1;i<=n;i++){
        cin >> d[i][1] >> d[i][2];
        if(d[i][2]<=t){
            if(mi>d[i][1]){
                mi=d[i][1];
            }
        }
    }
    
    if(mi==1001){
        cout << "TLE" << endl;
    }else{
        cout << mi << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;

#define MAX 2000001
#define VMAX 10000

int main() {
	short *A, *B;
	int C[VMAX + 1];
	int n;

	scanf("%d", &n);

	A = new  short[n + 1];
	B = new  short[n + 1];

	for (int i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
	}

	for (int i = 0; i < VMAX+1; i++) {
		C[i] = 0;
	}

	for (int j = 1; j <= n; j++) {
		C[A[j]]++;
	}

	for (int i = 1; i < VMAX + 1; i++) {
		C[i] = C[i] + C[i - 1];
	}

	for (int j = n; j > 0; j--) {
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}

	for (int i = 1; i <= n; i++) {
		if(i!=n)cout << B[i] << " ";
		if (i == n)cout <<B[i]<< endl;
	}

	delete[] A;
	delete[] B;

	return 0;
}



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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1;

const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

// a^n mod を計算 再帰
ll modpow(ll a,ll n,ll &mod){
  if(!n) return 1;
  ll x = modpow(a,n/2,mod)%mod;
  x *=x;
  if(n%2==1)x*=a;
  return x%mod;
}

int main(){
  int n,k;cin>>n>>k;
  vector<int> as(n);
  //cout<<as[3];
  rep(i,k){
    int d;cin>>d;
    rep(j,d){
      int a;cin>>a;
      as[a-1]=1;
    }
  }
  int ans=n;
  rep(i,n)ans-=as[i];
  cout<<ans;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=100005;
int rk[Maxn][2];
struct node{
    int type,val,id;
}w[2*Maxn];
int main(){
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int a,b;scanf("%d%d",&a,&b);
        w[2*i-1]=(node){0,a,i};
        w[2*i]=(node){1,b,i};
    }
    sort(w+1,w+2*n+1,[](const node&a,const node&b){
        return a.val<b.val;
    });
    bool succ=true;
    ll sum=0,ans=LLONG_MAX;
    for(int i=1;i<=2*n;i++)
        rk[w[i].id][w[i].type]=i;
    for(int i=1;i<=n;i++)
        sum+=w[i].val;
    for(int i=2;i<=n;i++)
        if(w[i].type!=w[i-1].type)
            succ=false;
    if(succ){
        cout<<sum<<"\n";
        return 0;
    }
    for(int i=1;i<=n;i++){
        if(rk[i][0]<=n&&rk[i][1]<=n)ans=min(ans,sum);
        else if(rk[i][0]<=n)ans=min(ans,sum+w[rk[i][1]].val-w[rk[i][0]==n?n-1:n].val);
        else if(rk[i][1]<=n)ans=min(ans,sum+w[rk[i][0]].val-w[rk[i][1]==n?n-1:n].val);
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3456
S = input()
N = len(S)

for i in range(((N-1)//2)//2+1):
    if S[i] == S[(N-1)//2-1-i] and S[i] == S[N-1-i]:
        continue
    else:
        break
else:
    for i in range((N+3)//2-1,N):
        if S[i] == S[N-1-i]:
            continue
        else:
            break
    else:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 3064
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
B=[list(map(int,input().split())) for i in range(N)]
B.sort(key=lambda x:x[0])
A.sort(key=lambda x:x[1])
C=[0]*N
cnt=0
for i in range(N):
  for j in range(N):
    if C[j]==0 and A[-i-1][0]<B[j][0] and A[-i-1][1]<B[j][1]:
      C[j]=1
      cnt+=1
      break
print(cnt)

Measured memory_bytes: 3064
import java.util.*;
class Main {

  static Integer[] PON_ARR = new Integer[]{0,1,6,8};
  static  Integer[] BON_ARR = new Integer[]{3};
  static  List<Integer> PON_LIST = Arrays.asList(PON_ARR);
  static  List<Integer> BON_LIST = Arrays.asList(BON_ARR);

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int val = a - (int)(a/10)*10;
    
    if(PON_LIST.contains(val)){
      System.out.println("pon");
    }else if(BON_LIST.contains(val)){
      System.out.println("bon");
    }else{
      System.out.println("hon");
    }
  }
}

Measured memory_bytes: 35708
n = int(input())
judge = {}
for i in range(n):
    s = input()
    if s in judge.keys():
        judge[s] += 1
    else:
        judge[s] = 1
judgelist = ['AC', 'WA', 'TLE', 'RE']
for p in judgelist:
    if p not in judge.keys():
        judge[p] = 0
for key in judgelist:
    print(key + ' x ' + str(judge[key]))


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

int main() {
	string s;
	cin >> s;
	if (s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}
	bool a[26]{};
	for (auto &c : s) {
		a[c - 'a'] = true;
	}
	bool f = true;
	for (auto &b : a) {
		f &= b;
	}
	if (f) {
		int n = s.size(), i = n - 1;
		for (int j = n - 1; j; j--) {
			if (s[j - 1] < s[j]) {
				i = j - 1;
				break;
			}
		}
		assert(i != n - 1);
		int j = i + 1;
		for (int k = j; k < n; k++) {
			if (s[i] < s[k] && s[k] < s[j]) {
				j = k;
			}
		}
		swap(s[i], s[j]);
		string t = "";
		for (int k = 0; k <= i; k++) {
			t += s[k];
		}
		s = t;
	} else {
		for (int i = 0; i < 26; i++) {
			if (!a[i]) {
				s += 'a' + i;
				break;
			}
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
if n <= 9:
  print(n)
elif n<=99:
  print(9)
elif n <=999:
  print(9+n-100+1)
elif n <= 9999:
  print(909)
elif n <= 99999:
  print(909+n-10000+1)
else:
  print(90909)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  long a, b, c=0, d=0, e, f, g, h, n;
  cin >> n;
  a=n+1;
  int x[n];
  rep(i,0,n) cin >> x[i];
  rep(i,0,n){
    if(x[i]<=a){
      a=x[i];
      c++;
    }
  }
  co(c);
    
  
  return 0;
}

Measured memory_bytes: 1024
A,B = [int(x) for x in input().split()]
if(B==1):
    print(0)
elif(B<A):
    print(1)
else:
    if((B-A)%(A-1)==0):
        print((B-A)//(A-1)+1)
    else:
        print((B-A)//(A-1)+2)


Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int p[] = new int[n];
        int hikaku[] = new int[n];
        
        for(int i = 0; i < n; i++){
            p[i] = stdIn.nextInt();
            hikaku[i] = p[i];
        }
        
        Arrays.sort(hikaku);
        int count = 0;
        
        for(int i = 0; i < n; i++){
            if(hikaku[i] != p[i]){
                count++;
            }
            

        }
        
        if(count <= 2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < n; i++){
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();        
        int N, M;
        long C = 1000000007;
        {int[] a = r.ii(); N = a[0]; M = a[1];}
        int[] a = new int[M];
        for(int i = 0; i < M; i++){
            a[i] = r.i();
        }
        int[] broken = new int[N+1];
        for(int temp : a){
            broken[temp] = 1;
        }
        long[] f = new long[N+1];
        f[0] = 1;
        f[1] = broken[1] == 1 ? 0 : 1;        
        for(int i = 2; i <= N; i++){
            if(broken[i] == 0)
                f[i] = (f[i-1] + f[i-2])%C;
        }
        println(f[N]);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	inline int tc()
	{
		int c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		return c;
	}
}
using ae86::ty;
using ae86::tc;

const int _ = 21<<1;

int n,lim[_][_]={0};
lint f[_][_][_]={0},g[_][_][_]={0};

int main()
{
	n=ty()*2;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			lim[i][j]=tc()=='1';

	for(int i=1;i<=n;i++)
	{
		f[i][i][i]=1;
		for(int j=1;j<=n;j++)
			if(lim[j][i])g[i][i][j]=1;
	}

	for(int i=3;i<=n;i+=2)
	{
		for(int l=1,r=l+i-1;r<=n;l++,r++)
		{
			for(int j=l;j<=r;j+=2)
				for(int k=r;k>j;k-=2)
				{
					lint temp=0;
					for(int a=k;a<=r;a++)temp+=g[l][j][a]*f[k][r][a];
					for(int a=j+1;a<k;a++)f[l][r][a]+=temp*f[j+1][k-1][a];
				}
			for(int j=l+1;j<r;j++)
				for(int k=r+1;k<n;k++)
					if(lim[j][k])g[l][r][k]+=f[l][r][j];
		}
	}

	lint ans=0;
	for(int i=1;i<n;i++)
		if(lim[i][n])ans+=f[1][n-1][i];
	printf("%lld\n",ans);

	return 0;
}


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

int main() {
  int N, Y;
  cin >> N >> Y;
  Y /= 1000;
  bool d = false;
  bool e = true;
  
  for (int A = 0; A <= Y / 10; A++) {
    for (int B = 0; B <= N - A; B++) {
      int C = N - A - B;
      if (A * 10 + B * 5 + C == Y && C >= 0) {
        d = true;
        e = false;
        cout << A << " " << B << " " << C << endl;
        break;
      }
    }
    if (d) {
      break;
    }
  }
  if (e) {
    cout << "-1 -1 -1" << endl;
  }
}    


Measured memory_bytes: 256
# Triangle

from math import *

triangle = [int(i) for i in input().rstrip().split()]
sides = [triangle[0], triangle[1]]
a = sides[0]
b = sides[1]
angle = triangle[2]

triangleArea = 0.5 * a * b * sin(radians(angle))
print(triangleArea)

otherSideSquare = a ** 2 + b ** 2 - 2 * a * b * cos(radians(angle))
otherSide = otherSideSquare ** 0.5
circumference = a + b + otherSide
print(circumference)

height = triangleArea / 0.5 / a
print(height)



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

int main(){
    int n;
    cin>>n;
    int p[n],maxp=0,sum=0;
    for (int i = 0; i < n; ++i) {
        cin>>p[i];
        sum+=p[i];
        maxp=max(maxp,p[i]);
    }
    cout<<sum-maxp/2<<endl;
}

Measured memory_bytes: 256
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if op =="+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(a//b)
    elif op == "?":
        break


Measured memory_bytes: 5596
#include<iostream>
    using namespace std;
     
    int main(){
      char a, b;
      cin >> a >> b;
      
      if(a == 'D'){
    	if(b == 'H'){
          cout << "D" << endl;
        } else {
          cout << "H" << endl;
        }
      } else {
        if(b == 'H'){
          cout << "H" << endl;
        } else {
          cout << "D" << endl;
        }
      }
    }

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
while (true) {
   if (arr[0] == "0 0") break;
   var nm = arr.shift().split(" ").map(Number);
   var point = [];
   for (var i = 0; i < nm[0]; i++) point[i] = [0, 0];
   for (var i = 0; i < nm[1]; i++) {
      var c = arr.shift().split(" ").map(Number);
      var s = c.shift();
      var k = c.shift();
      if (k == 1) point[c[0] - 1][0] += s;
      c.forEach(function(v, i) {
         point[v - 1][1] += s;
      });
   }
   var max = 0;
   for (var i = 0; i < nm[0]; i++) {
      for (var j = 0; j < nm[0]; j++) {
         if (i == j) continue;
         max = Math.max(max, point[i][1] - point[j][0]);
      }
   }
   console.log(max + 1);
}

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

using namespace std;

#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-8;
const double pi=acos(-1.0);
const int K=1e6+7;
const int mod=1e9+7;

int n,sum[K],pre[K];
vector<int>vc[K],road;

void dfs(int x,int f)
{
    sum[x]=1,pre[x]=f;
    for(int i=0;i<vc[x].size();i++)
    if(vc[x][i]!=f)
    {
        dfs(vc[x][i],x);
        sum[x]+=sum[vc[x][i]];
    }
}
int main(void)
{
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    cin>>n;
    for(int i=1,x,y;i<n;i++)
        scanf("%d%d",&x,&y),vc[x].PB(y),vc[y].PB(x);
    dfs(1,0);
    for(int i=n;i;i=pre[i])
        road.PB(i);
    reverse(road.begin(),road.end());
    int tb,ta;
    tb=sum[road[(road.size()+1)/2]];
    ta=n-tb;
    if(ta>tb) printf("Fennec\n");
    else printf("Snuke\n");

    return 0;
}




Measured memory_bytes: 36860
from typing import List, Tuple


if __name__ == "__main__":
    n = int(input())
    coordinates: List[Tuple[int, int]] = []

    for _ in range(n):
        (x, y) = tuple(map(lambda x: int(x), input().split()))
        coordinates.append((x, y))

    coordinates = sorted(coordinates, key=lambda x: (x[0], x[1]))

    for elem in coordinates:
        print(f"{elem[0]} {elem[1]}")



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

int main()
{
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    long long res = 0;
    for (int d = 60; d >= -1; d--)
    {
        if(d!=-1 && !(K&(1LL<<d))) continue;

        long long tmp = 0;

        for (int e = 60; e > -1; e--)
        {
            long long mask = 1LL << e;
            long long num = 0;
            for (int i = 0; i < N; i++)
            {
                if(mask&A[i]) num++;
            }
            
            if (e > d)
            {
                if(mask&K)
                    tmp += mask * (N - num);
                else
                    tmp += mask * num;
            }
            else if(e==d){
                tmp += mask * num;

            }

            else{
                tmp += mask * max(num, N - num);
            }


        }
        res = max(res, tmp);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int X;
  cin>>X;
  int t=X,sum=0;
  while(t!=0){
    sum+=t%10;
    t/=10;
  }
  if(X%sum==0){
    printf("Yes");
  }else{
    printf("No");
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define ull unsigned ll
#define FORR(i, a, b)   for(ll i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define MOD1 1000000007
#define MOD2 998244353
#define F first
#define S second
#define IOS std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define dbg(x) cout<<#x<<" = "<<x<<"\n";
#define print(a) for(auto x : a)    cout<<x<<" "; cout<<"\n";
using namespace std;
 
void OFFLINE(){
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #endif
}
 
int main(){
 
    IOS;
    // OFFLINE();
    //check for corner test cases
 
 
    int n;
    cin >> n;

    n %= 1000;

    if(n)   n = 1000 - n;
    cout<<n<<"\n";
    
    //check for corner test cases
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(auto &i:A)cin >> i;
	vector<int> B(N);
	for(int i=0;i<N;i++){
		B[A[i]-1]=i+1;
	}
	for(int i=0;i<N;i++){
		cout << B[i];
		if(i==N-1)cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define N 10000
using namespace std;
long long n,m;
int x,y,z;
int fa[100010];
int g[100010],cnt=0;

int find(int x){
    if(fa[x]==x) return x;
    return fa[x]=find(fa[x]);
}

int main() {
    cin >> n >> m;
    for(int i=1;i<=n;i++) fa[i]=i;
    for(int i=1;i<=m;i++){
        scanf("%d %d %d",&x,&y,&z);
        int u=find(x);
        int v=find(y);
        if(u!=v){
            if(u<v) fa[v]=u;
            else fa[u]=v;
        }
    }
    for(int i=1;i<=n;i++){
        fa[i]=find(i);
        if(g[fa[i]]==0){
            g[fa[i]]=1;
            cnt++;
        }
    }
    printf("%d\n",cnt);

    return 0;
}



Measured memory_bytes: 1024
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
void YES(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    ll n = s.size();
    bool ok = true;
    rep(i,0,n){
        ok &= s[i] == s[n-i-1];
    }
    rep(i,0,n/2){
        ok &= s[i] == s[n/2-1-i];
    }

    YES(ok);
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ll n;
cin>>n;
V<ll> a(n);
for(int i=0;i<n;i++)cin>>a[i];
ll ans=inf;
for(int i=0;i<=100;i++){
    ll res=0;
    for(int j=0;j<n;j++){
        ll d=abs(i-a[j]);
        res+=d*d;
    }
    chmin(ans,res);
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


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

vector<int> divisor(int n){
    vector<int> res;
    for(int i=1; i*i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

ll gcd(ll x, ll y){
  return y ? gcd(y, x%y) : x;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;cin>>N;
    vector<P> res;
    int dame=N;
    if(N%2==1) --dame;

    for(int i=1;i<=N;++i){
        for(int j=1;j<=N;++j){
            if(j<=i || j==dame) continue;
            res.push_back(P(i,j));
        }
        --dame;
    }
    cout<<res.size()<<endl;
    for(auto p:res){
        cout<<p.first<<" "<<p.second<<endl;
    }
}

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


void solve(){
  
}

int main() {
	// your code goes here
    
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    
    int ct = 1;
    while( a && c )
    {
        if(ct%2)
            c = max(0,c-b);
        else
            a = max(0,a-d);
        
        ct++;
    }
    
    if(ct%2 == 0)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 3600
//
// Created by yuu on 2019-07-07.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>

using namespace std;


int main(void){
    long L,R;
    cin>>L>>R;

    if(R-L>100010){
        cout<<0<<endl;
        return 0;
    }

    int min = 5000;
    for (long i = L; i <= R; ++i) {
        for (long j = i+1; j <= R; ++j) {
            int temp = i*j%2019;
            if(temp< min){
                min = temp;
            }
        }
    }


    cout<<min<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#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(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
/*bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}*/
int main(){
    int n, r;
    cin >> n >> r;
    if(n<10){
        cout << r+(100*(10-n)) << endl;
    }else cout << r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <cstdlib>
using namespace std;

typedef int INT;
#define int long long

int const X=-11111111111111LL;

int read(){
    string s;cin>>s;
    if(s=="x")return X;
    else{
        stringstream ss(s);
        int t;ss>>t;
        return t;
    }
}

string solve(vector<int> v){
    int N=v.size();
    bool none = false;
    for(int i=1;i<N;i++){
        if(v[i]==X && v[i-1]==X){
            none=true;
        }
        if(v[i-1]==X) continue;
        if(v[i]==X) continue;
        if(i%2==0){
            if(!(v[i-1]>v[i]))none=true;
        }else{
            if(!(v[i-1]<v[i]))none=true;
        }
        if(none)break;
    }
    if(none)return "none";

    int r =  1000000000+10;
    int l = -1000000000-10;
    for(int i=0;i<N;i++){
        if(v[i]!=X) continue;
        if(i%2==0){
            if(i>0)   r=min(r,v[i-1]-1);
            if(i<N-1) r=min(r,v[i+1]-1);
        }else{
            if(i>0)   l=max(l,v[i-1]+1);
            if(i<N-1) l=max(l,v[i+1]+1);
        }
    }
    if(l==r){ return [](int l){
            stringstream ss;
            ss << l;
            return ss.str();
        }(l);
    }
    else if(l > r) return "none";
    else return "ambiguous";
}

INT main() {
    int N;
    while(cin>>N && N){
        vector<int> v(N);
        for(int i=0;i<N;i++)v[i]=read();
        cout << solve(v) << endl;
    }
}

Measured memory_bytes: 1268
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int MOD(long x) {
  return x % 1000000007;
}

int main() {
  int N; cin >> N;
  int n[N];
  int memo[N];
  for (int i = 0; i < N; i++) {
    n[i] = 0;
    memo[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    cin >> n[i];
    memo[n[i]]++;
  }

  for (int i = N % 2 == 0 ? 1 : 0; i < N; i+= 2) {
    if (memo[i] != (i == 0 ? 1 : 2)) {
      cout << 0 << endl;
      return 0;
    }
  }
  long a = 1;
  for (int i = 0; i < N / 2; i++) {
    a = MOD(a * 2);
  }
  cout << a << endl;
}


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

void Main()
{
    int a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    b = abs(b - a);
    if(v <= w){
        cout << "NO" << endl;
        return;
    }
    int xa = v * t;
    int xb = b + w * t;
    if(xb <= xa){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}

template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind() {double x; scanf("%lf", &x); return x;}

///*....Bitmask....*///
int set_1(int n, int pos) {return n = (n | (1 << pos));}
int reset_0(int n, int pos) {return n = n & ~(1 << pos);}
bool check_bit(int n, int pos) {return n = n & (1 << pos);}

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

///*....Constraints....*///
const int N = (int) 2000 + 5;
const ll M = (ll) 1e9 + 7;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;

ll dp[N];

int n;
ll f(int sum) {
  if (sum == n)return 1ll;

  ll &ret = dp[sum];
  if (ret != -1)return ret;

  ll res = 0ll;
  for (int i = 3; i <= (n - sum); ++i) {
    int p = sum + i;
    if (p != n - 1 and p != n - 2) {
      ll k = f(p);
      res += k;
      if (res >= M)res %= M;
    }
  }
  return ret = res;
}

int main()
{

  Int(n);
  memset(dp, -1, sizeof(dp));
  ll res = f(0);

  printf("%lld\n", res);

  //printf("Case %d: ",++te);


  // cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
  return 0;
}






Measured memory_bytes: 3632
#include <stdio.h>

int main()
{
  int ret, N, A, B;
  int train;

  ret = scanf("%d %d %d", &N, &A, &B);
  train = N * A;
  if ( train < B )
    printf("%d\n", train);
  else
    printf("%d\n", B);
  return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) {if(a>b) {a=b;return true;} return false;}
const ll INF = 1LL<<60;
#define ASSERT(C, ...) assert( (C) || (PRINT(__VA_ARGS__), false) )
template <class Head> void PRINT(Head head) {
    std::cout << head << "\n";
}
template <class Head, class... Tail> void PRINT(Head head, Tail... tail) {
    std::cout << head << " ";
    PRINT(tail...);
}

ll solve() {
    ll N;
    cin >> N;
    vector<vector<ll>> A(N,vector<ll>(N));
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < N; j++ ) {
            cin >> A[i][j];
        }
    }
    vector<vector<ll>> B(N,vector<ll>(N));
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < N; j++ ) {
            B[i][j] = A[i][j];
        }
    }
    vector<vector<int>> C(N,vector<int>(N,1));
    for ( int k = 0; k < N; k++ ) {
        for ( int i = 0; i < N; i++ ) {
            for ( int j = 0; j < N; j++ ) {
                if ( i == k || j == k ) continue;
                ll d = B[i][k] + B[k][j];
                if ( d == A[i][j] ) C[i][j] = 0;
                else if ( d < A[i][j] ) {
                    return -1;
                }
                chmin( B[i][j], d );
            }
        }
    }

    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        for ( int j = i + 1; j < N; j++ ) {
            if ( B[i][j] != A[i][j] ) {
                return -1;
            }
            if ( C[i][j] == 1 ) ans += A[i][j];
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char* argv[]) {
  string A, B;
  cin >> A >> B;

  if (A.size() > B.size()) {
    cout << "GREATER" << endl;
    return 0;
  } else if (A.size() < B.size()) {
    cout << "LESS" << endl;
    return 0;
  }

  for (int i = 0; i < A.size(); ++i) {
    if (A[i] > B[i]) {
      cout << "GREATER" << endl;
      return 0;
    } else if (A[i] < B[i]) {
      cout << "LESS" << endl;
      return 0;
    }
  }

  cout << "EQUAL" << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    n, m = map(int,(input().split()))
    inlis = []
    lis_1 = []
    lis_n = []

    for _ in range(m):
        a, b = map(int, input().split())
        #print(a, b)
        if a == 1:
            lis_1.append(b)
            #print(lis_1)
        if b == n:
            lis_n.append(a)
            #print(lis_n)
    #print(lis_1, lis_n)
    set_1 = set(lis_1)
    set_n = set(lis_n)
    #print(set_1, set_n)
    if set_1 & set_n:
        #print(set_1 & set_n)
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 72408
#include "bits/stdc++.h"
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")

using namespace std;

using ll = long long;
#define all(x) begin(x), end(x)
const int MAXN = 1e5 + 10;
const int INF = 2*1e9;

int dp[MAXN];
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
	int n, k; cin >> n >> k;
	vector<int> h(n);
	for(int i{}; i<n; i++) cin >> h[i];
	dp[1] = abs(h[1]-h[0]);
	for(int i{2}; i<n; i++){
		// i'ye gelmek icin olan deger
	int mindeg = INT_MAX;
	for(int j{1}; j<=k && i-j>=0; j++){
		mindeg = min(mindeg, dp[i-j]+abs(h[i]-h[i-j]));
}
		dp[i] += mindeg;
		}

	cout << dp[n-1] << "\n";





}


Measured memory_bytes: 4024
N = int(input())
XYI = [tuple(map(int,input().split() + [i])) for i in range(N)]
sx = sorted(XYI, key=lambda x:x[0])
sy = sorted(XYI, key=lambda x:x[1])

es = []
for (x0,_,i0),(x1,_,i1) in zip(sx,sx[1:]):
  es.append((x1-x0, i0, i1))
for (_,y0,i0),(_,y1,i1) in zip(sy,sy[1:]):
  es.append((y1-y0, i0, i1))
es.sort(key=lambda x:x[0])
 
class UnionFind:
  def __init__(self,N):
    self.parent = [i for i in range(N)]
    self._size = [1] * N
    self.count = 0
  def root(self,a):
    if self.parent[a] == a:
      return a
    else:
      self.parent[a] = self.root(self.parent[a])
      return self.parent[a]
  def is_same(self,a,b):
    return self.root(a) == self.root(b)
  def unite(self,a,b):
    ra = self.root(a)
    rb = self.root(b)
    if ra == rb: return
    if self._size[ra] < self._size[rb]: ra,rb = rb,ra
    self._size[ra] += self._size[rb]
    self.parent[rb] = ra
    self.count += 1
  def size(self,a):
    return self._size[self.root(a)]

uf = UnionFind(N)
ans = 0
for d,a,b in es:
  if uf.is_same(a,b): continue
  uf.unite(a,b)
  ans += d
print(ans)

Measured memory_bytes: 53200
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
 
void fio() 
{
    std::ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
void inputread()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}
const ld p=6.28318530717958623200;

int32_t main()
{
    fio();
    ll n,i,k;
    cin >> n;
    vector<ll> a(n+5,0);
    
    for(i=1;i<n;i++)
    {
        cin >> k;
        a[k]++;
    }

    for(i=1;i<=n;i++)
    {
        cout << a[i] <<"\n";
    }
    

    return 0;
}

Measured memory_bytes: 4784
function Main(input){
	input = input.split("\n");
  var NQ = input.shift().split(" ");
  var N = ~~NQ[0];
  var Q = ~~NQ[1];
  var S = input.shift();
  var lr = input;
  
  var sum = [0];
  
  for(var i = 1 ; i < N; i++){
  	var a = S[i-1];
    var c = S[i];
    if(a == 'A' && c == 'C'){
    	sum[i] = sum[i-1] + 1;
    }else{
    	sum[i] = sum[i-1];
    }
  }
  
  var r = "";
  
  for(var i = 0; i < Q; i++){
  	if(i!= 0)r+="\n";
  	var el = lr[i].split(" ");
    var ooo = ~~el[0];
    var fourze = ~~el[1];
    r += (sum[fourze-1]-sum[ooo-1]);
  }
  
  return r;
  
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
8 3
ACACTACG
3 7
1 1
1 8
`);

Measured memory_bytes: 53456
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

ll llmax(ll a, ll b){
    if(a > b){
        return a;
    } else {
        return b;
    }
}

int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    ll resA = llmax(0, a - k);
    ll resB = 0;
    if(resA == 0){
        resB = llmax(0, b - (k - a));
    } else {
        resB = b;
    }
    cout << resA << " " << resB << endl;
    return 0;
}


Measured memory_bytes: 256
n,m=map(lambda x: int(x), input().split())
INF=10**12
dp=[INF]*n
for _ in range(m):
    dp[int(input())-1]=0
dp[0]=1 if dp[0]==INF else 0
if n>1:
    dp[1]=dp[0]+1 if dp[1]==INF else 0
if n>2:
    for i in range(2, n):
        if dp[i]==0:
            continue
        dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
print(dp[n-1])

Measured memory_bytes: 6900
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	s := r.nextString()
	r.Scan(true)
	t := r.nextString()

	ans := 0
	for i := range s {
		if s[i] == t[i] {
			ans++
		}
	}
	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>


using namespace std;

int main(){
  int a,b,c[110],ans = 0;
  
  cin >> a >> b;
  
  for(int i=0;i<a;i++)
    cin >> c[i];
  
  for(int i=0;i<a;i++){
    ans += c[i];
  }
  
  sort(c,c+a,greater<int>());
  
  if(ans <= c[b-1]*4*b){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
		for (int i = 0; i < N; i++) {
			H -= sc.nextInt();
		}
		System.out.println(H <= 0 ? "Yes" : "No");
	}
}

Measured memory_bytes: 48300
N,M = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[1])
cnt = 1
cur = A[0][1]
for i in range(1,M):
    if A[i][0]<cur:continue
    cur = A[i][1]
    cnt += 1
print(cnt)   

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

int main(){
    int n;
    while(cin >> n){
        vector<int> a(1<<n);
        rep(i, 1<<n) cin >> a[i];
        while(a.size() > 1){
            vector<int> b;
            rep(i, a.size()/2){
                b.push_back(abs(a[i*2] - a[i*2+1]));
            }
            a = b;
        }
        cout << a[0] << endl;
    }
}


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

using namespace std;

int n, cnt[2], ans = INT_MAX;
map<int, int> m[2];
map<int, int>::iterator it;
vector<pair<int, int>> v[2];
set<int> s;
int ta, tb;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &ta);
		cnt[i & 1]++;
		m[i & 1][ta]++;
	}
	for (int i = 0; i < 2; i++) {
		v[i].emplace_back(0, -1 - i);
		for (it = m[i].begin(); it != m[i].end(); it++)
			v[i].emplace_back(it->second, it->first);
		sort(v[i].begin(), v[i].end());
	}
	for (int j = 0; j < min(3, (int)v[0].size()); j++)
		for (int k = 0; k < min(3, (int)v[1].size()); k++) {
			auto& pa = v[0][v[0].size() - 1 - j];
			auto& pb = v[1][v[1].size() - 1 - k];
			if (pa.second != pb.second)
				ans = min(n - pa.first - pb.first, ans);
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 6136
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
const int MAX=1000000007;

int dp[(1<<18)][20];

int main() {
  int n,m,l,s,t;
  while(cin >> n >> m >> l >> s >> t && n) {
    int v[n+1][n+1];
    fill(v[0],v[n+1],MAX);
    for(int i=0; i<m; i++) {
      int x,y,z;
      cin >> x >> y >> z;
      v[x][y]=z;
      v[y][x]=z;
    }
    for(int i=1; i<=n; i++) v[i][i]=0;
    for(int k=1; k<=n; k++) {
      for(int i=1; i<=n; i++) {
	for(int j=1; j<=n; j++) {
	  if(v[i][k]!=MAX && v[k][j]!=MAX) v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
	}
      }
    }
    P r[l+1];
    for(int i=0; i<l; i++) cin >> r[i].F >> r[i].S;
    r[l].F=s;r[l].S=0;
    l++;

    fill(dp[0],dp[(1<<l)],MAX);
    dp[0][l-1]=0;
    /*
    for(int i=0; i<l; i++) {
      dp[(1<<i)][l-1]=v[r[i].F][s]+r[i].S;
      if(dp[(1<<i)][l-1]>t) dp[(1<<i)][l-1]=MAX;
    }
    */
    int ans=0;
    for(int p=0; p<(1<<l); p++) {
      for(int i=0; i<l; i++) {
	if(dp[p][i]!=MAX) {
	  if(i==l-1) {
	    int cnt=0;
	    for(int j=0; j<l-1; j++) {
	      if(p&(1<<j)) cnt++;
	    }
	    if(cnt>ans) ans=cnt;
	  }

	  for(int j=0; j<l; j++) {
	    if(!(p&(1<<j))) {
	      dp[p|(1<<j)][j]=min(dp[p|(1<<j)][j],dp[p][i]+v[r[j].F][r[i].F]+r[j].S);
	      if(dp[p|(1<<j)][j]>t) dp[p|(1<<j)][j]=MAX;
	    }
	  }
	}
      }
    }
    
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 13792