akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

//0305
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n-- > 0) {
            int r = sc.nextInt() ;
            int t = sc.nextInt() ;
            boolean fr = r % 100 == 0;
            boolean ft = t % 30 == 0;
            r /= 100;
            t /= 30;
            if (fr && ft) {
                System.out.println(r + t * 5);
            }else if(fr){
                System.out.println((r+t*5)+" "+(r+t*5+5));
            }else if(ft) {
                System.out.println((r+t*5)+" "+(r+t*5+1));
            }else {
              System.out.println((r+t*5)+" "+(r+t*5+1)+" "+(r+t*5+5)+" "+(r+t*5+6));  
            }
        }

    }
}


Measured memory_bytes: 26364
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main(){
  int n, k; cin >> n >> k;
  ll h[n]; REP(i, n) cin >> h[i];

  sort(h, h+n);

  ll ans = 1e10;
  REP(i, n-k+1){
    ans = min(ans, h[i+k-1]-h[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
E = [[] for _ in range(N)]

for _ in range(M):
    A, B = map(int, input().split())
    E[A-1].append(B-1)
    E[B-1].append(A-1)

ans = [None]*N
ans[0]=-1

queue=[0]
while queue:
    queue_new = []
    for q in queue:
        for e in E[q]:
            if ans[e] is not None: continue
            ans[e]=q
            queue_new.append(e)

    queue = queue_new

print("Yes")
for a in ans[1:]:
    print(a+1)

Measured memory_bytes: 34716
sub f{$$_=my$t=pop;grep$$_?$$_+$t:f(-$t),@$_}print$c*(2*(map{map{push@{-$_},-$a[--$|]for@a=split}<>;$$_||${@$_?f(1)?b:a:c}++}-<>..-1)-$c)+($a+$b)**2+$a*$a

Measured memory_bytes: 131532
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		string s=sc.S;
		int a=0;
		for(int i = 0;i<s.Length;i++) {
			if(s[i]=='R'){a++;}
			else{a--;}
		}
		
		Console.WriteLine("{0}",a>0?"Yes":"No");
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

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

int main(){

    char s1[12],s2[12],s3[12],dif;

    scanf("%[^ ]%*c",s1);
    scanf("%[^ ]%*c",s2);
    scanf("%s",s3);

    dif='A'-'a';

    printf("%c%c%c\n",s1[0]+dif,s2[0]+dif,s3[0]+dif);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  bool ok = false;
  int cnt = 0;
  rep(i, n) {
    int d1, d2;
    cin >> d1 >> d2;
    if (d1 == d2) {
      cnt++;
    } else {
      cnt = 0;
    }
    if (cnt >= 3) ok = true;
  }

  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3616
import java.math.*;
import java.util.*;
import static java.lang.System.*;

public class Main {
	//初期フィールド・メソッド---------------------------------------------
	static Scanner sc = new Scanner(System.in);
	static int min(int... ar) {Arrays.sort(ar); return ar[0];}
	static int max(int... ar) {Arrays.sort(ar); return ar[ar.length-1];}
	//------------------------------------------------------------


	//フィールド追加場所-----------------------------------------------
	//------------------------------------------------------------


	//メソッド追加場所------------------------------------------------
	//------------------------------------------------------------


	//mainメソッド---------------------------------------------------
	public static void main(String[] args) {
		while(sc.hasNext()) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if (n==0 && m==0) break;
			
			LinkedList<Integer> list = new LinkedList<>();
			for (int i=1; i<=n-1; i++) list.add(i);
			list.addFirst(n);
			
			int j = 0;
			while (list.size() != 1) {
				for (int i=0; i<(j==0?m:m-1); i++) {
					list.addLast(list.removeFirst());
				}
				list.removeFirst();
				j++;
			}
			
			out.println(list.getFirst());
		}
	}
	//------------------------------------------------------------
}


Measured memory_bytes: 41472
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int gcd(int a, int b){
	while(b){
		a %= b;
		swap(a, b);
	}
	return a;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	cout << lcm(360, n) / n << '\n';
	return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
int main()
{
	int num;
	ll st;
	scanf("%d%lld", &num, &st);
	vector<pii>v1, v2;
	for (int i = 0; i < num; i++)
	{
		ll za, zb;
		scanf("%lld%lld", &za, &zb);
		if (za < st)v1.push_back(make_pair(za, zb));
		else v2.push_back(make_pair(za, zb));
	}
	reverse(v1.begin(), v1.end());
	ll ans = 0;
	int las = 0;
	for (;;)
	{
		if (v1.empty())
		{
			ans += v2[v2.size() - 1].first - st;
			break;
		}
		if (v2.empty())
		{
			ans += st - v1[v1.size() - 1].first;
			break;
		}
		if (v1[v1.size() - 1].second >= v2[v2.size() - 1].second)
		{
			if (las != 1)ans += v2[v2.size() - 1].first - v1[v1.size() - 1].first;
			las = 1;
			v1[v1.size() - 1].second += v2[v2.size() - 1].second, v2.pop_back();
		}
		else
		{
			if (las != -1)ans += v2[v2.size() - 1].first - v1[v1.size() - 1].first;
			las = -1;
			v2[v2.size() - 1].second += v1[v1.size() - 1].second, v1.pop_back();
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 2804
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

lint itm[3000][3000];
lint dp[3000][3000][4];

int main(void){
    int H,W,K;
    cin >> H >> W >> K;
    rep(i,K){
        int r,c,v;
        cin >> r >> c >> v;
        r--,c--;
        itm[r][c]=v;
    }
    rep(i,H) rep(j,W){
        if(itm[i][j]) reprev(k,3) dp[i][j][k+1]=max(dp[i][j][k]+itm[i][j],dp[i][j][k+1]);
        if(i!=H-1) rep(k,4) dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
        if(j!=W-1) rep(k,4) dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
    }
    lint ans=0;
    rep(i,4) ans=max(ans,dp[H-1][W-1][i]);
    cout << ans << endl;
}

Measured memory_bytes: 355148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    

  int main(){
      lint k,n;
      cin>>k>>n;
      lint a[n];
      rep(i,n)cin>>a[i];
     vector<lint> x;
     rep(i,n-1){
         x.push_back(a[i+1]-a[i]);
     }
     x.push_back(k-a[n-1]+a[0]);
     sort(all(x),greater<lint>());
     cout<<k-x[0];


  }
  
  
     
  

Measured memory_bytes: 4084
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
string multi9(string a) {
	string res;
	int r = 0;
	int len = a.length();
	rep(i, len) {
		int t = a[i] - '0'; t *= 9; t += r;
		res.push_back('0' + t%10);
		r = t / 10;
	}
	if (r)res.push_back('0' + r);
	return res;
}
int sum(string a) {
	int res = 0;
	int len = a.length();
	rep(i, len) {
		res += a[i] - '0';
	}
	return res;
}
string add(string a, int b) {
	string res;
	string t = to_string(b); reverse(t.begin(), t.end());
	int r = 0;
	int l1 = a.length(); int l2 = t.length();
	rep(i, max(l1, l2)) {
		int nex = r;
		if (i < l1)nex += a[i] - '0';
		if (i < l2)nex += t[i] - '0';
		res.push_back('0'+nex % 10);
		r = nex / 10;
	}
	if (r)res.push_back('0' + r);
	return res;
}
string s;
bool can(int x) {
	int k = sum(add(s, 9 * x));
	if (k <= 9 * x)return true;
	else return false;
}
int main() {
	cin >> s; reverse(s.begin(), s.end());
	s = multi9(s);
	int le = 0; int ri = s.length()+1;
	while (ri - le > 1) {
		int mid = (ri + le) / 2;
		if (can(mid))ri = mid;
		else le = mid;
	}
	cout << ri << endl;
	return 0;
}

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

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i > (b); i--)

using namespace std;

int N;
int d[100005];

int main(void) {
    scanf("%d", &N);
    REP(i, 1, N + 1) scanf("%d", &d[i]);

    sort(d + 1, d + 1 + N);

    int ans = d[ N / 2 + 1 ] - d[N / 2];
    
    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 640
import sys
import itertools
import numpy as np
import networkx as nx

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
S = np.frombuffer(read(), 'S1').reshape(N, -1)[:, :M].astype('U1')

G = nx.DiGraph()
G.add_nodes_from(['S', 'T'])
for i, j in itertools.product(range(N), range(M)):
    if S[i, j] == '#':
        continue
    if (i + j) % 2 == 0:
        G.add_edge('S', (i, j), capacity=1)
    else:
        G.add_edge((i, j), 'T', capacity=1)
    if (i + j) % 2 == 0:
        for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            i1, j1 = i + dx, j + dy
            if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != '#':
                G.add_edge((i, j), (i1, j1), capacity=1)

flow_value, flow = nx.maximum_flow(G, 'S', 'T')
for i, j in itertools.product(range(N), range(M)):
    if (i, j) in flow:
        for v, f in flow[(i, j)].items():
            if v == 'T' or f == 0:
                continue
            i1, j1 = v
            if i1 == i + 1:
                a, b = 'v', '^'
            elif i1 == i - 1:
                a, b = '^', 'v'
            elif j1 == j + 1:
                a, b = '>', '<'
            else:
                a, b = '<', '>'
            S[i, j], S[i1, j1] = a, b

print(flow_value)
for row in S:
    print(''.join(row))

Measured memory_bytes: 117656
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

long long N, K;
long long Kcn, Ka, Kb;
long long res = 0;

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

  for(long long i = K; i <= N+1; i++){
    Ka = (2 * N - i + 1 ) * i / 2;
    Kb = (i-1) * i / 2;
    Kcn = Ka - Kb + 1;
    res += Kcn;
    res %= MOD;
  }

  cout << res << endl;
  return 0;
    
}
    

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n, m;
set<int> g[MAXN], gr[MAXN];
bool used[MAXN];
int ans[MAXN], D[MAXN];

bool read() {
    if (!(cin >> n >> m))
        return false;

    forn (i, n - 1 + m) {
        int u, v;
        cin >> u >> v;
        g[u - 1].insert(v - 1);
        gr[v - 1].insert(u - 1);
    }

    return true;
}

void solve() {
    queue<int> Q;
    fill(D, D + n, INF);

    forn (i, n) {
        if (g[i].empty()) {
            used[i] = true;
            Q.push(i);
            D[i] = 0;
        }
    }

    fill(ans, ans + n, 0);

    while (!Q.empty()) {
        int v = Q.front();
        Q.pop();

        for (auto i : gr[v]) {
            g[i].erase(v);

            if (g[i].empty()) {
                if (!used[i]) {
                    used[i] = true;
                    D[i] = D[v] + 1;
                    Q.push(i);
                }
            }
        }
    }

    forn (i, n)
        for (auto p : gr[i])
            if (ans[i] == 0 || D[p] < D[ans[i] - 1])
                ans[i] = p + 1;

    forn (i, n)
        cout << ans[i] << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 111488
#include <stdio.h>
#include <string.h>

char buffer[3276800];

int main(void) {
	char* pos;
	int count;
	while(1) {
		fgets(buffer,sizeof(buffer),stdin);
		pos=strchr(buffer,'\n');
		if(pos==NULL)pos=&buffer[strlen(buffer)];
		pos[0]=' ';
		pos[1]=0;
		if(strcmp(buffer,"END OF INPUT ")==0)break;
		for(pos=buffer,count=0;*pos!=0;pos++) {
			if(*pos==' ') {
				printf("%d",count);
				count=0;
			} else {
				count++;
			}
		}
		putchar('\n');
	}
	return 0;
}

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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 100000 + 10;

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

    int n;
    int64 s;

    cin >> n >> s;

    vector<int64> pos(n);
    vector<int64> pop(n);

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

    int p = 0;
    while (p < n && pos[p] < s) p++; // pivot

    int a = 0, b = n - 1;

    int64 LEFT = 0;
    int64 RIGHT = 0;

    vector<int> path;

    while (a < p && b >= p){
        if (pop[a] + LEFT >= pop[b] + RIGHT){
            LEFT = RIGHT + LEFT + pop[b];
            RIGHT = 0;
            path.push_back(+1);
            b--;
        }
        else{
            RIGHT = RIGHT + LEFT + pop[a];
            LEFT = 0;
            path.push_back(-1);
            a++;
        }
    }

    while (a < p) path.push_back(-1), a++;
    while (b >= p) path.push_back(+1), b--;

    int64 answer = 0;

    reverse(path.begin(), path.end());

    for (auto u : path){
        if (u == -1){
            answer += abs(s - pos[--a]);
            s = pos[a];
        }
        else{
            answer += abs(s - pos[++b]);
            s = pos[b];
        }
    }

    assert(a == 0 && b == n - 1);

    cout << answer << endl;

    return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    int maxi=0,mini=1e9+7,tmp=1e9+7;
    rep(i,n)maxi=max(maxi,a[i]);
    rep(i,n)if(a[i]==maxi)a[i]=0;
    if(maxi%2==0){
        rep(i,n)if(abs(a[i]-maxi/2)<tmp)mini=a[i],tmp=abs(a[i]-maxi/2);
    }
    else {
        rep(i,n){
            if(a[i]<=maxi/2 && abs(a[i]-maxi/2)<tmp)mini=a[i],tmp=abs(a[i]-maxi/2);
            else if(a[i]>maxi/2 && abs(a[i]-maxi/2-1)<tmp)mini=a[i],tmp=abs(a[i]-maxi/2-1);
        }
    }
    cout<<maxi<<' '<<mini<<endl;
    return 0;
}


Measured memory_bytes: 3708
import java.util.*;
import java.awt.geom.*;
public class Main {

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int x = sc.nextInt();
			int h = sc.nextInt();
			if((x|h) == 0) break;
			double areaxx = x * x;
			double b = (double)x / 2; 
			double c = Math.sqrt(b * b + h * h);
			double tri = x * c / 2 * 4;
			double res = areaxx + tri;
			System.out.printf("%.6f\n",res);
		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

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

	vector<int> ans(n, 0);


	for (int i = 1; i < n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			int dist = min(j - i, abs(x - i) + 1 + abs(y - j));
			//cout << i << " " << j << "->" << dist << endl;
			ans[dist]++;
		}
	}

	for (int i = 1; i < n; ++i) {
		cout << ans[i] <<  " ";
	}





	return 0;
}

Measured memory_bytes: 256
import numpy as np
import sys

X = int(input())
if X == 2 or X == 3:
    print(X)
    sys.exit()

while 1:
    for i in range(2, int(np.sqrt(X) + 1) ):
        if X % i == 0 :
            break

        if i+1 == int(np.sqrt(X) + 1 ):
            print(X)
            sys.exit()
    
    X += 1


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

using namespace std;

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

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

  int mi = a[0], ma = a[0];

  for(int i = 0; i < N; i++) {
    mi = min(mi, a[i]);
    ma = max(ma, a[i]);
  }

  if(ma - mi > 1) {
    cout << "No" << endl;
    return 0;
  }

  if(ma == mi) {
    int x = ma;
    if(x == N - 1) {
      cout << "Yes" << endl;
      return 0;
    }

    if(N >= x * 2) {
      cout << "Yes" << endl;
      return 0;
    }

    cout << "No" << endl;
    return 0;

  }

  int x = ma;

  int b = 0;

  for(int i: a) {
    if(i == ma) {
      b += 1;
    }
  }

  if((N - b) + 1 <= x && x <= (N - b) + b / 2){
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string s;

int main(void){
    
    cin >> s;
    bool a = false, b = false, c = false;
    for(int i = 0; i < s.size(); ++i){
        if(s[i] == 'a') a = true;
        if(s[i] == 'b') b = true;
        if(s[i] == 'c') c = true;
    }
    printf("%s\n", (a && b && c) ? "Yes" : "No");
    
    return 0;
}

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

long long dp[4][100111];

int main()
{
	int n;
	
	cin >> n;
	
	for(int i = 1; i <= n; i++)
	{
		cin >> dp[1][i] >> dp[2][i] >> dp[3][i];
	}
	
	for(int i = 1; i <= n; i++)
	{
		dp[1][i] += max(dp[2][i-1], dp[3][i-1]);
		dp[2][i] += max(dp[1][i-1], dp[3][i-1]);
		dp[3][i] += max(dp[1][i-1], dp[2][i-1]);
	}
	
	cout << max(dp[1][n], max(dp[2][n], dp[3][n]));
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
 int A,B,C;
 scanf("%d%d%d",&A,&B,&C);
 if(C==1)printf("Open\n");
 else if(A==1&&B==1)printf("Open\n");
 else printf("Close\n");
 return 0;
}

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

int main(){
    int flag=1;
    int n;
    int summ=0;
    int m,MIN=1000000000;
    int ans=0;

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

    for (int i = 1; i < n; i++){
        m=0;
        for (int j = i; j < n; j++){
            m+=w[j];
        }

        MIN=min(MIN,abs((m)-(summ-m)));
    }
    
    
    
    cout << MIN <<endl;
    //cout <<fixed<<setprecision(16)<< ans <<endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
S = input()
A = [0]*4
for i in range(4):
    A[i] = int(S[i])
zero = [0,1]

import itertools
for i in itertools.product(zero,repeat=3):
    tmp = A[0]
    for j in range(3):
        if i[j] == 0:
            tmp += A[j+1]
        else:
            tmp -= A[j+1]
    if tmp == 7:
        break
ans = S[0]
op = i
for i in range(3):
    if op[i] == 0:
        ans += "+"
    else:
        ans += "-"
    ans += S[i+1]
ans += "=7"
print(ans)

Measured memory_bytes: 38384
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d,z;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++){
        sum+=s[i]%48;
    }
    if(sum%9==0){
        cout<<"Yes"<<endl;

    }
    else cout<<"No"<<endl;
    return EXIT_SUCCESS;
}



Measured memory_bytes: 3704
#include <stdio.h>
#include <stdlib.h>
#define P 1000000007
int n, m, i, a[100010];

int main(void)
{
	long long int dp[100010];
	scanf("%d %d", &n, &m);
	for(i=0; i<n+1; i++){ a[i]=1; }
	for(i=0; i<m; i++){
		int f;
		scanf("%d", &f);
		a[f]=0;
	}
	
	dp[0]=1;
	dp[1]=1*a[1];
	for(i=2; i<=n; i++){
			dp[i]=((dp[i-2]+dp[i-1])*a[i])%P;
	}
	printf("%d", dp[n]%P);
	
	return 0;
}

Measured memory_bytes: 1280
a = int(input())
b = str(a)
d = [i for i in b]
num_kei = 0
for j in d:
    num_kei += int(j)

def hantei(kazu,kazu_kei):
    if kazu % kazu_kei == 0:
        print("Yes")
    elif kazu % kazu_kei != 0:
        print("No")

hantei(a,num_kei)

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

using namespace std;

int main() {
    string S; cin >> S;
    if(S[0] != S[1]) {
        if(S[1] != S[2]) {
            if(S[0] != S[2]) {
                cout << "Yes\n";
                return 0;
            }
        }
    }    
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
typedef long long ll;
ll min(ll x,ll y) {return x>y?y:x;}
int main()
{
	int n,a,b,x,y;
	ll ans=0;
	scanf("%d%d%d",&n,&a,&b);
	scanf("%d",&x);n--;
	while(n--)
	{
		scanf("%d",&y);
		ans+=min((ll)(y-x)*a,b);
		x=y;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
import sys
S = input()
T = input()
for i in range(0,len(S)):
    if S[(len(S)-i):]+S[0:(len(S)-i)] == T:
        print("Yes")
        sys.exit()
if S == T:
    print("Yes")
    sys.exit()
else:
    print("No")
    sys.exit()

Measured memory_bytes: 3060
a,b = map(int,input().split())

a_str = ""
b_str = ""
for i in range(b):
    a_str = a_str + str(a)
for i in range(a):
    b_str = b_str + str(b)


if a_str < b_str:
    print(a_str)
else:
    print(b_str)



Measured memory_bytes: 2940
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        if (calc2()) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }

    bool calc2()
    {

        cin = new Scanner();
        int N = cin.nextInt();
        int[] a = cin.ArrayInt(N);
        Array.Sort(a);
        int min = a[0];
        int max = a[N - 1];

        if (max - min >= 2) return false;

        if(min == max)
        {
            if (max == N - 1) return true; //全員違う
            else min--;  //違う場合は全員2以上
        }

        int mincnt = 0;
        int maxcnt = 0;
        for (int i = 0; i < N; i++)
        {
            if (a[i] == min) mincnt++;
            else maxcnt++;
        }

        if (maxcnt == 1) return false; //2以上のグループが1しかないのは矛盾

        int minPattern = mincnt + 1; //mincnt, maxcntの個数から、グループ数の理論最小値を求める。
        int maxPattern = mincnt + maxcnt / 2;   //上の理論最大値

        if (max >= minPattern && max <= maxPattern) return true;
        else return false;
    }

}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



Measured memory_bytes: 18912
#include<stdio.h>
#include<algorithm>
 
FILE *in, *out;
 
using namespace std;
 
int v[10][10], n;
 
int main ()
{
 
    //fscanf(stdin, "%d", &n);
    n = 10;
    long long toto = 0;
    int l, c;
    scanf("%d %d", &l, &c);
 
    for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                    fscanf(stdin, "%d", &v[i][j]);
                    if (i == j) {
                            v[i][j] = 0x3f3f3f3f;
                    }
            }
    }
 
    for(int k = 0; k < n; k++) {
            for(int i = 0; i < n; i++) {
                    for(int j = 0; j < n; j++) {
                            v[i][j] = min(v[i][j], (v[i][k] + v[k][j]));
                    }
            }
    }
 
    for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                    if (v[i][j] > 0x3f3f3f3f || i == j) {
                            v[i][j] = 0;
                    }
                    //fprintf(stdout, "%d ", v[i][j]);
            }
            //fprintf(stdout, "\n");
    }

    for(int i = 0; i < l; i++) {
        for(int j = 0; j < c; j++) {
            int x;
            scanf("%d", &x);
            if(x != -1) {
                toto += v[x][1];
            }
        }
    }

    printf("%lld", toto);

    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

int testcase_ends() {
  size_t N;
  scanf("%zu", &N);
  if (N == 0) return 1;

  std::vector<std::vector<int>> a(21, std::vector<int>(21));
  for (size_t i = 0; i < N; ++i) {
    size_t x, y;
    scanf("%zu %zu", &x, &y);
    a[y][x] = 1;
  }

  size_t M;
  scanf("%zu", &M);
  size_t x = 10;
  size_t y = 10;
  a[y][x] = 0;
  for (size_t i = 0; i < M; ++i) {
    char d;
    size_t w;
    scanf(" %c %zu", &d, &w);
    if (d == 'N') {
      for (size_t j = 0; j < w; ++j) {
        a[++y][x] = 0;
      }
    } else if (d == 'E') {
      for (size_t j = 0; j < w; ++j) {
        a[y][++x] = 0;
      }
    } else if (d == 'S') {
      for (size_t j = 0; j < w; ++j) {
        a[--y][x] = 0;
      }
    } else if (d == 'W') {
      for (size_t j = 0; j < w; ++j) {
        a[y][--x] = 0;
      }
    }
  }

  int res = 0;
  for (auto const& ai: a) res += std::accumulate(ai.begin(), ai.end(), 0);
  puts(!res? "Yes": "No");
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



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

#define SUIT 4
#define NUM 13

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

    int cards[SUIT][NUM] = {};
    int count, num;
    string suit;

    cin >> count;
    for (int i = 0; i < count; i++) {
        cin >> suit >> num;
        num--;
        if (suit == "S") {
            cards[0][num] = 1;
        } else if (suit == "H") {
            cards[1][num] = 1;
        } else if (suit == "C") {
            cards[2][num] = 1;
        } else if (suit == "D") {
            cards[3][num] = 1;
        }
    }

    for (int i = 0; i < SUIT; i++) {
        for (int j = 0; j < NUM; j++) {
            if (cards[i][j] == 0) {
                if (i == 0)
                    cout << "S ";
                else if (i == 1)
                    cout << "H ";
                else if (i == 2)
                    cout << "C ";
                else if (i == 3)
                    cout << "D ";
                cout << j + 1 << endl;
            }
        }
    }
}


Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
using namespace std;
typedef long long LL;

int main() {
    int n,l,ans=0,ab=100000;
	cin >>n>>l;
	for (int i = 0; i < n; i++) {
		ans+=i+l;
		if (min(abs(ab), abs(i + l)) == abs(i + l)) {
			ab=i+l;
		}
		
	}
	cout <<ans-ab<<endl;
    return 0;
}

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

long long calc(long long n)
{
    if(n%2 == 0)
    {
        return n^((n/2)%2);
    }
    else
    {
        return ((n+1)/2)%2;
    }   
}

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

    cout << (calc(b)^calc(a-1)) << endl;
}

Measured memory_bytes: 256
import sys
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
MOD = 1000000007

n, k = map(int, input().split())
d = []
A = []
for i in range(k):
    x = int(input())
    d.append(x)
    y = list(map(int, input().split()))
    A.append(y)


s = [0 for _ in range(n)]

for i in range(k):
    for j in range(d[i]):
        s[A[i][j]-1] += 1

ans = 0
for i in range(n):
    if s[i] == 0:
        ans += 1

print(ans)


Measured memory_bytes: 73068
# include "iostream"
# include "cstdio"

using namespace std;

bool check(int now){
	int tot=0; 
	for(int i=1;i<=now;i++){
		if(now%i==0) tot++; 
	}
	return tot==8; 
} 

int main(){
	register int i; 
	int n,ans;
	scanf("%d",&n); 
	for(i=1;i<=n;i+=2){
		ans+=check(i); 
	}
	printf("%d",ans); 
	return 0;
} 

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc115/tasks/abc115_d

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 50;

int N;
ll X;

ll f(int n, ll x) {
  ll m = (1LL << n + 2) - 3;
  ll m2 = (1LL << n + 1) - 3;
  ll p = (1LL << n + 1) - 1;
  ll p2 = (1LL << n)  - 1;

  if (x == 1) {
    return n == 0 ? 1 : 0;
  } else if (x < m2 + 2) {
    return f(n - 1, x - 1);
  } else if (x == m2 + 2) {
    return p2 + 1;
  } else if (x < m) {
    return p2 + 1 + f(n - 1, x - m2 - 2);
  } else {
    return p;
  }
}

void solve() {
  ll ans = f(N, X);
  printf("%lld\n", ans);
}

void input() {
  scanf("%d%lld", &N, &X);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // B - xxxxx

        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        byte[] bs = s.getBytes();
        HashSet<Byte> setB = new HashSet<>();

        for (byte b : bs) {
            setB.add(b);
        }

        byte sb = "a".getBytes()[0];
        String ans = "None";
        for (int i = 0; i < 26; i++) {
            if (!setB.contains(sb)) {
                //                System.out.println(sb);
                //                System.out.println((char)sb);
                ans = String.valueOf((char) sb);
                break;
            }
            sb++;
        }
        System.out.println(ans);

    }

}

Measured memory_bytes: 27556
import sys

import time


def main():
        n = sys.stdin.readline()

        astr = sys.stdin.readline()
        bstr = sys.stdin.readline()
        cstr = sys.stdin.readline()

        a = list(map(int, astr.strip().split(' ')))
        b = list(map(int, bstr.strip().split(' ')))
        c = list(map(int, cstr.strip().split(' ')))

        a.sort()
        b.sort()
        c.sort()

        cnt = 0

        bc = []
        sum = 0
        timesum = 0
        for bi in reversed(b):
                sum += len(c) - binary(bi,c)
                bc.append(sum)
        bc.reverse()

        cnt = 0
        for ai in a:
                bi = binary(ai, b)
                if(bi < len(bc)):
                    cnt += bc[bi]

        print(cnt)


def binary(x, li):
    upper = len(li)
    lower = -1
    index = int((upper + lower) / 2)

    while upper - lower > 1:
        if (x < li[index]):
            upper = index
        else:
            lower = index
        index = int((upper + lower)/2)
    
    return upper


main()

Measured memory_bytes: 31776
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int a[101010];

int main(){
    
    // 1. 入力情報.
    char c[101010];
    scanf("%s", c);
    int l = strlen(c);
    
    // 2. AtCoDeerくんが, すべてグーを出したと仮定.
    rep(i, l) if(c[i] == 'p') a[i] = -1;
    
    // 3. 後半すべてパーを出した.
    repr(i, l - 1, (l + 1) / 2) a[i] = (c[i] == 'p') ? 0 : 1;
    
    // 4. 集計.
    int ans = 0;
    rep(i, l) ans += a[i];
    
    // 5. 出力.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 4284
#include<stdio.h>
int main(void) {

	long long n, r;
	long long ans;

	scanf("%lld %lld", &n, &r);

	if (n < 10) {
		ans = 100 * (10 - n) + r;
		printf("%lld", ans);
	}
	else if (n >= 10) {
		ans = r;
		printf("%lld", ans);
	}

	return 0;
}

Measured memory_bytes: 128
//
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int mx[4] = { -1, 0, 1,  0};
int my[4] = {  0, 1, 0, -1};

int main()
{
    int H, W, Ch, Cw, Dh, Dw;
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    --Ch, --Cw, --Dh, --Dw;
    vector<vector<char>> S(H, vector<char>(W));
    REP(i, H) REP(j, W) cin >> S[i][j];
    vector<vector<int>> visited(H, vector<int>(W, -1)); // -1 : 未訪問 0 :訪問済みかつスタートからワープして到達する回数の最小値
    queue<pair<int, int>> q;
    q.push(pair<int, int>(Ch, Cw));
    visited[Ch][Cw] = 0;
    int count = 0;
    while (true)
    {
        vector<pair<int, int>> grids;
        // ワープなしでたどり着けるマスを調べる
        while (!q.empty())
        {
            pair<int, int> cur = q.front();
            q.pop();
            int curx = cur.first;
            int cury = cur.second;
            grids.push_back(cur);
            for (int i = 0; i < 4; ++i)
            {
                int nx = curx + mx[i];
                int ny = cury + my[i];
                if (nx >= 0 && nx < H && ny >= 0 && ny < W && S[nx][ny] == '.' && visited[nx][ny] == -1)
                {
                    visited[nx][ny] = count;
                    // ゴールにたどり着いたら走査を打ち切る
                    if (nx == Dh && ny == Dw)
                    {
                        cout << visited[Dh][Dw] << endl;
                        return 0;
                    }
                    q.push(pair<int, int>(nx, ny));
                }
            }
        }

        // ワープなしでたどり着くことのできるマスから、
        // ワープしなければたどり着けないマスを列挙し、queueに格納する
        ++count;
        for (const auto& cur : grids)
        {
            int curx = cur.first;
            int cury = cur.second;
            for (int x = curx - 2; x <= curx + 2; ++x)
            {
                for (int y = cury - 2; y <= cury + 2; ++y)
                {
                    if (x >= 0 && x < H && y >= 0 && y < W && S[x][y] == '.' && visited[x][y] == -1)
                    {
                        visited[x][y] = count;
                        if (x == Dh && y == Dw)
                        {
                            cout << visited[Dh][Dw] << endl;
                            return 0;
                        }
                        q.push(pair<int, int>(x, y));
                    }
                }
            }
        }
        // ワープしてもゴールにたどり着けない場合
        if (q.empty())
        {
            cout << -1 << endl;
            return 0;
        }
        grids.clear();
        // 上に戻り、ワープしてたどり着けるマスを起点として再び幅優先探索を行う
    }
    return 0;
}


Measured memory_bytes: 8620
import sys

def div(x, y):
    if x % y == 0:
        print y
    else:
        div(y, x%y)


line = sys.stdin.readline()
x, y = line.split(" ")

x = int(x)
y = int(y)

if x < y:
    x, y = y, x

if x == y:
    print x

else:
    div(x, y)

Measured memory_bytes: 6452
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  ll sum = 0;
  rep(i,n) sum += a[i];
  ll mi = 1e16;
  ll x = 0;
  ll y;
  rep(i,n-1) {
    x += a[i];
    y = sum - x;
    mi = min(mi, abs(x-y));
  }
  cout << mi << endl;

  return 0;
}


Measured memory_bytes: 1024
def shichigo(s):
    if '3' not in s:
        return False
    if '5' not in s:
        return False
    if '7' not in s:
        return False
    x = s.replace('3','').replace('5','').replace('7','')
    if x=='':
        return True
    return False

n = input()

l = [[] for i in range(len(n))]
l[0] = ['3','5','7']
for i in range(1,len(l)):
    for j in range(len(l[i-1])):
        l[i].append('3'+l[i-1][j])
        l[i].append('5'+l[i-1][j])
        l[i].append('7'+l[i-1][j])

ans = 0
for i in range(len(l)):
    for j in range(len(l[i])):
        if int(n) >= int(l[i][j]):
            if shichigo(l[i][j]):
                ans += 1

print(ans)


Measured memory_bytes: 5228
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 3e5 + 5;

string s[] = {"Sunny", "Cloudy", "Rainy"};

int main(){
    string k;
    cin >> k;
    for(int i = 0 ; i < 3 ; ++i)
        if(s[i] == k)
            cout << (s[(i + 1) % 3]) << endl;
}


Measured memory_bytes: 256
k = list([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])
i = int(input())
print(k[i-1])

Measured memory_bytes: 3060
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder str=new StringBuilder(br.readLine());
        int l=Integer.parseInt(br.readLine());
		for(int i=0;i<l;i++){
	        String[] op=br.readLine().split(" ");
			int op1=Integer.parseInt(op[1]);
			int op2=Integer.parseInt(op[2]);
			if(op[0].equals("print")){
				System.out.println(str.substring(op1,op2+1));
			}else if(op[0].equals("reverse")){
				str=str.replace(op1,op2+1,new StringBuilder(str.substring(op1,op2+1)).reverse().toString());
			}else if(op[0].equals("replace")){
				str=str.replace(op1,op2+1,op[3]);
			}
		}
	}
}

Measured memory_bytes: 21188
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

struct UF{
    const int node_num;
    vector<int> parent;
    vector<int> size;

    UF(int N) : node_num(N), parent(N), size(N, 1) {
        for(int i = 0; i < N; ++i) parent[i] = i;
    }

    //xの根を得る
    int root(int x){
        if(parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

    //xが属する木とyが属する木を一つに合わせる
    void unite(int x, int y){
        int root_x = root(x);
        int root_y = root(y);
        if(root_x == root_y) return;
        parent[root_y] = root_x;
        size[root_x] += size[root_y];
    }

    //xとyが属する木が同じならtrueを返す
    bool same(int x, int y){
        int root_x = root(x);
        int root_y = root(y);
        return root_x == root_y;
    }

    //xと同じ木に属する要素の数を返す
    int same_size(int x){
        int root_x = root(x);
        return size[root_x];
    }
};

int main(){
    Stream io;
    
    int N, M;
    io.read(N, M);
    vector<int> P(M);
    vector<int> Y(M);
    for(int i = 0; i < M; i++){
        io.read(P[i], Y[i]);
    }
    vector<vector<int>> v(N);
    for(int i = 0; i < M; i++){
        v[P[i] - 1].push_back(Y[i]);
    }
    for(int i = 0; i < N; i++){
        sort(v[i].begin(), v[i].end());
    }
    for(int i = 0; i < M; i++){
        auto p = lower_bound(v[P[i] - 1].begin(), v[P[i] - 1].end(), Y[i]);
        int x = p - v[P[i] - 1].begin() + 1;
        cout << setw(6) << setfill('0') << P[i];
        cout << setw(6) << setfill('0') << x << '\n';
    }
    return 0;
}

Measured memory_bytes: 7808
#include <iostream>

using namespace std;

int main()
{
    int c[3][3] = {};
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> c[i][j];
        }
    }

    for (int i = 0; i <= 100; i++)
    {
        for (int j = 0; j <= 100; j++)
        {
            for (int k = 0; k <= 100; k++)
            {
                int a[3] = {i, j, k};
                int b[3] = {};
                b[0] = c[0][0] - a[0];
                b[1] = c[0][1] - a[0];
                b[2] = c[0][2] - a[0];

                bool ok = true;
                for (int ii = 0; ii < 3; ii++)
                {
                    for (int jj = 0; jj < 3; jj++)
                    {
                        if (c[ii][jj] != a[ii] + b[jj])
                        {
                            ok = false;
                        }
                    }
                }
                if (ok)
                {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256