akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;

    int a[n + 1], c[n + 1];
    a[0] = 0;
    c[0] = 0;

    char now, prev, next;
    now = s[0];
    for (int i = 0; i < n; ++i)
    {
        if (i + 1 < n) next = s[i + 1];
        else next = 'T';
        a[i + 1] = a[i] + (now == 'A' && next == 'C');
        now = next;
    }

    prev = s[0];
    for (int i = 1; i <= n; ++i)
    {
        now = s[i - 1];
        c[i] = c[i - 1] + (prev == 'A' && now == 'C');
        prev = now;
    }

    int l, r;
    rep (i, q)
    {
        cin >> l >> r;
        cout << c[r] - a[l - 1] << "\n";
    }

    return 0;
}



Measured memory_bytes: 1872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    int n,m;
    cin >> n >> m;
    int H[n];
    bool Z[n];
    for(int i = 0;i < n;i++){
        cin >> H[i];
        Z[i] = true;
    }
    
    
    int a,b;
    for(int i = 0;i < m;i++){
        cin >> a >> b;
        if(H[a-1] > H[b-1]){
            Z[b-1] = false;
        }else if(H[a-1] < H[b-1]){
            Z[a-1] = false;
        }else{
            Z[a-1] = false;
            Z[b-1] = false;
        }
    }
    int ans = 0;
    for(int i = 0;i < n;i++){
        if(Z[i] == true){
            ans++;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 4124
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long k = in.nextLong();
        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = in.nextInt();
        }
        SortedMap<Integer, Integer> m = new TreeMap<>();
        long invPerA = 0;
        for(int i=0; i<n; i++) {
            invPerA += countGreater(m, a[i]);
            int c = m.containsKey(a[i]) ? m.get(a[i]) : 0;
            m.put(a[i], c+1);
        }
        long invForPrevA = 0;
        for(int i=0; i<n; i++) {
            invForPrevA += countGreater(m, a[i]);
        }
        BigInteger x1 = new BigInteger(Long.toString(invPerA));
        BigInteger x2 = new BigInteger(Long.toString(invForPrevA));
        BigInteger k2 = new BigInteger(Long.toString(k));
        BigInteger k3 = new BigInteger(Long.toString(k-1));
        BigInteger two = new BigInteger("2");
        BigInteger c = x1.multiply(k2).add(x2.multiply(k2).multiply(k3).divide(two));
        //long c = invPerA * k + invForPrevA * (k * (k-1) / 2);
        BigInteger mod = new BigInteger("1000000007");
        c = c.mod(mod);
        System.out.println(c.toString());
    }
    private static int countGreater(SortedMap<Integer, Integer> m, int key) {
        SortedMap<Integer, Integer> sub = m.tailMap(key);
        Set<Integer> keySet = sub.keySet();
        Iterator<Integer> it = keySet.iterator();
        int c = 0;
        while(it.hasNext()) {
            int k = it.next();
            if(k == key) {
                continue;
            }
            c += sub.get(k);
        }
        return c;
    }
}


Measured memory_bytes: 43796
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    string s,t;
    cin >> s >> t;
    s += s;
    bool ok = false;
    for (int i = 0; i < (int)t.size(); i++){
        int cnt = 0;
        for (int k = 0; k < (int)t.size(); k++){
            if (s[k+i] == t[k]){
                cnt++;
            }
        }
        if (cnt == (int)t.size()){
            ok = true;
        }
    }
    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }



    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define PK push_back
using namespace std;
typedef pair<int,int>P;
int a[100002];
int main(void){
	int n;
	int i,j;
	vector<P>v;
	cin>>n;
	int flg=0;
	P pp;
	for(i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]!=0)		flg=1;
	}
	a[0]=-1;
	a[n+1]=-1;
	i=1;
	//cout<<"check"<<endl;
	while(i<=n){
		j=i-1;
	//cout<<"I="<<i<<endl;
	//cout<<"J="<<j<<endl;
		while(a[i]==a[j])	j--;
	//cout<<"J="<<j<<endl;
	//cout<<"a[i]="<<a[i]<<" "<<"a[j]="<<a[j]<<endl;
		if(a[j]>a[i]){
			j=i+1;
			while(a[i]==a[j])	j++;
	//cout<<"a[i]1="<<a[i]<<" "<<"a[j]1="<<a[j]<<endl;
			if(a[i]<a[j]){
				pp.F=a[i];
				pp.S=1;
	//cout<<"PP.F1="<<pp.F<<" "<<"PP.S1="<<pp.S<<endl;
				v.PK(pp);
			}
			i=j;
		}
		if(a[j]<a[i]){
			j=i+1;
			while(a[i]==a[j])	j++;
	//cout<<"a[i]2="<<a[i]<<" "<<"a[j]2="<<a[j]<<endl;
			if(a[i]>a[j]){
				pp.F=a[i];
				pp.S=-1;
	//cout<<"PP.F2="<<pp.F<<" "<<"PP.S2="<<pp.S<<endl;
				v.PK(pp);
			}
			i=j;
		}
	}
	sort(v.begin(),v.end());
	//for(i=0;i<v.size();i++)		cout<<v[i].F<<" "<<v[i].S<<endl;
	int island=1;
	int MAX=1;
	for(i=0;i<v.size();i++){
		island+=v[i].S;
		if(v[i].F!=v[i+1].F&&i!=v.size()-1){
			MAX=max(MAX,island);
		}
	}
	MAX=max(MAX,island);
	if(flg==0)	MAX=0;
	cout<<MAX<<endl;
	return 0;
}



Measured memory_bytes: 4264
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int cnt[100005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		cnt[a]++;
	}
	int res=0;
	for(int i=0;i<=100000;i++){
		int all=0;
		for(int j=0;j<=2;j++){
			all+=cnt[i+j];
		}
		res=max(res,all);
	}
	printf("%d\n",res);
	return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    ll ans = 2 * 1e12 + 5;

    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            ans = min(ans, i + (N / i) - 2);
        }
    }

    cout << ans << endl;
}

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

int main() {
	string s;
	cin>>s;
	int l,r;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A'){
			l=i;
			break;
		}
	}
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='Z'){
			r=i;
			break;
		}
	}
	cout<<r-l+1<<endl;
}


Measured memory_bytes: 640
x = gets
until x.nil?
 y = x.to_i
 buntin = [512,256,128,64,32,16,8,4,2,1]
 weight = 0
 necebt = []
 buntin.each do |bt|
  if bt <= y
   necebt << bt
   y -= bt
  end
 end
 puts necebt.sort.join(" ")
 x = gets
end



Measured memory_bytes: 6828
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
using ll=long long;
using namespace std;
const auto mod=1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int ans=0;
  string s; cin >>s;
  int n=s.size();
  for(int i=0;i<n;++i){
  	if(s[i]!=s[n-i-1]) ans++;
  }
  
  cout << ans/2 << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int r = Integer.parseInt(sc.next());
    int d = Integer.parseInt(sc.next());
    int x = Integer.parseInt(sc.next());

    for (int i=0; i<10; i++){
      x = r*x - d;
      System.out.println(x);
    }
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll N, M;
    cin >> N >> M;
    ll tmp = M / N;
    for(int i = tmp; i > 0; i--) {
        ll amari = M - i * N;
        if(amari % i == 0) {
            cout << i << "\n";
            return 0;
        }
    }
    cout << 0 << "\n";
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        a: isize, v: isize,
        b: isize, w: isize,
        t: isize,
    }

    let flag: bool;
    if a == b {
        flag = true;
    } else if v <= w {
        flag = false;
    } else if (a - b).abs() <= (v - w) * t {
        flag = true
    } else {
        flag = false
    }

    if flag {
        println!("YES");
    } else {
        println!("NO");
    }
    
}


Measured memory_bytes: 2160
#include <stdio.h>
 
int main(void) {
    long long X, i, j;
    scanf("%lld", &X);
    for (i=-5400; i<=5400; i++) {
        for (j=-5400; j<=5400; j++) {
            if (i*i*i*i*i-j*j*j*j*j==X) {
                printf("%lld %lld", i, j);
                return 0;
            }
        }
    }
    return -1;
}


Measured memory_bytes: 1732
using System;

namespace ABC155A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            string[] ss = Console.ReadLine().Split(' ');
            a = int.Parse(ss[0]);
            b = int.Parse(ss[1]);
            c = int.Parse(ss[2]);
            if (a == b && b == c)
                Console.WriteLine("No");
            else if (a != b && b != c && a != c)
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}
int main(){
  int A,B,C,X,Y,count=INT_MAX,a,b;
  scanf("%d %d %d %d %d",&A,&B,&C,&X,&Y);
  for(int i=0;i<=max(X,Y);i++){
    //if(X-i<0)a=0;
    //else a=X-i;
    //if(Y-i<0)b=0;
    //else b=Y-i;
    count = min(count,C*i*2 + A*sei(X-i) + B*sei(Y-i));
  }
  printf("%d",count);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  Int n;
  F f;
  T ti;
  vector<T> dat;
  SegmentTree(){}
  SegmentTree(F f,T ti):f(f),ti(ti){}
  void init(Int n_){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }
  void build(const vector<T> &v){
    Int n_=v.size();
    init(n_);
    for(Int i=0;i<n_;i++) dat[n+i]=v[i];
    for(Int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  void set_val(Int k,T x){
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }
  T query(Int a,Int b){
    T vl=ti,vr=ti;
    for(Int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }
  template<typename C>
  Int find(Int st,C &check,T &acc,Int k,Int l,Int r){
    if(l+1==r){
      acc=f(acc,dat[k]);
      return check(acc)?k-n:-1;
    }
    Int m=(l+r)>>1;
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
    if(st<=l&&!check(f(acc,dat[k]))){
      acc=f(acc,dat[k]);
      return -1;
    }
    Int vl=find(st,check,acc,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(st,check,acc,(k<<1)|1,m,r);
  }
  template<typename C>
  Int find(Int st,C &check){
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> ls(n),rs(n);
  for(Int i=0;i<n;i++) cin>>ls[i]>>rs[i],ls[i]--;

  {
    using P = pair<Int, Int>;
    vector<P> vp;
    for(Int i=0;i<n;i++)
      vp.emplace_back(ls[i],rs[i]);
    sort(vp.begin(),vp.end());
    for(Int i=0;i<n;i++)
      tie(ls[i],rs[i])=vp[i];
  }

  {
    using P = pair<Int, Int>;
    vector<P> vp;
    for(Int i=0;i+1<n;i++)
      vp.emplace_back(rs[i],ls[i]);
    sort(vp.rbegin(),vp.rend());
    for(Int i=0;i+1<n;i++)
      tie(rs[i],ls[i])=vp[i];
  }

  const Int INF = 2e9;
  vector<Int> al(n),ar(n);
  al[n-1]=-INF;
  ar[n-1]=+INF;
  for(Int i=n-2;i>=0;i--){
    al[i]=max(al[i+1],ls[i]);
    ar[i]=min(ar[i+1],rs[i]);
    //cout<<ls[i]<<" "<<rs[i]<<"::::"<<al[i]<<" "<<ar[i]<<endl;
  }

  auto f1=[&](Int a,Int b){return max(a,b);};
  auto f2=[&](Int a,Int b){return min(a,b);};
  SegmentTree<Int> s1(f1,-INF);
  SegmentTree<Int> s2(f2,+INF);
  s1.build(ls);
  s2.build(rs);

  auto calc=[&](Int l,Int r)->Int{return l<=r?r-l:0;};

  Int ans=0;
  for(Int i=0;i<n;i++)
    chmax(ans,calc(ls[i],rs[i])+calc(f1(s1.query(0,i),s1.query(i+1,n)),
                                     f2(s2.query(0,i),s2.query(i+1,n))));

  for(Int i=0;i+1<n;i++){
    Int l=ls[n-1],r=rs[n-1];
    if(i) chmin(r,rs[i-1]);
    chmax(ans,calc(l,r)+calc(al[i],ar[i]));
  }

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


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

int main()
{
    int K, A, B;
    cin >> K >> A >> B;
    for (int i = A; i <= B; i++)
    {
        if (i % K == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	long long sum = 0;
	cin >> s;
	for(int i = 0; i < s.size(); i++)sum += s[i] - '0';
	cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 3728
import copy

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

ans = [10 ** 12 for i in range(2 ** (N - 1))]
seen = 1  #[[A[j] for j in range(i,N) if A[j] > A[i]] for i in range(0,N)]

for i in range(2 ** (N - 1)):
  AA = copy.deepcopy(A)
  cost = 0
  s = str(bin(i))[2:]
  if s.count("1") >= K:
    continue
    
  for j in range(N - 1):
    m = max(AA[:j + 1])
    a = AA[j + 1]
    if ((i >> j) & 1) and a <= m:
      cost += (m - a + 1)
      AA[j + 1] = m + 1
  
  if len([AA[i] for i in range(1,N) if AA[i] > max(AA[:i])]) >= K - 1:
    ans[i] = cost
    #print(AA,bin(i),cost)
    
print(min(ans))



Measured memory_bytes: 3572
<?php  
   fscanf(STDIN,"%d%d",$a,$v);
   fscanf(STDIN,"%d%d",$b,$w);
   fscanf(STDIN,"%d",$t);

if($v>$w&&abs($a-$b)<=($v-$w)*$t){
  echo "YES";
}else{
  echo "NO";
}
	
  

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

S = [list(input()) for _ in range(H)]

check = [[False]*W for _ in range(H)]

res = 0


for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue

        #if check[i][j]:
        #    continue

        mc = [[-1]*W for _ in range(H)]
        mc[i][j] = 0

        q = [(i, j)]
        #first = True
        while q:
            y, x = q.pop(0)
            for a, b in [(-1,0), (0,-1), (0,1), (1,0)]:
                if y+a < 0 or y+a >= H or x+b < 0 or x+b >= W:
                    continue

                if S[y+a][x+b] == "#":
                    continue


                if mc[y+a][x+b] == -1 or mc[y+a][x+b] > mc[y][x]+1:
                    mc[y+a][x+b] = mc[y][x]+1

                    res = max(res, mc[y+a][x+b])
                    q.append([y+a, x+b])

                    #if not first:
                        #check[y][x] = True
            #first = False

"""
for row in check:
    s = ""
    for x in row:
        if x:
            s += "#"
        else:
            s += "."
    print(s)
"""

print(res)

Measured memory_bytes: 3188
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    V = [int(i) for i in readline().split()]

    V.sort()
    x = V[0]
    for i in range(N-1):
        y = V[i+1]
        x = (x + y) / 2
    
    print(x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n;
	ll x[200005] = {};
	ll y[100005] = {};
	ll z[100005] = {};
	cin >> n;
	cin >> a;



	cout << ((n-a)*100+a*1900)*pow(2,a) << endl;
	//cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 256
ans_list = []

while True:
    x, y, s = map(int, input().split())
    if x == 0 and y == 0 and s == 0:
        break

    ans = 0
    for i in range(1, 1000):
        if i * (100 + x) // 100 > s:
            break
        for j in range(1, 1000):
            if i * (100 + x) // 100 + j * (100 + x) // 100 == s:
                ans = max(ans, i * (100 + y) // 100 + j * (100 + y) // 100)
            elif i * (100 + x) // 100 + j * (100 + x) // 100 > s:
                break
    #print(ans)
    ans_list.append(ans)

for i in ans_list:
    print(i)


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

#define readv(v) for(auto& a : v) cin >> a;

using ll = long long int;
using vi = vector<ll>;
using vvi = vector<vi>;

int main(){
    int N, M;
    cin >> N >> M;
    vvi ans(N, vi(2, 0));
    for (int i = 0; i < M; i++) {
        int p; char s[2];
        cin >> p >> s[0] >> s[1];
        if (not ans[p-1][0]) {
            ans[p-1][1] += (s[0]=='W');
            ans[p-1][0] += (s[0]=='A');
        }
    }
    int correct = 0, penalties = 0;
    for (int i = 0; i < N; i++) {
        correct += ans[i][0];
        if (ans[i][0]) penalties += ans[i][1];
    }
    cout << correct << ' ' << penalties << endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,h[N],w[N],g[N],x,y,s,t;
struct E{
	int l,to;
}e[N];
struct P{
	int d,w;
};
queue<P>Q;
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;++i){
		scanf("%d %d",&x,&y);
		e[i].to=y;
		e[i].l=h[x];
		h[x]=i;
	}
	scanf("%d %d",&s,&t);
	w[s]=1;
	Q.push({s,0});
	while(!Q.empty()){
		P k=Q.front();Q.pop();
		bool fl= (k.w%3)==2;
//		printf("%d %d %d\n",k.d,k.w,fl);
		for(int i=h[k.d];i;i=e[i].l){
			if(fl){
				if(!w[e[i].to]){
					w[e[i].to]=k.w/3+1;
					Q.push({e[i].to,k.w+1});
				}
			}
			else {
				if(g[e[i].to]!=k.w+1){
					g[e[i].to]=k.w+1;
					Q.push({e[i].to,k.w+1});
				}
			}
		}
		if(w[t])break;
	}
	if(!w[t])w[t]=-1;
	printf("%d",w[t]);
}

Measured memory_bytes: 2176
def SelectionSort(a,n)
    cnt=0
    (0..n-1).each do |i|
        mini=i
        (i..n-1).each do |j|
            if a[j] < a[mini] then
               mini=j
            end
        end
        if mini!=i then
           a[i],a[mini]=a[mini],a[i]
           cnt+=1
        end
    end
    return cnt
end
n=gets.to_i
indata=gets.split(' ').map(&:to_i)
n=SelectionSort(indata,n)
puts indata.join(' ')
puts n

Measured memory_bytes: 8656
#!/usr/bin/env python3
n, k = map(int, open(0).read().split())
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
print(len(Base_10_to_n(n, k)))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0LL;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define IT ::iterator
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);

int main()
{
   int n,i,j;
   cin >> n;
   vector<int>g[n+1];
   for(i=1;i<n;i++)
   {
		g[i].pb(i+1);
		g[i+1].pb(i);
   }
  // cout << g[n][0] << endl;
   int x,y;
   cin >> x >> y;
   g[x].pb(y);
   g[y].pb(x);
	vector<int>v(n+1,0);
	
   for(i=1;i<n;i++)
   {
   	queue<int>q;
   	int s=i;
   	q.push(s);
   	bool vis[n+1];
	int dist[n+1];
   	memset(dist,0,sizeof(dist));
   	memset(vis,false,sizeof(vis));	
   	vis[s]=true;
   	while(!q.empty())
	{
		int f=q.front();
		//cout << f << endl;
		q.pop();
		for(j=0;j<(int)g[f].size();j++)
		{
			int w=g[f][j];
			//cout << w << endl;
			if(vis[w]==false)
			{
				//if(f==n && s==3)cout << " w " << dist[f] << endl;
				vis[w]=true;
				dist[w]=dist[f]+1;
				if(w>s){
					//if(dist[w]==2)cout << " s " << s << " w " << w << endl;
				v[dist[w]]++;}
				
				q.push(w);
			}
		}
	}
   }
   
   for(i=1;i<n;i++)
   {
   	cout << v[i] << endl;
   }
}


Measured memory_bytes: 3752
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vdewansa
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BFrog2 solver = new BFrog2();
        solver.solve(1, in, out);
        out.close();
    }

    static class BFrog2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            int[] h = new int[N];
            for (int i = 0; i < N; i++) {
                h[i] = in.nextInt();
            }
            long[] cost = new long[N];
            cost[0] = 0;
            cost[1] = Math.abs(h[1] - h[0]);
            for (int i = 2; i < N; i++) {
                cost[i] = Long.MAX_VALUE;
                int s = Math.max(0, i - K);
                for (int j = s; j <= i; j++) {
                    cost[i] = Math.min(cost[i], cost[j] + Math.abs(h[i] - h[j]));
                }
            }
            out.println(cost[N - 1]);
        }

    }
}



Measured memory_bytes: 51016
import scala.io.StdIn._

object Main extends App {

  val (n, k) = readNK
  val numList = readLine.split(" ").map(_.toInt)

  var max = -1
  var maxPos = -1
  var sum = -1

  for (i <- 0 to numList.length - k) {

    if (max < 0) {
      sum = numList.slice(i, i + k).sum
    } else {
      sum = sum - numList(i - 1) + numList(i + k - 1)
    }

    if (sum >= max) {
      max = sum
      maxPos = i
    }
  }

  val out = numList.slice(maxPos, maxPos + k).map { num =>
    (num * (num + 1)).toDouble / (2 * num)
  }.sum


  println(out)

  private def readNK = {
    val nk = readLine.split(" ").map(_.toInt)
    nk(0) -> nk(1)
  }
}


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a < 6) cout << 0 << ln;
    else if(a < 13) cout << b / 2 << ln;
    else cout << b << ln;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
using P = pair<int,char>;
using T = tuple<int,int,int>;

int main(){
    char trump;
    while(cin>>trump,trump!='#'){
        vector<P> V[4];
        for(int i=0;i<4;i++){
            for(int j=0;j<13;j++){
                char a,b;
                cin>>a>>b;
                int str;
                if('2'<=a&&a<='9'){
                    str=a-'2';
                }else if(a=='T'){
                    str=8;
                }else if(a=='J'){
                    str=9;
                }else if(a=='Q'){
                    str=10;
                }else if(a=='K'){
                    str=11;
                }else{
                    str=12;
                }
                V[i].emplace_back(str,b);
            }
        }
        int EW=0,NS=0;
        int leader=0;
        for(int i=0;i<13;i++){
            vector<T> Trick;
            for(int j=0;j<4;j++){
                int suit;
                if(get<1>(V[j][i])==trump){
                    suit=2;
                }else if(get<1>(V[j][i])==get<1>(V[leader][i])){
                    suit=1;
                }else{
                    suit=0;
                }
                int str=get<0>(V[j][i]);
                Trick.emplace_back(suit,str,j);   
            }
            sort(Trick.begin(), Trick.end(),greater<T>());
            leader=get<2>(Trick.front());
            if(leader%2){
                EW++;
            }else{
                NS++;
            }
        }
        if(NS>6){
            cout<<"NS "<<NS-6<<endl;
        }else{
            cout<<"EW "<<EW-6<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3056
/*
* @author:  codancer
* @createTime:  2020-06-29, 11:14:13
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
const int N = 1e4+10;
int main(){
	int n;
	cin>>n;
	vector<ll> a(n+1,0);
	rep(i,1,n){
		for(int j=i;j<=n;j+=i) a[j]++;
	}
	ll ans=0;
	rep(i,1,n) ans+=a[i]*i;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 81328
n,m = map(int,input().split())
par = [i for i in range(n+1)]
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x] = y
ls = [list(map(int,input().split())) for _ in range(m)]
ans = 0
for i in ls:
    for k in ls:
        if i != k:
            [a,b] = k
            unite(a,b)
    flag = True
    for p in range(1,n+1):
        for q in range(1,n+1):
            if not same(p,q):
                flag = False
                break
        if flag == False:
            break
    if flag == False:
        ans += 1
    par = [i for i in range(n+1)]
print(ans)

Measured memory_bytes: 9188
from math import sqrt


def IsPrime(num):
    if num < 2:
        return True
    elif num == 2:
        return True
    elif num % 2 == 0:
        return False

    sqrtNum = sqrt(num)
    for i in range(3, int(sqrtNum) + 1, 2):
        if num % i == 0:
            return False

    return True


if __name__ == "__main__":
    x = int(input())

    for i in range(x, 10**5+4):
        if IsPrime(i):
            print(i)
            exit()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
 
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

void solve() {
  ll x;
  cin >> x;
  cout << (x / 500) * 1000 + (x % 500) / 5 * 5 << endl;
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
 
  return 0;
}

Measured memory_bytes: 256
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,a[100010],b[100010],p,ans=0;

int main()
{
	cin>>n;
	rep(i,n+1) scanf("%I64d",&a[i]);
	rep(i,n) scanf("%I64d",&b[i]);
	rep(i,n)
	{
		p=a[i];
		a[i]=max(a[i]-b[i],0LL);
		ans+=p-a[i];
		b[i]-=p-a[i];
		p=a[i+1];
		a[i+1]=max(a[i+1]-b[i],0LL);
		ans+=p-a[i+1];
		b[i]-=p-a[i+1];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <iterator>
#include <locale>
#include <memory>
#include <stdexcept>
#include <utility>
#include <string>
#include <fstream>
#include <ios>
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <streambuf>
#include <complex>
#include <numeric>
#include <valarray>
#include <exception>
#include <limits>
#include <new>
#include <typeinfo>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdlib>
#include <cstddef>
#include <cstdarg>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cwchar>
#include <cwctype>
using namespace std;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
using ll = long long;
using ull = unsigned long long;

#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v,0,sizeof(v))
#define MP(a,b) make_pair((a),(b))
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ABS(a) ((a)>0?(a):-(a))
template<class T> T MIN(const T& a, const T& b) { return a < b ? a : b; }
template<class T> T MAX(const T& a, const T& b) { return a > b ? a : b; }
template<class T> void MIN_UPDATE(T& a, const T& b) { if (a > b) a = b; }
template<class T> void MAX_UPDATE(T& a, const T& b) { if (a < b) a = b; }

constexpr int mo = 1000000007;
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	std::ios::sync_with_stdio(false);

	ll A, B, K;
	cin >> A >> B >> K;

	ll i = MIN(A, K);
	A -= i;
	K -= i;

	i = MIN(B, K);
	B -= i;
	K -= i;

	cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define MAX (long long )1e9+7
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define endl "\n"
#define all(A) A.begin(),A.end()





 
int32_t main(){
	string s1, s2;
	cin >> s1 >> s2;
	bool flag = true;
	for(int i = 0; i<s1.size() ; i++){
		if(s2[i] != s1[i]){
			flag = false;
			break;
		}
	}
	
	string r = flag == true? "Yes\n":"No\n";
	cout << r << endl;

	return 0;
 
}

Measured memory_bytes: 3628
def main():
    s = input()
    a, b, c, d = s
    ops = ["+", "-"]
    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                expr = a + op1 + b + op2 + c + op3 + d
                if eval(expr) == 7:
                    print(expr + "=7")
                    return


if __name__ == "__main__":
    main()


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

bool solve(vector<ll> &v, string &s) {
    vector<ll> b;
    int n = v.size();
    rep(i, n) {
        ll a = v[i];
        for (auto x : b) cmin(a, a ^ x);
        if (a) {
            if (s[i] == '1') {
                return false;
            }
            b.push_back(a);
        }
    }
    return true;
}

int main() {

    int t;
    cin >> t;

    rep(_, t) {
        int n;
        cin >> n;

        vector<ll> v(n);
        rep(i, n) cin >> v[i];

        string s;
        cin >> s;

        reverse(v.begin(), v.end());
        reverse(s.begin(), s.end());

        bool b = solve(v, s);
        cout << (b ? 0 : 1) << endl;

    }


}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
using namespace std;
int main() {
	int x = 0;
	string s;
	cin >> s;
	for (int a = 0; a < 4; a++) {
		for (int b = 0; b < 4; b++) {
			if (s[a] == s[b])x++;
		}
	}
	if (x == 8)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int upto=50000;
int main(){
    vector<bool> prs(upto+1,true);
    prs[0]=prs[1]=false;
    for(int i=2;i<=sqrt(upto);i++){
        if(prs[i]){
            for(int j=i*i;j<=upto;j+=i)prs[j]=false;
        }
    }
    for(;;){
        int n;
        scanf("%d",&n);
        if(n==0)break;
        int ans=0;
        for(int i=2;i<=n/2;i++){
            if(prs[i]&&prs[n-i])ans++;
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

string s;

int main(void){
    
    cin >> s;
    
    int a = 0, b = s.size();
    for(int i = 0; s[i] != 'A'; ++i) ++a;
    for(int i = s.size() - 1; s[i] != 'Z'; --i) --b;
    printf("%d\n", b - a);
    
    return 0;
}

Measured memory_bytes: 640
[k,n] = [int(x) for x in input().split()]
data = [int(x) for x in input().split()]
data.append(data[0]+k) # 最後の家から最初の家までの距離を追加する

kankaku_list = []
for i in range(n):
    kankaku_list.append(data[i+1]-data[i])

target_distance = k - max(kankaku_list)

print(target_distance)

Measured memory_bytes: 26444
N, K = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * N
for i in range(1, N):
    temp = []
    for j in range(1,K+1):
        if (i - j) == -1:
            break
        else:
            temp.append(c[i-j]+abs(h[i]-h[i-j]))
    c[i] = min(temp)
    #print(c, temp)
print(c[-1])

Measured memory_bytes: 52448
let m = 1039999

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let to_x = Array.make 128 0

let to_key s =
  let n = String.length s in
  let rec doit i p acc =
    if i = n then acc
    else doit (i + 1) (5*p) (acc + p*(to_x.(Char.code s.[i]))) in
  doit 0 1 0

let to_h1 k = k mod m
let to_h2 k = 1 + (k mod (m - 1))

let insert s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then ()
    else if t.(h) = "\000" then t.(h) <- s
    else doit (i + 1) in
  doit 0

let find s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then true
    else if t.(h) = "\000" then false
    else doit (i + 1) in
  doit 0

let () =
  to_x.(Char.code 'A') <- 1;
  to_x.(Char.code 'C') <- 2;
  to_x.(Char.code 'G') <- 3;
  to_x.(Char.code 'T') <- 4;
  let n = read_int () in
  let t = Array.make m "\000" in
  let rec doit i =
    if i < n then begin
      begin match split_on_char ' ' (read_line ()) with
      | ["insert"; s] -> insert s t
      | ["find"; s] -> print_endline (if find s t then "yes" else "no")
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

Measured memory_bytes: 20996
#include<iostream>
using namespace std;
int n,sum;
string s;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	int cnt=0;
	for(int i=1,x,y;i<=n;i++){
		cin>>x>>y;
		if(cnt>=3) continue;
		if(x==y) cnt++;
		else cnt=0;
	}
	if(cnt>=3) cout<<"Yes";
	else cout<<"No";
	
}

Measured memory_bytes: 3132
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))

def check(x):
  k = 0
  for i in range(N):
    if a[i] > x:
      k += a[i] // x
  return k <= K

ok = 10 ** 9 + 1
ng = 0
while ok - ng > 1:
  m = (ok + ng) // 2
  if check(m): ok = m
  else: ng = m
print(ok)

Measured memory_bytes: 92040
#include <bits/stdc++.h>
using namespace std;
const int MAXN=26;
bool mp[201000];
int main(int argc, char const *argv[])
{
    int n,m;
    while(~scanf("%d %d",&n,&m))
    {
        queue <int>q;
        memset(mp,true,sizeof(mp));
        int x;
        int a[m+100];
        for(int i=1;i<=m;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=m;i>=1;i--)
        {
            if(mp[a[i]])
            q.push(a[i]);
            mp[a[i]]=false;
        }
        while(!q.empty())
        {
            int t=q.front();
            printf("%d\n",t);
            q.pop();
        }
        for(int i=1;i<=n;i++)
        {
            if(mp[i])
            {
                printf("%d\n",i);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3972
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)

int main() {
	ll n; cin >> n;
	ll a[2][100] = {};
	rep(i, 0, n) cin >> a[0][i];
	rep(i, 0, n) cin >> a[1][i];

	ll maxV = 0;
	rep(i, 0, n) {
		ll t = 0;

		repe(j, 0, i) {
			t += a[0][j];
		}
		rep(k, i, n) {
			t += a[1][k];
		}
		maxV = max(t, maxV);
	}
	cout << maxV << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
#define MOD 1000000007;

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    cout << min(N * A, B) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;

lint ksum(lint n){
    return n*(n+1)/2;
}

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

    lint n; cin>>n;
    lint sum = 0;
    for (lint i = 1; i<=n; ++i){
        sum += i * ksum(n/i);
    }
    cout<<sum;
}


Measured memory_bytes: 3648
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var s string
	if sc.Scan() {
		s = sc.Text()
	}

	sei := strings.Split(s, " ")

	a, _:= strconv.Atoi(sei[0])
	b, _:= strconv.Atoi(sei[1])
	c, _:= strconv.Atoi(sei[2])

	d := b + c

	if d < a{
		fmt.Println(0)
	}else{
		ans := d - a
		fmt.Println(ans)
	}
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int n;
  cin>>n;
  int ans=0;
  rep(i,n){
    int a;
    cin>>a;
    ans^=a;
  }

  if(ans){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
}


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

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

  int k,a,b;
  cin >> k >> a >> b;

  int num = k;
  bool flag = false;
  while(true) {
    if(num > b) break;
    if(num >= a && num <= b) {
      flag = true;
      break;
    }
    num += k;
  }
  if(flag) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define sachin ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
    sachin
    long long a,b,c;
    cin>>a>>b>>c;
    if(a-b>=c)
        cout<<0<<endl;
    else cout<<b-(a-c)<<endl;
    return 0;
}


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

bool ans = true;
int flag;

int main(){
    string s;cin>>s;
    for(int i=0;i<s.length();i++){
        if(i==0)if(s[i]!='A')ans=false;
        if(i==1)if(!(s[i]>='a'&&s[i]<='z'))ans=false;
        if(i==s.length()-1){if(!(s[i]>='a'&&s[i]<='z'))ans=false;}
        if(i>=2 && i<=s.length()-2){
            if(!(s[i]>='a'&&s[i]<='z')){
                if(s[i]=='C')flag++;
                else ans=false;
            }
            else if(!(s[i]>='a'&&s[i]<='z'))ans=false;
        }
    }
    if(flag!=1)ans=false;
    if(ans)cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//

int main(){
    string x; cin>>x;
    stack<char> s;
    s.push('X');
    FOR(i,0,x.size()){
        if(s.top()=='S'&&x[i]=='T'){
            s.pop();
        }else{
            s.push(x[i]);
        }
    }
    co(s.size()-1);
}


Measured memory_bytes: 644