akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
}
int main()
{
    vok();
    int k;
    IN k;
    int a,b;
    IN a>>b;
    loop(i,a,b+1)
    {
        if(i%k==0)
        {
            OUT "OK"<<endl
            return 0;
        }
    }
    OUT "NG"<<endl
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int n;
int m;
vector< vi > bulbs(15);
int cur[15] = {};
int p[15] = {};
int ans = 0;
void compute(int i)
{
    if(i == n)
    {
        int j;
        int cnt = 0;
        FOR0(j, m)
        {
            int l, si = bulbs[j].size();
            int par = 0;
            FOR0(l, si)
            {
                int v = bulbs[j][l];
                if(cur[v]) par++;
            }
            par %= 2;
            if(p[j] == par) cnt++;
        }
        if(cnt == m) 
            ans++;
        return;
    }
    cur[i] = 1;
    compute(i+1);
    cur[i] = 0;
    compute(i+1);
    return;
}
int main()
{
    she_told_me_dont_worry
    cin>>n>>m;
    int k;
    int i, j;
    FOR0(i, m)
    {
        cin>>k;
        FOR0(j, k)
        {
            int temp;
            cin>>temp;
            temp--;
            bulbs[i].pb(temp);
        }
    }
    FOR0(i, m) cin>>p[i];
    compute(0);
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
N = int(input())
b = list(map(int, input().split()))
ans = []
cnt = len(b)
while b:
    for i in range(len(b)-1, -1, -1):
        if b[i] == i + 1:
            ans.append(b[i])
            del b[i]
            break
    cnt -= 1
    if cnt < 0:
        break
if cnt < 0:
    print(-1)
else:
    for i in range(len(ans)-1, -1, -1):
        print(ans[i])

Measured memory_bytes: 38512
import java.io.*;


public class Main {  
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		double num = Double.parseDouble(line);
		double ans = Math.pow(num, (double)3);
		System.out.println((int)ans);
	}
}

Measured memory_bytes: 24272
n = gets.to_i
c = 19.times.map{[0]*19}
n.times{
  a=9
  b=9
  r = gets.to_r
  while r.denominator>1
    a -= 1
    b -= 1
    r *= 10
  end
  while r.numerator%2==0
    a += 1
    r /= 2
  end
  while r.numerator%5==0
    b += 1
    r /= 5
  end
  a = [a, 18].min
  b = [b, 18].min
  c[a][b] += 1
}
ans = 0
19.times.each do |i|
  19.times.each do |j|
    ans -= c[i][j] if i>=9&&j>=9
    (18-i..18).each do |_i|
      (18-j..18).each do |_j|
        ans += c[i][j]*c[_i][_j]
      end
    end
  end
end
p ans/2

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

int main() {
    int a,b;
    cin >> a >> b;
    vector<vector<char>> g(100, vector<char>(100, '.'));
    for(int i = 0; i < 50; i++)
    {
        for(int j = 0; j < 100; j++)
        {
            g.at(i).at(j) = '#';
        }
        
    }
    
    int x = 0;
    int y = 0;
    for (int i = 0; i < a - 1; i++) {
        g.at(y).at(x) = '.';
        x += 2;
        if (x == 100) {
            x = 1;
            y += 2;
        }
        else if (x == 101) {
            x = 0;
            y += 2;
        }
    }
    
    x = 0;
    y = 99;
    for (int i = 0; i < b - 1; i++) {
        g.at(y).at(x) = '#';
        x += 2;
        if (x == 100) {
            x = 1;
            y -= 2;
        }
        else if (x == 101) {
            x = 0;
            y -= 2;
        }
    }
    
    cout << 100 << " " << 100 << endl;
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            cout << g.at(i).at(j);
        }
        cout << endl;
    }
}

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

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

//  sort(L.begin(), L.end());
  int ans = 0;
  for(int i = 0; i < N - 2; i++) {
    for(int j = i + 1; j < N - 1; j++) {
      if(L[i] == L[j]) continue;
      int x = L[i] + L[j];
      for(int k = j + 1; k < N; k++) {
        if(L[i] == L[k] || L[j] == L[k]) continue;
        int m = max(L[i], max(L[j], L[k]));
        if(m < (x + L[k] - m) ) {
          ans++;
          // cout << "debug: " << L[i] << ", " << L[j] << ", " << L[k] << endl;
        }
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(){
 int a, b;
 cin >> a >> b;
 if(a > b){
  cout << "a > b" << endl;
 }else if(a < b){
  cout << "a < b" << endl;
 }else if(a == b){
  cout << "a == b" << endl;
 }
 return 0;
}

Measured memory_bytes: 3092
from sys import stdin
import copy
N, L = [int(_) for _ in stdin.readline().rstrip().split()]
tastes = [(L+i-1) for i in range(1, N+1)]
origin = sum(tastes)
ans = 10**9
ans_sum = 0
for i in range(N):
    c_tastes = copy.deepcopy(tastes)
    c_tastes.pop(i)
    tmp = abs(origin-sum(c_tastes))
    if ans > tmp:
        ans = tmp
        ans_sum = sum(c_tastes)
print(ans_sum)

Measured memory_bytes: 3444
#define DEBUG(x) cout << #x << " = " << x << endl
#include<bits/stdc++.h>
using namespace std;
void ask(long long num) {
  cout << "? " << num << endl;
}
char receive() {
  char x; cin >> x;
  return x;
}
int main() {
  int l = 0;
  while (l <= 10) { 
    ask(pow(10, l));
    if (receive() == 'N') {
      break;
    }
    l++;
  }
  if (l == 11) {
    l = 1;
    while (l <= 10) {
      ask(pow(10, l) - 1);
      if (receive() == 'Y'){
        break;
      }
      l++;
    }
  }

  long long sf = 0;
  for (int i = 1; i <= l - 1; i++) {
    int left = i == 1 ? 0 : -1;
    int right = 10;
    while (left + 1 < right) {
      int mid = (left + right) / 2;
      long long num = sf * 10 + mid;
      cout << "?" << " " << num << endl;
      char a; cin >> a;
      if (a == 'Y') {
        left = mid;
      } else {
        right = mid;
      }
    }
    // the i-th digit is left
    sf = sf * 10 + left;
  }
  int last = -1;
  int start = l == 1 ? 1 : 0;
  for (int d = start; d <= 9; d++) {
    cout << "? " << sf * 100 + d * 10 << endl;
    char a; cin >> a;
    if (a == 'Y') {
      last = d;
      break;
    }
  }

  cout << "! " << sf * 10 + last << endl;
}


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

int main(){
    int n, q, left, right, mid, key, count=0;
    cin >> n;
    int S[n];
    for(int i=0;i<n;i++){
        cin >> S[i];
    }
    cin >> q;
    int T[q];
    for(int j=0;j<q;j++){
        cin >> T[j];
    }
    
    
    
    for(int j=0;j<q;j++){
        key = T[j];
        left = 0;
        right = n;
        while(left < right){
            mid = (left + right) / 2;
           if(S[mid] == key){
               count++;
                break;
            }
            else if(key < S[mid]){
               right = mid;
           }
           else{
               left = mid + 1;
           }
        }
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <fstream>
#include <vector>
#include <numeric> //accumulate

using namespace std;

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N;
  cin>>N;
  int a;
  int ans=0;
  for(int i=0;i<N;i++){
    cin>>a;
    while(a%2==0){
      a /= 2;
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,m,n) for(int i = m; i < n; ++i)
#define RFOR(i,m,n) for(int i = n - 1; i >= m; --i)
#define CIN(a) cin >> a
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a << endl
#define COUT2(a, b) cout << a << " " << b << endl
#define COUT3(a, b, c) cout << a << " " << b << " " << c << endl
#define pb push_back
#define PB push_back
#define VINT(v, n) vector<int> v(n); REP(i, n) { v[i] = 0 }
#define VINT2(v, n, m) vector<vector<int> > v(n, vector<int>(m)); REP(i, n) { REP(j, m) { v[i][j] = 0 } }
#define VCHAR(v, n) vector<char>v(n)
#define KIRIAGE(a, b) a += (b - a % b) % b
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
	int A, B;
	char op;
	CIN3(A, op, B);
	if(op == '+') COUT(A + B);
	else COUT(A - B);
}


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

int main(){
    int n,l;
    cin >> n >> l;
    int a[n]={};

    for(int i=1;i<=n;i++){
        a[i-1]=l+i-1;
    }

    int sum=0;
    for(int j=1;j<=n;j++){
        sum=sum+a[j-1];
    }

    if(a[0]>0){
        cout << sum-a[0] << endl;
    }else if(a[n-1]<0){
        cout << sum-a[n-1] << endl;
    }else{
        cout << sum << endl;
    }
    return 0;

}

Measured memory_bytes: 256
A, B, C, D = gets.split('').map(&:to_i)

%w(+ -).repeated_permutation(3) do |op1, op2, op3|
  if A.send(op1, B).send(op2, C).send(op3, D) == 7
    puts [A, op1, B, op2, C, op3, D, '=7'].join
    exit
  end
end

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

int main()
{
  int N, cnt;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A.at(i);
  sort(A.begin(), A.end());
  rep(i, N-1){
    if(A.at(i)==A.at(i+1)) cnt++;
  }
  cout << N-cnt << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> a(n+1);
    rep(i,n) {
        cin >> a[i];
    }
    rep(t,k){
        vector<int> nxt(n+1, 0);
        rep(i,n){
            int l = max(i-a[i], 0);
            int r = min(i+a[i]+1,n);
            nxt[l]++;
            nxt[r]--;
        }
        rep1(i,n){
            nxt[i] += nxt[i-1];
        }
        nxt[n] = 0;
        a = move(nxt);
        if (count(all(a), n) == n) {
            break;
        }
    }
    rep(i,n){
        cout << a[i] << (i<n-1 ? " " : "\n");
    }
    return 0;
}


Measured memory_bytes: 5088
#include <iostream>
 using namespace std;
 int main(){
     int n;
     cin>>n;
 if(n==25)cout<<"Christmas";
 if(n!=25){
     int m= 25-n;
     string s="Eve ";
      string s1 = s;
     for(int i=1;i<m;i++){
         s+=s1;
     }
     cout<<"Christmas"<<" "<<s;
 }
 
 }

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

ll dp[105][2][4];

int main(){
	string s;
	cin >> s;
	int k;
	cin >> k;
	int l = s.size();
	
	//dp初期条件
	dp[0][1][0] = 1;
	dp[0][1][1] = (s[0] - '0') - 1;
	dp[0][0][1] = 1;
	
	REP(i,l-1){
		rep(smaller, 2){
			rep(j, k+1){
				for (int x = 0; x <= 9 ; ++x) {
					int D = s[i] - '0';
					int nsmaller = smaller;  int nj = j;
					if(smaller == 0){
						if(x > D) continue;
						if(x != 0) nj++;
						if(x < D) nsmaller = 1;
						if(nj > k) continue;
					}else{
						if(x != 0) nj++;
						if(nj > k) continue;
					}
					dp[i][nsmaller][nj] += dp[i-1][smaller][j];
				}
			}
		}
	}
	
	ll ans = dp[l-1][0][k] + dp[l-1][1][k];
	cout << ans << endl;
	
    return 0;
}



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

using namespace std;
#define rep(i, N) for(int i=0;i<int(N);++i)
#define rep1(i, N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << "{" << p.first << ", " << p.second << "}";
    return os;
}

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

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

const int INF = (ll) 1e9;
const ll INFLL = (ll) 1e18 + 1;
const ll MOD = (ll) 1e9 + 7;
const double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll A, B, K;
    cin >> A >> B >> K;
    rep(i, K) {
        if (i & 1) {
            if (B & 1)B--;
            A += B / 2;
            B /= 2;
        } else {
            if (A & 1) A--;
            B += A / 2;
            A /= 2;
        }
    }
    cout << A << " " << B << endl;
}

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

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

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

const int OO = (int) 2e9;
const double eps = 1e-9;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	ll n;
	cin >> n;
	ll res = n;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res = min(res, i - 1 + n / i - 1);
		}
	}
	cout << res << endl;
	return 0;
}


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

int n;
int num[100];

int main(){
    //freopen("D:\\zhouyu\\study\\codes\\InsertSort.txt", "r", stdin);
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> num[i];
    }
    int temp;
    for(int i=0; i<n; i++){
        temp = num[i];
        for(int j=i-1; j>=0; j--){
            if(num[j] > temp){
                num[j+1] = num[j];
                num[j] = temp;
            }
            else{
                break;
            }
        }
        for(int k=0; k<n; k++){
            if(k==n-1){
                cout << num[k];
            }
            else{
                cout << num[k] << " ";
            }
        }
        cout << endl;
    }
}


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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

int gcd(int a, int b){
  while (b){
    a %= b;
    swap(a, b);
  }
  return a;
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

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

    int n;
    cin >> n;
    ll s = 0LL;
    for (int i = 1; i <= n; i++){
      for (int j = 1; j <= n; j++){
        for (int k = 1; k <= n; k++){
          int g = gcd(i, j);
          g = gcd(g, k);
          s += (ll)g;
        }
      }
    }

    cout << s << '\n';  

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(void)
{
    int N, K;
    string S;
    cin >> N >> S >> K;
    auto c = S[K - 1];
    for (auto &i: S) if (i != c) i = '*';
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
a=[list(map(int,input().split())) for _ in range(h)]
for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j]=min(c[i][j],c[i][k]+c[k][j])
s=0
for i in range(h):
  for j in range(w):
    if a[i][j]!=-1:
      s+=c[a[i][j]][1]
print(s)

Measured memory_bytes: 3444
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]a = new int[n];
    int[]A = new int[n];
   
    for(int i=0; i<n; i++){
        a[i] = sc.nextInt();
        while(a[i]%2 == 0) {
        	a[i] /= 2;
        	A[i]++;    	
        }
    }
    Arrays.sort(A); 	
	System.out.println(A[0]);
    }
}


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

int main()
{
    int n, ai, a[100000], ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> ai;
        a[i] = ai - 1;
    }
    for(int i = 0; i < n; i++){
        if(a[a[i]] == i) ans++;
    }
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <utility>
#include <cstring>
#include <algorithm>

using namespace std;

const int INF = 1e9 + 7;

int n, w;
vector<pair<int, int>> goods;

long long dp[101][100001];

int main(){
    cin >> n >> w;
    for(int i = 0; i <= 100; i++){
        for(int j = 1; j <= 100000; j++){
            dp[i][j] = 1ll << 60;
        }
    }
    
    for(int i = 0; i < n; i++){
        int w, v;
        cin >> w >> v;
        for(int j = 0; j <= 100000; j++){
            dp[i + 1][j] = dp[i][j];
            if(v <= j){
                dp[i + 1][j] = min(dp[i + 1][j], w + dp[i][j - v]);
            }
        }
    }

    for(int i = 100000; i >= 0; i--){
        if(dp[n][i] <= w){
            cout << i << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 79104
package main

import "fmt"

func main() {
	var S, T string

	fmt.Scan(&S)
	fmt.Scan(&T)

	check := 0

	for i := 0; i < len(S); i++ {
		if S[i] == T[i] {
			check = 1
		} else {
			check = 0
			break
		}
	}

	if check == 1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1748
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <string>
#include<iomanip>
#include<limits>
using namespace std;
int main(void){
   int N;
   string s;
   cin>>N;
   cin>>s;
   for(int i=0;i<s.length();i++){
       int a=s[i]-'A';
       a=(a+N)%26;
       cout<<char(a+'A');
   }
   cout<<endl;
}


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

using namespace std;

int main()
{
	const int MAX_VALUES = 101;
	bitset<MAX_VALUES> bits;
	bitset<MAX_VALUES> reversed;
	bits.flip();
	reversed.flip();
	int x, n, t;
    scanf("%d %d", &x, &n);
	if (n == 0) {
		printf("%d", x);
		exit(0);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &t);
		bits.reset(t);
		reversed.reset(MAX_VALUES - 1 - t);
	}
	if (bits[x]) {
        printf("%d", x);
		exit(0);
	}
	int rV = bits._Find_next(x);
	int lV = MAX_VALUES - 1 - reversed._Find_next(MAX_VALUES - 1 - x);
 	int d1 = abs(rV - x);
	int d2 = abs(lV - x);
	if (d1 < d2) {
        printf("%d", rV);
	}
	else if (d2 < d1) {
		printf("%d", lV);
	}
	else {
		printf("%d", min(rV, lV));
	}
	return 0;
}

Measured memory_bytes: 3248
#!/usr/bin/env python
import sys
from math import sin, cos, pi, sqrt
import bisect
sys.setrecursionlimit(10 ** 9)
inf = float("inf")
readline = sys.stdin.buffer.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
nt = lambda: tuple(map(int, readline().split()))

def main():
    A, B, H, M = nm()
    theta1 = 2 * pi * (H / 12 + M / 720)
    theta2 = 2 * pi * M / 60

    ans = A ** 2 + B ** 2 - 2 * A * B * cos(abs(theta2 - theta1))
    print(sqrt(ans)) 


if __name__ == '__main__':
    main()



Measured memory_bytes: 9604
#include<bits/stdc++.h>
using namespace std;
#define very_slow       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define inf             1e18
#define MAX             1e9
#define MIN            -1e9
#define no_of_test(x)        int x; cin>>x; while(x--)
//Actual Code Is At The Top
const int mod = 1e9 + 7;
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}
int32_t main()
{   
	very_slow
//	no_of_test(x)
	{  
     string s;
	 cin>>s;
	 bool flag=false;
	 for(int i=0;i<s.length();i++)
	 {
		 if(s[i]=='7')
		 {
			flag=true;
			 break;
		 }

	 }
	 if(flag)
	 {
		 cout<<"Yes"<<'\n';
	 }
	 else
	 {
		 cout<<"No"<<'\n';
	 }
	 


	}
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int black[200050];
int white[200050];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string S;
    cin >> S;
    S = "&" + S;
    for(int i = 1; i <= N; i++) {
        black[i] = black[i - 1];
        white[i] = white[i-1];
        if(S[i] == '#') black[i]++;
        else white[i]++;
    }
    int ans = INF;
    for(int i = 0; i <= N; i++) {
        int now = 0;
        now += (N - i) - (black[N] - black[i]);
        now += i - white[i];
        ans = min(ans, now);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
 
#define int long long
#define MOD 1000000007
 
using namespace std;
 
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for (auto v : V)
        os << v << " ";
    os << "]";
    return os;
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
    os << "{ ";
    for (auto m : M)
        os << "(" << m.first << ":" << m.second << ") ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}

void solve() {
    int n;
    cin >> n;
    cout << 8 - (n - 400) / 200 << endl; 
}
 
int32_t main() {
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    // cin >> t;
    // while(t--) {
    //     solve();
    // }
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#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)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

struct work {
  string name;
  int t;
};

int main() {
  int n, q, time = 0;
  cin >> n >> q;
  queue<work> Q;
  work w;
  rep(i, n) {
    cin >> w.name >> w.t;
    Q.push(w);
  }

  while (!Q.empty()) {
    w = Q.front();
    Q.pop();
    if (w.t <= q) {
      time += w.t;
      cout << w.name << " " << time << endl;
    }
    else {
      time += q;
      w.t -= q;
      Q.push(w);
    }
  }

  
  return 0;
}


Measured memory_bytes: 6300
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
m = 10**9 + 7

a = [None] * (N+1)
inva = [None] * (N+1)
a[0] = 1

for i in range(1, N+1):
    a[i] = i * a[i-1] % m

inva[N] = pow(a[N],m-2,m)
for i in range(N):
    inva[N-i-1] = inva[N-i] * (N-i) % m

ans = 0
for i in range(N):
    if i < K-1: continue
    tmp = (a[i] * inva[i-K+1] % m) * inva[K-1] % m 
    ans += A[i] * tmp
    ans %= m

for i in range(N):
    if i > N-K: continue
    tmp = (a[N-1-i] * inva[N-K-i] % m) * inva[K-1] % m 
    ans -= A[i] * tmp
    ans %= m

print(ans)

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

string s[11]={"light fly","fly","bantam","feather",
	"light","light welter","welter","light middle",
	"middle","light heavy","heavy"};
double g[]={48.0,51.0,54.0,57.0,60.0,64.0,69.0,75.0,81.0,91.0};

int main(){
	double n;
	while(cin >> n){
		int m;
		for(m = 0;m < 10 && n > g[m];m++);
		cout << s[m] << endl;
	}
	return 0;
}

/*
60.2
70.2
48.0
80.2
*/

Measured memory_bytes: 3216
N = int(input())
A = [int(x) for x in input().split()]
n1 = 0
n2 = 0
n4 = 0

for a in A:
  if a&1:
    n1 += 1
  elif a%4==0:
    n4 += 1
  else:
    n2 += 1

 
bl = True
# n1 <= n4なら、141414と並べてあとは適当
if n1 > n4:
  #1414...141のときだけ
  if not(n1 == n4 + 1 and n2 == 0):
    bl = False

answer = 'Yes' if bl else 'No'
print(answer)

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


int main() {

    int N;
    cin >> N;

    vector<string> A(N);

    map<string, int> mp;

    for (int i = 0; i < N; i++) {
        cin >> A.at(i);

        if (mp.count(A.at(i))) {
            mp[A.at(i)] += 1;
        } else {
            mp[A.at(i)] = 1;
        }
    }


    vector<string> results;
    int max = 0;

    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if (itr->second > max) {
            max = itr->second;
        }
    }

    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if (itr->second == max) {
            results.push_back(itr->first);
        }
    }

    for (int i = 0; i < results.size(); i++) {
        cout << results.at(i) << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 28404
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if (a <= b) cout << a << endl;
    else cout << a - 1 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;

		while(!(str=br.readLine()).equals("0")){
			int n = Integer.parseInt(str);
			long min[] = new long[n];
			long allMin[] = new long[n+1];
			long res=0;

			for(int i=0; i<n; i++){
				min[i] = Integer.parseInt(br.readLine());
			}

			Arrays.sort(min);

			for(int i=0; i<n; i++){
				allMin[i+1] += allMin[i] + min[i];
			}

			for(int i=0; i<n; i++){
				res += allMin[i];
			}

			System.out.println(res);

		}

	}
}

Measured memory_bytes: 25172
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    long long n, m, d;
    cin >> n >> m >> d;
    cout << fixed;
    cout << setprecision(8);
    if (d == 0) {
        cout << (double)(m - 1) / (double)(n) << endl;
    } else {
        cout << (double)(2 * (n - d) * (m - 1)) / (double)(n * n) << endl;
    }
}

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

const int MAX_N = 101;

int par[MAX_N];
int rank_[MAX_N];

void init(int n){
    for(int i = 1; i <= n; i++){
        par[i] = i;
        rank_[i] = 0;
    }
}

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

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

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    init(n);
    if(n%2 == 0){
        for(int i = 1; i <= n/2; i++){
            unite(i, n-i+1);
        }
    }
    else{
        for(int i = 1; i <= (n-1)/2; i++){
            unite(i, n-i);
        }
    }
    vector<pair<int, int>> ans;
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j++){
            if(!same(i, j)){
                ans.emplace_back(i, j);
            }
        }
    }
    cout << ans.size() << endl;
    for(auto p : ans){
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}

Measured memory_bytes: 384
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		if (a * b < c * d) {

			System.out.println(c * d);

		} else if (a * b > c * d) {

			System.out.println(a * b);

		} else if (a * b == c * d) {

			System.out.println(a * b);

		}

	}
}


Measured memory_bytes: 21844
def comb(n):
    return (n * (n - 1)) // 2


def main():
    n, m = [int(a) for a in input().split()]

    AB = [
        [int(a) for a in input().split()]
        for _ in range(m)
    ]

    table = {i: {i} for i in range(n)}  # (便利さ,行ける島集合)

    current_benrisa = 0
    max_hubensa = comb(n)

    reversed_benrisa = []
    for ai, bi in reversed(AB):
        reversed_benrisa.append(current_benrisa)
        s1_set = table[ai - 1]
        s2_set = table[bi - 1]
        if s1_set is s2_set:  # 変化なし
            continue

        s1_benrisa = len(s1_set)
        s2_benrisa = len(s2_set)
        # new_benri = s1_benrisa + s2_benrisa
        if len(s1_set) > len(s2_set):
            s1_set.update(s2_set)
            for t in s2_set:
                table[t] = s1_set
        else:
            s2_set.update(s1_set)
            for t in s1_set:
                table[t] = s2_set

        # new_set = s1_set.union(s2_set)
        # for t in new_set:
        #     table[t] = (new_benri, new_set)

        inc = s1_benrisa * s2_benrisa
        current_benrisa += inc
        continue

    for a in reversed(reversed_benrisa):
        print(max_hubensa - a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68800
#include <iostream>
#include <cstdlib>
#include <cmath>  
using namespace std;
int Abs(int a){
    if(a>0)return a;
    return -1*a;
}
int main()
{
    int N;
    cin>>N;
    
    int* A = new int[N+1];
    
    A[0] = 0;
    for(int i=1;i<N+1;i++){
        cin>>A[i];
    }
    int all = 0;
    for(int i=1;i<N+1;i++){
        all +=Abs(A[i]-A[i-1]);
    }
    all += Abs(A[N]);
    for(int i=1;i<N+1;i++){
        int ret =0;
        if(i==N){
            ret = all - Abs(A[N]-A[N-1])-Abs(A[N]) + Abs(A[N-1]);
        }
        else{
            ret = all - Abs(A[i]-A[i-1]) -Abs(A[i+1]-A[i])+ Abs(A[i+1]-A[i-1]);
        }
        cout<<ret<<endl;
    }
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int compute(vector<int> &a, int y){
	int ret = 0;
	for(auto x : a){
		ret += (x - y)*(x - y);
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<int> a(n);
	for(auto &x : a){
		cin>>x;
	}
	int sum = accumulate(a.begin(), a.end(), 0);
	cout<<min(compute(a, sum/n), compute(a, sum/n + 1))<<endl;

	return 0;
}

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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

ll chk(ll x){
  ll i = 0;
  for (; i * i * i * i * i <= x; ++i);
  --i;
  return (i * i * i * i * i == x ? i : -1);
}

ll myPow(ll x, int p){
  ll ret = 1;
  for (int i = 0; i < p; ++i) ret = ret * x;
  return ret;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  ll x; cin >> x;

  for (ll i = 0; i * i * i * i * i <= x; ++i){
    ll A = i * i * i * i * i;
    if (chk(x - A) != -1) return cout << i <<' '<< -(chk(x - A)), 0;
  }

  for (ll i = 1; i * i <= x; ++i){
    if (x % i == 0){
      ll t = x / i;
      ll B = 0;
      while (1){
        ll A = B + i;
        if (myPow(A, 4) + myPow(B, 4) + A * myPow(B, 3) + B * myPow(A, 3) + A * A * B * B > t) break;
        if (myPow(A, 4) + myPow(B, 4) + A * myPow(B, 3) + B * myPow(A, 3) + A * A * B * B == t)
          return cout << A << ' ' << B, 0;
        ++B;
      }
    }
  }
}



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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long r = count(begin(s), end(s), 'R');
  long long g = count(begin(s), end(s), 'G');
  long long b = count(begin(s), end(s), 'B');
  auto res = r * g * b;
  for (int j = 1; j < n; ++j) {
    for (int i = 0; i < j; ++i) {
      int k = 2 * j - i;
      if (k < n) {
        res -= s[i] != s[j] and s[j] != s[k] and s[k] != s[i];
      }
    }
  }
  cout << res << '\n';
}


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

using namespace std;

int main() {
	string s, t;
	cin >> s;
	cin >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	string ans;
	s < t ?  ans = "Yes": ans = "No";
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;
using System.Threading;

static class MainClass
{
    public static void Main(string[] args)
    {
        var abcd = Console.ReadLine().SplittedStringToInt32List();
        if (Math.Abs(abcd[0] - abcd[2]) <= abcd[3] || (Math.Abs(abcd[0] - abcd[1]) <= abcd[3] && Math.Abs(abcd[1] - abcd[2]) <= abcd[3]))
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
        
    }


    public static int Gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }
    public static BigInteger Gcd(BigInteger a, BigInteger b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }
    
    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    #endregion
}


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

VI tsort(VVI g) {
  int n = g.size();
  vector<bool> used(n, false);
  vector<int> ans;

  function<void(int)> dfs = [&](int u) {
    if(used[u]) return;
    used[u] = true;
    for(auto& i: g[u]) dfs(i);
    ans.push_back(u);
  };

  for(int i=0; i<n; ++i) dfs(i);
  reverse(ans.begin(), ans.end());
  return ans;
}

// VI tsort(VVI g) {
//   const int n = g.size();
//   VI h(n, 0);
//   REP(i, n) for(int j: g[i]) h[j]++;
//
//   stack<int> st;
//   REP(i, n) if(h[i] == 0) st.push(i);
//
//   VI ans;
//   while(st.size()) {
//     int i = st.top(); st.pop();
//     ans.push_back(i);
//     for(auto& j: g[i]) {
//       h[j]--;
//       if(h[j] == 0) st.push(j);
//     }
//   }
//
//   return ans;
// }

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

  int n, m;
  cin >> n >> m;
  VVI g(n, VI(0));
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    g[a].PB(b);
  }

  VI ans = tsort(g);
  for(int i: ans) cout << i << endl;

  return 0;
}



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

int main() {
  string s;
  cin >> s;
  int length = 0;
  int max = 0;

  for(int i=0;i<s.size();i++) {
    if(length != 0) {
      length++;
    }
    if(s[i] == 'A' && length == 0) {
      length++;
    }
    if(s[i] == 'Z') {
      max = length;
    }
  }

  cout << max << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>

using namespace std;

int main() {
	string s, t;
	int a, b;
	string u;
	cin >> s >> t >> a >> b >> u;
	if (s == u)cout << a - 1 << " " << b << endl;
	else cout << a << " " << b - 1 << endl;
	return 0;
}


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

using namespace std;
bool ard(string a,string b){
    int c=0;
    for(int i=0;i<a.length();i++){
        int f=b.find(a[i]);
        if(f!=string::npos){
            c++;
            b.erase(f,1);
        }
    }
    return (c==10);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    vector<string>v;
    for(int i=0;i<n;i++){
        string t;
        cin>>t;
        sort(t.begin(),t.end());
        v.push_back(t);
    }
    sort(v.begin(),v.end());
    long long ans=0;
    int fn=1;
    for(int i=1;i<v.size();i++){
        if(v[i]==v[i-1]){
            ans+=fn;
            fn++;
        }
        else
            fn=1;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

struct edge{ll from,to,cost;};
struct gragh{
	ll V;
	vector<edge> es; //辺
	vector<ll> d; //最短距離

	gragh(ll n){
		init(n);
	}

	void init(ll n){
		V=n+1; //1-origin
		d.resize(V);
		rep1(i,V-1) d[i]=INF;
	}

	void add_edge(ll from,ll to,ll cost){
		edge e;
		e.from=from;
		e.to=to;
		e.cost=cost;

		es.pb(e);
	}

	bool bellman_ford(ll s){//O(|V||E|)
		bool loop=false;
		rep1(i,V-1) d[i]=INF;
		d[s]=0;
		
		rep(i,(V-1)*2){
			bool update=false;
			rep(j,sz(es)){
				edge e=es[j];
				if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
					d[e.to]=d[e.from]+e.cost;
					if(i>=V-1){
						d[e.to]=-INF;
						loop=true;
					}

					update=true;
				}
			}
			if(!update) break;
		}

		if(loop) return true;
		else return false;
	}
};

int main(){
	ll N,M; cin>>N>>M;//辺数

	gragh g(N);
    //Mコの辺の情報入力
    rep(i,M){
        ll from,to,cost; cin>>from>>to>>cost;
        g.add_edge(from,to,-cost);
    }

	g.bellman_ford(1ll);

	if(g.d[N]==-INF) cout<<"inf";
	else{
		cout<<-g.d[N];
	}
}

Measured memory_bytes: 384
N, X = map(int, input().split())
L = list(map(int, input().split()))
p = 0
t = 1
while True:
  for i in range(N):
    p += L[i]
    if p > X:
      break
    elif i == N - 1:
      t += 1
      break
    else:
      t += 1
  break
print(t)

Measured memory_bytes: 3060
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner(System.in);
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int n = cin.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = cin.nextInt();

		int[] ans = solve(n, a);
		String ansstr = Arrays.stream(ans).mapToObj(Integer::toString).collect(Collectors.joining(" "));
		cout.println(ansstr);
	}

	private static int[] solve(int n, int[] a) {
		int[] b = new int[n];
		int[] ord = IntStream.range(0, n).map(x -> x % 2 == 0 ? x / 2 : (-x - 1) / 2).toArray();
		for (int i = 0; i < n; i++)
			b[n / 2 + ord[i]] = a[i];
		if (n % 2 == 1)
			// reverese
			for (int i = 0; i < n / 2; i++) {
				int t = b[i];
				b[i] = b[n - 1 - i];
				b[n - 1 - i] = t;
			}
		return b;
	}

	static class FastScanner {
		private final InputStream in;
		private final byte[] buf = new byte[1 << 14];
		private int bufs = 0;
		private final long[] num = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		private int ptr = 0;

		public FastScanner(InputStream in) {
			super();
			this.in = in;
		}

		boolean hasNext() {
			while (hasNextByte() && !isMeaningful(buf[ptr]))
				ptr++;
			return hasNextByte();
		}

		private boolean hasNextByte() {
			if (ptr < bufs)
				return true;
			ptr = 0;
			try {
				bufs = in.read(buf);
			} catch (IOException e) {
				throw new IllegalArgumentException(e);
			}
			if (bufs <= 0)
				return false;
			return true;
		}

		private static boolean isMeaningful(int b) {
			return 33 <= b && b <= 126;
			// return b != -1 && !Character.isWhitespace(b);
		}

		String next() {
			if (!hasNext())
				throw new IllegalArgumentException();
			StringBuilder sb = new StringBuilder();
			int b = read();
			while (isMeaningful(b)) {
				sb.appendCodePoint(b);
				b = read();
			}
			return sb.toString();
		}

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

		int nextInt() {
			long nl = nextLong();
			int ni = (int) nl;
			if (ni != nl)
				throw new IllegalArgumentException();
			return ni;
		}

		long nextLong() {
			if (!hasNext())
				throw new IllegalArgumentException();
			long n = 0;
			int plus = 1;
			int b = read();
			if (b == '-') {
				plus = -1;
				b = read();
			}
			if ('0' > b || b > '9')
				throw new java.lang.IllegalArgumentException();
			while (true) {
				if (!isMeaningful(b))
					return plus * n;
				n *= 10;
				n += num[b - '0'];
				b = read();
			}
		}

		private int read() {
			if (hasNextByte())
				return buf[ptr++];
			else
				return -1;
		}

	}
}


Measured memory_bytes: 46908
#include <bits/stdc++.h>
using namespace std;
 
int main(){ 
    int n,k;
    cin>>n>>k;

    int a[n];

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





    sort(a,a+n);

    int ans=0;

    for(int i=0;i<k;i++){
        ans=ans+a[i];
    }

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

Measured memory_bytes: 3516