akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, K, Q; cin >> N >> K >> Q;
    vector<int> B(N, K-Q);
    for (int i = 0; i < Q; i++) {
        int A; cin >> A; A--;
        B[A] += 1;
    }
    for (int b : B) {
        cout << (b > 0 ? "Yes" : "No") << '\n';
    }
    return 0;
}

Measured memory_bytes: 1024
using namespace std;
#include<iostream>
#include<bits/stdc++.h>
#define w(x) int x;cin>>x;while(x--)
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MAX 1000000
#define ll long long

void abc()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void sieve(vector<int>& prime) {
	for (int i = 2; i * i <= MAX; i++) {
		if (prime[i] == 1) {
			for (int j = i * i; j < MAX; j += i) {
				prime[j] = 0;
			}
		}
	}
}



int main()
{
	abc();

	ll n;
	cin >> n;
	ll m = n;

	ll res = 0;

	for (ll i = 2; i * i <= m; i++) {
		ll cost = 0;

		while (n % i == 0 and n > 1) {
			cost++;
			n = n / i;
		}

		int temp = 0, j = 1;
		while (cost - j >= 0) {
			cost = cost - j;
			temp++;
			j++;
		}
		res += temp;
	}

	if (n > 1) res++;
	cout << res;




}

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

int main() {
  string s;
  cin >> s;
  int sum = 0;
  for (int i = 0; i <s.size(); i++) {
    if (s.at(i) == 'R')
      sum++;
  }
  if (sum == 2 && s.at(1) == 'S') 
    sum--;
  cout << sum << endl;
}
    

Measured memory_bytes: 3576
#include <stdio.h>
int n;
int A[20];

int saiki(int num,int index) {
  if(num==0){
    return 1;
  }
  if(index==n || num<0){
    return 0;
  }
  if(saiki(num-A[index],index+1) || saiki(num,index+1)){
    return 1;
  }
  return 0;
}
int main(void) {
  scanf("%d",&n);
  int i;
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  int q;
  scanf("%d",&q);
  int num;
  for(i=0; i<q; i++){
    scanf("%d",&num);
    if(saiki(num,0)) {
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2100
#include <stdio.h>
 
int main()
{
    int N, a[100001], i, b[100001];
    scanf("%d", &N);
    for (i = 1; i <= N; i++)
    {
        scanf("%d", &a[i]);
    }
    for (i = 1; i <= N; i++)
    {
        b[a[i]] = i;
    }
    for (i = 1; i <= N; i++)
    {
        printf("%d", b[i]);
        if (i != N)
        {
            printf(" ");
        }
    }
    return 0;
}

Measured memory_bytes: 1536
// E - Knapsack 2
#include <bits/stdc++.h>
using namespace std;

#define VMAX 100000
#define WMAX 1000000000
vector<int> dp(VMAX+1, WMAX+1);

int main(){
	int N,W; cin>>N>>W;
	dp[0] = 0;
	for(int i=1; i<=N; i++){
		int w,v; cin>>w>>v;
		for(int j=VMAX; j>=v; j--) dp[j] = min(dp[j], dp[j-v] + w);
	}

	int a = 0;
	for(a=VMAX; a>=1; a--) if(dp[a]<=W) break;
	cout<< a <<endl;
}

Measured memory_bytes: 640
n=int(input())

a = list(map(int,input().split()))

b = list(map(int,input().split()))

res = 0

for i in range(n):
    if a[i] < b[i] and a[i+1] <= b[i]-a[i]:
        res += (a[i]+a[i+1])
        a[i] = 0
        a[i+1] = 0
    elif a[i] < b[i]:
        res += b[i]
        a[i+1] = a[i+1]+a[i]-b[i]
        a[i] = 0
    else:
        res += b[i]
        a[i] = a[i]-b[i]
    #print(a)

print(res)

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

struct UnionFind{
    
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int N): par(N+1), rank(N+1)  {
        for(int i = 0; i < N;i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int find(int x){
        if(par[x]==x)return x;
        else return par[x] = find(par[x]);
    }
    
    void unite(int x,int y){
        x = find(x);
        y = find(y);
        if(x == y)return;
        
        if(rank[x]<rank[y]){
            par[x] = y;

        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }

    }
    
    bool same(int x,int y){
        return find(x) == find(y);
    }
    
};

int main(void){
    
    int N,M;
    cin >> N >> M;
    
    int p;
    map<int,int> mp;
    
    for(int i = 0; i < N;i++){
        cin >> p;
        p--;
        mp[i] = p;
    }
    
    UnionFind tree(N);
    int x,y;
    for(int i = 0; i < M;i++){
        cin >> x >> y;
        x--,y--;
        tree.unite(x,y);
    }
    
    int cont = 0;
    for(int i = 0; i < N;i++){
        if(tree.find(i)==tree.find(mp[i]))cont++;
    }
    cout << cont <<endl;
}


Measured memory_bytes: 5760
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
    public static void Main(string[] args)
    {
        var input_N_W = Console.ReadLine().Split(' ');

        // 品物の個数
        var N = int.Parse(input_N_W[0]);

        // ナップサックの重量限界
        var W = int.Parse(input_N_W[1]);

        var weight = new int[N];
        var value = new int[N];

        for (var i = 0; i < N; i++)
        {
            var input = Console.ReadLine().Split(' ');

            weight[i] = int.Parse(input[0]);
            value[i] = int.Parse(input[1]);
        }

        var dp = new long[N + 1, W + 1];

        // DPループ
        for (int i = 0; i < N; i++)
        {
            for (int sum_w = 0; sum_w <= W; sum_w++)
            {
                // i 番目の品物を選ぶ場合
                if (sum_w >= weight[i])
                {
                   dp[i + 1, sum_w] = Math.Max(dp[i + 1, sum_w], dp[i, sum_w - weight[i]] + value[i]);
                }

                // i 番目の品物を選ばない場合
                 dp[i + 1, sum_w] = Math.Max(dp[i + 1, sum_w], dp[i, sum_w]);
            }
        }

        Console.WriteLine(dp[N, W]);
    }
}


Measured memory_bytes: 88800
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = li()

if N == 0:
    if A==[1]:
        print(1)
    else:
        print(-1)
    exit()

max_a = [0] * (N+1)
max_a[0] = 1 - A[0]

for i in range(1, N+1):
    max_a[i] = max_a[i-1] * 2 - A[i]
    if max_a[i] < 0:
        print(-1)
        exit()

cnt_list = [0]*(N)
cnt_list[-1] = min(A[-1], max_a[N-1])

for i in reversed(range(N-1)):
    if cnt_list[i+1] + A[i+1] <= max_a[i]:
        cnt_list[i] = cnt_list[i+1] + A[i+1]
    else:
        cnt_list[i] = max_a[i]

cnt = sum(cnt_list[:N+1]) + sum(A)

print(cnt)

Measured memory_bytes: 674984
#include<stdio.h>
#define N 1000000
#define M 50000
int main(){
  int i,j,k,n,q,a[N],b[M],count=0,l,m,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
    scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&b[j]);
  }
  for(j=0;j<q;j++){
    l=0;
    r=n;
    while(l<r){
      m=(l+r)/2;
      if(b[j]==a[m]){
	count++;
	break;
      }
      if(b[j]>a[m]){
	l=m+1;
      }
      if(b[j]<a[m]){
	r=m;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}



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

#define ll long long
using namespace std;

// take adjacency matrix to the kth power by repeatedly squaring it

const int N = 51, K = 61, M = 1e9 + 7;
int n;
ll k, dp[N][N][K], mat[N][N], tmp[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        mat[i][i] = 1;
        for(int j = 0; j < n; j++) {
            cin >> dp[i][j][0];
        }
    }
    for(int l = 1; l < K; l++) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                for(int k = 0; k < n; k++) {
                    dp[i][j][l] = (dp[i][j][l] + dp[i][k][l - 1] * dp[k][j][l - 1]) % M;
                }
            }
        }
    }
    for(int l = 0; l < K; l++) {
        if((k >> l) & 1) {
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < n; j++) {
                    tmp[i][j] = 0;
                    for(int k = 0; k < n; k++) {
                        tmp[i][j] = (tmp[i][j] + mat[i][k] * dp[k][j][l]) % M;
                    }
                }
            }
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < n; j++) {
                    mat[i][j] = tmp[i][j];
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            ans = (ans + mat[i][j]) % M;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }

const long long INF = 1LL << 60;


int main () {
    int M1, D1, M2, D2;

    cin >> M1 >> D1 >> M2 >> D2;

    if(M2-M1 ==1 || M1==12 && M2 ==1)cout << "1" << endl;
    else cout <<"0" << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<vector>
#include<unordered_map>

using namespace std;
using ll = long long;


ll n, q;
ll a[2 * 100005], b[2 * 100005];
ll p[100005 * 2], x[100005 * 2];
vector<ll>V[100005 * 2];
unordered_map<ll, ll>M;
ll counter[1000005 * 2];

void input(){
  cin >> n >> q;
  for(int i = 1; i <= n; ++i){
    M[i] = 0;
  }
  for(int i = 1; i < n; ++i){
    cin >> a[i] >> b[i];
    V[a[i]].push_back(b[i]);
    V[b[i]].push_back(a[i]);
  }
  for(int i = 1; i <= q; ++i){
    cin >> p[i] >> x[i];
    counter[p[i]] += x[i]; 
    
  }
  //for(int i = 1; i <= n; ++i){
    //cout << counter[i] << endl;
  //}
}

void solve(){
  stack<ll>S;
  bool visited[100005 * 2];
  for(int i = 1; i <= n; ++i){
    visited[i] = false;
  }
  visited[1] = true;
  //M[1] += counter[1];
  S.push(1);
  while(!S.empty()){
    ll tmp = S.top();
    S.pop();
    //cout << tmp << endl;
    for(int j = 0; j < V[tmp].size(); ++j){
      if(!visited[V[tmp][j]]){
        //cout << V[tmp][j] << endl;
        visited[V[tmp][j]] = true;
        // M[V[tmp][j]] += counter[tmp];
        counter[V[tmp][j]] += counter[tmp];
        S.push(V[tmp][j]);
      }
    }
  }
  for(int i = 1; i <= n; ++i){
    //cout << M[i] << " ";
    cout << counter[i] << " ";
  }
}

int main(){
  input();
  solve();
}


Measured memory_bytes: 33860
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#pragma warning( disable:4996 )
using namespace std;

#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))


int main(void) {
	/*int n;
	scanf("%d", &n);
	printf("%f\n", (double)(n / 2 + n % 2) / n);*/
	int n, k, h[100000];
	int count = 0;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
		if (h[i] >= k) {
			count++;
		}
	}

	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

#define LIMIT 7400000
int prime[LIMIT+10];
void makep(ll n){prime[0]=prime[1]=1;for(int i=2;i*i<=n;i++)if(!prime[i])for(int j=i*i;j<=n;j+=i)prime[j]=1;}
int*p;
int pcnt;

int main(){
	makep(LIMIT);
	rep(i,2,LIMIT)if(!prime[i])prime[pcnt++]=i;
	
	ll m,n;
	while(scanf("%lld%lld",&m,&n),m){
		p=calloc(m*m+10,sizeof(int));
		int flag=1;
		rep(i,m,m*m+1)if(!p[i]){
			if(!n--){
				printf("%lld\n",i);
				flag=0;
				break;
			}else{
				for(int j=i+i;j<=m*m;j+=i)p[j]=1;
			}
		}
		free(p);
		if(flag){
			rep(i,0,pcnt){
				if(prime[i]>m*m)if(!n--){
					printf("%lld\n",prime[i]);
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 30668
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	int n;
	char c[105];
	cin >> n;
	scanf("%s",c);
	if(n%2==1){
		cout << "No" << endl;
		
	}
	else{
		int f=0;
		for(int i=0;i<(n/2);i++){
			if(c[i]!=c[i+(n/2)]){
				f=1;
			}
		}
		if(f==0){
			cout << "Yes" << endl;
		}
		else
			cout << "No" << endl;	
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N;
	scanf("%d",&N);
	while(N > 3){
		if(N % 4 == 0 || N % 7 == 0){
			printf("Yes\n");
			return 0;
		}
		else if(N >= 7)	N -= 7;
		else if(N >= 4)	N -= 4;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int w, d;
int cnt[25], cnt2[25];

int main(void)
{
  while(1){
    cin >> w >> d;
    if(w == 0 && d == 0) break;
    for(int i = 1; i < 25; i++) cnt[i] = cnt2[i] = 0;
    int sum = 0, h;
    for(int i = 0; i < w; i++){
      cin >> h;
      sum += h;
      cnt[h]++;
    }
    for(int i = 0; i < d; i++){
      cin >> h;
      sum += h;
      cnt2[h]++;
    }
    for(int i = 1; i < 25; i++) sum -= min(cnt[i], cnt2[i]) * i;
    cout << sum << endl;
  }
  return 0;
}



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

using namespace std;

using ll = long long;

constexpr ll MOD = 1000000007;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;

    vector<ll> dp(K + 1, 0);
    ll ans = 0;
    for (int i = K; i >= 1; --i) {
        dp[i] = modpow(K / i, n);
        for (int j = i * 2; j <= K; j += i) {
            (dp[i] += MOD - dp[j]) %= MOD;
        }
        (ans += dp[i] * i % MOD) %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3936
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
	Scanner sc = new Scanner(System.in);
// 3つの文字の固まりをそれぞれ整数値と想定して読み込む 
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	if (a < b) {
		if (b < c) {
		System.out.printf("%d %d %d\n", a, b, c);
		}else if (a < c) { // ... 以降を書き足そう!
		System.out.printf("%d %d %d\n", a, c, b);
		} else {
		System.out.printf("%d %d %d\n", c, a, b);
		}
		}
	 else { if (b < c){// ... 以降を書き足そう! }
		if (a < c){
		System.out.printf("%d %d %d\n",b, a, c);
		} else {
		System.out.printf("%d %d %d\n", b, c, a);
		}
		} else {
		System.out.printf("%d %d %d\n", c, b, a);
		}
	}
}
}


Measured memory_bytes: 26200
#include <iostream>
#include <vector>

int main() {
    int N;
    std::cin >> N;

    std::vector<int> H(N);
    for (auto& h : H) std::cin >> h;

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        bool judge = true;
        for (int j = 0; j < i; ++j) {
            if (H[j] > H[i]) judge = false;
        }
        if (judge) ++ans;
    }

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


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

//*
ll fact[200010];
ll invfact[200010];
void makefact(int n,ll m){
	fact[0]=1;
	rep(i,0,n)fact[i+1]=fact[i]*(i+1)%m;
	invfact[n]=invp(fact[n],m);
	for(int i=n;i>0;i--)invfact[i-1]=invfact[i]*i%m;
}
ll choose(int n,int r,int m){return n<0||r<0||n-r<0?0:fact[n]*invfact[r]%m*invfact[n-r]%m;}
//*/


int main(){
	ll n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	a=a*invp(100-c,MOD)%MOD;
	b=b*invp(100-c,MOD)%MOD;
	c=c*invp(100,MOD)%MOD;
		
	makefact(2*n+5,MOD);
	ll ans=0;
	rep(i,0,n){
		//Aがかつ
		ans=(ans+(n+i)*choose(n-1+i,i,MOD)%MOD*pom(a,n,MOD)%MOD*pom(b,i,MOD)%MOD)%MOD;
		//Bがかつ
		ans=(ans+(n+i)*choose(n-1+i,i,MOD)%MOD*pom(b,n,MOD)%MOD*pom(a,i,MOD)%MOD)%MOD;
	}
	printf("%lld",(ans*invp(1-c,MOD)%MOD+MOD)%MOD);
}

Measured memory_bytes: 3328
n,a = map(int,input().split())
x = list(map(int,input().split()))

dpp = [0]*3000
dpm = [0]*3000

p = []
m = []
n0 = 0

for i in range(n):
    x1 = x[i] - a
    if x1 == 0:
        n0 += 1
    elif x1 > 0:
        p.append(x1)
    else:
        m.append(-x1)

for i in p:
    for j in range(2600,0,-1):
        if dpp[j] >= 1:
            dpp[j+i] += dpp[j]
    dpp[i] += 1

for i in m:
    for j in range(2600,0,-1):
        if dpm[j] >= 1:
            dpm[j+i] += dpm[j]
    dpm[i] += 1

ans = 0

for i in range(3000):
    ans += dpp[i] * dpm[i]

ans *= pow(2,n0)
ans += pow(2,n0) - 1

print(ans)


Measured memory_bytes: 67036
import java.util.Scanner;

/**
 * C - Maximum Volume
 * 正の整数 L が与えられます。
 * 縦、横、高さの長さ (それぞれ、整数でなくてもかまいません) の合計が L の直方体としてありうる体積の最大値を求めてください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 正の整数
        double l = sc.nextDouble();

        System.out.println( String.format( "%f", Math.pow( l / 3, 3 ) ) );

        sc.close();
    }
}

Measured memory_bytes: 23252
//ABC127 C - Prison 
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int INF=2147483647;
int n,m;
int ll,rr=INF,le,ri;
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>le>>ri;
		ll=max(ll,le);
		rr=min(rr,ri);
	}
	if(ll>rr){
		cout<<0<<endl;
		return 0;
	}
	else
		cout<<(rr-ll)+1<<endl;
	return 0;
}

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

int N, D, X;
int A[100];

int main(){
    cin >> N >> D >> X;
    for(int i = 0; i < N; i++) cin >> A[i];

    int ans = 0;
    for(int i = 0; i < N; i++){
        ans += (D-1)/A[i] + 1;
    }
    cout << (ans+X);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h> //-lm
#define rep(i,n) for(int i=0; i<n; i++)
#define getInt(n) scanf("%d", &n)
#define showAns(ans) printf("%d\n", ans)

int main(void){
    int N;
    getInt(N);

    int x,y,z; //x<=y<=z

    rep(i,N){
        int ans = 0;
        int x_max = sqrt((i+1)/6);
        for(x=1; x<=x_max; x++){
            int y_max = sqrt((i+1)/3);
            for(y=x; y<=y_max; y++){
                int z_max = sqrt(i+1);
                for(z=y; z<=z_max; z++){
                    if(x*x+y*y+z*z+x*y+y*z+z*x==i+1){
                        if(x==y && y==z) ans++;
                        if(x==y && y!=z) ans+=3;
                        if(x!=y && y==z) ans+=3;
                        if(x!=y && y!=z) ans+=6;
                    }
                }
            }
        }
        showAns(ans);
    }
    return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
//library end
int n;
string s[60];
int t[60];
string x;
int ans=0;
bool awake=true;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>s[i]>>t[i];
    }
    cin>>x;
    rep(i,n){
        if(!awake)ans+=t[i];
        if(s[i]==x)awake=false;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));

typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
int main(){
    int n,k;
    std::cin >> n>>k;
    std::vector<ll> x(n),y(n);
    rep(i,n)std::cin >> x[i]>>y[i];
    if(n==2){
        std::cout << abs(x[1]-x[0])*abs(y[1]-y[0]) << std::endl;
    }else if(n==3){
        ll ans=INF64;
        if(k==2){
            
            rep(i,3)rrep(j,i+1,3){
                ans=min(ans,abs(x[i]-x[j])*abs(y[i]-y[j]));
            }
        }
        if(k==3){
            sort(all(x));
            sort(all(y));
            ans=abs(x[2]-x[0])*abs(y[2]-y[0]);
        }
        std::cout << ans << std::endl;
    }else{
        ll ans=INF64;
        if(k==2){
            rep(i,n)rrep(j,i+1,n){
                ans=min(ans,abs(x[i]-x[j])*abs(y[i]-y[j]));
            }
        }
        if(k==3){
            rep(i,n)rrep(j,i+1,n)rrep(ii,j+1,n){
                int cnt=0;
                ll xa,xz,ya,yz;
                xa=min({x[i],x[j],x[ii]});
                xz=max({x[i],x[j],x[ii]});
                ya=min({y[i],y[j],y[ii]});
                yz=max({y[i],y[j],y[ii]});
                ans=min(ans,abs(xa-xz)*abs(ya-yz));
            }
        }
        else{
            rep(i,n)rrep(j,i+1,n)rrep(ii,j+1,n)rrep(jj,ii+1,n){
                int cnt=0;
                ll xa,xz,ya,yz;
                xa=min({x[i],x[j],x[ii],x[jj]});
                xz=max({x[i],x[j],x[ii],x[jj]});
                ya=min({y[i],y[j],y[ii],y[jj]});
                yz=max({y[i],y[j],y[ii],y[jj]});
                rep(t,n){
                    if(x[t]>=xa&&x[t]<=xz&&y[t]>=ya&&y[t]<=yz)cnt++;
                }
                if(cnt>=k)ans=min(ans,abs(xa-xz)*abs(ya-yz));
            }
        }
        std::cout << ans << std::endl;
    }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	ans := calc(b) ^ calc(a-1)
	fmt.Println(ans)
}

func calc(n int) int {
	c := ((n + 1) / 2) % 2
	if n%2 == 0 {
		return c ^ n
	}
	return c
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll N;
  cin >> N;
  vector<ll> T(N);
  rep(i,N)
  {
    cin >> T[i];
  }
  ll M = 1;
  rep(i,N)
  {
    M = max(M,lcm(M,T[i]));
  }
  cout << M << endl;
  return 0;
}


Measured memory_bytes: 3600
/**"I am not an authorized coder"**/
#include <bits/stdc++.h>
#define FOR(i, s, e)    for(int i=s; i<e; i++)
#define loop(i, n)      FOR(i, 0, n)
#define sf              scanf
#define pf              printf
#define pb              push_back
#define MP              make_pair
#define fr              first
#define sc              second
#define lli             long long
#define dd              double
#define all(v)          v.begin(), v.end()
#define PI              2*acos(0.0)
#define mem(ara, value) memset(ara, value, sizeof(ara))
#define paii            pair<int, int>
#define pall            pair<ll, ll>
#define SZ(a)           int(a.size())
#define open()          freopen("input.txt", "r", stdin)
#define show()          freopen("output.txt", "w", stdout)
#define read(a)         scanf("%d",&a)
#define read2(a,b)      scanf("%d%d",&a,&b)
#define read3(a,b,c)    scanf("%d%d%d",&a,&b,&c)
#define read4(a,b,c,d)  scanf("%d%d%d%d",&a,&b,&c,&d)
#define readI1(a)       scanf("%lld",&a)
#define readI2(a,b)     scanf("%lld %lld",&a,&b)
#define readI3(a,b,c)   scanf("%lld %lld %lld",&a,&b,&c)
#define readI4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define BOUNDARY(i, j)  ((i >= 0 && i < w) && (j >= 0 && j < h))
#define Mx 100009
#define EPS 1e-12
#define sq(x) ((x)*(x))
#define sq_dist(a,b)    (sqrt(sq(a.x-b.x)+sq(a.y-b.y)));
#define cross(o,a,b)    ((a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x))
using namespace std;
int main()
{
	int x0, y0, x1, y1, q, x2, y2;
    read4(x0,y0, x1, y1);
    read(q);
    for (int i = 0; i < q; i++)
    {
        read2(x2, y2);
        double x, y;
        x = (double)x0 + 1.0*(x1-x0)*((x1 - x0)*(x2 - x0) + (y1 - y0)*(y2 - y0)) / (pow(x1 - x0, 2) + pow(y1 - y0, 2));
        y = (double)y0 + 1.0*(y1-y0)*((x1 - x0)*(x2 - x0) + (y1 - y0)*(y2 - y0)) / (pow(x1 - x0, 2) + pow(y1 - y0, 2));
        printf("%.11f %.11f\n", x, y);
    }
    return 0;

}

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

vector<pair<int, int> > store(100007);

int main()
{
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> store[i].first;
        store[i].second = i;
    }

    sort(store.begin()+1 , store.begin()+N+1);

    for (int i = 1; i <= N; i++) {
        cout << store[i].second << ' ';
    }
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200005],b[200005];
int main(){
    int n;
    scanf("%d",&n);
    b[0]=-1;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    sort(b,b+n+1);
    for(int i=1;i<=n;i++){
        if(a[i]<=b[n/2]) printf("%d\n",b[n/2+1]);
        else printf("%d\n",b[n/2]);
    }

}


Measured memory_bytes: 3712
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define nl '\n'
#define sp ' '
#define zero '0'
#define r(a,b,c) for(ll a=(b);a<(c);++a)
#define v(a,b,c) for(ll a=(b);a>(c);--a)
#define f(a) cout<<fixed<<setprecision(10)<<a
#define d(a,b,c) cout<<setfill(a)<<setw(b)<<right<<c
#define hasten cin.tie(0);ios::sync_with_stdio(false)
ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,s,t,u,v,w,x,y,z;

const int prime[15]=
{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};

inline void in(){}
template<class T,class...A>
inline void in(T&&t,A&&...a){cin>>t;in(move(a)...);}

template <class T>inline void out(T t){cout<<t<<nl;}
template <class T, class...A>
inline void out(T t,A...a){cout<<t<<' ';out(move(a)...);}

inline ll dig(ll a){ll d=1;while(a/=10)++d;return d;}

inline ll gcd(ll a,ll b)
{ll c;while(a){c=a;a=b%a;b=c;}return b;}

inline bool isp(ll a){
	if(a<48){r(i,0,15)if(prime[i]==a)return 1;}
	else if(a<2809)return gcd(614889782588491410,a)==1;
	else {out("Error:Argument is Over-2808!");exit(1);}
	return 0;
}

int main(){
	hasten;
	ll en[100]={};
	in(n);
	r(i,0,n){
		in(a);
		if(en[a-1]==0){++s;++en[a-1];}
	}
	out(s);
	
}

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

int main(){
  string S;
  cin>>S;
  int ss=S.size();
  ll cnt=0,ans=0;
  if(S[0]=='B') cnt++;
  for(int i=1;i<ss;i++){
    if(S[i]=='W') ans+=cnt;
    else cnt++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return 1;}return 0;}

int N;
string S;

long long solve(){
	N = S.size();
  	vector<int> whsum(N+1,0);
  	vector<int> blsum(N+1,0);
  	for(int i = 0; i < N; ++i){
    	whsum[i+1]=whsum[i]+(S[i] == '.'?1:0);
    	blsum[i+1]=blsum[i]+(S[i] == '#'?1:0);
    }
	
  	long long res = 1LL << 60;
  	for(int left = 0; left <= N ; ++left){
    	long long tmp = 0;
      	//leftを全部白に
      	tmp += blsum[left]-blsum[0];
      
      	//rightを全部黒に
      	tmp += whsum[N]-whsum[left];
    	
    	chmin(res,tmp);
    }

	return res;

}

int main(){
	cin >> N >> S;
  	cout << solve() << endl;
}

Measured memory_bytes: 2180
N,Q = map(int,input().split())
S = input()
cnt = [0] * (N + 1)
lrs = []
for i in range(Q):
        lrs.append(list(map(int,input().split())))

for i in range(N):
        cnt[i+1] = cnt[i] + (1 if S[i:i+2] == "AC" else 0)
for lr in lrs:
        print(cnt[lr[1] - 1] - cnt[lr[0] - 1])

Measured memory_bytes: 32196
N,k = gets.split.map(&:to_i)
h = {}
N.times{
  a,b = gets.split.map(&:to_i)
  h[a] = (h[a] || 0) + b
}
h.keys.sort.each{ |a|
  k -= h[a]
  if k <= 0
    puts a; exit
  end
}


Measured memory_bytes: 7304
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
ll powmod(ll x, ll y, ll mod)
{
    ll ans = 1;
    while (y > 0)
    {
        if (y & 1)
        {
            ans *= x;
            ans %= mod;
        }
        x = x * x % mod;
        y >>= 1;
    }
    return ans;
}
struct COMB
{
    int L;
    vll kaijo, gyaku;
    ll mod;
    void __init__(int sz, ll md)
    {
        L = sz;
        mod = md;
        kaijo.resize(L + 1, 0);
        gyaku.resize(L + 1, 0);
        kaijo[0] = 1;
        repf(i, 1, L + 1)
            kaijo[i] = (kaijo[i - 1] * i) % mod;
        gyaku[L] = powmod(kaijo[L], mod - 2, mod);
        rep(i, L)
            gyaku[L - 1 - i] = gyaku[L - i] * (L - i) % mod;
    }
    ll powmod(ll x, ll y, ll mod)
    {
        ll ans = 1;
        while (y > 0)
        {
            if (y & 1)
            {
                ans *= x;
                ans %= mod;
            }
            x = x * x % mod;
            y >>= 1;
        }
        return ans;
    }

    ll calc(int n, int k)
    {
        if (n > L)
            return -1;
        return (((kaijo[n] * gyaku[k]) % mod) * gyaku[n - k]) % mod;
    }
    ll kai(int i)
    {
        return kaijo[i];
    }
    ll gya(int i)
    {
        return gyaku[i];
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    ll cnt = n * (n - 1) / 2;
    ll x = 0;
    vvii ans(n, vii(n, 0));
    while (cnt>0){
        repf(i,1,n+1){
            rep(k,n){
                ll ii = i + ((2 * k + 1) << x);
                if (ii>n)
                    break;
                ans[i-1][ii-1] = x + 1;
                cnt--;
            }
        }
        x++;
    }
    rep(i,n-1){
        repf(j,i+1,n){
            cout << ans[i][j] << " ";
        }
        cout << ENDL;
    }
}

Measured memory_bytes: 1536
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int M=10000000;
		for(;;)
		{
			int n=in.nextInt(),m=in.nextInt();
			int s=in.nextInt(),g1=in.nextInt(),g2=in.nextInt();
			if((n|m|s|g1|g2)==0)
				return;
			int cost[][]=new int[n+1][n+1];
			int war[][]=new int[n+1][n+1];
			int ans=M;
			for(int i=0;i<=n;i++)
			{
				Arrays.fill(cost[i], M);
				Arrays.fill(war[i], M);
			}
			for(int i=0;i<=n;i++)
			{
				cost[i][i]=0;
				war[i][i]=0;
			}
			for(int i=0;i<m;i++)
				cost[in.nextInt()][in.nextInt()]=in.nextInt();
			for(int i=0;i<=n;i++)
				for(int j=0;j<=n;j++)
					war[i][j]=cost[i][j];
			for (int i=0;i<=n;i++)
			{
				for(int j=0;j<=n;j++)
				{
					for(int k=0;k<=n;k++)
					{
						//j->kへ行くのにiを経由した方が良いかどうか
						int c=war[j][i]+war[i][k];
						war[j][k]=Math.min(war[j][k],c);
					}
				}
			}
			for(int i=0;i<=n;i++)
				ans=Math.min(ans, war[s][i]+war[i][g1]+war[i][g2]);	
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 14000
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
const long long inf = 1LL << 60;
vector<long long> IL(int n) {
    vector<long long> vec(n);
    for (int i=0; i<vec.size(); i++) cin >> vec.at(i);
    return vec;
}
vector<string> IS(int n) {
    vector<string> vec(n);
    for (int i=0; i<vec.size(); i++) cin >> vec.at(i);
    return vec;
}

void PA(vector<long long> vec) {
    for (int i=0; i<vec.size()-1; i++) cout << vec.at(i) << " ";
    cout << vec.at(vec.size()-1) << endl;
    return;
}
map<long long, long long> CL(vector<long long> vec) {
    map<long long, long long> count;
    for (long long x: vec) {
        count[x] += 1;
    }
    return count;
}

map<string, long long> CS(vector<string> vec) {
    map<string, long long> count;
    for (string s : vec) {
        count[s] += 1;
    }
    return count;
}


int main() {
    using ll = long long;
    using vl = vector<long long>;


    

    int n; cin >> n;
    vector<vector<int>> h(n+1, vector<int>(3));
    vector<vector<int>> dp(n+1, vector<int>(3));

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

    set<int> st = {0, 1, 2};

    for (int i=0; i<n; i++) {
        for (int j=0; j<3; j++) {
            switch (j)
            {
            case 0:
                dp[i+1][j] = max(dp[i][1], dp[i][2]) + h[i+1][j];
                break;
            case 1:
                dp[i+1][j] = max(dp[i][0], dp[i][2]) + h[i+1][j];
                break;
            default:
                dp[i+1][j] = max(dp[i][0], dp[i][1]) + h[i+1][j];
                break;
            }
        }
    }

    int ans = *max_element(dp[n].begin(), dp[n].end());
    cout << ans << endl;




}


Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
const ll INF = 1LL << 60;

int main() {
    
    char S[3];

    rep(i,3){
        cin >> S[i];
    }

    int count = 0;

    rep(i,3){
        //cout << i << endl;

        if(S[i] == 'R'){
            count += 1;
        }

        if((i==1)&&(S[i] == 'S')&&(count == 1)){
            break;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3620
// C - March
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------

lli solve()
{
  lli a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  map<lli, lli> mp;
  set<lli> st;
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  vs d;
  map<char, lli> e;
  rep(i, 0, n)
  {
    cin >> s;
    if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
    {
      e[s[0]]++;
      count++;
    }
  }
  b = e.size();
  for (auto x : e)
  {
    for (auto y : e)
    {
      for (auto z : e)
      {
        if (z.first > y.first && y.first > x.first)
        {
          ans += x.second * y.second * z.second;
        }
      }
    }
  }
  return ans;
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  out(solve());
}

Measured memory_bytes: 3576
// 日本語
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let vs: Vec<i16> = s.trim().chars().map(|token| token.to_string().parse().ok().unwrap()).collect();

    let mut i = 0;
    let mut result = 0;
    for v in vs {
        // cond
        if (i > 0 && v == 0) || (i < 0 && v == 1) {
            result += 1;
        }
        // stack
        i += if v == 1 { 1 } else { -1 };
    }
    println!("{}", result * 2);
}


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

int main() 
{
	int tmp , N,a[100000];

	cin >> N;
    for(int i=0;i<N;i++)cin >> a[i];
	tmp = a[0]-1;
	for (int i = 0;i < N;i++)
	{
		if (tmp == 1)
		{
			cout << i+1;
			return 0;
		}
		tmp = a[tmp]-1;
	}
	cout << "-1";
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

const int D = 60;
const int max_n = 200005;



int main() {
    string s; cin >> s;
    int n = s.size();

    int a = 0, b = 0, c = 0;
    rep(i,n){
        if(s[i] == 'a') a++;
        else if(s[i] == 'b') b++;
        else c++;
    }
    if((a == 1 && b == 0 && c == 0) || (a == 0 && b == 1 && c == 0) || (a == 0 && b == 0 && c == 1)){
        cout << "YES" << endl;
        return 0;
    }
    if((a == 1 && b == 1 && c == 0) || (a == 0 && b == 1 && c == 1) || (a == 1 && b == 0 && c == 1)){
        cout << "YES" << endl;
        return 0;
    }
    if(!a || !b || !c){cout << "NO" << endl; return 0;}
    if(abs(a-b) <= 1 && abs(b-c) <= 1 && abs(c-a) <= 1) {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
}




Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<pair<char, char>> td(q);
    rep(i, q) cin >> td[i].first >> td[i].second;
    s = '*' + s + '*';
    ll l = 0, r = n + 1;
    while((l + 1) < r) {
        ll m = (l + r) / 2;
        ll pos = m;
        rep(i, q) {
            if (td[i].first != s[pos]) continue;
            if (td[i].second == 'L') pos--;
            else pos++;
        }
        if (pos == 0) l = m;
        else r = m;
    }
    ll delcnt = l;
    l = 0, r = n + 1;
    while((l + 1) < r) {
        ll m = (l + r) / 2;
        ll pos = m;
        rep(i, q) {
            if (td[i].first != s[pos]) continue;
            if (td[i].second == 'L') pos--;
            else pos++;
        }
        if (pos == (n + 1)) r = m;
        else l = m;
    }
    delcnt += (n + 1 - r);
    cout << (n - delcnt) << endl;
    return 0;
}


Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
int n,x;
map<int,int> m;
int main(){
cin>>n;
for(int i=0;i<n;i++){
    cin>>x;
    m[x]=i;
    }
    for(auto i:m){
    cout<<i.second+1<<' ';
    }
}


Measured memory_bytes: 5504
#include<iostream>
using namespace std;
int main(){
	string a,b;
	cin>>a;
	cin>>b;
	if(a=="H"&&b=="H"){
	
		printf("H\n");
}
	else if(a=="D"&&b=="D"){
	
	printf("H\n");
}
	else{
	
		printf("D\n");
	
}
}

Measured memory_bytes: 256
n = gets.chomp.to_i

arr = Array.new(n + 1, 0)
ind = 1
while ind <= n 
	ngo = ind 
	while ngo <= n 
		arr[ngo] += 1
		ngo += ind 
	end
	ind += 1
end
cnt = 0
1.step(n, 2) do |i|
	cnt += 1 if arr[i] == 8
end
puts cnt

Measured memory_bytes: 14228
#include <stdio.h>

int main(void){
    int min, i, n, count=0;
    scanf("%d", &n);
    int p[n];
    for (i=0;i<n;i++){
        scanf("%d", &p[i]);
    }
    min = p[0];
    for (i=0;i<n;i++){
        if (min >= p[i]){
            min = p[i];
            count += 1;
        }
    }
    printf("%d", count);
    return 0;
}

Measured memory_bytes: 896
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < N; i++) set.add(sc.nextInt());
		System.out.println(N == set.size() ? "YES" : "NO");
	}
}

Measured memory_bytes: 101116
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static int[] primes( final int lim ) {

	boolean[] isPrime = new boolean[lim + 1];
	Arrays.fill( isPrime, true );
	isPrime[0] = isPrime[1] = false;

	final int indexLim = (int)sqrt( lim );
	int index = 2;
	while ( index <= lim ) {
	    for ( int i = index * 2; i <= lim; i += index ) {
		isPrime[i] = false;
	    }
	    index++;
	    while ( index <= lim && !isPrime[index] ){
		index++;
	    }		
	}
	final int count = count( isPrime, true );
	int[] answer = new int[count];
	index = 0;
	for ( int i = 0; i <= lim; i++ ) {
	    if ( isPrime[i] ) {
		answer[index] = i;
		index++;
	    }	    
	}
	return answer;
    }

    static int count( final boolean[] array, final boolean val ) {
	int count = 0;
	for ( boolean b : array ) {
	    if ( b == val ) {
		count++;
	    }
	}
	return count;
    }
    
    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	final int[] primes = primes( 1000000 );
	
	while ( true ) {

	    final int n = stdin.nextInt();
	    if ( n == 0 ){
		break;
	    }

	    int index = 0;
	    int count = 0;
	    while ( primes[index] <= n / 2 ) {
		if ( Arrays.binarySearch( primes, n - primes[index] ) > 0 ) {
		    count++;
		}
		index++;
	    }
	    System.out.println( count );
	}	
    }    
}

Measured memory_bytes: 23240
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a=int(input())
if a==25:
    print("Christmas") 
elif a==24:
    print("Christmas Eve") 
elif a==23:
    print("Christmas Eve Eve") 
else:
    print("Christmas Eve Eve Eve")


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

int main() {
	string S, s1, s2;
	int len;

	cin >> S;
	len = S.length();

	s1 = S.substr(0, (len - 1) / 2);
	s2 = S.substr(((len + 3) / 2) - 1, (len - 1) / 2);

	if (s1 == s2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <cstring>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000000000000
#define int long long
struct edge{int to,cap,rev;};

vector<edge> G[200];
int level[200];
int iter[200];

void add_edge(int from,int to,int cap){
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size()-1});
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty()){
		int v = que.front();que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e = G[v][i];
			if(e.cap >0&&level[e.to] <0){
				level[e.to] = level[v]+1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v,int t,int f){
	if(v==t)return f;
	for(int &i = iter[v];i<G[v].size();i++){
		edge &e = G[v][i];
		if(e.cap>0 && level[v] <level[e.to]){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d >0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow = 0;
	for(;;){
		bfs(s);
		if(level[t] < 0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f = dfs(s,t,inf))>0){
			flow += f;
		}
	}
}

signed main(){
	int n;
	cin >> n;
	vector<ll> a(n+1);
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	ll s=0;
	for(int i=1;i<=n;i++){
		if(a[i]>0){
			s += a[i];
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]>=0){
			add_edge(0,i,a[i]);
			add_edge(0,i,0);
		}else{
			add_edge(0,i,0);
			add_edge(i,n+1,abs(a[i]));
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(j%i==0){
				add_edge(j,i,inf);
			}
		}
	}
	ll ans = max_flow(0,n+1);
	cout <<  s-ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.TreeMap;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int time = 0;
		int by = 0;
		int count = 0;
		String ans = "Yes";
		Map<Integer, Integer> map = new TreeMap<Integer, Integer>();

		for (int i = 0; i < N; i++) {
			time = sc.nextInt();
			by = sc.nextInt();
			if (map.containsKey(by)) {
				map.replace(by, time + map.get(by));
			} else {
				map.put(by, time);
			}
		}

		for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
			count += entry.getValue();
			if (count > entry.getKey()) {
				ans = "No";
			}
		}

		sc.close();
		System.out.println(ans);
	}

};


Measured memory_bytes: 73668