akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#define INF 2000000000
using namespace std;
int c=0;
vector<int> merge(vector<int> A, vector<int> B){
  vector<int> res;
  int i=0,j=0;
  while(i<(int)A.size()||j<(int)B.size()){
    if(i<(int)A.size()&&j<(int)B.size()){
      if(A[i]<=B[j])res.push_back(A[i++]);
      else res.push_back(B[j++]);
    }
    else if(i<(int)A.size())res.push_back(A[i++]);
    else if(j<(int)B.size())res.push_back(B[j++]);
    c++;
  }
  return res;
}

vector<int> mergesort(vector<int> A){
  if(A.size()<2)return A;
  int mid=(A.size())/2;
  vector<int> left;
  vector<int> right;
  for(int i=0;i<(int)A.size();i++){
    if(i<mid)left.push_back(A[i]);
    else right.push_back(A[i]);
  }
  left=mergesort(left);
  right=mergesort(right);
  return merge(left,right);
}
 
 
int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  v=mergesort(v);
  for(int i=0;i<(int)v.size()-1;i++){
    cout<<v[i]<<" ";
  }
  cout<<v[n-1]<<endl<<c<<endl;
  return 0;
}



Measured memory_bytes: 15628
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<tuple>
#define LL long long
#define PP std::pair<LL,LL>
#define TT std::tuple<LL,LL,LL>
std::vector<PP> G[310];
std::vector<TT> A;
LL D[310];
LL ans;
int N;
int main(){
    std::cin>>N;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            LL tmp;
            std::cin>>tmp;
            if(i<=j)A.emplace_back(TT{tmp,i,j});
        }
    }
    std::sort(A.begin(),A.end());
    for(auto u:A){
        LL cost,s,t;
        LL D[300];
        for(int i=1;i<=N;i++)D[i]=1e15;
        std::tie(cost,s,t)=u;
        std::priority_queue<PP,std::vector<PP>,std::greater<PP>> pq;
        pq.push(PP{0,s});
        D[s]=0;
        while(!pq.empty()){
            PP p=pq.top();
            pq.pop();
            if(D[p.second]<p.first)continue;
            for(auto m:G[p.second]){
                if(D[m.first]>p.first+m.second){
                    D[m.first]=p.first+m.second;
                    pq.push(PP{D[m.first],m.first});
                }
            }
        }
        if(D[t]<cost){
            std::cout<<-1<<std::endl;
            return 0;
        }
        if(D[t]>cost){
            ans+=cost;
            G[s].emplace_back(PP{t,cost});
            G[t].emplace_back(PP{s,cost});
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}



Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const ll inf = 1e17 + 7, MOD = 1e7 + 9;


int main() {
	fastio();
	ll x;
	cin >> x;
	ll p = 100;
	int n=0;
	while(p < x) {
		n++;
		p = 1.01 * p;
	}
	/* long double a = x / (long double)(100); */
	/* deb(a); */
	/* ll n = ceil(log(a) / log(1.01)); */
	cout << n << "\n";
	return 0;
}



Measured memory_bytes: 3604
#include <cstdio>
inline int read(){
  int ans=0,c=getchar_unlocked();
  while(c<'0'||c>'9'){c=getchar_unlocked();}
  while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar_unlocked();}
  return ans;
}

int main(){
  int n,i;
  n=read();
  int a,count4=0,odd=0;
  for(i=0;i<n;++i){
    a=read();
    if(a%2){
      odd++;
    }else if(a%4==0){
      count4++;
    }
  }

  if(odd==0||odd+((n-count4-odd)?1:0)<=count4+1){
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
  return 0;
}

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

int main(){
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
//	(string)toupper(s1);
	cout << (char)toupper(s1[0]) << (char)toupper(s2[0]) << (char)toupper(s3[0]) << endl; 
}

Measured memory_bytes: 760
M, D = map(int, input().split())

ans = 0
for i in range(1, M + 1):
    for j in range(1, D + 1):
        if i == (j % 10) * (j // 10) and (j % 10) >= 2 and (j //10) >= 2:
            # print (i, j)
            ans += 1

print (ans)

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

int main() {
    int n; cin >> n;
    Int ans = (Int)n * (n-1);
    
    cout << ans/2 << endl;
}

Measured memory_bytes: 256
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
    var c = parseInt(tmp[2], 10);
     total= a*b/2;
    console.log(total);
	
	
	
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    ll h[n];
    rep(i, n){
        cin >> h[i];
    }

    reps(i, 1, n){
        if(h[i-1] < h[i]){
            h[i]--;
        }
    }

    bool is_valid = true;
    reps(i, 1, n){
        if(h[i-1] > h[i]){
            is_valid = false;
            break;
        }
    }

    is_valid ?
        cout << "Yes" :
        cout << "No";

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    //今から文字入力
    int a;
    int b;
    cin>>a>>b;
    if(a>b)
    {
        cout<<"a > b"<<endl;
    }
    else if(a==b)
    {
        cout<<"a == b"<<endl;
    }
    else
    {
        cout<<"a < b"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3116
# ARC 082 B

def resolve():
  s = input()
  t = input()
  # s: 昇順
  # t: 降順
  ss = sorted(list(s))
  tt = sorted(list(t))
  tt.reverse()

  ss = ''.join(ss)
  tt = ''.join(tt)

  if ss < tt:
    print('Yes')
  else:
    print('No')


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3060
import java.util.*;

public class Main {
	static char plus = '+';
	static char minus = '-';
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		int[] n = new int[4];
		for (int i = 0; i < 4; i++) {
			n[i] = s.charAt(i) - '0';
		}
		
		char[] op = {plus, plus, plus};
		
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				for (int k = 0; k < 2; k++) {
					if (calc(n, op) == 7) {
						System.out.println("" + n[0] + op[0] + n[1] + op[1] + n[2] + op[2] + n[3] + "=7");
						return;
					}
					op[2] = (op[2] == plus ? minus : plus);
				}
				op[1] = (op[1] == plus ? minus : plus);
			}
			op[0] = (op[0] == plus ? minus : plus);
		}
	}
	
	public static int calc(int[] n, char[] op) {
		int ans = n[0];
		for (int i = 0; i < op.length; i++) {
			if (op[i] == plus) {
				ans += n[i + 1];
			} else {
				ans -= n[i + 1];
			}
		}
		
		return ans;
	}
}

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

void fnInput(int &a_riElementCnt, vector<int> &a_rviElement, 
             int &a_riTargetCnt , vector<int> &a_rviTarget )
{
  cin >> a_riElementCnt;

  a_rviElement.resize(a_riElementCnt);
  for (int i = 0; i < a_riElementCnt; i++)
    cin >> a_rviElement[i];

  cin >> a_riTargetCnt;

  a_rviTarget.resize(a_riTargetCnt);
  for (int i = 0; i < a_riTargetCnt; i++)
    cin >> a_rviTarget[i];
}

int fnRcsSearch(int a_iPos, const vector<int> &a_cnrviElement, int a_iTarget,
                vector<vector<int>> &a_rvviOK)
{
  if (!a_iTarget)    return 1;
  if (a_iTarget < 0) return 0;
  if (a_rvviOK[a_iPos][a_iTarget] != -1)
    return a_rvviOK[a_iPos][a_iTarget];

  if (++a_iPos == a_cnrviElement.size())  return 0;

  int iRtn;
  int iSmallTarget;

  iRtn = fnRcsSearch(a_iPos, a_cnrviElement, a_iTarget, a_rvviOK);
  a_rvviOK[a_iPos][a_iTarget] = iRtn;
  if (iRtn)  return iRtn;

  iSmallTarget = a_iTarget - a_cnrviElement[a_iPos];
  iRtn = fnRcsSearch(a_iPos, a_cnrviElement, iSmallTarget, a_rvviOK);
  if (iSmallTarget >= 0)
    a_rvviOK[a_iPos][iSmallTarget] = iRtn;
  return iRtn;
}

void fnExhSearch(const vector<int> &a_cnrviElement, const vector<int> &a_cnrviTarget)
{
  vector<vector<int>> vviOK(21, vector<int>(2001, -1));
  
  for (int i = 0; i < a_cnrviTarget.size(); i++)
  {
    int iTarget = a_cnrviTarget[i];
    int iRtn;

    if (iRtn = fnRcsSearch(0, a_cnrviElement, iTarget, vviOK))
    {
      cout << "yes" << endl;
      vviOK[0][iTarget] = iRtn;
      continue;
    }

    int iSmallTarget = iTarget - a_cnrviElement[0];
    if (iRtn = fnRcsSearch(0, a_cnrviElement, iSmallTarget, vviOK))
      cout << "yes" << endl;
    else
      cout << "no" << endl;

    if (iSmallTarget >= 0)
      vviOK[0][iSmallTarget] = iRtn;
  }
}

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

  int iElementCnt, iTargetCnt;
  vector<int> viElement, viTarget;

  fnInput(iElementCnt, viElement, iTargetCnt, viTarget);
  fnExhSearch(viElement, viTarget);

  return 0;
}

Measured memory_bytes: 1340
import sys
from collections import deque

def main():
    N, M = map(int, input().split())
    a = deque([int(sys.stdin.readline().strip()) for _ in range(M)])

    atmp = -1
    if len(a) != 0:
        atmp = a.popleft()

    dp=[0] * (N+1)
    for i in range(0, N+1):
        if i == atmp:
            if len(a) != 0:
                atmp = a.popleft()
            continue

        if i == 0 or i == 1:
            dp[i] = 1
            continue

        if dp[i-1] == 0 and dp[i-2] == 0:
            break


        dp[i] = dp[i-1] + dp[i-2]

    print(dp[N] % 1000000007)

if __name__ == '__main__':
    main()

Measured memory_bytes: 471416
n = input()
s = len(n)-1

def calc(n,op):
  tmp = int(n[0])
  for i in range(len(op)):
    if op[i] == '+':
      tmp += int(n[i+1])
    else:
      tmp -= int(n[i+1])
  return tmp
for j in range(2**s):
  op = ''
  for k in range(s):
    if (j>>k)&1:
      op += '+'
    else:
      op += '-'
  if calc(n,op) == 7:
    ret = ''
    for l in range(len(op)):
      ret += n[l]
      ret += op[l]
    ret += n[-1]
    ret +='=7'
    print(ret)
    exit(0)

Measured memory_bytes: 9144
"use strict";

function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0], 10);
  var K = parseInt(input[0].split(" ")[1], 10);
  var max = (N - 1) * (N - 2) / 2;

  if (max < K) {
    console.log(-1);
    return;
  }

  var ans = [];

  for (var i = 0; i < N - 1; i++) {
    ans.push([i + 1, N]);
  }

  var edges = [];

  for (var _i = 0; _i < N - 1; _i++) {
    for (var j = 0; j < _i; j++) {
      edges.push([_i + 1, j + 1]);
    }
  }

  var add = max - K;

  for (var _i2 = 0; _i2 < add; _i2++) {
    ans.push(edges[_i2]);
  }

  console.log(ans.length);

  for (var _i3 = 0; _i3 < ans.length; _i3++) {
    var e = ans[_i3];
    console.log(e[0], e[1]);
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11980
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int A,B;
  char op;
  cin>>A>>op>>B;
  if(op == '+' ){
  cout<< A+B <<endl;
  }
  else if(op == '-' ){
  cout<< A-B <<endl;
  }
    }

   
  
   



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <algorithm>
int main(){
   long long N;
   long long p;
   std::cin >> N;
   std::string result;
   while (N){
       N -= 1;
       p = N%26;
       result += 'a' + p;
       N = N/26;
   }
  std::reverse(result.begin(),result.end());
  std::cout << result;
}


Measured memory_bytes: 3600
#include <utility> // pair make_pair
using std::swap; // c++11
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11

int main(void) {
    int a;
    int b;
    cin >> a >> b;
    cout << (a + b + 1) / 2 << endl;
    return 0;
}


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

#define pb push_back
#define mk make_pair
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())
#define ll long long
#define fi first
#define se second
#define FOR(i,a,b) for(ll int i = a;i<b;i++)
#define FORR(i,a,b) for(ll int i = a;i>=b;i--)

using namespace std;

typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef pair<int, int> pii;


bool compare(int a, int b){
    return(a>b);
}

int main(){
    #ifdef LOCAL_DEFINE
        freopen("input.txt","rt", stdin);
    #endif
        string f,a;
        cin>>f;
        cin.clear();
        cin>>a;
        ll cnt=0;
        for(int i=0; i<f.size(); i++){
            if(f[i]==a[i]) cnt++; 
        }
        cout<<cnt;
    #ifdef LOCAL_DEFINE
        cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s";
    #endif

    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int k, a, b;
    cin >> k >> a >> b;

    rep(i, 2000) {
        if (k*i >= a && k*i <= b) {
            puts("OK");
            return 0;
        }
    }
    puts("NG");
    return 0;
}

Measured memory_bytes: 3636
#!python3.4
# -*- coding: utf-8 -*-
# abc156/abc156_a
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, R = i2nn()
    if N < 10:
        print(R + 100 * (10 - N))
    else:
        print(R)
    return

main()


Measured memory_bytes: 3064
S = input()

for i in range(1 << len(S)-1):
    f = ''
    for j in range(len(S)-1):
        f += S[j]
        if (i >> j) & 1:
            f += '+'
        else:
            f += '-'
    f += S[-1]
    if eval(f) == 7:
        ans = f + '=7'
        print(ans)
        break


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

char a[55][55];
char b[55][55];
int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	rep(i,0,n)scanf("%s",a[i]);
	rep(i,0,m)scanf("%s",b[i]);
	rep(i,0,n-m+1)rep(j,0,n-m+1){
		ll flag=1;
		rep(ii,0,m)rep(jj,0,m)if(a[i+ii][j+jj]!=b[ii][jj]){
			flag=0;
			break;
		}
		if(flag){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VII;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int K;
  cin>>K;
  vector<ll> A(K),B(K+1),C(K+1);
  rep(i,K) cin>>A[i];
  B[K]=2,C[K]=2;
  rep(i,K){
    B[K-1-i]=(B[K-i]+A[K-1-i]-1)/A[K-1-i]*A[K-1-i];
    C[K-1-i]=C[K-i]/A[K-1-i]*A[K-1-i]+A[K-1-i]-1;
  }
  ll BB=B[0],CC=C[0];
  rep(i,K){
    BB=BB-BB%A[i];
    CC=CC-CC%A[i];
  }
  if(BB==2&&CC==2) cout<<B[0]<<" "<<C[0]<<endl;
  else cout<<-1<<endl;
}



Measured memory_bytes: 2560
n = int(input())
a = list(map(int,input().split()))
count = 0
geta = 0
for i in range(n-1):
    if a[i] + geta > a[i+1]:
        count += a[i] + geta -a[i+1]
        geta = a[i] + geta -a[i+1]
    else:
        geta = 0

print(count)


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

    int main() {
      int N; cin >> N;  // 作業回数
      int K; cin >> K;  // 限界線
      int S = 0;        // 移動距離サマリ

      rep(i,N){
        int x; cin >> x; // ボールのｘ座標
        if (x < K-x) {
          S += x + x ;
        } else {
          S += K-x + K-x;
        }
      }
      cout << S << endl;
    }

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

using namespace std;

int main(){
    int cost[10][10];
    int H,W;
    cin >> H >> W;

    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin >> cost[i][j];
        }
    }

    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }

    int grid;
    int ans = 0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> grid;
            if(grid == -1) continue;
            ans += cost[grid][1];
        }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadInts();
            var s = Read();
            var ans = "";
            for (int i = 0; i < input[0]; i++)
            {
                if (i == input[1]-1)
                {
                    ans += s[i].ToString().ToLower();
                }
                else
                {
                    ans += s[i];
                }
            }
            WriteLine(ans);
                
         }
       

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

    }
}


Measured memory_bytes: 11092
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <sstream>
#include <regex>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int x; cin >> x;
	if (x == 0)cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 3632
#include <cstdlib>
#include <iostream>
#include <typeinfo>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

  vector<int> esum(n + 1);
  vector<int> wsum(n + 1);

  for (int i = 0; i < n; i++)
  {
    if (s.at(i) == 'E')
    {
      esum.at(i + 1) = esum.at(i) + 1;
      wsum.at(i + 1) = wsum.at(i);
    }
    else
    {
      esum.at(i + 1) = esum.at(i);
      wsum.at(i + 1) = wsum.at(i) + 1;
    }
  }

  int ans = n;
  int tmp;

  for (int i = 0; i < n;i++){
    tmp = wsum.at(i) + esum.at(n) - esum.at(i + 1);
    ans = min(tmp, ans);
  }

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

Measured memory_bytes: 3076
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int accE[300010];
int accW[300010];

int main() {

    int N; cin >> N;
    string S; cin >> S;

    REP(i,S.size()) {
        if (S[i] == 'E') accE[i]++;
        if (S[i] == 'W') accW[i]++;
    }

    REP(i,300005)   {
        accE[i + 1] = accE[i + 1] + accE[i];
        accW[i + 1] = accW[i + 1] + accW[i];
    }
    
    int ans = 1e9;
    REP(i,S.size()) {
        int sum1 = accE[300005] - accE[i];
        int sum2 = (i == 0) ? 0 : accW[i - 1];
        ans = min(ans, sum1 + sum2);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3076
N = int(input())
T = []
A = []
for i in range(N):
  a, b = map(int, input().split())
  T.append(a)
  A.append(b)

t = T[0]
a = A[0]

for i in range(1, N):
  if t < T[i] and a < A[i]:
    t = T[i]
    a = A[i]
  else:
    x = (t + T[i] - 1) // T[i]
    y = (a + A[i] - 1) // A[i]
    t = T[i] * max(x, y)
    a = A[i] * max(x, y)

print(t + a)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main(void){
	int n,x,l,sum=0,count=1;
	cin >> n >> x;
	for(int i = 0; i < n; i++){
		cin >> l;
		sum += l;
		if(sum <= x){
			count++;
		}else{
			break;
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = input()


l = len(S)
ans = 0
for i in range(l):
    for j in range(i + 1, l + 1):
        for c in S[i:j]:
            if not c in ['A', 'C', 'G', 'T']:
                break
        else:
            ans = max(j - i, ans)
print(ans)


Measured memory_bytes: 65632
#include "bits/stdc++.h"
using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    string S2 = S + S;

    bool flag = true;
    int prepos = -1;
    vector<int> pos(T.size());
    for (int i = 0; i < T.size(); i++) {
        if (S2.find(T[i], prepos + 1) == string::npos) {
            flag = false;
            break;
        }
        else {
            prepos = S2.find(T[i], prepos + 1);
            if (prepos >= S.size()) prepos -= S.size();
            pos[i] = prepos;
        }
    }

    for (int i = 0; i < T.size(); i++) {
        pos[i]++;
        //cout << pos[i] << endl;
    }
    if (flag) {
        long long ans = pos[0];
        for (int i = 1; i < T.size(); i++) {
            if (pos[i] <= pos[i - 1]) {
                ans = ((ans + S.size() - 1) / S.size()) * S.size();
                ans += pos[i];
            }
            else ans += pos[i] - pos[i - 1];
        }
        cout << ans << endl;
    }
    else cout << "-1" << endl;
}

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

#define Max 250000
int prime[Max] = {};

int main()
{
	for (int i = 2; i < Max; i++)
	{
		prime[i] = 1;
	}
	for (int i = 2; i < Max; i++)
	{
		if (prime[i] == 0) continue;
		for (int j = i + i; j < Max; j += i)
		{
			prime[j] = 0;
		}
	}
	for (int i = 2; i < Max; i++)
	{
		prime[i] = prime[i] + prime[i - 1];
	}

	int n;
	while (cin >> n, n)
	{
		cout << prime[n * 2] - prime[n] << endl;
	}

	return 0;
}

Measured memory_bytes: 2136
#include<iostream>

int main(void)
{
    int a, b;
    while(std::cin >> a >> b){
        if(a == 0 && b == 0)
            break;
        if(a > b)
            std::cout << b << " " << a << std::endl;
        else
            std::cout << a << " " << b << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
int main(){
  ll n,m,k,i,j,result=0;
  int a[200010];
  string s;
  cin >> k;
  if(k%2==0 || k%5==0){
    cout << -1 << endl;
    return 0;
  }
  result = -1;
  j=0;
  rep(i,k+1){
    j = (j*(10%k))%k;
    j = (j+(7%k))%k;
    if(j==0){
      result=i+1;
      break;
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3616
# A, B = [int(i) for i in input().split(" ")]
# A = int(input())

N, K = [int(i) for i in input().split(" ")]
As = [int(i) for i in input().split(" ")]
MOD = 10 ** 9 + 7
ans = 0

count1 = [0] * N
for i in range(N):
    count1[i] = sum(As[i] > As[j] for j in range(N))

count2 = [0] * N
for i in range(N):
    count2[i] = sum(As[i] > As[j] for j in range(i + 1, N))

# print(ans, total2, total2 * (K-1))
for i in range(N):
    a = ((2*count2[i] + (K-1)*count1[i]) * K) // 2
    ans = (ans + a) % MOD
print(ans)


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

//#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int main()
{
    int N;
    cin >>N;
    string S,T;
    cin >> S >> T;
    for(int i=0; i<S.length(); i++){
        cout<< S[i] << T[i];
    }
    cout <<endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int t ;
	string n;
	int ctle = 0;
	int cwa = 0;
	int cre = 0;
	int cac = 0;
	cin >> t;
	while(t--){
		cin >> n;
		if(n == "AC"){
			cac++;
		}
		else if(n== "TLE"){
			ctle++;
		}
		else if(n == "WA"){
			cwa++;
		}
		else if(n== "RE"){
			cre++;
		}
	}
	cout << "AC x " << cac << endl;
	cout << "WA x " << cwa << endl;
	cout << "TLE x " << ctle << endl;
	cout << "RE x " << cre << endl;
	return 0;
}


Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;


public class Main {

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

		int n = sc.nextInt();
		int[] w = new int[n];
		HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
		
    	for (int i = 0; i < n; i++) {
    		w[i] = sc.nextInt();
    		hm.put(w[i], i);
    	}
    	int[] sort = w.clone();
    	Arrays.sort(sort);
    	
    	int ret = 0;
    	int swapi = 0;
    	int swapj = 0;
    	for (int i = 0; i < n; i++) {
    		int min = sort[i];
    		int mini = hm.get(min);
    		int ret2 = 0;
    		int ret3 = i == 0 ? 0 : (sort[0] + min) * 2;
    		while (mini != i) {
    			swapi = mini;
    			swapj = hm.get(sort[mini]);
    			int tmp = w[swapj];
    			w[swapj] = w[swapi];
    			w[swapi] = tmp;
    			hm.put(w[swapj], swapj);
    			hm.put(w[swapi], swapi);
    			
    			ret2 += w[swapj] + w[swapi];
    			ret3 += w[0] + w[swapi];
    			mini = hm.get(min);
    		}
    		
    		ret += Math.min(ret2, ret3);
    	}

		System.out.println(ret);
    	
        sc.close();
	}
}

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

ll gcd(ll a, ll b) {
  if (a < b) swap(a,b);
  if (b == 0) return a;
  return gcd(b, a%b);
}

int main() {
  ll N, X; cin >> N >> X;
  ll a[N];
  for (ll i = 0; i < N; i++) {
    ll x; cin >> x;
    a[i] = abs(X-x);
  }
  ll res = a[0];
  for (ll i = 1; i < N; i++) {
    res = gcd(res, a[i]);
  }
  cout << res << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int i, j;
	for(i = 1; i <= 9; i++)
	{
		for(j = 1; j <= 9; j++)
		{
			printf("%dx%d=%d\n", i, j, i * j);	
		} 
	} 
	return 0;
	
	
	
	

    
}


Measured memory_bytes: 2496
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int x, y;
    std::cin >> x >> y;
    int ans = 0;
    if (x == 1 && y == 1)
    {
        ans = 1000000;
        std::cout << ans << std::endl;
        return 0;
    }

    if (x == 1) { ans += 300000; }
    else if (x == 2)
    {
        ans += 200000;
    }
    else if (x == 3)
    {
        ans += 100000;
    }

    if (y == 1) { ans += 300000; }
    else if (y == 2)
    {
        ans += 200000;
    }
    else if (y == 3)
    {
        ans += 100000;
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		long N = sc.nextLong();
		//交通機関の収納数配列
		long[] kikan = new long[5];
		long min= (long)Math.pow(10, 15);
		for(int i = 0; i<5;i++) {
			kikan[i] = sc.nextLong();
			min = Math.min(min, kikan[i]);
		}
//		double a = Math.ceil((double)N/(double)min);
		long anser = (long)Math.ceil((double)N/(double)min)+4;
		System.out.println(anser);
		}
	}


Measured memory_bytes: 21844
from collections import deque
from collections import defaultdict
import heapq

N,M=map(int, raw_input().split())
cost=map(int, raw_input().split())

if M==N-1:
	print 0
	quit()

nl=[ [] for i in range(N) ]

for i in range(M):
	x,y=map(int,raw_input().split())
	nl[x].append(y)
	nl[y].append(x)


d=[ None for i in range(N) ]
V=[ None for i in range(N) ]

group_cost=defaultdict(lambda: [])

def dfs(start):
	q = deque([]) 
	V[start]=start
	d[start]=0
	heapq.heappush(group_cost[start],cost[start])
	q.append(start)

	while len(q)!=0:
		v=q.pop()
		for i in nl[v]:
			if V[i] is None:
				V[i]=start
				q.append(i)
				heapq.heappush(group_cost[start],cost[i])

for i in range(N):
	if V[i] is None:
		dfs(i)


H = []

ans=0
for v in group_cost.values():
	v=sorted(v)
	ans+=v[0]
	H.append(v[1:])

nokori_cost=list(heapq.merge(*H))


if N < 2*(N-M-1):
	print "Impossible"
elif M == N-1:
	print 0
else:
	ans += sum(nokori_cost[:2*(N-M-1) - len(group_cost.keys())])
	print ans





Measured memory_bytes: 53336
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,A,B,sa;
  cin >> N >> A >> B;
  sa=B-A;
  if (sa%2==0) {cout << sa/2 << endl;}
  else {
  cout << min(N-B,A-1)+1+(B-A-1)/2 << endl;
  
  }
  
  
}

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

int main() {
    char AA[50];
    int a,b;
    cin >> a >> b;
    for (int i=0; i<a; i++){
        cin >> AA[i];
    }
    b = b-1;
    AA[b] = towlower(AA[b]);
    for(int i= 0; i<a; i++){
        cout << AA[i];
    }
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    A.sort();
    long x = () {
        long ok = 0;
        long ng = N;
        while (1 < ng - ok)
        {
            long m = (ok + ng) / 2;
            if (A[m] < 0)
            {
                ok = m;
            }
            else
            {
                ng = m;
            }
        }
        if (ok == N - 1)
            ok = N - 2;
        return ok;
    }();
    // writeln(A);
    // writeln(x);
    writeln(A[x + 1 .. N].sum() - A[0 .. x + 1].sum());
    long a = A[0];
    foreach (i; x + 1 .. N - 1)
    {
        writefln("%s %s", a, A[i]);
        a = a - A[i];
    }
    writefln("%s %s", A[N - 1], a);
    long b = A[N - 1] - a;
    foreach (i; 1 .. x + 1)
    {
        writefln("%s %s", b, A[i]);
        b = b - A[i];
    }
}


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

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

int main(){
  int N;
  string S;
  cin >> N >> S;
  using mint = modint<(int)1e9+7>;
  int M = S.length();
  vector<mint> dp(N+1,0);
  dp[0] = 1;
  for(int i = 0; i < N; ++i){
    vector<mint> dp_(N+1,0);
    for(int j = 0; j <= N; ++j){
      if(j > 0) dp_[j-1] += dp[j]*2;
      else dp_[j] += dp[j];
      if(j+1 <= N) dp_[j+1] += dp[j];
    }
    dp = dp_;
  }
  cout << dp[M] << endl;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-


def main():
    """Function."""
    a, b, c, d = map(int, input().split())
    if a+b < c+d:
        print("Right")
    elif a+b == c+d:
        print("Balanced")
    else:
        print("Left")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include"bits/stdc++.h"
main(){for(int n,m,s,i,j,d[50][3500],M=1e5;std::cin>>n>>m>>s,n*=n;){std::fill(d[0],d[50],M);d[0][0]=1;for(i=1;i<=n;++i)for(j=0;j<=s;++j){if(j>=i)d[i][j]+=d[i-1][j-i]+d[i][j-i];if(j>m)d[i][j]-=d[i-1][j-m-1];d[i][j]%=M;}printf("%d\n",d[n][s]);}}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
int main (){
    char A;
  cin >> A;
    if(A == 'a'|| A == 'i' || A == 'u'||A == 'e'||A == 'o'){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
}
      

Measured memory_bytes: 256
import heapq
import math


def main():
    nvertices, nedges, s = map(int, input().split())
    Adj = [[] for i in range(nvertices)]
    for i in range(nedges):
        u, v, w = map(int, input().split())
        Adj[u].append((v, w))

    Q = [(0, s)]
    d = [float('inf')] * nvertices
    d[s] = 0
    while Q:
        w, u = heapq.heappop(Q)
        if d[u] < w:
            continue
        for v, cost in Adj[u]:
            if d[u] + cost < d[v]:
                d[v] = d[u] + cost
                heapq.heappush(Q, (d[v], v))

    for cost in d:
        if math.isinf(cost):
            print("INF")
        else:
            print(cost)


main()

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int MAXN = 2e5 + 5;

ll a[MAXN];

int main() {
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    ll ans = 1e18;
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        a[i] += a[i - 1];
    }
    for (int i = 1; i < n; i++) {
        ans = min(ans, abs(a[i] - (a[n] - a[i])));
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a,b;
  cin>>a>>b;
	if (a=='H' and b=='H') cout<<"H"<<endl;
	if (a=='H' and b=='D') cout<<"D"<<endl;
	if (a=='D' and b=='H') cout<<"D"<<endl;
  	if (a=='D' and b=='D') cout<<"H"<<endl;

  return 0;
}


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

void solv(vector<int>& arr){
  for(int i=1;i<arr.size();i++){
      
    for(int k=0;k<arr.size()-1;k++){
      cout<<arr[k]<<" ";
    }
    cout<<arr[arr.size()-1]<<endl;
    
    auto key = arr[i];
    auto j = i - 1;
    while(j>=0 && arr[j] > key){
      arr[j+1] = arr[j];
      j--;
    } 
    arr[j+1] = key;
  }
  
  for(int k=0;k<arr.size()-1;k++){
    cout<<arr[k]<<" ";
  }
  cout<<arr[arr.size()-1]<<endl;
  
}

int main(){
  int n, m;
  vector<int> arr;
  cin>> n;
  for(int i=0;i<n;i++){
    cin>> m;
    arr.push_back(m);
  }
  solv(arr);
  return 0; 
}


Measured memory_bytes: 3168
#include <iostream>
#include <string>

int main() {
  int n; std::cin >> n;
  std::string s, t; std::cin >> s >> t;
  for (int i = 0; i < n; ++i) {
    std::cout << s[i] << t[i]; 
  }
  std::cout << std::endl;
  
  return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}
template<typename T> T lcm(T a,T b){return a*b/gcd(a, b);}


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
int main() {
    IN(int, n);
    VIN(int, a, n);
    SORT(a);
    COUT(a[n/2]-a[n/2-1]);
}


Measured memory_bytes: 3760