akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

class SegmentTree {
private:
    int n;
    vector<ll> node;
    ll INF = (1ll << 31) - 1;
public:
    SegmentTree(int N) {
        n = 1;
        while (n < N) n *= 2;
        node.resize(2 * n - 1, 0);
    }

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

    ll query(int a, int b, int k, int l, int r) {
        if (b <= l || r <= a) return 0;
        if (a <= l && r <= b) return node[k];
        ll sum_l = query(a, b, 2 * k + 1, l, (l + r) / 2);
        ll sum_r = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return sum_l + sum_r;
    }

};

int main() {
    int n, q;
    cin >> n >> q;
    ll com, x, y;
    SegmentTree st(n);
    int N = 1;
    while (N < n) N *= 2;
    for (int i = 0; i < q; i++) {
        cin >> com >> x >> y;
        if (com == 0) {
            st.update(x - 1, y);
        } else {
            cout << st.query(x - 1, y, 0, 0, N) << "\n";
        }
    }    
    return 0;
}



Measured memory_bytes: 4880
#include<bits/stdc++.h>
#define ll long long
#define ULL unsigned long long
#define nl "\n"
#define mod 1000000007
#define pb push_back
#define po pop_back
#define f(i,x,n) for(ll i=x; i<n; i++)
#define all(c) c.begin(),c.end()
#define unique_sort(x) sort(all(x)),x.resize(distance(x.begin(),unique(all(x))))
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b, c))
using namespace std;
double pi=3.141592653589793238462643383279;
ll min(ll a,ll b)
{
 return a<b?a:b;
}
ll max(ll a, ll b)
{
    return a>b?a:b;
}
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return a.first<b.first;
}
int main()
{
    ll n,w;
    cin>>n>>w;
    std::vector<pair<ll,ll> > v;
    f(i,0,n)
    {
        ll x,y;
        cin>>x>>y;
        v.pb(make_pair(x,y));
    }
    sort(all(v),comp);
    ll dp[n+1][w+1];
    f(i,0,n+1)
    {
        f(j,0,w+1)
        {
            if(i==0||j==0)
            dp[i][j]=0;
            else if(j<v[i-1].first)
            dp[i][j]=dp[i-1][j];
            else
            dp[i][j]=max(dp[i-1][j],v[i-1].second+dp[i-1][j-v[i-1].first]);
        }
    }
    cout<<dp[n][w]<<nl;

  return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 x) : x(x) {
    if (x > P || x < 0) { cerr << "Invalied FiniteField!" << endl; exit(1); }
  }
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

ostream& operator<<(ostream& s, const FiniteField& x) { s << x.Value(); return s; }

FiniteField Combination(int a, int b) {
  FiniteField r = 1;
  for (int k = 0; k < b; k++) {
    r *= (a - k);
    r /= (1 + k);
  }
  return r;
}

FiniteField Solve() {
  int n;
  cin >> n;
  if (n <= 4) return 0;

  FiniteField r = 0;
  for (int a = 0; a <= 11; a++) {
    if (n - 5 - a < 0) continue;
    if ((n - 5 - a) % 2 == 1) continue;
    int b = (n - 5 - a) / 2;
    r += Combination(11, a) * Combination(b + 15, 15);
  }
  return r;
}

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

  int num_cases;
  cin >> num_cases;
  for (int case_id = 0; case_id < num_cases; case_id++) {
    cout << Solve() << endl;
  }
}

Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;

double before_degree = 0;;

int main(void){

    int n;
    while(cin >> n,n != 0){

        int ans = 0,tmp;
        vector<int> num(5010,0);
        for(int i = 0;i < n;i++){
            cin >> num[i];
        }
        vector<int> dp(5010,0);
        dp[0] = num[0];
        ans = dp[0];
        for(int i = 1;i < n;i++){
            dp[i] = max(num[i],dp[i-1]+num[i]);
            ans = max(ans,dp[i]);
        }


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



Measured memory_bytes: 3016
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

int n, i, j;
ll a[maxN];
vector< pair<ll, int> > ord;

int mini;
ll ans[maxN];

int main()
{
  //  freopen("test.in","r",stdin);

    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        ord.pb(mp(a[i], i));
    }

    sort(ord.begin(), ord.end());
    reverse(ord.begin(), ord.end());

    mini = n + 10;
    for (i = 0; i < ord.size(); i = j) {
        for (j = i; j < ord.size(); j++) {
            if (ord[i].first != ord[j].first) break;
            mini = min(mini, ord[j].second);
        }

        ll nxt = 0;
        if (j != ord.size()) nxt = ord[j].first;

        ans[mini] += (ord[i].first - nxt) * j;
    }

    for (i = 1; i <= n; i++)
        printf("%lld\n", ans[i]);



    return 0;
}


Measured memory_bytes: 4336
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DEBUG_OUTPUT_ENABLED 1
	#define DBG(X) dout << #X << "=" << (X) << '\n';
	#define SAY(X) dout << (X) << '\n';
#else
	#define DEBUG_OUTPUT_ENABLED 0
	#define DBG(X) 42;
	#define SAY(X) 42;
#endif

#define dout   ___debug::instance

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const multiset<T>& v) { for(auto el: v) cout << el << " "; return os; }
namespace ___debug {
	struct DebugStream {
		private:
			bool is_first;
		public:
			DebugStream(bool _is_first): is_first(_is_first) {}
			template<typename T> DebugStream operator<<(const T& value) const {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				cout << value;
				return DebugStream(false);
			};

			template<typename T> DebugStream printArray(T* l, T* r) {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				while(l != r) {
					cout << (*l);
					++l;
					if(l == r) {
						cout << '\n';
					} else {
						cout << ' ';
					}
				}
				return DebugStream(false);
			}
	};
	DebugStream instance(true);
};

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	ll x = fetch<ll>();
	ll cur = 100, answ = 0;
	while(cur < x) {
		cur += cur / 100;
		++answ;
	}
	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    ll n,t;
    cin>>n>>t;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    ll prof=0,buy=a[0];
    for(int i=1;i<n;i++){
        prof=max(prof,a[i]-buy);
        buy=min(buy,a[i]);
    }
    ll ans=0;
    set<ll> st;
    st.insert(a[0]);
    for(int i=1;i<n;i++){
        ll tgt=a[i]-prof;
        if(st.count(tgt)){
            ans++;
        }
        st.insert(a[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5760
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
import java.math.*;  
public class Main
{ 
    //By shwetank_verma
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    static int mod=1000000007;
    static boolean primes[]=new boolean[1000007];
    
    static boolean seive(int n){
        Arrays.fill(primes,true);
        primes[0]=primes[1]=false;
        for(int i=2;i*i<=n;i++){
            if(primes[i]==true){
                for(int p=i*i;p<=n;p+=i){
                    primes[p]=false;
                }
            }
        }
        if(n<1000007){
            return primes[n];
        }
        return false;
        
    }
    static int gcd(int a,int b){
        if(b==0)
        return a;
        return gcd(b,a%b);
    }
    static long GCD(long a,long b){
        if(b==0)
        return a;
        return GCD(b,a%b);
    }
    
  
    public static void main(String[] args) 
    { 
        FastReader sc=new FastReader(); 
        try{
           
                int t=sc.nextInt();
                int cntac=0;
                int cntwa=0;
                int cnttle=0;
                int cntre=0;
                while(t-->0){
                String str=sc.next();
                if(str.equals("AC")==true)
                	cntac++;
                else if(str.equals("RE")==true)
                	cntre++;
                else if(str.equals("WA")==true)
                	cntwa++;
                else if(str.equals("TLE")==true)
                	cnttle++;
                
                
        
                }
                System.out.println("AC x "+cntac);
                System.out.println("WA x "+cntwa);
                System.out.println("TLE x "+cnttle);
                System.out.println("RE x "+cntre);
           
            
        }catch(Exception e){
            return;
        }
    } 
}

Measured memory_bytes: 49344
#include<bits/stdc++.h>
#define p 1000000007
using namespace std;
long long f[100010][15];
long long mod[100010];
int main()
{
	string s;
	cin>>s;
	memset(mod,0,sizeof(mod));
	memset(f,0,sizeof(f));
	mod[0]=1;
	for(int i=1;i<=100000;i++)
	mod[i]=mod[i-1]*10%13;
	if(s[0]=='?')
	{
		for(int i=0;i<=9;i++)
		f[0][(i*mod[s.length()-1])%13]=1;
	}
	else f[0][(s[0]-'0')*mod[s.length()-1]%13]=1;
	for(int i=1;i<s.length();i++)
	{
		if(s[i]!='?')
		for(int j=0;j<13;j++)
		f[i][j]=f[i-1][(j+13-(s[i]-'0')*mod[s.length()-i-1]%13)%13],f[i][j]%=p;
		else
		for(int j=0;j<=9;j++)
		for(int k=0;k<13;k++)
		f[i][k]+=f[i-1][(k+13-j*mod[s.length()-i-1]%13)%13],f[i][k]%=p;
	}
	cout<<f[s.length()-1][5];
}

Measured memory_bytes: 12928
void main(){
	string s = readln().chomp();
	writeln(s.count("A")%3==0? "No": "Yes");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2664
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <tuple>

int main()
{
	int s;
	std::cin >> s;

	std::unordered_map<int ,int> a;

	a.insert({s, 1});
	int ai = s;
	for (int i = 2;; ++i) {
		if (ai % 2 == 0)
			ai = ai / 2;
		else
			ai = ai * 3 + 1;
		auto it = a.find(ai);
		if (it != a.end()) {
			std::cout << i << "\n";
			return 0;
		}
		a.insert({ai, i});
	}
	return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  

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

  ll dp[2][1000002];
  
  rep(i, N.length())
  {
    int x = N[N.length() - 1 - i] - '0';
    if(i == 0)
    {
      dp[0][i] = x;
      dp[1][i] = 10 -x;
    }
    else
    {
      dp[0][i] = min(dp[0][i-1] + x, x+1 + dp[1][i-1]);
      dp[1][i] = min(dp[0][i-1] + 10 - x, dp[1][i-1] + 9 -x);
    }
  }
  
  ll ret = min(dp[0][N.length() - 1], 1 + dp[1][N.length() - 1]);
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 17028
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            int C = int.Parse(Console.ReadLine());
            int D = int.Parse(Console.ReadLine());
            int E = int.Parse(Console.ReadLine());

            int[] data = new int[5] { A, B, C, D, E };
            int ans = 0;
            int min = 10;
            foreach (int item in data)
            {
                
                int r = item % 10;
                if (r == 0)
                {
                    ans += item;
                }
                else
                {
                    ans += (item / 10) * 10 + 10;
                    if (r < min||min==0) min = r;
                }
                
            }

            Console.WriteLine(ans-(10-min));
        }



        private static int[] Read(string input)
        {
            string[] inputs = input.Split(' ');
            int num = inputs.Length;
            int[] ints = new int[num];
            for (int i = 0; i < num; i++)
            {
                ints[i] = int.Parse(inputs[i]);
            }
            
            return ints;
        }


    }
}


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

int main() {
  int N,W;
  cin >> N >> W;
  int w[N], v[N];
  REP(i,N) cin >> w[i] >> v[i];

  int mxV = 1000 * N;
  int dp[N+1][mxV+1];
  REP(i,N+1) REP(j,mxV+1) dp[i][j] = 1001001001;
  dp[0][0] = 0;

  REP(i,N) REP(j,mxV+1) {
    dp[i+1][j] = dp[i][j];
    if (j-v[i] >= 0 && (dp[i][j-v[i]]+w[i]) <= W) {
      dp[i+1][j] = min(dp[i+1][j],dp[i][j-v[i]]+w[i]);
    }
  }

  int ans = 0;
  REP(i,mxV+1) if (dp[N][i] <= W) ans = i;
  cout << ans << endl;
}

Measured memory_bytes: 39680
#!/usr/bin/env python3
from collections import defaultdict
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def LIR(n):
    res = [None] * n
    for i in range(n):
        l, r = map(int, input().split())
        res[i] = (l-1, r-1, i)
    return res

#solve
def solve():
    n, q = LI()
    c = LI()
    lr = LIR(q)
    ans = [None] * q
    lr.sort(key=lambda x: x[1])
    dp = [-1] * (max(c) + 1)
    bit = [0] * (n + 1)
    def add(i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= n:
            bit[x - 1] += w
            x += x & -x
        return
    def sum(i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += bit[x - 1]
            x -= x & -x
        return res
    t = 0
    def f(t):
        l, r, j = lr[t]
        xr = sum(r)
        xl = sum(l-1)
        tmp = xr - xl
        ans[j] = tmp
        
    for i in range(n):
        ci = c[i]
        l = dp[ci]
        add(i, 1)
        dp[ci] = i
        if l != -1:
            add(l, -1)
        while t < q and lr[t][1]<= i:
            f(t)
            t += 1
        if t == q:
            break
    for ai in ans:
        print(ai) 
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 176664
#include<bits/stdc++.h>
#define md 998244353
using namespace std;
string s;
long long red[4005],  mxred[4005], mnred[4005], dp[4005], ans;
int u;
int main(){
  cin >> s;
  for(int i = 1; i <= s.size(); i++){
   u += '2' - s[i-1];
   mxred[i] = min(u, i);
   mnred[i] = max(0, u - i);
  }
  for(int i = s.size() + 1; i <= s.size()*2; i++){
    mxred[i] = min(u, i);
    mnred[i] = max(0, u + i - (int)s.size()*2);
  }
  dp[0] = 1;
  for(int i = 1; i <= s.size()*2; i++){
    for(int j = i; j >= 0; j--){
      dp[j] = (dp[j] + (j ? dp[j-1] : 0)) % md;
      if(mxred[i] < j || mnred[i] > j) dp[j] = 0;
      if(i == s.size()*2){
        ans = (ans + dp[j]) % md;
      }
    }
  }
  printf("%lld\n", ans);
}


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

int main() {
  long long A;
  string S;
  cin >> A >> S;
  int B = 0;
  for (int i=0; i<4; i++) {
    if (i == 1) continue;
    B *= 10;
    B += S[i]-'0';
  }
  long long ans = A*B;
  cout << ans/100 << endl;
  return 0;
}


Measured memory_bytes: 3624
c = [4,1,4,1,2,1,2,1]
readlines.each do |l|
  p = l.split.map(&:to_i)
  ans = 8.times.map{ c=c.rotate }.sort do |a,b|
    t = (a.zip(p).map{|i,j| [i-j,0].max}.inject(:+) <=>
         b.zip(p).map{|i,j| [i-j,0].max}.inject(:+))
    t==0 ? a.join.to_i <=> b.join.to_i : t
  end.first
  puts ans.join(" ")
end

Measured memory_bytes: 6120
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=100005;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll a,b,c,ans;
int main()
{
	cin>>a>>b>>c;
	if(c>a+b) ans=2*b+a+1;
	else ans=b+c;
	cout<<ans;
}

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

const long long mod = 1e9 + 7;

long long n, a, b;
vector < long long > fact;
map < int, long long > rfact;

long long add_mod (long long x, long long y) {
	return (x + y) % mod;
}

long long mul_mod (long long x, long long y) {
	return (x * y) % mod;
}

long long sub_mod (long long x, long long y) {
	return (x + mod - y) % mod;
}

long long pow_mod (long long x, long long y) {
	long long res = 1LL, t = x;
	while (y) {
		if (y & 1)
			res = mul_mod(res, t);
		t = mul_mod(t, t);
		y >>= 1;
	}
	return res;
}

long long div_mod (long long x, long long y) {
	return mul_mod(x, pow_mod(y, mod - 2));
}

long long my_c_mod (long long k) {
	return div_mod(rfact[n - k + 1], fact[k]);
}

void calc () {
	fact.assign(max(a, b) + 1, 1LL);
	for (long long i = 1; i <= max(a, b); ++i) 
		fact[i] = mul_mod(fact[i - 1], i);
	rfact[n] = n;
	for (long long i = 1; i <= max(a, b); ++i)
		rfact[n - i] = mul_mod(rfact[n - i + 1], n - i);
}

signed main () {
	cin >> n >> a >> b;
	calc();
	cout << sub_mod(sub_mod(pow_mod(2LL, n), 1LL), add_mod(my_c_mod(a), my_c_mod(b)));
}


Measured memory_bytes: 14336
from collections import deque

def bfs(grid, costs, queue, wall, res):
    ans = 0
    dxy = [(1,0), (-1,0), (0,1), (0,-1)]
    while res:
        y,x = queue.popleft()
        for dy, dx in dxy:
            y_,x_ = y+dy,x+dx
            if grid[y_][x_] == wall:
                continue
            queue.append([y_,x_])
            grid[y_][x_] = wall
            costs[y_][x_] = costs[y][x] + 1
            ans = max(ans, costs[y_][x_])
            res -= 1
    return ans

import sys
input = sys.stdin.readline
H,W = map(int, input().split())
wall = '#'
queue = deque([])
edges = [wall for _ in range(W+2)]
grid = [edges]
costs = [[0] * (W+2)]

for i in range(1,H+1):
    S = [wall]+list(input().strip())+[wall]
    for j in range(1,W+1):
        if S[j] == wall:
            queue.append([i,j])
    grid.append(S)
    costs.append([0] * (W+2))
grid.append(edges)
print(bfs(grid, costs, queue, wall, H*W - len(queue)))


Measured memory_bytes: 154844
#include <stdio.h>

int main(void)
{
	int i,x,y,z;
	for (i = 1; 1 ; i++)
	{
		scanf("%d %d", &x , &y);
		if (x == 0 && y == 0)
		{
			break;

		}else if (x > y)
		{
			z = x;
			x = y;
			y = z;
			/* code */
		}

		printf("%d %d\n",x,y);
		/* code */
	}

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int X,A;
    int counter = 1;
    cin >> X;
    int K = 360 / X;
    if (360 % X == 0)
        cout << K << endl;
    else {
        while(true){
            counter++;
            if ((counter * 360) % X == 0){
                cout <<  (counter * 360) / X << endl;
                break;
            }
        }
    }
    

}
    
     


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  vector<int> cost(n,1000000001);
  cost[0] = 0;
  rep (i, n) {
    cin >> h[i];
  }
  for (int i = 0; i < n ;i++) {
    for (int j = 1; j <= k ;j++) {
      if (i + j < n) cost[i+j] = min(cost[i+j], cost[i]+abs(h[i+j]-h[i]));
    }
  }
  cout << cost[n-1] << endl;
  return 0;
}


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

int main(){
	int a, b; cin >> a >> b;
	if (a <= b){
		cout << a << endl;
	}
	else{
		cout << (a - 1) << endl;
	}
	return 0;
}

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

#define ll long long

void solve()
{
    string s1;
    cin >> s1;
    ll sum=0;
    for(int i=0; s1[i]; ++i)
        sum+=(s1[i]-'0');
    sum%9 == 0 ? cout << "Yes\n" : cout << "No\n";
    
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("D:\\Codings\\CPP\\input.in", "r", stdin);
    freopen("D:\\Codings\\CPP\\output.in", "w", stdout);
    #endif

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

    int t=1;
    //cin >> t;
    while(t--)
        solve();
   
    return 0;
}


Measured memory_bytes: 3672
# sys.stdin.readline()
import sys
import math
input = sys.stdin.readline

x, y = input().split()
hex_x = int(x, 16)
hex_y = int(y, 16)
if hex_x > hex_y:
    ans = '>'
elif hex_x < hex_y:
    ans = '<'
else:
    ans = '='
print(ans)

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main()
{
	int sum=0,ave=0;
	int i;
	int n,m;
	
	for(i=0;cin >> n;++i)
	{
		char a;
		cin >> a >> m;
		sum+=n*m;
		ave+=m;
	}
	
	if(i!=0)
	{
		double a;
		a=double(ave)/i+0.5;
		ave=a;
		cout << sum << "\n" << ave << endl;
	}
	else
		cout << sum << "\n" << ave << endl;
}

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

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  int R, S, P;
  cin >> R >> S >> P;
  string T;
  cin >> T;
  
  vector<char> used(K, 'a');
  int score = 0;
  bool fin = false;
  int i = 0;
  while(!fin){
    for(int j = 0; j < K; j++){
      if(i + j == N){
        fin = true;
        break;
      }
      if(T[i + j] == 'r'){
        if(used[j] == 'r') used[j] = 'a';
        else{
          score += P;
          used[j] = 'r';
        }
      }else if(T[i + j] == 's'){
        if(used[j] == 's') used[j] = 'a';
        else{
          score += R;
          used[j] = 's';
        }
      }else{
        if(used[j] == 'p') used[j] = 'a';
        else{
          score += S;
          used[j] = 'p';
        }
      }
    }
    i += K;
  }
  
  cout << score << endl;
  
  return 0;
}

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

template <class T>
inline void read(T &res)
{
	res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	if (bo) res = ~res + 1;
}

template <class T>
inline T Max(const T &a, const T &b) {return a > b ? a : b;}

typedef long long ll;

const int N = 2e5 + 5, M = 4e6 + 5;

int n, a[N], add[N];
char s[M], op[N];
ll sum[N];

void work()
{
	int tot = 1, m; a[1] = 0;
	read(n); gets(s + 1);
	m = strlen(s + 1);
	for (int i = 1; i <= m; i++)
	{
		if (s[i] == ' ') continue;
		if (s[i] == '+' || s[i] == '-') op[tot++] = s[i], a[tot] = 0;
		else a[tot] = a[tot] * 10 + s[i] - '0';
	}
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
	add[n] = 0;
	for (int i = n - 1; i >= 1; i--) add[i] = op[i] == '-' ? 0 : add[i + 1] + 1;
	ll cur = a[1], ans = -1e18;
	for (int i = 1; i < n; i++)
		if (op[i] == '-') ans = Max(ans, cur - (sum[i + 1 + add[i + 1]]
			- sum[i]) + sum[n] - sum[i + 1 + add[i + 1]]), cur -= a[i + 1];
		else cur += a[i + 1];
	printf("%lld\n", Max(cur, ans));
}


int main()
{
	int T = 1;
	while (T--) work();
	return 0;
}

Measured memory_bytes: 5888
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int Ni =sc.nextInt();
		int[] A = new int[Ni];
		for(int n = 0;n < Ni; n++){
			int Nr = sc.nextInt();
			int Pr = sc.nextInt();
			int Nm = sc.nextInt();
			int Pm = sc.nextInt();
			int a = 0;
			
			if(Nm >= 5 && Pm >= 2){
				A[n] = (Nr * Nm / 10 * 8) + (Pr * Pm / 10 * 8);
				a = A[n];
			}else if(Nm >= 5 && Pm >= 0){
				A[n] = Nr * Nm + Pr * Pm;
				Pm = 2;
				a = (Nr * Nm / 10 * 8) + (Pr * Pm / 10 * 8);
			}else if(Nm >= 0 && Pm >= 2){
				A[n] = Nr * Nm + Pr * Pm;
				Nm = 5;
				a = (Nr * Nm / 10 * 8) + (Pr * Pm / 10 * 8);
			}else if(Nm <= 5 && Pm <= 2){
				A[n] = Nr * Nm + Pr * Pm;
				Nm = 5;
				Pm = 2;
				a = (Nr * Nm / 10 * 8) + (Pr * Pm / 10 * 8);
			}
			if(a < A[n] ){
		 		A[n] = a;
			}
		}
		for(int i = 0; i < Ni; i++){
			System.out.println(A[i]);
		}
	}
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 90000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;


int main(){
  ll N,X;cin >> N >> X;
  vector<ll> A(N);
  for(int i = 0;i < N;i++){
    cin >> A[i];
  }
  ll ans = 0;
  for(int i = 0;i < N-1;i++){
    if(A[i] > X){
      ans += A[i+1];
      ans += A[i]-X;
      A[i+1] = 0;
      continue;
    }else if(A[i]+A[i+1] > X){
      ans += A[i] + A[i+1] - X;
      A[i+1] -= A[i] + A[i+1] - X;
    }
  }
  cout << ans << endl;
}


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

#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl  "\n"

typedef long long int ll ;

void solve()
{
	ll a , b , c , d ;
	cin >> a >> b >> c >> d ;
	ll ans = -(1e9 * 1e9) - 1 ;
	for ( ll i : {a , b} )
	{
	 	 for ( ll j : {c , d} )
	 	 {	
			 ans = max(ans , i * j ) ;
		 }
	}
	cout << ans << endl ;
}  
int main()
{
	ios ;
	
    solve() ;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);




int main(){
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    deque<ll> d;
    rep(i,0,n-1){
        if(i==0){
            d.push_front(a[i]);
        }else{
            ll l=-1,r=d.size();
            ll mid;
            while(r-l>1){
                mid=(r+l)/2;
                if(d[mid]<a[i]){
                    l=mid;
                }else{
                    r=mid;
                }
            }
            if(l==-1){
                d.push_front(a[i]);
            }else{
                d[l]=a[i];
            }
        }
    }
    cout<<d.size()<<endl;
    
    
    
    return 0;
}




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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}

template <typename T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


int main() {
	ll a = -458;
	int A = 0, B = 0;
	ll ans  = 0;
	vector<ll> num;
	while (ans < pow(10, 13)  * 2) {
		ans = (a * a * a * a * a);
		num.push_back(ans);
		a++;
	}
	//cout << num.size();
	ll X;
	cin >> X;
	for (int i = 0; i < num.size(); i ++) {
		for (int j = 0; j < num.size(); j++) {
			if (num[i] - num[j] == X) {
				A = i - 458;
				B = j - 458;
				break;
			}
		}
	}
	cout << A << " " << B << endl;

	return 0;
}


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

using namespace std;

int main(){
  string s;

  getline(cin,s);
  for(int i=0;i<s.length();i++){
    if(s[i]=='a' && s[i+1]=='p' && s[i+2]=='p' && s[i+3]=='l' && s[i+4]=='e'){
      s[i]='p';
      s[i+1]='e';
      s[i+2]='a';
      s[i+3]='c';
      s[i+4]='h';
    }
    else if(s[i]=='p' && s[i+1]=='e' && s[i+2]=='a' && s[i+3]=='c' && s[i+4]=='h'){
      s[i]='a';
      s[i+1]='p';
      s[i+2]='p';
      s[i+3]='l';
      s[i+4]='e';
    }
  }

  cout<<s<<endl;
}


Measured memory_bytes: 2992
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  string s;

  cin>>k>>s;

  if(k>=s.size()) cout<<s<<endl;
  else{
    for(int i=0;i<k;i++) cout<<s[i];
    cout<<"..."<<endl;
  }

  return 0;
}

Measured memory_bytes: 3596
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
    auto N = readln.chomp.to!int;
    auto X = readln.split.map!(to!long).array;
    auto A = X[0..N];
    auto B = X[N..2*N];
    auto C = X[2*N..$];

    A.sort();
    C.sort();

    auto a_sum = new long[](N+1);
    auto c_sum = new long[](N+1);
    a_sum[0] = A.sum;
    c_sum[N] = C.sum;

    auto a_rbt = new RedBlackTree!(long, "a < b", true)();
    foreach (i; 0..N) a_rbt.insert(A[i]);

    foreach (i; 0..N) {
        long mn = a_rbt.front;
        a_sum[i+1] = a_sum[i];
        if (mn < B[i]) {
            a_sum[i+1] = a_sum[i+1] - mn + B[i];
            a_rbt.removeKey(mn);
            a_rbt.insert(B[i]);
        }
    }

    auto c_rbt = new RedBlackTree!(long, "a > b", true)();
    foreach (i; 0..N) c_rbt.insert(C[i]);

    foreach (i; iota(N-1, -1, -1)) {
        long mx = c_rbt.front;
        c_sum[i] = c_sum[i+1];
        if (mx > B[i]) {
            c_sum[i] = c_sum[i] - mx + B[i];
            c_rbt.removeKey(mx);
            c_rbt.insert(B[i]);
        }
    }

    long ans = - (1L << 60);
    foreach(i; 0..N+1) {
        ans = max(ans, a_sum[i] - c_sum[i]);
    }

    ans.writeln;
}


Measured memory_bytes: 35252
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    int a;
    cin>>a;
    vector<vector<int>> data(2, vector<int>(a));
    int sum=0;
    // 入力 (2重ループを用いる)
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < a; j++) {
        cin >> data.at(i).at(j);
        }
    }
    vector<int> s(a,0);
    vector<int> t(a,0);
    s.at(0)=data.at(0).at(0);
    t.at(0)=data.at(1).at(0);
    for(int i=1;i<a;i++){
        s.at(i)=s.at(i-1)+data.at(0).at(i);
        t.at(i)=t.at(i-1)+data.at(1).at(i);
    }
    rep(i,a){
        int p=s.at(i)+t.at(a-1);
        if(i!=0){
            p-=t.at(i-1);
        }
        //cout<<p<<endl;
        if(p>sum){
            sum=p;
        }
    }
    cout<<sum<<endl;
}



Measured memory_bytes: 256
chomp (my $n = readline ARGV);
my @l;
for (1..$n) {
  chomp (my ($t, $x, $y) = split / /, readline ARGV);
  push @l, [$t, $x, $y];
}
my ($pt, $px, $py) = (0, 0, 0);
while (my $l = shift @l) {
  my ($t, $x, $y) = @$l;
  my $dd = abs($x - $px) + abs($y - $py);
  my $dt = abs($t - $pt);
  say_no() if $dt < $dd;
  say_no() if ($dt - $dd) % 2;
  ($pt, $px, $py) = ($t, $x, $y);
}
print 'Yes';
sub say_no {
  print 'No';
  exit;
}

Measured memory_bytes: 34304
// Problem : gacha
// Contest : Virtual Judge - AtCoder
// URL : https://vjudge.net/problem/AtCoder-abc164_c
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    fast_io;
    int n; cin>>n; set<string> s;
    lp(i,0,n){
    	string t; cin>>t;
    	s.insert(t);
    }
    cout<<s.size();
}

Measured memory_bytes: 19252
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int dp[100001];

int go(int arr[],int n,int k)
{
    
    if(k==0)
        return 0;
        
    if(k<0)
        return 1;
    
    if(dp[k] != -1)
        return dp[k];

    
    int ans = 0;
    for(int i=1;i<=n;i++) 
    {
        if(k >= arr[i]) 
        {
            for(int j=1;j<=n;j++)
            {
                ans = go(arr,n,k-arr[i]-arr[j]); 
                if(ans == 0)
                    break;
            }
            if(ans == 1)
            {
                dp[k] = ans;
                return ans;
            }
        }
    }
    
    dp[k] = ans;
    return ans;
}

int main()
{
    int n,k;
    cin >> n >> k;
    
    int arr[n+1];
    for(int i=1;i<=n;i++)
        cin >> arr[i];
    
    memset(dp,-1,sizeof(dp));
    int x = go(arr,n,k);
    
    if(x == 1)
        cout << "First" << endl;
    else
        cout << "Second" << endl;
        
    return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main()
{
	cin >> n >> m;
	vi v(n);
	REP(i, n) cin >> v[i];
	FOR(i, 1, n)
	{
		if (v[i] + v[i - 1] > m) {
			ans += v[i] + v[i - 1] - m;
			v[i] = m - v[i - 1];
			if (v[i] < 0) {
				v[i] = 0;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int  main(){
 int a;
 cin >> a;
 int c[a];
 int count =0;
 rep(i,a){
    cin >> c[i];
 }
 rep(i,a){
    rep(j,a){
       if(i!=j){
          count += c[i]*c[j];
       }
    }
 }
 cout << count/2 << endl;
return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    if not (a % 3 and b % 3 and (a + b) % 3):
        print("Possible")
    else:
        print("Impossible")
    return

#B
def B():
    _, n = L
    I()
    l = LI()
    l.sort(reverse = True)
    print(sum(l[:n]))
    return

#C
def C():
    n = II()
    a = LI()
    for i in range(n-1):
        a[i + 1] += a[i]
    maxa = a[-1]
    ans = inf
    for i in range(n-1):
        ans = min(ans, abs(2 * a[i] - maxa))
    print(ans)
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 71804
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;

vecll AS(200001);
int main(int argc, char const *argv[])
{
  ll N; cin >> N;
  unordered_map<ll, ll> MP;
  REP(i, N) {
    cin >> AS[i];
    auto itr = MP.find(AS[i]);
    if (itr != MP.end()) itr->second += 1;
    else MP.insert(pair<ll, ll>(AS[i], 1LL));
  }
  ll SM = 0;
  for (const auto &pr : MP) SM += pr.second*(pr.second-1)/2;
  REP(i, N) {
    ll cnt = MP.find(AS[i])->second;
    ll res = SM - cnt*(cnt-1)/2 + (cnt-1)*(cnt-2)/2;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 9160
#include<iostream>
#include<vector>
int main(){
    int N;
    std::cin>>N;
    std::vector<int> A(N);
    for(int i=0;i<N;++i){
        std::cin>>A[i];
    }
    unsigned long long ans=0;
    for(int i=0;i<N;++i){
        for(int j=i+1;j<N;++j){
            for(int k=j+1;k<N;++k){
                if(i!=j && j!=k&& i!=k && A[i]!=A[j] && A[j]!=A[k] && A[i]!=A[k]){
                    if(A[i]+A[j]>A[k] && A[j]+A[k]>A[i] && A[k]+A[i]>A[j]){
                        ans++;
                    }
                }
            }
        }
    }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
 
const int MAXN = 101;
const int INF = (1<<28);
 
int N;
int A[MAXN];
int dp[MAXN][MAXN]; // begin, length (inclusive)
 
int main() {
  int Tc;
  cin >> Tc;
  while(Tc--) {
    cin >> N;
    for(int i = 0; i < N; ++i) {
      cin >> A[i];
    }
    fill(dp[0], dp[MAXN], -INF);
    for(int i = 0; i < N; ++i) dp[i][0] = 0;
    for(int j = 1; j < N; ++j) {
      for(int i = 0; i < N; ++i) {
        for(int k = 1; k <= j; ++k) {
          int m = (i + k) % N;
          int ni1 = i;
          int nj1 = k - 1;
          int ni2 = m;
          int nj2 = j - k;
          dp[i][j] = max(dp[i][j], dp[ni1][nj1] + dp[ni2][nj2] + abs(A[i] - A[m]));
        }
      }
    }
    int res = 0;
    for(int i = 0; i < N; ++i) {
      res = max(res, dp[i][N-1]);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

fn count(n: u64, c: u64, d: u64) -> u64 {
    n - ((n / c) + (n / d) - (n / (c * d / gcd(c, d))))
}

fn gcd(n: u64, m: u64) -> u64 {
    match (n, m) {
        (n, 0) => return n,
        (0, m) => return m,
        (n, m) => {
            let r = n % m;
            if r == 0 {
                m
            } else {
                gcd(m, r)
            }
        },
    }
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (a, b, c, d) = input!(u64, u64, u64, u64);

    println!("{}", count(b, c, d) - count(a - 1, c, d));
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

#define Pair pair<LL,LL>
using namespace std;

struct P{int x,y,r;};

struct edge{int to;long double cost;};
int N;
vector<edge> G[1003];
long double d[1003];

void dijkstra(int s){

    priority_queue<Pair,vector<Pair>,greater<Pair> > que;
    fill(d,d+N+2,100000000000000LL);
    d[s]=0;
    que.push(Pair(0,s));

    while(!que.empty()){
        Pair p=que.top();que.pop();
        int v = p.second;
        if(d[v]<p.first)continue;
        REP(i,G[v].size()){
            edge e = G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(Pair(d[e.to],e.to));
            }
        }
    }

}

long double dis(LL x1,LL y1,LL x2,LL y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main(){

    LL xs,ys,xt,yt;
    cin>>xs>>ys>>xt>>yt;
    cin>>N;
    vector<P> bar;
    REP(i,N){
        LL x,y,r;
        cin>>x>>y>>r;
        bar.push_back(P{x,y,r});
    }
    bar.push_back(P{xs,ys,0});
    bar.push_back(P{xt,yt,0});

    REP(i,N+2){
        REP(j,N+2){
            if(i==j)continue;
            G[i].push_back(edge{j,max(dis(bar[i].x,bar[i].y,bar[j].x,bar[j].y)-bar[i].r-bar[j].r,0.0L)});
            G[j].push_back(edge{i,max(dis(bar[i].x,bar[i].y,bar[j].x,bar[j].y)-bar[i].r-bar[j].r,0.0L)});
        }
    }

    dijkstra(N);
    cout<<fixed<<setprecision(10)<<d[N+1]<<endl;
    
    return 0;
}

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

int gcd(int x, int y){
 
    if(y==0)
        return x;
    
    return gcd(y, x%y);

}

int main(void){
    int x,y,r;
    cin >> x  >> y;

    if(x>y)
        r=gcd(x,y);
    else
        r=gcd(y,x);
    cout << r << "\n";
}




Measured memory_bytes: 3108