akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

ll nxt()
{
    ll x;
    cin >> x;
    return x;
}

const ll L = 2e5+5;
bool done[L];

void solve()
{
    ll n = nxt(), k = nxt();
    basic_string <ll> a;

    for(ll i=0; i<n; i++)
    {
        a += (nxt() - 1);
    }

    queue <ll> q;

    ll i = 0;
    while(!done[i])
    {
        done[i] = true;
        q.push(i);
        i = a[i];
    }

    while(!q.empty())
    {
        if(q.front() == i)
        {
            break;
        }

        if(!k)
        {
            cout << q.front() + 1 << endl;
            return;
        }

        else
        {
            q.pop();
            k--;
        }
    }

    k %= sz(q);

    while(!q.empty())
    {
        // if(q.front() == i)
        // {
        //     break;
        // }
        
        if(!k)
        {
            cout << q.front() + 1 << endl;
            return;
        }

        else
        {
            q.pop();
            k--;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll T = 1;
    // T = nxt();

    while(T--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 6684
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cmath>
#include <map>
#include <tuple>

using namespace std;

typedef long long ll;

//0~nまでのxの倍数個数
ll f(ll n, ll x) {
    if (n < 0) return 0;
    return n/x + 1;
}

int main() {
    ll a,b,x;
    cin >> a >> b >> x;


    cout << f(b, x) - f(a-1,x ) << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
	s = input()
	g = 0
	p = 0
	ans = 0
	for c in s:
		if c == "g":
			g += 1
		else:
			p += 1
	if len(s) % 2 == 0:
		ans = (g-p)//2
	else:
		ans = (g-p-1)//2

	print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3188
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)

const int M=1000000007;
const int MM=998244353;


 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=1e5+5;

ll sp[N];

void fill(){
  for(int i=1;i<N;i++)sp[i]=i;

    for(int i=2;i<N;i++){
      for(int j=i;j<N;j+=i){
        if(sp[j]==j)sp[j]=i;
      }
    }
}

//vl f(N);


int main()
{ 

IOS;

ll n;cin>>n;

ll k;cin>>k;

ll c=0;
FOR(i,n){
  ll x;cin>>x;
  c+=(x>=k);
}

cout<<c;

return 0;
 
}


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

int main(){
    int n,A[100];
    
    cin >> n;
    for(int i = 1 ; i <= n ; i++){
        cin >> A[i];
    }
    
    for(int i = 1 ; i <= n ; i++){
        if(i==1) cout << A[i];
        else cout << ' ' << A[i];
    }
    cout << endl;
    
    for(int j = 2 ; j <= n ; j++){
        int key = A[j] ,i = j-1;

        while(i > 0 && A[i] > key){
            A[i+1] = A[i];
            i--;
        }
        A[i+1] = key;
        
        for(int i = 1 ; i <= n ; i++){
            if(i==1) cout << A[i];
            else cout << ' ' << A[i];
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3100
<?php
//error_reporting(0);
$S = trim(fgets(STDIN));
//list($A,$B) =  explode(" ",trim(fgets(STDIN)));
//$B = explode(" ",trim(fgets(STDIN)));

$len = strlen($S);
$m = array();
$l = 0;
for($i=0;$i<$len;$i++) {
  if ($S[$i]=='A' || $S[$i]=='C' || $S[$i]=='G' || $S[$i]=='T') {
    $l++;
  }
  else {
    $m[]=$l;
    $l=0;
  }
}
$m[]=$l;
printf("%d\n",max($m));


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

def main():

    N = int(input())
    s = input().strip()
    for _ in range(N-1):
        tmp = ""
        for c in input().strip():
            if c in s:
                tmp += c
                s = s.replace(c, "", 1)
        s = tmp
    print("".join(sorted(s)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
N,K = (int(x) for x in input().split())
a = [input().split() for l in range(K * 2)]

list = [0] * N

for i in range(1,len(a),2):
    for n in range(len(a[i])):
        x = int(a[i][n])
        list[(x-1)] = 1
        


print(list.count(0))

Measured memory_bytes: 9524
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;

const int MAX = 100005;
const int NIL = -1;
int D[MAX];

typedef struct{
    int parent, left, right;
}Node;
Node T[MAX];

int getDepth(int u){
    int depth = 0;
    while(T[u].parent != NIL){
        depth++;
        u = T[u].parent;
    }
    return depth;
}

void setDepth(int u, int d){
    D[u] = d;
    if (T[u].right != NIL) setDepth(T[u].right, d);
    if (T[u].left != NIL) setDepth(T[u].left, d+1);
}

void printChildren(int u){
    /* 節点u のType取得 */
    char temp[15];
    if (T[u].parent == NIL) strcpy(temp, "root");
    else if (T[u].left == NIL) strcpy(temp, "leaf");
    else strcpy(temp, "internal node");

    /* 情報表示 */
    char msg[150];
    sprintf(msg, "node %d: parent = %d, depth = %d, %s, ",u, T[u].parent, D[u], temp);
    cout << msg;
    
    cout << '[';
    int c = T[u].left;
    int cnt = 0;
    while(c != NIL){
        if (cnt != 0) cout << ", " << c;
        else cout << c;
        cnt++;

        /* 子供の情報更新 */
        c = T[c].right;
    }
    cout << ']' << endl;

}

int main(void)
{
    int n;
    cin >> n;

    /* 木の初期化 */
    rep(i,n){
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }

    /* 入力 */
    rep(i,n){
        int id,k,c;
        cin >> id >> k;

        if (k == 0){
            T[id].left = NIL;
        }

        /* 入力された情報からparent, left, rightを設定する */
        int left_b;
        rep(j,k){
            cin >> c;
            if (j == 0) T[id].left = c;
            else{
                /* 左の子供の兄弟情報更新 */
                T[left_b].right = c;
            }
            /* 最も右の兄弟の情報更新 */
            if (j == k-1) T[c].right = NIL;

            /* 親情報更新 */
            T[c].parent = id;

            /* 左の兄弟を更新 */
            left_b = c;
        }
    }
    int root_id;
    rep(i,n){
        if (getDepth(i) < 1){
            root_id = i;
            break;
        }
    }
    /* 各接点の深さ情報を設定する */
    setDepth(root_id, 0);

    /* 情報を表示 */
    rep(i,n) printChildren(i);
    return 0;
}


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

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a + (b - 1)) / b; }
int positive_surplus(int &a) { return (a + MOD) % MOD; }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

class EThisMessageWillSelfDestructIn5s {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> big(N);
    map<int, int> check;
    rep(i, N) {
      cin >> A[i];
      big[i] = (i + 1) - A[i];
      check[big[i]]++;
    }
    int ans = 0;
    rep(i, N) {
      check[big[i]--];
      ans += check[(i + 1) + A[i]];
    }
    cout << ans << endl;
  }
};


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


Measured memory_bytes: 29048
#include <bits/stdc++.h>
#define sync ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define mod 1000000007
using namespace std;
vector<ll> prime,sfac;
vector<ll>ps;
void sieve(ll n)
{
	prime.assign(n+1,1);
	sfac.assign(n+1,1);    
    for (int p=2; p*p<=n; p++) 
    {         
        if (prime[p] == 1) 
        { 	sfac[p]=p;  			  
            for (int i=p*p; i<=n; i += p) 
              {  prime[i] = 0; sfac[i]=p;}
        } 
    } 
	for(ll i=2;i<=n;i++)
	{
		if(prime[i])
			ps.push_back(i);
	}
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll power(ll x, ll y) 
{ 
    ll res = 1;    
    while (y > 0) 
    { 
        ll k=y&1LL;
        if (k) 
            res = res*x;      
        y = y>>1LL;
        x = x*x;  
    } 
    return res; 
}
 
int isPrime(ll n) 
{ 
    if (n <= 1)  return 0; 
    if (n <= 3)  return 1; 
    if (n%2 == 0 || n%3 == 0) 
        return 0;   
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return 0;  
    return 1; 
} 
ll count(ll a[],ll b[],ll t,ll k,ll c,ll ai,ll bi,ll m,ll n)
{
    if(t>k)
        return c-1;
    ll c1=-1,c2=-1;
    if(ai<n)
        c1=count(a,b,t+a[ai],k,c+1,ai+1,bi,m,n);
    if(bi<m)
        c2=count(a,b,t+b[bi],k,c+1,ai,bi+1,m,n);
    if(c1==-1&&c2==-1)
        return n+m;
    else
    {
        return max(c1,c2);
    }
    

}
int main()
{    
    ll n,m,k;
    cin>>n>>m>>k;
    ll a[n],b[m],ac[n],bc[m];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        ac[i]=a[i];
    }
    for(int i=0;i<m;i++)
       { cin>>b[i];bc[i]=b[i];}
   for(int i=1;i<n;i++)
        a[i]+=a[i-1];
    for(int i=1;i<m;i++)
        b[i]+=b[i-1];
    ll c=0,mc=0,pos=n;
    for(int i=0;i<n;i++)
    {
        if(a[i]>k)
        {
            pos=i;
            break;
        }
    }

        c=pos;
        mc=c;
        pos--;
        ll rem=k;
        if(pos>-1)
            rem-=a[pos];        
        int p=lower_bound(b,b+m,rem)-b;
        ll cc=c;
        if(p==m)
        {
            c+=m;
            mc=c;
        }
        else
        {
            if(b[p]>rem)
                c+=p;
            else 
                c+=p+1;
            mc=c;
        }
        c=cc;
        while(pos>-1)
        {
            rem+=ac[pos];
            c--;cc--;
            p=lower_bound(b,b+m,rem)-b;
            if(p==m)
            {
                c+=m;                
            }
            else
            {
                if(b[p]>rem)
                    c+=p;
                else 
                    c+=p+1;                
            }
            if(c>mc)
                mc=c;
            c=cc;
            pos--;
        }
        cout<<mc<<endl;    

    



}


Measured memory_bytes: 9828
#include<stdio.h>
int main(void)
{
   int i,m,f,r,flag=1,cnt=0;
   char a[10000];
   do{
      scanf("%d %d %d",&m,&f,&r);
      if(m==-1||f==-1){
         a[cnt]='F';
      } else if(m+f>=80){
         a[cnt]='A';
      } else if(m+f<80&&m+f>=65){
         a[cnt]='B';
      } else if(m+f<65&&m+f>=50){
         a[cnt]='C';
      } else if(m+f<50&&m+f>=30){
         a[cnt]='D';
         if(r>=50){
            a[cnt]='C';
         }
      } else if(m+f<30){
         a[cnt]='F';
      }
      cnt++;
      if(m==-1&&f==-1&&r==-1){
         flag=0;
      }
   }while(flag);
   for(i=0;i<cnt-1;i++){
      printf("%c\n",a[i]);
   }
   return 0;
}

Measured memory_bytes: 604
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int R = sc.nextInt();
        if(N >= 10){
            System.out.println(R);
        }else{
            System.out.println(R + 100*(10-N));
        }
    }

}

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

ll solve() {
  ll A, B, C;
  cin >> A >> B >> C;
  if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0)
    return 0;
  ll ans = min(A * B, B * C);
  return min(ans, C * A);
}

int main() {
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 200

int top,S[200];

void push(int x);
int pop(void);

int main()
{
  int x,data[2],sum;
  char s[100];

  while( scanf("%s",s) != EOF )
    {
      if ( s[0] == '+' )
      {
        data[0] = pop();
        data[1] = pop();
        push(data[0]+data[1]);

      }
      else if ( s[0] == '-' )
      {
	data[0] = pop();
	data[1] = pop();
	push(data[1]-data[0]);

      }
      else if ( s[0] == '*' )
      {
	data[0] = pop();
	data[1] = pop();
	push(data[1]*data[0]);
      }
      else
      {
        x = atoi(s);
	//	printf("%d\n",x);
	push(x);
	
      }
    }

  printf("%d\n",pop());
  return 0;
}

void push(int x)
{
  top++;
  S[top]=x;
}

int pop(void)
{
  top--;
  return S[top+1];
}




Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

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

    map<string, int> m;
    REP(i, 0, N) {
        string s; cin >> s;
        m[s]++;
    }

    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <math.h>
#define P pow(4,j++)
main(){
  int i,j,n,c; char m[7],o,d[314159];
  for(i=0,scanf("%d %s",&n,m);i<n;i++,scanf("%s",m)){
    for(j=c=o=0;o!='\n';scanf("%c",&o))
      if(o=='A')c+=1*P;
      else if(o=='C')c+=2*P;
      else if(o=='G')c+=3*P;
      else if(o=='T')c+=4*P;
    m[0]=='i'?d[c]=1:(d[c]?printf("yes\n"):printf("no\n"));
  }
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  if (S[0]==S[1] && S[1] == S[2]){
    cout << "Yes" << endl;
  }
  else if (S[1]==S[2] && S[2]==S[3]){
    cout << "Yes" << endl;
  }
  else if (S[0]==S[1] && S[1]==S[2] && S[2]==S[3]){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

ll mod = 1000000007;

ll gcd(ll a, ll b){
  if (a%b == 0)return(b);
  else return(gcd(b, a%b));
}

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}

struct Square {
  int h,w,cnt;
  Square(int _h,int _w,int _cnt){
    h = _h;
    w = _w;
    cnt = _cnt;
  }
};

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

  int h,w;
  cin >> h >> w;
  int ch,cw,dh,dw;
  cin >> ch >> cw >> dh >> dw;
  ch--;cw--;dh--;dw--;

  vector<string> mp(h);
  rep(i,h)cin >> mp[i];

  vvi cnt(h,vi(w));
  list<Square> li;

  li.push_front(Square(ch,cw,1));
  while(!li.empty()){
    Square cur = li.front();
    li.pop_front();

    if(cur.h < 0 || cur.h >= h || cur.w < 0 || cur.w >= w)continue;
    if(cnt[cur.h][cur.w] != 0 && cnt[cur.h][cur.w] <= cur.cnt) continue;
    if(mp[cur.h][cur.w] == '#') continue;
    
    cnt[cur.h][cur.w] = cur.cnt;
    if(cur.h == dh && cur.w == dw)break;

    for(int i = -2;i <= 2;i++){
      for(int j = -2;j <= 2;j++){
        if(i == 0 && j == 0)continue;
        Square nxt = Square(cur.h+i, cur.w+j, cur.cnt);
        if(abs(i)+abs(j) == 1){
          li.push_front(nxt);
        }else{
          nxt.cnt++;
          li.push_back(nxt);
        }
      }
    }
  }

  cout << cnt[dh][dw] - 1 << endl;
}

Measured memory_bytes: 18692
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    ll N;
    cin >> N;
    vector<vector<ll>> X(2, vector<ll>(3));
    for(int i = 0; i < 2; ++i){
        for(int j = 0; j < 3; ++j){
            cin >> X[i][j];
        }
    }
    int sell_idx = 0, buy_idx = 1;
    for(int loop = 0; loop < 2; ++loop){
        vector<ll> dp(N + 1, -1);
        auto MemoRec = [&](auto&& self, int cur) -> ll {
            if(dp[cur] != -1)   return dp[cur];
            ll res = cur;
            for(int i = 0; i < 3; ++i){
                if(cur - X[sell_idx][i] >= 0){
                    chmax(res, self(self, cur - X[sell_idx][i]) + X[buy_idx][i]);
                }
            }
            return dp[cur] = res;
        };
        N = MemoRec(MemoRec, N);
        swap(sell_idx, buy_idx);
    }
    cout << N << endl;
}

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

c = 0
for i in range(N):
  am, ap = A[i], A[i+1]
  b = B[i]
  first = min(am, b)
  second = min(ap, b-first)
  A[i] -= first
  A[i+1] -= second
  c += first + second

print(c)
  

Measured memory_bytes: 19116
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long 
#define f(j) for(ll i=0;i<j;i++)
#define pb(i) push_back(i)
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;    
typedef vector<vector<long long> > matrix; 
ll dp[100][100001],w[100],v[100];
ll calc(int itmNum,int weight){
	ll t1=0,t2=0;
	if(itmNum<0 || !weight)	return 0;
	if(dp[itmNum][weight])	return dp[itmNum][weight];
	t1 = calc(itmNum-1,weight);
	if(w[itmNum]<=weight)
		t2 = calc(itmNum-1,weight-w[itmNum])+v[itmNum];
	dp[itmNum][weight]=max(t1,t2);
	return dp[itmNum][weight];
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	// faster
	int n,weight;
	cin>>n>>weight;
	f(n)	cin>>w[i]>>v[i];
	cout<<calc(n-1,weight);

return 0;	
}

Measured memory_bytes: 75028
unittest
{
	assert( [ "9 3", "0001000100" ].parse.expand.solve == "1 3 2 3" );
	assert( [ "5 4", "011110" ].parse.expand.solve == "-1" );
	assert( [ "6 6", "0101010" ].parse.expand.solve == "6" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	input.popFront;
	auto s = input.front.map!( ( a ) => ( a - '0' ).to!( long ) ).array;
	return tuple( nm[ 1 ], s );
}

auto solve( long m, long[] s )
{
	long[] anss;
	auto p = s.length.signed - 1;
	while( 0 < p )
	{
		auto d = min( m, p );
		while( 0 < d && s[ p - d ] ) d--;
		if( d == 0 ) return "-1";
		p -= d;
		anss ~= d;
	}
	return anss.to!( string[] ).retro.join( ' ' );
}


Measured memory_bytes: 6012
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] X = new int[N];
		int[] Y = new int[N];

		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
			Y[i] = sc.nextInt();
		}

		double total = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				int disX = (int) Math.pow(X[i] - X[j], 2);
				int disY = (int) Math.pow(Y[i] - Y[j], 2);
				total += Math.pow(disX + disY, 0.5);
			}
		}

		System.out.println(total / N);

	}

}

Measured memory_bytes: 35992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    

  int main(){
   lint x,y,a,b,c;
   cin>>x>>y>>a>>b>>c;
   lint p[a];
   lint q[b];
   lint r[c];
    rep(i,a)cin>>p[i];
    rep(i,b)cin>>q[i];
    rep(i,c)cin>>r[i];
    sort(p,p+a,greater<lint>());
    sort(q,q+b,greater<lint>());
    sort(r,r+c,greater<lint>());
    priority_queue <lint> que;
    rep(i,x){
        que.emplace(-p[i]);
    }
    rep(i,y){
        que.emplace(-q[i]);
    }
    rep(i,c){
        lint l=que.top();
        if(l>-r[i]){
            que.pop();
            que.emplace(-r[i]);
        }
    }
    lint ans=0;
    rep(i,x+y){
        ans+=que.top();
        que.pop();
    }
    cout<<-ans;
  }
  
  
     
  

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

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

    sort(a.begin(),a.end());
    vector<int> num(n);

    num.at(0)++;
    int kind=0;
    for(int i=1; i<n; i++){
        if(a.at(i-1)==a.at(i))num.at(kind)++;
        else{
            kind++;
            num.at(kind)++;
        }
    }
    sort(num.begin(),num.end());
    
    int ans=0, i=0;
    while(n>k+i){
        ans+=num.at(i);
        i++;
    }   

    cout << ans << endl;
}

Measured memory_bytes: 4828
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    	Scanner scanner = new Scanner(System.in);
    	int num = scanner.nextInt();
    	String s = scanner.next();
    	int left = 0;
    	for (int i = 0; i < num; i++) {
    	    if(s.charAt(i) == '(') left++;
    	    else left--;
    	    if (left < 0) {
    		s = "(" + s;
    		num++;
    		i++;
    		left++;
    	    }
    	}
    	for (int i = left ; i > 0; i--) {
    	    s = s + ")";
    	}
    	System.out.println(s);
    	scanner.close();
    }
}

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

const int mod = 1000*1000*1000+7;

int N, M;
vector<vector<int> > adj;
vector<vector<int> > Sub;
vector<vector<int> > prec;
vector<int> po;

vector<int> cc;
int dp(int mask) {
    int &ret = cc[mask];
    if(ret != -1) return ret;

    ret = 1;
    for(int i = 0; i < Sub[mask].size(); i++) {
        int nmask = Sub[mask][i];
        if(nmask == 0 || nmask == mask) continue;
        if((nmask & 3) != 0 && (nmask & 3) != 3) continue;

        int tmp = 1;
        for(int j = 0; j < N; j++) {
            if((nmask & (1<<j))) tmp = 1LL * tmp * (po[ prec[j][ mask ^ nmask ] ] - 1) % mod;
            if(((mask ^ nmask) & (1<<j))) tmp = 1LL * tmp * po[ prec[j][nmask] ] % mod;
        }
        tmp = 1LL * tmp * dp(nmask) % mod;
        ret += tmp;
        ret %= mod;
    }

    return ret;
}

int main() {
    po.resize(1000);
    po[0] = 1;
    for(int i = 1; i < 1000; i++) {
        po[i] = po[i - 1] * 2 % mod;
    }

    scanf("%d %d", &N, &M);

    adj.resize(N);

    for(int i = 0; i < M; i++) {
        int x, y; scanf("%d %d", &x, &y);
        x--; y--;

        adj[x].push_back(y);
    }

    Sub.resize(1 << N);
    for(int i = 0; i < (1 << N); i++) {
        if(i == 0) {
            Sub[i].push_back(0);
            continue;
        }
        for(int j = 0; j < Sub[ i - (i&-i) ].size(); j++) {
            Sub[i].push_back(Sub[ i - (i&-i) ][j]);
            Sub[i].push_back(Sub[ i - (i&-i) ][j] + (i&-i));
        }
    }

    prec = vector<vector<int> >(N, vector<int>(1 << N, 0));
    for(int u = 0; u < N; u++) {
        for(int mask = 0; mask < (1 << N); mask++) {
            int cnt = 0;
            for(int i = 0; i < adj[u].size(); i++) {
                int v = adj[u][i];
                if(mask & (1<<v)) cnt++;
            }
            prec[u][mask] = cnt;
        }
    }

    cc = vector<int>(1 << N, -1);
    cout << (po[M] - dp((1 << N) - 1) + mod) % mod;
}


Measured memory_bytes: 62588
a, b = *gets.split(/ /).map(&:to_i)
if a < b
    puts "a < b"
elsif a > b
    puts "a > b"
else
    puts "a == b"
end
__END__
Sample Input 1
1 2
Sample Output 1
a < b
Sample Input 2
4 3
Sample Output 2
a > b
Sample Input 3
5 5
Sample Output 3
a == b

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

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    if(k == 0){
        ll ans = 0;
        rep(i,n){
            ans = max(ans, a[i]);
        }
        cout << ans << endl;
        return 0;
    }

    ll lb = 0, rb = 1e9 + 7;
    while(rb - lb > 1){
        ll mid = (rb + lb) / 2;
        ll cnt = 0;
        rep(i, n) {
            if (a[i] % mid == 0) cnt--;
            ll res = a[i] / mid;
            cnt += res;
        }
        if (cnt > k) {
            lb = mid;
        } else {
            rb = mid;
        }
    }
    cout << rb << endl;
}


Measured memory_bytes: 4712
enc={' '=>'101','\''=>'000000',','=>'000011','-'=>'10010001','.'=>'010001','?'=>'000001',
'A'=>'100101','B'=>'10011010','C'=>'0101','D'=>'0001','E'=>'110','F'=>'01001','G'=>'10011011',
'H'=>'010000','I'=>'0111','J'=>'10011000','K'=>'0110','L'=>'00100','M'=>'10011001','N'=>'10011110',
'O'=>'00101','P'=>'111','Q'=>'10011111','R'=>'1000','S'=>'00110','T'=>'00111','U'=>'10011100',
'V'=>'10011101','W'=>'000010','X'=>'10010010','Y'=>'10010011','Z'=>'10010000'}

dec={'00000'=>'A','00001'=>'B','00010'=>'C','00011'=>'D','00100'=>'E','00101'=>'F','00110'=>'G',
'00111'=>'H','01000'=>'I','01001'=>'J','01010'=>'K','01011'=>'L','01100'=>'M','01101'=>'N',
'01110'=>'O','01111'=>'P','10000'=>'Q','10001'=>'R','10010'=>'S','10011'=>'T','10100'=>'U',
'10101'=>'V','10110'=>'W','10111'=>'X','11000'=>'Y','11001'=>'Z','11010'=>' ','11011'=>'.',
'11100'=>',','11101'=>'-','11110'=>'\'','11111'=>'?'}

while gets
  input=$_.chomp
  le,ld="",""
  input.each_char do |c|
    le+=enc[c]
  end
  while !le.empty?
    ld+=dec[format("%05s",le.slice!(0,5).reverse).reverse.gsub(" ","0")]
  end
  puts ld
end

Measured memory_bytes: 9264
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <tuple>

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

using P = std::pair<int, int>;

constexpr int MAX = 1e5 + 10;

int n, m;
std::vector<int> g[MAX];

bool used[3][MAX];

int d[3][MAX];

int main()
{

    std::cin >> n >> m;

    rep(i, m)
    {
        int u, v;
        std::cin >> u >> v;
        g[u].push_back(v);
    }

    std::queue<P> que;

    int s, t;
    std::cin >> s >> t;

    d[0][s] = 0;
  	used[0][s]=1;
    que.emplace(0, s);

    while (!que.empty())
    {

        int mod, x;
        std::tie(mod, x) = que.front();
        que.pop();

        if (mod == 0 && x == t)
            break;

        int nmod = (mod + 1) % 3;

        for (int y : g[x])
        {
            if (!used[nmod][y])
            {
                que.emplace(nmod, y);
                d[nmod][y] = d[mod][x] + 1;
              	used[nmod][y]=1;
            }
        }
    }

    if (!used[0][t])
        std::cout << -1 << std::endl;
    else
    {
        std::cout << d[0][t] / 3 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 7168
import CoreFoundation

func is_prime( n:Int) -> Bool {
  var r : Int
  if ( n == 1 || n == 2 || n == 3 ) { return true }
  if ( n < 2 || n%2 == 0 ) { return false }
  if ( n < 9 ) { return true }
  if ( n%3 == 0 ) { return false }

  r = Int( sqrt( Double(n) ) )
  var f : Int  = 5
  while ( f <= r ) {
    //print ( "\t", f )
    if ( n%f == 0 ) { return true }
    if ( n%(f+2) == 0 ) { return false }
    f += 6
  }
  return true
}

func unittest( ) -> Void {
  print( is_prime(3) )
  print( is_prime(2) )
  print( is_prime(4) )
  print( is_prime(5) )
  print( is_prime(7) )
}

//unittest()

let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

let m = arr[0]
let d = arr[1]

var i = 0; var j = 0
var range : [Int] = []
for i in 1...m {
	range.append(i)
}

var NewRange = range.filter{ !is_prime($0) } 
//print(NewRange)

var o = 0
i = 0
for i in range {
  //print( i )
  if( d < 22 ) {
    continue
  }
  for j in 22...d {
    var d_ten = j / 10
    var d_one = j % 10
    if( d_one < 2 || d_ten < 2 ) {
      continue
    }
    if( ( d_ten * d_one ) == i ) {
      o += 1
      //print( i, d_ten, d_one )
    }
  }
}

print( o )

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

ll N, X, A[2000];

int main(void) {
  cin >> N >> X;
  REP(i, 0, N) cin >> A[i];

  vector< vector<ll> > cost(N, vector<ll>(N));
  REP(i, 0, N) {
    cost[i][0] = A[i];
    REP(j, 1, N) {
      ll cur = (i - j + N) % N;
      cost[i][j] = min(cost[i][j - 1], A[cur]);
    }
  }

  ll ans = (1LL << 60);
  REP(i, 0, N) {
    ll sum = 0;
    REP(j, 0, N) sum += cost[j][i];
    sum += X * i;
    ans = min(ans, sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 31616
/*
	Created by Rahul Goel.
*/

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1000000000;

#define pii pair < int, int >
#define vi vector < int >
#define vvi vector < vector < int > >
#define vpii vector < pair < int, int > >
#define vvpii vector < vector < pair < int, int > > >
#define pb push_back
#define f first
#define s second
#define mp make_pair

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


Measured memory_bytes: 256
n,m=map(int,input().split())
ans = 0
wa = 0
wa_list = [0] * n
ac_list = [0] * n
for i in range(m):
  p,s=map(str,input().split())
  p=int(p)-1
  if ac_list[p] == 0:
    if s == "AC":
      ac_list[p] += 1
    else:
      wa_list[p] += 1
a=0
for i in range(n):
  if ac_list[i]==0:
    wa_list[i]=0
print(sum(ac_list),sum(wa_list))
  


Measured memory_bytes: 4596
#!/usr/bin/env python3
def main():
    N = int(input())
    c = 100000
    for _ in range(N):
        c *= 1.05
        t = c % 1000
        if t > 0:
            c += 1000 - t
    print(int(c))

if __name__ == "__main__":
    main()

Measured memory_bytes: 7532
#include <stdio.h>
#include <string.h>
int main(){
	char a[100], b[100], c[100];
	scanf("%s %s %s", &a, &b, &c);
	
	int akhirA=strlen(a)-1;
	int akhirB=strlen(b)-1;
	if(a[akhirA]==b[0]&&b[akhirB]==c[0]){
		puts("YES");
	}
	else{
		puts("NO");
	}
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int ans = 0, n = s.size();
  for(int i=0; i<n; ++i){
    if(i%2 == 0){
      ans += (s[i] == 'g' ? 0:-1);
    }else{
      ans += (s[i] == 'g' ? 1:0);
    }
  }
  cout << ans << endl;
}

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

typedef struct node{
  node *p,*l,*r;
  int key;
} Node;

typedef Node* Nodepointer;

Nodepointer T;

void insert(int z){
  Nodepointer t=(Node*)malloc(sizeof(Node));
  t->l=NULL;
  t->r=NULL;
  t->key=z;
  if(!f){
    T->key=z;
    f=1;
    return;
  }
  Nodepointer y=NULL,x=T;
  while(x!=NULL){
    y=x;
    if(t->key<x->key)x=x->l;
    else x=x->r;
  }
  t->p=y;
  if(y==NULL)T=t;
  else if(t->key<y->key)y->l=t;
  else y->r=t;
}

bool find(int key){
  Nodepointer x=T;
  while(x!=NULL){
    if(x->key==key)return true;
    if(key<x->key)x=x->l;
    else x=x->r;
  }
  return false;
}

void print(Nodepointer x,int y){
  if(y)cout<<' '<<x->key;
  if(x->l!=NULL)print(x->l,y);
  if(!y)cout<<' '<<x->key;
  if(x->r!=NULL)print(x->r,y);
}

int main(){
  string s;
  int n,z;
  cin>>n;
  T=(Node*)malloc(sizeof(Node));
  T->p=NULL;
  T->l=NULL;
  T->r=NULL;
  while(n--){
    cin>>s;
    if(s=="insert")cin>>z,insert(z);
    else if(f&&s=="find"){
      cin>>z;
      if(find(z))cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }
    else if(f){
      print(T,0);
      cout<<endl;
      print(T,1);
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 19960
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    string S; cin>>S;
    cout<< ( S[0]==S[1] and S[1]==S[2] ? "No" : "Yes" )<<"\n";


}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

using namespace std;

//#define FILE_IO

typedef long long LL;

int N;
LL A, B;

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    scanf("%lld%lld", &A, &B);
    for(int i = 2; i <= N; i++)
    {
        LL a, b;
        scanf("%lld%lld", &a, &b);
        LL m = max( (A + a - 1) / a, (B + b - 1) / b );
        A = m * a;
        B = m * b;
    }

    printf("%lld\n", A + B);

    return 0;
}


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

string S;
int Q;
int T,F;
char C;

deque<char> que;
bool inv = false;


int main(){
	cin >> S;
	cin >> Q;
	
	for(int i = 0; i < S.size(); i++){
		que.push_back(S[i]);
	}

	for(int i = 0; i < Q; i++){
		cin >> T;
		if(T == 2){
			cin >> F >> C;
			if((!inv && F == 1) || (inv && F == 2)){
				que.push_front(C);
			}
			else{
				que.push_back(C);
			}
		}
		else if(T == 1){
			inv = !inv;
		}
	}
	for(int i = 0; i < que.size(); i++){
		char x;
		if(inv){
			x = que[que.size()-1-i];
		}
		else{
			x = que[i];
		}
		printf("%c",x);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
using namespace std;
int n;
long double now = 1;
long double a[100010];
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] == 0) {
			cout << 0;
			return 0;
		}
	}
	for (int i = 1; i <= n; i++) {
		now *= a[i];
		if (now < 0 || now > 1000000000000000000) {
			puts("-1");
			return 0;
		}
	}
	cout << (long long)now;
	return 0;
}

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

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

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

    std::vector<int> index(a.size());
    std::iota(index.begin(), index.end(), 0);

    std::sort(
        index.begin(),
        index.end(),
        [&](int x, int y) { return a[x] < a[y]; });

    for (int i = 0; i < n; i++)
    {
        cout << index[i] + 1;
        if (i < n - 1)
            cout << " ";
        else
            cout << endl;
    }
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)



ll gcd(ll a , ll b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int main(){
  ll n,x;
  cin >> n >> x;
  ll dif;
  ll res,ans;
  rep(i,n){
    cin >> res;
    dif=abs(res-x);
    if(i==0)ans=dif;
    ans=gcd(ans,dif);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol gcd(lol x,lol y){//最大公約数
    if(y>x) swap(x,y);
    lol r=x%y;
    while(r!=0){
	x=y;
	y=r;
	r=x%y;
    }
    return y;
}
lol a,b;
lol i[3000];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol c=1,d=1,e=0,f=0,g=0,h=0;
  cin >>a>>b;
  a=gcd(a,b);
  b=sqrt(a);
  for(int n=2;n<=b;n++){
      if(a%n==0) e++;
      while(1){
	  if(a%n!=0) break;
	  a=a/n;
      }
  }
  if(a!=1) e++;
  cout <<e+1<<'\n';
  return (0);
}


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

const ll MOD=1000000007;

ll powmod(ll x, ll y){
	ll res=1;
	for(int i=0;i<y;i++){
		res=res*x%MOD;
	}
	return res;
}

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

	long long ans = powmod(10,N) - 2*powmod(9,N) + powmod(8,N);
	ans%=MOD;
	ans=(ans+MOD)%MOD;
	cout<<ans<<endl;
}


Measured memory_bytes: 3632
A[5][4][11],N,i,j,k,t;
main(void){
    for(scanf("%d",&N);N--;){
        scanf("%d%d%d%d",&i,&j,&k,&t);
        A[i][j][k]+=t;
    }
    for(i=1;i<5;i++){
        for(j=1;j<4;j++){
            for(k=1;k<11;k++){
                printf(" %d%s",A[i][j][k],k==10?"\n":"");
            }
        }
        if(i<4)
        puts("####################");
    }
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vll red(a);
  vll green(b);
  vll white(c);
  for(auto& i : red) cin >> i;
  for(auto& i : green) cin >> i;
  for(auto& i : white) cin >> i;
  
  sort(all(red));
  sort(all(green));
  sort(all(white));

  ll chr = 0, chg = 0;
  rep(i, 0, c){
    if(chr < x){
      if(chg < y){
        if(white.at(c - 1 - i) > min(red.at(a - x + chr), green.at(b - y + chg))){
          if(red.at(a - x + chr) >= green.at(b - y + chg)){
            green.at(b - y + chg) = white.at(c - 1 -i);
            chg++;
          }
          else{
            red.at(a - x + chr) = white.at(c - 1 - i);
            chr++;
          }
        }
      }
      else if(white.at(c - 1 - i) > red.at(a - x + chr)){
        red.at(a - x + chr) = white.at(c - 1 - i);
        chr++;
      }
    }
    else if(white.at(c - 1 - i) > green.at(b - y + chg)){
        green.at(b - y + chg) = white.at(c - 1 - i);
        chr++;
    }
  }

  ll ans =0;
  rep(i, 0, x) ans += red.at(a - i - 1);
  rep(i, 0, y) ans += green.at(b - i - 1);
  cout << ans << endl;
}

Measured memory_bytes: 2688
n=int(input())
l=[]
for iii in range(n):
  a,b=input().split()
  b=int(b)
  l.append([a,b,iii])
l.sort(key=lambda x:x[1],reverse=True)
l.sort(key=lambda x:x[0])
for iii in l:
  print(int(iii[2])+1)

Measured memory_bytes: 3060
import fractions
# 最小公倍数
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)    
a, b, c, d = map(int, input().split())
e = lcm(c, d)
#print("e: {}".format(e))
#print("c: {} - {}".format(b // c, (a - 1) // c))
#print("d: {} - {}".format(b // d, (a - 1) // d))
#print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
#print("count_c: {}".format(count_c))
#print("count_d: {}".format(count_d))
#print("count_e: {}".format(count_e))
print(b - a + 1 - (count_c + count_d - count_e))

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> vec(M*2);
  
  for (int i=0; i<M*2; i++) {
    cin >> vec.at(i);
  }
  
  for (int i=1; i<=N; i++) {
    int count = 0;
    for (int j=0; j<M*2; j++) {
      if (vec.at(j) == i) {
        count++;
      }
    }
    cout << count << endl;
  }
    
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = 998244353; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    vector<int> Ri, Gi, Bi;
    rep(i, 3 * N) {
        if (S[i] == 'R') Ri.push_back(i);
        else if (S[i] == 'G') Gi.push_back(i);
        else Bi.push_back(i);
    }

    vector<int> a(N), b(N), c(N);
    rep(i, N) {
        array<int, 3> t = { Ri[i], Gi[i], Bi[i] };
        sort(all(t));
        a[i] = t[0], b[i] = t[1], c[i] = t[2];
    }

    ll ans = 1;
    for (int i = 0, j = 0; i < N; ++i) {
        while (j < N && a[j] < b[i]) j++;
        ans = ans * (j - i) % MOD;
    }
    for (int i = N - 1, j = N - 1; i >= 0; --i) {
        while (j >= 0 && c[j] > b[i]) j--;
        ans = ans * (i - j) % MOD;
    }
    rep(i, 1, N + 1) ans = ans * i % MOD;
    write(ans);
}

Measured memory_bytes: 3088
s = input()

ans = 0
for i in range(len(s)-1, 1, -1):
    s_l = s[:i]
    if len(s_l)%2==1:
        continue
    else:
        if s_l[:len(s_l)//2] == s_l[len(s_l)//2:]:
            ans = max(ans, len(s_l))
if len(s)<= 3:
    print(1)
else:
    print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
char back(string s) {
	return s[s.size()-1];
}
int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (back(a) == b[0] && back(b) == c[0]) cout << "YES";
	else cout << "NO";
}

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

int main() {
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];

  int ans = X;
  for (int i : v)
    for (int j = 1; j <= D; j += i) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    x = input()

    c1 = x.count('1')
    if c1 > 1:
        cc1 = int('0b' + x, 0) % (c1 - 1)
    cc2 = int('0b' + x, 0) % (c1 + 1)

    def f(n):
        ans = 0
        while n > 0:
            ans += 1
            n = n % bin(n).count('1')
        return ans

    if c1 == 1:
        for i in range(n):
            if x[i] == '1':
                print(0)
            else:
                print(f((pow(2, n-i-1, c1+1) + cc2) % (c1 + 1)) + 1)
        exit()

    for i in range(n):
        if x[i] == '1':
            print(f((-pow(2, n-i-1, c1-1) + cc1) % (c1 - 1)) + 1)
        else:
            print(f((pow(2, n-i-1, c1+1) + cc2) % (c1 + 1)) + 1)

main()

Measured memory_bytes: 9472
import std,core.bitop;int l,n;void q(int[]a...){a.writefln!"%(%s %)";}void main(){l.readf!"%d";for(q(n=l.bsr+1,l.popcnt+n*2-3);l>1;n--)l%2&&q(1,n,l-1),q(n-1,n,l/=2),l&&q(n-1,n,0);}

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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		
		int input[] = new int[3];
		for(int i = 0; i < 3; i++){
			input[i] = Integer.parseInt(tmpArray[i]);
		}
		
		Arrays.sort(input);
		
		System.out.println(input[0]+ input[1]+input[2]*10);
	}

}


Measured memory_bytes: 23124