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

using namespace std;

bool dp[8002][8002] = {};

inline int abs(int x) {
  return(x>0?x:-x);
}

bool solve(vector<int> &v, int x){
  size_t vn = v.size();
  
  for (int i=0;i<vn;i++) {
    for (int j=0;j<8002;j++) {
      if (dp[i][j]) {
	dp[i+1][j+v[i]] = true;
	dp[i+1][abs(j-v[i])] = true;
      }
    }
  }
  return(dp[vn][abs(x)]);
}

int main(){
  vector<int> vert, horiz;
  bool direc_horiz = true;
  size_t n;
  string s;
  int x, y;
  cin >> s;
  cin >> x >> y;
  n = s.size();
  int one_step_length = 0;
  int i=0;
  while (s[i] == 'F' && i < n) {
    one_step_length++;
    i++;
  }
  x -= one_step_length;
  one_step_length = 0;
  for (;i<n;i++) {
    if (s[i] == 'F') {
      one_step_length++;
    } else {
      if (direc_horiz) {
	horiz.push_back(one_step_length);
      } else {
	vert.push_back(one_step_length);
      }
      direc_horiz = !direc_horiz;
      one_step_length = 0;
    }
  }

  if (one_step_length > 0) {
    if (direc_horiz) {
      horiz.push_back(one_step_length);
    } else {
      vert.push_back(one_step_length);
    }
    one_step_length = 0;
  }
  for (int i=0;i<8002;i++) {
    for (int j=0;j<8002;j++) {
      dp[i][j] = false;
    }
  }
  dp[0][0] = true;
  bool x_goal = solve(horiz, x);
  for (int i=0;i<8002;i++) {
    for (int j=0;j<8002;j++) {
      dp[i][j] = false;
    }
  }
  dp[0][0] = true;
  bool y_goal = solve(vert, y);
  // cout << x << "\t" << y << endl;
  // for (auto it = horiz.begin();it != horiz.end();it++) {
  //   cout << *it << "\t";
  // }
  // cout << endl;
  // for (auto it = vert.begin();it != vert.end();it++) {
  //   cout << *it << "\t";
  // }
  // cout << endl;
  if (x_goal && y_goal) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return(0);
}


Measured memory_bytes: 62848
#include <bits/stdc++.h>
using namespace std;
 
int main() {

	int N,R=0,L=0,work=0;
	cin >> N;
	vector<int> A(N);
	for (int i=0; i<N; i++){
		cin >> A.at(i);
		L += A.at(i);
	}	
	
	for (int i=0; i<N-1; i++) {
		for (int j=0; j<N-1-i; j++){
			if (A.at(j) > A.at(j+1)){
				work = A.at(j);
				A.at(j) = A.at(j+1);
				A.at(j+1) = work;
			}
		}
	}
	for (int i=(N-1) % 2; i<N; i +=2){
		R += A.at(i);
	}
	cout << R*2-L << endl;
	
}

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

class Main{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        String[] str = s.split(" ");
        int x=0;
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        int c = Integer.parseInt(str[2]);
        //System.out.println(a+" " + b +" "+ c);
        
        if(!(a<1 || a>10000) || (b<1 && b>10000) || (c<1 && c>10000) || (a>b)){
            for(; a<=b; a++){
                //System.out.println(a);
                if(c % a == 0){
                    x++;
                }
            }
            System.out.println(x);
        }
    }
}

Measured memory_bytes: 17092
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair< int, int > 
#define ff first
#define ss second

int32_t main() {
	int h, w, m;
	cin >> h >> w >> m;
	map < pi, int > mp;
	map < int, int > r,c;
	int max_r  = 0, max_c = 0;
	int id_r = 0, id_c = 0;
	for(int i = 0, u,v ; i < m; i++) {
		cin >> u >> v;
		mp[{u,v}]++;
		r[u]++;
		if(r[u] > max_r) {
			max_r = r[u];
			id_r = u;
		}
		c[v]++;
		if(c[v] > max_c) {
			max_c = c[v];
			id_c = v;
		}
	}

	int ans = 0;
	for(auto p : r) 
		ans = max(ans , p.ss + max_c - mp[{p.ff,id_c}]);
	for(auto p : c)
		ans = max(ans , p.ss + max_r - mp[{id_r, p.ff}]);
	cout << ans << endl;
}

Measured memory_bytes: 97368
main :: IO ()
main = do
    {--
        # 入力
            r <- readLn -- 入力が一行に一文字の場合
            as <- map read . words <$> getLine -- 一行に入力が複数ある場合


        # Solver
            putStrLn $ show $ solve a b -- solveの返り値がString型の場合
            putStrLn $ solve a b

    --}

    as <- map read . words <$> getLine -- 一行に入力が複数ある場合

    putStrLn $ show $ solve as -- showの返り値がString型の場合



solve :: [Int] -> Int
solve [n, i] = if n `mod` i == 0
                  then 0
                  else 1


{-- その他 備忘録
    # 型変換
       int 2 float: fromIntegral
       float 2 int: round 四捨五入
                    floor 床関数
                    ceiling 天井関数
       int 2 string: show

    # モジュール
        Data.List: sort
--}


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    string s; cin >> s;
    int k; cin >> k;
    vector<string> vec;
    for(int i = 0; i < s.size(); ++i){
        for(int j = 1; j <= k; ++j){
            string tmp = s.substr(i,j);//初め,文字数
            vec.push_back(tmp);
        }
    }
    sort(ALL(vec));
    vec.erase(unique(ALL(vec)),vec.end());
    cout << vec[k-1] << endl;
    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

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

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	vector<llong> p;

	cin >> N;
	p.resize(N);
	for(int i = 0; i < N; i++)
		cin >> p[i];

	vector<llong> a(N), b(N);
	llong one = 1e9/(N+1);
	for(int i = 0; i < N; i++){
		a[i] = (i+1)*one;
		b[i] = (N-i)*one;
	}

	for(int i = 0; i < N; i++){
		a[p[i]-1] += i;
	}

	// cerr << endl;
	// for(int i = 0; i < N; i++)
	// 	cerr << a[i]+b[i] << " ";
	// cerr << endl << endl;

	for(auto x : a)
		cout << x << " ";
	cout << endl;
	for(auto x : b)
		cout << x << " ";
	cout << endl;

	return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<stdlib.h>
int comp(const void *a,const void *b){return *(int*)b - *(int*)a;}
int main(){
  int k,n,i,j,l,s=0,ans=0;
  int a[200000]={};
  scanf("%d %d", &n, &k);
  for(i=0;i<n;i++){
    scanf("%d", &l);
    if(a[l]==0)s++;
    a[l]++;
  }
  qsort(a,sizeof(a)/sizeof(int),sizeof(int),comp);
  for(i=s-1;i>k-1;i--)ans+=a[i];
  printf("%d\n",ans);
  return 0;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	inline int tc()
	{
		int c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		return c;
	}
}
using ae86::ty;
using ae86::tc;

const int _ = 503;

int H,W,val[_][_]={0},va[_][_],vb[_][_];

int main()
{
	H=ty(),W=ty();
	for(int i=1;i<=H;i++)
		for(int j=1;j<=W;j++)
			val[i][j]=tc()=='#',va[i][j]=1,vb[i][j]=val[i][j];

	for(int i=2;i<=H;i+=2)
	{
		for(int j=2;j<=W;j++)if(!val[i][j])va[i][j]=0,vb[i][j]=1;
		va[i+1][W]=0,vb[i+1][W]=1;
	}

	for(int i=1;i<=H;i++,puts(""))
		for(int j=1;j<=W;j++)putchar(".#"[va[i][j]]);
	puts("");
	for(int i=1;i<=H;i++,puts(""))
		for(int j=1;j<=W;j++)putchar(".#"[vb[i][j]]);

	return 0;
}


Measured memory_bytes: 3712
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int cost[8][8]={
{   0,   0,   0,   0,   0,   0,   0,   0},
{   0,   0, 300, 500, 600, 700,1350,1650},
{   0, 300,   0, 350, 450, 600,1150,1500},
{   0, 500, 350,   0, 250, 400,1000,1350},
{   0, 600, 450, 250,   0, 250, 850,1300},
{   0, 700, 600, 400, 250,   0, 600,1150},
{   0,1350,1150,1000, 850, 600,   0, 500},
{   0,1650,1500,1350,1300,1150, 500,   0}
};

int dis[8][8]={
{ 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 6,13,18,23,43,58},
{ 0, 6, 0, 7,12,17,37,52},
{ 0,13, 7, 0, 5,10,30,45},
{ 0,18,12, 5, 0, 5,25,40},
{ 0,23,17,10, 5, 0,20,35},
{ 0,43,37,30,25,20, 0,15},
{ 0,58,52,45,40,35,15, 0}
};

int main() {
	int n1,n2,h1,h2,m1,m2;
	while(n1=in()){
		cin>>h1>>m1>>n2>>h2>>m2;
		int c=cost[n1][n2];
		int d=dis[n1][n2];
		int time1=h1*60+m1;
		int time2=h2*60+m2;
		if(d<=40&&(17*60+30<=time1&&time1<=19*60+30||17*60+30<=time2&&time2<=19*60+30)){
			c/=2;
			if(c%50){
				c+=50-c%50;
			}
		}
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    int N; cin>>N;

    vector<int> a(N),b(N);

    for (int i = 0; i < N; ++i) {
        cin>>a[i]>>b[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    if(N%2==1){
        int mini=a[N/2],maxi=b[N/2];
        cout<<maxi-mini+1<<endl;
        return;
    }else{
        int mini1=a[N/2-1],mini2=a[N/2];
        int maxi1=b[N/2-1],maxi2=b[N/2];
        cout<<(ll)maxi1-mini1+maxi2-mini2+1<<endl;
    }

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 4844
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))

    n, p = [], []
    for x in sorted(X):
        if x == 0:
            K -= 1
        elif x < 0:
            n.append(x)
        else:
            p.append(x)

    ans = INF
    n = n[::-1]
    for i in range(K + 1):
        j = K - i
        if i <= len(n) and j <= len(p):
            a, b = 0, 0
            if i > 0:
                a = abs(n[i - 1])
            if j > 0:
                b = abs(p[j - 1])
            ans = min(ans, a + b + min(a, b))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14872
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    n=n%10;
    if(n==2 || n==5 || n==4 || n==7 || n==9)
        printf("hon");
    else if(n==3)
        printf("bon");
    else
        printf("pon");
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int flag = 0;

    rep(i, 3) {
        if(s[i] == s[i+1]) {
            flag = 1;
        }
    }
    
    if(flag == 0) {
        cout << "Good";
    }
    else {
        cout << "Bad";
    }

    cout << endl;
    return 0;
}

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

using namespace std;

long long n;
long long a[100010];

long long calcDiff(int l, int r, long long lNum, long long rNum)
{
	long long totalDiff = 0;
	
	long long diffs[4];
	while (l <= r)
	{
		diffs[0] = abs(a[l] - lNum);
		diffs[1] = abs(a[l] - rNum);
		
		diffs[2] = abs(a[r] - lNum);
		diffs[3] = abs(a[r] - rNum);
		
		long long mDiff = -1;
		int maxI;
		for (int i = 0 ; i < 4 ; i++)
			if (diffs[i] > mDiff)
			{
				mDiff = diffs[i];
				maxI = i;
			}
		
		totalDiff = totalDiff + mDiff;	
			
		switch (maxI)
		{
		case 0:
			lNum = a[l];
			l++;
			break;
		case 1:
			rNum = a[l];
			l++;
			break;
		case 2:
			lNum = a[r];
			r--;
			break;
		case 3:
			rNum = a[r];
			r--;
			break;
		}
	}
	
	return totalDiff;
}

int main()
{
	scanf("%lld", &n);
	
	for (int i = 1 ; i <= n ; i++)
		scanf("%lld", &(a[i]));

	sort(a + 1, a + n + 1);
	
	int l = 1;
	int r = n;

	//first Left	
	long long lNum = a[1];
	long long rNum = a[1];
	long long curDiffA = calcDiff(2, n, a[1], a[1]);
	long long curDiffB = calcDiff(1, n - 1, a[n], a[n]);
	
	if (curDiffA > curDiffB)
		printf("%lld\n", curDiffA);
	else
		printf("%lld\n", curDiffB);
	
	return 0;
}

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

using namespace std;

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int a , b , c;
   cin >> a >> b >> c;
   if (a + b + c >= 22)
      cout << "bust" << '\n';
   else
      cout << "win" << '\n';
   return 0;
}


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

int main(){
    vector<bool> prime(1000001, true);
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i < sqrt(1000001); i++){
        if (prime[i]){
            for (int j = i * 2; j < 1000001; j += i){
                prime[j] = false;
            }
        }
    }
    while(1){
        int a, d, n;
        cin >> a >> d >> n;
        if (n == 0) break;

        int cnt = 0;
        while (1){
            if (cnt == n - 1 && prime[a]){
                cout << a << endl;
                break;
            }
            if (prime[a]) cnt++;
            a += d;
        }
    }
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
#define int long long 
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) (int)s.size()
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
const int MOD=1e9+7;
void solve()
{
fastio
int n,x,m;
cin>>n>>x>>m;
mii mp;
int last=x;
mp[last]=1;
vi v;
v.pb(last);
for(int i=2;i<=n;i++)
{
	last=(last*last)%m;
	if(mp[last])
	{
		int sum=0;
		int init=mp[last];
		for(int k=0;k<init-1;k++)
		{
			sum+=v[k];
		}
		int segment=i-init;
		int rem=n-(init-1);
		int grp=rem/segment;
		int grp_sum=0;
		for(int k=init-1;k<i-1;k++)
		grp_sum+=v[k];
		sum+=grp_sum*grp;
		int beg=init-1;
		for(int i=1;i<=(rem%segment);i++,beg++)
		sum+=v[beg];
		cout<<sum;
		return ;
	}
	else
	{
		mp[last]=i;
		v.pb(last);
	}
}
//10000000000 10 99959
int sum=0;
for(auto &x:v)
sum+=x;
cout<<sum;
}
signed main()
{
//code
fastio
int t;
t=1;
while(t--)
{
solve();
cout<<endl;
}
}


Measured memory_bytes: 6748
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<n; ++i)

int main() {
    int n;
    cin >> n;
    vector<long long> A(n);
    rep(i,n) cin >> A[i];

    vector<long long> dp(n); //prop
    dp.at(0) = 1000;
    for (int sellday=1; sellday<n; ++sellday) {
        dp.at(sellday) = max(dp.at(sellday), dp.at(sellday-1));
        for (int buyday=0; buyday<=sellday; ++buyday) {
            if (A[buyday] >= A[sellday])
                continue;
            long long property = dp.at(buyday);
            //buy
            long long stocks = property / A[buyday];
            long long remain = property % A[buyday];
            //sell
            property = A[sellday] * stocks + remain;
            dp.at(sellday) = max(dp.at(sellday), property);
        }
    }

    cout << dp.back() << endl;
    return 0;
}



Measured memory_bytes: 3152
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

string s;

bool isKaibun(ll l, ll r){
	ll n = r - l;
	rep(i, n) if(s[l + i] != s[r - 1 - i]) return false;
	return true;
}

int main(void){
	cin >> s;

	ll n = s.size();
	if(isKaibun(0, n) && isKaibun(0, (n - 1) / 2) && isKaibun((n + 3) / 2 - 1, n)) co("Yes");
	else co("No");

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    ll c[n - 1], s[n - 1], f[n - 1];
    for (int i = 0; i < n - 1; i++) cin >> c[i] >> s[i] >> f[i];
    for (int i = 0; i < n; i++) {
        ll cur = 0;
        for (int j = i; j < n - 1; j++) {
            if (cur < s[j]) {
                cur = s[j];
                cur += c[j];
            } else {
                ll t = (cur - s[j]) % f[j];
                if (t) cur += (f[j] - t);
                cur += c[j];
            }
        }
        cout << cur << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#define MN 2010

int n, m, q; 
char s[MN][MN];
int p[MN][MN], r[MN][MN], c[MN][MN]; 

int main()
{
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + s[i][j] - '0';
			r[i][j] = r[i - 1][j] + r[i][j - 1] - r[i - 1][j - 1] + (s[i][j] == '1' && s[i][j - 1] == '1');
			c[i][j] = c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1] + (s[i][j] == '1' && s[i - 1][j] == '1');
		}
	for(int i = 1; i <= q; i++)
	{
		int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
		int P = p[c][d] - p[c][b - 1] - p[a - 1][d] + p[a - 1][b - 1];
		int R = r[c][d] - r[c][b] - r[a - 1][d] + r[a - 1][b];
		int C = ::c[c][d] - ::c[c][b - 1] - ::c[a][d] + ::c[a][b - 1];
		printf("%d\n", P - R - C);
	}
	return 0;
}

Measured memory_bytes: 53120
# include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N] , res;
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
		for(int j = 1; j < i; j ++){
			res += a[j] * a[i];
		}
	}
	cout << res << "\n";
}

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

def main():
    mod=10**9+7
    H,W=MI()
    ans=0
    for i in range(H):
        s=input().split()
        if "snuke" in s:
            n=s.index("snuke")
            ans=(chr(n+97)).upper()+str(i+1)
            
    print(ans)
    

main()


Measured memory_bytes: 62056
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new java.util.Scanner(System.in);
		int count = 0;
		String W;
		ArrayList<String> Tline = new ArrayList<String>();

		W = sc.next();
		while(true) {
			String T = sc.next();
			if(T.equalsIgnoreCase(W)) {
				count++;
			}
			else if(T.equals("END_OF_TEXT")){
				break;
			}
		}
		System.out.println(count);
	}
}



Measured memory_bytes: 26300
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String s = sc.next();
		String t = sc.next();
		
		
		int d=0;
		for( int i=0 ;i<s.length() ;i++ ) {
			if( s.charAt(i) != t.charAt(i)) {
				d++;
			}
		}
		System.out.println(d);
	}

}

Measured memory_bytes: 41372
#f = open("C:/Users/naoki/Desktop/Atcoder/input.txt")
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)

select_num = N//2
inf = -10e+100

Dp_f = [[inf] * (3) for _ in range(N+1)]
Dp_s = [[inf] * (3) for _ in range(N+1)]
# 3　次元はそれぞれStart~3つに該当

pre_margin = 0
for i in range(1,N+1):
    Start = (i-1)//2
    End = (i+1)//2
    
    cur_margin = Start
    
    for j in range(Start,End+1):
        Dp_f[i][j-cur_margin] = max(Dp_s[i-1][j-pre_margin], Dp_f[i-1][j-pre_margin])   
        # [0] in 3rd dimension  not chosen at last num
        # must be transfered from [i-1]
    for j in range(Start,End+1):
        if j-1 == 0:
            Dp_s[i][j-cur_margin] = 0 + A[i]
        else:
            Dp_s[i][j-cur_margin] = Dp_f[i-1][j-1-pre_margin]+A[i]
    
    pre_margin = cur_margin
print(max(Dp_f[-1][select_num - cur_margin], Dp_s[-1][select_num - cur_margin]))


Measured memory_bytes: 169712
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//おまじない



int main() {

	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) {
		YES;
	}
	else {
		NO;
	}

	

	return 0;
}


Measured memory_bytes: 256
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, L) = (input[0], input[1])
let apples = (0..<N).map{$0+L}
let tmp = L>=0 ? apples[0] : N+L-1<0 ? apples[N-1] : 0
print(apples.reduce(0){$0+$1} - tmp)

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

int main() {
  string s1,s2;
  cin >> s1 >> s2;
  s2.erase(s2.size()-1);
  if(s1==s2){
    cout << "Yes" << endl;
  }
  
  else cout << "No" << endl;
  
}


Measured memory_bytes: 3576
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int X;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> X;
  long long lo = 0, hi = INF;
  while (hi - lo > 1) {
    long long mid = (lo + hi) / 2;
    if (mid*(mid-1) >= 2LL*X) hi = mid;
    else lo = mid;
  }
  cout << lo << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int ans=0;
  for(int i=0;i<n;i++){
    ans++;
    while(i+1<n&&a[i]==a[i+1]) i++;
    if(i==n-1) break;
    if(a[i]<a[i+1]){
      while(i+1<n&&a[i]<=a[i+1]) i++;
    }else{
      while(i+1<n&&a[i]>=a[i+1]) i++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
long long n, k, a[200000], s, ret;
int main() {
	while (true) {
		cin >> n >> k; s = 0; if (n == 0)break; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); if (i <= k)s += a[i]; }
		ret = s; for (int i = k + 1; i <= n; i++) { s -= a[i - k]; s += a[i]; ret = max(ret, s); }
		cout << ret << endl;
	}
	return 0;
}

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

using i64 = int64_t;

vector<i64> divisor(i64 n) {
    vector<i64> res;
    for (i64 i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i)
                res.push_back(n / i);
        }
    }
    return res;
}

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

    auto divisors = divisor(m);
    sort(divisors.begin(), divisors.end());
    i64 ans = 1;
    for(auto d: divisors){
        if(d < n)continue;
        ans = m / d;
        break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc140/submissions/7397810

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)

done = [False] * (1 << n)
b = [a[0]]
done[0] = True
for d in range(n):  # d: d-th trial is passed.
    j = 0  # j: skip num (already-generated or impossible-to-generate)
    for i in range(1 << d):  # Try split of i-th slim.
        while j < 1 << n and (done[j] or b[i] <= a[j]):
            j += 1
        if j == 1 << n:
            print("No")
            sys.exit(0)
        b.append(a[j])  # b[i] > a[j]
        done[j] = True
    b.sort(reverse=True)
print("Yes")


Measured memory_bytes: 34676
#include<stdio.h>
int main(){
  int Y[]={0,1,0,-1};
  int X[]={1,0,-1,0};
  int n,m,q,h,w,s,a,x[1000],y[1000],d[20][20],i,j,t,r,c[20][20];
  for(i=0;i<20*20;i++)d[i/20][i%20]=2;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)scanf("%d",&d[i+1][j+1]);
  }
  while(m--){
    scanf("%d",&q);
    if(q==0){
      scanf("%d %d %d %d",&h,&w,&s,&a);
      for(i=0;i<=s;i++){
	for(j=0;j<=s;j++){
	  if(a==  0||a==360)c[i][j]=d[h+i][w+j];
	  if(a== 90)c[i][j]=d[h+s-j-1][w  +i  ];
	  if(a==180)c[i][j]=d[h+s-i-1][w+s-j-1];
	  if(a==270)c[i][j]=d[h+  j  ][w+s-i-1];
	}
      }
      for(i=0;i<s;i++){
	for(j=0;j<s;j++)d[i+h][j+w]=c[i][j];
      }
    }
    if(q==1){
      scanf("%d %d %d",&h,&w,&s);
      for(i=0;i<s;i++){
	for(j=0;j<s;j++)d[h+i][w+j]=1-d[h+i][w+j];
      }
    }
    if(q==2){
      scanf("%d",&h);
      w=d[h][1];
      for(i=1;i<n;i++)d[h][i]=d[h][i+1];
      d[h][n]=w;
    }
    if(q==3){
      scanf("%d",&h);
      w=d[h][n];
      for(i=n-1;i;i--)d[h][i+1]=d[h][i];
      d[h][1]=w;
    }
    if(q==4){
      scanf("%d %d",&y[0],&x[0]);
      r=1;
      a=d[y[0]][x[t=0]];
      for(r=1;r-t;t++){//printf("%d %d\n",y[t],x[t]);
	for(i=0;i<4;i++){
	  if(a==d[y[t]+Y[i]][x[t]+X[i]]){
	    d[y[r]=y[t]+Y[i]][x[r]=x[t]+X[i]]=1-a;
	    r++;
	  }
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d",d[i+1][1]);
    for(j=1;j<n;j++)printf(" %d",d[i+1][j+1]);
    printf("\n");
  }
  return 0;
}
	  
      

Measured memory_bytes: 616
#!/usr/bin/env python3

from collections import defaultdict
from heapq import heappush, heappop
import sys
import numpy as np


sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x)


def solve1(D, CS, S):
    "void()"
    for i in range(D):
        print(S[i].argmax() + 1)


def solve(D, CS, S):
    "void()"
    last = [-1] * 26
    for i in range(D):
        dscore = np.zeros(26)
        for j in range(26):
            dscore[j] += S[i, j]
            dscore[j] -= sum(CS[k] * (i - last[k])
                             for k in range(26) if j != k)

        j = dscore.argmax()
        print(j + 1)
        last[j] = i


def calcScore(answer, D, CS, S):
    last = [-1] * 26
    score = 0
    for i in range(D):
        j = answer[i] - 1
        score += S[i, j]
        last[j] = i
        score -= sum(CS[j] * (i - last[j]) for j in range(26))
    return score


def main():
    D = int(input())
    CS = list(map(int, input().split()))
    S = np.int16(read().split())
    S = S.reshape((D, 26))

    # print(calcScore(answer, D, CS, S))
    solve(D, CS, S)


T = """
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
"""

OUT = """
1
17
13
14
13
"""


def _test():
    import doctest
    doctest.testmod()
    as_input(T)
    main()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 27532
import java.util.Scanner;

public class Main {

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

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int eatenChoco = 0;

		for (int i = 0; i < n; i++) {
			eatenChoco = eatenChoco + (d - 1) / a[i] + 1;
		}

		System.out.println(eatenChoco + x);

	}

}


Measured memory_bytes: 22228
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, m = gi()
l = gi()
print(sum([1 if e >= m else 0 for e in l]))

Measured memory_bytes: 52944
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b && a!=c) || (b==a && b!=c))
    {
        cout<<"Yes";
    }
    else if((a==c && a!=b) || (c==a && c!=b))
    {
        cout<<"Yes";
    }
    else if(b==c && b!=a ){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


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

using namespace std;
#define int int64_t
#define rep(i,a,n) for(int i=(a); i<(n); ++i)
#define reps(i,a,n) for(int i=(a); i<(n); --i)
#define all(x) (x).begin(),(x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed(n) fixed << setprecision(n)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
	cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n,cnt=0;
    cin>>n;

    rep(i,1,n+1){
        if(i % 15 != 0 && i % 5 != 0 && i % 3 != 0){
            cnt += i;
        }
    }

    cout<<cnt<<'\n';
    return 0;
}

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

int main(void){
	ll N,T,A,t,a;
	cin>>N>>t>>a;
	while(--N){
		cin>>T>>A;
		ll k=max(t/T+1-(t%T==0) ,a/A+1-(a%A==0));
		t=T*k;
		a=A*k;
	}
	cout<<t+a<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>sq;
  rep(i,40000)
  {
    sq.push_back(i*i);
  }
  cout<<*(upper_bound(all(sq),n)-1)<<endl;



  return 0;

}


Measured memory_bytes: 640
#include <cstdint>
#include <iostream>
#include <functional>
#include <queue>
#include <set>
#include <vector>
#include <utility>

using namespace std;

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

  vector<pair<int, int64_t>> rooms(N+1, {-1, 10000000});
  vector<vector<int>> paths(N+1);
  for (int m = 0; m < M; ++m) {
    int A, B;
    cin >> A >> B;
    if (B == 1) {
      paths[B].push_back(A);
      continue;
    }
    paths[A].push_back(B);
    paths[B].push_back(A);
  }
  rooms[1] = {0, 0};
  priority_queue<pair<int64_t, int>, vector<pair<int64_t, int>>, greater<pair<int64_t, int>>> q;
  q.push({0, 1});
  set<int> done;
  while (!q.empty()) {
    int from = q.top().second;
    q.pop();
    int64_t distance = rooms[from].second;
    for (int i = 0, size = paths[from].size(); i < size; ++i) {
      int to = paths[from][i];
      if (done.count(to)) continue;
      if (rooms[to].second > distance + 1) {
        rooms[to] = {from, distance + 1};
        q.push({distance + 1, to});
      }
    }
    done.insert(from);
  }
  cout << "Yes" << endl;
  for (int n = 2; n <= N; ++n) {
    cout << rooms[n].first << endl;
  }
  
  return 0;
}


Measured memory_bytes: 16900
import collections
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()
        K = int(input())

        if len(S) == 1:
            print(K // 2)
            exit()

        ans = 0
        start = 0
        end = len(S)
        cnt_1 = 1
        cnt_2 = 1

        if len(collections.Counter(S)) == 1:
            print((len(S) * K) // 2)
            exit()

        if S[0] == S[-1]:
            for i in range(1, len(S) - 1):
                if S[i] != S[0]:
                    start = i
                    break
                else:
                    cnt_1 += 1

            for i in range(1, len(S) - 1)[::-1]:
                if S[i] != S[0]:
                    end = i + 1
                    break
                else:
                    cnt_2 += 1

            ans += (cnt_1 // 2) + ((cnt_1 + cnt_2) // 2) * (K - 1) + (cnt_2 // 2)

        before = S[start]
        length = 1
        changes = 0
        for i in range(start + 1, end):
            if S[i] == before:
                length += 1
            else:
                changes += length // 2
                length = 1
                before = S[i]

        changes += length // 2
        ans += changes * K
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 38256
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*n

for i in range(1, n):
    c = 99999999999
    for j in range(max(0, i-k), i):
        c = min(c, dp[j]+abs(h[i]-h[j]))
        
    dp[i] = c
        
print(dp[-1])

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

int main() {
	int N;
	int flag5 = 0;
	int flag7 = 0;
	for (int i = 0;i < 3;i++) {
		cin >> N;
		if (N == 5) {
			flag5++;
		}
		else if (N == 7) {
			flag7++;
		}
	}
	if (flag5 == 2 && flag7 == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[N],k;
int cal(int m)
{
	int s=0;
	for(int i=1;i<=n;i++)
	{
		s+=(a[i]+m-1)/m-1;
		if(s>k)
			return 0;
	}
	return 1;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int l=0,r=1e9;
	while(r-l>1)
	{
		int m=l+r>>1;
		if(cal(m))
			r=m;
		else
			l=m;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 4504
#include <stdio.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
long long n,attack1,attack2;
vector<int> hp;
const long long INF=1e9;
bool check(long long x){
	long long cost=0;
	long long i;
	for(i=0;i<hp.size();i++){
		if(hp[i]-x*attack2>0){
			long long tmp=hp[i]-x*attack2;
			long long tmp2=(tmp+(attack1-attack2)-1)/(attack1-attack2);
			if(tmp>0)cost+=tmp2;
		}
	}
	//cout<<x<<":"<<cost<<endl;
	return cost<=x;
}
int main(){
	scanf("%d%d%d",&n,&attack1,&attack2);
	hp.resize(n);
	long long i;
	for(i=0;i<n;i++){
		scanf("%d",&hp[i]);
	}
	long long l=1,r=INF,ans;
	while(l<=r){
		long long mid=(l+r)>>1;
		//printf("%d %d %d\n",l,r,mid);
		if(check(mid)){
			ans=mid;
			r=mid-1;
		}
		else{
			l=mid+1;
		}
	}
	printf("%I64d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
    map<string,int> m;
    string s;
    getline(cin,s);
    string tem="";
    for(int i=0;i<s.length();i++){
        if(s[i]!=' '&&s[i]!='\n')
            tem+=s[i];
        else{
            if(m.find(tem)!=m.end()){
                (m.find(tem))->second++;
            }
            else{
                m.insert(pair<string,int>(tem,1));
            }
            tem="";
        }
    }
    if(m.find(tem)!=m.end()){
        (m.find(tem))->second++;
    }
    else{
        m.insert(pair<string,int>(tem,1));
    }
    string most,longest;
    map<string,int>::iterator it = m.begin();
    int mo=0;
    for(;it!=m.end();it++){
        if(it->first.length()>longest.length())
            longest=it->first;
        if(it->second>mo){
            most=it->first;
            mo=it->second;
        }
     //   cout<<it->first<<"    "<<it->second<<endl;
    }
    cout<<most<<" "<<longest<<endl;
    return 0;
}

Measured memory_bytes: 1188
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: RGB Cards
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int r, g, b;
  cin >> r >> g >> b;

  if ((r * 100 + g * 10 + b) % 4 == 0) puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int n,i;
    int a[1000];

    std::cin>>n;

    for(i=0;i<n;i++){
        std::cin>>a[i];
    }
    
    for(i=n-1;i>=0;i--){
        if(i==n-1){
            std::cout<<a[i];
        }else{
            std::cout<<" "<<a[i];
        }
    }
    std::cout<<std::endl;

    return 0;

}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;
const ll u=1000000000000000000;
int main(){
  ll n;
  cin>>n;
  
  ld ans=1;
  ll an=1;
  ll k;
  int c=0;
  rep(i,n){
    cin>>k;
    if(c==0||k==0){
    ans*=k;
    an*=k;
    if(ans>u){
      c++;
      
    }
    }
  }
  
  if(c==0||ans==0){
    cout<<an<<endl;
  }
  else{
    cout<<-1<<endl;
  }
}




Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var rates = Array.ConvertAll(ReadLine().Split(' '),int.Parse);
        var bet = new[] { 399, 799, 1199, 1599, 1999, 2399, 2799, 3199 };
        var set = new HashSet<int>();
        var counter = 0;
        for (var i = 0; i < num; i++)
        {
            var index = Search.LowerBound(bet, rates[i]);
            if (index >= bet.Length) counter++;
            else set.Add(index);
        }
        WriteLine($"{Max(1,set.Count)} {set.Count + counter}");
    }
}

public class Search
{
  public static int LowerBound(int[] array, int value)
    {
        var low = 0;
        var high = array.Length;
        while (high > low)
        {
            var mid = (high + low) / 2;
            if (array[mid] >= value) high = mid;
            else low = mid + 1;
        }
        return low;
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
ll f(ll n){
	if(n<=1)return 1;
	return 1+f(n/2)*2;
}

signed main(){
	//cout << fixed << setprecision(10);
	ll n;  cin>>n;
	cout<<f(n)<<endl;

	return 0;
}

Measured memory_bytes: 3608
n = gets.to_i
as = gets.split.map(&:to_i)

count = 0 # gte 3200
ans = as.each_with_object([]) do |a, arr|
  if a < 3_200
    arr << a / 400
  else
    count += 1
  end
end.uniq

min = ans.count > 0 ? ans.count : 1
max = ans.count + count

puts [min, max].join(" ")


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

#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front

typedef long long int ll;
typedef pair<int, int> ii; // are aligned to the right like this
typedef vector<ii> vii;  //vector pair
typedef vector<int> vi;   //vector integer
typedef vector<string> vs; //vector string


int main() 
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a>=0 && c>=0)
        cout<<b*d;
    else if(b<=0 && d<=0)
        cout<<a*c;
    else
    {
        if(a>=0 && d<=0)
            cout<<a*d;
        else if(b<=0 && c>=0)
            cout<<b*c;
        else 
            cout<<max(b*d,a*c);
    }      
}
 

Measured memory_bytes: 3632
import sys,queue,math,copy,itertools,bisect
from fractions import gcd
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())

N = NI()
A = LI()

A_sort = sorted(A)
A_num = [bisect.bisect_left(A_sort,a) for a in A]
ans = []
A_cnt = [0 for _ in range(N)]
cnt = 0

for i in range(N):
    bf1 = A_cnt[A_num[i]]
    bf2 = A_cnt[A_num[N-i-1]]
    A_cnt[A_num[i]] += 1
    A_cnt[A_num[N-i-1]] -= 1
    cnt += (abs(A_cnt[A_num[i]]) - abs(bf1))
    cnt += (abs(A_cnt[A_num[N-i-1]]) - abs(bf2))
    if cnt == 0:
        ans.append(i+1)

print (*ans)




Measured memory_bytes: 19412
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

vector<int> g[100000];
int t[100000], a[100000];
void tmindis(int x){
    for(int i = 0; i < g[x].size(); i++){
        int nord = g[x][i];
        if (t[nord] == -1){
            t[nord] = t[x] + 1;
            tmindis(nord);
        }
    }
    
}
void amindis(int x){
    for(int i = 0; i < g[x].size(); i++){
        int nord = g[x][i];
        if (a[nord] == -1){
            a[nord] = a[x] + 1;
            amindis(nord);
        }
    }
    
}

int main(){
    int n, u, v;
    scanf("%d %d %d", &n, &u, &v);
    
    
    for(int i = 0; i < n-1; i++){
        int e1,e2;
        scanf("%d %d", &e1, &e2);
        g[e1-1].push_back(e2-1);
        g[e2-1].push_back(e1-1);
    }

    
    fill(t, t+n, -1);
    fill(a, a+n, -1);
    t[u-1] = 0;
    a[v-1] = 0;
    tmindis(u-1);
    amindis(v-1);
    // for(int i = 0; i < n; i++){
    //     printf("%d ", t[i]);
    // }
    // puts("");
    // for(int i = 0; i < n; i++){
    //     printf("%d ", a[i]);
    // }
    // puts("");
    int node;
    int maxdis = 0;
    for(int i = 0; i < n; i++){
        if (a[i] - t[i] > 0 && a[i] > maxdis){
            maxdis = a[i];
            node = i;
        }
    }
    // printf("%d\n", node);
    int ans = a[node] - 1;
    printf("%d\n", ans);

}

Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {
	public static void main(String []args) {
		Scanner sc = new Scanner(System.in);
	      int A,B,T;
	      A = sc.nextInt();
	      B = sc.nextInt();
	      T = sc.nextInt();
	      
	      System.out.println((T/A)*B);
	}

}


Measured memory_bytes: 22736
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

vector<ll> p(51), total(51);

ll rec(ll n, ll x) {
  if (n == 0) return (x == 1) ? 1 : 0;
  
  if (x == 1) return 0;
  else if (x < total[n-1] + 2) {
    return rec(n-1, x-1);
  } else if (x == total[n-1] + 2) {
    return p[n-1] + 1;
  } else if (x < total[n]) {
    return p[n-1] + 1 + rec(n-1, x - total[n-1] - 2);
  } else {
    return p[n];
  }
}

int main() {
  ll n,x;
  cin >> n >> x;
  p[0] = 1, total[0] = 1;

  for (int i = 1; i <= 50; ++i) {
    p[i] = p[i-1] * 2 + 1;
    total[i] = total[i-1] * 2 + 3;
  }

  // cout << rec(n,x) << endl;
  printf("%lld\n", rec(n,x));
}


Measured memory_bytes: 256