akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 1010101010;

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

    int N;
    cin >> N;
    
    while(N != 0){
        vector<P> w;
        REP(i, N){
            int x, y;
            cin >> x >> y;
            w.pb(mp(y, x));
        }
        w.pb(w[0]);
        int xu = -20000, xd = 20000, yu = -20000, yd = 20000;
        REP(i, 4){
            int x, y;
            cin >> x >> y;
            chmax(yu, y);
            chmin(yd, y);
            chmax(xu, x);
            chmin(xd, x);
        }

        LL ans = 0;
        REP(i, N){
            int x1 = w[i].se;
            int x2 = w[i+1].se;
            int y = w[i].fi;
            ans += (x1 - x2) * y;
            x1 = max(xd, min(xu, x1));
            x2 = max(xd, min(xu, x2));
            y = max(yd, min(yu, y));
            ans -= (x1 - x2) * y;

        }
        cout << ans << endl;

        cin >> N;
    }

    return 0;
}


Measured memory_bytes: 3140
using System;
using System.Linq;

namespace Test
{
    
    class MainClass
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                var num = int.Parse(Console.ReadLine());

                if (num == 0) break;
                var points = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                var average = points.Average();
                var variance = (points.Select(x => (x - average) * (x - average)).Sum()) / num;
                var result = Math.Sqrt(variance);

                Console.WriteLine(result);
            }
        }
    }
}

Measured memory_bytes: 6028
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

X, Y, Z = map(int, readline().split())

X, Y, Z = Z, X, Y
print(X, Y, Z)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define mod 1000000007LL
#define FOR(i,m,n) for(int i = (m); i < (n); i++)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())
 
 
typedef long long ll;
typedef vector<int> vi; 
typedef pair<int,int> ii;


ll pow(ll a, ll b){
    int ans = 1;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}


const int N=1e5;


void run(){
	
	int a, b; cin>>a>>b;
	
	
	if(a%2 != b%2) cout<<"IMPOSSIBLE";
	else cout<<(a+b)/2;
	
	
	
}


int main(){
	
	fastio;
	
	int tt=1; 
	//cin>>tt;
	
	while(tt--){
		run();
	}
	
	return 0;
}


Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;

bool comp(const int& a, const int& b) {
	return a > b;
}

int main()
{
	ll ANS=0;
	ll X,S=100;
	cin >> X;
	for (int i = 1;;i++){
		ll t;
		t = S / 100;
		S = S+t;
		if (S >= X) {
			ANS = i;
			break;
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 3164
def answer(array)
  l = array.length
  counts = (0..l).map{|n| 0}
  array.each{|a|
    counts[a] = counts[a - 1] + 1
  }
  l - counts.max
end

def test()
  puts answer([1, 2]) == 0
  puts answer([2, 1]) == 1
  puts answer([4,1,3,2]) == 2
  puts answer([9,1,2,3,4,5,6,7,8]) == 1
  puts answer([1, 3, 2, 4]) ==  2
  puts answer([3,2,5,1,4,6]) == 4
  puts answer([3,2,5,1,4]) == 3
end

len = gets.to_i
arr = []
len.times{|n|
  arr << gets.to_i
}

print(answer(arr))

Measured memory_bytes: 5428
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int[] x = sc.IntArray();

        int answer = 0;

        for(int i = 0; i < 5; i++)
        {
            if(x[i] == 0)
            {
                answer = i + 1;
                break;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 28080
#include <iostream>
#include <string>
#include <cmath>
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long int ll;

ll ncr(ll n, ll r) {
  ll m = 1, p = 1;
  for(ll i=0; i<r; ++i){
		 m = m * (n-i);
	 }
  for(ll i=0; i<r; ++i){
		p = p * (i+1);
	}
  return m/p;
}

int main(){
	  int N;
		cin>>N;
	  vector<string> S(N);
		for (int i = 0; i < N; ++i) {
		  cin>>S[i];
			sort(S[i].begin(),S[i].end());
		}
    ll count=0;

		sort(S.begin(), S.end());
		ll ans = 0, tmp = 1;
		string cmp = S[0];
		for(int i=1; i<N; ++i) {
		  if(cmp == S[i]) {
		    ++tmp;
		  }
			else {
		    if(tmp > 1) ans += ncr(tmp,2);
		    tmp = 1;
		    cmp = S[i];
		  }
		}
		if(tmp > 1)
		  ans += ncr(tmp,2);
		cout<<ans<<endl;

}


Measured memory_bytes: 7296
#include<stdio.h>

int main(void){
  char s[100001];
  int q,i,S;
  int t[200001],f[200001];
  char c[200001];
  int k=0;
  char b[200001],a[200001];
  int B=0;
  int A=0;
  
  scanf("%s\n%d",s,&q);
  for(i=0;i<=q-1;i++){
    scanf("\n%d",&t[i]);
    if(t[i]==2){
      scanf(" %d %c",&f[i],&c[i]);
    }
  }
  
  S=0;
  while(s[S]!=NULL){
    S++;
  }
  S=S-1;
  
  for(i=0;i<=q-1;i++){
    if(t[i]==1){
      k++;
    }else{
      if((k+f[i])%2==1){
        b[B]=c[i];
        B++;
      }else{
        a[A]=c[i];
        A++;
      }
    }
  }
  
  if(k%2==0){
    for(i=B-1;i>=0;i--){
      printf("%c",b[i]);
    }
    for(i=0;i<=S;i++){
      printf("%c",s[i]);
    }
    for(i=0;i<=A-1;i++){
      printf("%c",a[i]);
    }
  }else{
    for(i=A-1;i>=0;i--){
      printf("%c",a[i]);
    }
    for(i=S;i>=0;i--){
      printf("%c",s[i]);
    }
    for(i=0;i<=B-1;i++){
      printf("%c",b[i]);
    }
  }
  
  
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll a,b,h,m; cin>>a>>b>>h>>m;
  long double pi=3.1415926536897932384;
  long double aa=(60*h+m)*pi/360,bb=m*pi/30;
  cout<<fixed<<setprecision(12);
  long double ans=pow(a*a+b*b-2*a*b*cos(aa-bb),0.5);
  co(ans);
  return 0;
}

Measured memory_bytes: 4172
lines = []
colums = []

while True:
 H,W = map(int,input().split())
 if H == 0 and W == 0:
   break
 lines.append(H)
 colums.append(W)

for H,W in zip(lines,colums):
 for i in range(H):
   if i == 0 or i == H-1:
     for j in range(W):
       print("#",end="")
   else:
     for j in range(W):
       if 0 < j and j < W-1:
         print(".",end="")
       else:
         print("#",end="")
   print("\n",end="")
 print("\n",end="")


Measured memory_bytes: 7016
xs = [parse(Int, x) for x in readlines()]

modup(x, n) = mod(n - mod(x, n), n)

dts = modup.(xs, 10)
# maxi = argmax(dts)
maxi = indmax(dts)

xsup = [Int(ceil(x / 10) * 10) for x in xs]
val = sum(xsup) - xsup[maxi] + xs[maxi]
print(val)

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

const int MAXN = 100005;
const int MOD = int(1e9) + 7;
const double PI = acos (-1.0);
const int INF = 0x3f3f3f3f;
const int dx[] = { -1, 0, 1, 0, 1, 1, -1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

template <class T> inline T min (T a, T b, T c) { return min (min (a, b), c); }
template <class T> inline T max (T a, T b, T c) { return max (max (a, b), c); }
template <class T> inline T min (T a, T b, T c, T d) { return min (min (a, b), min (c, d)); }
template <class T> inline T max (T a, T b, T c, T d) { return max (max (a, b), max (c, d)); }
template <class T> inline T min (T a, T b, T c, T d, T e) { return min (min (min (a, b), min (c, d)), e); }
template <class T> inline T max (T a, T b, T c, T d, T e) { return max (max (max (a, b), max (c, d)), e); }

string a;
bool vis[200005];
int main ()
{
    while (cin >> a)
    {
        memset(vis, 0, sizeof(vis));
        int lf, rg, end = a.length();
        lf = 0, rg = 1;
        int ans = end;
        while (rg < end)
        {
            if (a[lf] == 'S' && a[rg] == 'T')
            {
                vis[lf] = vis[rg] = 1;
                ans -= 2;
                while(lf >= 0 && vis[lf]) --lf;
                ++rg;
                while (lf >= 0 && rg < end)
                {
                    if(vis[lf])
                    {
                        --lf;
                        continue;
                    }
                    if (a[lf] == 'S' && a[rg] == 'T')
                    {
                        vis[lf] = vis[rg] = 1;
                        --lf, ++rg;
                        ans -= 2;
                    }
                    else
                        break;
                }
                if (vis[rg]) lf = rg + 1, rg += 2;
                else lf = rg, ++rg;
            }
            else 
                ++lf, ++rg;
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<long long> s(N);
    for (long long &t: s)
        cin>>t;

    long long ans = 0;
    for (int d=1; d<N; d++)
    {
        long long a = 0;
        int l = d;
        int r = N-1-d;
        while (l<N-1)
        {
            if (l==r || l==r+d || r<d)
                break;

            a += s[l];
            a += s[r];
            ans = max(ans, a);

            l += d;
            r -= d;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
 
 
int main(void)
{
    ll n; cin>>n;
    ll ans=1;
  bool ng = false;
    rep(i,n){
        ll a; cin>>a;
        if(a==0){
          cout << 0 << endl;
          return 0;
        }
        if(ans>1000000000000000000/a){
            ng = 1;
        }
      cerr << ans << endl;
        ans*=a;
    }
  if(ng)ans=-1;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

class wuf{
    public:
        wuf(){
            wuf(0);
        };
        wuf(int N){
            rnk.resize(N);
            par.resize(N);
            diff_weight.resize(N);
            for(int i=0;i<N;i++){
                rnk[i] = 0;
                par[i] = i;
                diff_weight[i] = 0;
            }
        }

        int root(int x){
            if(x == par[x]) return x;
            else{
                int r = root(par[x]);
                diff_weight[x] += diff_weight[par[x]];
                return par[x] = r;
            }
        }

        bool same(int x, int y){
            x = root(x); y = root(y);
            return x == y;
        }

        int weight(int x){
            root(x);
            return diff_weight[x];
        }

        int diff(int x, int y){
            return weight(y) - weight(x);
        }

        bool merge(int x, int y, int w){
            w += weight(x);
            w -= weight(y);

            x = root(x); y = root(y);
            if(x == y) return false;

            if(rnk[x] < rnk[y]) swap(x,y), w = -w;
            if(rnk[x] == rnk[y]) rnk[x]++;
            par[y] = x;
            diff_weight[y] = w;
            return true;
        }

    private:
        vector<int> rnk, par, diff_weight;
};

int main(){
    int N,M; cin >> N >> M;
    wuf wf = wuf(N);
    int x,y,d;
    for(int i=0;i<M;i++){
        cin >> x >> y >> d;
        x--; y--;
        if(!wf.same(x,y)){
            wf.merge(x,y,d);
        }else{
            if(wf.diff(x,y) != d){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<map>
#define M 1000000007
using namespace std;
map<long long,int> m;
int main(){
	long long h,w,n;
	cin>>h>>w>>n;
	for(long long u=0;u<n;u++){
		long long a,b;cin>>a>>b;
		long long i=a-1;if(i<2)i=2;
		while(i<h&&i<=a+1){
			long long j=b-1;if(j<2)j=2;
			while(j<w&&j<=b+1){
				long long k=i*M+j;
				map<long long,int>::iterator itr=m.find(k);
				if(itr==m.end()){
					m[k]=1;
				}
				else{
					itr->second++;
				}
				j++;
			}
			i++;
		}
	}
	int cnt[10];
	for(int i=0;i<10;i++)cnt[i]=0;
	map<long long,int>::iterator itr=m.begin();
	while(itr!=m.end()){
		cnt[itr->second]++;
		itr++;
	}
	int sum=0;
	for(int i=1;i<10;i++)sum+=cnt[i];
	cout<<(h-2)*(w-2)-sum<<endl;
	for(int i=1;i<10;i++){
		cout<<cnt[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
#define rep(i,s,t) for (int i=s;i<=t;++i)
const int maxn=1e5+10;
using namespace std;
typedef long long ll;
ll n,s;
ll f(ll b,ll n){
    return n<b?n:f(b,n/b)+n%b;
}
int main()
{
    scanf("%lld%lld",&n,&s);
     
    if (n==s) return 0*printf("%lld\n",n+1);
    for(ll i=2;i<=sqrt(n)+1;++i) if (f(i,n)==s) return 0*printf("%lld\n",i);
    if (n>s+1) for(ll i=sqrt(n);i;--i){
        ll b=(n-s)/i+1;
        if (f(b,n)==s) return 0*printf("%lld\n",b);
    }
    puts("-1");  
    return 0;
}
    

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	string s;
	getline(cin,s);
	if(s.find("C")<s.length()){
		int k=s.find("C");
		if(s.find("F",k)<s.length()) cout<<"Yes";
		else cout<<"No";
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (int argc, char const* argv[])
{
	int n;
	cin >> n;
	int even = 0;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if(x % 2 == 0) {
			++even;
		}
	}
	int p = 1;
	int q = 1;
	for(int i = 0; i < n; i++) {
		p *= 3;
	}
	for(int i = 0; i < even; i++) {
		q *= 2;
	}
	int ans = p - q;
	cout << ans << endl;
	return 0;
}

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



int main() {
  
  int X, N;
  scanf("%d %d", &X, &N);

  if(N==0){
    printf("%d\n", X);
    return 0;
  }

  vector<int> p(N);
  for(int i=0;i<N;i++){
    scanf("%d", &p[i]);
  }
  
  int N_MAX = 100;
  vector<int> v(N_MAX+2);
  for(int i=0;i<N;i++){
    v[p[i]]=1;
  }
  
  for(int i=0;i<N+1;i++){
    if(v[X-i]==0){printf("%d\n", X-i);break;}
    if(v[X+i]==0){printf("%d\n", X+i);break;}    
  }

  return 0;
}




Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
int n,y,ans,ic,uc,hc;
int main(){
    cin>>n>>y;


    for(int i=0;i<n+1;i++){
        if(1000*i>y||i>n)break;
        for(int u=0;u<n+1;u++){
            if(1000*i+5000*u>y||i+u>n)break;
            for(int h=0;h<n+1;h++){
                if(1000*i+5000*u+10000*h>y||i+u+h>n)break;
                if(1000*i+5000*u+10000*h==y&&i+u+h==n){
                    ic=h;
                    uc=u;
                    hc=i;
                    ans=1;
                    break;
                }
            }if(ans)break;
        }if(ans)break;
    }

    for(int i=0;i<1000000000;i++){
        int aho;
    }








    if(ans==1){
        cout<<ic<<" "<<uc<<" "<<hc<<endl;
    }else{
        cout<<"-1 -1 -1"<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

//????????£?¨?---------------------------
void print_rect(int H, int W);      //????????¢???????????¢??°
//------------------------------------
int main(void)
{
	int H, W;

	while(1){
		scanf("%d %d", &H, &W);
		
		if((H == 0) && (W == 0))
			break;
		else print_rect(H, W);
	}
	return 0;
}

//--------------------------------------------
void print_rect(int H, int W)
{
	for(int y = 0; y < H; y++){
		for(int x = 0; x < W; x++){
			if((((y%2) != 0) && ((x%2) == 0))
		    || (((x%2) != 0) && ((y%2) == 0))){
				printf(".");
			}
			else{
				printf("#");
			}
		}
		printf("\n");
	}
	printf("\n");
}

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
char a[7][7];
int h, w, k, ans = 0, black;

int main() {
    cin >> h >> w >> k;
    cin.ignore();
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++)
            cin >> a[i][j];
    }

    for(int C = 0; C < (1 << h); C++) {
        for(int R = 0; R < (1 << w); R++) {
            black = 0;

            for(int i = 0; i < h; i++)
                for(int j = 0; j < w; j++) {
                    if(((C >> i) & 1) == 0 && ((R >> j) & 1) == 0 && a[i][j] == '#')
                        black++;
                }

            if(black == k)
                ans++;
            
        }
    }
    cout << ans;
}

Measured memory_bytes: 3596
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,popcnt")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1<<19, mod = 1e9 + 7, i2 = (mod+1)/2;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	string s;
	cin >> s;
	int a = 0;
	for(auto i : s) {
		if(i == 'C' && a == 0) a++;
		if(i == 'F' && a == 1) a++;
	}
	cout << (a==2?"Yes\n":"No\n");
	return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int L[N];
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }
    int res = 0;
    for (int i = 0; i < N-2; i++) {
        for (int j = i + 1; j < N-1; j++) {
            if ( L[i] == L[j]) continue;
            for (int k = j + 1; k < N; k++) {
                int a = L[i];
                int b = L[j];
                int c = L[k];
                if ( a == c || b == c) continue;
                if ( a < b + c && b < a + c && c < a + b) {
                    res++;
                }
            }
        }
    }
    cout << res << endl;
}

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

int C(int n) {
	int count=0,a, b, c, d;
	for (a = 0; a <= 9; a++) {
		for (b = 0; b <= 9; b++) {
			for (c = 0; c <= 9; c++) {
				for (d = 0; d <= 9; d++) {
					if (a + b + c + d == n) {
						count += 1;
					}
				}
			}
		}
	}
	return count;
}

int main() {
	int n,ans;
	while(cin >> n){
		ans = 0;
		ans = C(n);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
int N,M,P,S,i,X[101];main(){while(true){S=0;scanf("%d%d%d",&N,&M,&P);if(N==0){break;}for(i=1;i<=N;i++){scanf("%d",&X[i]);S+=X[i];}printf("%d\n",X[M]==0?0:(100-P)*S/X[M]);}}

Measured memory_bytes: 2608
(let ((a (read))
      (b (read))
      (c (read))
      (k (read)))
  (loop until (> b a)
        while (> k 0)
        do (setf k (1- k)
                 b (* b 2)))
  (loop until (> c b)
        while (> k 0)
        do (setf k (1- k)
                 c (* c 2)))
  (format t "~A~%"
          (if (< a b c)
              "Yes"
              "No")))

Measured memory_bytes: 23580
#include <bits/stdc++.h>
using namespace  std;
#define MAXNUM 222222
#define rep(i,s,t) for(int i=s;i<t;i++)
typedef long long ll;
const ll mod=1e9+7;
void add(ll &a,ll b)
{
    a+=b;
    if(a>=mod)a-=mod;
}
int c[MAXNUM];ll bef[MAXNUM],dp[MAXNUM];
int main()
{
    int n;scanf("%d",&n);
    dp[0]=1;
    rep(i,1,n+1)
    {
        scanf("%d",&c[i]);
        dp[i]=dp[i-1];
        if(bef[c[i]]&&bef[c[i]]!=i-1)
            add(dp[i],dp[bef[c[i]]]);
        bef[c[i]]=i;
    }
    printf("%lld\n",dp[n]);
}

Measured memory_bytes: 4352
#include <complex>
#include <cmath>
#include <stdio.h>
using namespace std;
typedef complex<double> xy_t;
xy_t P[110], a, b, c;

double cross_product(xy_t a,xy_t b) {
  return (conj(a)*b).imag()/2.0;
}

int main () {
  int N=0; //??????????????????????????°???N??¨??????
  double x, y;
  while (~scanf("%lf,%lf", &x, &y)) {
    P[N++] = xy_t(x,y);
  }
  //??¢????¨????
  double sum = 0.0;
  for (int i=0; i+2<N; ++i) {
    xy_t a=P[0], b=P[i+1], c=P[i+2];
    sum += cross_product(b-a, c-a);
  }
  printf("%.6f\n", abs(sum));
}

Measured memory_bytes: 1088
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N = I()
A = LI()
"""
i番目を抜く時、iとi-1,iとi+1の距離を全体から引いて、そこにi-1とi+1の距離を足す
"""
A = [0] + A + [0]
total = 0
diff1 = []
diff2 = []
for aidx in range(len(A)):
    if aidx == 0:
        continue
    total += abs(A[aidx]-A[aidx-1])
    if aidx == len(A)-1:
        break
    diff1.append(abs(A[aidx] - A[aidx-1])+abs(A[aidx+1] - A[aidx]))
    diff2.append(abs(A[aidx-1] - A[aidx+1]))
#  print(total, diff1, diff2)
for aidx in range(N):
    print(total-diff1[aidx]+diff2[aidx])


Measured memory_bytes: 19568
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

class BIT {
	std::vector<int> bit;
	int size;
public:
	BIT() { }
	BIT(int sz) { init(sz); }
	void init(int sz) {
		bit = std::vector<int>((size = sz) + 1);
	}
	int sum(int i) {
		int s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	void add(int i, int x) {
		while (i <= size) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = -1;
		cin >> n;
		if (n <= 0) return 0;
		vector<int> a(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		int left = -1, right = 1e9;
		while (right - left > 1) {
			int mid = (right + left) / 2;
			BIT bit(n * 2 + 1);
			long long sum = n + 1, cnt = 0, need = (long long)n * (n + 1) / 4 + 1;
			bit.add(sum, 1);
			for (int i = 0; i < n; ++i) {
				sum += a[i] > mid ? 1 : -1;
				cnt += bit.sum(2 * n) - bit.sum(sum);
				bit.add(sum, 1);
			}
			if (cnt >= need) {
				right = mid;
			} else {
				left = mid;
			}
		}

		cout << right << endl;
	}
	return 0;
}


Measured memory_bytes: 1420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;

//a^b(mod p)をO(log b)で求める
ll calc(ll a,ll b){
  if(!b) return 1;
  if(b%2) return (a*calc(a,b-1))%MOD;
  ll d=calc(a,b/2);
  return (d*d)%MOD;
}

//aCb(mod MOD)
ll modpow(ll a,ll b){
  ll rtn=1;
  if(a<b) return 0; //a<bの場合は0
  if(a/2<b) b=a-b; //計算量削減

  for(ll i=a;i>a-b;i--){
    rtn*=i;
    rtn%=MOD;
  }
  for(ll i=b;i>0;i--){
    rtn*=calc(i,MOD-2);
    rtn%=MOD;
  }
  return rtn;
}

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

  for(ll i=1;i<=k;i++){
    ll ans=modpow(n-k+1,i);
    ans*=modpow(k-1,i-1);
    ans%=MOD;
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 256
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
   
    ll n,k,i,j,cn=0,st=0;
    cin>>n>>k;
    ll a[n+2];
    vector<ll> v;
    for(i=1;i<=n;i++) cin>>a[i];
    i = 1;
    bool vi[n+2] = {false};
    vi[1] = true;
    v.pb(1);
    while(1)
    {
    	if(vi[a[i]])
    	{
    		st = a[i];
    		break;
    	}
    	v.pb(a[i]);
    	vi[a[i]] = true;
    	i = a[i];
    }
    ll minu = 0,si=0;
   
    //for(auto u:v) cout<<u<<" ";
    for(i=0;i<v.size();i++)
    {
    	if(st==v[i])
    	{
    		minu = i;
    		si = v.size()-i;
    		break;
    	}
    }
    if(k<v.size()) cout<<v[k];
    else
    {
    	k -= minu;
    	//k--;
    	k %= si;


    	cout<<v[minu+k];
    }
 


}

Measured memory_bytes: 7068
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    string s;
    cin >> s;
    if (s.substr(0,4) == "YAKI")cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

     int c[10][10], a[201][201];

     int i, j, h, w, k, s;

     cin>>h>>w;

     for( i=0; i<10; i++)
          for( j=0; j<10; j++)
               cin>>c[i][j];

     for( i=1; i<=h; i++)
          for( j=1; j<=w; j++)
               cin>>a[i][j];

     for ( k = 0; k < 10; ++k)
        for (i = 0; i < 10; ++i)
            for (j = 0; j < 10; ++j)
                if (c[i][k] + c[k][j] < c[i][j])
                    c[i][j] = c[i][k] + c[k][j];

     s = 0;

     for( i=1; i<=h; i++)
          for( j=1; j<=w; j++)
               if( a[i][j] != -1  )
                    s += c[a[i][j]][1];

     cout<<s;




     return 0;
}


Measured memory_bytes: 384
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder
{
    class Program
    {
        //メイン関数
        static void Main(string[] args)
        {
            int x = ReadI();

            WriteLine((24 - x) + 24);
        }

        //メインじゃない関数
        private static string Read() { return ReadLine(); }
        private static int ReadI() { return int.Parse(ReadLine()); }
    }
}


Measured memory_bytes: 11092
N=int(input())
A=list(map(int,input().split()))
A.sort()
idx=N
for i in range(N):
    if A[i]>0:
        idx=i
        break
if idx==0:
    print(sum(A))
elif idx==N:
    print(sum(A[(N//2)*2:])-sum(A[:(N//2)*2]))
else:
    x=sum(A[(idx//2)*2:])-sum(A[:(idx//2)*2])
    y=sum(A[((idx+1)//2)*2:])-sum(A[:((idx+1)//2)*2])
    z=sum(A[(1+idx//2)*2:])-sum(A[:(1+idx//2)*2])
    print(max(x,y,z))

Measured memory_bytes: 14496
#include <stdio.h>
int main(){
	char b[110],s[110]={0},*q,*p;
	while(fgets(b,105,stdin),*b!='.'){
		q=s+1;
		for(p=b;*p!='.';p++){
			if(*p=='('||*p=='[') *q++=*p;
			if(*p==')'||*p==']'){
				q--;
				if(!((*q=='('&&*p==')')||(*q=='['&&*p==']'))){
					puts("no");
					break;
				}
			}
		}
		if(*p=='.')puts(q==s+1?"yes":"no");
	}
return 0;
}

Measured memory_bytes: 0
# Aizu Problem 0279: A Pair of Prizes

import sys, math, os, datetime

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    n = int(input())
    if n == 0:
        break
    t = [int(_) for _ in input().split()]
    if max(t) < 2:
        print("NA")
    else:
        print(1 + len([i for i in t if i > 0]))

Measured memory_bytes: 9728
///////////////////////////////////////////// Template /////////////////////////////////////////////
#![allow(non_snake_case, unused)]
use std::collections::*;

//////////////////// missing functions in 1.15.1 ////////////////////
macro_rules! eprint {
	($($t:tt)*) => { {
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	} };
}
macro_rules! eprintln {
	($($t:tt)*) => { {
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	} };
}

//////////////////// useful functions ////////////////////
pub trait SetMin {
	fn setmin(&mut self, v: Self) -> bool;
}
impl<T> SetMin for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
}
pub trait SetMax {
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMax for T where T: PartialOrd {
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

macro_rules! debug {
	($($v: expr),*) => {
		$(eprint!("{} = {:?} ", stringify!($v), $v);)*
		eprintln!("@ {}:{}", file!(), line!());
	}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:ty),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}
////////////////////////////////////////////////////////////////////////////////////////////////////

fn s(mut n: i64) -> i64 {
	let mut s = 0;
	while n > 0 {
		s += n % 10;
		n /= 10;
	}
	s
}

fn run() {
	let n = read!(i64);
	println!("{}", ["No", "Yes"][(n % s(n) == 0) as usize]);
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  int key = 0;
  string c = b;
  for(int i = 0;i<a.size();i++){
    if(a == b){
      cout << "Yes" << endl;
      key = 1;
      break;
    }
    char tmp = a.at(a.size()-1);
    c.at(0) = tmp;
    for(int i = 1;i<a.size();i++){
      c.at(i) = a.at(i-1);
    }
    a = c;
  }
  if(key == 0){
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define md %998244353
#define INF 2e9
#define EPS 1e-9
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define endl "\n"
#define FOR(i,a,b) for (long long i = a; i < b; i++)
#define REV(i,a,b) for (long long i = a; i > b; i--)
#define mset(a, v) memset(a, v, sizeof(a))
#define fd(n) fixed<<setprecision(n)
typedef std::pair<int, int> pii;
typedef std::vector<long long> vi;
typedef std::vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll solve(ll x,ull y,ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
 ll n,k;
  cin>>n>>k;
  ll a[n];
  for(ll i=0;i<n;i++)
     cin>>a[i];
  sort(a,a+n);
  ll ans=0;
  
  for(ll i=0;i<k;i++)
     ans = ans + a[i];
  cout<<ans;
  
}


Measured memory_bytes: 3668
count = int(input())

num = map(int, input().split())

n_max = -1000001
n_min = 1000001
n_sum = 0

for n in num:
    n_sum += n
    if n_max < n:
        n_max = n
    
    if n_min > n:
        n_min = n

print(f'{n_min} {n_max} {n_sum}')
    


Measured memory_bytes: 6336
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
edge1 = []
edgeN = []
for _ in range(M):
    s, n = map(int, input().split())
    if s == 1:
        edge1.append(n)
    elif n == N:
        edgeN.append(s)
if len(set(edge1) & set(edgeN)) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 21852
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <random>
#include <fstream>

#define REP(i, N) for(int i = 0; i< N; i++)
using namespace std;
#define ll long long

int main(){
   /* int N, K;
    char S[101];
    cin >> N >> K;
    cin >> S;
    char Skotae[101];
    REP(i, N){
        Skotae[i] = S[i];
    }
    sort(Skotae, Skotae + N);
    int chigau[101] = 0;
    REP(i, N){
        if(Skotae[N - i - 1] )
    }*/
    char S[500], T[500];
    cin >> S;
    cin >> T;
    int nagasa = strlen(S);
    int nagasat = strlen(T);
    int hatenanagasa = 0;
    int tstart = -1;
    REP(i, nagasa){
        int ikeru = 0;
      //  printf("%c,%d,%c,%d\n",S[nagasa - i - 1], nagasa - i - 1, T[nagasat - hatenanagasa - 1], nagasat -hatenanagasa - 1);
        if(S[nagasa - i - 1] == '?' ) {hatenanagasa++;ikeru = 1;}
        else {
            REP(j, hatenanagasa + 1){
                if(S[nagasa - i - 1] == T[nagasat - hatenanagasa - 1 + j]){
                    ikeru = 1;
                    hatenanagasa = hatenanagasa - j + 1;
                    break;
                }
            }
        }
        if(ikeru == 0)hatenanagasa = 0;
        if(hatenanagasa >= nagasat) {tstart = nagasa - i - 1;break;}
    }
    //printf("%d\n", tstart);
    if(tstart == -1) printf("UNRESTORABLE");
    else{
        REP(i, nagasa){
            if(i >= tstart && i < tstart + nagasat){
                printf("%c", T[i - tstart]);
            }
            else if(S[i] == '?') printf("a");
            else printf("%c", S[i]);
            }
        }
    printf("\n");

}


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

using namespace std;

#define ll 			long long
#define db			double
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cadd(a,b)		a = add (a, b)
#define cpop(a,b)		a = pop (a, b)
#define cmul(a,b)		a = mul (a, b)
#define pr			pair<int, int>
#define fi			first
#define se			second
#define SZ(x)		(int)x.size()
#define bin(i)		(1 << (i))
#define Auto(i,node)	for (int i = LINK[node]; i; i = e[i].next)

template<typename T> inline bool cmax(T & x, T y){return y > x ? x = y, true : false;}
template<typename T> inline bool cmin(T & x, T y){return y < x ? x = y, true : false;}
template<typename T> inline T dmax(T x, T y){return x > y ? x : y;}
template<typename T> inline T dmin(T x, T y){return x < y ? x : y;}

const int MAXN = 5e6 + 5;

ll ans[MAXN], pw[MAXN];
int cnt = 0;

inline int get(ll w, int d) { return w / pw[d] % 10; }

inline db calc(ll w){
	int sum = 0;
	ll x = w;
	while (x) {
		sum += x % 10;
		x /= 10;
	}
	return sum;
}

inline bool cmp(ll a, ll b){
	ll ca = calc(a), cb = calc(b);
	return a * cb < b * ca;
}

int main(){
#ifdef cydiater
	freopen("input.in", "r", stdin);
#endif
	ll n; scanf("%lld", &n);
	pw[0] = 1;
	up (i, 1, 17) pw[i] = pw[i - 1] * 10;
	up (d, 0, 15) {
		ll cur = pw[d];
		up (i, 0, d - 1) {
			ll tmp = pw[d] + pw[i + 1] - 1;
			if (cmp(tmp, cur)) cur = tmp;
			else break;
		} 
		ans[++cnt] = cur; 
		while (true) {
			ll nxt1 = -1, nxt2 = -1;
			up (i, 0, d) if (get(cur, i) < 9) {
				nxt1 = cur + pw[i];
				if (i > 0) nxt2 = cur + pw[i - 1];
				break;
			} 
			if (nxt1 == -1) break;
			cur = (nxt2 == -1 || cmp(nxt1, nxt2)) ? nxt1 : nxt2;
			ans[++cnt] = cur;
			if (cnt >= n) break;
		}
	}
	assert(cnt >= n);
	up (i, 1, n) printf("%lld\n", ans[i]);
	return 0;
}



Measured memory_bytes: 2304
#include<bits/stdc++.h>
typedef long long LL;
const LL maxn=1e6+9;
inline LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
LL T,n,sum;
LL a[maxn],ans[maxn];
int main(){
	n=Read();
	for(LL i=1;i<=n;++i) a[i]=2*Read(),sum+=a[i];
	sum/=2;
	for(LL i=1;i<n;i+=2) sum-=a[i];
//	printf("%lld\n",sum);
	ans[1]=a[n]-sum;
	for(LL i=2;i<=n;++i) ans[i]=a[i-1]-ans[i-1];
	for(LL i=1;i<=n;++i) printf("%lld ",ans[i]);
	return 0;
}

Measured memory_bytes: 6144
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node{int p/* ??????u?????? */,l/* ??????u?????????????????? */ ,r/* ??????u????????????????????? */;};

Node T[MAX]; //????????°
int n/*??\??????????????°*/, D[MAX];

void print(int u){ // ??????u????????±???????????????
	int i,c;
	cout << "node " << u << ": "; // ??????u???????????????
	cout << "parent = " << T[u].p << ", "; // ??????u??????
	cout << "depth = " << D[u] << ", "; // ??????u?????±???

	if(T[u].p == NIL) cout << "root, "; // ???????????¨????????????????????????????????§??????
	else if(T[u].l == NIL) cout << "leaf, "; // ???????????¨????????????????????????????????§??????
	else cout << "internal node, "; // ??????u????????¨???????????§??????

	cout << "[";

	for(i=0,c=T[u].l ; c != NIL ; i++,c=T[c].r){ // ????????????????????????????????¢?´¢????????????
		if(i) cout << ", ";
		cout << c;
	}
	cout << "]" << endl;
}

// ?????°????????±???????±???????
int rec(int u, int p){
	D[u] = p;
	if(T[u].r != NIL) rec(T[u].r,p); // ???????????????????????±???????¨????
	if(T[u].l != NIL) rec(T[u].l,p+1); // ?????????????????????????????±???+1????¨????
}

int main(){
	int i,j,d/*?¬???°*/,v/*????????????*/,c,l,r;
	cin >> n;
	for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;

	for(i=0;i<n;i++){
		cin >> v >> d;
		for(j=0;j<d;j++){
			cin >> c;
			if(j==0) T[v].l = c; // ????????????????????\?????????
			else T[l].r = c; // ??????????????????????????\?????????
			l = c;
			T[c].p = v;
		}
	}
	for(i=0;i<n;i++){
		if(T[i].p == NIL) r=i;
	}

	rec(r,0);

	for(i=0;i<n;i++) print(i);

	return 0;
}

Measured memory_bytes: 7776
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
typedef pair<int,int> pii;
pii a[maxn];
int main() {
    int n;
    scanf("%d",&n);
    for(int i = 1;i <= n;++i) {
        scanf("%d",&a[i].first);
        a[i].second = i;
    }
    sort(a + 1, a + 1 + n);
    for(int i = 1;i <= n;++i) printf("%d%c",a[i].second,i == n ? '\n' : ' ');
    return 0;
}


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

void Main()
{
  int N; cin >> N;
  vector<int> A(N);
  map<int, int> m;
  rep(i,N) {
    cin >> A[i];
    if (m.find(A[i]) == m.end()) m[A[i]] = 1;
    else m[A[i]] = (m[A[i]]+1)%2;
  }
  map<int,int>::iterator it;
  int ans = 0;
  for (it = m.begin(); it != m.end(); it++) ans += it->second;
  cout << ans << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;

	int ans = 0;
	rep(i, 1, N + 1) {
		if (1 <= i and i <= 9) ans++;
		else if (100 <= i and i <= 999) ans++;
		else if (10000 <= i and i <= 99999) ans++;
	}
	cout << ans << endl;
}







Measured memory_bytes: 384
/*
 * omg.cpp
 *
 *  Created on: 2019/06/03
 *      Author: J01003
 */
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
	int x;
	cin>>x;
	cout<<x*x*x<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n,res=0;
    scanf("%d",&n);
    int d[n];
    for(int i=0;i<n;i++){
        scanf("%d",&d[i]);
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            res+=d[i]*d[j];
        }
    }
    printf("%d\n",res);
    return 0;
    
}

Measured memory_bytes: 128
N = int(input())
W = list([str(input()) for _ in range(N)])
f = 1

for i in range(N-1):
  if W[i][-1] != W[i+1][0]:
    f = 0
    break

for i in range(N):
  if W.count(W[i]) != 1:
    f = 0
    break
    
if f == 1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define pb push_back
#define w(x) int x; cin>>x; while(x--)
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define ff first
#define ss second
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define me max_element
const int mod = 1e9 + 7;

void ganekasar() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

ll n;

ll mul(ll& a, ll b)
{
    return a*b%mod;
}

void add_self(ll& a, ll b)
{
    a += b;

    if(a>mod)
        a -= mod;
}

struct M 
{
    vvi t;

    M()
    {
        t.resize(n, vi(n));
    }

    M operator*(M &b)
    {
        M c = M();

        f(i,n)
            f(j,n)
                f(k,n)
                    add_self(c.t[i][k], mul(t[i][j], b.t[j][k]));

        return c;
    }
};

int main() 
{
    ganekasar();
    
    ll k;
    cin>>n>>k;

    vvi can(n, vi(n));

    f(i,n) f(j,n) cin>>can[i][j];

    M answer = M();

    f(i,n) answer.t[i][i] = 1;

    M m;

    f(i,n) f(j,n) m.t[i][j] = can[i][j];

    while(k)
    {
        if(k&1)
            answer = answer*m;
        m = m*m;
        k /= 2;
    }

    ll total = 0;

    f(i,n) f(j,n) add_self(total, answer.t[i][j]);

    cout<<total<<endl;

    return 0; 
} 

Measured memory_bytes: 3684
def main():
  while True:
    n = int(input())
    if n == 0:
      break
    wlst = list(map(int, input().split()))
    connect = [[None] * n for _ in range(n)]
    for i in range(n):
      for j in range(n):
        connect[i][j] = abs(wlst[i] - wlst[j]) <= 1
    
    max_lst = [[False] * (n + 1) for _ in range(n + 1)]
    for i in range(n + 1):
      max_lst[0][i] = True
    
    dp = [[0] * n for _ in range(n + 1)]
    
    def check(length, left):
      ret = dp[length - 1][left]
      for k in range(length - 1, 0, -2):
        if not max_lst[length - k - 1][left + k]:continue
        if connect[left + k - 1][left + length - 1]:
          temp = length - k + 1 + dp[k - 1][left]
          if ret < temp:
            ret = temp
      return ret
    
    for length in range(2, n + 1):
      for left in range(n - length + 1):
        dp[length][left] = check(length, left)
        if dp[length][left] == length:
          max_lst[length][left] = True
    
    print(dp[n][0])

main()
  


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX 1000000007
int main(){
  ll n,k,ans=0;
  cin>>n>>k;
  for(ll m=k;m<=n+1;m++){
    ans+=((2*n-m+1)*m/2-(m-1)*(m)/2+1)%MAX;
  }
  cout<<ans%MAX;
    
 
}

Measured memory_bytes: 3632
#include <array>
#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;
constexpr uint64_t mod = 1e9 + 7;

template <int N> struct Factors {
  uint64_t fcts[N + 1];
  uint64_t invs[N + 1];
 public:
  constexpr static uint64_t mod_pow(uint64_t num, uint64_t p) {
    uint64_t ans = 1;
    num %= mod;
    while (0 < p) {
      if (p & 1) {
        ans = (ans * num) % mod;
      }
      num = (num * num) % mod;
      p >>= 1;
    }
    return ans;
  }

  constexpr Factors() : fcts(), invs(){
    fcts[0] = 1;
    for (uint64_t i = 1; i <= N; i++)
      fcts[i] = i;
    for (uint64_t i = 2; i <= N; i++) {
      fcts[i] = (fcts[i] * fcts[i - 1]) % mod;
    }

    invs[N] = mod_pow(fcts[N], mod - 2);
    for (int i = N - 1; 0 <= i; i--)
      invs[i] = ((uint64_t)invs[i + 1] * (i + 1)) % mod;
  }

  uint64_t comb(uint64_t m, uint64_t n) const {
    if (m == 0 || n == 0)
      return 1;
    return (((uint64_t)fcts[m] * invs[n]) % mod) * invs[m - n] % mod;
  }

  uint64_t comb_h(uint64_t m, uint64_t n) const {
    if (m == 0 || n == 0)
      return 1;
    return (((uint64_t)fcts[n + m - 1] * invs[n]) % mod) * invs[m - 1] % mod;
  }
  void dump() const {
    for (int i = 0; i < 20; ++i) {
      cout << fcts[i] << " " << flush;
    }
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  constexpr Factors<200000> cfactors;

  size_t n, m;
  cin >> n >> m;
  vector<pair<int, int>> factors;
  for (int i = 2; m != 1; ++i) {
    int num = 0;
    while (m % i == 0) {
      num++;
      m /= i;
    }
    if (0 < num) {
      factors.push_back(make_pair(i, num));
    }
  }
  int ans = 1;
  for (size_t i = 0; i < factors.size(); ++i) {
    int count = factors[i].second;
    ans = (ans * cfactors.comb_h(n, count)) % mod;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 888