akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];

            var result = Math.Min(b / a, c);

            Console.WriteLine(result);
        }

    }
}


Measured memory_bytes: 13268
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0

for i in range(n):
    for j in range(i+1, n):
        length = l[i] + l[j]

        index = bisect.bisect_left(l[j+1:], length)
        ans += index

print(ans)

Measured memory_bytes: 51676
#include <stdio.h>
#include <math.h>
 
int main() {
 
  double a,b,c;
  double S,L2, L, h;
 
  scanf("%lf %lf %lf",&a,&b,&c);
 
  S = 0.5*a*b*sin(c*3.14159265359/180);
  L2 = a*a+b*b-2*a*b*cos(c*3.1415926359/180);
  L = sqrt(L2)+a+b;
  h = 2*S/a;
 
  printf("%.11lf\n%.11lf\n%.11lf\n",S ,L,h); 
 
  return 0;
}


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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  vector<vector<int>> p(n);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    p[a].push_back(b);
    p[b].push_back(a);
  }

  queue<int> q;
  q.push(0);

  while (!empty(q)) {
    int x = q.front();
    q.pop();
    vector<int> v = p[x];
    for (auto&& e : v) {
      if (ans[e] < 0) {
      ans[e] = x + 1;
      q.push(e);
      }
    }
  }

  cout << "Yes" << endl;

  for (int i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 10428
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e6+5;
ll inf=1e15;

ll n,dp[sz][2][2];

ll f(int i,int is0,int is9){
    if(i==n){
        if(is9 and is0){
            return 1;
        }
        return 0;
    }
    ll &res=dp[i][is0][is9];
    if(res!=-1){
        return res;
    }
    res=0;
    for(int j=0;j<10;j++){
        res=(res+f(i+1,(is0|(j==0)),(is9|(j==9))))%mod;
    }

    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n;
        memset(dp,-1,sizeof(dp));
        cout<<f(0,0,0);
    }

    return 0;
}

Measured memory_bytes: 112780
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
#import numpy as np
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s, n, node):
    # 頂点が探索済みかどうかのチェック配列
    check = [False for _ in range(n)]
    check[s] = True
    # 次見る頂点を格納するキュー
    queue = deque([s])
    visited_num = 1

    # 問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color = [-1 for _ in range(n)]
    color[s] = 0

    while visited_num < n:
        # グラフが全連結ではない場合
        if len(queue) == 0:
            # 空配列を返す
            # 現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex = queue.popleft()
        # インデックスがない場合は
        for next_vertex in node[now_vertex]:

            if check[next_vertex] == True:
                continue

            queue.append(next_vertex)
            check[next_vertex] = True

            # 問題固有の計算
            color[next_vertex] = color[now_vertex]+1
            visited_num += 1

    return color


mod = 10**9+7
# n=int(input())
# n,m=list(map(int,input().split()))
# a=list(map(int,input().split()))
def ceil(x, y): return (x+y-1)//y
def input_list(): return list(map(int, input().split()))


n, m, k = list(map(int, input().split()))
t_a = list(map(int, input().split()))
t_b = list(map(int, input().split()))

a = [0]
for each in t_a:
    a.append(each+a[-1])


b = [0]
for each in t_b:
    b.append(each+b[-1])

a_ind = bisect.bisect_right(a, k)
# print(a)
# print(b)
ans = 0
for i in range(a_ind):
    zan = k-a[i]
    b_ind = bisect.bisect_right(b, zan)-1
    cal = (i+b_ind)
    ans = max(ans, cal)
    #print(i, b_ind, cal)

print(ans)


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

const int IINF = INT_MAX;
const int MAX_N = 50000;
int N,W,H,x[MAX_N],y[MAX_N],uf[MAX_N],masks[MAX_N],sz[MAX_N];
// ↑←↓→

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

void unit(int x,int y){
  x = find(x), y = find(y);
  if( x != y ) uf[x] = y;
}

int main(){
  cin >> N >> W >> H;
  rep(i,N) { 
    cin >> x[i] >> y[i];
    uf[i] = i, masks[i] = sz[i] = 0;

    if( y[i] == 1 ) masks[i] |= (1<<0);
    if( x[i] == 1 ) masks[i] |= (1<<1);
    if( y[i] == H ) masks[i] |= (1<<2);
    if( x[i] == W ) masks[i] |= (1<<3);
  }
  map<int,int> mp;
  rep(i,N){
    if( mp.count(x[i]) ) unit(find(mp[x[i]]),find(i));
    else                 mp[x[i]] = i;
  }
  mp.clear();
  rep(i,N){
    if( mp.count(y[i]) ) unit(find(mp[y[i]]),find(i));
    else                 mp[y[i]] = i;
  }

  map<int,int> bitmask;
  set<int> S;
  vector<int> group;
  rep(i,N) S.insert(find(i));
  rep(i,N) ++sz[find(i)];

  if( S.size() == 1 ) {
    cout << sz[find(0)] - 1 << endl;
    return 0;
  }

  rep(i,N) bitmask[find(i)] |= masks[i];
  for(set<int>::iterator it = S.begin(); it != S.end(); it++) group.push_back(*it);

  int ans = IINF;
  rep(i,4){
    int cost = (int)S.size()-1;
    rep(j,(int)group.size()){
      cost += sz[group[j]];
      if( (bitmask[group[j]]>>i) & 1 ) --cost; 
    }
    ans = min(ans,cost);
  }
  cout << ans << endl;
  return 0;
}

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

#define int long long
const int mod = 1e9+7;

const int N = 1005;
template<typename T> T gcd(T a,T b) { if(a==0) return 0; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }


int32_t main(){

    int n,k;
    cin>>n>>k;
    

    if(n%k==0)
        cout<<0;
    else
        cout<<1;

    return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> l(n);
  for (int i = 0; i < n; ++i) cin >> l[i];

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      for (int k = j + 1; k < n; ++k) {
	ll sides[3] = {l[i], l[j], l[k]};
	sort(sides, sides + 3);
	if (sides[0] + sides[1] > sides[2] && l[i] != l[j] && l[j] != l[k] && l[i] != l[k]) ans++;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3632
#include <iostream>

using namespace std;




class dice{
	private:
		int top;
		int front;
		int right;
		int left;
		int back;
		int bottom;
	public:
		dice();
		dice(int top,int front,int right,int left,int back,int bottom);
		void roll(char ch);
		//void changstatus(side new_top,side new_front);
		int gettop();
		int getfront();
		int getright();
		int getleft();
		int getback();
		int getbottom();
		void getallsides();
};

dice::dice(){
	this->top = 1;
	this->front = 2;
	this->right = 3;
	this->left = 4;
	this->back = 5;
	this->bottom = 6;

}

dice::dice(int top,int front,int right,int left,int back,int bottom){
	this->top=top;
	this->front=front;
	this->right=right;
	this->left=left;
	this->back=back;
	this->bottom=bottom;
}

void dice::roll(char ch){
	int temp;
	switch (ch){
		case 'E':
			temp = this->top;
			this->top = left;
			this->left = bottom;
			this->bottom = right;
			this->right = temp;
			break;
		case 'W':
			temp = this->top;
			this->top = right;
			this->right = bottom;
			this->bottom = left;
			this->left = temp;
			break;
		case 'S':
			temp = this->top;
			this->top = back;
			this->back = bottom;
			this->bottom = front;
			this->front = temp;
			break;
		case 'N':
			temp = this->top;
			this->top = front;
			this->front = bottom;
			this->bottom = back;
			this->back = temp;
			break;
	}
}

void dice::getallsides(){
	cout << top << " "<<front<<" "<<right<<" "<<left<<" "<<back<<" "<<bottom<<endl;
}

int dice::gettop(){
	return this->top;
}

int dice::getbottom(){
	return this->bottom;
}

int dice::getfront(){
	return this->front;
}

int dice::getback(){
	return this->back;
}

int dice::getleft(){
	return this->left;
}

int dice::getright(){
	return this->right;
}

/*

void dice::changstatus(){
	int
}
*/


int main(){

	int top,front,right,left,back,bottom;
	dice dice1,dice2;
	int count;
	int new_top,new_front;

	cin >>top>>front>>right>>left>>back>>bottom;

	dice1 = dice(top,front,right,left,back,bottom);


	cin >> count;

	string method[]={"","N","N","N","EN","WN"};
	string temp;
    bool flag;
	for(int k=0;k<count;k++){
		flag = false;
		cin >> new_top >> new_front;
        dice2 = dice1;
		for(int i=0;i<6;i++){
			temp=method[i];
			if(i==4||i==5){
				dice2 = dice1;
			}
			for(int j=0;j<temp.length();j++){
				dice2.roll(temp[j]);
			}

			for(int j=0;j<4;j++){
				dice2.roll('E');
				if(dice2.gettop()==new_top&&dice2.getfront()==new_front){
					flag = true;
					cout << dice2.getright()<<endl;
					break;
				}
			}

			if (flag==true){
				break;
			}
		}

	}

	return 0;
}



Measured memory_bytes: 3204
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

const int N = 34;

int n, d, ans, x[N][N];

int main() {
	scanf("%d%d", &n, &d);
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= d; j ++) {
			scanf("%d", &x[i][j]);
		}
		for(int k = 1; k < i; k ++) {
			int dis = 0;
			for(int j = 1; j <= d; j ++) {
				dis += (x[k][j] - x[i][j]) * (x[k][j] - x[i][j]);
			}
			int x = sqrt(dis);
			if(x * x == dis) ans ++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
// 17.07.2017


# include <iostream>
# include <algorithm>


using namespace std;

const int N = 51;

int len [N], n, k, sum;

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

   for ( int i = 0; i < n; i++ )
      cin >> len [i];

   sort (len, len+n);

   for ( int i = 0; i < k; i++ )
      sum += len [n-i-1];

   cout << sum;

   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1E-11;

bool dp[10050];
int main() {
	int N, i, j, t;
	scanf("%d", &N);
	dp[0] = true;
	for (i = 1; i <= N; i++) {
		scanf("%d", &t);
		for (j = 10000; j >= t; j--) if (dp[j - t]) dp[j] = true;
	}

	for (i = 10000; i >= 0; i--) if (i % 10 && dp[i]) return !printf("%d\n", i);
	return !printf("0\n");
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <stack>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	//入力
	long a[100000], b[100000], x[100000] = {};
	long N, M = 1000000000, ans = 0;
	cin >> N >>M;
	//処理
	if (N < M) ans = 0;
	else ans = 10;
	//出力
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {
    int INF = 1 << 28;
    String[] unit = {  "",  "Man", "Oku", "Cho", "Kei", 
                     "Gai",  "Jo", "Jou",  "Ko", "Kan", 
                     "Sei", "Sai", "Gok", "Ggs", "Asg", 
                     "Nyt", "Fks", "Mts"};
    void run() {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            int m = sc.nextInt(), n = sc.nextInt();
            if ((m|n) == 0) break;
            BigInteger bi = BigInteger.valueOf(m);
            bi = bi.pow(n);
            String ans = ""; int p = 0;
            while (!bi.equals(BigInteger.ZERO)) {
                BigInteger[] dr = bi.divideAndRemainder(BigInteger.valueOf(10000));
                int a = dr[1].intValue();
                if (a != 0) ans = "" + a + unit[p] + ans;
                bi = dr[0]; p++;
            }
            System.out.println(ans);
        }
    }
    
    void debug(Object...os) {
        System.out.println(deepToString(os));
    }
    
    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 19708
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 5123;
 
int n, k;
int v[MAXN];
bool memo[MAXN];
 
bool solve (int x) {
	memset (memo, 0, sizeof memo);
	memo[0] = true;
 
	for (int i = 0; i < n; ++i) {
		if (i == x) continue;
		for (int j = k; j >= v[i]; --j)
			memo[j] |= memo[j - v[i]];
	}
 
	for (int i = max (k - v[x], 0); i < k; ++i)
		if (memo[i]) return false;
 
	return true;
}
 
int main () {
 
	cin >> n >> k;
 
	int ans = 0;
	for (int i = 0; i < n; ++i)
		scanf ("%d", v + i);
 
	sort (v, v + n);
 
	if (!solve (0)) {
		cout << ans << endl;
		return 0;
	}
 
	int l = 0, r = n;
	while (r - l > 1) {
		int mid = (l + r) >> 1;
		if (solve (mid))
			l = mid;
		else
			r = mid;
	}
 
	cout << ans + l + 1 << endl;
 
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

in gcd(in a, in b) {return b != 0ll ? gcd(b, a % b) : a;}//最大公約数
map<in,in> soin(in n){
    map<in,in> ret;
    for(in i=2ll;i*i<=n;i ++){
        while(n%i==0ll){
            ret[i] ++;
            n /= i;
        }
    }
    if(n!=1ll) ret[n]=1ll;
    return ret;
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in a,b;
    cin>>a>>b;
    in x=gcd(a,b);
    auto y=soin(x);
    in ans =y.size();
    ans ++;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int k, t;
  cin >> k >> t;
  vector<int> a(t);
  int maxi = 0;
  for(int i = 0; i < t; i++) {
    cin >> a[i];
    maxi = max(maxi, a[i]);
  }
  if(k % 2 == 0) {
    if(maxi > k / 2) {
      cout << (maxi - k / 2) * 2 - 1 << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    if(maxi > (k + 1) / 2) {
      cout << (maxi - (k + 1) / 2) * 2 - 1 << endl;
    } else {
      cout << 0 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
long long x[210000];
long long y[210000];

int main(){
	int a;scanf("%d",&a);
	long long ret=0;
	for(int i=0;i<a;i++){
		scanf("%lld%lld",x+i,y+i);
		ret=max(ret,y[i]);
	}
	long long L=inf;
	long long toc=0;
	for(int i=0;i<a;i++){
		L=min(L,toc);
		toc+=y[i];

		ret=max(ret,toc-L);
		if(i<a-1)toc-=x[i+1]-x[i];
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 3328
s = [input() for i in range(int(input()))]
t = [input() for i in range(int(input()))]
import collections as cl
dic_s = cl.Counter(s)
dic_t = cl.Counter(t)
max_value = 0
for key in dic_s.keys():
  if key in dic_t:
    if dic_s[key] > dic_t[key]:
      max_value = max(dic_s[key] - dic_t[key], max_value)
  else:
    max_value = max(dic_s[key], max_value)
print(max_value)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int OO = 1e9;
int brute(int a, int b){
  ll rnk = 1LL * a * b;
  set<int> ss;
  for(int i = 1;i < rnk;i++){
    if(i == a)continue;
    ll x = (rnk - 1) / i;
    while(ss.find(x) != ss.end() || x == b)
      x--;
    if(x)
      ss.insert(x);
  }
//  for(auto el : ss)
//    cout << el << ' ';
//  cout << endl;
  return ss.size();
}
int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
//  cout << 10000 << endl;
//  for(int i = 1;i < 100;i++){
//    for(int j = 1;j < 100;j++){
//      cout << rand() % 10000 + 1 << ' ' << rand() % 10000 + 1 << endl;
//    }
//  }
//  return 0;
  int q;
  cin >> q;
  while(q--){
    int a, b;
    cin >> a >> b;
    ll rnk = 1LL * a * b;
    if(rnk <= 2){
      cout << 0 << endl;
      continue;
    }
    ll res = 0;
    ll prev = -1;
    ll i = 1;
    ll lo, hi;
    lo = 1, hi = rnk - 2;
    while(hi - lo > 20){
      ll mid = (lo + hi) / 2;
      bool b = 0;
      ll j = max(lo, mid - 50000);
      for(;j <= min(hi - 1, mid + 50000);j++){
        if((rnk - 1) / j == (rnk - 1) / (j + 1)){
          hi = j;
          b = 1;
          break;
        }
      }
      if(!b){
        lo = j - 1;
      }
    }
    for(;lo <= hi;lo++){
      if((rnk - 1) / lo == (rnk - 1) / (lo + 1))
        break;
    }
    ll ans = lo + (rnk - 1) / lo - 1;
    if(lo >= a && (rnk - 1) / a != (rnk - 1) / (a + 1) && (rnk - a) / a != (rnk - 1) / (a + 1))
      ans--;
    ll x = (rnk - 1) / b;
    while(x && (rnk - 1) / x > b){
      x++;
    }
    while(x && (rnk - 1) / x < b){
      x--;
    }
    if(x && (rnk - 1) / x == b)
    if((rnk - 1) / (x + 1) == b - 1){
      ans--;
    }
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
      int n,gcd=1;
        cin >> n;
        int a[n+5];
        cin >> gcd;
        for(int i = 1; i<n; i++)
        {
            cin >> a[i];
            gcd=__gcd(gcd,a[i]);

        }
        cout<<gcd<<endl;


    
}


Measured memory_bytes: 3888
fun main(args: Array<String>) {
    var (N, M) = listOfInt()
    val A = listOfInt().sortedDescending()
    val B = Array(10) { false }
    val D = arrayListOf(0, 2, 5, 5, 4, 5, 6, 3, 7, 6)
    val dp = Array(N + 1) { -1 }; dp[0] = 0
    for (m in 0 until M) {
        B[A[m]] = true
        for (n in D[A[m]] .. N) {
            dp[n] = Math.max(dp[n], dp[n - D[A[m]]] + 1)
        }
    }
    while (N > 0) {
        for (n in 9 downTo 1) {
            if (B[n]) {
                if (N >= D[n] && dp[N - D[n]] == dp[N] - 1) {
                    print(n)
                    N -= D[n]
                    break;
                }
            }
        }
    }
    println()
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

Measured memory_bytes: 41572
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut cnt = 1;
    let mut ans = 0;
    for &ai in a.iter() {
        if ai == cnt {
            cnt += 1;
        } else {
            ans += 1;
        }
    }
    println!("{}", if ans == n { -1 } else { ans as isize });
}


Measured memory_bytes: 8444
n = int(input())

M= [[] for i in range(n)]

for i in range(n):
  M[i] = list(map(int, input().split()))

p = [M[0][0]]

for i in range(n):
  p.append(M[i][1])

f_inf = float("inf")

m = [[f_inf for i in range(n)] for j in range(n)]

def matrixChainOrder(n):
  for i in range(n):
    m[i][i] = 0
  for l in range(2, n+1):
    for i in range(n-l+1):
      j = i + l - 1
      for k in range(i, j):
        q = m[i][k] + m[k+1][j] + p[i]*p[k+1]*p[j+1]
        if q < m[i][j]:
          m[i][j] = q

matrixChainOrder(n)

print(m[0][n-1])


Measured memory_bytes: 5776
#include <iostream>
#include <vector>
#include <numeric>
#include <climits>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm> 


#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;


int main() {

	while(1){
		int a,b,s;
		cin >> a >> b >> s;

		if(a==0&&b==0&&s==0) break;
			
		int ans=0;
		vector<int> list1;
		vector<int> list2;
		for(int i=1;i<s+1;i++){
			for(int j=1;j<s+1;j++){
				int item1=i,item2=j;
				//if(i+j>=s) break;
				//cout << item1+item2 << endl;
				if((((item1*(100+a))/100)+((item2*(100+a))/100))==s){
					list1.push_back(item1);
					list2.push_back(item2);

				}
			}
		}
		rep(i,list1.size()){
			int item1=list1[i],item2=list2[i];	

		//	if(ans<(item1*(100+b)/100)+(item2*(100+b)/100)) cout << "DEBUG:" << item1 << " " << item2 << endl;
			ans=max(ans,(item1*(100+b)/100)+(item2*(100+b)/100));

		}

		cout <<  ans << endl;
	}


}

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

constexpr ll INF = 1ll<<60;
template<class T>
void chmin(T &a, T b) {if (a > b) a = b;}
ll dp[30][50010];

int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	vector<ll> coin(N); for (ll i = 0; i < M; ++i) cin >> coin[i];
	for (ll i = 0; i < 30; ++i) for (ll j = 0; j < 50010; ++j) dp[i][j] = INF;
	dp[0][0] = 0;
	for (ll i = 0; i < M; ++i)
	{
		for (ll j = 0;j <= N; ++j)
		{
			chmin(dp[i+1][j], dp[i][j]);
			if (j-coin[i]>=0)chmin(dp[i+1][j], dp[i+1][j-coin[i]]+1);
		}
	}
	std::cout << dp[M][N] << std::endl;
}


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int d;
  cin >> d;
  cout << "Christmas";
  for (int i = 0; i < 25 - d; ++i) cout << " Eve";
  cout << '\n';
  return 0;
}

Measured memory_bytes: 256
object Main extends App {  
  val Array(a,b,c,d) = readLine.split("").filter(_.nonEmpty).map(_.toInt)
  
  def calc(ope: Boolean, x: Int, y: Int) = if (ope) x + y else x - y
  
  val ops = for {
    op1 <- Seq(true, false)
    op2 <- Seq(true, false)
    op3 <- Seq(true, false)
    if (calc(op3, calc(op2, (calc(op1, a, b)), c), d)) == 7
  } yield (op1, op2, op3)
  
  def opStr(bool: Boolean) = if (bool) "+" else "-"
  
  println(s"$a${opStr(ops(0)._1)}$b${opStr(ops(0)._2)}$c${opStr(ops(0)._3)}$d=7")
}

Measured memory_bytes: 25548
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=6010;
int n,a[maxn],tot,head[maxn];
int nxt[maxn],to[maxn];
void add(int x,int y) {
	tot++; nxt[tot]=head[x];
	head[x]=tot; to[tot]=y;
}
bool dfs(int u,int p) {
	for (int i=head[u],v;i;i=nxt[i]) {
		v=to[i]; if (v==p) continue;
		if (a[v]<a[u]&&!dfs(v,u)) return 1;
	}
	return 0;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); int x,y;
	for (int i=1;i<=n;i++) read(a[i]);
	for (int i=1;i<n;i++) {
		read(x); read(y);
		add(x,y); add(y,x);
	}
	for (int i=1;i<=n;i++)
		if (dfs(i,0)) printf("%d ",i);
	printf("\n");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

struct UnionFind{
  VI par;
  VI siz;
  VI rank;
  UnionFind(int n):par(n),rank(n),siz(n){
    rep(i,n){
      par[i]=i;
      siz[i]=1;
      rank[i]=0;
    }
  }
  int root(int x){
    if(par[x]==x) return x;
    int r=root(par[x]);
    return par[x]=r;
  }
  bool same(int x, int y){
    return root(x)==root(y);
  }
  void unite(int x, int y){
    x=root(x);y=root(y);
    if(x==y) return;
    if(rank[x]<rank[y]) swap(x,y);
    if(rank[x]==rank[y]) rank[x]++;
    par[y]=x;
    siz[x]+=siz[y];
  }
  int size(int x){
    return siz[root(x)];
  }
};

int main(){
  ll N,M;
  cin>>N>>M;
  VL A(M),B(M);
  rep(i,M) cin>>A[i]>>B[i];
  UnionFind uf(N);
  rep(i,M) uf.unite(A[i]-1,B[i]-1);
  int ans=0;
  rep(i,N) ans=max(ans,uf.size(i));
  cout<<ans<<endl;
}



Measured memory_bytes: 8796
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a>>b>>c;
    if(a==b and b==c){
        cout << "No";
    }else if(a!=b and b != c and a != c){
        cout << "No";
    }else{
        cout << "Yes";
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define fi first
#define se second
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	double n;
	while(cin>>n){
		if(n<=48.00) cout<<"light fly"<<endl;
		else if(n<=51.00) cout<<"fly"<<endl;
		else if(n<=54.00) cout<<"bantam"<<endl;
		else if(n<=57.00) cout<<"feather"<<endl;
		else if(n<=60.00) cout<<"light"<<endl;
		else if(n<=64.00) cout<<"light welter"<<endl;
		else if(n<=69.00) cout<<"welter"<<endl;
		else if(n<=75.00) cout<<"light middle"<<endl;
		else if(n<=81.00) cout<<"middle"<<endl;
		else if(n<=91.00) cout<<"light heavy"<<endl;
		else cout<<"heavy"<<endl;
	}
}

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

using namespace std;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    char g[10][10];
    bool visx[10], visy[10];
    for(int i = 0; i < H; ++i) scanf("%s", g[i]);
    int ans = 0;
    for(int mask = 0; mask < (1 << (H+W)); ++mask) {
        memset(visx, 0, sizeof(visx));
        memset(visy, 0, sizeof(visy));
        int cnt = 0;
        for(int r = 0; r < H; ++r) {
            if((1<<r) & mask) {
                visx[r] = true;
            }
        }
        for(int c = H; c < H+W; ++c) {
            if((1<<c) & mask) {
                visy[c-H] = true;
            }
        }
        for(int r = 0; r < H; ++r) {
            for(int c = 0; c < W; ++c) {
                if(g[r][c] == '#' && !visx[r] && !visy[c])
                    ++cnt;
            }
        }
        //printf("cnt = %d\n", cnt);
        if(cnt == K) ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  
  bool handan=false;
  
  for (int i=A; i<=B; i++){
    if(i%K == 0){
      handan = true;
      break;
    }
  }
  
  if(handan){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
}

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

using namespace std;

typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<LL> vl;
typedef vector<vector<LL>> vvl;
typedef vector<vector<vector<LL>>> vvvl;


const int inf = 1e9+7;
const LL INF = 1e18+5;
const int mod = 1e9+7;
const int mxN = 1e5+5;
const int mxM = 1e5+5;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("E:\\Coding\\Programming\\input.txt", "r", stdin);
    freopen("E:\\Coding\\Programming\\output.txt", "w", stdout);
    #endif
    int n,x,t;
    cin>>n>>x>>t;
    if(n%x==0){
        cout<<(n/x)*t<<endl;
    }else{
        int ans = n/x;
        cout<<(ans+1)*t<<endl;
    }
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    long long arr[100001];
    int q;
    int b, c;
    long long ans = 0;
    map<int, int> dict;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> arr[i];
        ans += arr[i];
        dict[arr[i]] += 1;
    }
    cin >> q;
    for(int i=0; i<q; i++){
        cin >> b >> c;
        //int before = dict[arr[b]];
        ans -= b * (long long)dict[b];
        ans += (long long)dict[b] * c;
        dict[c] += dict[b];
        dict[b] = 0;
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 8724
a, b, c, d = gets.chomp.split.map(&:to_i)
res = b - a + 1
res -= [b / c - (a + c - 1) / c + 1, 0].max
res -= [b / d - (a + d - 1) / d + 1, 0].max
l = c.lcm(d)
res += [b / l - (a + l - 1) / l + 1, 0].max
puts res

Measured memory_bytes: 14296
import sys
import numpy as np

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

MOD = 10 ** 9 + 7

def cmb(n, k):
    if k < 0 or k > n: return 0 
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD

def cumprod(arr, MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv

U = 10 ** 6 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
X, Y = lr()
if (X+Y)%3 != 0 or X > Y + Y or Y > X + X:
    print(0); exit()

time = (X+Y) // 3
diff = abs(X-Y)
a = (time-diff)//2
# timeCaが答え
answer = cmb(time, a)
print(answer%MOD)


Measured memory_bytes: 53576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<map<ll, ll>> V(N);

	for (ll i = 0; i < N; ++i)
	{
		string s; cin >> s;
		for (auto e : s)
		{
			++V[i][e];
		}
	}

	string res;
	auto m = V[0];

	for (auto &p : m)
	{
		char t = p.first;
		ll mi = p.second;
		for (ll i = 1; i < N; ++i)
		{
			mi = min(mi, V[i][t]);
		}
		for (ll i = 0; i < mi; ++i)
			res += t;
	}
	sort(res.begin(), res.end());
	std::cout << res << std::endl;
}

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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<std::string> W) {
  set<string> w;
  bool ok = true;
  for(int i = 0 ; i  + 1< W.size() ; i++){
    if( W[i].back() != W[i+1].front()) ok = false;
  }
  for( auto i : W ) w.insert(i);
  if( W.size() != w.size()) ok = false;
  if(ok) cout << YES << endl;
  else cout << NO << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<std::string> W(N);
  for (int i = 0; i < N; i++) {
    std::cin >> W[i];
  }
  solve(N, std::move(W));
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<vc> vcc;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 7;
void solve(){
    int a, b, c, x, y;  cin>>a>>b>>c>>x>>y;
    int ans=INF;
    for(int i = 0; i <= max(x,y); i++){
        ans=min(ans,2*i*c+max(0,x-i)*a +max(0,y-i)*b);
    }
    cout<<ans;
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 256
N,Q=map(int,input().split())
s="0"+input()+"0"
queri=[input().split() for i in range(Q)]
 
L,R=0,N+1
for i in range(Q-1,-1,-1):
    t,d=queri[i]
    if t==s[L] and d=="R":
        L-=1
    elif t==s[L+1] and d=="L":
        L+=1
    if t==s[R] and d=="L":
        R+=1
    elif t==s[R-1] and d=="R":
        R-=1
 
print(R-L-1)

Measured memory_bytes: 39344
#include <iostream>
using namespace std;
int main()
{
    long long A, B;
    char op='+' ||'-';
    cin >> A >> op >> B;
    if(op=='+')
    cout << A +  B << endl;
    if (op == '-')
        cout << A - B << endl;
    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file

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

const int MAX = 1000001;

// structure to store queries
struct Query
{
    int l, r, idx;
};

// cmp function to sort queries according to r
bool cmp(Query x, Query y)
{
    return x.r < y.r;
}

// updating the bit array
void update(int idx, int val, int bit[], int n)
{
    for (; idx <= n; idx += idx&-idx)
        bit[idx] += val;
}

// querying the bit array
int query(int idx, int bit[], int n)
{
    int sum = 0;
    for (; idx>0; idx-=idx&-idx)
        sum += bit[idx];
    return sum;
}

void answeringQueries(int arr[], int n, Query queries[], int q)
{
    // initialising bit array
    int bit[n+1];
    memset(bit, 0, sizeof(bit));

    // holds the rightmost index of any number
    // as numbers of a[i] are less than or equal to 10^6
    int last_visit[MAX];
    memset(last_visit, -1, sizeof(last_visit));

    // answer for each query
    int ans[q];
    int query_counter = 0;
    for (int i=0; i<n; i++)
    {
        // If last visit is not -1 update -1 at the
        // idx equal to last_visit[arr[i]]
        if (last_visit[arr[i]] !=-1)
            update (last_visit[arr[i]] + 1, -1, bit, n);

        // Setting last_visit[arr[i]] as i and updating
        // the bit array accordingly
        last_visit[arr[i]] = i;
        update(i + 1, 1, bit, n);

        // If i is equal to r of any query  store answer
        // for that query in ans[]
        while (query_counter < q && queries[query_counter].r == i)
        {
            ans[queries[query_counter].idx] =
                     query(queries[query_counter].r + 1, bit, n)-
                     query(queries[query_counter].l, bit, n);
            query_counter++;
        }
    }

    // print answer for each query
    for (int i=0; i<q; i++)
        cout << ans[i] << endl;
}

// driver code
int main()
{
    int n,q;
    cin>>n>>q;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];

    Query queries[q];
    for(int i=0;i<q;i++)
    {int l1,r1;
    cin>>l1>>r1;
    queries[i].l = l1-1;
    queries[i].r = r1-1;
    queries[i].idx = i;
    }
    sort(queries, queries+q, cmp);
    answeringQueries(a, n, queries, q);
    return 0;
}


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

class Main {

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();

        if(k <= a){
            System.out.println(k);
        }
        else if(k <= a+b){
            System.out.println(a);
        }
        else{
            System.out.println(2*a+b-k);
        }
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;
    
        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }
    
        int nextInt() {
            return Integer.parseInt(next());
        }
    
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 32612
N = int(input())
plan = [[int(i) for i in input().split()] for j in range(N)]
x = 0
y = 0
t = 0
 
for i in range(N):
    newT = plan[i][0]
    x_t = plan[i][1]
    y_t = plan[i][2]
    distance = abs((x_t+y_t) - (x+y))
    time_lag = newT - t
 
    if distance % 2 == time_lag % 2:
        if distance <= time_lag:
            t = newT
            x = x_t
            y = y_t
            continue
    
    print("No")
    exit()
 
print("Yes")

Measured memory_bytes: 21108
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N,W;
    cin >>N >>W;
    vector<ll> weight(N);
    vector<ll> value(N);
    ll wa = 0;
    rep(i,N){
        cin >> weight[i] >> value[i];
        wa += value[i];
    }
    vector<vector<ll>> memo(N + 1,vector<ll>(wa + 1,INF));
    rep(i,N + 1)memo[i][0] = 0;
    rep(i,N){
        rep(j,wa + 1){
            if(j <= value[i]){
                memo[i + 1][j] = min(memo[i][j],weight[i]);
            }
            else{
                memo[i + 1][j] = min(memo[i][j],memo[i][j - value[i]] + weight[i]);
            }
        }
    }/*
    rep(i,N + 1){
        rep(j,wa + 1){
            if(memo[i][j] != INF)
            cout << memo[i][j] << " ";
            else cout << -1 << " ";
        }
        cout << endl;
    }*/
    ll ans = 0;
    rep(i,wa + 1){
        if(memo[N][i] <= W){
            ans = i;
        }
        else break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 80256
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b;
    cin>>a>>b;
    ll gg=__gcd(a,b);
    ll ans=a*b/gg;
    cout<<ans;
    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    int x; cin>>x;
    int para = 360;
    int cnt = 1;
    while(para % x != 0) cnt++, para = 360*cnt;
    cout << para / x << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,m,sol=1;
    cin >> n >> m;
    for(ll i = 1; i*i <= m; i++){
        if(m%i == 0){
           ll novo = m/i;
           if(n <= novo){
              sol = max(sol,i);
           }
           novo = i;
           if(n <= i){
              sol = max(sol,m/i);
           }
        }
    }
    cout << sol << endl;
}


Measured memory_bytes: 256
N,X,M = map(int,input().split(" "))
q = [-1] * (M + 1)
A = X
i = 0
su = []
p1 = 0
p2 = 0
while q[A] == -1:
    q[A] = i
    su.append(A)
    A = (A * A) % M
    i += 1

if N == len(su):
    print(sum(su))
else:
    r = q[A]
    r2 = (N - r) % (i - r)

    ans1 = sum(su[0:r])
    ans2 = sum(su[r:r + r2])
    ans3 = sum(su[r::])

    print(ans1 + ans2 + ans3 * ((N - r) // (i - r)))

Measured memory_bytes: 13740