akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int h, w, k;
  cin >> h >> w >> k;
  int black = 0;
  vector<vector<int>> a(7, vector<int>(7,-100));
  rep(i,h){
    rep(j,w){
      char z;
      cin >> z;
      if(z == '#'){
        a[i+1][j+1] = 1;
        black++;
      }
      else{
        a[i+1][j+1] = 0;
      }
    }
  }
  
   
  vector<int> tate(7,-100);
  vector<int> yoko(7,-100);
  rep(i,h){
    int k = 0;
    rep(j,w){
      k += a[i+1][j+1];
    }
    tate[i+1] = k;
  }
  rep(i,w){
    int k = 0;
    rep(j,h){
      k += a[j+1][i+1];
    }
    yoko[i+1] = k;
  }
  
  int ans = 0;
  
  for (int x = 0; x < (1 << 7); x++) {
   for (int y = 0; y < (1 << 7); y++) {
    bitset<7> s(x);
    bitset<7> t(y);
      
    int sum = 0;
    for (int i = 0; i < h + 1; i++) {
      if (s.test(i)) {
        sum += tate[i];
      }
    }
    
    for (int i = 0; i < w + 1; i++) {
      if (t.test(i)) {
        sum += yoko[i];
      }
    }
    for (int i = 0; i < h + 1; i++) {
      for (int j = 0; j < w + 1; j++) {
        if (s.test(i) && t.test(j)) {
          if(a[i][j] == 1){
            sum = sum - 1;
          }
        }
      }
    }
      
    if(black - sum == k){
      ans++;
    }
      
    }
  }
  int num;
  num = 12 - (h + w);
  int two = 1;
  if(num == 0){
  }
  else{
  rep(i,num){
    two = two * 2;
  }
  }
  
  cout << ans / two;
  
  return 0;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<cstring>
#include<cassert>
#include<iostream>
#include<algorithm>

using namespace std;

#define Whats(x) cout<<#x<<" is "<<(x)<<endl
#define Divhim() cout<<">>>>>>>>>>>>>>>"<<endl
#define Divher() cout<<"<<<<<<<<<<<<<<<"<<endl
#define Oops() cout<<"!!!!!!!!!!!!!!!"<<endl

template<typename T> bool GetMin(T &a,T b)
{
	return ((a<=b)?false:(a=b,true));
}

template<typename T> bool GetMax(T &a,T b)
{
	return ((a>=b)?false:(a=b,true));
}

/*
	 -<Unlimited Blade Works>-
 */

const int N=3333;
const int MOD=1e9+7;

void SU(int &x,int y)
{
	((x+=y)>=MOD)&&(x-=MOD);
}

int n;
char s[N];
int f[N];

int main()
{
	scanf("%d%s",&n,s+2);
	f[1]=1;
	for(int i=2;i<=n;++i)
	{
		if(s[i]=='>')
		{
			for(int j=2;j<i;++j)
				SU(f[j],f[j-1]);
			for(int j=i;j>=2;--j)
				f[j]=f[j-1];
			f[1]=0;
		}
		else
		{
			for(int j=i-2;j>=1;--j)
				SU(f[j],f[j+1]);
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i)
		SU(ans,f[i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N; cin >> N;
    bool S[13],H[13],C[13],D[13];
    rep(i,13){
        S[i]=H[i]=C[i]=D[i]=false;
    }
    rep(i,N){
        char c; int a; cin >> c >> a;
        a--;
        if(c=='S') S[a]=true;
        if(c=='H') H[a]=true;
        if(c=='C') C[a]=true;
        if(c=='D') D[a]=true;
    }
    rep(i,13) if(!S[i]) cout << 'S' << " " << i+1 << endl; 
    rep(i,13) if(!H[i]) cout << 'H' << " " << i+1 << endl; 
    rep(i,13) if(!C[i]) cout << 'C' << " " << i+1 << endl; 
    rep(i,13) if(!D[i]) cout << 'D' << " " << i+1 << endl; 

    return 0;
}


Measured memory_bytes: 3096
n,m,x = map(int,input().split())
c,a = [],[]
for _ in range(n):
    l = list(map(int,input().split()))
    c.append(l[0])
    a.append(l[1:])
ans = float("inf")
for i in range(2**n):
    e = [0 for _ in range(m)]
    okane = 0
    for j in range(n):
        if (i >> j) & 1:
            katta = a[j]
            okane += c[j]
            for k in range(m):
                e[k] += katta[k]
    f = min(e)
    if f >= x:
        ans = min(ans,okane)
if ans == float("inf"):
    print(-1)
else:
    print(ans)

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a.at(i);
    int preX = 0;
    int X = 0;
    int postX = 0;
    int count_max = 0;
    sort(a.begin(),a.end());
    int j = 0;
    for (int i = 0; i < N; i++) {
        if (a.at(i) == j) postX++;
        else if (a.at(i) > j) {
            if (preX + X + postX > count_max) count_max = preX + X + postX;
            preX = X;
            X = postX;
            postX = 0;
            i--;
            j++;
        }
        if (i == N - 1 && preX + X + postX > count_max) count_max = preX + X + postX;
    }
    cout << count_max << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;


ll n;
ll dp[22][(1LL << 22)+1];
const ll mod = 1e9 + 7;
ll women[22];
ll solve(ll id, ll mask)
{
        if(id == n) {
                if(mask == 0) return 1LL;
                return 0;
        }
        ll &ret = dp[id][mask];
        if(ret != -1) return ret;
        ll canTake = women[id]&mask;
        ret=0;
        for(ll j=0;j<n;j++){
                if(canTake&(1LL<<j)){
                        ret = (ret + solve(id+1 , (mask^(1LL << j))))%mod;
                }
        }
        return ret;
}
int main()
{
        cin >> n;
        memset(dp,-1,sizeof dp);
        ll wo = (1LL << n)-1;
        for(ll i=0;i<n;i++) {
                ll x = 0;
                for(ll j=0;j<n;j++) {
                        ll k;
                        cin >> k;
                        if(k) x |= (1LL << j);
                }
                women[i]=x;
        }
        cout << solve(0,wo) << endl;
        return 0;
}


Measured memory_bytes: 721152
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    def divisor(n):
        res = []
        for i in range(1, int(np.sqrt(n)) + 1):
            if n % i == 0:
                res.append(i)
                j = n // i
                if j != i:res.append(j)
        res.sort(reverse = True)
        return res[::-1]
    n = int(input())
    div1 = divisor(n - 1)
    div2 = divisor(n)
    ans = len(div1) - 1
    for d in div2:
        if d == 1: continue
        nn = n
        while nn % d == 0:
            nn //= d
        if nn % d == 1:
            ans += 1

    print(ans)

if __name__ == "__main__":
    main() #endline===============================================

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

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int (i)=(a);(i)<(b);++(i))
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cout<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<char> vc;
typedef vector<vector<int>> vii;
typedef vector<vector<lint>> vll;
typedef vector<vector<char>> vcc;

class B754 {
public:
    string S;

    void input(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in>>S;
    }

    void solve(std::istream& in, std::ostream& out){
        input(in, out);
        int ans = (int)1e9;
        REP(i, LEN(S)-2){
            int num = 100*(S[i]-'0')+10*(S[i+1]-'0')+(S[i+2]-'0');
            ans = min(ans, abs(num-753));
        }
        out<<ans<<'\n';
    }
};


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


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i).sort
Y = "Yes"
N = "No"

if a[0] + 1 < a[-1]
    puts N
elsif a[0] + 1 == a[-1]
    x = a.index(a[-1])
    y = n - x

    s = a[0] - x + 1
    t = a[-1] - y + 1
    puts (s > 0 && s <= y / 2) || (t > 0 && t <= x / 2) ? Y : N
else
    puts a[0] == n - 1 || a[0] <= n / 2 ? Y : N
end

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

const int N = 2e3 + 100;

int n, w[N], b[N];
int dp[N][N];
int cw[N][N], cb[N][N];

int main() {
  char s[5];
  scanf("%d", &n);
  for (int i = 1; i <= 2 * n; i++) {
    int x;
    scanf("%s %d", s + 1, &x);
    if (s[1] == 'W') {
      w[x] = i;
    } else {
      b[x] = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if (w[i] < w[j]) {
        cw[i][0]++;
      }
    }
    for (int j = 1; j <= n; j++) {
      cw[i][j] = cw[i][j - 1];
      if (w[i] < b[j]) {
        cw[i][j]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if (b[i] < b[j]) {
        cb[0][i]++;
      }
    }
    for (int j = 1; j <= n; j++) {
      cb[j][i] = cb[j - 1][i];
      if (b[i] < w[j]) {
        cb[j][i]++;
      }
    }
  }
  int c1 = 0, c2 = 0;
  for (int i = 1; i <= n; i++) {
    c1 += cw[i][0];
    c2 += cb[0][i];
    dp[i][0] = c1;
    dp[0][i] = c2;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = min(dp[i - 1][j] + cw[i][j], dp[i][j - 1] + cb[i][j]);
    }
  }
  printf("%d\n", dp[n][n]);
  return 0;
}

Measured memory_bytes: 51584
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint comb(int a, int b){
	mint ans = 1;
	for(ll i = 1; i <= b; i++){
		ans = ans * (a - i + 1) / i;
	}
	return ans;
}

int main(){
	int n, k;
	cin >> n >> k;
	rep2(i, 1, k+1){
		mint a1, a2;
		a1 = comb(n-k+1, i);
		a2 = comb(k-1, i-1);
		mint ans;
		ans = a1 * a2;
		cout << ans.x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
N,M = map(int,input().split())
d = defaultdict(lambda:1)

for i in range(M):
    a = int(input())
    d[a] = 0

mod = 10**9+7
dp = [0]*(N+1)
dp[0] = 1
dp[1] = d[1]
for i in range(N-1):
    dp[i+2] = dp[i+1] + dp[i]
    dp[i+2] *= d[i+2]
    dp[i+2] %= mod
print(dp[N])

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const ll mod = 1e9 + 7;
const ll inf = ll(4e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
    if (n == 0)return 1;
    if (n % 2 == 0)return modexp((x * x) % md, n / 2, md);
    return (x * modexp((x * x) % md, n / 2, md)) % md;
}
int n;
pair<ll,pii>a[15];
ll ans[16];
int ax[16]={0},ay[16]={0},countx=0,county=0;
void road(int i){
    if(i==n){
        int count=countx+county;
        ll curr=0;
        f(i,0,n){
            ll curr1=inf;
            f(j,0,countx+1){
                curr1=min(curr1,a[i].first*abs(ax[j]-a[i].second.first));
            }
            ll curr2=inf;
            f(j,0,county+1){
                curr2=min(curr2,a[i].first*abs(ay[j]-a[i].second.second));
            }
            curr+=min(curr1,curr2);
            if(curr>ans[count])return;
        }
        ans[count]=curr;
        return;
    }
    road(i+1);
    ++countx;ax[countx]=a[i].second.first;
    road(i+1);
    --countx;
    ++county;ay[county]=a[i].second.second;
    road(i+1);
    --county;
}
int main() {
    fastio;
    // clock_t tm = clock();
    cin>>n;
    f(i,0,n){
        cin>>a[i].second.first>>a[i].second.second>>a[i].first;
    }
    sort(a,a+n);
    f(i,0,n+1)ans[i]=inf;
    road(0);
    f(i,0,n+1)cout<<ans[i]<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    string s;cin >> s;
    int l= 0,r = 0;
    int n = s.size();
    int ans = 0;
    rep(i,n){
        int nextl = i,nextr = n;
        while(l < nextl){
            l++;
        }
        if(r < l)r = l;
        while(r < nextr){
            if(s[r] =='A'|| s[r] == 'T'||s[r] == 'G'||s[r] == 'C')r++;
            else break;
            
        }
        ans = max(ans,r-l);
    }
    cout << ans << endl;
    return 0;
}

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

int n,m;
const long long mod=1e9 + 7;
char mat[1005][1005];
long long rj[1005][1005];

int main () {
	
	cin>>n>>m;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cin>>mat[i][j];
		}
	}
	int r=0; 
	while(r<n && mat[r][0]!='#'){
		rj[r][0]=1;
		r++;
	}
	r=0;
	while(r<m && mat[0][r]!='#'){
		rj[0][r]=1;
		r++;
	}
	for(int i=1; i<n; i++){
		for(int j=1; j<m; j++){
			if(mat[i][j]!='#'){
				rj[i][j]=rj[i-1][j];
				rj[i][j]+=rj[i][j-1];
				rj[i][j]=rj[i][j]%mod;
			}
		//	cout<<rj[i][j]<<" ";
		}
		//cout<<endl;
	}
	/*for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cout<<rj[i][j]<<" ";
		}
		cout<<endl;
	}*/
	cout <<rj[n-1][m-1];
	
	return 0;
}

Measured memory_bytes: 9088
using System;

namespace ALDS1_3_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] initial = input.Split(' ');
            int N = int.Parse(initial[0]);
            int quantum = int.Parse(initial[1]);
            string[] name_in = new string[N];
            int[] time_in = new int[N];

            string[] name_out = new string[N];
            int[] time_out = new int[N];
            int finish = 0;
            int count = 0;
            int current = 0;

            for (int i = 0; i < N; i++)
            {
                input = Console.ReadLine();
                string[] tmp = input.Split(' ');
                name_in[i] = tmp[0];
                time_in[i] = int.Parse(tmp[1]);
                finish += time_in[i];
            }

            while (current < finish)
            {
                for (int i = 0; i < N; i++)
                {
                    if (time_in[i] == 0) continue;
                    if (time_in[i] > quantum)
                    {
                        time_in[i] -= quantum;
                        current += quantum;
                    } else
                    {
                        current += time_in[i];
                        time_in[i] = 0;
                        name_out[count] = name_in[i];
                        time_out[count] = current;
                        count++;
                    }
                }
            }

            for (int i = 0; i < N; i++)
            {
                Console.WriteLine("{0} {1}", name_out[i], time_out[i]);
            }
        }
    }
}

Measured memory_bytes: 15248
#include<iostream>
using namespace std;
int n;
int main(){
  cin >> n;
  int a=n,x=0;
  bool f=true;
  while(f){
    if(a<10) f=false;
    x+=a%10;
    a/=10;
  }
  if(n%x==0) cout << "Yes\n";
  else cout << "No\n";

  
  return 0;
}


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

typedef pair<int, int> P;

int main() {

    ll n;
    cin >> n;

    ll tmp;
    ll ans = 1e13;
    for(ll i = 1; i <= sqrt(n); i++){
        if(n%i==0){
            tmp = n/i;
            ans = min(ans,(i-1+tmp-1));
        }
    }

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

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m; cin>>n>>m;
    int N = n;
    vector<int> a(n);
    vector<P > p(m);
    REP(i,n){
        cin>>a[i];
    }
    sort(all(a));
    REP(i,m){
        cin>>p[i].second>>p[i].first;
    }
    sort(all(p));
    int j = m-1;
    REP(i,n){
        if(a[i]<p[j].first&&p[j].second!=0){
            a[i]=p[j].first;
            p[j].second--;
            continue;
        } else if(p[j].second==0){
            if(j>0) j--;
            else break;
            if(a[i]<p[j].first&&p[j].second>0){
                a[i]=p[j].first;
                p[j].second--;
            }
            else if(a[i]<p[j].first) break; 
        } 
    }
    lint ans = 0;
    REP(i,n){
        //print(a[i]);
        ans+=a[i];
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 1408
import java.util.*;
import java.util.stream.*;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    
    List<Integer> numList = new ArrayList<>();
    
    while(sc.hasNextInt()){
      numList.add(sc.nextInt());
    }
    
    System.out.println(new HashSet<>(numList).size());
  }
 
}

Measured memory_bytes: 21716
import collections

x = input()
TF =  x.isupper() and x.isalpha()
flg  = 0
if(TF):
    li = [i for i in x]
    count_dict = collections.Counter(li)
    list = [v for k, v in count_dict.items()]
    if(list == [2,2]):
        print("Yes")
        flg = 1
if(flg == 0):
    print("No")

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll INF = 1LL << 60;
const ll MOD = (ll) 1e9 + 7;

int main(){
    ll n, k;
    cin >> n >> k;
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        m[a]++;
    }
    vector<int> v;
    for (auto&& x : m) {
        v.push_back(x.second);
    }
    sort(v.begin(), v.end());
    int ans = 0;
    int kind = m.size();
    for (int i = 0; i < kind - k; i++) {
        ans += v[i];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 10748
o = input()
e = input()

ans = ''.join(map(lambda a: a[0] + a[1], zip(o, e)))

# ans = ''
# for i in range(len(e)):
#     ans += o[i] + e[i]

if len(o) == len(e):
    print(ans)
else:
    ans += o[-1]
    print(ans)




Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
using namespace std;
const int MOD=1000000007;
int n,k;
long long fac[2001]={1},inv[2001]={1};
inline long long power(long long a,long long b,long long P)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%P;
		b>>=1,a=a*a%P;
	}
	return res;
}
long long C(long long n,long long m)
{
	if(n<m) return 0;
	if(m==0) return 1;
	return fac[n]*inv[n-m]%MOD*inv[m]%MOD;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%MOD;
	inv[n]=power(fac[n],MOD-2,MOD);
	for(int i=n-1;i>0;i--)
		inv[i]=inv[i+1]*(i+1)%MOD;
	for(int i=1;i<=k;i++)
		printf("%lld\n",C(k-1,i-1)*C(n-k+1,i)%MOD);
	return 0;
}

Measured memory_bytes: 256
using System;

class Program{
    public static void Main(){
        var s=Console.ReadLine().Split(' ');
        var a=int.Parse(s[0]);
        var b=int.Parse(s[1]);
        while(a%b!=0){
            var tmp=b;
            b=a%b;
            a=tmp;
        }
        Console.WriteLine(b);
    }
}

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

using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> edges(n - 1);
    vector<vector<int>> tree(n + 1);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        edges[i] = make_pair(a, b);
        tree[a].emplace_back(b);
        tree[b].emplace_back(a);
    }

    int mx = 0;
    map<pair<int, int>, int> colors;
    vector<int> cs(n + 1, 0);
    vector<bool> used(n + 1, false);
    queue<int> q;
    used[1] = 1;
    q.emplace(1);
    while (!q.empty()) {
        int front = q.front();
        q.pop();
        mx = max(mx, (int)tree[front].size());
        int cur = 1;
        for (auto v: tree[front]) {
            if (used[v]) {
                continue;
            }
            if (cur == cs[front]) {
                cur++;
            }
            cs[v] = cur;
            colors[make_pair(front, v)] = cur;
            colors[make_pair(v, front)] = cur;
            cur++;
            used[v] = true;
            q.emplace(v);
        }
    }
    cout << mx << endl;
    for (auto e: edges) {
        cout << colors[e] << endl;
    }
    return 0;
}


Measured memory_bytes: 19712
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define ll long long
using namespace std;
 
int main() {
  int n, x;
  cin >> n >> x;
  int a[110];
  a[0] = 0;
  for (int i = 1; i <= n; i++) {
    int l;
    cin >> l;
    a[i] = a[i - 1] + l;
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (a[i] <= x) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//k_k_dubey_
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define mx 500005
#define non __builtin_popcount
#define ml map<ll, ll> 
#define uml unordered_map<ll, ll>
#define ms map<string , ll> 
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define pl pair<ll, ll>
#define vl vector<ll>
#define vll vector<pl>
#define tpl pair<pl, ll>
#define vlll vector<tpl>
#define vs vector<string>
#define pb push_back
#define mk make_pair
#define M_PI 3.14159265358979323846
#define endl '\n'
#define fst ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%I64d",&x)
#define inf ((ll)1e18 + 1)
#define bs binary_search
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define pow powr
#define rep(i,a,b)  for (i=(a);i<(b);i++)
#define nrep(i,a,b) for (i=(a);i>(b);i--)
using namespace std;
 
bool isp[mx];
 
void sv(){
 
	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}
 
ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

void bta_de_yarr(){
    
	ll  i, j,n, a[mx];
	cin>>n;
    
    ll ans=0;
    if(!(n &1)){

        n>>=1;

        while(n){
            ans+= (n/5);
            n/=5;
        }
    }
    cout<<ans;

	cout<<endl;
}

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

ll inv(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main(){
  ll X,Y;
  cin >>X>>Y;
  const int mod = 1000000007;
  if((X+Y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }
  ll x = (2*X-Y)/3;
  ll y = (-X+2*Y)/3;
  if(x<0 || y<0){
    cout << 0 << endl;
    return 0;
  }
  vector<ll> fact(x+y+1);
  fact[0] = 1;
  rep1(i,x+y) fact[i] = (fact[i-1]*i)%mod;
  ll inv1 = inv(fact[x],mod-2,mod);
  ll inv2 = inv(fact[y],mod-2,mod);
  ll ans = fact[x+y];
  ans = ans*inv1%mod;
  ans = ans*inv2%mod;
  cout << ans << endl;
}


Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long 
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
signed main() {
	string a, b;
	cin >> a >> b;
	if (a.size() < b.size())puts("LESS");
	else if (a.size() > b.size())puts("GREATER");
	else {
		for (int i = 0; i < a.size(); i++) {
			if (a[i] - '0' < b[i] - '0') {
				puts("LESS");
				return 0;
			}
			if (a[i] - '0' > b[i] - '0') {
				puts("GREATER");
				return 0;
			}
		}
		puts("EQUAL");
	}
	getchar(); getchar(); return 0;
}

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

int main(){
  int N; cin >> N;
  vector<int> dict(N); // 文字列と出現回数の辞書作成

  for (int i=0; i < N; i++) { // 辞書内の文字列xに対応する出現回数を+1する
    int x ;
    cin >> x; // 文字列 x 入力
    dict.at(x)++;
  }
  
  int length;
    for (int i=0; i < N; i++) { 
      if (dict.at(i)){
        length = i;
      }
  }
  int ng_flag = 0;
  if(length%2 == 0){
    for(int i = length; i > length/2 ; i--){
      if(dict.at(i) <= 1){
        ng_flag = 1;
      }
    }
    if(dict.at(length/2)!=1){
      ng_flag = 1;
    }
    for(int i = 0; i < length/2 ; i++){
      if(dict.at(i)){
        ng_flag = 1;
      }
      } 
  }else{
    for(int i = length; i > (length+1)/2 ; i--){
      if(dict.at(i) <= 1){
        ng_flag = 1;
      }
    }
    if(dict.at((length+1)/2)!=2){
      ng_flag = 1;
    }
    for(int i = 0; i < (length+1)/2 ; i++){
      if(dict.at(i)){
        ng_flag = 1;
      }
    }
  }
  if(ng_flag){
    cout << "Impossible" << endl;
  } else {
    cout << "Possible" << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionL
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            
            // 整数配列の入力
            var n = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            if (n[0] > n[1]) Console.WriteLine("safe");
            else if (n[0] <= n[1]) Console.WriteLine("unsafe");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28232
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

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

const LL  INF=1<<31;



int main(){
     int a[6];
          int ans[4]={0};
     for(int i=0;i<6;++i){
          cin>>a[i];
          ans[a[i]-1]++;
     }
     int ans1=0;
     for(int i=0;i<4;++i){
          if(ans[i]==2)ans1++;
     }

     

     if(ans1==2)cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int man;
int to(int a)//二进制一的个数
{
	int sum =0; 
	for(int i=0;i<man;i++)
	{
		if(a&(1<<i))sum++;
	}
	return sum;
} 
/*
3
1
2 1
1
1 1
1
2 0
*/
map<int,vector<pair<int,int>>> mp;//谁说的话，说话对象，是诚实/不善良的人 
bool isok(int a)
{
	for(int i=0;i<man;i++)
	{
		if(a&(1<<i))//如果A说这是一个诚实的人，进去。 
		{
			vector<pair<int,int>> k = mp[i];//拿到说话对象和身份 
			for(int j=0;j<k.size();j++)
			{
				int tmp = k[j].second;//MP说的身份 
				int t = 0;
				if(a&(1<<k[j].first))t=1;
				else t=0;//A说的身份 
				if(tmp!=t)//如果有矛盾，就不是能够匹配的 
				{
					return false;
				}
			}
		}
	}
	return true;
}
int main()
{
	cin>>man;
	for(int i=0;i<man;i++)
	{
		int task;//有多少个证据 
		cin>>task;
		for(int j=0;j<task;j++)
		{
			int a,b;
			cin>>a>>b;//证据的对象和身份 
			a--;
			mp[i].push_back(make_pair(a,b));
		}
	}
	vector<int> ans;
	int sum = -1;//求出最多有多少个诚实的人。 
	for(int i=0;i<pow(2,15);i++)
	{
		if(isok(i))
			if(to(i)>sum)
			{
				sum = to(i);
//				cout<<i<<endl;
			}
	}
	//输出 
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,num,mem = -1,now = -1,str[100000] = {0},sum = 0,ans = 0;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&num);
        if(mem != ((i % 2) == num))
        {
            mem = ((i % 2) == num);
            now++;
            str[now]++;
        }
        else str[now]++;
    }
    if(now + 1 < 3)
    {
        for(int i = 0; i < now + 1; i++)ans = ans + str[i];
        printf("%d\n",ans);
    }
    else
    {
        for(int i = 0; i < 3; i++)sum =sum + str[i];
        ans = sum;
        for(int i = 3; i < now + 1; i++)
        {
            sum = sum + str[i] - str[i - 3];
            ans = max(ans,sum);
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  rep(i,S.size()){
    int x = S[i] - 'A';
    x += N;
    x %= 26;
    S[i] = (char)('A' + x);
  }

  cout << S << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0;i <n;i++)
#define RFOR(i, n) for(int i = n;i >= 0;i--)
#define REP(i, m, n) for(int i = m;i < n;i++)
#define RREP(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999

using namespace std;
int main(int argc, char const *argv[])
{
 int a,b,h,s;
 cin >>a>>b>>h;
 s = (a+b)*h;
 cout<<s/2<<endl;

return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int x;
    cin >> x;
    if (x >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3568
#include <stdio.h>
#include <stdlib.h>

long long int printGCD(long long int v1, long long int v2) {
	long long int a, b, r;

	if(v1 > v2) {
		a = v1;
		b = v2;
	}
	else {
		a = v2;
		b = v1;
	}

	while(b != 0) {
		r = a % b;
		a = b;
		b = r;
	}

	return a;
}
long long int printLCM(long long int v1, long long int v2) {
	long long int a, b, GCD;

	a = v1;
	b = v2;
	GCD = printGCD(a, b);

	return (long long int)(a / GCD * b);
}

int main(void) {
	long long int array[100];
	int N, i;

	scanf("%d", &N);
	for(i = 0; i < N; i++) {
		scanf("%lld", &array[i]);
	}

	for(i = 0; i < N-1; i++) {
		array[i+1] = printLCM(array[i], array[i+1]);
	}

	printf("%lld", array[i]);

	return EXIT_SUCCESS;
}

Measured memory_bytes: 128
# https://atcoder.jp/contests/abc161/tasks/abc161_a

X, Y, Z = gets.split.map(&:to_i)

ans = [X, Y, Z]
ans[0], ans[1] = ans[1], ans[0]
ans[0], ans[2] = ans[2], ans[0]
puts ans.join(' ')


Measured memory_bytes: 14392
import itertools
n = int(input())

po = {}

for i in range(n):
  ai = int(input())
  po_dict = {}
  for j in range(ai):
    x,y = map(int, input().split())
    po_dict[x-1]=y
  po[i]=po_dict

#print(po)
  
def check(lis):
  for i, yi in enumerate(lis):
    if yi==1:
      #print(po[i])
      for k,v in po[i].items():
        if lis[k]!=v:
          return False
  return True

ys=[0,1]
max_t=0
for lis in itertools.product(ys,repeat=n):
  if check(lis):
    if max_t <sum(lis):
      max_t = sum(lis)

print(max_t)

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


int main(void){
    // Your code here!
   int A;
   cin >> A;
   int a,b,c,d;
   a = A % 10;
   A /= 10;
   b = A % 10;
   A /= 10;
   c = A % 10;
   A /= 10;
   d = A % 10;
   if(d+c+b+a==7){
       cout << d << "+" << c << "+" << b << "+" << a << "=" << 7 << endl;
   }
   else if(d+c+b-a==7){
       cout << d << "+" << c << "+" << b << "-" << a << "=" << 7 << endl;
   }
   else if(d+c-b+a==7){
       cout << d << "+" << c << "-" << b << "+" << a << "=" << 7 << endl;
   }
   else if(d+c-b-a==7){
       cout << d << "+" << c << "-" << b << "-" << a << "=" << 7 << endl;
   }
   
   else if(d-c+b+a==7){
       cout << d << "-" << c << "+" << b << "+" << a << "=" << 7 << endl;
   }
   else if(d-c+b-a==7){
       cout << d << "-" << c << "+" << b << "-" << a << "=" << 7 << endl;
   }
   else if(d-c-b+a==7){
       cout << d << "-" << c << "-" << b << "+" << a << "=" << 7 << endl;
   }
   else if(d-c-b-a==7){
       cout << d << "-" << c << "-" << b << "-" << a << "=" << 7 << endl;
   }
   
   
}


Measured memory_bytes: 256
using System;

    class Program
    {
        static void Main(string[] args)
        {
            int n;

            string num = Console.ReadLine();
            n = int.Parse(num);

            for (int i = 1; i <= n ; i++)
            {
                if (i % 3 == 0 || i % 10 == 3 || i % 100 / 10 == 3 || i % 1000 / 100 == 3 || i % 10000 / 1000 == 3)
                {
                    Console.Write(" " + i);
                }     
            }
            Console.WriteLine("");
        }
    }



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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int main(void) {
    string s = in<string>();
    int K = in();
    int N = s.size();
    VI xs(N);
    rep(i, N) xs[i] = s[i] - 'a';

    for (int i = 0; i < N && K; i++) {
        if (!xs[i]) { continue; }
        int p = 26 - xs[i];
        if (p <= K) {
            xs[i] = 0;
            K -= p;
        }
    }

    xs[N - 1] = (xs[N - 1] + K) % 26;

    rep(i, N) cout << ((char)(xs[i] + 'a'));
    cout << endl;

    return 0;
}



Measured memory_bytes: 896
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()
for i in range(N):
    A[i] -= i
A.sort()
print(sum(abs(A[i]-A[N//2]) for i in range(N)))


Measured memory_bytes: 94476
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

using ull_t = unsigned long long;


bool is_kaibun(const string &s)
{
#ifdef DEBUG
    cerr << "s = " << s << endl;
#endif
    
    int N = s.length();
    if (N > 1)
    {
        for (int i = 0; i < (N / 2); ++i)
        {
            if (s.at(i) != s.at(N - 1 - i))
                return false;
        }
    }
    return true;
}


bool judge(const string &S)
{
    int N = S.length();
    
    if (not is_kaibun(S)) return false;
    if (not is_kaibun(S.substr(0, N/2))) return false;
    if (not is_kaibun(S.substr(1 + N/2, N/2))) return false;

    return true;
}


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

    cout << (judge(S) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
data = [
    [[0 for r in range(10)] for f in range(3)] for b in range(4)
]

# ??\??????????????????????????§????????????????????????????????????
count = int(input())
for c in range(count):
    b, f, r, v = [int(i) for i in input().split()]
    data[b-1][f-1][r-1] += v

for bi, b in enumerate(data):
    for f in b:
        for r in f:
            print(' {0}'.format(r), end='')

        print()
    if bi < 3:
        print('#' * 20)

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

int main() {
    string S;cin >> S;
    set<char> st;
    for (auto c : S) {
        st.insert(c);
    }
    if (st.size() == 1) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 100;
    for (char key = 'a'; key <= 'z'; key++) {
        string s = S;
        bool is_unmatch = true;
        int count = 1;
        while (is_unmatch) {
            string tmp_s;
            is_unmatch = false;
            for (int i = 0; i < s.size()-1; i++) {
                if (s[i] == key || s[i+1] == key) tmp_s.push_back(key);
                else {
                    is_unmatch = true;
                    tmp_s.push_back(s[i]);
                }
            }
            if (is_unmatch == true) {
                count++;
                s = tmp_s;
            }
        }
        ans = min(ans, count);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <chrono>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_i = pair<double, int>;
using i_d = pair<int, double>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr ll LL2_MOD = 1000000007;
static constexpr ll INF = 1LL << 60;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = {
  { typeid(int), "%d" }, { typeid(ll), "%lld" }, { typeid(double), "%lf" }, { typeid(char), "%c" }};

template <class T> static void scan(vector<T>& v);
static void scan(vector<string>& v, bool isWord = true);
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; }

ll dp[101][100001];

int main(int argc, char *argv[]) {
  //INFILE();

  ll n, w;
  cin >> n >> w;

  vector<ll> weights(static_cast<int>(n));
  vector<ll> values(static_cast<int>(n));
  REP(i, 0, n) {
    cin >> weights[i] >> values[i];
  }

  REP(i, 1, n + 1) {
    REP(j, 0, w + 1) {
      chmax(dp[i][j], dp[i - 1][j]);
      if (j - weights[i - 1] < 0) continue;
      chmax(dp[i][j], dp[i - 1][j - weights[i - 1]] + values[i - 1]);
    }
  }

  cout << *max_element(ALL(dp[n])) << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)(j);i <= (int)(k);i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define fix cout<<fixed<<setprecision(20);
const int maxn=(int)1e6+5;
const int inf=(int)1e9+5;
int ans,n,dp[maxn],a[maxn],Ans[maxn];
vector<int> E[maxn];
void dfs(int x,int fa){
    //debug(x);
    for(auto v:E[x])if(v!=fa){
        int p=lower_bound(dp,dp+1+ans,a[v])-dp;
        int tmp=dp[p],tmpans=ans;
        dp[p]=min(dp[p],a[v]);
        ans=max(p,ans);
        Ans[v]=ans;
        dfs(v,x);
        dp[p]=tmp;
        ans=tmpans;
    }
    //debug(x);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    rep(i,1,n)cin>>a[i];
    rep(i,1,n+2)dp[i]=inf;dp[0]=-1;
    rep(i,1,n-1){
        int x,y;cin>>x>>y;E[x].push_back(y);E[y].push_back(x);
    }
    E[0].push_back(1);
    dfs(0,0);
    rep(i,1,n)cout<<Ans[i]<<endl;
}
/* 
dp[i]: LIS第i位的最小值
applying rollback technique to the dynamic programming of solving the longest increasing subsequence problem.

Here the rollback refers to, when processing updates of values of variables and questions one after another, 
withdrawing the changes as it wasbefore the latest changes. 

wr 下标a[v] , ans 没更新

 */

Measured memory_bytes: 50032
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int s = 1;
vector<int> dat, lazy;

void init(int n_) {
	while (s < n_)s *= 2;
	dat.resize(2 * s - 1);
	lazy.resize(2 * s - 1);
}

void eval(int k, int l, int r) {
	if (lazy[k]) {
		dat[k] += lazy[k];
		if (r - l > 1) {
			lazy[2 * k + 1] += lazy[k] / 2;
			lazy[2 * k + 2] += lazy[k] / 2;
		}
		lazy[k] = 0;
	}
}

void add(int a, int b, int x, int k = 0, int l = 0, int r = s) {
	eval(k, l, r);
	if (r <= a || b <= l)return;
	if (a <= l && r <= b) {
		lazy[k] += x * (r - l);
		eval(k, l, r);
		return;
	}
	add(a, b, x, 2 * k + 1, l, (l + r) / 2);
	add(a, b, x, 2 * k + 2, (l + r) / 2, r);
	dat[k] = dat[2 * k + 1] + dat[2 * k + 2];
}

int query(int a, int b, int k = 0, int l = 0, int r = s) {
	if (r <= a || b <= l)return 0;
	eval(k, l, r);
	if (a <= l && r <= b)return dat[k];
	int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
	int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
	return vl + vr;
}

int n, m, q, l[200010], r[200010], a[100010], b[100010];
vector<int> vec;
vector<pair<P, P>> ve;
int ans[100010];

signed main() {
	cin >> n >> m >> q;
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> r[i];
		vec.push_back(l[i]);
		vec.push_back(r[i]);
		vec.push_back(l[i] + 1);
	}
	for (int i = 0; i < q; i++) {
		cin >> a[i] >> b[i];
		vec.push_back(a[i]);
		vec.push_back(b[i]);
		vec.push_back(a[i] + 1);
	}
	sort(all(vec));
	vec.erase(unique(all(vec)), vec.end());
	n = (int)vec.size();
	init(n);
	for (int i = 0; i < m; i++) {
		l[i] = lower_bound(all(vec), l[i]) - vec.begin();
		r[i] = lower_bound(all(vec), r[i]) - vec.begin();
		ve.push_back(make_pair(make_pair(r[i], 1), make_pair(l[i], 0)));
	}
	for (int i = 0; i < q; i++) {
		a[i] = lower_bound(all(vec), a[i]) - vec.begin();
		b[i] = lower_bound(all(vec), b[i]) - vec.begin();
		ve.push_back(make_pair(make_pair(b[i], 2), make_pair(a[i], i)));
	}
	sort(all(ve));
	for (int i = 0; i < (int)ve.size(); i++) {
		if (ve[i].first.second == 1)add(0, ve[i].second.first + 1, 1);
		else {
			int x = query(ve[i].second.first, ve[i].second.first + 1);
			ans[ve[i].second.second] = x;
		}
	}
	for (int i = 0; i < q; i++)cout << ans[i] << endl;
}

Measured memory_bytes: 30696