akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
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<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
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<<52;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

ll n,a,b;
vl x;

int main(){
	cin>>n>>a>>b;
	x=vl(n);
	for(int i=0;i<n;i++) cin>>x[i];
	ll ans=0;
	for(int i=1;i<n;i++){
		ans+=min(a*(x[i]-x[i-1]),b);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include "iostream"
#define nmax 1000
#define mmax 1000
typedef unsigned long long ull;
using namespace std;
int n, m;
int cost[nmax];
int voter[mmax];
int sport[nmax];
int p_max(int a[nmax],int imax) {
	int mx=0, ans;
	for (int i = 0; i < imax; i++){
		if (mx < a[i]) {
			ans = i;
			mx = a[i];
		}

	}
	return ans;
}
int vote(int a) {
	for (int i = 0; i < n; i++) {
		if (cost[i] <= a)return i;
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> cost[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> voter[i];
	}
	for (int i = 0; i < m; i++) {
		int slt=vote(voter[i]);
		sport[slt]++;

	}
	cout << p_max(sport, n)+1<<endl;


	return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> a(n),b(n),c(n);
	for(int i=0;i<n;i++) cin >> a[i];
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++) cin >> b[i];
	for(int i=0;i<n;i++) cin >> c[i];
	sort(c.begin(),c.end());

	long long  ans=0;
	vector<int> ab(n),bc(n);
	for(int i=0;i<n;i++){
		ans+=(lower_bound(a.begin(),a.end(),b[i])-a.begin())
			*(c.end()-upper_bound(c.begin(),c.end(),b[i]));
	}
	cout << ans << endl;
}


Measured memory_bytes: 2176
<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%d", $k);
fscanf(STDIN, "%d", $x);
fscanf(STDIN, "%d", $y);
$b = 0;
if ($n > $k) {
    $b = $n - $k;
}
$a = $n - $b;
echo ($a * $x) + ($b * $y) . "\n";

Measured memory_bytes: 3576
#include<stdio.h>
int main(void){
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if(r<=x&&x<=W-r&&r<=y&&y<=H-r){
printf("Yes\n");
}
else
printf("No\n");
return 0;
}

Measured memory_bytes: 584
/*h  t t p : / / t a k u -k . h a t e n a blog . c o m / entry /2013/ 03 / 2 6 / 174239 */
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
for(var i=0;i<Arr.length;i++){
   var arr=Arr[i].split(",").map(Number);
   (function(x1,y1,x2,y2,xq,yq){
      var k=(x2-x1==0)?Infinity:(y2-y1)/(x2-x1);
      var ans;
      if(k==0)ans=[xq,y1-(yq-y1)];
      else if(k==Infinity)ans=[x1-(xq-x1),yq];
      else{
         var  a1=(y2-y1)/(x2-x1);
         var  a2=(-1)/a1;
         var  b1=y1-a1*x1;
         var  b2=yq-a2*xq;
         var  xm=(b2-b1)/(a1-a2);
         var  x=2*xm-xq;
         var  y=a2*x+b2;
         ans=[x,y];
      }
      console.log(ans[0].toFixed(6)+" "+ans[1].toFixed(6));
   }).apply(null,arr);
}

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

const int MAXN = 2e3 + 3;
int s[MAXN][MAXN], v[MAXN][MAXN], e[MAXN][MAXN], romokh[2][MAXN][MAXN];
int n, m, q;
int a1, a2, b1, b2;

void input();
void cm_romokh();
void solve();

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	input();
	return 0;
}

void input() {
	cin >> n >> m >> q;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			s[i][j] = c - '0';
			//cout << s[i][j] << endl;
			if (i == 0 && j == 0) v[i][j] = (s[i][j] == 1);
			else if (i == 0) {
				v[i][j] = v[i][j - 1] + (s[i][j] == 1);
				e[i][j] = e[i][j - 1] + (s[i][j] == s[i][j - 1] && s[i][j] == 1);
			}
			else if (j == 0) {
				v[i][j] = v[i - 1][j] + (s[i][j] == 1);
				e[i][j] = e[i - 1][j] + (s[i][j] == s[i - 1][j] && s[i][j] == 1);
			}
			else {
				v[i][j] = v[i][j - 1] + v[i - 1][j] - v[i - 1][j - 1] + (s[i][j] == 1);
				e[i][j] = e[i][j - 1] + e[i - 1][j] - e[i - 1][j - 1] + (s[i][j] == 1 && s[i][j] == s[i - 1][j]) + (s[i][j] == 1 && s[i][j] == s[i][j - 1]);
			}
		}
	cm_romokh();
	//cout << romokh[1][1][2];
	while (q--) {
		cin >> a1 >> b1 >> a2 >> b2;
		if (a1 > a2) swap(a1, a2);
		if (b1 > b2) swap(b1, b2);
		a1--, a2--, b1--, b2--;
		solve();
	}
}

void cm_romokh() {
	for (int i = 1; i < n; i++) {
		romokh[0][i][0] = (s[i][0] == s[i - 1][0] && s[i][0] == 1);
		for (int j = 1; j < m; j++)
			romokh[0][i][j] = romokh[0][i][j - 1] + (s[i][j] == s[i - 1][j] && s[i][j] == 1);
	}
	for (int i = 1; i < m; i++) {
		romokh[1][0][i] = (s[0][i] == s[0][i - 1] && s[0][i] == 1);
		for (int j = 1; j < n; j++)
			romokh[1][j][i] = romokh[1][j - 1][i] + (s[j][i] == s[j][i - 1] && s[j][i] == 1);
	}
}

void solve() {
	int te = 0, tv = 1;
	if (a1 == 0 && b1 == 0) {
		tv = v[a2][b2];
		te = e[a2][b2];
	}
	else if (a1 == 0) {
		tv = v[a2][b2] - v[a2][b1 - 1];
		te = e[a2][b2] - e[a2][b1 - 1] - romokh[1][a2][b1];
	}
	else if (b1 == 0) {
		tv = v[a2][b2] - v[a1 - 1][b2];
		te = e[a2][b2] - e[a1 - 1][b2] - romokh[0][a1][b2];
	}
	else {
		tv = v[a2][b2] + v[a1 - 1][b1 - 1] - v[a1 - 1][b2] - v[a2][b1 - 1];
		te = e[a2][b2] + e[a1 - 1][b1 - 1] - e[a1 - 1][b2] - e[a2][b1 - 1];
		te -= romokh[0][a1][b2] - romokh[0][a1][b1 - 1];
		te -= romokh[1][a2][b1] - romokh[1][a1 - 1][b1];
	}
	cout << tv - te << endl;
}


Measured memory_bytes: 81888
using System;

public class Program
{
    private int N;
    private long[] A;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.LongArray();

        long ans = 0;

        while (true)
        {
            bool flag = true;
            for (int i = 0; i < N; i++)
            {
                if (A[i] >= N)
                {
                    flag = false;
                    long c = A[i] / N;
                    A[i] %= N;
                    for (int j = 0; j < N; j++)
                    {
                        if (i == j) continue;
                        A[j] += c;
                    }

                    ans += c;
                }
            }

            if (flag) break;
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 11092
n=int(input())
a=0
b=0
c=0
d=0
for _ in range(n):
    g=input()
    if g=="AC":
        a+=1
    if g=="WA":
        b+=1
    if g=="TLE":
        c+=1    
    if g=="RE":
        d+=1
print("AC x "+str(a))
print("WA x "+str(b))
print("TLE x "+str(c))
print("RE x "+str(d))

Measured memory_bytes: 9212
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INPUT1(n, a) for(int i##n = 0; i##n < n; i##n++) {cin >> a[i##n]; } //n = count, a = vector 
#define OUTPUT1(n, a) cout << "---count---" << endl << n << endl << "---content---" << endl; for(const auto b : a){cout << b << endl; }
#define INPUT2(x, y, field) for(int i##x = 0; i##x < y; i##x++) { for(int j##x = 0; j##x < x; j##x++) { cin >> field[i##x][j##x]; } }
#define OUTPUT2(x, y, field) cout << "---count---" << endl << x << " " << y << endl <<"---content---" << endl; for(int i##x = 0; i##x < y; i##x++) { cout << i##x << "   "; for(int j##x = 0; j##x < x; j##x++) { cout << field[i##x][j##x] << " "; } cout << endl; }

using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
    // Your code here!
    int n(0);
    cin>>n;
    cout<<(n+1)/2<<endl;
}


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


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

  if((a+b) % 2 == 0 && a != b){
    cout << (a+b)/2 <<endl;
  }else{
    cout << "IMPOSSIBLE" <<endl;
    
  }
}


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

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
const int N = 1e3+5;

ll n , x , y , z , k , a[N] , b[N] , c[N];
vector<ll> v;
priority_queue<ll> q;

bool check(ll num)
{
    ll cnt = 0 , up , rem;
    for(int i=1; i<=x; i++)
    {
        rem = num - a[i]; //m7tag kam 3shan ab2a num
        up = upper_bound(v.begin() , v.end() , rem-1) - v.begin(); //3dd el as8ar
        up = v.size() - up;
        cnt += up;
    }

    return cnt >= k;
}

void solve(ll val)
{
    for(int i=1; i<=x; i++)
    {
        int j=(int)v.size()-1;
        while(j>=0 && k>=0 && a[i]+v[j] > val)
        {
            k--;
            q.push(a[i]+v[j]);
            j--;
        }
    }
    while(k>0) q.push(val) , k--;
}

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

    cin >> x >> y >> z >> k;
    for(int i=1; i<=x; i++)
    {
        cin >> a[i];
    }

    sort(a+1 , a+x+1);
    for(int i=1; i<=y; i++)
        cin >> b[i];
    for(int i=1; i<=z; i++)
        cin >> c[i];

    for(int i=1; i<=y; i++)
    {
        for(int j=1; j<=z; j++)
        {
            v.push_back( (b[i]+c[j]) );
        }
    }

    sort(v.begin() , v.end());

    ll l = 1 , h = 1e14 , mid , idx = -1;
    while(l<=h)
    {
        mid = (l+h)/2;
        if (check(mid))
        {
            idx = max(idx , mid);
            l = mid+1;
        }
        else h=mid-1;
    }

    solve(idx);

    while(q.size())
    {
        cout << q.top() << "\n";
        q.pop();
    }

    return 0;
}

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

int main(){
    ll n;
    cin>>n;
    ll a[5]={0};
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(s[0]=='M')a[0]++;
        else if(s[0]=='A')a[1]++;
        else if(s[0]=='R')a[2]++;
        else if(s[0]=='C')a[3]++;
        else if(s[0]=='H')a[4]++;
    }
    sort(a,a+5);
    ll res=0;
    res+=a[4]*a[3]*a[2];
    res+=a[4]*a[3]*a[1];
    res+=a[4]*a[3]*a[0];
    res+=a[4]*a[2]*a[1];
    res+=a[4]*a[2]*a[0];
    res+=a[4]*a[1]*a[0];
    res+=a[3]*a[2]*a[1];
    res+=a[3]*a[2]*a[0];
    res+=a[3]*a[1]*a[0];
    res+=a[2]*a[1]*a[0];
    cout<<res;
    
    
}    

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

int main(void)
{
	int te[5];
	set<int> check;
	while(cin>>te[0]){
		if(!te[0]) break;
		check.clear();
		for(int i=1; i< 5; i++){
			cin >> te[i];
		}
		for(int i=0; i<5; i++){
			check.insert(te[i]);
		}
		int tmp = 0;
		if(check.size()==2){
			if(check.find(1) == check.end()){
				tmp = -1;
			}else if(check.find(2) == check.end()){
				tmp = -2;
			}
			for(int i=0;i<5;i++){
				if(te[i]+tmp==1){
					cout << "1" << endl;
				}else{
					cout << "2" << endl;
				}
			}
			
		}else{
			for(int i=0;i<5; i++){
				cout <<"3"<< endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
S = input()
if int(S[:2]) <= 12 and int(S[:2]) >= 1:
  if int(S[2:]) <= 12 and int(S[2:]) >= 1:
    print("AMBIGUOUS")
  else:
    print("MMYY")
elif int(S[2:]) <= 12 and int(S[2:])>= 1:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
    int W, H, N;
    cin >> W >> H >> N;
    vector<int> res(4);
    res[0] = 0;
    res[1] = 0;
    res[2] = W;
    res[3] = H;
    rep(i, N)
    {
        int x, y, a;
        cin >> x >> y >> a;
        switch (a)
        {
        case 1:
            if (res[0] < x)
                res[0] = x;
            break;
        case 2:
            if (res[2] > x)
                res[2] = x;
            break;
        case 3:
            if (res[1] < y)
                res[1] = y;
            break;
        case 4:
            if (res[3] > y)
                res[3] = y;
            break;
        }
    }
    int result = (res[2] - res[0]) * (res[3] - res[1]);
    if (res[2] - res[0] < 0 || res[3] - res[1] < 0)
        result = 0;
    cout << result << endl;
}


Measured memory_bytes: 256
S = gets.chomp
# S = 'eraser' * (10**4)
T_SUBS = %w(dream dreamer erase eraser).freeze

# stack level too deep
# def rec(t_candidate)
#   T_SUBS.each do |t_sub|
#     t_new = t_candidate + t_sub
#     if t_new == S
#       puts 'YES'
#       exit
#     end
#     rec(t_new) if S.start_with?(t_new)
#   end
# end
#
# rec('')
# puts 'NO'

def run_step(candidates)
  news = []
  candidates.each do |candidate|
    T_SUBS.each do |t_sub|
      new = candidate + t_sub
      news.push(new) if S.start_with?(new)
    end
  end
  news
end

candidates = ['']
until candidates.empty?
  candidates = run_step(candidates)
  if candidates.any? { |c| c == S }
    puts 'YES'
    exit
  end
end

puts 'NO'


Measured memory_bytes: 102216
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll a[1001][1001],sum[1001][1001];
int main(){
    int n,m,q;
    cin>>n>>m>>q;
    int li,ri;
    rep(i,m){
        cin>>li>>ri;
        ++a[ri][li];
    }
    rep(i,505)rep(j,505){
        sum[i+1][j+1]+=a[i+1][j+1]+sum[i][j+1]+sum[i+1][j]-sum[i][j];
    }
    int pi,qi;
    rep(i,q){
        cin>>pi>>qi;
        cout<<sum[qi][qi]-sum[qi][pi-1]-sum[pi-1][qi]+sum[pi-1][pi-1]<<endl;
    }
    return 0;
}


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

ll x, y, z, k;
ll a[1024], b[1024], c[1024];

int main(){
  cin >> x >> y >> z >> k;
  for(int i=0;i<x;i++) cin >> a[i];
  for(int i=0;i<y;i++) cin >> b[i];
  for(int i=0;i<z;i++) cin >> c[i];
  vector<ll> ab;
  for(int i=0;i<x;i++)for(int j=0;j<y;j++) ab.push_back(-a[i] - b[j]);
  sort(ab.begin(), ab.end());
  
  vector<ll> abc;
  for(int i=0;i<min(k, x*y);i++)for(int j=0;j<z;j++) abc.push_back(ab[i] - c[j]);
  sort(abc.begin(), abc.end());
  
  for(int i=0;i<k;i++) cout << -abc[i] << endl;
  
  return 0;
}
  
  

Measured memory_bytes: 43364
#include <bits/stdc++.h>
using namespace std;
#define dump(X) cout << #X << ' ' << X << endl
#define pe(X) cout << X << endl
typedef long long ll;
int n;
string s[1010];
int idx[1010];
bool solve(){
	cin >> n;
	if(!n)return false;
	for(int i=0;i<n;i++)cin >> s[i];
	for(int i=0;i<n;i++){
		idx[i]=-1;
		for(int j=0;j<s[i].size();j++){
			if(s[i][j]!='.')break;
			if(s[i][j+1]!='.'){
				s[i][j]='+';
				idx[i]=j;
				int pre=-1;
				for(int k=i-1;k>=0;k--){
					if(idx[k]<idx[i]){
						break;
					}
					if(idx[k]==idx[i]){
						pre = k;
						break;
					}
				}
				if(pre!=-1){
					for(int k=pre+1;k<i;k++){
						s[k][j]='|';
					}
				}
				break;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<idx[i];j++){
			if(s[i][j]=='.')s[i][j]=' ';
		}
	}
	for(int i=0;i<n;i++){
		cout << s[i] << endl;
	}
	return true;
}

int main(){
	while(solve()){}
	return 0;
}



Measured memory_bytes: 3824
n = int(input())
a = list(map(int, input().split()))
ans = -1
bool = True
while bool:
    for i in range(n):
        if a[i] % 2 != 0:
            bool = False
            break
        else:
            a[i] = a[i]//2
    ans += 1
print(ans)


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

int GCD(int x,int y){
  if(y == 0) return x;
  return GCD(y,x%y);
}

int main() {
  int a;
  ll ans = 0;
  cin >> a;
  for(int i = 1;i <= a;i++){
    for(int j = 1;j <= a;j++){
      for(int k = 1;k <= a;k++){
        int g = GCD(i,j);
        int gg = GCD(g,k);
        ans += gg;
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
  long long l,r;
  cin >> l >> r;
  r = min(r,l+4038);
  int ans = 2018;
  for(long long i = l;i <= r;i++){
    for(long long j = i+1;j <= r;j++){
      int x = (i*j)%2019;
      ans = min(ans,x);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int x, y, s;


signed main(){
    while(cin >> x >> y >> s, x+y+s > 0){
        int ans = 0;
        rep(i, 1, s) rep(j, 1, s){
            int a = i*(100+x)/100;
            int b = j*(100+x)/100;
            if(a+b != s) continue;
            a = i*(100+y)/100;
            b = j*(100+y)/100;
            chmax(ans, a+b);
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3084
use std::io;
use std::str::FromStr;

type Pair = (u64, u64);

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (n, m) = input_tuple();
    let mut stores: Vec<Pair> = Vec::new();
    for _ in 0..n {
        let store = input_tuple();
        stores.push(store);
    }
    stores.sort_by(|x, y| x.0.cmp(&y.0));
    let mut sum = 0;
    let mut ans = 0;
    // println!("{:?}", stores);
    for store in stores {
        // println!("{}", sum);
        if store.1 + sum > m {
            ans += store.0 * (m - sum);
            break;
        } else if store.1 + sum == m {
            ans += store.0 * store.1;
            break;
        } else {
            ans += store.0 * store.1;
            sum += store.1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n;
	cin >> n;
	if (n <= 999) cout << "ABC\n";
	else cout << "ABD\n";

	return 0;
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

type Edge struct {
	from, to, cost int
}

type Route struct {
	path []int
}

// ベルマンフォード法
func bellmanFord(N, P, S, E int, edges []Edge) ([]int, bool) {
	d := make([]int, N+1)
	for i := 0; i <= N; i++ {
		d[i] = math.MaxInt64
	}
	d[S] = 0
	for i := 0; i < N-1; i++ {
		for _, e := range edges {
			if d[e.from] != math.MaxInt64 &&
				d[e.to] > d[e.from]+e.cost {
				d[e.to] = d[e.from] + e.cost
			}
		}
	}

	negative := make([]bool, N+1)
	for i := 0; i < N; i++ {
		for _, e := range edges {
			if d[e.from] != math.MaxInt64 &&
				d[e.to] > d[e.from]+e.cost {
				d[e.to] = d[e.from] + e.cost
				negative[e.to] = true
			}
			negative[e.to] = negative[e.to] || negative[e.from]
		}
	}

	return d, negative[E]
}

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

	N, M, P := getInt(), getInt(), getInt()
	edges := make([]Edge, M)
	for i := 0; i < M; i++ {
		f, t, c := getInt(), getInt(), getInt()
		edges[i] = Edge{f, t, -c + P}
	}

	// out(edges)
	// ここから
	d, negativeLoop := bellmanFord(N, P, 1, N, edges)

	if negativeLoop {
		out(-1)
	} else {
		out(max(0, -d[N]))
	}
}


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

"""

input:
5 4
0 1
1 2
2 3
3 4

output:
1
2
3
"""

import sys

sys.setrecursionlimit(int(3e6))
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        source, target = map(int, v_detail)
        init_adj_table[source].append(target)
        init_adj_table[target].append(source)
    return init_adj_table


def graph_dfs(current, prev):
    global timer
    pre_v[current] = lowest_v[current] = timer
    timer += 1

    color[current] = VISITED_IN_STACK
    for adj in adj_table[current]:
        if color[adj] is UNVISITED:
            parent_v[adj] = current
            # recursive dfs
            graph_dfs(adj, current)
            lowest_v[current] = min(lowest_v[current], lowest_v[adj])
        elif adj is not prev:
            lowest_v[current] = min(lowest_v[current], pre_v[adj])

    return None


def art_points():
    graph_dfs(root, -1)

    np = 0
    for v in range(1, vertices):
        parent = parent_v[v]
        if parent is root:
            np += 1
        elif pre_v[parent] <= lowest_v[v]:
            art_set.add(parent)

    if np > 1:
        art_set.add(root)

    return art_set


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])
    pre_v, parent_v, lowest_v = ([float('inf')] * vertices for _ in range(3))
    init_adj_table = tuple([] for _ in range(vertices))
    adj_table = generate_adj_table(v_info)

    timer = 0
    root = 0
    art_set = set()
    color = [UNVISITED] * vertices

    res = art_points()
    if res:
        print(*sorted(res), sep='\n')

Measured memory_bytes: 23732
#include "stdio.h"

int Q, N, C;
int ans;
int num;
bool flag[128];

int main() {
	scanf("%d", &Q);
	for (int i = 0; i < Q; i++) {
		scanf("%d %d", &N, &C);
		ans = 127*(N-1);
		if (N % 2 == 0)ans += 127 - C;
		else ans += C;
		printf("%d\n", ans);
	}
	return 0;
}

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

int main(void)
{
	string s;

	cin >> s;

	if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
using namespace std;

main {
  string s;
  stack<int> a;
  while (cin >> s) {
    if (s == "+") {
      int r = a.top();
      a.pop();
      int l = a.top();
      a.pop();
      a.push(l + r);
      continue;
    }
    if (s == "-") {
      int r = a.top();
      a.pop();
      int l = a.top();
      a.pop();
      a.push(l - r);
      continue;
    }
    if (s == "*") {
      int r = a.top();
      a.pop();
      int l = a.top();
      a.pop();
      a.push(l * r);
      continue;
    }
    a.push(stoi(s));
  }
  cout << a.top() << endl;
}

Measured memory_bytes: 3184
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto s = readln.chomp;
  auto rn = s.count('0');
  auto bn = s.count('1');
  writeln(min(rn, bn) * 2);
}


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

const int len = 32;

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

  if (N == 0) {
    cout << '0' << endl;
    return 0;
  }

  ll acc_u = 0, acc_l = 0;
  vector<ll> b(len), u(len), l(len);
  rep(i, len) {
    ll n = ll(1) << i;
    b[i] = (i % 2 == 0) ? n : -n;
    if (i % 2 == 0)
      acc_u += b[i];
    else
      acc_l += b[i];
    u[i] = acc_u;
    l[i] = acc_l;
  }

  ll num = N;
  vector<int> bits(len);
  for (int i = len - 1; i > 0; i--) {
    if (l[i - 1] > num || num > u[i - 1]) {
      bits[i] = true;
      num -= b[i];
    }
  }
  if (num == 1)
    bits[0] = true;

  bool print = false;
  rep(i, len) {
    bool on = bits[len - i - 1];
    if (on)
      print = true;
    if (print)
      cout << (on ? '1' : '0');
  }
  cout << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<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()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut ans: usize = 0;
    for i in 1..=n {
        for j in (i..=n).step_by(i) {
            ans += j;
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 2176
#include<stdio.h>
  int main(){
    char str[200];
    int i=0,s=0,length,half;

    scanf("%d",&length);
    scanf("%s",str);
    half=length/2;
    
    if(length%2==0){

    while(i<half){
      if(str[i]==str[half+i]){
        i++;
      }
      else{
        s++;
        printf("No\n");
        break;
      }
    }
    if(s==0){
     printf("Yes\n");
    }
    }
else{
printf("No\n");
}
    return 0;
  }


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

n = int(input())
s = []
for i in range(2):
    for j in range(n):
        a = int(input())
        s.append((a, i))
s.sort()

ans = 1
l = []
cur = None
for num, c in s:
    if not l:
        l.append(s[i])
        cur = c
    elif c == cur:
        l.append(num)
    else:
        ans *= len(l)
        ans %= mod
        l.pop()
print(ans)

Measured memory_bytes: 76248
#関数リスト
import sys
input = sys.stdin.readline
from collections import defaultdict, deque

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    h, w, k = MI()
    x1, y1, x2, y2 = MI()
    x1 -= 1
    y1 -= 1
    x2 -= 1
    y2 -= 1

    mylist = [0] * h

    #tableの読み込み
    for i in range(h):
        temp = input().rstrip()
        temp = [temp[j] for j in range(w)]
        mylist[i] = temp
    #初期化
    distance = [[-1 for i in range(w)] for j in range(h)]
    distance[x1][y1] = 0
    d = deque()
    start = (x1, y1)
    goal = [x2, y2]
    d.append(start)
    move = ([-1,0],[1,0],[0,1],[0,-1])

    while d:
        pos = d.popleft()
        x = pos[0]
        y = pos[1]
        if x == x2 and y == y2:
            print(distance[x2][y2])
            exit()
        dist = distance[x][y]
        for i in move:
            #tempxの初期化
            tempx = x
            tempy = y
            for l in range(k):
                tempx += i[0]
                tempy += i[1]
                if not ((tempx >= 0 and tempx <= h-1) and (tempy >= 0 and tempy <= w - 1)):
                    break
                elif mylist[tempx][tempy] == "." and distance[tempx][tempy] == -1:
                    distance[tempx][tempy] = dist + 1
                    d.append((tempx, tempy))
                elif dist + 1 <= distance[tempx][tempy] and mylist[tempx][tempy] == ".":
                    distance[tempx][tempy] = dist + 1
                else:
                    break
    print(-1)            
        
main()


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

int main(){
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<k;i++)
		ans+=a[i];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int c[5];
int main(){
	int a,b;
	rep(i,3){
		cin>>a>>b;
		c[a]++;c[b]++;
	}
	bool flg=true;
	rep(i,5)
		flg &= c[i]<=2;
	if (flg)
		cout <<"YES"<<endl;
	else
		cout <<"NO"<<endl;
}

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

int main() {
  
  double A,B;
  cin >> A >> B ;
  
  int form = min(A,B); ///繰り返しの範囲を求める。
  int Pf = 1; ///素因数を蓄積する。
  
  for(int i=2; i<=form; i++){
    
    ///
    int An = A/i;
    double Ad =A/i;
    int Bn = B/i;
    double Bd = B/i;
    ///それぞれiで割った時のintとdoubleの値を出す。比較用。
    
    if(An==Ad && Bn==Bd){///A,Bがそれぞれiで割れるという条件
      A/=i;
      B/=i;
      Pf*=i;
      i=1;///iを2に戻して再スタート
    }
    
  }
  
  int64_t Ans = A*B*Pf;///最小公倍数を求める公式
  
  cout << Ans << endl;
  
      
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr char sp = ' ';

int K;
string S;

string next(string T) {
	bool f = false;
	for (char c : T) {
		if (c != '9') {
			f = true;
		}
	}
	if (!f) {
		T.push_back('0');
		for (char &c : T) {
			c = '0';
		}
		T[0] = '1';
	}
	else {
		for (int i = T.size() - 1; i >= 0; i--) {
			if (T[i] != '9'&&(i==0||T[i - 1] - T[i] >= 0)) {
				T[i]++;
				for (int j = i + 1; j < T.size(); j++) {
					T[j] = max('0', char(T[j - 1] - 1));
				}
				break;
			}
		}
	}
	return T;
}

int main() {
	cin >> K;
	S = "1";
	for (int i = 1; i < K; i++) {
		S = next(S);
	}
	cout << S << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n,x;
    scanf("%d",&n);
 
    for(int i = 1; i<= n; i++)
    {
        if(i%3 == 0){
            printf(" %d",i);
        }else{
            x = i;
            do{
                if(x%10 == 3){
                    printf(" %d",i);
                    break;
                }
                x /=10;
            }while(x);
        }
    }
    printf("\n");
}


Measured memory_bytes: 2740
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int flag=0;
    string s;
    cin>>s;
    if(s.size()==1)
    {
    	printf("-1 -1\n");
    	return 0;
	}
    for(int i=0;i<s.size()-1;i++)
    {
        if(s[i]==s[i+1])
        {
            printf("%d %d\n",i+1,i+2);
            flag=1;
            break;
        }
        else if(i<s.size()-2&&s[i]==s[i+2])
        {
            printf("%d %d\n",i+1,i+3);
            flag=1;
            break;
        }
    }
    if(!flag)
    printf("-1 -1\n");
    return 0;    
}

Measured memory_bytes: 512
X,Y,Z,K = map(int, input().split())
cakes = [list(map(int, input().split())) for _ in range(3)]
 
cakes = list(map(lambda x : sorted(x, reverse=True), cakes))
ans = list()
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1)>K:
                break
            ans.append(cakes[0][i] + cakes[1][j] + cakes[2][k])
ans.sort(reverse=True)
print("\n".join(map(str, ans[:K])))


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

int main(){
  int N, M;
  int max = 0;
  cin >> N;
  vector<string> s(N);
  for(int i = 0; i < N; i++){
    cin >> s[i];
  }
  cin >> M;
  vector<string> t(M);
  for(int i = 0; i < M; i++){
    cin >> t[i];
  }
  for(int i = 0; i < N; i++){
    int x = 0;
    for(int j = 0; j < N; j++){
      if(s[i] == s[j]){
        x++;
      }
    }
    for(int j = 0; j < M; j++){
      if(s[i] == t[j]){
        x--;
      }
    }
    if(max <= x){
      max = x;
    }
  }
  if(max <= 0){
    cout << '0' << endl;
  }
  else{
    cout << max << endl;
  }
}
      
      


Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func calcSeq(n int, ints []int) []int {
	aInts := make([]int, n+1)
	for i := 1; i < n+1; i++ {
		aInts[i] = min(ints[i], ints[i-1])
	}
	return aInts[1:]
}

func sum(ints []int) (sum int) {
	for _, i := range ints {
		sum += i
	}
	return
}

func min(l, r int) int {
	if l > r {
		return r
	}
	return l
}

func main() {
	/*
		// A: X1, X2, X3
		// A: 10,  2, 2
		// B: 10,  2

		// A: X1, X2, X3, X4
		// A: 10, 10,  8, 8
		// B: 10, 15,  8

		// A:     , X1, X2, X3,  X4
		// A:     , 10, 10, 15,  20
		// B: (10), 10, 15, 20, (20)
		// () is dummy
		// ai = min(bi, bi-1)
	*/
	n := nextInt()
	ints := make([]int, n+1)
	// index: 0, [1, 2, ... , n-1], n
	for i := 1; i < n; i++ {
		ints[i] = nextInt()
	}
	// dummy
	ints[0] = ints[1]
	ints[n] = ints[n-1]
	fmt.Println(sum(calcSeq(n, ints)))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll ans=1;
  if(n==1) ans=m;
  for(ll i=2; i*i<=m; i++) {
    if(m%i==0) {
      ll x=m,c=0;
      while(x%i==0) {
        x/=i;
        c++;
      }
      if(c>=n) ans=max(ans,i);
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main() {
	int x; cin >> x;
	if (x % 7 == 0) cout << "thu" << endl;
	if (x % 7 == 1) cout << "fri" << endl;
	if (x % 7 == 2) cout << "sat" << endl;
	if (x % 7 == 3) cout << "sun" << endl;
	if (x % 7 == 4) cout << "mon" << endl;
	if (x % 7 == 5) cout << "tue" << endl;
	if (x % 7 == 6) cout << "wed" << endl;
	return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   int i, a[ ]= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
      while (cin>>i){
     cout<<a[i-1]<<endl;
      }

}



Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <unistd.h>
#include <bits/stdc++.h>

#define pii pair<int,int>
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

using Graph = vector<vector<int>>;

typedef long long ll;
static const ll INF = 1000000000000000000LL;
const int MAX = 2100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
//経路
//コンビネーション
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    int r1,r2,c1,c2;
    cin >> r1 >> c1 >> r2 >> c2;

    COMinit();

    ll res = 0;
    for(int i = c1; i <= c2; ++i)
    {
        ll tmp;
        tmp = COM(r2+i+1,i+1) - COM(r1+i,i+1);
        if(tmp < 0)tmp += MOD;
        tmp %= MOD;
        res += tmp;
        res %= MOD;
    }

    cout << res << endl;

    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    int pre = 0;
    int cnt = 0;
    for(int i = 0; i < N; i++)
    {
        int h;
        cin >> h;
        if(h > pre) cnt += h - pre;
        pre = h;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    string a, b; cin >> a >> b;

    bool ok = false;
    rep(_, 2){
        if(_ == 1) a = a.substr(1);

        auto check = [&]{
            int alen = a.size(), blen = b.size();
            int idx = 0;
            rep(i, alen){
                if(i % 2 == 1) continue;

                bool ok = false;
                rep(j, idx, blen){
                    if(b[j] == a[i]){
                        idx = j + 1;
                        ok = true;
                        break;
                    }
                }
                if(not ok) return false;
            }
            return true;
        };
        ok |= check();
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }



vi mts { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };


void solve(int N, int M, vi& a) {
    vi u(8, -1);
    rep(i,M){
        int m = mts[ a[i] ];
        amax(u[m], a[i]);
    }

    vvi dp(N+10, vi(10, -1));
    dp[0] = vi(10, 0);

    rep(i,N){
        for (int m=2; m<=7; ++m) {
            if (u[m] == -1) continue;
            int p = 1 + (9 - u[m]);
            dp[i][0]++;
            dp[i][p]++;
            dp[i+m] = max(dp[i+m], dp[i]);
            dp[i][0]--;
            dp[i][p]--;
        }
    }
    for (int n=9; n>=1; --n) {
        rep(j, dp[N][1+9-n]) putchar('0'+n);
    }
    putchar('\n');
}

int main() {
    int N, M; cin >> N >> M;
    vi a(M);
    rep(i,M) cin >> a[i];
    solve(N,M,a);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;



int main() {
	string s;
	cin >> s;
	bool alf[26];
	bool check = false;
	for (int i = 0; i < 26; i++) alf[i] = false;

	for (int i = 0; i < s.length(); i++) {
		for (int j = 0; j < 26; j++) {
			if (s[i] == 'a' + j) alf[j] = true;
		}

	}

	for (int i = 0; i < 26; i++) {
		if (alf[i] == false) {
			cout << (char)('a' + i) << endl;
			check = true;
			break;
		}

	}
	if (check == false) cout << "None" << endl;
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>

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

int main() {
    string t, ans; 

    cin >> t;

    if (t == "Sunny") ans = "Cloudy";
    if (t == "Cloudy") ans = "Rainy";
    if (t == "Rainy") ans = "Sunny";
    

    cout << ans << endl;
}



Measured memory_bytes: 256
import itertools

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())

f = factorization(n)

#print(f)

if len(f) == 1 and f[0][1] == 1:
    print(len(str(n)))
else:
    pf = []
    for r in f:
        if r[0] == 1:
            continue
        pf += [r[0]]*r[1]
    ans = len(str(n))
    for i in range(1,len(pf)//2+1):
        for c in itertools.combinations(pf, i):
            #print(c)
            tmp = 1
            for t in c:
                tmp *= t
            ans = min(ans, max(len(str(tmp)), len(str(n//tmp))))
    print(ans)

Measured memory_bytes: 9028
import itertools
q = int(input())
left = []
right = []
for _ in range(q):
    l, r = map(int, input().split())
    left.append(l)
    right.append(r)

def check(n):
    root = int(n ** 0.5)
    if n == 1:
        return False
    elif n == 2:
        return True
    for i in range(2, root + 2):
        if n % i == 0:
            return False
    return True

upper = max(right)
f = [0, 0]
for i in range(3, upper + 1):
    if i % 2 == 0:
        f.append(0)
    elif check(i) and check((i + 1) // 2):
        f.append(1)
    else:
        f.append(0)
cumsum = list(itertools.accumulate(f))
for l, r in zip(left, right):
    if l == 1:
        print(cumsum[r - 1])
    else:
        print(cumsum[r - 1] - cumsum[l - 2])

Measured memory_bytes: 15656