akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define vvl vector<vector<ll>>
#define vl  vector<ll>
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
//lcm:最小公倍数、gcd:最大公約数
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back 
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

//ll n;
string s;
signed main(){
	acc_io;
	//ll n;
	cin>>s;
	string ans;
	rep(i,0,s.size()){
		if(s[i]=='B'){
			if(ans.size())	ans.pop_back();
		}
		else{
			ans.push_back(s[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int mod = 1000000007;

int main()
{
    int N, ans = 0;
    string S;
    cin >> N >> S;
    for (int i = 0; i < N - 2; i++)
    {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
            ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let (k, x): (usize, usize) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        let mut ws = s.split_whitespace();
        let a = ws.next().unwrap().parse().unwrap();
        let b = ws.next().unwrap().parse().unwrap();
        (a, b)
    };

    if 500 * k >= x {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main()
{
    int a[10]={};
    int i;
    
    for (i=0; i<10; i++) {
        cin >> a[i];
    }
    
    sort(a,a+10);
    
    for (i=9; i>6; i--) {
        cout << a[i] <<endl;
    }
    
}

Measured memory_bytes: 1176
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>

using namespace std;
typedef long long ll;

int main()
{
  int n, t;
  cin >> n >> t;
  vector<ll> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }

  ll sum = 0;
  for (int i = 1; i < n; i++) {
    if (vec[i - 1] + t > vec[i]) {
      sum += vec[i] - vec[i - 1];
    } else {
      sum += t;
    }
  }
  sum += t;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll S[150000];
vector<ll> K;
ll Ssum[150000];
ll dp[2050][2050];

void chmin(ll &a, ll b) {
    a = min(a, b);
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, L;
    cin >> N >> M >> L;
    K.resize(N);
    for(int i = 0; i < N; i++) cin >> K[i];
    K.push_back(-1);
    sort(K.begin(), K.end());
    for(int i = 1; i <= M; i++) {
        cin >> S[i];
        Ssum[i] = Ssum[i-1] + S[i];
    }
    //dp[1][1] = 0;
    dp[2][1] = (Ssum[K[2]] - Ssum[K[1] - 1]) / L;
    for(int num = 3; num <= N; num++) {
        for(int after = 1; after <= num - 2; after++) {
            dp[num][after] = 1e18;
            chmin(dp[num][after], dp[num-1][after] + (Ssum[K[num]] - Ssum[K[num-1]-1]) / L);
            //cerr << num << " " << after << " " << dp[num][after] << endl;
        }
        dp[num][num-1] = 1e18;
        for(int after = 1; after <= num - 2; after++) {
            chmin(dp[num][num-1], dp[num-1][after] + (Ssum[K[num]] - Ssum[K[after]-1]) / L);
        }
        //cerr << num << " " << num-1 << " " << dp[num][num-1] << endl;
    }
    ll ans = 1e18;
    for(int i = 1; i < N; i++) {
        chmin(ans, dp[N][i] + (Ssum[K[N]] - Ssum[K[i]-1]) / L);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 27580
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=998244353
########################################################
n,k=INPUT()
A=[]
for i in range(k):
    x,y=INPUT()
    A.append([x,y])
A.sort()
s,e=-1,-1
S=[]
for i in range(len(A)):
    if i==0:
        S.append([A[i][0],A[i][1]])
    else:
        if A[i][0]>S[-1][1]:
            S.append([A[i][0],A[i][1]])
        else:
            S[-1][1]=A[i][1]
cum=[0]*(n+1)
dp=[0]*(n+1)
dp[1]=1
cum[1]=1
for i in range(2,n+1):
    for ele in S:
        x=ele[0]
        y=ele[1]
        dp[i]=(dp[i]+cum[max(i-x,0)]-cum[max(0,i-y-1)])%J
    cum[i]=(cum[i-1]+dp[i])%J
print(dp[n])


Measured memory_bytes: 86692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	int ans = sz(s) + 10;
	rep(i,0,26){
		char c = i+'a';
		string t = s; t.push_back(c);
		int cur = 0;
		rep(i,0,sz(s)){
			int j = i;
			while(t[j] != c) ++j;
			cur = max(cur, j-i);
		}
		ans = min(ans, cur);
	}
	cout << ans << endl;
}

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

using i64 = int64_t;

int main(){
    int n, m, t;
    cin >> n >> m >> t;
    vector<int> v;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        v.push_back(a);
    }
    int ans = 0;
    for(int i=1;i<n;++i){
        ans += max(0, v[i]-v[i-1]-2*m);
    }
    ans += v[0] - m;
    ans += max(0, t-v.back()-m);

    cout << ans << endl;

    return 0;
}



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

void solve_A(){
	//AAAAAAAAAA
	int a,b;
	cin >> a >> b;
	cout << max(0,a-2*b) << endl;
}

void solve_B(){
	//BBBBBBBBBB
	int n,i,d[100],sum=0,sum2=0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> d[i];
		sum+=d[i];
		sum2+=(d[i]*d[i]);
	}
	cout << (sum*sum-sum2)/2 << endl;
}

void solve_C(){
	//CCCCCCCCCC
	int n,i,ans=1;
	char s[100005];
	cin >> n >> s;
	for(i=1;i<n;i++) if(s[i-1]!=s[i]) ans++;
	cout << ans << endl;
}

void solve_D(){
	//DDDDDDDDDD
	long long n,i,j,l,m,ans=0;
	vector<long long> g;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> l;
		g.push_back(l);
	}
	sort(g.begin(),g.end());
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			m=g[i]+g[j];
			ans += (n-(lower_bound(g.begin(),g.end(),m)-g.begin()));
		}
	}
	cout << n*(n-1)*(n-2)/6 - ans << endl;
}

int main() {
	// your code goes here
	//solve_A();
	solve_B();
	//solve_C();
	//solve_D();
	return 0;
}

Measured memory_bytes: 256
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    S = input().rstrip()

    def check(s):
        a = len(s) // 2
        for i in range(a):
            if s[i] != s[-(i+1)]:
                return False
        return True
    b = len(S) // 2
    s1 = S[:b]
    s2 = S[b+1:]
    if check(S) and check(s1) and check(s2):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
S = input()

A = list('AKIHABARA')
ap = [0, 4, 6, 8]
l = []

for i in range(2 ** 4):
    for j in range(4):
        if i >> j & 1 == 1:
            A[ap[j]] = ''
    l.append(''.join(A))
    A = list('AKIHABARA')

if S in l:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++) 

using namespace std;

int main() {
  string a,b;
  cin>>a>>b;
  int A=stoi(a),B=stoi(b);
  int cnt=0;
  for(int i=A;i<=B;i++){
    string s=to_string(i);
    if(s[0]==s[4]&&s[1]==s[3])cnt++;
  }
  cout<<cnt<<endl;
}

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

#define int long long
#define loop(x) for(int i = 0;i<(x);i++)
string alpha = "abcdefghijklmnopqrstuvwxyz";
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.tie(0);
	int x; cin >> x;
	cout << (double)(2.0 * (double)x * 3.14159);
}

Measured memory_bytes: 3804
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

struct point{
	double x,y;
	point operator+(point p){
		return point{x+p.x,y+p.y};
	}
	point operator-(point p){
		return point{x-p.x,y-p.y};
	}
	point operator*(double p){
		return point{x*p,y*p};
	}
	point operator/(double p){
		if(!p) return point{0,0}; 
		return point{x/p,y/p};
	}
	bool operator==(point p){
		return fabs(x-p.x)<eps&&fabs(y-p.y)<eps;
	}
};
 
typedef pair<point,point> pp;
typedef vector<point> VP;
const point O{0,0};
 
class Geom{
	public:
	double Length(point x,point y){
		point z=y-x;
		return sqrt(z.x*z.x+z.y*z.y);
	}
	double IP(point p,point q){
		return p.x*q.x+p.y*q.y;
	}
	double CP(point p,point q){
		return p.x*q.y-q.x*p.y;
	}
/*	string Convex_Concave(VP p){
		p.push_back(p[0]);
		string s;
		for(VP::iterator i=p.begin()+1;i!=p.end()-1;i++){
			s=Counter_Clockwise(pp(*(i-1),*i),*(i+1));
			if(s[1]=='l') return "Concave";
		}
		return "Convex";
	}*/
	double Heron(point A,point B,point C){
		double a=Length(B,C),b=Length(C,A),c=Length(A,B),s=(a+b+c)/2;
		return sqrt(s*(s-a)*(s-b)*(s-c));
	}
	double Area(VP p){
		double sum=0,cp;
		p.push_back(p[0]);
		for(VP::iterator i=p.begin()+1;i!=p.end();i++){
			cp=CP(*(i-1),*i);
			if(cp>0) sum+=Heron(O,*(i-1),*i);
			else if(cp<0) sum-=Heron(O,*(i-1),*i);
		}
		return sum;
	}
/*	string Containment_polyon_point(VP p,point x){
		string s;
		p.push_back(p[0]);
		double sum,area=Area(p);
		for(VP::iterator i=p.begin()+1;i!=p.end();i++){
			
		}
	}*/
	void Point_in(point& p){
		cin>>p.x>>p.y;
	}
};

int N;
VP p;
point q;

int main(){
	cout<<syosu(1);
	Geom geo;
	cin>>N;
	p=VP(N);
	for(VP::iterator i=p.begin();i!=p.end();i++) geo.Point_in(*i);
/*	cin>>Q;
	for(int i=0;i<Q;i++){
		geo.Point_in(q);
		string s=geo.Containment_polyon_point(p,q);
		if(s=="Containment") cout<<2<<endl;
		else if(s=="On_side") cout<<1<<endl;
		else cout<<0<<endl;
	}*/
	cout<<geo.Area(p)<<endl;
}

Measured memory_bytes: 1316
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>

int main(void){
    std::string S;
    int N, ans=1000;
    std::cin >> S;

    N = S.size();

    for (int i=0; i<N-2; ++i){
        int tmp = std::stoi(S.substr(i, 3));
        ans = std::min(ans, abs(tmp - 753));
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

bool isPrime[1000000];
int main()
{
	fill(isPrime, isPrime+1000000, true);
	for (int i = 2; i < 1000; ++i)
	{
		if (isPrime[i])
		{
			for (int j = 2*i; j < 1000000; j += i)
				isPrime[j] = false;
		}
	}

	int n;
	while (scanf("%d", &n), n)
	{
		int ans = 0;
		for (int i = 3; i <= n/2; i += 2)
			if (isPrime[i] && isPrime[n-i])
				++ans;
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//
		Scanner sc = new Scanner(System.in);
		// 最初の座標
		double firstX = 0;
		double firstY = 0;

		// 二つ目の座標
		double secondX = 0;
		double secondY = 0;

		while (sc.hasNext()) {
			// 最初の座標
			firstX = sc.nextDouble();
			firstY = sc.nextDouble();

			// 二つ目の座標
			secondX = sc.nextDouble();
			secondY = sc.nextDouble();

			break;
		}
		// 二つの座標の距離
		double answer;
		answer = Math.sqrt(((secondX - firstX) * (secondX - firstX))
				+ ((secondY - firstY) * (secondY - firstY)));

		System.out.println(answer);
	}
}

Measured memory_bytes: 18380
#include <stdio.h>
#define WARU 1000000007

/* aの逆数の計算 */

long gyaku(long a){
   long b=WARU,u=1,v=0,t,tmp;
   while (b) {
      t=a/b;
      tmp=a-t*b;
      a=b;b=tmp;
      tmp=u-t*v;
      u=v;v=tmp;
   }
   u%=WARU; 
   if (u<0) u+=WARU;
   return u;
}

/* a^nの計算 */

long modpow(long int a, long int n) {
   long int res=1;
  
   while (n>0) {
        if (n%2==1) res=(res*a)%WARU;
        a=(a*a)%WARU;
        n/=2;
    }
    return res;
}

int main(){
   long int n,a,b,ans,all,nn,bi,i,na,nb,wa,wb;
 
   scanf("%ld %ld %ld",&n,&a,&b);
   all=modpow(2,n)-1;
   na=nb=wa=wb=1;
   for (i=0;i<a;) {
      na=(na*(n-i))%WARU;
      i++;
      wa=(wa*i)%WARU;
   }
   for (i=0;i<b;) {
      nb=(nb*(n-i))%WARU;
      i++;
      wb=(wb*i)%WARU;
   }
  na=(na*gyaku(wa))%WARU;
   nb=(nb*gyaku(wb))%WARU;
/*    na=(na*modpow(wa,WARU-2))%WARU;
   nb=(nb*modpow(wb,WARU-2))%WARU;*/
   printf("%ld\n",(all+(WARU-na)+(WARU-nb))%WARU);
   return 0;
}


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

int main(){
	int N,Q;
	ll K;
	cin >> N >> K >> Q;
	vector<int> A(N,K-Q);
	int a;
	for(int i(0);i<Q;++i){
		cin >> a;
		A[a-1]++;
	}
	for(int i(0);i<N;++i){
		if(A[i]<=0){
			cout << "No" << endl;
		}else{
			cout << "Yes" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int a;
    int b;
    int c;


    while(cin >> a >> b)
    {
        c = a+b;
        int digit=0;
        while (c>=1)
        {
            c = c/10;
            digit++;
        }

        cout << digit << endl;
    }



    return 0;
}

Measured memory_bytes: 2972
#include <iostream>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;

  if((a==5&&b==7&&c==5)||(a==7&&b==5&&c==5)||(a==5&&b==5&&c==7)){
    cout << "YES" << endl;
  }else{
    cout << "NO"  << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i,a,b,c,d,n,w[1000],ans=0x3f3f3f;
int main()
{
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>w[i];
	}
	for(i=0;i<n;i++)
	{
		for(a=0;a<i;a++)
		{
			c+=w[a];
		}
		for(b=i;b<n;b++)
		{
			d+=w[b];
		}
		if(abs(c-d)<=ans)
		{
			ans=abs(c-d);
		}
		c=0;
		d=0;
	}
	cout<<ans;
	return 0;
}


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

using namespace std;
//#pragma GCC optimize("O3")

typedef long long ll;
typedef long double ld;
const int mod = (int)1e9 + 7;
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int n;
const int maxN = 2e5 + 10;
int x[maxN], v[maxN];
int pref_max[maxN];
int suf_min[maxN];
//YA DEBIL
int fenw[maxN];
void updF(int v, int by) {
    v += 1;
    while (v < maxN) {
        fenw[v] = sum(fenw[v], by);
        v = (v | (v - 1)) + 1;
    }
}
int get(int r) {
    r += 1;
    int ans = 0;
    while (r > 0) {
        ans = sum(ans, fenw[r]);
        r &= (r - 1);
    }
    return ans;
}
int get(int l, int r) {
    int p = get(r);
    p -= get(l - 1);
    if (p < 0) p += mod;
    return p;
}
int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    vector < int > all;
    vector < pair < int, int > > by;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> v[i];
        all.emplace_back(v[i]);
        by.emplace_back(x[i], v[i]);
    }
    sort(by.begin(), by.end());
    sort(all.begin(), all.end());
    for (int i = 0; i < n; i++) {
        v[i + 1] = by[i].second;
        v[i + 1] = lower_bound(all.begin(), all.end(), v[i + 1]) - all.begin() + 1;
    }
  
    for (int i = 1; i <= n; i++) {
        pref_max[i] = max(pref_max[i - 1], v[i]);
    }
    suf_min[n + 1] = 1e9;
    for (int i = n; i >= 1; i--) {
        suf_min[i] = min(suf_min[i + 1], v[i]);
    }
  
  

    updF(0, 1);
    for (int i = 1; i <= n; i++) {
        int p = get(suf_min[i] - 1, pref_max[i]);
      
        updF(pref_max[i], p);
      
    }
  
    cout << get(n, n) << '\n';
  
    return 0;
}


Measured memory_bytes: 9696
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>

#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  char a, b;
  while (cin >> a >> b) {
    if (a == 'D') {
      if (b == 'D') cout << 'H';
       else cout << 'D';
    } else cout << b;
    cout << endl;
  }
  return 0;
}


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

int main()
{
	int n;
	cin >> n;
	auto d = vector<int>({ 1 });
	int t = 6;
	while(t <= n){
		d.push_back(t);
		t *= 6;
	}
	t = 9;
	while(t <= n){
		d.push_back(t);
		t *= 9;
	}
	sort(d.begin(), d.end());
	auto dp = vector<vector<int>>(d.size() + 1, vector<int>(n + 1, n + 1));
	dp[0][0] = 0;
	for(auto i = 1; i <= (int)d.size(); ++i){
		int s = d[i - 1];
		for(auto j = 0; j <= n; ++j){
			dp[i][j] = min(dp[i][j], dp[i - 1][j]);
			if(j + s <= n){
				dp[i][j + s] = min({dp[i][j + s], dp[i - 1][j] + 1, dp[i][j] + 1});
			}
		}
	}
	cout << dp[d.size()][n] << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, x=0;
  cin >> N;
  
  for (int i = 0; i < N; i++){
	string S;
    cin >> S;
    if(S=="Y")x=1;
      
  }
  
  if(x==1) cout << "Four" << endl;  
  else    cout << "Three" << endl;
  
 }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int pos, key;
int queue[2000000];
char command[8];

inline void insert_key(int val) {
    int i = pos++;
    while (i > 0) {
        int p = (i - 1) / 2;
        if (queue[p] >= val) { break; }
        queue[i] = queue[p];
        i = p;
    }
    queue[i] = val;
}

inline int extract_key() {
    int result = queue[0], val = queue[--pos], i = 0;
    for (int left, right; i * 2 + 1 < pos; ) {
        left = i * 2 + 1, right = i * 2 + 2;
        if (right < pos && queue[right] > queue[left]) {
            left = right;
        }
        if (queue[left] <= val) {
            break;
        }
        queue[i] = queue[left];
        i = left;
    }
    queue[i] = val;
    return result;
}

int main(void) {
    while (true) {
        scanf("%s", command);
        if (command[0] == 'i') {
            scanf("%d", &key);
            insert_key(key);
        }
        else if (command[1] == 'x') {
            printf("%d\n", extract_key());
        }
        else {
            break;
        }
    }
    return 0;
}

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

def main():
  s = input().strip()
  coffee = 'coffee'
  if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
  else:
    print('No')
    
if __name__=='__main__':
  main()



Measured memory_bytes: 2940
import java.util.*;

// ABC 27-C
// http://abc027.contest.atcoder.jp/tasks/abc027_c
 
public class Main {
	
	public static void main (String[] args) throws java.lang.Exception {
		Scanner in = new Scanner(System.in);
		
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		
		System.out.println(a <= c && c <= b ? "Yes" : "No");
	}
}

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

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> A(H);
  for(int i = 0; i < H; ++i) cin >> A[i];
  vector<vector<int>> B(H,vector<int>(W,-1));
  int c = 1;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(A[i][j] != '#') continue;
      B[i][j] = c;
      ++c;
    }
  }
  for(int i = 1; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(B[i-1][j] < 0) continue;
      if(B[i][j] > 0) continue;
      B[i][j] = B[i-1][j];
    }
  }
  for(int i = H-2; i >= 0; --i){
    for(int j = 0; j < W; ++j){
      if(B[i+1][j] < 0) continue;
      if(B[i][j] > 0) continue;
      B[i][j] = B[i+1][j];
    }
  }
  for(int i = 0; i < H; ++i){
    for(int j = 1; j < W; ++j){
      if(B[i][j-1] < 0) continue;
      if(B[i][j] > 0) continue;
      B[i][j] = B[i][j-1];
    }
  }
  for(int i = 0; i < H; ++i){
    for(int j = W-2; j >= 0; --j){
      if(B[i][j+1] < 0) continue;
      if(B[i][j] > 0) continue;
      B[i][j] = B[i][j+1];
    }
  }
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      cout << B[i][j] << ((j+1 < W) ? " " : "\n");
    }
  }
}


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

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
const ll MAX = 200001;

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

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

// 二項係数計算
ll COM(ll n,ll k){
    if (n == 1) return 1;
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
    COMinit();
    ll n,k;cin >> n >> k;
    if(k>=n)k=n-1;
    ll ans=0;
    REP(i,k+1){
        ans+=(COM(n,i)*COM(n-1,n-i-1));
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int h,w;
    cin>>h>>w;
    for(int i=0;i<w+2;i++){
        cout<<'#';
    }
    cout<<endl;
    for(int i=0;i<h;i++){
        cout<<'#';
        string s;
        cin>>s;
        cout<<s;
        cout<<'#';
        cout<<endl;
    }
    for(int i=0;i<w+2;i++){
        cout<<'#';
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int n, m;
llong solve(int a, vector<vector<int>> &v, vector<int> &p, bool used[]){
  if(a == n){
    REP(i,m){
      int on = 0;
      REPI(itr, v[i]){
        if(used[*itr]) on++;
      }
      if(on % 2 != p[i]) return 0;
    }
    return 1;
  }

  llong res = 0;
  res += solve(a+1, v, p, used);
  used[a] = true;
  res += solve(a+1, v, p, used);
  used[a] = false;
  return res;
}

int main(){

  cin >> n >> m;

  vector<vector<int>> v(m);
  REP(i,m){
    int k;
    cin >> k;
    REP(j,k){
      int tmp;
      cin >> tmp;
      tmp--;
      v[i].pb(tmp);
    }
  }

  vector<int> p(m);
  REP(i,m){
      cin >> p[i];
  }

  bool used[10] = {};

  cout << solve(0, v, p, used) << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <queue>
#include <map>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long ll;
#define MOD int(1e9+7)
#define REP(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define fi first
#define se second

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

	string s; cin >> s;

	int ans = 0;
	int l = 0,r=s.size()-1;
	while (l < r) {
		if (s[l] == s[r]) {
			l++; r--;
		}
		else if (s[l] == 'x' || s[r] == 'x') {
			if (s[l] == 'x') {
				l++;
				ans++;
			}
			else {
				r--;
				ans++;
			}
		}
		else{
			ans = -1;
			break;
		}
	}

	cout << ans << endl;

    return 0;
}



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

int isodd(int x){
	if(x % 2 == 1){
		return 1;
	}
	return 0;
}

int main(){
	int x, p;
	scanf(" %d %d", &x, &p);
	double y=0, d = (double)x;
	if(isodd(x)){
		d+= 1.0-0.02*p;
		y+=1.0;
	}
	y += d/(0.02*p);
	printf("%lf",y);
}


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

int main()
{
    int N;
    int Q[200006] = {};
    cin >> N;
    for ( int i = 0; i < N; i++ ) {
        int P;
        cin >> P;
        Q[P] = Q[P - 1] + 1;
    }
    cout << N - *max_element(Q + 1, Q + N + 1) << endl;
    return ( 0 );
}


Measured memory_bytes: 1024
from collections import Counter
#https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

def main():
    N,M,K = list(map(int,input().split()))
    counter = Counter()
    uf = UnionFind(N+1)
    for i in range(M):
        a,b = list(map(int,input().split()))
        counter.update((a,b))
        uf.union(a,b)
    
    ans = [0]*(N+1)

    for i in range(1,N+1):
        ans[i] = uf.size(i)-counter[i]-1
    for i in range(K):
        a,b = list(map(int,input().split()))
        if uf.same(a,b):
            ans[a] -= 1
            ans[b] -= 1
    
    for i in range(1,N):
        print(ans[i] if 0<=ans[i] else 0,end=" ")
    print(ans[N] if 0<=ans[i] else 0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 94808
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  int a[20],b[20],c[19],i,ans=0;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    scanf("%d",&b[i]);
  }
  for(i=0;i<n-1;i++){
    scanf("%d",&c[i]);
  }
 int old = a[0];
	for (int i = 0; i < n; ++i) {
		ans += b[a[i]-1];
		if (a[i] - old == 1) {
			ans += c[old - 1];
		}
		old = a[i];
 
	}
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) = println(run {
    val n = readLine()!!.toInt()
    val x = (1..n).map { readLine()!!.split(" ") }

    x.map { if(it[1]=="JPY") it[0].toDouble() else 380000.0 * it[0].toDouble() }.sum()
})


Measured memory_bytes: 35820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,l;
    cin>>n>>l;
    ll mina=500,ans=0,minai;
    rep(0,i,n){
        ll x=l+i;
        if(mina>abs(x)){
            minai=x;
            mina=abs(x);
        }
        ans+=x;
    }
    cout<<ans-minai;
    
    
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

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

int main() {
  int H, W; cin >> H >> W;
  vector<string> S(H); REP(i, H) cin >> S[i];
  ll INF = pow(10, 9);
  vector<vector<int>> dp(500, vector<int>(500, INF));
  for(int i = 0; i < 500; ++i) {
    dp[i][i] = 0;
  }
  auto id = [&](int x, int y) {return x * W + y;};

  // 全マスを4方向に進めるかどうか判定する
  for(int i = 0; i < H; ++i) {
    for(int k = 0; k < W; ++k) {
      if(S[i][k] == '#') continue;
      for(int m = 0; m < 4; ++m) {
        if(i + dx[m] < 0 || i + dx[m] >= H || k + dy[m] < 0 || k + dy[m] >= W) {
          continue;
        }
        if(S[i + dx[m]][k + dy[m]] == '#') {
          continue;
        }
        dp[id(i, k)][id(i + dx[m], k + dy[m])] = 1;
        dp[id(i + dx[m], k + dy[m])][id(i, k)] = 1;
      }
    }
  }

  for (int k = 0; k < 500; k++){       // 経由する頂点
    for (int i = 0; i < 500; i++) {    // 始点
      for (int j = 0; j < 500; j++) {  // 終点
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }

  int ans = 0;
  REP(i, 500) {
    REP(k, 500) {
      if(dp[i][k] != 1000000000 && ans < dp[i][k]) ans = dp[i][k];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
class SegmentTree(object):
    def __init__(self,A,dot,e):
        n=2**((len(A)-1).bit_length())
        self.__n=n
        self.__dot=dot
        self.__e=e
        self.__node=[e]*(2*n)
        for i in range(len(A)):
            self.__node[i+n]=A[i]
        for i in range(n-1,-0,-1):
            self.__node[i]=dot(self.__node[2*i],self.__node[2*i+1])

    def add(self,i,c):
        i+=self.__n
        node=self.__node
        node[i]=self.__dot(c,node[i])
        while(i!=1):
            i//=2
            node[i]=self.__dot(node[2*i],node[2*i+1])

    def sum(self,l,r):
        vl,vr=self.__e,self.__e
        l+=self.__n; r+=self.__n
        while(l<r):
            if(l%2==1):
                vl=self.__dot(vl,self.__node[l])
                l+=1
            l//=2
            if(r%2==1):
                r-=1
                vr=self.__dot(self.__node[r],vr)
            r//=2
        return self.__dot(vl,vr)

def resolve():
    n,m=map(int,input().split())
    LRC=[0]*m
    for i in range(m):
        l,r,c=map(int,input().split())
        l-=1
        LRC[i]=(l,r,c)
    LRC.sort()

    A=[INF]*n
    A[0]=0
    tree=SegmentTree(A,min,INF)
    for l,r,c in LRC:
        s=tree.sum(l,r)
        tree.add(r-1,s+c)

    ans=tree.sum(n-1,n)
    if(ans==INF): ans=-1
    print(ans)
resolve()

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

int main()
{
  char strs[101];
  char strp[101];
  cin >> strs;
  cin >> strp;
  int lens = strlen(strs);
  int lenp = strlen(strp);
  int i,j,k;
  char temp[lenp];
  int result;
  for(i = 0;i < lens;++i){
    if(i <= lens - lenp){
      result = strncmp(strs+i,strp,lenp);
      if(result == 0){
        cout << "Yes" << endl;
        return 0;
      }else{
        continue;
      }
    }else{
      k = 0;
      for(j = i;j < lens;++j){
        temp[k] = strs[j];
        ++k;
      }
      for(j = 0;j < lenp+i-lens;++j){
        temp[k] = strs[j];
        ++k;
      }
      result = strncmp(temp,strp,lenp);
      if(result == 0){
        cout << "Yes" << endl;
        return 0;
      }else{
        continue;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,l; cin>>n>>l;
	int all=(1+n)*n/2+(l-1)*n;
	int dif=1e9,ans=all;
	for(int i=1;i<=n;++i){
		int j=l+i-1;
		if(abs(j)<dif)ans=all-j,dif=abs(j);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,d=0;
  scanf("%d %d %d",&a,&b,&c);
  a=a%b;
  for(int i=0; i<b; i++){
    if((a*i)%b==c){
      d=1;
      break;
    }
  }
  printf(d?"YES":"NO");
  return 0;}

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

int main(void)
{
    IOS
    ll l, r;
    cin >> l >> r;
    int ans = 0;
    if (r-l < 2019) {
        ans = 2018;
        FOR(i,l,r) FOR(j,i+1,r+1) ans = min(ans,(i % 2019) * (j % 2019) % 2019);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    VV gragh(n,V(n,INF));
    VV reg(m, V(3));
    rep(i,n){
        gragh[i][i] = 0;
    }
    rep(i,m){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        gragh[a][b] = c;
        gragh[b][a] = c;
        reg[i][0] = a;
        reg[i][1] = b;
        reg[i][2] = c;
    }
    

    rep(k,n){
        rep(i,n){
            rep(j,n){
                chmin(gragh[i][j],gragh[i][k]+gragh[k][j]);
            }
        }
    }
    
    ll cnt = 0;
    rep(i,m){
        if(gragh[reg[i][0]][reg[i][1]]<reg[i][2]){
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>

#define int ll

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define per(i,b) for(ll i=b-1;i>=0;i--)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

struct Node {
    int par;
    vi cs;
    Node(int p, vi const& cs) : par(p), cs(cs) {}
    Node(){}
};

vi ansester;
vi marked;

void update(vector<Node> & g, int v, int a){
    ansester[v] = a;
    for(int c : g[v].cs){
        if(!marked[c]) update(g,c,a);
    }
}

int solve(vector<Node> g, vector<pair<char,int>> query){
    ansester.assign(g.size()+1, 1);
    marked.assign(g.size()+1, 0);
    int ans = 0;
    rep(i,query.size()){
        char q; int v;
        tie(q,v) = query[i];
        if(q=='M'){
            update(g,v,v);
            marked[v] = true;
        } else {
            ans += ansester[v];
        }
    }
    return ans;
}

signed main(){
    int N, Q;
    while(cin>>N>>Q && N){
        vector<Node> g(N+1);
        rep(i,N-1){
            int x; cin>>x;
            g[i+2].par = x;
            g[x].cs.eb(i+2);
        }
        vi ignore(N+1);
        vector<pair<char,int>> query;
        rep(i,Q){
            char c; int v;
            cin>>c>>v;
            if(c=='M'){
                if(!ignore[v]){
                    query.eb(c,v);
                    ignore[v] = true;
                }
            } else {
                query.eb(c,v);
            }
        }
        cout << solve(g,query) << endl;
    }
}

Measured memory_bytes: 22424
#include<stdio.h>
int main(void){
    int loop,a,b,c=0,d=0;
while(1){ scanf("%d",&loop);
    if(loop==0)break;
    
    	a=0,b=0,c=0,d=0;
    for(;loop--;){
        scanf("%d %d",&a,&b);
        if(a!=b){
            if(a>b){
                c+=a+b;
            }else{
                d+=a+b;
            }
        }else{
            c+=a;
            d+=b;
        }
    }
    printf("%d %d\n",c,d);
}
    return 0;
}

Measured memory_bytes: 1028
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 2248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> ii;

const int MAXN = 5e5+3; //AREGLAAAAAAAAR!!!!


int main(){
	string s;
	cin>>s;
	if(s.size()>=4){
		if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I') printf("Yes\n");
		else printf("No\n");
	}else{
		printf("No\n");
	}
	return 0;

}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

x = na()
print(x.index(0) + 1)

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

int main(){
	int N, M;
	cin >> N;
	vector<string> blue(N);
	for(int i = 0; i < N; i++)
		cin >> blue.at(i);
	cin >> M;
	vector<string> red(M);
	for(int i = 0; i < M; i++)
		cin >> red.at(i);

	int maxYen = 0;
	for(int i = 0; i < N; i++){
		int yen = 0;
		for(int j = 0; j < N; j++)
			if(blue.at(i) == blue.at(j))
				yen++;
		for(int j = 0; j < M; j++)
			if(blue.at(i) == red.at(j))
				yen--;
		if(maxYen < yen)
			maxYen = yen;
	}
	cout << maxYen << endl;

	return 0;
}

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

int main(){
  char w[10], t[1000], c = 0, i;
  scanf("%s", w);
  while(scanf("%s", t) && strcmp(t, "END_OF_TEXT") != 0){
    for(i = 0;i < strlen(t);i++) t[i] = 'A' <= t[i] && 'Z' >= t[i] ? t[i] - 'A' + 'a' : t[i];
    if(strcmp(t, w) == 0) c++;
  }
  printf("%d\n", c);
  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <stack>
#include <functional>
#include <utility>
template<typename T>
class SWAG {
    using P = pair<T, T>;  // raw_data, fold_all
    using Func = function<T(T, T)>;
    stack<P> front_stack, back_stack;
    Func func;

public:
    SWAG(Func _func)
        : func(_func) {}
    void push(T ele) {
        if (back_stack.empty()) {
            back_stack.emplace(ele, ele);
        } else {
            T lst = back_stack.top().second;
            back_stack.emplace(ele, func(lst, ele));
        }
    }
    void pop() {
        if (front_stack.empty()) {
            T fold = back_stack.top().first;
            front_stack.emplace(fold, fold);
            back_stack.pop();
            while (back_stack.size()) {
                T ele = back_stack.top().first;
                front_stack.emplace(ele, fold = func(ele, fold));
                back_stack.pop();
            }
        }
        front_stack.pop();
    }
    T fold_all() {
        if (front_stack.empty()) {
            return back_stack.top().second;
        } else if (back_stack.empty()) {
            return front_stack.top().second;
        } else {
            return func(front_stack.top().second, back_stack.top().second);
        }
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, L;
    cin >> n >> L;
    auto MIN = [](ll a, ll b) {
        return min(a, b);
    };
    SWAG<ll> swag(MIN);
    REP(i, 0, n) {
        ll a;
        cin >> a;
        swag.push(a);
        if (i >= L) {
            swag.pop();
        }
        if (i + 1 >= L) {
            cout << swag.fold_all() << " \n"[i + 1 == n];
        }
    }
    return 0;
}



Measured memory_bytes: 4712
# 044a

N = int(input())    # 宿泊数Nを代入
K = int(input())    # 最初のK泊を代入
X = int(input())    # K泊までの一泊あたりの料金Xを代入
Y = int(input())    # K+1泊目以降の一泊あたりの料金Yを代入

if N <= K:
    hotel_fee = N * X
else:
    hotel_fee = K * X + (N - K) * Y

print(hotel_fee)



Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

vector<vector<P>> T;
int visit[100010] = {};
int res[100010];

int dfs(int n,int ng){
  visit[n] = 1;
  int col = 1;
  int ncol = 0;
  for(P edge : T[n]){
    if(visit[edge.first])continue;
    if(col == ng)col++;
    res[edge.second] = col;
    ncol = max(ncol, dfs(edge.first, col));
    col++;
  }
  return max(ncol, col-1);
}

int main(void){
  int n;
  cin >> n;
  T = vector<vector<P>>(n);
  for(int i = 0;i < n-1;++i){
    int a,b;
    scanf("%d %d", &a, &b);
    --a;--b;
    T[a].push_back(P(b,i));
    T[b].push_back(P(a,i));
  }
  int ncol = dfs(0,0);
  printf("%d\n", ncol);
  for(int i = 0;i < n-1;++i){
    printf("%d\n", res[i]);
  }
  return 0;
}


Measured memory_bytes: 7680
import java.util.*;

class Main {
	public static void main(String[] arg){
		Scanner in = new Scanner(System.in);
		int[][][] apart = new int[4][3][10];
		int n = in.nextInt();
		for(int i=0;i<n;i++){
			int b = Integer.parseInt(in.next());
			int f = Integer.parseInt(in.next());
			int r = Integer.parseInt(in.next());
			int v = Integer.parseInt(in.next());
			apart[b-1][f-1][r-1] = 	apart[b-1][f-1][r-1] + v;
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<10;k++){
					if(k == 9) System.out.println(" "+apart[i][j][k]);
				    else  System.out.print(" "+apart[i][j][k]);
				} 
				if(j==2 && i!=3) System.out.println("####################");
			}
		}
	}	
}

Measured memory_bytes: 20584
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int a=sc.nextInt();
    
    if(n<a){
      System.out.println("0");
    }
    else{
      System.out.println("10");

    }
    
    
  }
}


Measured memory_bytes: 22868
class Counter(dict):
  def __missing__(self, i):
    return 0

n = int(input())

s = Counter()

for _ in range(n):
  i = input()
  s[i] += 1

s = dict(sorted(s.items(), key=lambda x: -x[1]))
m = max(list(s.values()))

ans = []
for i in s:
  if s[i] == m:
    ans.append(i)

ans.sort()

print('\n'.join(ans))



Measured memory_bytes: 66140
#include <iostream>
#include <bits/stdc++.h>
#include <climits>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define INF 1LL << 60;


int main() {
  
  vector<int> n(4);
  cin >> n[0] >> n[1] >> n[2] >> n[3];
  
  bool flag = true;
  
  sort(n.begin(), n.end());
  
  if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9){
    flag = true;
  }
  else{
    flag = false;
  }
  
  if(flag == true){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
}

Measured memory_bytes: 256