akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[],int n,int g){
    for(int i = g ; i < n ; i++){
        int v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v){
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void shellSort(int A[], int n){
    for(int h = 1 ;;){
        if(h>n) break;
        G.push_back(h);
        h = 3*h + 1;
    }
    
    for(int i = G.size()-1 ; i >= 0 ; i--){
        insertionSort(A,n,G[i]);
    }
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++) scanf("%d",&A[i]);
    cnt = 0;
    shellSort(A,n);
    cout << G.size() << endl;
    for(int i=G.size()-1;i >= 0;i--){
        printf("%d", G[i]);
        if(i) printf(" ");
    }
    printf("\n");
    printf("%d\n",cnt);
    for(int i=0;i<n;i++) printf("%d\n",A[i]);
    
    return 0;
}


Measured memory_bytes: 7144
import sys
from io import StringIO
import unittest

# 再起限界
import sys
sys.setrecursionlimit(4100000)


def resolve():
    original_s = list(sys.stdin.readline().split()[0])
    sum_list = []
    sum_list_append = sum_list.append

    def dfs(s, sum):
        if len(s) == 0:
            sum_list_append(sum)
            return
        if len(s) == 1:
            sum_list_append(sum + int(s[0]))
            return

        dfs(s[1:], sum + int(s[0]))

        dfs([s[0] + s[1]] + s[2:], sum)

    dfs(original_s, 0)
    print(sum(sum_list))


if __name__ == "__main__":
    resolve()


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """125"""
        output = """176"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """9999999999"""
        output = """12656242944"""
        self.assertIO(input, output)


Measured memory_bytes: 6320
#include <stdio.h>
#include <math.h>
int main()
{
	int hajime[3000]={0};
	int owari[3000]={0};
	int i;
	int x=0;
	int count=0;
	while(1){
		scanf("%d %d",&hajime[x],&owari[x]);
		if(hajime[x]==0&&owari[x]==0){
			break;
		}
		x++;
	}
	x=0;
	for(i=hajime[x]; i<=owari[x]; i++){
		if(hajime[x]==0&&owari[x]==0){
			break;
		}
		if(i%400==0){
			printf("%d\n",i);
			count++;
		}
		else if(i%100==0){
		}
		else if(i%4==0){
			printf("%d\n",i);
			count++;
		}
		else{
		}
		if(i==owari[x]){
			if(count==0){
				printf("NA\n");
			}
			if(hajime[x+1]!=0&&owari[x+1]!=0){
				printf("\n");
			}
			x++;
			i=hajime[x]-1;
			count=0;
		}
	}
	return 0;
}

Measured memory_bytes: 644
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

ll posCW[100005], posCCW[100005], suff[100005], pref[100005], dp1[100005], dp2[100005];
ll N, L;

//pref[x] : calories get to eat x-th sushi from counterclockwise direction (1 .. x)
//suff[x] : calories get to eat x-th sushi from clockwise direction (N .. x)
//posCCW : distance to the sushi in counterclockwise direction from starting point
//posCW : distance to the sushi in clockwise direction from starting point

int main(){

    ios :: sync_with_stdio(false);
    cin >> N >> L;
    FOR(i,N){
        cin >> posCCW[i] >> pref[i];
        posCW[i] = L - posCCW[i];
        suff[i] = pref[i];
        pref[i] += pref[i-1];
    }

    FORD(i,N,0){
        suff[i] += suff[i+1];
    }

    FOR(i,N){
        //option 1a : walk counter-lockwise to A, then back to starting point
        dp1[i] = max(dp1[i-1], pref[i] - 2*posCCW[i]);

        //option 2a : walk counter clockwise to A
        dp2[i] = max(dp2[i-1], pref[i] - posCCW[i]);
    }

    ll ans = 0;
    FOR(i,N+1){
        ans = max(ans, max(
            //option 1b : after option 1a, walk clockwise from starting point to B
            dp1[i-1] + suff[i] - posCW[i],

            //option 2b : before option 2a, walk clockwise from starting point to B, then back to starting point
            dp2[i-1] + suff[i] - 2*posCW[i]
        ));
    }

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

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

int main() {
    while(true) {
        int m, d; cin >> m >> d;
        if (m == 0)
            break;
        
        vector<string> ans{"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};
        vector<int> months{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        m--;
        int days = 0;
        rep(i, m) {
            days+= months.at(i);
        }
        days+= d;

        cout << (ans.at(days % 7)) << endl;
    }
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  map<int, int> freqs;
  int a;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a);
    ++freqs[a];
  }

  int ans = 0;
  for (pair<int, int> p : freqs) {
    int val = p.first, cnt = p.second;
    if (cnt > val) { ans += (cnt - val); }
    else if (cnt < val) { ans += cnt; }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  string s;
  cin >> s;
  int len = s.length() - 1;
  int ans = 0;
  for(int i = 0; i <= len/2; ++i) {
    if(s[i] != s[len-i]) ++ans;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef pair<ll, ll> P;
typedef vector<ll> vll;

template<class T = ll>
T in() {
    T x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll x, y, z, k;
        cin >> x >> y >> z >> k;
        vll a(x), b(y), c(z);
        rep(i, x) a[i] = in();
        rep(i, y) b[i] = in();
        rep(i, z) c[i] = in();

        vll ab;
        rep(i, x) rep(j, y) ab.eb(a[i] + b[j]);
        sort(all(ab), greater<>());
        priority_queue<ll, vector<ll>, greater<>> que;

        rep(i, min(x * y, k)) {
            rep(j, z) {
                if (que.size() < k) que.push(ab[i] + c[j]);
                else if (que.top() < ab[i] + c[j]) {
                    que.pop();
                    que.push(ab[i] + c[j]);
                }
            }
        }

        vll ans(k);
        rep(i, k) {
            ans[k - i - 1] = que.top();
            que.pop();
        }
        rep(i, k) printf("%lli\n", ans[i]);


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 10608
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n, q = li()
edge = [list(li_()) for _ in range(n-1)]
query = [list(li()) for _ in range(q)]

# 各頂点に指定の数字を入れる
num = [0]*n
for pi, xi in query:
    pi -= 1
    num[pi] += xi

# 木を構築
tree = [[] for _ in range(n)]
for ai, bi in edge:
    tree[ai].append(bi)
    tree[bi].append(ai)


# ルートから、親+自分の数字を入れる
visited = [False]*n
stack = [0]
visited[0] = True

while stack:
    cur = stack.pop()
    for nex in tree[cur]:
        if visited[nex]:
            continue

        visited[nex] = True
        num[nex] += num[cur]
        stack.append(nex)

# 出力
print(*num)


Measured memory_bytes: 125020
import queue
k = int(input())

if k <= 9:
    print(k)
else:
    q = queue.Queue()
    for i in range(9):
        q.put(i+1)
    for i in range(k):
        s = q.get()
        if s  % 10 == 0:
            q.put(s * 10)
            q.put(s * 10 + 1)
        elif s  % 10 == 9:
            q.put(s * 10 + 8)
            q.put(s * 10 + 9)
        else:
            t = s  % 10
            q.put(s * 10 + t - 1)
            q.put(s * 10 + t)
            q.put(s * 10 + t + 1)
    print(s)


Measured memory_bytes: 12576
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll a,b,c,k,temp;
    cin>>a>>b>>c>>k;
    temp=min(a,k);
    ll ans=temp;
    k-=temp;
    a-=temp;
    if(k==0){
        cout<<ans<<endl;
        return 0;
    }
    temp=min(b,k);
    k-=temp;
    if(k==0){
        cout<<ans<<endl;
        return 0;
    }
    temp=min(c,k);
    ans-=temp;
    k-=temp;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
a = int(input())
b = int(input())
c = int(input())
x = int(input())

res = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                res += 1

print(res)


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
const int INF=1<<25;
int L[200][200];
int S[200][200];
int d[2][200];
int z[1000];
int main() {
    int N,M;
    while(scanf("%d %d",&N,&M),N) {
        fill((int*)L,(int*)(L+200),INF);
        fill((int*)S,(int*)(S+200),INF);
        for(int i=0;i<N;i++) {
            L[i][i]=S[i][i]=0;
        }
        for(int i=0;i<M;i++) {
            int x,y,t;
            char s[2];
            scanf("%d %d %d %s",&x,&y,&t,s);x--;y--;
            if(s[0]=='L') {
                L[x][y]=L[y][x]=min(L[x][y],t);
            }else {
                S[x][y]=S[y][x]=min(S[x][y],t);
            }
        }
        int R;
        scanf("%d",&R);
        for(int i=0;i<R;i++) {
            scanf("%d",&z[i]);z[i]--;
        }
        for(int k=0;k<N;k++) {
            for(int i=0;i<N;i++) {
                for(int j=0;j<N;j++) {
                    L[i][j]=min(L[i][j],L[i][k]+L[k][j]);
                    S[i][j]=min(S[i][j],S[i][k]+S[k][j]);
                }
            }
        }
        fill((int*)d,(int*)(d+2),INF);
        d[0][z[0]]=0;
        for(int i=0;i+1<R;i++) {
            for(int j=0;j<N;j++) {
                d[(i+1)&1][j]=INF;
            }
            for(int j=0;j<N;j++) {
                d[(i+1)&1][j]=min(d[(i+1)&1][j],d[i&1][j]+L[z[i]][z[i+1]]);
                for(int k=0;k<N;k++) {
                    d[(i+1)&1][j]=min(d[(i+1)&1][j],d[i&1][k]+L[z[i]][k]+S[k][j]+L[j][z[i+1]]);
                }
            }
        }
        int ans=INF;
        for(int i=0;i<N;i++) {
            ans=min(ans,d[(R-1)&1][i]);
        }
        printf("%d\n",ans);
    }
    
}

Measured memory_bytes: 1508
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Pencils
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer st = new StringTokenizer(br.readLine());

		int N, A, B, C, D;
		N = parseInt(st.nextToken());
		A = parseInt(st.nextToken());
		B = parseInt(st.nextToken());
		C = parseInt(st.nextToken());
		D = parseInt(st.nextToken());

		int AB, CD;
		AB = (N / A) * B;
		if (N % A > 0) AB += B;
		CD = (N / C) * D;
		if (N % C > 0) CD += D;

		System.out.println(AB < CD ? AB : CD);
	}
}



Measured memory_bytes: 24468
S = input()
K = int(input())
S_0 = [i for i in S]
S_1 = S_0+S_0
ans_0 = 0
tmp = S_0[0]
tmp_0 = S_0[0]
flag = True
for i in range(1,len(S_0)):
    if S_0[i] == tmp:
        S_0[i] = "0"
        ans_0 += 1
    tmp = S_0[i]
    if S[i] != tmp_0:
        flag = False
ans_1 = 0
tmp = S_1[0]
for i in range(1,len(S_1)):
    if S_1[i] == tmp:
        S_1[i] = "0"
        ans_1 += 1
    tmp = S_1[i]
ans = ans_0 + (ans_1 - ans_0)*(K-1)
if flag == False:
    print(ans)
else:
    print((len(S)*K)//2)

Measured memory_bytes: 3188
#define DEBUG 0

/**
 * File    : E.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-28 20:34:04
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

/*
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}

void No()
{
  cout << "No" << endl;
  exit(0);
}
*/

/*
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
*/

// const ll MOD = 1000000007;

int N;
ll M;
ll a[200010];
ll ans;

bool solve(int t)
{
  ll res = 0;
  for (auto i = 0; i < t; i++)
  {
    res = max(res, a[i] + a[2 * t - 1 - i]);
  }
  for (auto i = 0; i < N - t; i++)
  {
    ll temp = a[2 * t + i] + a[2 * N - 1 - i];
    if (temp < M)
    {
      return false;
    }
    else
    {
      res = max(res, temp - M);
    }
  }
  ans = min(ans, res);
  return true;
}

int main()
{
  cin >> N >> M;
  ans = 100 * M;
  for (auto i = 0; i < 2 * N; i++)
  {
    cin >> a[i];
  }
  sort(a, a + 2 * N);
  int ng = -1;
  int ok = N + 1;
  while (abs(ok - ng) > 1)
  {
    int t = (ng + ok) / 2;
#if DEBUG == 1
    cerr << "t = " << t << endl;
#endif
    if (solve(t))
    {
#if DEBUG == 1
      cerr << "ok, ans = " << ans << endl;
#endif
      ok = t;
    }
    else
    {
#if DEBUG == 1
      cerr << "ng" << endl;
#endif
      ng = t;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
for i in range(1,int(input())+1):
  x = i
  if x%3==0:
    print (" ", end="")
    print (i, end="")
    continue
  while True:
    if x%10==3:
      print (" ", end="")
      print (i, end="")
      break
    x = int(x/10)
    if not x:
      break
print ()


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

using namespace std;

#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ull unsigned long long int

const int INF = 1e9 + 7;
const int N = 1e5+5;


int main() {

	IO;

	int n;
	cin >> n;
	
	vector<vector<int>> a(9, vector<int>(9));
	
	for (int i = 1; i <= n; ++i) {
		if (i % 10 == 0) continue;
		
		int x = i % 10;
		int t = 1;
		int m = i;
		while (m > 0) {
			t = m;
			m/=10;
		}
		
		a[t-1][x-1]++;
	}
	
	int ans = 0;
	
	for (int i = 0; i < 9; ++i) {
		for (int j = 0; j < 9; ++j) {
			ans += a[i][j] * a[j][i];
		}
	}
	
	cout << ans;
	
}


Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  vint L(N*2);
  repeat(i,N*2){
    cin>>L[i];
  }
  sort(L.begin(),L.end());
  int ans = 0;
  repeat(i,N){
    ans += L[2*i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Mon May 11 17:28:28 2020

@author: shinba
"""

n = int(input())

A = []
B = []

for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    
ans = 0

for i in range(n-1,-1,-1):
    sup = (A[i]+ans) % B[i]
    ans += B[i] - sup if sup != 0 else 0

print(ans)
    
    
    
    


Measured memory_bytes: 11052
#include <stdio.h>

int main(void){
    int x1, y1, size;
    int paper[10][10];
    int max = 0;
    int blank = 100;
    int i, j;
    
    int sx[4] = {0, 1, 0, -1};
    int sy[4] = {1, 0, -1, 0};
    int lx[4] = {0, 2, 0, -2};
    int ly[4] = {2, 0, -2, 0};

    for(i=0; i<10; i++){
	for(j=0; j<10; j++){
	    paper[i][j] = 0;
	}
    }

    while(scanf("%d,%d,%d", &x1, &y1, &size) != EOF){
	if(size == 1){
	    if(x1 >= 0 && x1 <= 9 && y1 >= 0 && y1 <= 9){
		if(paper[x1][y1] == 0) blank--;
		paper[x1][y1] += 1;
		if(paper[x1][y1] > max) max = paper[x1][y1];	
	    }
	    for(i=0; i<4; i++){
		if(x1+sx[i] >= 0 && x1+sx[i] <= 9 && y1+sy[i] >= 0 && y1+sy[i] <= 9){
		    if(paper[x1+sx[i]][y1+sy[i]] == 0) blank--;
		    paper[ x1+sx[i] ][ y1+sy[i] ] += 1;
		    if(paper[ x1+sx[i] ][ y1+sy[i] ] > max) max = paper[x1+sx[i]][y1+sy[i]];
		}
	    }
	}else if(size == 2){
	    for(i = -1; i <= 1; i++){
		for(j = 1; j >= -1; j--){
		    if(x1+i >= 0 && x1+i <= 9 && y1+j >= 0 && y1+j <= 9){
			if(paper[x1+i][y1+j] == 0) blank--;
			paper[ x1+i ][ y1+j ] += 1;
			if(paper[ x1+i ][ y1+j] > max) max = paper[ x1+i ][ y1+j];	
		    }
		}
	    } 
	}else if(size == 3){
    	    for(i = -1; i <= 1; i++){
		for(j = 1; j >= -1; j--){
		    if(x1+i >= 0 && x1+i <= 9 && y1+j >= 0 && y1+j <= 9){
			if(paper[x1+i][y1+j] == 0) blank--;
			paper[ x1+i ][ y1+j ] += 1;
			if(paper[ x1+i ][ y1+j] > max) max = paper[ x1+i ][ y1+j];	
		    }
		}
	    }     
    	    for(i=0; i<4; i++){
		if(x1+lx[i] >= 0 && x1+lx[i] <= 9 && y1+ly[i] >= 0 && y1+ly[i] <= 9){
		    if(paper[ x1+lx[i] ][ y1+ly[i] ] == 0) blank--;
		    paper[ x1+lx[i] ][ y1+ly[i] ] += 1;
		    if(paper[ x1+lx[i] ][ y1+ly[i] ] > max) max = paper[x1+lx[i]][y1+ly[i]];
		}
	    }
	}
    }

    printf("%d\n", blank);
    printf("%d\n", max);

    return 0;
}

Measured memory_bytes: 0
N = int(input())
R = [[int(i) for i in input().split()] for i in range(N)]
B = [[int(i) for i in input().split()] for i in range(N)]

for i in R:
    i[0],i[1] = i[1],i[0]
R,B = sorted(R)[::-1],sorted(B)

answer = 0
for i in B:
    for j in R:
        if i[0]>j[1] and i[1]>j[0]:
            answer += 1
            R.remove(j)
            break
print(answer)

Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int o = 0;
    string s;
    cin>>s;
    for (int i = 1; i < s.size(); ++i){
    	if(s[i-1] == s[i]){
    		s[i] = (s[i] - '0' + 1)%2 + '0';
    		o++; 
    	}
    }
    cout << o << endl;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n;
	cin >> n;
	vector<int> s;
	long long int sum = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.push_back(a);
		sum = sum + a;
	}
	long long int now = 0;
	long long int now1 = 0;
	long long int judge = sum / 2;
	long long int ans = 0;
	ans = 1000000000000000000;
	for (int i = 0; i < n - 1; i++) {
		now = now + s[i];
		ans = min(ans, abs(sum - now * 2));
	}
	cout << ans;
}

Measured memory_bytes: 1528
def solve():
    s = input()
    K = int(input())

    cand = set()
    for e,c in enumerate(s):
        for i in range(1, K+1):
            if e+i > len(s): break                
            sub = s[e:e+i]
            cand.add(sub)
    cand = list(cand)
    cand.sort()

    print(cand[K-1])

    
    
if __name__ == "__main__":
    solve()

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

int main(){
  int n, t, a;
  int h[1000];

  cin >> n;
  cin >> t >> a;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  double min = fabs(a - (t - h[0]*0.006));
  int index = 1;
  for (int i = 1; i < n; i++) {
    if (min > fabs(a - (t - h[i]*0.006))) {
      min = fabs(a - (t - h[i]*0.006));
      index = i + 1;
    }
  }

  cout << index << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

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

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; }

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

constexpr ll mod = 1e9 + 7;
const double PI = acos(-1.0);

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

  int n; cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());

  int sum = 0;
  for(int i=0; i<n-1; i++) {
    sum += l[i];
  }

  if (sum > l[n-1]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;

int main() {
    int n; cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];

    map<char, ll> cnt;

    vector<char> head = {'M', 'A', 'R', 'C', 'H'};
    rep(i, n) for (auto c: head) if (s[i][0] == c) cnt[c]++;

    ll ans = 0;

    for (int i = 0; i <= 2; ++i) {
        for (int j = i + 1; j <= 3; ++j) {
            for (int k = j + 1; k <= 4; ++k) {
                ans += cnt[head[i]] * cnt[head[j]] * cnt[head[k]];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6144
import itertools

N = int(input())
nums = [3, 5, 7]
res = 0
for i in range(10):
  for balls in itertools.product(nums, repeat=i):
    num = ''
    if 3 in balls and 5 in balls and 7 in balls:
      for j in range(i):
        num += str(balls[j])
      if int(num) > N:
        break
      res += 1

print(res)

Measured memory_bytes: 3060
h, w, k = map(int, input().split())

p = [input() for i in range(h)]
H =[0]*h
W = [0]*w

b = 0
for i in range(h):
  for j in range(w):
    if p[i][j] == '#':
      H[i] += 1
      W[j] += 1
      b += 1
   
d = b - k

ans = 0

for i in range(2**h):
  for k in range(2**w):
    black1 = 0
    for j in range(h):

      if ((i>>j)&1):
        black1 += H[j]
    
    for l in range(w):

      if ((k>>l)&1):
        black1 += W[l]
        
    for j in range(h):
      for l in range(w):
        if (i>>j)&1 and (k>>l)&1 and p[j][l] == '#':
          black1 -= 1

    
    if black1 == d:
      ans += 1

print(ans)
  



Measured memory_bytes: 9248
/**
 *      purpose : CODE FESTIVAL 2017 qual C A
 *      author  : kyomukyomupurin
 *      created : 2018-11-15 15:19:50
**/

#include <bits/stdc++.h>
typedef int64_t int64;
#define print(x) cout << (x) << '\n'
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string S; cin >> S;
    if (S.find("AC") != string::npos) print("Yes");
    else print("No");
    
    return 0;
}


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

ll N;
set<ll> S;

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        ll l;
        cin >> l;
        S.insert(l);
    }
    if(S.size()==N) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 9600
n, q = map(int, input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

u = UnionFind(n)
for i in range(q):
	c, x, y = map(int, input().split())
	if c==0:
		u.union(x, y)
	else:
	    if u.same(x, y):
	        print(1)
	    else:
	        print(0)




Measured memory_bytes: 5796
typedef long long ll;
typedef long double ld;
#define mod 1000000007
#define INF 1000000000
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int x, y;
	cin >> x >> y;
	if (2 * x <= y && y % 2 == 0 && 4 * x >= y) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	
	return 0;
}


Measured memory_bytes: 3524
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

h = ri()
w = ri()
n = ri()
x = max(h, w)
print((n + x - 1) // x)

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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = 500005, M = 1e9 + 7;

int n, m, fact[N], factInv[N];


void add(int& w, int u) {
    w += u;
    if (w >= M) w -= M;
}

int mul(int w, int u) {
    return (long long)w * u % M;
}

int powaer(int a, int k) {
    if (k == 0) return 1;
    return mul(powaer(mul(a, a), k / 2), k % 2 ? a : 1);
}

int inv(int w) {
    return powaer(w, M - 2);
}

int newton(int n, int k) {
    if (k > n || n < 0) return 0;
    return mul(fact[n], mul(factInv[k], factInv[n - k]));
}


int main() {
    scanf("%d %d", &n, &m);

    fact[0] = 1;
    for (int i = 1; i <= m; i++) {
        fact[i] = mul(fact[i - 1], i);
    }
    
    factInv[m] = inv(fact[m]);
    for (int i = m - 1; i >= 0; i--) {
        factInv[i] = mul(factInv[i + 1], i + 1);
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        int wrong = mul(mul(newton(n, i), newton(m, i)), fact[i]);
        int any = mul(mul(newton(m - i, n - i), fact[n - i]), mul(newton(m - i, n - i), fact[n - i]));
        int res = mul(wrong, any);
//         debug(i, wrong, any, res);
        if (i % 2 == 0) add(ans, res);
        else {
            ans -= res;
            if (ans < 0) ans += M;
        }
    }
    
//     int ans = 0;
//     for (int i = 0; i <= n; i++) {
//         int left = mul(newton(m, n), fact[n]);
//         int right = mul(mul(newton(n, i), mul(newton(n, i), fact[i])), mul(newton(m - n, n - i), fact[n - i]));
//         debug(i, left, right);
//         add(ans, mul(left, right));
//     }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 7620
#include <iostream>
#include <algorithm>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int powmod(int a, int n, int mod) {
	if (a >= mod) a %= mod;
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return (a * powmod(a, n - 1, mod)) % mod;
}

int mod = 1000000007;
int n, k;
int a[20];
int dp[21][1001];
int fact[10000];
int finv[10000];

int comb(int n, int k) {
	return fact[n] * finv[k] % mod * finv[n - k] % mod;
}

signed main() {
	int i, j, l;
	
	fact[0] = 1;
	finv[0] = 1;
	for (i = 1; i < 10000; i++) {
		fact[i] = (i * fact[i - 1]) % mod;
		finv[i] = powmod(fact[i], mod - 2, mod);
	}
	
	cin >> n >> k;
	rep(i, k) cin >> a[i];
	
	dp[0][0] = 1;
	rep(i, k) {
		rep(j, n + 1) {
			rep(l, min(n - j, a[i]) + 1) {
				dp[i + 1][j + l] += dp[i][j] * comb(n - j, l) % mod * comb(n - l, a[i] - l);
				dp[i + 1][j + l] %= mod;
			}
		}
	}
	
	cout << dp[k][n] << endl;
	return 0;
}

//Aij = i日目に子供jがクッキーをもらった1, もらってない0
//とし、ΣScore(A) (all A)を求める問題。Score(A)が積の形で都合が悪い. 
// (本番はcnt[i] = i個クッキーを貰った子供の数とし、Score(A) = Πi ^ cnt[i]と言い換え、各「配列cnt」が何回現れるかを考察したが、筋が悪かった）
//こういうときは、「何かの個数」に言い換えられると嬉しい。
//このテクは、ARCの過去問「Convex Score」にもある。
//
//重要な考察：Score(A)は、「各子供から1つずつクッキーを選ぶ方法の個数」と同じ。
//Aを作ったあと、各子供から選んだクッキー（マス）に印をつけてみる。つまり、次のような行列を考える
//B = i日目に子供jがクッキーをもらいかつ選んだ2, もらったが選ばず1, もらわず0
//Bの作り方：Aを作った後、Aの各列の「1」を1つずつ選び、〇をつける。〇をつけた1を2に書き換えたものをBとする。
//このとき、各Aごとに作れるBはScore(A)個ある。もちろんAが違えば対応するBも異なる。
//よって、作れるBの個数が答えになる。
//
//作れるBの制約は、
//・Bij in {0, 1, 2}
//・任意のiについて、#{j | Bij >= 1} = a[i]
//・任意のjについて、#{i | Bij = 2} = 1
//と書ける。これらを全て満たす行列（表）を数えればよいことが分かった。
//
//ここからは典型で、i=1,2,…ごとに1行ずつ決めていくだけ。
//・「2」を入れた列には{0, 1}しか入れることができない
//というのが特別な制約で、「2」を入れた列数jが大事そう。
//・dp[i][j] = i日決めた. 2を入れた列数がj個. 何通り？
//というdpを考える。遷移として、
//・2を新たにl個追加する場合を考える。
//　・この場合、dp[i][j]からは、dp[i + 1][j + l]に「必ず遷移する」ので、立式可能。
//　・まず、j + l <= N かつ l <= a[i]を満たす必要がある.
//	・このとき、2を入れる方法は、N - j列のうちからl列を選ぶ方法なので、comb(N - j, l)通り.
//　・その各々について、残るN - l列からa[i] - l列には1を、それ以外の列には0を入れる方法が、comb(N - l, a[i] - l)通り.
//・よって、dp[i][j]からdp[i + 1][j + l]には、各々comb(N - j, l) × comb(N - l, a[i] - l)通りの遷移がある。
//あとはi, j, lをループで回せば良い。計算量はO(KN^2)。


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

int main() {
  int A, B;
  cin >> A;
  cin >> B;
  
  int r = 0;
  
  for (int i = A; i <= B; i++) {
    int s = i % 10, t = i / 10000 % 10;
    int u = i / 10 % 10, v = i / 1000 % 10;
    if (s == t && u == v)
      r++;
  }
  cout << r << endl;
}

Measured memory_bytes: 256
using System;

class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            char s1 = S[0];
            char s2 = S[1];
            char s3 = S[2];

            char t1 = T[0];
            char t2 = T[1];
            char t3 = T[2];

            int ans = 0;

            if (s1 == t1)
            {
                ans++;
            }

            if (s2 == t2)
            {
                ans++;
            }

            if (s3 == t3)
            {
                ans++;
            }

            Console.WriteLine(ans);
        }
    }

Measured memory_bytes: 11092
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S divup_L(S a, T b){
  return (a+b-1)/b;
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int X;
int Y;
int main(){
  int Lj4PdHRW;
  long long a=1, b=1;
  rd(N);
  for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
    rd(X);
    rd(Y);
    a = (divup_L(a,X)) * X;
    b = (divup_L(b,Y)) * Y;
    chmax(a, b / Y * X);
    chmax(b, a / X * Y);
  }
  wt_L(a+b);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190829-1

// --- original code ---
// int N, X, Y;
// {
//   ll a = 1, b = 1;
//   rd(N);
//   rep(N){
//     rd(X,Y);
//     a = (a /+ X) * X;
//     b = (b /+ Y) * Y;
//     a >?= b / Y * X;
//     b >?= a / X * Y;
//   }
//   wt(a+b);
// }


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

namespace AtCoderIO
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = int.Parse(str[2]);

            int num = B / A;

            if (num > C)
            {
                num = C;
            }

            Console.WriteLine(num);
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
A,B,C,D,E,F = map(int,input().split())

ws = set()
for a in range(F+1):
    if a*100*A > F: break
    for b in range(F+1):
        if a*100*A + b*100*B > F: break
        ws.add(a*100*A + b*100*B)

ss = set()
for c in range(F+1):
    if c*C > F: break
    for d in range(F+1):
        if c*C + d*D > F: break
        ss.add(c*C + d*D)

os = -1
ow = 999
for w in ws:
    if w==0: continue
    for s in ss:
        if s+w > F: continue
        if w*E < s*100: continue
        if os * (s+w) < s * (os+ow):
            os,ow = s,w
print(os+ow, os)

Measured memory_bytes: 3188
count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
    b,f,r,v = map(int, input().split())
    count[b-1][f-1][r-1] += v
for i in range(4):
    for j in range(3):
        for k in range(10):
            if k == 9:
                print(f' {count[i][j][k]}')
            else:
                print(f' {count[i][j][k]}', end='')
    if i != 3:
        print('####################')


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define LL long long
#define dob complex<double>
#define Abs(a) ((a) < 0 ? (-(a)) : (a))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
#define writeln(x) (write(x), putchar('\n'))
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const int l1 = 10000000;
const int l2 = 25500000;
const int yzh = 1e9+7;
void read(int &x) {
    char ch; bool flag = 0;
    for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
    for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
    x *= 1-2*flag;
}
void print(int x) {if (x > 9) print(x/10); putchar(x%10+48); }
void write(int x) {if (x < 0) putchar('-'); print(Abs(x)); }

int s, f[l2+5];

int quick_pow(int a, int b) {
    int ans = 1;
    while (b) {
    if (b&1) ans = 1ll*ans*a%yzh;
    a = 1ll*a*a%yzh, b >>= 1;
    }
    return ans;
}
int count1(int n) {
    int ans = 0, r = 0, cnt = 0;
    for (int i = 1; i < l1; i++) {
    cnt -= f[i-1];
    while (cnt+f[r+1] <= s && r < l2) cnt += f[++r];
    if (cnt == s) ++ans;
    if (r == l2) break;
    }
    return ans;
}
int count2(int n) {
    int lim = n/8, ans = lim;
    for (int t = 1; t <= lim; t++)
    if (n%t == 0) {
        int len = n/t;
        (ans += (1ll*quick_pow(10, len-1)*9%yzh-t)%yzh) %= yzh;
    }
    return ans;
}
void work() {
    for (int i = 1, r = 10, cnt = 1; i < l1; i++, i = r, r = r*10, cnt++)
    for (int j = i; j < r; j++) f[j] = cnt;
    for (int i = l1; i <= l2; i++) f[i] = 8;
    read(s);
    writeln(((count1(s)+count2(s))%yzh+yzh)%yzh);
}
int main() {
    work();
    return 0;
}

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

using namespace std;

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

  int n, k;
  cin >> n >> k;
  vector<int> l(n);
  for (auto &e : l) {
    cin >> e;
  }
  sort(l.rbegin(), l.rend());
  int ans = 0;
  for (int i = 0; i < k; ++i) {
    ans += l[i];
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Program{
  public static void Main(){
    
    string input = Console.ReadLine();
 
    if ((input[2] == input[3])&&(input[4] == input[5]))
    {
      Console.WriteLine("Yes");
    }
    else
    {
      Console.WriteLine("No");
    }
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    string S;
    cin >> N >> S;
    int m = 0;
    for(int i = 1; i < N - 1; i++) {
        set<char> left;
        set<char> right;
        for(int j = 0; j < i; j++) {
            left.insert(S[j]);
        }
        for(int j = i; j < N; j++) {
            right.insert(S[j]);
        }
        int cnt = 0;
        auto itr = left.begin();
        for(int j = 0; j < left.size(); j++) {
            if(right.find(*itr++) != right.end()) {
                cnt++;
            }
        }
        m = max(m, cnt);
    }
    cout << m << endl;
}

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

int calc2(int A, int C){
	return A / C;
}

int calc(int A, int B, int C){
	return calc2(B, C) - calc2(A - 1, C);
}

int lcm(int a, int b){
	int g = __gcd(a, b);
	return a * b / g;
}

signed main(){
	int A, B, C, D;
	scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
	printf("%lld\n", calc(A, B, 1) - calc(A, B, C) - calc(A, B, D) + calc(A, B, lcm(C, D)));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;

int main() {
  int n, k; cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
  } else cout << n - k << endl;
  return 0;
}



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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    //y /= gcd(x,y);
    return (x*y);
}

#define WA printf("WA\n");
int main()
{
    ll as,ae,bs,be,ans=0;
    cin >> as >> ae >> bs >> be;
    if(ae <= bs || be <= as)ans = 0;
    else if(as <= bs)ans = ((ae <= be)? ae-bs:be-bs);
    else ans = ((ae <= be)? ae-as:be-as);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  var a = lines[0]
  var characters = lines[1].split(" ").map(x => x.split(""))
  var new_ary = []
  for(var i = 0; i < a; i++) {
    new_ary.push(characters[0][i])
    new_ary.push(characters[1][i])
  }
  console.log(new_ary.join(""))
});

Measured memory_bytes: 21320
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int main(void) {
	int X;
    scanf("%d", &X);

    if (X == 7 || X == 5 || X == 3) puts("YES");
    else puts("NO"); 

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
    public void Proc()
    {
        int itemCount = int.Parse(Console.ReadLine());
        int[] items = new int[itemCount];
        string[] inpt = Console.ReadLine().Split(' ');
        for(int i=0; i<itemCount; i++)
        {
            items[i] = int.Parse(inpt[i]);
        }

        this.MargeSort(items, 0, itemCount);

        StringBuilder ans = new StringBuilder();
        foreach(int item in items)
        {
            if(ans.Length > 0)
            {
                ans.Append(" ");
            }
            ans.Append(item);
        }
        Console.WriteLine(ans.ToString());
        Console.WriteLine(this.ProcCnt);
    }

    private int ProcCnt = 0;
    private void Marge(int[] array, int left, int mid, int right)
    {
        int n1 = mid - left;
        int n2 = right - mid;

        int[] l = new int[n1 + 1];
        int[] r = new int[n2 + 1];

        for(int i= 0; i< n1; i++)
        {
            l[i] = array[left + i];
        }
        for(int i=0; i< n2; i++)
        {
            r[i] = array[mid + i];
        }
        l[n1] = int.MaxValue;
        r[n2] = int.MaxValue;

        int idx1 = 0;
        int idx2 = 0;
        for(int i= left; i< right; i++)
        {
            if(l[idx1] <= r[idx2])
            {
                array[i] = l[idx1];
                idx1++;
            } else
            {
                array[i] = r[idx2];
                idx2++;
            }
            this.ProcCnt++;
        }
    }

    private void MargeSort(int[] array, int left, int right)
    {
        if(left + 1 < right)
        {
            int mid = (left + right) / 2;
            MargeSort(array, left, mid);
            MargeSort(array, mid, right);
            Marge(array, left, mid, right);
        }
    }

    static void Main(string[] args)

    {

        Program prg = new Program();
        prg.Proc();

    }
}

Measured memory_bytes: 102832
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int get_num(char buf[7]){

	int ret = 0;

	for(int i = 0; buf[i] != '\0'; i++){

		ret = 10*ret+(buf[i]-'0');
	}

	return ret;
}


int main(){

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

	queue<char> ANS;

	int open_num = 0;
	stack<int> S;

	char buf[7];
	int tmp;

	for(int i = 0; i < N; i++){

		scanf("%s",buf);
		tmp = get_num(buf);

		while(open_num < tmp){ //閉じカッコの数と同じだけ開きカッコをpush
			ANS.push('(');
			S.push(++open_num);
		}

		if(tmp == S.top()){
			ANS.push(')');
			S.pop();
		}
	}

	if(!S.empty()){

		printf(":(\n");
		return 0;

	}else{

		while(!ANS.empty()){
			printf("%c",ANS.front());
			ANS.pop();
		}
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 3396
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int r,g,b;

  cin>>r>>g>>b;

  int ans=(r*100)+(g*10)+b;

  if(ans%4){
    cout<<"NO"<<endl;
  }else{
    cout<<"YES"<<endl;
  }
  
  return 0;

}




Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s,t;
    cin >> s >> t;
    map<char, vector<ll>> mps;
    for (ll i = 0; i < s.size(); i++) mps[s[i]].push_back(i+1),mps[s[i]].push_back(i+1+s.size());
    for (char s = 'a'; s <= 'z'; s++) {
        auto& v = mps[s];
        sort(v.begin(), v.end());
    }
    ll cnt = 0;
    ll freq = 0;
    for (ll i = 0; i < t.size(); i++) {
        if (mps[t[i]].empty()) {
            printf("%d\n",-1);
            return 0;
        } else {
            auto& q = mps[t[i]];
            ll tmp = *upper_bound(q.begin(),q.end(),cnt);
            if (tmp < s.size()) cnt = tmp;
            else freq++, cnt = tmp - s.size(); 
        }
    }
    printf("%lld\n",freq * s.size() + cnt);
}

Measured memory_bytes: 2800