akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <bitset>
#include <queue>
#include <set>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

#define LL long long
#define ULL unsigned long long
#define eps 1e-9
#define N 2010
#define M 600050
#define pii pair<int,int>
#define MP make_pair
#define inf 0x3f3f3f3f
#define md ((ll+rr)>>1)
#define lson ll, md, ls
#define rson md + 1, rr, rs
#define ls rt<<1
#define rs rt<<1|1
#define Pi acos(-1.0)
#define mod 1000000007
#define ui unsigned int
LL powmod(LL a,LL b,LL p){
    if(b < 0) return 0;
    LL res = 1; a %= p;
    for(;b;b>>=1){
        if(b & 1) res = res * a % p;
        a = a * a % p;
    }
    return res;
}

int fst[N],nxt[M],vv[M],e;

void init(){
    e = 0;
    memset(fst,-1,sizeof fst);
}

void add(int u,int v){
    vv[e] = v,nxt[e] = fst[u],fst[u] = e++;
    vv[e] = u,nxt[e] = fst[v],fst[v] = e++;
}

int dis[N][N];

void dfs(int u,int f,int o){
    for(int i = fst[u]; ~i; i = nxt[i]){
        int v = vv[i];
        if(v == f)continue;
        dis[o][v] = dis[o][u] + 1;
        dfs(v, u, o);
    }
}

pair<int, int> edge[N];

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    init();
    for(int i = 1; i < n; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        add(u, v);
        edge[i] = MP(u,v);
    }
    
    for(int i = 1; i <= n; i++){
        dis[i][i] = 0;
        dfs(i, 0, i);
    }
    
    int ans = inf;
    if(k % 2 == 0){
        for(int i = 1; i <= n; i++){
            int tmp = 0;
            for(int j = 1; j <= n; j++){
                if(dis[i][j] > k / 2) tmp++;
            }
            ans = min(ans,tmp);
        }
    }else{
        for(int i = 1; i < n; i++){
            int u = edge[i].first;
            int v = edge[i].second;
            int tmp = 0;
            for(int j = 1; j <= n; j++)
                if(min(dis[u][j],dis[v][j]) > k/2) tmp++;
            ans = min(ans,tmp);
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 16128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
#define MP make_pair
#define PB push_back
#define F_d first
#define S_d second
#define LARGE 100000000
#define MOD 100000
#define LL long long

int H, W, N, ITR = 0, ans = 0;
string grid[1009];
int cost[1009][1009];
pair<int, int> NUM[15], st, go;//S123456789
queue<pair<int, int>>Q;

void solve(pair<int, int> now) {
	int i = now.F_d, j = now.S_d;
	if (i + 1 < H && grid[i + 1][j] != 'X' && cost[i + 1][j] > cost[i][j] + 1) {
		cost[i + 1][j] = cost[i][j] + 1; Q.push(MP(i + 1, j));
	}
	if (i > 0 && grid[i - 1][j] != 'X' && cost[i - 1][j] > cost[i][j] + 1) {
		cost[i - 1][j] = cost[i][j] + 1; Q.push(MP(i - 1, j));
	}
	if (j + 1 < W && grid[i][j + 1] != 'X' && cost[i][j + 1] > cost[i][j] + 1) {
		cost[i][j + 1] = cost[i][j] + 1; Q.push(MP(i, j + 1));
	}
	if (j > 0 && grid[i][j - 1] != 'X' && cost[i][j - 1] > cost[i][j] + 1) {
		cost[i][j - 1] = cost[i][j] + 1; Q.push(MP(i, j - 1));
	}
	return;
}


int main() {
	cin >> H >> W >> N;
	for (int i = 0; i < H; i++) {
		cin >> grid[i];
		for (int j = 0; j < W; j++) {
			cost[i][j] = LARGE;
			if (grid[i][j] == 'X') ;
			else if (grid[i][j] == 'S') NUM[0] = MP(i, j);
			else if (grid[i][j] != '.') NUM[grid[i][j] - '0'] = MP(i, j);
		}
	}

	for (int i = 0; i < N; i++) {
		st = NUM[i]; go = NUM[i + 1];
		cost[st.F_d][st.S_d] = 0;
		Q.push(st);
		while (!Q.empty()) {
			pair<int, int>now = Q.front();
			solve(now);
			Q.pop();
		}
		ans += cost[go.F_d][go.S_d];
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) cost[i][j] = LARGE;
		}
	}
	cout << ans << endl;

	return 0;
}

//チーズ
/*
int H, W, N, ans, tag, si, sj;
char MAP[1009][1009];
int dp[1009][1009];

bool inmap(int i, int j) {
return ((i >= 0 && i <= H - 1) && (j >= 0 && j <= W - 1));
}
bool pass(int i, int j) {
return (MAP[i][j] != 'X');
}

int DFS(int i, int j) {
if (dp[i][j] != LARGE)return dp[i][j];
if (MAP[i][j] - '0' == tag) {
si = i; sj = j;
return 0;
}

if (inmap(i + 1, j) && pass(i + 1, j)) dp[i][j] = min(dp[i][j], DFS(i + 1, j) + 1);
if (inmap(i - 1, j) && pass(i - 1, j)) dp[i][j] = min(dp[i][j], DFS(i - 1, j) + 1);
if (inmap(i, j + 1) && pass(i, j + 1)) dp[i][j] = min(dp[i][j], DFS(i, j + 1) + 1);
if (inmap(i, j - 1) && pass(i, j - 1)) dp[i][j] = min(dp[i][j], DFS(i, j - 1) + 1);
cout << i << " " << j << " " << dp[i][j] << endl;
return dp[i][j];
}

int main() {
cin >> H >> W >> N;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> MAP[i][j];
if (MAP[i][j] == 'S') {
si = i; sj = j;
}
}
}

for (int i = 1; i <= N; i++) {
cout << i << " " << si << " " << sj << endl << endl;
for (int j = 0; j < H; j++) {
for (int k = 0; k < W; k++) {
dp[j][k] = LARGE;
}
}
tag = i;
ans += DFS(si, sj);

}

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



Measured memory_bytes: 7964
#include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define ULL ull
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int, pii >
#define pll pair <ll,ll>
#define pb push_back
#define big 20160116
#define INF 2147483647
#define pq priority_queue
using namespace std;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
namespace Mymath{
	LL qp(LL x,LL p,LL mod){
		LL ans=1;
		while (p){
			if (p&1) ans=ans*x%mod;
			x=x*x%mod;
			p>>=1;
		}
		return ans;
	}
	LL inv(LL x,LL mod){
		return qp(x,mod-2,mod);
	}
	LL C(LL N,LL K,LL fact[],LL mod){
		return fact[N]*inv(fact[K],mod)%mod*inv(fact[N-K],mod)%mod;
	}
	template <typename Tp> Tp gcd(Tp A,Tp B){
		if (B==0) return A;
		return gcd(B,A%B);
	}
	template <typename Tp> Tp lcm(Tp A,Tp B){
		return A*B/gcd(A,B);
	}
};
namespace fwt{
	using namespace Mymath;
	void FWT(int a[],int n,LL mod)
	{
	    for(int d=1;d<n;d<<=1)
	        for(int m=d<<1,i=0;i<n;i+=m)
	            for(int j=0;j<d;j++)
	            {
	                int x=a[i+j],y=a[i+j+d];
	                a[i+j]=(x+y)%mod,a[i+j+d]=(x-y+mod)%mod;
	                //xor:a[i+j]=x+y,a[i+j+d]=x-y;
	                //and:a[i+j]=x+y;
	                //or:a[i+j+d]=x+y;
	            }
	}

	void UFWT(int a[],int n,LL mod)
	{
		LL rev=inv(2,mod);
	    for(int d=1;d<n;d<<=1)
	        for(int m=d<<1,i=0;i<n;i+=m)
	            for(int j=0;j<d;j++)
	            {
	                int x=a[i+j],y=a[i+j+d];
	                a[i+j]=1LL*(x+y)*rev%mod,a[i+j+d]=(1LL*(x-y)*rev%mod+mod)%mod;
	                //xor:a[i+j]=(x+y)/2,a[i+j+d]=(x-y)/2;
	                //and:a[i+j]=x-y;
	                //or:a[i+j+d]=y-x;
	            }
	}
	void solve(int a[],int b[],int n,LL mod)
	{
	    FWT(a,n,mod);
	    FWT(b,n,mod);
	    for(int i=0;i<n;i++) a[i]=1LL*a[i]*b[i]%mod;
	    UFWT(a,n,mod);
	}
};
const int Maxn=19;
char c[Maxn*2];
int n;
LL dp[Maxn][Maxn];
int main(){
	n=read();
	scanf("%s",c);
	LL ans=0;
	for (int i=0;i<(1<<n);i++){
		string a,b;
		for (int j=0;j<n;j++){
			if (i&(1<<j)){
				a+=c[j];
			}
			else{
				b+=c[j];
			}
		}
		reverse(a.begin(),a.end());
		reverse(b.begin(),b.end());
		int sa=a.size(),sb=b.size();
		a='$'+a;
		b='$'+b;
	//	cout<<a<<' '<<b<<endl;
		
		dp[0][0]=1;
		for (int j=1;j<=n;j++){
			for (int l=0;l<=min(i,sa);l++){
				int r=j-l;
				dp[j][l]=0;
				if (l && a[l]==c[j+n-1]) dp[j][l]+=dp[j-1][l-1];
				if (r && b[r]==c[j+n-1]) dp[j][l]+=dp[j-1][l];
			//	cout<<j<<' '<<l<<' '<<r<<' '<<dp[j][l]<<endl;
			}
		}
		ans+=dp[n][sa];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define N 100005
using namespace std;
LL ans;
int n,x[N],y[N];
vector<int>g[N];
int fa[N],cnt[N],sz[N];
bool mark[N],mark2[N];
int gf(int k) {
	return fa[k]==k?fa[k]:fa[k]=gf(fa[k]);
}
int main() {
	scanf("%lld",&n);
	for(int i=1; i<N; i++)fa[i]=i;
	for(int i=1; i<=n; i++)scanf("%d%d",&x[i],&y[i]),g[x[i]].push_back(y[i]);
	for(int i=1; i<N; i++) {
		int a;
		if(!g[i].empty())a=g[i][0];
		for(int j=1; j<g[i].size(); j++) {
			int b=g[i][j];
			fa[gf(b)]=gf(a);
		}
	}
	for(int i=1;i<=n;i++){
		sz[gf(y[i])]+=!mark2[y[i]];
		mark2[y[i]]=1;
		cnt[gf(y[i])]+=!mark[x[i]];
		mark[x[i]]=1;
	}
	for(int i=1;i<=n;i++){
		int f=gf(y[i]);
		ans+=1ll*sz[f]*cnt[f];
		sz[f]=0;
	}
	printf("%lld\n",ans-n);
	return 0;
}



Measured memory_bytes: 5888
def GCD(a, b):
    if b == 0:
        return a
    return GCD(b, a%b)

gcd = []
for i in range(210):
    gcd.append([-1] * 210)
for i in range(205):
    for j in range(205):
        gcd[i][j] = GCD(i, j)

K = int(input())
ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd[gcd[a][b]][c]
print(ans)


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  // 公約数を全探索して配列を作成し逆順ソート
  vector<int> d(100);
  for (int i=1; i<=min(A, B); i++) {
    if (A%i==0 && B%i==0) {
      d.push_back(i);
    }
  }
  reverse(d.begin(), d.end());
  cout << d.at(K-1) << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int main() {
	int n, m, a, b;
	read(n), read(m), read(a), read(b);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++)
			if (i <= b && j <= a) putchar('1');
			else if (i > b && j > a) putchar('1');
			else putchar('0');
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#define int long long
#define ll getchar();getchar();return 0;
	using namespace std;
	signed main() {
		int a, b, c;
		cin >> a >> b >> c;
		if (a + b < c)cout << a+b+1+b << endl;
		else cout << b + c << endl;
		ll
	}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#pragma warning(disable : 4996)
using namespace std;
int n, t[1111]; string S[1111];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			cin >> S[i];
			for (int j = 0; j < S[i].size(); j++) {
				if (S[i][j] == '.') {
					t[i] = j + 1;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < S[i].size(); j++) {
				if (S[i][j] == '.') {
					if (S[i][j + 1] != '.') {
						printf("+");
					}
					else {
						bool flag = false;
						for (int k = i + 1; k < n; k++) {
							if (t[k] < j + 1) {
								break;
							}
							if (t[k] == j + 1) {
								flag = true; break;
							}
						}
						if (flag) {
							printf("|");
						}
						else {
							printf(" ");
						}
					}
				}
				else {
					printf("%c", S[i][j]);
				}
			}
			printf("\n");
		}
	}
	return 0;
}

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

class ORDER {
public:
    char temp;
    void CHANGE() {
        while (temp = cin.get()) {
            if (temp == EOF) {
                cin.clear();
                cin.seekg(0, ios::end);
                break;
            }
            if (0x41 <= temp && temp <= 0x5A) {  // 0x41 = 'A', 0x5A = 'Z'
                temp += 0x20;
            }
            else if (0x61 <= temp && temp <= 0x7A) {  // 0x61 = 'a', 0x7A = 'z'
                temp -= 0x20;
            }
            cout << temp << flush;
        }
    }
};

int main() {
    ORDER x;
    x.CHANGE();
    return 0;
}


Measured memory_bytes: 3084
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps=1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.answer"



int main() {
	int a;
	while (cin >> a) {
		cout<< a*(a + 1) / 2 + 1<<endl;

	}
	return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<(int)n;i++)
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
const int maxn = 105;
const int maxw = 1e5 + 5 ;
#define int long long
int dp[maxn][maxw];
int arr[2][maxn];

int32_t main(){
    IOS;
    int n,w;
    cin>>n>>w;
    rep(i,n)
        rep(j,2)
            cin>>arr[j][i];
    memset(dp,0,sizeof(dp));
    for(int i=arr[0][0];i<=w;i++)
        dp[0][i]=arr[1][0];
    rep1(i,n){
        rep(j,w+1){
            if(j-arr[0][i]>=0)
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-arr[0][i]]+arr[1][i]);
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n-1][w]<<endl;
    return 0;
}

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

#define ll 				long long int
#define gof 			for(long long int i = 0 ; i < n ; i++)
#define for1(i,s,e) 	for(long long int i = s ; i < e ; i++)
#define forr(i,e,s) 	for(long long int i = e ; i >= s; i--)
#define vi 				vector<long long int>
#define all(x) 			x.begin(), x.end()
#define pb(x) 			push_back(x)
#define maxv(x) 		*max_element(x)
#define minv(x) 		*min_element(x)
#define mkvec(type,a,n) vector<type> a(n)

const ll ARR = 1e5;
const ll INF = 1e9;
const ll mod = 1e9+7;

void IO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}

void solve(){

	int n;
	cin >> n;
 //  AC, WA, TLE, or RE
	string s[] = {"AC\0","WA\0","TLE\0","RE\0"};

	map<string,int> m;

	for1(i,0,4) m[s[i]] = 0;

	gof{
		string t;
		cin >> t;
		m[t]++;
	}


	for1(i,0,4){
		cout << s[i] << " x " << m[s[i]] << "\n";
	}

	return;

}

int main(){
	IO();
    ll t = 1;
    //cin >> t;
    while(t--) solve();
    return 0;
}




Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int a, b, c;
int main() {
	for(int i = 0; i < 3; i++) {
		cin >> a >> b >> c;
		int p = a * 3600 + b * 60 + c;
		cin >> a >> b >> c;
		int q = a * 3600 + b * 60 + c;
		int r = q - p;
		cout << r / 3600 << ' ' << r / 60 % 60 << ' ' << r % 60 << endl;
	}
	return 0;
}

Measured memory_bytes: 2992
#include<stdio.h>

int main(){
  int n = 0;
  int b[100] = {};
  int a[100] = {};
  int i = 0;
  int sum = 0;
  scanf("%d",&n);
  for(i = 0;i < n-1;i++){
    scanf("%d",&b[i]);
  }
  
  a[0] =  b[0];
  for(i = 0;i < n-1;i++){
    if(a[i] <= b[i]){
      a[i+1] = b[i];
    }else{
      a[i] = b[i];
      a[i+1] = b[i];
    }
  }
  
  for(i = 0;i < n;i++){
    sum += a[i];
  }
  printf("%d",sum);
  return 0;
}
  

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
#include<vector>
#include<math.h>
#include<queue>
#include<functional>

int n, m, s, g;
struct load{
	int x;
	int y;
	int d;
	int c;
};
struct P{
	double cost;
	int from;
	int now;
	int sp;
	bool operator > (const P& p) const{
		return cost > p.cost;
	}
};
//vector<vector<vector<double>>> vvvi;

double cost[31][31][31];//from now sp


int main(){


	while (cin >> n >> m, n | m){
		vector<load> L;
		cin >> s >> g;
		for (int i = 0; i < m; i++){
			int x, y, d, c;
			cin >> x >> y >> d >> c;
			L.push_back({ x, y, d, c });
			L.push_back({ y, x, d, c });
		}
		priority_queue<P, vector<P>, greater<P>> q;
		q.push({ 0.0, s, s, 0 });
		cost[s][s][0] = 0.0;

		for (int i = 0; i < 31; i++)
			for (int j = 0; j < 31; j++)
				for (int k = 0; k < 31; k++)
					cost[i][j][k] = 100000.0;

		while (!q.empty()){
			if (q.top().now == g &&q.top().sp == 1)break;
			P q2 = q.top();
			q.pop();
			for (int i = 0; i < (signed int)L.size(); i++){
				for (int j = -1; j < 2; j++){
					if (q2.now == L[i].x&&q2.from != L[i].y&& L[i].c >= q2.sp + j)
						if (q2.sp + j>0)
							if (q2.cost + L[i].d / (double)(q2.sp + (j)) < cost[q2.now][L[i].y][q2.sp + (j)]){
								q.push({ q2.cost + L[i].d / (double)(q2.sp + (j)), q2.now, L[i].y, q2.sp + (j) });
								cost[q2.now][L[i].y][q2.sp + (j)] = q2.cost + L[i].d / (double)(q2.sp + (j));
							}
				}
			}
		}
		if (!q.empty())printf("%.5lf\n", q.top().cost);
		else cout << "unreachable" << endl;
	}
	return 0;
}

Measured memory_bytes: 2016
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
string s;
int i=0,b,c;
signed main(){
	cin>>s;
	while(1){
		if(s[i]=='A'){
			b=i;
			break;
		}
		i++;
	}
	i=s.size()-1;
	while(1){
		if(s[i]=='Z'){
			c=i;
			break;
		}
		i--;
	}
	cout<<c-b+1;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int A,B,C;

int main(){
    cin>>A>>B>>C;

    int ans=max(A,max(B,C))*10+A+B+C-max(A,max(B,C));

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int ans = 0, f = 0;
	for (int i = 0; i < n; i++) {
		if (f < h[i])ans += h[i] - f;
		f = h[i];
	}
		cout << ans << endl;
	return 0;
}

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

int main () {
  vector<int> line(3) ;
  
  for ( int i = 0 ; i < 3 ; i++ ) {
    cin >> line.at(i) ;
  }
  
  sort( line.begin() , line.end() ) ;
  
  if ( line.at(0) == line.at(1) ) {
    cout << line.at(2) << endl ;
  } else {
    cout << line.at(0) << endl ;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void) {
	long long int x, ans = 0;
	cin >> x;
	ans += 2 * (x / 11);
	x %= 11;
	if (x > 6) ans += 2;
	else if (x > 0) ans += 1;

	cout << ans << endl;
	system("pause");
}

Measured memory_bytes: 504
import numpy as np
import statistics

k,n = map(int,input().split())

a = list(map(int,input().split()))


b = np.array(a)


b = b%k
b.sort()



dis = 0

for i in range(1,n):
    dis = max(dis,abs(b[i]- b[i-1]))

dis = max(dis,(b[0]+k-b[n-1]))


print(k - dis)

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

#define ll long long
#define ld long double
#define mod 998244353LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define foi(i,a,n) for(i = (a); i <= (n); i++)
#define pd(x) cout<<x
#define sd(x) cin>>x
#define nl cout<<endl
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define all(a) (a).begin(), (a).end()
#define foreach(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//ll fibonacci[2][2] = {{0,1},{1,1}};
//ll identity[2][2] = {{1,0},{0,1}};

int main() {
	ll i,j,k;
	ll n;
	cin >> n;
	string s;
	cin >> s;
	vll dp(8,0);
	dp[0] = n;
	ll ans = 1;
	fo(k,0,s.length()) {
		ll curr = ((s[k] == 'R') ? 1 : (s[k] == 'G' ? 2 : 4));
		if (dp[7 ^ curr] != 0) {
			ans = (ans * dp[7 ^ curr])%mod;
			dp[7 ^ curr]--;
		} else {
			bool flag = false;
			for (i=1;i<8;i<<=1) {
				if (i != curr && dp[i]) {
					flag = true;
					ans = (ans * dp[i])%mod;
					dp[i | curr]++;
					dp[i]--;
				}
			}
			if (!flag) {
				ans = (ans * dp[0])%mod;
				dp[0]--;
				dp[curr]++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef uint32_t u32;
typedef uint64_t u64;

int main() {

  for(;;) {
    int n;
    std::cin >> n;
    if( n == 0 ) break;
    int x = 0, y = 0;
    for(int i = 0; i < n; ++i) {
      int a, b;
      std::cin >> a >> b;
      if( a > b ) x += a + b;
      if( a < b ) y += a + b;
      if( a == b ) {
        x += a; y += b;
      }
    }
    std::cout << x << " " << y << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if a * b * c != 0 else 10 ** 9
    else:
        ret0 = dfs(cur + 1, a, b, c)
        reta = dfs(cur + 1, a + l[cur], b, c) + 10
        retb = dfs(cur + 1, a, b + l[cur], c) + 10
        retc = dfs(cur + 1, a, b, c + l[cur]) + 10
        return min(ret0, reta, retb, retc)
print(dfs(0,0,0,0))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int A,B;
int main(){
  cin >> A;
  B=A%100;
  A/=100;
  if(A<=0&&B<=0||(A>12&&B>12)||A<=0&&B>12||B<=0&&A>12) cout << "NA" << endl;
  else if(A>0&&A<=12&&B>0&&B<=12) cout << "AMBIGUOUS" << endl;
  else if(A>0&&A<=12) cout << "MMYY" << endl;
  else if(B>0&&B<=12) cout << "YYMM" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

vector<int> to[440];



int main(){
    int H,W;cin>>H>>W;
    char c[25][25];
    rep(i,0,H)rep(j,0,W)cin>>c[i][j];
    rep(i,0,H){
        rep(j,0,W){
            if(c[i][j]=='.'){
                if(i-1>=0&&c[i-1][j]=='.'){
                    to[i*W+j].push_back((i-1)*W+j);
                    to[(i-1)*W+j].push_back(i*W+j);
                }
                if(i+1<H&&c[i+1][j]=='.'){
                    to[i*W+j].push_back((i+1)*W+j);
                    to[(i+1)*W+j].push_back(i*W+j);
                }
                if(j-1>=0&&c[i][j-1]=='.'){
                    to[i*W+j].push_back(i*W+j-1);
                    to[i*W+j-1].push_back(i*W+j);
                }
                if(j+1<W&&c[i][j+1]=='.'){
                    to[i*W+j].push_back(i*W+j+1);
                    to[i*W+j+1].push_back(i*W+j);
                }
            }
        }
    }
    int MAX=-1,GMX=-1;
    rep(i,0,H*W){
        if(c[i/W][i%W]=='#')continue;
        MAX=-1;
        vector<int> dist(H*W,-1);
        queue<int> que;
        dist[i] = 0;
        que.push(i); 
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            MAX=max(MAX,dist[v]);
            for (int nv : to[v]) {
                if (dist[nv] != -1) continue; 

                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }
        GMX=max(MAX,GMX);
    }
    cout<<GMX<<endl;
}







Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 200200;
int a[N];
int b[N];
bool inQ[N];
int Q[N];
int L, R;
ll ans = 0;
int n;

void solve(int id) {
	int p = id - 1, q = id + 1;
	if (p < 0) p += n;
	if (q >= n) q -= n;
	int k = (b[id] - a[id]) / (b[p] + b[q]);
	if (k <= 0) return;
	ans += k;
	b[id] -= (b[p] + b[q]) * k;
	solve(p);
	solve(q);
}

inline void putInQ(int id) {
	if (inQ[id]) return;
	int p = id - 1, q = id + 1;
	if (p < 0) p += n;
	if (q >= n) q -= n;
	if (b[id] < a[id] + b[p] + b[q]) return;
	inQ[id] = 1;
	Q[R++] = id;
	if (R == N) R = 0;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &b[i]);
	for (int i = 0; i < n; i++) {
		putInQ(i);
	}
	while(L != R) {
		int id = Q[L++];
		if (L == N) L = 0;
		inQ[id] = 0;
		int p = id - 1, q = id + 1;
		if (p < 0) p += n;
		if (q >= n) q -= n;
		int k = (b[id] - a[id]) / (b[p] + b[q]);
		if (k <= 0) continue;
		ans += k;
		b[id] -= k * (b[p] + b[q]);
		putInQ(p);
		putInQ(q);
	}
	for (int i = 0; i < n; i++)
		if (a[i] != b[i]) {
			printf("-1\n");
			return 0;
		}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 2816
import math
import itertools

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

n=int(input())
ans=0
lis = [i for i in range(1,n+1)]
for v in itertools.combinations_with_replacement(lis, 3):
    a=math.gcd(v[0],v[1])
    ans+=math.gcd(a,v[2])*permutations_count(3, len(set(v))-1)
print(ans)

Measured memory_bytes: 9196
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <complex>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()

template <typename T, typename E>
ostream &operator<<(std::ostream &os, const std::pair<T, E> &p){
  return os << "(" << p.first << ", " << p.second << ")";
}

typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  typedef pair<int, int>    PI;
  typedef pair<PI, PI>      PP;

  map<PI, string> name;
  map<string, vector<PI> > pos;
  map<PI, vector<PI> > G;
  map<PI, PI> cost;
  map<string, int> id;
  priority_queue<PP, vector<PP>, greater<PP> > que;

  int N, T;
  string A, B;
  cin >> N >> T >> A >> B;
  
  REP(i, N){
    int a;
    cin >> a;
    vector<string> stations(a);
    vector<int> distance(a - 1);
    REP(j, a){
      cin >> stations[j];
      pos[stations[j]].push_back(PI(i, j));
      name[PI(i, j)] = stations[j];

      if (stations[j] == A){
        cost[PI(i, j)] = PI(0, 0);
        que.push(PP(PI(0, 0), PI(i, j)));
      }

      if (id.find(stations[j]) == id.end()){
        int size = id.size();
        id[stations[j]] = size;
        name[PI(size, -1)] = stations[j];
      }
    }
    
    REP(j, a - 1){
      cin >> distance[j];
      G[PI(i, j)].push_back(PI(j + 1, distance[j]));
      G[PI(i, j + 1)].push_back(PI(j, distance[j]));
    }
  }
  
  while (!que.empty()){
    PI ps = que.top().second;
    PI pi = que.top().first;
    que.pop();

    if (name[ps] == B){
      cout << pi.first << " " << pi.second << endl;
      exit(EXIT_SUCCESS);
    }

    if (cost[ps] < pi) continue;
    
    if (ps.second == -1){       // norikae
      for (PI next : pos[name[ps]]){
        auto iter = cost.find(next);
        if (iter == cost.end() || iter->second > pi){
          cost[next] = pi;
          que.push(PP(pi, next));
        }
      }
    } else {
      PI nps(id[name[ps]], -1);
      PI npi(pi.first + T, pi.second + 1);
      auto iter = cost.find(nps);
      if (iter == cost.end() || iter->second > npi){
        cost[nps] = npi;
        que.push(PP(npi, nps));
      }

      for (const PI &e : G[ps]){
        PI nps(ps.first, e.first);
        PI npi(pi.first + e.second, pi.second);
        auto iter = cost.find(nps);
        if (iter == cost.end() || iter->second > npi){
          cost[nps] = npi;
          que.push(PP(npi, nps));
        }
      }
    }
  }
  cout << -1 << endl;
  
  return 0;
}

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

using namespace std;

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin >> N;
    int d[N];
    rep(i, N) { cin >> d[i]; }
    sort(d, d + N, greater<int>());
    int total = 1;
    int ncomp = d[0];
    rep(i, N) {
        if (ncomp > d[i]) {
            ncomp = d[i];
            total++;
        }
    }
    cout << total << endl;
    return 0;
}

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

int main()
{
	int n,m;
	cin>>n;
	m=n%10;
	if(m==2 || m==4 || m==9 || m==7 || m==5)
		cout<<"hon";
	else if(m==0 || m==1 || m==6 || m==8)
		cout<<"pon";
	else
		cout<<"bon";
	return 0;
}

Measured memory_bytes: 3624
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, p = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    o = 0
    e = 0
    for e in a:
        if e % 2:
            o += 1
        else:
            e += 1
    if o:
        print(2 ** (n-1))
    else:
        if p:
            print(0)
        else:
            print(2 ** n)
        


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

"""


Measured memory_bytes: 9396
import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int h;
		int t =0;
		for(int i=0; i<n; i++)
		{
			h= sc.nextInt();
			if(h>=k)
				t += 1;
		}

		System.out.println(t);
	}
}

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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

string s[100000];

int main() {
	ll N;
	cin >> N;

	rep(i,0,N) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}

	ll ans = 0;
	map<string,ll> maps;

	rep(i,0,N) {
		maps[s[i]]++;
	}

	for(auto data : maps) {
		// cout << data.first << " => " << data.second << "\n";
		ans += data.second * (data.second - 1) / 2;
		// ans += data.second;
    }

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

Measured memory_bytes: 18176
Palette = [[0,0,0],[0,0,255],[0,255,0],[0,255,255],[255,0,0],[255,0,255],[255,255,0],[255,255,255]]
Color = ["black","blue","lime","aqua","red","fuchsia","yellow","white"]

def solve hex
  rgb = hex.split("")
  r = (rgb[0] + rgb[1]).hex.to_i
  g = (rgb[2] + rgb[3]).hex.to_i
  b = (rgb[4] + rgb[5]).hex.to_i
  similar = -1
  diff = 10000
  Palette.size.times do |k|
    dk = Math.sqrt((r - Palette[k][0]) ** 2 + (g - Palette[k][1]) ** 2 + (b - Palette[k][2]) ** 2)
    if dk < diff
      diff = dk
      similar = k
    end
  end
  Color[similar]
end

while (input = $stdin.gets.chomp) != "0" do
  printf "%s\n", solve(input.delete("#"))
end

Measured memory_bytes: 6160
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main()
{
    int n, k;
    cin >> n >> k;
    map<int, bool> mp;
    map<int, ll> dp;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> v;
    rep(i, n) cin >> a[i] >> b[i];
    mp[k] = true;
    mp[0] = true;
    v.push_back(0);
    v.push_back(k);

    rep(i, 30 + 1)
    {
        if (((k >> (30 - i)) & 1) == 1)
        {
            //cerr << i << endl;
            int tmp = ((k >> (31 - i)) << (31 - i));
            tmp |= ((1 << (30 - i)) - 1);
            // cerr << bitset<30>(tmp) << endl;
            mp[tmp] = true;
            v.push_back(tmp);
        }
    }
    map<int, int> used;

    rep(i, n)
    {
        used.clear();
        for (auto x : v)
        {
            if (mp[(x | a[i])] == false || used[(x | a[i])] == true)
            {
                continue;
            }
            used[(x | a[i])] = true;
            dp[(x | a[i])] += b[i];
        }
    }
    ll ans = 0;
    for (auto x : v)
    {
        chmax(ans, dp[x]);
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 998244353 
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_backP
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int main(){
	boost;

	ll n,k;
    cin>>n>>k;

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

    sort(arr,arr+n);
    ll sum = 0;
    for(int i =0;i<n-k;i++){
        sum = sum + arr[i];
    }

    cout<<sum;
    return 0;
}

Measured memory_bytes: 1792
import java.io.*
import java.util.*
import java.lang.Math.*


fun main() {
    val N = rd.readInt()
    var mp = mutableMapOf<String, Int>()
    mp["AC"] = 0
    mp["WA"] = 0
    mp["TLE"] = 0
    mp["RE"] = 0

    for (i in 0 until N) {
        val key = rd.readString()
        mp[key] = mp[key]!! + 1
    }

    for ((k, v) in  mp) {
        println("$k x $v")
    }
}


//val rd = debug.Reader("abc", "173", "b", "sample-1")
val rd = Reader()
fun main(args: Array<String>) {
    Thread(null, MainThread(), "mainThread", 128 * 1024 * 1024).start()
}


const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
class MainThread : Runnable {
    override fun run() { main() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


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

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  long S;
  COMinit();
  cin>>S;
  if(S<=2){
    cout<<0<<endl;
    return 0;
  }
  long ans=0;
  for(int i=1;i<S;i++){
    long tmp=S-i*3;
    if(tmp<0) break;
    ans+=COM(tmp+i-1,i-1);
    ans%=MOD;
    //cout<<i<<ans<<endl;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 15572
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    string s;
    cin>>s;

    if(s[c-1]=='#'||s[d-1]=='#')
    {
        cout<<"No";
        return 0;
    }

    for(int i=a;i<max(c,d);i++)
    {
        if(s[i]=='#'&&s[i+1]=='#')
        {
            cout<<"No";
            return 0;
        }
    }

    bool flag=false;
    if(c>d)
    {
        for (int i = b-2; i <d-1 ; ++i) {
            if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.')
            {
                flag=true;
                break;
            }
        }
        if (flag)
            cout<<"Yes";
        else
            cout<<"No";
    }

    else
    {
        cout<<"Yes";
    }


}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

        int x = scanner.nextInt();
        int y = scanner.nextInt();
        while( x+y > 0 ){
            if(x > y){
                int a = x;
                x = y;
                y = a;
            }
            
            System.out.println(x+" "+y);
            x = scanner.nextInt();
            y = scanner.nextInt();
        }
    }
}



Measured memory_bytes: 35988
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define dump(x) cerr<<#x<<": "<<x<<endl
#define debug(x) cerr<<#x<<": "<<x<<" ("<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;

int main() {
    string S; cin >> S;
    int cnt = 0;
    rep(i, S.size()-1) {
        char a = S[i], b = S[i+1];
        if(a != b) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


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


public class Main {
    
    public static void main(String[] args) {
 
      Scanner sc = new Scanner(System.in);
        
      int a = sc.nextInt();
      int b = sc.nextInt();
      int h = sc.nextInt();
      
      System.out.println((a + b)*h/2);
              

      
      
      
    }          
 }

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

long double P[3003], dp[3003][3003];

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    int N;
    cin >> N;
    
    for(int i=1; i<=N; i++)
        cin >> P[i];
    
    dp[0][0] = 1;
    
    for(int i=1; i<=N; i++)
        for(int j=0; j<=N; j++)
        {
            dp[i][j] = dp[i-1][j] * (1 - P[i]);
            
            if(j >= 1)
                dp[i][j] += dp[i-1][j-1] * P[i];
        }
    
    long double ans = 0;
    
    for(int tail=0, head=N; head > tail; tail++, head--)
        ans += dp[N][head];
    
    cout << fixed << setprecision(12) << ans << "\n";
    return 0;
}

Measured memory_bytes: 141056
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc106_c
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            double k = double.Parse(Console.ReadLine());

            if(str[0] != '1'){
                WriteLine(str[0]);
            }else{
                for(int i=1; i<str.Length; i++){
                    if(str[i] != '1'){
                        if(k <= i){
                            WriteLine(1);
                        }else{
                            WriteLine(str[i]);
                        }
                        return;
                    }
                }
                WriteLine(1);
            }
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){ 
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 100+5;
const int K = 100000+5;

int n;
int k;
int a[N];
bool vis[N][K];
int memo[N][K];

int main(){
	ri2(n,k);
	for(int i=0; i<n; i++) ri(a[i]);
	memo[0][0] = 1;
	memo[0][1] = -1;
	for(int i=0; i<=n; i++){
		for(int j=1; j<=k; j++){
			memo[i][j] = add(memo[i][j],memo[i][j-1]);
		}
		if(i == n) break;
		for(int j=0; j<=k; j++){
			int l = j;
			int r = min(k+1,j+a[i]+1);
			memo[i+1][l] = add(memo[i+1][l],memo[i][j]);
			memo[i+1][r] = add(memo[i+1][r],-memo[i][j]);
		}
	}
	printf("%d\n",memo[n][k]);
	return 0;
}


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


int main(){
  ll ans=0;
  int n;
  cin >>n;
  ll a[n+1];
  rep(i,n+1)cin >>a[i];
  ll b[n];
  rep(i,n)cin >> b[i];

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

}

Measured memory_bytes: 1792
import collections
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    BC = []
    for q in range(Q):
        b, c = map(int, input().split())
        BC.append((b, c))
    
    C = dict(collections.Counter(A))
    s = sum(A)
    ans = []
    for b, c in BC:
        cb = C.get(b, 0)
        delta = cb * (c - b)
        s += delta
        ans.append(s)
        C[c] = C.get(c, 0) + cb
        C[b] = 0
    
    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

Measured memory_bytes: 39348
const main = (input) => {
  input = input.split(' ');
  const K = parseInt(input[0], 10);
  const S = parseInt(input[1], 10);
  
  const count = 0;
  for (const i = 0; i<=K i++) {
    for(const n = 0; n<=K; n++) {
      if (0<=S-i-n&&S-i-n<=K) {
        count++;
      }
    }
  }
  console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		int K = sc.nextInt();
		List<Long> A = new ArrayList<>();
		for(int i = 0; i < X; i++)
			A.add(sc.nextLong());
		Collections.sort(A, Collections.reverseOrder());
		List<Long> B = new ArrayList<>();
		for(int i = 0; i < Y; i++)
			B.add(sc.nextLong());
		Collections.sort(B, Collections.reverseOrder());
		List<Long> C = new ArrayList<>();
		for(int i = 0; i < Z; i++)
			C.add(sc.nextLong());
		Collections.sort(C, Collections.reverseOrder());
		List<Long> tasteAB = new ArrayList<>();
		List<Long> taste = new ArrayList<>();
		for(int i = 0; i < X; i++) {
			for(int j = 0; j < Y; j++) {
				if(i*j > K)
					break;
				tasteAB.add(A.get(i) + B.get(j));
			}
		}
		Collections.sort(tasteAB, Collections.reverseOrder());
		for(int i = 0; i < tasteAB.size(); i++) {
			if(i > K)
				break;
			for(int j = 0; j < Z; j++) {
				if(i*j > K)
					break;
				taste.add(tasteAB.get(i) + C.get(j));
			}
		}
		Collections.sort(taste, Collections.reverseOrder());
		StringBuilder ans = new StringBuilder();
		for(int i = 0; i < K; i++)
			ans.append(taste.get(i) + "\n");
		System.out.println(ans);
	}

}


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

int main(){
  int A,B,C,D;
  
  cin >> A >> B >> C >> D;
  
  if((A+B) > (C+D)){
    cout << "Left" << endl;
  }
  else if((A+B) < (C+D)){
    cout << "Right" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}

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

using ll = long long;

int main() {
  int N;
  scanf("%d", &N);
  vector<ll> a(N), b(N);

  ll asum = 0, bsum = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &a[i]);
    asum += a[i];
  }
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &b[i]);
    bsum += b[i];
  }

  if (asum < bsum) {
    return !printf("-1\n");
  }

  deque<ll> disp;
  for (int i = 0; i < N; ++i) {
    disp.push_back(b[i] - a[i]);
  }

  sort(disp.begin(), disp.end());
  int res = 0;
  bool changed_front = false;
  bool changed_back = false;

  while (disp.size() > 1) {
    if (disp.back() <= 0) {
      disp.pop_back();
      res += changed_back;
      changed_back = false;
      continue;
    }
    if (disp.front() >= 0) {
      disp.pop_front();
      res += changed_front;
      changed_front = false;
      continue;
    }

    if (disp.front() + disp.back() >= 0) {
      ll temp = disp.back();
      disp.back() += disp.front();
      disp.front() += temp;
      changed_front = true;
      changed_back = true;
    } else {
      ll temp = disp.front();
      disp.front() += disp.back();
      disp.back() += temp;
      changed_front = true;
      changed_back = true;
    }
  }

  printf("%d\n", res + changed_front + changed_back);
}

Measured memory_bytes: 2560