akhauriyash/Code-Regression huggingface dataset:
import sys

N, M = map(int, input().split())

S = [-1 for i in range(N)]

flag = True
for _ in range(M):
    s, c = map(int, input().split())
    if S[s - 1] == -1 or S[s - 1] == c:
        S[s - 1] = c
    else:
        flag = False
        break

if S[0] == 0 and N > 1:
    print(-1)
    sys.exit()
elif S[0] == 0 and N == 1:
    print(0)
    sys.exit()

if S[0] == -1 and N > 1:
    S[0] = 1
elif S[0] == -1 and N == 1:
    print(0)
    sys.exit()

for i in range(1, len(S)):
    if S[i] == -1:
        S[i] = 0

if flag:
    for s in S:
        print(s, end="")
else:
    print(-1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	rep(i,1,10){
		rep(j,1,10){
			cout<<i<<'x'<<j<<'='<<i*j<<endl;
		}
	}
	
}

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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int Maxn = 2e5 + 100;

int N, A[Maxn];
int pw2[40];
#include <bits/extc++.h>
using namespace __gnu_pbds;
gp_hash_table <int, int> Map;

inline void Solve ()
{
	pw2[0] = 1;
	for (int i = 1; i <= 31; ++i) pw2[i] = pw2[i - 1] * 2;
	sort (A + 1, A + N + 1, greater <int>());
	int ans = 0;
	for (int i = 1; i <= N; ++i)
	{
		if (!Map[A[i]]) continue;
		for (int j = 1; j <= 31; ++j)
		{
			if (pw2[j] > 2 * A[i]) break;
			if (pw2[j] <= A[i]) continue;
			if (Map[pw2[j] - A[i]])
			{
				if (pw2[j] == 2 * A[i] && Map[pw2[j] - A[i]] == 1) break;
				++ans;
				--Map[A[i]];
				--Map[pw2[j] - A[i]];
				break;
			}
		}
	}
	cout << ans << endl;
}

inline void Input ()
{
	N = read<int>();
	for (int i = 1; i <= N; ++i) ++Map[A[i] = read<int>()];
}

int main()
{

#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}


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


int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = 0;
  if(a+b>2*c){
    ans += 2*c*min(x,y);
    if(x-y>=0){
      if(a>2*c) ans += (x-y)*2*c;
      else      ans += (x-y)*a;
    }
    else{
      if(b>2*c) ans += (y-x)*2*c;
      else      ans += (y-x)*b;
    }
  }
  else ans += x*a+y*b;
  cout << ans << endl;

  return 0;
}


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

typedef long long ll;

int main() {
	int n; cin >> n;
	ll a = 0;
	vector<int> A(n);
	map<int, ll> C;
	for(int i = 0; i < n; i++) {
		cin >> A[i];
		C[A[i]]++;
	}
	for(auto x : C)
		a += x.second * (x.second - 1) / 2;
	for(int i = 0; i < n; i++) cout << a - C[A[i]] + 1 << "\n";
}


Measured memory_bytes: 10240
package main

import "fmt"

func main() {
	var H, W int
	fmt.Scanf("%d %d", &H, &W)
	field := make([][]byte, H)
	for i := 0; i < H; i++ {
		var s string
		fmt.Scanf("%s", &s)
		field[i] = []byte(s)
	}
	d := make([][]int, H*W)
	for i := 0; i < H*W; i++ {
		d[i] = make([]int, H*W)
		for j := 0; j < H*W; j++ {
			d[i][j] = 1000
		}
	}
	for h := 0; h < H; h++ {
		for w := 0; w < W; w++ {
			src := w + W*h
			if field[h][w] == '#' {
				continue
			}
			d[src][src] = 0
			if h-1 >= 0 && field[h-1][w] == '.' {
				dst := w + W*(h-1)
				d[src][dst] = 1
			}
			if h+1 < H && field[h+1][w] == '.' {
				dst := w + W*(h+1)
				d[src][dst] = 1
			}
			if w-1 >= 0 && field[h][w-1] == '.' {
				dst := w - 1 + W*h
				d[src][dst] = 1
			}
			if w+1 < W && field[h][w+1] == '.' {
				dst := w + 1 + W*h
				d[src][dst] = 1
			}
		}
	}
	for k := 0; k < W*H; k++ {
		for i := 0; i < W*H; i++ {
			for j := 0; j < W*H; j++ {
				if d[i][j] > d[i][k]+d[k][j] {
					d[i][j] = d[i][k] + d[k][j]
				}
			}
		}
	}
	max := -1
	for i := 0; i < W*H; i++ {
		for j := 0; j < i; j++ {
			if d[i][j] > max {
				if d[i][j] != 1000 {
					max = d[i][j]
				}
			}
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> b;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    b.resize(n);
    for(auto &i : b){
        cin >> i;
        i--;
    }
    vector <int> p;
    for(int i = 0 ; i < n ; i++){
        p.push_back(i);
    }
    sort(p.begin(), p.end(), [&](int l, int r){
        return b[l] < b[r];
    });
    int pt = 0;
    vector <int> a(n * n, -1);
    for(int i = 0 ; i < n ; i++){
        a[b[i]] = i;
    }
    vector <int> found;
    vector <int> cnt(n);
    for(int i = 0 ; i < n * n ; i++){
        if(a[i] != -1){
            if(cnt[a[i]] != a[i]) finish("No");
            found.push_back(a[i]);
            cnt[a[i]]++;
            continue;
        }
        while(pt < n && cnt[p[pt]] >= p[pt]) pt++;
        while(found.size() && cnt[found.back()] == n) found.pop_back();
        if(pt < n) a[i] = p[pt];
        else if(found.size()) a[i] = found.back();
        else finish("No");
        cnt[a[i]]++;
    }
    cout << "Yes" << endl;
    for(auto &i : a) cout << i + 1 << " ";
    cout << endl;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100], b[100];
ll f[100];
ll d[100][100];
main(){
    ll n;
    cin >> n;
    for (ll i =0; i< n;i++){
        cin >> a[i];
    }
    for (ll i =0 ; i < n; i++){
        cin >> b[i];
    }
    for (ll i = 0; i <= 50; i++){
        for (ll j = 0; j <= 50; j++){
            d[i][j] = 1e18;
            if(i == j) d[i][j] = 0;
            if(j > i)
            for (ll x = i + 1; x <= 50;  x++){
                if((j - i) % x == 0) {d[i][j] = (1ll << x); break;}
            }
        }
    }
    ll ans = 0;
    for (ll i = 0; i <= 50; i++){
        for (ll k = 0; k <= 50; k++)
        {
            for (ll i = 0; i <= 50; i++)
            {
                for (ll j = 0; j <= 50; j++)
                {
                    if ((d[i][k] | d[k][j]) < d[i][j])
                        d[i][j] = (d[i][k] | d[k][j]);
                }
            }
        }
        ll x = 0;
        for (ll j = 0; j < n; j++){
            x = max(x, d[b[j]][a[j]]);
        }
      //  cout << endl << x << endl;

        if(x == 0) break;
        if( x > 1e17){
            cout << -1<< endl;
            return 0;
        }
        ll y = 0;
        while(x-(x&-x) > 0) x -= (x&-x);
     //   cout <<x << endl;
        ans += x;
        while( x > 1) {x/=2; y++;}
        f[y] = 1;
     //   cout << x << endl;
        for (ll i = 0; i <= 50; i++){
        for (ll j = 0; j <= 50; j++){
            d[i][j] = 1e18;
            if(i == j) d[i][j] = 0;
            if(j > i)
            for (ll x = i + 1; x <= 50;  x++){
                if((j - i) % x == 0) {
                        d[i][j] =min(d[i][j], (1ll << x));
                        if(f[x] == 1) d[i][j] = 0;
                }
            }
        }
    }
    }
    cout << ans << endl;

}


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

int main(){
	int n, m;
	int a[100][100];
	int b[100];
	int c[100] = {0};
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++){
		cin >> b[i];
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			c[i] += a[i][j] * b[j];
		}
		cout << c[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>

int main (){
	int year;
	int month;
	int date;
	int x;
	
	scanf ("%d/%d/%d", &year, &month, &date);
	
	x = year + 1;
	
	printf ("%d/%02d/%02d\n", x, month, date);
	
	return 0;
}

Measured memory_bytes: 1680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		
		if(a>b) {
			if(b<c&&c<a) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}else if(a<b) {
			if(a<c&&c<b) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}

}


Measured memory_bytes: 22740
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
 
using namespace std;
 
int h, w;
char s[12][13];
string ss[12];
int a[12];
int b[12];
 
void dfs1(int x, bool f) {
    if (x == w) {
        puts("YES");
        exit(0);
    } else if (b[x] != -1) {
        dfs1(x + 1, f);
    } else {
        int i, j;
        
        for (i = x + 1; i < w; i++) {
            if (b[i] != -1) continue;
            
            for (j = 0; j < h; j++) {
                if (s[j][x] != s[a[j]][i]) break;
            }
            
            if (j == h) {
                b[x] = i;
                b[i] = x;
                
                dfs1(x + 1, f);
                
                b[x] = b[i] = -1;
            }
        }
        
        if (!f) {
            for (j = 0; j < h; j++) {
                if (s[j][x] != s[a[j]][x]) break;
            }
            
            if (j == h) {
                b[x] = x;
                
                dfs1(x + 1, true);
                
                b[x] = -1;
            }
        }
    }
}
 
void dfs2(int x, bool f) {
    if (x == h) {
        dfs1(0, w % 2 == 0);
    } else if (a[x] != -1) {
        dfs2(x + 1, f);
    } else {
        int i;
        
        for (i = x + 1; i < h; i++) {
            if (a[i] != -1) continue;
            if (ss[x] != ss[i]) continue;
            
            a[x] = i;
            a[i] = x;
            
            dfs2(x + 1, f);
            
            a[x] = a[i] = -1;
        }
        
        if (!f) {
            a[x] = x;
            
            dfs2(x + 1, true);
            
            a[x] = -1;
        }
    }
}
 
int main() {
    int i;
    
    scanf("%d %d", &h, &w);
    
    for (i = 0; i < h; i++) scanf("%s", s[i]);
    
    for (i = 0; i < h; i++) {
        ss[i] = s[i];
        sort(ss[i].begin(), ss[i].end());
    }
    
    for (i = 0; i < h; i++) a[i] = -1;
    for (i = 0; i < w; i++) b[i] = -1;
    
    dfs2(0, h % 2 == 0);
    
    puts("NO");
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    string s,t;
    cin>>s>>t;
    rep(i,t.size()){
        s = s.back() + s.substr(0, s.size()-1);
        if(s==t){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int A, B; cin >> A >> B;
  int result = 0;
  if (A>=6&&A<=12) result = B/2;
  if (A>=13) result = B;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll n;
 cin>>n;
 vector<ll> a(n);
 for(ll i=0;i<n;i++)cin>>a[i];
 bool f = true;
 for(ll i=0;i<n;i++){
  if( a[i] % 2 == 0 ){
   if(a[i]%3 == 0 || a[i]%5==0 ){

   }else{
    f = false;
   }
  }
 }
 if( f ){
  cout<<"APPROVED"<<endl;
 }else{
  cout<<"DENIED"<<endl;
 }
    return 0;
}


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

using namespace std;

int main()
{
        int N, W;
        cin >> N >> W;
        vector<int> c(N), w(N);
        for (int i = 0; i < N; i++)
            cin >> w[i] >> c[i];

        vector<long long> dp(W + 1);
        for (int i = 0; i < N; i++)
            for (int wa = W; wa-w[i] >=0; wa--)
                dp[wa] = max(dp[wa], dp[wa - w[i]] + c[i]);
        long long _max = 0;
        for (int i = 0; i < W + 1; i++)
            _max = max(_max, dp[i]);
        cout << _max << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
input=sys.stdin.readline
import collections
n,d,a=map(int,input().split())
XH=[]
for i in range(n):
  XH.append([int(i) for i in input().split()])
XH.sort(key=lambda x:x[0])
D=collections.deque()
x,h=XH[0]
t=(h-1)//a+1
ans=t
D.append([x,h,t])
adj=t
for i in range(1,n):
  x,h=XH[i]
  while D:
    lx,lh,t=D.popleft()
    if lx<x-2*d:
      adj-=t
    else:
      D.appendleft([lx,lh,t])
      break
  h=max(0,h-adj*a)
  t=(h-1)//a+1
  ans+=t
  adj+=t
  D.append([x,h,t])
print(ans)





Measured memory_bytes: 66640
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

vector<int> divisor(int n)
{
    vector<int> res;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            res.pb(i);
            if(i != n/i){
                res.pb(n/i);
            }
        }
    }
    sort(all(res));
    return res;
}

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> res = divisor(c);
    int cnt = 0;
    rep(i,res.size()){
        if(a <= res[i] && res[i] <= b){
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

int main(){
  string s;
  cin >> s;
  int l = s.length();
  vector<vector<ll>> dp(2,vector<ll>(l+1,0));
  dp[0][1] = 2; dp[1][1] = 1;
  for(int i = 1; i < l; i++) {
    (dp[1][i+1] += 3*dp[1][i]) %= mod;
    if(s[i] == '1') {
      (dp[1][i+1] += dp[0][i]) %= mod;
      (dp[0][i+1] += dp[0][i]*2) %= mod;
    } else {
      (dp[0][i+1] += dp[0][i]) %= mod;
    }    
  }
  cout << (dp[0][l] + dp[1][l]) % mod << endl;
  return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll ans = 1;
    for(ll i=k;i<=n;++i){
        ll val1 = ((i-1)*i)/2;
        ll a = n-i+1;
        ll val2 = (i*(2*a + (i-1)))/2;
        ans += (val2+1-val1);
        //ans%=(1000000000+7);
    }
    cout<<ans%(1000000000+7)<<'\n';
    return 0;
}

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

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

	for(int i=0; i*4<=N; i++){
		if((N-i*4)%7 == 0){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i<=a; i--)
#define INF 1e9

int main()
{
	int N, K, T, U, V, L;
	int D[201];
	cin >> N >> K >> T >> U >> V >> L;
	REP(i, 0, N) cin >> D[i];
	D[N] = L;
	
	int cnt = 0;
	double ans = 0.0, res = 0.0;
	REP(i, 0, N + 1) {
		double dist = D[i];
		if (i - 1 >= 0) dist -= D[i - 1];

		while (dist > 0.0) {
			if (res > 0.0) {
				ans += min(dist / V, res);

				double ndist = dist - min(dist, res*V);
				double nres = res - min(dist / V, res);
				dist = ndist;
				res = nres;
			}

			if (cnt > 0 && res == 0.0) {
				res = T;
				cnt--;
			}
			if (res == 0.0) {
				ans += 1.0*dist / U;
				dist = 0.0;
			}
		}

		if (cnt == K) res = T;
		else cnt++;
	}

	printf("%.6lf\n", ans);
	return 0;
}

Measured memory_bytes: 3204
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

vector<vector<int>>g;
vector<int>color;//0:1,1:2
int one,two;

void dfs(int v,int c=0){
  color[v]=c;
  if(c==0)++one;
  else ++two;
  for(auto x:g[v]){
    if(color[x]==-1)dfs(x,1-c);
  }
}

void solve(){
  int n;
  cin>>n;
  g.resize(n);
  one=0,two=0;
  color.resize(n,-1);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  dfs(0);
  vector<int>ans(n);
  set<int>st,st1,st2;
  for(int i=3;i<=n;i+=3)st.emplace(i);
  for(int i=1;i<=n;i+=3)st1.emplace(i);
  for(int i=2;i<=n;i+=3)st2.emplace(i);
  if((one>n/3)&&(two>n/3)){
    rep(i,n){
      if (color[i]==0&&(!st1.empty())){
        ans[i]=*st1.begin();
        st1.erase(*st1.begin());
      }
      else if(color[i]==1&&(!st2.empty())){
        ans[i]=*st2.begin();
        st2.erase(*st2.begin());
      }
      else {
        ans[i]=*st.begin();
        st.erase(*st.begin());
      }
    }
  }
  else if(two<=n/3){
    rep(i,n){//先に処理しないとダメ
      if(color[i]==1){
        ans[i]=*st.begin();
        st.erase(*st.begin());
      }
    }
    rep(i,n){
      if(ans[i]!=0)continue;
      if(!st.empty()){
        ans[i]=*st.begin();
        st.erase(*st.begin());
      }
      else if(!st2.empty()){
        ans[i]=*st2.begin();
        st2.erase(*st2.begin());
      }
      else{
        ans[i]=*st1.begin();
        st1.erase(*st1.begin());
      }
    }
  }
  else {
    rep(i,n){//先に処理しないとダメ
      if(color[i]==0){
        ans[i]=*st.begin();
        st.erase(*st.begin());
      }
    }
    rep(i,n){
      if(ans[i]!=0)continue;
      if(!st.empty()){
        ans[i]=*st.begin();
        st.erase(*st.begin());
      }
      else if(!st2.empty()){
        ans[i]=*st2.begin();
        st2.erase(*st2.begin());
      }
      else{
        ans[i]=*st1.begin();
        st1.erase(*st1.begin());
      }
    }
  }
  rep(i,n){
    if(i)cout<<" ";
    cout<<ans[i];
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


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

string code(const string& s){
  string ret(1,s[0]);
  string t = "aiueo";
  for(size_t i = 1; i < s.length(); ++i){
    if(t.find(s[i-1]) != string::npos){
      ret += s[i];
    }
  }
  return ret;
}

int main(){
  int n;
  while(cin >> n, n){
    vector<string> S(n);
    for(int i = 0; i < n; ++i) cin >> S[i];
    int ans = -1;
    vector<string> T(n);
    for(int i = 0; i < n; ++i) T[i] = code(S[i]);
    for(int k = 1; k <= 50; ++k){
      set<string> C;
      for(auto t : T) C.insert(t.substr(0,k));
      if((int)C.size() == n){
        ans = k;
        break;
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3160
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n;
    cin >> n;

    vector<lint> a(n);
    rep(i, n){
        cin >> a[i];
    }

    lint ans = 0;
    bool flag = true;
    while(flag){
        flag = false;
        rep(i, n){
            if(a[i] >= n){
                flag = true;
                lint k = a[i] / n;
                ans += k;
                rep(j, n){
                    if(i == j){
                        a[j] -= k * n;
                    }else{
                        a[j] += k;
                    }
                }
            }
        }
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=0;
	bool check=false;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		if(x%2!=0) check=true;
	}
	if(/*ans%2==0&&*/check==false) cout<<"second";
	else cout<<"first";
}

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

using namespace std;



int c(int n)
{
    int x=1;
    while (n != 1)
    {
       if (n & 1)
            n = 3*n + 1;

        else
            n = n/2;
        x++;

    }
  return x;

}

int main()
{
   int n;
   cin>>n;
   if(n==1)
   {
       cout<<4<<endl;
       return 0;
   }
   else if(n==2)
   {
       cout<<4<<endl;
       return 0;
   }

   cout<<c(n)+1;
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);

        String str = sc.nextLine();
        char[] c = str.toCharArray(); 

        int n = str.length();

        for(int i=0;i<n;i++){
            if(65 <= c[i] && c[i] <= 90){
                c[i] += 32;
            }

            else if(97 <= c[i] && c[i] <= 122){
                c[i] -= 32;
            }

            else{

            }

            System.out.printf("%c",c[i]);

        }

        System.out.println();

        sc.close();

    }



}


Measured memory_bytes: 29240
import java.util.Scanner;

class Main{
    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);

        String S = scanner.next();
        String T = "ABC";

        if(S.equals(T)){
            System.out.println("ARC");
        }else{
            System.out.println("ABC");
        }

    }
}

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

using namespace std;
long long mod = 1000000000+7;
  long long  pow(long long  a, long long  b, long long m)
 {
        stack<int>k;
        int j = 128;
        int l = 1;
       int an = 1;
        while(b){
            if(b>=j){
                k.push(j);
                b-=j;
            }
            j/=2;
        }
        while(!k.empty()){
            if(k.top()==l){
                an = (an*a)%mod;
                k.pop();
            }
            a = (a*a)%mod;
            l*=2;
        }

        return an;
 }

    int bi (long long k,long long n,long long a,long long b){
        int index = -1;
        int l = 0;
        int r = n;
         int mid;
        while(l<=r){
                mid = l+(r-l)/2;
            if(k-(mid*a)>(n-mid)*b){
                    index = mid;
            l = mid+1;
            }
            else {
                r = mid-1;
            }

        }
    return index;
    }


    int v[1000];
    int w[1000];
 vector<vector<long long > >vc(100010,vector<long long>(101,-1));
    long long knap(long long n,long long W){
            if(vc[W][n]!=-1){
                return vc[W][n];
            }
        long long result;
    if(W==0||n==0){
        return 0;
    }
    else if (w[n]>W){
         result =   knap(n-1,W);
    }
    else{
        result =  max(knap(n-1,W),knap(n-1,W-w[n])+v[n]);
    }
        vc[W][n] = result;
        return result;

    }


 int main(){
   ios_base::sync_with_stdio(0);cin.tie(NULL);
    //freopen("pizza.in","r",stdin);
    //freopen("pizza.out","w",stdout);
            int n ,W;
      cin>>n>>W;
      for(int i = 1;i<=n;++i){
        cin>>w[i]>>v[i];
      }
    cout<<knap(n,W)<<endl;



    return 0;
}


Measured memory_bytes: 82304
#include <stdio.h>

int main(void)
{
  int n;
  int seq[5001], max;
  int buf;
  int i, j;
  
  while (1) {
    scanf("%d", &n); if ( n == 0 ) break;
    for ( i = 0; i < n; i++ ) {
      scanf("%d", &seq[i]);
    }

    max = seq[0];
    for ( i = 0; i < n; i++ ) {
      buf = 0;
      for ( j = i; j < n ; j++) {
	  buf += seq[j];
	  if ( buf > max ) max = buf; 
      }
    }
    
    printf("%d\n", max);
  }
    
  return 0;
}

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

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	cout << a+b+c-max(a,max(b,c)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
#define int ll

int dp[45];

int fib(int n) {
  if(dp[n]) return dp[n];
  if(n == 0) return 1;
  else if(n == 1) return 1;
  else return dp[n] = fib(n-1) + fib(n-2);
}

signed main(void) {
  int n;
  cin >> n;
  cout << fib(n) << endl;
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  VV<> g(n);
  while (m--) {
    int s, t; cin >> s >> t, --s, --t;
    g[s].push_back(t);
  }
  long double res = 1e100;
  for (int x = n - 1; x >= 0; --x) if (x == n - 1 or g[x].size() >= 2) {
    V<long double> dp(n);
    for (int v = n - 2; v >= 0; --v) {
      if (v != x) {
        for (int u : g[v]) {
          dp[v] += dp[u];
        }
        dp[v] /= g[v].size();
      } else {
        long double mx = 0;
        for (int u : g[v]) {
          dp[v] += dp[u];
          mx = max(mx, dp[u]);
        }
        dp[v] -= mx;
        dp[v] /= g[v].size() - 1;
      }
      dp[v] += 1;
    }
    res = min(res, dp[0]);
  }
  cout << fixed << setprecision(15) << res << '\n';
}

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

int main(){
    int n;

    cin >> n;

    for(int i = 1; i <= n; i++){
        if(i % 3 == 0){
            cout << " " << i;
            continue;
        }else if(i % 10 == 3){
            cout << " " << i;
            continue;
        }
        int x = i;
        while(x > 0){
            x /= 10;
            if(x % 10 == 3){
                cout << " " << i;
                break;
            }
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, k;

signed main() {
	cin >> n >> k;
	if (n <= k)cout << min(n, k - n) << endl;
	else {
		if (!(n - k) % k)cout << 0 << endl;
		else {
			int x = n - ((n - k) / k + 1)*k;
			cout << min(x, k - x) << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
ll INF = 1000000007;


/***************/
 #define amin main
/***************/

ll exp(ll x, ll n)
{if(n==0) return 1;if(n==1) return x%INF;if(n%2==0) return exp((x*x)%INF,n/2); else return(x*exp((x*x)%INF,n/2))%INF;}


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i;
	ll a,b,v,w;
	cin>>a>>v>>b>>w>>t;
	if(a!=b)
	{
		if(v<=w)
			cout<<"NO"<<endl;
		else
		{
			ld k = abs(a-b);
			ld g = (ld)abs(v-w);
			if( (ld)k/t <= g )
				cout<<"YES"<<endl;
			else
				cout<<"NO"<<endl;

		}
	}
	else
		cout<<"YES"<<endl;
	


	
	

	
	


	
	return 0;
}

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

int main() {
  int r;
  cin >> r;
  double ans = (double)2 * r * M_PI;
  cout << fixed << ans << setprecision(10) << endl;
}

Measured memory_bytes: 3784
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from math import gcd, ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    A,B = LMIIS()
    if A & 1:
        if B & 1:
            #A, (A+1 A+2).....(B-1,B)
            print(A^(B-A)//2%2)
        else:
            #A, (A+1 A+2).....(B-2,B-1),B
            print(A^((B-A-1)//2%2)^B)
    else:
        if B & 1:
            #(A, A+1).....(B-1,B)
            print((B-A+1)//2%2)
        else:
            #(A, A+1).....(B-2,B-1),B
            print((B-A)//2%2^B)



    

if __name__ == '__main__':
    main()

Measured memory_bytes: 65348
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AMultiplication1 solver = new AMultiplication1();
        solver.solve(1, in, out);
        out.close();
    }

    static class AMultiplication1 {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            long a = s.nextLong();
            long b = s.nextLong();
            out.println(a * b);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 32508
n,k = map(int, input().split())
p = list(map(int, input().split()))

bag = []
bag_max = 0

for i in range(n):

    if i < k:
        bag.append(p[i])
        if bag_max < p[i]:
            bag_max = p[i]
    else:
        if bag_max > p[i]:
            bag.append(p[i])
            bag.remove(bag_max)
            bag_max = max(bag)

print(sum(bag))

Measured memory_bytes: 64292
#include<cstdio>
#include<cstring>
#include<cmath>
#include <cstdlib>
#include<algorithm>
#define eps 1e-8
using namespace std;
const int N = 1000010;
struct Point{
	double x,y;
	Point(){
	}
	Point(double xx,double yy){
		x=xx;
		y=yy;
	}
}p[N];
Point O;
double R;
double sqr(double x){
	return x*x;
}
double dist(Point a,Point b){
	return sqrt(sqr(a.x-b.x)+sqr((a.y-b.y)));
}
Point cnt(Point a,Point b){
	return Point((a.x+b.x)/2,(a.y+b.y)/2.0);
}
Point cnt(Point a,Point b,Point c){   //求三角形abc外心 
	double x1=a.x,y1=a.y;
	double x2=b.x,y2=b.y;
	double x3=c.x,y3=c.y;
	
	double a1=2*(x2-x1);
	double b1=2*(y2-y1);
	double c1=x2*x2+y2*y2-x1*x1-y1*y1;
	
	double a2=2*(x3-x2);
	double b2=2*(y3-y2);
	double c2=x3*x3+y3*y3-x2*x2-y2*y2;
	
	double x=(c1*b2-c2*b1)/(a1*b2-a2*b1);
	double y=(a1*c2-a2*c1)/(a1*b2-a2*b1);
	
	return Point(x,y);
}
int n;
void work(){ //求最小圆 
	random_shuffle(p+1,p+n+1);
    O=p[1];
    R=0;
    int i,j,k;
    for(i=2;i<=n;i++){
    	if(dist(O,p[i])<R+eps) continue;
    	O=p[i];
    	R=0;
    	for(j=1;j<i;j++){
    		if(dist(O,p[j])<R+eps) continue;
    		O=cnt(p[i],p[j]);
    		R=dist(O,p[i]);
    		for(k=1;k<j;k++){
    			if(dist(O,p[k])<R+eps) continue;
    			O=cnt(p[i],p[j],p[k]);
    			R=dist(O,p[i]);
			}
		}
	}
	printf("%.18f\n",R);
}
 
 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%lf%lf",&p[i].x,&p[i].y);
    work();
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <map>

using namespace std;

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

    int res=0;
    map<int, int> m;
    for (int i=1; i<=N; ++i) {
        int a;
        scanf("%d", &a);
        m[i] = a;
        if (m[a] == i)
            ++res;
    }

    printf("%d\n", res);
    return 0;
}


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

typedef unsigned long long ull;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const ull mod = 1e9 + 7;

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

	map <int,int> mp;
	int N,A;	cin>>N;
 	FOR(i,1,N+1)	mp[i]=0;
	FOR(i,1,N){
		cin>>A;
		mp[A]++;
	}
	
	for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
      	cout <<itr->second <<endl;
    }

    return 0;
}

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

int main(void) {
	int N[50] = {0},n, m, a[50], b[50];
	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < m; i++) {
		 N[a[i]-1]+= 1;
	}
	for (int i = 0; i < m; i++) {
		N[b[i]-1] += 1;
	}
	for (int i = 0; i < n; i++) {
		cout<<N[i]<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	if(n>=0&&n<1200)cout<<"ABC"<<endl;
	if(n>=1200&&n<2800)cout<<"ARC"<<endl;
	if(n>=2800&&n<=4208)cout<<"AGC"<<endl;
	return 0;	
} 

Measured memory_bytes: 256
#include <iostream>
    #include <algorithm>
    #include <math.h>
    #include <string.h>
    #include <stdio.h>
    #include <vector>
    using namespace std;
    typedef long long LL;
    const int MAX=2e5+5;
    const LL mod=1e9+7;
    int n,c[MAX];
    vector<int> st[MAX];
    LL dp[MAX];
    int main(){
        scanf("%d",&n);
        for(int i=1;i<=n;++i){
            scanf("%d",c+i);
        }
        n=unique(c+1,c+n+1)-c-1;
        static int prv[MAX];
        for(int i=1;i<=n;++i){
            if(prv[c[i]]!=0){
                st[i-1].push_back(prv[c[i]]);
            }
            prv[c[i]]=i;
        }
        dp[0]=1;
        for(int i=1;i<=n;++i){
            dp[i]=dp[i-1];
            for(int j=0;j<(int)st[i].size();++j){
                dp[i]=(dp[i]+dp[st[i][j]-1])%mod;
            }
        }
        printf("%lld\n",dp[n]);
        return 0;
    }

Measured memory_bytes: 13440
#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() {
    ll N, H, W;
    cin >> N >> H >> W;
    vector<ll> A(N), B(N);
    rep(i,N) cin >> A[i] >> B[i];

    ll ans = 0;
    rep(i,N) {
        if (A[i] >= H && B[i] >= W) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define repvin(n) vint a(n);r(i,n)cin>>a[i];
#define int long long
#define str string
#define vint vector<signed>
#define pint pair<signed,signed>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60

signed main(){
  int n;
  cin>>n;
  vint a(n);
  repi(n)cin>>a[i];
  SORT(a);
  map<int,int> m;
  repi(n)m[a[i]]++;
  a.erase(unique(all(a)),a.end());
  int res=0;
  rep(i,a.size()){
    res=max(res,m[a[i]]+m[a[i]-1]+m[a[i]+1]);
  }
  cout<<res<<endl;
  
  return 0;
}


Measured memory_bytes: 6528
n, a, b = map(int,input().split())
x = list(map(int,input().split()))

d = []
for i in range(n-1):
  d.append(x[i+1]-x[i])

f = 0
for i in range(n-1):
  if d[i]*a <= b:
    f += d[i]*a
  else:
    f += b
    
print(f)


Measured memory_bytes: 14252
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
summ = sum(a)
ruisekiwa = []
tmp = 0
for i in range(n):
    tmp += a[i]
    ruisekiwa.append(tmp)
ans = 100100100100
for i in range(len(ruisekiwa) - 1):
    ans = min(ans, abs(ruisekiwa[i] - (summ - ruisekiwa[i])))
print(ans)
# print(ruisekiwa)


Measured memory_bytes: 30484
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T>
struct BIT{
    //1-index
    private:
    V<T> arr;
    int n;

    public:
    BIT(int siz){
        n=siz;
        arr.assign(n+1,0);
    }
    //一点更新
    void add(T a,T v){
        //x+=(x&-x) 初項a,それ以降a<=2^Nが列挙
        for(T x=a;x<=n;x+=(x&-x)){
            arr[x]+=v;
        }
    }
    T sum(T a){
        T ret=0;
        for(T x=a;x>0;x-=(x&-x))ret+=arr[x];
        return ret;
    }
};
int main(){
    string s;
    cin>>s;
    int n=s.size();
 BIT<ll> t(n);
 V<ll> v(n);
  map<ll,int> mp;
 for(int i=0;i<n;i++){
     if(s[i]=='B')v[i]=1e9;
     else v[i]=0;
     mp[v[i]];
 }
 ll cnt=1;
 for(auto &p:mp)p.se=cnt++;
 ll ans=0;
 for(int i=0;i<n;i++){
     ans+=i-t.sum(mp[v[i]]);
     t.add(mp[v[i]],1);
 }
 cout<<ans<<endl;
}

Measured memory_bytes: 3732
n,a,b = map(int,input().split())
s=list(input())
ai, bi = 0, 0

for i in s:
    if i == "c":
        print("No")
    elif i == "b":
        if a+b > ai+bi and b > bi:
            print("Yes")
            bi += 1
        else:
            print("No")
    else:
        if a+b >ai+bi:
            print("Yes")
            ai += 1
        else:
            print("No")

Measured memory_bytes: 4712
import java.util.List;
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int ans=Math.max(A,Math.max(B,C))-Math.min(A,Math.min(B,C));

		System.out.println(ans);
	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


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

int main(){
    int n,x;
    string ans = "Yes";
    cin >> n >> x;
    if(x==1||x==2*n-1) ans = "No";
    cout << ans << endl;
    if(ans=="No") return 0;
    for(int i = 0;i < 2*n-1;i ++){
        int a;
        if(i<n-1){
            a = x-(n-1-i);
            if(a<=0) a = 2*n-1+a;
        }else{
            a = x+(i-n+1);
            if(a>2*n-1) a = a-(2*n-1);
        }
        cout << a << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
H, W = map(int, input().split())
T = [[int(t) for t in input().split()] for _ in range(H)]
A = [[0] * W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if T[i][j] == 1:
            A[i][j] = 0
        elif i == 0 or j == 0:
            A[i][j] = 1
        else:
            A[i][j] = min(A[i - 1][j], A[i][j - 1], A[i - 1][j - 1]) + 1

mx = 0
for a in A:
    mx = max(mx, max(a))

print(mx ** 2)



Measured memory_bytes: 55620
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define		int 			long long int
#define		pb				push_back
#define		fi(n)			for(int i=0;i<n;i++)
#define		fi1(n)			for(int i=1;i<n;i++)
#define		fj(n)			for(int j=0;j<n;j++)
#define		fj1(n)			for(int j=1;j<n;j++)
#define		rep(z,a,n)		for(z=a;z<n;z++)
#define		rep2(z,a,n)		for(z=a;z<n;z+=2)
#define		clr(x)			memset(x, 0, sizeof(x))
#define		print(x,n)		for(int i=0;i<n;i++) cout<<x[i]<<" ";  cout<<"\n"
#define		nl 				"\n"
#define		vi				vector<int>
#define		mp 				make_pair
#define		pairi			pair<int,int>
#define		vpairi			vector<pair<int,int>>
#define		ff				first
#define		ss				second
#define		inf 			2e18
#define 	input 			"C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//input.txt"
#define 	output 			"C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//output.txt"
#define 	error 			"C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//error.txt"

int ctoi(char a){ int x=a-48;return x;}
string itos(int a){
	string out_string;
	stringstream ss;
	ss<<a;
	out_string=ss.str();
	return out_string;
}
char itoc(int a){ return itos(a)[0];}
int pow(int e,int x){
	int ans=1;
	while(x>0){
		if(x&1) ans*=e;
		e*=e;
		x>>=1;
	}return ans;
}
string bin(int x){
	bitset<sizeof(1)*CHAR_BIT> bits(x);
	string b=bits.to_string(); return b;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	#endif
	int T=1;
	// cin>>T;
	while(T--){
		int n,k,m,x,y;
		// cin>>n;
		// int a[n];clr(a);
		string a,b;
		cin>>a>>b;
		n=a.length();m=b.length();
		int ans[n+1][m+1];clr(ans);
		fi1(n+1){
			fj1(m+1){
				if(a[i-1]==b[j-1]){
					ans[i][j]=ans[i-1][j-1]+1;
				}
				else{
					ans[i][j]=max(ans[i-1][j],ans[i][j-1]);
				}
			}
		}
		// cout<<ans[n][m]<<nl;
		list<char> lcs;
		int i=n,j=m;
		while(i>=1 && j>=1){
			if(a[i-1]==b[j-1]){
				lcs.push_front(a[i-1]);
				i--;j--;
			}
			else{
				if(ans[i-1][j]>ans[i][j-1]) i--;
				else j--;
			}
		}
		for(auto x:lcs) cout<<x;
		cout<<nl;
	}
	return 0;
}


Measured memory_bytes: 70784