akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

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

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  int ans = 0;
  cin >> n;
  for(int i=1;i<=n;i++){
    if(to_string(i).size()%2!=0) ans++;
  }
  cout<< ans <<endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define all(c) begin(c),end(c)
const ll INF = 1e15;

struct edge { ll from, to, cost; };
edge es[2000];
ll d[1000];
int V, E;	//頂点、辺数
			//頂点sからの最短d
void bellmanford(int s) {
	d[s] = 0;
	int count = 0;
	while (count<V) {
		bool update = false;
		rep(i, E) {
			edge e = es[i];
			if (d[e.from] != INF&&d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		count++;
		if (!update)break;
	}
}

int main() {
	cin.sync_with_stdio(false);
	cin >> V >> E;
	rep(i, E) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--; c = -c;
		es[i].from = a; es[i].to = b; es[i].cost = c;
	}
	rep(i, V)d[i] = INF;
	bellmanford(0);
	ll pre = -d[V - 1];
	bellmanford(0);
	if (pre<-d[V-1]) {
		cout << "inf" << endl;
		return 0;
	}
	cout << -d[V - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define elif else if
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define filoop(n) for(ll i=0;i<(n);i++)
#define fjloop(n) for(ll j=0;j<(n);j++)

int main()
{
    ffast;
    //freopen("0in.txt","r",stdin);
    //freopen("0out.txt","w",stdout);


    int n,k,cnt=0;
    cin>>n>>k;
    while(n!=0)
    {
        n = n/k;cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}





Measured memory_bytes: 256
s = gets.chomp
case s
when /(0[1-9]|1[012]){2}/
  puts 'AMBIGUOUS'
when /\A(0[1-9]|1[012])/
  puts 'MMYY'
when /(0[1-9]|1[012])\z/
  puts 'YYMM'
else
  puts 'NA'
end


Measured memory_bytes: 1788
n, x = map(int, input().split())
l = list(map(int, input().split()))
res = 1
d = [0] * (n+1)
for i in range(n):
    d[i+1] = d[i] + l[i]
    if d[i+1] <= x:
        res += 1

# print(d)
print(res)


Measured memory_bytes: 2940
s = input()
result_sum = 0 # 総和 
plus_count = len(s) - 1 # 集合の要素数

for bit in range(1 << plus_count): # bit全探索
  splitted_string = s[0] # 最初の数字を取る
  for iter_plus in range(plus_count):
    if bit & (1 << iter_plus): # ビットを立てる -> +を挿入する
      splitted_string += '+'
    splitted_string += s[iter_plus+1] # 適宜+が入った状態で数字列が構築
    
  # +で区切って,それぞれintに変換し合計
  splitted_integer = [int(x) for x in splitted_string.split('+')]
  result_sum += sum(splitted_integer)
print(result_sum)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int f(int n) {
    int cnt = 0;
    while (true) {
        if (n % 2 == 1) break;
        ++cnt;
        n /= 2;
    }
    return cnt;
}

int main() {
    int N;
    cin >> N;
    
    vector<pair<int, int>> S;
    REP(i, N + 1) {
        S.push_back(make_pair(f(i), i));
    }
    sort(S.rbegin(), S.rend());
    cout << S[0].second << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <time.h>
 
using namespace std;

typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  ll ans = 0;
  rep(i,1,1000001){
    ll a = n/i;
    rep(j,1,a+1){
      ll b =i*j;
      if(n-b>0)ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
N, Q = map(int,input().split())
E = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = map(int,input().split())
    E[a].append(b)
    E[b].append(a)
PX = [list(map(int,input().split())) for _ in range(Q)]

def main():
    V = [0]*(N+1)
    for p,x in PX:
        V[p] += x
    stack = [1]
    gone = [False]*(N+1)
    gone[1] = True
    while len(stack) > 0:
        node = stack.pop(-1)
        for e in E[node]:
            if not(gone[e]):
                stack.append(e)
                V[e] += V[node]
                gone[e] = True
    print(*V[1:],sep =" ")
    return 

if __name__ == "__main__":
    main()

Measured memory_bytes: 103396
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
#define ll long long
#define SF scanf
#define PF printf
#define PB push_back
#define MP make_pair
#define mx 5000001
#define MOD 1000000007
#define INP          freopen("in.txt", "r", stdin);
#define OUT          freopen("out.txt", "w", stdout);
#define BOOST        std::ios_base::sync_with_stdio(false);

char st[210][210];
int vis[210][210];
int sz1,sz2,ns,mm;
queue<pair<int,int> >pq;
queue<pair<int,int> >pq2;
int fx[]={1,-1,0,0};
int fy[]={0,0,1,-1};
int level[210][210];
int lev[210][210];
void bfs2()
{

    pair<int,int>pp;

    pp=pq2.front();
    int x=pp.first;
    int y=pp.second;
    lev[x][y]=0;
    vis[x][y]=1;
    while(!pq2.empty())
    {
        pp=pq2.front();
        pq2.pop();
        int p1=pp.first;
        int p2=pp.second;
        for(int p=0;p<4;p++)
        {
            int x=p1+fx[p];
            int y=p2+fy[p];
            if(x>0&&x<=sz1&&y>0&&y<=sz2&&vis[x][y]==0&&(st[x][y]=='.'||st[x][y]=='%'))
            {

                pq2.push(MP(x,y));
                lev[x][y]=lev[p1][p2]+1;
                vis[x][y]=1;
            }


        }
    }
}

void bfs3(int i,int j)
{
    level[i][j]=0;
    pair<int,int>pp;
    vis[i][j]=1;
    pq.push(MP(i,j));
    while(!pq.empty())
    {
        pp=pq.front();
        pq.pop();
        int p1=pp.first;
        int p2=pp.second;
        for(int p=0;p<4;p++)
        {
            int x=p1+fx[p];
            int y=p2+fy[p];
            if(x>0&&x<=sz1&&y>0&&y<=sz2&&vis[x][y]==0&&(st[x][y]=='.'||st[x][y]=='%'))
            {


                level[x][y]=level[p1][p2]+1;
                if(level[x][y]<lev[x][y]||lev[x][y]==0)
                {
                    pq.push(MP(x,y));
                    vis[x][y]=1;
                }

            }


        }
    }
}
int main()
{


    ll n,t,i,j,n1,k,m,f=0,s=0,c=0,p=1,c1=0,p1=0,p2=0,res=0,c2,s1,s2,ss,pp,x,y,q;
    string st1,st2;
   // SF("%lld",&n);


    cin>>sz1>>sz2;
    ns=1000000;
    for(i=1;i<=sz1;i++)
    {
        for(j=1;j<=sz2;j++)
        {
            cin>>st[i][j];
            if(st[i][j]=='%')
            {
                x=i,y=j;
            }
        }
    }
    memset(vis,0,sizeof(vis));
    memset(lev,0,sizeof(lev));
    memset(level,0,sizeof(level));


    for(i=1;i<=sz1;i++)
    {
        for(j=1;j<=sz2;j++)
        {
            if(st[i][j]=='$')
            {
                pq2.push(MP(i,j));
            }

        }
    }
    if(!pq2.empty())
    bfs2();
    memset(vis,0,sizeof(vis));
    memset(level,0,sizeof(level));
    for(i=1;i<=sz1;i++)
    {
        for(j=1;j<=sz2;j++)
        {
            if(st[i][j]=='@')
            {
                bfs3(i,j);
            }

        }
    }
    if(level[x][y]==0||(lev[x][y]!=0&&lev[x][y]<=level[x][y]))
    {
        //cout<<level[x][y]<<" "<<lev[x][y]<<endl;
        cout<<"No"<<endl;

    }
    else
    {
        //cout<<level[x][y]<<" "<<lev[x][y]<<endl;
        cout<<"Yes"<<endl;
    }





return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
typedef long long ll;
int N, A[MAX];
ll psum[MAX];

int main(){
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		scanf("%d", A + i);
		psum[i] += psum[i - 1] + A[i];
	}
	ll ans = N, xsum = 0;
	ll l, r, len = 0;
	for(l = 1, r = 1; r <= N; r++){
		xsum ^= A[r];
		if((psum[r] - psum[l - 1]) == xsum){
			len = r - l + 1;
		}
		else{
			ans += len * (len - 1) / 2;
			while(l <= r && psum[r] - psum[l - 1] != xsum){
				xsum ^= A[l++];
			}
			len = r - l + 1;
			ans -= max(0LL, (len - 1) * (len - 2) / 2);
		}
	}
	ans += len * (len - 1) / 2;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long

signed main() {
    int n;
    cin >> n;
    int sum = 0;
    int ma = 0;
    FOR(i,1,n+1) {
        sum+=i;
        if(sum>=n) {
            ma=i;
            break;
        }
    }
    sum = n;
    rrep(i,ma+1) {
        if(i==0) continue;
        if(sum-i>=0) {
            sum-=i;
            cout << i << endl;
        }
        
    }
    return 0;
}



Measured memory_bytes: 3632
def main():
    n=int(input())
    s=list(input())
    #d=list(map(int,input().split()))
    ans=1
    now=s[0]
    for i in range(n):
        if s[i]==now:
            continue
        else:
            ans+=1
            now=s[i]
    print(ans)
main()

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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define endl "\n"

set<ll> adj[100005];
vector<ll> a[100005]; 
map<pair<ll,ll>,ll> hm;

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

    // cout<<fixed<<setprecision(15);

    ll n,d;
    cin>>n>>d;

    ll a[n][d];

    for(ll i = 0 ; i < n ; i++)
    {
        for(ll j = 0 ; j < d ; j++)
        {
            cin>>a[i][j];
        }
    }

    ll cnt = 0;

    for(ll i = 0 ; i < n ; i++)
    {
        for(ll j = i + 1; j < n ; j++)
        {
            ld sum = 0.0;

            for(ll k = 0 ; k < d ; k++)
            {
                sum += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]); 
            }

            sum = sqrt(sum);

            if(ceil(sum) == floor(sum))
            {
                cnt++;
            }

        }
    }

    cout<<cnt<<endl;

}

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

const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ll long long
#define vi vector < int >
#define vll vector < ll >
#define pii pair < int , int >
#define ff first
#define tc \
    int ttt; cin >> ttt;\
    while(ttt --)
#define ss second
#define f(i,a,b) for(int i=a;i<b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define nl '\n'
#define all(x) x.begin() , x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
int logg(ll x , ll y) {if (x == 0) return -1; return logg(x / y, y) + 1;}
ll poww(ll a, ll b, ll m) {
	if (b == 0) return 1;
	ll ans = 1;
	ans = poww(a, b >> 1, m);
	ans = (ans * ans) % m;
	if (b & 1) ans = (ans * a) % m;
	return ans;
}
// Start of code
const int N = 1e5 + 5;
int height[N];
int dp[N];

int solve (int n) {

	dp[1] = 0;
	f(i, 2, n + 1) dp[i] = min(abs(height[i] - height[i - 1]) + dp[i - 1], (i == 2) ? 100000 : abs(height[i] - height[i - 2]) + dp[i - 2]);
	return dp[n];
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast;

	int n;
	cin >> n;
	f(i, 1, n + 1) cin >> height[i];
	cout << solve(n) << nl;
}


Measured memory_bytes: 4440
#include <iostream>

using namespace std;

int main()
{
	int n;
	int count[4][3][10] = {};
	int b, f, r, v;
	int i, j, k;

	cin >> n;

	for (i = 0; i < n; i++)
	{
		cin >> b >> f >> r >> v;
		count[b - 1][f - 1][r - 1] += v;
	}

	for (i = 0; i < 4; i++)
	{
		for (j = 0; j < 3; j++)
		{
			for (k = 0; k < 10; k++)
			{
				cout << " " << count[i][j][k];
			}
			cout << endl;
		}
		if (i != 3)
		{
			for (j = 0; j < 20; j++)
			{
				cout << '#';
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1164
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define pb push_back
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rii(x,y) ri(x), ri(y)

#define fst first
#define snd second

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

const ll MOD = 1e9+7;
const int MAXN = 1e5+5;

ll fact[MAXN];

int main(){
	fact[0] = 1;
	FOR(i,1,MAXN) fact[i]=(i*fact[i-1])%MOD;
	int N, M;
	rii(N,M);
	if(M>N) swap(N,M);
	ll ans;
	if(N>M+1){
		ans = 0;
	}else{
		ans = fact[N]*fact[M] %MOD;
		if(N==M) ans = (ans*2)%MOD;
	}
	printf("%lld\n",ans);
}

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

int main(){
  int num[200];
  int n,count,ans;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  sort(num,num+n);
  count=num[0];
  reverse(num,num+n);
  ans=num[0];
  cout<<ans-count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <cmath>
#include <sstream>
#include <queue>
#include <map>
#include <cstring>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <random>
using namespace std;


int main() {
    int N;
    long long result = 0;
    cin >> N;
    int* A = new int[N];
    int* B = new int[N];
    for (int i = 0; i < N; ++i) {
        cin >> A[i] >> B[i];
    }
    for (int i = N - 1; i >= 0; --i) {
        result += (B[i] - (A[i] + result) % B[i]) % B[i];
    }
    cout << result << endl;
    delete [] A;
    delete [] B;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int n,m,l; 
    int i,j,k; 
    int a[100][100]; 
    int b[110][110]; 
    long long c[100][100]={}; 
    scanf("%d %d %d",&n,&m,&l); 
    for(i=0;i<n;i++){  
        for(j=0;j<m;j++){   
            scanf("%d",&a[i][j]);  
            
        } 
        
    } 
    for(i=0;i<m;i++){  
        for(j=0;j<l;j++){   
            scanf("%d",&b[i][j]); 
            } 
        
    }
    for(i=0;i<n;i++){  
        for(j=0;j<l;j++){   
            for(k=0;k<m;k++){    
                c[i][j]+=a[i][k]*b[k][j];   
                
            }   
            if(j!=0) printf(" ");   
            printf("%lld",c[i][j]);  
            
        }  
        puts(""); 
        
    } 
    return 0;
    
}


Measured memory_bytes: 2100
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

class UnionFindPathCompression():
    def __init__(self, n):
        self.parents = list(range(n))
        self.rank = [1]*n
        self.group_size = [1]*n

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        #親を探す p = parentの意味
        px = self.find(x)
        py = self.find(y)

        if px == py:
            return
        else:
            if self.rank[px] < self.rank[py]:
                self.parents[px] = py
                self.group_size[py] += self.group_size[px]
            else:
                self.parents[py] = px
                self.group_size[px] += self.group_size[py]
                #ランクの更新
                if self.rank[px] == self.rank[py]:
                    self.rank[px] += 1
                
n,m = map(int,input().split())
ufpc = UnionFindPathCompression(n)
query = []
for i in range(m):
    a, b = (int(x) for x in input().split())
    a,b = a-1, b-1
    query.append([a,b])

ans = [0]*m
ans[m-1] = n*(n-1)//2
#queryを後ろから発行してunionfind
for i in range(m-2, -1, -1):
    a,b = query[i+1][0], query[i+1][1]
    if ufpc.find(a) == ufpc.find(b):
        ans[i] = ans[i+1]
    else:
        #親のサイズで不便さを計算
        ans[i] = ans[i+1] - ufpc.group_size[ufpc.parents[a]] * ufpc.group_size[ufpc.parents[b]]

    ufpc.union(a,b)
for aa in ans:
    print(aa)


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

using namespace std;

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

int main()
{
    vector<int>vc;
    ll n;
    for(ll i = 0; i < 10; i++){
        cin >> n;
        vc.push_back(n);
    }
    sort(vc.begin(), vc.end(), cmp);
    for(ll i = 0; i < 3; i++){
        cout << vc[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3136
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const numbers = arg[1].split(" ").map(n=>parseInt(n));
    
    console.log(numbers.reduce((m,n)=>m+n) - N);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
	string s, t;
	cin >> s >> t;
	int x = stoi(s+t);
	for(int i=1;i<=1000;i++){
		if(i*i==x){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

int main(void){
	int n=in(),i,p[100001],ans=0;
	rep(i,n)p[i]=in();
	rep(i,n-1){
		if(p[i]==i+1){
			swap(&p[i],&p[i+1]);
			ans++;
		}
	}
	if(p[n-1]==n){
		swap(&p[i-1],&p[i]);
		ans++;
	}
	print(ans);
	return 0;
}

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

#define INF 2000000000

long long int dp[3010][3010][5];
long long int item[3030][3030];

int main(){

    int r,c,kk;

    cin >> r >> c >> kk;

    for(int i = 0;i <= r;i++){
        for(int j = 0;j <= c;j++){
            item[i][j] = -1;
            for(int l = 0;l <= 4;l++){
                dp[i][j][l] = 0;
            }
        }
    }

    for(int i = 0;i < kk;i++){
        int rr,cc,v;
        cin >> rr >> cc >> v;
        item[rr][cc] = v;
    }

    long long int ans = 0;

    for(int i = 1;i <= r;i++){
        for(int j = 1;j <= c;j++){
            for(int k = 0;k <= 3;k++){
                if(k == 0){
                    dp[i][j][k] = max(dp[i][j-1][k],dp[i-1][j][4]);
                }else{  // k = 1,2,3
                    dp[i][j][k] = dp[i][j-1][k];
                    if(item[i][j] >= 1){
                        dp[i][j][k] = max(dp[i][j][k],dp[i][j-1][k-1] + item[i][j]);
                        dp[i][j][k] = max(dp[i][j][k],dp[i-1][j][4] + item[i][j]);
                    }
                }
            }
            long long int tmp_max = 0;
            for(int k = 0;k <= 3;k++) tmp_max = max(tmp_max,dp[i][j][k]);
            dp[i][j][4] = tmp_max;
            ans = max(ans,tmp_max);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 427172
# @author 

import sys

class ATakahashiCalendar:
    def solve(self):
        m, d = [int(_) for _ in input().split()]
        ans = 0
        for mi in range(1, m + 1):
            for di in range(1, d + 1):
                d1, d2 = di % 10, (di // 10) % 10
                if d1 >= 2 and d2 >= 2 and d1 * d2 == mi:
                    ans += 1

        print(ans)

solver = ATakahashiCalendar()
input = sys.stdin.readline

solver.solve()


Measured memory_bytes: 39536
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int L = scan.nextInt();
        int R = scan.nextInt();
        int ans = Integer.MAX_VALUE;
        long x = 0;
        if (R - L >= 2019) {
            System.out.println(0);
            System.exit(0);
        }
        for (int i = L; i < R; i++) {
            for (int j = L + 1; j <= R; j++) {
                int m = (int)(((long)i * j) % 2019);
                ans = Math.min(ans, m);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
#include <stdio.h>


int main(){

	int n, i, j;
	int A[101], tmp;
	int count=0;

	scanf( "%d", &n );

	for( i=0; i<n; i++ )
		scanf( "%d", &A[i] );

	for( i=0; i<n; i++ ){
	for( j=(n-1); j>i; j-- ){
		
		if( A[j] < A[j-1] ){
			tmp = A[j];
			A[j] = A[j-1];
			A[j-1] = tmp;	

			count++;
		} 

	}}

	for( i=0; i<n; i++ )
		printf( "%d%c", A[i], i!=(n-1)?' ':'\n' );

	printf( "%d\n", count );



	return 0;
}

Measured memory_bytes: 600
macro_rules! get {
    (Vec<t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (N, M) = get!(usize, usize);
    let (a, b): (Vec<_>, Vec<_>) = get!(i64, i64; N).into_iter().unzip();
    let (c, d): (Vec<_>, Vec<_>) = get!(i64, i64; M).into_iter().unzip();

    for i in 0..N {
        let mut ans = 1;
        let mut x = (c[0] - a[i]).abs() + (d[0] - b[i]).abs();
        for j in 1..M {
            let y = (c[j] - a[i]).abs() + (d[j] - b[i]).abs();
            if y < x {
                ans = j + 1;
                x = y;
            }
        }
        println!("{}", ans);
    }
}

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

typedef long long int ll;
ll cnt = 0;
void dfs(ll n, ll d, string s,char h = 'a')
{
    if(s[s.size() - 1] > h + 1){
        return;
    }

    if(d - 1 == n){
        cout << s << "\n";
        return;
    }
    h = max(h, s[s.size() - 1]);
    char t = 'a';
    for(ll i = 0;i < d;i++){
        s.push_back(t);
        dfs(n, d + 1, s, h);
        s.pop_back();
        t += 1;
    }
}

int main()
{
    ll n, sum = 0;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0;i < n;i++){
        cin >> a[i];
    }
    vector<ll> t(n + 1), t2(n + 1);
    for(ll i = 0;i < n;i++){
        t[a[i]]++;
        t2[a[i]]++;
    }
    for(ll i = 0;i < n + 1;i++){
        ll tmp = 1;
        for(ll j = t2[i];j > t2[i] - 2;j--){
            tmp *= j;
        }
        tmp /= 2;
        t2[i] = tmp;
    }
    for(ll i = 0;i < n + 1;i++){
        ll tmp = 1;
        for(ll j = t[i] - 1;j > t[i] - 3;j--){
            tmp *= j;
        }
        tmp /= 2;
        t[i] = tmp;
        sum += t2[i];
    }

    vector<ll> bans(n + 1);

    for(ll i = 0;i < n + 1;i++){
        bans[i] = t2[i] - t[i];
    }

    for(ll i = 0;i < n;i++){
        cout << sum - bans[a[i]] << "\n";
    }


    return 0;
}

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

int main() {
  double n,k;
  cin>>n>>k;
  double ans=0;
  for(int64_t i=1;i<=n;i++){
    if(i>=k){
      ans+=1/n;
    }
    else{
      double t=1/n;
      int64_t z=i;
      int count=0;
      while(z<k){
        z*=2;
        count++;
      }
      t*=(1/pow(2,count));
      ans+=t;
    }
  }
   cout << fixed << setprecision(20);
 
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[120],r[120];
string s[120];
inline bool cmp(int x,int y){
	if(s[x]!=s[y]) return (s[x]<s[y]);
    else return (a[x]>a[y]);
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s[i]>>a[i];
		r[i]=i;
	}
	sort(r+1,r+n+1,cmp);
	for(int i=1;i<=n;i++) cout<<r[i]<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1LL<<60
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main(){
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];
  sort(a, a+n);
  if(a[n-1] - a[0] > 1){
    cout << "No" << endl;
    return 0;
  }
  int M = 0, N;
  N = a[n-1];
  while(a[M] == (N-1)) M++;
  if(M <= (N-1) && (2*N-M) <= n) cout << "Yes" << endl;
  else if(M == 0 && N == (n-1)) cout << "Yes" << endl;
  else cout << "No" << endl; 
	return 0;
}


Measured memory_bytes: 640
// B - Exponential

#include <bits/stdc++.h>
using namespace std;

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

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      int k = N - i - j;
      if (k < 0) {
        break;
      } else if (Y == 10000 * i + 5000 * j + 1000 * k) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
use std::io;
use std::io::{stdin, Read};
use std::process::exit;

fn main() {
    let mut input_line: String = String::new();
    stdin().read_line(&mut input_line).expect("Err");
    let inputs: Vec<&str> = input_line.split_whitespace().collect();

    let r:i32 = inputs[1].to_string().parse().unwrap();
    let mut l:i32 = inputs[0].to_string().parse().unwrap();
    let d:i32 = inputs[2].to_string().parse().unwrap();

    let mut ans = 0;

    while l!=(r+1){
        if l % d == 0{
            ans += 1;
        }
        l += 1;
    }

    println!("{}", ans);

}	

Measured memory_bytes: 2064
N, M = map(int, input().split())
g = [[] for _ in range(N)]
in_deg = [0] * N
for _ in range(M):
  x, y = map(int, input().split())
  g[x - 1].append(y - 1)
  in_deg[y - 1] += 1
dist = [0] * N
q = [x for x in range(N) if in_deg[x] == 0]
while q:
  v = q.pop()
  for u in g[v]:
    dist[u] = max(dist[u], dist[v] + 1)
    in_deg[u] -= 1
    if in_deg[u] == 0:
      q.append(u)
print(max(dist))


Measured memory_bytes: 59168
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int n,l;
  cin >> n >> l;
  vector <string> s;
  REP(i,n){
    string str;
    cin >> str;
    s.pb(str);
  }
  sort(s.begin(),s.end());
  REP(i,n){
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }


double keisan(int d, int e, int f) {
	d = gcd(d, e);
	d = gcd(d, f);
	return d;
}

int main() {
	int N;
	cin >> N;
	int i, j, k, sum = 0;
	for (i = 1; i<= N; i++) {
		for (j = 1; j <= N; j++) {
			for (k = 1; k <= N; k++) {
				sum = sum + keisan(i, j, k);
			}
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3636
//arc067_c.cpp
//Sat Jun  9 11:57:17 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

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

	int yakusu = 0;
	int num[1000000]={};

	int maxa = 0;

	for (int i=2;i<=n;i++){
		int a = 2;
		int temp = i;
		while (i>=a*a){
			if (temp%a == 0){
				num[a]++;
				temp = temp/a;
				if (a > maxa){
					maxa = a;
				}
			}else {
				a++;
			}
		}
		if (temp > maxa){
			maxa = temp;
		}
		num[temp]++;
	}

	ll ans = 1;
	for (int i=2;i<=maxa;i++){
		ans = (ans *(num[i]+1))%1000000007;
	}

	cout << ans << endl;
}

Measured memory_bytes: 4224
#include<iostream>
#include<vector>
#include<algorithm>

#define REP(n) for(int i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 1000000005

int main(){

    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
       cin >> a[i];
    }

    ll ans = 0;
    for(int i = 0;i < n;i++){

        if(i == n-1){
            ans+=k;
        }else{
            ans += min(k,a[i+1]-a[i]);
        }
        //cout << ans << endl;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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; }

int n;
// 正しい値以下ならtrue
bool isOk(vector<ll> a, ll p) {
	ll temp = p;
	rep(i,n) {
		//cout << "i:" << i << " temp:" << temp << " a[i]:" << a[i] << endl;
		if(a[i] < temp && i%2 == 0) return false;
		else if(a[i] < temp && i%2 == 1) return true;
		else temp = a[i] - temp;
	}
		//cout << "p:" << p << " temp:" << temp << endl;
	if (p == temp) return true;
	else if (p < temp) {
		//cout << "p:" << p << " temp:" << temp << endl;
		return true;
	}
	else if (p > temp) {
		//cout << "p:" << p << " temp:" << temp << endl;
		return false;
	}
}

ll binary_search(vector<ll> a, ll max) {
	ll left = 0, right = max+1;
	while(right - left > 1) {
		int mid = (right + left) / 2;
		//cout << "left:" << left << " right: " << right << " mid:" << mid << endl;
		//cout << "calc: " << calc(a,mid) << endl;
		if(isOk(a, mid)) left = mid;
		else right = mid;
	}
	return left;
}
int main() {
	cin >> n;
	vector<ll> a(n);
	ll max = -1e18;
	rep(i,n) {
		cin >> a[i];
		chmax(max, a[i]);
	}
	vector<ll> ans(n);
	
	ans[0] = binary_search(a, max);
	for(int i=1; i<n; i++) {
		ans[i] = a[i-1] - ans[i-1];
	}
	rep(i,n) {
		cout << ans[i]*2;
		if (i != n-1) cout << " ";
		else cout << endl;
	}


  return 0;
}


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

using namespace std;

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

    int a[100];
    int to0 = 0;
    int toN = 0;
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        if (a[i] < x) {
            to0++;
        } else if (a[i] > x) {
            toN++;
        }
    }

    cout << min(to0, toN) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, sum = 0; cin >> N;
    for (int i = 0; i < N; i++) {
        int left, right; cin >> left >> right;
        sum += (right - left) + 1;
    }
    printf("%d\n", sum);
}


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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;

//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define SORT(V) sort((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//main
//------------------------------------------
int main() {
  int H, W;
  cin >> H >> W;
  VS a(H);
  REP(i, H){
      cin >> a.at(i);
  }

  VB goodx(H), goody(W);

  REP(i, H){
    REP(j, W){
      if(a.at(i).at(j)=='#'){
        goodx.at(i)=true;
        goody.at(j)=true;
      }
    }
  }

  REP(i, H){
    if(goodx.at(i)){
      REP(j, W){
        if(goody.at(j)){
          cout << a.at(i).at(j);
        }
      }
      cout << endl;
    }
  }










}


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

const int INF = 2e9;

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n,vector<int>(m));
    vector<int> c(n);
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    int ans = INF;
    rep(s,1<<n){
        int cost = 0;
        vector<int> d(m);
        rep(i,n){
            if(s>>i&1){
                cost += c[i];
                rep(j,m) d[j] += a[i][j];
            }
        }
        bool ok = true;
        rep(j,m) if(d[j] < x) ok = false;
        if(ok) ans = min(ans,cost);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3572
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int n = in();
  vector<int> a(n);
  cin >> a;
  if (prev_permutation(all(a))) cout << a << endl;
  next_permutation(all(a));
  cout << a << endl;
  if (next_permutation(all(a))) cout << a << endl;
}



Measured memory_bytes: 3088
def main():
    _ = int(input())
    A = list(map(int, input().split()))
    min_value = 1e10
    cnt = 0
    for a in A:
        if a <= min_value:
            min_value = a 
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 24744
#include<bits/stdc++.h>
using namespace std;
int main(){
    char s[100];
    int k;
    cin>>k;
    cin>>s;
    if(strlen(s)<=k){
        for(int i=0;i<strlen(s);i++){
            cout<<s[i];
        }
    }else{
        for(int i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"...";
    }
    cout<<'\n';

return 0;
}


Measured memory_bytes: 3624
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
/*istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}*/
const ll INF=1e9+7;

// x 以下のルンルン数が何個あるか
long long calc(long long x) {
    // x を文字列にする
    stringstream ss;
    ss << x;
    string S = ss.str();
    int N = S.size();

    long long dp[20][11][2] = {0};
    dp[1][10][1] = 1;
    for (int j = 1; j < S[0]-'0'; ++j) dp[1][j][1] = 1;
    dp[1][S[0]-'0'][0] = 1;
    for (int i = 1; i < N; ++i) {
        // from j = 10
        for (int add = 1; add <= 10; ++add)
            dp[i+1][add][1] += dp[i][10][1];

        // from j = 0 ~ 9
        for (int j = 0; j < 10; ++j) {
            for (int k = -1; k <= 1; ++k) {
                int add = j + k;
                if (add < 0 || add > 9) continue;

                dp[i+1][add][1] += dp[i][j][1];
                if (add < S[i]-'0') 
                    dp[i+1][add][1] += dp[i][j][0];
                else if (add == S[i]-'0')
                    dp[i+1][add][0] += dp[i][j][0];
            }
        }
    }
    long long res = 0;
    for (int j = 0; j < 10; ++j) res += dp[N][j][0] + dp[N][j][1];
    return res;
}


int main()
{
    int K;
    cin >> K;
    long long left = 0, right = 1LL<<50;
    while (right - left > 1) {
        long long x = (left + right) / 2;
        if (calc(x) >= K) right = x;
        else left = x;
    }
    cout << right << endl;
    return 0;
} 


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def main():
    n, a, b, c, d = map(int, input().split())
    memo = {}
    def dfs(x):
        if x == 0:
            return 0
        elif x == 1:
            return d
        elif x in memo:
            return memo[x]
        else:
            ret = min(
                d * x,
                d * (x - x//2*2) + a + dfs(x//2),
                d * ((x+1)//2*2 - x) + a + dfs((x+1)//2),
                d * (x - x//3*3) + b + dfs(x//3),
                d * ((x+2)//3*3 - x) + b + dfs((x+2)//3),
                d * (x - x//5*5) + c + dfs(x//5),
                d * ((x+4)//5*5 - x) + c + dfs((x+4)//5)
            )
            memo[x] = ret
            return ret
    print(dfs(n))

t = int(input())
for i in range(t):
    main()

Measured memory_bytes: 20056
#include <iostream>

using namespace std;

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if (x >= 0 &&
        x + r <= W &&
        y >= 0 &&
        y + r <= H)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>PP;
int main(){
  int h,w;
  int dy[4]={-1,0,1,0};
  int dx[4]={0,1,0,-1};
  char maps[1005][1005];
  queue<PP>que;
  
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>maps[i][j];
      if(maps[i][j]=='#'){
        que.push(PP(0,P(i,j)));
      }
    }
  }
  
  int maxim=0;
  while(!que.empty()){
    PP now=que.front();que.pop();
    int num=now.first;
    int y=now.second.first,x=now.second.second;
    for(int i=0;i<4;i++){
      int ny=y+dy[i];
      int nx=x+dx[i];
      if(maps[ny][nx]=='.'&&ny>=0&&ny<=h-1&&nx>=0&&nx<=w-1){
        maxim=max(maxim,num+1);
        que.push(PP(num+1,P(ny,nx)));
        maps[ny][nx]='#';
      }
    }
  }
  
  cout<<maxim<<endl;
  return(0);
}


Measured memory_bytes: 13328
N = int(input())
pos_list = [[0] * 2 for i in range(N)]
for i in range(N):
    X, L = map(int, input().split())
    pos_list[i] = [X + L, X - L]
    # pos_list.append([X + L, X - L])
sorted_data = sorted(pos_list)
# print(pos_list)
ans = 0
current = -(10 ** 9)
for val in sorted_data:
    if current <= val[1]:
        ans += 1
        current = val[0]
print(ans)


Measured memory_bytes: 25164
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

for bit in range(1 << d): #d個左にシフトする。d=2なら100となって十進法なら4。
    count = 0
    sum = 0
    nokori = [i+1 for i in range(d)]

    for i in range(d): #与えられbitにおいてすべて足し算する。
        if bit & (1 << i):
            sum += pc[i][0] * (i + 1) * 100 + pc[i][1]
            count += pc[i][0]
            nokori.remove(i + 1)

    # G 点に満たなければ nokori のうち一番大きいものを解く
    if sum < g:
        use = max(nokori)
        n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
        count += n
        sum += n * use * 100

    if sum >= g:
        ans = min(ans, count)

print(ans)

Measured memory_bytes: 3064
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product#accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
def run():
    A,B,H,M = map(int, input().split())
    t_h = (H + M /60) / 12 * 2 * math.pi
    xh = A * math.cos(t_h)
    yh = A * math.sin(t_h)

    t_m = M * math.pi / 30
    xm = B * math.cos(t_m)
    ym = B * math.sin(t_m)

    L = (xh - xm) ** 2 + (yh - ym) ** 2
    L = math.sqrt(L)
    print(L)

if __name__ == "__main__":
    run()

Measured memory_bytes: 9528
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

ll N, x;
ll a[100005];
ll ans;

void solve() {
	for (int i = 0; i < N - 1; i++) {
		if (a[i] + a[i + 1] <= x) continue;
		ll r = (a[i] + a[i + 1]) - x;

		ll tmp = min(r, a[i + 1]);
		a[i + 1] -= tmp;
		r -= tmp;
		ans += tmp;

		tmp = min(r, a[i]);
		a[i] -= tmp;
		r -= tmp;
		ans += tmp;

	}

	//_PA(a, N);

	cout << ans << endl;
}

int main() {
	cin >> N >> x;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	solve();
	return 0;
}




Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
	while(true){
		int n;
		cin >> n;
		if(n==0){
			break;
		}
		const int MAXN=100;
		int a[MAXN];

		for(int i=0; i<n; i++){
			cin >> a[i];
		}
		int max=a[0], min=a[0], kei=0;
		for(int i=0; i<n; i++){
			if(max < a[i]){
				max=a[i];
			}
			if(min > a[i]){
				min=a[i];
			}
			kei+=a[i];
		}
		int heikin;
		heikin=(kei-max-min)/(n-2);
		cout << heikin << endl;
	}

	return 0;
}

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

int main() {
   int N,M;
   cin>>N >> M;
   vector<int> A(M);
   for(int i=0;i<M;i++ ){
       cin>>A.at(i);
   }
   for(int i=0;i<M;i++){
       N-=A.at(i);
   }
   if(N<0){
       cout<< -1 <<endl;
   }
   else{
       cout<< N <<endl;
   }




}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

ll N,K;

typedef pair<ll,ll> ll2;

void compute() {

}

int main() {
  cin >> N >> K;
  vector<ll2> vec(N);
  rep(i,N) {
    cin >> vec[i].first >> vec[i].second;
  }
  sort(ALL(vec));
  ll sum = 0;
  rep(i,(int)vec.size()) {
    sum += vec[i].second;
    if( sum >= K ) {
      cout << vec[i].first << endl;
      return 0;
    }
  }
  
  compute();
  return 0;
}


Measured memory_bytes: 1792
// ProblemURL : https://atcoder.jp/contests/abc094/tasks/abc094_a
// ---------------------------------------------
package main

import "fmt"

func main() {
	var a, b, x int
	fmt.Scan(&a, &b, &x)

	if a <= x && x <= a+b {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
def main():
    N, K = map(int, input().split())
    AB = []
    for i in range(N):
        a, b = map(int, input().split())
        AB.append([a, b])
    AB.sort(key=lambda x: x[0])

    c = 0
    for a, b in AB:
        if K <= c + b:
            ans = a
            break
        c += b
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 21248