akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cassert>
#include<random>
#include<fstream>
#include<chrono>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ld           long double
#define pii          pair<int,int>
#define vi           vector<int>
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define endl         '\n'
#define rep(i,s,e)   for(int i=(s);i<=(e);i++)
#define brep(i,s,e)  for(int i=(s);i>=(e);i--)
#define all(x)       (x).begin(),(x).end()
#define ball(x)      (x).rbegin(),(x).rend()
#define sz(x)        (int)x.size()
#define mem(x,y)     memset(x,y,sizeof(x))
#define VR46         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);ifstream fin("ip.txt");ofstream fout("op.txt");
#define milf(x)      x.reserve(1LL<<14LL); x.max_load_factor(0.25); // less_equal
#define pbds         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937              rng(chrono::steady_clock::now().time_since_epoch().count());
#define int          long long
const int INF = 0x3F3F3F3F3F3F3F3F;
const int MOD = 1e9+7;
ld EPS = 1e-12;

const int N = 3e3;
int n;
ld dp[N][N];
ld p[N];

ld REC(int id, int hd)
{
    if( id>=n )
        return (ld)(hd > (n>>1));
    if( dp[id][hd]!=(ld)(-1) )
        return dp[id][hd];
    ld ans = 0;
    ans += REC( id+1, hd+1 )*p[id];
    ans += REC( id+1, hd )*((ld)(1) - p[id]);
    dp[id][hd] = ans;
    return ans;
}

signed main()
{
    VR46 // DONT USE DEQUE IF NOT NECESSARY
    // int t;cin>>t;rep(test,1,t)
    {
        cin >> n;
        rep(i,0,n-1)
            cin >> p[i];
        rep(i,0,n-1) rep(j,0,n-1)
            dp[i][j] = (ld)(-1);
        printf("%.12LF\n",REC( 0, 0 ));
    }
}

Measured memory_bytes: 141056
#include<stdio.h>

int memo[50] = { 0 };

int F(int n) {
	if (n < 2)return memo[n] = 1;
	else if (memo[n - 2] && memo[n - 1])return memo[n] = memo[n - 1] + memo[n - 2];
	else if (memo[n - 1])return memo[n] = memo[n - 1] + F(n - 2);
	else if (memo[n - 2])return memo[n] = memo[n - 2] + F(n - 1);
	else return memo[n] = F(n - 2) + F(n - 1);
}

int main() {
	int N;
	scanf("%d", &N);
	printf("%d\n", F(N));
	return 0;
}


Measured memory_bytes: 2104
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		Main instance = new Main();
		instance.init(300000);
		read().stream().map(instance::execute).forEach(System.out::println);
	}

	private static List<Integer> read() {
		List<Integer> list = new ArrayList<>();
		Scanner sc = new Scanner(System.in);
		while (true) {
			int nextVal = sc.nextInt();
			if (nextVal == 1) {
				break;
			}
			list.add(nextVal);
		}
		sc.close();
		return list;
	}

	private List<Integer> mondaySaturdayList = new ArrayList<>();
	private List<Integer> mondaySaturdayPrimeList = new ArrayList<>();

	public void init(int maxValue) {
		int i;
		boolean isMonday;
		for (i = 1, isMonday = true; i < maxValue;) {
			if (isMonday) {
				i = i + 5;
				isMonday = false;
			} else {
				i = i + 2;
				isMonday = true;
			}
			mondaySaturdayList.add(i);
		}
		IntStream primeStream = mondaySaturdayList.stream().mapToInt(num -> num);
		for (int j : mondaySaturdayList) {
			if (j * j > maxValue) {
				break;
			}
			primeStream = primeStream.filter(num -> num <= j || num % j != 0);
		}
		mondaySaturdayPrimeList = primeStream.boxed().collect(Collectors.toList());
	}

	public String execute(int value) {
		StringBuilder sb = new StringBuilder(String.valueOf(value));
		sb.append(": ");
		sb.append(getPrimeFactors(value).stream().map(String::valueOf).collect(Collectors.joining(" ")));
		return sb.toString();
	}

	private List<Integer> getPrimeFactors(int value) {
		List<Integer> primeFactors = new ArrayList<>();
		for (Integer prime : mondaySaturdayPrimeList) {
			if (value > prime && value % prime == 0) {
				primeFactors.add(prime);
			}
		}
		if (primeFactors.isEmpty() && (value % 7 == 1 || value % 7 == 6)) {
			primeFactors.add(value);
		}
		return primeFactors;
	}
}

Measured memory_bytes: 42900
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    class ClassMain {



           
        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                for (int i = 0; i < 9; i++) {
                    line = Console.ReadLine();
                    n += int.Parse(line);
                
                }
                Console.WriteLine(n);

            }
        }

       



    }
}

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

int main(){
#ifdef _DEBUG
    freopen("inp.txt", "r", stdin );
    freopen("ans.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0); cin.tie(0);
    int n, k; cin >> n >> k;
    if(n == 1){
        cout << 0 << '\n';
        return 0;
    }
    vector<int> a(n + 1), mi(n + 1);
    mi[0] = 1e9 + 5;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        mi[i] = min(mi[i - 1], a[i]);
    }
    int mx = 0, cnt = 0;
    for(int i = 1; i <= n; i++) mx = max(mx, a[i] - mi[i - 1]);
    for(int i = 1; i <= n; i++) if(mx == a[i] - mi[i]) cnt++;
    cout << cnt << '\n';
}


Measured memory_bytes: 3992
import collections

n = int(input())
s = [input() for i in range(n)]
s = map(list,s)
lst = []
for i in s:
  i.sort()
  lst.append(''.join(i))
ans = collections.Counter(lst)
ctr = 0
for v in ans.values():
  if v != 1:
    for n in range(1,v):
      ctr+=n
      
print(ctr)

Measured memory_bytes: 20204
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	string s = readln.chomp;
	string t = readln.chomp;
	
	int n = s.length.to!int;
	int m = t.length.to!int;
	
	int[][] xf = new int[][](26, n);
	// xf[k][i]: position where character k will be found after position i
	// (-1 if impossible)
	foreach(k; 0 .. 26) foreach(i; 0 .. n) xf[k][i] = -1;
	log("xf:", xf);
	
	int[][] pos;
	foreach(k; 0 .. 26){
		int[] q = [];
		pos ~= q;
	}
	foreach(i, c; s){
		int k = (c - 'a').to!int;
		pos[k] ~= i.to!int;
	}
	log("pos:", pos);
	
	foreach(k; 0 .. 26){
		log("k:", k, "pos[k]:", pos[k], "length:", pos[k].length);
		if(pos[k].length == 0){
			foreach(i; 0 .. n) xf[k][i] = -1;
		}
		else{
			int ix = 0;
			foreach(i; 0 .. n){
				if(i < pos[k][ix]) xf[k][i] = pos[k][ix];
				else if(ix < pos[k].length - 1){
					ix += 1;
					xf[k][i] = pos[k][ix];
				}
				else xf[k][i] = pos[k][0];
				log("k:", k, "i:", i, "ix:", ix, "xf[k]:", xf[k]);
			}
		}
	}
	log("xf:", xf);
	
	long ans = 0;
	int x = n - 1;
	foreach(j, c; t){
		int k = (c - 'a').to!int;
		log("ans:", ans, "x:", x, "j:", j, "c:", "" ~ c, "xf[k][x]:", xf[k][x]);
		if(xf[k][x] < 0){
			"-1".writeln;
			return;
		}
		else{
			if(xf[k][x] <= x){
				ans += (n + xf[k][x]) - x;
				x = xf[k][x];
			}
			else{
				ans += xf[k][x] - x;
				x = xf[k][x];
			}
		}
	}
	
	ans.writeln;
	
}


Measured memory_bytes: 13844
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    int H,W;
    cin >> H >> W;
    vector<string> vec(H);
    for(int i=0;i<H;i++){
        string x;
        cin >> x;
        vec[i]=x;
    }
    vector<vector<int>> L(H,vector<int>(W,0));
    vector<vector<int>> R(H,vector<int>(W,0));
    vector<vector<int>> D(H,vector<int>(W,0));
    vector<vector<int>> U(H,vector<int>(W,0));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(vec[i][j]=='#'){
                L[i][j]=0;
            }else{
                if(j==0){
                    L[i][j]=1;
                }else{
                L[i][j]=L[i][j-1]+1;
                    
                }
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=W-1;j>=0;j--){
            if(vec[i][j]=='#'){
                R[i][j]=0;
            }else{
                if(j==W-1){
                    R[i][j]=1;
                }else{
                R[i][j]=R[i][j+1]+1;
                    
                }
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(vec[i][j]=='#'){
                D[i][j]=0;
            }else{
                if(i==0){
                    D[i][j]=1;
                }else{
                D[i][j]=D[i-1][j]+1;
                    
                }
            }
        }
    }
    for(int i=H-1;i>=0;i--){
        for(int j=0;j<W;j++){
            if(vec[i][j]=='#'){
                U[i][j]=0;
            }else{
                if(i==H-1){
                    U[i][j]=1;
                }else{
                U[i][j]=U[i+1][j]+1;
                    
                }
            }
        }
    }
    int reg=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            reg =max(reg,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
        }
    }

    cout << reg << endl;
}

Measured memory_bytes: 67200
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int h = Integer.parseInt(scanner.next());
        int n = Integer.parseInt(scanner.next());
        for (int i = 1; i <= n; i++) {
            h = h - Integer.parseInt(scanner.next());
        }
        if (h <= 0) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 45444
#include<cstdio>
#include<cmath>
int m=99,n,w[12]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
void dfs(int p,int s,int c)
{
	if(s^n){if(p--)for(int i=0;i<6&&s+w[p]*i<=n;++i)dfs(p,s+w[p]*i,c+i);}
    else m=m<c?m:c;
}
int main()
{
	scanf("%d",&n);
	dfs(12,0,0);
	printf("%d",m);
}

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

int main(){
  int n,tmpn,sum;
  cin >> n;
  tmpn = n;
  sum = 0;

  while(tmpn){
    sum += tmpn%10;
    tmpn /= 10;
  }

  if(n%sum==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;
const int mod=1e9+7;


int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x,y;
    cin>>x>>y;
    for(int i=0;i<=x;i++){
    	for(int j=0;j<=x;j++){
    		int c=i+j;
    		int cc=i*2+j*4;
    		if(c==x&&cc==y){
    			cout<<"Yes";
    			return 0;
    		}
    	}
    }
    cout<<"No";
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    int a[n];
    int i, sum;
    sum = 0;
    for(i=0;i<n;i++){
        cin >> a[i];
        sum += a[i];
    }
    int p=0;
    int th = sum/4/m;
    if(th*4*m>=sum)th--;
    //float th=sum/4.0/m;
    for(i=0;i<n;i++){
        if(th < a[i]) p++;
    }
    if(p>=m){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*

                                  In the name of Allah, Most Gracious, Most Merciful


*/
#include<bits/stdc++.h>
#include<numeric>
using namespace std;

//*** constant value ***
const long double PI = 3.141592653589793238;
const double EPS = 1e-6 ;
//*** constant value ***

//****** define ********
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define dd double
#define vll vector<ll>
#define vs vector<string>
#define fn(i,n) for(ll i = 0; i<n; i++)
#define f(i,a,b) for(i=a;i<b;i++)
#define f1(i,a,b) for(i=b-1;i>=a;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define vpl vector<pll>
#define pb push_back
#define mk make_pair
#define x first
#define y second
#define tt cout<<"Came here"<<endl;
//****** define ********
void solve()
{
  string s;
  cin>>s;

  if(s[2]==s[3] && s[4]==s[5])
    cout<<"Yes";
  else
    cout<<"No";

}

int main()
{
    IOS;
    ll tc = 1;
    while(tc--)
    {
        solve();
    }


return 0;
}



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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

import bisect

def main():
    mod=10**9+7
    N,W=MI()
    w=[0]*N
    v=[0]*N
    for i in range(N):
        w[i],v[i]=MI()
    w1=w[0]
    for i in range(N):
        w[i]-=w1
        
    a=set([0])
    for i in range(N+1):
        for j in range(3*i+1):
            ww=w1*i+j
            if ww>W:
                break
            a.add(ww)
    a=list(a)
    a.sort()#sortしないと順番がぐちゃぐちゃになっている？かも
    M=len(a)
    
    
    #dp[i][j]はiまでの商品で,重さa[j]のときの価値の最大
    dp=[[-1]*(M) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0]=0
    ans=0
    
    for i in range(N):
        for j in range(M):
            if dp[i][j]!=-1:
                dp[i+1][j]=max(dp[i+1][j],dp[i][j])
                ww=a[j]+w1+w[i]
                if ww<=W:
                    jj=bisect.bisect_left(a,ww)
                    dp[i+1][jj]=max(dp[i+1][jj],dp[i][j]+v[i])
                    ans=max(ans,dp[i+1][jj])
                    
    print(ans)
                    
    
            

main()


Measured memory_bytes: 54364
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int a, b, c, d; cin >> a >> b >> c >> d;
  int x = max(a, c);
  int y = min(b, d);
  if(x <= y) cout << y - x << endl;
  else cout << 0 << endl;
  return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007LL

class UnionFind{
  int n;
  vector<int> data;
public:
  UnionFind(int _n):n(_n),data(_n,-1){}
  bool link(int a, int b){
    int ra=find_root(a);
    int rb=find_root(b);
    if(ra!=rb){
      if(data[rb]<data[ra]) swap(ra,rb);
      data[ra]+=data[rb];
      data[rb]=ra;
    }
    return (ra!=rb);
  }
  bool check(int a, int b){
    return (find_root(a)==find_root(b));
  }
  int find_root(int a){
    return ((data[a]<0)?a:(data[a]=find_root(data[a])));
  }
};

ll mod_pow(ll x, ll n, ll mod){
  ll res = 1;
  while(n>0){
    if(n&1) res = res*x%mod;
    x = x*x%mod;
    n >>= 1;
  }
  return res;
}

struct ST {
  int i;
  int src, dst;
  ll weight;
  ll mst;
  ST(){}
  ST(int i, int src, int dst, ll weight):i(i),src(src),dst(dst),weight(weight),mst(-1){}
};
bool operator<(const ST& a, const ST& b){
  return a.weight > b.weight;
}

int N, M;
ll X;
ST edges[2005];


ll calc(int a){
  priority_queue<ST> que;
  rep(i,M){
    if(i == a) continue;
    que.push(edges[i]);
  }
  UnionFind uf(N);
  ll X = 0;
  int cnt = 0;
  {
    ST st = edges[a];
    uf.link(st.src, st.dst);
    X += st.weight;
    cnt++;
  }
  
  while(cnt < N-1){
    ST st = que.top(); que.pop();
    if(uf.check(st.src, st.dst)) continue;
    uf.link(st.src, st.dst);
    X += st.weight;
    cnt++;
  }
  return X;
}


map<ll,int> memo;
ll f(ll X){
  ll cnt = 0;
  FOR(it,memo){
    if(it->first <= X) cnt += it->second;
  }

  if(cnt == 0) return (mod_pow(2, M, MOD) - 2 + MOD)%MOD;
  return (mod_pow(2, M-cnt+1, MOD) - 2 + MOD)%MOD;
}

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

  rep(i,M){
    int u, v;
    ll w;
    cin >> u >> v >> w;
    u--; v--;
    edges[i] = ST(i,u,v,w);
  }


  ll mn = 1e18;
  rep(i,M){
    ll W = calc(i);
    edges[i].mst = W;
    mn = min(mn, W);
    memo[W]++;
  }
  
  if(mn > X){
    cout << 0 << endl;
  }
  else{
    ll ans = (f(X-1) - f(X) + MOD)%MOD;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 560
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;

// vector<vector<int>> mat(N, vector<int>(M, 0));

int main(int argc, const char *argv[])
{
    //ABC142

    int N ,K;
    cin>>N >>K;

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

    int count = 0;

    for (int i = 0; i < N; i++)
    {
        if(vec[i] >= K)
        {
            count++;
        }
    }

    cout<<count;
    
    

    

    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;

public class Program
{
	public static void Main(String[] args)
	{
		Int64 a = Convert.ToInt64(Console.ReadLine());
		var lst = new List<char>();
		for (int i = 1; i <= 11; ++i)
		{
			if (a <= (long)Math.Pow(26, i))
			{
				a -= 1;
				for (int j = 0; j < i; ++j)
				{
					lst.Add((char)((int)'a' + (a % 26)));
					a /= 26;
				}

				break;
			}
			else
			{
				a -= (long)Math.Pow(26, i);
			}
		}
		// Console.WriteLine(a);
		lst.Reverse();
		foreach (var item in lst)
		{
			Console.Write(item);
		}

		Console.WriteLine();
	}
}

Measured memory_bytes: 28176
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  string s;
  cin >> s;
  int ans = 700;
  rep(i,3)(s[i] == 'o'?ans+=100:ans+=0);
  cout << ans <<endl;
}

Measured memory_bytes: 256
/*
	DATE:		2020-03-12 09:48:52
	NAME:		
	PROBLEM:	ABC156_E
*/
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e5;
const int MOD = 1e9 + 7;

long long add(long long x, long long y) {
  return ((x % MOD) + (y % MOD)) % MOD;
}

long long mul(long long x, long long y) {
  return ((x % MOD) * (y % MOD)) % MOD;
}

long long fact[2 * MAXN + 7];
long long invfact[2 * MAXN + 7];

long long fastpow(long long x, long long y) {
  if (y == 0) {
    return 1;
  }
  if (y % 2) {
    return mul(x, fastpow(x, y - 1));
  }
  return fastpow(mul(x, x), y / 2);
}

long long comb(int x, int y) {
  return mul(fact[x], mul(invfact[y], invfact[x - y]));
}

long long spread(int x, int y) {
  return comb(x + y - 1, x);
}

long long solve(int x, int n) {
  return mul(comb(n, x), spread(x, n - x));
}

int main() {
  fact[0] = invfact[0] = 1;
  
  for (int i = 1; i <= 2 * MAXN; i++) {
    fact[i] = mul(fact[i - 1], i);
    invfact[i] = fastpow(fact[i], MOD - 2);
  }

  int n, k;
  cin >> n >> k;
  k = min(k, n - 1);

  long long ans = 0;

  for (int i = 0; i <= k; i++) {
    ans = add(ans, solve(i, n));
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 6528
#include"bits/stdc++.h"
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif

	int n,k;cin>>n>>k;
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<n-1;i++)
	{
		if(s[i]==s[i+1])ans++;
	}

	cout<<min(n-1, 2*k+ans);
}

Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

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

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

    vector<ll> ul(N+1,MOD*MOD);
    vector<ll> dl(N+1,MOD*MOD);

    ul[0]=1;
    for(int i=1; i<=N; i++){
        ul[i]=min(MOD*MOD,2LL*(ul[i-1]-A[i-1]));
    }

    dl[N]=A[N];
    for(int i=N-1; i>=0; i--){
        dl[i]=dl[i+1]+A[i];
    }

    ll ans=0;
    ll prev=0;
    for(int i=N; i>=0; i--){
        ll cnt=min(ul[i],dl[i]);
        if(cnt<prev/2+prev%2+A[i]){
            cout << -1 << endl;
            return 0;
        }else{
            ans+=cnt;
            prev=cnt;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5536
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10,mod=998244353,g0=3;
inline int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=(ll)res*x%mod;
		x=(ll)x*x%mod;
		y>>=1;
	}
	return res;
}
int N,n,m;
int dp[205][8005],g[100][2];
int rev[maxn],A[maxn],B[maxn],fac[maxn],ifac[maxn];
inline void ntt(int *y,int flag){
	REP(i,0,N-1) if(i<rev[i]) swap(y[i],y[rev[i]]);
	for(int k=2,t=1;k<=N;k<<=1,++t)
		for(int i=0;i<N;i+=k)
			for(int j=0,x=1;j<(k>>1);++j,x=(ll)x*g[t][flag]%mod){
				int x1=y[i+j],x2=(ll)y[i+j+(k>>1)]*x%mod;
				y[i+j]=(x1+x2)%mod,y[i+j+(k>>1)]=(x1-x2+mod)%mod;
			}
}
int main(){
	n=read(),m=read();
	N=1;
	while(N<=n*2) N<<=1;
	REP(i,0,N-1) rev[i]=(rev[i>>1]>>1)|((i&1)*(N>>1));
	for(int t=0,k=1;k<=N;k<<=1,++t){
		g[t][1]=ksm(g0,(mod-1)/k);
		g[t][0]=ksm(g[t][1],mod-2);
	}
	fac[0]=1;
	REP(i,1,N) fac[i]=(ll)fac[i-1]*i%mod;
	ifac[N]=ksm(fac[N],mod-2);
	DREP(i,N,1) ifac[i-1]=(ll)ifac[i]*i%mod;
	dp[0][0]=1;
	REP(i,1,n) B[i]=ifac[i+2];
	ntt(B,1);
	int inv_N=ksm(N,mod-2);
	REP(i,1,m){
		REP(j,0,N) A[j]=0;
		REP(j,0,n) A[j]=(ll)dp[i-1][j]*ifac[j]%mod;
		ntt(A,1);
		REP(j,0,N-1) A[j]=(ll)A[j]*B[j]%mod;
		ntt(A,0);
		REP(j,0,n) dp[i][j]=((ll)A[j]*inv_N%mod*fac[j+2]+((ll)j*(j+1)/2+1)%mod*dp[i-1][j])%mod;
	}
	int ans=0;
	REP(i,0,n) ans=(ans+(ll)ifac[i]*ifac[n-i]%mod*dp[m][i])%mod;
	ans=(ll)fac[n]*ans%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;

int main(int argc, const char * argv[]) {
  int N, M; cin >> N >> M;
  vector<int> A(N), D;
  vector<pair<int,int>> C;

  for (int i=0; i<N; i++)
    cin >> A[i];
  
  int b, c;
  for(int i=0; i<M; i++){
    cin >> b >> c;
    C.emplace_back(c,b);
  }
  

  sort(C.begin(), C.end());
  int num = 0;
  while(C.size()){
    tie(c,b) = C.back(); C.pop_back();
    for (int i=0; i<b; i++){
      D.push_back(c);
      num++;
    }
    if (num >= N) break;
  }
  
  sort(A.begin(), A.end());
  sort(D.begin(), D.end());
  ll ans = 0;
  for (int i=0; i<N; i++){
    if(A.back() > D.back()){
      ans += A.back(); A.pop_back();
    }else{
      ans += D.back(); D.pop_back();
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2932
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <climits>

using namespace std;
#define forn(x, n)         for (int x = 0; x < n; x++)
#define forr(x, n)         for (int x = n; x >= 0; x--)
#define for1(x, n)         for (int x = 1; x < n; x++)
#define fore(x, a, b, c)   for (int x = a; x <= b; x += c)
#define all(container)     (container).begin(), container.end()
#define rall(container)    (container).rbegin(), container.rend()
#define sz(container)      (int) (container).size()
#define pb                 push_back
#define eb                 emplace_back
#define fi                 first
#define sc                 second

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef LOCAL_DEFINE
    #include "DEBUG.hpp"
#else
    #define eprint(...) 0
#endif
template<class T> bool smin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool smax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(void)
{
    int n;
    scanf("%d", &n);
    int tot = 1000 * ((n + 1000 - 1) / 1000);
    printf("%d\n", tot - n);
    return 0;
}

Measured memory_bytes: 3824
N = int(input())
A = list(map(int,input().split()))

print(2*N-2)

maxa = max(A)
mina = min(A)

if abs(maxa) > abs(mina):
    maxi = A.index(maxa)
    for i in range(N):
        if i==maxi:
            continue
        print(maxi+1,i+1)
    for i in range(N-1):
        print(i+1,i+2)
        
else:
    mini = A.index(mina)
    for i in range(N):
        if i==mini:
            continue
        print(mini+1,i+1)
    for i in range(N-1):
        print(N-i,N-i-1)

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

int main() {
  int N;
  cin >> N;
   
  if (N / 10 % 111 == 0) {
  	cout << "Yes" << endl;
  } 
  else if (N % 1111 == 0) {
    cout << "Yes" << endl;
  }
  else if ((N - (N / 1000) * 1000) % 111 == 0) {
        cout << "Yes" << endl;
  }
  else {
      cout << "No" << endl;
  }
}
 

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

int main(void)
{
  int n = 0;
  std::cin >> n;
  std::unordered_map<int, int> map;
  int number = 0;
  for(int index = 0; n > index; ++index)
  {
    std::cin >> number;
    map.emplace(number, index + 1);
  }
  for(int number = 1; n >= number; ++number)
  {
    std::cout << map[number] << ' ';
  }
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, a, b) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << '\n';

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") puts("Cloudy");
  else if (s == "Cloudy") puts("Rainy");
  else puts("Sunny");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int X,ans = 0,s = 1;
int main(){
	ios::sync_with_stdio(false);
	cin >> X;
	int a = 0;
	while(true){
		a += s;
		if(a >= X){
			ans = s;
			break;
		}
		s++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	cout << a[n - 1] - a[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n,k;
  cin >> n >> k;

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  ll ans=10000000000000000;
  rep(i,n-k+1){
    if(p[i+k-1]<=0) ans=min(ans,0-p[i]);
    else if(p[i]<=0 && 0<p[i+k-1] && abs(p[i])>=abs(p[i+k-1])) {
      ans=min(ans,2*p[i+k-1]-p[i]);
    }
    else if (p[i]<=0 && 0<p[i+k-1] && abs(p[i])<abs(p[i+k-1])) {
      ans=min(ans,p[i+k-1]-2*p[i]);
    }
    else ans=min(ans,p[i+k-1]);
  }

cout << ans << endl;

}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef long long LL;
const int p=1000000007;
int n,m,f[310][310][310],l[310],r[310],x[310],ans;

int main()
{
    scanf("%d%d",&n,&m);
    repu(i,1,m)
        scanf("%d%d%d",&l[i],&r[i],&x[i]);
    f[1][0][0]=3;
    repu(i,1,n)
    {
        int l1=-1,r1=n+1,l2=-1,r2=n+1;
        repu(j,1,m)
            if (r[j]==i)
            {
                if (x[j]==1)
                    r1=min(r1,l[j]-1);
                if (x[j]==2)
                    l1=max(l1,l[j]),r2=min(r2,l[j]-1);
                if (x[j]==3)
                    l2=max(l2,l[j]);
            }
        repu(j,l1,r1)
            repu(k,l2,min(r2,j))
                if (f[i][j][k])
                {
                    if (i==n)
                        (ans+=f[i][j][k])%=p;
                    (f[i+1][j][k]+=f[i][j][k])%=p;
                    (f[i+1][i][j]+=f[i][j][k])%=p;
                    (f[i+1][i][k]+=f[i][j][k])%=p;
                }
    }
    printf("%d\n",ans);
    return 0;
}

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

using ll=long long; 

void solve(){
	vector<int>a(5);
	for(int i=0; i<5; i++){
		cin>>a[i];
	}
	int minv=1000000;
	sort(a.begin(), a.end());
	do{
		int sum=0;
		for(int i=0; i<4; i++){
			sum+=a[i];
			sum=((sum+9)/10)*10;
		}
		sum+=a[4];
		minv=min(minv, sum);
	}while(next_permutation(a.begin(), a.end()));
	cout<<minv<<endl;
}

signed main(){
	//while(1)
	solve();
}

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

const ll N = 1e6 + 10;
const ll mod = 1e9 + 7;

map<int, int> tot;

int mi_p[N];

ll binpow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

ll inv(ll x) {
	return binpow(x, mod - 2);
}

void init() {
	for (int i = 2; i < N; i++) {
		if (mi_p[i]) continue;
		for (int j = i; j < N; j += i)
			mi_p[j] = i;
	}
}

void update_tot(ll x) {
	while (x != 1) {
		int p = mi_p[x];
		int cnt = 0;
		while (x % p == 0) x /= p, ++cnt;
		tot[p] = max(tot[p], cnt);
	}
}

int main() {
	init();
	int n; cin >> n;
	int a[n] = {};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		update_tot(a[i]);
	}
	ll L = 1;
	for (auto pr : tot) {
		L *= binpow(pr.first, pr.second), L %= mod;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += L * inv(a[i]), ans %= mod;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 7884
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define WRAP(y,x,h,w) (0<=y && y<h && 0<=x && x<w)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n, m, q;
	cin >> n >> m >> q;
	vector<str> cell(n);
	REP(i, n)
		cin >> cell[i];
	vvi blue(n, vi(m, 0));
	vvi xcon(n, vi(m, 0));
	vvi ycon(n, vi(m, 0));
	REP(i, n) {
		REP(j, m) {
			if (i - 1 >= 0&& j - 1 >= 0) {
				blue[i][j] -= blue[i - 1][j-1];
				xcon[i][j] -= xcon[i - 1][j-1];
				ycon[i][j] -= ycon[i - 1][j-1];
			}
			if (i - 1 >= 0) {
				blue[i][j] += blue[i - 1][j];
				xcon[i][j] += xcon[i - 1][j];
				ycon[i][j] += ycon[i - 1][j];
			}
			if (j - 1 >= 0) {
				blue[i][j] += blue[i][j - 1];
				xcon[i][j] += xcon[i][j - 1];
				ycon[i][j] += ycon[i][j - 1];
			}
			if (cell[i][j] == '1') {
				blue[i][j]++;
				if (j - 1 >= 0 && cell[i][j - 1] == '1') {
					xcon[i][j]++;
				}
				if (i - 1 >= 0 && cell[i - 1][j] == '1') {
					ycon[i][j]++;
				}
			}
		}
	}
	REP(i, q) {
		int x1, y1, x2, y2;
		cin >> y1 >> x1 >> y2 >> x2;
		x1--;
		y1--;
		x2--;
		y2--;
		int ans = 0;
		if (x1 - 1 >= 0 && y1 - 1 >= 0)
			ans += blue[y1 - 1][x1 - 1];
		if (x1 - 1 >= 0) 
			ans+= -blue[y2][x1 - 1] - ycon[y1][x1-1] + ycon[y2][x1-1];
		if (y1 - 1 >= 0) 
			ans += -blue[y1 - 1][x2]-xcon[y1-1][x1]+ xcon[y1 - 1][x2];
		ans += blue[y2][x2] + ycon[y1][x2] - ycon[y2][x2] +xcon[y2][x1] - xcon[y2][x2];
		cout <<ans<< endl;
	}
	return 0;
}

Measured memory_bytes: 52992
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;



ll pow5(ll n){
    return n*n*n*n*n;
}

ll h[200005];
int main(){
    IOS
    //freopen("output.txt","w",stdout);

    int n,m;
    cin>>n>>m;
    bool ans[n+1];
    memset(ans,true,sizeof ans);

    for(int i=1;i<=n;i++)cin>>h[i];

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

        int u,v;
        cin>>u>>v;

        if(h[u]<=h[v])ans[u]=false;
        if(h[v]<=h[u])ans[v]=false;
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(ans[i]==true)cnt++;
    }
    cout<<cnt<<"\n";
}


Measured memory_bytes: 4512
#include <iostream>
using namespace std;
 
int main()
{
  int X, A, B;
  cin >> X >> A >> B;
 
  int diff = B - A;
 
  if(diff <= 0)
    cout << "delicious" << endl;
  else if(X - diff >= 0)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
 
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s[0]=='R'&&s[1]=='R'&&s[2]=='R') cout<<'3';
  else if((s[0]=='R'&&s[1]=='R')||(s[1]=='R'&&s[2]=='R')) cout<<'2';
  else if(s[0]=='R'||s[1]=='R'||s[2]=='R') cout<<'1';
  else cout<<'0';
}


Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  double a, b, x;
  cin>>a>>b>>x;
  double theta;
  if(a*a*b<2*x) {
    theta = atan(2*(a*a*b-x)/(a*a*a));
    theta *= 180/PI;
  }
  else {
    theta = atan(a*b*b/(2*x));
    theta *= 180/PI;
  }
  cout<<setprecision(20)<<theta<<endl;
}



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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int main() {
  string s;
  cin >> s;
  
  REP(i,19){
    if(i == 5 || i == 13) cout << " ";
    else cout << s.at(i);
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(){


int n;
cin >> n;
int T[n+1];
int sum = 0;
int m;
for(int i=1; i<n+1; i++){
  cin >> T[i];
  sum += T[i];
}
cin >> m;
int p,x;
for(int i=1; i<m+1; i++){
  cin >> p >> x;
  cout << sum - (T[p]-x) << endl;
}



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 10007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int al,bl,a[5000],b[5000];
int rec(int x,int k){
      for(int i=k;i<al;i++){
            if(a[i]==x)return i;
      }
      return -1;
}
int main(){
      cin>>al>>bl;
      REP(i,al)cin>>a[i];
      REP(i,bl)cin>>b[i];
      int ans=0;
      REP(i,bl){
            int s=0,c=0;
            while(1){
                  s=rec(b[i+c],s);s++;
                  if(s==0)break;
                  else c++;
            }
            ans=max(ans,c);
      }
      cout<<ans<<endl;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define N 105
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
template<typename T>
inline void in(T &x)
{
	x=0;
	char c=getchar();
	bool fu=0;
	while(c<'0'||c>'9'){if(c=='-')fu=1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	x=fu?-x:x;
}
int n,m,a[N],tmp[3],ans;
int main()
{
	in(n);
	for(int i=0;i<n;++i)in(a[i]);
	for(int i=0;i<n;++i)
	for(int j=i+1;j<n;++j)
	for(int k=j+1;k<n;++k)
	if(a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k])
	{
		tmp[0]=a[i];tmp[1]=a[j];tmp[2]=a[k];
		sort(tmp,tmp+3);
		if(tmp[0]+tmp[1]>tmp[2])++ans;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
using namespace std;
int n,a[233333],S,ans,f[66666],sum[20];
int dfs(int S){
	if(!S)return 0;
	if(f[S]<INF)return f[S];
	for(int i=0;i<16;i++)if((S>>i)&1)
		for(int j=0;j<16;j++)if(i!=j&&(S>>j)&1){
			int p=i^j,x=S^(1<<i)^(1<<j)^(1<<p);
			if(S>>p&1)f[S]=min(f[S],dfs(x)+2);
			else f[S]=min(f[S],dfs(x)+1);
		}
	return f[S];
}
int main(){
	cin>>n;
	for(int i=1,x,y,z;i<n;i++){
		cin>>x>>y>>z;
		a[x]^=z,a[y]^=z;
	}
	for(int i=0;i<n;i++)sum[a[i]]++;
	for(int i=1;i<16;i++){
		ans+=(sum[i]>>1);
		S+=(1<<i)*(sum[i]&1);
	}
	memset(f,0x3f,sizeof f);
	ans+=dfs(S);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<62)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vl p(n);
    cin>>p;
    ll min=p[0],c=n;
    rep(i,n){
        if(min>p[i]) min=p[i];
        if(min<p[i]) c--;
    }
    puta(c);
    
}


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

using namespace std;

int main(){
    while(true){
        // 1?????\???
        string s;
        getline(cin, s);

        // .??????????????????
        if(s == ".")
            return 0;

        // rb(round), sb(square)
        string stack = "";

        //??¨??????????????????
        for(auto &x:s){
            // ?????¬??§
            if(x == '(' || x == '[')
                // stack?????????
                stack.push_back(x);
            // ?????¬??§
            else if(x == ')' || x == ']'){
                // stack?????? ??? no
                if(stack.empty()){
                    stack.push_back('.');
                    break;
                // ??¬??§?????????????????????
                }else if(x == ')' && stack.back() == '('){
                    stack.pop_back();
                }else if(x == ']' && stack.back() == '['){
                    stack.pop_back();
                // no
                }else {
                    stack.push_back('.');
                    break;
                }
            }
        }

        // ??????0??????yes
        if(stack.empty())
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}

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

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()

template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<bool> VB;
typedef vector<double> VD;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 5e18;
// const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793238

signed main() {
    LCIN(N, K, Q);
    VL sum(N);
    REP(i, Q) {
        LCIN(A);
        A--;
        sum[A]++;
    }
    REP(i, N) { cout << (K - (Q - sum[i]) <= 0 ? "No" : "Yes") << "\n"; }
}


Measured memory_bytes: 1408
import sys

L,R = map(int,input().split())

ans = 2019
for i in range(L,R):
    for j in range(i+1,R+1) :
        pro = (i*j) %2019
        ans = min(ans,pro)
        if ans == 0 :
            print(0)
            sys.exit()

print(ans)

Measured memory_bytes: 3060