akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
n,m = map(int,input().split())
ab = [[0,0] for _ in range(m)]
for i in range(m):
    ab[i][1],ab[i][0] = map(int,input().split())

ab.sort()

cnt = 0
before = 0
for i in range(m):
    if cnt >= 1 and ab[i][1] < before:
        pass
    else:
        before = ab[i][0]
        cnt += 1

print(cnt)


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

using namespace std;

int main(){

	int a, output,inst, flag;
	string b,result;
	output = 0;
	inst = 0;
	
	cin >> a >> b;
	for (int i=0; i<a; i++){
		int inter = i+1;
		for(int k=0; k<=i; k++){
		
			flag = 0;
			for(int j=inter; j<a; j++){
				if(b.at(k) == b.at(j)){
					flag = 1;
				}
			}
			if(flag == 1)result = result + b.at(k);
			
		}
		
		for(int k=0; std::abs(k)<result.size(); k++){
			
			flag = 0;
			for(int l=k-1; l >= 0; l--){
				if(result.at(k) == result.at(l)) flag = 1;
				
			}
			if(flag == 0) output++;
		}
		
		if(inst <= output) inst = output;
		output = 0;
	
		
		result = "";
	}
		cout << inst << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    int x, y;
};

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

    vector<P> p(n);
    int b = 0;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;

        if ((x + y) % 2 == 0) b++;
        p[i] = { x, y };
    }

    if (b % n) {
        cout << -1 << endl;
        exit(0);
    }
    b /= n;

    int l = 31;
    int m = l + b;
    vector<int> d(m, 1);
    int s = -b;
    for (int j = 0; j < l; j++) {
        s += d[j] = 1 << j;
    }

    cout << m << '\n';
    for (int j = 0; j < m; j++) {
        cout << d[j] << " \n"[j == m - 1];
    }

    const char *c = "LDUR";
    string r(m, 'R');
    for (int i = 0; i < n; i++) {
        uint32_t x = p[i].x - p[i].y + s;
        uint32_t y = p[i].x + p[i].y + s;

        for (int j = 0; j < l; j++) {
            x >>= 1;
            y >>= 1;
            r[j] = c[(x & 1) + (y & 1) * 2];
        }
        cout << r << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>

int main() {
    ll N, K; cin >> N >> K;
    vl h(N);
    rep(i,N) cin >> h[i];

    sort(h.begin(),h.end());

    vl a(N-K+1);
    rep(i,N-K+1) a[i] = h[K - 1 + i] - h[i];

    sort(a.begin(),a.end());

    cout << a[0] << endl;
}

Measured memory_bytes: 4748
#include <stdio.h>
#include <vector>

using namespace std;

int main(){

  int n, kin;
  vector <int> k;
  scanf("%d", &n);
  k.push_back(-1);
  for(int i=1;i<=n;++i){
    scanf("%d", &kin);
    k.push_back(kin);
  }
  
  for(int i=1;i<=n;++i){
    printf("node %d: key = %d, ", i, k[i]);
    if(i != 1)printf("parent key = %d, ", k[i/2]);
    if(i*2 < n+1)printf("left key = %d, ", k[i*2]);
    if(i*2+1 < n+1)printf("right key = %d, ", k[i*2+1]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2788
#include<bits/stdc++.h>    
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define pb push_back
#define inf 1e16
#define mod 1000000007
#define en '\n'
#define ld long double
ll pw(ll b, ll r){
	ll ans = 1;
	while(r){
		if(r&1)ans = (ans*b)%mod;
		b = (b*b)%mod;
		r>>=1;
	}
	return ans;
}
ll fact[100005];
ll ncr(ll n, ll r){
	if(n<r)return 0 ; 
	ll num = fact[n] ; 
	ll den = (fact[r]*fact[n-r])%mod;
	num = (num*pw(den,mod-2))%mod;
	return num;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,k;cin>>n>>k;
	for(int i = 0 ; i <= n ; i ++ ){
		if(i==0)fact[i]=1;
		else fact[i]=(i*fact[i-1])%mod;
	}
	ll arr[n];for(int i = 0 ; i < n ; i ++ )cin>>arr[i];
	sort(arr,arr+n,greater<ll>());
	vector<pi>v;
	ll val = arr[0],counter=0;
	for(int i = 0 ; i < n ; i ++ ){
		if(val==arr[i])counter++;
		else{
			v.pb({val,counter});
			counter=1;
			val=arr[i];
		}
	}
	v.pb({val,counter});
	ll cov = 0 ; 
	ll ans = 0 ; 
	ll left = n ; 
	for(int i = 0 ; i < v.size() ; i ++ ){
		ll add = 0, sub = 0 ;
		left-=v[i].second; 
		for(int j = 1 ; j <= min(k,v[i].second) ; j ++ ){
			add=(add+(ncr(cov,k-j)*ncr(v[i].second,j))%mod)%mod;
		}
		for(int  j = 1 ; j <= min(k,v[i].second) ; j ++ ){
			sub=(sub+(ncr(left,k-j)*ncr(v[i].second,j))%mod)%mod;
		}
		add = sub-add;
		while(add<0)add+=mod;
		ans = (ans+(add*(v[i].first<0?v[i].first+mod:v[i].first))%mod)%mod;
		while(ans<0)ans+=mod;
		cov+=v[i].second;
	}
	cout<<ans<<en;
	return 0 ; 
}



Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
const int N=2010;
int n,m,q,Right[N][N],down[N][N],cnt[N][N];
char s[N][N];
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for (int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++){
		cnt[i][j]=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1]+s[i][j]-'0';
		down[i][j]=down[i-1][j]+down[i][j-1]-down[i-1][j-1]+(s[i][j]=='1'&&s[i+1][j]=='1');
		Right[i][j]=Right[i-1][j]+Right[i][j-1]-Right[i-1][j-1]+(s[i][j]=='1'&&s[i][j+1]=='1');
	}
	while (q--){
		int x1,y1,x2,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int ans=(cnt[x2][y2]-cnt[x2][y1-1]-cnt[x1-1][y2]+cnt[x1-1][y1-1]);
		ans-=(down[x2-1][y2]-down[x2-1][y1-1]-down[x1-1][y2]+down[x1-1][y1-1]);
		ans-=(Right[x2][y2-1]-Right[x2][y1-1]-Right[x1-1][y2-1]+Right[x1-1][y1-1]);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 52992
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp> 
using namespace std; 

int minRoot;

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

    int K, N;
    cin >> K >> N;
    minRoot = K;

    vector<int> A(N, 0);
    for (int i = 0; i < N; ++i){
        cin >> A[i];
    } 

    vector<int> d(N, 0);
    for (int i = 0; i < N - 1; ++i){
        d[i] = A[i + 1] - A[i];
    }
    d[N - 1] = K - A[N - 1] + A[0];

    int max_d = 0;
    for (int i = 0; i < N; ++i){
        max_d = max_d < d[i] ? d[i] : max_d;
    }
    cout << K - max_d << "\n";

    return 0;
}



Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		a.Bs(100,false,x=>x);
		var h=new int[2];
		for(int i = 0;i<n;i++) {h[i&1]+=a[i];}
		Console.WriteLine("{0}",h[0]-h[1]);
	}
}
static class Ex1{
	public static void Bs<T>(this T[] a,int n,bool b,Func<T,int> f){
		var h=new int[n+1];
		var li=new List<T>[n+1];
		for(int i = 0;i<=n;i++) {li[i]=new List<T>();}
		for(int i=0;i<a.Length;i++) {li[f(a[i])].Add(a[i]);}
		if(b){for(int i=0,j=0;i<=n;i++) {foreach(T d in li[i]){a[j]=d;j++;}}}
		else{for(int i=n,j=0;i>=0;i--) {foreach(T d in li[i]){a[j]=d;j++;}}}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
signed main() {
	int ans = 0;
	int a[5], n; cin >> n;
	a[0] = 0; a[1] = 0; a[2] = 0; a[3] = 0;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		a[(int)(s[0] == 'B') * 2 + (int)(s.back() == 'A')]++;
		for (int i = 0; i < s.size() - 1; i++)if (s[i] == 'A'&&s[i + 1] == 'B')ans++;
	}
	if (!a[1] && !a[2])ans += max(0, a[3] - 1);
	else if (a[1] == a[2])ans += a[3] + a[1];
	else ans += min(a[1], a[2]) + a[3];
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define KETAMAX (15)
#define SETMAX (200)
using namespace std;
int main(void){
    
    int a[SETMAX] = {0};
    int b[SETMAX] = {0};
    int keta[SETMAX] = {0};
    int SetCount = 0;
    int ret = 0;
    char Dumy[KETAMAX] = {'\0'};
    
    while(1){
        
        ret = scanf("%d%d",&a[SetCount],&b[SetCount]);
        
        if(ret == EOF){
            break;
        }
        
        keta[SetCount] = sprintf(Dumy,"%d",(a[SetCount] + b[SetCount]));
        SetCount++;
    }
    
    for(int i = 0; i < SetCount; i++){
        printf("%d\n",keta[i]);
    }
    
    return(0);
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int dx[8]={0,1,0,-1,1,1,-1,-1},dy[8]={1,0,-1,0,1,-1,1,-1};
void dfs(int x,int y,int id,char c,int H,int W,vector<vector<int> >&vis,const vector<string>&S)
{
	vis[x][y]=id;
	for(int r=0;r<(c=='.'?4:8);r++)
	{
		int tx=x+dx[r],ty=y+dy[r];
		if(tx>=0&&ty>=0&&tx<H&&ty<W&&!vis[tx][ty]&&S[tx][ty]==c)
		{
			dfs(tx,ty,id,c,H,W,vis,S);
		}
	}
}
vector<vector<int> >f(int H,int W)
{
	vector<string>S(H+2,string(W+2,'.'));
	for(int i=0;i<H;i++)
	{
		cin>>S[i+1];
		S[i+1]="."+S[i+1]+".";
	}
	H+=2;
	W+=2;
	vector<vector<int> >vis(H,vector<int>(W,0));
	int sz=0;
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)
	{
		if(!vis[i][j])
		{
			dfs(i,j,++sz,S[i][j],H,W,vis,S);
		}
	}
	vector<vector<bool> >used(H,vector<bool>(W,false));
	vector<vector<int> >ret(sz);
	queue<pair<int,int> >P;
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)
	{
		if(vis[i][j]==1)
		{
			used[i][j]=true;
			P.push(make_pair(i,j));
		}
	}
	char now='.';
	while(!P.empty())
	{
		queue<pair<int,int> >Q;
		now=now=='.'?'#':'.';
		while(!P.empty())
		{
			int x=P.front().first,y=P.front().second;
			P.pop();
			for(int r=0;r<(S[x][y]=='.'?4:8);r++)
			{
				int tx=x+dx[r],ty=y+dy[r];
				if(tx>=0&&ty>=0&&tx<H&&ty<W&&!used[tx][ty]&&now==S[tx][ty])
				{
					used[tx][ty]=true;
					Q.push(make_pair(tx,ty));
					P.push(make_pair(tx,ty));
					if(vis[x][y]!=vis[tx][ty])
					{
						ret[vis[x][y]-1].push_back(vis[tx][ty]-1);
					}
				}
			}
		}
		P=Q;
	}
	for(vector<int>&g:ret)
	{
		sort(g.begin(),g.end());
		g.erase(unique(g.begin(),g.end()),g.end());
	}
	return ret;
}
string makehash(int u,const vector<vector<int> >&G)
{
	string ret="(";
	vector<string>A;
	for(int v:G[u])
	{
		A.push_back(makehash(v,G));
	}
	sort(A.begin(),A.end());
	for(string&s:A)ret+=s;
	ret+=")";
	return ret;
}
main()
{
	int H,W;
	while(cin>>H>>W,H)
	{
		vector<vector<int> >G1=f(H,W);
		cin>>H>>W;
		vector<vector<int> >G2=f(H,W);
		cout<<(makehash(0,G1)==makehash(0,G2)?"yes":"no")<<endl;
	}
}



Measured memory_bytes: 3504
import java.util.Scanner;

/**
 * A
 */
public class Main {

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a == b && b == c) {
            System.out.println("1");
        } else if (a == b || b == c || a == c) {
            System.out.println("2");
        } else {
            System.out.println("3");
        }
        
        sc.close();
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define N 2100
int len,ans;
char a[N],b[N];
int pre[N],nex[N],v[N];
int dis(int x,int y)
{
	if(x>y)swap(x,y);
	return min(y-x,x+len-y);
}
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%s%s",a,b);
	len=strlen(a);
	int fir=len,las=-1;
	for(int i=0;i<len;i++)if(b[i]=='1')
	{
		fir=min(fir,i);
		las=max(las,i);
	}
	if(fir==len)
	{
		for(int i=0;i<len;i++)if(a[i]=='1')
			return puts("-1"),0;
		return puts("0"),0;
	}
	int p=-1;
	for(int i=0;i<len;i++)
	{
		if(b[i]=='1')p=i;
		if(p==-1)pre[i]=len+i-las;
		else pre[i]=i-p;
	}
	p=len;
	for(int i=len-1;i>=0;i--)
	{
		if(b[i]=='1')p=i;
		if(p==len)nex[i]=len-i+fir;
		else nex[i]=p-i;
	}
	ans=1<<30;
	for(int i=0;i<len;i++)
	{
		int sum=0,tans=1<<30;
		memset(v,0,sizeof(v));
		for(int j=0;j<len;j++)
		{
			int t=(j+i)%len;
			if(a[j]=='1'&&b[t]=='0')
			{
				if(pre[j])
					v[pre[j]-1]=max(v[pre[j]-1],nex[j]);
				sum++;
			}
			if(a[j]=='0'&&b[t]=='1')
				sum++;
		}
		for(int j=len-1;j>=0;j--)
		{
			v[j]=max(v[j],v[j+1]);
			tans=min(tans,j+j+v[j]+dis(v[j],i));
			tans=min(tans,v[j]+v[j]+j+dis((len-j)%len,i));
		}
		ans=min(ans,tans+sum);
	}
	printf("%d\n",ans);
	return 0;
}


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

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

    int count = 1;
   rep(i, n-1) {
       if (s[i] != s[i+1]) count++;
   }

   cout << count << endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	vector<llong> a;
	map<llong, llong> m;

	cin >> N;
	a.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		m[a[i]]++;
	}

	if (m.size() == 1 && m[0] > 0) {
		cout << "Yes" << endl;
	} else if (N%3 != 0) {
		cout << "No" << endl;
	} else {
		if (m.size() != 3) {
			if (m[0] == N/3) {
				cout << "Yes" << endl;
			} else {
				cout << "No" << endl;
			}
		} else {
			map<llong, llong> mm;
			vector<llong> v;
			for (auto it = m.begin(); it != m.end(); ++it) {
				v.push_back(it->first);
				mm[it->second]++;
			}
			if (mm.size() != 1) {
				cout << "No" << endl;
			} else {
				if ((v[0]^v[2]) == v[1] && (v[1]^v[0]) == v[2] && (v[2]^v[1]) == v[0]) {
					cout << "Yes" << endl;
				} else {
					cout << "No" << endl;
				}
			}
		}
	}

	return 0;
}

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

template <int Mod, bool IsPrime = false>
class mod_int {
    using ll = long long;

public:
    constexpr mod_int() : n(0) {}
    constexpr mod_int(int n_) : n(n_) {
        if(n >= Mod)     n %= Mod;
        else if(n < 0) n = (n % Mod + Mod) % Mod;
    }
    constexpr mod_int(ll n_) : n(n_) { n = (n + Mod) % Mod; }

    constexpr operator int() const { return n; }
    constexpr operator ll() const  { return n; }

    constexpr bool operator==(mod_int const& other) const { return n == other.n; }
    constexpr mod_int& operator+=(mod_int const& other) {
        if((n += other.n) >= Mod) n -= Mod;
        return *this;
    }
    constexpr mod_int& operator-=(mod_int const& other) {
        if((n += Mod - other.n) >= Mod) n -= Mod;
        return *this;
    }
    constexpr mod_int& operator*=(mod_int const& other) {
        n = (unsigned long long)n * other.n % Mod;
        return *this;
    }
    constexpr typename std::enable_if<IsPrime, mod_int>::type& operator/=(mod_int const& other) {
        return *this *= other.inverse();
    }
    constexpr mod_int operator+(mod_int other) const { return mod_int(*this) += other; }
    constexpr mod_int operator-(mod_int other) const { return mod_int(*this) -= other; }
    constexpr mod_int operator*(mod_int other) const { return mod_int(*this) *= other; }
    constexpr mod_int operator/(mod_int other) const { return mod_int(*this) /= other; }

    constexpr typename std::enable_if<IsPrime, mod_int>::type inverse() const {
        ll a = n, b = Mod, u = 1, v = 0;
        while(b) {
            ll t = a / b;
            a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);
        }
        return mod_int(u);
    }

private:
    ll n;
};

template <int Mod, bool IsPrime>
std::ostream& operator<<(std::ostream& os, mod_int<Mod, IsPrime> const& n) {
    os << (int)n;
    return os;
}

constexpr int default_mod = 1000000007;

using mint = mod_int<default_mod, true>; // default

int main() {
    int n; cin >> n;
    vector<int> a(n);
    int xsum = 0, xsum_r = 0;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        xsum_r ^= a[i];
    }

    vector<mint> dp0(1 << 20), dp(1 << 20), pre_zero(1 << 20);
    mint ans = 1, zero = 0;
    for(int i = 0; i < n - 1; ++i) {
        xsum ^= a[i];
        xsum_r ^= a[i];
        if(xsum != 0) { // cancel lazy
            dp0[xsum] += (zero - pre_zero[xsum]) * dp[xsum];
            pre_zero[xsum] = zero;
        }
        if(xsum == xsum_r || xsum == 0) {
            if(xsum == xsum_r) ans += 1;
            ans += (xsum == 0 ? dp : dp0)[xsum_r];
        }
        if(xsum == 0) {
            zero += 1;
            dp[0] += mint(1) + dp[0];
        } else {
            dp[xsum] += mint(1) + dp0[xsum];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 26752
while true
  n = gets.to_i
  break if n == 0
  s = gets.strip

  n.times do |i|
    curc = nil
    count = 0
    temp_s = []
    s.each_char do |c|
      unless curc
        curc = c
      end
      if curc != c
        temp_s << count << curc
        count = 1
      else
        count += 1
      end
      curc = c
    end
    temp_s << count << curc if curc
    s = temp_s.join

  end
  puts s
end

Measured memory_bytes: 10332
import bisect
import math
import itertools

def main():
    s = set([1])
    m = 1000

    for b in range(2, int(math.sqrt(m)) + 1):
        for p in itertools.count(2):
            q = b ** p
            if q > m:
                break
            s.add(q)
    
    s = list(sorted(s))
    x = int(input())

    y = bisect.bisect_left(s, x)
    if s[y] == x:
        print(x)
    else:
        print(s[y-1])

main()


Measured memory_bytes: 3064
#include<iostream>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main()
{
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;
public class Main{ 
  public static void main(String[] args) {                       
    Scanner sc = new Scanner(System.in); 
    int H = sc.nextInt();
    int i=1;
    while(i<=H){
      while(true){
        int x = i;
        if(x%3==0){
          System.out.print(" "+i);
          i++;
          break;
        }
        while (true) { 
          if (x % 10 == 3) { 
            System.out.print(" "+ i);
            i++; 
            break; 
          } 
          x /= 10; 
          if (x != 0){
            continue; 
          }
          else{
            i++;
            break;
          } 
        }
        break;
      }
    }
    System.out.println("");
  }
}

Measured memory_bytes: 28908
n=int(input())
li=[]
for i in range(n):
  li.append(int(input()))
out=sum(li)
if out%10!=0:
  print(out)
else:
  li.sort()
  for i in li:
    if i%10!=0:
      print(out-i)
      break
  else:
    print(0)

Measured memory_bytes: 62368
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

macro_rules! eprint(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = write!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! eprintln(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! dbg {
    ($val:expr) => {
        // Use of `match` here is intentional because it affects the lifetimes
        // of temporaries - https://stackoverflow.com/a/48732525/1063961
        match $val {
            tmp => {
                eprintln!(
                    "[{}:{}] {} = {:#?}",
                    file!(),
                    line!(),
                    stringify!($val),
                    &tmp
                );
                tmp
            }
        }
    };
}

fn main() {
    input! {
        n: usize,
        a_v: [u64; n],
    }

    let answer = if a_v.iter().all(|&a| a % 2 == 0) {
        "second"
    } else {
        "first"
    };

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


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

int main(){
    string s;
    cin >> s;
    int count=0;
    rep(i,s.size()){
        if(s[i]!=s[s.size()-1-i]){
            count++;
        }
    }
    cout << count/2 << endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;


void main() {
    int n; scan(n);
    auto a = readln.split.to!(int[]);
    auto b = readln.split.to!(int[]);

    auto bk = new int[][][](30, 2, 0);

    foreach (i ; 0 .. 30) {
        foreach (bj ; b) {
            int bl = bj & ((1<<i) - 1);
            bk[i][(bj >> i) & 1] ~= bl;
        }

        bk[i][0].sort();
        bk[i][1].sort();
    }

    int ans;

    foreach (k ; 0 .. 30) {
        long cnt;

        foreach (ai ; a) {
            int al = ai & ((1<<k) - 1);

            int sw = (ai >> k) & 1;
            int ub = (1 << k) - al;
            cnt += bk[k][1-sw].assumeSorted.lowerBound(ub).length.to!int;
            cnt += bk[k][sw].length.to!int - bk[k][sw].assumeSorted.lowerBound(ub).length.to!int;
        }

        ans ^= ((cnt & 1) << k);
    }

    writeln(ans);
}








void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

public class Main{

    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);
        int input = Integer.parseInt(scan.nextLine());
        int cur = 1000;
       while(cur<input){
           cur+=1000;
       }
        System.out.println(cur-input);
    }

}

Measured memory_bytes: 35600
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define gap                        ' '
#define EPS                        1e-9
#define P_INF                      2e9+17
#define N_INF                     -2e9-17
#define MOD                        100000007
#define PI                         2*acos(0.0)
#define All(x)                     x.begin(),x.end()
#define Mem(Name, type)            memset(Name, type, sizeof(Name))

template<typename T>
T GCD(T a, T b) { return a ? GCD(b % a, a) : b; }

template<typename T>
T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto ob : v) os << ob << " ";
    return os;
}

template<typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
    for (auto ob : v) os << ob.first << " : " << ob.second << std::endl;
    return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class BDistance {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n, d, ans = 0;
        in >> n >> d;
        while (n--) {
            ll x, y;
            in >> x >> y;
            ld dis = sqrt((x * x) + (y * y));
            if (dis <= (ld) d) ans++;
        }
        out << ans << endl;
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    BDistance solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3676
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int main()
{
	int t, n;
	while (cin >> t, t) {
		cin >> n;
		int sum = 0;
		for (int i = 0; i < n; i++) {
			int s, f;
			cin >> s >> f;
			sum += abs(s - f);
		}
		if (sum < t)cout << t - sum << endl;
		else cout << "OK" << endl;
	}
	return 0;
}

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

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

    int n, k, t;
    cin >> n >> k;
    REP(i, n) cin >> t;

    cout << 1 + ((n - k) + (k - 2)) / (k - 1) << endl;

    return 0;
}

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

int main() {

#ifdef LOCAL_DEFINE
	freopen("input.txt", "rt", stdin);
#endif

	int a, b;
	cin >> a >> b;

	cout << (a - 1) * (b - 1) << endl;

#ifdef LOCAL_DEFINE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s. \n";
#endif

	return 0;
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(5);
  for (auto &e : a) {
    cin >> e;
  }
  ll b = a.front();
  for (auto e : a) {
    b = min(b, e);
  }
  cout << 5 + (n - 1) / b << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define gc getchar()
inline int read(){
	register int x(0);register char c(gc);
	while(c>'9'||c<'0')c=gc;
	while(c>='0'&&c<='9')x=x*10+c-48,c=gc;
	return x;
}
#define reset(a) memset((a),0,sizeof(a))
const int N=210000;
struct node{
	int val;
	int ID;
	int revID;
}a[N];
int b[N];
bool cmp(node x,node y){
	return x.val<y.val;
}
int in[N],cnt;
struct edge{
	int to,next;
}e[N*30];
int head[N],tot,HEAD[N];
void add(int x,int y){
//	cout<<x<<' '<<y<<'\n';
	e[++tot].next=head[x];e[tot].to=y;head[x]=tot;
	e[++tot].next=HEAD[y];e[tot].to=x;HEAD[y]=tot;
}
#define ls id<<1
#define rs id<<1|1
#define mid ((l+r)>>1)
void build(int l,int r,int id){
	if(l==r){
		in[id]=b[l];
		return;
	}
	build(l,mid,ls);
	build(mid+1,r,rs);
	in[id]=++cnt;
	add(in[id],in[ls]);
	add(in[id],in[rs]);
}
void IN(int l,int r,int x,int y,int to,int id){
	if(l>=x&&r<=y){
		add(to,in[id]);
		return;
	}
	if(x<=mid)IN(l,mid,x,y,to,ls);
	if(y>mid)IN(mid+1,r,x,y,to,rs);
}
#undef mid
int vis[N],turn[N],CNT,bl[N],n;
void clean(){
	reset(vis);reset(turn);reset(bl);CNT=tot=0;cnt=2*n;
	reset(head);reset(HEAD);reset(in);
}
void dfs1(int u){
	vis[u]=1;
	int i;
	for(i=head[u];i;i=e[i].next)
		if(!vis[e[i].to])dfs1(e[i].to);
	turn[++CNT]=u;
}
void dfs2(int u){
	bl[u]=CNT;
	for(int i=HEAD[u];i;i=e[i].next)
		if(!bl[e[i].to])dfs2(e[i].to);
}
void kosaraju(){
	register int i;
	for(i=1;i<=cnt;i++)
		if(!vis[i])dfs1(i);
	CNT=0;
	for(i=cnt;i>=1;i--)if(!bl[turn[i]]){
		CNT++;
		dfs2(turn[i]);
	}
}
int ans;
bool check(int now){
//	cout<<now<<'\n';
	clean();
	build(1,2*n,1);
	register int i;
	for(i=1;i<=n;i++)
		add(a[i].ID,n+a[i].revID),add(a[i].ID+n,a[i].revID);
	for(i=1;i<=n;i++){
		int l=1,r=i-1,L=i,R=i;
		while(l<=r){
			int mid=(l+r)>>1;
			if(a[i].val-a[mid].val<now)r=mid-1,L=mid;
			else l=mid+1;
		}
		l=i+1,r=n;
		while(l<=r){
			int mid=(l+r)>>1;
			if(a[mid].val-a[i].val<now)l=mid+1,R=mid;
			else r=mid-1;
		}
		if(L!=i)
			IN(1,2*n,L,i-1,a[i].ID,1);
		if(R!=i)
			IN(1,2*n,i+1,R,a[i].ID,1);
	}
	kosaraju();
	for(i=1;i<=n;i++)
		if(bl[a[i].ID]==bl[a[i].revID]||bl[a[i].ID]==bl[a[i].ID+n])return 0;
	return 1;
}
int main(){
	//freopen("T3.in","r",stdin);
	//freopen("T3.out","w",stdout);
	n=read();
	register int i;
	for(i=1;i<=n;i++){
		a[i*2-1].val=read();a[i*2].val=read();
		a[i*2-1].ID=i*2-1;a[i*2-1].revID=i*2;
		a[i*2].ID=i*2;a[i*2].revID=i*2-1;	
	}
	n*=2;
	cnt=2*n;	
	sort(a+1,a+1+n,cmp);
	for(i=1;i<=n;i++)
		b[i]=a[i].revID,b[i+n]=b[i]+n;
	int l=0,r=1e9;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid))ans=mid,l=mid+1;
		else r=mid-1;
	}
	cout<<ans;
}

Measured memory_bytes: 21632
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define SUB(a, b) (((a%MOD+MOD)%MOD-(b%MOD+MOD)%MOD+MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) (x/gcd(x,y)*y)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }
template<typename I> int ACC(I f, I l, int i){ return accumulate(f, l, i); }


int N, K;
VI g[100010];
int fact[100010], finv[100010];
 
 
int extGCD(int a, int b, int &x, int &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    int d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}
 
 
void makeFact(int n){
    fact[0] = 1;
    repe(i, 1, n) fact[i] = MUL(i, fact[i-1]);
    extGCD(fact[n], MOD, finv[n], finv[0]);
    finv[0] = 1;
    repr(i, n, 1) finv[i] = MUL(i+1, finv[i+1]);
}


int perm(int n, int k){
	if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return MUL(fact[n], finv[n-k]);
}


int dfs(int v = 0, int p = -1){
	int res = 1;
    rep(i, 0, SZ(g[v]))
        if(p != g[v][i]) CHMUL(res, dfs(g[v][i], v));
    if(!v) return MUL(res, perm(K-1, SZ(g[v])));
    return MUL(res, perm(K-2, SZ(g[v])-1));
}


signed main(){
	cin >> N >> K;
	rep(i, 0, N-1){
		int a, b;
        cin >> a >> b;
       	a--, b--;
        g[a].pb(b);
        g[b].pb(a);
    }

	makeFact(K);

    cout << MUL(K, dfs()) << endl;

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  string s, t;
  cin >> s >> t;
  int n = s.length();
  vector<int> sa(26, 0), ta(26, 0);
  vector<int> sv(n), tv(n);
  for(int i=0; i<n; i++){
    if(sa[s[i]-'a']){
      sv[i] = sa[s[i]-'a'];
    }else{
      sv[i] = i+1;
      sa[s[i]-'a'] = i+1;
    }
  }
  for(int i=0; i<n; i++){
    if(ta[t[i]-'a']){
      tv[i] = ta[t[i]-'a'];
    }else{
      tv[i] = i+1;
      ta[t[i]-'a'] = i+1;
    }
  }
  for(int i=0; i<n; i++){
    if(tv[i]!=sv[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 2440
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;
const int mod = 1e9+7;
int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int lcs(string a, string b) {
  int n = a.size(), m = b.size();
  int dp[2][m+1];
  for(int i = 0;i <= n;i++) {
    for(int j = 0;j <= m;j++) {
      if(i==0||j==0) dp[i%2][j] = 0;
      else {
        if(a[i-1] == b[j-1]) dp[i%2][j] = 1 + dp[1-i%2][j-1];
        else dp[i%2][j] = max(dp[i%2][j-1], dp[1-i%2][j]);
      }
    }
  }
  return dp[n%2][m];
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

bool equal(string s) {
  for(int i = 0,j = s.size()/2;j < s.size();i++,j++) {
    if(s[i] != s[j]) return false;
  }
  return true;
}

ll fact(int n) {
  ll ans = 1;
  fr(i,2,n+1) ans = (ans*i)%mod;
  return ans;
}

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int x = 0, ans = 0;
  trav(i,s) {
    if(i == 'I') x++;
    else x--;
    ans = max(ans,x);
  }
  ans = max(ans,x);
  cout<<ans;
}



Measured memory_bytes: 256
/**
 * C - GeT AC
 * https://atcoder.jp/contests/abc122/tasks/abc122_c
 **/
#include<iostream>
#include<string.h>
#include<vector>

using namespace std;

int main() {
    int N, Q;
    string S;
    cin >> N >> Q;
    cin >> S;
    vector<int> ac_map(N);
    int target=0;
    for(int i=0; i<S.length(); i++) {
        if(i==S.length()-1) {
            ac_map[i] = target;
        } else {
            ac_map[i] = target;
            if((S[i]=='A')&(S[i+1]=='C')) {
                target++;
            }
        }
    }
    vector<int> ans;
    for(int i=0; i<Q; i++) {
        int l, r;
        cin >> l >> r;
        if(l-1==0) {
            ans.push_back(ac_map[r-1]-0);
        } else {
            ans.push_back(ac_map[r-1]-ac_map[l-1]);
        }
    }
    cout << endl;
    for(auto a:ans) {
        cout << a << endl;
    }
}

Measured memory_bytes: 1912
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    bool North = false;
    bool South = false;
    bool West = false;
    bool East = false;
    string ans;
    string S;

    cin >> S;

    for (int i = 0, size=S.size(); i < size; i++) {
        if (S[i] == 'N') {
            North = true;
        } else if (S[i] == 'S') {
            South = true;
        } else if (S[i] == 'W') {
            West = true;
        } else {
            East = true;
        }
    }

    ans = not ((North^ South) or (West^East)) ? "Yes": "No";
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys

def input():
    return sys.stdin.readline()[:-1]
RS = input
RI = lambda x=int: x(RS())
RA = lambda x=int: map(x, RS().split())
RSS = lambda: RS().split()


def solve():
    ans = []
    for i in s:
        if i == "P":
            ans.append("P")
        else:
            ans.append("D")
    print("".join(ans))
    return



s = RS()
solve()

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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n+1);
    vector<ll> ans(n + 1);
    ll sum = 0;
    ll S = 0;
    for (int i = 1; i < n + 1; i++)
    {
        cin >> a[i];
        sum += a[i];
        if(i%2==0)
        {
            S += 2 * a[i];
        }
    }
    ans[1] = sum - S;
    for (int i = 2 ; i < n + 1; i++)
    {
        ans[i] = 2 * a[i - 1] - ans[i - 1];
    }
    for (int i = 1; i < n + 1;i++)
    {
        cout << ans[i] << " ";
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
 
  UnionFind(int n) {
    init(n);
  }
 
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
 
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
ll 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;
    }
}

// 二項係数計算
ll COM(ll n, ll 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() {
ll n,k; cin>>n>>k;
ll a = n - k;
COMinit();
for(ll i=1; i<=k; i++){
ll ca = COM(k-1,i-1)*COM(a+1,i);
ca%=MOD;
cout << ca << endl;}
}

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

int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1;
    cin >> h2 >> m2 >> k;
    cout << max(h2*60+m2-h1*60-m1-k,0) << endl;
    return 0;
}

Measured memory_bytes: 3632
fun main(args:Array<String>):Unit {
    val a = readLine()!!.split(' ').map(String::toInt)
    println(Time(a[3], a[4], a[5]) - Time(a[0], a[1], a[2]))
    val b = readLine()!!.split(' ').map(String::toInt)
    println(Time(b[3], b[4], b[5]) - Time(b[0], b[1], b[2]))
    val c = readLine()!!.split(' ').map(String::toInt)
    println(Time(c[3], c[4], c[5]) - Time(c[0], c[1], c[2]))
}
class Time(hour:Int, minute:Int, second:Int){
    private constructor(second:Int):this(second / 3600, (second % 3600) / 60, second % 60)
    private val mSecond = second % 60
    private val mMinute = (second / 60 + minute) % 60
    private val mHour = ((second / 60) + minute) / 60 + hour
    override fun toString(): String = "$mHour $mMinute $mSecond"
    operator fun plus(other:Time):Time = Time(mHour + other.mHour, mMinute + other.mMinute, mSecond + other.mSecond)
    operator fun minus(other:Time):Time = Time(mHour * 3600 + mMinute * 60 + mSecond - other.mHour * 3600 - other.mMinute * 60 - other.mSecond)
}


Measured memory_bytes: 32144
#include<iostream>
#include<cmath>
#include<cstdio>
struct Point{
	double x;
	double y;
};
void kock(int n,struct Point p1,struct Point p2){
	if(n==0){
		return;
	}
	Point s,t,u;
	s.x=(2*p1.x+p2.x)/3.0;
	s.y=(2*p1.y+p2.y)/3.0;
	t.x=(p1.x+2*p2.x)/3.0;
	t.y=(p1.y+2*p2.y)/3.0;
	u.x=(t.x-s.x)*cos((60*M_PI)/180)-(t.y-s.y)*sin((60*M_PI)/180)+s.x;
	u.y=(t.x-s.x)*sin((60*M_PI)/180)+(t.y-s.y)*cos((60*M_PI)/180)+s.y;
	
	kock(n-1,p1,s);
	printf("%.8f %.8f\n",s.x,s.y);
	kock(n-1,s,u);
	printf("%.8f %.8f\n",u.x,u.y);
	kock(n-1,u,t);
	printf("%.8f %.8f\n",t.x,t.y);
	kock(n-1,t,p2);
}
int main(){
	int n;
	std::cin>>n;
	struct Point p1,p2;
	p1.x=0.0; p1.y=0.0;
	printf("%.8f %.8f\n",p1.x,p1.y);
	p2.x=100.0; p2.y=0.0;
	kock(n,p1,p2);
	printf("%.8f %.8f\n",p2.x,p2.y);
	return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
#include <cassert>
#include<stdarg.h>
using namespace std;
typedef long long ll;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
 
/*sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);*/
 
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
 
struct debug {
	~debug() { cerr << endl; }
	
	//eni(!=) cerr << boolalpha << i; ris; }        Part 1
	
	template < class c > typename \
	enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
		cerr << boolalpha << i;
		return * this;
	}
	
	//eni(==) ris << range(begin(i), end(i)); }     Part 2
	
	template < class c > typename \
	enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
		return * this << range(begin(i), end(i)); 
	}
	
	/*sim, class b dor(pair < b, c > d) {           Part 3
		ris << "(" << d.first << ", " << d.second << ")";
	}*/
	
	template < class c, class b > debug & operator << (pair < b, c > d) {
		return * this << "(" << d.first << ", " << d.second << ")";
	}
	
	/*sim dor(rge<c> d) {                           Part 4
		*this << "[";
		for (auto it = d.b; it != d.e; ++it)
			*this << ", " + 2 * (it == d.b) << *it;
		ris << "]";
	}*/
	
	template < class c > debug & operator <<(rge<c> d) {
		*this << "[";
		for (auto it = d.b; it != d.e; ++it)
			*this << ", " + 2 * (it == d.b) << *it;
		return * this << "]";
	}
	
};

 
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define pb push_back
int INF = 1e9;
int arr[7] = {0, 1, 3, 2, 4, 6, 5};

int gcd(int a, int b){
	return __gcd(a, b);
}
void read(vector<ll> &a){
	for(ll &i : a) cin >> i;
}
void read(vector<int> &a){
	for(int &i : a) cin >> i;
}

void test_case(int tnum){
	int n;
	cin >> n;
	ll ans = 0; 
	ll tosub = 0;
	for(int i = 1; i <= sqrt(n-1); i++){
		for(int j = i; j * i < n; j++){
			ans++;
			if(i == j){
				tosub++;
			}
		}
	}
	ans *= 2;
	ans -= tosub;
	cout << ans << '\n';
}

 
//Can the answaer be binary searched?
//Any special cases? n=1/0;
//n^2 does it?
//Dp state?
 
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t;
	t = 1;
	// cin >> t;

	
	for(int i =1; i<=t;i++){
		test_case(i);
	}
}

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

int main() {
    std::size_t n{}, x{};
    std::cin >> n >> x;
    std::vector<std::size_t> l(n, 0);
    for (std::size_t i = 0; i < n; ++i)
        std::cin >> l[i];
    std::size_t d = 0;
    std::size_t c = 0;
    for (std::size_t i = 0; i <= n; ++i) {
        if (d > x)
            break;
        ++c;
        if (i < n)
            d += l[i];
    }
    std::cout << c << std::endl;
    return 0;
}

Measured memory_bytes: 256
/*
  Contest 102
  B - Maximum Difference
  Rakesh Kumar --> 27/09/2020
 */

#include <bits/stdc++.h>

using ll = long long int;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    ll n = 0;
    std::cin >> n;
    ll val = 0;
    std::cin >> val; n--;
    ll min = val;
    ll max = val;
    while (n--) {
        std::cin >> val;
        min = std::min(val, min);
        max = std::max(val, max);
    }
    std::cout << max - min << std::endl;

    return 0;
}


Measured memory_bytes: 3508
s = input();
count1 = 0;
for i in range(8) :
	if i < 4 :
		op1 = '+';
	else :
		op1 = '-';
	
	if count1 % 2 == 0 :
		op2 = '+';
	else :
		op2 = '-';
	
	if i % 2 == 0 :
		op3 = '+';
	else :
		op3 = '-';
		count1 += 1;
	
	ans = s[0] + op1 + s[1] + op2 + s[2] + op3 + s[3];
	if eval(ans) == 7 :
		print(ans+'=7');
		break;

Measured memory_bytes: 3060