akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }


#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);

  int N, W;
  cin >> N >> W;


  vector<int> v(N), w(N);
  for(int i = 0; i < N; i++) { cin >> v[i] >> w[i]; }

  // // dp
  // dp[i][j] := i?????? ?????§?????????????????£??? ??????j ??\?????§????????§??????
  vector< vector<int> > dp = make_2d_vector(N+1, W+1, 0);
  for(int i = 1; i <= N; i++ ) {
    for(int j = 1; j <= W; j++ ) {
      if( j >= w[i-1] ) {
        dp[i][j] = max( dp[i-1][j], dp[i-1][ j-w[i-1] ] + v[i-1]);
      } else {
        dp[i][j] = dp[i-1][j];
      }
    }
  }

  cout << dp[N][W] << "\n";





  // dp[i][j] := i???????????§?????????????????£??? ??????j??\??? ??§????????§??????
  // vector< vector<int> > dp = make_2d_vector(N+1, W+1, 0);
  // for(int i = 1; i <= N; i++) {
  //   for(int j = 0; j <= W; j++) {
  //     if( w[i-1] <= j )
  //       dp[i][j] = max( dp[i-1][j], dp[i-1][j - w[i-1]] + v[i-1]);
  //     else
  //       dp[i][j] = dp[i-1][j];
  //   }
  // }
  // cout << dp[N][W] << "\n";

  // // dp[i][j] := i???????????§?????????????????£????????? j ??§????????§??????
  // auto dp = make_2d_vector(N + 1, W + 1, 0);
  // for(int i = 1; i <= N; i++) {
  //   for(int j = 0; j <= W; j++) {
  //     if( w[i-1] <= j )
  //       dp[i][j] = max( dp[i-1][j], dp[i-1][j - w[i-1]] + v[i-1] );
  //     else
  //       dp[i][j] = dp[i-1][j];
  //   }
  // }

  // cout << dp[N][W] << "\n";

  return 0;
}

Measured memory_bytes: 6804
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n = Integer.parseInt(scanner.next());
    int[] a = new int[n];
    int[] dif = new int[n];
    for(int i=0; i<n; i++){
      a[i] = Integer.parseInt(scanner.next());
      dif[a[i]] ++;
    }
    scanner.close();

    int ans = 1;
    for(int i=(n+1)%2; i<n; i+=2){
      if(i == 0){
        if(n == 1){
          System.out.println(1);
          break;
        }else if(dif[0] != 1){
          System.out.println(0);
          break;
        }
      }else if(dif[i] != 2){
        System.out.println(0);
        break;
      }else if(n-2 <= i){
        for(int j=0; j<n/2; j++){
          ans *= 2;
          ans %= 1000000007;
        }
        System.out.println(ans);
      }
    }
  }
}


Measured memory_bytes: 59796
#include <cstdio>
int main()
{
    int n;
    while (scanf("%d",&n)&&n!=0) {
        int maxP,maxD=0,p,d1,d2;
        for (int i=0; i<n; i++) {
            scanf("%d%d%d",&p,&d1,&d2);
            if (maxD<d1+d2) {
                maxP=p;
                maxD=d1+d2;
            }
        }
        printf("%d %d\n",maxP,maxD);
    }
}

Measured memory_bytes: 768
/******************************************c++
* 20.04.07 AtCoder Beginner Contest 159. B - String Palindrome 
* https://atcoder.jp/contests/abc159/tasks_print
* 
*********************************************/
/*********************************************

問題文長さが奇数である文字列Sが以下の条件をすべて満たすとき、
Sは「強い回文」であるといいます。Sは回文である。
NをSの長さとするとき、Sの1文字目から(N−1)/2文字目まで(両端含む)からなる文字列は
回文である。Sの(N+3)/2文字目からN文字目まで(両端含む)からなる文字列は回文である。
Sが強い回文かどうかを判定してください。

::test input::
akasaka

*********************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int (i)=1;(i)<=(n);i++)
#define rez(i,n) for(int (i)=0;(i)<(n);i++)
#define ET "\n"

class CRun{
private:
    struct {
        string s = "";
    }gv;
public:
    CRun(){}; ~CRun(){};
    void build(); void solve();
    
    bool string_reverse_chk(string);
};

void CRun::build(){
    cin >> gv.s;
}

bool CRun::string_reverse_chk(string s) {
    string rev_s = s;
    reverse(rev_s.begin(), rev_s.end());
    if (s.compare(rev_s) == 0) return true;
    return false;
}

void CRun::solve(){
    string ans = "No";
    
    do {
        int slen = gv.s.length();
        string srev = gv.s;
        reverse(srev.begin(), srev.end());
        
        //condition 1.
        if (!string_reverse_chk(gv.s)) break;
        
        //condition 2.
        string cut_s1 = gv.s.substr(0, (slen -1)/2);
        string cut_s2 = srev.substr(0, (slen -1)/2);
        if (!string_reverse_chk(cut_s1)) break;
        if (!string_reverse_chk(cut_s2)) break;
        
        //condition 3.
        string cut_s3 = gv.s.substr((slen+3)/2 -1, slen);
        string cut_s4 = srev.substr((slen+3)/2 -1, slen);
        if (!string_reverse_chk(cut_s3)) break;
        if (!string_reverse_chk(cut_s4)) break;
        
        
        
        ans = "Yes";
    } while (0);
    
    cout << ans;
}


int main(){
    CRun run;
    run.build();
    run.solve();
}



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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

typedef tuple<int, int, int> T;

void solve() {
  int n;
  cin >> n;
  vi l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());
  int a, b;
  ll ans = 0;
  dump(l);
  rep(i, n) rep(j, n) {
    if (i < j) {
      a = l[i];
      b = l[j];
      int p = lower_bound(l.begin(), l.end(), a + b) - l.begin();
      ans += max(p - j - 1, 0);
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

const int oo = 0x3f3f3f3f;
const int maxn = 40000 + 10;
const int maxm = 8000000 + 10;

int S, T;
namespace Dinic {

    int ecnt = 1; 
    int dis[maxn], cur[maxn];
    int st[maxn], to[maxm], nxt[maxm], cap[maxm];

    void addedge(int u, int v, int c) {
        to[++ecnt] = v; nxt[ecnt] = st[u]; st[u] = ecnt; cap[ecnt] = c;
        to[++ecnt] = u; nxt[ecnt] = st[v]; st[v] = ecnt; cap[ecnt] = 0;
    }

    bool bfs() {
        static int q[maxn];
        int head = 0, tail = 0;
        memset(dis, 0xff, sizeof dis);

        dis[q[tail++] = S] = 0;
        while(head < tail) {
            int x = q[head++];
            for(int i = st[x]; i; i = nxt[i]) 
                if(cap[i] && !~dis[to[i]]) {
                    dis[to[i]] = dis[x] + 1;
                    q[tail++] = to[i];
                }
        }
        return ~dis[T];
    }

    int dfs(int u, int flow) {
        if(u == T || !flow) 
            return flow;

        int res = 0;
        for(int& i = cur[u]; i; i = nxt[i]) {
            int aug, v = to[i];
            if(dis[v] == dis[u] + 1 && (aug = dfs(v, min(flow, cap[i])))) {
                res += aug;
                flow -= aug;
                cap[i] -= aug;
                cap[i^1] += aug;
                if(!flow) return res;
            }
        }
        return res;
    }
    int maxflow() {
        int ans = 0;
        while(bfs()) {
            memcpy(cur, st, sizeof st);
            ans += dfs(S, oo);
        }
        return ans;
    }
}

int main() {
    char grid[110][110];
    int n, m, si, sj, ti, tj;
    //freopen("data.txt", "r", stdin);
    
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i++) scanf("%s", grid[i]);

    for(int i = 0; i < n; i++) 
        for(int j = 0; j < m; j++) {
            int sx, tx;
            sx = i * m + j;
            tx = i * m + j + n*m;

            if(grid[i][j] == 'S') {
                S = i * m + j;

                si = i, sj = j;
                for(int k = 0; k < n; k++) if(k ^ i) 
                    if(grid[k][j] != '.') Dinic :: addedge(S, k * m + j, 1);
                for(int k = 0; k < m; k++) if(k ^ j) 
                    if(grid[i][k] != '.') Dinic :: addedge(S, i * m + k, 1);
            }
            else if(grid[i][j] == 'T') {
                T = i * m + j;

                ti = i, tj = j;
                for(int k = 0; k < n; k++) if(k ^ i)
                    if(grid[k][j] != '.') Dinic :: addedge(k * m + j + n * m, T, 1);
                for(int k = 0; k < m; k++) if(k ^ j) 
                    if(grid[i][k] != '.') Dinic :: addedge(i * m + k + n * m, T, 1);
            }
            else {
                Dinic :: addedge(sx, tx, 1);
                for(int k = 0; k < n; k++) if(k ^ i) 
                    if(grid[k][j] != '.') Dinic :: addedge(tx, k * m + j, 1);
                for(int k = 0; k < m; k++) if(k ^ j) 
                    if(grid[i][k] != '.') Dinic :: addedge(tx, i * m + k, 1);
            }
        }

    if(si == ti || sj == tj) return printf("%d\n", -1), 0;

    printf("%d\n", Dinic :: maxflow());


    return 0;
}


Measured memory_bytes: 53632
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    s='$'+s;
    ll R[n+2]={0},G[n+2]={0},B[n+2]={0};
    for(int i=1;i<=n;i++)
    {
        R[i]=R[i-1];
        G[i]=G[i-1];
        B[i]=B[i-1];
        if(s[i]=='R')
            R[i]++;
        if(s[i]=='G')
            G[i]++;
        if(s[i]=='B')
            B[i]++;
    }
    B[n+1]=B[n];
    G[n+1]=G[n];
    R[n+1]=R[n];
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(s[i]==s[j])
                continue;
            if((s[i]=='R' && s[j]=='G')||(s[i]=='G' && s[j]=='R'))
            {
                ans+=(B[n]-B[j]);
                ll diff=j-i;
                ll k=j+diff;
                if(k>n)
                    continue;
                if(s[k]=='B')
                    ans--;
            }
            if((s[i]=='R' && s[j]=='B')||(s[i]=='B' && s[j]=='R'))
            {
                ans+=(G[n]-G[j]);
                ll diff=j-i;
                ll k=j+diff;
                if(k>n)
                    continue;
                if(s[k]=='G')
                    ans--;
            }
            if((s[i]=='B' && s[j]=='G')||s[i]=='G' && s[j]=='B')
            {
                ans+=(R[n]-R[j]);
                ll diff=j-i;
                ll k=j+diff;
                if(k>n)
                    continue;
                if(s[k]=='R')
                    ans--;
            }
        }
    }
    cout<<ans<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

int main(void){
    int A, B, C;
    cin >> A >> B >> C;

    // implements
    if(A == B){
        printf("%d\n", C);
    }
    else if(A == C){
        printf("%d\n", B);
    }
    else{
        printf("%d\n", A);
    }
    return 0;
}


Measured memory_bytes: 256
<?php

list($k) = explode(' ', trim(fgets(STDIN)));
list($a, $b) = explode(' ', trim(fgets(STDIN)));

for ($i = $a; $i <= $b; ++$i) {
    if ($i % $k === 0) {
        echo 'OK';
        exit;
    }
}

echo 'NG';


Measured memory_bytes: 16016
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>

using namespace std;

const int INF = 1e6;

bool isprime(int n, vector<int> prime){
    for (int i=0; i<prime.size(); i++){
        if (n%prime[i] == 0)  return false;
    }
    return true;
}

int main(){
    int n;  cin >> n;
    vector<int> prime;
    long long ans=1;

    for (int i=2; i<=n; i++){
        if (isprime(i, prime)){
            prime.push_back(i);
            int count=0;
            int num=n;
            while(num > 0){
                count += num/i;
                num /= i;
            }
            ans = (ans*(count+1))%1000000007;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
const int K = 100010;
int _w;

int k, a[K];

bool solve( int x, ll &l, ll &r ) {
	if( l % x ) {
		l /= x;
		++l;
		l *= x;
	}
	r /= x;
	r *= x;
	return l <= r;
}

int main() {
	_w = scanf( "%d", &k );
	for( int i = 0; i < k; ++i )
		_w = scanf( "%d", a+i );
	ll al = 2, ar = 2;
	for( int i = k-1; i >= 0; --i ) {
		if( !solve( a[i], al, ar ) )
			return puts("-1"), 0;
		ar += a[i] - 1;
	}
	printf( "%lld %lld\n", al, ar );
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n, m, a[50], b[50], x[50]={0};
 
   cin >> n >> m;
   for(int i=0;i<m;i++) cin >> a[i] >> b[i];
   for(int i=0;i<m;i++){
      x[a[i]-1]++;
      x[b[i]-1]++;
   }
 
   for(int i=0;i<n;i++)
      cout << x[i] <<endl;
}

Measured memory_bytes: 3636
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int a,b,c;cin>>a>>b>>c;
  int m = min(c, a-b);
  cout << c-m << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

using ll = long long;
using ull = unsigned long long;

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

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N;
    cin >> N;
    vector<string> S(N);
    REP(i,N) cin >> S[i];
    vector<int> p(N,0);
    vector<pair<bool,bool>> q(N); // Bで始まる, Aで終わる
    int bst = 0;
    int afn = 0;
    int b2a = 0;
    int nn = 0;
    REP(i,N) {
        bool f1 = false;
        bool f2 = false;
        int n = 0;
        if (S[i][0] == 'B') f1 = true;
        if (S[i][S[i].size()-1] == 'A') f2 = true;
        REP(j,S[i].size()-1) {
            if (S[i][j] == 'A' && S[i][j+1] == 'B') n++;
        }
        nn += n;
        p[i] = n;
        q[i] = make_pair(f1,f2);
        if (f1 && f2) {
            b2a++;
        }
        else if (f1) {
            bst++;
        }
        else if (f2) {
            afn++;
        }   
    }
    //cout << b2a <<" "<<bst<<" "<<afn<<endl;
    int ans = nn;
    int aandb = min(afn,bst);
    afn -= aandb;
    bst -= aandb;
    if (aandb == 0) {
        //cout << "hoge" << endl;
        // ~~a か　b~~ しかない
        if (b2a == 0) ;
        else if (b2a == 1) {
            if (max(afn, bst) != 0) ans ++;
        }
        else {
            if (max(afn,bst) != 0) ans += b2a;
            else ans += b2a - 1;
        }
    }
    else if (b2a != 0) {
        //cout << "huga" << endl;
        ans += b2a + 1;
        aandb --;
        b2a = 0;
    }
    ans += aandb;
    cout << ans << endl;

    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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


int main() {

	int a, b, c;
	cin >> a >> b >> c;

	if(a < b) swap(a, b);
	if(a < c) swap(a, c);
	if(b < c) swap(b, c);

	int ans = 0;

	while(a >= b + 2){
		ans++;
		b += 2;
	}
	while(a >= c + 2){
		ans++;
		c += 2;
	}

	if(a - b == 0){
		if(a == c) cout << ans << endl;
		else cout << 	ans + 2 << endl;
	}
	else{
		if(a == c) cout << ans + 2 << endl;
		else cout << ans + 1 << endl;
	}

	return 0;

}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_178
{
    class E
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            long[] pluses = new long[n];
            long[] minuses = new long[n];
            for(int i = 0; i < n; i++)
            {
                int[] xy = ReadInts();
                pluses[i] = xy[0] + xy[1];
                minuses[i] = xy[0] - xy[1];
            }
            Array.Sort(pluses);
            Array.Sort(minuses);

            long res = Max(pluses[n - 1] - pluses[0], minuses[n - 1] - minuses[0]);
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main(){
	int N;
	cin >> N;
	int a[N], S=0;
	for(int i=0; i<N; i++){
		cin >> a[i];
		S += a[i];
	}
	sort(a, a+N);
	reverse(a, a+N);
	for(int i=0; 2*i+1<N; i++) S -= 2*a[2*i+1];
	cout << S << endl;
}

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

using namespace std;

int main() {
  int N;
  long long K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
  }
  vector<int> visited(N, -1);
  int a = 0;  // 最初の町からサイクルにたどり着くまでの移動回数
  int T = 0;  // サイクルの周期
  int p = 0;
  for (int i = 0; i <= N; i++) {
    if (visited[p] != -1) {
      T = i;
      break;
    }
    visited[p] = i;
    p = A[p];
  }
  a = visited[p];
  T -= a;
  p = 0;
  if (K <= a) {
    for (int i = 0; i < K; ++i) p = A[p];
  } else {
    for (int i = 0; i < a; ++i) p = A[p];
    K = (K - a) % T;
    for (int i = 0; i < K; ++i) p = A[p];
  }
  cout << p + 1 << endl;
  return 0;
}


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

# 完全に含まれる操作の回数はceil(N/(A+B))
ans = (N // (A+B)) * A
# 不完全な操作は高々1回
# A>N%(A+B)なら、青色はN%(A+B)個で、N%(A+B)>=Aなら、青色はA個
ans += min(N % (A+B), A)
 
print(ans)

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

const double PI = 3.141592653589;

int main() {
	int h, w, i, j;

	while(true) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;

		for (i = 0; i < h; i++){
			for (j = 0; j < w; j++){
				if ((i + j) % 2) cout << ".";
				else cout << "#";
			}
			cout << endl;
		}
		cout << endl;

	}

	return 0;
}


Measured memory_bytes: 3096
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class ETozanAndGezan {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,c=INT_MAX;
        in>>n;
        vector<int> a(n),b(n);
        ll ans=0,t=0;
        fr(i,n){
            in>>a[i]>>b[i];
            ans+=a[i];
            if(a[i]>b[i]) c=min(c,b[i]);
        }
        out<<(c<INT_MAX?ans-c:0)<<endl;
    }
};

int main() {
    ETozanAndGezan solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        int max = 0;
        int ans = 0;
        int tmp = 0;
        for(int i = 0;i<n;i++){
            tmp = sc.nextInt();
            sc.nextLine();
            ans += tmp;
            if(tmp > max){
                max = tmp;
            }
        }
        ans -= max/2;
        System.out.println(ans);
    }
}

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

int main() {
  int n;
  cin>>n;
  vector<int> a(n),b(n+1,0);
  for(int i=0;i<n;i++){
    cin>>a[i];
    b[a[i]]++;
  }
  int64_t sum=0;
  for(int i=1;i<=n;i++){
    sum+=b[i]*(b[i]-1LL)/2LL;
  }
  int64_t ans;
  for(int i=0;i<n;i++){
    ans=sum-b[a[i]]+1;
    cout<<ans<<endl;
  }
}


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

using namespace std;

#define forn for (ll i = 0; i < n; i++)
#define form for (ll j = 0; j < m; j++)
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (ll i = a; i < b; i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

ll gcd(ll a, ll b){
    ll r;
    while (b != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}


ll *calc_z(string s){
    ll n = s.size();
    ll *z = new ll[n] {0};
    ll l = 0, r = 0;
    for (ll i = 1; i < n; i++){
        if (r >= i) z[i] = min(z[i-l], r-i+1);
        while (z[i]+i < n && s[z[i]] == s[z[i]+i]) z[i]++;
        if (i + z[i] - 1 > r){
            l = i;
            r = i+z[i]-1;
        }
    }
    return z;
}

int find_lower(int *a, int n, int v){
    int l = -1, r = n;

    while (r-l > 1){
        int m = (l+r)/2;
        if (a[m] <= v) l = m;
        else r = m;
    }
    return l;
}

void init(){
}

int bin(int *p, int n, int x){
    int l = 0, r = n-1;
    while (r >= l){
        int m = (l+r)/2;
        if (p[m] == x) return m;
        if (p[m] > x) r = m-1;
        else l = m+1;
    }
    return -1;
}

bool ok(vector<int> a, int k, int x){ //n=6, k=4, x=4, a={1,2,3,4,5,6}
    int n = (int) a.size(); 
    int s = 0;
    int z = 0;
    while (n-z >= k){
        sort(a.rbegin(), a.rend());
        int g = 0;
        for (int i = 0; i < n && g < k; i++){
            if (a[i] > 0){
                g++;
                a[i]--;
                if (a[i] == 0) z++;
            }
        }
        if (g == k) s++;
    }
    return s >= x;
}

void solve(){
    int n, k;
    cin >> n >> k;
    vi h(n);
    forn cin >> h[i];
    sort(h.begin(), h.end());
    ll ans = 0;
    if (k >= n) ans = 0;
    else{
        for (int i = 0; i < n-k; i++){
            ans += h[i];
        }
    }
    cout << ans << '\n';
}

int main(){
    //init();

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

    //ll t; cin >> t; while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 4752
import itertools

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

#onにするスイッチを選ぶ
switch = [i for i in range(1,n+1)]
comb = []
for i in range(n+1):
    for v in itertools.combinations(switch,i):
        comb.append(v)

ans = 0
for i in comb:
    for j in range(m):
        tmp = 0
        for l in range(1,ks[j][0]+1):
            if ks[j][l] in i:
                tmp += 1
        if tmp%2 != p[j]:
            break
    else:
        ans += 1

print(ans)

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

int main() {
  int n;
  bool a[4][13];
  cin >> n;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 13; j++) {
      a[i][j] = false;
    }
  }
  for (int i = 0; i < n; i++) {
    int x, y;
    char c;
    cin >> c >> y;
    switch (c) {
    case 'S':
      x = 0;
      break;
    case 'H':
      x = 1;
      break;
    case 'C':
      x = 2;
      break;
    case 'D':
      x = 3;
      break;
    }
    a[x][y - 1] = true;
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 13; j++) {
      if (!a[i][j]) {
        char c;
        switch (i) {
        case 0:
          c = 'S';
          break;
        case 1:
          c = 'H';
          break;
        case 2:
          c = 'C';
          break;
        case 3:
          c = 'D';
          break;
        }
        cout << c << " " << j + 1 << endl;
      }
    }
  }
}

Measured memory_bytes: 3092
import sys
import math

def fact(n, modulus):
    ans=1
    for i in range(1,n+1):
        ans = ans * i % modulus    
    return ans % modulus

arr=[]
arr =(input().split())

n = int(arr[0])
m = int(arr[1])

modulus = 1000000007

if abs(n-m)>1 :
    print(0)
elif n==m:
    ans = (fact(n,modulus)*fact(m,modulus))%modulus
    ans = ans+ans
    if ans > modulus:
        ans-=modulus
    print(ans)
else:
    print( (fact(n,modulus)*fact(m,modulus))%modulus)
    

Measured memory_bytes: 3064
/**
 * @author: Jun
 * @date  : 03-17-2019
 **/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007

int arr[3];
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> arr[0] >> arr[1] >> arr[2];
    sort(arr,arr+3);
    if(arr[0]==arr[1] && arr[1]==5 && arr[2]==7){
        cout << "YES" << el;
    } else {
        cout << "NO" << el;
    }
    return 0;
}

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

int main () {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (max(a,c) - min(a,c) <= d) {
    cout << "Yes" << endl;
  }
  
  else if ((max(a,b) - min(a,b) <= d) && (max(b,c) - min(b,c) <= d)) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#include <unordered_map>
 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 200005
#define inf 2000000000
#define MOD 1000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<pair<int, int>, int> tup;
 
 
inline void solve()
{
    int a,b;
    cin>>a>>b;
    if (a > b)
        swap(a,b);
    if(a==2 && b==3) cout<<1;
    else if(a==1 && b==2) cout<<3;
    else cout<<2;
}
 
int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();
		double[] l = new double[N+2];	// l[0] = 0
		double[] r = new double[N+2];	// r[0] = 0;
		double T = 0.0;
		for(int i = 1; i <= N; i++)
		{
			l[i] = T;
			T += GetDouble();
			r[i] = T;
		}
		l[N + 1] = T;
		r[N + 1] = T;

		double[] v = new double[N+2];	// v[0] = v[N+1] = 0
		for(int i = 1; i <= N; i++)
			v[i] = GetDouble();

		double sum = 0;		
		double prevV = 0.0;
		for(double x = 0.5; x <= T; x += 0.5)
		{
			double currentV = 1000;
			for(int i = 0; i < N + 2; i++)
			{
				double tmpV;
				if(x < l[i])
					tmpV = v[i] + (l[i] - x);
				else if(x <= r[i])
					tmpV = v[i];
				else
					tmpV = v[i] + (x - r[i]);
				currentV = Math.Min(currentV, tmpV);
			}
			sum += 0.25 * (prevV + currentV);
			prevV = currentV;
		}

		Console.WriteLine($"{sum:F6}");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

bool test(string &s, string t, ll i) {
	if (i + sz(t) > sz(s)) return false;
	FOR(j,0,sz(t)) if (s[i+j] != t[j]) return false;
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string s; cin >> s;

	vb dp(sz(s)+1);
	dp[sz(s)] = true;

	FORD(i,0,sz(s)) for (string t: {"dream","dreamer","erase","eraser"}) {
		if (test(s,t,i) && dp[i+sz(t)]) dp[i] = true;
	}
	cout << (dp[0] ? "YES" : "NO") << endl;

}



Measured memory_bytes: 512
N, H = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(N)))

a_max = max(a)  # 振るの最大ダメージ
b = [x for x in b if x > a_max]  # 振るの最大ダメージより、投げつけるダメージが低い刀は投げつける意味がないので除去
b.sort(reverse=True)

result = 0

# 投げつけるダメージが高い順に刀を投げていき、刀が尽きる前に倒せればそれで終了
for x in b:
    result += 1
    H -= x
    if H <= 0:
        break

# もし投げつけるだけで倒せなかった場合は、振るの最大ダメージの刀を振る
# 振るの最大ダメージの刀が投げつける刀に入っていた場合は、必要なだけ振った後に投げつけたことにする
if H > 0:
    result += (H + (a_max - 1)) // a_max

print(result)


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            int[] B = new int[N];
            string[] B_in = Console.ReadLine().Split(' ');
            for (int i = 0; i < N-1; i++)
            {
                B[i] = int.Parse(B_in[i]);
            }
            B[N - 1] = B[N - 2];
            A[0] = B[0];
            int result = A[0];
            for (int i = 1; i < N-1; i++)
            {
                A[i] = Math.Min(B[i-1], B[i]);
                result += A[i];
            }
            result += B[N - 1];
            Console.WriteLine(result.ToString());
//            Console.Read();
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <string>
#include <stdlib.h>
#include <vector>
#include <climits>
#include <math.h>
#include <map>
#include <set>
using namespace std;
int main()
{
	long long int n;
	cin>>n;
	long long int sum=0;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			for (int z = 1; z <= n; ++z)
			{
				sum=sum+__gcd(i,__gcd(j,z));
			}
		}
	}
	cout<<sum;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <chrono>
#include <sstream>
#include <sys/stat.h>
#include <string>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
	std::string s;
	cin >> s;
	//cout <<s.length();

	for(int i=0;i<((s.length()-1)-1)/2;i++){
		if(s[i]!=s[(((s.length()-1)-1)/2)-i]){
			cout << "No";
			return 0;
		}
	}

	for(int i=((s.length()+3)-1)/2;i<s.length();i++){
		if(s[i]!=s[s.length()-i+(((s.length()+3)-1)/2)-1]){
			cout << "No";
			return 0;
		}
	}

	int stringlength=(s.length()/2);

	for(int i=0;i<stringlength;i++){
		if(s[i]!=s[(s.length()-i-1)]){
			cout << "No";
			return 0;
		}
	}



	cout << "Yes";
	

}

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

int n,x,sum,ans;
vector<int> v;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i)
	{
		cin>>x;
		v.push_back(x);
	}	

	sort(v.begin(),v.end());

	for(int i=0;i<v.size()-1;++i)
		ans+=v[i];
	ans+=v[n-1]/2;
	cout<<ans<<"\n";
}

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

public class Main {
	public static void main(String[] args) throws Exception {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			
			String[] tmp = br.readLine().split(" ");
			int n = Integer.parseInt(tmp[0]);
			int m = Integer.parseInt(tmp[1]);
			
			List<Integer>[] g = new ArrayList[n];
			for (int i = 0; i < n; i++) {
				g[i] = new ArrayList<>();
			}
			
			for (int i = 0; i < m; i++) {
				tmp = br.readLine().split(" ");
				int a = Integer.parseInt(tmp[0]) - 1;
				int b = Integer.parseInt(tmp[1]) - 1;
				g[a].add(b);
				g[b].add(a);
			}
			
			int[] ans = new int[n];
			
			Queue<Integer> q = new ArrayDeque<>();
			q.offer(0);
			while (!q.isEmpty()) {
				int p = q.poll();
				for (int v : g[p]) {
					if (ans[v] == 0) {
						ans[v] = p + 1;
						q.add(v);
					}
				}
			}
			
			PrintWriter pw = new PrintWriter(System.out);
			pw.println("Yes");
			for (int i = 1; i < n; i++) {
				pw.println(ans[i]);
			}
			pw.flush();
			
		}
	}
}

Measured memory_bytes: 71492
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            if (K == 1) {
                out.println(0);
            } else {
                out.println(N - K);
            }
        }

    }
}



Measured memory_bytes: 21972
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;

int main()
{
    stat();
unsigned ll a,b;
cin>>a>>b;
ull cur=a;
ull ans=0;
for(;;){
if(cur>b){break;}
++ans;
cur*=2;

}
cout<<ans<<endl;

    return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define ALL(x) (x).begin(), (x).end()

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

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    int N;
    cin >> N;
    ll a[100000];
    rep(i, N) {
        cin >> a[i];
    }

    sort(a, a+N);

    int ans = 0;
    rep(i, N) {
        int e = a[i];
        int j = i;
        while(a[j]==e) j++;
        int e_num = j - i;

        if(e_num > e) {
            ans += e_num-e;
        } else if(e_num < e) {
            ans += e_num;
        }
        i = j-1;
    }

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


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) a.begin(), a.end();

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int aa = a;
    int bb = b;
    int cc = c;

    int cnt = 0;
    while(bb <= aa) {
        bb *= 2;
        k --;
    }

    if (cc *int(pow(2, k))> bb && cc * int(pow(2, k)) > aa)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3996
n,m=map(int,input().split())
py=[list(map(int,input().split()))+[i] for i in range(m)]
py.sort(key=lambda x:x[1])
ans=[]
cnt=[0]*n
for p,y,i in py:
    ans.append(['{0:06d}{1:06d}'.format(p,cnt[p-1]+1),i])
    cnt[p-1]+=1
ans.sort(key=lambda x:x[1])
for a,i in ans:
    print(a)

Measured memory_bytes: 42536
#include<bits/stdc++.h>
using namespace std;
const int maxl=128;
const string alphabet="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int query(string s)
{
    cout<<"? "<<s<<endl;
    int ret;
    cin>>ret;
    return ret;
}
int cnt[62],n;
bool issubstring(string s)
{
    int v=query(s);
    return n-v==s.size();
}
string solve(int l,int r)
{
    if(l==r)return string(cnt[l],alphabet[l]);
    int mid=(l+r)>>1;
    string s1=solve(l,mid),s2=solve(mid+1,r);
    string ret;
    while(!s1.empty()||!s2.empty())
    {
        if(s2.empty())ret.push_back(s1.front()),s1.erase(s1.begin());
        else if(!s1.empty()&&issubstring(ret+s1.front()+s2))ret.push_back(s1.front()),s1.erase(s1.begin());
        else ret.push_back(s2.front()),s2.erase(s2.begin());
    }
    return ret;
}
int main()
{
    for(int i=0;i<62;i++)cnt[i]=maxl-query(string(maxl,alphabet[i])),n+=cnt[i];
    string res=solve(0,61);
    cout<<"! "<<res;
    return 0;
}

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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

const ll inf = 1e18;
const int nax = 1e5 + 5;

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

	ll h[n];
	forn(i,0,n)
	{
		cin>>h[i];
	}

	sort(h,h+n);
	ll ans = 0;

	forn(i,0,n-k)
	{
		ans+=h[i];
	}

	cout<<ans;

	return 0;
}

Measured memory_bytes: 1792
N = int(input())
A = sorted(list(map(int, input().split())))
m = A[-1]+1
dp = [0]*(m*2)
ans = 0

for a in A:
    for i in range(0, m//a+1):
        dp[a*i] += 1
for a in A:
    if dp[a] == 1:
        ans += 1

print(ans)

Measured memory_bytes: 35796
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;
int store[100001];
int point[10001];
long long int ans[10001];
int abs(int x){
	if(x>0) return x;
	else return x*-1;
}

int main(){
	lli d;
	int n,m;
	while(cin >> d&&d){
		cin >> n >> m;
		store[0]=0;
		for(int i=1; i<n; ++i){
			cin >> store[i];
		}
		for(int i=0; i<m; ++i){
			cin >> point[i];
		}
		for(int i=0; i<m; ++i){
			ans[i]=INF;
		}
		sort(store,store+n);
		for(int i=0; i<m; ++i){
			int up=n,down=0;
			int count=0;
			/*for(int j=0; j<n; ++j){
				cout << store[j] << "\n";
			}*/
			//cout << "\n";
			while(1){
				int mid=(up+down)/2.0;
				if(ans[i]>abs(point[i]-store[mid])) ans[i]=abs(point[i]-store[mid]);
				if(count==1000) {
					break;
				}
				if(store[mid]>point[i]){
					up=mid;
				} else {
					down=mid;
				}
				++count;
			}
			if(d-point[i]<ans[i]) ans[i]=d-point[i];
			//cout << ans[i] << "\n";
		}
		long long int Ans=0;
		for(int i=0; i<m; ++i){
			Ans+=ans[i];
		}
		cout << Ans << "\n";
	}
}

Measured memory_bytes: 1688
#include <iostream>

using namespace std;

int main() {

	int n, j, x[10];

	while(cin >> n) {
		if(n==0)
			break;
		for(int i=0; i<10; i++) {
			x[i]=0;
		}
		for(int i=0; i<n; i++) {
			cin >> j;
			x[j]++;
		}
		for(int i=0; i<10; i++) {
			if(x[i]!=0) {
				while(x[i]>0) {
					cout << "*";
					x[i]--;
				}
			}
			else
				cout << "-";
			cout << endl;
		}
	}

	return 0;

}

Measured memory_bytes: 0
s = []
n = int(input())
for i in range(n):
    s.append(input())
print("AC x " + str(s.count("AC")))
print("WA x " + str(s.count("WA")))
print("TLE x " + str(s.count("TLE")))
print("RE x " + str(s.count("RE")))

Measured memory_bytes: 16272
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  Int ans=0;
  for(Int i=0;i<n;i++){
    Int a;
    cin>>a;
    while(~a&1) a>>=1,ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
class Dice{
    public:
    int a[7],n;
    
    Dice(){}
    
    void roll_E(){   //東のとき
        roll(1,4,6,3);
    };   
    
    void roll_W(){  //西のとき
        roll(1,3,6,4);
    };
    
    
    void roll_S(){   //南のとき
        roll(1,5,6,2);
    };
    void roll_N(){  //北のとき
        roll(1,2,6,5);
    };
    
    
    void roll(int i, int j, int k, int l){    //転がったときの値の移動
       n = a[i], a[i] = a[j], a[j] = a[k], a[k] = a[l], a[l] = n; 
    }
    
    void way(char m){  //方角を判断
        if(m == 'E') roll_E();
        else if(m == 'W') roll_W();
        else if(m == 'S') roll_S();
        else if(m == 'N') roll_N();
    }
    
};
    



int main(void){
    // Your code here!
    Dice dice;
    char direction; //方向
    
    for(int i = 1; i <= 6; i++){    //各面に値を入力
        cin >> dice.a[i];
    }
    
    while(cin >> direction){
        dice.way(direction);
    }
    
    cout << dice.a[1] << endl;
    
}


Measured memory_bytes: 3116
#include<iostream>
using namespace std;
int main ()
{
	long long n; cin >> n;
	long long k; cin >> k;
	long long ans = 0;
	for (long long i = k; i <= n + 1; i++)
	{
		ans += ((2 * n + 1 - i) * i - (i - 1) * i) / 2 + 1;
		ans %= 1000000007;
	}
	cout << ans;
}

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

int main() {
    int n;
    cin>>n;
    string ans="No";
    for (int i=1; i<10; i++) {
        if (n % i == 0 && (n / i) <= 9) {
            ans="Yes";
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int>a(n);
	rep(i,n)cin>>a[i];
	sort(a.begin(),a.end());
	int max = a[a.size()-1];
	vector<int>map(max+1,1);
	int head = 0,cnt=0;
	while(head<a.size()){
		if(map[a[head]]==1){
			if(head<a.size()-1){
				if(a[head]!=a[head+1])cnt++;
			}else{
				cnt++;
			}
			for(int i=1;i*a[head]<=max;i++)map[i*a[head]]=0;
		}
		head++;
	}
	cout<<cnt<<endl;



	return 0;
}

Measured memory_bytes: 7932