akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define HEIGHT_MAX 10
#define WIDTH_MAX 1000
#define BUF_SIZE (WIDTH_MAX+50)

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}

#define min(a,b) ((a) > (b) ? (b) : (a))

int main(void) {
    int height, width, ulimit;
    int i, j;
    static char map[HEIGHT_MAX][WIDTH_MAX];

    get_int3(&height, &width, &ulimit);
    
    for(i = 0; i < height; i++) {
        char buf[BUF_SIZE];
        get_str(buf, BUF_SIZE);
        for(j = 0; j < width; j++) {
            map[i][j] = (buf[j] - '0');
        }
    }
    int pat, bit;
    int ans = (WIDTH_MAX+HEIGHT_MAX);
    for(pat = 0; pat <(1<<height); pat+=2) {
        int res = __builtin_popcount(pat);
        if(res >= ans) continue;
        int sum[11] = {0};
        int group[11] = {0};
        int idx = 1;
        int wid;
        int moved = 0;
        // create groups
        for(bit = 0; bit <= height; bit++) {
            if(pat & (1<<bit)) group[idx++] = bit;
        }
        group[idx++] = height;
#ifdef DEBUG
        for(i = 0; i < idx; i++) printf("%d ", group[i]);
#endif

        // pat = 0: [0, 5]
        for(wid = 0; wid < width;) {
            int flag = 1;
            int new[11] = {0};
            for(i = 0; i < idx-1; i++) {
                for(bit = group[i]; bit < group[i+1]; bit++) {
                    new[i] += map[bit][wid];
                }
#ifdef DEBUG
                for(j = 0; j < idx-1; j++) { printf("(%d+%d) vs %d\n", new[i], sum[i], ulimit); }
#endif
                // must split
                if(sum[i] + new[i] > ulimit) { flag = 0; break; }
            }
#ifdef DEBUG
            printf("flag: %d ", flag);
#endif
            if(!flag) {
                if(!moved) { break; }
                res++;
                moved = 0;
                for(i = 0; i < idx-1; i++) sum[i] = 0;
            } else {
                moved = 1;
                wid++;
                for(i = 0; i < idx-1; i++) sum[i] += new[i];
            }
        }
#ifdef DEBUG
        printf("[pat: %d] possible?: %d ans: %d\n", pat, moved, res);
#endif
        if(!moved) continue;
        ans = min(ans, res);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
# coding: utf-8

import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

# N = int(input())
# S = input()
A, B, C = map(int, input().split())
# 横
# L = [int(x) for x in input().split()]
# 縦
# A = [int(input()) for _ in range(N)]
# 多次元
# L = [[int(x) for x in input().split()] for _ in range(N)]

print(max(0, C - (A - B)))



Measured memory_bytes: 38256
import numpy as np

A,B = map(int,input().split())

x = B - A + 1
A_ = bin(A)
B_ = bin(B)
# A = format(A,'b').zfill(31)
# B = format(B,'b').zfill(31)
A -= 1
digitsA = []
digitsB = []
for i in range(1,41):
    div = 2 ** i
    # itA = int((A+1) / div)
    # amariA = (A+1) % div
    # itB = int((B+1) / div)
    # amariB=  (B+1) % div
    # print(A,itA,amariA)
    if(i == 1):
        if(A % 4 == 1 or A % 4 == 2):
            digitA = 1
        else:
            digitA = 0
        if(B % 4 == 1 or B % 4 == 2):
            digitB = 1
        else:
            digitB = 0
        # digitA = int(np.logical_xor(itA % 2,amariA))
        digitsA.append(digitA)
        # digitB = int(np.logical_xor(itB % 2,amariB))
        digitsB.append(digitB)
    else:
        itA = int(A / div)
        amariA = A % div
        itB = int(B / div)
        amariB=  B % div
        border = div / 2
        if(amariA >= border and (amariA % 2 == 0)):
            digitA = 1
        else:
            digitA = 0
        digitsA.append(digitA)
        if(amariB >= border and (amariB % 2 == 0)):
            digitB = 1
        else:
            digitB = 0
        digitsB.append(digitB)

num = 0
numA = 0
numB = 0
# print(digitsA)
# print(digitsB)
for i in range(40):
    num += np.logical_xor(digitsA[i],digitsB[i]) * (2 ** i)
    # numA += digitsA[i] * (2 ** i)
    # numB += digitsB[i] * (2 ** i)

print(num)
'''
while(1):
    div = 2 ** i 
    if(div > B):
        break
    A_ = int(A/div)
    B_ = int(B/div)
    a = (B_ - A_ + 1) % 2
    print(a)
    x.append(a)
    
    i += 1

num = 0
for i in range(len(x)):
    num += x[i] * (2 ** i)

print(num)
'''

Measured memory_bytes: 12452
#include<bits/stdc++.h>
using namespace std;
const int MAXN=200000+10;
int n;
int cnt;
struct job{
	int a,b;
}w[MAXN];
job r[MAXN];
void merge_sort(int s,int t){
	if(s==t) return;
	int mid=(s+t)/2;
	merge_sort(s,mid);
	merge_sort(mid+1,t);
	int i=s,j=mid+1,k=s;
	while(i<=mid&&j<=t){
		if(w[i].b<w[j].b){
			r[k]=w[i];
			k++;i++;
		}
		else{
			r[k]=w[j];
			k++;j++;
		}
	}
	while(i<=mid){
		r[k]=w[i];
		k++;i++;
	}
	while(j<=t){
		r[k]=w[j];
		k++;j++;
	}
	for(int i=s;i<=t;i++)
		w[i]=r[i];
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&w[i].a,&w[i].b);
	merge_sort(1,n);
	int k=1;
	cnt=w[1].a;
	while(cnt<=w[k].b&&k<=n){
		k++;
		cnt+=w[k].a;
	}
	if(k==n+1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
typedef long long ll;

int par[100000];
int ran[100000];
int n;

void init(int k){
	for(int i = 0; i < k; ++i){
		par[i] = i;
		ran[i] = 0;
	}
}

int find(int x){
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(ran[x] < ran[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(ran[x] == ran[y]) ++ran[x];
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

int main(){
	int n; cin >> n;
	init(n);
	vector< pair<int, int> > vx, vy;
	for(int i = 0; i < n; ++i){
		int x, y; cin >> x >> y; --x; --y;
		vx.push_back(pair<int, int>(x, i));
		vy.push_back(pair<int, int>(y, i));
	}
	sort(vx.begin(), vx.end());
	sort(vy.begin(), vy.end());
	vector< pair<int, pair<int, int> > > v;
	for(int i = 0; i < n - 1; ++i){
		pair< int, pair<int, int> > p;
		p.first = vx[i + 1].first - vx[i].first;
		p.second = pair<int, int>(vx[i + 1].second, vx[i].second);
		v.push_back(p);
		p.first = vy[i + 1].first - vy[i].first;
		p.second = pair<int, int>(vy[i + 1].second, vy[i].second);
		v.push_back(p);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for(int i = 0; i < v.size(); ++i){
		if(!same(v[i].second.first, v[i].second.second)){
			unite(v[i].second.first, v[i].second.second);
			ans += v[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7656
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
string s;
	



int main()
{
 ll n,m;
 cin>>n>>m;
 
 ll s,c,ans[n];
 
 for(ll i=0;i<n;i++)ans[i]=-1;
 for(ll i=0;i<m;i++)
 {
 	cin>>s>>c;
 	
 	if((ans[s-1]==-1||ans[s-1]==c  ))
 	ans[s-1]=c;
 	else
 	return cout<<-1,0;
 }
 if(ans[0]==0&&n!=1)return cout<<-1,0;
 
 for(ll i=1;i<n;i++)
 {
 	if(ans[i]==-1)ans[i]=0;
 }

if(ans[0]==-1&&n>1)ans[0]=1;
else if(ans[0]==-1)ans[0]=0;

for(ll i=0;i<n;i++)cout<<ans[i];
}




Measured memory_bytes: 3624
import java.util.*;
import java.io.*;

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}

//......................................@uthor_Alx..............................................


   public static void main(String[] args) throws  IOException{
	        		  assign();
	        		  int n=int_v(read());
	        		  //int[] n=int_arr();
	        		  //int nn[]=a[0],k=a[1];
	        		  Set<String> ss=new HashSet<>();
	        		  for(int i=0;i<n;i++){ss.add(read());}
	        		  	out.write(ss.size()+"");
                      out.flush();
	        		 
	}
}
	       
	          



	
  





Measured memory_bytes: 67148
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string s; cin>>s;
    int ans=0;
    REP(i,s.size()-1){
        if(s[i]!=s[i+1]) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
object Main{
  case class Job (days: Int, pay: Int)

  def main(args: Array[String]) : Unit = {
    val sc = new java.util.Scanner(System.in)
    val n,m = sc.nextInt
    val jobs = (1 to n)
      .map{_ => Job(sc.nextInt,sc.nextInt) }
      .groupBy { job => job.days }

    val candidate = collection.mutable.PriorityQueue[Int]()
    var result = 0
    (1 to m).foreach { x =>
      //candidate.addAll(jobs.getOrElse(x,List.empty))
      jobs.getOrElse(x,List.empty).foreach{job => candidate += job.pay }

      if(candidate.nonEmpty) {
        result += candidate.dequeue
      }
    }
    println(result)
  }
}



Measured memory_bytes: 146168
#include<stdio.h>

int Solve(int n, int l) {
	int mintas=abs(l);
	int minnum=0;
	int taste, ans = 0;

	for (int i = 1;i <= n;i++) {
		taste=abs(l+i-1);
		if (taste <= mintas) {
			mintas = taste;
			minnum = i;
		}
	}
	for (int i = 1;i <= n;i++) {
		if (i != minnum) {
			ans += l + i - 1;
		}
	}

	return ans;
}
int main() {
	int n, l;
	scanf("%d%d", &n, &l);
	printf("%d", Solve(n,l));
	return 0;
}

Measured memory_bytes: 128
n = int(input())
l = list(map(int, input().split()))
w = list(set(l))
r = {w[i]:0 for i in range(len(w))}
for i in range(n):
    r[l[i]] += 1
t = list(r.items())
ans = 0
for i in range(len(t)-2):
    for j in range(i+1, len(t)-1):
        for k in range(j+1, len(t)):
            y = sum([t[i][0], t[j][0], t[k][0]])
            x = max([t[i][0], t[j][0], t[k][0]])
            if 2*x < y:
                ans += t[i][1] * t[j][1] * t[k][1]
print(ans)

Measured memory_bytes: 9272
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;

int main(void)
{
        ll h, w;
        cin >> h >> w;

        if (h == 1 || w == 1) {
                cout << 1 << endl;
        } else {
                cout << (h * w) / 2 + ((h * w) & 1);
        }
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
SIZE=300000; MOD=10**9+7 #ここを変更する

inv = [0]*(SIZE+1)# inv[j] = j^{-1} mod MOD
fac = [0]*(SIZE+1)# fac[j] = j! mod MOD
finv = [0]*(SIZE+1)# finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE+1):
    inv[i] = MOD -(MOD//i)*inv[MOD%i]%MOD
    fac[i] = fac[i-1]*i%MOD
    finv[i]= finv[i-1]*inv[i]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0


h,w,n = [int(i) for i in input().split()]
xy = [[1,1]]+[[int(i) for i in input().split()] for _ in range(n)]

dp = [0]*(n+1)
dp[0] = 1

xy.sort()

#print(xy)

for i in range(1,n+1):
    x,y = xy[i]
    for j in range(i):
        xj,yj = xy[j]
        dp[i] -= choose(x - xj + y-yj, y-yj)*dp[j]
        dp[i] %= MOD

ans = 0
#print(dp)
for i,dpi in enumerate(dp):
    x,y=xy[i]
    ans += choose(h-x + w-y, w-y) * dpi
    ans %= MOD
print(ans)




Measured memory_bytes: 54424
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int power(int a, int b){
	return (a-b)*(a-b);
}

int main(){
	int N; cin>>N;
	vector<int> in(N);
	int nin = inf, nax = -112;
	rep(i,N){
		cin>>in[i];
		nax = max(nax, in[i]);
		nin = min(nin, in[i]);
	}
	int ans = inf;
	for(int i = nin; i <= nax; ++i){
		int e_ans = 0;
		rep(j,N){
			e_ans += power(i,in[j]);
		}
		ans = min(ans, e_ans);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(void)
{
    int N;
    cin >> N;
    vector<long> A(N);
    long sum=0;
    for (int i = 0; i < N; i++){
       cin >> A[i];
       sum+=A[i];
    }
    int Q;
    cin >> Q;
    map<long, long> Map;
    for (int i = 0; i < N; i++){
        Map[A[i]]++;
    }
    for (int i = 0; i < Q; i++){
        long B,C;
        cin >> B >> C;
        sum+=Map[B]*C;
        sum-=Map[B]*B;
        Map[C]+=Map[B];
        Map[B]=0;
        cout << sum << endl;
    }
}

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

using namespace std;

#define int long long
#define size(x) ((int) x.size())
typedef pair<int,int> pii;

const int MAXN = 1e5 + 5;

int n, root, cnt;
int a[MAXN];
int d[MAXN], sz[MAXN];
int v, par;

vector<int> adj[MAXN];
vector<pii> ans;

pii b[MAXN];

bool cmp(int i, int j) {
	return d[i] > d[j];
}

int getP(int i) {
	int hp = d[i] - n + 2 * sz[i];
	auto tmp = lower_bound(b, b + n, pii(hp, 0)) - b;
	//cerr << b[tmp].first << " " << b[tmp].second << endl;
	if (b[tmp].first != hp) 
		return -1;
	return b[tmp].second;
}

int dfs(int u) {
	int val = 0;
	for (auto v : adj[u])
		val += dfs(v) + sz[v];
	return val;
}
	
int32_t main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)  {
		cin >> d[i];
		b[i] = {d[i], i};
		a[i] = i;
		sz[i] = 1;
	}
	sort(b, b + n);
	sort(a, a + n, cmp);
	for (int i = 0; i < n - 1; i++) {
		v = a[i];
		par = getP(v);
		//cout << v << " " << par << endl;
		if (par == -1)
			return cout << -1 << endl, 0;
		sz[par] += sz[v];
		ans.push_back({v, par}); 
		adj[par].push_back(v);
		if (2 * sz[v] > n) 
			return cout << -1 << endl, 0;
		//cout << v << " " << par << endl;
	}
	root = a[n - 1];
	if (d[root] != dfs(root))
		return cout << -1 << endl, 0;
	for (auto x : ans) 
		cout << x.first + 1 << " " << x.second + 1 << endl;
	return 0;
}

Measured memory_bytes: 14704
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
    int x;
    cin >> x;
    if (x >= 30)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}

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

int main() {
  int n, x, y, h, w, l, as, bs, s, cost;
  int a[6] = {60, 80, 100, 120, 140, 160};
  int b[6] = {2, 5, 10, 15, 20, 25};
  int c[6] = {600, 800, 1000, 1200, 1400, 1600};
  while (1) {
    cin >> n;
    if (!n) break;
    cost = 0;
    for (int i=0; i<n; i++) {
      cin >> x >> y >> h >> w;
      l = x + y + h;
      as = lower_bound(a, a+6, l) - a;
      bs = lower_bound(b, b+6, w) - b;
      s = max(as, bs);
      if (s < 6) {
        cost += c[s];
      }
    }
    cout << cost << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(){
int a[6],i,b,c;
for(i=0;i<5;i++){
scanf("%d\n",&a[i]);
}
b=a[4]*a[0];
if(a[4]<=a[2]){
c=a[1];
}
else{
c=a[1]+(a[4]-a[2])*a[3];
}
if(b<c){
printf("%d\n",b);
}
else{
printf("%d\n",c);
}
return 0;
}


Measured memory_bytes: 2108
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	int x,y,z,e,ee,res=10000000;
	while(1){
		cin >> e;
		if(e==0){
			break;
		}
		for(z=0;z<=1000;z++){
			ee=e;
			if(z*z*z<=ee)
				ee-=z*z*z;
			for(y=0;y<=1000;y++){
				x=ee;
				if(y*y<=x)
					x-=y*y;
				res=min(res,x+y+z);
			}
		}
		cout << res << endl;
		res=1000000;
	}
	return 0;
}



/*int main(){
	long z,e,ee,res=1000000;
	while(1){
		cin >> e;
		if(e==0)
			break;

		for(int i=0; e!=0;i++){
            if(i*i*i > e){
                z = i;
                break;
            }
        }
        
        for(int i=0; i<20;i++){
            z-=1;
            ee=e;
            if(z<0){
                z=0;
            }
            ee-=z*z*z;
            if(ee==0){
                res=min(res,z);
            }
            for(int y=0;ee!=0;y++){
                if(y*y > ee){
                    ee-=(y-1)*(y-1);
					res=min(res,z+(y-1)+ee);
					break;
				}
            }
		}
        cout << res << endl;
		res=1000000;
	}
	return 0;
}*/

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

 int main(){
 long long a, b, k;
 cin >> a >> b >> k;

 if(k <= a){
 cout << a - k << ' ' << b <<endl;
}else if(k <= a+b){
 cout << 0 << ' ' << b - (k-a) <<endl;
 }else{
 cout << 0 << ' ' << 0 <<endl;
 }
 }

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

int main()
{
  cout << in() * in() << endl;
  return 0;
}

Measured memory_bytes: 1200
#import pysnooper
import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
from itertools import accumulate,combinations#,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n,k=map(int,input().split())
print(n%k if n>=k else 0)

Measured memory_bytes: 3828
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim_i = (b); i < lim_i; i++)
#define REP(i, ...) REP_((i), __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Mar  8 21:00:01 JST 2020
 **/

template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}

signed main() {
    Int A, B, M;
    cin >> A >> B >> M;
    vector<Int> a(A);
    REP(i, A) cin >> a[i];
    vector<Int> b(B);
    REP(i, B) cin >> b[i];
    Int mi = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    REP(i, M) {
        Int x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        dump(x, y, z);
        chmin(mi, a[x] + b[y] - z);
    }
    cout << mi << endl;
}


Measured memory_bytes: 1792
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


int main() {
    long double a, b, c; cin >> a >> b >> c;

    if (2 * sqrt(a*b) < c - a - b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 760
#include<stdio.h>
int main(void){
        int i,j,H,W,count;
        while(1){
                scanf("%d %d",&H,&W);
                count = 0;
                j = 0;
                if(H==0 && W == 0) break;
                else if(H ==0 || W == 0) printf("\n");
                else {
                        for(i=0;i<H;i++){
                                j = 0;
                                count = i % 2;
                                if(count == 0) while(1){
                                                printf("#");
                                                j++;
                                                if(j >= W) break;
                                                printf(".");
                                                j++;
                                                if(j >= W) break;
                                        }
                                else while(1){
                                                printf(".");
                                                j++;
                                                if(j >= W) break;
                                                printf("#");
                                                j++;
                                                if(j >= W) break;
                                        }
                                printf("\n");
                        }
                }
                printf("\n");
        }
        return 0;
}

Measured memory_bytes: 572
/*Author SHUBH AGRAWAL  */

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
//a power n mod p

#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 

long long int modp(lld a,lld p,lld n)
{
    int d[100];
    int i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

long long int nCrModPFermat(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
    
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    lld fac[n+1]; 
    fac[0] = 1; 
    for (lld i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


long long int gcd(lld b,lld a)
{
    if(a<b) return gcd(a,b);
    if(a%b==0) return b;
    return gcd(a%b , b);
}


lld l,r,mid,ans;
lld n,m,i,j,k;
lld x,w,y,z;

void solve()
{
    cin>>n>>x>>y;
    ans=(n/(x+y))*x;
    z=n%(x+y);
    if(n%(x+y))
    {
        if(z<x) ans+=z;
        else
            ans+=x;
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        n: usize,
        d: [i32; n],
    }
    let mut set = std::collections::HashSet::new();
    for di in &d {
        set.insert(di);
    }
    println!("{}", set.len());
}


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

int main() {
  int N;
  cin >> N;
  string S = "MARCH";
  vector<long long> V(5);

  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < 5; j++) {
      if (s.at(0) == S.at(j)) V.at(j)++;
    }
  }

  long long ans = 0;

  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      for (int k = j + 1; k < 5; k++) {
        ans += V.at(i) * V.at(j) * V.at(k);
      }
    }
  }

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

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

int main() {
	int x, y;
	scanf("%d%d", &x, &y);
	
	int mi = x*2, ma = x*4;
	if(y%2==0 && y>=mi && y<=ma) puts("Yes");
	else puts("No");
	
	return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ignore ignore
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define bitcount(x)  __builtin_popcount(x)
#define bitcountll(x)  __builtin_popcountll(x)
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define YES printf("YES\n")
#define NO printf("NO\n")
#define yes printf("Yes\n")
#define no printf("No\n")
#define lin printf("\n")
// Iterator
#define rep(i,n) for(i=0;i<n;++i)
#define rrep(i,n) for(i=n-1;i>=0;--i)
#define lp(i,a,b) for(i=a;i<b;++i)
#define rlp(i,a,b) for(i=a;i>=b;--i)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// function
#define sz(x) x.size()
#define inrange(i,a,b) (i>=a && i<=b)
#define FLUSH fflush(stdout)
#define precision(x) cout << setprecision(x) << fixed
#define remax(a,b) a=max(a,b)
#define remin(a,b) a=min(a,b)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
// Constant
const double PI = acos(-1);
const double eps = (1e-9);
const ll INF = 2e15;
const int M = (1e9)+7;
const int N = (1e5);  // check the limit, man
int main()
{
    int s,n,a;
    in2(s,n);
    while(n--)
        in(a),s-=a;
    if(s>0)
        no;
    else
        yes;
}







Measured memory_bytes: 256
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int n, m;
    cin >> n >> m;
    vector<ll> dp(n * 1000 + 1, MAX);
    dp[0] = 0;

    for(int i = 0; i < n; i++){
        int w, v;
        cin >> w >> v;
        for(int j = n * 1000; j >= v; j--){
            dp[j] = min(dp[j], dp[j - v] + w);
        }
    }

    for(int i = n * 1000; i >= 0; i--){
        if(dp[i] <= m){
            cout << i << "\n";
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
//make sure to make new file!
import java.io.*;
import java.util.*;

public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      String s1 = f.readLine();
      String s2 = f.readLine();
      
      if(s2.length() == s1.length()+1 && s2.substring(0,s2.length()-1).equals(s1)){
         out.println("Yes");
      } else {
         out.println("No");
      }
      
      
      
      
      
      
      
      
      out.close();
   }
   
      
}

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

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    for(int i = 0; i < b; i++){
        if((a*(i+1)%b) == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

#define int long long

using namespace std;

const int oo = 2e18;

const int MAXN = 2e5 + 100;

#ifndef ONLINE_JUDGE 
#include "/media/brayand/7801-B00D/debugger.h"
#else
template<typename T>
void db(T x){}
#endif

int N;

int arr[MAXN];

vector<int> L[MAXN];

map<int,int> mp[MAXN];

int sz[MAXN];

int res[MAXN];

void DFS(int nodo, int padre)
{
	sz[nodo] = 1;

	for(auto v : L[nodo])
	{
		if(v != padre)
		{
			DFS(v,nodo);

			int value = sz[v]-mp[v][arr[nodo]];

			res[arr[nodo]] += value*(value+1)/2;

			sz[nodo] += sz[v];
			if(mp[nodo].size() < mp[v].size())swap(mp[nodo],mp[v]);
			for(auto x : mp[v])
			{
				mp[nodo][x.first] += x.second;
			}
		}
	}

	mp[nodo][arr[nodo]] = sz[nodo];

}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N;

    for(int i = 1 ; i <= N ; i++)
    {
    	cin >> arr[i];
    }

    for(int i = 1 ; i <= N-1 ; i++)
    {
    	int a, b;
    	cin >> a >> b;
    	L[a].push_back(b);
    	L[b].push_back(a);
    }

    DFS(1,-1);

    for(int i = 1 ; i <= N ; i++)
    {
    	int value = sz[1]-mp[1][i];
    	res[i] += value*(value+1)/2;
    }

    for(int i = 1 ; i <= N ; i++)
    {
    	cout << N*(N+1)/2-res[i] << '\n';
    }

    return 0;
}

Measured memory_bytes: 91048
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}


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

    if(n==100)n++;
    int ans=pow(100,d)*n;

    cout<<ans<<endl;


}





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

int main() {
  string s;
  cin >> s;
  
  if(s.length() % 2 != 0){
    cout << "No" << endl;
    return 0;
  }
  
  string res = "Yes";
  
  for(int i = 0; i < (int)s.length(); i+=2){
    if(!(s[i] == 'h' && s[i+1] == 'i')){
      res = "No";
      break;
    }
  }

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        String S = scan.next();

        char[] array = S.toCharArray();

        if(array[0] == array[1] && array[2] == array[3] && array[1] != array[2]){

            System.out.println("Yes");
            return;

        }else if(array[0] == array[2] && array[1] == array[3] && array[1] != array[2]){

            System.out.println("Yes");
            return;

        }else if (array[0] == array[3] && array[1] == array[2] && array[0] != array[1]){

            System.out.println("Yes");
            return;
        }
        
        System.out.println("No");
        return;

    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define mod 1000000007
#define MOD 998244353
#define pb push_back
#define fi first
#define se second
#define vii vector<pair<int,int> >
#define vi vector<ll>
#define ll long long
#define rep(i,a,b) for(i=a;i<=b;i++)
#define inf 100000000000000000
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
using namespace std;
 
int main()
{
    IOS;
    ll n,h,w;
    cin>>n>>h>>w;
    cout<<(n-h+1)*(n-w+1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                   \
  ifstream in("atcoder-problems/diverta2019_d.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll N;
  cin >> N;

  ll ans = 0;
  ll i = 1;
  while ((N - i) / i > i) {
    if ((N - i) % i == 0) {
      ans += (N - i) / i;
    }
    i++;
  }
  cout << ans << endl;
}

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

#define READ                freopen("in.txt", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)

#define si(a)               scanf("%d", &a)
#define sii(a,b)            scanf("%d %d", &a, &b)
#define siii(a,b,c)         scanf("%d %d %d", &a, &b, &c)

#define CLR(a)              memset(a, 0, sizeof(a))
#define SET(a)              memset(a, -1, sizeof(a))

#define PI                  acos(-1.0)

#define pb                  push_back
#define mp                  make_pair
#define SORT(v)             sort(v.begin(), v.end())
#define REV(v)              reverse(v.begin(), v.end())
#define FOR(i, n)           for(int i=0; i<n; i++)
#define FOR1(i, n)          for(int i=1; i<=n; i++)
#define ROF(i, n)           for(int i=n-1; i>=0; i--)
#define ROF1(i, n)          for(int i=n; i>=1; i--)
#define LOOP(i, x, y)       for(int i=x; i<=y; i++)
#define fastIO()            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long              LL;
typedef unsigned long long     ULL;
typedef vector<int>            VI;
typedef pair<int, int>         PII;
typedef pair<string, int>      PSI;
typedef pair<char, int>        PCI;

const int MAX = 10;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;

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

//bool valid(int a, int b){ return (a>=1 and a<=n and b>=1 and b<=m); }


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

    int cnt = 0;
    int n = str.size();

    FOR(i, n/2){
        //cout << i << str[i] << " " << str[n-i] << endl;
        if(str[i] != str[n-i-1]) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


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

int main(void){
	string str, instruction, temp;
	int a,b,q;

	cin >> str;
	cin >> q;

	for (int i = 0; i < q; i++){
		cin >> instruction >> a >> b;
		if (instruction == "replace"){
			cin >> temp;
			str.replace (a, (b-a)+1, temp);
		}
		else if (instruction == "reverse"){
			for (int i = a, j = b; i < ((a + b) / 2)+1; i++, j--){
				char temp = str[j];
				str[j] = str[i];
				str[i] = temp;
			}
		}
		else if (instruction == "print"){
			for (int i = a; i < b + 1; i++){
				cout << str[i];
			}
			cout << "\n";
		}
	}

	return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> l(k), r(k);
    rep(i, k) {
        cin >> l[i] >> r[i];
    }
    vector<mint> dp(n+2);
    vector<mint> imos(n+2);
    mint now = 0;
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        now += imos[i];
        dp[i] += now;
        for (int j = 0; j < k; j++) {
            int nl = i + l[j];
            int nr = i + r[j];
            if (nl >= n) continue;
            if (nr >= n) nr = n;
            imos[nl] += dp[i];
            imos[nr+1] -= dp[i];
        }
    }

    cout << dp[n-1] << endl;
    return 0;
}
/*
g++ -std=c++17 -Wall -Wextra -g -O0 -fsanitize=undefined,address main.cpp && oj t
*/

Measured memory_bytes: 6424
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

int main(){
	
	int n, a[100];
	
	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	bool checker;
	
	for(int num = 1; num <= 100000000; num++){
		checker = true;
		for(int i = 0; i < n; i++){
			if(a[i] % num != 0){
				checker = false;
				break;
			}
		}
		if(checker){
			printf("%d\n", num);
		}
	}
	
	return 0;
}

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

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll N, K;
vector<ll> a;
ll ans = std::numeric_limits<ll>::max();

template<typename T1 = long long, typename T2 = long long>
void recursive_comb(vector<T2> indexes, T1 s, T1 rest, std::function<void(vector<T2>)> func) {
  if(rest==0) {
    func(indexes);
  }
  else {
    if (s < 0) return;
    recursive_comb(indexes, s-1, rest, func);
    indexes[rest-1] = s;
    recursive_comb(indexes, s-1, rest-1, func);
  }
}
template<typename T1 = long long, typename T2 = long long>
void foreach_comb(T1 n, T1 k, std::function<void(vector<ll>)> func) {
  vector<ll> indexes(k);
  recursive_comb(indexes, n-1, k, func);
}

int main() {
  cin >> N >> K;
  a.resize(N);
  rep(i,N) cin >> a[i];
  
  // vector<ll> ind(K);
  // recursive_comb(ind, N-1, K);
  foreach_comb(N, K, [&](vector<ll> ind) {
    ll cost = 0;
    vector<ll> builds = a;
    ll cind = 0;
    ll high = 0;
    for (ll i=0; i<N; ++i) {
      if(i == ind[cind]) {
        if(builds[i] > high) {
          high = builds[i];
        }
        else {
          high += 1;
          cost += high - builds[i];
          builds[i] = high;
        }
        cind++;
      }
      else {
        high = max(builds[i], high);
      }
    }
    ans = min(cost,ans);
  });
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int n,k;
vector<int> v[100030];
int d[100030][5];
long long f(int node, int prev){ //현재 노드랑 i lv 떨어진 곳에 있는 색
    int i;
    long long ret=d[node][0]=k-d[node][1]-d[node][2];
    for(int nxt : v[node])if(nxt!=prev){
        d[nxt][1]=1;
        for(i=2;i<4;i++){
            d[nxt][i]=d[node][i-1];
        }
        ret=(ret*f(nxt,node))%mod;
        d[node][1]++;
    }
    return ret;
}
int main(){
    int i,j,a,b;
    scanf("%d %d",&n,&k);
    for(i=1;i<n;i++){
        scanf("%d %d",&a,&b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    printf("%lld",f(1,0)%mod);
    return 0;
}


Measured memory_bytes: 12288
#include<stdio.h>

struct Card {
  char suit;
  int value;
};

void bubbleSort(Card A[], int n) {
  for ( int i = 0; i < n; i++ ) {
    for ( int j = n - 1; j > i; j-- ) {
      int v = j - 1;
      if (A[j].value < A[v].value) {
        Card t = A[j];
        A[j] = A[v];
        A[v] = t;
      }
    }
  }

  for ( int i = 0; i < n; i++ ) {
    if(i) printf(" ");
    printf("%c%d", A[i].suit, A[i].value);
  }
  printf("\n");
  printf("Stable\n");
}

void selectionSort(Card A[], int n) {
  for ( int i = 0; i < n; i++ ) {
    int min = i;
    int v = i + 1;
    while(v < n) {
      if ( A[min].value > A[v].value ) min = v;
      v++;
    }
    Card t = A[i];
    A[i] = A[min];
    A[min] = t;
  }
  for ( int i = 0; i < n; i++ ) {
    if(i) printf(" ");
    printf("%c%d", A[i].suit, A[i].value);
  }
  printf("\n");
}

int main() {
  int n, i;
  char t[3];
  Card A[36], B[36];

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    scanf("%s", t);
    B[i].suit = A[i].suit = t[0];
    B[i].value = A[i].value = t[1] - '0';
  }

  bubbleSort(A, n);
  selectionSort(B, n);

  for ( i = 0; i < n; i++ ) {
    if (A[i].suit != B[i].suit) break;
  }
  if (i == n) printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}



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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// p[i][j]: 先頭がi、終端がjの数列でX-Yの最大値
ll p[4000][4000];
// q[i][j]: 先頭がi、終端がjの数列でY-Xの最大値
ll q[4000][4000];

ll N;
vector<ll> a;

signed main() {
  cin >> N;
  a.resize(N);
  rep(i, N)
    cin >> a[i];
  rep(i, 4000) { p[i][i] = q[i][i] = 0; }
  for (ll len = 1; len <= 4000; len++) {
    rep(i, 3999) {
      ll j = i+len;
      if (j > N) continue;
      p[i][j] = max(a[i]-q[i+1][j], a[j-1]-q[i][j-1]);
      q[i][j] = max(a[i]-p[i+1][j], a[j-1]-p[i][j-1]);
    }
  }
  cout << p[0][N] << endl;
  return 0;
}


Measured memory_bytes: 249856
// d = B - A
// C <= x <= D, -D <= x <= -Cのxを(N-1)個足してdをつくれるか
 
// 正数をm使うとすると
// mC + (N-1-m)(-D) <= B - A <= mD + (N-1-m)(-C) が必要
// この区間の整数を全て取れるので十分
 
#include <iostream>
using ll = long long;
using namespace std;
 
int main() {
  ll N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  ll d = B - A;
  for (int m = 0; m <= N-1; m++) {
    ll l = m * C + (N-1-m) * (-D);
    ll r = m * D + (N-1-m) * (-C);
    if (l <= d && d <= r) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

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

#define int long long

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

#define len(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

const int N = 2e5 + 7;

int go[N][62];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> go[i][0];
        go[i][0]--;
    }
    for (int j = 1; j < 62; j++) {
        for (int i = 0; i < n; i++) go[i][j] = go[go[i][j - 1]][j - 1];
    }
    int v = 0;
    for (int i = 62; i > -1; i--) {
        if ((1LL << i) <= k) {
            k -= (1LL << i);
            v = go[v][i];
        }
    }
    cout << v + 1;
    return 0;
}


Measured memory_bytes: 100512