akhauriyash/Code-Regression huggingface dataset:
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;

class UnionFind {
public:
	vector <ll> par; // 各元の親を表す配列
	vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}
};

int main() {
	cin >> N >> M;
	UnionFind tree(N + 1);
	ll cnt = 0;
	rep(i, M) {
		cin >> A >> B >> C;
		if (!tree.issame(A, B)) {
			tree.merge(A, B);
			cnt++;
		}
	}
	cout << N - cnt;
}


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

NEXT = 2
DATA = 1
PREV = 0
def dll_processor(operations):

    front = None
    end = None

    for o in operations:
        if o[0] == "insert":
            front, end = insert(front, end, o[1])
        elif o[0] == "delete":
            front, end = delete(front, end, o[1])
        elif o[0] == "deleteFirst":
            front, end = delete_first(front, end)
        elif o[0] == "deleteLast":
            front, end = delete_last(front, end)
        #print(get_list(front))

    return get_list(front)

def get_list(front):
    if not front:
        return []

    l = []
    target = front
    while True:
        l.append(target[DATA])
        if not target[NEXT]:
            break
        target = target[NEXT]
    return l

def insert(front, end, target):
    node = [None, target, None]
    if front:
        front[PREV] = node
        node[NEXT] = front
        return node, end
    else:
        return node, node

def delete(front, end,target):

    delete_node = front
    while not delete_node[DATA] == target:
        delete_node = delete_node[NEXT]
        if delete_node == None:
            return front, end

    if delete_node[PREV] == None:
        delete_node[NEXT][PREV] = None
        return delete_node[NEXT], end
    elif delete_node[NEXT] == None:
        delete_node[PREV][NEXT] = None
        return front, delete_node[PREV]
    else:
        delete_node[NEXT][PREV] = delete_node[PREV]
        delete_node[PREV][NEXT] = delete_node[NEXT]
        return front, end

def delete_last(front, end):

    if not end[PREV]:
        return None, None
    else:
        end[PREV][NEXT] = None
        return front, end[PREV]

def delete_first(front, end):

    if not front[NEXT]:
        return None, None
    else:
        front[NEXT][PREV] = None
        return front[NEXT], end

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))

if __name__ == "__main__":
    main()


Measured memory_bytes: 605448
#include<stdio.h>
int main(void){
int i, j, n, a[10000];
scanf("%d", &n);
for(i = 0; i < n; i++){
  scanf("%d", &a[i]);
}
for(j = n - 1; j >= 0; j--){
  if(j > 0){
  printf("%d ", a[j]);
  }else{
    printf("%d", a[j]);
}
}
printf("\n");
return 0;
}


Measured memory_bytes: 2044
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>

using namespace std;

int utate[520];
int uyoko[520];
int unaname[5];
int ntate[520];
int nyoko[520];
int nnaname[5];

int ufsuuji[1200000];
int ussuuji[1200000];
int nfsuuji[1200000];
int nssuuji[1200000];


int n,u,v,m;
int k;
int nkotae,ukotae;

int main(){
	cin >> n >> u >> v >> m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin >> k;
			ufsuuji[k]=i;
			ussuuji[k]=j;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin >> k;
			nfsuuji[k]=i;
			nssuuji[k]=j;
		}
	}
	for(int i=0;i<m;i++){
		cin >> k;
		if(ufsuuji[k] != 0){
			uyoko[ufsuuji[k]]++;
			if(uyoko[ufsuuji[k]]==n) ukotae++;
			utate[ussuuji[k]]++;
			if(utate[ussuuji[k]]==n) ukotae++;
			if(ufsuuji[k]==ussuuji[k]){
				unaname[1]++;
				if(unaname[1]==n) ukotae++;
			}
			if(ufsuuji[k]+ussuuji[k]==n+1){
				unaname[2]++;
				if(unaname[2]==n) ukotae++;
			}
		}
		if(nfsuuji[k] != 0){
			nyoko[nfsuuji[k]]++;
			if(nyoko[nfsuuji[k]]==n) nkotae++;
			ntate[nssuuji[k]]++;
			if(ntate[nssuuji[k]]==n) nkotae++;
			if(nfsuuji[k]==nssuuji[k]){
				nnaname[1]++;
				if(nnaname[1]==n) nkotae++;
			}
			if(nfsuuji[k]+nssuuji[k]==n+1){
				nnaname[2]++;
				if(nnaname[2]==n) nkotae++;
			}
		}
		if(n==1){
			ukotae = min(1,ukotae);
			nkotae = min(1,nkotae);
		}
		if(ukotae>=u && nkotae>=v){
			cout << "DRAW" << endl;
			return 0;
		}
		else if(ukotae>=u){
			cout << "USAGI" << endl;
			return 0;
		}
		else if(nkotae>=v){
			cout << "NEKO" << endl;
			return 0;
		}
	}
	cout << "DRAW" << endl;
	return 0;
}




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

int main() {
    int n, x, y; cin >> n >> x >> y;

    vector<int> dists(n - 1, 0);
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int dist = j - i;
            if (i + 1 <= x + (y - x - 1) / 2) {
                dist = min(dist, abs((i + 1) - x) + abs((j + 1) - y) + 1);
            }
            ++dists[dist - 1];
        }
    }

    for (auto ans : dists) {
        cout << ans << endl;
    }
}



Measured memory_bytes: 3608
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2,tune=native")

#include <x86intrin.h>
#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int A[N + 2], L[N + 2], R[N + 2];
    for (int i = 1; i <= N; i++) {
	cin >> A[i];
	L[i] = R[i] = A[i];
    }
    L[0] = L[N + 1] = R[0] = R[N + 1] = 0;
    for (int i = 1; i <= N; i++) {
	L[i] = __gcd(L[i], L[i - 1]);
	R[N - i + 1] = __gcd(R[N - i + 1], R[N - i + 2]);
    }
    int res = 0;
    for (int i = 1; i <= N; i++) {
	res = max(res, __gcd(L[i - 1], R[i + 1]));
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 1408
N, M = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())
c = [0] * M
d = [0] * M
for i in range(M):
    c[i], d[i] = map(int, input().split())


for i in range(N):
    distance = abs(a[i] - c[0]) + abs(b[i] - d[0])
    check_point = 1
    for j in range(M):
        temp = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if distance > temp:
            distance = temp
            check_point = j + 1
    print(check_point)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <random>
#include <deque>

#define INF_LL 1e18
#define INF 1e9

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

using namespace std;

using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

const ll MOD = 1e9+7;

int dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
int dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

template<typename T>
void chmax(T &a, T b){
	a = max(a, b);
}

template<typename T>
void chmin(T &a, T b){
	a = min(a, b);
}

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

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

class RMQ{
	int n;
	vector<int> dat;
public:
	RMQ(int n_){
		n = 1;
		while(n < n_) n *= 2;
		REP(i, n*2-1){
			dat.push_back(INF);
		}
	}

	void update(int x, int i){
		i += n-1;
		dat[i] = x;
		while(i > 0){
			i = (i-1)/2;
			dat[i] = min(dat[i*2+1], dat[i*2+2]);
		}
	}

	int query(int a, int b, int l, int r, int x){
		if(a <= l && r <= b) return dat[x];
		if(r <= a || b <= l) return INF;

		int res = INF;
		res = min(query(a, b, l, (l+r)/2, x*2+1), query(a, b, (l+r)/2, r, x*2+2));
		return res;
	}
	int query(int a, int b){
		return query(a, b, 0, n, 0);
	}
};

const ll mod = 1e9+7;

int N, K;
vector<ll> a;
bool dp[5050] = {};

bool ok(ll in){
	if(in >= N) return true;
	memset(dp, 0, sizeof(dp));
	dp[0] = true;
	REP(i, N){
		if(i == in) continue;
		for(int j = K+1;j >= a[i];j--){
			if(dp[j-a[i]]) dp[j] = true;
		}
	}
	FOR(i, max(0, (int)K-(int)a[in]), K){
		if(dp[i]){
			return true;
		}
	}
	return false;
}

int main(void){
	int a, b, c;
	cin >> a >> b >> c;
	if(b-a == c-b){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


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

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    sc.close();

    int train = N * A;
    int taxi = B;

    if (train < taxi){
      System.out.println(train);
    } else {
      System.out.println(taxi);
    }

  }
  
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

#define ll long long
//#define int long long
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;

#define dump(x)  cerr << #x << " = " << (x) << endl; 
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

ll N, x;
ll a[101];

signed main(){

	cin >> N >> x;

	for (int i = 0; i < N; i++) cin >> a[i];

	sort(a, a + N);

	int i;
	for (i = 0; i < N; i++){
		// もう配れなくなったらbreak
		if (x < a[i]) break;
		x -= a[i];
	}

	// 最後の人のがあまりがある場合
	if (i == N && x > 0) i--;

	cout << i << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
  string s1,s2;
  cin>>s1>>s2;
  int c1[27],c2[27];
  for(int i = 0; i<27; i++){
    c1[i] = 0;
    for(int j = 0; j<s1.size(); j++){
      if(s1[j] == 'a'+i){
        c1[i]++;
      }
    }
    }
    for(int i = 0; i<27; i++){
      c2[i] = 0;
      for(int j = 0; j<s2.size(); j++){
        if(s2[j] == 'a'+i){
          c2[i]++;
        }
      }
      }
  sort(c1,c1+27);
  sort(c2,c2+27);
  int flag = 0;
  for(int i = 0; i<27; i++){
    if(c1[i]!=c2[i]){
      flag = 1;
    }
  }
  if(flag) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 776
use input::Input;

fn main() {
    let mut input = Input::default();

    let a: i64 = input.parse();
    let v: i64 = input.parse();
    let b: i64 = input.parse();
    let w: i64 = input.parse();
    let t: i64 = input.parse();

    let d = (a - b).abs();
    let u = v - w;

    if u > 0 && u * t >= d {
        println!("YES");
    } else {
        println!("NO");
    }
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int main() {
    
    long long int n,m;
    cin >> n >> m;
    int used[n];
    int data[n];
    for(int i=0;i<n;i++) used[i]=0;
    //used[0] = 1;

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


    int t=1;
    int p=0;
    while(true){
        if(used[p]) break;
        used[p] = t;
        p = data[p]-1;
        t++;
    }

    //cout << used[p] << " " << t << endl;

    /*for(int i=0;i<n;i++){
        cout << used[i] << " ";
    }
    cout << endl;
    */
    //cout << m << endl;
    int loop = (m-used[p]+1) % (t-used[p]);

    for(int i=0;i<loop;i++) {
        p = data[p]-1;
    }

    if(m < used[p]) {
        p=0;
        for(int i=0;i<m;i++) {
            p = data[p]-1;
        }
        cout << p+1 << endl;
        return 0;
    }

    cout << p+1 << endl;
} 

Measured memory_bytes: 5184
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k-1] << endl;
}

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

int main(){
    int A, B, C, N, M ,K;
    int sum = 0;
    int t = 0;
    string s, s1;

    cin >> A >> B >> C;

    if(A< C && C < B) cout << "Yes" << endl;
    else if(A> C && C > B) cout << "Yes" << endl;
    else cout << "No" << endl;
//    vector<int> X();

//    for(int i = 0; i < ; i++){}
//    for(int j = 0; j < ; j++){}

//    cout <<  << endl;
}

Measured memory_bytes: 256
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a,b,c,k=mp()
if k<=a:
    print(k)
elif k<=a+b:
    print(a)
else:
    print(2*a-k+b)

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, A, B;
    cin >> X >> A >> B;
    X -= A;
    int ans;
    ans = X / B;
    X -= B * ans;
    cout << X << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n, ma = MINF, mi = INF;
int main() {
	cin >> n;
	REP(i, n) {
		ll a;
		cin >> a;
		ma = max(ma, a);
		mi = min(mi, a);
	}
	cout << (ma - mi + 1) / 2 << endl;
}



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

void bfs(vector<int> v, map<vector<int>, int>& m) {
    const int N = v.size();
    queue<vector<int>> que;
    que.push(v);
    m[v] = 0;
    while(!que.empty()) {
        auto now = que.front();
        que.pop();
        int cost = m[now];
        if(cost >= (N-1)/2) {
            continue;
        }
        for(int i=0; i<N; ++i) {
            for(int j=i+2; j<=N; ++j) {
                auto next = now;
                reverse(next.begin()+i, next.begin()+j);
                if(m.count(next) == 0) {
                    m[next] = cost + 1;
                    que.push(next);
                }
            }
        }
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    for(int i=0; i<N; ++i) {
        cin >> v[i];
    }
    auto v2 = v;
    sort(v2.begin(), v2.end());
    map<vector<int>, int> m1, m2;
    int res = N - 1;
    bfs(v, m1);
    bfs(v2, m2);
    do {
        if(m1.count(v2) == 0 || m2.count(v2) == 0) {
            continue;
        }
        res = min(res, m1[v2] + m2[v2]);
    } while(next_permutation(v2.begin(), v2.end()));
    cout << res << endl;
}


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

int main() {
	int a,b;
	cin >> a >> b;
	if(a<b){
		for(int i = 0;i<b;i++)printf("%d",a);
	}else{
		for(int i = 0;i<a;i++)printf("%d",b);
	}
	printf("\n");
	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);

        int H;
        int W;

        while(true) {
            H = sc.nextInt();
            W = sc.nextInt();
            if(H == 0&&W == 0) {
                break;
            }
            
            for(int i = 0; i < H; i++) {
                for(int j = 0; j < W; j++) {
                    if(i == 0|| i == H - 1||j == 0||j == W - 1){
                        System.out.print("#");
                    }
                    else {
                        System.out.print(".");
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 36296
x1, y1, x2, y2 = map(int,input().split())
# (x2-x1) + (y2-y1)i
# -(y2-y1) + (x2-x1)i
n_x, n_y = y1 - y2, x2 - x1
x3, y3 = x2 + n_x, y2 + n_y
x4, y4 = x1 + n_x, y1 + n_y
print(x3,y3,x4,y4)

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
using namespace std;
// Problem https://atcoder.jp/contests/abc125/tasks/abc125_c
// Reference http://drken1215.hatenablog.com/entry/2019/04/27/224100_1
// ABC125C_1の改訂版。ひとまずvector[i]->vector.at(i)に置換

int GCD(int a,int b){
    if(b != 0){
        int c = a%b;
        return GCD(b,c);
    }
    return a;
}

int solver(int allNumber,vector<int> numbers){
    /** 配列の出力法確認 
     for(int j=0;j<allNumber;j++){
        cout << numbers.at(j) << ",";
    } 
    cout << endl; **/
    /** GCDチェック 
    int TestGCD = GCD(72,18);
    cout << "GCDTEST1:" << TestGCD << endl;
    TestGCD = GCD(0,100);
    cout << "GCDTEST2:" << TestGCD << endl; 
    **/
    vector<int> left(allNumber+1,0); // 左側からの累積GCD配列
    vector<int> right(allNumber+1,0); // 右側からの累積GCD配列
    // 左からの累積GCD
    for(int i=0;i<allNumber;i++){
            left.at(i+1)=GCD(left.at(i),numbers.at(i));
    }
    // 右からの累積GCD
    for(int i=allNumber-1;i>=0;i--){
// 誤り for(int i = allNumber;allNumber>=0;i++) -> 無限ループ        
       // 誤り right.at(i)=GCD(right.at(i+i),numbers.at(i)); -> Typo i+iでは範囲外の配列へのアクセスを試みる
       // vector[i+i] では 適当な値を拾ってきて、エラーが出ない
       right.at(i)=GCD(right.at(i+1),numbers.at(i));
    }
    /**for(int j=0;j<=allNumber;j++){
        cout << "j:" << left.at(j) << " " << right.at(j) << endl;
    }**/
    int answer = 0;
    for(int i=0;i<allNumber;++i){
        int l = left[i];
        int r = right[i+1];
        int tmp;
        tmp = GCD(l,r);
        if(answer < tmp){
            answer=tmp;
        }      
    } 
    return answer; 
}

int main(void){
    int N,answer;
    cin >> N ;
    vector<int> A(N);
    for(int i=0;i<N;++i){
        cin >> A.at(i);
    }
    answer = solver(N,A);
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
plan = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]
dp[0] = plan[0]
for i in range(0, n - 1):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + plan[i + 1][k])
print(max(dp[n - 1]))


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

int main() {
  int n; cin >> n;
  
  vector<int> wests(n, 0);
  vector<int> easts(n, 0);
  for (int i = 0; i < n; i++) {
    char d; cin >> d;
    if (d == 'W') wests.at(i)++;
    else if (d == 'E') easts.at(i)++;
  }
  
  vector<int> ps_wests(n, 0);
  partial_sum(wests.begin(), wests.end(), ps_wests.begin());
  vector<int> ps_easts(n, 0);
  partial_sum(easts.begin(), easts.end(), ps_easts.begin());
  
  int answer = ps_easts.at(n - 1) - ps_easts.at(0);
  for (int i = 1; i < n; i++) {
    int num_people = ps_wests.at(i - 1) + ps_easts.at(n - 1) - ps_easts.at(i);
    answer = min(answer, num_people);
  }
  
  cout << answer << endl;
}

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

int main(){
  int n;  cin >> n;
  int ans = 1<<30;
  while(n--){
    int a;  cin >> a;
    int cnt = 0;
    while(a % 2 == 0){
      a >>= 1;
      cnt++;
    }
    ans = min(ans, cnt);
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = (a + d - 1) / d;
  int y = (c + b - 1) / b;
  cout << (x >= y ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3632
n=int(input())

lis=[]
for i in range(n):
    d1,d2=map(int,input().split())
    if d1==d2:
        lis.append(1)
    else:
        lis.append(0)

c=0
for i in range(n-2):
    if sum(lis[i:i+3])==3:
        c+=1

if c!=0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9172
import sys
N, A, B, C, D = list(map(int, input().split()))
S = input()
A -= 1
B -= 1
C -= 1
D -= 1
if C < D:
    i = A
    while i < C:
        while i < C and S[i] == '.':
            i += 1
        _cnt_r = 0
        while i < C and S[i] == '#':
            i += 1
            _cnt_r += 1
        if _cnt_r >= 2:
            print('No')
            sys.exit()
    i = B
    while i < D:
        while i < D and S[i] == '.':
            i += 1
        _cnt_r = 0
        while i < D and S[i] == '#':
            i += 1
            _cnt_r += 1
        if _cnt_r >= 2:
            print('No')
            sys.exit()
    print('Yes')
else:
    i = B - 1
    cnt_s = 0
    while i <= D + 1:
        _cnt_s = 0
        while i <= D + 1 and S[i] == '.':
            i += 1
            _cnt_s += 1
        cnt_s = max(cnt_s, _cnt_s)
        _cnt_r = 0
        while i <= D + 1 and S[i] == '#':
            i += 1
            _cnt_r += 1
        if _cnt_r >= 2:
            print('No')
            sys.exit()
    if cnt_s <= 2:
        print('No')
        sys.exit()
    i = A
    while i < C:
        while i < C and S[i] == '.':
            i += 1
        _cnt_r = 0
        while i < C and S[i] == '#':
            i += 1
            _cnt_r += 1
        if _cnt_r >= 2:
            print('No')
            sys.exit()
    print('Yes')


Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
//mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());
//int rnd(int x) { return mrand()%x;}
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
int main(){
	int  k,a,b;
	scanf("%d%d%d",&k,&a,&b);
	int fg=b/k-(a-1)/k;
	if(fg){
		printf("OK");
	} 
	else{
		printf("NG\n");
	}
	return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;r0=x;r1=y;a0=1;a1=0;b0=0;b1=1;
  while(r1>0){q=r0/r1;r2=r0%r1;a2=a0-q*a1;b2=b0-q*b1;r0=r1;r1=r2;a0=a1;a1=a2;b0=b1;b1=b2;}
  *c=r0;*a=a0;*b=b0;
}

ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}

ll fact[2000100],fact_inv[2000100];

void init() {
  fact[0]=1;
  REP(i,1,2000100) fact[i]=fact[i-1]*i%MAX;
  fact_inv[2000050]=get_inv(fact[2000050],MAX);
  rrep(i,2000050)fact_inv[i]=fact_inv[i+1]*(i+1)%MAX;
}

ll nCr(int N,int K){
  if(K<0||K>N)return 0;
  return fact[N]*fact_inv[K]%MAX*fact_inv[N-K]%MAX;
}

void Main() {
  init();
  ll n,m,k;
  cin >> n >> m >> k;
  ll sum=0;
  REP(j,1,n*m) {
    ll x2=j/m,y2=j%m;
    sum+=x2+y2;
    sum%=MAX;
  }
  ll ans=0;
  rep(i,n*m) {
    ans+=nCr(n*m-2,k-2)*sum%MAX;
    ans%=MAX;
    ll x=(i+1)/m,y=(i+1)%m;
    sum-=(n-x)*(m-y)%MAX;
    sum+=(n-x-1)*y%MAX;
    sum+=MAX;
    sum%=MAX;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

Measured memory_bytes: 31616
#include <iostream>
#include <unordered_map>

using namespace std;

typedef long long ll;

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

    unordered_map<int, int> map;
    for (int i = 0; i < N; ++i)
    {
        int a;
        cin >> a;

        if (map.find(a) != map.end())
        {
            map[a] += 1;
        }
        else
        {
            map[a] = 1;
        }
    }

    int ans = 0;
    for (auto& kv: map)
    {
        if (kv.first < kv.second) ans += kv.second - kv.first;
        if (kv.first > kv.second) ans += kv.second;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n, k;
  cin >> n >> k;
  int a[200005];
  REP(i, n) { cin >> a[i]; }
  FOR(i, k, n) {
    if (a[i] > a[i - k]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

const int N=110000;
typedef long long LL;
const LL mod=1e9+7;

int n;

int main()
{
	scanf("%d",&n);
	if (n%2==0) n--;
	printf("%d\n",n/2);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  string S;
  int flag=0;
  cin >> S;
  for(int i=0; i<S.length(); i++){
    if(i%2 == 0){
      if(S[i] == 'R' || S[i] == 'U' || S[i] == 'D');
      else{
        flag = 1; break;
      }
    }else{
      if(S[i] == 'L' || S[i] == 'U' || S[i] == 'D');
      else{
        flag = 1; break;
      }
    }
  }
  if(flag == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main() {
  int h,n;
  cin >> h >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a.at(i);
  }
  
  int max=0;
  for(int i=0; i<n; i++){
    max=max+a.at(i);
  }
  if(max>=h){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

int main() {
  string n;
  int num1,num2,ans;
  ans = 0;
  cin >> n;
  for(int i=0;i<n.size();i++){
    num1 = n.at(i)-'0';
    ans += num1;
  }
  num2 = stoi(n);
  if (num2%ans == 0){
  	cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N, A, B;
    cin >> N >> A >> B;

    int ans = 0;
    FOR(i, 1, N + 1){
        int tmp = 0;
        int i0 = i;
        while(i0 > 0){
            tmp += i0 % 10;
            i0 /= 10;
        }
        if(A <= tmp && tmp <= B) ans += i;
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int n, m;
int x[100010], y[100010];


int solve(){
	int sumX = 0, sumY = 0;
	rep(i, 0, n) sumX = ADD(sumX, x[i]*(2*i-n+1));
	rep(i, 0, m) sumY = ADD(sumY, y[i]*(2*i-m+1));
	return MUL(sumX, sumY);
}


signed main(){
	cin >> n >> m;
	rep(i, 0, n) cin >> x[i];
	rep(i, 0, m) cin >> y[i];

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 1920
/*input

*/
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define MAX 100005
#define pb push_back
#define mp make_pair


using namespace std;
using namespace std::chrono;


signed main(){
	int x,y;
	cin >> x >> y;
	int price[]={0,300000,200000,100000,0};
	int tot = price[min(x,4LL)]+price[min(y,4LL)];
	if(tot == 600000)
		tot += 400000;
	cout << tot << '\n';
}


Measured memory_bytes: 256
//abc136

#include "iostream"
#include <string>
using namespace std;


int main(void)
{
	int a,b;
	int val1,val2;
	cin >> a;
	cin >> b;
	if ((a - b) >= (a + b))
	{
		val1 = a - b;
	}
	else
	{
		val1 = a + b;
	}

	if ((a - b) >= (a * b))
	{
		val2 = a - b;
	}
	else
	{
		val2 = a * b;
	}

	if (val1 < val2)
	{
		val1 = val2;
	}

	cout << val1;
	return 0;
}






Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        final int size=100;
        boolean[] sizes=new boolean[size];
        for(int i=0;i<size;i++){
            sizes[i]=false;
        }
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        for(int i=0;i<n;i++){
            int size2=scanner.nextInt();
            sizes[size2-1]=true;
        }
        int result=0;
        for(int i=0;i<size;i++){
            result=sizes[i]?result+1:result;
        }
        System.out.println(result);

    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    if(a>k) cout<<a-k<<" "<<b<<"\n";
    else cout<<0<<" "<<(b-k+a)*(b-k+a>0)<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD=1e9+7;
const int MAXK=10010;
long long dp[MAXK][110];
int d,a[MAXK];
string k;

inline long long dfs(int pos,int rest,bool limit){
	if(pos==-1) return rest==0;
	if(!limit && dp[pos][rest]!=-1) return dp[pos][rest];
	int up=limit?a[pos]:9;
	long long res=0;
	for(register int i=0;i<=up;++i)
		(res+=dfs(pos-1,(rest+i)%d,limit&&i==a[pos]))%=MOD;
	return dp[pos][rest]=res%MOD;
}

inline long long solve(){
	for(register int i=k.size()-1;i>=0;--i) a[k.size()-1-i]=k[i]-'0';
	return dfs(k.size()-1,0,1);
}

int main(){
	memset(dp,-1,sizeof(dp));
	cin>>k;
	cin>>d;
	cout<<(solve()-1+MOD)%MOD<<endl;
	return 0;
}

Measured memory_bytes: 9344
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int [][] K = new int [N][M+1];
        int [] count = new int [M];
        int ans = 0;
        
        for(int i=0; i<N; i++){
            K[i][0] =sc.nextInt();
            for(int j=1; j<=K[i][0]; j++){
                K[i][j] = sc.nextInt();
                count[K[i][j]-1]++;
            }
        }
        
        for(int i=0; i<M; i++){
            if(count[i] == N){
                ans++;
            }
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define Mid ((l+r)/2)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define drep(i,a,b) for(int i=(a);i>=(b);--i)
#define file(a) freopen(#a".in","r",stdin),freopen(#a".out","w",stdout);
const int maxn=1e5+5,mod=1e9+7,inf=1e18+7;
int n,m,Q,K,T;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

signed main(){
    //file(a);
    int a=read(),b=read(),c=read(),d=read();
    int ans=-inf;
    ans=max(ans,max(a*c,max(a*d,max(b*c,b*d))));
    printf("%lld\n",ans);



    return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int N = 1e5;
int a[N+5];

int p[2];

int main()

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

    int arr[3], ans = 0;

    for (int i = 0; i < 3; i++) {

        cin >> arr[i];
        p[arr[i]%2]++;
    }

    sort(arr, arr+3);

    if (p[0] == 2) {

        if (arr[2]%2 == 0) arr[2]++;

        ans = 1;
    }

     if (p[1] == 2) {

        if (arr[2]%2) arr[2]++;

        ans = 1;
    }

    ans += (arr[2]-arr[1])/2 + (arr[2]-arr[0])/2;

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def cross3(p0, p1, p2):
    return (p1[0] - p0[0]) * (p2[1] - p0[1]) - (p1[1] - p0[1]) * (p2[0] - p0[0])

def solve():
    N = int(readline())
    mp = defaultdict(list)
    for i in range(N):
        x, y = map(int, readline().split())
        mp[x].append(y)
    *S, = mp.items()
    S.sort()
    def calc(S, k):
        P = []; Q = []
        r = 0; R = [0]
        for x, ys in S:
            ys.sort(reverse=k)
            for y in ys:
                p = (x, y)
                while len(P) >= 2 and cross3(P[-2], P[-1], p) <= 0:
                    r += abs(cross3(P[-2], P[-1], p))
                    P.pop()
                P.append(p)
                while len(Q) >= 2 and cross3(Q[-2], Q[-1], p) >= 0:
                    r += abs(cross3(Q[-2], Q[-1], p))
                    Q.pop()
                Q.append(p)
            R.append(r)
        return R
    R0 = calc(S, 0)
    S.reverse()
    R1 = calc(S, 1)

    L = len(S)
    ans = 10**20
    for i in range(L+1):
        ans = min(ans, R0[i] + R1[-1-i])
    write("%d\n" % ((ans+1) // 2))
solve()


Measured memory_bytes: 51476
import sys
from collections import defaultdict

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n = int(input())
	dd=defaultdict(lambda :0)
	for i in range(n):
		s = input()
		a=list(s)
		a.sort()
		s=''.join(a)
		dd[s]+=1
		
	ret=0
	for k in dd.keys():
		r=dd[k]
		ret += r*(r-1)//2
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;

    X -= Z;
    int count = 0;
    while (X >= Y + Z) {
        count++;
        X -= (Y + Z);
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<LL> v(n);
    REP(i,n) {
        cin >> v[i];
        if ( i>0 ) v[i]+=v[i-1];
    }
    LL ans=1LL<<60;
    REP(i,n-1) {
        chmin(ans,abs(v[n-1]-v[i]*2));
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4764
import java.util.*

val MAX_N = 100000
val par = Array(MAX_N) {0}
val rank = Array(MAX_N) {0}
val size = Array(MAX_N) {0}

fun init() {
    for(i in 0 until MAX_N) {
        par[i] = i
        rank[i] = 0
        size[i] = 1
    }
}

fun find(a: Int): Int {
    if (par[a] == a){
        return a
    } else{
        par[a] = find(par[a])
        return par[a]
    }
}

fun unite(a:Int, b: Int) {
    val ta = find(a)
    val tb = find(b)
    if(ta == tb) return

    if(rank[ta] < rank[tb]){
        par[ta] = tb
        size[tb] += size[ta]
    }else{
        par[tb] = ta
        size[ta] += size[tb]
        if(rank[ta] == rank[tb]) rank[ta]++;
    }
}

fun same(a: Int, b: Int): Boolean{
    return find(a) == find(b);
}

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val k = sc.nextInt()
    init()
    val countAB = Array(n) {0}
    repeat(m) {
        val a = sc.nextInt() - 1
        val b = sc.nextInt() - 1
        unite(a, b)
        countAB[a]++
        countAB[b]++
    }
    val countCD = Array(n) { mutableSetOf<Int>()}
    repeat(k) {
        val c = sc.nextInt() - 1
        val d = sc.nextInt() - 1
        countCD[c].add(d)
        countCD[d].add(c)
    }

    println((0 until n).map {
        val blockCount = countCD[it].count { pos -> same(it, pos) }
        (size[find(it)] - 1) - countAB[it] - blockCount
    }.joinToString(" "))
}

Measured memory_bytes: 153744
from collections import defaultdict

# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N = int(input())
    if N == 0:
        exit()
    votes = input().split()
    remain = N
    d = dict()
    for a in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
        d[a] = 0
    for v in votes:
        d[v] += 1
        remain -= 1
        # maxを探す
        # max>other + remain -> fin
        max_key = max((v, k) for (k, v) in d.items())[1]
        if all(val+remain < d[max_key] for key, val in d.items() if key != max_key):
            print(max_key, N-remain)
            return
    print("TIE")


while True:
    solve()



Measured memory_bytes: 6300
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        }

        long min = a[0];
        long max = a[0];
        long sum = a[0];
        
        for(int i=1;i<n;i++){
            if(min>a[i]){min=a[i];}
            if(max<a[i]){max=a[i];}
            sum += a[i];
        }
        System.out.println(min + " " + max + " " + sum);
    }
}


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

using namespace std;

const int MOD = (int)1e9 + 7;
const int N = 2000010;

inline int add(int u, int v) {
    return (u += v) >= MOD ? u - MOD : u;
}
 
inline int sub(int u, int v) {
    return (u -= v) < 0 ? u + MOD : u;
}
 
inline int mul(int u, int v) {
    return (long long)u * v % MOD;
}
 
inline int power(int u, int v) {
    int res = 1;
    while (v) {
        if (v & 1) res = mul(res, u);
        u = mul(u, u);
        v >>= 1;
    }
    return res;
}
 
inline int inv(int u) {
    return power(u, MOD - 2);
}

int fac[N];

int binomial(int n, int k) {
    if (k > n || k < 0) return 0;
    return mul(fac[n], inv(mul(fac[k], fac[n - k])));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    fac[0] = 1;
    for (int i = 1; i < N; i++) fac[i] = mul(fac[i - 1], i);
    int res = 0;
    for (int a = 0; a <= x; a++) {
        if ((x - a) & 1) continue;
        int b = (x - a) / 2;
        if (b + 2 * a != y) continue;
        res = add(res, binomial(a + b, a));
    }
    cout << res << endl;
    return 0;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  vector<int> nxt(n+1, 0);
  for (int i = n-2; i >= 0; --i) {
    if (a[i] == 0 && a[i+1] == 0)
      nxt[i] = nxt[i + 1] + 1;
  }

  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int j = i + 1, cur = a[i], sum = a[i];
    while (j < n) {
      if ((cur ^ a[j]) == (sum + a[j])) {
        cur ^= a[j];
        sum += a[j];
        j += nxt[j] + 1;
      } else break;
    }     
    ans += j-i;
  }

  cout << ans << '\n';
}

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

int main(){
  int N;
  string S;
  cin >> N;
  cin >> S;

  int cnt=1;
  for(int i=0;i<N-1;i++){
    if(S[i]!=S[i+1])cnt++;
  }
  
  cout << cnt << endl;

}

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

int main(){
    string s;
    cin >> s;
    int ans=0;
    int k=0;
    for(int i=0;i<3;i++){
        if(s.at(i)=='R'){
            k++;
        }else{
            ans=max(ans,k);
            k=0;
        }
    }
    cout<<max(ans,k)<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
#define allsort(X) sort(X.begin(),X.end())

typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;





ll i,j,k;


int main(){
    ll N;
    cin>>N;
    V ans(N+1,0);
    for(ll x=1;x*x<=N;x++){
        for(ll y=1;y*y<=N;y++){
            for(ll z=1;z*z<=N;z++){
                if(x*x+y*y+z*z+x*y+y*z+z*x<=N)ans.at(x*x+y*y+z*z+x*y+y*z+z*x)++;
            }
        }
    }
    for(ll i=1;i<=N;i++)cout<<ans[i]<<endl;
    
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;

	cout << S.substr(0, (int)S.size() - 8) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();
        int k = sc.nextInt();

        int cnt = 0;
        for (int i = 1; i <= n; i += 2) {
            cnt++;
        }
        System.out.println(cnt >= k ? "YES" : "NO");
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <algorithm>

const long long int MAX_W = 100001;
const long long int MAX_N = 100;

int main(){
  // read problem
  long long int N, W, tmp_w, tmp_v;
  std::vector<long long int> w,v;
  
  scanf("%lld%lld", &N, &W);
  
  for(long long int i = 0; i < N; i++){
    scanf("%lld%lld", &tmp_w, &tmp_v);
    w.push_back(tmp_w);
    v.push_back(tmp_v);
  }
  
  // solve problem
  std::vector< std::vector<long long int> > table(N);
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j <=W; j++){
      table[i].push_back(0);
    }
  }
  
  for(long long int i = w[0]; i <= W; i++){
    table[0][i] = v[0];
  }
  
  for(long long int i = 1; i < N; i++){
    for(long long j = 1; j <= W; j++){
      table[i][j] = table[i-1][j]; // the case where i-th item is not used
      if(j >= w[i]){ // the case where i-th item is used
        table[i][j] = std::max(table[i][j], table[i-1][j-w[i]] + v[i]);
      }
    }
  }
  
  /*for(long long int j = 0; j <= W; j++){
    for(long long int i = 0; i < N; i++){
      std::cerr << table[i][j] << " ";
    }std::cerr << std::endl;
  }*/
  
  std::cerr << "Answer:" << std::endl;
  std::cout << table[N-1][W] << std::endl;
  
  return 0;
}

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

int main()
{
    int n, m; cin>>n>>m;
    vector<vector<long>> a(n, vector<long>(3));
    for(auto& v: a) for(auto& e: v) cin>>e;

    long res=LONG_MIN;
    for(int k=0; k<8; ++k) {
        vector<long> s(n);
        for(int i=0; i<n; ++i)
            for(int j=0; j<3; ++j) s[i]+=((k>>j)&1)?a[i][j]:-a[i][j];
        sort(rbegin(s), rend(s));
        res=max(res, accumulate(begin(s), begin(s)+m, 0L));
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main(){
	priority_queue<int > q1;
	int n,m;
	cin>>n>>m;
	int a=0;
	int i=0;
	for(i=0;i<n;i++){
		cin>>a;
		q1.push(a);
	}
	int b=0;
	int c=0;
	for(i=0;i<m;i++){
		b=q1.top();
		c+=b;
		q1.pop();
	}
	cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 256