akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
// template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

int main() {
    ll x;
    cin >> x;
    ll ans = x / 11 * 2;
    x %= 11;
    if (x > 6) cout << ans + 2 << endl;
    else if (x) cout << ans + 1 << endl;
    else cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    char a;cin >> a;

    cout << char(a+1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main(){
  int n;
  cin >> n;
  vector<vector<int>> tree(n);
  vector<vector<long long>> dp(n,vector<long long> (2, 1));
  for(int i=0;i<n-1;i++){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    tree[x].emplace_back(y);
    tree[y].emplace_back(x);
  }
  function<void(int, int)> dfs = [&, &dfs](int now, int root){
    for(int to:tree[now]){
      if(to != root) {
        dfs(to, now);
        dp[now][0] *= (dp[to][0]+dp[to][1]);
        dp[now][1] *= dp[to][0];
        dp[now][0] %= MOD;
        dp[now][1] %= MOD;
      }
    }
    return;
  };
  dfs(0, -1);
  cout << (dp[0][0]+dp[0][1]) % MOD <<endl;
}

Measured memory_bytes: 22340
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 200000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
struct Edge{
    int x,y;
    int dis;
    Edge(){}
    Edge(int x,int y,int dis):x(x),y(y),dis(dis){}
    bool operator <(const Edge &rhs)const{
        return dis<rhs.dis;
    }
}edge[N];
int tot;
struct Node{
    int x,y;
}node[N];
int father[N];

bool cmpX(int a,int b){
    return node[a].x<node[b].x;
}
bool cmpY(int a,int b){
    return node[a].y<node[b].y;
}
int Find(int x){
    if(father[x]!=x)
        return father[x]=Find(father[x]);
    return x;
}
int n;
int Kruskal(){
    for(int i=1;i<=n;i++)
        father[i]=i;

    int mst=0;
    sort(edge+1,edge+1+tot);
    for(int i=1;i<=tot;i++){
        int x=Find(edge[i].x);
        int y=Find(edge[i].y);
        if(x!=y){
            mst+=edge[i].dis;
            father[x]=y;
        }
    }
    return mst;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&node[i].x,&node[i].y);

    for(int i=1;i<=n;i++)
        father[i]=i;
    sort(father+1,father+1+n,cmpX);
    for(int i=1;i<n;i++){
        int x=father[i];
        int y=father[i+1];
        int dis=node[y].x-node[x].x;
        edge[++tot]=Edge(x,y,dis);
    }

    for(int i=1;i<=n;i++)
        father[i]=i;
    sort(father+1,father+1+n,cmpY);
    for(int i=1;i<n;i++){
        int x=father[i];
        int y=father[i+1];
        int dis=node[y].y-node[x].y;
        edge[++tot]=Edge(x,y,dis);
    }

    int mst=Kruskal();
    printf("%d\n",mst);

    return 0;
}


Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		int a = number.nextInt();
		int b = number.nextInt();
		if(a > b) System.out.println("a > b");
		if(a < b) System.out.println("a < b");
		if(a == b) System.out.println("a == b");
	}
}


Measured memory_bytes: 26232
#include<bits/stdc++.h>
using namespace std;
const int N=510;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,m,h,w,c[N][N],a[N][N];
void modify(int x,int y,int v) {
    for(int i=x;i<=n;i+=i&-i)
        for(int j=y;j<=m;j+=j&-j) c[i][j]+=v;
}
int query(int x,int y) {
    int ret=0;
    for(int i=x;i;i-=i&-i)
        for(int j=y;j;j-=j&-j) ret+=c[i][j];
    return ret;
}
int main() {
    n=gi(),m=gi(),h=gi(),w=gi();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) modify(i,j,1000),a[i][j]=1000;
    for(int i=h;i<=n;i++)
        for(int j=w;j<=m;j++) {
            int t=query(i,j)-query(i-h,j)-query(i,j-w)+query(i-h,j-w);
            if(t>=0) a[i][j]-=t+1,modify(i,j,-t-1);
            if(a[i][j]<-1e9) return puts("No"),0;
        }
    if(query(n,m)>0) {
        puts("Yes");
        for(int i=1;i<=n;i++,puts(""))
            for(int j=1;j<=m;j++) printf("%d ",a[i][j]);
    }
    else puts("No");
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)
using Graph = vector<vector<int>>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
    int n,m;cin>>n>>m;
    Graph g(n);
    int a[m],b[m];
    rep(i,m){
        cin>>a[i]>>b[i];
        g[a[i]-1].push_back(b[i]-1);
    }
    int s,t;cin>>s>>t;
    s--;t--;
    queue<pair<int,int>> q;
    q.push({s,0});
    int dist[n][3];
    rep(i,n) rep(j,3) dist[i][j]=-1;
    dist[s][0]=0;
    while(!q.empty()){
        int p=q.front().first,qq=q.front().second;q.pop();
        for(auto now:g[p]){
            int qqnow=(qq+1)%3;
            if(dist[now][qqnow]==-1){
                dist[now][qqnow]=dist[p][qq]+1;
                q.push({now,qqnow});
            }
        }
    }
    if(dist[t][0]==-1) cout<<-1<<"\n";
    else cout<<dist[t][0]/3<<"\n";

}

Measured memory_bytes: 7680
#include <iostream>
#include <queue>
#include <string>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  ll k;
  cin >> k;
  queue<ll> que;
  rep(i, 9) que.push(i+1);
  ll ans;
  rep(i, k){
    ll x = que.front();
    que.pop();
    if (x % 10 != 0) que.push(10 * x + (x % 10) - 1);
    que.push(10 * x + (x % 10));
    if (x % 10 != 9) que.push(10 * x + (x % 10) + 1);
    if (i == k - 1) ans = x;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n; cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            for(ll k=1;k<=n;k++){
                ans+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll cost(int i, int s, VL &a){
	if(s==0||s==4) return a[i];
	else if(s==1||s==3){
		if(a[i]%2==0&&a[i]>0) return 0LL;
		else if(a[i]>0) return 1LL;
		else return 2LL;
	}else{
		if(a[i]%2LL==0LL) return 1LL;
		else return 0LL;
	}
}

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

ll mpow(ll a, ll b){
	if(b==0){
		return 1;
	}else if(b%2==0){
		ll memo = mpow(a,b/2);
		return memo*memo%MOD;
	}else{
		return mpow(a,b-1)*a%MOD;
	}
}

signed main() {
	ll n; cin>>n;
	map<PLL, PLL> s;
	ll zeros=0LL;
	rep(i,n){
		ll a,b; cin>>a>>b;
		if(a==0&&b==0) zeros++;
		else if(a==0){
			s[MP(0,1)].first++;
		}else if(b==0){
			s[MP(0,1)].second++;
		}else{
			ll p=abs(a), q=abs(b);
			ll g=gcd(p,q); a/=g; b/=g;
			if((a>0&&b>0)||(a<0&&b<0)){
				a=abs(a); b=abs(b);
				s[MP(a,b)].first++;
			}else{
				a=abs(a); b=abs(b);
				s[MP(b,a)].second++;
			}
		}
	}

	ll ans=1LL;
	for(auto e: s){
		ll p = mpow(2,e.second.first)+mpow(2,e.second.second)-1LL%MOD;
		// cerr<<e.first.first SP e.first.second SP e.second.first SP e.second.second SP p<<endl;
		ans=(ans*p)%MOD;
	}
	cout<<(ans+zeros-1+MOD)%MOD<<endl;
	return 0;
}


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

int main()
{
   int x;
   cin >> x;
   for(int i = -118; i <=119; i++)
   {
       for(int j = -118; j <=119; j++)
       {
           if(i*i*i*i*i - j*j*j*j*j == x)
           {
               cout << i << " " << j;
               return 0;
           }
       }
   }



}



Measured memory_bytes: 3632
#include<stdio.h>
int main() {
	char X[200001];
	int i = 0, c = 0, len, tmp = 0, ans = 0;
	scanf("%s", &X);
	len = strlen(X);
	while (X[i] != 0)
	{
		if (X[i] == 'S')
		{
			c++;
		}
		else if (X[i] = 'T' && c > 0)
		{
			c--;
			tmp++;
		}
		i++;
	}
	ans = len - tmp * 2;
	printf("%d\n", ans);

	return 0;
}

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








int main(){


  long long n,a,b,c,d,e;
  cin>>n>>a>>b>>c>>d>>e;
  
  long long tmp=a;
  tmp=min(tmp,b);
  tmp=min(tmp,c);
  tmp=min(tmp,d);
  tmp=min(tmp,e);
  
  cout<<((n+tmp-1)/tmp)+4<<endl;
  
  

  
    
    
    
  
  

  
  

  

        
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii;
struct C{bool operator()(pii a,pii b){
	int x=a.first*a.first+a.second*a.second;
	int y=b.first*b.first+b.second*b.second;
	if(x!=y)return x<y;
	return a.first<b.first;
}};
main(){
	int i,j,h,w;
	vector<pii>v;
	vector<pii>::iterator it;
	for(i=1;i<151;i++)for(j=i+1;j<151;j++)v.push_back(make_pair(i,j));
	sort(v.begin(),v.end(),C());
	for(;scanf("%d%d",&h,&w),h;printf("%d %d\n",it->first,it->second))it=++find(v.begin(),v.end(),make_pair(h,w));
}

Measured memory_bytes: 1164
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){cout<<"Left"<<endl;}
  if(a+b==c+d){cout<<"Balanced"<<endl;}
  if(a+b<c+d){cout<<"Right"<<endl;}
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,w,n,goal=0;
    cin>>h>>w>>n;
    if(h>=w){
	    goal+=n/h;
	    if(n%h!=0)goal++;
	}
    else{
	    goal+=n/w;
	    if(n%w!=0)goal++;
	}
	cout<<goal<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>

using namespace std;

using ll = long long;

int nodes[100001];
int N;
int M;
int values[100001];
int par[100001];
int height[100001];

void init()
{
	for (int i = 0; i < N; ++i)
	{
		par[i] = i;
		height[i] = 0;
	}
}

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

	return par[x] = find(par[x]);
}

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

	if (x == y)return;

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

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

int main()
{
	cin >> N >> M;
	init();
	for (int i = 1; i <= N; ++i)
	{
		cin >> values[i];
	}

	for (int i = 0; i < M; ++i)
	{
		int x, y;
		cin >> x >> y;

		unite(x, y);
	}

	int ans = 0;

	for (int i = 1; i <= N; ++i)
	{
		if (same(i, values[i]))ans++;
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//繰り返し2乗法
ll powerMOD(ll x, ll y){//繰り返し2乗法
  if(y < 0){
    return 0;
  }else if(y == 0){
    return 1LL;
  }else if(y%2 == 0){//偶数
    return (powerMOD(x,y/2)%MOD2)*(powerMOD(x,y/2)%MOD2)%MOD2;
  }else{//奇数
    return (powerMOD(x,y-1)%MOD2)*x%MOD2;
  }
}

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N; cin >> N;
  vector<int> d(N); for(int i=0; i<N; i++){ cin >> d[i]; }
  for(int i=0; i<N; i++){ 
    if(i==0 && d[i]!=0){ cout << 0 << endl; return 0; }
    else if(i!=0 && d[i]==0){ cout << 0 << endl; return 0; }
  }
  sort(d.begin(), d.end());
  
  //main
  vector<int> v;
  int c = 1;
  for(int i=0; i<N; i++){
    if(i!=N-1 && d[i] == d[i+1]){
      c++;
    }else if(i!=N-1 && d[i] == d[i+1]-1){
      v.pb(c);
      c = 1;
    }else if(i==N-1){
      v.pb(c);
    }else{
      cout << 0 << endl; return 0;
    }
  }
  /*for(int i=0; i<v.size(); i++){
    cout << v[i] << " ";
  }
  cout << endl;*/
  
  ll tmp = 1;
  for(int i=0; i<v.size()-1; i++){
    tmp *= powerMOD(v[i],v[i+1]);
    tmp %= MOD2;
    //cout << i << " " << power(v[i],v[i+1]) << " " << tmp << endl;
    //cout << v.size() << endl;
  }
  
  // output
  cout << tmp << endl;

  return 0;
}

Measured memory_bytes: 1276
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<long long> A(N);
  for (auto& e : A) cin >> e;
  sort(begin(A), end(A));
  constexpr long long kInf = 1e18;
  long long res = 1;
  bool ok = true;
  for (const auto& e : A) {
    if (log10(res) + log10(e) > 18) {
      ok = false;
      break;
    }
    res *= e;
  }
  if (res > kInf) ok = false;
  cout << (ok ? res : -1) << endl;
}


Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <cstring>
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int i,j;
  int c=0;
  for(i=0;i<s.size();i++){
    for(j=0;j<s.size();j++){
      if(s[i]==s[j]){
        c++;
      }
    }
    if(c%2==1){
      cout << "No" << "\n";
      return 0;
    }
  }
  cout << "Yes" << "\n";
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""


"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline
from collections import namedtuple
item = namedtuple('item', ['cal', 'pri'])


def Cond(x, n, items, pizza):
    y = [0] * n
    for i in range(n):
        y[i] = items[i].cal - x * items[i].pri
    y.sort(reverse=True)

    total = pizza.cal - x * pizza.pri
    for i in range(n):
        if y[i] > 0:
            total += y[i]
        else:
            break
    return total >= 0



def main(args):
    # n = 3
    # k = 2
    # items = [item(2, 2), item(5, 3), item(2, 1)]

    N = int(input())
    A, B = map(int, input().split())
    C = int(input())
    toppings = []
    for i in range(N):
        toppings.append(item(int(input()), B))
    pizza = item(C, A)

    lb = 0
    ub = 1e5
    for i in range(100):
        mid = (lb + ub) / 2
        if Cond(mid, N, toppings, pizza):
            lb = mid
        else:
            ub = mid
    print(int(ub))


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8152
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    ll n;
    cin >> n;
    ll a = 1, b = n;
    ll ans = LINF;
    while(a <= sqrt(n)) {
        if(n % a == 0) {
            b = n / a;
            ll minv = a + b - 2;
            ans = min(ans, minv);
            a++;
        } else a++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <string>
#include <vector>
#include <algorithm>

std::string parse(std::string const& s, size_t& i,
                  std::vector<std::string> const& ops, size_t preced = 0) {

  if (preced == ops.size()) {
    if (s[i] == '(') {
      auto res = parse(s, ++i, ops, 0);
      assert(s[i] == ')');
      ++i;
      return res;
    }
    assert(isalpha(s[i]));
    return std::string(1, s[i++]);
  }

  auto res = parse(s, i, ops, preced+1);
  if (ops[preced][0] == 'L') {
    while (i < s.length()) {
      char op = s[i];
      if (!std::count(ops[preced].begin()+1, ops[preced].end(), op)) break;
      auto tmp = parse(s, ++i, ops, preced+1);
      res = "(" + res + op + tmp + ")";
    }
  } else {
    while (i < s.length()) {
      char op = s[i];
      if (!std::count(ops[preced].begin()+1, ops[preced].end(), op)) break;
      auto tmp = parse(s, ++i, ops, preced);
      res = "(" + res + op + tmp + ")";
    }
  }
  return res;
}

void solve_testcase() {
  size_t G;
  scanf("%zu", &G);

  std::vector<std::string> ops(G);
  for (size_t i = 0; i < G; ++i) {
    char A;
    size_t M;
    scanf(" %c %zu", &A, &M);
    ops[i] += A;
    for (size_t j = 0; j < M; ++j) {
      char op;
      scanf(" %c", &op);
      ops[i] += op;
    }
  }

  size_t N;
  scanf("%zu", &N);
  for (size_t i = 0; i < N; ++i) {
    char buf[128];
    scanf("%s", buf);
    std::string s = buf;
    size_t j = 0;
    printf("%s\n", parse(s, j, ops).c_str());
  }
}

int main() {
  int D;
  scanf("%d", &D);
  for (int i = 0; i < D; ++i) {
    if (i > 0) puts("");
    solve_testcase();
  }
}



Measured memory_bytes: 2744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int r;
    cin >> r;
    cout << 2 * r * M_PI << endl;
    return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <deque>
using namespace std;

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

	long long x,y=0;

	deque<long long> qu;

	for (int i = 1; i <= 9; ++i) {
		qu.push_back(i);
	}

	for (int j = 0; j < K; ++j) {
		x = qu.front();
		y = x;

		if (x % 10 != 0) { qu.push_back(10 * x + x % 10 - 1); }
		qu.push_back(10 * x + x % 10);
		if (x % 10 != 9) { qu.push_back(10 * x + x % 10 + 1); }

		qu.pop_front();
	}

	cout << y << endl;

}

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

using namespace std;

typedef long long  ll;

int Solve()
{
    int n, n1, n2;
    cin >> n;
    n1 = n2 = n;

    while (n1 != 0) {
        string s = to_string(n1);
        string t = s;
        reverse(t.begin(), t.end());

        if (s == t)
            break;
        --n1;
    }
    while (true) {
        string s = to_string(n2);
        string t = s;
        reverse(t.begin(), t.end());

        if (s == t)
            break;
        ++n2;
    }

    if (abs(n - n1) <= abs(n - n2))
        return n1;
    else
        return n2;
}

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

    cout << Solve() << endl;

    return 0;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
P1 t[200002];
ll c[200002]={},total=0;
ll c1[200002]={};
int main() {

	ll n,d,a;
	cin>>n>>d>>a;
	rep(i,n){
		ll x,h;
		cin>>x>>h;
		t[i].first=x;
		t[i].second=h;
	}
	ll f=1;
	sort(t,t+n);
	c1[0]=t[0].first+2*d;
	c[0]=t[0].second/a+min(f,t[0].second%a);
	total+=c[0];
	ll cg=1,cs=0;
	for(int i=1; i<n-1; i++){
		for(int j=cs; j<cg; j++){
			if(c1[j]>=t[i].first){
				t[i].second-=(c[cg-1]-c[j-1])*a;
				break;
			}
			else cs++;
		}
		if(t[i].second<=0)continue;
		c1[cg]=t[i].first+2*d;
		c[cg]=t[i].second/a+min(f,t[i].second%a);
		total+=c[cg];
		c[cg]+=c[cg-1];
		cg++;
	}
	for(int j=cs; j<cg; j++){
		if(c1[j]>=t[n-1].first){
			t[n-1].second-=(c[cg-1]-c[j-1])*a;
			break;
		}
	}
	if(t[n-1].second>0)total+=t[n-1].second/a+min(f,t[n-1].second%a);
	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    if(n % k == 0) cout << 0 << endl;
    else cout << 1 << endl;}

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

int Q;
string X,Y;
int N,M;
int dp[1001][1001];

int solve(int xd,int yd){
  if( dp[xd][yd] != -1 ) return dp[xd][yd];
  if( xd==N || yd==M ) return dp[xd][yd] = 0;
  int ret;
  if( X[xd] == Y[yd] )
    ret = solve( xd+1,yd+1 ) + 1;
  else
    ret = max( solve(xd+1,yd), solve(xd,yd+1) );

  return dp[xd][yd] = ret;
}

int main(){
  cin >> Q;
  for(int ttt=0;ttt<Q;ttt++){
    cin >>X >> Y;
    N = X.size(); M = Y.size();
    memset(dp,-1,sizeof(dp));
    cout << solve(0,0) << endl;
  }
}

Measured memory_bytes: 5216
import sys
from bisect import bisect
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
b.sort()
c.sort()

bc = [0 for _ in range(n)]
for i in range(len(b)):
    if b[i] >= c[n-1]:
        break
    p = bisect(c,b[i])
    bc[i] = (n-p)

for i in range(len(b)-1,0,-1):
    bc[i-1] += bc[i]
ans = 0
for x in a:
    if x < b[n-1]:
        p = bisect(b,x)
        ans += bc[p]

print(ans)

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

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

  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  int i = lower_bound(a.begin(), a.end(), x) - a.begin();
  cout << min(i, m - i) << '\n';
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 25 20:54:45 2020

@author: naoki
"""


N = int(input())
A = list(map(int, input().split()))

money = 1000
stock = 0
for i in range(N-1):
    if A[i+1] > A[i]:
        stock = stock + money//A[i]
        money = money%A[i]
    else:
        money = money + stock*A[i]
        stock = 0

print(money+stock*A[N-1])

Measured memory_bytes: 61676
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(h, w, k) = in.readLine().split("\\s+").map(_.toInt)

    val choco = Array.ofDim[Array[Int]](h)
    for (hi <- choco.indices) {
      choco(hi) = in.readLine().map(_.toInt - '0').toArray
    }

    def pow(n: Int, k: Int): Int = {
      if (k == 0) {
        1
      } else {
        n * pow(n, k - 1)
      }
    }

    var min = (h - 1) * (w - 1)

    for (hPattern <- 0 until pow(2, h - 1)) {
      val hi2ci = Array.ofDim[Int](h)
      for (hi <- 1 until h) {
        hi2ci(hi) = hi2ci(hi - 1) + ((hPattern >> (hi - 1)) & 1)
      }

      def countVertical(): Option[Int] = {
        def greedy(sw: Int): Int = {
          val columnCount = Array.ofDim[Int](hi2ci.max + 1)

          for (wi <- sw until w) {
            for (hi <- 0 until h) {
              if (choco(hi)(wi) == 1) {
                if (columnCount(hi2ci(hi)) + 1 > k) {
                  return wi - 1
                }
                columnCount(hi2ci(hi)) += 1
              }
            }
          }
          w - 1
        }

        var verticalCount = 0
        var prevVertical = -1
        var wi = 0
        while (wi < w) {
          val vertical = greedy(wi)
          if (vertical == prevVertical) {
            return None
          } else {
            prevVertical = vertical
            wi = vertical + 1
            if (w - 1 != vertical) {
              verticalCount += 1
            }
          }
        }

        Some(verticalCount)
      }

      countVertical() match {
        case None =>
        case Some(verticalCount) =>
          min = Math.min(min, verticalCount + hi2ci.max)
      }
    }

    out.println(min)

    out.flush()
  }
}


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

int main() {
	int l, r, d;
  	cin >> l >> r >> d;
  	if (l % d == 0)
    	cout << (r / d) - (l / d) + 1;
 	else
      	cout << (r / d) - (l / d);
	return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>
typedef struct{
  char c;
  int n;
}Card;

int main(){
  int i, j, k, n, minj;
  Card c1[36], c2[36], c3[36];
  Card v;
  char c;
    scanf("%d\n", &n);
  for(i=0; i<n; i++){
    scanf("%c%d", &c1[i].c, &c1[i].n);
    scanf("%c", &c);
  }
  for(i=0; i<n; i++)
  c2[i]=c1[i];
 
 k=0;
  for(i=1; i<=9; i++){
    for(j=0; j<n; j++){
      if(c1[j].n==i){
          c3[k]=c1[j];
          k++;
      }
    }
  }
  for ( i = 0; i < n; i++){
	for ( j = 1; j < n; j++){
  	if(c1[j].n < c1[j - 1].n){
    	v = c1[j];
    	c1[j] = c1[j - 1];
    	c1[j - 1] = v;
  	}
  	}
  }
  for ( i = 0; i < n; i++){
	if (i > 0)
  	printf(" ");
	printf("%c%d", c1[i].c, c1[i].n);
  }
    printf("\n");
  
  k=0;
  for(i=0; i<n; i++){
      if(c1[i].c != c3[i].c){
        printf("Not stable\n");
        k++;
        break;
      }
  }
  if(k==0)printf("Stable\n");
  
    for( i = 0; i < n ; i++){
    minj = i;
      for( j = i; j < n; j++){
        if (c2[j].n < c2[minj].n) minj = j;
      }
      v = c2[i]; c2[i] = c2[minj]; c2[minj] = v;
    }
      for ( i = 0; i < n; i++){
      if (i > 0)
      printf(" ");
      printf("%c%d", c2[i].c, c2[i].n);
    }
      printf("\n");
 
    k=0;
  for(i=0; i<n; i++){
      if(c2[i].c != c3[i].c){
        printf("Not stable\n");
        k++;
        break;
      }
  }
  if(k==0)printf("Stable\n");

  
  return 0;
}

Measured memory_bytes: 1848
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 200001;
int n;
vector<int> g[N];

int main(){
    scanf("%d", &n);
    for(int i = 0, x; i<n-1; ++i){
        scanf("%d", &x);
        g[x].push_back(i+1);
    }
    for(int i = 1; i<=n; ++i)printf("%d\n", g[i].size());
}

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

int main(void) {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  for (int i = 0;; i++) {
    if (i * Y + (i + 1) * Z > X) {
      cout << i - 1 << endl;
      break;
    }
  }
  return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	cout<<a[2]<<" "<<a[0]<<" "<<a[1]<<endl;
	return 0;
}

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

using namespace std;

int digsum(int a){
    int sum = 0;
    int dig;
    while(a){
        dig = a % 10;
        sum += dig;
        a = a / 10;
    }
    return sum;
}
int main(){
    int n,a,b; scanf("%d%d%d",&n,&a,&b);
    vector<int> t(n);
    
    int sum = 0;
    for(int i = 1 ; i <= n ; i++){
        t[i-1] = digsum(i);
        if(a <= t[i-1] && t[i-1] <= b)
            sum += i;
    }
    
    printf("%d\n",sum);
    
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
// #define range(i,a,b,c) for(int i=a;\
c>0?i<b:\
i>b;\
i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

int H, W;

bool ng(int y, int x) {
	return y < 0 || H <= y || x < 0 || W <= x;
}

ll n, m;

void solve() {
	cin >> n >> m;
	ll a = min(n, m / 2);
	ll b = (m - 2 * a) / 4;
	dump(a);
	dump(b);
	cout << a + b << endl;
}

























signed main() {
	int T = 100;
	cout << fixed << setprecision(15);
	rep(i, T) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
def calc_sum(num):
    total = 0
    while num > 0:
        r = num % 10
        q = num // 10
        num = q
        total += r

    return total
# <--- function

# --> main roution
while True:
    n = int(input())
    if n == 0:
        break
    print(calc_sum(n))  


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

int main() {
  int H, W;
  cin >> H >> W;
  int A[10] = {}, c[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> c[i][j];
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int a;
      cin >> a;
      if (a >= 0) A[a]++;
    }
  }

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }

  int ret = 0;
  for (int i = 0; i < 10; i++) {
    ret += c[i][1] * A[i];
  }
  cout << ret << endl;
}

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

#define NREP() for(ull i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ull i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ull ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    cin >> x >> y;
    cnt = 1;
    while (x <= y) {
        x *= 2;
        cnt++;
    }
    MSG(cnt - 1)
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS 
#include<stdio.h>

int main() {
	long int N, M,L,K;
	L = 0; K = 0;
	scanf("%ld%ld", &N, &M);
	if (2 * N > M) {
		L = M / 2;
	}
	else {
		L = N;
		K = M - 2 * N;
		L = L + K / 4;
	}
	printf("%ld", L);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         
        for(int i=1; ; i++){
            int x = sc.nextInt();
            if(x==0){
                break;
            }
            System.out.printf("Case %d: %d\n",i,x);
        }
 
    }
 
}



Measured memory_bytes: 67984
#include <cstdio>
#include <bitset>

using namespace std;

int main()
{
  int n;
  bitset<1000000> is_prime;
  is_prime.set();
  is_prime[0] = false, is_prime[1] = false;
  for (int i = 2; i * i< 1000000; i++) {
    for (int j = i * 2; j < 1000000; j += i) {
      is_prime[j] = false;
    }
  }
  while (scanf(" %d ", &n) == 1) {
    int c = 0;
    for (int i = 0; i <= n; i++) {
      if (is_prime[i]) {c++;}
    }
    printf("%d\n", c);
  }
  return 0;
}

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

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

  if(a <= 0 && b >= 0) cout << "Zero" << endl;
  else if(a >= 0 || (b - a) & 1) cout << "Positive" << endl;
  else cout << "Negative" << endl;

  return 0;
}


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

using namespace std;

typedef long long int ll;

void solve()
{
	ll n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++)
	{
		ll x;
		cin >> x;
		n -= x;
	}
	
	if(n < 0) cout << -1;
	else cout << n; 
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}



Measured memory_bytes: 3596
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a)printf("%d\n", k);
	else if (k <= a + b)printf("%d\n", a);
	else printf("%d\n", a - (k - a - b));
	return 0;
}


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

int a[1000];

int main(void)
{
  while (1) {
    int n, m, max = -1;
    cin >> n >> m;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }

    for (int i = 0; i < n - 1; ++i) {
      for (int j = i + 1; j < n; ++j) {
	if (max < a[i] + a[j] && a[i] + a[j] <= m) {
	  max = a[i] + a[j];
	}
      }
    }
    if (max == -1) {
      cout << "NONE" << endl;
      continue;
    }
    cout << max << endl;
  }
  return 0;
}



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

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0) {
			cout << " " << i;
			continue;
		}
		for (int j = i; j > 0; j /= 10) {
			if (j % 10 == 3) {
				cout << " " << i;
				break;
			}
		}
	}
	cout << endl;
}



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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A + B > C + D) {
        cout << "Left" << endl;
    } else if (A + B < C + D) {
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
}


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

using namespace std;

int main()
{
  long double A, B, ans;
  long long trueAns;
  cin >> A;
  cin >> B;
  B = round(B * 100);
  ans = A * B;
  ans /= 100;
  trueAns = ans;
  cout << trueAns << endl;
  return 0;
}


Measured memory_bytes: 3792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 8/3/2018
 
 19:50-20:20, 21:30-
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=1e5+1;
int N;
LL A[MAX_N];
LL T;
void solve() {
  map<LL,int> D;
  LL btm=A[0];
  FOR(i,1,N) {
    if(A[i]<btm) btm=A[i];
    else if(A[i]>btm) {
      D[-(A[i]-btm)]++;
    }
  }
  cout<<D.begin()->second<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>T;
  REP(i,N) cin>>A[i];
  solve();
  return 0;
}


Measured memory_bytes: 7296
n = gets.chomp.to_i
memo={"S" => 0, "H" => 0, "C" => 0, "D" => 0}

n.times do
    mark,number = gets.chomp.split(" ")
    memo[mark]=memo[mark]|(1 << (number.to_i-1))
end

memo.each{|key,value|
    13.times do |x|
        if value&(1 << x)==0 then
            print(key," ",x+1,"\n")
        end
    end
}

Measured memory_bytes: 8712
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
  ll X;
  cin >> X;

  if (X < 600) cout << '8' << endl;
  else if (X < 800) cout << '7' << endl;
  else if (X < 1000) cout << '6' << endl;
  else if (X < 1200) cout << '5' << endl;
  else if (X < 1400) cout << '4' << endl;
  else if (X < 1600) cout << '3' << endl;
  else if (X < 1800) cout << '2' << endl;
  else if (X < 2000) cout << '1' << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;
using ll = long long;

int main()
{
	int MAX = 100002;
	vector<int> is_prime(MAX, 1);
	is_prime[0] = is_prime[1] = 0;
	for (int i = 2; i < MAX; ++i) {
		if (!is_prime[i])
			continue;
		for (int j = i * 2; j < MAX; j += i)
			is_prime[j] = 0;
	}

	vector<int> a(MAX, 0);
	for (int i = 0; i < MAX; ++i) {
		if (i % 2 == 0)
			continue;
		if (is_prime[i] && is_prime[(i+1)/2])
			a[i] = 1;
	}

	vector<int> s(MAX+1, 0);
	for (int i = 0; i < MAX; ++i)
		s[i + 1] = s[i] + a[i];

	int Q;
	cin >> Q;
	for (int q = 0; q < Q; ++q) {
		int l, r;
		cin >> l >> r;
		++r;

		cout << s[r] - s[l] << endl;
	}
}



Measured memory_bytes: 1792
# include <bits/stdc++.h>
using namespace std;
long double pi = 3.14159265359;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    int sum = 0;
    while(m--){
        int x;
        cin >> x;
        sum += x;
    }
    if(n < sum){
        cout << "-1\n";
    }else{
        cout << n - sum << '\n';
    }
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  string s,t;
  cin >> s >> t;

  int ans = 0;
  rep(i,3){
    if(s.at(i)==t.at(i)) ans++;
  }

  cout << ans;

  
}

Measured memory_bytes: 3604
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
int kaijo(int n){
	int ans = 1;
	if (n != 0){
		for (int i = 0; i < n; i++){
			ans *= (n - i);
		}
	}
	else{
		ans = 1;
	}
	return ans;
}

int main(){
	int r, g, a;
	cin >> r >> g;
	a = 2 * g - r;
	cout << a << endl;

	return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    int N, M;
    cin >> N >> M;
    int a, b;
    vector<bool> ftoi;
    vector<bool> itoN;
    ftoi.resize(N);
    fill(ftoi.begin(), ftoi.end(), false);
    itoN.resize(N);
    fill(itoN.begin(), itoN.end(),false);
    for (int i = 0; i < M; i++)
    {
        cin >> a >> b;

        if (a > b) swap(a, b);

        if (a == 1)
        {
            ftoi[b - 1] = true;
        }
        if (b == N)
        {
            itoN[a - 1] = true;
        }
        
    }

    for (int i = 0; i < N; i++)
    {
        if (ftoi[i] & itoN[i])
        {
            cout << "POSSIBLE" << endl;
            return 0;
        }
        
    }
    
    cout << "IMPOSSIBLE" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1010;
int n;
LL x[maxn],y[maxn],u[maxn],v[maxn],bs[35];
void work(){
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
    LL sum = (x[0] + y[0]) % 2;
    for (int i = 0; i < n; i++) if ((x[i] + y[i] - sum) % 2 != 0) {cout<<"-1"<<endl;return;}

    if (sum == 0) {
      cout << 32 << endl;
      for (int i = 30; i > -1; i--) cout<<bs[i]<<" ";
      cout << 1 << endl;
      for (int i = 0; i < n; i++) x[i]++;
    }else {
      cout << 31 << endl;
      for (int i = 30; i > -1; i--) cout<<bs[i]<<" ";
      cout << endl;
    }

    for (int i = 0; i < n; i++) u[i] = x[i] + y[i], v[i] = x[i] - y[i];

    for (int i = 0; i < n; i++) {
        for (int j = 30; j > -1; j--) {
            if (u[i] > 0 && v[i] > 0) {cout << 'R'; u[i] -= bs[j];  v[i] -= bs[j];}//x[i] > y[i] & x[i] > 0
            else if (u[i] > 0 && v[i] < 0) {cout << 'U'; u[i] -= bs[j];  v[i] += bs[j];}//y[i] > x[i] & y[i] > 0
            else if (u[i] < 0 && v[i] > 0) {cout << 'D'; u[i] += bs[j];  v[i] -= bs[j];}//x[i] > y[i] && y[i] < 0
            else {cout << 'L'; u[i] += bs[j];  v[i] += bs[j];}//x[i] < y[i] & x[i] < 0;
      }
      if (sum == 0) cout << 'L';
      cout << endl;
    }
}
int main(){
    bs[0] = 1;
    for (int i=1;i<32;i++) bs[i] = bs[i-1] << 1;
    work();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,t;
	cin>>n>>t;
	int i,a[n][2],ans=1000000;
	for(i=0;i<n;i++)cin>>a[i][0]>>a[i][1];
		
	for(i=0;i<n;i++){
		if(a[i][1]<=t&&a[i][0]<ans)ans=a[i][0];
	}
	if(ans==1000000)cout<<"TLE"<<endl;
	else cout<<ans<<endl;
	
		
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int k=n%10;
	if(k==3){
		cout<<"bon"<<endl;
	}else if(k==0||k==1||k==6||k==8){
		cout<<"pon"<<endl;
	}else{
		cout<<"hon"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3560