akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define db double
#define lowbit(p) (p&(-p))
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define A first
#define B second
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
/*
题意:
有一棵树,每个节点的权值v_x都要满足v_fa[x]<=v_x<=v_fa[x]+d

要求在v_x*p_x总和小于等于C
然后要所有节点的v_x的值最大
*/
#define M 55
struct ed{
	int x,nx;	
}e[M];
int nx[M],ecnt=1,fa[M*M*M];
void add(int x,int y){
	e[ecnt]=(ed){y,nx[x]};
	nx[x]=ecnt++;
}
struct node{
	ll cost,val,num;
}a[M];
ll v[M],V,d,dp[M*M*M];
int cnt[M],tot,n;
#define inf 1000000000
int m;
ll sz[M];
void dfs(int f,int x){
	cnt[x]=1;
	for (int i=nx[x];i;i=e[i].nx)if (e[i].x!=f){
		dfs(x,e[i].x);
		cnt[x]+=cnt[e[i].x];
		v[x]+=v[e[i].x];
	}
//	printf("%d %lld %d\n",x,v[x],cnt[x]);
	if (f)a[++tot]=(node){v[x],cnt[x],d};
				      //  cost  val  num
}
//多重背包
/*
容量范围在1e9
不过物品个数很少..?

那么问题就转化成
50种物品的多重背包
容量权值还有价值都是1e9的

看了题解
靠
好厉害


struct node{
	ll cost,val,num;
}a[M];
*/
bool cmp(node a,node b){
	//不会爆longlong
	return a.val*b.cost>b.val*a.cost;
}
ll chk(ll V){
	ll res=0;
	int i;
	ll tmp;
	for (i=1;i<=n;i++){
		tmp=min(sz[i],V/a[i].cost);
		res+=tmp*a[i].val;
		V-=a[i].cost*tmp;
	}
	return res;
}
void cal(){
	sort(a+1,a+tot+1,cmp);
	int i,j,k;
	m=0;
	for (i=1;i<=tot;i++){
		sz[i]=max(0ll,a[i].num-50);
		Min(a[i].num,50);
		m+=a[i].num*a[i].val;
	}
	for (i=1;i<=m;i++){
		dp[i]=V+1;
	}
	for (i=1;i<=tot;i++){		
		for (j=1;j<=a[i].num;j*=2){
			a[i].num-=j;
			for (k=m;k>=0;k--)if (dp[k]<=V&&k+j*a[i].val<=m){
				Min(dp[k+j*a[i].val],dp[k]+j*a[i].cost);
			}
		}
		j=a[i].num;
		for (k=m;k>=0;k--)if (dp[k]<=V&&k+j*a[i].val<=m){
			Min(dp[k+j*a[i].val],dp[k]+j*a[i].cost);
		}		
	}
	/*
		for (i=1;i<=tot;i++){
//		printf("i=%d num=%lld cost=%lld val=%lld\n",i,a[i].num,a[i].cost,a[i].val);
		for (k=m;k>=0;k--)if (dp[k]<=V){
			for (j=1;j<=a[i].num&&k+j*a[i].val<=m;j++){
//				nk=j*a[i].val+k;
				Min(dp[k+j*a[i].val],dp[k]+j*a[i].cost);
			}
		}
	}
	*/
	ll res=0;
	for (i=0;i<=m;i++)if (dp[i]<=V){
		Max(res,i+chk(V-dp[i]));
	}
	printf("%lld\n",res);
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	freopen("1.in","r",stdin);
	read(n); read(V); read(d);
	int i;
	read(v[1]);
	for (i=2;i<=n;i++){
		read(v[i]);
		read(fa[i]);
		add(fa[i],i);
	}
	dfs(0,1);
	a[++tot]=(node){v[1],cnt[1],V};
	cal();
	return 0;
}

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


int main(void){
  int a[3], b[3], c[4] = {0}, k, aa, bb;
  rep(i, 3){
    scanf("%d %d", &a[i], &b[i]);
    c[a[i] - 1]++;
    c[b[i] - 1]++;
  }
  if(c[0] > 2 || c[1] > 2 || c[2] > 2 || c[3] > 2){
    
    printf("NO");
  }else{
    printf("YES");
  }

}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char S[100001];
	scanf("%s", S);
	
	int l, r, n;
	for (n = 0; S[n] != 0; n++);
	for (l = n / 2; l > 0 && S[l] == S[l-1]; l--);
	for (r = (n - 1) / 2; r < n - 1 && S[r] == S[r+1]; r++);
	if (l < n - r - 1) printf("%d\n", r + 1);
	else printf("%d\n", n - l);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1800
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var k = int.Parse(Console.ReadLine());
        long res = 0;
        Func<int, int, int> yug = (a, b) =>
        {
            int r = 201;
            while (true)
            {
                r = a % b;
                if (r == 0) break;
                a = b;
                b = r;
            }
            return b;
        };
        for (var al = 1; k >= al; al++)
        {
            for (var bl = 1; k >= bl; bl++)
            {
                for (var cl = 1; k >= cl; cl++)
                {
                    int a = al;
                    int b = bl;
                    int c = cl;
                    b = yug(a, b);
                    a = b;
                    b = c;
                    b = yug(a, b);
                    res += b;
                }
            }
        }
        Console.WriteLine(res);
    }
}

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

int main() {
  int s; cin >> s;
  set<int> st;
  int x = s;
  while (st.count(x) == 0) {
    st.insert(x);
    if(x % 2 == 0) {
      x = x / 2;
    }
    else {
      x = x * 3 + 1;
    }
  }
  cout << st.size() + 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a;
  cin >> a;
  if(a >= 65 && a <= 90){
    cout << 'A' << endl;
  }
  else if(a >= 97 && a <= 122){
    cout << 'a' << endl;
  }
}

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
 
int main()
{
int N,K,s[100],b,i,j;
bool f;
while(cin>>N>>K,N|K){
for(i=0;i<K;i++)cin>>s[i];
for(j=0;j<N;j++)for(i=0;i<K;i++){cin>>b;s[i]-=b;}
f=1;
for(i=0;i<K;i++)if(s[i]<0)f=0;
if(f) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}

Measured memory_bytes: 852
import copy

n = int(input())

p_list_org = list(map(int,input().split()))

p_list = copy.deepcopy(p_list_org)

p_list.sort()

cnt = 0
for i in range(n):
    if p_list[i] != p_list_org[i]:
        cnt += 1
    else:
        pass

if cnt <= 2:
    print("YES")
else:
    print("NO")



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

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

int main(){
  int k;
  int ans=0;
  cin >>k;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
        ans+=gcc(i,gcc(j,l));
      }
    }
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>

#define N 100001

int A[N];
char X[N];
int Number[N];
char C[N];

void quic_sort(int , int );
void Swap1(int* , int* );
void Swap2(char* , char* );
int Check(int );
int Partition(int , int );

int main()
{
  int n, i;
  scanf("%d", &n);
  for(i=0 ; i<n ; i++)
  {
    getchar();
    scanf("%c%d", &X[i], &A[i]);
  }
  for(i=0 ; i<n ; i++)
  {
    Number[i] = A[i];
    C[i] = X[i];
  }
  quic_sort(0, n-1);
  printf("%s\n", (Check(n) ? "Stable" : "Not stable"));
  for(i=0 ; i<n ; i++) printf("%c %d\n", X[i], A[i]);
  return 0;
}

void Swap1(int* a, int* b)
{
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void Swap2(char* a, char* b)
{
  char tmp = *a;
  *a = *b;
  *b = tmp;
}

int Partition(int p, int r)
{
  int x = A[r];
  int i = p - 1, j;
  for(j=p ; j<r ; j++)
  {
    if(A[j] <= x)
    {
      i++;
      Swap1(&A[i], &A[j]);
      Swap2(&X[i], &X[j]);
    }
  }
  Swap1(&A[i+1], &A[r]);
  Swap2(&X[i+1], &X[r]);
  return i+1;
}

void quic_sort(int p, int r)
{
  if(p < r)
  {
    int q = Partition(p, r);
    quic_sort(p, q-1);
    quic_sort(q+1, r);
  }
}

int Check(int n)
{
  int i, j;
  for(i=1 ; i<n ; i++)
  {
    if(A[i-1] == A[i])
    {
      int a, b;
      for(j=0 ; j<n ; j++)
      {
        if(A[i-1] == Number[j] && X[i-1] == C[j]) a = j;
        if(A[i] == Number[j] && X[i] == C[j]) b = j;
      }
      if(a > b) return 0;
    }
  }
  return 1;
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e9;

int main() {
  ll n, ans = 0, mn = INF, p = 1;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll dp[n + 1][2];
  dp[0][0] = 0;
  dp[0][1] = -INF;
  rep(i, n) {
    dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
    dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
  }
  cout << dp[n][0] << endl;
  return 0;
}


Measured memory_bytes: 2560
from sys import stdin
input = stdin.readline

s = "abcdefghijklmnopqrstuvwxyz"
n = int(input())
res = ""

while n:
    if n % 26 == 0:
        res += "z"
    else:
        res += s[(n - 1) % 26]
    n = (n - 1) // 26

print(res[::-1])

Measured memory_bytes: 9172
#include<iostream>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
int N,M;
main()
{
	cin>>N>>M;
	int ans=1;
	UF uf(N);
	for(int i=0;i<M;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		uf.unite(a,b);
		int now=uf.size(a);
		if(ans<now)ans=now;
	}
	cout<<ans<<endl;
}


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

#define MOD 1000000007

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

  vi a, b;
  rep(i, n)
  {
    ll _a;
    cin >> _a;
    a.push_back(_a);
  }

  rep(i, m)
  {
    ll _b;
    cin >> _b;
    b.push_back(_b);
  }

  int ans = 0;

  ll a_k = 0;
  int a_index = -1;

  ll b_k = 0;
  int b_index = -1;

  // b全部読む
  while(b_index + 1 < b.size()) {
    b_index++;
    b_k += b[b_index];
  }

  for (int i = 0; i <= n; i++)
  {
    if (i > 0)
    {
      a_index++;
      a_k += a[a_index];
    }

    // bを減らす
    while (a_k + b_k > k && b_index >= 0)
    {
      b_k -= b[b_index];
      b_index--;
    }

    if (a_k + b_k <= k)
    {
      ans = max(ans, a_index + b_index + 2);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int x,y;
	cin >> x >> y;
	if(x % y == 0) cout << -1 << endl;
	else cout << x * (y - 1) << endl;
	return 0;
}

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


int main() {

  ll N;
  cin >> N;
  string S;
  cin >> S;
  ll ans = 1;
  char s_old = S[0];
  if (N == 1) cout << ans << endl;
  else {
    for (ll i = 1; i < N; ++i) {
      char s_new = S[i];
      if (s_old != s_new) ans++;
      s_old = s_new;
    }
    cout << ans	<< endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int MAXN = int(1E5);
const int INF = (1<<30);
char s[MAXN + 5];
vector<int>vec;
int main() {
	scanf("%s", s+1);
	int len = strlen(s+1);
	for(int i=0;i<26;i++) {
		vec.clear();
		for(int j=1;j<=len;j++)
			if( s[j] == 'a' + i )
				vec.push_back(j);
		for(int j=0;j<vec.size();j++)
			vec[j] = 2 * j - vec[j];
		int Max = -INF, mx;
		for(int j=vec.size()-1;j>=0;j--) {
			if( Max >= vec[j] ) {
				printf("%d %d\n", (2*j - vec[j]), (2*mx - Max));
				return 0;
			}
			else Max = vec[j], mx = j;
		}
	}
	puts("-1 -1");
}

Measured memory_bytes: 768
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){
    int n; cin >> n;
    vector<ll> A(n); rep(i, n) cin >> A[i];
    ll GCD = A[0];
    rept(i, 1, n){
        GCD = __gcd(GCD, A[i]);
    }
    cout << GCD << ln;
}


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

int main(){
    int n,m;
    while(cin>>n>>m,n||m){
        vector<pair<int,pair<int,int>>> v(m);
        vector<int> used(n,0);
        used[0]=1;
        rep(i,m){
            cin>>v[i].first>>v[i].second.first>>v[i].second.second;
        }
        sort(v.begin(),v.end());
        rep(i,m){
            if(used[v[i].second.first-1]) used[v[i].second.second-1]=1;
        }
        int ans=0;
        rep(i,n){
            ans+=used[i];
        }
        cout<<ans<<endl;
    }
}

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

map<int,int> cnt;
int n, a, mx1, mx2, mx3;
long long ans;

int main(){
	scanf("%d", &n);
	for (int i=1; i<=n; i++){
		scanf("%d", &a);
		cnt[a]++;
	}
	for (map<int,int>::iterator it = cnt.begin(); it != cnt.end(); it++){
		if (it->second >= 4){
			mx3 = max(mx3, it->first);
		}
		if (it->second >= 2){
			if (it->first > mx1){
				mx2 = mx1;
				mx1 = it->first;
			}
			else if (it->first > mx2)
				mx2 = it->first;
		}
	}
	ans = max(1LL*mx3*mx3, 1LL*mx1*mx2);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<array>
#include<string>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	
	for (int i = 0; i < 2; i++) {
		if (a <= b) {
			ans = ans + b;
			b--;
		}
		else if (b < a) {
			ans = ans + a;
			a--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    
	  Scanner sc = new Scanner(System.in);
	  int x = sc.nextInt();
	  
	  int y = x;
	  
	  for(int i = 0 ; i < 2 ; i++){
		  y = y * x;
	  }
	  
	  System.out.println(y);
	  
  }
} 

Measured memory_bytes: 26140
#include<bits/stdc++.h>
using namespace std;
int t;
string s, ans[3] = {"Sunny", "Cloudy", "Rainy"};
int main(){
	cin >> s;
	if(s == ans[0]) t = 1;
	else if(s == ans[1]) t = 2;
	else t = 0;
	cout << ans[t] << "\n";
}

Measured memory_bytes: 256
import math

c60 = math.cos(math.radians(60))
s60 = math.sin(math.radians(60))

def koch(d, p1, p2):
    if d == 0: return

    sx = (2 * p1[0] + p2[0]) / 3
    sy = (2 * p1[1] + p2[1]) / 3

    tx = (p1[0] + 2 * p2[0]) / 3
    ty = (p1[1] + 2 * p2[1]) / 3

    dx = tx - sx
    dy = ty - sy

    ux = dx * c60 - dy * s60 + sx
    uy = dx * s60 + dy * c60 + sy

    koch(d-1, p1, (sx, sy))
    print('{0:.8f} {1:.8f}'.format(sx, sy))

    koch(d-1, (sx, sy), (ux, uy))
    print('{0:.8f} {1:.8f}'.format(ux, uy))

    koch(d-1, (ux, uy), (tx, ty))
    print('{0:.8f} {1:.8f}'.format(tx, ty))

    koch(d-1, (tx, ty), p2)

n = int(input())

ax = 0
ay = 0

bx = 100
by = 0

print('{0:.8f} {1:.8f}'.format(ax, ay))
koch(n, (ax, ay), (bx, by))
print('{0:.8f} {1:.8f}'.format(bx, by))

Measured memory_bytes: 7948
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 



int32_t main()
{
	IOS
	int n;cin>>n;
	vi A(n+2),B(n+1);
	for(int i=1;i<=n+1;i++)cin>>A[i];
	for(int i=1;i<=n;i++)cin>>B[i];
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int mn1=min(A[i],B[i]);
		ans+=mn1;
		B[i]-=mn1;
		A[i]-=mn1;
		
		int mn2=min(B[i],A[i+1]);
		ans+=mn2;
		B[i]-=mn2;
		A[i+1]-=mn2;
	}
	cout<<ans<<endl;

}


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

int main() {
  int n;
  cin>>n;
  int64_t friends[n];
  for(int i=0; i<n; i++) cin>>friends[i];

  int64_t ans = 0;
  sort(friends, friends+n, greater<int64_t>());

  // for(int i=0; i<n-1; i++) ans += friends[i];
  ans = friends[0];
  int count = 1;
  if(n%2==0) {
    for(int i=1; i<n/2; i++) ans+=friends[i]*2;
  }
  else {
    for(int i=1; i<n/2; i++) ans+=friends[i]*2;
    ans += friends[n/2];
  }


  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 5116
#include<stdio.h>
 
#define N 100
 
static const int MAX = 500;
static const int INFTY = (1<<21);
 
main(){
  int l, i, j, x, v,c=0,k=0;
  int u = 0,mincost = 0;
  int cost[N];
  int d[N];
  int p[N],M[N][N];
   
   
  scanf("%d", &l);
  for ( i = 0; i< l; i++ ){
    for ( j = 0; j < l; j++ ){
      M[i][j] = INFTY;
    }
  }
   
  for ( i = 0; i < l; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }
  
  for(i=0;i < l;i++){
    d[i] = INFTY;
    p[i] = -1;
    cost[i] = 0;
  }
  
  d[0] = 0;
  
  while(1){
    u = -1;
    mincost = INFTY;
     
    for(i=0;i < l;i++){
      if(d[i] < mincost && cost[i] == 0){
	mincost = d[i];
	u = i;
      }
    }
    
    if(u == -1) break;
          
    cost[u] = 1;
    
    for(v=0;v <l;v++){
      if(d[v] > d[u]+M[u][v]){
	p[v] = u;
	d[v] = d[u]+M[u][v];
      }
    }
  }
  
  for ( i = 0; i < l; i++ ){
    printf("%d %d\n", i, (d[i]==INFTY?-1:d[i]));
  }
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

bool comp(tuple<ll,ll,string> a,tuple<ll,ll,string> b){
	return (get<1>(a) < get<1>(b));
}

void solve(int n,int q){
	vector<tuple<ll,ll,string>> v(n);
	ll x,y;
	rep(i,n){
		cin>>get<2>(v[i])>>x>>y;
		get<0>(v[i])=y-x+1;
		get<1>(v[i])=y;
	}
	sort(all(v),[](auto &a,auto &b){
		return get<0>(a)<get<0>(b);
	});
	v.push_back(tuple<ll,ll,string>(LINF,LINF+1,""));
	while(q--){
		cin>>x;
		tuple<ll,ll,string> z=make_tuple(0ll,x,"");
		auto itr=lower_bound(all(v),z,comp);
		if(get<0>(*itr)<=x&&itr!=v.end()-1){
			cout<<get<2>(*itr)<<" "<<x-get<0>(*itr)+1<<"\n";
		}
		else{
			cout<<"Unknown\n";
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,q;
	while(cin>>n>>q,n)solve(n,q);
}


Measured memory_bytes: 3280
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

bool cmp(pair<int,int> &a,pair<int,int> &b){
	return a.F<b.F;
}

void solve(int test_case) {//234 Coloring Colorfully
	int n,m;
	cin>>n>>m;
	vpii arr(n);
	REP(i,0,n-1){
		int a,b;
		cin>>a>>b;
		arr[i]={a,b};
	}
	sort(arr.begin(),arr.end(),cmp);
	ll sum = 0;
	for(auto i:arr) {
		int req = min(i.S,m);
		sum+=req*(ll)i.F;
		m-=req;
	}
	cout<<sum;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3984
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();
		int sum=0;
		int cnt=0;
		if(n>=(h+w)){
			if(h>w){
				for(int x=0;sum<n;x++){
					sum = sum+h;
					cnt++;
				}
				System.out.println(cnt);
			}else if(w>h){
				for(int y=0;sum<n;y++){
					sum=sum+w;
					cnt++;
				}
				System.out.println(cnt);
			}else{
				for(int z=0;sum<n;z++){
					sum=sum+h;
					cnt++;
				}
				System.out.println(cnt);
			}
		}else if(n>=h||n>=w){
			cnt=1;
			System.out.println(cnt);
		}else{
			cnt=1;
			System.out.println(cnt);
		}
	}

}


Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

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

long long dp[100][2];
const int MAX_DIGIT = 50;


// dp[ i ][ smaller ] := X
// X を上から i 桁目まで決めたとき、それを K
// K の上から i 桁目までと比較したときに、
// smaller = 0 のとき、K とちょうど一致する場合
// smaller = 1 のとき、K よりも小さくなっている場合についての、スコアの最大値

int main(){
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N);
    for(int i = 0 ; i < N; ++i) cin >> A[i];

    memset(dp, -1, sizeof(dp)); // -1に初期化
    dp[0][0] = 0;
    for(int d= 0; d < MAX_DIGIT; ++d){
        long long mask = 1LL << (MAX_DIGIT - d - 1);

        // A で元々 d 桁目にビットが立っているものの個数
        int num = 0;

        for(int i=0; i < N; ++i){
            if(A[i] & mask ) ++ num;
        }

        // X の d 桁目を 0, 1 にしたときのコスト
        long long cost0 = mask * num;
        long long cost1 = mask * (N - num);

        //smaller --> smaller 
        if(dp[d][1] != -1 ){
            chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1)); // 0でも1でも可能
        }

        //exat --> smaller
        if(dp[d][0] != -1){
            // K の d 桁目が 1 だったら、X の d 桁目は 0 にする
            if(K & mask){
            chmax(dp[d+1][1], dp[d][0] + cost0);                
            }
        }

        //exact -- > exact
        if(dp[d][0] != -1){
            if(K & mask){
                chmax(dp[d+1][0], dp[d][0] + cost1);
            }else{
                chmax(dp[d+1][0], dp[d][0] + cost0);
            }
        }
    }

    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
}

Measured memory_bytes: 1024
def gcd(a,b): 
    if a == 0: 
        return b 
    return gcd(b % a, a) 
  
def lcm(a,b): 
    return (a*b) // gcd(a,b) 
  
n = int(input())
arr = input()   # takes the whole line of n numbers
a = list(map(int,arr.split(' ')))
l = a[0]
ans = 0
for i in range(n):
    l = lcm(l, a[i])
for i in range(n):
    ans = ans + l//a[i]
print(ans%1000000007)


Measured memory_bytes: 4084
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int N;
vector<string> res;

void dfs(char c, string &s) {
    if(s.size() == N) {
        res.emplace_back(s);
        return;
    }
        
    for(char k='a'; k<=c; k++) {
        char nc = (char)(c + (k == c));
        s += k;
        dfs(nc, s);
        s.pop_back();
    }
}

int main() {
    cin >> N;

    string a;
    dfs('a', a);

    sort(res.begin(), res.end());
    for(auto e : res) cout << e << endl;
    return 0;
}


Measured memory_bytes: 9588
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int n,m,a[50],b[50],c[50],d[50],ans,mina;
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++)
    scanf("%d %d",&a[i],&b[i]);
  for(int i=0;i<m;i++)
    scanf("%d %d",&c[i],&d[i]);
  for(int i=0;i<n;i++){
    ans=1;
    mina=abs(a[i]-c[0])+abs(b[i]-d[0]);
    for(int j=1;j<m;j++){
      if(mina>abs(a[i]-c[j])+abs(b[i]-d[j])){
        ans=j+1;
        mina=abs(a[i]-c[j])+abs(b[i]-d[j]);
      }
    }printf("%d\n",ans);
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

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

	string ans;
	n--;
	ans += n % 26 + 'a';
	while (true) {
		n /= 26;
		if (n == 0) break;
		n--;
		ans += n % 26 + 'a';
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}


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

long long dp[3005][3005];

long long solution(int n , int* arr , long long sum){
    
    for(int i=0 ; i<n ; i++){
        dp[i][i] = arr[i];
    }

    int i=0;
    int j=1;
    while(j<n){
        dp[i][j] = max(arr[i] , arr[j]);
        i++;
        j++;
    }
    
    for(int k=2 ; k<n ; k++){
        int i=0 ;
        int j=k;
        while(j<n){
            dp[i][j] = max(arr[i] + min(dp[i+1][j-1] , dp[i+2][j]) , arr[j] + min(dp[i][j-2] , dp[i+1][j-1]));
            i++;
            j++;
        }
    }

    // for(int i=0 ; i<n ; i++){
    //     for(int j=0 ; j<n ; j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

return (2*dp[0][n-1] - sum);

}



int main(){
    int n;
    cin>>n;
    int* arr = new int[n];
    long long sum = 0;
    for(int i=0 ; i<n ; i++){
        cin>>arr[i];
        sum += arr[i];
    }
    cout<<solution(n , arr , sum)<<endl;
}

Measured memory_bytes: 70016
import java .util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	Set<String> s = new HashSet<String>();
	for(int i=0;i<n;i++){
	    s.add( sc.next() );
	}
	System.out.print(s.size());
    }
}


Measured memory_bytes: 77072
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()

using namespace std;

typedef vector<int> vi;
typedef long long   ll;

int dx[] = {0 , 0 , 1 , -1 , 1 , 1 , -1 , -1};
int dy[] = {1 ,-1 , 0 , 0 , -1 , 1 ,  1 , -1};

int main()
{
    ll n;
    cin >> n;
    ll tmp = n , sum = 0;
    while(tmp){
        sum += tmp%10;
        tmp /= 10;
    }
    (n % sum == 0) ? cout<<"Yes"<<endl : cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
     
 int main(){
 int h,w;
 scanf("%d%d",&h,&w);
 int qes[h][w],j,i,ans[h*w][4],cnt=0; 
 for(i=0;i<h;i++){
  for(j=0;j<w;j++){
   scanf("%d",&qes[i][j]);
  }
 }
 for(i=h-1;i>0;i--){
  for(j=0;j<w;j++){
   if(qes[i][j]!=0){
    if(qes[i][j]%2==1){
     qes[i][j] -= 1;
     qes[i-1][j]+=1;
     ans[cnt] [0] =i+1;
     ans[cnt] [1] =j+1;
     ans[cnt] [2] =i;
     ans[cnt] [3] =j+1;
     cnt++;
    }
   }
  }
 }
 for(i=w-1;i>0;i--){
  if(qes[0][i]%2==1){
   qes[0][i]-= 1;
   qes[0][i-1]+=1;
   ans[cnt] [0] =1;
   ans[cnt] [1] =i+1;
   ans[cnt] [2] =1;
   ans[cnt] [3] =i;
   cnt++;
  }
 }
 printf("%d\n",cnt);
 for(i=0;i<cnt;i++){
  printf("%d %d %d %d\n",ans[i][0],ans[i][1],ans[i][2],ans[i][3]);
 } 
 return 0;
}
  

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> edges(n);
    vector<int> used(n,-1),l;
    vector<bool> loop(n,false);
    for (int i = 0;i < m;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
    }
    for (int i = 0;i < n;++i) if (used[i] < 0) {
        vector<int> s;
        s.push_back(i);
        used[i] = 0;
        while (!s.empty()) {
            int b = s.back();
            bool f = false;
            for (int& j : edges[b]) {
                if (used[j] < 0) {
                    s.push_back(j);
                    used[j] = 0;
                    f = true;
                    break;
                } else if (used[j] == 0) {
                    if (l.empty()) {
                        for (int k = s.size()-1;k >= 0;--k) {
                            l.push_back(s[k]);
                            loop[s[k]] = true;
                            if (s[k] == j) break;
                        }
                    }
                }
            }
            if (!f) {
                used[b] = 1;
                s.pop_back();
            }
        }
    }
    if (l.empty()) {
        cout << -1 << endl;
        return 0;
    }
    reverse(l.begin(),l.end());
    bool f = true;
    while (f) {
        f = false;
        int s = l.size();
        for (int i = 0;i < s;++i) {
            for (int& j : edges[l[i]]) if (loop[j] && l[(i+1)%s] != j) {
                f = true;
                bool g = true;
                for (int k = i+1;k < s;++k) {
                    if (l[k] == j) {
                        g = false;
                        break;
                    }
                    loop[l[k]] = false;
                }
                if (g) {
                    for (int k = 0;k < s;++k) {
                        if (l[k] == j) break;
                        loop[l[k]] = false;
                    }
                }
                break;
            }
            if (f) break;
        }
        vector<int> nl;
        for (int& i : l) if (loop[i]) nl.push_back(i);
        l = nl;
    }
    // p_ary(l,0,l.size());
    cout << l.size() << endl;
    for (int& i : l) cout << i+1 << "\n";
    return 0;
}

Measured memory_bytes: 256
def main():
    a, b, x = map(int, input().split())

    ans = 0
    if a == 0:
        # 割り切れる
        n_a = 0
        ans += 1
    else:
        # a未満で割り切れるものを除外する
        n_a = (a - 1) // x
    n_b = b // x
    ans += n_b - n_a

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ii a[1001];
ii b[1001];

ll dist(ii a, ii b)
{
	return (abs(a.fi-b.fi)+abs(a.se-b.se));
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].fi>>a[i].se;
	}
	for(int i=0;i<m;i++)
	{
		cin>>b[i].fi>>b[i].se;
	}
	for(int i=0;i<n;i++)
	{
		ll d=ll(1e18); int idx=-1;
		for(int j=0;j<m;j++)
		{
			if(dist(a[i],b[j])<d)
			{
				idx=j;
				d=dist(a[i],b[j]);
			}
		}
		cout<<idx+1<<'\n';
	}
}


Measured memory_bytes: 256
from operator import mul
from functools import reduce
from collections import Counter 
from itertools import accumulate

def comb(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

n,a,b = map(int, input().split())
v = list(map(int, input().split()))
c = Counter(v)
keys = sorted(c.keys(), reverse=True)
acc = [0] + list(accumulate([c[k] for k in keys]))
costs = [0] + list(accumulate([c[k]*k for k in keys]))

d = []
for lim in range(a,b+1):
    for i,k in enumerate(keys):
        if acc[i+1] >= lim:
            d.append((costs[i] + (lim - acc[i]) * k, lim, comb(c[k], lim - acc[i])))
            break
e = sorted([[x[0] / x[1],x[2]] for x in d], reverse=True)
cnt = 0
mx = e[0][0]
i =0
while i < len(e) and mx <= e[i][0]:
    cnt += e[i][1]
    i += 1

print('{:.8f}'.format(mx))
print(cnt)


Measured memory_bytes: 38640
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)

using namespace std;

const int N = (int)2e5 + 1;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

int n, a[N], b[N];

ll ok (ll val){
  ll sum = 0;
  forn (i, 1, n) sum += abs(a[i] - (i + val));
  return sum;
}

int main (){
  scanf ("%d", &n);
  forn (i, 1, n){
    scanf ("%d", a + i);
  }
  ll l = -1e13, r = 1e13;
  while (r - l > 1){
    ll mid = l + r >> 1;
    if (ok(mid) <= ok(mid + 1)) r = mid;
    else l = mid;
  }
  printf ("%lld\n", min(ok(l), ok(r)));
  return 0;
}


Measured memory_bytes: 1024
import collections
X = int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

for i in range(X):
  J = X - i
  d = collections.Counter(prime_factorize(J))
  dv = list(d.values())
  if len(set(dv)) == 1 and dv[0] >= 2:
    print(J)
    break
  if dv == []:
    print(1)
    break
  

Measured memory_bytes: 65432
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */

ll f(ll a, ll b) {
    return ((a % b != 0) ? (a + b) / b : a / b);
}

int main() {
    ll N, A, B; cin >> N >> A >> B;
    ll maxv = 0;
    ll h[N]; rep(i, N) cin >> h[i], maxv = max(maxv, h[i]);
    ll ng = 0, ok = maxv;
    while(ng + 1 < ok) {
        ll mid = (ng + ok) / 2;
        ll cnt = 0;
        rep(i, N) {
            if(h[i] - mid * B > 0) {
                cnt += (h[i]-mid*B+A-B-1)/(A - B);
            }
        }
        if(cnt > mid) {
            ng = mid;
        }else if(cnt <= mid) {
            ok = mid;
        }
    }
    cout << ok << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<algorithm>
using namespace std;
int c[100000];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%d",c+i);
		int ret=0;
		int count=0;
		for(int i=0;i<a;i++){
			if(c[i])count++;
			ret=max(ret,c[i]);
		}
		if(ret<2){
			printf("NA\n");
		}else printf("%d\n",count+1);
	}
}

Measured memory_bytes: 1076
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define mod 1000000007;
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,ans=0;
    cin>>n;
    ll arr[n+1];
    ll brr[n];
    for(int i=0;i<n+1;i++)
    cin>>arr[i];
    for(int i=0;i<n;i++)
    {
        cin>>brr[i];
        ans+=min(brr[i],arr[i]+arr[i+1]);
        arr[i+1]=max(0LL,min(arr[i]+arr[i+1]-brr[i],arr[i+1]));
    }
    cout<<ans;


    return 0;
}

Measured memory_bytes: 1792
package main

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

func main() {
	N := nextInt()

	p := 0
	q := 0

	for i := 0; i < N; i++ {
		p = p*10 + nextInt()
	}
	for i := 0; i < N; i++ {
		q = q*10 + nextInt()
	}

	rest := make([]int, 0)
	for i := 0; i < N; i++ {
		rest = append(rest, i+1)
	}

	cand := perm(0, rest)
	pr := -1
	qr := -1
	for i := 0; i < len(cand); i++ {
		if p == cand[i] {
			pr = i
		}
		if q == cand[i] {
			qr = i
		}
	}

	fmt.Println(abs(pr - qr))
}

func perm(curr int, rest []int) []int {
	if len(rest) == 0 {
		return []int{curr}
	}

	next := make([]int, 0)
	queue := make([]int, 0)

	for i := 0; i < len(rest); i++ {
		rest2 := make([]int, 0)
		for j := 0; j < len(queue); j++ {
			rest2 = append(rest2, queue[j])
		}
		for j := i + 1; j < len(rest); j++ {
			rest2 = append(rest2, rest[j])
		}

		next = append(next, perm(curr*10+rest[i], rest2)...)
		queue = append(queue, rest[i])
	}

	return next
}

func printArray(arr []int) {
	for i := 0; i < len(arr); i++ {
		print(arr[i])
		print(", ")
	}
	println()
}

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

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 4864
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        long x = in.nextLong();
        long y = in.nextLong();
        long mult = y / x;
        int res = 0;
        long cnt = 1;
        while (cnt <= mult) {
            res++;
            cnt *= 2;
        }
        out.println(res);

        out.close();
        //INT OVERFLOW -> USE LONG
        //ARR OUT OF BOUNDS
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public double[] nextDoubleArray(int n) {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextDouble();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        public char[] nextCharArray(int n) {
            char[] arr = nextLine().trim().replaceAll("\\s", "").toCharArray();
            return arr;
        }

        public String[] nextStringArray(int n) {
            String[] arr = new String[n];
            for (int i = 0; i < n; i++) {
                arr[i] = next();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 21076
use std::io::*;
use std::str::FromStr;
//portable utility
#[allow(dead_code)]
fn switch<T>(flag: bool, true_value: T, false_value: T) -> T {
    if flag {
        true_value
    } else {
        false_value
    }
}
#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
#[allow(dead_code)]
fn read_string() -> Vec<char> {
    read::<String>().chars().collect()
}
#[allow(dead_code)]
fn read_vector<T: FromStr>(number: usize) -> Vec<T> {
    (0..number).map(|_| read()).collect()
}
fn main() {
    let (n, m): (i32, i32) = (read(), read());
    let list: Vec<i32> = read_vector(m as usize);
    let sum: i32 = list.iter().sum();
    let days = n - sum;
    if days >= 0 {
        println!("{}", days);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 2168
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		 int table[] = {0, 1, 2, 3, 5, 7, 8, 9};
		
		int n = scanner.nextInt();
		while(n != 0) {
			int on = n;
			long num = 0;
			long deg = 1;
			while(on != 0) {
				int r = on % 8;
				num += deg * table[r];
				on -= r;
				on /= 8;
				deg *= 10;
			}
			System.out.println(num);

			n = scanner.nextInt();
		}
	}

}

Measured memory_bytes: 54948
import sys
# import math
# import queue
# import copy
# import bisect#2分探索
from collections import deque


def input():
    return sys.stdin.readline()[:-1]
def inputi():
    return int(input())

K=inputi()
vals=[10**5+1]*K
visit=[]
vals[1]=0
q = deque([1])
flag=False
while len(q)>0:
    s=q.popleft()
    vs=vals[s]
    if s==0:
        print(vs+1) 
        flag=True
        break
    #visit.append(s)
    s0=(10*s)%K

    if vs<vals[s0]:
        vals[s0]=vs
        q.appendleft(s0)
    s1=(s+1)%K

    if vs+1<vals[s1]:
        vals[s1]=vs+1
        q.append(s1)
    #print(q,s,s0,s1,vals)

#if flag==False:
#    print(vals[0]+1)


Measured memory_bytes: 42736
#include <cstdio>

const int MAXN=3e5+5;
int cnt[MAXN],sum[MAXN]; //sum[i]=sum_{ak<=i}{ak}+sum_{ak>i}{1}
int ans[MAXN];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1,x;i<=n;++i){
		scanf("%d",&x);
		++sum[++cnt[x]];
	}
	for(int i=2;i<=n;++i)
		sum[i]+=sum[i-1];
	for(int i=n,m=0;i;--i){
		while(i*(m+1)<=n && sum[m+1]>=i*(m+1))
			++m;
		ans[i]=m;
	}
	for(int i=1;i<=n;++i)
		printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N,ans=0;
	cin>>N;
	vector<int>A(N);
	REP(i,N) cin>>A[i];
	std::sort(A.begin(),A.end());
	
	int i=0;
	while(i<N){
		int co=1;
		//cout<<"b"<<endl;
		while(A[i]==A[i+1]){
			co++;
			i++;
			//cout<<"a"<<endl;
		}
		i++;
		if(co%2==1)ans++;
	}	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 640
// Created by sahim on 7/3/2020.
#include"bits/stdc++.h"
using namespace std ;
#define ll unsigned long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

template <class ...Args>
auto &log(const Args &...args) {return ((cerr << " " << args), ...) << '\n';}
#define watch(...)  cerr << "[ "#__VA_ARGS__" ] = "; log(__VA_ARGS__) << '\n'
//C++17
template<typename... Args>
void read(Args&... args){((cin >> args), ...);}
template<typename... Args>
void write(Args... args){((cout << args << " "), ...);}

const int mod = 1e9 +7 ;



int main() {
    IOS
    int n ;
    cin >>  n ;
     if(n%1000)cout << 1000 - n % 1000 <<'\n';
     else cout << 0 << '\n' ;
    return 0;

}




Measured memory_bytes: 3628