akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin (),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll n, a, b;
	cin >> n >> a >> b;
	ll both = n/(a+b);
	ll rem = min(a, n%(a+b));
	cout << both*a + rem;
}








Measured memory_bytes: 256
a,b,c,x,y = map(int,input().split())
sum_l = []
#a,b only
sum_l.append(a*x+b*y)
#c only
sum_l.append(max(x,y)*2*c)
#min(x,y) 
sum_n = min(x,y)*2*c
if(x>y):
    sum_n +=(x-y)*a
else:
    sum_n += (y-x)*b
sum_l.append(sum_n)
print(min(sum_l))

Measured memory_bytes: 9148
#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>

using namespace std;

int main(int argc, char *argv[]) {
	int r;
	cin >> r;
	cout << r * 2 * 3.1415926 << endl;
	
}


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

int main() {
    string s;
    cin>>s;
    for(int i=0; i<s.length(); ++i) {
        if(count(s.begin(), s.end(), s[i])!=2) {
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
}


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

int main()
{
	int N;
	cin >> N;
	vector<long long> A(N);
	unordered_map<long long, long long> freq;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		freq[A[i]]++;
	}
	
	long long total = 0;
	for (auto& x : freq)
	{
		total += x.second * (x.second - 1) / 2;
	}
	
	for (int k = 0; k < N; ++k)
	{
		long long answer = total;
		long long x = freq[A[k]];
		if (x > 1)
			answer = answer - x*(x-1)/2 + (x-1)*(x-2)/2;
		cout << answer << '\n';
	}
}


Measured memory_bytes: 9160
#include <stdio.h>

#define N 200000

int main() {
	static int link1[N], link2[N];
	int n, m, i;

	scanf("%d%d", &n, &m);
	while (m--) {
		int a, b;

		scanf("%d%d", &a, &b), a--, b--;
		if (a == 0)
			link1[b] = 1;
		if (b == n - 1)
			link2[a] = 1;
	}
	for (i = 1; i < n - 1; i++)
		if (link1[i] && link2[i]) {
			printf("POSSIBLE\n");
			return 0;
		}
	printf("IMPOSSIBLE\n");
	return 0;
}


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

typedef long long ll;
#define PI 2 * acos (0.0)

ll MOD = 1e9 + 7 ;
ll arr[200005] ;

int main()
{
  ll n, x, cntTwo = 0, cntFive = 0, divTwo = 2, divFive = 5, ans ;
  cin >> n ;

  if(n % 2 != 0)  cout << 0 << endl ;
  else {
    while(true) {
      x = n / divTwo ;
      cntTwo += x ;
      divTwo *= 2 ;
      if(x == 0)  break ;
    }

    while(true) {
      x = n / divFive ;
      x /= 2 ;
      cntFive += x ;
      divFive *= 5 ;
      if(x == 0)  break ;
    }

    ans = min(cntFive, cntTwo) ;
    cout << ans << endl ;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef long double ld;
#define loopi(n) for(i=0;i<n;i++) 
#define loopj(n) for(j=0;j<n;j++)
#define loopnode(v) for(ll i : v)
#define mod7 1000000007
#define mod9 1000000009
#define mod8 100000000
#define modl 998244353
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef std::vector<ll> vecl;
typedef std::vector<bool> vecb;
typedef std::vector<long double> vecd;
typedef std::vector<string> vecstr;
typedef std::vector<char> vecch;
typedef std::vector< pair<ll,ll> >  vecpair;
typedef unordered_map<ll,ll> umap;
typedef unordered_map<long double,int> umapd;
typedef unordered_map<string,ll> umapstr;
typedef unordered_map<char,ll> umapc;
typedef set< ll,greater<ll>  > st;
typedef priority_queue<ll> q_max;
typedef priority_queue<ll,vector<ll>,greater<ll> > q_min;
ll j=0,i=0;//ll maxm = INT_MIN;

//vecl node[300001];vecl color(300001,-1);umap u;vecl res(300001,0);//ll flag = 1;
//vecb visited(300000+1,false);

int main(int argc, char const *argv[])
{

	ll x[5];
	loopi(5)
	{
		cin>>x[i];
	}
	loopi(5)
	{
		if(x[i]==0)
			break;
	}
	cout<<i+1;

	return 0;

	
}

Measured memory_bytes: 3620
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, f[10][10];

II getFirstLast(int u) {
    vector<int> a;
    while (u) {
        a.emplace_back(u % 10);
        u /= 10;
    }
    return II(a[SZ(a)-1], a[0]);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    ll res = 0;
    FOR(i,1,n) {
        II x = getFirstLast(i);
        if (x.FI == 0 || x.SE == 0) continue;
        f[x.FI][x.SE]++;
    }
    FOR(i,1,9)
        FOR(j,1,9) res += (ll) f[i][j] * f[j][i];
    cout << res;
    return 0;
}


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

s = sum(range(1, n + 1))

for i in range(2, n+1):
  t = n // i
  # 1 + 2 + 3 + ... + t
  s += i * (1 + t) * t // 2
#  for j in range(1, n // i + 1):
#    s += i * j

print(s)

Measured memory_bytes: 9084
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define set multiset
#define null NULL
#define ort (b+s)/2

using namespace std;

typedef long long Lint;
typedef long double db;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef pair<db,db> dd;
typedef pair<int,string> is;

const int maxn = 1000020;
const int K = 320;
const int MOd = 1e9 + 7;

Lint ar[maxn], a, k;
vector<Lint> v;

Lint f( Lint x ) {
	Lint ans = 0;
	for(int i=1;i<=a;i++) {
		if( ar[i] == 0 ) {
			if( 0 <= x )
				ans += a;
		} else if( ar[i] > 0 ) {
			Lint h = x/ar[i];
			// -3/4 || -4/4
			if( x < 0 && x%ar[i] != 0 ) h--;
			int t = upper_bound( all( v ), h ) - v.begin();
			ans += t;//printf("asdasd %lld\n",h);
		} else {
			// 4, -3
			Lint h = x/ar[i];
			// -3, -2
			if( x < 0 && (-x)%(-ar[i]) != 0 ) h++;
			int t = v.end()-lower_bound( all( v ), h );
			//printf("asd %lld\n",h);
			ans += t;
		}
		if( ar[i]*ar[i] <= x ) ans--;
		//printf("%d --> %d (%lld)\n",i,ans,ar[i]);
	}
	//printf("x=%lld --> ans=%lld\n",x,ans);
	return ans/2;
}
int dn[maxn][2];
void solve() {
	string s;
	cin >> s;
	dn[s.size()][1] = 1;
	for(int i=s.size()-1;i>=0;i--) {
		s[i] -= '0';
		dn[i][0] = min( dn[i+1][1] + 1 + s[i], dn[i+1][0] + s[i] );
		dn[i][1] = min( dn[i+1][1] + 10 - s[i] - 1, dn[i+1][0] + 10 - s[i] );
		//printf("asd %d %d\n",dn[i][0],dn[i][1]);
	}
	cout << min( dn[0][0], dn[0][1] + 1 ) << endl;
}

int main(  ) {


    int n = 1;
    //scanf("%d",&n);
    while( n-- ) solve();

    return 0;
}


Measured memory_bytes: 9476
# -*- coding: utf-8 -*-
a, b, c = map(int,input().split())

if a == b == c and a % 2 == 0:
    print(-1)
else:
    ans = 0
    while True:
        #print(a, b, c)
        if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
            print(ans)
            break
        else:
            ans += 1
            tmpa = a
            tmpb = b
            tmpc = c
            a = tmpb // 2 + tmpc // 2 - tmpa
            b = tmpa // 2 + tmpc // 2 - tmpb
            c = tmpa // 2 + tmpb // 2 - tmpc


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  string s;cin>>s;int sz=s.size();int i;
  deque<char> a;
  for(i=0;i<sz;i++){
    if(s.at(i) =='0'){
      a.pb('0');
    }else if(s.at(i) =='1'){
      a.pb('1');
    }else{
      if(!a.empty()){a.pop_back();}
    }
  }
  //caricurate
  //output
  while(!a.empty()){
    cout<<a.front();
    a.pop_front();
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

typedef struct
{
        int MEMBER00 ;
        int MEMBER01 ;
        int MEMBER02 ;
        int MEMBER03 ;
        int MEMBER04 ;
        int MEMBER05 ;
} STRUCT00 ;

int main ( )
{
        STRUCT00 VAR00 ;
        char VAR01 [ 100 ] ;
        int VAR02 = 0 , VAR03 = 0 , VAR04 ;

        scanf ( "%d %d %d %d %d %d" , & VAR00 . MEMBER00 , & VAR00 . MEMBER01 ,
                        & VAR00 . MEMBER02 , & VAR00 . MEMBER03 , & VAR00 . MEMBER04 , & VAR00 . MEMBER05 ) ;

        scanf ( "%s" , VAR01 ) ;

        VAR02 = strlen ( VAR01 ) ;
        while ( VAR03 < VAR02 )
        {
                if ( VAR01 [ VAR03 ] == 'S' )
                {
                        VAR04 = VAR00 . MEMBER01 ;
                        VAR00 . MEMBER01 = VAR00 . MEMBER00 ;
                        VAR00 . MEMBER00 = VAR00 . MEMBER04 ;
                        VAR00 . MEMBER04 = VAR00 . MEMBER05 ;
                        VAR00 . MEMBER05 = VAR04 ;
                }
                else if ( VAR01 [ VAR03 ] == 'W' )
                {
                        VAR04 = VAR00 . MEMBER03 ;
                        VAR00 . MEMBER03 = VAR00 . MEMBER00 ;
                        VAR00 . MEMBER00 = VAR00 . MEMBER02 ;
                        VAR00 . MEMBER02 = VAR00 . MEMBER05 ;
                        VAR00 . MEMBER05 = VAR04 ;
                }
                else if ( VAR01 [ VAR03 ] == 'N' )
                {
                        VAR04 = VAR00 . MEMBER04 ;
                        VAR00 . MEMBER04 = VAR00 . MEMBER00 ;
                        VAR00 . MEMBER00 = VAR00 . MEMBER01 ;
                        VAR00 . MEMBER01 = VAR00 . MEMBER05 ;
                        VAR00 . MEMBER05 = VAR04 ;
                }
                else if ( VAR01 [ VAR03 ] == 'E' )
                {
                        VAR04 = VAR00 . MEMBER02 ;
                        VAR00 . MEMBER02 = VAR00 . MEMBER00 ;
                        VAR00 . MEMBER00 = VAR00 . MEMBER03 ;
                        VAR00 . MEMBER03 = VAR00 . MEMBER05 ;
                        VAR00 . MEMBER05 = VAR04 ;
                }
                VAR03 = VAR03 + 1 ;
        }

        printf ( "%d\n" , VAR00 . MEMBER00 ) ;
        return 0 ;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a % 2==0 || b % 2==0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}
  

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int P[N];
    REP(i, N){
        cin >> P[i];
    }

    int res = 0;
    REP(i, N-2){
        if(P[i+1] < max(P[i], P[i+2]) and P[i+1] > min(P[i], P[i+2])){
            res++;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3596
require 'prime'

MAX = 10 ** 6
n = gets.to_i
a_n = gets.split.map(&:to_i)

# 全GCDが1でない場合どちらでもない
all_gcd = a_n[0]
1.upto(n-1) do |i|
    all_gcd = all_gcd.gcd(a_n[i])
end
if all_gcd > 1
    puts "not coprime"
    exit 0
end

## ============
## 以下は全GCDは常に1前提
## ============

memo = Array.new(MAX + 1, 0)
primes = Array.new(MAX + 1, 0)
Prime.each(MAX) do |i|
    primes[i] = 1
end

a_n.each do |a|
    # 素数はすでに計算済みなので素因数分解を省略
    if primes[a] == 1
        if memo[a] == 1
            puts "setwise coprime"; exit 0
        end

        memo[a] = 1
    else
        Prime.prime_division(a).each do |x, cnt|
            if memo[x] == 1
                puts "setwise coprime"; exit 0
            end
            memo[x] = 1
        end
    end
end

puts "pairwise coprime"


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

const int maxn = 200010;
int n, a[maxn], st[20][maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]), st[0][i] = i;
    }
    for (int i = 1; i < 20; i++) {
        for (int j = 1; j + (1 << i) - 1 <= n; j++) {
            int x = a[st[i - 1][j]], y = a[st[i - 1][j + (1 << (i - 1))]];
            st[i][j] = x < y ? st[i - 1][j] : st[i - 1][j + (1 << (i - 1))];
        }
    }
    auto query = [&](int l, int r) {
        int k = log2(r - l + 1);
        int x = a[st[k][l]], y = a[st[k][r - (1 << k) + 1]];
        return x < y ? st[k][l] : st[k][r - (1 << k) + 1];
    };
    function<long long(int, int)> solve = [&](int l, int r) {
        if (l > r) return 0LL;
        int t = query(l, r);
        return solve(l, t - 1) + solve(t + 1, r) + 1LL * a[t] * (t - l + 1) * (r - t + 1);
    };
    printf("%lld\n", solve(1, n));
    return 0;
}

Measured memory_bytes: 29184
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define print(x) cout << (x) << endl 
#define min2(a, b) ((a) < (b)) ? (a) : (b)
#define max2(a, b) ((a) > (b)) ? (a) : (b)
#define count counting_variable

typedef long long ll;

using namespace std;

int main(){
    unsigned long long N, A[5], mincap = 0;
    cin >> N;
    rep(i, 0, 5) cin >> A[i];
    rep(i, 0, 5){
        if(A[i] < A[mincap]) mincap = i;
    }
    print(((N - 1) / A[mincap] + 5));
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	long k,a,b;
	cin >> k >> a >> b;
	long ans=0;
	if(!(a+1<b)) ans=k+1;
	else{
		k-=a-1;
		ans=a;
		ans+=(b-a)*(k/2);
		if(k%2) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// ConsoleApplication9.cpp : アプリケーションのエントリ ポイントを定義します。
//


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define p(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
//#define int long long


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

bool arr[100000100];
vector<ll>sosuu;
void Eratosthenes() {
	ll N = 10000010;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (ll i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (ll j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int ll i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu.pb(i);
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}


bool prime(ll n) {
	if (n == 1)return false;
	if (n == 2)return true;
	for (int i = 2; i < (int)sqrt(n) + 1; i++) {
		if (n%i == 0)return false;
	}
	return true;
}

int N, M;
int P[100010], Y[100010];
vector<int>v[100010];

int main() {
	cin >> N >> M;
	REP(i, M) {
		cin >> P[i] >> Y[i];
		v[P[i]].pb(Y[i]);
	}
	REP(i, N) {
		VSORT(v[i+1]);
	}
	REP(i, M) {
		cout << setw(6) << setfill('0') << P[i];
		vector<int>::iterator it = lb(v[P[i]], Y[i]);
		cout << setw(6) << setfill('0') << it-v[P[i]].begin()+1<<endl;
	}
}



Measured memory_bytes: 8704
n, w = map(int, input().split())

dist = [[float('inf')] * 10 for i in range(10)]
for i in range(10):
    c = list(map(int, input().split()))
    for j in range(10):
        dist[i][j] = c[j]

# warshall_floydを回してdistを改良
def warshall_floyd(dist):
    for k in range(10):
        # i:start j:goal k:中間地点でループ回す
        for i in range(10):
            for j in range(10):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    return dist
warshall_floyd(dist)

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

cnt = 0
for row in board:
    for i in row:
        if (i == -1) or (i == 1):
            continue
        else:
            cnt += dist[i][1]
print(cnt) 

Measured memory_bytes: 40540
A, B = map(int, input().split())

a = A % 2
b = B % 2
c = B - A + 1

if A == B:
    print(A)
elif c == 3:
    print(A ^ (A + 1) ^ B)
elif a == 0:
    x = c % 4
    ans = 0
    for i in range(x):
        ans ^= B - i
    print(ans)
else:
    x = (c - 1) % 4
    ans = A
    for i in range(x):
        ans ^= B - i
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    rep(bit,1<<(n-1)){
        ll res = 0;
        ll now = s[0]-'0';
        rep(i,n-1){
            if(bit>>i&1){
                res += now;
                now = (ll)(s[i+1]-'0');
            }else{
                now = 10*now+(ll)(s[i+1]-'0');
            }
        }
        res+=now;
        ans+=res;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string a,b;
    cin>>a>>b;
    if (a.size()>b.size())
        cout<<"GREATER\n";
    else if (a.size()<b.size())
        cout<<"LESS\n";
    else
    {
        int i,f=0;
        for (i=0;i<a.size();i++)
        {
            if (a[i]>b[i])
            {
                f=1;
                break;
            }
            else if (a[i]<b[i])
            {
                f=2;
                break;
            }
        }
        if (f==0)
            cout<<"EQUAL\n";
        else if (f==1)
            cout<<"GREATER\n";
        else if (f==2)
            cout<<"LESS\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int N, A, B, used[100], rings[100], G[100][199];

int rec(int pos)
{
	used[pos] = 1; int ret = 1;

	for(int i = 0; i < rings[pos]; i++)
	{
		if(!used[G[pos][i]])
		{
			ret = max(ret, rec(G[pos][i]) + 1);
		}
	}

	used[pos] = 0;

	return ret;
}

int main()
{
	int N, A, B;

	while(true)
	{
		scanf("%d", &N);
 
		if(N == 0) { break; }

		for(int i = 0; i < 100; i++)
		{
			used[i] = rings[i] = 0;
		}

		for(int i = 0; i < N; i++)
		{
			scanf("%d", &A); A--;
			scanf("%d", &B); B--;

			G[A][rings[A]] = B; rings[A]++;
			G[B][rings[B]] = A; rings[B]++;
		}

		int nodes = 0;

		for(int i = 0; i < 100; i++)
		{
			if(rings[i])
			{
				nodes++;
			}
		}

		int ret = 0;

		for(int i = 0; i < 100; i++)
		{
			ret = max(ret, rec(i));

 			if(ret == nodes) break;
		}
 
		printf("%d\n", ret);
	}

	return 0;
}

Measured memory_bytes: 3192
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;

ll n, m;
vector<vector<ll>> sw(10);
vector<ll> li(10);




int main() {
	ll a, b, c; cin >> a >> b >> c;
	if (a == b && b == c) cout << 1 << endl;
	else if (a == b || b == c || a == c) cout << 2 << endl;
	else cout << 3 << endl;
}

Measured memory_bytes: 256
a, b, c, d, e, f = map(int, input().split())
W = set(); S = set()
sa = 0; wsa = a * 100

for i in range(0, f + a * 100, a * 100):
    for j in range(0, f + b * 100, b * 100):
        w = i + j
        if w <= f:
            W.add(w)
        else:
            break
for i in range(0, f // 2 + c, c):
    for j in range(0, f // 2 + d, d):
        s = i + j
        if s <= f // 2:
            S.add(s)
        else:
            break
S.remove(0)
for i in W:
    for j in S:
        if e / (100 + e) >= j / (i + j) > sa / wsa and i + j <= f:
            sa, wsa = j, i + j
print(wsa, sa)

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

vector<pair<long long, long long>> prime_factrization(long long n);


int main(){
    long long N, tmp, tmptmp;
    vector<pair<long long, long long>> prime_f;

    std::cin >> N;
    prime_f = prime_factrization(N);
    long long ans = prime_f.size();


    for(long long i = 0; i < prime_f.size(); i++){
        //std::cout << prime_f[i].first << " " << prime_f[i].second << "\n";
        if(prime_f[i].second > 1){
            tmp = 3;
            tmptmp = 2;

            while(tmp <= prime_f[i].second){
                ans = ans + 1;
                tmptmp++;
                tmp = tmp + tmptmp;
            }

        }
    }

    std::cout << ans;

}

vector<pair<long long, long long>> prime_factrization(long long n){
    vector<pair<long long, long long>> res;

    for(long long a = 2; a*a <= n; a++){
        if(n%a != 0){
            continue;
        }
        long long ex = 0;
        while(n%a == 0){
            ex++;
            n = n/a;
        }

        res.push_back({a,ex});
    }

    if(n != 1){
        res.push_back({n,1});
    }

    return res;

}

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

int dp[200][20000];
//サイズが違うだけでもとの問題とほぼ同じ
//品物を入れる入れないであるから、nが小さければbit全探索も可能だろう。
//dp[i][j]=i番目以降の品物から重さの総和がj以下となるときの価値の総和の最大値
int main(){
  //input
  int n,W;
  cin>>n>>W;
  vector<int>v(n);
  vector<int>w(n);
  for(int i=0;i<n;i++)cin>>v[i]>>w[i];
  for(int i=0;i<n;i++){dp[0][i]=0;}

  
  for(int i=1;i<=n;i++){
    for(int j=0;j<=W;j++){
      if(j<w[i-1])dp[i][j]=dp[i-1][j];//i番目がｊよりも重ければ、i-1番目の値を踏襲
      else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);//そうでなければ踏襲したほうが価値が高いか、交換したほうが価値が高いかを判断
    }
  }
  //output
  cout<<dp[n][W]<<endl;
  return 0;
}





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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

void dfs(int pos, int from, vector<vector<int>>& G, vector<int>& A, vector<int>& dp, stack<pair<int,int>>& dpr, vector<int>& ans){
    auto itr = lower_bound(ALL(dp), A[pos]);
    int it = itr - dp.begin();
    dpr.push(make_pair(it, *itr));
    dp[it] = A[pos];

    auto lis = lower_bound(ALL(dp), INF);
    int ls = lis - dp.begin();
    ans[pos] = ls;

    for(auto next: G[pos]){
        if (next == from){
            continue;
        }else{
            dfs(next, pos, G, A, dp, dpr, ans);
            auto p = dpr.top();
            dpr.pop();
            dp[p.first] = p.second;
        }
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N){
        cin >> A[i];
    }

    vector<vector<int>> G(N);
    REP(i,N-1){
        int u,v;
        cin >> u >> v;
        u--;
        v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    vector<int> ans(N,0);
    vector<int> dp(N, INF);
    stack<pair<int,int>> dpr;
    dfs(0, -1, G, A, dp, dpr, ans);

    REP(i,N){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 40876
import java.util.Scanner;
import java.util.Stack;
import java.util.TreeSet;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        Stack<Integer> st=new Stack<Integer>();
        while(true){
           String s=sc.nextLine();
           if(s.equals("."))break;
           boolean ans=true;
           int n=s.length();
           st.clear();
           st.add(300);
        for(int i=0;i<n;i++){
            if(s.equals("."))break;
            if(s.charAt(i)=='(')st.add(1);
            if(s.charAt(i)=='[')st.add(2);
            if(s.charAt(i)==')'){
               int g= st.pop();
               if(g!=1){ans=false;
                break;
               }
            }
            if(s.charAt(i)==']'){
                int g= st.pop();
                if(g!=2){ans=false;
                        break;
                }
             }
            
            }
            if(st.size()!=1)ans=false;
            if(ans)System.out.println("yes");
            else System.out.println("no");
    }
}
}



Measured memory_bytes: 43992
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

class unko10 {
public:
	char C[1275725], C9[211470];
	constexpr unko10() : C(), C9() {
		char c[11] = {};
		int d = 0;
		int k[11] = {};
		int saidai[11] = {};
		int ma = 10;

		auto ci = C;
		while (d >= 0) {
			c[d] = k[d]++ + 'a';
			saidai[d + 1] = max(saidai[d], k[d]);
			d++;
			if (d == ma) {
				rep(i, ma)* ci++ = c[i];
				*ci++ = '\n';
				d--;
			}

			while (d >= 0 && (c[d] - 'a') == saidai[d]) {
				k[d] = 0;
				c[d] = 'z';
				d--;

			}
		}
		d = 0;
		ma = 9;
		ci = C9;
		while (d >= 0) {
			c[d] = k[d]++ + 'a';
			saidai[d + 1] = max(saidai[d], k[d]);
			d++;
			if (d == ma) {
				rep(i, ma)* ci++ = c[i];
				*ci++ = '\n';
				d--;
			}

			while (d >= 0 && (c[d] - 'a') == saidai[d]) {
				k[d] = 0;
				c[d] = 'z';
				d--;
			}
		}
	}
} f;


char dn[37260], *di = dn;
int N, k,cnt;
char c[10];
void keisan(int n, int saidai) {
	if (n == N) {
		rep(i, N) *di++ = c[i];
		*di++ = '\n';
	}
	else {
		rep1(i, saidai + 1) {
			c[k++] = 'a' + i - 1;
			keisan(n + 1, max(saidai, i));
			k--;
		}
	}
}

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


	scanf("%d", &N);

	if (N < 9) {
		keisan(0, 0);
		fwrite(dn, 1, di - dn, stdout);
	}
	else if (N == 9){
		fwrite(f.C9, 1, 211470, stdout);
	}
	else {
		fwrite(f.C, 1, 1275725, stdout);
	}

	Would you please return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n, q;
int v[111111];

bool check(int x, int key) {
   return v[x] < key;
}

int solve(int key) {
   int l = -1, r = n - 1;
   while (r - l > 1) {
      int m = (l + r) / 2;
      (check(m, key)?l:r) = m;
   }
   return v[r] == key;
}

int main() {
   cin >> n;
   rep (i, n) cin >> v[i];
   cin >> q;
   int cnt = 0;
   while (q--) {
      int x;
      cin >> x;
      if (solve(x)) cnt++;
   }
   cout << cnt << endl;

   return 0;
}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int cnt(string s, string t) {
    int ret = 0;
    for (int i = 0; i < 26; ++i) {
        if (s.find('a' + i) != string::npos && t.find('a'+ i) != string::npos)
            ret++;
    }
    return ret;
}

int main() {
    int n, ans = 0;
    string s;
    cin >> n >> s;
    for (int i = 1; i <= n - 1; ++i) {
        ans = max(ans, cnt(s.substr(0, i), s.substr(i, n)));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

S = [0] * (N + 1)
for i in range(N):
    S[i + 1] = S[i] + A[i]

X = [0] * N
Y = [0] * N
x = 1
y = 3

for i in range(2, N - 1):
    L = S[i]
    R = S[N] - S[i]
    while abs(L - 2 * S[x + 1]) <= abs(L - 2 * S[x]):
        x += 1
    X[i] = x
    while abs(R - 2 * (S[y + 1] - L)) <= abs(R - 2 * (S[y] - L)):
        y += 1
    Y[i] = y

ans = S[N]
for i in range(2, N - 1):
    x = X[i]
    y = Y[i]
    B = S[x]
    C = S[i] - S[x]
    D = S[y] - S[i]
    E = S[N] - S[y]
    P = [B, C, D, E]
    ans = min(ans, max(P) - min(P))

print(ans)


Measured memory_bytes: 99192
#include<stdio.h>
int main(){
  int n,rr=0,r=0,p=1,a[100010],i,j,d[100010];
  char s[200010];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  for(i=0;i<n;i++){
    while(p<=a[i]){
      d[rr++]=p++;
      s[r++]='(';
    }
    //for(j=0;j<rr;j++)printf("%d ",d[j]);printf("\n");
    if(d[rr-1]!=a[i]){
      printf(":(\n");
      return 0;
    }
    s[r++]=')';
    rr--;
  }
  s[r]=0;
  printf("%s\n",s);
  return 0;
}
	   



Measured memory_bytes: 2328
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

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

    string s;
    cin >> s;
    for (size_t i = 0; i < s.size(); i++) {
        if (i == k - 1)
            cout << (char)(s.at(i) - 'A' + 'a');
        else
            cout << (char)s.at(i);
    }
}

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

int n, m;
vector<vector<int>> a;
vector<int> memo;
vector<bool> erased;

int solve();

int main() {
  cin >> n >> m;
  a.assign(n, vector<int>(m, 0));
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < m; ++j) {
      cin >> a[i][j];
      --a[i][j];
    }
  cout << solve() << endl;
  return 0;
}

int solve() {
  int ans = n;
  erased.assign(m, 0);
  memo.assign(n, 0);
  for(int i = 0; i < m; ++i) {
    vector<int> cnt(m, 0);
    for(int j = 0; j < n; ++j) ++cnt[a[j][memo[j]]];
    int now = 0;
    for(int j = 0; j < m; ++j)
      if(cnt[now] < cnt[j]) now = j;
    ans = min(ans, cnt[now]);
    erased[now] = 1;
    for(int j = 0; j < n; ++j)
      while(memo[j] < m && erased[a[j][memo[j]]]) ++memo[j];
  }
  return ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#include <iomanip>
//    int n=132;
//    bitset<16>binar(n);
//    int a = bitset<16>(binar).to_ulong();
//    cout<<a;
 
#define int long long
#define pb push_back
#define rep(i,b) for ( int i = 0; i < b; i++)
#define rep1(i,b) for ( int i = 1; i <= b; i++)
#define all(c) (c).begin(),(c).end()
#define MOD 100000007
#define pi  3.14159265358979323846
 
using namespace std;
 
signed main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a){
		cout<<k;
	}
	else if(k>a && k<=a+b){
		cout<<a;
	}
	else if(k>a+b && k<=a+b+c){
		cout<<a-(k-(a+b));
	}
}
	
	
	

		
	
	


Measured memory_bytes: 3644
/*
  B - ∵∴∵
  <http://abc058.contest.atcoder.jp/tasks/abc058_b>
*/

#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[]) {

  char O[51],E[51];
  int oLen,eLen;
  int i;

  scanf("%s", O);
  scanf("%s", E);

  oLen = strlen(O);
  eLen = strlen(E);

  if( (oLen-eLen) == 0 ){
    for( i=0; i<eLen; i++ ){
      printf("%c%c", O[i], E[i]);
    }
  }else{
    for( i=0; i<eLen; i++ ){
      printf("%c%c", O[i], E[i]);
    }
    printf("%c", O[oLen-1]);
  }

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
int main()
{
	int i,j,a[6],t=0;
	for(i=0;i<6;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<5;i++)
	{
		for(j=0;j<5;j++)
		{
			if(abs(a[i]-a[j])>a[5])
				t=1;
		}
	}
	if(t==1)
		printf(":(\n");
	else
		printf("Yay!\n");
	return 0;
}


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

using namespace std;

typedef long long int ll;

ll lcm(ll a, ll b) {
  return a * b / __gcd(a, b);
}

int main() {
  ll n; cin >> n;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      ll x = 4 * i * j - n * i - n * j;
      ll y = n * i * j;
      if (x > 0 && y % x == 0) {
        cout << i << ' ' << j << ' ' << y / x << endl;
        return 0;
      }
    }
  }
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

long long pow(long long a, long long b, long long m)
{
    long long ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%m;
        b/=2;
        a=(a*a)%m;
    }
    return ans;
}

const int N=1e5+5;
const int mod=1e9+7;
int32_t main() {
int n;
cin>>n;
vector<int> in(N,0);
set<int> s;
    for (int i = 0; i < n; ++i) {
        int a;
        cin>>a;
        in[a]++;
        s.insert(a);
    }
    int ans=1;
   int sum=0;
    for(auto x:s){
        if((x==0&&in[x]>1)||(x!=0&&in[x]!=2))return cout<<0,0;
       else if(x) sum++;
    }
    ans=pow(2,sum,mod);
    cout<<ans;
}

Measured memory_bytes: 3968
// B - 仲良しうさぎ
// https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_b
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> n;
  vlli a(n), b(n);
  rep(i, 0, n)
  {
    cin >> a[i];
    // b[a[i] - 1] = i;
  }
  rep(i, 0, n)
  {
    if (a[a[i] - 1] == i + 1)
    {
      count++;
    }
  }

  cout << count / 2 << endl;
}

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


int main()
{
	string s;
	set<char>S;
	cin>>s;
	for(int i=0;i<3;i++)
	{
		S.insert(s[i]);
	}
	if(S.size()==3)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define INF 1000000000000000LL
const ll MOD = 1000000007;
const double PI = acos(-1);
//or-> ||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl

signed main(){
	IO_STREAM;
	ll K,N;
	cin>>K>>N;
	int A[N];
	rep(i,0,N) cin>>A[i];
	int Dist[N];
	int maxx=0;
	rep(i,0,N){
		if(i==N-1){
			Dist[i]=(K+A[0])-A[i];
		}
		else{
			Dist[i]=A[i+1]-A[i];
		}
		maxx=max(maxx,Dist[i]);
	}
	DBG("","","","");
	cout<<(K-maxx)<<endl;
	return 0;
}


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

int main(){
    int n, b, f, r, v, b1[3][10], b2[3][10], b3[3][10], b4[3][10];
    cin>>n;
    
    for( int i=0; i<3; i++)
        for( int j=0; j<10; j++)
            b1[i][j]=0;
    
    for( int i=0; i<3; i++)
        for( int j=0; j<10; j++)
            b2[i][j]=0;
    
    for( int i=0; i<3; i++)
        for( int j=0; j<10; j++)
            b3[i][j]=0;
    
    for( int i=0; i<3; i++)
        for( int j=0; j<10; j++)
            b4[i][j]=0;
    
    for( int i=0; i<n; i++){
        cin>>b>>f>>r>>v;
        if(b==1) b1[f-1][r-1]+=v;
        if(b==2) b2[f-1][r-1]+=v;
        if(b==3) b3[f-1][r-1]+=v;
        if(b==4) b4[f-1][r-1]+=v;
    }
    
    for( int i=0; i<3; i++){
        for( int j=0; j<10; j++)
            cout<<' '<<b1[i][j];
        cout<<endl;
    }
    
    for( int i=0; i<20; i++)
        cout<<'#';
    cout<<endl;
    
    for( int i=0; i<3; i++){
        for( int j=0; j<10; j++)
            cout<<' '<<b2[i][j];
        cout<<endl;
    }
    
    for( int i=0; i<20; i++)
        cout<<'#';
    cout<<endl;
    
    for( int i=0; i<3; i++){
        for( int j=0; j<10; j++)
            cout<<' '<<b3[i][j];
        cout<<endl;
    }
    for( int i=0; i<20; i++)
        cout<<'#';
    cout<<endl;
    
    for( int i=0; i<3; i++){
        for( int j=0; j<10; j++)
            cout<<' '<<b4[i][j];
        cout<<endl;
    }
    
    
    
    
    
}



Measured memory_bytes: 3080
import java.util.*;
import java.math.*;
class Main {
    public static void main(String[] args) {
        Scanner scan_ = new Scanner(System.in);
        int a_ = 0;
        int b_ = 0;
        String op = null;
        while(scan_.hasNext()) {
            a_  = scan_.nextInt();
            switch(scan_.next()) {
                case "+":
                  b_  = scan_.nextInt();
                    System.out.println(a_  + b_);
                    break;
                case "-":
                    b_  = scan_.nextInt();
                    System.out.println(a_  - b_);
                    break;
                case "/":
                    b_  = scan_.nextInt();
                    System.out.println(a_  /  b_);
                    break;
                case "%":
                     b_  = scan_.nextInt();
                    System.out.println(a_  % b_);
                     break;
                 case "*":
                     b_  = scan_.nextInt();
                    System.out.println(a_  * b_);
                     break;
                case "?":
                    b_  = scan_.nextInt();
                    break;
            }
            
            
        }
        
        
    }
}



Measured memory_bytes: 26232
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import itertools

N,A,B,C,D = map(int, sys.stdin.readline().rstrip().split())


# diff = D-C
# 1 : [D-diff, D]
# 2 : [-diff, diff], [2D-2diff, 2D]
# 3 : [D-2diff, D+diff], [3D-3diff, 3D]
# 4 : [-2diff, 2diff] [2D-3diff, 2D+diff], [4D-4diff, 4D]
# 5 : [D-3diff, D+2diff] [3D-4diff, 3D+diff], [5D-5diff, 5D]


diff = D-C
target_diff = abs(A-B)
odd_or_evens = (N-1) % 2
upper_raw_count = int(math.ceil(float(target_diff) / D))
upper_count = (upper_raw_count + (upper_raw_count + odd_or_evens) % 2)
upper = upper_count * D
lower_raw_count = int(math.floor(float(target_diff) / D))
lower_count = (lower_raw_count - (lower_raw_count + odd_or_evens) % 2 )
lower = lower_count * D

#print("target = {}".format(target_diff))
#print("raw_lower {}*{}={}".format(D, lower_raw_count, D*lower_raw_count))
#print("raw_upper {}*{}={}".format(D, upper_raw_count, D*upper_raw_count))
#print(diff)
#print("{} < {} < {}".format(lower, target_diff, upper))


if target_diff > (N-2) * D:
    print("NO")
else:
    #print((upper - target_diff) // diff)
    #print("{} < {} < {}".format(upper - (upper_count + (N-1)) // 2 * diff, target_diff, upper))
    #print((target_diff - lower) // diff)
    #print("{} < {} < {}".format(lower, target_diff, lower + ((N-1-lower_count) // 2) * diff))
    if (
            (upper - (upper_count + (N-1)) // 2 * diff) <= target_diff
    ) or (
        (lower + ((N-1-lower_count) // 2) * diff) >= target_diff):
        print("YES")
    else:
        print("NO")

exit(0)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

int main(){

    long long N;
    cin >> N;

    vector<long long> people(5);
    for(int i = 0; i < 5; i++){
        cin >> people[i];
    }

    long long max = 0;
    long long dig = 0;
    for(int i = 0; i < 5; i++){
        if (max <= N / people[i]) {
            max = N / people[i];
            dig = N % people[i];
        }
    }

    if (dig == 0) {
        cout << max + 4 << endl;
    }else{
        cout << max + 5 << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

typedef pair<long long int,int> P;
const int INF=1e9;

const int MAX_SIZE = 1e5;
struct edge{int to,yen,snuk;};
vector<edge> es[MAX_SIZE];

long long int dyen[MAX_SIZE];
long long int dsnuk[MAX_SIZE];

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

	int n,m,s,t;
	cin >> n >> m >> s >> t;
	s--;t--;

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

	for(int i=0;i<n;i++){
		dyen[i] = dsnuk[i] = 1e15;
	}

	priority_queue<P,vector<P>,greater<P>> que; // 最小コスト,始点

	dyen[s] = 0;
	que.push(P(0,s));
	while(!que.empty()){
		P tmp = que.top(); que.pop();
		int ss = tmp.second;
		long long int cost = tmp.first;
		if(cost > dyen[ss]) continue;
		dyen[ss] = cost;
		edge ee;
		for(int j=0;j<es[ss].size();j++){
			ee = es[ss][j];
			if(dyen[ee.to] > dyen[ss] + ee.yen){
				dyen[ee.to] = dyen[ss] + ee.yen;
				que.push(P(dyen[ee.to],ee.to));
			}
		}
	}
	dsnuk[t] = 0;
	que.push(P(0,t));
	while(!que.empty()){
		P tmp = que.top(); que.pop();
		int ss = tmp.second;
		long long int cost = tmp.first;
		if(cost > dsnuk[ss]) continue;
		dsnuk[ss] = cost;
		edge ee;
		for(int j=0;j<es[ss].size();j++){
			ee = es[ss][j];
			if(dsnuk[ee.to] > dsnuk[ss] + ee.snuk){
				dsnuk[ee.to] = dsnuk[ss] + ee.snuk;
				que.push(P(dsnuk[ee.to],ee.to));
			}
		}
	}
	
//	for(int i=0;i<n;i++){
//		cout << dyen[i] << " " << dsnuk[i] << "\n";
//	}
	long long int min_[n];
	min_[n-1] = dyen[n-1]+dsnuk[n-1];
	for(int i=n-2;i >= 0;i--){
		min_[i] = min(min_[i+1],dyen[i]+dsnuk[i]);
	}
	for(int i=0;i<n;i++){
		cout << (long long int)1e15 - min_[i] << "\n";
		//printf("%I64d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 11380
// https://atcoder.jp/contests/abc061/tasks/abc061_b
"use strict";
function Main(input) {
  const [a, ...b] = input.trim().split("\n");
  const [N, M] = a.trim().split(" ").map(Number);
  const c = b.flatMap((a) => a.trim().split(" "));

  for (let i = 1; i <= N; i++) {
    const d = c.filter((d) => Number(d) === i);
    console.log(d.length);
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 30588
#include <iostream>
#include<algorithm>
#include<set>
#include<iterator>
#include<map>
#include<unordered_map>
#include<vector>
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define pb push_back
#define F first
#define S second

int32_t main() {
   
    string s;
    cin>>s;
    
    int n= s.size();
    
    for(int i = n - 2; i > 0; i -= 2){
        string a = s.substr(0,i/2);
        string b = s.substr(i/2,i/2);
        
        if(a==b){
            cout << i;
            break;
        }
    }
    
	return 0;
}


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n,m,q;
int a[100],b[100],c[100],d[100];

int p[17];
int ans=0;

void dfs(int now)
{
    if (now==n)
    {
        int sum=0;
        for (int i=1;i<=q;i++)
            if (p[b[i]]-p[a[i]]==c[i]) sum+=d[i];
        ans=max(ans,sum);
        return;
    }
    for (int i=p[now];i<=m;i++)
    {
        p[now+1]=i;
        dfs(now+1);
    }
}

int32_t main()
{
    IOS
    cin>>n>>m>>q;
    for (int i=1;i<=q;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];

    p[0]=1;
    dfs(0);
    cout<<ans<<endl;
}



Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
typedef vector<int> vi;

const int w[] = {9,8,7,6,5,4,3,2,1,0};

int main() {
	int in;
	while (cin>>in) {
		vi used;
		REP(i,10) {
			int weight = pow(2,w[i]);
			if (weight<=in) {
				in -= weight;
				used.push_back(weight);
			}
		}
		sort(used.begin(),used.end());
		REP(i,used.size()) {
			if(i!=0) cout<<" ";
			cout<<used[i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 0