akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
using ll=long long;
const ll LINF=1e18;

template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;};
ll dp[3000][3000][4];
int main() {
  int r,c,k; cin>>r>>c>>k;
  ll a[r][c]; fill(a[0],a[r],0);
  for(int i=0;i<k;i++) {
    ll f,g,h; cin>>f>>g>>h; f--; g--;
    a[f][g] = h;
  }

  fill(dp[0][0], dp[r][0], -LINF);
  dp[0][0][0] = 0;
  dp[0][0][1] = a[0][0];

  for(int i=0;i<r;i++) {
    for(int j=0;j<c;j++) {
      for(int k=0;k<4;k++) {
        if (i+1 < r) {
          chmax(dp[i+1][j][0], dp[i][j][k]); // 下の行に移る
          chmax(dp[i+1][j][1], dp[i][j][k] + a[i+1][j]); // 下の行に移る
        }
        if (j+1 < c) {
          chmax(dp[i][j+1][k], dp[i][j][k]); // 右に移る
          if (k+1 < 4) {
            chmax(dp[i][j+1][k+1], dp[i][j][k] + a[i][j+1]);
          }
        }
      }
    }
  }

  ll an = 0;
  for(int i=0;i<4;i++) {
    an = max(an, dp[r-1][c-1][i]);
  }
  cout<<an<<endl;
}


Measured memory_bytes: 355032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n;
    cin>>n;
    vector<pair<ll,ll>> v;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        v.push_back({b,a});
    }

    sort(all(v));
    ll end=0;
    rep(i,n){
        if(end+v[i].second>v[i].first){
            cout<<"No"<<endl;
            return 0;
        }

        end+=v[i].second;
    }

    cout<<"Yes"<<endl;
}

Measured memory_bytes: 7400
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)*}
    };
}

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)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

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")
    };
}
use std::cmp::{min,max};
use std::collections::HashMap;
fn main() {
    input!{
        a:usize,
        b:usize,
    }
    let ans = if b == 1 {
        0
    } else {
         a -b
    };
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Graph{
	private:
	int n;
	vvi g;
	vi imos,big,dep;
	vp edge;
	void Bdfs(int v,int d){
		dep[v]=d;
		for(auto u:g[v]) if(dep[u]==-1) Bdfs(u,d+1);
	}
	int BDFS(int v){
		int d=dep[v],S=0;
		for(auto u:g[v]){
			int D=dep[u];
			if(D==d-1) continue;
			if(D==d+1) S+=BDFS(u);
			else if(D<d) S++;
			else S--;
		}
		return imos[v]=S;
	}
	void BDfs(int v,int t,int& id){
		big[v]=t;
		for(auto u:g[v]) if(dep[u]==dep[v]+1){
			if(imos[u]) BDfs(u,t,id);
			else{
				id++;
				BDfs(u,id,id);
			}
		}
	}
	int Biconnect(){
		imos=big=vi(n);
		dep=vi(n,-1);
		int t=0;
		Bdfs(0,0);BDFS(0);BDfs(0,0,t);
		return t+1;
	}
	public:
	Graph(int v){
		n=v;
		g=vvi(v);
	}
	void add_edge(int s,int t){
		g[s].push_back(t);
		g[t].push_back(s);
	}
	void solve(){
		int N=Biconnect();
		vp a;
		for(int u=0;u<n;u++) for(auto v:g[u]) if(big[u]<big[v])a.push_back({min(u,v),max(u,v)});
		sort(a.begin(),a.end());
		for(auto p:a) cout<<p.first<<' '<<p.second<<endl;
	}
};

int n,m;

int main(){
	cin>>n>>m;
	Graph g(n);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g.add_edge(u,v);
	}
	g.solve();
}


Measured memory_bytes: 6660
A,B,C=map(int,input().split())

t=0
while(True):
    if(A%2==1 or B%2==1 or C%2==1) :
        break
    a=(A+B)/2
    b=(B+C)/2
    c=(C+A)/2
    if(A==a and B==b and C==c):
        print(-1)
        exit()
    A=a
    B=b
    C=c
    t+=1
print(t)


Measured memory_bytes: 38256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.Stream;
import java.util.Arrays;

public class Main {
	public static void main(String args[]) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		int N = Integer.parseInt(line);
		String readline = br.readLine();
		readline = readline.trim();
		String[] stra = readline.split(" ");
		int[] inta = Stream.of(stra).mapToInt(Integer::parseInt).toArray();
		
		//for (int j = 0; j < inta.length; j++) {
		//	System.out.println(j.class);
		//}
		
		Arrays.sort(inta);
		//System.out.println(Arrays.toString(inta));
		
		int count = 0;
		for (int i = 0; i < N ; i++ ){
			count = count + inta[2 * i];
		}
		
		System.out.println(count);
	}
}

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

N = int(readline())

x = N
S = 0
while x:
    q,r = divmod(x,10)
    x=q; S+=r

answer = 'Yes' if N%S == 0 else 'No'
print(answer)

Measured memory_bytes: 3064
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.ascii;

void main() {
    int k;
    long[] a;

    scan(k);
    a = readln.split.to!(long[]);

    auto u = new long[](k), b = new long[](k);

    if (a[k-1] == 2) {
        u[k-1] = 3;
        b[k-1] = 2;
    }
    else {
        writeln(-1);
        return;
    }

    foreach_reverse (i ; 0 .. k - 1) {
        u[i] = (u[i+1]/a[i])*a[i] + a[i] - 1;
        b[i] = ((b[i+1] + a[i] - 1) / a[i]) * a[i];

        if (b[i] > u[i]) {
            writeln(-1);
            return;
        }
    }

    debug {
        writeln(u);
        writeln(b);
    }

    writeln(b[0], " ", u[0]);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

int main(){
    int n;
    scanf("%d",&n);
    vector<int> v(n);
    for(int i=0;i<n;i++) scanf("%d",&v[i]);
    for(int i=n-1; i>=0;i-=2) printf("%d ",v[i]);
    for(int i=n%2;i<n;i+=2) printf("%d ",v[i]);
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...)                                                             \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    void solve() {
        int n;
        string s;
        cin >> n;
        set<string> S;
        while (n--) {
            cin >> s;
            S.insert(s);
        }
        cout << S.size() << '\n';
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 19240
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner reader = new Scanner(System.in);
        String []d={"Sunny","Cloudy","Rainy"};
        String input=reader.next();
       switch(input){
           case  "Sunny":
               {
                   System.out.println("Cloudy");
                   break;
               }
           case  "Cloudy":
               {
                   System.out.println("Rainy");
                   break;
               }
           case  "Rainy":
               {
                   System.out.println("Sunny");
                   break;
               }
        
       }
    }}

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

template<class T = int>
class BIT {
    private:
        T size;
        vector<T> data;
    public:
        BIT(T size) {
            this->size = size;
            this->data = vector<T>(size + 1, 0);
        };

        void add(T index, T value = 1) {
            while (index <= this->size) {
                this->data[index] += value;
                index += index & (-index);
            }
        };

        T sum(T index) {
            T ret = 0;
            while (index > 0) {
                ret += this->data[index];
                index -= index & (-index);
            }
            return ret;
        };

        T search(T value) {
            T i = 0, s = 0;
            T step = 1;
            while (step < this->size) step *= 2;

            while (step > 0) {
                if (i + step <= this->size && s + this->data[i + step] < value) {
                    i += step;
                    s += this->data[i];
                }
                step /= 2;
            }
            return i + 1;
        };
};

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

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

    map<int, int> pToI;
    for (int i = 0; i < N; i++) {
        pToI[P[i]] = i + 1;
    }

    BIT<> tree(N);
    long ans = 0;

    for(int p = N; p > 0; p--) {
        int i = pToI[p];

        int left = tree.sum(i);
        int right = (N - p) - left;
        tree.add(i);

        int L1 = (left >= 2) ? tree.search(left - 1) : 0;
        int L2 = (left >= 1) ? tree.search(left) : 0;
        int R1 = (right >= 1) ? tree.search(left + 2) : N + 1;
        int R2 = (right >= 2) ? tree.search(left + 3) : N + 1;

        long cnt = 0;
        if (L2 != 0) cnt += (L2 - L1) * (R1 - i);
        if (R1 != 0) cnt += (R2 - R1) * (i - L2);

        ans += cnt * p;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int h,w,ans;
    cin>>h>>w;
    if(h==1 || w==1)
    {
        cout<<"1";return;
    }
    ans=(long long int)(h*w+1)/2;
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <memory.h>
#include <stdlib.h>


int main(void)
{	
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	
	if(b<=c || d<=a){
		printf("0\n");
	} else if(c<b && b<=d &&a<c){
		printf("%d\n",b-c);
	} else if(a<d && d<=b &&c<a){
		printf("%d\n",d-a);
	} else if(a<=c && d<=b){
		printf("%d\n",d-c);
	} else {
		printf("%d\n",b-a);
	}
	return 0;
}


Measured memory_bytes: 128
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    A = LI()

    s = 0
    f = 1000
    for i in range(N-1):
        f += s * A[i]
        if A[i+1] > A[i]:
            s = f // A[i]
            f -= s * A[i]
        else:
            s = 0
    print(f+s*A[-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 68772
n=int(input())
for i in range(n):
    l=list(map(int,input().split()))
    if l[0]*l[0]+l[1]*l[1] == l[2]*l[2]:
        print("YES")
    elif l[2]*l[2]+l[1]*l[1] == l[0]*l[0]:
        print("YES")
    elif l[0]*l[0]+l[2]*l[2] == l[1]*l[1]:
        print("YES")
    else:
        print("NO")




Measured memory_bytes: 5596
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

int fx(string s){
  int ans=0;
  for(int i=0;i<s.size();i++)ans+=s[i]-'0';
  return ans;
}

signed main(){
  while(true){
    string s;
    cin>>s;
    if(s=="0")break;
    cout<<fx(s)<<endl;
  }
}



Measured memory_bytes: 3192
#include <iostream>
#include <vector>
using namespace std;
int main(){
	vector<int> a;
	int in;
	while(cin >> in){
		if(in != 0)
			a.push_back(in);
	}
	int no = 1;
	for(auto it : a){
		cout << "Case " << no << ": " << it << endl;
		no++;
	}
return 0;
}

Measured memory_bytes: 3256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,k,n) for(int i=k;i<n;i++)
using namespace std;

int main(){
	int t; cin>>t;
	for(int z=0;z<t;z++){
		int n,k; cin>>n>>k;
		int a[n],b[n-1]; rep(i,n) cin>>a[i];
		rep(i,n-1) b[i]=a[i+1]-a[i];
		sort(b,b+n-1);
		long ans=0;
		rep(i,n-k) ans+=b[i];
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 3848
#include <iostream>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <iomanip>
#include <math.h>
#include <algorithm>
#define oo 1000000007
#define maxN 207
using namespace std;

long long f[2007];

int main() {

    int n;
    cin >> n;

    f[0] = 1LL;
    for (int i = 3; i <= n; ++i) {
        for (int j = 3; j <= i; ++j) {
            f[i] = (f[i]+f[i-j])%oo;
        }
    }
    cout << f[n] << endl;
    return 0;
}

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int dp[][] = new int[99][50];
		int n = 0;
		for (int i = 0; i < 100; i++) {
			if (!sc.hasNext()) {
				n = i - 1;
				break;
			}
			String tmp[] = sc.next().split(",");
			for (int j = 0; j < tmp.length; j++)
				dp[i][j] = Integer.parseInt(tmp[j]);
			// System.out.println(Arrays.toString(dp[i]));
		}
		// System.out.println(n);
		if (n == 0) {
			System.out.println(dp[0][0]);
		} else {
			for (int i = 1; i <= n / 2; i++) {
				for (int j = 0; j <= i; j++) {
					if (j - 1 < 0) {
						dp[i][j] += dp[i - 1][j];
					} else {
						dp[i][j] += Math.max(dp[i - 1][j], dp[i - 1][j - 1]);
					}
				}
			}
			for (int i = n / 2 + 1; i <= n; i++) {
				for (int j = 0; j <= n - i; j++) {
					dp[i][j] += Math.max(dp[i - 1][j], dp[i - 1][j + 1]);
				}
			}
			System.out.println(dp[n][0]);
		}
	}
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int lgsz = 30;
const int zero = 1000, one = 1001, two = 1002;
int p2[60 + 5];
vector<string> operations;

string inline int_to_str(int a) {
	if (a == 0) return "0";
	string s;
	for (; a; s += a % 10 + 48, a /= 10);
	reverse(all(s));
	return s;
}

void inline add_to(int i, int j, int to) {
	operations.push_back("+ " + int_to_str(i) + " " + int_to_str(j) + " " + int_to_str(to));
}

void inline cmp_to(int i, int j, int to) {
	operations.push_back("< " + int_to_str(i) + " " + int_to_str(j) + " " + int_to_str(to));
}

void inline set_0(int i) {
	cmp_to(zero, zero, i);
}

void inline set_1(int i) {
	cmp_to(zero, one, i);
}

void inline mul_by_power_of_2(int i, int e) {
	cont (k, e) add_to(i, i, i);
}

void inline mul_power_of_2_to(int i, int e, int k) {
	const int j = 100;
	set_0(j);
	add_to(i, zero, j);
	cont (i, e) add_to(j, j, j);
	add_to(j, zero, k);
}

void inline or_to(int i, int j, int to) {
	const int or_p = 2000;
	cmp_to(zero, i, or_p);
	cmp_to(zero, j, to);
	add_to(to, or_p, to);
	cmp_to(zero, to, to);
}

void inline and_to(int i, int j, int to) {
	const int and_p = 2001;
	cmp_to(zero, i, and_p);
	cmp_to(zero, j, to);
	add_to(to, and_p, to);
	cmp_to(one, to, to);
}

void inline factorize_to_binary(int i, int fm, int len = lgsz) {
	const int sum = 3000, j = 3001, cur = 3002, cur_sum = 3003, cur_del = 3004;
	set_0(sum);
	add_to(i, one, j);
	for (int k = len; k >= 0; --k) {
		add_to(sum, p2[k], cur_sum);
		cmp_to(cur_sum, j, fm + k);
		mul_power_of_2_to(fm + k, k, cur_del);
		add_to(sum, cur_del, sum);
	}
}

void inline mul_bool_to(int i, int j, int to, int len = lgsz) {
	const int fm = 4000;
	factorize_to_binary(i, fm, len);
	circ (k, 0, len) {
		and_to(fm + k, j, fm + k);
	}
	set_0(to);
	circ (k, 0, len) {
		mul_by_power_of_2(fm + k, k);
		add_to(to, fm + k, to);
	}
}

void inline mul(int i, int j, int to) {
	const int fm = 200, a = 300, del = 301;
	factorize_to_binary(j, fm);
	set_0(to);
	set_0(a);
	add_to(a, i, a);
	circ (k, 0, lgsz) {
		mul_bool_to(a, fm + k, del, 60);
		add_to(to, del, to);
		add_to(a, a, a);
	}
}

void inline init() {
	p2[0] = one;
	add_to(0, 1, 5);
	cmp_to(zero, 5, one);
	cont (i, 60) {
		p2[i] = one + i;
		add_to(p2[i - 1], p2[i - 1], p2[i]);
	}
}

int main() {
	init();
	mul(0, 1, 2);
	cout << operations.size() << ln;
	for (string cmd : operations) {
		cout << cmd << ln;
	}
}

Measured memory_bytes: 14444
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<30)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

ll calc(ll num){
  if(num%4==0){
    return num;
  }else if(num%4==1){
    return 1;
  }else if(num%4==2){
    return num+1;
  }else if(num%4==3){
    return 0;
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll A,B;
  ll ans=0;
  cin >> A >> B;
  if(A==B){
    cout << A << endl;
    return 0;
  }
  A--;
  ll a=calc(A);
  ll b=calc(B);
  ans=a^b;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;
 
int main(){
int n;
cin>>n;
int total=0;
int l[100001],r[100001];
rep(i,0,n){
    
    cin>>l[i]>>r[i];
    total+=r[i]-l[i]+1;
}
cout<<total<<endl;
return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

struct Dungeon{
	int plus,pos;

	bool operator<(const Dungeon &d)const{
		if(plus!=d.plus) return plus<d.plus;
		else pos<d.pos;
	}
};

struct SegmentTree{
	int sz;
	vector<int> val,lazy;

	SegmentTree(int n){
		Init(n);
	}

	void Init(int n){
		sz=1;
		while(sz<n) sz*=2;
		val.assign(sz*2-1,0);
		lazy.assign(sz*2-1,0);
	}

	inline void Evaluate(int k){
		val[k]+=lazy[k];
		if(k<sz-1){
			lazy[k*2+1]+=lazy[k];
			lazy[k*2+2]+=lazy[k];
		}
		lazy[k]=0;
	}

	void Update(int k){
		val[k]=max(val[k*2+1],val[k*2+2]);
	}

	void Add(int a,int b,int x,int k,int l,int r){
		Evaluate(k);

		if(r<=a||b<=l) return;
		if(a<=l&&r<=b){
			lazy[k]+=x;
			Evaluate(k);
			return;
		}

		Add(a,b,x,k*2+1,l,(l+r)/2);
		Add(a,b,x,k*2+2,(l+r)/2,r);
		Update(k);
	}

	void Add(int a,int b,int x){
		Add(a,b,x,0,0,sz);
	}

	int Max(int a,int b,int k,int l,int r){
		Evaluate(k);

		if(r<=a||b<=l) return 0;
		if(a<=l&&r<=b) return val[k];

		int lv=Max(a,b,k*2+1,l,(l+r)/2);
		int rv=Max(a,b,k*2+2,(l+r)/2,r);
		Update(k);

		return max(lv,rv);
	}

	int Max(int a,int b){
		return Max(a,b,0,0,sz);
	}
};


void Solve(){
	int n,h,di[100000],hi[100000],life;

	cin >> n >> h;
	rep(i,0,n-1) cin >> di[i] >> hi[i];

	life=h;

	ll ans=0;
	SegmentTree st(n);
	priority_queue<Dungeon> que;
	rep(i,0,n-1){
		st.Add(i,i+1,life);
		Dungeon in;
		life-=di[i];

		in.plus=hi[i];
		in.pos=i;

		que.push(in);
		while(life<=0){
			Dungeon heal=que.top();
			que.pop();

			int maxi=st.Max(heal.pos,i+1);

			if(heal.plus+maxi>h){
				heal.plus=h-maxi;
				que.push(heal);
				continue;
			}

			int num=min((-1*life)/heal.plus+1,(h-maxi)/heal.plus);
			ans+=num;
			life+=num*heal.plus;

			st.Add(heal.pos,i+1,num*heal.plus);
			que.push(heal);
		}
	}

	cout << ans << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 4916
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>
#include <ctype.h>
using namespace std;
int a,b,d,r;
double f,aa,bb;
int main(){
	cin>>a>>b;
	d=a/b;
	r=a%b;
	aa=a;
	bb=b;
	f=aa/bb;
	cout<<d<<" "<<r<<" ";
	printf("%.8lf\n", f);
	cout<<endl;
    return 0;}


Measured memory_bytes: 1240
#!/usr/bin/env ruby

k = 0
loop do
  k += 1
  w = gets.chomp!.to_i
  break if w.zero?

  n = gets.chomp!.to_i

  things = []
  dyn = Array.new(w+1, -1)

  n.times do
    things << gets.chomp!.split(?,).map(&:to_i)
  end

  ## ???????¨???????
  # ?????????
  dyn[0] = 0
  # ??????
  things.each do |e|
    w.downto(0) do |i|
      next if dyn[i] < 0
      next if i+e[1] > w
      dyn[i+e[1]] =  dyn[i] + e[0] if dyn[i+e[1]] < dyn[i] + e[0]
    end
  end

  max = dyn.max

  (w+1).times do |i|
    if dyn[i] == max
      puts "Case #{k}:"
      puts max
      puts i
      break
    end
  end
end

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

int main(){

  while(1){
    int x, y;
    cin>>x>>y;
    
    if (x==0 && y==0)break;
    if (x > y) swap(x, y);
    
    cout<<x<<" "<<y<<endl;
  }
  
  return 0;
}



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

int main(void){
    int n;
    cin >> n;
    set<int> st;
    for(int i=0; i<n; i++){
        int aa;
        cin >> aa;
        st.insert(aa);
    }
    int s[11000];
    for(int i=0; i<11000; i++){
        s[i] = -1;
    }
    int ix = 0;
    for(auto itr = st.begin(); itr != st.end(); ++itr) {
        s[ix] = *itr;
        ix++;
    }
    int q;
    cin >> q;
    int t[1000];
    for(int i=0; i<q; i++){
        cin >> t[i];
    }

    int count = 0;
    
    for(int i=0; i<q; i++){
        for(int j=0; j<n; j++){
            if(t[i] == s[j]) count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3184
#include <iostream>

using namespace std;

int main() {
  for (;;) {
    int n, m, h, d, a[9];
    char l[30][10];
    cin >> n;
    if (!n) return 0;
    cin >> m >> h >> d;
    m--;
    h--;
    for (int i = 0; i < d; i++)
      cin >> l[i];
    for (int i = 0; i < n; i++)
      a[i] = i;
    for (int i = 0; i < d; i++)
      for (int j = 0; j < n-1; j++)
        if (l[i][j] == '1')
          swap(a[j], a[j+1]);
    int p = a[h];
    if (m == p) {
      cout << 0 << endl;
      goto next;
    }
    for (int i = 0; i < n; i++)
      a[i] = i;
    for (int i = 0; i < d; i++) {
      for (int j = 0; j < n-1; j++)
        if (l[i][j] == '0' && (!j || l[i][j-1] == '0') && (j == n-2 || l[i][j+1] == '0') &&
            (a[j] == m && a[j+1] == p || a[j] == p && a[j+1] == m)) {
          cout << i+1 << ' ' << j+1 << endl;
          goto next;
        }
      for (int j = 0; j < n-1; j++)
        if (l[i][j] == '1')
          swap(a[j], a[j+1]);
    }
    cout << 1 << endl;
next:;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#ifndef ONLINE_JUDGE
#define OJ \
    freopen("input.txt", "r", stdin); \
    //freopen("output.txt", "w", stdout);
#else
#define OJ ;
#endif
void solve()
{
    int n;
    ll ans=0;
    cin>>n;
    vector<int> l(n);
    for(int i=0;i<n;++i)
        cin>>l[i];
    sort(l.begin(),l.end());
    for(int i=0;i<n;++i)
    {

        for(int j=i+1;j<n;++j)
        {
            if(l[i]!=l[j])
            for(int k=j+1;k<n;++k)
            {
                if(l[j]!=l[k]){
                if(l[k]<l[j]+l[i])
                {
                     ans++;
                }
                }
            }
        }
    }
    cout<<ans<<"\n";
    
}
signed main()
{
    OJ
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //int _t;cin>>_t;while(_t--)
    solve();
    return 0;
}

Measured memory_bytes: 3660
getConbination :: Int -> Int -> (Int, Int, Int)
getConbination n y = head ([(a, b, n-a-b) | a <- [0..n], b <- [0..n-a], 10000*a+5000*b+1000*(n-a-b) == y] ++ [(-1, -1, -1)])

showAnswer :: (Int, Int, Int) -> String
showAnswer (a, b, c) = show a ++ " " ++ show b ++ " " ++ show c

toInt :: String -> Int
toInt = read :: String -> Int

main = do
  [n, y] <- map toInt . words <$> getLine
  putStrLn $ showAnswer $ getConbination n y

Measured memory_bytes: 508
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    N=int(input())
    A=sorted(list(map(int,input().split())))

    l=[0]*(10**6+5)

    for i in A:
        if l[i]!=0:
            l[i]+=1
            continue
        for j in range(i,10**6+5,i):
            l[j]+=1
    
    cnt=0
    for i in A:
        if l[i]==1:
            cnt+=1
    print(cnt)




    
resolve()

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

import sys
import os
import math

P = [[0 for i in range(10)] for j in range(10)]

def paint(x, y):
    if 0 <= x <= 9 and 0 <= y <= 9:
        P[x][y] += 1

for s in sys.stdin:
    x, y, s = map(int, s.split(','))

    if s >= 1:
        paint(x, y)
        paint(x - 1, y)
        paint(x + 1, y)
        paint(x, y - 1)
        paint(x, y + 1)

    if s >= 2:
        paint(x - 1, y - 1)
        paint(x + 1, y - 1)
        paint(x - 1, y + 1)
        paint(x + 1, y + 1)

    if s >= 3:
        paint(x - 2, y)
        paint(x + 2, y)
        paint(x, y - 2)
        paint(x, y + 2)

    # debug
    #print('-----------------------')
    #for row in P:
    #    print(*row)

white = 0
for row in P:
    white += row.count(0)

max_value = 0
for row in P:
    max_value = max(max_value, max(row))

print(white)
print(max_value)

Measured memory_bytes: 7840
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;

int main() {
    uint32_t N, amari;
    cin >> N;
    amari = N % 1000;

    cout << (amari==0 ? 0: 1000-amari) << endl;

	return 0;
}



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

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

    uint64_t p = 1;
    for (int i = 1; i <= N; ++i) {
        p *= i;
        p %= (1000000000 + 7);
    }

    std::cout << p << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,ans=0;
  cin>>a>>b>>c;
  vector<int>v={a,b,c};
  for(int i = 0;i<3;i++)
  {if(v.at(i)==5)ans+=1;}
      if(ans==2)cout<<"YES"<<endl;
      else if(ans!=2) cout<<"NO"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;


namespace debug
{
    class Program
    {
        static void Main(string[] args)
        {
            ProgramC a = new ProgramC();
            a.main();

        }
    }

    //ABC096
    class ProgramA
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);

            Console.WriteLine((a -1)*(b-1));
        }
    }

    class ProgramB
    {
        public void main()
        {
            int n = int.Parse(Console.ReadLine());

            int ans = 0;
            for (int i = 1; i <= n; i = i + 2)
            {
                int count = 0;
                for (int j = 1; j < Math.Sqrt(i);j++)
                {
                    if(i % j == 0)
                    {
                        if (i == j * j)
                            count++;
                        else
                            count += 2;
                    }
                }

                if (count == 8)
                    ans++;
            }

            Console.WriteLine(ans);
            

        }
    }

    class ProgramC
    {
        public void main()
        {
            string s = Console.ReadLine();
            long k = long.Parse(Console.ReadLine());

            int pos = 0;
            for(int i = 0;i < s.Length;i++)
            {
                if (s[i] != '1')
                {
                    pos = i;
                    break;
                }
            }

            if (k - 1 < pos)
                Console.WriteLine("1");
            else
                Console.WriteLine(s[pos]);

        }
    }

    class ProgramD
    {
        public void main()
        {
            long n = long.Parse(Console.ReadLine());
            string[] xi = Console.ReadLine().Split(' ');

            long[] a = new long[n];

            for (int i = 0; i < n; i++)
                a[i] = long.Parse(xi[i]);

            //ソートする
            Array.Sort(a);

            //最大値候補
            long sum = a[n - 1] / 2;

            //二分探索
            long min = -1;
            long max = n;
            while(min + 1 != max)
            {
                long temp = (min + max) / 2;
                if (a[temp] <= sum)
                    min = temp;
                else
                    max = temp;
            }

            if(min == -1)
            {
                Console.WriteLine(a[n - 1] + " " + a[0]);
                return;
            }

            if (min == n - 2)
            {
                Console.WriteLine(a[n - 1] + " " + a[n - 2]);
                return;
            }

            if (sum - a[min] < a[max] - sum)
                Console.WriteLine(a[n - 1] + " " + a[min]);
            else
                Console.WriteLine(a[n - 1] + " " + a[max]);

        }

    }

    

}


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

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

  vector<int> v(n);
  for (size_t i = 0; i < n; i++) cin >> v[i];

  long long ans = 0;
  for(int a=0; a<=100; ++a){
    for(int b=0; b<=100 && a+b <= min(n, k); ++b){
      long long sum = 0;
      vector<int> m(min(n, k));

      for(int i=0; i<a; ++i){
        if(v[i] < 0) m.emplace_back(v[i]);
        sum += v[i];
      }
      for(int i=n-1; i>n-1-b; --i){
        if(v[i] < 0) m.emplace_back(v[i]);
        sum += v[i];
      }
      sort(m.begin(), m.end());
      for(int i=0; i<k - (a + b) && i < m.size(); ++i) sum-=m[i];
      ans = max(ans, sum);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
counter = 0
def myAnswer(H:list) -> int:
   global counter
   if(len(H)==0):
      return
   if(len(H)==1):
      counter += H[0]
      return
   MIN = min(H)
   for i in range(len(H)):
      H[i] -= MIN
   counter += MIN
   myAnswer(H[:H.index(0)])
   myAnswer(H[H.index(0)+1:])


def modelAnswer():
   return
def main():
   N = int(input())
   H = list(map(int,input().split()))
   myAnswer(H[:])
   print(counter)
if __name__ == '__main__':
   main()



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

using namespace std;

long long a[400001];

int main () {
	int n;
	cin >> n;
	for (int i = 1;i <= 3 * n;i ++) cin >> a[i];
	sort (a + 1, a + 3 * n + 1);
	long long ans = 0;
	for (int i = n + 1;i <= 3 * n;i += 2) ans += a[i];
	cout << ans;
	return 0;
}

Measured memory_bytes: 2560
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val d = sc.nextInt()
    println(problem092a(a, b, c, d))
}

fun problem092a(a: Int, b: Int, c: Int, d: Int): Int {
    return Math.min(a, b) + Math.min(c, d)
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x;
    cin >> n >> x;
    vector<int> ds(n);
    for (int& d : ds) {
        cin >> d;
    }
    int sum = 0;
    int count = 0;
    for (int d : ds) {
        count += sum <= x;
        sum += d;
    }
    count += sum <= x;
    cout << count << endl;
    return 0;
}


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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;

  vector<P> vu, vd, vl, vr;
  vector<P> tmpl, tmpr;

  rep(i, n) {
    ll x, y;
    char key;
    cin >> x >> y >> key;
    if (key == 'U') {
      vu.emplace_back(x, y);
    } else if (key == 'D') {
      vd.emplace_back(x, y);
    } else if (key == 'L') {
      vl.emplace_back(x, y);
      tmpl.emplace_back(y, x);
    } else {
      vr.emplace_back(x, y);
      tmpr.emplace_back(y, x);
    }
  }

  sort(all(vu));
  sort(all(vd));
  sort(all(tmpl));
  sort(all(tmpr));

  ll ans = INF;

  for (auto& it_l : tmpr) {
    auto it_r = lower_bound(all(tmpl), it_l);
    if (it_r == tmpl.end())
      continue;
    if (it_r->first == it_l.first) {
      ll t = abs(it_r->second - it_l.second) * 5;
      chmin(ans, t);
    }
  }
  for (auto& it_l : vu) {
    auto it_r = lower_bound(all(vd), it_l);
    if (it_r == vd.end())
      continue;
    if (it_r->first == it_l.first) {
      ll t = abs(it_r->second - it_l.second) * 5;
      chmin(ans, t);
    }
  }

  rep(i, 4) {
    map<ll, vector<P>> mu, md, ml, mr;
    for (const auto& it : vr) {
      mr[it.second - it.first].push_back(it);
    }

    for (const auto& it : vd) {
      ll idx = it.second - it.first;
      auto vr = mr.find(idx);
      if (vr == mr.end()) {
        continue;
      }
      auto& v = vr->second;
      auto itr = lower_bound(all((v)), make_pair(it.first, (ll)-INF));
      if (itr == v.begin()) {
        continue;
      }
      itr = prev(itr);
      ll t = 10 * abs(it.first - itr->first);
      chmin(ans, t);
    }
    auto tmp = vr;
    vr = vu;
    swap(tmp, vd);
    swap(tmp, vl);
    swap(tmp, vu);
    for (auto& itr : vu) {
      swap(itr.first, itr.second);
      itr.second *= -1;
    }
    for (auto& itr : vd) {
      swap(itr.first, itr.second);
      itr.second *= -1;
    }
    for (auto& itr : vl) {
      swap(itr.first, itr.second);
      itr.second *= -1;
    }
    for (auto& itr : vr) {
      swap(itr.first, itr.second);
      itr.second *= -1;
    }
  }

  if (ans == INF) {
    cout << "SAFE" << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 31132
use std::io;
use std::io::*;
use std::str::FromStr;


fn abc(buf:Vec<i32>) -> i32 {
    let max:i32 = *buf.iter().max().unwrap();
    let min:i32 = *buf.iter().min().unwrap();
    return max - min;
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    /*
    assert_eq!(abc(), "Yes");
    assert_eq!(abc(101), "No");
    assert_eq!(abc(999999999), "Yes");
    */
    let n: i32 = read();
    let mut A: Vec<i32> = (0..n).map(|_| read()).collect();

    let result = abc(A);
    println!("{}", result);
}



Measured memory_bytes: 4352
import random
D = int(input())
C = input().split()
C = [int(c) for c in C]
S = []
for i in range(D):
  s = input().split()
  s = [int(j) for j in s]
  S.append(s)
#T = [1,17,13,14,13]
T = [26] * D
def value():
  M = 0
  last = [0] * 26
  for d in range(1,D+1):
    N = 0
    t = T[d-1]
    last[t-1] = d
    #print(last)
    for j in range(26):
      N = N + C[j]*(d-last[j])
    M = M + S[d-1][t-1] - N
  return(M)
Vmax = value()
#print(Vmax)
Q = []
for i in range(1000):
  Q.append([random.randint(1,D), random.randint(1,26)])
for i in range(1000):
  Tprev = T
  T[Q[i][0]-1] = Q[i][1]
  V = value()
  if V > Vmax:
    Vmax = V
  else:
    T = Tprev
  #print(Vmax)
#print(T)
for t in T:
  print(t)

Measured memory_bytes: 9908
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>

#define ll long long

int main()
{
    ll N, K;
    std::cin >> N >> K;

    int count = 0;
    while(N != 0) {
        count++;
        N /= K;
    }
    
    std::cout << count << std::endl;
}

Measured memory_bytes: 3576
#include<iostream>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>//min,max,swap,rand,reverse,sort,lower_bound
#include<functional>
#include<vector>
#include<list>
#include<map>
#include<tuple>
#include<cmath>//abs, sin, cos
#include<bitset>
using namespace std;

int main()
{
	int A, B;
	int power = 1;
	int tap = 0;
	cin >> A >> B;
	while (B >= power) {
		if (B <= power)
			break;
		power += A-1;
		tap++;
		if (B <= power)
			break;
	}

	cout << tap << endl;

	return 0;
}

Measured memory_bytes: 3132
#!/usr/bin/env python3
import sys
from math import factorial

def comb(n: int, r: int):
    return factorial(n) // (factorial(r)*factorial(n-r))

def solve(n: int, a: "List[int]"):
    a.sort()

    m = a[-1]
    print(m, min(a, key=lambda x:abs(m/2-x)))
    
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2005,mx=4000000,mod=1e9+7;
inline void add(int &x,int y){
	x+=y;if(x>=mod) x-=mod;
}
inline int pls(int x,int y){
	add(x,y);return x;
}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline int qpow(int a,int b){
	int res=1;
	for(;b;b>>=1,a=mul(a,a)) if(b&1) res=mul(res,a);
	return res;
}
int n,k;
int fac[N*N],inv[N*N];
int f[N][N];
inline int C(int n,int m){
	if(n<0||m<0||n<m) return 0;
	return mul(mul(fac[n],inv[m]),inv[n-m]);
}
int main(){
	fac[0]=1;
	for(int i=1;i<=mx;i++) fac[i]=mul(fac[i-1],i);
	inv[mx]=qpow(fac[mx],mod-2);
	for(int i=mx-1;i>=0;i--) inv[i]=mul(inv[i+1],i+1);
	scanf("%d%d",&n,&k);
	if(k==1){puts("1");return 0;}
	for(int i=1;i<=n;i++) f[i][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=i;j++)
			f[i][j]=pls(f[i-1][j],mul(f[i][j-1],mul(n-j+1,C(n*k-i-(j-1)*(k-1)-1,k-2))));
	printf("%lld",f[n][n]);
	return 0;
}

Measured memory_bytes: 48768
n,x=map(int,input().split())
a=list(map(int,input().split()))
ret =0
if a[0]>x:
  ret+=a[0]-x
  a[0]=x
for i in range(1,n):
  if a[i-1]+a[i]>x:
    ret+=a[i-1]+a[i]-x
    a[i]=max(0,x-a[i-1])
print(ret)


Measured memory_bytes: 14152
import Data.List
main =
  getContents >>=
    mapM_ putStrLn
    . map (unwords . map show . sort . map (read :: String -> Int) . words)
    -- . map ((\xs -> if xs!!0 < xs!!1 then xs!!0 ++ " " ++ xs!!1 else xs!!1 ++ " " ++ xs!!0) . words)
    . init . lines



Measured memory_bytes: 4600
#include<bits/stdc++.h>
#define ll long long
#define no cout<<"NO"<<endl;
#define pb push_back
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define mod 1000000007
#define f first
#define sec second
#define gcd(x,y) __gcd(x, y)
using namespace std;
int main()
{
	string t,s;
	cin>>t>>s;
	/*while(t--)
	{
		
	}*/
	ll x=0;
	for(ll i=0;i<t.size();i++)
	{
		if(s[i]!=t[i])
		x++;
	}
	cout<<x<<endl;
	//cout<<t+t*t+t*t*t<<endl;
}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long long> v;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        if (tmp % 2 == 0) {
            v.push_back(tmp);
        }
    }

    if (v.size() == 0) {
        cout << 0 << endl;
        return 0;
    }
    sort(v.begin(), v.end());
    int count = 0;
    while (true) {
        int n = 0;
        while (v[0] % 2 == 0) {
            v[0] /= 2;
            n++;
        }
        v.erase(v.begin());
        if (v.size() == 0) {
            cout << count + n << endl;
            return 0;
        }
        int p = pow(3, n);
        for (int i = 0; i < v.size(); i++) {
            v[i] *= 3;
        }
        count += n;
    }
}

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

int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d;
    e = (c+b-1)/b;
    f = (a+d-1)/d;
    if(f>=e){
        cout << "Yes" <<endl;
    }
    else {
        cout << "No" <<endl;
    }
}

Measured memory_bytes: 3624
using System;

class ITP1_8_D{
    static void Main(string[] args){
        string str = Console.ReadLine().Trim();
        char[] ring = str.ToCharArray();
        string str2 = Console.ReadLine().Trim();
        char[] word = str2.ToCharArray();
        Boolean bl = true;
        for(int i=0; i<ring.Length; i++){
            if(ring[i]==word[0]){
                int j=0;
                int k=i;
                while(ring[k]==word[j]){
                    if(k==ring.Length-1){
                        k=-1;
                    }
                    if(j==word.Length-1){
                        Console.WriteLine("Yes");
                        bl = false;
                        break;
                    }
                    k++;
                    j++;
                }
            }
            if(!bl) break;
        }
        if(bl) Console.WriteLine("No");
    }
}


Measured memory_bytes: 17912
#include <iostream>

using namespace std;

int main()
{
    int a[1000],n,i;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    i--;
    cout << a[i];
    for(int ii=i-1; ii >= -1;ii--) {
        if(ii==-1)break;
        cout << " " << a[ii];
    }
    cout << endl;
}



Measured memory_bytes: 3064
// in the name if Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll N= 1e6 ;
#define f first
#define s second
ll n , k ;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> k >> n  ;
k -= (n-1);
if(n==1)return cout << 0 , 0 ;
cout << k-1 ;
    return 0;
}


Measured memory_bytes: 256