akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
const int N = 22, D[][2] = {
		{0,  1},
		{1,  0},
		{-1, 0},
		{0,  -1}
};
int n, m;
bool vis[N][N];
char s[N][N];
bool valid(int x, int y) {
	return 0 <= x && x < n && 0 <= y && y < m && s[x][y] == '.' && !vis[x][y]++;
}
int bfs(int i, int j) {
	queue<pair<int, int>> q;
	q.push({i, j});
	memset(vis, 0, sizeof vis);
	vis[i][j] = true;
	int level = 0;
	while (q.size()) {
		int sz = q.size();
		while (sz--) {
			auto cur = q.front();
			q.pop();
			for (int d = 0; d < 4; ++d) {
				int x = cur.first + D[d][0];
				int y = cur.second + D[d][1];
				if (valid(x, y)) {
					q.push({x, y});
				}
			}
		}
		++level;
	}
	return level - 1;
}
int main() {
//	freopen("input.in", "r", stdin);
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; ++i)
		scanf("%s", s[i]);
	int res = -1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (s[i][j] == '.') {
				res = max(res, bfs(i, j));
			}
		}
	}
	printf("%d\n", res);
	return 0;
}




Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
	}
	for i := 0; i < n; i++ {
		if as[i] == 0 {
			fmt.Println(0)
			return
		}
	}
	ans := 1
	for i := range as {
		if as[i] > 1e18/ans {
			fmt.Println(-1)
			return
		}
		ans *= as[i]
		if ans > int(1e18) {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, m;
  cin >> n;
  set <ll> a;
  ll l;
  rep(i, n) {
    cin >> l;
    a.insert(l);
  }
  cin >> m;
  set <ll> b;
  rep(i, m) {
    cin >> l;
    b.insert(l);
  }
  set <ll> s;
  for (auto value : a) {
    if (!b.count(value)) {
      s.insert(value);
    }
  }
  for (auto value : b) {
    if (!a.count(value)) {
      s.insert(value);
    }
  }
  for (auto value : s) {
    cout << value << endl;
  }
}


Measured memory_bytes: 40596
N,M,Q = map(int,input().split())
abcd = [list(map(int,input().split())) for i in range(Q)]
ans = 0
for a in range(1,M+1):
    for b in range(a,M+1):
        for c in range(b,M+1):
            for d in range(c,M+1):
                for e in range(d,M+1):
                    for f in range(e,M+1):
                        for g in range(f,M+1):
                            for h in range(g,M+1):
                                for i in range(h,M+1):
                                    for j in range(i,M+1):
                                        lista = [a,b,c,d,e,f,g,h,i,j]
                                        ans1 = 0
                                        for A,B,C,D in abcd:
                                            if lista[B-1]-lista[A-1] == C:
                                                ans1 += D
                                        ans = max(ans,ans1)
print(ans)


Measured memory_bytes: 9152
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>

using namespace std;

int h[1024*1500];
int w[1024*1500];

int getInt(){
  int c = getchar();
  int ret = 0;
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n,m;
  while(n=getInt(), m=getInt(), n+m){
    int hh[n];
    int ww[m];
    int mm = 0;

    for(int i=0; i<n; i++)
      hh[i] = getInt();
    for(int i=0; i<m; i++)
      ww[i] = getInt();

    for(int i=0; i<n; i++){
      int sum = 0;
      for(int j=i; j<n; j++){
	sum += hh[j];
	h[sum]++;
      }
      mm = max(mm, sum);
    }
    for(int i=0; i<m; i++){
      int sum = 0;
      for(int j=i; j<m; j++){
	sum += ww[j];
	if(sum > mm) break;
	w[sum]++;
      }
    }
    long long ans = 0;
    for(int i=0; i<=mm; i++){
      if(w[i] | h[i]){
	ans += (long long)w[i] * h[i];
	w[i] = h[i] = 0;
      }
    }

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

Measured memory_bytes: 0
import copy

H,W,K = map(int,input().split())
C = [list(input()) for _ in range(H)]

M = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if C[i][j] == "#":
            M[i][j] = 1

def bit_01(keta):
    ans = []
    for i in range(2**(keta)):
        ans.append("".join(["{:0", str(keta), "b}"]).format(i))
    return ans

vert = bit_01(H)
hori = bit_01(W)

def check(v,h,M):
    M = copy.deepcopy(M)
    for i in range(len(v)):
        if v[i] == "1":
            for ii in range(W):
                M[i][ii] = 0
    for j in range(len(h)):
        if h[j] == "1":
            for jj in range(H):
                M[jj][j] = 0
    S = 0
    for i in range(W):
        for j in range(H):
            S += M[j][i]
    return S == K

ans = 0
for vp in vert:
    for hp in hori:
        if check(vp,hp,M):
            ans += 1

print(ans)
        

Measured memory_bytes: 77756
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int mid_exam=sc.nextInt();
            int final_exam=sc.nextInt();
            int re_exam=sc.nextInt();
            if(mid_exam==-1 && final_exam==-1 && re_exam == -1) break;
            if(mid_exam==-1 || final_exam ==-1){
                System.out.println("F");
            }
            else if(mid_exam+final_exam>=80){
                 System.out.println("A");
            }
            else if(mid_exam+final_exam>=65){
                 System.out.println("B");
            }
            else if(mid_exam+final_exam>=50){
                 System.out.println("C");
            }
            else if(mid_exam+final_exam>=30 )
                 {
                   if(re_exam>=50) System.out.println("C");  
                  else System.out.println("D");
                 }
            else System.out.println("F");
        }
        
    }
}


Measured memory_bytes: 26468
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define int long long

signed main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  double ave = 0.0;
  for (int i = 0; i < n; i++) {
    ave += a[i];
  }
  ave /= n;
  int p = 0;
  double diff = abs(ave - a[0]);
  for (int i = 1; i < n; i++) {
    double res = abs(ave - a[i]);
    if (res < diff) {
      diff = res;
      p = i;
    }
  }
  cout << p << endl;
  return 0;
}


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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int main() {
    int N;
    int X[101];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }
    lld ans = 100000000000LL;
    for (int i = 1; i < 101; i++) {
        lld sum = 0;
        for (int j = 0; j < N; j++) {
            sum += (X[j]-i) * (X[j]-i);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <functional>
//#pragma optimize GCC("O3")
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	if (n >= 30)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 3636
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    int n;
    cin >> n;
    rep(i, n + 1){
        int temp = i * 108;
        temp = temp / 100;
        if(temp == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, X, T;
	cin >> N >> X >> T;
	int ans = (N + X - 1) / X * T;
	cout << ans << endl;
	return 0;
}


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

S = input()
bob = int(input())

M = eval(S)

L = int(S[0])

for o, v in zip(S[1::2], S[2::2]):
    if o == "*":
        L *= int(v)
    else:
        L += int(v)

if M == L == bob:
    print("U")
elif M == bob:
    print("M")
elif L == bob:
    print("L")
else:
    print("I")


Measured memory_bytes: 5604
//                                                   ¯\_(ツ)_/¯
  #pragma GCC optimize("Ofast")
 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
#define pi pair<int,int>
const int N=3e7+5,MOD=998244353;

using namespace std;

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


	scanf("%d",&n);

	vector<vector<int>>dp(n,vector<int>(3,0));

	for(int i=0;i<n;i++){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		if(i==0)dp[i][0]=a,dp[i][1]=b,dp[i][2]=c;
		else{

		 	dp[i][0]=max(a+dp[i-1][1],a+dp[i-1][2]);
		 	dp[i][1]=max(b+dp[i-1][0],b+dp[i-1][2]);
		 	dp[i][2]=max(c+dp[i-1][0],c+dp[i-1][1]);
		}
	}

	printf("%d\n",max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) );

}

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

using namespace std;

int main()
{
    int n;
    int ans;
    while(1){
        cin >> n;
        if(n == 0)break;
        if(n <= 2){
            cout << 1 << endl;
            continue;
        }
        vector<int> ways(n+1);
        ways[1] = 1;
        ways[2] = 2;
        ways[3] = 4;
        for(int i = 4; i <= n; i++){
            ways[i] = ways[i-1] + ways[i-2] + ways[i-3];
        }
        if(ways[n] % 3650 == 0){
            ans = ways[n] / 3650;
        }else{
            ans = (ways[n] / 3650) + 1;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ForBlue.ABC_090
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);

            long cnt = 0;
            for (int i = k + 1; i <= n; i++)
            {
                //1周期中の個数
                int length = i - k;
                //周期数
                int f = n / i;
                cnt += f * length;
                if (n % i >= k)//余り処理
                {
                    if (k == 0)
                    {
                        cnt += n % i;
                    }
                    else
                    {
                        cnt += n % i - k + 1;
                    }
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13140
n,k = map(int,input().split())

def comb(n,k):
    if n<k:
        return 0
    r = 1
    for i in range(k):
        r *= (n-i)
    for i in range(k):
        r //= (k+1)
    return r
def perm(n,k):
    if n<k:
        return 0
    r = 1
    for i in range(k):
        r *= (n-i)
    return r

single = n//k
if k%2 == 0:
    single =  n//(k//2)

double = perm(single,2)*3
if k%2 == 0:
    odd = perm((single+1)//2,2)*3
    even = perm(single//2,2)*3
    double = odd + even

triple = perm(single,3)
if k%2 == 0:
    odd = perm((single+1)//2,3)
    even = perm(single//2,3)
    triple = odd + even

print(single + double + triple)
         


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <queue>
#include <set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef unordered_map<int,int> m32;
typedef map<ll,ll> m64;
typedef unordered_map<ll,set<ll> > m648;
typedef pair<ll,p64 > pp64;
ll MOD = 1e9 + 7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF LLONG_MAX
v64 dp;

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    v64 a(n,0);
    forn(i,n) cin >> a[i];
    v64 dp(n,0);
    forn(i,n){
    	if(i==0) continue;
    	else if(i==1) dp[i]=dp[i-1]+abs(a[i-1]-a[i]); 
    	else dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
    }
    cout << dp[n-1] << ln;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

ll n;
map<ll, ll> m, mm;

map<ll, ll> prime_factor(ll n) {
	map<ll, ll> res;
	for (int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			++res[i];
			n = n / i;
		}
	}
	if (n != 1) {
		res[n] = 1;
	}
	return res;
}

ll solve(ll x) {
	ll res = 0;
	REP(i, n) {
		if (m[i + 1] > x - 2) {
			res++;
		}
	}
	return res;
}

signed main() {
	cin >> n;

	REP(i, n) {
		mm = prime_factor(i + 1);
		REP(j, n) {
			m[j] += mm[j];
		}
	}

	ll ans = solve(75) + solve(25) * (solve(3) - 1) + solve(15) * (solve(5) - 1) + solve(5) * (solve(5) - 1) * (solve(3) - 2) / 2;

	cout << ans << endl;
}

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

int main(void){
  int number, manipulate_number;
  cin >> number >> manipulate_number;

  string s;
  cin >> s;

  vector<int> nums;
  int now = 1;
  int cnt = 0;
  for(int i = 0; i < number; i++){
    if(s[i] == (char)('0' + now)) cnt++;
    else{
      nums.emplace_back(cnt);
      now ^= 1;
      cnt = 1;
    }
  }
  if(cnt != 0) nums.emplace_back(cnt);

  if(nums.size() % 2 == 0) nums.emplace_back(0);


  int add_range = 2 * manipulate_number + 1;
  vector<int> sum(nums.size() + 1);
  for(int i = 0; i < nums.size(); i++){
    sum[i + 1] = sum[i] + nums[i];
  }
  int ans = 0;

  for(int i = 0; i < nums.size(); i += 2){
    int left = i;
    int right = min(i + add_range, (int)nums.size());
    int tmp = sum[right] - sum[left];

    ans = max(tmp, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1272
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = (int)(1e6) + 5;
int p[N];
int q[N];
struct treap
{
    treap *l,*r;
    int ans;
    int cnt;
    int pr;
    int v;
    treap(int vv)
    {
        l = r = 0;
        ans = v = vv;
        cnt = 1;
        pr = rand();
    }
    void up(void)
    {
        cnt = 1;
        ans = v;
        if (l)
            smin(ans,l->ans),cnt += l->cnt;
        if (r)
            smin(ans,r->ans),cnt += r->cnt;
    }
};
typedef treap * tr;
tr merge(tr a,tr b)
{
    if (!a)
        return b;
    if (!b)
        return a;
    if (a->pr > b->pr)
    {
        a->r = merge(a->r,b);
        a->up();
        return a;
    }
    else
    {
        b->l = merge(a,b->l);
        b->up();
        return b;
    }
}
void split(tr Root,int k,tr & L,tr & R)
{
    if (!Root)
        return void(L = R = 0);
    int cnt = 1;
    if (Root->l) cnt += Root->l->cnt;
    if (cnt <= k)
    {
        split(Root->r,k - cnt,Root->r,R);
        L = Root;
    }
    else
    {
        split(Root->l,k,L,Root->l);
        R = Root;
    }
    Root->up();
}
void add(tr &Root,int pos,int v)
{
    tr L,R;
    split(Root,pos,L,R);
    Root = merge(L,merge(new treap(v),R));
}
int sz = 0;
int get(tr Root,int v)
{
    if (!Root)
        return 0;
    int ans1 = !Root->r ? 2 * N : Root->r->ans;
    int cnt1 = !Root->r ? 0 : Root->r->cnt;
    int ans2 = !Root->l ? 2 * N : Root->l->ans;
    int cnt2 = !Root->l ? 0 : Root->l->cnt;
    if (v > ans1)
        return cnt2 + 1 + get(Root->r,v);
    else
    if (Root->v < v)
        return cnt2 + 1;
    else
        return get(Root->l,v);
}
void go(tr Root)
{
    if (!Root)
        return;
    go(Root->l);
    q[Root->v] = ++sz;
    go(Root->r);
}
void print(tr Root)
{
    if (!Root)
        return;
    print(Root->l);
    cerr << Root->v << ' ';
    print(Root->r);
}
int main(void)
{
    srand(time(0));
    ios_base :: sync_with_stdio(0);
    int n,k;
    cin>>n>>k;
    for (int i = 1;i <= n;++i)
    {
        int v;
        cin>>v;
        p[v] = i;
    }
    tr Root = 0;
    for (int i = 1;i <= n;++i)
    {
        int index = get(Root,p[i] + k);
        add(Root,index,p[i]);
    }
    go(Root);
    for (int i = 1;i <= n;++i)
        cout << q[i] << " \n"[i == n];
    return 0;
}


Measured memory_bytes: 33024
#include <iostream>
#include <vector>
#include <list>

using namespace std;

int main() {
	int n; cin >> n;
	list<int> b(n);
	vector<int> ans;
	for (auto& e : b) cin >> e;
	while (!b.empty()) {
		int t = b.size();
		for (auto it = b.rbegin(); it != b.rend(); ++it) {
			if (*it == t) {
				b.erase(--it.base());
				ans.push_back(t);
				break;
			}
			--t;
		}
		if (!t) break;
	}
	if (ans.size() != n) cout << -1 << endl;
	else {
		for (int i = n - 1; i >= 0; --i) cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
const D EPS = 1e-9;
#define se second
#define fi first
#define mk make_pair
#define X real()
#define Y imag()
#define EQ(n,m) (abs((n)-(m)) < EPS)
D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) {  return (conj(a)*b).Y;}
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;
  if (cross(b,c) < -EPS) return -1;
  if (dot(b,c)   < -EPS) return +2;
  if (norm(b) < norm(c)) return -2; 
  return 0;
}
bool isecSS(P a1, P a2, P b1, P b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
         ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}
P crosspointLL(P a1, P a2, P b1, P b2) {
  D d1 = cross(b2-b1, b1-a1);
  D d2 = cross(b2-b1, a2-a1);
  if (EQ(d1, 0) && EQ(d2, 0)) return a1;
  if (EQ(d2, 0)) throw "c7c7";
  return a1 + d1/d2 * (a2-a1);
}
P x;
L a,t;
vector<pair<pair<double,double>,pair<int,int> > >v;
int main(){
  int m,n,a1,a2;
  cin>>m;
  while(m--){
    int ans=0;
    v.clear();
    D p1,p2,p3,p4;
    cin>>p1>>p2>>p3>>p4>>n;
    a.fi=P(p1,p2),a.se=P(p3,p4);
    rep(i,n){
      cin>>p1>>p2>>p3>>p4>>a1>>a2;
      t.fi=P(p1,p2),t.se=P(p3,p4);
      if(!isecSS(a.fi,a.se,t.fi,t.se))continue;
      x=crosspointLL(a.fi,a.se,t.fi,t.se);
      v.push_back(mk(mk(x.Y,x.X),mk(a1,a2)));
    }
    sort(v.begin(),v.end());
    rep(i,v.size())if(i){
      int q1=v[i-1].se.fi,q2=v[i].se.fi;
      int q3=v[i-1].se.se,q4=v[i].se.se;
      if(q1==q2&&q3!=q4)ans++;
      if(q1!=q2&&q4==q3)ans++;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3240
#include <bits/stdc++.h>
#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

struct S{
    ll one, zero, inv;
};

S op(S l, S r) {
    return {l.one+r.one, l.zero+r.zero, l.inv+r.inv+l.one*r.zero};
}
S e() {
    return {0, 0, 0};
}
S mapping(bool b, S a) {
    if(!b) return a;
    ll n = a.one + a.zero;
    return {a.zero, a.one, a.one*a.zero - a.inv};
}
bool composition(bool l, bool r) {
    return l ^ r;
}
bool id() {
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, Q;
    cin >> N >> Q;
    vector<S> a(N);
    for(int i = 0; i < N; i++) {
        ll b;
        cin >> b;
        a[i] = {b, 1 - b, 0};
    }
    atcoder::lazy_segtree<S,op,e,bool,mapping,composition,id> seg(a);
    for(int q = 0; q < Q; q++) {
        auto tmp = seg.all_prod();
        //cerr << tmp.one << " " << tmp.zero << " " << tmp.inv << endl;
        int T, L, R;
        cin >> T >> L >> R;
        L--;
        if(T == 1) {
            seg.apply(L, R, true);
        } else {
            auto tmp = seg.prod(L, R);
            cout << tmp.inv << endl;
        }
    }
    return 0;
}

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

int main() {
    cout.tie(0)->sync_with_stdio(0);
    using ldouble = long double;
    const ldouble pi = 4 * atan(1.0);
    ldouble A, B, H, M;
    cin >> A >> B >> H >> M;
    ldouble ang_a = 2.0 * pi * (H/12.0 + M/(12.0 * 60.0));
    ldouble ang_b = 2.0 * pi * (M/60.0);
    ldouble ang = abs(ang_a - ang_b);
    cout << setprecision(20);
    cout << sqrt(A*A + B*B - 2.0 * A * B * cos(ang)) << '\n'; 
}


Measured memory_bytes: 4084
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, M, X = MAP()
CA = [LIST() for _ in range(N)]

ans = INF

for x in product([0, 1], repeat=N):
	#print(x)
	skill = [0]*M
	cost = 0
	for i in range(N):
		if x[i] == 1:
			cost += CA[i][0]
			for j in range(M):
				skill[j] += CA[i][j+1]
	#print(skill, cost)
	if all(p >= X for p in skill):
		ans = min(ans, cost)

if ans == INF:
	print(-1)
else:
	print(ans)


Measured memory_bytes: 10480
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
// #pragma GCC optimize("O2")
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef multiset <ll> mms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define deb(x) cout << #x << " " << x << endl;
#define ff first
#define ss second
#define pb(v) push_back(v)
#define lb(v) lower_bound(v)
#define ub(v) upper_bound(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b) {
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s) {
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v) {
	forl(i,v.size()) cout<<v[i]<<" ";
	cout<<"\n";
}
void pa(ll *v, ll size) {
	forl(i,size) cout<<v[i]<<" ";
	cout<<"\n";
}
void removeDups(mv &v) {
	sort(all(v));
	mv::iterator it = unique(v.begin(), v.end());
	v.resize(distance(v.begin(), it));
}
inline ld kthRoot(ld n, ll k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}
ll power(ll x, ll y, ll p) {
	ll res=1;
	x=x%p;
	while(y>0) {
		if(y&1) res = (res*x)%p;
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x, ll mod) {
	if(x>=mod) x%=mod;
}

ll mod = 1e9 + 7;

ll arr[102];
bool checkValidity(ll a, ll b, ll c) { 
    if (a + b <= c || a + c <= b || b + c <= a) 
        return false; 
    else
        return true; 
}
void thisIsMain() {
	ll n;
	cin>>n;
	forl(i,n) cin>>arr[i];
	sort(arr, arr + n);
	ll ans = 0;
	forl(i,n) for(ll j=i + 1;j<n;j++) for(ll k=j+1;k<n;k++) ans += (arr[i] != arr[j] && arr[j] != arr[k] && checkValidity(arr[i], arr[j], arr[k]));
	cout<<ans<<"\n";
}

int main(void)
{
	fastio
	ll t = 1;
	// cin>>t;
	while(t--) thisIsMain();
	return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int a, b;
  cin >> a >> b;
  int s = 1;
  int t = 0;
  while (s < b) {
    s += (a - 1);
    t++;
  }
  cout << t << endl;
}

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using vl = vector<ll>;

int main() {
  ll n;
  cin >> n;
  vl x(n);
  rep(i, n) cin >> x[i];
  ll l, q;
  cin >> l >> q;
  vector<vl> r(20, vl(n));
  rep(i, n) r[0][i] = upper_bound(all(x), x[i] + l) - x.begin() - 1;
  rep(k, 19) rep(i, n) r[k + 1][i] = r[k][r[k][i]];
  rep(_, q) {
    ll a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    a--;
    b--;
    ll ans = 1;
    for(ll k = 19; k >= 0; k--)
      if(r[k][a] < b) {
        a = r[k][a];
        ans += 1 << k;
      }
    cout << ans << '\n';
  }
}

Measured memory_bytes: 20364
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/7/ALDS1_7_D
# 難しい 解き方は図を参照
import sys
sys.setrecursionlimit(2**20)  # 再帰回数上限の向上 かなり多くしないとREになる


class Node:
    def __init__(self,
                 parent=None,
                 left=None,
                 right=None):
        self.parent = parent
        self.left = left  # 左の子ノード
        self.right = right  # 右の**子**


# 答えの列を作るときに必要
def post_parse(T, u, post_ls):
    if u == None:
        return
    post_parse(T, T[u].left, post_ls)
    post_parse(T, T[u].right, post_ls)
    post_ls.append(u)


# データの読み込み
N = int(input())
pre_ls = list(map(int, input().split()))
in_ls = list(map(int, input().split()))
root_pos = 0
ROOT = pre_ls[root_pos]
T = {key+1: Node() for key in range(N)}

# 再帰関数で復元する


def rec(l: int, r: int, root_pos: int):
    '''
    l,rはin_lsに対して範囲を指定するidx
    l:rであり、半開区間
    root_posはpre_lsにおけるrootのidx。本では木の左下から復元するのを前提に実装していたが、
    ここではどういう順番で復元しても大丈夫なように実装する。
    '''
    # 即時終了条件
    if r-l <= 1:  # 指定区間が1ノード以下になったらおかしいので終了
        return
    root = pre_ls[root_pos]
    mid = in_ls.index(root)  # rootを持つ要素のidxを返す

    # 木の復元
    # 左部分木がある場合
    if mid != l:
        root_pos_left = root_pos+1  # preorderにおいては左部分木のroot_posは必ず現在の位置の隣になる
        T[pre_ls[root_pos]].left = pre_ls[root_pos_left]
        T[pre_ls[root_pos_left]].parent = pre_ls[root_pos]
        # 次の探索へ
        rec(l, mid, root_pos_left)
    # 右部分木がある場合
    if mid != r-1:  # rは一つ先を指定していることに注意すると気付ける
        root_pos_right = root_pos+1+mid-l  # 右部分木のrootは、左部分木がおわった直後にある
        T[pre_ls[root_pos]].right = pre_ls[root_pos_right]
        T[pre_ls[root_pos_right]].parent = pre_ls[root_pos]
        rec(mid+1, r, root_pos_right)


# 木の復元
rec(0, N, root_pos)

# # print(T)
# for i in range(N):
#     print(T[i+1].parent, T[i+1].left, T[i+1].right)
# post orderの作成
post_ls = []
post_parse(T, ROOT, post_ls)

print(*post_ls)



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

string N;

long dp[20][1000][2][2];

long gochiusa(int now, int back_three, bool if_gochiusa, bool if_less){
    if(dp[now][back_three][if_gochiusa][if_less] != -1){
        return dp[now][back_three][if_gochiusa][if_less];
    }else if(now == N.size()){
        return dp[now][back_three][if_gochiusa][if_less] = if_gochiusa;
    }else if(if_gochiusa && if_less){
        return dp[now][back_three][if_gochiusa][if_less] = gochiusa(now + 1, 0, true, true) * 10;
    }else if(if_gochiusa){
        return dp[now][back_three][if_gochiusa][if_less] = gochiusa(now + 1, 0, true, true) * (N[now] - '0') + gochiusa(now + 1, 0, true, false);
    }else if(back_three / 10 == 51 && if_less){
        long ans = 0;
        for(int i = 0; i < 10; i++){
            if(i == 3){
                ans += gochiusa(now + 1, 0, true, true);
            }else{
                ans += gochiusa(now + 1, back_three % 100 * 10 + i, false, true);
            }
        }
        return dp[now][back_three][if_gochiusa][if_less] = ans;
    }else if(back_three / 10 == 51 && N[now] == '3'){
        long ans = 0;
        for(int i = 0; i < 3; i++){
            ans += gochiusa(now + 1, back_three % 100 * 10 + i, false, true);
        }
        return dp[now][back_three][if_gochiusa][if_less] = ans + gochiusa(now + 1, 0, true, false);
    }else if(back_three / 10 == 51){
        long ans = 0;
        for(int i = 0; i < N[now] - '0'; i++){
            if(i == 3){
                ans += gochiusa(now + 1, 0, true, true);
            }else{
                ans += gochiusa(now + 1, back_three % 100 * 10 + i, false, true);
            }
        }
        return dp[now][back_three][if_gochiusa][if_less] = ans + gochiusa(now + 1, back_three % 100 * 10 + N[now] - '0', false, false);
    }else if(if_less){
        long ans = 0;
        for(int i = 0; i < 10; i++){
            ans += gochiusa(now + 1, back_three % 100 * 10 + i, false, true);
        }
        return dp[now][back_three][if_gochiusa][if_less] = ans;
    }else{
        long ans = 0;
        for(int i = 0; i < N[now] - '0'; i++){
            ans += gochiusa(now + 1, back_three % 100 * 10 + i, false, true);
        }
        return dp[now][back_three][if_gochiusa][if_less] = ans + gochiusa(now + 1, back_three % 100 * 10 + N[now] - '0', false, false);
    }
}

int main(){
    cin >> N;
    for(int i = 0; i < 20; i++){
        for(int j = 0; j < 1000; j++){
            for(int k = 0; k < 2; k++){
                for(int l = 0; l < 2; l++){
                    dp[i][j][k][l] = -1;
                }
            }
        }
    }
    cout << gochiusa(0, 0, false, false) << endl;
}



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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;
const ll llinf = LLONG_MAX;
const ull ullinf = ULLONG_MAX;

int d,g;
int p[11],c[11];
const int N = 5500 + 100000 + 1;
int dp[11][5500 + 100000 + 1];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  FILE *stream2;
  stream1 = freopen("in", "r", stdin);
  stream2 = freopen("out", "w", stdout);
  if (stream1 == NULL) return 0;
  if (stream2 == NULL) return 0;
#endif
  cin >> d >> g;
  for (int i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  for (int i = 0; i < 11; i++) {
    for (int j = 0; j < N; j++) {
      dp[i][j] = -1;
    }
  }
  dp[0][0] = 0;
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < N; j++) {
      if (dp[i][j] == -1) continue;
      if (dp[i + 1][j] == -1) dp[i + 1][j] = dp[i][j];
      else dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      for (int k = 1; k <= p[i]; k++) {
        if (k == p[i]) {
          if (dp[i + 1][j + k * (i + 1) + c[i]] == -1) dp[i + 1][j + k * (i + 1) + c[i]] = dp[i][j] + k; 
          else dp[i + 1][j + k * (i + 1) + c[i]] = min(dp[i + 1][j + k * (i + 1) + c[i]], dp[i][j] + k);
          continue;
        }
        if (dp[i + 1][j + k * (i + 1)] == -1) dp[i + 1][j + k * (i + 1)] = dp[i][j] + k;
        else dp[i + 1][j + k * (i + 1)] = min(dp[i + 1][j + k * (i + 1)], dp[i][j] + k);
      }
    }
  }
  int ans = INT_MAX;
  for (int i = g / 100; i < N; i++) {
    if (dp[d][i] == -1) continue;
    ans = min(ans, dp[d][i]);
  }
  cout << ans << endl;
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  fclose(stream2);
#endif
  return 0;
}

Measured memory_bytes: 4736
a=input()
if a=="SUN":
    print(7)
elif a=="MON":
    print(6)
elif a=="TUE":
    print(5)
elif a=="WED":
    print(4)
elif a=="THU":
    print(3)
elif a=="FRI":
    print(2)
else:
    print(1)


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  rep(i, M) {
    cin >> L[i] >> R[i];
  }
  int Lf = L[0];
  int Rf = R[0];
  rep(i, M) {
    Lf = max(Lf, L[i]);
    Rf = min(Rf, R[i]);
  }
  int ans = Rf - Lf +1;
  if (ans < 0) {
    cout << 0 << endl;
  }
  else {
    cout << ans << endl;
  }
}

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

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;

const int mod = (int)1e9 + 7;
const int MAXN = 1e5+12;

string s;

int main() {

    NoType;

    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '?') {
            s[i] = 'D';
        }
    }

    cout << s;

return 0;
}


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

int main(void){
    int n;
    int a[200001];
    scanf("%d", &n);
    
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        //printf("%d\n",a[i]);
    }
    
    long long int ans=0;
    
    int nowa=a[0];
    for(int i=1;i<n;i++){
        if(nowa>a[i]){
            ans+=-a[i]+nowa;
            //printf("%lld %d %d\n",ans,nowa,a[i]);
        }else{
            nowa=a[i];
        }
    }
    
    printf("%lld",ans);
}


Measured memory_bytes: 2456
n, m = map(int, input().split())
s = []
a = []
for _ in range(n):
    x = input()
    if '#' in x:
        s.append(x)
for j in range(m):
    res = False
    for x in s:
        if x[j] == '#':
            res = True
            break
    a.append(res)
s = ["".join(x[i] for i in range(m) if a[i]) for x in s]

for x in s:
    print(x)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
typedef pair<int,int> P;
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 (b<a) { a = b; return 1; } return 0; }

int dist[1101010][3];
signed main(){
  int n,m;
  cin >> n >> m;
  vvint to(n);
  rep(i,0,m){
    int a,b;
    cin >> a >> b;
    a--;b--;
    to[a].push_back(b);
  }
  rep(i,0,n){
    rep(j,0,3){
      dist[i][j] = INF;
    }
  }
  int sv,tv;
  cin >> sv >> tv;
  sv--;tv--;
  dist[sv][0] = 0;
  queue<P> que;
  que.push(P(sv,0));
  while(!que.empty()){
    P key = que.front();
    int val = key.first;
    int num = key.second;
    que.pop();
    for(int p:to[val]){
      int nnum = (num+1)%3;
      if(dist[p][nnum] == INF){
        dist[p][nnum] = dist[val][num]+1;
        que.push(P(p,nnum));
      }
    }
  }
  if(dist[tv][0] == INF) cout << -1 << endl;
  else cout << dist[tv][0]/3 << endl;
}

Measured memory_bytes: 9856
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] xs = new long[n];
            long sum = 0;
            for (int i = 0; i < n; ++i) {
                int tmp = in.nextInt();
                sum += tmp;
                xs[i] = tmp + ((i > 0) ? xs[i - 1] : 0);
            }

            long minDiff = Long.MAX_VALUE;
            for (int i = 0; i < n - 1; ++i) {
                minDiff = Math.min(minDiff, Math.abs(xs[i] - (sum - xs[i])));
            }
            out.println(minDiff);
        }

    }
}



Measured memory_bytes: 65608
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890l
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
#define rep0(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(ll kk = l1; kk <= l2; kk++)
#define foritr(itr, A) for(set<ll>::iterator itr = A.begin(); itr != A.end(); itr++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define cr(x) cerr << #x << " = " << x << "\n";
#define crA(x, A) cerr << #x << " = " << A[x] << "\n";
#define spacing if(db)cout << " ";
#define space " "
#define cbr cout << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)));
#define bg(ms) (*ms.begin())
#define ed(ms) (*prev(ms.end(), 1))
#define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c)))
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, A[MAXN];
int main()
{
	FAST
	cin >> n;
	FOR(i,0,n) cin >> A[i];
	ll ans = A[0];
	FOR(i,0,n) ans = __gcd(ans, A[i]);
	cout << ans << "\n";
}


Measured memory_bytes: 1024
//In The Name Of GOD

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll mod = 998244353;
const ll inf = 2000000000;
const ll infll = (ll)2*1000*1000*1000*1000*1000*1000;
const ll maxn = 100*1000+1;
#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);

int sz[maxn];
bool mark[maxn];

int main(){
  IO;
  int n,m;
  cin >> n >> m;
  mark[1]=true;
  for(int i=1;i<=n;i++)sz[i]=1;
  for(int i=0;i<m;i++){
    int u,v;
    cin >> u >> v;
    if(mark[u])mark[v]=true;
    if(sz[u]==1)mark[u]=false;
    sz[u]--;
    sz[v]++;
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    ans+=mark[i];
  }
  cout<<ans;
}


Measured memory_bytes: 768
fn main() {    
    let mut s = String::new();    
    std::io::stdin().read_line(&mut s).ok();    
    let (n,a,b) = {                                
        let mut x = s.split_whitespace();    
        let n: i32 = x.next().unwrap().parse().unwrap();    
        let a: i32 = x.next().unwrap().parse().unwrap();    
        let b: i32 = x.next().unwrap().parse().unwrap();    
        (n,a,b)    
    };    
    if n*a <= b {    
        println!("{}",n*a);    
    }else{    
        println!("{}",b);    
    }    
}       

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define endl "\n"
#define int ll
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define all( x ) x.begin(), x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef unsigned long long ull;

const int inf = 1e9 + 5;
const long double PI = 3.141592653589793;

void solve(){
  int a, b;
  cin>>a>>b;
  cout<<a*b<<endl;
  return;
}  
signed main(){
  fast;
  int t;
  //cin>>t;
  t = 1;
  while(t--){
    solve();
  }
}
/*
░░░░░░░░░░▄▄░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░██▀█▄░░▄██▀░░░░▄██▄░░░░░░░░░░░
░░░░░░░░██▄▄▄████████▄▄█▀░▀█░░░░░░░░░░░
░░░░░░░▄██████████████████▄█░░░░░░░░░░░
░░░░░░▄██████████████████████░░░░░░░░░░
░░░░░▄████████▀░▀█████████████░░░░░░░░░
░░░░░███████▀░░░░▀████████████▄░░░░░░░░
░░░░██████▀░░░░░░░░▀███████████▄▄▄▀▀▄░░
░▄▀▀████▀░░░▄▄░░░░░░░░░████████░░░░░█░░
█░░░▀█▀█░░░░▀▀░░░░░░██░░███░██▀░░░░▄▀░░
█░░░░▀██▄░░░▄░░░▀░░░▄░░░███░██▄▄▄▀▀░░░░
░▀▄▄▄▄███▄░░▀▄▄▄▀▄▄▄▀░░░███░█░░░░░░░░░░
░░░░░░████▄░░░░░░░░░░░░▄██░█░░░░░░░░▄▀▀
░░░░░░███▀▀█▀▄▄▄▄▄▄▄▄▄▀█████░░░░░░▄▀░░▄
░░░░░░█▀░░█░▀▄▄▄▄▄▄▄▄▄▀░███░█▀▀▀▄▀░░▄▀░
░░░░░░░░░▄▀░░░░░░░░░░░░░▀█▀░░█░░░░█▀░░░
░░░░░░░░░█░░░█░░░░░░░░░░░░░░░█░░░░░█░░░
░░░░░░░░░█▄▄█░▀▄░░█▄░░░░░░░░█░░▄█░░█░░░
░░░░░░░░░▀▄▄▀░░█▀▀█░▀▀▀▀█▀▀█▀▀▀▀█░█░░░░
hOi!!
I'm TemMie
*/

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

using namespace std;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    long long n,sum = 0,a[105];
    cin >> n;
    for (long long i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    long long tb = sum/n;
    long long t = sum % n;
    if (t > n/2) tb++;
    long long ans = 0;
    for (long long i = 1; i <= n; i++)
        ans = ans + (a[i] - tb)*(a[i] - tb);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
                                                                                                
  
long long gcd( long long x, long long y ){

               if( y == 0 ) return x;

               long long z = x % y;

               return gcd( y, z );

               }


int main(void){
                                                                                                
   
    long long n, i;
   
    long long t, l;

    long long a[101];
   
      
    scanf("%lld", &n);
   

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

         scanf("%lld", &a[i] );

         }

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

         a[i + 1] = a[i] / gcd( a[i], a[i + 1] ) * a[i + 1];

         }



    printf("%lld\n", a[n - 1] );


    return 0;
                                                          
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;
void solve(){
    int n,k,ans=0,a;
    cin >> n>> k;
    fol(i,n){
        cin >> a;
        ans += min(2*(a),2*(k-a));
    }
    cout << ans << endl;
}

int main(){
/*/Debug by file input
    ifstream fin("input");
    cin.rdbuf(fin.rdbuf());// */
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  string S; cin >> S;
  int N = sz(S);
  map<char,int> mp;
  rep(i,N){
    mp[S[i]]++;
  }
  for(auto m:mp){
    if(m.second%2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256