akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define int long long

using namespace std;

vector < char > ans;

inline void change(int x,int k){
	while(x){
		ans.push_back((x%k)+'0');
		x/=k;
	}
}

int n,k;

signed main(){
	scanf("%lld%lld",&n,&k);change(n,k);
	printf("%d",ans.size());
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

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

int main() {
  char a;
  cin >> a;
  if (('a' == a)or('i' == a)or('u' == a)or('e' == a)or('o' == a)) {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include<map>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define rpe(i,r,l) for(int i=(r);i>=(l);--i)
#define rpp(i,x,e,head) for(int i=head[x];~i;i=e[i].next)
#define dyes cerr<<"yes"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define pts puts("")
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
inline int read() {
	int f=1,x=0;
	char ch;
	do {
		ch=getchar();
		if(ch=='-')f=-1LL;
	} while(ch<'0'||ch>'9');
	do {
		x=x*10+ch-'0';
		ch=getchar();
	} while(ch>='0'&&ch<='9');
	return f*x;
}
template <class T> inline void chmax(T &a,T b) {
	if(a<b) a=b;
}
template <class T> inline void chmin(T &a,T b) {
	if(a>b) a=b;
}
inline void swap(ll &a,ll &b) {
	ll c=a;
	a=b;
	b=c;
}
using namespace std;
#define mst(a,val) memset(a,val,sizeof(a))
#define pii pair<int,double>
#define piii pair<int,pair<int,int> >
#define mp(i,j) make_pair(i,j)
#define fi first
#define sc second
#define id(i,j) ((i-1)*m+j)
#define inf (0x3f3f3f3f)
int n,k;
int a[3000][3000][2];
inline int getsm(int x,int y,int tx,int ty,int t) {
	int now=a[tx][ty][t];
	if(y) now-=a[tx][y-1][t];
	if(x) now-=a[x-1][ty][t];
	if(x&&y) now+=a[x-1][y-1][t];
	return now;
}
int main() {
	n=read();k=read();
	char oscar[10];
	rep(i,1,n) {
		int x=read(),y=read();
		scanf("%s",oscar);
		int op=(*oscar=='B');
		if((x<0&&y>=0)||(x>=0&&y<0)) {
			op^=1;
		}
		x=abs(x);y=abs(y);
		//cerr<<x<<" "<<y<<" "<<op<<endl;
		a[x%(k<<1)][y%(k<<1)][op]++;
	}
	rep(i,0,(k<<1)) {
		rep(j,0,(k<<1)) {
			rep(t,0,1) {
				//a[i][j][k]+=a[i-1][j][k]+a[i][j-1][k];
				if(i) a[i][j][t]+=a[i-1][j][t];
				if(j) a[i][j][t]+=a[i][j-1][t];
				if(i&&j) a[i][j][t]-=a[i-1][j-1][t];
			}
		}
	}
	//rep(i,0,k<<1){
	//	rep(j,0,k<<1) cerr<<a[i][j][0]<<" ";
	//	pts;
	//}
	//enum the bl p
	int ans=0;
	rep(i,0,k) {
		rep(j,0,k) {
			int now=0;
			now+=getsm(i,j,i+k-1,j+k-1,1);//self
			//cerr<<now<<endl;
			if(i&&j)
				now+=getsm(0,0,i-1,j-1,1);
			if(j)
				now+=getsm(i,0,i+k-1,j-1,0);
			if(i)
				now+=getsm(0,j,i-1,j+k-1,0);
			now+=getsm(i+k,j+k,k*2-1,k*2-1,1);
			if(j) now+=getsm(i+k,0,2*k-1,j-1,1);
			now+=getsm(i+k,j,2*k-1,j+k-1,0);
			now+=getsm(i,j+k,i+k-1,2*k-1,0);
			if(i) now+=getsm(0,j+k,i-1,2*k-1,1);
			//cerr<<now<<endl;
			chmax(ans,now);
		}
	}
	rep(i,0,k) {
		rep(j,0,k) {
			int now=0;
			now+=getsm(i,j,i+k-1,j+k-1,0);//self
			//cerr<<now<<endl;
			if(i&&j)
				now+=getsm(0,0,i-1,j-1,0);
			if(j)
				now+=getsm(i,0,i+k-1,j-1,1);
			if(i)
				now+=getsm(0,j,i-1,j+k-1,1);
			now+=getsm(i+k,j+k,k*2-1,k*2-1,0);
			if(j) now+=getsm(i+k,0,2*k-1,j-1,0);
			now+=getsm(i+k,j,2*k-1,j+k-1,1);
			now+=getsm(i,j+k,i+k-1,2*k-1,1);
			if(i) now+=getsm(0,j+k,i-1,2*k-1,0);
			//cerr<<now<<endl;
			chmax(ans,now);
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 47104
x = int(input())
#2回で3~11を作れる
count = 0
if x == 7:
  count=2
  x = 0
count += (x//11)*2
x = x%11
if x==0:
  count += 0
elif x>6:
  count+=2
else:
  count += 1
print(count)

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

int main()
{
	long long N, K; cin >> N >> K;
	map<long long, long long> m;
	for(long long i = 0; i < N; i++){
		long long a, b; cin >> a >> b;
		m[a] += b;
	}

	long long count = 0;
	long long num = 0;
	for(auto it = m.begin(); it != m.end() && count < K; it++){
		count += it->second;
		num = it->first;
	}

	cout << num << endl;

	return 0;
}

Measured memory_bytes: 4224
//ranger2k aka Rishabh Agarwal

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define F first
#define S second
#define ll long long int

const ll mod = INT64_MAX;
const ll INF = 1e18;
const long double PI = 3.1415926;

ll power(ll a, ll b)
{
    if (b == 0)
        return 1;
    ll temp = power(a, b / 2) % mod;
    if (b % 2 == 0)
    {
        return (temp * temp) % mod;
    }
    else
    {
        return ((a * temp) % mod * temp) % mod;
    }
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    ll No_of_cases;
    No_of_cases = 1;
    //cin >> No_of_cases;
    // ll Case = 1;
    while (No_of_cases--)
    {
        // ll ans = 0;
        ll n, k;
        cin >> n >> k;
        ll a[n];
        for (ll x = 0; x < n; x++)
        {
            cin >> a[x];
        }
        unordered_set<ll> s;
        ll count = 0;
        ll temp = 0;
        while (true)
        {
            if (s.find(temp) == s.end())
            {
                s.insert(temp);
                temp = a[temp] - 1;
                count++;
            }
            else
            {
                break;
            }
        }
        ll temp2 = 0;
        ll count1 = 0;
        while (temp2 != temp)
        {
            count1++;
            temp2 = a[temp2] - 1;
        }
        if (k >= count1)
        {
            k = k - count1;
            k = k % (count - count1);
            while (k)
            {
                temp = a[temp] - 1;
                k--;
            }
            cout << temp + 1 << "\n";
        }
        else
        {
            temp = 0;
            while (k)
            {
                temp = a[temp] - 1;
                k--;
            }
            cout << temp + 1 << "\n";
        }
        // cout << "Case #" << Case << ": " << ans << "\n";
        // Case++;
    }
    return 0;
}


Measured memory_bytes: 12896
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ull unsigned long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main()
{	
	fast
	string s;
	cin>>s;
	cout<<string(s.length(),'x');
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1000000005;

struct S
{
	int x, y;
};

struct G
{
	int x, y , n;
};

int main()
{
	int n,m;
	cin >> n >> m;
	vector<S> ab(n);
	vector<G> cd(m);
	rep(i,n)
	{
		int a,b;
		cin >> a >> b;
		ab[i].x=a;
		ab[i].y=b;
	}
	rep(i,m)
	{
		int c,d;
		cin >> c >>d;
		cd[i].x = c;
		cd[i].y = d;
		cd[i].n = i+1;
	}

	rep(i,n)
	{
		int ans = 0;
		rep(j,m)
		{
			int d = abs(ab[i].x-cd[j].x)+abs(ab[i].y-cd[j].y);
			if(d<abs(ab[i].x-cd[ans].x)+abs(ab[i].y-cd[ans].y))
			{
				ans = j;
			}
		}
		cout<<cd[ans].n<<endl;
	}
	return 0;
}

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

int main(){
    int x,y;
    cin >> x >> y;
    bool ok = false;
    // i は鶴、 x-i は亀
    rep(i,x){
        if(i*2 + (x-i)*4 == y){
            ok = true;
            break;
        }
    }

    if(ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

long long memo[51][51][2501];
int x[51]={};

long long dp(int, int, int);

int main(){
    int N, A;
    long long sum=0;
    
    scanf("%d %d", &N, &A);
    for (int i=1; i<=N; i++) scanf("%d", &x[i]);
    
    for (int j=0; j<51; j++){
        for (int k=0; k<51; k++){
            for (int s=0; s<2501; s++){
                memo[j][k][s] = -1;
            }
        }
    }
    
    for (int k=1; k<=N; k++){
        sum += dp(N, k, k*A);
    }
    
    printf("%lld\n", sum);
    
    return 0;
}

long long dp(int j, int k, int s){
    if (memo[j][k][s] != -1) return memo[j][k][s];
    long long result;
    if (j==0 && k==0 && s==0) result = 1;
    else if (j>=1 && x[j]>s) result = dp(j-1, k, s);
    else if (j>=1 && k>=1 && x[j]<=s) result = dp(j-1, k, s)+dp(j-1, k-1, s-x[j]);
    else result = 0;
    memo[j][k][s] = result;
    return result;
}

Measured memory_bytes: 51072
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
H, W, K = lr()
cases = [1] * 10  # 縦棒i本で何通りの横棒の書き方があるか(0本含む)
cases[-1] = 0 
for i in range(2, 9):
    cases[i] = cases[i-2] + cases[i-1]

dp = [0] * W
dp[0] = 1
for i in range(H):
    prev = dp[:]
    for j in range(W):
        left = j; right = W-(j+1)
        dp[j] *= cases[left] * cases[right]
        if j > 0:
            dp[j] += prev[j-1] * cases[left-1] * cases[right]
        if j < W-1:
            dp[j] += prev[j+1] * cases[left] * cases[right-1]
        dp[j] %= MOD
        
answer = dp[K-1] % MOD
print(answer)
# 19

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        sc.close();

        if (n % k == 0) {
            System.out.println(0);
        } else {
            System.out.println(1);
        }
    }
}

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

using namespace std;

typedef long long LL;

const int N = 110;

int n;
struct R{
    string name;
    int score;
    int id;
}r[N];

bool cmp(const R &a, const R &b)
{
    if(a.name != b.name) return a.name < b.name;
    else return a.score > b.score;
}

bool cmp2(const R &a, const R &b)
{
    return a.id < b.id;
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> r[i].name >> r[i].score;
        r[i].id = i;
    }
    sort(r + 1, r + 1 + n, cmp);

    for(int i = 1; i <= n; i++)
        cout << r[i].id << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <list>

using namespace std;

int main() {
  int q, x;
  char com[20];

  list<int> v;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s", com);
    if (com[0] == 'i') {
      scanf("%d", &x);
      v.push_front(x);
    } else if (com[6] == 'L') {
      v.pop_back();
    } else if (com[6] == 'F') {
      v.pop_front();
    } else if (com[0] == 'd') {
      scanf("%d", &x);
      for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
        if (*it == x) {
          v.erase(it);
          break;
        }
      }
    }
  }
  int i = 0;
  for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
    if (i++) printf(" ");
    printf("%d", *it);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 33884
import numpy as np
n,m = map(int, input().split())
A = np.array([list(map(int, input().split())) for _ in range(n)], dtype='int64')
ind = np.argsort(A[:,0])
A = A[ind]
num = 0
money = 0
for a,b in A:
    num += b
    if num < m:
        money += a * b
    else:
        money += a * (b - (num - m))
        break
print(money)

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

#define TRACE
#ifdef TRACE
#define tr(...) __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 tr(...)
#endif

#define ll long long
#define ld long double 
#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (ll)(a.size())
#define all(a) a.begin(), a.end() 
#define fr(i,n) for(i=1;i<=n;i++)
#define rp(i,n) for(i=0;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef pair<ll, ll> ii;
typedef vector<ll> vl;
const ll N = 200010;
ll mod=1e9+7;

ll ffmod(ll x, ll y, ll mod)
{
    ll rt=1;
    while(y)
    {
        if(y&1ll) rt=(rt*x)%mod;
        x=(x*x)%mod, y/=2ll;
    }
    return rt;
}

queue<ll> q;
vl v[N];
ll deg[N], dis[N];

int main()
{
    FIO;
    ll n,m,x,y,cur,mx=0,i;
    cin>>n>>m;
    fr(i,m) cin>>x>>y, v[x].PB(y), deg[y]++;
    fr(i,n) if(deg[i]==0) q.push(i), dis[i]=0;
    while(!q.empty())
    {
        cur=q.front();
        q.pop();
        mx=max(mx, dis[cur]);
        for(auto it:v[cur])
        {
            dis[it]=max(dis[it], dis[cur]+1);
            deg[it]--;
            if(deg[it]==0)
                q.push(it);
        }
    }
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 10496
#include<stdio.h>

int main(void)
{
	int W, H, x, y, r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if(x < r || y < r || x + r > W || y + r > H){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	
	return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
nodes = tuple([] for i in range(N))
for i in range(M):
    a, b = MAP()
    a -= 1
    b -= 1
    nodes[a].append(b)
    nodes[b].append(a)

# 二部グラフ判定
color = [-1] * N
def check(u):
    stack = [(u, -1, 0)]
    while stack:
        u, prev, c = stack.pop()
        if color[u] == -1:
            color[u] = c
        else:
            if color[u] == c:
                continue
            else:
                return False
        for v in nodes[u]:
            if v != prev:
                stack.append((v, u, 1-c))
    return True

if check(0):
    a = sum(color)
    b = N - a
    ans = a*b - M
else:
    ans = N*(N-1) // 2 - M
print(ans)


Measured memory_bytes: 27200
import java.util.Scanner;
import java.io.PrintWriter;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sec = Integer.parseInt(sc.next());

        PrintWriter pw = new PrintWriter(System.out);
        pw.println((sec/3600) + ":" + (sec/60%60) + ":" + (sec%60));
        pw.flush();
    }
}


Measured memory_bytes: 26232
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define cs(ans); cout<<setprecision(20)<<fixed<<ans<<endl;
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds; 
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
ll pwm(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//st.order_of_key(num)->number of elements < num
//st.find_by_order(i)->iterator of ith element in sorted order starting from zero
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define int long long int
//Binary_Search->dp->greedy
//auto check = [&](ll x){};
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int X[]={2,1,-1,-2,-2,-1,1,2}; 
int Y[]={1,2,2,1,-1,-2,-2,-1}; 
struct comp{
	bool operator()(const pair<int,int>&a,const pair<int,int>&b) const {
		if(a.first>b.first) return true;
		if(a.first<b.first) return false; 
		if(a.second<b.second) return true;
		return false;
	}
};	
void solve(){
	int n;
	cin>>n;
	cout<<(Ceil(n,1000)*1000)-n<<endl;
	
	
	
}
int32_t main(){
int t=1;
//scanf("%d",&t);
while(t--){
	solve();
}
return 0;
}    


Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 345;
const LL MOD = 998244353;
LL dp[MAXN][MAXN * MAXN];
LL dp2[MAXN][MAXN * MAXN];
int a[MAXN];

LL add(LL a, LL b) {
   return (a + b) % MOD;
}

LL sub(LL a, LL b) {
   return (a - b + MOD) % MOD;
}

LL qpow(LL a, LL p) {
   if (!p) return 1;
   LL tmp = qpow(a, p / 2);
   tmp = (tmp * tmp) % MOD;
   if (p % 2) tmp = (tmp * a) % MOD;
   return tmp;
}

int main() {
    int N;
    scanf("%d", &N);
    LL sum = 0;
    for (int i = 1; i <= N; i++) {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    dp[0][0] = dp2[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= sum; j++) {
            dp[i][j] = (dp[i - 1][j] * 2) % MOD;
            dp2[i][j] = dp2[i - 1][j];
            if (j >= a[i]) {
               dp[i][j] = add(dp[i][j], dp[i - 1][j - a[i]]);
               dp2[i][j] = add(dp2[i][j], dp2[i - 1][j - a[i]]);
            }
        }
    }
    LL ans = qpow(3, N);
    for (int i = 1; i <= sum; i++) {
        if (i < (sum - i)) continue;
        //printf("S = %d dp = %lld\n", i, dp[N][i]);
        ans = sub(ans, (dp[N][i] * 3) % MOD);
    }
    if (sum % 2 == 0) {
       //printf("YO = %lld\n", dp2[N][sum / 2]);
       ans = add(ans, (dp2[N][sum / 2] * 3));
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 562304
n,k=map(int,input().split())
L=[]
for s in range(n):
  a,b=map(int,input().split())
  L.append((a,b))
#print(L)
L=sorted(L,key=lambda x:x[0])
#print(L)
sun=0
for s in L:
  sun+=s[1]
  if sun+1>k:
    print(s[0])
    exit()

Measured memory_bytes: 18960
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
ll m,n,t,x,y; 

int main()
{
    std::ios::sync_with_stdio(0); std::cin.tie(0);
    cin>>t;
    if(t==1000000000000000000) cout<<0<<" "<<1000000000<<" "<<1000000000<<" "<<0<<" "<<0<<" "<<0;
    else if(t<=1e9) cout<<0<<" "<<0<<" "<<0<<" "<<t<<" "<<1<<" "<<0;
    else
    {
    	ll a=t/1000000000;
    	a++;
    	ll c=a*1000000000-t;
    	cout<<0<<" "<<0<<" "<<a<<" "<<1<<" "<<c<<" "<<1000000000;
	}
	return 0;
}

Measured memory_bytes: 3660
// Aizu Vol-5 0533: Contest
// 2017.8.30 bal4u@uu

#include <stdio.h>

int max[2][3];

int main()
{
	int i, j, p, s[2];

	for (j = 0; j < 2; j++) {
		for (i = 0; i < 10; i++) {
			scanf("%d", &p);
			if      (p > max[j][0]) max[j][2] = max[j][1], max[j][1] = max[j][0], max[j][0] = p;
			else if (p > max[j][1]) max[j][2] = max[j][1], max[j][1] = p;
			else if (p > max[j][2]) max[j][2] = p;
		}
		for (s[j] = i = 0; i < 3; i++) s[j] += max[j][i];
	}
	printf("%d %d\n", s[0], s[1]);
	return 0;
}

Measured memory_bytes: 2736
fun main(args: Array<String>) {
    val n = readInt()
    val s = readString()

    var c = s[0]
    var ans = 1
    for (i in 1 until n) {
        if (s[i] != c) {
            ans++
            c = s[i]
        }
    }
    println(ans)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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

ll n,m,a,b;
ll t[MAX];
ll A[MAX],B[MAX],C[MAX];

int main(){
  scanf("%lld %lld",&n,&m);
  for(int i=0;i<m;i++){
    a=b;
    scanf("%lld",&b);
    if(i){
      t[min(a,b)]++;
      t[max(a,b)]--;
    }
  }
  ll ans=0;
  for(int i=1;i<=n;i++){
    t[i]+=t[i-1];
    scanf("%lld %lld %lld",&A[i],&B[i],&C[i]);
    ans+=min(A[i]*t[i],B[i]*t[i]+C[i]);
  }
  printf("%lld\n",ans);
  return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
	int n;
	cin>>n;
	rep(loop,n){
		int rui[5]={};
		string s;
		int o=0;
		int p=0;
		while(cin>>s){
			if(s=="HIT"){
				if(rui[3]==1)p++;
				rui[3]=rui[2];
				rui[2]=rui[1];
				rui[1]=1;
			}
			if(s=="OUT"){
				o++;
				if(o>=3)break;
			}
			if(s=="HOMERUN"){
				p+=1+rui[3]+rui[2]+rui[1];
				rui[3]=0;
				rui[2]=0;
				rui[1]=0;
			}
		}
		cout<<p<<endl;
	}
}

Measured memory_bytes: 1212
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll A, P;
    cin >> A >> P;
    cout << (A * 3 + P) / 2;
    return 0;
}


Measured memory_bytes: 3192
n,m = map(int, input().split())
h_list = list(map(int, input().split())) #元リスト（変えない）
newlist = list(h_list) #変換用リスト
for i in range(m):
    a, b = map(int, input().split())
    if h_list[a-1] < h_list[b-1]:
        newlist[a-1] = 0
    elif h_list[a-1] > h_list[b-1]:
        newlist[b-1] = 0
    else:
        newlist[a-1] = 0
        newlist[b-1] = 0
print(n - newlist.count(0))

Measured memory_bytes: 20112
#include <algorithm>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define show(x) std::cout << #x << " = " << (x) << "\n";
#define xshow(x)

#define rng(x) x.begin(), x.end()

template <class T>
using vec = std::vector<T>;
using std::map;
using std::set;
using std::string;
using ll = long long;

using std::abs;
using std::max;
using std::min;

const ll INF = 12345678987654321;

template <class T>
vec<T> make_vec(int N, const T& val) {
    return vec<T>(N, val);
}

template <class T>
vec<vec<T>> make_vec(int M, int N, const T& val) {
    return make_vec(M, vec<T>(N, val));
}

template <class T>
vec<vec<vec<T>>> make_vec(int M, int N, int P, const T& val) {
    return make_vec(M, N, vec<T>(P, val));
}

template <class T>
vec<vec<vec<vec<T>>>> make_vec(int M, int N, int P, int Q, const T& val) {
    return make_vec(M, N, P, vec<T>(Q, val));
}

template <class Iterator>
void print(Iterator begin, Iterator end) {
    while(begin != end) {
        std::cout << *(begin++);
        if(begin != end) {
            std::cout << " ";
        }
        else {
            std::cout << "\n";
        }
    }
}

template <class Container>
void print(const Container& c) {
    print(rng(c));
}

// Solution begins here

int main() {
    std::ios::sync_with_stdio(false);

    int N, C;
    std::cin >> N >> C;
    auto W = make_vec(N + 1, 0ll);
    auto V = make_vec(N + 1, 0ll);
    ll sv = 0;
    for(int i = 1; i <= N; ++i) {
        std::cin >> W[i] >> V[i];
        sv += V[i];
    }

    // F[i][value]: min weight required to get value
    auto F = make_vec(sv + 1, INF);
    F[0] = 0;
    for(int i = 1; i <= N; ++i) {
        for(int j = sv; j >= V[i]; --j) {
            F[j] = min(F[j], F[j - V[i]] + W[i]);
        }
    }

    ll ans = 0;
    for(ll j = sv; j >= 0; --j) {
        if(F[j] <= C) {
            ans = max(ans, j);
        }
    }

    std::cout << ans << "\n";
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A, B, K; cin >> K >> A >> B;
    for(int i = A; i <= B; i++){
        if(i % K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  long n,m;
  cin >> n >> m;
  vector<long> a(n);
  long right = 0;
  long left = 1e7;
  rep(i,n){
    cin >> a.at(i);
    right = max(right,a.at(i)*2);
    left = min(left,a.at(i)*2);
  }
  sort(a.begin(),a.end());
  vector<long> sum(n+1,0);
  for(int i=n-1;i>=0;i--){
    sum.at(i) = sum.at(i+1) + a.at(i);
  }
  while(right - left > 0){
    long mid = (right + left + 1)/2;
    long add = 0;
    rep(i,n){
      long par = mid - a.at(i);
      long id = lower_bound(a.begin(),a.end(),par) - a.begin();
      add += (n - id);
    }
    if(add < m){
      right = mid - 1;
    }else{
      left = mid;
    }
  }
  long add = 0;
  long ans = 0;
  rep(i,n){
    long par = left - a.at(i);
    long id = lower_bound(a.begin(),a.end(),par) - a.begin();
    add += (n - id);
    ans += sum.at(id) + (n - id)*a.at(i);
  }
  cout << ans - (add - m)*left << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>

#define MAX 100002

int A[MAX];
int B[MAX];

int main(void) {
	int i, j, n, q, m, t;
	int com, x, y;
	int *p, *b, *a;
	int pos = MAX;
	int last_y = 0;

	scanf("%d %d\n", &n, &q);
	for(i=0;i<=n;i++) {
		A[i] = 0;
		B[i] = 0;
	}
	
	for(i=0;i<q;i++) {
		scanf("%d %d %d\n", &com, &x, &y);
		if(com == 0) {
			A[x] += y;
			if(pos > x && y != 0) pos = x;
		} else {
			if(pos != MAX) {
				for(j=pos,a=&A[j],b=&B[j],t=B[j-1];j<=n;j++,a++,b++){
					*b = t = (*a)+ t;
				}
				pos = MAX;
			}
			
			printf("%d\n", B[y]-B[x-1]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1384
from heapq import*
L,R=[],[]
B=t=0
Q,*E=open(0)
for e in E:
	if' 'in e:_,a,b=map(int,e.split());t^=1;a*=2*t-1;c=heappushpop([L,R][t],a);heappush([R,L][t],-c);B+=b+a-c-c
	else:print(-L[0],B-L[0]*t)


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

#define F first
#define S second
#define PB push_back

vector<pair<pair<int,int>,int> > v1,v2;
bool is_reach[100100];
int po_v1[100100]; // id
int po_v2[100100]; // id
priority_queue<pair<int,pair<int,int> > > pq;
int n;

int fi_dif(int a,int b)
{
    return abs(a-b);
}

void add_path(int who)
{
    if(po_v1[who]!=0&&!is_reach[v1[po_v1[who]-1].S])
    {
        pq.push({-fi_dif(v1[po_v1[who]].F.F,v1[po_v1[who]-1].F.F),{who,v1[po_v1[who]-1].S}});
    }
    if(po_v1[who]!=n-1&&!is_reach[v1[po_v1[who]+1].S])
    {
        pq.push({-fi_dif(v1[po_v1[who]].F.F,v1[po_v1[who]+1].F.F),{who,v1[po_v1[who]+1].S}});
    }
    if(po_v2[who]!=0&&!is_reach[v2[po_v2[who]-1].S])
    {
        pq.push({-fi_dif(v2[po_v2[who]].F.F,v2[po_v2[who]-1].F.F),{who,v2[po_v2[who]-1].S}});
    }
    if(po_v2[who]!=n-1&&!is_reach[v2[po_v2[who]+1].S])
    {
        pq.push({-fi_dif(v2[po_v2[who]].F.F,v2[po_v2[who]+1].F.F),{who,v2[po_v2[who]+1].S}});
    }
}

main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        v1.PB({{a,b},i});
        v2.PB({{b,a},i});
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    for(int i=0;i<n;i++)
    {
        po_v1[v1[i].S]=i;
        po_v2[v2[i].S]=i;
    }
    int ans=0;
    is_reach[0]=true;
    add_path(0);
    while(!pq.empty())
    {
        int cost=-pq.top().F;
        int a=pq.top().S.F;
        int b=pq.top().S.S;
        pq.pop();
        if(is_reach[b])
            continue;
        ans+=cost;
        // printf("%d %d %d\n",cost,a,b);
        is_reach[b]=true;
        add_path(b);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 8648
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func main() {
	scanner.Split(bufio.ScanWords)

	prime := 1000000000 + 7

	nBalls := nextInt()
	nBoxes := nextInt()

	if nBalls > nBoxes {
		fmt.Println(0)
	} else {
		nComb := 1
		for iBall := 0; iBall < nBalls; iBall++ {
			nComb = (nComb * (nBoxes - iBall)) % prime
		}
		fmt.Println(nComb)
	}
}



Measured memory_bytes: 1116
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int h, w;
char g[1024][1024], joi[3][3];

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

bool eq(int i, int j){
    for (int d = 0; d < 4; d++){
        if (g[i + dy[d]][j + dx[d]] != joi[dy[d]][dx[d]]) return false;
    }
    return true;
}

int main(){
    memset(g, 'X', sizeof(g));
    while (cin >> h >> w){
        for (int i = 0; i < h; i++){
            scanf("%s", &g[i + 1][1]);
            g[i + 1][w + 1] = 'X';
        }
        for (int i = 0; i < 2; i++){
            scanf("%s", joi[i]);
        }

        int before = 0;
        int diff = 0;
        for (int i = 1; i <= h; i++){
            for (int j = 1; j <= w; j++){
                static char cnt[256];
                char orig = g[i][j];
                before += eq(i, j);
                for (char c : "JOI"){
                    cnt[c] = 0;
                    g[i][j] = c;
                    for (int k = 0; k < 4; k++){
                        cnt[c] += eq(i - 1 + dy[k], j - 1 + dx[k]);
                    }
                }
                g[i][j] = orig;
                for (char c : "JOI"){
                    diff = max(diff, cnt[c] - cnt[orig]);
                }
            }
        }
        cout << before + diff << endl;
    }
}

Measured memory_bytes: 2224
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) x.size()
#define int ll
 
using namespace std;
const int mod2 = 100001347; 
const int N = (int)1e5 + 123;
const int mod1 = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
const int p1 = 547;
const int p2 = 769;
int n;
int h1[N], h2[N], pw1[N], pw2[N];
string a;  	
map <pii, int> m;
pii get (int l, int r) {
	int f = (h1[r] - ((h1[l - 1] * pw1[r - l + 1]) % mod1) + mod1) % mod1;
	int s = (h2[r] - ((h2[l - 1] * pw2[r - l + 1]) % mod2) + mod2) % mod2;
	return mp (f, s);
}
void solve () {
	cin >> n >> a;
	a = '#' + a;	
	for (int i = 1; i <= n; i ++) {
		h1[i] = h1[i - 1] * p1 + a[i];
		h2[i] = h2[i - 1] * p2 + a[i];
		h1[i] %= mod1;
		h2[i] %= mod2;
	}
	pw1[0] = pw2[0] = 1;
	for (int i = 1; i <= n; i ++) {
		pw1[i] = pw1[i - 1] * p1;
		pw1[i] %= mod1;
		pw2[i] = pw2[i - 1] * p2;
		pw2[i] %= mod2;
	}
	int l = 0, r = n / 2;
	int o = 0;
	while (l <= r) {       
			
		int mid = l + r >> 1;
		bool check = 0;
		for (int i = 1; i + mid - 1 <= n; i ++) {
			pii x = get (i, i + mid - 1);					
			int pos = m[x];
			if (pos != 0 && pos < i) {
				check = 1;
				break;
			} 
			if (pos == 0) {
				m[x] = i + mid - 1;
			}
		}
		if (check == 1) {
			o = mid;
			l = mid + 1;
		}
		else {
			r = mid - 1;
		}
	}
	cout << o;  
}
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//	cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

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

using namespace std;

typedef pair<int,int> pii;
#define vec vector

int main()
{
    int n;
    vec<pii> a;

    while(cin>>n)
    {
        a.resize(n);
        for(int i=0;i<n;i++)
        {
            cin>>a[i].second>>a[i].first;
        }
        sort(a.begin(),a.end());

        int now=0;
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            if(now<a[i].second)
            {
                cnt++;
                now=a[i].first;
            }
        }
        cout<<cnt<<endl;
    }

    return 0;
}



Measured memory_bytes: 3588
#include <iostream>
using namespace std;
typedef long long LL;
LL n, a, b, cnt[300000+10];

int main() {
    cin >> n >> a >> b;
    int rem = n - a;
    int typ = a;

    if (b-1 > rem || (b-1)*a < rem) {
        return !printf("-1\n");
    }

    rem -= (b-1);
    cnt[a] = (b-1); 
    for (int i = 1; i <= a-1; i++) {
        if (rem >= b-1) {
            rem -= b-1;
            cnt[i] = b-1;
        } else {
            cnt[i] = rem;
            rem = 0;
        }
    }
    for (int i = 1; i <= a; i ++) cnt[i] ++;
    for (int i = 1; i <= a; i ++) {
        cnt[i] += cnt[i-1];
    }

    for (int i = 1; i <= a; i ++) {
        for (int j = cnt[i]; j > cnt[i-1]; j --) {
            printf("%d ", j);
        }
    }
    printf("\n");
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e5+10;
const int mod=1e9+7;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    ll ans=0;
    for(auto &v:s)
    {
        int x=v-'0';
        ans+=x;
    }
    if(ans%9==0)
        cout<<"Yes"<<'\n';
    else
        cout<<"No"<<'\n';


}


Measured memory_bytes: 3776
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

constexpr lli inf = 10000 * 10000;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {


	string s;
	cin >> s;
	if (s == "ABC") {
		cout << "ARC" << endl;
	}else{
		cout << "ABC" << endl;
	}

	return 0;
}


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

const int SIZE=500;
using Bit=bitset<SIZE>;

int solve(int n,int m){
    unordered_map<Bit,int> mp;
    mp[Bit()]=0;
    vector<Bit> b(n);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++){
        unordered_map<Bit,int> nex;
        for(auto &e:mp){
            nex[e.first]=max(nex[e.first],e.second);
            nex[e.first^b[i]]=max(nex[e.first^b[i]],e.second+1);
        }
        mp=nex;
    }
    return mp[Bit()];
}
int main(){
    int n,m;
    while(cin>>n>>m,n){
        cout<<solve(n,m)<<endl;
    }
    return 0;
}


Measured memory_bytes: 215880
#include<iostream>

using namespace std;
int main(){
    string s;
    cin>>s;
    int A[4]={};
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            if(s[i]-s[j]==0) A[i]++;
        }
    }
    bool a=true;
    for(int i=0;i<4;i++){
        if(A[i]!=2) a=false;
    }
    if(a) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

void solve(long long N, long long A, long long B)
{
    long long sum = 0;
    long long keta_sum = 0;
    string ke;
    for (int i = 1; i <= N; i++)
    {
        keta_sum = 0;
        string num = to_string(i);
        for (int j = 0; j < (int)(num.size()); j++)
        { 
            ke = num[j];
            int keta = stol(ke.c_str());
            keta_sum += keta;
        }

        if (keta_sum <= B && keta_sum >= A)
        {
            sum += i;
        }
    }
    cout << sum << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;    // 現在地はで，nにいきたい, m種類の船
    vector<vector<int>> to(n);
    rep(i, m) {
        int a, b; cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    // to[n-1] <- to[j] <- to[1]
    rep(i, to[0].size()) {
        int mid = to[0][i];
        rep(j, to[mid].size()) {
            int des = to[mid][j];
            if (des == n - 1) { 
                puts("POSSIBLE");
                return 0;
            }
        }
    }
    puts("IMPOSSIBLE");
    return 0;
}

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

namespace ABC
{
    class ProgramB
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var r = 0;
            var result = false;

            for (var i = 0; i < n; i++)
            {
                var inputs = Console.ReadLine().Split(" ");
                var d1 = long.Parse(inputs[0]);
                var d2 = long.Parse(inputs[1]);

                if (d1 == d2)
                    r++;
                else
                    r = 0;

                if (r >= 3)
                {
                    result = true;
                    break;
                }
            }

            Console.WriteLine(result ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 27528
n = int(input())
lst = [list(map(int, input().split())) for i in range(n)]
ans = [[0]*3 for i in range(n)]
ans[0] = lst[0]
for i in range(1, n):
  ans[i][0] = lst[i][0] + max(ans[i-1][1], ans[i-1][2])
  ans[i][1] = lst[i][1] + max(ans[i-1][0], ans[i-1][2])
  ans[i][2] = lst[i][2] + max(ans[i-1][0], ans[i-1][1])

res = max(ans[n-1][0], max(ans[n-1][1], ans[n-1][2]))
print(res)

Measured memory_bytes: 47384
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long ll;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  if(abs(a-c)<=x||(abs(a-b)<=x&&abs(b-c)<=x)) cout << "Yes" << '\n';
  else  cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
while (n=gets.to_i)!=0
  mt=Array.new(n).map{Array.new(n,0)}
  pos=[n/2,n/2-1]
  (1..n**2).each do |i|
    pos[0],pos[1]=(pos[0]+1)%n,(pos[1]+1)%n
    if mt[pos[0]][pos[1]]!=0
      pos[0],pos[1]=(pos[0]+1)%n,(pos[1]-1)%n 
    end
    mt[pos[0]][pos[1]]=i
  end
  mt.each do |i|
    i.each do |j| printf("%4d",j) end
    printf("\n")
  end
end

Measured memory_bytes: 8604
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	map<int, int>mp;
	rep(i, 3) {
		int a; cin >> a;
		mp[a]++;
	}
	cout << (mp.size() == 2 ? "Yes" : "No") << "\n";

	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 100000;
int pre[N];
bool t[N];
int find(int x)
{
	int r=x;
	while(r!=pre[r])
		r=pre[r];
	
	int i=x,j;
	while(pre[i]!=r)
	{
		j=pre[i];
		pre[i]=r;
		i=j;
	}
	return r;
}
 
void mix(int x,int y)
{
	int fx=find(x),fy=find(y);
	if(fx!=fy)
	{
		pre[fy]=fx;
	}
} 

int n,m;
int main()
{
    cin>>n>>m;
    for (int i=0;i<n;i++)
    {
        pre[i]=i;
    }
    for (int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        mix(x,y);
    }
    memset(t,0,sizeof(t));
    for (int i=0;i<n;i++)
    {
        t[find(i)]=1;
    }
    int ans=0;
    for (int i=0;i<n;i++)
    {
        if (t[i]) ans++;
    }
    cout<<ans-1;
    return 0;
}




Measured memory_bytes: 4076
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;
int main(){
  cin>>n;
  int even=0,odd=0;
  REP(i,n){
    int a;scanf("%d",&a);
    if(a&1) ++odd;
    else ++even;
  }
  even+=odd/2;
  odd%=2;

  if(odd && even) puts("NO");
  else puts("YES");
  return 0;
}





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

using namespace std;

int main()
{
	int N, M; cin >> N >> M;
	vector<vector<int>> jobs(M);
	for (int i=0; i<N; i++) {
		int a,b;
		cin >> a >> b;
      	if (a > M) continue;
		jobs[M-a].push_back(b);
	}
	long long int ans = 0;
	priority_queue<int> pqueue;
	for (int i=1; i<=M; i++) {
		for (int b : jobs[M-i]) {
			pqueue.push(b);
		}
		if (!pqueue.empty()) {
			ans += pqueue.top();
			pqueue.pop();
		}
	}

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


Measured memory_bytes: 5504