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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
//printf("%.12lf\n",mid);
// __builtin_popcount(int) count 1's in binary
int mod = 1000000007;

int mymod(int num){
  if (num< 0){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

double eps = .0000000001;
bool bad[100001];
int memo[100001];
bool memoo[100001];
int n, m;
long long func(int ind){
    if (memoo[ind]){
        return memo[ind];
    }
    if (ind == n ){
        return 1;
    }else if (ind > n){
        return 0;
    }
    if (bad[ind]){
        return 0;
    }
    long long res = (func(ind+1)+func(ind+2))%mod;
    memo[ind] = res;
    memoo[ind] = true;
    return res;
}
int main ()
{
  prep ();
  
  cin >> n >> m;
  for (int i=0; i<m; i++){
      int num;
      cin >> num;
      bad[num] = true;
  }
  cout << func(0);
  return 0;
  
}
// in dp problems think: up until here, intervals, or "what if there's 1, 2, 3..."
// in math problems write out equations
// also in math problems to change multiplication/division to addition/subtraction use logs, add/subtract something to make the multiplication easier (like if it's 3*f(x)+2, change it to 3*(f(x)+1)-1)
// if printint pow function, put an (int) or (long long) next to it
// if checked everything check for bugs (like sorting wrong way or not putting a break in a loop)
// if n is 10^7 try brute force if the operations are simple
// if can't do dp do brute force/greedy
// to save time don't copy maps/vectors into variables if it already exists
// only use long long if need to
// if wrong on decimal problem, check if program rounds or if you can round to a certain amt of decimals
// if decimals too, if can subtract instead of divide
// in grid traversal problems check if doing sideways or not
// if TLE try to take away loop
// in recursion looking math problems look at things from the point of view of both sides (the start and the end sections of the recursion)
// think about how many possible answers there are to the problem
// try to set the answer to the problem and see if it's possible (like w/ binary search)
// if it makes it easier use +1 indexing
// think twice when writing things down that you're going to use later
// for conversions think if you can compute them w/ only one conversion 
// if the problem involves two things moving at the same time, see if you can generalise it to just one thing moving (590/B) (1117/C)
// if nt think primes
// see if you can do a pattern of steps to achieve something (1148/C) (1119/C)
// for problems where you're searching for like a pair that requires something, if it's a yes/no prob, don't focus on individual elements if it's too long (593/B)
// if sub-interval requirements, try to reduce problem into prefix array problem (pairwise numbers) (1174/D)
// think from the end of the problem (if this is the result, what is an attribute of it?)
// if repeating action, if good for debugging use function
// if you know you can do bin search to make it easier but can also solve it shorter way, just do bin search

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

ll n, k;
vvl to;

mint dfs(ll p, ll v, ll o, ll h) {
    if (to[v].size() == 0) return k;
    if (h > 0 && to[v].size() == 1) {
        if (h == 1) return k - o - 1;
        return k - o - 2;
    }
    ll s = sz(to[v]);
    mint res = k - o - 2;
    if (h <= 1) res += 1;
    if (h == 0) res += 1;
    ll cnt = 0;
    rep(i, s) {
        if (to[v][i] == p) continue;
        res *= dfs(v, to[v][i], cnt, h + 1);
        cnt++;
    }
    return res;
}

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

    cin>>n>>k;
    to = vvl(n);
    rep(i, n - 1) {
        ll v1, v2;
        cin>>v1>>v2; v1--; v2--;
        to[v1].push_back(v2);
        to[v2].push_back(v1);
    }
    mint ans = dfs(-1, 0, 0, 0);
    cout<<ans<<endl;
}

Measured memory_bytes: 11648
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define pb push_back
#define se second
#define fi first
#define int long long 
#define pi pair<int,int>
#define vpi vector<pi>
#define vvpi vector<vpi>
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define For(i,n) for(int i=0;i<n;i++)
#define Forn(i,a,n) for(int i=a;i<n;i++)
#define pie =3.14159265358979323846264338327950;
const int mod= 1e9+7;

int n;
int ar[3005];
int dp[3005][3005];

int f(int start, int end){
	if(start>end){
		return 0;
	}
	if(start==end){
		return ar[start];
	}
	if(dp[start][end]!=-1) return dp[start][end];
	int ans= max({ar[start]+min(f(start+2,end),f(start+1,end-1)), ar[end]+min(f(start+1,end-1), f(start,end-2))});
	//cout<<start<<" "<<end<<" "<<ans<<endl;
	dp[start][end]=ans;
	return ans;
}

void solve(){
	fio;
	cin>>n;
	int sum=0;
	For(i,n){
		cin>>ar[i];
		sum+=ar[i];
	}
	memset(dp,-1,sizeof(dp));
	int k= f(0,n-1);
	//cout<<k<<endl;
	cout<<2*k-sum<<endl;
}

int32_t main(){
	fio;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){ 
		//cout<<"Case #"<<i<<":\n";
		solve();
	}
	return 0;
}


Measured memory_bytes: 74392
// Aizu Vol-1 0149: Eye Test
// 2017.8.1

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);

#define MAX 50
char buf[MAX + 5], *p;
int c[2][4];

int getDouble(void)
{
	int len = 0, n = 0;

	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	if (*p == '.') p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0'), len++;
#define MAGIC 2
	if (len > MAGIC) while (1);
	while (len < MAGIC) n = 10 * n, len++;
	return n;
}

int main()
{
	int i, d[2];

	while (gets(p = buf) != NULL) {
		d[0] = getDouble(), d[1] = getDouble();
		for (i = 0; i < 2; i++) {
			if     (d[i] >= 110) c[i][0]++;
			else if (d[i] >= 60) c[i][1]++;
			else if (d[i] >= 20) c[i][2]++;
			else                 c[i][3]++;
		}
	}
	for (i = 0; i < 4; i++) printf("%d %d\n", c[0][i], c[1][i]);
	return 0;
}

Measured memory_bytes: 524
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use superslice::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        a: usize, b: usize, c: usize,
    }

    if a == b && b == c && c == a {
        println!("0")
    } else {
        let mut abc_vec = vec![a, b, c];
        abc_vec.sort();

        let diff = vec![abc_vec[2]-abc_vec[0], abc_vec[2]-abc_vec[1]];

        // both even
        if diff.iter().all(|x| x % 2 == 0) {
            println!("{}", diff.iter().sum::<usize>() / 2)
        } else if diff.iter().all(|x| x % 2 == 1) {
            // both odd
            println!("{}", diff.iter().sum::<usize>() / 2)
        } else {
            println!("{}", (diff.iter().sum::<usize>()+1) / 2 + 1)
        }
    }
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
struct item
{
	int w,val;
};
long long solve(vector<item>v,int n,int w)
{
	long long dp[n+1][w+1];
	for(int i=0;i<=w;i++)
		{
            dp[1][i] = 0;
            dp[0][i] = 0;
        }
	dp[1][v[1].w] = v[1].val;

	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<=w;j++)
		{
			dp[i][j] = dp[i-1][j];
			if(v[i].w>j)
				continue;
			dp[i][j] = max(dp[i][j],v[i].val + dp[i-1][j-v[i].w]);
		}
	}

	return *max_element(dp[n] , dp[n] + w + 1);


}
int main()
{
	int n,w;
	cin>>n>>w;
	vector<item>v(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>v[i].w>>v[i].val;
	}
	cout<<solve(v,n,w);
}

Measured memory_bytes: 82432
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

int main() {
    ll n,k;
    cin >> n >> k;
    if(n == 1){
        cout << k << endl;
        return 0;
    }
    cout << fixed << setprecision(0) << k*pow((k-1),n-1) << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
S = input()
allsum = 0

for i in range(2**(len(S)-1)):
    bi = format(i,"b")
    bi = "0" * (len(S) - len(bi) - 1) + bi
    st = S[0]
    stsum = 0
    for k in range(len(S) - 1):
        if bi[k] == "0":
            stsum += int(st)
            st = S[k+1]
        else:
            st = st + S[k+1]
    stsum += int(st)
    allsum += stsum
print(allsum)

Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

VEC(Pll) bestSplits(VEC(lint)& A)
{
    const int N = SZ(A);


    VEC(lint) Sum(N + 1, 0LL);
    partial_sum(ALL(A), BEGIN(Sum) + 1);

    VEC(Pll) Ret(N + 1);

    // Need atleast 2 elements to split.
    FOR(i, 2, N + 1) {
        lint sum = Sum[i];
        // among Sum[1] ... Sum[i - 1], pick one closest to sum / 2
        int x = lower_bound(BEGIN(Sum), BEGIN(Sum) + i, sum / 2) - BEGIN(Sum);
        Ret[i] = Pll(Sum[x], Sum[i] - Sum[x]);
        if (x >= 1) {
            Pll ret2(Sum[x - 1], Sum[i] - Sum[x - 1]);
            if (abs(ret2.FIR - ret2.SEC) < abs(Ret[i].FIR - Ret[i].SEC))
                swap(Ret[i], ret2);
        }
        if (Ret[i].FIR < Ret[i].SEC)
            swap(Ret[i].FIR, Ret[i].SEC);
    }

    return Ret;
};

void solveSingleCase(int caseNo)
{
    int N;
    cin >> N;
    VEC(lint) A(N);
    READVEC(A);
    VEC(Pll) left = bestSplits(A);
    reverse(ALL(A));
    VEC(Pll) right = bestSplits(A);
    reverse(ALL(A));

    lint ret = 1LL << 60;
    FOR(i, 2, N - 1) {
        int l = i, r = N - i;
        // l >= 2, r >= 2
        lint cand = left[l].FIR - left[l].SEC;
        cand = max(cand, right[r].FIR - right[r].SEC);
        cand = max(cand, abs(left[l].FIR - right[r].SEC));
        cand = max(cand, abs(left[l].SEC - right[r].FIR));
        ret = min(ret, cand);
    }

    cout << ret << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 9700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
    ll d;int id;
}c[100005];
bool cmp(node x,node y){return x.d>y.d;}
int fa[100005],siz[100005],deep[100005];
ll d[100005];
vector<int>to[100005];
void dfs(int x){for(auto tar:to[x])deep[tar]=deep[x]+1,dfs(tar);}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%lld",&c[i].d),c[i].id=i,siz[i]=1;
    sort(c+1,c+n+1,cmp);
    for(int i=1;i<=n;i++)d[i]=c[n+1-i].d;
    for(int i=1;i<n;i++)
    {
        int t=lower_bound(d+1,d+n+1,c[i].d+2*siz[c[i].id]-n)-d;
        t=n+1-t;
        if(c[t].d!=c[i].d+2*siz[c[i].id]-n){puts("-1");return 0;}
        fa[c[i].id]=c[t].id,siz[c[t].id]+=siz[c[i].id];
    }
    for(int i=1;i<=n;i++)if(fa[i])to[fa[i]].push_back(i);
    dfs(c[n].id);
    ll s=0;
    for(int i=1;i<=n;i++)s+=deep[i];
    if(s!=c[n].d){puts("-1");return 0;}
    for(int i=1;i<=n;i++)if(fa[i])printf("%d %d\n",i,fa[i]);
    return 0;
}

Measured memory_bytes: 15140
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    char s[1000000]={};
    scanf("%s",s);
    int k=strlen(s);
    if(k<=n)
       cout<<s<<endl;
    else if(k>n){
      for(int i=0;i<n;i++){
        printf("%c",s[i]);}
        cout<<"..."<<endl;
    }

    return 0;
}

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

using namespace std;

int main()
{
	long long n;
  	cin>>n;
  	unordered_map <string , int> m;
  	for(long long i=0; i<n; i++)
    {
      	string t;
      	cin>>t;
      	m[t]++;
    } 
  	cout<<m.size()<<"\n";
}  
  

Measured memory_bytes: 17532
<?php
# 数値の入力
fscanf(STDIN, "%d %d", $data1, $data2);
$count = $data2-$data1+1;

for($i=1; $i<($data1*2); $i++){
    if($count>-1000001 and $count<1000001){
        echo $count." ";
    }
    $count += 1;
}
?>

Measured memory_bytes: 3828
n = int(input())
fn,fk,mod = [1]*n,[1]*n,10**9+7
for i in range(n-1): fn[i+1] = (fn[i]*(i+2))%mod
def power(n,k):
	if k==1: return n
	elif k%2==0: return power((n**2)%mod,k//2)
	else: return (n*power(n,k-1))%mod
def comb(n,k):
	if n<k or k<0: return 0
	elif k==0 or n==k: return 1
	else: return (((fn[n-1]*fk[n-k-1])%mod)*fk[k-1])%mod
fk[-1] = power(fn[-1],mod-2)
for i in range(2,n+1): fk[-i] = (fk[-i+1]*(n+2-i))%mod
fn.append(1)
ans = fn[n-2]*(n-1)
for i in range(n-2,(n-1)//2,-1):
	ans = (ans-comb(i-1,n-i-1)*fn[i-1]*fn[n-i-2])%mod
print(ans)

Measured memory_bytes: 82164
N, M = map(int, input().split())
pref = [[] for _ in range(N)]
P,Y = [0]*M,[0]*M
for i in range(M):
    P[i],Y[i] = map(int, input().split())
    pref[P[i]-1].append(Y[i])

for i in range(N):
    pref[i].sort()

from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort

def solve(P,Y,pref):
    ans = []
    for p, y in zip(P,Y):
        ind = bisect_left(pref[p-1],y)+1
        num = '0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(ind)))+str(ind)
        ans.append(num)
    return ans
print(*solve(P,Y,pref),sep='\n')

Measured memory_bytes: 31988
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int,read().split())

n = 1
for x in A:
    if x == n:
        n += 1

answer = N - n + 1
if answer == N:
    answer = -1
print(answer)

Measured memory_bytes: 20408
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
cnt=[0]*(10**5+10)
for a in A:
    cnt[a]+=1
s=sum(A)
Q=int(input())
for _ in [0]*Q:
    b,c=map(int,input().split())
    s+=cnt[b]*(c-b)
    cnt[c]+=cnt[b]
    cnt[b]=0
    print(s)

Measured memory_bytes: 87672
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  deque<int> d;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (i % 2 == 0) d.push_back(a);
    else d.push_front(a);
  }
  if (n % 2 == 1) reverse(all(d));
  for (int i = 0; i < n; i++) {
    cout << d[i] << (i == n - 1 ? '\n' : ' ');
  }
  return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
#define MOD 1000000007
typedef long long ll;
//------------------------------------------------------------------------

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

  string s; cin >> s;

  cout <<s.substr(0,4) <<" "<< s.substr(4,8) <<  endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#define int long long
using namespace std;
 
int f(int a, int b) {
	if (a > b) swap(a, b);
	if (a == b) return 2 * a - 2;
	int x = 2 * sqrt((long double)a * b - 0.5) - 2;
	int st = 1, ed = 2000000000, mid;	//oooxxx, [st, ed)
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if ((a * b - 1) / mid >= b) st = mid;
		else ed = mid;
	}
	if ((a * b - 1) / st == b) x--;
	return x;
}
 
signed main() {
	int q, a, b;
	cin >> q;
	while (q--) { cin >> a >> b; cout << f(a, b) << endl; }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

int main(){
    ll n , x; cin >> n >> x;
    ll bound = 1;
    ll cur = 0;
    rep(i,n){
        ll l ; cin >> l;
        cur += l;
        if(cur<=x) bound++;
    }
    cout << bound << endl;
}

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

int main(){
  int n; cin>>n;
  long long a[n],sum=0,ans=INT_MAX,snuke=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  for(int i=0;i<n-1;i++){
    snuke+=a[i];
    ans=min(abs(sum-2*snuke),ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();

		sc.nextLine();

		Long sum = (long) 0;
		for(int i=0; i<M; i++) {
			sum += sc.nextLong();
		}

		if(sum <= N) {
			System.out.println(N-sum);
		}else{
			System.out.println("-1");
		}


		sc.close();
	}

}


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

int N;
int A[100010];
int sum = 0;
int all = 0;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%d",A + i);
    sort(A,A + N);
    reverse(A,A + N);
    for(int i = 0; i < N; i++)
    {
        all += A[i];
        if(i & 1)sum += A[i];
    }
    printf("%d\n",(all - sum) - sum);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
    {
        static void Main(string[] args)
        {   
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]), k = int.Parse(s[1]);
            
            Console.WriteLine(n - k + 1);

            
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 11092
def mapt(fn, *args):
    return list(map(fn, *args))

def Array(listseq):
    return mapt(Vector, listseq)

def Vector(lines):
    return mapt(str, lines)
    
    
r, c = mapt(int, input().split(" "))
arrays = [mapt(int, input().split(" ")) for i in range(r)]

def calc(arrays, r):
    y_axis = [sum(i) for i in zip(*arrays)]
    arrays.append(y_axis)
    x_axis = [sum(i) for i in arrays]
    for i in range(r+1):
        arrays[i].append(x_axis[i])
    for row in Array(arrays):
        print(" ".join(row))

calc(arrays, r)



Measured memory_bytes: 6300
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 310;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

int n, a[MAXN][MAXN], b[MAXN][MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) FOR(j,1,n) cin >> a[i][j];
    FOR(i,1,n)
        FOR(j,1,n)
            FOR(k,1,n)
                if (a[i][k] + a[k][j] < a[i][j]) {
                    cout << -1;
                    return 0;
                }
    ll res = 0;
    FOR(i,1,n)
        FOR(j,i+1,n) {
            b[i][j] = a[i][j];
            FOR(k,1,n)
                if (k != i && k != j && a[i][k] + a[k][j] == a[i][j]) {
                    b[i][j] = 0;
                }
            res += b[i][j];
        }
    cout << res;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define true 1
#define false -1
int solve(int ,int );

int i,A[2000],m[2000],n,q;

int main()
{
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
    if(solve(0,m[i])==true)
      printf("yes\n");
    else
       printf("no\n");
  }

  
  return 0;
}


int solve(int i,int m){
  int res;
  if (m == 0)
    return true;
  if (i >= n)
    return false;
  if(solve(i+1,m)==true)res=true;
  else if(solve(i+1,m-A[i])==true)res=true;
  else res=false;
  return res;
}



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

int main(){
	int h,w,c;
	string d;
	cin>>h>>w;
	vector<vector<int> > g;
	g.resize(h);
	for(int i=0;i<h;i++){
		g[i].resize(w);
	}
	for(int y=0;y<h;y++){
		cin>>d;
		c=-1;
		for(int x=0;x<w;x++){
			if(d[x]=='c'){
				g[y][x]=0;
				c=0;
			}
			else if(c!=-1){
				c++;
				g[y][x]=c;
			}
			else g[y][x]=c;
			if(x==w-1) cout<<g[y][x]<<endl;
			else cout<<g[y][x]<<" ";
		}
	}
	return 0;
}


Measured memory_bytes: 3192
#include<stdio.h>

int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    char pic_a[n][n];//[y][x]
    char pic_b[m][m];
    for(int i = 0;i < n;i++)scanf("%s",pic_a[i]);
    for(int i = 0;i < m;i++)scanf("%s",pic_b[i]);
    int maxoffset = n-m;
    int flag = 0;
    for(int offx = 0;offx <= maxoffset;offx++)for(int offy = 0;offy <= maxoffset;offy++){
        flag = 0;
        for(int i = 0;i < m;i++)for(int j = 0;j < m;j++)if(pic_a[i+offx][j+offy] != pic_b[i][j])flag = 1;
        if(!flag){
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 128
from collections import Counter

N = list(map(int, input()))
MOD = 2019
cnt = 0
M = len(N)
ans = 0
mod_list = [0]
ten = 1

for n in N[::-1]:
    ans += ten*n
    mod_list.append(ans%MOD)
    ten *= 10
    ten %= MOD

SUM = 0
for k,v in Counter(mod_list).items():
    SUM += v * (v-1) /2

print(int(SUM))

Measured memory_bytes: 19900
#include <iostream>
#include <string>
#include <time.h>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#include <math.h>
using namespace std;
typedef long long  ll;
static const ll INF = (ll)1 << 62;
static const ll MOD = 1e9 + 7;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	ll n; cin >> n;
	cout << (n - 2) * 180 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n, k;
    cin >> n >> k;
    long long int a[2000001];
    long long int i;
    long long int j=-1000000;
    for(i=0; i<2000001; i++){
        a[i] = j;
        j++;}
    long long int b[(2*n)-1]={0};
    long long int m = k-(n-1);
    for(i=0; i<(2*n)-1; i++){
        b[i] = m;
        m++;}
    for(i=0; i<(2*n)-1; i++){
        cout << b[i] << " ";}}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
	
int main(){
	ll n,a[200010];
	cin>>n;
	rep(i,0,n)cin>>a[i];
	sort(a,a+n);
	ll use[1000010]={0};
	rep(i,0,n){
		ll j=1;
		while(a[i]*j<=a[n-1]){
			use[a[i]*j]++;
			j++;
		}
	}
	ll ans=0;
	rep(i,0,n){
		if(use[a[i]]==1)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 12964
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int r[202020], t[202020];
LL m[2020];

int main(){
    
    // 1. 入力情報.
    char c[202020];
    scanf("%s", c);
    int l = strlen(c);
    
    // 2. 10 の 冪乗 について, 2019 で 割った余りを保存.
    t[0] = 1;
    repx(i, 1, 202020) t[i] = 10 * t[i - 1] % 2019;
    // rep(i, 10) printf("t[%d]=%d\n", i, t[i]);
    
    // 3. 2019 で 割った余りを 保存.
    // i文字目までで, 2019で割った余りを保存.
    repr(i, l - 1, 0){
        r[i] = r[i + 1] + (c[i] - '0') * t[l - 1 - i];
        r[i] %= 2019;
    }
    // rep(i, l + 1) printf("r[%d]=%d\n", i, r[i]);
    
    // 4. 余りの個数を集計.
    rep(i, l + 1) m[r[i]]++;
    
    // 5. 条件を満たす整数の組は？
    LL ans = 0;
    rep(i, 2020) ans += m[i] * (m[i] - 1LL) / 2LL;
    
    // 6. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define frr(i,s,n) for(int i=s;i<=n;i++)
#define fr(i,s,n) for(int i=s;i<n;i++)
#define lli long long int
#define llu unsigned long long int
#define vi vector <int>
#define vii vector <long long int>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define mk make_pair
#define mpp map<int,int>
#define ff first
#define ss second
#define mod 1000000007

using namespace std;

vector <int> v[100001];
vector <int> vis(100001);
int dp[100001];
int dfs(int node)
{
	if(vis[node])
		return dp[node];
	vis[node] = 1;
	int mx = 0;
	for(auto child : v[node])
		mx = max(mx,dfs(child) + 1);
	return dp[node] = mx;
}

void loop()
{
	int n;
	cin>>n;
	int count = 0;
	for(int i=1;i<=n-1;i++)
	{
		for(int j=1;j<=n-1;j++)
		{
			if((n-(i*j)) >= 1 && (n-(i*j)) <= n)
				count++;
			else
				break;
		}
	}
	cout<<count<<"\n";
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	fast;
    int t=1;
    //cin>>t;
    while(t--)
    	loop();
}


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

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(n) for(int i = 0; i < n; i++)
#define run(i, a, b) for(int i = a; i < b; i++)
#define cinarr(arr, n) repi(n) cin >> arr[i]
#define coutarr(arr, n) repi(n) cout << arr[i] << " "; cout << endl
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define cinset(st, n) {int _t; repi(n) {cin >> _t; st.insert(_t);}}


typedef long long int ll;
typedef unsigned long long int ull;

int main(){
    FAST_IO
    
    int n;
    cin >> n;
    
    cout << !n << endl;
}


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

int main(){
  string A,B,C;
  cin>>A>>B>>C;
  
  
  if(A.at(A.size()-1)==B.at(0)&&B.at(B.size()-1)==C.at(0)){
cout<<"YES"<<endl;
  }
else{
  cout<<"NO"<<endl;
}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;


int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	double ret=0;
	for (int i=0; i<n; i++) {
		double x; cin>>x; ret+=1./x;
	} 
	cout<<setprecision(10)<<fixed<<1./ret<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;//n stones
int i;
int h[n];
for(i=0;i<n;i++){
    cin>>h[i];
}
int dp[n];
dp[0]=0;
dp[1]=abs(h[0]-h[1]);
for(i=2;i<n;i++){
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
}

cout<<dp[n-1];

    return 0;
}

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

int a,b;
int h=100,w=100;
char grid[101][101];
int main(){
  int i,j,bl=1,wh=1;
  cin >> a >> b;
  for(i=1;i<=50;i++){
    for(j=1;j<=100;j++){
      grid[i][j] = '.';
      grid[i+50][j] = '#';
    }
  }
  while(bl<b){
    grid[2*(bl/50)+1][2*(bl%50)+1] = '#';
    bl++;
  }
  while(wh<a){
    grid[2*(wh/50)+52][2*(wh%50)+1] = '.';
    wh++;
  }







  
  cout << h<<' '<<  w << endl;
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++)cout << grid[i][j];
    cout << endl;
  }
  return 0;
  
}


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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    string ans;
    if (A+B < C+D) {
        ans = "Right";
    }
    else if (A+B == C+D) {
        ans = "Balanced";
    }
    else {
        ans = "Left";
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
  int H, N;
  cin >> H >> N;
  int A[N];
  for (int i = 0;i < N;i++) {
    cin >> A[i];
  }
  int sum = 0;
  for (int i = 0;i < N;i++) {
    sum += A[i];
  }
  if (sum >= H) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;

}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int st[111];
int P[111][11];

signed main(){
    cin>>N;
    rep(i,N){
        rep(j,10){
            int a;cin>>a;
            st[i]=st[i]*2+a;
        }
    }
    rep(i,N)rep(j,10+1)cin>>P[i][j];

    int ans=LLONG_MIN;
    for(int i=1;i<1024;i++){
        int sum=0;
        rep(j,N){
            int b=st[j]&i;
            sum+=P[j][__builtin_popcount(b)];
        }
        chmax(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT{
    __INIT(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout<<fixed<<setprecision(15);
    }
}__init;

int main(void){
    ll k,a,b;
    cin>>k>>a>>b;
    for(ll i=a;i<=b;++i){
        if(i >= k && i%k == 0){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
}

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

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

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}


int N;
vector<long long> A;
vector<long long> sum;

int main() {
    cin >> N; 
    A.resize(N); sum.resize(N+1); sum[0] = 0;
    for (int i = 0; i < N; ++i) cin >> A[i], sum[i+1] = sum[i] + A[i];

    long long res = 1LL<<60;
    for (int i = 0; i <= N; ++i) {
        int low = 0, high = i;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] >= sum[i] - sum[mid]) high = mid;
            else low = mid;
        }
        long long P = sum[low], Q = sum[i] - sum[low];
        long long P2 = sum[high], Q2 = sum[i] - sum[high];
        long long left_min = min(P, Q), left_max = max(P, Q);
        if (abs(P2-Q2) < abs(P-Q)) left_min = min(P2, Q2), left_max = max(P2, Q2);

        low = i, high = N;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] - sum[i] >= sum[N] - sum[mid]) high = mid;
            else low = mid;
        }
        long long R = sum[low] - sum[i], S = sum[N] - sum[low];
        long long R2 = sum[high] - sum[i], S2 = sum[N] - sum[high];
        long long right_min = min(R, S), right_max = max(R, S);
        if (abs(R2-S2) < abs(R-S)) right_min = min(R2, S2), right_max = max(R2, S2);

        long long tmp = max(left_max, right_max) - min(left_min, right_min);
        res = min(res, tmp);
    }
    cout << res << endl;
}


Measured memory_bytes: 3328
//by yjz
#include<bits/stdc++.h>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
typedef long long ll;
using namespace std;
const int maxn = 200111;
int n;
int a[maxn], b[maxn];
ll ans = 0;
void check(int x)
{
	int s = (b[(x-1+n)%n]+b[(x+1)%n]);
	if (b[x]<a[x])
	{
		puts("-1");
		exit(0);
	}
	if (b[x]-a[x]>=s)
	{
		int tmp = (b[x]-a[x])/s;
		ans += tmp;
		b[x] -= s*tmp;
		check(x);
		check((x-1+n)%n);
		check((x+1)%n);
	}
}
int main()
{
	scanf("%d", &n);
	for (int i=0; i<n; i++) scanf("%d", &a[i]);
	for (int i=0; i<n; i++) scanf("%d", &b[i]);
	for (int i=0; i<n; i++)
	{
		check(i);
	}
	for (int i=0; i<n; i++)
	{
		if (b[i]!=a[i])
		{
			puts("-1");
			return 0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,sum=0;
  cin >> N;
  int tmp = N;
  while(N>0){
    sum += N % 10;
    N = N /10;
  }
  if(tmp % sum ==0)
    printf("Yes");
  else
    printf("No");
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int a[110]; int k;
		for (int i = 0; i < n; i++)cin >> a[i]; cin >> k;
		int l = 0, r = n - 1;
		int cnt = 0;
		while (l <= r) {
			cnt++;
			int m = (l + r) / 2;
			if (a[m] == k) { cout << cnt << endl; goto heaven; }
			else if (a[m] < k)l = m + 1;
			else if (a[m] > k)r = m - 1;
		}
		cout << cnt << endl;
	heaven:;
	}
}


Measured memory_bytes: 3080
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int mod = 10009;
inline int modpow(int n, int m){
	int res = 1;
	for(; m; m >>= 1){
		if(m & 1) res = res * n % mod;
		n = n * n % mod;
	}
	return res;
}
int n, e[22][22];
int I[1 << 22], N[22];
bool kcolor(int k){
	ll ans = 0;
	rep(i, 1 << n){
		if(__builtin_popcount(i) % 2) ans -= modpow(I[i], k);
		else ans += modpow(I[i], k);
	}
	ans = (ans % mod + mod) %  mod;
	 
	return ans;
}
int color(){
	rep(i, n){
		int bit = 1 << i;
		rep(j, n) if(e[i][j]) bit |= 1 << j;
		N[i] = bit;
	}
	rep(i, 1 << n) I[i] = 0;
	I[0] = 1;
	for(int i = 1; i < 1 << n; i++){
		int v = 0;
		for(; !(i & 1 << v); v++);
		I[i] = I[i - (1 << v)] + I[i & ~N[v]];
		if(I[i] > mod) I[i] -= mod;
	}
	 
	int lo = 0, hi = n, mid;
	while(lo + 1 < hi){
		mid = (lo + hi) / 2;
		if(kcolor(mid)) hi = mid;
		else lo = mid;
	}
	return hi;
}
typedef complex<double> P;
namespace std{
	bool operator<(const P& a, const P& b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
inline double cross(const P& a, const P& b){ return imag(conj(a)*b); }
inline double dot(const P& a, const P& b){ return real(conj(a)*b); }
struct L : public vector<P>{
	L(const P &a, const P &b) {
		push_back(a); push_back(b);
	}
};
typedef vector<P> G;

inline int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if(cross(b, c) > 0)   return +1;		// counter clockwise
	if(cross(b, c) < 0)   return -1;		// clockwise
	if(dot(b, c) < 0)     return +2;		// c--a--b on line
	if(norm(b) < norm(c)) return -2;		// a--b--c on line
	return 0;
}
bool overlap(const L &a, const L &b){
	if(abs(cross(a[1] - a[0], b[1] - b[0])) > EPS) return 0;
	rep(i, 2){
		if(a[0] == b[i]  && a[1] == b[1 - i]) return 1;
		if(ccw(b[i], a[0], a[1]) == 2) return 1;
		if(ccw(a[i], b[0], b[1]) == 2) return 1;
	}
	return 0;
}

int main(){
	int m;
	while(cin >> m, m){
		vector<G> gs;
		string name[100];
		vector<string> s;
		rep(i, m){
			cin >> name[i];
			s.pb(name[i]);
			int x, y;
			G g;
			while(cin >> x, x >= 0){
				cin >> y;
				g.pb(P(x, y));
			}
			gs.pb(g);
		}
		memset(e, 0, sizeof(e));
		sort(all(s));
		s.erase(unique(all(s)), s.end());
		n = s.size();
		
		rep(i, m) rep(j, i) if(name[i] != name[j]){
			rep(k, gs[i].size()) rep(l, gs[j].size()){
				L a(gs[i][k], gs[i][(k + 1) % gs[i].size()]), b(gs[j][l], gs[j][(l + 1) % gs[j].size()]);
				if(overlap(a, b)){
					int p = lower_bound(all(s), name[i]) - s.begin();
					int q = lower_bound(all(s), name[j]) - s.begin();
					e[p][q] = e[q][p] = 1;
				}
			}
		}
		cout << color() << endl;
	}
	return 0;
}

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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void){
	int n;
	scanf("%d",&n);
	int a[n];
	int i;
	long ans = 0;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		a[i] -=i+1;
	}
	qsort(a, n, sizeof(int), compare_int); //qsortする。
	for(i=0;i<n;i++){
		ans += abs( a[i] - a[n/2]);
	}
	printf("%ld",ans);
	return 0;
}

Measured memory_bytes: 1788
import numpy as np

N ,M= map(int,input().split())
l=list(map(int,input().split()))
n0 = 2**int(np.ceil(np.log2(2*(max(l))-1)))

A = np.zeros(n0)
#B=np.zeros(n0)
#l=list(map(int,input().split()))

for i in range(N):
    A[l[i]-1]+=1
   # B[i]=l[i]

C = np.fft.ifft( np.fft.fft(A)*np.fft.fft(A) )
ans=0
j=2
q=[]
for ci in np.real(C[:2*(max(l))-1] + 0.5):
    #ans+=int(ci)*j
    q.append([int(ci),j])
    j+=1
q.reverse()
#print(q)
z=0
j=0
while z<M:
    ans+=q[j][0]*q[j][1]
    z+=q[j][0]
    j+=1
ans-=(z-M)*q[j-1][1]
print(ans)


Measured memory_bytes: 66244
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n,q;
  cin >> n >> q;
  ll a[n];
  REP(i,n){
    cin >> a[i];
  }
  ll x[q];
  REP(i,q){
    cin >> x[i];
  }
  REP(i,q){
    ll l = 0, r = 0;
    ll ans = 0;
    ll sum = 0;
    for(l=0; l<n; l++){
      while(r<n&&sum+a[r]<=x[i]){
        sum += a[r];
        r++;
      }
      ans += r-l;
      //if(r==l) r++;
      sum -= a[l];
    }
    cout << ans << endl;
  }
  return 0;
}



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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

int main() {
    ll n, m, q;
    cin >> n >> m >> q;
    vector<vector<ll>> nums(n + 1, vector<ll>(n + 1, 0));
    ll l, r;
    for (int i = 0; i < m; ++i) {
        cin >> l >> r;
        nums[l][r] += 1;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            nums[i][j] += nums[i - 1][j] + nums[i][j - 1] - nums[i - 1][j - 1];
        }
    }
    ll ans = 0;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r;
        ans = nums[r][r] - nums[l - 1][r] - nums[r][l - 1] + nums[l - 1][l - 1];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int L=1e5+10;
int rep[L];
int main() {
	int N,M;
	string S;
	cin >> N >> M >> S;
	for(int i=N;i>=0;i--){
		if(S[i]=='0'){
			rep[i]=i;
		}
		else{
			rep[i]=rep[i+1];
		}
	}
	vector<int> ret;
	int c=N;
	while(c>0){
		//cerr << c << endl;
		int k=max(c-M,0);
		k=rep[k];
		if(k<c){
			ret.push_back(abs(k-c));
		}
		else{
			cout << -1 << endl;
			return 0;
		}
		c=k;
	}
	reverse(ret.begin(),ret.end());
	auto sp="";
	for(auto i:ret){
		cout << sp << i;
		sp=" ";
	}
	cout << endl;




	return 0;
}



Measured memory_bytes: 1464
#include <stdio.h>
#include <stdint.h>
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))

int main(void) {
        int64_t init, N, K, a, b, result;
        result = 0;
        scanf("%lld %lld", &N, &K);
        // count case a < b
        for (b = 1; b <= N; b++) {
                // for each a from 1 to N,
                result += (N / b) * MAX(0, b - K);
                if (K == 0)
                        result -= 1;
                //printf("%d %d\n", b, result);
                result += MAX(N % b - K +1, 0);

                //printf("%lld %d\n", b, result);
        }
        printf("%lld\n", result);

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int A;
  int B;
  int C;
  cin >>A>> B>>C;
  int x=A+B+C;
  if(x >=22) {
cout << "bust" << endl;
  }
else {
cout << "win" << endl;
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
int par[MAX];
int root(int x){
	if(par[x] == x)return x;
	else return par[x] = root(par[x]);
}
int merge(int x, int y){
	x = root(x);
	y = root(y);
	par[x] = y;
}
set<int>st, ans;
int main(){
	int n, m, a, k, b;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <=m; ++i)par[i] = i;
	for(int i = 0; i < n; ++i){
		scanf("%d", &k);
		scanf("%d", &a);
		st.insert(a);
		for(int j = 0; j < k-1; ++j){
			scanf("%d", &b);
			merge(a, b);
		}
	}
	for(auto x : st)ans.insert(root(x));
	if(ans.size() > 1)puts("NO");
	else puts("YES");
}

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

const int INF = 10000;
int n,k;

int N[110];
int dp[110][4][4];

int f(int i, int a, int b)
{
	if(i==n)return 1;
	if(dp[i][a][b]>=0)return dp[i][a][b];
	if(N[i]!=0){
		return dp[i][a][b] = f(i+1,N[i],a)%INF;
	}
	
	return dp[i][a][b] = ((a==b&&a==1)||(a==N[i+1]&&a==1)||(N[i+1]==N[i+2]&&N[i+1]==1)?0:f(i+1,1,a)) + 
						 ((a==b&&a==2)||(a==N[i+1]&&a==2)||(N[i+1]==N[i+2]&&N[i+1]==2)?0:f(i+1,2,a)) + 
						 ((a==b&&a==3)||(a==N[i+1]&&a==3)||(N[i+1]==N[i+2]&&N[i+1]==3)?0:f(i+1,3,a));
}

int main()
{	
	int a,b;
	cin >> n >> k;
	for (int i = 0; i < k; ++i){
		cin >> a >> b;
		N[a-1] = b;
	}
	fill((int*)dp,(int*)(dp+(sizeof(dp)/sizeof(*(dp)))),-1);
	cout << f(0,0,0)%INF << endl;
	
	return 0;
}

Measured memory_bytes: 1176