akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] -= 1

memo = [0] * n

index = 0
memo_index = 0
cnt_k = 1
while 1:
    tmp_move_to = a[index]
    if not memo[tmp_move_to]:
        memo[tmp_move_to] = 1
        index = tmp_move_to
        if cnt_k == k:
            print(tmp_move_to + 1)
            exit()
        cnt_k += 1
    else:
        break
k -= cnt_k

kaburi = tmp_move_to
circle = [kaburi]

index = kaburi
while 1:
    if kaburi == a[index]:
        break
    else:
        circle.append(a[index])
        index = a[index]
# print(circle)
print(circle[k % len(circle)] + 1)


Measured memory_bytes: 94140
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >>m;
    long long ans=0;
    vector<long long> x,y,z;
    for(int i =0;i<n;i++){
        long long a,b,c;
        cin >> a>>b>>c;
        // cerr<< a<<b<<c<<endl;
        x.push_back(a);
        y.push_back(b);
        z.push_back(c);
    }
    vector<long long> score1,score2,score3,score4,score5,score6,score7,score8;
    for(int i =0;i<n;i++){
        score1.push_back(x[i]+y[i]+z[i]);
        score2.push_back(x[i]+y[i]-z[i]);
        score3.push_back(x[i]-y[i]+z[i]);
        score4.push_back(-x[i]+y[i]+z[i]);
        score5.push_back(x[i]-y[i]-z[i]);
        score6.push_back(-x[i]-y[i]+z[i]);
        score7.push_back(-x[i]+y[i]-z[i]);
        score8.push_back(-x[i]-y[i]-z[i]);
    }
    sort(score1.begin(),score1.end());
    reverse(score1.begin(),score1.end());
    sort(score2.begin(),score2.end());
    reverse(score2.begin(),score2.end());
    sort(score3.begin(),score3.end());
    reverse(score3.begin(),score3.end());
    sort(score4.begin(),score4.end());
    reverse(score4.begin(),score4.end());
    sort(score5.begin(),score5.end());
    reverse(score5.begin(),score5.end());
    sort(score6.begin(),score6.end());
    reverse(score6.begin(),score6.end());
    sort(score7.begin(),score7.end());
    reverse(score7.begin(),score7.end());
    sort(score8.begin(),score8.end());
    reverse(score8.begin(),score8.end());
    vector<long long> sum;
    long long num1=0,num2=0,num3=0,num4=0,num5=0,num6=0,num7=0,num8=0;
    for(int i =0;i<m;i++){
        num1+=score1[i];
    }
    sum.push_back(num1);
    // cout<<num1<<endl;
    for(int i =0;i<m;i++){
        num2+=score2[i];
    }
    sum.push_back(num2);
    // cout<<num2<<endl;
    for(int i =0;i<m;i++){
        num3+=score3[i];
    }
    sum.push_back(num3);
    // cout<<num3<<endl;
    for(int i =0;i<m;i++){
        num4+=score4[i];
    }
    sum.push_back(num4);
    // cout<<num4<<endl;
    for(int i =0;i<m;i++){
        num5+=score5[i];
    }
    sum.push_back(num5);
    // cout<<num5<<endl;
    for(int i =0;i<m;i++){
        num6+=score6[i];
    }
    sum.push_back(num6);
    // cout<<num6<<endl;
    for(int i =0;i<m;i++){
        num7+=score7[i];
    }
    sum.push_back(num7);
    // cout<<num7<<endl;
    for(int i =0;i<m;i++){
        num8+=score8[i];
    }
    sum.push_back(num8);
    // cout<<num8<<endl;
    for(int i =0;i<8;i++){
        long long hoge = sum[i];
        ans = max(ans,hoge);
    }
    cout <<ans << endl;
}

Measured memory_bytes: 384
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define set(x) cout<<fixed<<setprecision(x);
using namespace std;
//**********************************************DO IT NO****************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{   
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    {  
      int a,b,c,x,y;
      cin>>a>>b>>c>>x>>y;
      int p=a*x+b*y;
      int q=min(x,y);
      int r,r1;
        r=2*c*max(x,y);
        r1=2*q*c;
        if(x<y)
           r1+=(y-x)*b;
           else if(y<x)
          r1+=(x-y)*a;
      cout<<min(p,min(r,r1));
    }
}
// 🍪 🍪 🍪


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define rep(i, n) for(i = 0; i < (int)(n); i++)
using namespace std;

signed main() {
	int a, b;
	
	cin >> a >> b;
	if ((a * b) % 2) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}

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

int main() {
    int N; cin >> N;
    int K; cin >> K;
    int R = min(N, K);
    vector<int> V(N);
    rep(i, N){
        cin >> V[i];
    }

    int fa = 0;
    for (int i = 0; i <= R; i++){
        for (int j = 0; j <= R-i; j++){
            priority_queue<int, vector<int>, greater<int> > Q;
            for (int k = 0; k < i; k++){
                Q.push(V[k]);
            }
            for (int k = 0; k < j; k++){
                Q.push(V[N-1-k]);
            }
            for (int k = 0; k < K-i-j; k++){
                if(Q.empty())break;
                int x = Q.top();
                if(x < 0){
                    Q.pop();
                } else {
                    break;
                }
            }
            int ans = 0;
            while(!Q.empty()){
                int y = Q.top(); Q.pop();
                ans += y;
            }
            fa = max(fa, ans);
        }
    }

    cout << fa << endl;

    return 0;
}

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

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

    string s, t, a;
    cin >> s >> t;

    for (int i = 0; i < n; i++)
    {
        a += s[i];
        a += t[i];
    }

    cout << a << endl;
}

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

int main(){
	int a,b,c,k; cin>>a>>b>>c>>k;
	int ans=0;
	rep(i,a){
		k--;
		ans++;
		if(k==0) {cout<<ans<<endl; return 0;}
	}
	rep(i,b){
		k--;
		if(k==0) {cout<<ans<<endl; return 0;}
	}
	rep(i,c){
		k--;
		ans--;
		if(k==0) {cout<<ans<<endl; return 0;}
	}
}

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

namespace ABC110C___String_Transformation
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string lineA = Console.ReadLine().Trim();
            string lineB = Console.ReadLine().Trim();

            Dictionary<char, int> dicA = new Dictionary<char, int>();
            Dictionary<char, int> dicB = new Dictionary<char, int>();

            //Aの出現頻度
            for (int i = 0; i < lineA.Length; i++)
            {
                if (dicA.ContainsKey(lineA[i]))
                    dicA[lineA[i]]++;
                else
                    dicA.Add(lineA[i], 1);
            }

            //Bの出現頻度
            for (int i = 0; i < lineB.Length; i++)
            {
                if (dicB.ContainsKey(lineB[i]))
                    dicB[lineB[i]]++;
                else
                    dicB.Add(lineB[i], 1);
            }

            //出現頻度でソート
            List<int> listA = dicA.OrderBy((x) => x.Value).Select((x) => x.Value).ToList();
            List<int> listB = dicB.OrderBy((x) => x.Value).Select((x) => x.Value).ToList();

            for  (int i = 0; i < listA.Count; i++)
            {
               if (listA[i] != listB[i])
                {
                    Console.WriteLine("{0}", "No");
                    return;
                }
             }

            Console.WriteLine("{0}", "Yes");
            return;

        }
    }

}


Measured memory_bytes: 15072
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
ll n, ww, dp[105][100005], v[100005], w[100005];
ll dynamic(ll wt, ll x){
	//if (dp[W] != -1)return dp[W];
	if (wt > ww || wt < 0)return 0;
	if (x > n)return 0;
	if (dp[x][wt] != -1)return dp[x][wt];
	if (wt- w[x] < 0){
		dp[x][wt] = dynamic(wt, x-1);
	}else dp[x][wt] = max((v[x]+dynamic(wt-w[x],x-1)), dynamic(wt, x-1));//take or not
	return dp[x][wt];
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> ww;
	for (ll i = 1; i <= n; i++){
		cin >> w[i] >> v[i];
	}
	memset(dp, -1, sizeof(dp));
	for (ll i = 0; i <= ww; i++)dp[0][i] = 0;
	for (ll i = 0; i <= n; i++)dp[i][0] = 0;
	
	cout << dynamic(ww, n);
}


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

int main() {
  long long H, W; cin >> H >> W;
  if(H == 1 || W == 1) cout << 1 << endl;
  else if(H*W % 2 == 0) cout << H*W/2 << endl;
  else cout << H*W/2+1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    int n= s.length();
    string t = "";
    for(int i=0;i<n;i++){
    	if(s[i] == '?'){
    		t += "D";
    	}else{
    		t += s[i];
    	}
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 3892
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int w,n,a,b;
	int num[30];
	cin>>w>>n;
	for(int i=0;i<w;i++)num[i]=i+1;
	while(n--){
		cin>>a;
		cin.ignore(1);//改行まで最大１文字読み飛ばし
		cin>>b;
		swap(num[a-1],num[b-1]);
	}
	for(int i=0;i<w;i++)
		cout<<num[i]<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = 2000000000;
// const ll MOD = 1000000007;

int A, B;

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

  int sum = 0;
  if (A > B) {
    sum += A;
    A--;
  } else {
    sum += B;
    B--;
  }
  if (A > B) {
    sum += A;
    A--;
  } else {
    sum += B;
    B--;
  }

  cout << sum << endl;
  return 0;
}

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

unordered_map <string, bool> mp;

char s[110][11];

int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		mp.clear();
		bool flag = true;
		for (int i = 1; i <= n; ++i)
		{
			scanf("%s", s[i]);
			if (mp.find(s[i]) == mp.end()) mp[s[i]] = true;
			else flag = false;
			if (i != 1 && s[i][0] != s[i - 1][strlen(s[i - 1]) - 1]) flag = false;
		}
		puts(flag ? "Yes" : "No");
	}
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N,K;
string S;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>K;
    cin>>S;
    
    vector<int> vec;
    int cnt=0;
    rep(i,N){
        if(i&&S[i]!=S[i-1]){
            if(S[i-1]=='0') cnt*=-1;
            vec.push_back(cnt);
            cnt=1;
        }else{
            cnt++;
        }
    }
    if(S[N-1]=='0') cnt*=-1;
    vec.push_back(cnt);
    int mx=0,now0=0,num=0,tail=0;
    rep(i,vec.size()){
        num+=abs(vec[i]);
        if(vec[i]<0) now0++;
        while(now0>K){
            num-=abs(vec[tail]);
            if(vec[tail++]<0) now0--;
        }
        chmax(mx,num);
    }
    cout1(mx)
}

Measured memory_bytes: 1020
import sys
import math
sys.setrecursionlimit(int(1e6))

x = int(input() )
if (x < 600):
    print('8')
elif (x < 800):
    print('7')
elif (x < 1000):
    print('6')
elif (x < 1200):
    print('5')
elif (x < 1400):
    print('4')
elif (x < 1600):
    print('3')
elif (x < 1800):
    print('2')
else:
    print('1')


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

int n, m;
int c[20], t[20][50000];

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

	for (int i = 0; i < m; i++)
		cin >> c[i];

	sort(c, c + m);

	for (int i = 0; i < n; i++)
		t[0][i] = i + 1;

	for (int i = 1; i < m; i++) {
		for (int j = 0; j < n; j++) {
			if (j == c[i] - 1)
				t[i][j] = 1;
			else if (j >= c[i])
				t[i][j] = min(t[i - 1][j], t[i][j - c[i]] + 1);
			else
				t[i][j] = t[i - 1][j];
		}
	}

	cout << t[m - 1][n - 1] << endl;

	return 0;
}


Measured memory_bytes: 6992
N, W = map(int, input().split())
wl = [0]*(N+1)
vl = [0]*(N+1)
for i in range(1, N+1):
    wl[i], vl[i] = map(int, input().split())

NIL = int(1e18)
MAX = int(1e5)

dp = [NIL]*(MAX+1)
dp[0]= 0

for i in range(1, N+1):
    w, v = wl[i], vl[i]
    for k in reversed(range(MAX+1)):
        if k + v <= MAX and dp[k] != NIL:
            dp[k+v] = min(dp[k+v], dp[k] + w)

ans = 0
for i in reversed(range(MAX+1)):
    if dp[i] <= W:
        ans = i
        break
print(ans)


Measured memory_bytes: 42076
unittest
{
	assert( [ "2", "1 2 1 2 2 1" ].solve == 2 );
	assert( [ "3", "1 1 2 2 3 3 3 2 1" ].solve == 1 );
	assert( [ "3", "1 1 2 2 2 3 3 3 1" ].solve == 3 );
}



import std.algorithm;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	as[] -= 1;
	
	// インラインDP
	// dp[ (iターン目) ][ 残したカード1枚目の数字 ][ 残したカード2枚目の数字 ] = 最大得点
	auto dp = new long[][]( n, n );
	foreach( ref dpp; dp ) dpp[] = long.min;					// -2000未満にしておけば絶対0以上にならないので無視できる
	auto z = 0L;												// 全体加算値
	auto mm = 0L;												// 全体最大値
	auto ms = new long[ n ];									// 部分最大値
	ms[] = long.min;
	auto queue = DList!( Tuple!( long, long, long ) )();		// 更新キュー
	
	// 最初のカード2枚を処理
	dp[ as[ 0 ] ][ as[ 1 ] ] = 0;
	dp[ as[ 1 ] ][ as[ 0 ] ] = 0;
	ms[ as[ 0 ] ] = 0;
	ms[ as[ 1 ] ] = 0;
	as.popFrontN( 2 );
	
	// 途中のカードを3枚ずつ処理
	foreach( i; 0L .. n - 1 )
	{
		if( as[ 0 ] == as[ 1 ] && as[ 1 ] == as[ 2 ] )
		{
			// 次の3枚が全て同値の場合
			// 全てのx,yについて dp[ i+1 ][ x ][ y ] = dp[ i ][ x ][ y ] +1 が最適になるので、全体加算値に+1する
			z++;
		}
		else
		{
			foreach( j; 0 .. 3 )
			{
				auto a = as[ j ];
				auto b = as[ 0 + ( j <= 0 ) ];
				auto c = as[ 1 + ( j <= 1 ) ];
				
				// 前ターンのx,yを両方を残す場合
				// dp[ i+1 ][ x ][ y ] = dp[ i ][ x ][ y ] になるので、処理不要
				
				// 前ターンのx,yの片方を残す場合
				// dp[ i+1 ][ x ][ a or b or c ] = dp[ i ][ x ][ ? ].reduce!max になるので、部分最大値を使って更新する
				// また、捨て札y,b,cが全て同値の場合は+1する
				foreach( x; 0L .. n )
				{
					auto v = ms[ x ];
					if( b == c ) v = max( v, dp[ x ][ b ] + 1 );
					queue.insertBack( tuple( x, a, v ) );
				}
				
				// 前ターンのx,yのどちらも残さない場合
				// dp[ i + 1 ][ a or b or c ][ a or b or c ] = dp[ i + 1 ][ ? ][ ? ].reduce!max になるので、全体最大値を使って更新する
				// また、捨て札x,y,aが全て同値の場合は+1する
				queue.insertBack( tuple( b, c, max( mm, dp[ a ][ a ] + 1 ) ) );
			}
		}
		
		// DPテーブルと最大値を更新
		while( !queue.empty )
		{
			auto x = queue.front[ 0 ];
			auto y = queue.front[ 1 ];
			auto v = queue.front[ 2 ];
			queue.removeFront;
			
			dp[ x ][ y ] = max( dp[ x ][ y ], v );
			dp[ y ][ x ] = max( dp[ y ][ x ], v );
			ms[ x ] = max( ms[ x ], v );
			ms[ y ] = max( ms[ y ], v );
			mm = max( mm, v );
		}
		as.popFrontN( 3 );
	}
	
	// 最後のカード1枚を処理
	return max( mm, dp[ as[ 0 ] ][ as[ 0 ] ] + 1 ) + z;
}


Measured memory_bytes: 36180
#!/usr/bin/env python3
import sys
import numpy as np


def solve(S: str):
    w = {'SUN':7, 'MON':6, 'TUE':5, 'WED':4, 'THU':3, 'FRI':2, 'SAT':1}
    print(w[S])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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



int main() {
		int i, j;
		int n, k;
		cin >> n >> k;
		vector<bool> d(10, false);
		for(i=0;i<k;i++) {
			int t;
			cin >> t;
			d[t] = true;
		}
		while (1) {
			string s = to_string(n);
			int size = s.size();
			for(i=0; i<size;i++)
				if (d[s[i] - '0'])break;
			if (i == size)break;
			n++;
		}
		cout << n << endl;
	}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    auto Q = readln.chomp.to!int;
    auto K = readln.split.map!(to!int).array;

    foreach (k; K) {
        long d = 0;
        long m = 0;
        long dm = 0;
        long ans = 0;

        foreach (i; 0..k) {
            if (S[i] == 'D') {
                d += 1;
            } else if (S[i] == 'M') {
                m += 1;
                dm += d;
            } else if (S[i] == 'C') {
                ans += dm;
            }
        }

        foreach (i; k..N) {
            if (S[i-k] == 'D') {
                d -= 1;
                dm -= m;
            } else if (S[i-k] == 'M') {
                m -= 1;
            }

            if (S[i] == 'D') {
                d += 1;
            } else if (S[i] == 'M') {
                m += 1;
                dm += d;
            } else if (S[i] == 'C') {
                ans += dm;
            }
        }

        ans.writeln;
    }
}


Measured memory_bytes: 4348
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define MOD 1000000007
#define int long long
int func1(int X){
  int i=1;
  while(i<X)
    i*=2;
  return i;
}
signed main(){
 int N,K;
  cin>>N>>K;
  double ans=0;
  rep(i,1,N+1) ans+=1.0/N/func1((i+K-1)/i);
  printf("%.10f\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
long binary(long s){
	long a=0,b=1e9;
	long temp;
	while(b-a>1){
		temp=(a+b)/2;
		if(s<=temp*temp) b=temp;
		else a=temp;
	}return b;
}
int main(){
	long S;cin>>S;
	long a,b;
	b=binary(S);long c=b*b-S;
	if(c>1e9){ a=b-1;c-=b; }
	else a=b;
	cout<<0<<" "<<0<<" "<<a<<" "<<1<<" "<<c<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
 
int dp[100010];
int n;
int conti;
bool pasa;
int main(){
     cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        conti ++;
        cin >> h[i];
        if(conti > 0){
        conti--;
        pasa = true;
       //printf("prueba")
}
    }
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i=2; i<n; i++){
        dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007


int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  int ans = 0;
  bool f = true;

  while(f){

    rep(i,N){

      if(A[i] % 2 == 0){ 
        A[i] /= 2;
      }
      else{
        f = false;
        break;
      }
    }

    if(f) ans++;
  }

cout << ans << endl;
 
}


Measured memory_bytes: 256
N,K = map(int,input().split())
dice = list(range(1,N+1))
count = []
for i in dice:
    tmp = i
    t = 0
    while tmp < K:
        tmp *= 2
        t += 1
    count.append(t)
ans = []
for i in range(len(count)):
    ans.append(1/N*(1/2)**count[i])
print(sum(ans))

Measured memory_bytes: 11032
#include<stdio.h> 

int main(){
  int j,i,N,key;
  int A[100];

  scanf("%d",&N); /*the number of elements*/
  for(j=0; j<N; j++){
    /* insert A[j] into the sorted sequence A[1,...,j-1] */
    scanf("%d",&A[j]);
  }

  /*The output first line*/
  for(j=0; j<N; j++){
    printf("%d",A[j]);
    if(j < N-1){
      printf(" ");
    }
  }
  printf("\n");

  for(j=1; j<N; j++){
    key=A[j];
    i=j-1;
    while((i >= 0) && (A[i] >key)){
      A[i+1]=A[i];
      i=i-1;
    }  
    A[i+1]=key;
    
    for(i=0; i<N; i++){
      printf("%d",A[i]);
      if(i < N-1){
	printf(" ");
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int near[maxn],fa[maxn],siz[maxn];
int getfa(int n){
    return fa[n]==n?n:fa[n]=getfa(fa[n]);
}
int main(){
    int n,m,k,a,b;cin>>n>>m>>k;
    for(int i=1;i<=n;i++){siz[i]=1;fa[i]=i;}
    for(int i=1;i<=m;i++){
        cin>>a>>b;near[a]++;near[b]++;
        if(getfa(a)==getfa(b)) continue;
        siz[fa[a]]+=siz[fa[b]];fa[fa[b]]=fa[a];
    }
    for(int i=1;i<=k;i++) {
        cin>>a>>b;
        if(getfa(a)==getfa(b)) near[a]++,near[b]++;
    }
    for(int i=1;i<=n;i++)
        cout<<siz[getfa(i)]-near[i]-1<<' ';
    return 0;
}

Measured memory_bytes: 2560
/*
  AOJ 0572
  Title:
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

int A,B;
int acard[5000],bcard[5000];


dump(int * a,int * b)
{
        int i;
        for(i=0;i<5;i++)
                printf("%d|",a[i]);
        printf("\n");
        for(i=0;i<5;i++)
                printf("%d|",b[i]);
        printf("\n");

}
int saichou_itti(int * a,int * b)
{
        int *p;

        //dump(a,b);

        if(*b==0)
                return(0);
        
        for(p=a;*p;p++)
                if(*p==*b)
                        return(1+saichou_itti(p+1,b+1));
       
        return(0);
}
int solve()
{
        int max_,cnt,i;

        max_=0;
        for(i=0;i<B;i++)
        {
                cnt=saichou_itti(&acard[0],&bcard[i]);
                if(cnt>max_)
                        max_=cnt;
        }
        return(max_);
}

main()
{
        int i,ret;


        scanf("%d %d",&A,&B);
        for(i=0;i<A;i++)
                scanf("%d",&acard[i]);
        for(i=0;i<B;i++)
                scanf("%d",&bcard[i]);
        ret=solve();

        //ret=saichou_itti(acard,bcard);

        printf("%d\n",ret);

  return(0);
}

Measured memory_bytes: 632
n,q = gets.split(" ").map(&:to_i)
s = gets.chomp.split("")
aci =[0]*(n+1)
for i in 1..n-1 do
    if s[i-1] == "A" && s[i] == "C"
        aci[i+1] = aci[i] + 1
    elsif
        aci[i+1] = aci[i]
    end
end
q.times do
    l,r = gets.split(" ").map(&:to_i)
    puts aci[r] - aci[l]
end


Measured memory_bytes: 10876
function Main(input) {
     
    	input = input.split("\n");
    	tmp = input[0].split(" ");
     
    	var rd = tmp[0];
    	var gr = tmp[1];
    	var bl = tmp[2];
    	var k = input[1];
      
      	var result = false;
     
    	for (var i = 0; i < k; i++){ 
          	if (gr < rd || gr == rd) {
            	gr = gr * 2;
            } else if (bl < gr || bl == gr) {
            	bl = bl * 2;
            } 
        }
        if (gr > rd && bl > gr){
            result = true;
        }
      
      	if (result) console.log('Yes');
      	else console.log('No');
    }
    Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29612
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

typedef int cost_type;
struct edge {
	int to;
	cost_type cost;
	edge(){}
	edge(int to,cost_type cost) : to(to) ,cost(cost) {}
};

typedef pair<cost_type,int> P;

void dijkstra(int s,vector<P::first_type>& cost_table,vector<vector<edge> >& edges,vector<int>* _prev = NULL){
	
	//init
	cost_table.resize((int)edges.size());
	fill(cost_table.begin(),cost_table.end(),P::first_type(INF));
	if(_prev) _prev->resize((int)edges.size());
	if(_prev) fill(_prev->begin(),_prev->end(),-1);
	
	priority_queue<P,vector<P>,greater<P> > q;
	q.push(P(0,s));
	cost_table[s] = 0;

	while(!q.empty()){
		P p = q.top(); q.pop();
		int v = p.second;
		if(cost_table[v] < p.first) continue;
		for(int i = 0; i < (int)edges[v].size(); i++){
			edge& e = edges[v][i];
			if(cost_table[e.to] > cost_table[v] + e.cost){
				cost_table[e.to] = cost_table[v] + e.cost;
				if(_prev) (*_prev)[e.to] = v;
				q.push(P(cost_table[e.to],e.to));
			}
		}
	}
}

int main(){
	int n,m;
	while(cin>>n>>m,(n||m)){
		vector<string> v(m);
		FOR(i,m) cin>>v[i];
		vector<vector<edge> >e(n*m);
		int start;
		FOR(i,m) FOR(j,n){
			if(v[i][j] == '&'){
				start = i * n + j;
			}
			static int dx[] = {0,0,1,-1};
			static int dy[] = {1,-1,0,0};
			FOR(k,4){
				int nh = dx[k] + i;
				int nw = dy[k] + j;
				if(nh < 0 || nh >= m || nw <0 || nw >= n) continue;
				int nx = nh * n + nw;
				int ct = v[i][j] != '#' && v[nh][nw] == '#';
				e[i * n + j].push_back(edge(nx,ct));
			}
		}

		vector<int> cost;
		dijkstra(start,cost,e);

		int ans = INF;
		FOR(i,m) FOR(j,n){
			if(i == 0 || i == m-1 || j == 0 || j == n-1){
				ans = min(ans,cost[i*n+j]);
			}
		}

		cout << ans << endl;

	}

	return 0;
}

Measured memory_bytes: 2064
main :: IO ()
main = do
  ss <- getLine
  putStrLn $ solve ss

solve :: String -> String
solve str = go (dropWhile (/= 'C') str)
  where
    go :: String -> String
    go [] = "No"
    go (s:ss)
      | s == 'F' = "Yes"
      | otherwise = go ss


Measured memory_bytes: 380
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){
    string s,re;
    cin >> s;
    re = s;
    reverse(re.begin(),re.end());
    rep(i,s.size()){
        if(s[i]!=re[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    int n = s.size()-1;
    for(int i=0; i<n/2; i++){
        if(s[i]!=s[n/2-i-1]){
        cout <<"No" << endl;
        return 0;
        }
    }
    for(int i=n/2+1; i<=n; i++){
        if(s[i]!=s[n-i]){
        cout << "No" << endl;
        return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}




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

bool isPrime(int x) {
  if (x == 2) return true;
  if (x < 2 || x % 2 == 0) return false;

  int i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0) return false;
    i += 2;
  }
  return true;
}

int main() {
  int q;
  cin >> q;
  vector<bool> v(100010, false);
  vector<int> d(100010, false);
  for (int i = 1; i < 100010; i++) {
    if (isPrime(i)) v.at(i) = true;
  }

  int cnt = 0;
  for (int i = 0; i < 100010; i++) {
    if (v.at(i)) {
      if (v.at((i + 1) / 2)) cnt++;
    }
    d.at(i) = cnt;
  }

  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << d.at(r) - d.at(l - 1) << endl;
  }
}

Measured memory_bytes: 1024
from collections import deque
n, q = map(int, input().split())
queue = deque([input().split() for _ in range(n)])
t = 0
while len(queue):
    p = queue.popleft()
    if int(p[1]) <= q:
        t += int(p[1])
        print(p[0], t)
    else:
        p[1] = int(p[1]) - q
        t += q
        queue.append(p)

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int main() {
  int a,b;
  cin >> a >> b;
  ANS(a * b);
  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	double a,b;
	while(cin>>a>>b,a||b){
		double t=sqrt(a*a/4+b*b);
		printf("%.9f\n",2*a*t+a*a);
	}
}

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

int main() {
    string N;
    cin >> N;
    char s = N.at(N.size()-1);
    if (s=='3') cout << "bon";
    else if (s=='0' || s=='1' || s=='6' || s=='8')cout << "pon";
    else cout << "hon";
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
#include <iostream>
#include <limits>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define ld long double
ld a, b, c, d, e, f, x, y;
ld shish(ld a)
{
	if (a == 0) { return a; }
	
	a *= 1000;
	if (a > 0) {
		a += 0.51;
	}
	else {
		a -= 0.51;
	}
	a = (ld)((int)a);
	a /= 1000;
	return a;
}
int main() {
	while (cin >> a >> b >> c >> d >> e >> f) {
		y = (a*f - c*d) / (ld)(a*e - b*d);
		x = (c*e - f*b) / (ld)(a*e - b*d);

		x = shish(x);
		y = shish(y);
		if (x == 0) { cout << "0.000"; }
		else {
			cout << fixed << setprecision(3) << x;
		}
		cout << " ";
		if (y == 0) { cout << "0.000" << endl; }
		else{
			cout << fixed << setprecision(3) << y << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3168
S = input()
flag = True
N = len(S)

for i in range(N//2):
    if S[i]!=S[N-1-i]:
        flag = False

N2 = (N-1)//2
for i in range(N2//2):
    if S[i]!=S[N2-1-i]:
        flag = False

N3 = (N+3)//2
for i in range(N-N3+1):
    if S[N3-1+i]!=S[N-1-i]:
        flag = False

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import java.util.*;

public class Main {

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

        int[] s = new int[n];
        int total = 0;
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
            total += s[i];
        }

        int min = Integer.MAX_VALUE;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += s[i];
            if (min > Math.abs(sum - (total - sum))) {
                min = Math.abs(sum - (total - sum));
            }
        }

        System.out.print(min);
    }

}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>

int main(){
    int a, b, c, d, p, X, Y;
    std::cin >> a >> b >> c >> d >> p;
    X = p * a;
    
    if(p > c)
        Y = b + d * (p - c);
    else
        Y = b;

    std::cout << std::min(X, Y) << std::endl;

    return 0;
}

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

int calc(int x) {
	int result = 0;
	while (x % 100 == 0) {
		x /= 100;
		result += 1;
	}
	return result;
}

int main() {
	int D, N;
	cin >> D >> N;

	int cnt = 0, val = 0;

	while (cnt < N) {
		val += 1;
		if (calc(val) == D) {
			cnt += 1;
		}
	}
	cout << val << "\n";
}


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

typedef long long ll;

int main() {
#ifdef TooLazy
    freopen("in.txt", "r", stdin);
#endif /// TooLazy

    string s;
    map<char, int> mp;
    cin >> s;
    int n = s.size();
    for(int i=0; i<n; i++) {
        char c = s[i];
        mp[c]++;
    }

    if( mp.size() == 26 ) {
        puts("None");
        exit(0);
    }

    char ch;

    for(char c = 'a'; c <= 'z'; c++) {
        if( mp[c] == 0 ) {
            ch = c;
            break;
        }
    }

    cout << ch << "\n";

    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N;
	cin >> N;
	vector<int> L;
	rep(i, 0, N) {
		int l;
		cin >> l;
		L.push_back(l);
	}

	vsort(L);
	int l_max = L[L.size() - 1];
	int sum_l = 0;
	rep(i, 0, N - 1) {
		sum_l += L[i];
	}

	if(sum_l > l_max) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node
{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int);
void init(void);
void printList(void);
void deleteNode(NodePointer);
void deleteFirst(void);
void deleteLast(void);
void delete(int);
void insert(int);

main()
{
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for(i = 0; i < n; i++)
    {
      scanf("%s %d", com, &key);
      if(com[0] == 'i')
	{
	  insert(key);
	  np++;
	  size++;
	}
      else if(com[0] == 'd')
	{
	  if(strlen(com) > 6)
	    {
	      if(com[6] == 'F') deleteFirst();
	      else if(com[6] == 'L') deleteLast();
	    }
	  else
	    {
	      delete(key);
	      nd++;
	    }
	  size--;
	}
    }

  printList();
  return 0;
}


NodePointer listSearch(int key)
{
  NodePointer x;
  x = nil -> next;
  while(x != nil && x -> key != key)
    {
      x = x -> next;
    }
  return x;
}

void init()
{
  nil = malloc(sizeof(struct node));
  nil -> next = nil;
  nil -> prev = nil;
}

void printList()
{
  NodePointer cur = nil -> next;
  int isf = 1;
  while(1)
    {
      if(cur == nil) break;
      if(isf == 0) printf(" ");
      printf("%d", cur -> key);
      cur = cur -> next;
      isf = 0;
    }
  printf("\n");
}

void deleteNode(NodePointer t)
{
  t -> prev -> next = t -> next;
  t -> next -> prev = t -> prev;
  free(t);
}

void deleteFirst()
{
  NodePointer t = nil -> next;
  if(t == nil) return;
  deleteNode(t);
}

void deleteLast()
{
  NodePointer t = nil -> prev;
  if(t == nil) return;
  deleteNode(t);
}

void delete(int key)
{
  NodePointer t;
  t = listSearch(key);
  if(t == nil) return;
  deleteNode(t);
}

void insert(int key)
{
  NodePointer x;
  x = malloc(sizeof(struct node));
  x -> key = key;

  x -> next = nil -> next;
  nil -> next -> prev = x;
  nil -> next = x;
  x -> prev = nil;
}

Measured memory_bytes: 31788
#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>;
using v  = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

ll cost(ll h){
    if(h==1)return 1;
    return 2*cost(h/2)+1;
}


int main(){
    ll h;
    cin >>h;
    
    cout << cost(h) << endl;
    
    return 0;
}

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


int main() {
  int a, b, c, d, e;
  int m, n;
  int i, j, k;

    std::cin >> k;

    c=0;
    for(int i=1; i<=k; i+=2){
        for(int j=2; j<=k; j+=2){
            c++;
        }
    }
    printf("%d\n", c);


  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>

#define MOD 998244353

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))

typedef long long int64;

int main(void){
    int64 H,W;
    scanf("%lld %lld",&H,&W);
    char A[H][W];

    for(int64 i=0;i<H;i++){
        scanf("%s",&A[i]);
    }
    int64 dp[H][W];
    for(int64 i=0;i<H;i++){
        for(int64 j=0;j<W;j++){
            dp[i][j]=2000;
        }
    }

    int tmp=2000;

    for(int64 i=0;i<H;i++){
        tmp=2000;
        for(int64 j=0;j<W;j++){
            if(A[i][j]=='#'){
                dp[i][j]=0;
                tmp=1;
            }else{
                dp[i][j]=MIN(dp[i][j],tmp);
                tmp++;
            }
        }
    }
    for(int64 j=0;j<W;j++){
        for(int64 i=0;i<H;i++){
            if(i==0) continue;
            dp[i][j]=MIN(dp[i][j],dp[i-1][j]+1);
        }
    }
    for(int64 i=H-1;i>=0;i--){
        for(int64 j=W-1;j>=0;j--){
            if(j==W-1) continue;
            dp[i][j]=MIN(dp[i][j],dp[i][j+1]+1);
        }
    }
    
    for(int64 j=W-1;j>=0;j--){
        for(int64 i=H-1;i>=0;i--){
            if(i==H-1) continue;
            dp[i][j]=MIN(dp[i][j],dp[i+1][j]+1);
        }
    }

    int64 ans=0;

    for(int64 i=0;i<H;i++){
        for(int64 j=0;j<W;j++){
            ans=MAX(ans,dp[i][j]);
        }
    }

    // for(int i=0;i<H;i++){
    //     for(int j=0;j<W;j++){
    //         printf("\t%d",dp[i][j]);
    //     }
    //     printf("\n");
        
    // }

    printf("%lld",ans);
    
    
    return 0;
}


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

public class C
{
    public const long INF = 999999999999999999;
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, long.Parse);
        var asum = a.Sum();
        var snk = 0L;
        var abstmin = C.INF;
        for (int i = 0; i < n-1; i++)
        {
            snk += a[i];
            var abst = Math.Abs(asum - 2 * snk);
            abstmin = Math.Min(abstmin, abst);
        }
        Console.WriteLine(abstmin);
    }
}

Measured memory_bytes: 34140
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const INF: i64 = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let a: i64 = sc.get();
    let b: i64 = sc.get();
    let c: i64 = sc.get();
    let d: i64 = sc.get();
    let mut ans = -INF;
    ans = max(ans, b * d);
    ans = max(ans, a * c);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    println!("{}", ans);
}


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

int main() {
    int n;cin>>n;
    int mn=1e9;
    int zero=0;
    int minus=0;
    ll sum=0;
    for (int i=0;i<n;i++) {
        int a;cin>>a;
        sum+=abs(a);
        mn=min(mn,abs(a));
        if (a==0)
            zero=1;
        else if (a<0) {
            minus++;
        }
    }
    if (zero||minus%2==0)
        cout<<sum<<endl;
    else
        cout<<sum-2*mn<<endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
max_op = 0
1.upto(31).each do |x|
  d = 2 ** x
  result = 0.upto(n-1).each do |i|
    break false if (a[i] % d) != 0
    true
  end
  max_op = x if result
end
puts max_op


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

int a[100005] = {};

int main(void)
{
	int max;
	cin >> max;
	a[0]++;
	for(int i=0;i<max;++i){
		int c,b;
		cin >> c >> b;
		a[c]++;a[b+1]--;
	}
	int sum=0;
	int maxn=1;
	for(int i=0;i<=100005;++i){
		sum+=a[i];
		if(i <= sum)
		{
			maxn = i;
		}
	}
	cout << maxn-1 << endl;
	return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


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

    ll ans = 0;
    ll comb = (k * (k - 1) / 2) % MOD;
    for(int i = 0; i < n; i++){
        ll be = 0, af = 0;
        for(int j = 0; j < i; j++){
            if(a[j] < a[i]) be++;
        }
        for(int j = i + 1; j < n; j++){
            if(a[j] < a[i]) af++;
        }
        ans = (ans + (k * af) + (comb * (be + af))) % MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>


int main(void){


	long long int n;
	long long int a[100001];
	long long int i,j;
	long long int b;

	long long int ret;

	long long int c[3]={};

	long long int mod;

	mod = 1000000007;

	scanf("%lld",&n);

	//R,G,Bいずれかの色

	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}

	c[0] = 0;
	ret = 1;

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

		b = 0;

		for(j=0;j<3;j++){
			if(c[j] == a[i]){
				if(b == 0){ c[j]++;	}
				b++;
			}
		}

		ret = ( ret * b ) % mod;
//		printf("n:%d %d(b=%d)\n",i,ret,b);

	}

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


	return 0;
}



Measured memory_bytes: 896
n = int(input())
res = []
 
for i in range(n):
    x, y = input().split()
    y = int(y)
    res.append((x, y, i))
 
res.sort(key=lambda x: (x[0], -x[1]))
 
for x, y, i in res:
    print(i+1)

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

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        int N, K, R, S, P;
        {int[] a = in.ii(); N = a[0]; K = a[1];
            a = in.ii(); R = a[0]; S = a[1]; P = a[2];}
        char[] T = in.s().toCharArray();
        int ans = 0;
        for(int i = 0; i < K; i++){
            for(int j = 0; i+K*j < N; ){
                while(i+K*(j+1) < N && T[i+K*j] != T[i+K*(j+1)]){
                    char c0 = T[i+K*j];
                    ans += c0 == 's' ? R : c0 == 'p' ? S : P;
                    j++;
                    //out.print(c0);
                }
                if(i+K*(j+1) >= N){
                    char c0 = T[i+K*j];
                    ans += c0 == 's' ? R : c0 == 'p' ? S : P;
                    //out.print(c0);
                    break;
                }
                //out.print(" ");
                char c0 = T[i+K*j];
                int count = 0;
                while(i+K*j < N && c0 == T[i+K*j]){
                    count++;
                    j++;
                    //out.print(c0);
                }
                int point = c0 == 's' ? R : c0 == 'p' ? S : P;
                ans += (count+1)/2*point;
            }
            //out.println();
        }
        out.println(ans);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 25044