akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll INF=ll(1e18)+1;


struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
};


int deg[100005];
vector<int> to[100005];


int main() {
  ios::sync_with_stdio(false);
	cin.tie(0);
  int n,m,k;
  cin>>n>>m>>k;
  UnionFind uf(n);
  rep(i,m){
    int a1,b1;
    cin>>a1>>b1;
    a1--;b1--;
    deg[a1]++;
    deg[b1]++;
    uf.unite(a1,b1);
  }
  rep(i,k){
    int c1,d1;

    cin>>c1>>d1;
    c1--;d1--;
    to[c1].push_back(d1);
    to[d1].push_back(c1);
  }

  rep(i,n){
    int ans=uf.size(i);
    for (int j:to[i]){
      if (uf.same(i,j)) ans--;
    //  cout<<j<<'j';
    }
  //  cout<<uf.size(i)<<' '<<deg[i]<<endl;
    ans-=deg[i];
    ans--;
    cout<<ans<<' ';
  }

}


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

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

	if (a > b)
	{
		cout << 0 << '\n';
		return 0;
	}

	if (n == 2)
	{
		cout << 1 << '\n';
		return 0;
	}

	if (n < 2)
	{
		if (a == b)
			cout << 1 << '\n';
		else
			cout << 0 << '\n';
		return 0;
	}


	cout << (b - a) * (n - 2) + 1 << '\n';

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

/*
int main() {
	string s;
	int ans = 0;
	while (cin >> s) {
		rep(i, s.size()) {
			int n = 0;
			while ('0' <= s[i + n] && s[i + n] <= '9') n++;
			ans += atoi(s.substr(i, n).c_str());
			i += n;
		}
	}
	cout << ans << endl;
} */


int main() {
	string s;
	int ans = 0;
	while (cin >> s) {
		s += ' ';
		string num;
		rep(i, s.size()) {
			if ('0' <= s[i] && s[i] <= '9') num += s[i];
			else {
				ans += atoi(num.c_str());
				num.clear();
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a,b,c,d;
signed main()
{
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	cout<<max(a*c,max(a*d,max(b*c,b*d)));
	return 0;
}

Measured memory_bytes: 3760
#include <stdio.h>
int main(void){
  char s[1000];
  char array[1000];
  int w;
  scanf("%s", &s);
  scanf("%d", &w);
  int len = 0;
  while(s[len] != '\0'){
    len++;
  }
  int i, j=0;
  for(i=0; i<len; i++){
    if(i%w == 0){
      array[j] = s[i];
      j++;
    }
    array[j] = '\0';
  }
  printf("%s\n", array);
  return 0;
}


Measured memory_bytes: 128
n, m = map(int, input().split())
s = []
for i in range(m):
    line = list(map(int, input().split()))
    s.append(line[1:])
p = list(map(int, input().split()))
ans = 0
for pat in range(2**n):
    light_flag = True
    for i in range(m):
        tot = 0
        for sw in s[i]:
            if pat & (2 ** (sw - 1)):
                tot += 1
        if tot % 2 != p[i]:
            light_flag = False
    if light_flag:
        ans += 1
print(ans)

Measured memory_bytes: 40816
#include <cstdio>

int main(void){
		char str[3];
		scanf("%s", str);
		int price = 700;
		for(int i = 0; i < 3; i++){
				if(str[i] == 'o')price+=100;
		}
		printf("%d\n", price);
		return 0;
}



Measured memory_bytes: 128
s = input()
for i in range(2**(len(s)-1)):
    total = int(s[0])
    ope = s[0]
    for j in range(len(s)-1):
        if ((i >> j) & 1):
            total += int(s[1+j])
            ope = ope + "+" + s[1+j]
        else:
            total -= int(s[1+j])
            ope = ope + "-" + s[1+j]
    if total == 7:
        print(ope+"=7")
        break

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "MyDisjointset.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000000;
struct edge {
	int to, cost;
	bool operator < (const edge& e1) const {
		return e1.cost < cost;
	}
};
int main() {
	priority_queue <P, vector<P>, greater<P> > q;
	vector <edge> g[100001];
	int v, e, r; cin >> v >> e >> r;
	for (int i = 0; i < e; i++) {
		int s, t, co; cin >> s >> t >> co;
		edge e1; e1.to = t; e1.cost = co;
		g[s].push_back(e1);
	}
	q.push(P(0, r));
	int *d = new int[v];
	fill(d, d + v, INF);
	d[r] = 0;
	while (!q.empty()) {
		P p = q.top(); q.pop();
		int f = p.first, s = p.second;
		if (d[s] <f) continue;
		for (int i = 0; i < g[s].size(); i++) {
			if (d[g[s][i].to] > d[s] + g[s][i].cost) {
				d[g[s][i].to] = d[s] + g[s][i].cost;
				q.push(P(d[g[s][i].to], g[s][i].to));
			}
		}
	}
	for (int i = 0; i < v; i++) {
		if (d[i] == INF) cout << "INF" << endl;
		else cout << d[i] << endl;
	}
	delete[] d;
	return 0;
}

Measured memory_bytes: 13032
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define     mod             1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

vector<bool> v(1e6+1, true);

vector<int> a;

void sieve(int sz, int maxm)
{ 
  for(int i=0; i<sz-1; i++)
  {
    for(int j=a[i]+a[i]; j<=maxm; j+=a[i])
    {
      v[j]=false;
    }
  }
}


int32_t main()
 
{  
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS;
 
      int i, n;
      cin>>n;

      a.assign(n,0);
      int maxm=0;
      map<int, int> m;
      for(int i=0; i<n; i++)
      {
        cin>>a[i];
        m[a[i]]++;
        maxm=max(maxm, a[i]);
      }
      sort(a.begin(), a.end());

      sieve(n, maxm);

      int ans=0;
    

     

      for(int i=0; i<n; i++)
      {
     
        if(m[a[i]]==1 && v[a[i]])
        {
          ans++;
         
        }
      
      }
      cout<<ans<<endl;
   
    
}

Measured memory_bytes: 13336
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
int main(){
   int n;
   string s;
   cin >> n >> s;
   if(n%2==1){cout << "No" << endl;}
   else{
       for(int i = 0; i<n/2; i++){
           if(s.at(i)!=s.at(n/2+i)){
               cout << "No" <<endl;
               break;
           }
           else if(i==n/2-1){
               cout <<"Yes"<< endl;
           }
       }
   }
   
}

Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>
#define LEN 1000005
#define MAX 1000


typedef struct pp{
  char name[100];
  int t;
}P;


P Q[LEN+1];
int head, tail, n;


void initialize();
//キューを空に設定
int Empty();
//キューが空かを判断
int isFull();
//キューが満杯か判断
void enqueue(P);
//tailが指す場所にxを追加, MAX以上になってしまう場合はtailを0として循環
P dequeue();
//headが指すキューの先頭の要素を変数xに一時的に記録し、headを1増やしてからxを返す


int main(){

  int elaps=0,c;
  int i,q;
  P u;

  scanf("%d %d", &n, &q);
  initialize();

  for ( i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  for ( i = 1; tail != head; i++){



    if( Q[i].t > q){  
      Q[i].t = Q[i].t - q;
      elaps += q;
      Q[i] = dequeue();
      enqueue(Q[i]);
    }

    else{
     elaps += Q[i].t;
     printf("%s %d\n",Q[i].name,elaps);
     //u = dequeue();
     head++;
   }

 }
 return 0;
}


void initialize(){
  head = 0;
  tail = n;
}


void enqueue(P x){
  tail++;
  Q[tail] = x;
  //if(tail + 1 == MAX) tail = 0;
  //else

}


P dequeue(){

  P x;
  head++;
  x = Q[head];
  /*if(head + 1 == MAX) head = 0;
  else head++;*/
  return x;
}


Measured memory_bytes: 20912
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,a,b;
int main(){
	cin>>n>>a>>b;
	if ((b-a)&1) puts("Borys");
	else puts("Alice");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i, j, n, w;
  scanf("%d %d", &n, &w);

  long cell[2][w+1];
  int weight[n];
  long value[n];

  for (i=0; i<n; i++)
    scanf("%d %ld", &weight[i], &value[i]);

  for (i=0; i<=w; i++)
    cell[0][i] = weight[0]<=i ? value[0] : 0;
  
  for (i=1; i<n; i++) {
    for (j=0; j<=w; j++) {
      if (j>weight[i] && cell[(i+1)%2][j-weight[i]]+value[i]>cell[(i+1)%2][j])
	cell[i%2][j] = cell[(i+1)%2][j-weight[i]]+value[i];
      else
	cell[i%2][j] = cell[(i+1)%2][j];
    }
  }
  printf("%ld\n", cell[(n-1)%2][w]);

  return 0;
}


Measured memory_bytes: 1664
n,m=gets.split(' ').map(&:to_i)
h=gets.split(' ').map(&:to_i)
#tajigen = Array.new(4) { Array.new(2,0) }
#maze = h.times.map { gets.chomp }
ans = Array.new(n+1,1)
ans[0] = 0
m.times do
  a,b=gets.split(' ').map(&:to_i)
  if h[a-1]>h[b-1]
    ans[b]=0
  elsif h[a-1]==h[b-1]
    ans[a]=0
    ans[b]=0
  else
    ans[a]=0
  end
end
puts ans.count(1)


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

using namespace std;

typedef long long ll;

const ll INF = 1e18;

struct FloydWarshall {
    int n;
    vector<vector<ll>> g;
    vector<vector<ll>> dists;
    
    FloydWarshall(int n):n(n) {
        g.assign(n + 1, vector<ll>(n + 1, INF));
    }
    
    void addEdge(int from, int to, ll w) {
        g[from][to] = w;
    }
    
    bool solve() {
        dists.assign(n + 1, vector<ll>(n + 1, INF));
        for (int i = 0; i < n + 1; i++) {
            for (int j = 0; j < n + 1; j++) {
                dists[i][j] = g[i][j];
            }
            dists[i][i] = 0;
        }
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (dists[i][k] < INF && dists[k][j] < INF && 
                            dists[i][k] + dists[k][j] < dists[i][j]) {
                        dists[i][j] = dists[i][k] + dists[k][j];
                        if (i == j && dists[i][j] < 0) {
                            return false;
                        }
                    }
                }
            }
        }
        return true;
    } 
};

int main() {
    int v, e, s;
    cin >> v >> e;
    FloydWarshall d(v);
    for (int i = 0; i < e; i++) {
        int from, to, w;
        cin >> from >> to >> w;
        d.addEdge(from, to, w);
    }
    if (!d.solve()) {
        cout << "NEGATIVE CYCLE" << endl;
    }
    
    else {
        for (int i = 0; i < v; i++) {
            for (int j = 0; j < v; j++) {
                if (j > 0) {
                    cout << " ";
                }
                if (d.dists[i][j] == INF) {
                    cout << "INF";
                }
                else {
                    cout << d.dists[i][j];
                }
            }
            cout << endl;
        }
    }
    return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  int ans[a][b],ansb[a][b];
  int vec[a][b];
  string s;
  for(int i=0;i<a;i++){
    cin>>s;
    for(int j=0;j<b;j++){
      ans[i][j]=0;
      ansb[i][j]=0;
      if(s[j]=='.'){
        vec[i][j]=0;
      }
      else{
        vec[i][j]=1;
      }
    }
  }
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      if(i==0){
        ans[i][j]=1;
      }
      if(j%2==0&&i!=a-1){
        ans[i][j]=1;
      }
      if(i==a-1){
        ansb[i][j]=1;
      }
      if(j%2==1&&i!=0){
        ansb[i][j]=1;
      }
      if(vec[i][j]==1){
        ans[i][j]=1;
        ansb[i][j]=1;
      }
    }
  }
  
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      if(ans[i][j]==0){
        cout<<".";
      }
      else{
        cout<<"#";
      }
    }
    cout<<endl;
  }
  cout<<endl;
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      if(ansb[i][j]==0){
        cout<<".";
      }
      else{
        cout<<"#";
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3712
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
string S;
int K;
int N;
set<string> values;
int main()
{
    cin >> S;
    cin >> K;
    N = S.size();
    for (int i = 0; i < N; i++)
    {
        string tmp = "";
        for (int j = 0; j < 10; j++)
        {
            if (i + j < N)
            {
                tmp += S[i + j];
            }
            values.emplace(tmp);
        }
    }
    int cnt = 0;
    for (const auto &val : values)
    {
        cnt++;
        if (cnt >= K)
        {
            cout << val << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <cmath>

double distance(int x[], int y[], int n, int p) {
    double d = 0.0;
    if (p > 0) {
        for (int i = 0; i < n; i++) {
            d += std::pow(std::abs(x[i] - y[i]), p);
        }
        d = std::pow(d, 1.0 / p);
    } else {
        for (int i = 0; i < n; i++) {
            d = std::max(d, std::abs(x[i] - y[i]));
        }
    }
    return d;
}

int main(int argc, const char *argv[]) {
    int n;
    std::cin >> n;
    int x[n], y[n];
    for (int i = 0; i < n; i++) {
        std::cin >> x[i];
    }
    for (int i = 0; i < n; i++) {
        std::cin >> y[i];
    }
    std::cout << std::fixed << distance(x, y, n, 1) << std::endl;
    std::cout << std::fixed << distance(x, y, n, 2) << std::endl;
    std::cout << std::fixed << distance(x, y, n, 3) << std::endl;
    std::cout << std::fixed << distance(x, y, n, 0) << std::endl;
    return 0;
}

Measured memory_bytes: 3464
import math
NM = 10000
p = [2] * NM
c = 1
a = 3
while c < NM:
    m = int(math.sqrt(a))
    r = True
    for i in p:
        if i > m:
            break
        if a % i == 0:
            r = False
            break
    if r:
        p[c] = a
        c += 1
    a += 2

while True:
    n = int(raw_input())
    if n == 0:
        break
    print sum(p[:n])
        

Measured memory_bytes: 4756
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  if($n < 10){
    echo $n;
    exit;
  }

  if($n < 100){
    echo 9;
    exit;
  }

  if($n < 1000){
    echo $n - 90;
    exit;
  }

  if($n < 10000){
    echo 909;
    exit;
  }

  if($n < 100000){
    echo $n - 9090;
    exit;
  }

  echo 90909;


Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


int main(){FIN
    
    string s;cin>>s;
    ll c0=0, c1=0;
    REP(i,s.size()){
        if(s[i]=='0') c0++;
        else c1++;
    }
    ll m = min(c1,c0);
    cout<<m*2<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N, W;
  cin >> N >> W;
  vector<vector<int> > dp(W + 1, vector<int>(N + 1, -1));
  dp[0][0] = 0;
  rep(i, N)
  {
    int v, w;
    cin >> v >> w;
    rep(j, W + 1)
    {
      if(dp[j][i] != -1)
      {
        dp[j][i + 1] = max(dp[j][i + 1], dp[j][i]);
        int nw = j + w;
        int nv = dp[j][i] + v;
        if(nw <= W)
        {
          dp[nw][i + 1] = max(dp[j][i + 1], nv);
        }
      }
    }
  }
  int ans = 0;
  rep(i, W + 1)
  {
    ans = max(ans, dp[i][N]);
  }
  cout << ans << endl;
  return 0;
}


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

const int N = 210;

int a[N];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n << 1; ++ i){
		scanf("%d", &a[i]);
	}
	std::sort(a, a + (n << 1));
	int ans = 0;
	for (int i = 0; i < n; ++ i){
		ans += std::min(a[i << 1], a[i << 1 | 1]);
	}
	return printf("%d\n", ans), 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    
    int A,B,i;
    int sum = 0;
    
    scanf("%d %d", &A, &B);
    
    for(i = 0; i < 2; i++){
        if(A >= B){
            sum += A;
            A -= 1;
        }
        else{
            sum += B;
            B -= 1;
        }
    }
    
    printf("%d\n",sum);
    

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)2e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)2e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (2 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 2, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 1) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 2;
    LL sum = a;
    while(b){
        if(b&2)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

PII operator+(const PII &a, const PII &b){
    return PII(a.first + b.first, a.second + b.second);
}

vector<vector<int> > xc(100001), yc(100001);

PII func(PII p){
    PII res(0, 0);
    if(!xc[p.first].empty()){
        vector<int> line = xc[p.first];
        xc[p.first].clear();
        ++res.first;
        for(auto &i:line){
            res = res + func(PII(p.first, i));
        }
    }
    if(!yc[p.second].empty()){
        vector<int> line = yc[p.second];
        yc[p.second].clear();
        ++res.second;
        for(auto &i:line){
            res = res + func(PII(i, p.second));
        }
    }
    return res;
}

signed  main(){
    int N;
    cin >> N;
    vector<int> line(N);
    REP(i, N)cin>>line[i];
    sort(ALL(line));
    cout << line[N/2] - line[N/2-1] << endl;
    return 0;
}



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

typedef long long LL;
typedef pair<int, int> II;

int main() {
	string S; cin >> S;
	if (S.size() > 4) S = S.substr(0, 4);

	cout << ((S == "YAKI") ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n, a = 0, ans = 0;
    cin >> n;
    for(int i = 1; i < n + 1; ++i){
       cin >> a;
       if((i * a) % 2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

long long N;
vector<long long> a;

int main()
{
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }

    int ans = 1;

    int f = 0;
    int prev = a[0];
    for (int i = 1; i < N; i++)
    {
        if(f == 0)
        {
            if(prev < a[i])
            {
                f = 1;
            }
            else if(prev > a[i])
            {
                f = -1;
            }
        }
        else
        {
            if ((f == 1 && prev > a[i]) || (f == -1 && prev < a[i]))
            {
                f = 0;
                ans++;
            }
        }
        prev = a[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
N, K = map(int, input().split())
x = list(map(int, input().split()))
ret = 10 ** 9
for i in range(N-K+1):
    init = abs(x[i])
    dist = abs(x[i]-x[i+K-1])
    l = init + dist
    init = abs(x[i+K-1])
    r = init + dist
    ret = min(ret, l, r)
print(ret)

Measured memory_bytes: 14252
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1000;

ll dps(ll h) {
  if (h == 1)
    return 1;
  else
    return 1 + 2 * dps(h / 2);
}

void Main() {
  ll h;
  cin >> h;
  cout << dps(h) << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

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

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  ll mi = kMod * kMod;
  REP(i, 0, 100001) {
    ll su = i * 2 * C + A * max(ll(0), X - i) + B * max(ll(0), Y - i);
    if (mi > su) {
      mi = su;
    }
  }
  cout << mi << endl;

  return 0;
}


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

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var S = ReadLine().Split();
        if (S.Contains("Y"))
        {
            WriteLine("Four");
        }
        else
        {
            WriteLine("Three");
        }
    }
}


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

int aSum[100005];

int main() {
  int n, q;
  cin >> n;
  ll s = 0;
  rep(i,n) {
    ll a;
    cin >> a;
    aSum[a]++;
    s += a;
  }

  cin >> q;
  vector<ll> ans(q+1, s);
  rep(i,q) {
    ll b, c;
    cin >> b >> c;
    ans[i+1] = ans[i] + aSum[b]*(c - b);
    aSum[c] += aSum[b];
    aSum[b] = 0;
  }

  rep(i,q) cout << ans[i+1] << endl;
  return 0;
}

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


int main() {
    int N,T,A;
    cin >> N >> T >> A;
    vector<int> H(N);
    rep(i,N) {
        cin >> H[i];
    }
    double min = 100000;
    int ans;
    rep(j,N) {
        if (abs(A - (T - 0.006*H[j])) < min) {
            min = abs(A - (T - 0.006*H[j]));
            ans = j + 1;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3632
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Data.Maybe (fromMaybe)
import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Maybe
import Control.Monad.Trans.Class (lift)
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

-- 有向グラフに閉路があるか判定し、閉路があれば Nothing を返す。
-- 閉路がなければ最長路の長さを返す。
solve :: V.Vector [Int] -> Maybe Int
solve !edges = runST $ runMaybeT $ do
  let !n = V.length edges  -- 頂点の個数
  !vec <- UM.replicate n (-2 :: Int) -- -2: new, -1: DFSの最中, 正: チェック済み
  let dfs !x = do
        s <- UM.read vec x
        case s of
          -2 -> do
            -- x を通る閉路があるかチェックする
            UM.write vec x (-1)
            !v <- foldM (\ !a y -> max a <$> dfs y) 0 (edges V.! x)
            lift $ do let !v' = v + 1
                      UM.write vec x v'
                      return v'
          -1 -> mzero  -- コールスタックのどこかで dfs x が呼ばれている。閉路
          v -> return v
  mapM_ dfs [0..n-1]
  lift (U.maximum <$> U.unsafeFreeze vec)

main = do
  n <- readLn
  xs <- V.replicateM n $ do
    U.map (subtract 1) . U.unfoldrN (n-1) (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let m = n * (n - 1) `quot` 2  -- グラフの頂点数
  let -- (i,j) (0 <= i < j < n) を 0 以上 m 未満の整数値にコードする
      makePair :: Int -> Int -> Int
      makePair !i !j | i' < j' = n * i' - (i' + 1) * i' `quot` 2 + j' - i' - 1
                     | otherwise = undefined
        where !i' = min i j; !j' = max i j
  -- 「試合 (i,j) よりも試合 (i',j') の方を後に行う場合に辺 makePair i j → makePair i' j' が存在する」ようなグラフを作る
  let edges :: V.Vector [Int]
      edges = V.create $ do
        !e <- VM.replicate m []
        V.forM_ (V.indexed xs) $ \(!i,ys) -> do
          U.forM_ (U.zip ys (U.tail ys)) $ \(!a,!b) -> do
            -- (i,a) -> (i,b)
            let !b' = makePair i b
            -- VM.modify e (b' :) (makePair i a)
            t <- VM.read e (makePair i a)
            VM.write e (makePair i a) $! b' : t
        return e
  print $ fromMaybe (-1) $ solve edges


Measured memory_bytes: 103036
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define pi acos(-1)
using ll = long long;
using namespace std;
using namespace __gnu_pbds;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


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



void solve(){
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	ll ans = 0,remainder = 0,power_ten = 1;;
	map<ll,ll> mp;
	mp[0]++;
	for(int i=0;i<s.size();i++){
		remainder = ( remainder + power_ten*(s[i] - '0'))%2019;
		mp[remainder]++;
		power_ten = power_ten *10%2019;
	}
	
	for(int i=0;i<2019;i++)
		ans += (mp[i]*(mp[i] - 1))/2;
	
	cout<<ans;
}	


 
int main()
{
    
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //int n; cin>>n; for (int i = 0; i < n; ++i)
    solve();
    return 0;
}

Measured memory_bytes: 3796
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007


int main() {
  ll N;
  cin >> N;
  string s;
  cin >> s;

  ll L = 1, R = -1;
  vector<ll> vec(2*N , 0);

  if(s.at(0) == 'W' || s.at(2*N -1) == 'W'){
    cout << 0 << endl;
    return 0;
  }

  vec.at(0) = L;

  rep(i, 2*N -1){
    if(s.at(i) == s.at(i+1)) 
      vec.at(i+1) = (-1) * vec.at(i);
    else 
      vec.at(i+1) = vec.at(i);
  }

  if(vec.at(2*N -1) != R){
    cout << 0 << endl;
    return 0;
  }

  vector<ll> right;

  rep(i,2*N){
    if(vec.at(i) == R) right.push_back(i);
  }

  if(right.size() != N){
    cout << 0 << endl;
    return 0;
  }

  vector<ll> NUM(N,0);
  rep(i,N){
    NUM.at(i) = right.at(i) - 2*i; 
  }

  ll ans = 1;

  rep(i,N){
    ll a = ((i+1) * NUM.at(i)) % MOD1;
    ans = (ans * a) % MOD1;
  }

  cout << ans << endl;


}

Measured memory_bytes: 3704
#include<stdio.h>
#include<math.h>
int main(void)
{
	double s,d,f,g,h,j,i,k,a,b,C,za;
	scanf("%lf %lf %lf",&a,&b,&C);
	//printf("%lf %lf %lf",a,b,C);
	k=0.5;
	za=3.1415926535;
	C=za/180*C;
	g=k*a*b*sin(C);
	f=a+b+(sqrt((a*a+b*b)-(2*a*b*cos(C))));
	//printf("%lf %lf\n",sqrt(a*a+b*b)-2*a*b*cos(C),a+b+(sqrt((a*a+b*b)-(2*a*b*cos(C)))));
	h=b*sin(C);
	printf("%lf\n%lf\n%lf\n",g,f,h);
	return 0;
}

Measured memory_bytes: 2996
#include <iostream>
#include <fstream>
#include <set>
#include <tuple>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <map>
#include <queue>
#include <stack>

int main() {
	std::string str; std::cin >> str;
	if (str == "ABC") {
		std::cout << "ARC\n";
	}
	else {
		std::cout << "ABC\n";
	}
}

Measured memory_bytes: 3592
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	key := make([]int, N)
	An := make(map[int]int)
	var ans, max int
	for i := range key {
		key[i] = nextInt()
		max = MaxOf(key[i], max)
	}
	for i := 0; i < N; i++ {
		for j := 1; j*key[i] <= max; j++ {
			if An[key[i]] >= 2 {
				break
			}
			An[j*key[i]]++
		}
	}
	for i := 0; i < N; i++ {
		if An[key[i]] == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 84656
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define scl(x) scanf("%lld",x);
map<ll,ll>vis;
vector<string>length[109];
ll len[109];
map<string,ll>cnt;
vector<ll>ans;
vector<ll>ans2;
ll colour[50009];
map<ll,ll>distinct;
vector<ll>not_used;
map<ll,string>name;
int main()
{
  ll i=0,j=1,k,l,p=1,q=1,r,s,t=-1,u=1,v=2,w,x,y=5,z=0,n,m=1,sum=0;
  name[1]="Sheldon",name[2]="Leonard",name[3]="Penny",name[4]="Rajesh",name[5]="Howard";
  string str1,str2,str3;
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  l=min(a,d);
  r=max(i,d-a);
//  l=l+min(b,r);
  r=max(i,r-b);
//  cout<<l<<'\n';
  l=l-min(r,c);
  cout<<l;
  	
}

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

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

  int ball;

  int sum = 0;

  for(int i = 0;i < N;i++){
    cin >> ball;
    sum += min(2 * ball,2 *(K-ball));
  }

  cout << sum << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t,a,b,c,d,g;
int main()
{
    cin>>t;
    while(t--)
	{
        cin>>a>>b>>c>>d;
        g=__gcd(d,b);
        if(a<b || d<b || (a-(a-c-1)/g*g)-b<0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/10
// Problem:ABC 070 PalindromicNumber a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

  string N;
  cin >> N;
  bool ok = true;
  REP(i, N.size()) {
    if (N[i] != N[N.size() - 1 - i]) ok = false;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}



Measured memory_bytes: 256
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

N = int(input())
li = [input() for i in range(N)]
li.sort()

key = set(li)
c = [0]*len(key)
ind = 0
ans = [[] for _ in range(len(key))]
for i in key:
    p = bisect_left(li,i)
    q = bisect_right(li,i)
    ans[ind] = [q-p, i]
    ind += 1

ans.sort(reverse=True)
p = ans[0][0]
q = []
for i in range(len(ans)):
    if ans[i][0] == p:
        q.append(ans[i][1])
q.sort()
[print(i,end='') for i in q]


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

student_dic = [0 for i in range(N)]
for i in range(N):
    student_dic[A[i]-1] = i+1


for i in range(N):
    if i == N-1:
        print(student_dic[i])
    else:
        print(student_dic[i], end=" ")


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

using namespace std;

const int ms_c = 31;
int d[ms_c][ms_c];
const int ms = 500 + 17;
int colors[ms][ms];

int arr[3][ms_c];
pair<int, int> cost[3][ms_c];


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

    int n, c;
    cin >> n >> c;

    vector<vector<int> > cost(3, vector<int>(c));
    for(int i = 1; i <= c; ++i)
    {
        for(int j = 1; j <= c; ++j)
            cin >> d[i][j];
    }

    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
            cin >> colors[i][j];
    }


    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
        {
            ++arr[(i + j) % 3][colors[i][j]];
        }
    }


    for(int i = 0; i < 3; ++i)
    {
        for(int j = 1; j <= c; ++j)
        {
            int value = 0;

            for(int k = 1; k <= c; ++k)
            {
                value += d[k][j] * arr[i][k];
            }

            cost[i][j - 1] = value;
        }
    }


    int answer = -12;

    for(int i = 1; i <= c; ++i)
    {
        for(int j = 1; j <= c; ++j)
        {
            if(j != i)
            {
                for(int k = 1; k <= c; ++k)
                {
                    if(k != j && k != i)
                    {
                        if(answer == -12)
                            answer = cost[0][i - 1] + cost[1][j - 1] + cost[2][k - 1];
                        else
                            answer = min(answer, cost[0][i - 1] + cost[1][j - 1] + cost[2][k - 1]);
                    }
                }
            }
        }
    }


    cout << answer << '\n';




}


   /* int n;
    cin >> n;

    vector<int> can;

    can.push_back(1);

    for(int i = 1; i <= 5; ++i)
    {
        int v = 1;

        for(int j = 1; j <= i; ++j)
            v *= 9;

        can.push_back(v);
    }


    for(int i = 1; i <= 6; ++i)
    {
        int v = 1;

        for(int j = 1; j <= i; ++j)
            v *= 6;

        can.push_back(v);
    }

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


    int value = n;
    int amount = 0;

    for(int i = 0; i < can.size(); ++i)
        cout << can[i] << ' ';

    while(value != 0)
    {
        //cout << "KEK\n";
        ++amount;
        int l = 0, r = can.size() - 1, curans = 1e9;

        while(l <= r)
        {

            int mid = (l + r) / 2;

//            cout << mid << ' ' << value << '\n';

            if(can[mid] == value)
            {
                //value = 0;
                curans = mid;
                break;
            }
            else
            {
                if(can[mid] > value)
                {
                    r = mid - 1;
                }
                else
                {
                    curans = mid;
                    l = mid + 1;
                }
            }

        }

        cout << value << ' ' << can[curans] << '\n';

        value -= can[curans];
    }


    cout << amount << '\n';*/



Measured memory_bytes: 1280
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
using node = tuple<ll, ll>;
const int inf = numeric_limits<int>::max();

int main(void) {
  int n;
  ll k;
  cin >> n >> k;
  auto to = vector<int>(n);
  auto dist = vector<int>(n, inf);
  for(int i = 0;i < n; ++i) {
    cin >> to[i];
    --to[i];
  }

  int now = 0;
  int step = 0;
  ll head;
  ll loop_len;
  auto rev = map<int, int>();
  while(1) {
    if(dist[now] != inf) {
      head = (ll)dist[now];
      loop_len = (ll)(step - dist[now]);
      break;
    }
    dist[now] = step;
    rev[step] = now;
    ++step;
    now = to[now];
  }
  if(k <= head) {
    int finish = (int)k;
    cout << rev[finish] + 1 << endl;
  } else {
    int finish = (int)(head + (k - head) % loop_len);
    cout << rev[finish] + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 13988
#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
const int _ = 100007;
int n,dis[_],A,B;
int main()
{
	register int i;
	register lint ans=0;
	scanf("%d%d%d",&n,&A,&B);
	for(i=1;i<=n;i++)scanf("%d",&dis[i]);
	for(i=1;i<n;i++)ans=(ans+min(1ll*A*(dis[i+1]-dis[i]),1ll*B));
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll MOD = 1e9 + 7;
double EPS = 1e-8;


#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;

using Tree = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q, L;
    while(cin >> Q >> L) {
        if(Q == 0 && L == 0) break;
        Tree st;

        ll cur = 0LL;

        rep(i, Q) {

            // cout << i << " cur " << cur << " st[";
            // for(auto&& j : st) cout << j << ", ";
            //     cout << "]" << endl;

            int query;
            cin >> query;
            if (query == 0) {
                st.insert(L + cur);
            } else if (query == 1) {
                ll d;
                cin >> d;
                cur += d;
                int cnt = 0;
                while (st.size() > 0 && *st.begin() <= cur) {
                    cnt++;
                    st.erase(st.begin());
                }
                if(cnt > 0 ) cout << "damage " << cnt << '\n';
            } else if (query == 2) {
                int k;
                cin >> k;
                auto it = st.find_by_order(k - 1);
                if (it == st.end()) cout << "miss" << '\n';
                else {
                    cout << "hit" << '\n';
                    st.erase(it);
                }
            } else if (query == 3) {
                ll x, r;
                cin >> x >> r;
                ll L = cur + x - r, R = cur + x + r;
                int cnt = 0;
                auto it = st.lower_bound(L);
                while (it != st.end() && *it <= R) {
                    ++cnt;
                    it = st.erase(it);
                }
                cout << "bomb " << cnt << endl;
            } else {
                int k;
                cin >> k;
                auto it = st.find_by_order(k - 1);
                if (it == st.end()) cout << "distance -1" << '\n';
                else {
                    cout << "distance " << (*it) - cur << '\n';
                }
            }
        }
        cout << "end" << '\n';
    }
    return 0;
}


Measured memory_bytes: 6316
//36
#include<iostream>

using namespace std;

int main(){
  for(int h,m,s,hh,mm,ss;cin>>h>>m>>s>>hh>>mm>>ss;){
    int hhh,mmm,sss;
    int b;
    sss=(ss-s+60)%60;
    b=ss<s;
    mmm=(mm-m+60-b)%60;
    b=mm-m-b<0;
    hhh=hh-h-b;
    cout<<hhh<<' '<<mmm<<' '<<sss<<endl;
  }
  return 0;
}

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

typedef long long i64;
int main() {
    int a, b; cin >> a >> b;
    if(b < a) swap(a, b);
    if((a <= 0 && 0 <= b)) {
        puts("Zero");
    }else if(b < 0) {
        int k = b - a;
        if(k & 1) puts("Positive");
        else puts("Negative");
    }else
      puts("Positive");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long a, b, c, d;
    long long max;
    
    cin >> a >> b >> c >> d;
    max = a * c;
    
    long long tmp = a * d;
    if(tmp > max) max = tmp;
    
    tmp = b * c;
    if(tmp > max) max = tmp;
    
    tmp = b * d;
    if(tmp > max) max = tmp;
    
    if(max < 0 && a <= 0 && b >= 0) max = 0;
    if(max < 0 && c <= 0 && d >= 0) max = 0;
    
    cout << max << endl;
}

Measured memory_bytes: 3192