akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

void dfs(vector<vector<pll>> &g,vll &color,ll n,ll c){
	if(color.at(n)!=-1) return ;
	color.at(n) = c ;
	for(int i=0;i<g.at(n).size();i++){
		dfs(g,color,g.at(n).at(i).first,(c^(g.at(n).at(i).second&1))) ;
	}
}

int main(){
	ll n ; cin >> n ;
	vector<vector<pll>> g(n,vector<pll>(0)) ;
	for(int i=0;i<n-1;i++){
		ll u,v,w ;
		cin >> u >> v >> w ;
		u-- ; v-- ;
		g.at(u).push_back(make_pair(v,w)) ;
		g.at(v).push_back(make_pair(u,w)) ;
	}
	vll color(n,-1) ;
	dfs(g,color,0,0) ;
	for(int i=0;i<n;i++){
		cout << color.at(i) << endl ;
	}
}


Measured memory_bytes: 11520
#define _USE_MATH_DEFINES

//#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <vector>
    
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

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

    if((n%10 == 2)||(n%10 == 4)||(n%10 == 5)||(n%10 == 7)||(n%10 == 9)){
        cout<<"hon"<<endl;
        return 0;
    }
    if((n%10 == 0)||(n%10 == 1)||(n%10 == 6)||(n%10 == 8)){
        cout<<"pon"<<endl;
        return 0;
    }
    if((n%10 == 3)){
        cout<<"bon"<<endl;
        return 0;
    }


} // end of main
    
//実行は、Opt + Ctl + N


Measured memory_bytes: 3636
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int counter=0;
		while(true) {
			int team_su=sc.nextInt();
			if(team_su==0) {
				break;
			}
			else {
				if(counter!=0) {
					System.out.println("");
				}
				counter++;
				String[] kuni=new String[team_su];
				int[] kachiten=new int[team_su];
				int[] id=new int[team_su];
				for(int i=0; i<team_su; i++) {
					kuni[i]=sc.next();
					kachiten[i]=sc.nextInt()*3+sc.nextInt()*0+sc.nextInt();
					id[i]=i;
				}

				int tmp1=0,tmp2=0;
				int tmp3=0,tmp4=0;
				String a="",b="";

				for(int i=0; i<team_su; i++) {
					for(int j=i; j<team_su; j++) {
						if(kachiten[i]<kachiten[j]) {
							tmp1=kachiten[i];
							tmp2=kachiten[j];
							a=kuni[i];
							b=kuni[j];
							tmp3=id[i];
							tmp4=id[j];
							kachiten[i]=tmp2;
							kachiten[j]=tmp1;
							kuni[i]=b;
							kuni[j]=a;
							id[i]=tmp4;
							id[j]=tmp3;
						}

						if(kachiten[i]==kachiten[j]) {
							tmp3=id[i];
							tmp4=id[j];
							if(tmp3>tmp4) {
								tmp1=kachiten[i];
								tmp2=kachiten[j];
								a=kuni[i];
								b=kuni[j];
								kachiten[i]=tmp2;
								kachiten[j]=tmp1;
								kuni[i]=b;
								kuni[j]=a;
								id[i]=tmp4;
								id[j]=tmp3;
							}
						}
					}
				}
				for(int i=0; i<team_su; i++) {
					System.out.println(kuni[i]+","+kachiten[i]);
				}
			}
		}
	}
}


Measured memory_bytes: 27208
#include <stdio.h>

int num_digit(n)
{
    int result = 1;

    while ((n = n / 10))
        result++;

    return result;
}

int main(void)
{
    int a, b;

    while (scanf("%d %d", &a, &b) != EOF)
        printf("%d\n", num_digit(a + b));

    return 0;
}

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

long long int dp[1005][(1<<12)+5];
int main(){
  int n,m;
  cin >> n >> m;//見栄を張らずにループで埋める
  for(int i=0;i<1005;i++)for(int j=0;j<(1<<12)+5;j++)dp[i][j]=1e18;
  dp[0][0]=0;
  long long int a;
  int b,c,d;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    c=0;
    for(int j=0;j<b;j++){
      cin >> d;
      c+=(1<<(d-1));
    }
    for(int j=0;j<(1<<n);j++){//最初に埋めた分を小さくできそうなら更新する
      if(dp[i+1][j]>dp[i][j])dp[i+1][j]=dp[i][j];
      if(dp[i+1][j|c]>dp[i][j]+a)dp[i+1][j|c]=dp[i][j]+a;
    }
  }
  if(dp[m][(1<<n)-1]==1e18)cout << -1 << endl;
  else cout << dp[m][(1<<n)-1] << endl;
}



Measured memory_bytes: 32384
import collections

n = int(input())
s = [input() for _ in range(n)]
a = list(set(s))
ans = []

t = collections.Counter(s)
v = list(t.most_common())[0][1]

for i,j in list(t.most_common()):
	if v == j:
		ans.append(i)

for i in sorted(ans):
	print(i)



Measured memory_bytes: 55788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) lower_bound(all(v),k)-v.begin()
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
ll inf=100100100100;
const int mod=1000000007;
int main(){
   int n,w;cin>>n>>w;
   vvi dp(n,vi(n*1001,inf));
   vi omosa(n),kachi(n);
   rep(i,n)dp[i][0]=0;
   rep(i,n)cin>>omosa[i]>>kachi[i];
   rep(i,n){
      rep(j,(i+1)*1001){
         if(j>kachi[i]){
            if(i>0){
               chmin(dp[i][j],dp[i-1][j-kachi[i]]+omosa[i]);
            }
         }
         else chmin(dp[i][j],omosa[i]);
        if(i>0)chmin(dp[i][j],dp[i-1][j]);
      }
   }
   for(int i=n*1001-1;i>=0;i--){
      if(dp[n-1][i]<=w){
         cout<<i<<endl;
        return 0;
      }
   }
}


Measured memory_bytes: 79488
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val n = in.readLine().toInt

    System.out.println(
      Math.pow(n, 3).toInt
    )
  }
}


Measured memory_bytes: 27320
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

H,W = II()
a = [III() for _ in range(H)]

num = 0
move = []
for i in range(H):
    for j in range(W-1):
        if a[i][j]%2==1:
            a[i][j+1] += 1
            num += 1
            move.append([i+1,j+1,i+1,j+2])

for i in range(H-1):
    if a[i][W-1]%2==1:
        a[i+1][W-1] += 1
        num += 1
        move.append([i+1,W,i+2,W])

print(num)
for i in move:
    print(*i, sep=' ')

Measured memory_bytes: 71516
H,W,D = map(int,input().split())

A = [[] for _ in range(H)]
Aset = [[] for _ in range(H)]
for i in range(H):
    A[i] = list(map(int,input().split()))
    Aset[i] = set(A[i])

#1,1+D,1+2D,...
#2,2+D,2+2D,...
#...
#D,2D,3D,...
cost = [0]*(H*W+1)
for i in range(1,D+1):
    num = i
    now = None#座標
    while True:
        if num > H*W:
            break
        for row in range(H):
            if num in Aset[row]:
                #print(row)
                ind = A[row].index(num)
                if now == None:
                    now = (ind, row)#x,y
                    cost[num] = 0
                else:
                    cost[num] = cost[num-D] + abs(ind-now[0]) + abs(row-now[1])
                    now = (ind, row)
        num += D

Q = int(input())
for _ in range(Q):
    l, r = map(int,input().split())
    print(cost[r]-cost[l])

Measured memory_bytes: 79964
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////
ll Gcd(ll x, ll y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return Gcd(y, x%y);
}
ll lcm(ll a, ll b) {
	ll g = Gcd(a, b);
	return a / g * b;
}
int N, K;
int A[100100];
int main() {
	cin >> N >> K;
	int M = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		M = max(M, A[i]);
	}
	int ans = A[0];
	for (int i = 1; i < N; ++i) {
		ans = gcd(ans, A[i]);
	}
	if (K%ans == 0 && K <= M) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
using namespace std;

int main() {
    int a[3];
    scanf("%d%d%d", &a[0], &a[1], &a[2]);
    sort(a, a+3);
    if(a[2] > a[1] && a[0] == a[1]) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int>a(n);
  vector<int>b(n);
  vector<ll>ans(100001);
  priority_queue<int>pq;
  for(int i=0;i<n;i++)cin>>a[i]>>b[i];
  vector<vector<int>>data(100001);
  for(int i=0;i<n;i++){
    data[a[i]].push_back(b[i]);
  }
  ll sum=0;
  ans[0]=0;
  for(int i=1;i<=100000;i++){
    for(int j=0;j<data[i].size();j++){
      pq.push(data[i][j]);
    }
    if(pq.size()>0){
      sum+=pq.top();
      pq.pop();
    }
    ans[i]=sum;
  }
  cout<<ans[m]<<endl;
}
      
  
  


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

using namespace std;

int main()
{
	double ans = 0;
	int n, m, d;
	cin >> n >> m >> d;
	printf("%.8f", 1.0 * (2 * n - 2 * d) / (1ll * n * n) * (m - 1) * (0.5 * (d == 0 ? 1 : 2)));
	return 0;
}


Measured memory_bytes: 384
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_d

import sys
input=sys.stdin.readline

def main():
    M=int(input())
    dc=[tuple(map(int,input().split())) for i in range(M)]
    ans=0
    n=0
    for i in range(M):
        n+=dc[i][0]*dc[i][1]
        ans+=dc[i][1]
    ans-=1
    def aint(x):
        ret=0
        cnt=0
        while(x>0):
            cnt+=1
            ret+=x//10
            x//=10
        cnt-=1
        return int(ret)-cnt
            
    if n>=10:
        ans+=aint(n)
        

    while(n>=10):
        ns=str(n)
        n=0
        for i in range(10):
            c=ns.count(chr(i+ord("0")))
            n+=i*c
        ans+=len(ns)-1
        if n>=10:
            ans+=aint(n)
    print(ans)
        
    
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 99276
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>

#define lc (now<<1)
#define rc (now<<1|1)
#define mid (ql+qr)/2
using namespace std;
typedef pair<int,int> pp;
const int _=1e2;
const int maxn=5e5+_;
const int fbin=(1<<21)+_;
int n,p[maxn];
int read()
{
	int x=0; char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x;
}
void write(int x)
{
	if(x>=10)write(x/10);
	putchar(x%10+'0');
}

int nlen,num[maxn];
namespace GRAPH
{
	struct edge
	{
		int x,y,next;
	}a[maxn*2];int len,last[maxn],du[maxn];
	void ins(int x,int y)
	{
		len++;
		a[len].x=x;a[len].y=y; du[y]++;
		a[len].next=last[x];last[x]=len;
	}
	priority_queue< pp,vector<pp>,greater<pp> >q;
	void topsort()
	{
		for(int i=1;i<=n;i++)
			if(du[i]==0)q.push(make_pair(p[i],i));
		while(!q.empty())
		{
			pp g=q.top();q.pop();
			num[++nlen]=g.first;
			for(int k=last[g.second];k;k=a[k].next)
			{
				int y=a[k].y;
				du[y]--;
				if(du[y]==0)q.push(make_pair(p[y],y));
			}
		}
	}
}

int sli;
namespace SEG
{
	int tr[2*fbin];
	void update(int now){tr[now]=max(tr[lc],tr[rc]);}
	void pushdown(int now){tr[lc]=max(tr[lc],tr[now]),tr[rc]=max(tr[rc],tr[now]);}
	void change(int now,int ql,int qr,int k,int p)
	{
		if(ql==qr){tr[now]=p;return ;}
		if(k<=mid)change(lc,ql,mid,k,p);
		else change(rc,mid+1,qr,k,p);
		update(now);
	}
	int getmaxpos(int now,int ql,int qr,int l,int r)
	{
		if(ql==l&&qr==r)return tr[now];
			 if(r<=mid)  return getmaxpos(lc,ql,mid,l,r);
		else if(mid+1<=l)return getmaxpos(rc,mid+1,qr,l,r);
		else return max(getmaxpos(lc,ql,mid,l,mid),getmaxpos(rc,mid+1,qr,mid+1,r));
	}
}

int as[maxn];
int main()
{
	int K,x;
	n=read(),K=read(); sli=n+2*(K-1);
	for(int i=1;i<=n;i++)
		x=read(),p[x]=i;
	
	for(int i=1;i<=n;i++)
	{
		x=SEG::getmaxpos(1,1,sli,K-1+ p[i],K-1+ p[i]+K-1);
		if(x!=0)
			GRAPH::ins(x,i);
			
		x=SEG::getmaxpos(1,1,sli,K-1+ p[i]-K+1,K-1+ p[i]);
		if(x!=0)
			GRAPH::ins(x,i);
						
		SEG::change(1,1,sli,K-1+ p[i],i);
	}
	
	GRAPH::topsort();
	for(int i=1;i<=n;i++)as[num[i]]=i;
	for(int i=1;i<=n;i++)write(as[i]),putchar('\n');
	
	return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  rep(i, s.size()) {
    if (s[i] != t[i]) {cout << "No" << endl; return 0;}
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n); rep (i, n) cin >> a[i];
    ll now = 0;
    ll ans = 0;
    rep (i, n) {
        if (now > a[i]) {
            ll k = now - a[i];
            ans += k;
        } else {
            now = a[i];
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4776
n, x, y = gets.split(" ").map(&:to_i)

ans = (1..n-1).map{ |i| n - i }
# p ans

a = x
b = y - x - 1
c = n - y + 1

# p a, b, c
# b == 0 ならば、ansをいじらない

a.times do |a_i|
  c.times do |c_i|
    ans[(a-a_i-1) + b + c_i + 1 - 1] -= 1
    ans[(a-a_i-1) + c_i + 1 - 1] += 1
  end
end

# p ans

a.times do |a_i|
  b.times do |b_i|
    old = (a-a_i-1) + b_i + 1
    new = (a-a_i-1) + (b - b_i) + 1
    # puts "[debug] #{a_i}, #{b_i}, #{old}, #{new}"
    if old > new then
      ans[old-1] -= 1
      ans[new-1] += 1
    end
  end
end

# p ans

b.times do |b_i1|
  b.times do |b_i2|
    old = b_i2 - b_i1
    new = b_i1 + 1 + 1 + (b - b_i2)
    if old > new then
      ans[old-1] -= 1
      ans[new-1] += 1
    end
  end
end

# p ans

b.times do |b_i|
  c.times do |c_i|
    old = c_i + (b - b_i)
    new = b_i + 1 + 1 + c_i
    # puts "[debug] #{b_i}, #{c_i}, #{old}, #{new}"
    if old > new then
      ans[old-1] -= 1
      ans[new-1] += 1
    end
  end
end

# p ans

ans.each do |n|
  puts n
end


Measured memory_bytes: 1788
using System;

class program
{
    

    static void Main(string[] args)
    {
        string[] inputs = Console.ReadLine().Split();
        int H = int.Parse(inputs[0]);
        int W = int.Parse(inputs[1]);

        char[,] map = new char[H + 2, W + 2];
        for (int i = 0; i < H + 2; i++)
        {
            map[i, 0] = '#';
            map[i, W + 1] = '#';
        }
        for (int i = 0; i < W + 2; i++)
        {
            map[0, i] = '#';
            map[H + 1, i] = '#';
        }

        for (int i = 0; i < H; i++)
        {
            string input = Console.ReadLine();
            for (int j = 0; j < W; j++)
            {
                map[i + 1, j + 1] = input[j];
            }
        }

        for(int i = 0; i < H + 2; i++)
        {
            for(int j = 0; j < W + 2; j++)
            {
                Console.Write(map[i, j]);
            }
            Console.WriteLine();
        }

    }
}

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

int main(){
  int n;
  int a[111];
  
  scanf(" %d",&n);
  
  for(int i=0;i<n;i++){
    scanf(" %d",&a[i]);
  }

  int cnt=0;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n-i-1;j++){
      if(a[j]>a[j+1]){
	int temp=a[j];
	a[j]=a[j+1];
	a[j+1]=temp;
	cnt++;
      }
    }
  }
  
  for(int i=0;i<n;i++){
    printf("%d",a[i]);
    if(i+1!=n){
      printf(" ");
    }
  }
  
  printf("\n%d\n",cnt);

  return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}
//cout << fixed << setprecision(15);
int N, M, K, H, W, L, R, X, Y, ans;
string S, T;

signed main(){
  cin >> S;
  N = S.size();
  ans = 0;
  int a = 0;
  rep(i,N){
    if(S[i]=='B') continue;
    ans += i-a;
    a++;
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 3720
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a;
  cin >> a;
  if(a > 999){
    cout << "ABD\n";
  }
  else{
    cout << "ABC\n";
  }
}

Measured memory_bytes: 3596
n = int(input())
a = list(map(int,input().split()))
cnt = [0] * ((10**5) + 1)
for i in range(n):
         cnt[a[i]] += 1
sumcnt = [0]
for i in range(len(cnt)):
         sumcnt.append(sumcnt[i]+cnt[i])
ans = 0
for i in range(len(sumcnt) - 3):
         if ans < sumcnt[i+3] - sumcnt[i]:
                  ans = sumcnt[i+3] - sumcnt[i]
print(ans)


Measured memory_bytes: 13964
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<iostream>
using namespace std;
#include<string>
#include<sstream>
#include<algorithm>
#include<functional>
#include<set>
#include<math.h>
#include<map>
#include<vector>
#include<list>
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define fi first
#define se second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	int a, b;
	cin >> a >> b;
	if (a - b >= 2)
	{
		cout << a + a - 1 << endl;
	}
	else if (b - a >= 2)
		cout << b + b - 1 << endl;
	else
		cout << a + b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

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

  ll m = INF*INF;
  rep(i, 5){
    ll a;
    cin >> a;
    m = min(m, a);
  }

  cout << (n+m-1)/m + 4 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h, w, k;
	cin >> h >> w >> k;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	--x1; --y1; --x2; --y2;
	vector<string> grid(h);
	for (int i = 0; i < h; ++i)
		cin >> grid[i];
	auto valid = [&](const pair<int, int>& p){ return p.first >= 0 && p.first < h && p.second >= 0 && p.second < w; };
	vector<vector<int>> dist(h, vector<int>(w, 1e9));
	vector<vector<bool>> vis(h, vector<bool>(w));
	queue<pair<int, int>> q;
	q.emplace(x1, y1);
	dist[x1][y1] = 0;
	vis[x1][y1] = 1;
	while (!q.empty()){
		auto u = q.front(); q.pop();
		for (int j = 0; j < 4; ++j){
			for (int i = 1; i <= k; ++i){
				int nr = u.first + i * dir[j].first;
				int nc = u.second + i * dir[j].second;
				if (!valid({nr, nc})) continue;
				if (grid[nr][nc] != '.' || dist[nr][nc] <= dist[u.first][u.second]) break;
				if (vis[nr][nc]) continue;
				dist[nr][nc] = dist[u.first][u.second] + 1;
				if (nr == x2 && nc == y2){
					cout << dist[nr][nc] << '\n'; return 0;
				}
				vis[nr][nc] = 1;
				q.emplace(nr, nc);
			}
		}
	}
	cout << -1 << '\n';
}


Measured memory_bytes: 12176
s = raw_input()
n = len(s)
ans = 0
for msk in range(0, (1 << (n - 1))):
    t = ''
    for i in range(n):
        t += s[i]
        if ((msk >> i) & 1) == 1:
            t += '+'
    ans += eval(t)
print ans


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define mem(x, y) memset(x, y, sizeof(x))
#define pii pair<int, int>
#define pli pair<LL, int>
#define mkp make_pair
const int N = 20;
int D, a[N], n, mask[N];
LL ans;

int cal(int i) {
    return a[i] + (i ? mask[i - 1] : 0) - mask[i] * 10;
}

void go(int L) {
    int tot = 1 << L;
    for(int ma = 0; ma < tot; ma++) {
        for(int k = 0; k < L; k++) mask[k] = ma >> k & 1;
        if(mask[L - 1]) continue;
        LL res = 1;
        for(int k = 0; k * 2 < L; k++) {
            int i = k, j = L - 1 - i;
            int F = cal(i), S = cal(j);
            if(F + S != 0) res = 0;
            else {
                if(F > 0) res *= (10 - F);
                else res *= max(0, (10 - S - (!k)));
            }
        }
        ans += res;
    }
}

int main()
{
    scanf("%d", &D);
    while(D) a[n++] = D % 10, D /= 10;
    while(n <= N) go(n++);
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 384
#include<cstdio>
int a[200001],sum,n;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",a+i),sum^=a[i];
    for(int i=1;i<=n;i++)printf("%d ",a[i]^sum);puts("");
}

Measured memory_bytes: 3204
class Dice:
  def __init__(self, state):
    self.state = state

  def vertical(self, direction):
    s = self.state
    state = [s[1], s[5], s[0], s[4]]
    if direction < 0:
      s[0], s[1], s[4], s[5] = state
    elif 0 < direction:
      s[0], s[1], s[4], s[5] = reversed(state)
    return self
  
  def lateral(self, direction):
    s = self.state
    state = [s[2], s[5], s[0], s[3]]
    if direction < 0:
      s[0], s[2], s[3], s[5] = state
    elif 0 < direction:
      s[0], s[2], s[3], s[5] = reversed(state)
    return self

  def north(self):
    self.vertical(-1)
    return self

  def south(self):
    self.vertical(1)
    return self
  
  def east(self):
    self.lateral(1)
    return self

  def west(self):
    self.lateral(-1)
    return self

is_eql = False
n = int(input())
init_states = []

for i in range(n):
  init_states.append(input().split())

try:
  for i in range(0, n):
    for j in range(i + 1, n):
      dice1 = Dice(init_states[i])
      dice2 = Dice(init_states[j])
  
      for c in list('NNNNWNNNWNNNENNNENNNWNNN'):       
        if c == 'N':
          dice2.north()
        elif c == 'S':
          dice2.south()
        elif c == 'W':
          dice2.west()
        elif c == 'E':
          dice2.east()
        if dice1.state == dice2.state:
          is_eql = True
          raise Exception
except Exception:
  pass

print('No' if is_eql else 'Yes')



Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
long long int fun(long long int n)
{
    if(n==1)
    return 1;
    else 
    {
        return fun(n/2)*2+1;
    }
}
int main() {
    long long int n;
    cin>>n;
    cout<<fun(n);
   // cout<<sum<<" ";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

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

    ll min_D = 100000000;
    rep(i, S.size() - 2) {
        string T = S.substr(i, 3);
        ll V = stoi(T);
        ll D = abs(V - 753);
        min_D = min(min_D, D);
    }

    cout << min_D << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
ll dp[21][(1<<21)];

using namespace std;

int main(){
	ll n;
	cin >> n;
	int arr[n][n];
	
	for(int i=0 ; i<n ; i++){
		for(int j=0 ; j<n ; j++){
			cin >> arr[i][j];
		}
	}

	// Let dp[i][j] denote the number ways to make a sum of j till row i taking exactly one from eacb row i
	// We have dp[i][j] =  dp[i-1][j-x] where x is the face value of the two position

	ll col = (1<<n);

	//cout << col << "w\n";
	
	ll num = 1;

	for(ll i=0 ; i<col ; i++){
		dp[0][i] = 0;
	}

	for(ll i=0 ; i<n ; i++){
		if(arr[0][i] == 1){
			dp[0][num] = 1;
		}
		num *= 2;
	}


	for(ll i=1 ; i<n ; i++){
		for(int j=0 ; j<col ; j++){
			dp[i][j] = 0;
			num = 1;

			if(__builtin_popcount(j)==(i+1)){
				for(int k=0 ; k<n && j>=num; k++){
					if(arr[i][k] == 1){
						dp[i][j] = (dp[i][j]%MOD + dp[i-1][j-num]%MOD)%MOD;
					}
					num *= 2;
				}	
			}
			
		}
	}

	/*for(int i=0 ; i<n ; i++){
		for(int j=0 ; j<col ; j++){
			cout << dp[i][j] << " ";
		}
		cout << "\n";
	}*/

	cout << dp[n-1][(1<<n)-1] << "\n";
	return 0;
}

Measured memory_bytes: 344320
//#pragma GCC optimize("Ofast")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include<unordered_set>

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
//#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

int MAX = 100010;
int MOD = (ll)1000000000 + 7;
ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;


typedef pair<ll, int>P;//firstは距離、secondは頂点番号
struct Ver { ll dist; unordered_set<int>company; };//頂点に、始点からの距離と最後に使った会社を持たせる
struct edge { int to, cmp; };//辺には行き先の頂点と会社を持たせる
Ver d[100010];
int V;//頂点数
int M;//辺の本数

vector<edge>G[100010];//グラフ
					  //int d[MAX];//始点からの距離
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;
	unordered_set<int>st;//キューに入っている頂点番号
			   //全点への距離をINFで初期化
	for (int i = 0; i < V + 1; ++i) {
		d[i].dist = INF;
	}
	//始点への距離は0
	d[s].dist = 0;
	//始点をキューに入れる
	que.push(P(0, s)); st.insert(s);
	while (!que.empty()) {
		P p = que.top(); que.pop();
		auto c = st.erase(p.second);
		int v = p.second;//今見ている頂点
		if (d[v].dist < p.first)continue;

		//今見ている頂点につながるすべての辺について距離を更新する
		int n = G[v].size();
		for (int i = 0; i < n; ++i) {
			edge e = G[v][i];
			int cost = 1;
			//vに訪れるのに最後に使った会社(複数の場合もある)が今見ている辺の会社と同じならコストを0にする
			if (d[v].company.find(e.cmp) != d[v].company.end())cost = 0;
			//今見ている辺を使うことでe.toへの距離が小さくなるなら、距離を更新し、最後に使った会社をe.cmpとする
			if (d[e.to].dist > d[v].dist + cost) {
				d[e.to] = { d[v].dist + cost,{ e.cmp } };
				que.push(P(d[e.to].dist, e.to)); st.insert(e.to);
			}
			//今見ている辺を使っても距離が変わらない場合、最後に使った会社に(もしe.cmpがなかったら)e.cmpを追加する
			else if (d[e.to].dist == d[v].dist + cost) {
				if (d[e.to].company.find(e.cmp) == d[e.to].company.end()) {
					d[e.to].company.insert(e.cmp);
					if (st.find(e.to) == st.end()) {
						que.push(P(d[e.to].dist, e.to)); st.insert(e.to);
					}
				}

			}
		}
	}
}

int main() {
	cin >> V >> M;
	int p, q, c;
	for (int i = 0; i < M; i++) {
		scanf("%d %d %d", &p, &q, &c);
		G[p].push_back({ q,c });
		G[q].push_back({ p,c });
	}
	dijkstra(1);
	ll ans = d[V].dist;
	if (ans == INF) {
		cout << -1 << endl; return 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 32024
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;

int main() {
	long long int K;
	string S;
	char ans;
	cin >> S >>K;
	for (int i = 0; i < S.size(); i++)
	{

		if ((S[i] == '1'&&i + 1 == S.size() )|| (i + 1 >= K&&S[i] == '1'))
		{
			ans = '1';
			break;
		}
		if (S[i] != '1')
		{
			ans = S[i];
			break;
		}
	}
	cout << ans;
}

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

void lcs(string s, string t){
	int s1 = s.length();
	int t1 = t.length();
	int arr[s1+1][t1+1];
	for(int i=0; i<=s1; i++){
		for(int j=0; j<=t1; j++){
			if(i==0 || j==0) arr[i][j] = 0;
			else if (s[i-1] == t[j-1]) arr[i][j] = arr[i-1][j-1] + 1;
			else arr[i][j] = max(arr[i-1][j], arr[i][j-1]);
		}
	}
	int last = arr[s1][t1];
	char ans[last+1];
	ans[last] = '\0';
	int i=s1, j=t1;
	while(i>0 && j>0){
		if(s[i-1] == t[j-1]){
			ans[last-1] = s[i-1];
			i--, j--, last--;
		}
		else if (arr[i-1][j] > arr[i][j-1]) i--;
		else j--;
	}
	cout << ans << endl;
}
int main(){
	string s, t;
	cin >> s;
	cin >> t;
	lcs(s, t);
}

Measured memory_bytes: 35456
#include <iostream>
#include <cmath>
#include <algorithm>

#define SIZE 100

using namespace std;

int digitSum(int);

int main(int argc, char const *argv[])
{
    int N, L;
    cin >> N >> L;
    string S[SIZE];
    for(int i=0; i<N; i++){
        cin >> S[i];
    }
    sort(S, S+N);
    string ans;
    for(int i=0; i<N; i++){
        ans += S[i];
    }
    cout << ans;
    return 0;
}

int digitSum(int a){
    if(a==0){
        return 0;
    }
    return a%10 +digitSum(a/10);
}


Measured memory_bytes: 256
<?php
  	fscanf(STDIN, "%d %d", $N, $X);
	$bounds = array_merge(array(0),explode(" ", trim(fgets(STDIN))));
	$boundPoints = array(0);	
	$boundCounts = 0;
	for ($i=1;$i<=$N+1;$i++) {
      	$boundPoints[$i] = $boundPoints[$i-1] + $bounds[$i-1];
      	if ($boundPoints[$i] <= $X) {
          	$boundCounts++;
        } 
    }

	echo $boundCounts;

	

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    vector<int> v(3);
    REP(i,3) cin >> v[i];
    sort(ALL(v));
    int ans = 0;
    ans += v[2] - v[1];
    v[0] += ans;
    if ((v[2] - v[0]) % 2 != 0 ) ans += 2;
    ans += (v[2] - v[0]) / 2;

    cout << ans << endl;


    return 0;
}

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

int main () {
  int n, m, x;
  cin >> n >> m >> x;
  int a[n];
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int sub;
    cin >> sub;
    if (sub < x) {
      ans++;
    }
  }
  ans = (ans > m - ans) ? m - ans : ans;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <cassert>
#ifdef DEBUG
#include "./Lib/debug.hpp"
#else
#define dump(...)
template<class T>inline auto d_val(T a, T b) { return a; }
#endif

/* (=＾o＾=) */
#define int ll

/* macro */
#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define REPI2(it,b,e) for(auto it = (b); it != (e); ++it)
#define REPI(it,c) REPI2(it, (c).begin(), (c).end())
#define RREPI(it,c) REPI2(it, (c).rbegin(), (c).rend())
#define REPI_ERACE2(it, b, e) for(auto it = (b); it != (e);)
#define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end())
#define ALL(x) (x).begin(),(x).end()
#define cauto const auto&
/* macro func */
#define SORT(x) do{sort(ALL(x));}while(false)
#define RSORT(x) do{sort((x).rbegin(),(x).rend());}while(false)
#define UNIQUE(v) do{v.erase( unique(v.begin(), v.end()), v.end() );}while(false)
#define MAX(x,y) do{x = std::max(x,y);}while(false)
#define MIN(x,y) do{x = std::min(x,y);}while(false)
#define BR do{cout<<"\n";}while(false)

/* type define */
using ll = long long;
using PAIR = std::pair<ll, ll>;
using VS = std::vector<std::string>;
using VL = std::vector<long long>;
using VVL = std::vector<VL>;
using VVVL = std::vector<VVL>;
using VD = std::vector<double>;
template<class T>
using V = std::vector<T>;

/* using std */
using std::cout;
constexpr char endl = '\n';
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::unordered_multiset;
using std::multiset;
using std::bitset;
using std::priority_queue;

/* constant value */
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;

/* Initial processing  */
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;

/* Remove the source of the bug */
signed pow(signed, signed) { assert(false); return -1; }

/* define hash */
namespace std { template <>	class hash<std::pair<ll, ll>> { public:	size_t operator()(const std::pair<ll, ll>& x) const { return hash<ll>()(1000000000 * x.first + x.second); } }; }

/* input */
template<class T> std::istream& operator >> (std::istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }

//=============================================================================================


signed main() {
	string str;
	cin >> str;

	cout << str.substr(0, str.size() - string("festival").size()) << endl;
}

Measured memory_bytes: 256
using System;

namespace ABC126_Bbb
{
    class Program
    {
        static void Main(string[] args)
        {
            var yyy = Console.ReadLine();
            var s = yyy.Substring(0, 2);
            var t = yyy.Substring(2, 2);
            var y = int.Parse(s);
            var d = int.Parse(t);
            if ((1 <= y && y <= 12) && (1 <= d && d <= 12))
            {
                Console.WriteLine("AMBIGUOUS");
            }
            else if ((1 <= y && y <= 12) && d > 12)
            {
                Console.WriteLine("MMYY");
            }
            else if ((1 <= d && d <= 12) && y > 12)
            {
                Console.WriteLine("YYMM");
            }
            else if(y == 0 && (1 <= d && d <= 12))
            {
                Console.WriteLine("YYMM");
            }
            else if((1 <= y && y <= 12) && d == 0)
            {
                Console.WriteLine("MMYY");
            }
            else
            {
                Console.WriteLine("NA");
            }
        }
    }
}


Measured memory_bytes: 11092
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n;
    cin >> n;
    vector<string> S(n);
    vector<string::iterator> SI(n);

    REP(i, n)
    {
        cin >> S[i];
        sort(ALL(S[i]));
        SI[i] = S[i].begin();
    }

    char max_char = 'a';
    string sub_string = "", ans = "";
    bool is_continue = true;
    while (is_continue)
    {
        //まず今の位置における最大のアルファベットを求める
        REP(i, n)
        {
            if (max_char < *SI[i])
                max_char = *SI[i];
        }

        //最大値との相違がないか確かめる
        bool is_changed = false;
        REP(i, n)
        {
            if (max_char != *SI[i])
            {
                is_changed = true;
                break;
            }
        }

        //最大値との相違がなければ一つ進める
        if (!is_changed)
        {
            REP(i, n)
            {
                ++SI[i];
            }
            sub_string.PB(max_char);
        }
        //最大値との相違があれば、部分文字列は消滅
        else
        {
            ans += sub_string;
            sub_string = "";
            REP(i, n)
            {
                if (max_char > *SI[i])
                    ++SI[i];
            }
        }

        //いずれかの文字列が最後に到達したら終了
        REP(i, n)
        {
            if (SI[i] == S[i].end())
            {
                ans += sub_string;
                is_continue = false;
                break;
            }
        }
    }

    sort(ALL(ans));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3100
#coding: utf-8

while True:
    x, op, y = map(str, input().split())
    if op == '?':
        break
    a = int(x)
    b = int(y)
    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    else:
        print(a // b)


Measured memory_bytes: 5600
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<list>
#include<set>
using namespace std;
int main(){
  int n;
  int s[22],h[22],c[22],d[22];
  char cord;
  int a;
  cin >> n;
  memset(s,0,sizeof(s));
  memset(h,0,sizeof(h));
  memset(c,0,sizeof(c));
  memset(d,0,sizeof(d));
  for(int i=0;i<n;i++){
      cin >> cord >> a;
      if(cord=='S'){
        s[a]=1;
      }else if(cord=='H'){
        h[a]=1;
      }else if(cord=='C'){
        c[a]=1;
      }else if(cord=='D'){
        d[a]=1;
      }
  }
  for(int i=1;i<=13;i++){
      if(s[i]==0){
          cout << "S " << i << endl;
      }
  }
  for(int i=1;i<=13;i++){
      if(h[i]==0){
          cout << "H " << i << endl;
      }
  }
  for(int i=1;i<=13;i++){
      if(c[i]==0){
          cout <<"C " << i << endl;
      }
  }
  for(int i=1;i<=13;i++){
      if(d[i]==0){
          cout <<"D " << i << endl;
      }
  }

  return 0;
}




Measured memory_bytes: 3116
import sys
from collections import deque

readline = sys.stdin.buffer.readline
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


def solve():
    n, Q = nm()
    G = [list() for _ in range(n)]
    for _ in range(n-1):
        u, v = nm()
        u -= 1; v -= 1
        G[u].append(v)
        G[v].append(u)
    a = [0]*n
    for _ in range(Q):
        p, x = nm()
        a[p-1] += x
    q = deque()
    q.append(0)
    seen = [1] + [0]*(n-1)
    while q:
        v = q.popleft()
        for x in G[v]:
            if not seen[x]:
                seen[x] = 1
                a[x] += a[v]
                q.append(x)
    print(*a)
    return

solve()

# T = ni()
# for _ in range(T):
#     solve()


Measured memory_bytes: 56144
def calc(x, base):
    res = 0
    while x:
        x, m = divmod(x, base)
        res += m
    return res


def main():
    N = int(input())
    ans = min(calc(i, 6) + calc(N - i, 9) for i in range(N + 1))
    print(ans)


main()


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <vector>

typedef long long ll;

#define debug(x) cerr << #x << ": " << x << "\n";
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;

int c[15], a[15][15];

int main(){
  int N,M,X;
  cin >> N >> M >> X;
  rep(i,N){
    cin >> c[i];
    rep(j,M){
      cin >> a[i][j];
    }
  }

  int ans = 1e+9;
  for(int bit = 0; bit <= (1<<N); bit++){
    vector<int> v(N);
    rep(i,N){
      if(bit & (1<<i)) v[i] = 1;
    }
    vector<int> w(M);
    int now = 0;
    rep(j,N){
      if(v[j]){
        rep(k,M){
          w[k] += a[j][k];
        }
        now += c[j];
      }
    }
    bool ok = true;
    rep(i,M){
      if(w[i] < X) ok = false;
    }
    if(ok) ans = min(ans,now);
  }
  if(ans == 1e+9) cout << -1 << endl;
  else cout << ans << endl;
}
      


Measured memory_bytes: 3616
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
int dp[3005][3005];
string s,t;
int main()
{
	cin>>s;
	cin>>t;
	
	int d1=s.length(),d2=t.length();
	memset(dp,0,sizeof(dp));
	for(int i=d1;i>0;i--){
        for(int j=d2;j>0;j--){
            if(s[i-1]==t[j-1])
                dp[i][j]=dp[i+1][j+1]+1;
            else
                dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
        }
    }

    int flag=0;
	for(int i=1,j=1;i<=d1&&j<=d2;i++,j++){
		if(s[i-1]==t[j-1])
			cout<<s[i-1],flag=1;
		else if(dp[i][j]==dp[i+1][j])
		    j--;
		else 
		    i--;
    }
    
//	if(!flag)
//	cout<<"The answer is (an empty string).\n";
}

Measured memory_bytes: 38900
using System;

namespace ABC144B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= 9; j++)
                {
                    if(i*j==N)
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }
            }
            Console.WriteLine("No");
        }
    }
}


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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	
	vector<vector<char> > c(h,vector<char>(w));
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			cin >> c[i][j];
		}
	}
	
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < 2; j++)
		{
			for(int k = 0; k < w; k++)
			{
				cout << c[i][k];
			}
			cout << endl;
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
#define VLCIN(a, n) REP(i,n){cin >> a[i];}
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = (ll)pow(10,7);
/****** define constant end ********/
/****** define variable start ******/
ll n, m, l;
vl a, b, c;
ll q;
vl s, t;
Graph G;
/******* define variable end *******/
vector<vector<ll>> d;

void warshall_floyd(){
	for(ll k = 0; k < n; k++){
		for(ll i = 0; i < n; i++){
			for(ll j = 0; j < n; j++){
				if(i == j){
					d[i][j] = 0;
					d[j][i] = 0;
				}else{
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
	}
}
vector<vector<ll>> d2;

void warshall_floyd2(){
	for(ll k = 0; k < n; k++){
		for(ll i = 0; i < n; i++){
			for(ll j = 0; j < n; j++){
				if(i == j){
					d2[i][j] = 0;
					d2[j][i] = 0;
				}else{
					d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
				}
			}
		}
	}
}
int solve() {
	cin >> n >> m >> l;
	RES(a, m);
	RES(b, m);
	RES(c, m);
	RES(G, n);
	d.resize(n, vl(n, INF));
	REP(i, n){
		d[i][i] = 0;
	}
	REP(i, m){
		cin >> a[i] >> b[i] >> c[i];
		Edge e = {b[i]-1, c[i]};
		Edge e2 = {a[i]-1, c[i]};
		G[a[i]-1].push_back(e);
		G[b[i]-1].push_back(e2);
		d[a[i]-1][b[i]-1] = c[i];
		d[b[i]-1][a[i]-1] = c[i];
	}
	warshall_floyd();
	Graph G2(n);
	d2.resize(n, vl(n, INF));
	REP(i, n){
		d2[i][i] = 0;
	}
	REP(i, n){
		REP(j, n){
			if(d[i][j] <= l){
				Edge e = {j, 1};
				Edge e2 = {i, 1};
				G2[i].push_back(e);
				G2[j].push_back(e2);
				d2[i][j] = 1;
				d2[j][i] = 1;
			}
		}
	}
	warshall_floyd2();
	cin >> q;
	RES(s, q);
	RES(t, q);
	REP(i, q){
		cin >> s[i] >> t[i];
		if(d2[s[i]-1][t[i]-1] == INF){
			cout << -1 << endl;
		}else{
			cout << d2[s[i]-1][t[i]-1] - 1<< endl;
		}
	}

	return 0;
}
int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 13984