akhauriyash/Code-Regression huggingface dataset:
def gcd(m, n):
    return m if n == 0 else gcd(n, m%n)


def lcm(m, n):
    return m // gcd(m, n) * n


def main():
    MOD = 10**9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    m = 1
    for i in a:
        m = lcm(m, i)
    
    ans = 0
    for i in a:
        b = m // i
        ans += b
    
    print(ans%MOD)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4084
import collections
n=int(input())
graph=[]
for i in range(n+1):
  graph.append([])
for i in range(n-1):
  a,b=map(int,input().split())
  graph[a].append(b)
  graph[b].append(a)
c=list(map(int,input().split()))
c.sort()
c.reverse()
ans=['0']*n
pointer=0
queue=collections.deque([[1,1]])
while queue:
  a=queue.popleft()
  ans[a[0]-1]=str(c[pointer])
  for i in graph[a[0]]:
    if i==a[1]:
      continue
    queue.append([i,a[0]])
  pointer+=1
print(sum(c)-c[0])
print(' '.join(ans))

Measured memory_bytes: 75864
#include<bits/stdc++.h>
#define lint long long int
using namespace std;
int main()
{
	lint a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a&&c)
	{
		c-=b;
		if(c<=0) break;
		a-=d;
	}
	if(a<=0)
	{
		cout<<"No"<<endl;
	}
	else 
	{
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  pair<string,int> p[n];
  int sum=0;
  rep(i,n){
    cin>>p[i].fst>>p[i].scd;
    sum+=p[i].scd;
    if(i!=0) p[i].scd+=p[i-1].scd;
  }
  string s;
  cin>>s;
  rep(i,n){
    if(s==p[i].fst){
      cout<<sum-p[i].scd<<endl;
      return 0;
    }
  }

  return 0;
}


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

int main()
{
  int n;
  cin>>n;
  double *prob = new double[n+1];
  for(int i=1;i<=n;i++)
  {
    cin>>prob[i];
  }

  double **heads = new double*[n+1];
  for(int i=0;i<=n;i++)
  {
    heads[i] = new double[n-i+1];
    for(int j=0;j<n-i+1;j++)
    {
      heads[i][j] = 0.0;
    }
  }
  heads[0][0] = 1.0;
  for(int i=1;i<=n;i++)
  {
    for(int j=0;j<=i-1;j++)
    {
      heads[j+1][i-1-j]+= heads[j][i-1-j] * prob[i];
      heads[j][i-1-j+1]+= heads[j][i-1-j] * (1.0-prob[i]);
    }
  }
  double sum=0.0;
  for(int i=((n+1)/2);i<=n;i++)
  {
    sum+= heads[i][n-i];
  }
  cout<<setprecision(10)<<sum<<"\n";
  return 0;
}


Measured memory_bytes: 35456
import java.util.Scanner;

public class Main {
  private static final int M = 1_000_000_007;
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int X = scanner.nextInt();
    int Y = scanner.nextInt();
    if ((X + Y) % 3 != 0) {
      System.out.println(0);
      return;
    }

    int n = (X + Y) / 3;
    if (X < n || Y < n) {
      System.out.println(0);
      return;
    }
    System.out.println(choose(n, Y - n, M));
  }

  public static long choose(long n, long k, long mod) {
    if (k > n - k) return choose(n, n - k, mod);
    long res = 1;
    for (int i = 0; i < k; i++) {
      res = (res * (n - i)) % mod;
    }
    for (int i = 1; i <= k; i++) {
      res = (res * inverse(i, mod)) % mod;
    }
    return res % mod;
  }

  private static long inverse(long a, long mod) {
    return modpow(a, mod - 2, mod);
  }

  private static long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
      if (n % 2 == 1) res = (res * a) % mod;
      a = (a * a) % mod;
      n >>= 1;
    }
    return res % mod;
  }
}


Measured memory_bytes: 21844
k = int(input())
arr = list(map(int, input().split()))

a = arr[0]
b = arr[1]

count=0

now_max = arr[0]

for num in range(a,b+1):
    if num%k==0:
        print('OK')
        break
    elif num==b and num%k!=0:
        print('NG')


Measured memory_bytes: 9188
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

    set<int> a;
    for (int i = 0; i < n; i++) {
        int num;
        cin >> num;
        
        if (a.count(num) != 0) {
            cout << "NO" << endl;
            return 0;
        }
        a.insert(num);
    }
    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>

using namespace std;

int main(){
    long long n, m;
    cin >> n >> m;
    multimap<long long, long long> edge;
    for(long long i = 0; i < m; i++){
        long long a, b;
        cin >> a >> b;
        edge.insert(make_pair(a, b));
        edge.insert(make_pair(b, a));
    }
    long long ans[n+1] = {0};
    queue<long long> q;
    q.push(1);
    set<long long> existNum;
    existNum.insert(1);
    while(!q.empty()){
        long long cur = q.front();
        // cerr << "cur=" << cur << endl;
        q.pop();
        multimap<long long, long long>::iterator itr = edge.find(cur);
        if(itr != edge.end()){
            long long pnum = edge.count(cur);
            for(long long i = 0; i < pnum; i++){
                if(existNum.find(itr->second) == existNum.end()){
                    // cerr << itr->second << endl;
                    ans[itr->second] = cur;
                    existNum.insert(itr->second);
                    q.push(itr->second);
                }
                itr++;
            }
        }
    }
    if(existNum.size() < n-1){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        for(long long i = 2; i < n+1; i++){
            cout << ans[i] << endl;
        }
    }
    return 0;
}

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

int main(){
  int N;cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin>>A.at(i);
  sort(A.begin(),A.end());
  cout<<A.at(N-1)-A.at(0)<<endl;
}

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

char maze[MAX_N];
ll N;
ll A,B,C,D;

ll d[MAX_N];

bool ok(ll x,ll y) {
    bool res=true;
    for(ll i=x;i<y;++i){
        if(maze[i]=='#' && maze[i+1]=='#')res=false;
    }
    return res;
}

int main(){
    cin >> N >> A >> B >> C >> D;
    A--;B--;C--;D--;
    rep(i,N)cin >> maze[i];
    ll x1,x2,y1,y2;
    x1=max(A,B);
    x2=min(A,B);
    if(A>B){
        y1=C;
        y2=D;
    }else{
        y1=D;
        y2=C;
    }
    ll res1=true,res2=true;
    maze[x2]='#';
    if(!ok(x1,y1)){
        res1=false;
        for(ll i=x2;i<y2;++i){
            if(maze[i]=='.' && maze[i+1]=='.' && maze[i+2]=='.')res1=true;
        }
    }
    maze[y1]='#';
    maze[x2]='.';
    if(!ok(x2,y2)){
        res1=false;
        maze[y1]='.';
        for(ll i=x1;i<y1;++i){
            if(maze[i]=='.' && maze[i+1]=='.' && maze[i+2]=='.')res1=true;
        }
    }

    maze[x2]='.';
    maze[y1]='.';
    maze[x1]='#';
    if(!ok(x2,y2)){
        res2=false;
        for(ll i=x1;i<y1;++i){
            if(maze[i]=='.' && maze[i+1]=='.' && maze[i+2]=='.')res2=true;
        }
    }
    maze[y2]='#';
    maze[x1]='.';
    if(!ok(x1,y1)){
        res2=false;
        maze[y2]='.';
        for(ll i=x2;i<y2;++i){
            if(maze[i]=='.' && maze[i+1]=='.' && maze[i+2]=='.')res2=true;
        }
    }

    if(res1 || res2)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;
 
public class Main{
 
    public static void main(String[] args) {
 
        int a = 0;
        String operator = "";
        int b = 0;
 
        // テキスト入力
        Scanner sc = new Scanner(System.in);
        String out = "";
 
        // 演算子の変数に入っている中身で場合わけ
        while (true) {
 
            //
            while (sc.hasNext()) {
                a = sc.nextInt();
                operator = sc.next();
                b = sc.nextInt();
                break;
            }
 
            if (operator.equals("?")) {
                break;
 
            } else if (operator.equals("/")) {
                out = out + a / b + "\n";
 
            } else if (operator.equals("*")) {
                out = out + a * b + "\n";
 
            } else if (operator.equals("+")) {
                out = out + (a + b) + "\n";
 
            } else if (operator.equals("-")) {
                out = out + (a - b) + "\n";
            }
        }
        // 出力
        System.out.print(out);
    }
}

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

const ll MOD=1e9+7;
int main(){
    int n;
    cin>>n;
    vector<int> x(n),v(n);
    for(int i=0;i<n;i++) cin>>x[i]>>v[i];
    {
        vector<int> ids(n);
        iota(ids.begin(),ids.end(),0);
        sort(ids.begin(),ids.end(),[&](int lhs,int rhs){return x[lhs]<x[rhs];});
        for(int i=0;i<n;i++){
            x[ids[i]]=i;
        }
    }

    vector<int> ranges(n,-1);
    {
        vector<int> ids(n);
        iota(ids.begin(),ids.end(),0);
        vector<int> r(n);
        sort(ids.begin(),ids.end(),[&](int lhs,int rhs){return v[lhs]<v[rhs];});
        int tmp=0;
        for(int i=0;i<n;i++){
            int id=ids[i];
            tmp=max(tmp,x[id]);
            r[id]=tmp;
        }
        tmp=n-1;
        vector<int> l(n);
        for(int i=n-1;i>=0;i--){
            int id=ids[i];
            tmp=min(tmp,x[id]);
            l[id]=tmp;
        }

        for(int i=0;i<n;i++){
            ranges[r[i]]=max(ranges[r[i]],l[i]);
        }
    }
    vector<ll> dp(n+1);
    dp[0]=1;
    ll sum=1;
    int bound=0;
    for(int i=0;i<n;i++){
        dp[i+1]=sum;
        sum+=dp[i+1];
        sum%=MOD;
        while(bound<=ranges[i]){
            sum-=dp[bound];
            sum%=MOD;
            dp[bound]=0;
            bound++;
        }
    }
    sum=(sum%MOD+MOD)%MOD;
    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 5076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int main(){
	string s;cin>>s;
	int l=-1,r=-1,ans=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A'&&l==-1){
			l=i;
		}
		else if(s[i]=='Z') r=i;
		if(r>l&&r-l+1>ans) ans=r-l+1;	
	}
	cout<<ans;
	return 0;
}

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

int main()
{
  int N, L, j, ans = 300;
  cin >> N >> L;

  for(int i = 1; i <= N; i++){
    if(ans > abs(L + i - 1)){
      ans = abs(L + i -1);
      j = i;
    }
  }

  int sum = 0;
  for(int i = 1; i <= N; i++){
    if(i != j)
      sum += L + i -1;
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bitset>
#include<string>
using namespace std;
string tbl01[]={
	"101","000000","000011","10010001","010001","000001","100101","10011010",
	"0101","0001","110","01001","10011011","010000","0111","10011000",
	"0110","00100","10011001","10011110","00101","111","10011111","1000",
	"00110","00111","10011100","10011101","000010","10010010","10010011","10010000"
};
string tbl01_idx=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string str_AB=" .,-'?";

string from01(string s){
	string r;
	for(int i=0;i<s.size();){
		for(int j=0;j<32;j++){
			if(s.substr(i,tbl01[j].size())!=tbl01[j]){
				if(j==31)return r;
				continue;
			}
			i+=tbl01[j].size();
			r+=tbl01_idx[j];
			break;
		}
	}
}
string fromAB(string &s){
	string r;
	for(int i=0;i<s.size();i++){
		int c=str_AB.find(s[i]);
		if(c==str_AB.npos)c=s[i]-'A';
		else c+=26;
		r+=bitset<5>(c).to_string<char,char_traits<char>,allocator<char> >();
	}
	return r;
}
int main(){
	string s;
	while(getline(cin,s))cout<<from01(fromAB(s))<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int min(int a[], int n);
int max(int a[], int n);
long sum(int a[], int n);
int main(void) {
  int n, i;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  if (n <= 0) {
    puts("0 0 0");
  } else {
    printf("%d %d %ld\n", min(a,n), max(a,n), sum(a,n));
  }
  return 0;
}
int min(int a[], int n) {
  int min = a[0];
  int i;
  for (i = 1; i < n; i++) {
    if (min > a[i]) min = a[i];
  }
  return min;
}
int max(int a[], int n) {
  int max = a[0];
  int i;
  for (i = 1; i < n; i++) {
    if (max < a[i]) max = a[i];
  }
  return max;
}
long sum(int a[], int n) {
  long sum = 0;
  int i;
  for (i = 0; i < n; i++) {
    sum += a[i];
  }
  return sum;
}


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

int main() {
  int n;
  cin >> n;
  
  int a, b, cnt = 0;
  bool check = false;
  for(int i=0; i<n; i++) {
    cin >> a >> b;
    if(a==b) cnt++;
    else cnt = 0;
    if(cnt==3) {
      check = true;
      break;
    }
  }
  
  if(check) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3644
from itertools import permutations


def main():
    n = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))

    a = None
    b = None

    perms = tuple(permutations(range(1, n + 1), n))

    for i in range(len(perms)):
        if a is None and tuple(perms[i]) == p:
            a = i
        if b is None and tuple(perms[i]) == q:
            b = i
        if a is not None and b is not None:
            print(abs(a - b))
            exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 13836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll ans = 0;
    while(true)
    {
        bool flag = false;
        for(int i = 0; i < n; i++)
        {
            if(a[i] >= n)
            {
                ll dec = a[i] / n;
                a[i] = a[i] % n;
                for(int j = 0; j < n; j++)
                {
                    if(j == i) continue;
                    a[j] += dec;
                }
                ans += dec;
                flag = true;
            }
        }
        if(!flag) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
	const int max = 101;
	char buf[max];
	char *half;
	int len;
	set<char> a, b, result;
	int maxcount = 0, count;

	scanf("%d", &len);
	scanf("%s", buf);

	for (int i = 1; i < len; i++) {
		half = &buf[i];
		for (int j = 0; &buf[j] != half; j++) {
			a.insert(buf[j]);
		}
		for (; *half != '\0'; half++) {
			b.insert(*half);
		}
		set_intersection(a.begin(), a.end(), b.begin(), b.end(), 
						inserter(result, result.end()));
		count = 0;
		for (set<char>::iterator itr = result.begin();
				itr != result.end(); itr++) {
			count++;
		}
		if (count > maxcount) {
			maxcount = count;
		}
		a.erase(a.begin(), a.end());
		b.erase(b.begin(), b.end());
		result.erase(result.begin(), result.end());
	}

	cout << maxcount << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
  int n, ans=0;
  vector<int> l;
  cin >> n;
  for(int i=0;i<n;i++) {
    int p;
    cin >> p;
    l.push_back(p);
  }
  sort(l.begin(), l.end());
  for(int i=0;i<n-2;i++) {
    for(int j=i+1;j<n-1;j++) {
      for(int k=j+1;k<n;k++) {
        if(l[k]<l[i]+l[j] && l[i]!=l[j] && l[j]!=l[k] && l[i]!=l[k]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int ans = 0;
    auto c = [](char x){return x == '9';};
    if (all_of(s.begin()+1, s.end(), c)) {
        ans = s[0] - '0';
    } else {
        ans = s[0] - '1';
    }
    ans += (n-1)*9;
        
    cout << ans << endl;
}


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

int main(void){
	string s;
	bool mode = false;
	int cnt = 0;
	set<char> st = {'y','u','i','o','p','h','j','k','l','n','m'};
	while(true){
		cin >> s;
		if(s == "#") break;
		for(int i = 0; i < s.size(); ++i){
			if(st.find(s[i]) != st.end()){
				if(mode){
					cnt++;
					mode = !mode;
				}
			}else{
				if(!mode){
					cnt++;
					mode = !mode;
				}
			}
			if(i == 0) cnt = 0;
		}
		cout << cnt << endl;
	}
	return 0;
}


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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int imos[100010];

int main () {
    int n;
    imos[0]++;
    imos[100002]--;
    cin >> n;
    REP (i, 0, n) {
        int a, b;
        cin >> a >> b;
        imos[a]++;
        imos[b + 1]--;
    }
    REP (i, 1, 100010) imos[i] += imos[i - 1];
    int ans = 0;

    REP (i, 0, 100010) {
        if (imos[i] >= i) ans = i;
    }
    cout << ans - 1 << endl;
    return 0;
}

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

7+1=8
1000
111
001
110

1101
0010

最大でも111111
１回でも11同士があたったらだめ
しゃくとり？

1 2 4 1
1---3でOUT
1-3なのか2-3なのかわからない
1-3だったら2-3はとれる 2-3だったら、
1-3だめで2-3OKはありうる
これっぽい
ちがうか
いや、取り除いてく感じかな

1 2 4 1
1点
　2点
    3点
      NGだったから、頭の1をひく
  2 4 1
      2点
      
      
001
010
100
111
001
110
*/
int main(){
  ll N,ans=0,X=0,S=0,cnt=0; cin>>N;
  vector<ll> A(N,0);
  for(ll i=0; i<N; i++) cin>>A[i];
  for(ll i=0; i<N; i++){
    S+=A[i];
    X^=A[i];
    cnt++;
    if(S==X) ans+=cnt;
    else{
      while(S!=X){
        cnt--;       
        S-=A[i-cnt];
        X^=A[i-cnt];
      }
      ans+=cnt;  
    }  
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
from heapq import heappop, heappush

N,M = map(int,input().split())
LRC = [list(map(int,input().split())) for _ in range(M)]

INF = float('inf')
def dijkstra(s,n,g): # sからの最短距離 頂点数n g[v]=[(u1,w1),(u2,w2)....]:vからuへの有向辺があり、重みw
  que = []
  d = [INF for _ in range(n)]
  d[s] = 0
  heappush( que,(0,s) )
  while len(que)>0:
    p =  heappop(que)
    v = p[1]
    if d[v] < p[0]:
      continue
    for i in range(len(g[v])):
      edge = g[v][i]
      if d[edge[0]] > d[v] + edge[1]:
        d[edge[0]] = d[v] + edge[1]
        heappush( que,(d[edge[0]] , edge[0]) )
  return d

G = [[] for _ in range(N)]
for i in range(N-1):
  G[i+1].append((i,0))
for l,r,c in LRC:
  l -= 1
  r -= 1
  G[l].append((r,c))

p = dijkstra(0,N,G)[N-1]
print(p if p != INF else -1)


Measured memory_bytes: 99416
N, M = map(int, input().split())

ab = []
for i in range(N):
    tmp = list(map(int ,input().split()))
    ab.append(tmp)
    
cd = []
for i in range(M):
    tmp = list(map(int, input().split()))
    cd.append(tmp)
    
for i in range(N):
    a, b = ab[i][0], ab[i][1]
    d = 10**12
    for j in range(M):
        tmp = abs(a - cd[j][0]) + abs(b - cd[j][1])
        if tmp < d:
            d = tmp
            ans = j+1
    print(ans)

Measured memory_bytes: 3064
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i).sort.reverse
b = gets.strip.split.map(&:to_i).sort
c = gets.strip.split.map(&:to_i).sort

#p a
#p b
#p c

result = 0
b.each do |current_b|
  a_count = a.length - (a.bsearch_index {|c_a| c_a < current_b } || a.length)
  c_count = c.length - (c.bsearch_index {|c_c| c_c > current_b } || b.length)
  result += a_count*c_count
end

p result


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

int main()
{
    char RGB[3];
    cin >> RGB[0] >> RGB[1] >> RGB[2];

    int num = atoi(RGB);

    if(num % 4 == 0)cout << "YES";
    else cout << "NO";
    cout << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ans=10**18
for i in range(2):
    accum=0
    cnt=0
    if i:
        for i in range(n):
            if i%2:
                if accum+a[i]>=0:
                    cnt+=(accum+a[i])+1
                    accum=-1
                else:
                    accum+=a[i]
            else:
                if accum+a[i]<=0:
                    cnt+=1-(accum+a[i])
                    accum=1
                else:
                  accum+=a[i]
        ans=min(ans,cnt)
    else:
        for i in range(n):
            if i%2==0:
                if accum+a[i]>=0:
                    cnt+=(accum+a[i])+1
                    accum=-1
                else:
                    accum+=a[i]
            else:
                if accum+a[i]<=0:
                    cnt+=1-(accum+a[i])
                    accum=1
                else:
                    accum+=a[i]
        ans=min(ans,cnt)
print(ans)

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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
typedef long long ll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int main(){
    int n,m;
    cin >> n >> m;
    vector<ll> x(m);
    rep(i,m){
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    if(m<=n){
        cc(0);
        return 0;
    }
    vector<ll> sa(m-1);
    rep(i,m-1){
        sa[i]=x[i+1]-x[i];
    }
    sort(sa.begin(), sa.end(), greater<int>());
    ll sigma = accumulate(sa.begin(), sa.end(), 0);
    ll sasa = 0;
    rep(i, n-1){
        sasa += sa[i];
    }
    cc(sigma - sasa);
}

Measured memory_bytes: 1792
#include <iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn = 1e5 + 10;
struct node
{
    ll id;
    long long value;
} a[maxn], b[maxn], c[maxn], d[3*maxn];

bool cmp(const node a, const node b)
{
    if(a.value != b.value)
        return a.value > b.value;
    else
        return a.id < b.id;
}
int main()
{
    ll x, y, e, f, g, num;
    scanf("%lld %lld %lld %lld %lld", &x, &y, &e, &f, &g);
    for(ll i = 1; i <= e; i++)
    {
        scanf("%lld", &num);
        d[i].value = num;
        d[i].id = 1;
    }
    for(ll i = 1; i <= f; i++)
    {
        scanf("%lld", &num);
        d[i+e].value = num;
        d[i+e].id = 2;
    }
    for(ll i = 1; i <= g; i++)
    {
        scanf("%lld", &num);
        d[i+e+f].value = num;
        d[i+e+f].id = 3;
    }
    sort(d + 1, d + 1 + e + f + g, cmp);
    long long sum = 0;
    int change = 0;
    for(int i = 1; i <= e + f + g; i++)
    {
        if(x + y <= change)
            break;
        if(d[i].id == 1 && x > 0){
            sum += (long long)(d[i].value);
            x--;
        }
        else if(d[i].id == 2 && y > 0){
            sum += (long long)(d[i].value);
            y--;
        }
        else if(d[i].id == 3 && x + y > change){
            sum += (long long)(d[i].value);
            change++;
        }
    }
    printf("%lld", sum);

    return 0;
}


Measured memory_bytes: 6400
#include<iostream>

using namespace std;

int main(void){
    
    int n,otsuri,count;
    const int money[6]={1,5,10,50,100,500};

    while(cin>>n,n){
            
        otsuri=1000-n;
        count=0;
        for(int i=5;i>=0;i--){
            while(otsuri>=money[i]){
                otsuri=otsuri-money[i];
                count++;
            }   
        }   
        cout<<count<<endl;
    }   


}

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

def digit_sum(n, b):
    if b == 1:
        return n
    res = 0
    while n > 0:
        res += n % b
        n //= b
    return res

def main():
    n = int(input())
    s = int(input())
    
    ans = -1
    if n == s:
        ans = n + 1
    else:
        for b in range(2, int(n**0.5) + 1):
            if digit_sum(n, b) == s:
                ans = b
                break
        
        else:
            for p in range(1, int(n**0.5)+1):
                b = (n - s) // p + 1
                if b >= 2 and digit_sum(n, b) == s:
                    if ans == -1:
                        ans = b
                    else:
                        ans = min(ans, b)
                
                if b >= 1 and digit_sum(n, b+1) == s:
                    if ans == -1:
                        ans = b+1
                    else:
                        ans = min(ans, b+1)

    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 74080
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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 ll INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  int n, a;
  cin >> n >> a;
  vector<int> x(n);
  vector<int> low;
  vector<int> high;
  vector<int> same;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    x[i] = tmp;
    if (tmp == a) {
      same.push_back(tmp);
    } else if (tmp < a) {
      low.push_back(a - tmp);
    } else {
      high.push_back(tmp - a);
    }
  }

  // 50 * 50 -> スコアの合計の最大値は 2500

  int sumh = SUM(high);
  int suml = SUM(low);

  vector<ll> dph(2501, 0);
  vector<ll> dpl(2501, 0);

  for (int i = 0; i < high.size(); i++) {
    for (int j = sumh; j >= high[i]; j--) {
      // i 番目までの要素を使って合計がjになるパターン数
      if (high[i] == j) {
        dph[j]++;
      } else if (j - high[i] >= 0 && dph[j - high[i]] != 0) {
        dph[j] += dph[j - high[i]];
      }
    }
  }
  // rep(i, 10) {
  //   cerr << dph[i] << " ";
  // }
  cerr << endl;
  for (int i = 0; i < low.size(); i++) {
    for (int j = suml; j >= low[i]; j--) {
      // i 番目までの要素を使って合計がjになるパターン数
      if (low[i] == j) {
        dpl[j]++;
      } else if (j - low[i] >= 0 && dpl[j - low[i]] != 0) {
        dpl[j] += dpl[j - low[i]];
      }
    }
  }

  ll ans = same.size() == 0 ? 0 : (pow(2, same.size()) - 1);
  rep(i, 2501) {
    ans += dpl[i] * dph[i] * pow(2, same.size());
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int a, b;
    cin >> a >> b;
    if (a < b)
    {
        rep(i, b)
        {
            cout << a;
        }
        cout << endl;
    }
    else
    {
        rep(i, a)
        {
            cout << b;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  string n ;
  cin >> n ;
  
  if(n.at(0)==n.at(2)){
    cout <<"Yes"<<endl ;
  }
  else{
    cout <<"No"<<endl ;
  }
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;

int ans[500][500];
void distribute(vector<int> v,int tmp) {
	if (v.size() == 0 || v.size() == 1)return;
	int len = v.size();
	int d = len / 2;
	vector<int> le,ri;
	rep(i, d)le.push_back(v[i]);
	Rep(i, d, len) {
		ri.push_back(v[i]);
	}
	distribute(le, tmp+1);
	distribute(ri, tmp + 1);
	rep(i, d) {
		Rep(j, d, len) {
			ans[v[i]][v[j]] = tmp;
		}
	}
}
void solve() {
	int n; cin >> n;
	vector<int> ori(n);
	rep(i, n) {
		ori[i] = i;
	}
	distribute(ori, 1);
	rep(i, n) {
		Rep(j, i + 1, n) {
			if (j > i + 1)cout << " ";
			cout << ans[i][j];
		}
		cout << endl;
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//init();
	solve();

	//cout << "finish" << endl;
	//stop
	return 0;
}

Measured memory_bytes: 1536
mod = 10**9+7

def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%mod
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], mod -2, mod)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % mod
    return frac, fraci
frac, fraci = frac(200000)

def count(S):
    res = 1
    cnt = 0
    for s in S:
        if s:
            cnt += 1
        else:
            res = (res*cnt)%mod
            cnt -= 1
        if cnt < 0:
            return 0
    return res
N = int(input())
S = [1 if s == 'B' else 0 for s in input().strip()]
L = 2*N
S = [(S[i] + i)%2 for i in range(L)]
if sum(S) != N:
    print(0)
else:
    print(count(S)*frac[N]%mod)

Measured memory_bytes: 62052
using System;

namespace ITP1_1_A
{
    class Program
    {

        static private int max;
        static private int sum;
        static private bool finish;

        static void Main(string[] args)
        {
            while (true)
            {
                inputNum();
                if (finish) return;
                Console.WriteLine(CountWays());
            }
        }

        static void inputNum()
        {
            string[] num = Console.ReadLine().Split();
            if (int.Parse(num[0]) == 0 && int.Parse(num[1]) == 0)
            {
                finish = true;
                return;
            }
            max = int.Parse(num[0]);
            sum = int.Parse(num[1]);
        }

        static int CountWays()
        {
            int count = 0;
            for (int i = 1; i <= max; i++)
            {
                for (int j = i+1; j <= max; j++)
                {
                    for (int k = j+1; k <= max; k++)
                    {
                        if(i+j+k==sum&&!(i==j||j==k||k==i)) count++;
                    }
                }
            }
            return count;
        }
    }
}



Measured memory_bytes: 7876
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

        double prob = 0;

        for (int i = 1; i <= n; i++){
            // 最初のサイコロの目について、確率を計算する
            prob = prob + eachProb(i, k);
        }

        System.out.println(prob / (double) n);
    }

    private static double eachProb(int deme, int k){
        if (deme >= k){
            return 1;
        }

        for (int i = 1; i < 100; i++){
            if (deme * Math.pow(2, i) >= k){
                return 1/ Math.pow(2, i);
            }
        }
        // 実質的にここは通らないはず
        return 0;

    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
using namespace std;
int main(){
    string s;
    cin >> s;
    int N = s.size();
    long long rsl = 0;
    vector<int>w,b;
    for(int i=0; i<N; i++){
        if(s[i]=='B'){
            b.push_back(i);
        }else{
            w.push_back(i);
        }
    }
    for(int i=0; i<w.size(); i++){
        rsl += w[i] - i;
    }
    cout << rsl << endl;
    return 0;
}

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

//-std=c++11
//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long
#define FI ios_base::sync_with_stdio(0); cin.tie(NULL);
#define PREC cout << setprecision(10) << fixed;

#define PB push_back
#define MP make_pair

const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
const int MX = 1e5 + 5;

const int mxn = 1e6 + 5;
int minPrime[mxn];
void aux_func()
{
	for (int i = 2; i * i <= mxn; i++) 
	{
		//if i is prime
		if (minPrime[i] == 0) 
		{ 
			for (int j = i * i; j <= mxn; j += i)
			{
				// not yet found
				if(minPrime[j] == 0)
					minPrime[j] = i;
			}
		}
	}
	for (int i = 2; i <= mxn; ++i) 
	{
		if (minPrime[i] == 0) 
			minPrime[i] = i;
	}
}

vector<pair<int,int> > factorize(int n) 
{
	vector< pair<int,int> > res;
	while (n != 1) 
	{
		int cnt = 0;
		int div = minPrime[n];
		while(n % div == 0)
		{
			n /= div;
			cnt++;
		}
		res.PB(MP(div,cnt));
	}
	return res;
}

int main()
{
	aux_func();
	int n;
	cin >> n;
	int ans = 0;
	for(int c=1;c<n;c++) {
		int val = n-c;
		vector<pair<int,int> > fact = factorize(val);
		int cnt = 1;
		for(int i=0;i<fact.size();i++) {
			cnt = cnt * (fact[i].second + 1);		
		}

		ans += cnt;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 7532
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var cnt, ans int

func main() {
	reader.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())
	M, _ := strconv.Atoi(read())

	arr := make(SortBy, N)
	for i := 0; i < N; i++ {
		arr[i] = make([]int, 2)
		arr[i][0], _ = strconv.Atoi(read())
		arr[i][1], _ = strconv.Atoi(read())
	}
	sort.Sort(arr)
	pq := &PriorityQueue{}
	heap.Init(pq)
	var j int
	for i := M - 1; 0 <= i; i-- {
		for j < len(arr) {
			if arr[j][0]+i <= M {
				heap.Push(pq, arr[j][1])
				j++
			} else {
				break
			}
		}
		if pq.Len() != 0 {
			ans += heap.Pop(pq).(int)
		}
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i][0] == a[j][0] {
		return a[i][1] > a[j][1]
	}
	return a[i][0] < a[j][0]
}

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] > h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 9984
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

N = int(input())
As = list(map(int, input().split()))

Ss = dict()

for i in range(1, N):
    a = As[i-1] - 1
    if (a in Ss):
        Ss[a] += 1
    else:
        Ss[a] = 1

for i in range(0, N):
    if (i in Ss):
        print(Ss[i])
    else:
        print(0)


Measured memory_bytes: 38796
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,d,k;
    cin >> n >> d >>k;
    int cnt=0;
    rep(i,n){
        int m;
        cin>> m;
        cnt+=(d-1)/m+1;
    }

    cout << cnt+k;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
pair<int, int> e(pair<int, int> a, pair<int, int> b) {
    if (a.second*b.first >= a.first*b.second) {
        return a;
    }
    else {
        return b;
    }
}
int main () {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    pair<int, int> ans = make_pair(100*A, 0);
    for (int a = 0; a <= F; a += 100*A) {
        for (int b = 0; a+b <= F; b += 100*B) {
            if (a+b != 0) {
                for (int c = 0; a+b+c <= F; c += C) {
                    for (int d = 0; a+b+c+d <= F; d += D) {
                        if ((a+b) / 100 * E >= c+d) {
                            ans = e(ans, make_pair(a+b+c+d, c+d));
                        }
                    }
                }
            }
        }
    }
    printf("%d %d\n", ans.first, ans.second);
}

Measured memory_bytes: 256
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
N=II()
List=[]
for i in range(N):
  tmp=LI()
  List.append(tmp)
cnt=0
Max=0
for i in range(N):
  if List[i][0]==List[i][1]:
    cnt+=1
  else:
    cnt=0
  Max=max(cnt,Max)
if Max>=3:
  print('Yes')
else:
  print('No')
  

Measured memory_bytes: 9108
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int i = 1;
        int a;
        long Sum = 0;
        int Max = -1000000;
        int Min = 1000000;
        while (i <= n) {
            a = scan.nextInt();
            Sum += a;
            if (Max < a) {
                Max = a;

            }
            if (Min > a) {
                Min = a;
            }
            i++;
        }
        System.out.println(Min + " " + Max + " " + Sum);
    }
}


Measured memory_bytes: 41164
package main

import (
	"fmt"
	"strings"
)

func main(){
	var S,T string
	fmt.Scan(&S,&T)
	var strs []string
	strs = strings.Split(T, "")
	strs = strs[:len(strs)-1]
	new:=strings.Join(strs, "")
	if S==new{
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
	
}

Measured memory_bytes: 1824
#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int x; scanf("%d", &x); return x; }
long long lin() { long long x; scanf("%lld", &x); return x; }

signed main() { 
        int a, b;
        cin >> a >> b;
        if (a + b >= 10) cout << "error" << endl;
        else cout << a + b << endl;
        return 0;
}               



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

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;

int N,M, visit[100001];
vi adj[100001];
int num[2], ed, bi;
ll ans = 0;

void dfs(int node, int val) {
    visit[node] = val; num[val] ++;
    for (int i: adj[node]) {
        if (visit[i] == -1) dfs(i,val^1);
        else if (visit[i] == val) bi = 0;
    }
}

void process(int x) {
    num[0] = num[1] = 0, bi = 1;
    dfs(x,0);
    if (bi) {
        ans += (ll)num[0]*num[1];
    } else {
        ll no = num[0]+num[1];
        ans += no*(no-1)/2;
    }
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> N >> M;
	F0R(i,M) {
	    int a,b; cin >> a >> b;
	    adj[a].pb(b), adj[b].pb(a);
	}
	FOR(i,1,N+1) visit[i] = -1;
	FOR(i,1,N+1) if (visit[i] == -1) process(i);
	ans -= M;
	cout << ans;
}

// read!
// ll vs. int!

Measured memory_bytes: 6912
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>


using namespace std;
typedef long long ll;

#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 100


void calc(int n){
    int m,x,y,p,q,r,vec_x=0,vec_x1=0,vec_y=0,vec_y1=0;
    vector<pair<int,int> > cards;
    
    scanf("%d%d%d%d",&m,&p,&q,&r);
    
    cards.push_back(make_pair(1,n));
    
    for(int i=0;i<m;i++){
        vector<pair<int,int> > cards2;
        vector<int> count;
        
        scanf("%d%d",&x,&y);
        
        count.push_back(1);
        
        for(int j=0;j<cards.size();j++){
            count.push_back(count[j] + cards[j].second-cards[j].first+1);
            
            if(count[j] <=  x  &&  x  < count[j+1]){
                vec_x  = j;
            }
            if(count[j] <= x+1 && x+1 < count[j+1]){
                vec_x1 = j;
            }
            if(count[j] <=  y  &&  y  < count[j+1]){
                vec_y  = j;
            }
            if(count[j] <= y+1 && y+1 < count[j+1]){
                vec_y1 = j;
            }
            
        }
        
        /*y+1 - n*/
        
        cards2.push_back(make_pair(cards[vec_y1].first+(y+1-count[vec_y1]),
                                   cards[vec_y1].second));
        
        for(int j=vec_y1+1;j<cards.size();j++){
            cards2.push_back(cards[j]);
        }
        
        /*x+1 - y*/
        if(vec_x1 != vec_y){
            cards2.push_back(make_pair(cards[vec_x1].first+(x+1-count[vec_x1]),cards[vec_x1].second));
        
            for(int j=vec_x1+1;j<vec_y;j++){
                cards2.push_back(cards[j]);
            }
        
            cards2.push_back(make_pair(cards[vec_y].first,cards[vec_y].first+(y-count[vec_y])));
            
        }else{
            cards2.push_back(make_pair(cards[vec_x1].first+(x+1-count[vec_x1]),
                                       cards[vec_y].first+(y-count[vec_y])));
        }
        
        
        /*1 - x*/
        for(int j=0;j<vec_x;j++){
            cards2.push_back(cards[j]);
        }
        cards2.push_back(make_pair(cards[vec_x].first,cards[vec_x].first+(x-count[vec_x])));
        
        cards = cards2;
    }
    
    /*ans [count_a,count_b)*/
    int count_a=1,count_b=1,ans=0;
    for(int j=0;j<cards.size();j++){
        count_a=count_b;
        count_b+=cards[j].second-cards[j].first+1;
        if(q < count_a  &&  count_b <= p) continue;

        int a,b;
        
        //[a,b]
        a = max(0,p-count_a);
        b = min(count_b-count_a-1,q-count_a);
        
        if(b < a) continue;
        
        /* cards[j].first+a ~  cards[j].first+b */
        
        if(r < cards[j].first+a) continue;

        ans += min(r-cards[j].first,b)-a+1;
        
    }
    
    printf("%d\n",ans);
    
    return;
}

int main(){
    int n;
    
    while(1){
        scanf("%d",&n);
        if(n==0) break;
        calc(n);
    }
    
    return 0;
}

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

typedef long long ll;
ll dp[100010]={0},a[100010]={0};
ll inf=0x7fffffff;

int main(){
   int n,k;
   scanf("%d%d",&n,&k);
   fill(dp,dp+100010,inf);
   for(int i=0;i<n;i++){
    scanf("%lld",a+i);
   }
   dp[0]=0;
   dp[1]=abs(a[1]-a[0]);
   for(int i=2;i<=n;i++){
    for(int j=1;j<=k;j++){
        if(i<j){
            break;
        }
        else dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
    }
    //printf("%d %lld\n",i,dp[i-1]);
   }
   printf("%lld",dp[n-1]);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int N, M;
int H[100010];
vector<int> G[100010];

void _main() {
    cin >> N >> M;
    REP (i, N) cin >> H[i];
    REP (i, M) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    int ans = 0;
    REP (i, N) {
        bool ok = true;
        REP (j, G[i].size()) {
            ok &= (H[G[i][j]] < H[i]);
        }
        ans += ok;
    }
    cout << ans << endl;
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 10228