akhauriyash/Code-Regression huggingface dataset:
import numpy
from bisect import bisect_left, bisect_right
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
for i in range(1,N):
  A[i]+=A[i-1]

ans=A[N-1]
for m in range(2,N-1):
  sum_left=A[m-1]
  i=bisect_left(A,sum_left/2)
  sum1=A[i]
  if i!=0:
    if A[i]+A[i-1]>sum_left:
      sum1=A[i-1]
  sum2=sum_left-sum1

  sum_right=A[N-1]-sum_left
  i=bisect_left(A,sum_left+sum_right/2)
  sum3=A[i]-sum_left
  if i!=m:
    if A[i]+A[i-1]-2*sum_left>sum_right:
      sum3=A[i-1]-sum_left
  sum4=sum_right-sum3
  max_sum=max(sum1,sum2,sum3,sum4)
  min_sum=min(sum1,sum2,sum3,sum4)
  dif=max_sum-min_sum
  if dif<ans:
    ans=dif

print(ans)

Measured memory_bytes: 33364
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  int q = min(A, B);
  int w = max(A, B);
  if ((w - q) % 2 == 0) {
    cout << q + (w - q) / 2 << endl;
  }
 else {
   cout << "IMPOSSIBLE" << endl;
 }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N; cin >> N;
    long long ans = 0;

    for(int i=1; i<=N; i++){
        if(i%3 == 0 || i%5 == 0){
            continue;
        }else{
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
n, k = map(int, input().split())
a = list(map(int, input().split()))
town = [0] * n
move = []
next1 = a[0] - 1
flag = 0
for i in range(k):
    town[next1] += 1
    move += [next1]
    if town[next1] > 1:
        flag = 1
        break
    if i == k-1:
        break
    next1 = a[next1] - 1
if flag == 0:
    print(next1+1)
else:
    first = move.index(move[-1])
    roop = move[first:-1]
    print(roop[(k - first)%len(roop)-1]+1)

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  vector<ll> v(n);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%lld", &v[i]);
  }
  ll ans = -INF;
  ll mn = v[0];
  for (int i = 1; i < n; ++i) {
    ans = max(ans, v[i] - mn);
    mn = min(mn, v[i]);
  }
  fprintf(stdout, "%lld\n", ans);
  return 0;
}

Measured memory_bytes: 2584
while True:
    cnt = 0
    try:
        n = int(input())
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        if a+b+c+d==n:
                            cnt+=1
        print(cnt)
    except:
        break


Measured memory_bytes: 5592
/**
*    created: 05.07.2020 18:19:27
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#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(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    map<int,int> to1;
    map<int,int> ton;
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        if (a == 1) to1[b]++;
        if (b == 1) to1[a]++;
        if (a == n) ton[b]++;
        if (b == n) ton[a]++;
    }
    for (auto p : to1) {
        if (ton[p.first] > 0) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 22288
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  int n;
  cin >> n;
  int ng = 0;
  int ok = n+1;
  while(abs(ng-ok)>1){
    int mid = (ng+ok)/2;
    int p = n;
    int q = mid;
    while(p>0 && q>0){
      if(q <= p){
        p -= q;
      }
      q --;
    }
    if(p>0){
      ng = mid;
    }
    else{
      ok = mid;
    }
  }
  while(n>0 || ok>0){
    if(ok <= n){
      n -= ok;
      cout << ok << endl;
    }
    ok --;
  }
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  vector<vector<int>> path(m, vector<int>(2));
  rep(i, n){
    cin >> h.at(i);
  }
  rep(i, m){
    cin >> path.at(i).at(0) >> path.at(i).at(1);
    path.at(i).at(0)--;
    path.at(i).at(1)--;    
  }
  rep(i, m){
    if(h.at(path.at(i).at(0))<=h.at(path.at(i).at(1))){
      ok.at(path.at(i).at(0)) = false;
    }
    if(h.at(path.at(i).at(1))<=h.at(path.at(i).at(0))){
      ok.at(path.at(i).at(1)) = false;
    }
  }
  int ans = 0;
  rep(i, n){
    if(ok.at(i) == true ){
      ans++;
    }
  }
  cout << ans << endl;




    
}


Measured memory_bytes: 9048
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; 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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
const int MAX = 2010101;

long long fac[MAX], finv[MAX], inv[MAX];

void binom_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long binom(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll r1, c1, r2, c2;

ll g(ll r, ll c)
{
    ll res = 0;
    for (ll i = 0; i <= r; i++)
    {
        res += binom(i + c + 1, c);
        res %= MOD;
    }
    return res;
}

int main()
{
    binom_init();
    cin >> r1 >> c1 >> r2 >> c2;
    ll ans = 0;
    ans = g(r2, c2);
    ans = (ans + MOD - g(r2, c1 - 1)) % MOD;
    ans = (ans + MOD - g(r1 - 1, c2)) % MOD;
    ans += g(r1 - 1, c1 - 1);
    ans %= MOD;
    cout << ans << endl;
}


Measured memory_bytes: 47360
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main(void){
    int i,j,k,x,y,z,n,m,w;
    scanf("%d",&n);
    char s[n][n];
    for(i=0;i<n;i++){
        scanf("%s",s[i]);
    }
    y=0;
    for(i=0;i<n;i++){
        x=0;
        for(j=0;j<n;j++){
            for(k=0;k<n;k++){
                if(s[(j+i)%n][k]==s[(k+i)%n][j])x++;
            }
        }
        if(x==n*n)y++;
    }
    printf("%d",y*n);
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#define MOD_BY UINT32_C(1000000007)

uint32_t add(uint32_t a, uint32_t b) {
	uint32_t r = a + b;
	if (r >= MOD_BY) r -= MOD_BY;
	return r;
}

uint32_t mul(uint32_t a, uint32_t b) {
	return (uint32_t)(((uint64_t)a * b) % MOD_BY);
}

#define GENKAI 200000

int N, K;
int rCount[GENKAI];
int* rinsetu[GENKAI];

uint32_t search(int node, int parent, int penalty) {
	uint32_t answer = K - penalty;
	int i;
	int newPenalty = 1; /* このノードの分 */
	if (parent >= 0) newPenalty++; /* 親の分 */
	for (i = 0; i < rCount[node]; i++) {
		if (rinsetu[node][i] != parent) {
			answer = mul(answer, search(rinsetu[node][i], node, newPenalty));
			newPenalty++; /* 親以外のすでに辿ったノードの分 */
		}
	}
	return answer;
}

int main(void) {
	int i;
	if (scanf("%d%d", &N, &K) != 2) return 1;
	for (i = 1; i < N; i++) {
		int a, b;
		if (scanf("%d%d", &a, &b) != 2) return 1;
		a--;
		b--;
		/* 失敗時メモリリークするが、どうせすぐ終了するので無視 */
		rinsetu[a] = realloc(rinsetu[a], ++rCount[a] * sizeof(int));
		if (rinsetu[a] == NULL) return 1;
		rinsetu[a][rCount[a] - 1] = b;
		rinsetu[b] = realloc(rinsetu[b], ++rCount[b] * sizeof(int));
		if (rinsetu[b] == NULL) return 1;
		rinsetu[b][rCount[b] - 1] = a;
	}
	printf("%" PRIu32 "\n", search(0, -1, 0));
	return 0;
}

/*
これまでに選んできた色は使えない
これまでに選んできた色：親 + 親で今のノードの前に何ノード決めたか
*/


Measured memory_bytes: 10368
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>



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


map<string, int> mp;
#define ll long long

int main() {
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    
    if (a[2] % 2 == 0||a[1]%2==0||a[0]%2==0) {
        cout << 0 << endl;
    }
    else {
        cout << a[0] * a[1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int search(int A[],int n,int key){
  int i = 0;
  A[n] = key;
  while (A[i] != key) i++;
  return i != n;
}

int main() {
  int i, n, A[10000+1], q, key, sum = 0;

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

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    if ( search(A, n, key)) {
      sum++;
    }
  }
  printf("%d\n",sum);
  
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int N;
   cin >> N;
   vector<int> A(N);
   for(int i = 0; i < N; i++){
       cin >> A[i];
   }
   vector<int> B(N);
   for(int i = 0; i < N; i++){
       B[i] = A[i];
   }
   sort(A.begin(),A.end());
   int X,Y;
   X = A[N-2];
   Y = A[N-1];
   if(X == Y) {
       for(int i = 0; i < N; i++){
           cout << X << endl;
       }
   }
   else{
       for(int i = 0; i < N; i++){
           if(B[i] == Y){
               cout << X << endl;
           }
           else cout << Y << endl;
       }
   }
}

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

using namespace std;

char grid[8][8];

void rotate90() {
  char temp[8][8];
  
  for(int i=0; i<8; i++) {
    for(int j=0; j<8; j++) {
      temp[i][j] = grid[8-j-1][i];
    }
  }
  
  memcpy(grid, temp, sizeof(grid));
  
}

int main() {
  
  for(int i=0; i<8; i++)
    for(int j=0; j<8; j++) cin >> grid[i][j];

  for(int i=0; i<3; i++) {
    cout << (i+1)*90 << endl;
    rotate90();
    
    for(int j=0; j<8; j++) {
      for(int k=0; k<8; k++) {
	cout << grid[j][k];
      }
      cout << endl;
    }

  }
  
  return 0;
}

Measured memory_bytes: 1140
D=int(input())
C=list(map(int,input().split()))
cs=sum(C)
S=[list(map(int,input().split())) for i in range(D)]
l=[0]*26
for d in range(D):
    x=[S[d][i]-cs+C[i] for i in range(26)]
    j=x.index(max(x))
    l[j]=d+1
    print(j+1)

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


using namespace std;

typedef long long ll;

const ll INF = (ll) (1e18+5);

int main()
{
    /* ios::sync_with_stdio(0); */
    /* cin.tie(0); */
    ll N, W; cin >> N >> W;
    vector <ll> weight, value;
    for (ll i = 0; i < N; ++i){
        ll w, v; cin >> w >> v;
        weight.push_back(w); value.push_back(v);
    }
    ll sum = 0;
    for(ll x : value){
        sum += x;
    }
    //dp table needs only to be as long as the sum of the values of all items combined
    vector <ll> dp(sum + 1, INF);
    dp[0] = 0;
    // dp[i] - the minimum total weight of items with value exactly i
    for (ll item = 0; item < N; ++item){
        for (ll excess_value = sum - value[item]; excess_value >= 0; --excess_value){
            dp[value[item] + excess_value] = min(dp[value[item] + excess_value], dp[excess_value] + weight[item]);
        }
    }
    ll ans = 0;
    for (ll i = 0; i <= sum; ++i){
        if (dp[i] <= W){
            ans = max(ans, i);
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1024
n, x, y = [int(i) for i in input().split()]
k = [0 for _ in range(n-1)]
x -= 1
y -= 1

for i in range(n):
    for j in range(i + 1, n):
        l = min(abs(j - i), abs(x - i) + 1 + abs(y - j))
        k[l - 1] += 1

for i in k:
    print(i)


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

int main(){
    string s;
    cin >> s;
    bool ok = false;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '7'){
            ok = true;
            break;
        }
    }
    if(ok){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}

Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////




int main(){
  int h,w,n;

  cin >> h >> w >> n;

  int a[n];

  rep(i,0,n)
    cin >> a[i];
     
  int b[h][w];

  rep(i,0,h)
    rep(j,0,w)
      b[i][j] = 0;
  int t = 1;
  int i = 0 , j = 0 , k = 0;
  
  while(k < n){
    
    b[i][j] = k+1;
    
    //cout << "k+1:" << k+1 << " i:" << i << " j:" << j << " a[k]:" << a[k] << " b[i][j]:" << b[i][j] << endl;

    a[k]--;
    if(a[k] <= 0){
      k++;
    }
    
    if(t == 1){
      
      if( j == w - 1){
        //cout << "case:1" << endl;
        t = 2;
        i++;
        continue;
      }
      
      else if( b[i][j+1] > 0){
        t = 2;
        i++;
        continue;
      } 

      else{
        j++;
      }
    }

    if(t == 2){
      if( i+1 == h ){
        t = 3;
        j--;
        continue;
      }

      else if( b[i+1][j] > 0 ){
        t = 3;
        j--;
        continue;
      }

      else{
        i++;
      }
    }
    
    if(t == 3){
      if(j-1 < 0 ){
        t = 4;
        i--;
        continue;
      }
      else if(b[i][j-1] > 0){
        //cout << "done" << endl;
        t = 4;
        i--;
        continue;
      }
      else{
        j--;
      }
    }

    if(t == 4){
      if( i-1 < 0 ){
        t = 1;
        j++;
        continue;
      }
      else if(b[i-1][j]){
        t = 1;
        j++;
        continue;
      }
      else{
        i--;
      }
    }
    
    
  }
   
  rep(i,0,h){
    rep(j,0,w){
      cout << b[i][j] << " ";
    }
    cout << endl;
  }

  ret 0;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll mod=1e9+7;
ll MOD=mod;
ll MAX=1e6;
vector<ll> fac(MAX), finv(MAX), inv(MAX);
//long long fac[MAX], finv[MAX], inv[MAX];

ll pow(ll x, ll n, ll mod) { //x^n 計算量O(logn)
	ll ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x;
            ans%=mod;
		}
		x = x * x; //一周する度にx, x^2, x^4, x^8となる
        x%=mod;
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans%mod;
}

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

int main(){
    ll n,a,b; cin>>n>>a>>b;
    ll mod=1e9+7;
    vector<ll> com(b+10,0);
    com[0]=1;
    COMinit();
    rep(i,b+3){
        com[i+1]=com[i]*(n-i);
        com[i+1]%=mod;
        com[i+1]*=inv[i+1];
        com[i+1]%=mod;
    }
    ll res=pow(2,n,mod);
    res--;
    res-=com[a];
    res-=com[b];
    res%=mod;
    if(res<0) res+=mod;
    cout<<res<<endl;
}

Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

template<typename T>
vector<T> prime_factorization(T n) {
	vector<T> ret;
	vector<bool> is_prime(n + 1, true);
	
	for(T i = 2; i <= n; ++i) {
		
		if( is_prime[i] ) {
			for(T j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}
			
			if( i % 5 == 1 ) ret.push_back(i);
		}
	}
	
	return ret;
}

int main(void) {
	int n;
	cin >> n;
	
	vector<int> primes = prime_factorization(55555);
	
	for(int i = 0; i < n; ++i) {
		cout << primes[i] << " ";
	}
	
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	int n;	cin >> n;
  	string s;	cin >> s;
  	if(s.size()%2 != 0){cout << "No" << endl; return 0;}
  	
  	if(s.substr(0,s.size()/2) == s.substr(s.size()/2,s.size()/2)){
    	cout << "Yes" << endl;
    }
  	else cout << "No" << endl;
} 

Measured memory_bytes: 256
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const ll &a, const ll &b){
    return abs(a)>abs(b);
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e6;

int main(){
    IOS;
    make(ll,x);
    ll l=1; ll r=1e5; ll ans=1;
    while(l<=r){
        ll m=(l+r)/2;
        if((m*(m+1))/2>=x){
            ans=m; r=m-1;
        }
        else l=m+1;
    }
    cout<<ans<<endl;




    return 0;
}



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

int main(){
	int n,h,l,p,q;
	while(cin>>n,n){
		h=0;
		l=1000;
		for(int i=0;i<n;i++){
			p=0;
			for(int j=0;j<5;j++){
				cin>>q;
				p+=q;
			}
			h=max(h,p);
			l=min(l,p);
		}
		cout<<h<<" "<<l<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
    cin >> a >> b;
    if(a>0)  cout << "Positive";               
    else if(b>=0)  cout << "Zero";          
    else if((a&1)^(b&1))  cout << "Positive";  
    else cout << "Negative";
    return 0;
}

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

from heapq import heappop, heappush


x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

class CakeSet:
    def __init__(self, status):
        self.status = status
        self.cost = calc_cost(status)

    def next_list(self):
        ret = []
        if self.status[0] + 1 < x:
            ret.append(CakeSet((self.status[0] + 1, self.status[1], self.status[2])))
        if self.status[1] + 1 < y:
            ret.append(CakeSet((self.status[0], self.status[1] + 1, self.status[2])))
        if self.status[2] + 1 < z:
            ret.append(CakeSet((self.status[0], self.status[1], self.status[2] + 1)))
        return ret

    def __lt__(self, other):
        return self.cost > other.cost

def calc_cost(status):
    return a[status[0]] + b[status[1]] + c[status[2]]

def main():
    memo = set()
    initial = CakeSet((0, 0, 0))
    costs = []
    queue = []
    heappush(queue, initial)
    while len(costs) < k:
        cakeSet = heappop(queue)
        if cakeSet.status in memo:
            continue
        costs.append(cakeSet.cost)
        memo.add(cakeSet.status)
        for next_set in cakeSet.next_list():
            heappush(queue, next_set)
    for cost in costs[:k]:
        print(cost)


if __name__ == '__main__':
    main()


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

int main(){
  int flag=0;
  char s[5];

  cin >> s;
  if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]){
    flag=1;
  }else if(s[0]==s[2] && s[1]==s[3] && s[0]!=s[1]){
    flag=1;
  }else if(s[0]==s[3] && s[1]==s[2] && s[0]!=s[1]){
    flag=1;
  }

  if(flag==0){
    cout << "No\n";
  }else{
    cout << "Yes\n";
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define LL long long

int main(){

	int x, seed,x_sqrt,currentVal, maxVal = 0, i;
	std::cin >> x;
	x_sqrt = (int)std::sqrt(x);

	if(x<=3){
		std::cout << x << std::endl;
		return 0;
	}

    for(seed=2;seed<=x_sqrt;seed++){
		currentVal = seed;
        for(i=0;i<x;i++){
			currentVal *= seed;
			if(currentVal>x)break;
			if(currentVal>=maxVal){
				maxVal = currentVal;
				if(maxVal==x){
					std::cout << maxVal << std::endl;
					return 0;
				}
			}
        }
    }

	std::cout << maxVal << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <bitset>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
 
typedef long long ll;
typedef long double ld;
 
const ll MOD = 1e9 + 7, INF = 1e18 + 1;
 
using namespace std;
 
int p[1000000], sz[1000000], n, L, R;
int a[1000000], t, dp[1000][1000], ans;
 
struct block
{
	int l, r, v;
 
	bool blocked, stable;
} d[1000000];
 
int find (int x)
{
	if (p[x] == x) return x;
	else return p[x] = find (p[x]);
}
 
block unblock (block& s)
{
	if ((s.l - 1 < L || d[p[s.l - 1]].stable) && (s.r + 1 > R || d[p[s.r + 1]].stable)) 
	{
		s.blocked = true;
	}
	else s.blocked = false;
}
 
void update (int a, int b, int c)
{
	a = find (a);
	b = find (b);
 
	if (a == b) return;
 
	if (sz[a] < sz[b]) swap (a, b);
 
	d[a] = {min (d[a].l, d[b].l), max (d[a].r, d[b].r), c, false, true};
 
	unblock (d[a]);
 
	p[b] = a;
	sz[a] += sz[b];
}
 
bool check (int k)
{
	vector <int> v, new_v;
 
	L = 0, R = n - 1;
 
	for (int i = 0; i < n; i++)
	{
		p[i] = i;
		sz[i] = 1;
	}
 
	for (int i = 0; i < n; i++)
	{
		if (a[i] >= k) d[i] = {i, i, 1, false, false};
		else d[i] = {i, i, 0, false, false};
		if (i && d[find (i - 1)].v == d[find (i)].v) update (i - 1, i, d[i].v);
	}

	for (int i = 0; i < n; i++)
	{
		unblock (d[find (i)]);
		if (d[find (i)].stable && (v.empty () || v.back () != find (i))) v.push_back (find (i));
	}
 
	while (L < R)
	{
		d[find (L)].l++;
 
		L++;
 
		d[find (R)].r--;
 
		R--;
 
		for (int i : v)
		{
			block x = d[find (i)];
 
			if (x.blocked) continue;
 
			if (x.l - 1 >= L)
			{
				int to = find (x.l - 1);
				if (d[to].stable && d[to].v == x.v ||
					!d[to].stable && ((d[to].v + (L & 1)) % 2 == x.v)) update (i, to, x.v);
			}
 
			if (x.r + 1 <= R)
			{
				int to = find (x.r + 1);
				if (d[to].stable && d[to].v == x.v ||
					(!d[to].stable && ((d[to].v + (L & 1)) % 2 == x.v))) update (i, to, x.v);
			}
		}
 
		new_v.clear ();
 
		for (int i : v)
		{
			unblock (d[find (i)]);
 
			block x = d[find (i)];
 
			if (x.blocked || !x.stable) continue;
 
			if (!new_v.empty () && new_v.back () == find (i)) continue;
 
			new_v.push_back (find (i));
		}
		v = new_v;
	}

	if (d[find (L)].stable) return d[find (L)].v;
	else return (d[find (L)].v + L) & 1;
}
 
int main ()
{
	cin >> n;
 
	n = 2 * n - 1;
	 
	for (int i = 0; i < n; i++)
	{
		scanf ("%d", &a[i]);
	}
	 
	int l = 0, r = 2e9;
	
	while (l < r)
	{
		int mid = (l + r + 1) / 2;
	
		if (check (mid)) l = mid;
		else r = mid - 1;
	}

	cout << l;
}

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

const int MAX = 3000000;
const int mod = 1000000007;

long long fac[MAX]; //i!%mod=fac[i]
long long finv[MAX]; //pow(i!,-1)%mod=finv[i]
long long inv[MAX]; //pow(i,-1)%mod=inv[i]

void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(int argc, char const *argv[])
{
	cominit();
	int r1,c1,r2,c2;
	cin>>r1>>c1>>r2>>c2;
	long long ans=com(r2+c2+2,r2+1)-com(r1+c2+1,r1)-com(c1+r2+1,c1)+com(r1+c1,r1);
	ans%=mod;
	ans+=mod;
	ans%=mod;
	cout<<ans<<endl;
	return 0;
}


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

int main(){
    char S[4];
    char T[4];
    cin >> S >> T;
    int cnt = 0;
    for(int i = 0; i < 3; i++){
        if(S[i] == T[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
use std::cmp::min;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main(){
    input!{
        v:[u64;3],
    }
    let result = v[0] / (v[1] + v[2]) * v[1] + min(v[0] % (v[1] + v[2]), v[1]);
    println!("{}", result)
}

Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<cstring>
#define chkmin(a,b) a=min(a,b);
using namespace std;
const int maxn=300010;
int n,f[70000000],h[maxn];
char s[maxn];
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	memset(f,0x3f,sizeof(f));f[0]=0;
	for(int i=1;i<=n;i++)
		h[i]=h[i-1]^(1<<(s[i]-'a')); 
	for(int i=1;i<=n;i++)
		for(int j=0;j<26;j++)
			chkmin(f[h[i]],f[h[i]^(1<<j)]+1);
	printf("%d",max(1,f[h[n]]));
}

Measured memory_bytes: 274688
X, Y = map(int, input().split())
money = 0
for i in [X, Y]:
    if i == 1:
        money += 300000
    elif i == 2:
        money += 200000
    elif i == 3:
        money += 100000
if X == 1 and Y == 1:
    money += 400000
print(money)


Measured memory_bytes: 2940
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
      int[] Kn = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
      int K = sc.nextInt();

      System.out.println(Kn[K-1]);

    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    int n;
    scanf("%d", &n);

    int h[n], i, ans=0, tmp=0;
    for(i=0; i<n; i++) scanf("%d", &h[i]);
    for(i=0; i<n-1; i++)
    {
        if(h[i]>=h[i+1]) tmp++;
        else
        {
            if(tmp>ans) ans=tmp;
            tmp=0;
        }
    }
    if(tmp>ans) ans=tmp;
    printf("%d", ans);
    return 0;

}

Measured memory_bytes: 512
#include<stdio.h>
#define MAX 1000000

typedef struct{

  int x,y,z;

}Tree;


Tree A[MAX];

int Depth(int);

int main(){

  int i,j,n,num,d,c,k=0;


  scanf("%d",&n);

  for(i = 0; i < n ;i++){

    A[i].x = -1;
    A[i].y = -1;
    A[i].z = -1;
  }


  for(i = 0; i < n ;i++){

    scanf("%d%d",&num,&d);

    for(j = 0; j < d; j++){

      scanf("%d",&c);

      if(j == 0)A[num].y = c;

      else A[k].z = c;

      k = c;
      A[c].x = num;

    }
  }


  for(i = 0; i < n; i++){

    printf("node %d: parent = %d, depth = %d,",i,A[i].x,Depth(i));

    if(Depth(i) == 0) printf(" root, [");

    else if(A[i].y == -1) printf(" leaf, [");

    else printf(" internal node, [");

    j = A[i].y;

    while(j != -1){

      printf("%d",j);

      j = A[j].z;

      if(j != -1){

	printf(", ");
      }
    }

    printf("]\n");
  }

  return 0;
}



int Depth(int num){

  int dep = 0;

  while(A[num].x != -1){

    num = A[num].x;
    dep++;
  }

  return dep;
}
      
	  
	



Measured memory_bytes: 2960
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

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

  int N;
  cin >> N;
  cout << (N - 1) / 2 << endl;

  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define in_arr(name,size) for(int i = 0;i<size;i++)\
cin >> name[i];
#define QUICK ios_base::sync_with_stdio(0);cout << fixed;

string upper(string);
string lower(string);
bool isalup(string);
bool isalow(string);
/*
class node{
public:
    int val;
    node* next;
    node(int a){
        next = NULL;
        val = a;
    }
    ~node(){
        cout << "One node is removed\n";
    }
};

class linklist{
    public:
    node*head = NULL;
    node* tail;
    void add(int a){
        node*temp = new node(a);
        temp->next = head;
        head = temp;
        if(size()==1)
            tail = head;
    }
   bool isempty(){
        return head == NULL;
    }
    void remove_front(){
        node* temp = head;
        head = head->next;
        delete temp;
    }
    void remove_val(int a){
        if(!detect(a)){
            cout << "Element not founded\n";
            return;
        }
        cout << "akan ada node yang akan dihapus\n";
        node* temp = head;
        node* dummy = new node(0);
        dummy->next = head;
        node*temp_2 = dummy;

        while(temp&&temp_2){
            if(temp->val==a)
            {
                node* temp_3 = temp;
                temp_2->next = temp->next;
                if(temp->next==NULL)
                    break;
                temp = temp->next->next;
                delete temp_3;
                continue;
            }
            temp_2 = temp_2->next;
            temp = temp->next;
        }

        delete dummy;
    }
    ~linklist(){
        while(!isempty()){
            remove_front();
        }
    }
    bool detect(int a){
        node* temp = head;
        while(temp!=NULL){
            if(temp->val==a)
                return true;
            temp = temp->next;
        }
        return false;
    }
    int size(){
        int a = 0;
        node*temp = head;
        while(temp){
            a++;
            temp = temp->next;
        }
        return a;
    }

};*/

int main(){
    int ans = 0;
    int a,b,c;
    cin >> a >> b >> c;
    for(int i = a;i<=b;i++){
        if(i%c==0)
            ans++;
        
    }
cout << ans;

   /* cout << "TES\n";
    linklist one;
    cout << "TES\n";
    one.add(20);
    cout << "TES\n";
    one.add(50);
    cout << "TES\n";
    one.add(100);
    cout << "TES\n";
    one.add(20);
    cout << "TES\n";
    one.remove_val(20);
    cout << "TES\n";
    cout << "Size linked list :" << one.size() << endl;*/

    return 0;
}









string upper(string a){
    for(char& c:a){
        if(islower(c))
            c -= 32;
       }
    return a;
}
    string lower(string a){
        for(char& c : a){
            if(isupper(c))
                c += 32;
        }
        return a;
    }
    bool isalup(string a){
        for(char& c: a){
            if(islower(c))
                return false;
        }
        return true;
    }
    bool isalow(string a){
        for(char& c:a){
            if(isupper(c))
                return false;
        }
       return true;
    }


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

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((a == b && b == c) || (a != b && b != c && a != c)) {
    cout << "No\n";
  }
  else {
    cout << "Yes\n";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx; 
    int dy = ty - sy;
    for(int i = 0; i < abs(dy); i++) cout << 'U';
    for(int i = 0; i < abs(dx); i++) cout << 'R';
    for(int i = 0; i < abs(dy); i++) cout << 'D';
    for(int i = 0; i < abs(dx); i++) cout << 'L';
    cout << 'L';
    for(int i = 0; i < abs(dy+1); i++) cout << 'U';
    for(int i = 0; i < abs(dx+1); i++) cout << 'R';
    cout << 'D';
    cout << 'R';
    for(int i = 0; i < abs(dy+1); i++) cout << 'D';
    for(int i = 0; i < abs(dx+1); i++) cout << 'L';
    cout << 'U';
    cout << endl; 
}



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

int main(){

  int r = 0;
  double sum = 0;

  cin >> r;

  if(r>=1 && r<=100){
    sum = r*2*(M_PI);
  }

cout << sum << endl;
//cout << (sum - 458.67252742410977361942)*100 << endl;
}

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

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 998244353;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    ll a, b, k;
    cin >> a >> b >> k;
    cout << max(0LL, a-k) _ min(b, max(0LL, b-(k-a))) << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

#define ll signed long long 
const ll MOD = 1000000007;
const ll MAX = 200001;

ll fac[MAX], fac_inv[MAX], inv[MAX];

// テーブルを作る前処理
void combination_init() {
  fac[0] = fac[1] = 1;
  fac_inv[0] = fac_inv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    fac_inv[i] = fac_inv[i - 1] * inv[i] % MOD;
  }
}

ll combination(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (fac_inv[k] * fac_inv[n - k] % MOD) % MOD;
}

ll pow(ll n, ll k) {
  ll ret = 1;
  while (k > 0) {
    if (k & 1) {
      ret = ret * n;
      ret %= MOD;
    }
    n = n * n;
    n %= MOD;
    k >>= 1;
  }
  return ret;
}



int main() {
  combination_init();
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = pow(2ll, n) - 1;
  if (ans < 0) {
    ans += MOD;
  }
  ans %= MOD;

  ll s = 1;
  for (int i = n - a + 1; i <= n; ++i) {
    s *= i;
    s %= MOD;
  }
  s *= fac_inv[a];
  s %= MOD;

  ans -= s;
  if (ans < 0) {
    ans += MOD;
  }
  ans %= MOD;
  
  s = 1;
  for (int i = n - b + 1; i <= n; ++i) {
    s *= i;
    s %= MOD;
  }
  s *= fac_inv[b];
  s %= MOD;

  ans -= s;
  if (ans < 0) {
    ans += MOD;
  }
  ans %= MOD;

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


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

using namespace std;

vector<int> adj[100100];
int dp[100100];
int n, m, ans;

int dfs(int u) {
    if (!dp[u]) {
        for (int v : adj[u]) {
            dp[u] = max(dp[u], dfs(v));
        }
        dp[u]++;
    }
    return dp[u];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
    }
    for (int i = 0; i < n; i++) ans = max(ans, dfs(i));
    cout << ans - 1 << '\n';
}

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

int main() {
  int n; cin>>n; bool ok=true;
  int a[n];
  for(int i=0;i<n;i++) {
    cin>>a[i];
  }
  sort(a,a+n);
  for(int i=0;i<n-1&&ok;i++) {
    if (a[i]==a[i+1]) ok=false;
  }
  cout<<((ok)?"YES":"NO")<<endl;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_D 10
#define MAX_N_PROBLEM 100
i64 D, G;
i64 P[MAX_D + 1];
i64 C[MAX_D + 1]; // 1-indexed

void solve() {
  i64 min_n = 10000; // 解く問題数の最小値
  for (i64 bit = 0; bit < pow(2, D); bit++) {
    i64 score = 0;
    i64 n_problem = 0;
    REPS(i, D) {
      if (bit & (1 << (i - 1))) {
        // 完全に解く
        score += (i * 100) * P[i] + C[i];
        n_problem += P[i];
      }
    }

    if (score >= G) {
      chmin(min_n, n_problem);
    } else {
      // 残りの問題で配点が最も高いものを解く
      i64 rem = (G - score);
      i64 k = 0;
      REPS(i, D) {
        if (bit & (1 << (i - 1))) continue;
        chmax(k, i);
      }
      i64 n = rem / (k * 100) + (rem % (k * 100) > 0);
      n_problem += n;
      score += (k * 100) * n;
      if (n < P[k]) {
        assert(score >= G);
        chmin(min_n, n_problem);
      }
    }
  }

  cout << min_n << endl;
}

int main() {
  cin >> D >> G;
  REPS(i, D) {
    cin >> P[i] >> C[i];
  }

  solve();

  return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  long n, m;
  readf("%s %s\n", &n, &m);
  auto a = readln.chomp.split.to!(long[]);

  auto d = n - a.sum;
  if (d >= 0) {
    d.writeln;
  } else {
    writeln(-1);
  }
}


Measured memory_bytes: 3312
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
typedef long long int ll;

int main(){
    int n; cin >> n;
    n--;
    vector<int> v(500,0);
    for(int i=0;i<500;i+=2){
        v[i]=1;
    }
    for(int i=1;i<500;i+=4){
        v[i]=2;
    }
    for(int i=3;i<500;i+=8){
        v[i]=3;
    }
    for(int i=7;i<500;i+=16){
        v[i]=4;
    }
    for(int i=15;i<500;i+=32){
        v[i]=5;
    }
    for(int i=31;i<500;i+=64){
        v[i]=6;
    }
    for(int i=63;i<500;i+=128){
        v[i]=7;
    }
    for(int i=127;i<500;i+=256){
        v[i]=8;
    }
    for(int i=255;i<500;i+=512){
        v[i]=9;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n-i;j++){
            cout << v[j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int w,n,str[30],fin[30],ans[31],add[31],now=0;
    char stri[7];
    cin>>w>>n;
    for(int i=0;i<n;i++){
        cin>>stri;
        if(stri[3]=='\0'){
            str[i]=stri[0]-'0';
            fin[i]=stri[2]-'0';
        }
        else if(stri[4]=='\0'&&stri[1]==','){
            str[i]=stri[0]-'0';
            fin[i]=(stri[2]-'0')*10+(stri[3]-'0');
        }
        else if(stri[4]=='\0'){
            str[i]=(stri[0]-'0')*10+(stri[1]-'0');
            fin[i]=stri[3]-'0';
        }
        else {
            str[i]=(stri[0]-'0')*10+(stri[1]-'0');
            fin[i]=(stri[3]-'0')*10+(stri[4]-'0');
        }
        add[i]=fin[i]-str[i];
    }
    for(int i=1;i<=w;i++){
        now=i;
        for(int j=0;j<n;j++){
            if(now==str[j])now+=add[j];
            else if(now==fin[j])now-=add[j];
        }
        ans[now]=i;
    }
    for(int i=1;i<=w;i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX/2;

int main(){
    int H, N; cin >> H >> N;
    vector<int> dp(H+1, INF);
    dp[0] = 0;
    for(int i=0; i<N; i++){
        int a, b; cin >> a >> b;
        for(int j=0; j<H; j++){
            int nj = min(a+j, H);
            dp[nj] = min(dp[nj], dp[j]+b);
        }
    }
    //for(auto i : dp) cout << i << endl;
    cout << dp[H] << endl;
}

Measured memory_bytes: 256
//from PKU1125
main(){
	int a,b,c,t,k,n,i,j,time[101][101],cost[101][101];
	for(;scanf("%d%d",&k,&n),n;){
		/*initialize*/
		memset(time,11,sizeof(time));
		memset(cost,11,sizeof(cost));
		for(i=1;i<=n;i++)time[i][i]=cost[i][i]=0;
		for(;k;k--){
			scanf("%d%d%d%d",&a,&b,&c,&t);
			time[a][b]=time[b][a]=t;
			cost[a][b]=cost[b][a]=c;
		}

		{/*warshall-floyd*/
			int k,i,j;
			for(k=1;k<=n;k++)
				for(i=1;i<=n;i++)
					for(j=1;j<=n;j++){
						if(time[i][j]>time[i][k]+time[k][j])
							time[i][j]=time[i][k]+time[k][j];
						if(cost[i][j]>cost[i][k]+cost[k][j])
							cost[i][j]=cost[i][k]+cost[k][j];
					}
		}

		{/*query*/
			for(scanf("%d",&k);k;k--){
				scanf("%d%d%d",&a,&b,&t);
				printf("%d\n",t?time[a][b]:cost[a][b]);
			}
		}
	}exit(0);
}

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

int64_t n;

void solve() {
    int64_t ans = 1e12;
    for (int64_t i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            int64_t tmp = i + (n / i) - 2;
            if (tmp < ans) {
                ans = tmp;
            }
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 256
//============================================================================
// Name        : abc104-a.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
using namespace std;

int main() {
	
	int R;
	cin >> R;
	if(R < 1200){
		cout << "ABC" << endl;
		return 0;
	}
	if(R < 2800){
		cout << "ARC" << endl;
		return 0;
	}
	cout << "AGC" << endl;
	
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define mod 1e9+7
int x,y;
int main()
{
    
    cin>>x>>y;
    int ans=0;
    if(x==1)
        ans+=300000;
    else if(x==2)
        ans+=200000;
    else if(x==3)
        ans+=100000;


    if(y==1)
        ans+=300000;
    else if(y==2)
        ans+=200000;
    else if(y==3)
        ans+=100000;

    if(x==1&&y==1)
        ans+=400000;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define vll vector<ll>
#define G vector<vll >
#define gg vector<int>
#define F first
#define S second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define RFOR(i,a,b) for(int i=a;i>=b;i--)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define endl '\n'
#define clr(a) memset(a,0,sizeof(a))
#define all(x) x.begin(),x.end()
#define rll read_ll();
#define gc getchar
#define pc putchar
typedef long long ll;
template<class T> inline T lcm(T a,T b){
        return a/gcd(a,b)*b;
}
template<typename T>
void debug(T first) {
    cout << first << "\n";
}
template<typename T, typename... Args>
void debug(T first, Args... args) {
    cout << first << " ";
    debug(args...);
}


ll read_ll(){char c=gc();while((c<'0'||c>'9')&&c!='-')c=gc();ll ret=0;int neg=0;if(c=='-')neg=1,c=gc();while(c>='0'&&c<='9'){ret=10*ret+c-48;c=gc();}return neg?-ret:ret;}

int main()
{
	string s; cin>>s;
	int n = s.length();
	ll cnt = 0, ans = 0;
	reverse(all(s));
	for(auto val : s) {
		if(val == 'W') cnt++;
		else ans+=cnt;
	}
	cout<<ans;
	return 0;
}

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

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }


int main() {

    CIN(int, N);
    CINS(int, A, N);

    int ans = A[0];
    for (int i = 1; i < N; i++) {
        ans = gcd(ans, A[i]);
    }

    cout << ans << "\n";
    return 0;
}

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

int main()
{
	vector<int> a(3);
	for (int i = 0; i < 3; i++)
	{
		cin >> a.at(i);
	}

	sort(a.begin(), a.end());
	
	cout << a.at(0) << " " << a.at(1) << " " << a.at(2) << endl;
}



Measured memory_bytes: 3088