akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

/**
 * C4
 */
public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int len = Integer.parseInt(sc.nextLine());
        int[] hash = new int[10000003];
        for(int i=0; i<len; i++){
            String[] command = sc.nextLine().split(" ");
            int key = Node.convertToInt(command[1])*3%10000003;
            switch (command[0]) {
                case "insert":
                    hash[key] = 1;
                    break;
                case "find":
                    String res = hash[key]==1 ? "yes": "no";
                    System.out.println(res);
                    break;
            }
        }
        sc.close();
    }


}

/**
 * Node
 */
class Node {
    public static int convertToInt(String str){
        int len = str.length();
        int converted = 0;
        for(int i=0; i<len; i++){
            converted += toInt(str.charAt(i))*Math.pow(5,i);
        }
        return converted;
    }
    private static int toInt(char c){
        int result = -1;
        switch (c) {
            case 'A':
                result = 3; 
                break;
            case 'C':
                result = 2;
                break;
            case 'G':
                result = 1;
                break;
            case 'T':
                result = 4;
                break;
        }
        return result;
    }
}


Measured memory_bytes: 491024
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000

int main(){
    char a[3][3];
    for(int i=0;i<3;i++){
        for(int n=0;n<3;n++){
            cin>>a[i][n];
            if(i==n)cout<<a[i][n];
        }
    }

    return 0;
}


Measured memory_bytes: 256
function main(input) {
  const args = input.split("\n");
  const N = args[0],
    nums = args.slice(1, args.length - 1);

  // console.log(nums.filter((n, i)=> nums.indexOf(n) === i).length);
  console.log(Array.from(new Set(nums)).length);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    ll n, k, q;
    cin >> n >> k >> q;
    vec<int> p(n, 0);
    rep(i, q) {
        int a;
        cin >> a;
        a--;
        p[a]++;
    }
    int ans = 0;
    rep(i, n) {
        if (k - (q-p[i]) > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

}

Measured memory_bytes: 1024
total = 0
c = []
for i in range(5):
    a = input()
    b = int(a)
    if int(a[-1]) != 0:
        c.append(int(a[-1]))
        total += b - int(a[-1]) + 10
    else:
        total += b

if c:
    total += min(c)
    total -= 10
print(total)

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

int main()
{
    int H, W;
    char S[110][110];
    cin >> H >> W;
    bool row[110] = {false};
    bool col[110] = {false};

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            char temp;
            cin >> temp;
            S[i][j] = temp;
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (S[i][j] == '#')
            {
                row[i] = true;
                col[j] = true;
            }
        }
    }

    for (int i = 0; i < H; i++)
    {
        if (row[i])
        {
            for (int j = 0; j < W; j++)
            {
                if (col[j])
                {
                    cout << S[i][j];
                }
            }
            cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for X in A:
  y = C
  for a, b in zip(X, B):
    y += a * b
  if y > 0:
    ans += 1
print(ans)

Measured memory_bytes: 9188
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  n, m, q = map(int, input().split())
  counts = numpy.zeros((n, n), dtype=numpy.int)
  llr = [], []
  for _ in range(m):
    l, r = map(int, input().split())
    counts[l-1, r-1] += 1
  
  cusum = counts.cumsum(0).cumsum(1)
  for _ in range(q):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    
    if p-1 < 0:
      print(cusum[q, q])
    else:
      print(cusum[q, q] - cusum[p-1, q] - cusum[q, p-1] + cusum[p-1, p-1])

if __name__=='__main__':
  main()



Measured memory_bytes: 18248
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define sz(a) (int)(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,a,c) for(auto it=c.begin()+a;it!=c.end();it++)
#define fr(i,a,n)	for(int i=a;i<n;i++)
#define present(c,x) (c.find(x)!=c.end()) //for set/map etc.
#define cpresent(c,x) (find(all(c),x)!=c.end())
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
int N=100001;
int mod=1e9+7;


int min(int a,int b){if(a<b) return a; else return b;}
int max(int a,int b){if(a>b) return a; else return b;}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int p, int q){if(p%q==0) return q; else{return gcd(q,p%q);}} 
bool comp(int a, int b) 
{ 
    return (a > b); 
}

bool comp1(pi a, pi b)
{
	if(a.first==b.first)return a.second<b.second;
	else return a.first>b.first;
}

template<typename T> 
istream& operator>>(istream& in, vector<T>& v)
{
	for (T& x : v) in >> x; return in;
}

template<typename T> 
ostream& operator<<(ostream& out, vector<T>& v)
{
	for (T& x : v) out << x<<" "; return out;
}

// template<typename T>
int sum1(vector<int>& v)
{
	int sum=0;
	// for(auto x: v)sum+=x;
	fr(i,0,v.size())sum+=v[i];
	return sum;
}





 void solve()
{
	int n;
	cin>>n;
	// int a= (n*(n-1))%mod;
	// if(n>2)
	// {
		// fr(i,0,n-2)
		// {
			// a= a*10;
			// a= a%mod;
		// }
	// }
	int a=1,b=1,c=1;
	fr(i,0,n)
	{
		a= (a*10)%mod;
		b= (b*9)%mod;
		c= (c*8)%mod;
	}
	cout<<((a- 2*b + c)%mod+mod)%mod;
}

signed main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// int t;
	// cin>>t;
	// while(t--)
	// {
	// 	solve();
	// 	cout<<endl;
	// }
	solve();
	return 0;	
} 	

Measured memory_bytes: 3652
from collections import defaultdict
alpha='abcdefghijklmnopqrstuvwxyz'
inf=float('inf')
res=dict()
for a in alpha:
    res[a]=inf
for i in range(int(input())):
    S=input()
    data=defaultdict(int)
    for s in S:
        data[s]+=1
    for a in alpha:
        res[a]=min(res[a],data[a])
ans=''
for a in alpha:
    ans+=a*res[a]
print(ans)

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

int main(){
  int A,B,T;
  cin >> A >> B >> T;
  int cnt = 0;
  int time = 0;
  for(;time < T+0.5-A;){
    time += A;
    cnt += B;
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
# 累積和, 二分探索
from itertools import accumulate
from bisect import bisect_right

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

a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

result = 0
for i in range(N + 1):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_right(b, t)
    result = max(result, i + j - 1)
print(result)


Measured memory_bytes: 50744
#include <stdio.h>

using namespace std;

int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x >= r && x <= W - r) && (y >= r && y <= H - r))
		printf("Yes\n");
	else{
		printf("No\n");
	}
}


Measured memory_bytes: 2696
import bisect
n,m,v,p = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
#print(a)
if (v<=p):
    limit = a[n-p]
    if (a[n-p] <= m):
        print(n)
    else:
        x = bisect.bisect_left(a,a[n-p]-m)
        print(n-x)
else:
    limit = a[n-p]
    #print(1,limit)
    wa = [0]*n
    wa[0] = a[0]
    for i in range(1,n):
        wa[i] = wa[i-1] + a[i]
    #print(limit,wa)
    ans = 0
    for i in range(n-p-1,-1,-1):
        sa = limit - a[i]
        if (sa==0):
            ans += 1
            continue
        elif (sa > m):
            continue
        if (i>=v):
            ans += 1
            
        else:
            nokori = (v-i-1-(p-1))*m
            #x = bisect.bisect_left(a,a[i]+m)
            #print(i,nokori)
            if (nokori <= (a[i]+m)*(n-p-i) - (wa[n-p]-wa[i])):
                ans += 1
                #print(i)
              
    print(ans + p)
    

Measured memory_bytes: 14252
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n, m;
	cin>>n>>m;
	int A[n][m];int B[m];int C[n];
	
	// 数组一定要注意初始化！！！ 
	for(int i=0;i<n;i++)
		C[i]=0;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>A[i][j];
		}
	}
	for(int i=0;i<m;i++)
		cin>>B[i];
	
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			C[i]+=((A[i][j])*B[j]);
		}
	}
	
	for(int i=0;i<n;i++)
		printf("%d\n",C[i]);

	
	return 0;
}


Measured memory_bytes: 3212
N, M, Q = map(int, input().split())

table = [[0 for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    L, R = map(int, input().split())
    table[L][R] += 1

for i in range(N+1):
    for j in range(N):
        table[i][j+1] += table[i][j]
for i in range(N):
    for j in range(N+1):
        table[i+1][j] += table[i][j]

for _ in range(Q):
    p, q = map(int, input().split())
    print(table[q][q] - table[q][p-1] - table[p-1][q] + table[p-1][p-1])



Measured memory_bytes: 18492
#include<iostream>
#include<complex>
#include<queue>
using namespace std;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
int main(){

    int w,h;
    while(cin>>w>>h,w){
        string screen[30];
        bool flg[30][30]={{false}};

        complex<int> pos;
        for(int i = 0;i < h;i++){
            cin>>screen[i];
            for(int j = 0;j < w;j++){
                if(screen[i][j] == '@'){
                    pos.real() = i;
                    pos.imag() = j;
                }
            }
        }

        queue< complex < int > > Q;
        Q.push(pos);
        while(!Q.empty()){
            complex<int> D = Q.front();
            Q.pop();
            flg[D.real()][D.imag()] = true;
            for(int i = 0;i < 4;i++){
                int x = D.real()+dx[i],y = D.imag()+dy[i];
                if(0<=x&&x<h&&0<=y&&y<w){
                    if(!flg[x][y]&&screen[x][y] == '.'){
                        complex<int>E;
                        E.real() = x;
                        E.imag() = y;
                        Q.push(E);
                    }
                }
            }
        }

        int cnt = 0;
        for(int i = 0;i < h;i++){
            for(int j = 0;j < w;j++){
                cnt += flg[i][j];
            }
        }
        cout<<cnt<<endl;


    }


    return 0;
}

Measured memory_bytes: 4256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	s := next()
	fmt.Printf("%c%d%c\n", s[0], len(s)-2, s[len(s)-1])
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
    int i, j;
    int a[4], b[4];
    
    while((scanf("%d", &a[0] ) != EOF)) {
        for(i = 1; i < 4; i++)
            scanf("%d", &a[i]);
        for(i = 0; i < 4; i++)
            scanf("%d", &b[i]);
        int count_hit = 0, count_blow = 0;
        for(i = 0; i < 4; i++) {
            for(j = 0; j < 4; j++) {
                if(i == j && a[i] == b[j])
                    count_hit++;
                else {
                    if(a[i] == b[j])
                        count_blow++;
                }
            }
        }
        
        printf("%d %d\n", count_hit, count_blow);
    }
    
    return(0);
}

Measured memory_bytes: 596
N,Y=map(int,input().split())
flag=0

for x in range(N+1):
  if flag==1:
    break
  for y in range(N+1-x):
    z=N-x-y
    money=10000*x+5000*y+1000*z
    if money == Y:
      print(x," ",y," ",z)
      flag=1
      break
        
if flag==0:
  print("-1 -1 -1")

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
	int i,n,d[6]={2,4,8,16,32,64};
	cin>>n;
	for(i=0;i<6;i++){
		if(d[i]>n){
			cout<<d[i-1]<<endl;
			return 0;
		}
	}
  cout<<d[i-1]<<endl;
	return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> vec = {a, b, c};
    sort(all(vec));

    int cnt = 0;
    int gap = vec[2] - vec[1];
    cnt += gap;
    vec[0] += gap;
    gap = vec[2] - vec[0];
    if (gap % 2 == 0) cnt += gap / 2;
    else cnt += (gap + 1) / 2 + 1;

    cout << cnt << endl;
}

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

int main(){
    string S, T;
    cin >> S >> T;
    int N, M;
    N = (int)S.size();
    M = (int)S.size();
    vector<int> SA(N+1, 0), TA(M+1, 0);
    for (int i = 1; i <= N; i++) {
        if (S[i-1] == 'A') SA[i] = SA[i-1]+1;
        else SA[i] = SA[i-1];
    }
    for (int i = 1; i <= M; i++) {
        if (T[i-1] == 'A') TA[i] = TA[i-1]+1;
        else TA[i] = TA[i-1];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int sp, tp;
        sp = (b-a+1) + SA[b] - SA[a-1];
        tp = (d-c+1) + TA[d] - TA[c-1];
        if ((sp-tp) % 3 == 0) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll d; cin>>d;
  vector<ll> c(26);
  rep(i, 26) cin>>c[i];
  vector<vector<ll>> s(d, vector<ll>(26));
  rep(i, d) rep(j, 26) cin>>s[i][j];
  vector<ll> t(d);
  rep(i, d) {
    cin>>t[i]; t[i]--;
  }

  vector<ll> nsc(26);
  vector<ll> score(d);
  vector<ll> last(26, -1);
  rep(i, d) {
    last[t[i]] = i;
    rep(j, 26) {
      if (t[i] == j) nsc[j] += s[i][j];
      else nsc[j] -= c[j]*(i-last[j]);
    }
    ll sum = 0;
    rep(j, 26) sum += nsc[j];
    score[i] = sum;
  }

  rep(i, d) cout << score[i] << endl;

  return 0;
}


Measured memory_bytes: 3704
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <bitset>
#define ll long long 
#define ri register int 
using std::min;
using std::bitset;
using std::max;
template <class T>inline void read(T &x){
    x=0;int ne=0;char c;
    while(!isdigit(c=getchar()))ne=c=='-';
    x=c-48;
    while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
    x=ne?-x:x;return ;
}
const int maxn=405;
const int inf=0x7fffffff;
bitset <maxn> o[maxn];
bool ok[maxn];
int a[100005],b[100005],m,n;
int main(){
	int x,y;
    read(n),read(m);
    for(ri i=1;i<=m;i++)read(a[i]),read(b[i]);
    for(ri i=1;i<=n;i++){
        o[i][i]=1;
        for(ri j=m;j>=1;j--){
            x=o[i][a[j]],y=o[i][b[j]];
            if(x&y)ok[i]=1;
            else if(x)o[i][b[j]]=1;
            else if(y)o[i][a[j]]=1;
        }
    }
    ll ans=0;
    for(ri i=1;i<=n;i++){
        for(ri j=i+1;j<=n;j++){
            if(ok[i]||ok[j])continue;
            if(!((o[i]&o[j]).any()))ans++;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
def solve():
    n, y = map(int, input().split())
    r = range(n+1)

    ans = "-1 -1 -1"
    for i in r:
        for j in r:
            k = (y-(10000*i+5000*j))//1000
            if k >= 0 and 10000*i+5000*j+1000*k == y and i+j+k == n:
                ans = "{} {} {}".format(i, j, k)
                print(ans)
                return

    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#![allow(non_snake_case)]
use std::cmp::{min, max};

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let N:usize = sc.read();
    let A:Vec<usize> = sc.vec(N);
    let mut dp:Vec<Vec<i64>> = vec![vec![-1;N+1];N+1];
    for i in 0..(N+1){
        dp[i][i] = 0;
    }
    let mut s:i64 = 0;
    for i in 0..N{
        s += A[i] as i64;
    }

    println!("{}", 2*(rec(&mut dp, 0, N, N, &A) as i64) - s);

}

fn rec(dp: &mut Vec<Vec<i64>>, l:usize, r:usize, N:usize, A:&Vec<usize>) -> usize{
    if dp[l][r] >= 0{
        return dp[l][r] as usize
    }

    if (N-(r-l))%2 == 1{
        dp[l][r] = min(rec(dp, l+1,r,N,A), rec(dp, l, r-1,N,A)) as i64;
    }else{
        dp[l][r] = max(rec(dp, l+1, r,N,A)+A[l], rec(dp, l,r-1,N,A)+A[r-1]) as i64;
    }
    dp[l][r] as usize
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}




Measured memory_bytes: 90492
fn main() {
    let a: i32 = read();
    println!("{}", a + a * a + a * a * a);
}

fn read<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
  cin>>s;
  stack<char>S;
  int N=s.size();
  for(int i=0;i<N;i++){
  if(s.at(i)!='B')
    S.push(s.at(i));
    else {
    if(!S.empty())
      S.pop();
    }
  
  }int M=S.size();
  string ans="";
  for(int i=0;i<M;i++){
    ans=S.top()+ans;
    S.pop();
  }
  cout<<ans<<endl;
   return 0;
}


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

using namespace std;

const int maxn = 310;

int n,m,a[maxn][maxn],res,cnt[maxn],sport[maxn];
bool choose[maxn];

bool fin(int ma) {
    for (int i=1;i<=m;i++) {
        cnt[i]=0;
        choose[i]=true;
    }
    for (int i=1;i<=n;i++) {
        cnt[a[i][1]]++;
        sport[i]=1;
    }
    for (int times=1;times<=m;times++) {
        int id=-1;
        for (int i=1;i<=m;i++)
            if (cnt[i]>ma) {
                id=i;
                break;
            }
        if (id==-1) return true;
        if (times==m) return false;
        choose[id]=false;
        for (int i=1;i<=n;i++) {
            cnt[a[i][sport[i]]]--;
            while (!choose[a[i][sport[i]]]) sport[i]++;
            cnt[a[i][sport[i]]]++;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
   // freopen("in.txt","r",stdin);
    cin>>n>>m;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++) cin>>a[i][j];
    int lo=1,hi=n;
    while (lo<=hi) {
        int mid = (lo+hi)/2;
        if (fin(mid)) {
            res=mid;
            hi=mid-1;
        }
        else lo=mid+1;
    }
    cout<<res;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

vector<int> a1(100001, 0), a2(100001, 0);

int main()
{
    int n, v;
    cin >> n;
    rep(0, i, n)
    {
        cin >> v;
        if (i % 2 == 0)
        {
            a1[v]++;
        }
        else
        {
            a2[v]++;
        }
    }
    P max1(0, 0), max2(0, 0), semimax1(0, 0), semimax2(0, 0);
    rep(0, i, 100001)
    {
        if (max1.first < a1[i])
        {
            semimax1 = max1;
            max1 = make_pair(a1[i], i);
        }
        else if (semimax1.first < a1[i])
        {
            semimax1 = make_pair(a1[i], i);
        }

        if (max2.first < a2[i])
        {
            semimax2 = max2;
            max2 = make_pair(a2[i], i);
        }
        else if (semimax2.first < a2[i])
        {
            semimax2 = make_pair(a2[i], i);
        }
    }
    /*
    cout << max1.first << ' ' << max1.second << endl;
    cout << max2.first << ' ' << max2.second << endl;
    cout << semimax1.first << ' ' << semimax1.second << endl;
    cout << semimax2.first << ' ' << semimax2.second << endl;
    */

    if (max1.second != max2.second)
    {
        cout << n - (max1.first + max2.first) << endl;
    }
    else
    {
        cout << n - max(max1.first + semimax2.first, max2.first + semimax1.first) << endl;
    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
const ll INF=1e10;
int d[10][10];
int V=10;

void warshall_floyd(){
    rep(k,0,V){
        rep(i,0,V){
            rep(j,0,V){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W;
    cin>>H>>W;
    rep(i,0,10){
        rep(j,0,10){
            cin>>d[i][j];
        }
    }
    warshall_floyd();
    int ans=0;
    int A[H][W];
    rep(i,0,H){
        rep(j,0,W){
            cin>>A[i][j];
            if(A[i][j]!=-1) ans+=d[A[i][j]][1];
        }
    }
    cout << ans<<"\n";
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int n,t[100],h[100],x,y,a,ba,l,i,j;
	while(1)
	{
		x=0;
		ba=0;
		l=1;
		scanf("%d", &n);
		if(n==0)
		break;
		for(i=0; i<n; i++)
		scanf("%d", &t[i]);
		for(i=1; i<=n*2; i++)
		{
			for(j=0; j<n; j++)
			{
				if(t[j]==i)
				break;
				else if(j==n-1)
				{
					h[x]=i;
					x++;
				}
			}
		}
		for(i=0; i<n-1; i++)
		{
			for(j=n-1; j>=i+1; j--)
			{
				if(t[j]<t[j-1])
				{
					a=t[j];
					t[j]=t[j-1];
					t[j-1]=a;
				}
			}
		}
		x=n;
		y=n;
		a=0;
		while(x>0&&y>0)
		{
			if(l%2!=0)
			{
				for(i=0; i<n; i++)
				{
					if(ba<t[i]&&t[i]!=999)
					{
						ba=t[i];
						t[i]=999;
						x--;
						break;
					}
					else if(i==n-1)
					ba=0;
				}
			}
			if(l%2==0)
			{
				a++;
				for(i=0; i<n; i++)
				{
					if(ba<h[i]&&h[i]!=999)
					{
						ba=h[i];
						h[i]=999;
						y--;
						break;
					}
					else if(i==n-1)
					ba=0;
				}
			}
			l++;
		}
		printf("%d\n%d\n", y, x);
	}
	return 0;
}


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

int a, b, c, k;
int main() {
	cin >> a >> b >> c >> k;
	int n = 0;
	while (b <= a) {
		b *= 2;
		++n;
	}
	while (c <= b) {
		c *= 2;
		++n;
	}
	if (n <= k)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 3636
from collections import defaultdict
 
n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7
d = defaultdict(int)
 
inner = 0
for i in range(n):
    d[a[i]] += 1
    for j in range(i+1,n):
        if a[i] > a[j]:
            inner += 1
 
t = 0
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            t += 1
 
x = ((t)*(k)*(k-1)//2)%mod
y = (inner*k)%mod
print(int((x+y)%mod))

Measured memory_bytes: 9548
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                A[j][k] = None
for i in range(3):
    if [None,None,None] == A[i]:
        print("Yes")
        exit(0)
for i in range(3):
    if [None,None,None] == [A[0][i],A[1][i], A[2][i]]:
        print("Yes")
        exit(0)
if [A[i][i] for i in range(3)] == [None,None,None]:
    print("Yes")
    exit(0)
if [A[0][2],A[1][1], A[2][0]] == [None,None,None]:
    print("Yes")
    exit(0)
print("No")

Measured memory_bytes: 3064
from collections import defaultdict


def main():
    n = int(input())
    d = defaultdict(int)
    for i in range(n):
        d[int(input())] += 1

    ans = 0
    for k in d.keys():
        if d[k] % 2 == 1:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 15456
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define ll long long int
ll max(ll a, ll b) {  return a > b ? a : b; }
ll gcd(ll a, ll b) { if (a == 0) return b; return b == 0 ? a : gcd(b, a % b);}
#define case(i) cout<<"Case #"<<i<<": ";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
#define debug2(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ]"; err(++it, args...);}
#define time__(d) for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second; debug2("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define pii pair <ll , ll >
#define pb push_back
#define PRECISION 10
const ll inf = 9223372036854775800;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;

void getac(int T) {
    int n;
    int m;
    cin >> n >> m;
    for (int i = 0; i <= n; i++) {
        int rem = n - i;
        if ((i * 2) + (rem * 4) == m) {
            cout << "Yes\n";
            return ;
        }
    }
    cout << "No\n";
}
int  main()
{

    fastio;
    int t = 1;
    if (takeTestCases) cin >> t;
    int t_t = 1;
    while (t--) {
        if (printCaseNo)
        case (t_t);

        getac(t_t);
        t_t++;
    }
    cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 3808
odd = [i for i in input()]
even = [i for i in input()]
password_list = []
for i in range(len(even)):
    password_list.append(odd[i])
    password_list.append(even[i])
if len(odd) == len(even)+1:
    password_list.append(odd[len(odd)-1])
password = "".join(password_list)
print(password)

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

int main(){
    ll n,a,b,c,ans=0;
    cin>>n>>a>>b>>c;
    vector<char> v;
    string s[n];
    for(ll i=0;i<n;i++) cin>>s[i];
    for(ll i=0;i<n-1;i++){
        if(s[i]=="AB"){
            if(s[i+1]=="BC"){
                if(a>0) a--,b++,v.push_back('B');
                else    a++,b--,v.push_back('A');
            }
            else if(s[i+1]=="AC"){
                if(b>0) b--,a++,v.push_back('A');
                else    b++,a--,v.push_back('B');
            }
            else{
                if(a<b) a++,b--,v.push_back('A');
                else    a--,b++,v.push_back('B');
            }
        }   
        if(s[i]=="BC"){
            if(s[i+1]=="AC"){
                if(b>0) b--,c++,v.push_back('C');
                else    b++,c--,v.push_back('B');
            }
            else if(s[i+1]=="AB"){
                if(c>0) c--,b++,v.push_back('B');
                else    c++,b--,v.push_back('C');
            }
            else{
                if(b<c) b++,c--,v.push_back('B');
                else    b--,c++,v.push_back('C');
            }
        }
        if(s[i]=="AC"){
            if(s[i+1]=="AB"){
                if(c>0) c--,a++,v.push_back('A');
                else    c++,a--,v.push_back('C');
            }
            else if(s[i+1]=="BC"){
                if(a>0) a--,c++,v.push_back('C');
                else    a++,c--,v.push_back('A');
            }
            else{
                if(a<c) a++,c--,v.push_back('A');
                else    a--,c++,v.push_back('C');
            }
        }
        if(a<0 || b<0 || c<0)   ans=-1;
    }
    if(s[n-1]=="AB"){
        if(a>0) v.push_back('B');
        else if(b>0)    v.push_back('A');
        else    ans=-1;
    }
    if(s[n-1]=="BC"){
        if(c>0) v.push_back('B');
        else if(b>0)    v.push_back('C');
        else    ans=-1;
    }
    if(s[n-1]=="AC"){
        if(a>0) v.push_back('C');
        else if(c>0)    v.push_back('A');
        else    ans=-1;
    }
    if(ans==-1) cout<<"No"<<endl;
    else{
        cout<<"Yes"<<endl;
        for(ll i=0;i<n;i++) cout<<v[i]<<endl;
    }
    return 0; 
}


Measured memory_bytes: 6888
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int num = 0, ans = 0;
    REP(i,n){
        if(s[i] == 'I') num++;
        else num--;
        ans = max(ans, num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>


int main(void){

  int x, y;
  int a, b, c;


  x=y=0;
  while(scanf("%d,%d,%d", &a, &b, &c)!=EOF){
    if(a+b>c){
      
      if(pow(a, 2)+pow(b, 2) == pow(c, 2)){
	x++;
      }
      else if(a==b){
	y++;
      }
    }
  }

  printf("%d\n%d\n", x, y);

  return(0);
}





Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI acos(-1)
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
const int N = 0;
 
typedef long long int ll;
 
using namespace std;


 
int main(){
    FIN;
    //freopen("../input.txt", "r", stdin);freopen("../output.txt", "w", stdout);
    string s;cin>>s;
    ll modulo[2020];
    fore(i,0,2020)modulo[i] = 0;
    modulo[0] = 1;
    ll temp = 0;
    ll mod10 = 1;
    ll ans = 0;
    fore(i,0,s.size()){
        int pos = s.size()-1-i;
        temp += ((s[pos]-'0')*mod10)%2019;
        temp %= 2019;
        mod10 = ((mod10%2019) * 10)%2019;
        modulo[temp]++;
        if(modulo[temp]>=2){
            ans += modulo[temp]-1;
        }
        //cout<<temp<<"\n"; 
    }   
    cout<<ans;
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove reader 
// - fastio
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?, is MAXN correct?)
// - special cases (n=1, graph not connected?)
// - re-initialize efficiently between test cases

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int a[n];
    int x[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)x[i][j]=-1;
    }
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<a[i];j++){
            int p,q;cin>>p>>q;p--;
            x[i][p]=q;
        }
    }
    int ans = 0;
    for(int k=1;k<(1<<n);k++){
        bitset<15> s(k);
        //cout<<s<<endl;
        int res=0;
        for(int i=0;i<s.size();i++){
            if(s[i]==1)res++;
        }
        bool jud=true;
        
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i==j)continue;
                if(s[i]==1&&s[j]==0&&x[i][j]==1){
                    jud=false;break;
                }
                else if(s[i]==1&&s[j]==1&&(x[i][j]==0||x[j][i]==0)){
                    jud=false;break;
                }
            }
        }
        if(jud){
            //cout<<s<<endl;
            ans=max(ans,res);
        }
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import Counter

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

ACounter=Counter(A)
Acommon=ACounter.most_common()

count=len(Acommon)
answer=0
index=-1

while(count>K):
  answer+=Acommon[index][1]
  count-=1
  index-=1
print(answer)

Measured memory_bytes: 39320
// finish date: 2019/11/24

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1000000007;
const long long INFll = 100000000000000000;

bool checker(string S, string query) {
    int pos = 0;
    rep(i, S.length()) {
        if (S[i] == query[pos]) {
            pos++;
            if (pos == 3) return true;
        }
    }
    return false;
}

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    rep(i, 1000) {
        string query = to_string(i);
        while (query.length() < 3) query = '0' + query;
        if (checker(S, query)) ans++;
    }

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


Measured memory_bytes: 384
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
print("? " +  " ".join(map(str, [i for i in range(1, n + 1)])))
flg = str(input())
ng = n + 1
ok = 1
while ok + 1 < ng:
    mid = (ok + ng) // 2
    print("? " + " ".join(map(str, [i for i in range(mid, mid + n)])))
    s = str(input())
    if flg != s:
        ng = mid
    else:
        ok = mid


L = [i for i in range(ok + 1, ok + n)]
b_cnt = 0
r_cnt = 0
LL = []
R = []
B = []
if flg == "Red":
    R += [ok]
    B += [ok + n]
else:
    B += [ok]
    R += [ok + n]

for j in range(1, 2 * n + 1):
    if ok <= j <= ok + n:
        continue
    L += [j]
    print("? " + " ".join(map(str, L)))
    L.pop()
    s = str(input())
    if s == "Blue":
        B += [j]
    else:
        R += [j]

LL = B[:n//2] + R[:n//2]
for k in range(ok + 1, ok + n):
    LL += [k]
    print("? " + " ".join(map(str, LL)))
    LL.pop()
    s = str(input())
    if s == "Blue":
        B += [k]
    else:
        R += [k]


ans = [""] * (2 * n)
for b in B:
    ans[b - 1] = "B"
for r in R:
    ans[r - 1] = "R"

print("! " + "".join(map(str, ans)))




Measured memory_bytes: 82736
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int A[200010];
map<int, int> mp;

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;

    rep(i, N) cin >> A[i];
    rep(i, N) A[i] -= i;
    rep(i, N) {
        mp[A[i]]++;
    }
    int ans = 0;
    rep(i, N) {
        ans += mp[-A[i] - i * 2];
        //cout << -A[i] - i * 2 << " " << ans << endl;
    }
    cout << ans << endl;
    



    return 0;
}


Measured memory_bytes: 27816
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def check(s):
        return s == s[::-1]
    s = input()
    n = len(s)
    if check(s) and (s[:(n-1)>>1]) and check(s[((n+3)>>1)-1:]):
        print("Yes")
    else:
        print("No")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38416
//shipc_d.cpp
//Sat Jul  7 20:35:37 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INF 1000000000000000000
using namespace std;
using ll=long long;
struct edge {ll to, cost;};
typedef pair<int,int> P;

vector<edge> Y[100000];
vector<edge> S[100000];
ll dy[100000];
ll ds[100000];
ll dtotal[100000];
ll dtotalt[100000];
int v,e;

void dijkstra (int s, int t){
	priority_queue<P, vector<P>, greater<P>> pq; //小さい順 
	fill (dy,dy+v,INF);
	dy[s] = 0;
	pq.push(P(0,s));
	while(!pq.empty()){
		P p = pq.top();
		pq.pop();
		int vtemp = p.second;
		if (dy[vtemp] < p.first){
			continue;
		}
		for (int i=0;i<Y[vtemp].size();i++){
			edge e = Y[vtemp][i];
			if (dy[e.to] > dy[vtemp] + e.cost){
				dy[e.to] = dy[vtemp] + e.cost;
				pq.push(P(dy[e.to],e.to));
			}
		}
	}

	fill (ds,ds+v,INF);
	ds[t] = 0;
	pq.push(P(0,t));
	while(!pq.empty()){
		P p = pq.top();
		pq.pop();
		int vtemp = p.second;
		if (ds[vtemp] < p.first){
			continue;
		}
		for (int i=0;i<S[vtemp].size();i++){
			edge e = S[vtemp][i];
			if (ds[e.to] > ds[vtemp] + e.cost){
				ds[e.to] = ds[vtemp] + e.cost;
				pq.push(P(ds[e.to],e.to));
			}
		}
	}
}

int main(){
	int s,t;
	cin >> v >> e >> s >> t;
	s--;
	t--;

	for (int i=0;i<e;i++){
		int start, end;
		ll yens, snuks;
		cin >> start >> end >> yens >> snuks;
		start--;
		end--;
		edge temp;
		temp.to = end;
		temp.cost = yens;
		Y[start].push_back(temp);
		temp.to = start;
		Y[end].push_back(temp);
		temp.to = end;
		temp.cost = snuks;
		S[start].push_back(temp);
		temp.to = start;
		S[end].push_back(temp);
	}

	dijkstra(s,t);
	ll minmoney=INF;
	vector<ll> dans;
	for (int i=v-1;i>=0;i--){
		dtotal[i] = dy[i]+ds[i];
		if (minmoney > dtotal[i]){
			minmoney = dtotal[i];
		}
		dans.push_back(minmoney);
	}

	for (int i=v-1;i>=0;i--){
		cout << 1000000000000000 - dans[i] << endl;
	}


}

Measured memory_bytes: 20580
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef pair<ll,string> Ps;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;
typedef priority_queue<Ps,vector<Ps>,greater<Ps>> Ps_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e18;
const double PI=3.1415926535897932;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod


ll N=0;
vec JUN;
vec FREQ(62);
ll SUM[62][129];
char ans[129];

ll Ask(string S){
    cout<<"? "<<S<<endl;
    ll x; cin>>x;
    return x;
}

ll Query(string S){
    return N-Ask(S);
}
void init(){
    rep(i,26) JUN.pb('a'+i);
    rep(i,26) JUN.pb('A'+i);
    rep(i,10) JUN.pb('0'+i);
    rep(i,62){
        string S;
        rep(j,128) S.pb(JUN[i]);
        FREQ[i]=128-Ask(S);
    }
    rep(i,62) N+=FREQ[i];
    rep(i,62) REP(j,1,129) SUM[i][j]=-1;
    rep(i,62) SUM[i][N]=FREQ[i];
    
    return;
}

void Cut(ll L, ll R){
    ll MID=(L+R)/2;
    ll m=61;
    vec Search;
    rep(i,62) {
        if(SUM[i][R]==SUM[i][L]){
            REP(j,L+1,R) SUM[i][j]=SUM[i][R];
            m=i; 
        }
        else Search.pb(i);
    }
    if(Search.size()==1){
        REP(j,L,R) ans[j]=JUN[Search[0]];
        return;
    }
    if(Search.size()<62){
        ll X=SUM[m][N]-SUM[m][L];
        ll CC=MID-L;
        REP(j,1,Search.size()){
            ll A=Search[j];
            string ret;
            rep(k,N) {
                if(k<MID) ret.pb(JUN[A]);
                else ret.pb(JUN[m]);
            }
            ll Y=Query(ret);
            SUM[A][MID]=Y-X;
            CC-=(SUM[A][MID]-SUM[A][L]);
        }
        SUM[Search[0]][MID]=SUM[Search[0]][L]+CC;
        Cut(L,MID);
        Cut(MID,R);
        return;
    }

    ll Sum=FREQ[61];
    rep(j,61){
        string ret;
        rep(k,N){
            if(k<MID) ret.pb(JUN[j]);
            else ret.pb('9');
        }
        SUM[j][MID]=Query(ret);
        Sum+=SUM[j][MID];
    }
    SUM[61][MID]=FREQ[61];
    ll P=(Sum-MID)/62;
    rep(j,62) SUM[j][MID]-=P;
    Cut(L,MID);
    Cut(MID,R);
    return;
}
string Solve(){
    init();
    Cut(0,N);
    string ret;
    rep(i,N) ret.pb(ans[i]);
    return ret;
}
int main(){
    string ANS=Solve();
    cout<<"! "<<ANS<<endl;
}



Measured memory_bytes: 3780
#include <stdio.h>
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int a[m];
  for(int i=0;i<m;i++) scanf("%d", &a[i]);
  int s=0;
  for(int i=0;i<m;i++) s+= a[i];
  if(n>=s) printf("%d", n-s);
  else printf("-1");
  return 0;
}


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

using namespace std ; 

const int N = 1e5 + 7 ; 


int main(){
    ios_base::sync_with_stdio(0) ; 
    cin.tie(0); 
    //freopen("in.in" ,"r" , stdin) ; 
    set<string> ss ; 
    int n ;
    cin>>n ; 
    for(int i = 0 ; i< n;i++){
        string s; 
        cin>>s ; 
        ss.insert(s) ; 
    }
    cout<<ss.size() ;
    return 0 ; 
}

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

int main(){
    ll n, k;
    cin >> n >> k;
    vector<int> dices(n);
    rep(i,n) cin >> dices.at(i);
    ll tmptotal = 0;
    int maxindex = 0;
    ll maxval = 0;
    rep(i,k) tmptotal += dices.at(i);
    maxval = tmptotal;
    for(int i = 1;i < n-k+1;i++){
        tmptotal = tmptotal - dices.at(i-1) + dices.at(i+k-1);
        // cout << dices.at(i-1) << " " << dices.at(i+k-1) << " " << tmptotal << endl;
        if(maxval < tmptotal) {
            maxval = tmptotal;
            maxindex = i;
        }
    }
// cout << "maxindex:" << maxindex << endl;
    ll ktotal = 0;
    // cout << maxval << endl;
    double kitai = (double)(maxval + k) / 2.0;
    cout << fixed << setprecision(10) << kitai << endl;
} 

Measured memory_bytes: 1024
#include<set>
#include<iostream>
using namespace std;
int main() {
    int T;
    cin >> T;
    set<int> s;
    while (T--) {
        int a;
        cin >> a;
        if (a==0) {int t; cin >> t;s.insert(t);
            cout << s.size() << endl;
        }
        else if (a==1) {
            int t;
            cin >> t;
            cout << (s.find(t) != s.end()) << endl;
        }
    }
    return 0;
}


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

#define infi            5e9
#define infl            5e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)

using namespace std;

inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}

// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//


int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle//freopen("in.txt", "r", stdin);//#endif
    //freopen("in.txt", "r", stdin);

    string str;
    cin >> str;

    stack<char>qq;
    loop(i, str.length()){
        if(str[i]!='B')qq.push(str[i]);
        else if(!qq.empty())qq.pop();
    }
    str="";
    while(!qq.empty()){
        str+=qq.top();
        qq.pop();
    }
    reverse(str.begin(),str.end());
    cout << str << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int K, N;
	int i, j, a;
	int ans = 0;

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

	int L[50];
	for(i = 0; i < N; i++)
		scanf("%d", &L[i]);

	for(i = 0; i < N; i++) {
		for(j = i + 1; j < N; j++) {
			if(L[i] > L[j]) {
				a = L[i];
				L[i] = L[j];
				L[j] = a;
			}
		}
	}

	for (i = N - 1; i >= N - K; i--)
		ans = ans + L[i];

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128