akhauriyash/Code-Regression huggingface dataset:
//写経　おぶ　すぬけ
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for (int i = 0 ; i <  (n) ; ++i) 
struct UnionFind {
	vector<int> d;
	UnionFind(int n=0): d(n,-1) {} //このコロンってなんですか
	int find(int x){
		if (d[x] < 0) return x; //x:根
		return d[x] = find(d[x]);//x:子 -> xの親の根を返す
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);//根同士をくっつける。
		if ( x ==  y) return false ; 
		/*連結成分が一致してるんだったらfalse返す。
			minimum spanning tree (クラスカル法と言うのをやるときに、くっつけたかどうかを取れると嬉しい.
			chmin/chmaxみたいなノリかな
		 */
		if ( d[x] > d[y]) swap(x,y);//xの方が大きいようにする（ただしサイズは負デモっているので不等号が逆）
		d[x] += d[y] ; //xにyをくっつける.
		d[y] = x;
		return true; 
	}
	bool same(int x, int y) { return find(x) == find(y) ; }
	int size(int x) { return -d[find(x)];}
};

int deg[100005];
vector<int> to[100005] ;
int main(){
	int n, m, k;
	cin >> n>> m>> k;
	UnionFind uf(n);
	rep(i,m){
		int a, b;
		cin >> a>> b;
		--a; --b;
		deg[a] ++ ;
		deg[b] ++ ;
		uf.unite(a,b);//degはフレンドの数かな そうです（そうなので）
	}
	rep(i,k){
		int a, b;
		cin >> a>> b;
		--a, --b ; //block関係
		to[a].push_back(b);
		to[b].push_back(a);
	}
	rep(i,n){
		int ans = uf.size(i)-1-deg[i]; //出力する答え、行ける場所 - 自分 - フレンドの数
		//ここからブロックしている人間をコロス
		for ( int u : to[i] ){
			if (uf.same(i,u)) --ans;
			//blockしてる人間が、同じ集合ないの人間だったらans-=1だよ
		}
		printf("%d%c", ans , i==n-1?'\n':' ');//改行とかスペース区切りのやつ
		//%cはフォーマット指定子"文字"
	}
}



Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	getline(cin,s);
	stringstream ss(s);
	string t;
	while (ss >> t)
	{
		cout << t[0];
	}
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> sum(M);
  for (int i = 0; i < M; i++) {
    cin >> sum.at(i);
  }
  
  int count = 0;
  for (int i = 0; i < M; i++) {
    count += sum.at(i);
  }
  
  if (count <= N) {
    cout << N - count << endl;
  }
  else cout << "-1" << endl;
  
}


Measured memory_bytes: 3648
#include<stdio.h>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a - b == 0 && a != c || a == c && a != b || b == c && b != a)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,Q;
int mo;
int A[101010],B[101010],C[101010];

int ok[1010101][2];

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<303030> uf;
int id(int v,int p,int par) { return v*6+p%3*2+par;}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>Q>>mo;
	int G=0;
	FOR(i,M) {
		cin>>A[i]>>B[i]>>C[i];
		A[i]--;
		B[i]--;
		if(i) G=__gcd(G,abs(C[i]-C[0]));
	}
	if(G==0) G=mo;
	mo=__gcd(mo,3*G);
	int c=C[0]%(3*G);
	
	ll a=c;
	FOR(i,2*mo) {
		ok[a][i%2]=1;
		a=a*2%mo;
	}
	
	FOR(i,M) {
		C[i]=(C[i]-c+3*G)/G%3;
		FOR(x,3) {
			uf(id(A[i],x,0),id(B[i],2*x+C[i],1));
			uf(id(A[i],x,1),id(B[i],2*x+C[i],0));
			uf(id(B[i],x,0),id(A[i],2*x+C[i],1));
			uf(id(B[i],x,1),id(A[i],2*x+C[i],0));
		}
	}
	
	FOR(i,Q) {
		cin>>x>>y>>r;
		x--,y--;
		int ret=0;
		FOR(j,3) FOR(k,2) if(uf[id(y,0,0)]==uf[id(x,j,k)]) {
			int dif=(r+c-j*G+3*G+3*mo)%mo;
			if(ok[dif][k]) ret=1;
		}
		if(ret) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1);

    const int MAX = 105;
    for (int x = 1; x < MAX; x++) {
        for (int y = 1; y < MAX; y++) {
            for (int z = 1; z < MAX; z++) {
                int tmp = x * x + y * y + z * z + x * y + y * z + x * z;
                if (tmp > N) continue;
                A[tmp]++;
            }
        }
    }

    for (int i = 1; i <= N; i++) {
        cout << A[i] << endl;
    }
}

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

int main()
{
	int ans = 0;
	int N, X;
	
	do{
		cin >> N >> X;
		ans = 0;
		
		if( N == 0 && X == 0 )break;
		
		for(int i = 1; i <= N - 2; i++){
			for(int j = i + 1; j <= N - 1; j++){
				for(int k = j + 1; k <= N; k++){
					if( i + j + k == X ){
						ans++;
					}
				}
			}
		}
		cout << ans << endl;
		
	}while( 1 );

	return 0;
}

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

int main() {
  int n,ans=0;
  cin>>n;
  vector<int>wei(n);
  rep(i, n){
    cin>>wei[i];
    ans+=wei[i];
  }
  int j=0;
  while(ans>0){
    ans-=2*wei[j];
    j++;
  }
  
  cout<<min(ans*(-1),ans+2*wei[j-1])<<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 INF 114514
using namespace std;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A,B,C,D,E,F;
	float anss=0,answ=1;
	cin >> A >> B >> C >> D >> E >> F;
	vector<float> w;
	vector<float> s;
	int n;
	rep(i,30){
		rep(j,30){
			if (100*A*i+100*B*j<=F){
				w.push_back(100*A*i+100*B*j);
			}else{
				break;
			}
		}
	}
	rep(i,1000){
		rep(j,1000){
			if(C*i+D*j<=F){
				s.push_back(C*i+D*j);
			}else{
				break;
			}
		}
	}
	for(int i=1;i<w.size();i++){
		rep(j,s.size()){
			if (s[j]<=w[i]*E/100){
				if (100*anss/(anss+answ)<=100*s[j]/(w[i]+s[j])&&w[i]+s[j]<=F){
					anss=s[j];
					answ=w[i];
				}
			}
		}
	}
	cout << answ+anss << " " << anss << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define FOR(i, N) for (long i = 0; i < (N); i++)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string N;
    cin >> N;
    int sum = 0;
    FOR(i, N.size()) {
        sum += N[i] - '0';
    }

    if (sum % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int p=0;
    long long sum=0;
    p=min(k,a);
    k-=p;
    sum+=p;
    p=min(k,b);
    k-=p;
    p=min(k,c);
    k-=c;
    sum+=(p*(-1));
    cout<<sum<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
inline int R()
{
	char c;int sign=1,res=0;
	while((c=getchar())>'9'||c<'0') if(c=='-') sign=-1;
	res+=c-'0';
	while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
	return res*sign;	
}
int main()
{
	int n,m,k;
	n=R();m=R();
	k=R();
	printf("%d\n",(k-1)/max(n,m)+1);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, k;

	cin >> n >> k;

	ll cnt1 = 0;
	ll cnt2 = 0;

	FOR(i, 1, n + 1) {
		if (i % k == 0) {
			cnt1++;
		}
		else if (k % 2 == 0 && i % k == k / 2) {
			cnt2++;
		}
	}

	ll ans = pow(cnt1, 3) + pow(cnt2, 3);

	cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|_
//g++ -std=c++1z temp.cpp
//./a.out

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
    int n,p,i,j,ans;
    bool ch;
    while(1){
        cin>>n>>p;
        if(n==0&&p==0)break;
        
        vector<int> v(n,0);
        j=0;
        while(1){
            j%=v.size();
            if(p>0){
                v[j]++;
                p--;
            }
            else{
                p=v[j];
                v[j]=0;
            }
            ch=false;
            ans=-1;
            if(p==0){
                rep(i,v.size()){
                    if(ans==-1&&v[i]>0){
                        ans=i;
                        ch=true;
                    }
                    else if(v[i]>0){
                        ch=false;
                        break;
                    }
                }
                if(ch){
                    
                    fin(ans);
                    break;
                }
            }
            j++;
        }
    }
    
//////////////////////////////////////////////////////
return 0;}











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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long

int main(){
  int n, m, x, result = 0, sum = 0;
  cin >> n >> m >> x;
  int a[n] = {0};
  rep(i, m){
    int tmp;
    cin >> tmp;
    a[tmp] = 1;
  }

  FOR(i, 0, x){
    sum += a[i];
  }
  FOR(i, x, n){
    result += a[i];
  }
  result = min(result, sum);
  puts(result)
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define sd(a) scanf("%lld",&a)
#define pd(a) printf("%lld",a)
using namespace std;
const int maxn=1e3+10;
int a[maxn][maxn];
int dur[maxn];
bool vis[maxn];
main(){
    int n;
    sd(n);
    for(int i=1;i<=n;++i)dur[i]=1ll;
    for(int i=1;i<=n;++i)
    for(int j=1;j<n;++j)sd(a[i][j]);
    int day=0;
    while(1){
        day++;
        memset(vis,false,sizeof(vis));
        bool flag=true;
        for(int i=1;i<=n;++i){
            int to=a[i][dur[i]];
            if(dur[i]==n||vis[i]||vis[to]||a[to][dur[to]]!=i||dur[to]==n)continue;
            else {
                flag=false;
                vis[i]=true;
                vis[to]=true;
                dur[i]++;
                dur[to]++;
            }
        }
        if(flag)break;
    }
    for(int i=1;i<=n;++i){
        if(dur[i]!=n){
            puts("-1");
            return 0;
        }
    }
    pd(day-1);
    puts("");
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll=long long;

const int N=5e3+10;

int main(){
    string s;
    cin>>s;
    int n=s.length();
    for(int i=0; i<n; i++){
        cout<<'x';
    }
}



















Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
#define MAX 500000
#define INFTY 1000000000
 
void MargeSort(int *,int,int);
void Marge(int *,int,int,int);
 
int count=0;
 
int main(void){
  int n,i,A[MAX];
 
  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%d", &A[i]);
 
  MargeSort(A,0,n);
  //for(i=0;i<n;i++) printf("%d", A[i]);
  //printf("\n");
 
  for(i=0;i<n;i++){
    if(i!=n-1) printf("%d ",A[i]);
    else printf("%d\n", A[i]);
  }
  printf("%d\n", count);
 
  return 0;
}
 
void MargeSort(int *A,int left, int right){
  int mid;
 
  if(left+1<right){
    mid=(left+right)/2;
    MargeSort(A,left,mid);
    MargeSort(A,mid,right);
    Marge(A,left,mid,right);
  }
 
}
 
void Marge(int *A,int left, int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int L[n1+1],R[n2+1];
  int i,j,k;
 
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
 
  L[n1]=INFTY; R[n2]=INFTY; i=0; j=0;
 
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    } else {
      A[k]=R[j];
      j++;
    }
    count++;
  }
 
}

Measured memory_bytes: 4504
A,B,M=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
x=[]
y=[]
c=[]
ans=10**7
for _ in range(M):
    i,j,k=map(int,input().split())
    #print(a[i-1]+b[j-1]-k)
    ans = min(ans,a[i-1]+b[j-1]-k)
a.sort()
b.sort()
min_=a[0]+b[0]
print(min(ans,min_))

Measured memory_bytes: 67820
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
    int n;
    string s;
    map<string,int> mp;
    cin >> n;
    rep(i,n){
        cin >> s;
        mp[s]++;
    }
    cout << mp.size() << endl;
    return 0;
}

Measured memory_bytes: 19248
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}
long double pi = acos(-1);

signed main (){
  int A,B,H,M;
  cin >> A >> B >> H >> M;
 long double theta = 5.5 *(H*60.+M)*pi/180.;
   long double ans = sqrt(sq(A) + sq(B) -2.*A*B*cos(theta));
   printf ("%.15Lf",ans); 
    return 0;
}


Measured memory_bytes: 4148
#include<stdio.h>
#include<string.h>
#include<utility>
#include<queue>
using namespace std;
typedef struct P{int rh,rw,lh,lw,d;}P;
struct Order{bool operator ()(P const&a, P const&b) const{return a.d>b.d;}};

int W,H,i,j,rh,rw,lh,lw,f;
int rm[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int lm[4][2]={{0,-1},{0,1},{1,0},{-1,0}};
bool dp[55][55][55][55];
char M[55][110]={0},t;

int main()
{
	for(;scanf("%d%d\n",&W,&H),W;)
	{
		memset(M,0,sizeof(M));
		memset(dp,0,sizeof(dp));
		for(i=1;i<=H;i++)
			for(j=1;j<=2*W+2;j++)
			{
				t=getchar();
				if(t=='R'){rh=i;rw=j;t='.';}
				if(t=='L'){lh=i;lw=j;t='.';}
				M[i][j]=t;
			}
		priority_queue<P,vector<P>,Order>Q;
		P p={rh,rw,lh,lw,0};
		Q.push(p);
		for(f=0;!Q.empty();)
		{
			p=Q.top();Q.pop();
			if(M[p.rh][p.rw]=='%'&&M[p.lh][p.lw]=='%'){f=1;break;}
			if(M[p.rh][p.rw]=='%'||M[p.lh][p.lw]=='%'||p.d==1500)
				continue;
			for(i=0;i<4;i++)
			{
				P ins={p.rh,p.rw,p.lh,p.lw,p.d+1};
				if(M[p.rh+rm[i][0]][p.rw+rm[i][1]]=='.'||M[p.rh+rm[i][0]][p.rw+rm[i][1]]=='%'){ins.rh+=rm[i][0];ins.rw+=rm[i][1];}
				if(M[p.lh+lm[i][0]][p.lw+lm[i][1]]=='.'||M[p.lh+lm[i][0]][p.lw+lm[i][1]]=='%'){ins.lh+=lm[i][0];ins.lw+=lm[i][1];}
				if(!dp[ins.rh][ins.rw][ins.lh][ins.lw-W-1])
				{
					dp[ins.rh][ins.rw][ins.lh][ins.lw-W-1]=1;
					Q.push(ins);
				}
			}
		}
		puts(f?"Yes":"No");
	}
	return 0;
}

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

#define FST first
#define SCD second
#define MODP 1000000007

typedef long long LL;
typedef pair<int, int> PA;

int cmp(PA x, PA y) {
    return x.SCD < y.SCD;
}

int main() {
#ifdef FDB
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n, m, k;
    cin>>n;
    int mi = n + 1, cnt = 0;
    for (int i=0;i<n;++i) {
        int x;
        scanf("%d", &x);
        if (x<=mi) cnt += 1;
        mi = min(x, mi);
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	forci(0,n)	cin>>a[i];
	sort(a,a+n);
	int sum=0;
	for(int i=0;i<k;i++)	sum+=a[i];
	cout<<sum<<endl;

	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}






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

int main() {
  int N; 
  cin>>N;
  int sum;
  int X=N;
  while(X>0){
    sum += X%10;//1の位を足す
    X /= 10;//1の位を消す
  }
  if(N%sum==0)puts("Yes");
  else puts("No");
  return 0;
}

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

int main(void) {
	// Your code here!
	int n, c, p, t=0, M;
	cin >> n >> c;
	for (int i = 0; i < c; i++) {
		cin >> p;
		t = t + p;
	}
	n++;
	M = t / n;
	if (t%n > 0) {
		M++;
	}
	printf("%d\n", M);
}


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

#define esp 1e-9

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n;
	cin>>n;
	map<long long int,long long int> m;
	set<long long int> s;
	while(n--){
		long long int x;
		cin>>x;
		m[x]++;
		s.insert(x);
	}
	set<long long int>::iterator it;
	long long int maxx=0;
	for(it=s.begin();it!=s.end();it++){
		maxx=max(maxx,(m[*it]+m[*it+1]+m[*it-1]));
	}
	cout<<maxx;
	return 0;
}

Measured memory_bytes: 12348
#include "bits/stdc++.h"

using namespace std;

//typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)



signed main(){

	int N;
	int a[123456], b[123456];
	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> a[i];
	}
	int sum = 0;
	for (int i = 0; i < N; i++){
		cin >> b[i];
		a[i] -= b[i];
		sum += a[i];
	}
	if (sum < 0){
		cout << -1 << endl;
		return 0;
	}

	sort(a, a + N);

	int ans = 0;
	sum = 0;
	for (int i = 0; i < N; i++){
		if (a[i] < 0){ 
			sum += a[i];
			ans++;
		}
	}

	if (ans == 0){
		cout << ans << endl;
		return 0;
	}

	for (int i = N - 1; i >= 0; i--){
		sum += a[i];
		ans++;
		if (sum >= 0){
			cout << ans << endl;
			return 0;
		}
	}


	return 0;
}


Measured memory_bytes: 1792
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out = "";
    while (scanner.hasNext()) {
      int a = scanner.nextInt() + scanner.nextInt();
      out += Integer.toString(a).length() + "\n";
    }
    System.out.print(out);
  }
}

Measured memory_bytes: 20512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		sc.close();
		String rs = String.valueOf(S);
		int num = rs.length();

		for(int i=0; i<num; i++) {
			System.out.print(S[i]);
			System.out.print(T[i]);
		}
	}
}


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

int main() {
  char c;
  int num = 0;
  for (int i = 0; i < 4; i++) {
    cin >> c;
    if (c == '-') {
      num--;
    } else if (c == '+') {
      num++;
    }
  }
  cout << num << endl;
  
  return 0;
}
  


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n, max = -1;
	string s;
	map<string, int> res;
	map<string, int>::iterator it;
	vector<string> v;
	
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> s;
		res[s]++;
		max = (res[s] > max) ? res[s] : max;
	}
	
	for (it = res.begin(); it != res.end(); it++) {
		if (it->second == max) cout << (it->first) << endl;
	}
	
    return 0;
}


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

using namespace std;

int main() {
  int x, y;
  cin >> x >> y;

  for (int i = 0; i <= x; ++i) {
    int nx = i;
    int ny = x - nx;
    if ((nx * 2 + ny * 4) == y) {
      puts("Yes");
      return 0;
    }
      
  }
  puts("No");
  return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, K;
        cin >> N >> K;
        vll p(N);
        rep(i, 0, N) cin >> p[i];
        sort(all(p));
        cout << accumulate(p.begin(), p.begin()+K, 0LL) << endl;
}

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


int main()
{
	int n,m,a,b;
	string s,t="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>s;
			if(s=="snuke")
			{
				a=i;
				b=j;
			}
		}
	}
	cout<<t[b]<<a<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;

int main(void) {
  int x;
  cin >> x;
  int i = 1;
  while(1) {
    if (x * i % 360 == 0) {
      cout << i << endl;
      return 0;
    }
    i++;
  }
  return 0;
}


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

#define tt template<typename T> ostream& operator <<(ostream& os, const
#define tuv template<typename U, typename V> ostream& operator<<(ostream& os, const
tt vector<T>& v)            { os << "["; for(auto & x : v) os << " " << x; os << " ]"; return os; }
tt vector<vector<T> >& m)   { for(auto & x : m) { for(auto & y : x) os << y << " "; os << "\n"; } return os; }
tt set<T>& s)               { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt unordered_set<T>& s)     { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt queue<T>& q)             { queue<T> q2(q); while(!q2.empty()) { os << q2.front() << " "; q2.pop(); } return os; }
tt stack<T>& s)             { stack<T> s2(s); while(!s2.empty()) { os << s2.top() << " "; s2.pop(); } return os; }
tuv pair<U,V>& p)           { os << "(" << p.first << "," << p.second << ")"; return os; }
tuv map<U,V>& m)            { os << "{ "; for(auto & x : m) os << x.first << ":" << x.second << " "; os << "}"; return os; }
tuv unordered_map<U,V>& um) { os << "{ "; for(auto & x : um) os << x.first << ":" << x.second << " "; os << "}"; return os; }


int main(int argc, char * argv[])
{
    std::ios_base::sync_with_stdio(false);    
    std::cin.tie(NULL);

    int n;
    std::cin >> n;
    
    int digit = n % 10;
    if(digit == 2 || digit == 4 || digit == 5 || digit == 7 || digit == 9)
    {
	std::cout << "hon" << std::endl;
    }
    else if(digit == 0 || digit == 1 || digit == 6 || digit == 8)
    {
	std::cout << "pon" << std::endl;
    }
    else if(digit == 3)
    {
	std::cout << "bon" << std::endl;
    }


    return 0;
}


Measured memory_bytes: 3648
a = input()
b = input()
c = input()

aa = len(a)
bb = len(b)
cc = len(c)

lensum = aa + bb + cc # 文字列の長さの最大値
ab = [0]*(lensum+cc+1) # 相対的位置に対して合わさるかどうかを記録
ac = [0]*(lensum+bb+1)
bc = [0]*(lensum+aa+1)

def match(v,w): # 2つの文字を合わせられるかどうかを調べる
    if(v != '?' and w != '?' and v != w):
        return 0
    else:
        return 1

def match2(A,B,k): # 2つの文字列とその相対的位置に対して合わさるかチェック
    AA = len(A)
    BB = len(B)
    if(k>=AA):
        return 1
    elif(k<-BB):
        return 1
    else:
        flg = 1
        st = max(0,k)
        la = min(AA,BB+k)
        for i in range(st,la):
            if(match(A[i],B[i-k])==0):
                flg = 0
                break
        return flg

#ab,ac,bcに対して計算する
for i in range(lensum+cc+1):
    ab[i] = match2(a,b,i-bb-cc)
for i in range(lensum+bb+1):
    ac[i] = match2(a,c,i-bb-cc)
for i in range(lensum+aa+1):
    bc[i] = match2(b,c,i-aa-cc)

def milen(a,b,c):
    minlen = lensum # 文字列の長さの最大値
    for i in range(-bb-cc,aa+cc+1): # iが文字列Bの開始位置
        for j in range(-bb-cc,aa+bb+1): # jが文字列Cの開始位置
            if(ab[i+bb+cc] == 0): 
                continue
            elif(ac[j+bb+cc] == 0):
                continue
            elif(j-i+aa+cc < 0 or j-i+aa+cc >= lensum+aa+1): #BとCが離れすぎている場合を除く
                continue  
            elif(bc[j-i+aa+cc] == 0):
                continue   
            else:
                sta = min(0,i,j) #文字列の中で一番左にある開始位置
                en = max(aa,i+bb,j+cc) #文字列の中で一番右にある終了位置
                minlen = min(minlen,en-sta) #更新
    return minlen

print(milen(a,b,c))

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

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

    map<ll, ll> mp;

    ll point = 1;
    ll loop, start;
    vector<ll> vec;
    for (int i = 0; i <= n+3; i++) {
        if (mp.count(point)) {
            start = mp[point];
            loop = i - start;
            break;
        }
        //cout << point << endl;
        vec.push_back(point);
        mp[point] = i;
        point = a[point];
        
    }
    //cout << a[6] << endl;

    //for (ll x : vec) cout << x << endl;
    if (k < start) {
        cout << vec[k] << endl;
        return 0;
    }
    //cout << loop << endl;
    //cout << start << endl;
    k -= start;
    ll p = k%loop;
    ll ans = vec[start + p];
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 18616
#include<bits/stdc++.h>
using namespace std;
 
main()
{
  int n;
  int c[501];
  int s[501];
  int f[501];
  int t[501];
  
  cin >> n;
  for(int i=0;i<n-1;i++)
    cin >> c[i] >> s[i] >> f[i];
 
  for(int i=0;i<n;i++){
    int ans=0;
    for(int j=i;j<n-1;j++){
      if(ans<s[j])
        ans=s[j];
      else if(ans%f[j]!=0){
        int k;
        for(k=1;f[j]*k<ans;k++);
        ans+=(f[j]*k)-ans;
      }
      ans+=c[j];
    }
    cout << ans << endl;
  }
  
  return (0);
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n; R(n);
    int an=0;
    VI a(n),b(n);
    REP(i,n){
        R(a[i]);
    }
    REP(i,n)R(b[i]);
    REP(i,n)an+=max(0,a[i]-b[i]);
    W(an);
    return 0;
}


Measured memory_bytes: 256
def main():
    
    inp = input()
    x = int(inp.strip())

    maxi = 1
    for i in range(1, x):
        for j in range(2, 11):
            if i ** j <= x:
                maxi = max(maxi, i**j)
    
    print(maxi)

if __name__ == '__main__':
    main()

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

int main(){
  int a, n;
  int min, max;
  long long int sum;
  min = 9999999;
  max = -9999999;
  sum = 0;
  cin >> n;
  rep(i, n) {
    cin >> a;
    if (a < min) min = a;
    if (max < a) max = a;
    sum += a;
  }
  printf("%d %d %lld\n", min, max, sum);
  return 0;
}



Measured memory_bytes: 3208
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    sump=0
    summ=0
    minm=-10**9
    minp=10**9
    countm=0
    for i in range(n):
        if a[i]>=0:
            sump+=a[i]
            minp=min(minp,a[i])
        else:
            countm+=1
            summ+=a[i]
            minm=max(minm,a[i])
    #print(sump,summ,countm,minm,minp)
    if countm%2==0:
        return sump-summ
    else:
        return sump-summ-min(minp,abs(minm))*2

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

    

Measured memory_bytes: 20084
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
        
        while(true){
        	int H=sc.nextInt();
        	int W=sc.nextInt();
            if(H==0&&W==0)
                break;
        
        	for(int i=0;i<H;i++){
        		for(int j=0;j<W;j++){
                    if(i==0||j==0||i==H-1||j==W-1)
                    	System.out.print("#");
                    else
                        System.out.print(".");
            	}
           	 System.out.println();
            }
            System.out.println();
        }
	}
}



Measured memory_bytes: 35952
x = int(input())

item_count = x // 100
amari = x % 100

for i in range(item_count):
  for j in range(5, 0, -1):
    if amari - j >= 0:
      amari -= j
      break
  if amari == 0:
    break
if amari == 0:
  print(1)
else:
  print(0)

Measured memory_bytes: 38384
<?php
  $n = (int)trim(fgets(STDIN));
  $l = explode(" ", trim(fgets(STDIN)));
  sort($l);
//   print_r($l);
  $cnt = 0;
  for($i=0; $i<$n; $i++){
      for($j=$i+1; $j<$n; $j++){
          $top = $j;
          $btm = $n;
          $ab = $l[$i]+$l[$j];
          while($top+1 < $btm){
              $cen = intdiv($top+$btm,2);
              if($ab > $l[$cen]){
                  $top = $cen;
              }else{
                  $btm = $cen;
              }
          }
          $cnt += ($top-$j);
      }
  }
  echo $cnt;


Measured memory_bytes: 16332
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

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

int main() {
  int N, ga, sa, ba, gb, sb, bb;
  cin >> N;
	cin >> ga >> sa >> ba >> gb >> sb >> bb;
  vector<long long> dp1, dp2;

	// A, B1 後の最大ドングリ数を求める．
	dp1.push_back(0); // dp1[0] = 0;
	for(int i=1; i<N+1; i++) {
		long long dg=0, ds=0, db=0; // ドングリが少なく，金属が一個も買えないときドングリi個のまま
		if(i>=ga) dg = dp1[i-ga] + gb;
		if(i>=sa) ds = dp1[i-sa] + sb;
		if(i>=ba) db = dp1[i-ba] + bb;
		long long dd = dp1[i-1] + 1;
		dp1.push_back(max(max(dd, dg), max(ds, db)));
	}

	//cout << dp1[N] << endl;

	// B2, A 後の最大ドングリ数を求める．
	dp2.push_back(0); // dp2[0] = 0;
	for(int i=1; i<dp1[N]+1; i++) {
		long long dg=0, ds=0, db=0; // ドングリが少なく，金属が一個も買えないときドングリi個のまま
		if(i>=gb) dg = dp2[i-gb] + ga;
		if(i>=sb) ds = dp2[i-sb] + sa;
		if(i>=bb) db = dp2[i-bb] + ba;
		long long dd = dp2[i-1] + 1;
		dp2.push_back(max(max(dd, dg), max(ds, db)));
	}

	cout << dp2[dp1[N]] << endl;

  return 0;
}


Measured memory_bytes: 264476
N, W = map(int, input().split())

VW = tuple(map(int, input().split()) for _ in range(N))

dp = [0] * (W + 1)
for v, w in VW:
    for i in reversed(range(w, W + 1)):
        dp[i] = max(dp[i], dp[i - w] + v)

ans = dp[W]
print(ans)


Measured memory_bytes: 5980
<?php
  fscanf(STDIN, "%d%d", $n, $k);
  $max = 0;
  $a = 0;
  for($i=1; $i<=$n; $i++){
      $score = $i;
      $coin = 0;
      while ($score < $k){
          $score*=2;
          $coin++;
      }
      $max = max($max,$coin);
      $a += 2**($max-$coin);
  }
  $b = (2**$max)*$n;
  echo $a/$b;

Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vec vector

typedef long long ll;

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

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

template<class T> T gcd(T m, T n) {
  if (n == 0) return m;
  return gcd(n, m % n);
}

template<class T> T lcm(T m, T n) {
  return m * n / gcd(m, n);
}

const ll inf = 1LL << 60;
const int mod = 1e9 + 7;

using namespace std;

/* Input variables. */
int n;
string s;

/* Solve! */
void solve() {
  int cnt = 0;
  rep(i, n - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') cnt++;
  }
  cout << cnt << endl;
}

int main() {
  /* Input handling. */
  cin >> n;
  cin >> s;

  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
using namespace std;
typedef long long ll;
#define mp make_pair;
#define pb push_back;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int used[4]={};
vector<int> g[4];

int dfs(int index){
  int far=0;
  used[index]=1;
  for(int i=0; i < g[index].size(); i++){
    if(!used[g[index][i]]){
      far = max(far, dfs(g[index][i])+1);      
    }
  }
  return far;
}



int main(){
  int a,b;
  for(int i=0; i<3; i++){
    cin >> a >> b;
    g[a-1].push_back(b-1);
    g[b-1].push_back(a-1);
  }
  int far=0;
  for(int i=0; i<4; i++){
    for(int j=0;j<4; j++){
      used[j]=0;
    }
    far = max(dfs(i),far);
    //    cout << far << endl;
  }
  if(far==3){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }

  
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 
#define ALL(a)  (a).begin(),(a).end()
const long long INF = 1LL<<58;
const long long MOD=1e9+7;


using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int a, int b)
{
  if(a>b){
    return gcd(b,a);
  }
	return a == 0 ? b : gcd(b % a, a);
}
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}

long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}


template<class T>void chmin(T &a,T b){
  if(a>b){
    a=b;
  }
}

//formerは前方のindex(自分自身を含んで良い)
template<class T>int former(const vector<T>&v,T x){
  return upper_bound(v.begin(),v.end(),x)-v.begin()-1;
}
//latterは後方のindex(自分自身を含んで良い)
template<class T>int latter(const vector<T>&v,T x){
  return lower_bound(v.begin(),v.end(),x)-v.begin();
}


int main() {
  string S;
  cin>>S;
  int zero=0;
  int ichi=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='0'){
      zero++;
    }else{
      ichi++;
    }
  }
  cout<<min(zero,ichi)*2<<endl;

  
  



  
    

}
  




Measured memory_bytes: 512
# 169

# 1.入力をちゃんと受け取ること
# ex: 「2 5」 => a=2, b=5 みたいにしないといけない
a, b = map(int, input().split())
# print(a)
# print(b)

# 2. 目的通りの計算をする
# ex. ２つの整数AとBの掛け算をやる
answer = a * b

# 3 計算の結果を出力する
print(answer)


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

int main(){
    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
#include<bits/stdc++.h> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl "\n"
#define p_b push_back
#define m_p make_pair
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;

// char alphabet[26] = {'a','b','c','d','e','f','g','h','i',
//        'j','k','l','m','n','o','p','q','r','s','t','u','v',
//        'w','x','y','z'};

/* x power y */

int power(int x, unsigned int y) 
{ 
    int res = 1;     // Initialize result 
   
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = res*x; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = x*x;  // Change x to x^2 
    } 
    return res; 
}

int32_t main(){
 	fastIO;
 	vector<int> gr[100005];
 	int n,m;cin>>n>>m;
 	int wt[n+1];
 	for(int i=1;i<=n;i++)cin>>wt[i];
 	int u,v;
 	for(int i=0;i<m;i++){
 		cin>>u>>v;
 		gr[u].p_b(v);
 		gr[v].p_b(u);
 	}
 	int cnt=0;
 	for(int i=1;i<=n;i++){
 		if(gr[i].size()==0)
 			cnt++;
 		else{
 			bool flag=1;
 			for(auto aa:gr[i]){
 				if(wt[aa]>=wt[i]){
 					flag=0;
 					break;
 				}
 			}
 			// if(flag)cout<<i<<" ";
 			cnt+=flag;
 		}	
 	}
 	cout<<cnt<<endl;
} 			



Measured memory_bytes: 10292
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		TreeMap<String, List<Integer>> map = new TreeMap<>();
		int q = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			int op = sc.nextInt();
			String key = sc.next();
			switch (op) {
				case 0:
					if (map.get(key) == null) {
						map.put(key, new ArrayList<>());
					}
					map.get(key).add(sc.nextInt());
					break;
				case 1:
					if (!Objects.isNull(map.get(key))) {
						for (int num : map.get(key)) {
							sb.append(num);
							sb.append('\n');
						}
					}
					break;
				case 2:
					map.remove(key);
					break;
				case 3:
					String r = sc.next();
					Map<String, List<Integer>> submap = map.subMap(key, r);
					int count = 0;
					for (String str : submap.keySet()) {
						List<Integer> list = map.get(str);
						for (int num : list) {
							sb.append(str);
							sb.append(' ');
							sb.append(map.get(str).get(count++));
							sb.append('\n');
						}
						count = 0;
					}
					count = 0;
					if (map.get(r) != null) {
						for (int num : map.get(r)) {
							sb.append(r);
							sb.append(' ');
							sb.append(map.get(r).get(count++));
							sb.append('\n');
						}
					}
					break;
			}
		}
		System.out.print(sb.toString());
	}
}



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

int main(){
	int a, b, c;
	long long k;
	scanf("%d %d %d", &a, &b, &c);
	scanf("%lld", &k);
	if (k & 1) printf("%d\n", b - a);
	else printf("%d\n", a - b);
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mood 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	int N;
	cin>>N;
	VI A(N);
	VI B(N);
	REP(i,N){
		cin>>A[i]>>B[i];
	}
	ll ans=0;
	for(int i=N-1;i>=0;i--){
		A[i]+=ans;
		if(A[i]%B[i]==0)continue;
		else{
			ans+=B[i]-(A[i]%B[i]);
			//cout<<B[i]-(A[i]%B[i])<<endl;
		}
	}
	cout<<ans<<endl;
	return 0;
}




















Measured memory_bytes: 1792
def main():
    h,w,k=map(int,input().split())
    s=[list(input()) for _ in range(h)]
    
    ans=[[0]*w for _ in range(h)]
    for idx in range(h):
        if '#' in s[idx]:
            i=idx
            break
            
    start,j,cnt,first=i,0,1,True

    while i<h:
        if j==w:
            if first:
                ans[i]=ans[i-1]
                i+=1
                j=0
                continue
            first=True
            i+=1
            j=0
            cnt+=1
            continue

        if s[i][j]=='#':
            if first:
                first=False
                ans[i][j]=cnt
                j+=1
                continue
            cnt+=1
            ans[i][j]=cnt
        else:
            ans[i][j]=cnt

        j+=1
    
    for i in range(start):
        ans[i]=ans[start]
    
    for i in range(h):
        print(*ans[i]) 
    
if __name__=='__main__':
    main()

Measured memory_bytes: 8272