akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
#include<limits.h>
using namespace std;

int q,n,len;
string s;

inline bool check(int x,int A,int B){
	return len*x+(B-x)/len<=A;
}

void solve(int A,int B,int C,int D,char AA,char BB){
	s="";
	n=A+B;
	len=n/(B+1);
	int l=0,r=A/len+1;
	while(l+1<r){
		int mid=(l+r)>>1;
		if(check(mid,A,B)) l=mid;
		else r=mid;
	}
	r=(B-l)/len;
	A-=len*l+r;
	for(int i=C;i<=D;i++){
		if(i<=l*(len+1)) s+=((i%(len+1)==0)?BB:AA);
		else if(n-i+1<=r*(len+1)) s+=((n-i+1)%(len+1)==0?AA:BB);
		else s+=((i<=l*(len+1)+A)?AA:BB);
	}
}

int main(){
	scanf("%d",&q);
	while(q--){
		int A,B,C,D;
		scanf("%d%d%d%d",&A,&B,&C,&D);
		if(A>B) solve(A,B,C,D,'A','B');
		else{
			solve(B,A,A+B+1-D,A+B+1-C,'B','A');
			reverse(s.begin(),s.end());
		}
		printf("%s\n",s.c_str());
	}
	return 0;
}

/*
数据不清空，爆零两行泪
读题不认真，爆零两行泪
分析不仔细，爆零两行泪
建树不构造，爆零两行泪
变量不统一，爆零两行泪
边界不算清，爆零两行泪
*/

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>


using namespace std;

int main() {
    int K, S;
    cin >> K >> S;
    int t = 0;
    for (int i = 0; i <= K; ++i) {
        for (int j = 0; j <= K; ++j) {
            int z = S - i - j;
            if (z >= 0 && z <= K) t += 1;
        }
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int asc(const void* a, const void* b)
{
	if (*(long long int*)a > * (long long int*)b)return 1;
	if (*(long long int*)a < *(long long int*)b)return -1;
	return 0;
}
long long int fact[100005];
long long int modpow(long long int a, long long int n, long long int p)
{
	if (n < 0)
		return 0;
	long long int res = 1;
	while (n > 0)
	{
		if (n % 2 > 0)
			res = res * a % p;
		a = a * a % p;
		n /= 2;
	}
	return res;
}
long long int comb(long long int n, long long int r, long long int p)
{
	if (n < r)
		return 0;
	long long int res = fact[n];
	res = res * modpow(fact[r], p - 2, p) % p;
	res = res * modpow(fact[n - r], p - 2, p) % p;
	return res;
}
int main()
{
	long long int n, k;
	scanf("%lld %lld", &n, &k);
	long long int i;
	long long int a[100005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int p = 1000000007;
	qsort(a, n, sizeof(long long int), asc);
	long long int ans = 0;
	fact[0] = 1;
	for (i = 1; i <= n; i++)
		fact[i] = fact[i - 1] * i % p;
	for (i = k - 1; i < n; i++)
		ans = (ans + a[i] * comb(i, k - 1, p) % p) % p;
	for (i = 0; i <= n - k; i++)
		ans = (ans + p - a[i] * comb(n - i - 1, k - 1, p) % p) % p;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,t,tem;
	int i,j;
	bool flag;
	cin>>s>>t;
	for(i=s.size()-t.size();i>=0;i--)
	{
		flag=true;
		tem=s;
		for(j=0;j<t.size();j++)
		{
			if(t[j]!=s[j+i]&&s[j+i]!='?')
			{
				flag=false;
				break;
			}
			tem[j+i]=t[j];
		}
		if(flag)
		{
			for(j=0;j<tem.size();j++)
			{
				if(tem[j]=='?')
				{
					cout<<"a";
				}
				else
				{
					cout<<tem[j];
				}
			}
			cout<<endl;
			return 0;
		}
	}
	cout<<"UNRESTORABLE"<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

class Doubling:
    def __init__(self, A, K_max, decrement=True):
        """
        :param A: リスト。i から A[i] へと移動する
        :param K_max: K_max = 2**(k_max) まで参照する可能性がある
        :param decrement: True = A の要素の decrement が必要
        """
        self.k_max = K_max.bit_length()
        self.n = len(A)
        self.decrement = decrement
        self.doubling = [[-1] * self.n for _ in range(self.k_max)]
        for i, a in enumerate(A):
            self.doubling[0][i] = a - self.decrement

        for i in range(1, self.k_max):
            for j in range(self.n):
                if self.doubling[i - 1][j] != -1:
                    self.doubling[i][j] = self.doubling[i - 1][self.doubling[i - 1][j]]

    def apply(self, start, K):
        """
        :param start: スタート地点
        :param K: K回進む
        :return:
        """
        i = start - self.decrement
        for k in range(K.bit_length()):
            m = 1 << k
            if m & K:
                i = self.doubling[k][i]
            if i is None:
                break
        return i + self.decrement


######################################################################################


N, K = map(int, input().split())
A = list(map(int, input().split()))
doubling = Doubling(A, 10**18 + 1, decrement=True)
print(doubling.apply(1, K))

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

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        //input
        String[] input = br.readLine().split(" ");
        long A = Long.parseLong(input[0]);
        long B = Long.parseLong(input[1]);
        long K = Long.parseLong(input[2]);

        while(K > 0){
          if(A >= 1){
            if(K >= A){
              K = K - A;
              A = 0;
            }else{
              A = A - K;
              break;
            }
          }else if(B >= 1){
            if(K >= B){
              K = K - B;
              B = 0;
            }else{
              B = B - K;
              break;
            }
          }else{
            break;
          }
        }

        System.out.println(A + " " + B);
      }
    }
}

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

int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s,t;
  cin>>s>>t;
  for(int i = 0; i < s.length();i++){
    char last = s[s.length()-1];
    s.pop_back();
    s = last + s.substr(0, s.length());
    if(s == t) {
      cout << "Yes" << endl;
      return 0;
    }
  }  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
a,b,c,d = map(int,input().split())
a_life = c-b
t_life = a-d
if a_life<=0:
  print('Yes')
  sys.exit()
elif t_life<=0:
  print('No')
  sys.exit()


while(a_life>0 or t_life>0):
  a_life -= b
  if a_life<=0:
    print('Yes')
    sys.exit()
  t_life -= d
  if t_life<=0:
    print('No')
    sys.exit()

Measured memory_bytes: 9080
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define reprd(i,a,b) for (int i=(a);i>=(b);--i)
#define repr(i,n) reprd(i,n,0)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110;
int X, Y;

ll solve(int x, int y) {
    if (x % y == 0) return -1;
    return x;
}

int main(int argc, const char * argv[]) {
    cin >> X >> Y;

    output(solve(X, Y));

    return 0;
}

Measured memory_bytes: 3120
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e3;

int n;
int k;
int sum;
int a[N];

int b[N];

bool can(int d){
    for(int i = 1; i <= n; i++){
        b[i] = a[i] % d;
    }
    sort(b + 1 , b + n + 1);
    int i = 1;
    int j = n;
    int stp = 0;
    int now = 0;
    while(i <= j){
        if(stp <= 0){
            stp += b[i];
            now += b[i];
            i++;
        } else {
            stp -= d - b[j];
            j--;
        }
    }
    if(stp == 0)
        return now <= k;
    return 0;
}

int main(){
    scanf("%d%d" , &n , &k);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &a[i]);
        sum += a[i];
    }
    int ans = 0;
    for(int i = 1; i*i <= sum; i++){
        if(sum % i == 0){
            if(can(i)){
                ans = max(ans , i);
            }
            if(can(sum / i)){
                ans = max(ans , sum / i);
            }
        }
    }
    printf("%d\n" , ans);
}


Measured memory_bytes: 256
#include <iostream>
#define ll long long int
using namespace std;
int main() 
{
    ll k;
    cin >> k;
    if ( k%2 == 0 || k%5 == 0) cout << -1;
    else 
    {
        ll c = 0;
        for( ll i = 1; i <= k + 1; i++ )
        {
            c = c*10 + 7;
            c = c%k;
            if ( c%k == 0)
            {
                cout << i;
                break;
            }
        }
    }
    cout << endl;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(15);
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll ave = A + B / 2;
    ll ans = 0;
    if (C * 2 < A + B)
    {
        ans = min(X, Y) * C * 2;
        if (X < Y)
        {
            ans += (Y - X) * min(2 * C, B);
        }
        else if (X > Y)
        {
            ans += (X - Y) * min(2 * C, A);
        }
    }
    else
    {
        ans += X * A + Y * B;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1e9 + 7;

class ModCalc
{
	LLONG m_mod = MOD;
	vector<LLONG> m_fac;
	vector<LLONG> m_ifac;

public:
	ModCalc(const LLONG mod)
	{
		m_mod = mod;
	}

	// Combinationを計算したいときの前処理：O(max)
	ModCalc(const int max, const LLONG mod)
	{
		m_mod = mod;
		m_fac = vector<LLONG>(max + 1);
		m_ifac = vector<LLONG>(max + 1);
		m_fac[0] = m_ifac[0] = 1;
		for (int i = 0; i < max; ++i)
		{
			m_fac[i + 1] = m_fac[i] * (i + 1) % mod;    // n! (mod M)
			m_ifac[i + 1] = m_ifac[i] * ModPow(i + 1, mod - 2) % mod;   // k!^(M-2) (mod M)
		}
	}

	const LLONG ModAdd(LLONG a, LLONG b) const
	{
		return (a + b) % m_mod;
	}

	const LLONG ModSubtract(LLONG a, LLONG b) const
	{
		LLONG diff = a - b;
		return diff >= 0 ? diff : diff + m_mod;
	}

	const LLONG ModMulti(LLONG a, LLONG b) const
	{
		LLONG prod = a * b % m_mod;
		return prod >= 0 ? prod : prod + m_mod;
	}

	const LLONG ModDiv(LLONG a, LLONG b) const
	{
		LLONG c = m_mod, u = 1, v = 0;
		while (c)
		{
			LLONG t = b / c;
			b -= t * c; swap(b, c);
			u -= t * v; swap(u, v);
		}
		u %= m_mod;
		if (u < 0) u += m_mod;
		return (a % m_mod) * u % m_mod;
	}

	const LLONG ModPow(LLONG x, LLONG n) const
	{
		LLONG ret = 1;
		while (n != 0)
		{
			if (n & 1) ret = ret * x % m_mod;
			x = x * x % m_mod;
			n = n >> 1;
		}
		return ret;
	}

	const LLONG ModComb(LLONG n, LLONG r) const
	{
		if (n == 0 && r == 0) return 1;
		if (n < r || n < 0) return 0;
		LLONG tmp = m_ifac[n - r] * m_ifac[r] % m_mod;
		return tmp * m_fac[n] % m_mod;
	}
};

int main()
{
	LLONG N; cin >> N;
	ModCalc mod(MOD);
	LLONG ans = mod.ModPow(10, N);
	LLONG nine = mod.ModPow(9, N), eight = mod.ModPow(8, N);
	ans = mod.ModSubtract(ans, nine);
	ans = mod.ModSubtract(ans, nine);
	ans = mod.ModAdd(ans, eight);
	cout << ans << endl;
}


Measured memory_bytes: 3608
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int, int>P;
const int INF = 1<<29;
struct Edge{
  int to,l;
  Edge(){}
  Edge(int to, int l):to(to),l(l){}
};

vector<Edge>G[3005];
int N,M,K;
int dist[3005],s[3005];

void dijkstra(){
  fill(dist, dist+N, INF);
  priority_queue<P, vector<P>, greater<P> >q;
  for(int i=0;i<K;i++){
    dist[s[i]] = 0;
    q.push(P(0,s[i]));
  }

  while(!q.empty()){
    P p = q.top(); q.pop();
    int v = p.second;
    if(dist[v] < p.first) continue;
    for(int i=0;i<G[v].size();i++){
      Edge e = G[v][i];
      if(dist[e.to] > dist[v] + e.l){
	dist[e.to] = dist[v] + e.l;
	q.push(P(dist[e.to], e.to));
      }
    }
  }
}

int main(){
  scanf("%d%d%d", &N,&M,&K);
  for(int i=0;i<M;i++){
    int a,b,l;scanf("%d%d%d", &a,&b,&l); a--; b--;
    G[a].push_back(Edge(b,l));
    G[b].push_back(Edge(a,l));
  }

  for(int i=0;i<K;i++){
    scanf("%d", &s[i]); s[i]--;
  }

  dijkstra();
  int res = 0;
  for(int i=0;i<N;i++){
    res = max(res, dist[i]);
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<G[i].size();j++) res = max(res, (dist[i]+dist[G[i][j].to]+G[i][j].l+1)/2);
  }
  printf("%d\n", res);
  return 0;
}

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

using namespace std;

typedef long long int ll;

#define pb push_back

ll const mod=1e9+7 ;

ll dp[2002] ;

ll add(ll a,ll b){
    return (a+b) % mod ;
}

void func(int num)
{
    if(num<=2001)
    {
        ll total=0 ;
    
        if((num==1)|(num==2)) dp[num]=0 ;
    
        else if((num==3)|(num==4)|(num==5)|(num==0)) dp[num]=1 ;
    
        else 
        {
            dp[num]=1 ;
            
            for(int i=3 ; num-i>=0 ; i++){
                total=add(dp[num-i],total) ;
            }
            
            dp[num]=total ;
        }
        func(num+1) ;
    }
}

int main()
{
    func(0) ;
    
    int n;
    
    cin>>n;
    
    //for(int i=0;i<)
    
    cout<<dp[n] ;
}

Measured memory_bytes: 3616
W, H, N = map(int, input().split())
WL = 0
HL = 0
X = []
Y = []
A = []
for _ in range(N):
    x,y,a = map(int, input().split())
    X.append(x)
    Y.append(y)
    A.append(a)

for i in range(N):
    if A[i] == 1 and WL <= X[i]:
        WL = X[i]
    elif A[i] == 2 and W >= X[i]:
        W = X[i]
    elif A[i] == 3 and HL <= Y[i]:
        HL = Y[i]
    elif A[i] == 4 and H >= Y[i]:
        H = Y[i]

if W - WL <= 0 or H - HL <= 0:
    print(0)
    exit()

print((W - WL) * (H - HL))

Measured memory_bytes: 3064
#include "iostream"

using namespace std;

long long int N;
long long int a=1;
long long int b;
long long int c;
int num;
int num2;
int f=20;

int main() {
	cin >> N;
	while (a*a <= N) {
		if (N%a == 0) {
			b = a;
			num = 0;
			while (b >= 10) {
				b /= 10;
				num++;
			}
			c = N / a;
			num2 = 0;
			while (c >= 10) {
				c /= 10;
				num2++;
			}
			if (num >= num2 && f > num)f = num+1;
			if (num<num2 && f>num2)f = num2+1;
		}
		a++;
	}
	cout << f << endl;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())

cnt = Counter()
for i in range(26):
    s = chr(ord("a")+i)
    cnt[s] = 100
for _ in range(N):
    S = input()
    for i in range(26):
        s = chr(ord("a")+i)
        cnt[s] = min(S.count(s), cnt[s])

res = ""
for i in range(26):
    s = chr(ord("a")+i)
    res += s*cnt[s]

print(res)

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())    //昇順
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>()) //降順
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define INF 1000000000000000000


using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) {
    REP(i, a.size()) cin >> a[i];
}
void readv_m1(vector<int> &a) {
    REP(i, a.size()) {
        cin >> a[i];
        a[i]--;
    }
}

ll mod = 1000000007;


//解答参照済み
int main()
{

    ll N, M, L;
    cin >> N >> M >> L;
    vec A(M), B(M), C(M);
    mat d(N, vec(N, INF));
    REP(i, M) {
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;
        B[i]--;
        d[A[i]][B[i]] = C[i];
        d[B[i]][A[i]] = C[i];
    }

    // warshall_floyd
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }


    mat d2(N, vec(N, INF));
    REP(i, N) {
        REP(j, N) {
            if (d[i][j] <= L) {
                d2[i][j] = 1;
                d2[j][i] = 1;
            }
        }
    }
    // warshall_floyd
    REP(k, N) {
        REP(i, N) {
            REP(j, N) {
                d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
            }
        }
    }


    ll Q;
    cin >> Q;
    vec s(Q), t(Q);
    REP(i, Q) {
        cin >> s[i] >> t[i];
        s[i]--;
        t[i]--;
        ll ans = d2[s[i]][t[i]] - 1;
        if (ans == INF - 1) ans = -1;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<set>
using ll =  long long;

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

using namespace std;

int main(){

    int n;
    cin >> n;
    ll ans=0;

    for(int i=1; i<=n; i++){
        if(i%3==0)continue;
        if(i%5==0)continue;
        ans+=i;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> ans(n, 0);
	rep2(i, 1, n){
		char now = s.at(i);
		ans.at(i) = ans.at(i-1);
		if(now == 'C' && s.at(i-1) == 'A') ans.at(i)++;
	}
	rep(i, q){
		int l, r;
		cin >> l >> r;
		l--; r--;
		cout << ans.at(r) - ans.at(l) << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

int ctoi(const char c) {
	return c - '0';
}
int keta(int a) {
	return to_string(a).size();
}

signed main() {
	int n, k;
	cin >> n >> k;
	if (n > 9) {
		cout << k << endl;
	}
	else {
		cout << k + 100 * (10 - n) << endl;
	}
}


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 <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>

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(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll a, b;
  cin >> a >> b;
  if (a <= 0 && b >= 0) {
    cout << "Zero" << endl;
    return 0;
  }
  if (a > 0) {
    cout << "Positive" << endl;
    return 0;
  }
  if (abs(a - b) % 2 == 0) {
    cout << "Negative" << endl;
    return 0;
  }
  cout << "Positive" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define INF_LL 1e18
#define INF 1e9

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

using namespace std;

using ll = long long;
using PII = pair<int, int>;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

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

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	ll A, B, C;
	cin >> A >> B >> C;
	ll res = INF_LL;
	res = min(res, A*B*(C%2));
	res = min(res, B*C*(A%2));
	res = min(res, C*A*(B%2));
	cout << res << endl;
}


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

const ll INF = 1LL << 60;

ll n, a, b;

const int mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

mint f(ll a) {
    mint ans = 0;

    // a 回す
    mint bunbo = 1;
    mint bunshi = 1;
    rep(i, a) {
        bunshi *= (n - i);
        bunbo *= (i + 1);
    }

    return bunshi / bunbo;
}

int main() {
    cin >> n >> a >> b;
    mint total = 2;

    // n C 0 を除く
    total = total.pow(n) - 1;

    combination comb(1e5 + 10);

    mint tmp1 = f(a);
    mint tmp2 = f(b);
    // cout << tmp1 << " " << tmp2 << endl;

    mint ans = total;
    ans -= tmp1;
    ans -= tmp2;

    cout << ans << endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N, K;
    cin >> N >> K;
    if(2*K > (N-1)*(N-2)){
        cout << -1 << endl;
        return 0;
    }
    vector<pair<ll, ll>> edges(0);
    rep(i, N-1){
        edges.push_back({N, i+1});
    }
    ll d = (N-1)*(N-2)/2 - K;
    ll c = 0;
    bool flag = false;
    rep(i, N-1){
        rep2(j, i+1, N-1){
            if(c == d){
                flag = true;
                break;
            }
            edges.push_back({i+1, j+1});
            c++;
        }
        if(flag){
            break;
        }
    }
    cout << N-1+d << endl;
    rep(i, N-1+d){
        cout << edges.at(i).first << " " << edges.at(i).second << endl;
    }
}

Measured memory_bytes: 3668
use std::collections::VecDeque;

fn bfs(graph: &Vec<Vec<usize>>, n: usize, start: usize) -> Vec<Option<usize>> {
    let mut distance = vec![None; n];
    let mut q = VecDeque::new();
    q.push_back((start, 0));
    while !q.is_empty() {
        let (current, d) = q.pop_front().unwrap();
        if distance[current].is_some() {
            continue;
        }
        distance[current] = Some(d);
        for &next in graph[current].iter() {
            q.push_back((next, d + 1));
        }
    }
    distance
}

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => {
            get().parse::<$t>().unwrap()
        };
        () => {
            get!(i64)
        };
    }

    let (n, mut x, mut y) = (get!(usize), get!(usize), get!(usize));
    x -= 1;
    y -= 1;
    let mut graph = vec![vec![]; n];
    for i in 0..n - 1 {
        graph[i].push(i + 1);
        graph[i + 1].push(i);
    }
    graph[x].push(y);
    graph[y].push(x);

    let mut ans = vec![0; n - 1];
    for i in 0..n {
        let distance = bfs(&graph, n, i);
        for &d in distance.iter() {
            if d.unwrap() == 0 {
                continue;
            }
            ans[d.unwrap() - 1] += 1;
        }
    }

    for &x in ans.iter() {
        println!("{}", x / 2);
    }
}


Measured memory_bytes: 4352
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  string a;
  cin>>a;
  cout<<a[0]<<a.size()-2<<a[a.size()-1]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
using namespace std;
typedef pair<int,int> ii;

int mod = 998244353;

signed main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n; cin >> n;
	
	int small[n], big[n];
	ii arr[n];
	
	for(int i = 0;i < n;i++){
		cin >> small[i] >> big[i];
		small[i] *= 2; big[i] *= 2;
		arr[i] = ii(small[i],big[i]);
	}
	
	sort(small,small+n);
	sort(big,big+n);
	
	int h = n/2;
	int smallMedian = (small[h] + small[n-h-1])/2;
	int bigMedian = (big[h] + big[n-h-1])/2;
	
	//cout << smallMedian << " " << bigMedian << "\n";
	
	if(n%2 == 0){
		cout << (bigMedian - smallMedian + 1);
	}
	else{
		cout << (bigMedian - smallMedian) / 2 + 1;
	}
	
}



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;




int n, m;
string s;
int a[maxn];
int nr[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>m;
    n++;
    cin>>s;
    if (s.front()=='1' || s.back()=='1') out(-1);
    for (int i=0; i<n; i++) {
	a[i] = s[i]-'0';
    }

    //check 1111..
    {
	int x=0;
	for (int i=0; i<n; i++) {
	    if (i-x>m) out(-1);
	    if (a[i] == 0) x=i;
	}
    }

    //nearest_right
    {
	nr[n-1]=n-1;
	for (int i=n-2; i>=0; i--) {
	    nr[i] = (a[i]==0? i: nr[i+1]);
	}
    }

    vector<int> v;

    for (int i=n-1; i>0; ) {
	if (i-m<=0) {
	    v.push_back(i);
	    break;
	}
	int j = nr[i-m];
	assert(j<i);
	v.push_back(i-j);
	i = j;
    }


    reverse(v.begin(), v.end());
    for (int x: v)cout<<x<<" ";
    cout<<endl;

    return 0;
}


Measured memory_bytes: 5576
import math

N,P = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

#奇数の数と偶数の数を数えておこうね。
even = 0
odd = 0
for i in range(N):
    if A[i]%2 == 0:
        even += 1
    else:
        odd += 1

if P == 0: #偶数を探すよ。
    #奇数を偶数個
    odds = 0
    for i in range(odd+1):
        if i % 2 == 0:
            odds += math.factorial(odd)/(math.factorial(i)*math.factorial(odd-i))
    #偶数を何個でも
    evens = 0
    for i in range(even+1):
        evens += math.factorial(even)/(math.factorial(i)*math.factorial(even-i))

elif P == 1: #奇数を探そう。
    #奇数を奇数個
    odds = 0
    for i in range(odd+1):
        if i % 2 != 0:
            odds += math.factorial(odd)/(math.factorial(i)*math.factorial(odd-i))
    #偶数を何個でも
    evens = 0
    for i in range(even+1):
        evens += math.factorial(even)/(math.factorial(i)*math.factorial(even-i))


print(int(odds*evens))

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

int main() {
    ll d, g, ans = 10000, sum = 0, hoge = 0;
    vector<int> p(10), c(10);
    cin >> d >> g;
    rep(i, d) cin >> p[i] >> c[i];

    for (int bit = 0; bit < (1 << d);bit++){
        sum = 0;
        hoge = 0;
        for (int i = 0; i < d; i++) {
            if (bit & (1 << i)) {
            sum += c[i];
            sum += (i + 1) * 100 * p[i];
            hoge += p[i];
            }
        }
        if(sum >= g){
            ans = min(hoge, ans);
        }
        else{
            for (int i = d - 1; i >= 0;i--){
                if(bit & (1<<i))
                    continue;
                for (int j = 0; j < p[i]; j++)
                {
                    sum += (i+1) * 100;
                    hoge++;
                    if(sum >= g){
                        ans = min(hoge, ans);
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    pair<ll, ll> p[n];
    for(int i = 0; i < n; i++)
    cin >> p[i].first >> p[i].second;
    sort(p, p + n);
    ll c = 0;
    
        for(int i = 0; i < n && m > 0; i++){
        c += p[i].first * min((ll)m, p[i].second);
        m -= min((ll)m, p[i].second);
        }
    
    cout << c;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
ll gcd(int a,int b)
{
if(a>b)
swap(a,b);
 
if(a==0)
  return b;
return gcd(b%a,a);
 
}
int main()
{ 
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);

ll k;
cin>>k;
ll sum=0;
for(ll i=1;i<=k;i++)
  for(ll j=1;j<=k;j++)
    for(ll m=1;m<=k;m++)
    {
      ll x=gcd(i,j);
      x=gcd(x,m);
      sum+=x;
    }

cout<<sum<<endl;
}
 
 

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=INF,a[100000],b,c,cmp=0,data,m,h,x,y,xcmp=0,ycmp=0,sum=0,cmpp;

string s,w;

vector<int> z;

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

     bool fl=true;
       cin >> n;
      rep(i,n){
          cin >> a[i];
      }
      rep(i,n-1){
          if(a[i]!=a[i+1]){
              fl=false;
          }
      }
      if(fl==true){
          Cout(0);
          return 0;
      }
      sort(a,a+n);
      reverse(a,a+n);
      b=a[n-1];
      c=a[0];
     // Cout(b);
      //out(c);
      rrep(i,b,c){
          rep(j,n){
          cmpp=(a[j]-i);
          cmp+=cmpp*cmpp;
          }
          //Cout(cmp);
          if(ans>cmp){
              ans=cmp;
          }
          cmp=0;
        }
      
     Cout(ans);
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    static const double pi=3.141592653589793238462643383279;
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    double h_ang=0.5*(60.0*h+m);
    double m_ang=6.0*m;
    double ang=max(h_ang-m_ang,m_ang-h_ang);
    if(ang>180) ang=360.0-ang;
    double ansans=a*a+b*b-2*a*b*cos(ang*pi/180.0);
    printf("%.15f\n",sqrt(ansans));
}

Measured memory_bytes: 4188
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, l;
vector<int> x;
vector< vector<int> > dbl;
/*
int f(int a, int b, int res){
    if(a > b) return f(b, a, 0);
    if(a == b) return res;
    for(int k = 20-1; k >= 0; k--){
        if(dbl[a][k] >= b){
            return f(dbl[a][k-1], b, res + (1<<k));
        }
    }
    return 1e9;
}*/

int f(int a, int b){
    if(a > b) return f(b, a);
    int res = 0;
    while(a < b){
        for(int k = 0; k < 20; k++){
            if(dbl[a][k] >= b){
                if(k == 0){
                    a = b;
                    res++;
                }else{
                    a = dbl[a][k-1];
                    res += (1 << (k-1));
                }
                break;
            }
        }
    }
    return res;
}

int main(void){
    cin >> n;
    x.assign(n, 0);
    for(int i=0;i<n;i++) cin >> x[i];
    cin >> l;
    dbl.assign(n, vector<int>(20, 0));

    int nx = 0;
    for(int i=0;i<n;i++){
        while(nx+1 < n && x[nx+1] <= x[i]+l) nx++;
        dbl[i][0] = nx;
    }
    for(int k=1;k<20;k++){
        for(int i=0;i<n;i++){
            dbl[i][k] = dbl[dbl[i][k-1]][k-1];
        }
    }

    int q;
    cin >> q;
    while(q--){
        int a, b;
        cin >> a >> b;
        cout << f(--a, --b) << endl;
    }
}


Measured memory_bytes: 14720
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] h = new int[n];
		
		for( int i=0 ; i<n ; i++ ) {
			h[i] = sc.nextInt();
		}
		

		Map<Integer,Set<Integer>> route = new HashMap<Integer, Set<Integer>>(); 
		
		for( int i=0 ; i<m ; i++ ) {
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			addRoute(route, a, b);
			addRoute(route, b, a);
		}
		
		int c=0;
		for( int i=0 ; i<n ; i++ ) {
			Set<Integer> path = route.getOrDefault(i, Collections.emptySet());
			int cur = h[i];
			
			boolean isHigher = path.stream().allMatch((it)->cur > h[it]); 
			if( isHigher ) c++;
		}
		System.out.println(c);
	}

	private static void addRoute(Map<Integer, Set<Integer>> route, int a, int b) {
		Set<Integer> path = route.computeIfAbsent(a, k -> new HashSet<>());
		path.add(b);
		route.put(a, path);
	}
}

Measured memory_bytes: 95160
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back

#define INT 1.01

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

    int64_t X;
    cin >> X;

    int64_t ret = 0, v = 100;
    while(true){
        ret ++;
        v *= INT;
        if(X<=v) break;
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3636
n, k = map(int, input().split())

a = [int(i) for i in input().split()]

ans = float('inf')
for i in range(1 << n):
    res = 0
    cnt = 0
    m = 0
    for j in range(n):
        if i >> j & 1:
            cnt += 1
            res += max(m-a[j] + 1, 0)
            m = max(m+1, a[j])
        else:
            m = max(m, a[j])

    if cnt == k:
        ans = min(ans, res)

print(ans)


Measured memory_bytes: 3064
n, q = map(int, input().split())

g = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = (int(x) - 1 for x in input().split())
    g[a].add(b)
    g[b].add(a)

ctr = [0] * n
for _ in range(q):
    it = map(int, input().split())
    p = next(it) - 1
    x = next(it)
    ctr[p] += x

st = [0]
used = [0] * n
used[0] = 1
while st:
    v = st.pop()
    for u in g[v]:
        if used[u]: continue
        used[u] = 1
        ctr[u] += ctr[v]
        st.append(u)
print(*ctr)


Measured memory_bytes: 81920
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    string s;
    cin >> s;

    bool res = false;
    REP(i, s.size() - 1)
    if (s[i] == 'A' && s[i + 1] == 'C')
        res = true;
    cout << (res ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int N; cin >> N;
    vector<pair<int, int> > ab(N); rep(i, N) cin >> ab[i].second >> ab[i].first;
    vector<pair<int, int> > cd(N); rep(i, N) cin >> cd[i].first >> cd[i].second;

    Sort(ab); Sort(cd);
    int ans = 0;
    vector<bool> vb(N, false);

    rep (i, N) {

        pair<int, int> tmp;
        int flg = -1;

        rep(j, ab.size()) {
            if (ab[j].second < cd[i].first && ab[j].first < cd[i].second && !vb[j]) flg = j;
        }

        if (flg != -1) {
            ans++;
            vb[flg] = true;
        }
        // ab.erase(ab.begin() + flg);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,k,ans=1;

inline int min(int a,int b) { return a<b? a:b; }

int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		ans+=min(ans,k);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vin a(n);rep(i,n)cin>>a[i];
    vin len(n+1),omit(n);
    len[0]=abs(a[0]);len[n]=abs(a[n-1]);
    rep(i,n-1)len[i+1]=abs(a[i+1]-a[i]);
    omit[0]=abs(a[1]);omit[n-1]=abs(a[n-2]);
    rep2(i,1,n-1)omit[i]=abs(a[i+1]-a[i-1]);
    int sum=0;
    rep(i,n+1)sum+=len[i];
    rep(i,n)cout<<sum-len[i]-len[i+1]+omit[i]<<endl;
}

Measured memory_bytes: 4584
#include<stdio.h>
int main(void){
  char a[11];
  int i;
  int sum=0,total=0;
  scanf("%s",&a);
  for(i=0;i<10;i++){
    if(a[i]=='A'||a[i]=='C'||a[i]=='G'||a[i]=='T')
      sum=sum+1;
    else sum=0;
    if(total<sum)
      total=sum;
  }
  printf("%d",total);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n;
  while(cin >> n && n) {
    int ans,max=0;
    rep(i,n) {
      int a,b,c;
      cin >> a >> b >> c;
      if(b+c>max) {
	ans=a;
	max=b+c;
      } 
    }
    cout << ans << " " << max << endl;
  }
  return 0;
}


Measured memory_bytes: 1160
import java.util.*;

class Main{
public static void main(String[] args){
	long count = 0;
	Scanner scan = new Scanner(System.in);
	int num = scan.nextInt();//町の数
	long[] mons = new long[num+1];//n-1番目の街のモンスター数
	long[] yusya = new long[num];//n-1番目の勇者が倒せるモンスターの数
	for(int i = 0;i<num+1;i++){
		mons[i]=Long.parseLong(scan.next());
	}
	for(int i = 0;i<num;i++){
		yusya[i]=Long.parseLong(scan.next());
	}

	for(int i = 0;i<num;i++){
		if(mons[i]>=yusya[i])count+=yusya[i];
		else if((mons[i]+mons[i+1])<=yusya[i]){
			count+=mons[i]+mons[i+1];
			mons[i+1]=0;
		}else if(mons[i]<yusya[i]&&yusya[i]<(mons[i]+mons[i+1])){
			count+=yusya[i];
			mons[i+1]-=(yusya[i]-mons[i]);
		}
	}

	System.out.println(count);
}

}

Measured memory_bytes: 56712
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int n, m, i, j, temp, min;
  scanf("%d %d", &n, &m);
  int s[n][n];
  int c[m][m];
  for(i = 0; i < n; i++) scanf("%d %d", &s[0][i], &s[1][i]);
  for(i = 0; i < m; i++) scanf("%d %d", &c[0][i], &c[1][i]);
  int ans[n];
  for(i = 0; i < n; i++) ans[i] = 1000000000;
  temp = 0;
  int num;
  for(i = 0; i < n; i++){
    min = ans[i];
    for(j = 0; j < m; j++){
      temp = abs(s[0][i] - c[0][j] ) + abs(s[1][i] - c[1][j]);
      if(temp < min){
	num = j + 1;
	min = temp;
      }
    }
    ans[i] = num;
  }
  
  for(i = 0; i < n; i++) printf("%d\n", ans[i]);

  return 0;
}


Measured memory_bytes: 128
N = int(input())
AAA = list(map(int, input().split()))

AAA.sort()

m = AAA[0]
M = AAA[N-1]

procedures = []
for i in range(1, N-1):
    if AAA[i] > 0:
        procedures.append((m, AAA[i]))
        m -= AAA[i]
    else:
        procedures.append((M, AAA[i]))
        M -= AAA[i]
procedures.append((M, m))

print(M-m)
for x, y in procedures:
    print(x, y)


Measured memory_bytes: 19328