akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cassert>
#include <algorithm>

int search_right_label(int top, int front){
	int right = 0;
	int face[7][5] = {	/* face[上面ラベル][側面ラベル群] */
		{0, 0, 0, 0, 0}, /* face[0][]はラベルに合わせるため無視(0で埋める) */
		{2, 3, 5, 4, 2}, /* 上 1のとき、横の4面の値 + 1周して隣[1][1] */
		{3, 1, 4, 6, 3}, /* 上 2のとき、横の4面の値 + 1周して隣[2][1] */
		{1, 2, 6, 5, 1}, /* 上 3のとき、横の4面の値 + 1周して隣[3][1] */
        {5, 6, 2, 1, 5}, /* 上 4のとき、横の4面の値 + 1周して隣[4][1] */
	    {1, 3, 6, 4, 1}, /* 上 5のとき、横の4面の値 + 1周して隣[5][1] */
	    {4, 5, 3, 2, 4}  /* 上 6のとき、横の4面の値 + 1周して隣[6][1] */
	};
	
	for(int i = 0; i < 4; i++){		/* 側面(4面)から、正面ラベル探し dice[top][0～3] */
		if(face[top][i] == front){
			right = face[top][i+1]; /* 正面ラベルの右隣が右面ラベル */
			break;
		}
	}
	return right;
}

int main(){
	using namespace std;
	
	static const int INPUT_DICE_MIN = 0;
	static const int INPUT_DICE_MAX = 100;
	static const int INPUT_QUEST_CNT_MIN = 1;
	static const int INPUT_QUEST_CNT_MAX = 24;
	
	/* diceの値入力 */
	int dice[7] = {0};					/* diceの値 (添字はラベル1～6) */
    for(int i = 1; i <= 6; i++){
        cin >> dice[i];
		assert(INPUT_DICE_MIN <= dice[i] && dice[i] <= INPUT_DICE_MAX);		/* 前提条件 */
    }
	
	/* 質問数の入力 */
	int quest_cnt = 0;				/* 質問数のカウント */
	cin >> quest_cnt;
	assert(INPUT_QUEST_CNT_MIN <= quest_cnt && quest_cnt <= INPUT_QUEST_CNT_MAX);	/* 前提条件 */
	
	/* 質問 */
	int top_num;					/* 上の入力値 */
	int top_label;					/* 上の入力値のラベル */
	int front_num;					/* 正面の入力値 */
	int front_label;				/* 正面の入力値のラベル */
	int right_label;				/* 指定の入力値での右のラベル */
	
	while(cin >> top_num >> front_num){
		/* 右面のラベルを求める */
		for(int label = 1; label <= 6; label++){
			if(dice[label] == top_num){			/* 上のラベルを求める */
				top_label = label;
			}
			else if(dice[label] == front_num){	/* 正面のラベルを求める */
				front_label = label;
			}
		}
		right_label = search_right_label(top_label, front_label);
		cout<< dice[right_label] << endl;
	}
	return 0;
}


Measured memory_bytes: 3056
//vector には.find() がなぜかないのでアルゴリズムを使う (線形？　オーダー不明)
//set map のメンバのfind はlogn保障らしい。

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cstdio>
#include <string>

using namespace std;

int main() {
    int i,j;
    int n,q,C=0;
    int buf;
    set<string> dictionary;
	set<string>::iterator itr;
	string com,str;
    
    //入力
    cin >> n;
	for(i=0; i<n; i++){
		cin >> com;
		cin >> str;

		if(com=="insert"){
			dictionary.insert(str);
		}
		else { //"find"の場合
			if( dictionary.find(str) != dictionary.end() ) printf("yes\n");
			else printf("no\n");
		}
	}

    
	return 0;
}

Measured memory_bytes: 30612
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		HashSet<Character> set = new HashSet<Character>();
		set.add('A');
		set.add('C');
		set.add('G');
		set.add('T');
		
		int max = 0;
		String str = sc.next();
		
		for (int i = 0; i < str.length(); i++) {
			nextStr:
			for (int j = i; j < str.length(); j++) {
				for (int k = i; k <= j; k++) {
					if (!set.contains(str.charAt(k)))
						continue nextStr;
				}
				max = Math.max(j - i + 1, max);
			}
		}
		System.out.println(max);
	}

}


Measured memory_bytes: 26980
#include <stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	int num[n];
	int count1=0,count2=0,count4=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
		if(num[i]%4==0)
		count4++;
		else if(num[i]%2==0)
		count2++;
		else
		count1++;
	}
	if(count2==0&&count1<=count4+1)
	printf("Yes");
	else if(count2>0&&count4>=count1)
	printf("Yes");
	else
	printf("No");
	return 0;
} 

Measured memory_bytes: 512
using System;
using System.Linq;

class D
{
	static void Main()
	{
		Console.ReadLine();
		var d = Console.ReadLine().Select((c, i) => new { c, i }).ToLookup(_ => _.c, _ => _.i).Select(g => g.ToArray()).ToArray();

		var q = from i1 in d.Select(g => g[0])
				from i2 in d.Select(g => Find(g, i1 + 1)).Where(x => x > 0)
				select d.Count(g => g.Last() > i2);
		Console.WriteLine(q.Sum());
	}

	static int Find(int[] a, int v)
	{
		var i = Array.BinarySearch(a, v);
		if (i < 0) i = ~i;
		return i < a.Length ? a[i] : 0;
	}
}


Measured memory_bytes: 14304
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] b = {0, 0, 0, 0, 0};

		for(int i = 0; i < n; i++) {
			String str = sc.next();
			switch(str.charAt(0)) {
			case 'M': b[0]++; break;
			case 'A': b[1]++; break;
			case 'R': b[2]++; break;
			case 'C': b[3]++; break;
			case 'H': b[4]++; break;
			}
		}

		long a = 0;
		for (int i = 0; i < 3; i++) {
			for (int j = i + 1; j < 4; j++) {
				for (int k = j + 1; k < 5; k++) {
					a += b[i] * b[j] * b[k];
				}
			}
		}
		System.out.println(a);
	}
}


Measured memory_bytes: 42188
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N = II()
    S = [0]*N
    numAB = 0
    numA = 0
    numB = 0
    ans = 0
    for i in range(N):
        s = input()
        ans += s.count('AB')
        if s[-1] == 'A':
            if s[0] == 'B':
                numAB += 1
            else:
                numA += 1
        elif s[0] == 'B':
            numB += 1



    if numA > 0 and numAB > 0:
        numA -= 1
        numAB += 1
    # elif numA == 0 and numAB > 0:
    #     numAB -= 1
    if numB > 0 and numAB > 0:
        numB -= 1
        numAB += 1
    # elif numB == 0 and numAB > 0:
    #     numAB -= 1
    if numAB > 0:

        ans += numAB -1  + min(numA,numB)
    else:
        ans += min(numA,numB)
    
        
    print(ans)
if __name__ == '__main__':
    main()

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

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto & a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define endl "\n"
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);

	const int MAX = 1'000'001;
	int N; cin >> N;
	vi C(MAX, 0);
	vector<char> seen(MAX, false);

	vi A(N); trav(v, A) cin >> v, C[v]++;
	sort(all(A));

	int r = 0;

	trav(v, A) {
	  if(C[v] == 1) {
		for(int d = 1; d * d <= v; d++) {
		  if(v % d == 0 and (seen[d] or seen[v/d]))
			goto done;
		}

		r ++;
done:;
	  }

	  seen[v] = true;
	}

	cout << r << endl;
}


Measured memory_bytes: 8968
a = set()
for i in range(1, 35):
    for j in range(2, 10):
        a.add(i ** j)
b = []
for i in a:
    if i <= 1000:
        b.append(i)
# print(sorted(b))
b.sort(reverse=True)
x = int(input())
for i in b:
    if i <= x:
        print(i)
        break

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

int main()
{
	int x,n,i,a[105]={0},s=0;
	
	cin>>n;
	
	for(i=1;i<=n;i++){
		cin>>x;
		a[x]=1;
	}
	for(i=1;i<=100;i++){
		if(a[i]==1){
			s++;
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
X = list(map(int, input().split()))

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

total = 0
min_sekisan = 1
mod = 10 ** 9 + 7
for i in range(1, n):
    min_sekisan *= i
    min_sekisan %= mod
#print(min_sekisan)

counter = 0
for i in range(n-1):
    counter += min_sekisan
    total -= (min_sekisan * X[i]) % mod
    min_sekisan *= i + 1
    min_sekisan *= mod_inv(i + 2, mod)
    min_sekisan %= mod
total += (X[n-1] * counter) % mod
print(total % mod)

"""
from collections import defaultdict as dd
import copy
def count(n):
    lis = [[[i for i in range(1, n + 1)], dd(int)]]
    while len(lis[0][0]) != 1:
        temp = []
        for nums, counter in lis:
            for i in range(len(nums)-1):
                new_dic = copy.deepcopy(counter)
                new_dic[nums[i]] -= 1
                new_dic[nums[i+1]] += 1
                temp.append([nums[:i] + nums[i+1:], new_dic])
        lis = temp
    return lis
#print(count(4))
#print(len(count(4)))

total = dd(int)
for lis, dic in count(7):
    for key, val in dic.items():
        total[key] += val
print(total)
"""

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  rep(i,n){
    cin>>a[i]>>b[i]>>c[i];
  }
  int dp[n][3];//dp[i][j]:i+1日目にｊを選択した場合の幸福度の最大値
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  fori(i,1,n){
    dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]);
  }
  cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<endl;
  return 0;
}


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

int main() {
  int a,b,c,d,e,k;  
  cin >> a >> b >> c>> d >> e >> k;

  if(e - a > k){
    cout << ":(" << endl;
  }else {
    cout << "Yay!" << endl;
  }
}


Measured memory_bytes: 256
/*
    Don't practice until you get it right. Practice until you can't get it wrong.
*/
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld double
#define pii pair<ll,ll>
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vp vector<pii>
#define pb push_back
#define mp make_pair
#define sc(a) scanf("%lld",&a);
#define sd(a) scanf("%lf",&a);
#define test() ll tt;cin>>tt;for(ll testcase=1;testcase<=tt;testcase++)
#define all(v) v.begin(),v.end()
#define vivek_ghosh ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000055
#define mod 1000000007
#define ff first
#define ss second
const int INF=0x3f3f3f3f;
 
ll power(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}
 
ll modinv(ll a,ll m)
{
    ll g =__gcd(a, m);
    ll res=power(a, m-2, m);
    return res;
}
 
vb prime(MAX,true);
vl prm;
void sieve()
{
	prime[0] = prime[1] = false;
	for(ll p=2;p*p<MAX;p++)
	{
		if(prime[p])
		{
			for(ll i=p*p;i<MAX;i+=p)
				prime[i] = false;
		}
	}
	for(ll p=2;p<MAX;p++)
	{
		if(prime[p])
			prm.pb(p);
	}
}

ll n,m,t,i,j,k,q,x,y,ans=0,cnt=0,sum=0,mx=-1,mn=INT_MAX;
string s;
 
int main()
{
	vivek_ghosh;
	
	cin>>n>>m;
	map<ll,ll> wa,ac;
	ll pen = 0, cor = 0;
	for(i=0;i<m;i++)
	{
		ll p;
		cin>>p>>s;
		
		if(s == "AC")
		{
			if(ac[p] == 0)
			{
				cor++;
				pen+=wa[p];
			}
			ac[p]++;
		}
		else if(s == "WA")
		{
			wa[p]++;
		}
	}
	
	cout<<cor<<" "<<pen<<endl;
	
 
	return 0;
}



Measured memory_bytes: 12928
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a,b,c,d,p;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		p = sc.nextInt();
		int r1,r2;
		r1 = a*p;
		r2 = (p<=c)? b : b + (p - c) * d;

		System.out.println(Math.min(r1, r2));

	}

}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("6");
            WillReturn.Add("aabbca");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("10");
            WillReturn.Add("aaaaaaaaaa");
            //1
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("45");
            WillReturn.Add("tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir");
            //9
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[1];

        int UB = S.Length - 1;
        int Answer = 0;
        for (int I = 0; I <= UB - 1; I++) {
            string LeftStr = S.Substring(0, I + 1);
            string RightStr = S.Substring(I + 1);

            int CurrCnt = LeftStr.ToCharArray().Intersect(RightStr.ToCharArray()).Count();
            if (Answer < CurrCnt)
                Answer = CurrCnt;
        }
        Console.WriteLine(Answer);
    }
}


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

typedef long long ll;
const int N = 1e5 + 5;

int main() {
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    cout << (A+B) % 24 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[101],t[101];
int main()
{
	int i,j,n;
	scanf("%d",&n);
	scanf("%s %s",s,t);
	for(i=0,j=0;i<n||j<n;)
	{
		if(i<=j)
		{
			printf("%c",s[i]);
			i++;
		}
		else
		{
			printf("%c",t[j]);
			j++;
		}
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i<N;i++)
    cin >> p.at(i);

  sort(p.begin(), p.end(), greater<int>());
  int sum = 0;
  for (int i = 0; i<N;i++)
    sum += p.at(i);
  sum -= p.at(0) / 2;
  cout << sum << endl;
}

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


#ifdef LOCAL
#define DEBUGMSG()                                                              \
{                                                                               \
    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]" ;        \
}
#define DEBUGVAR(x)                                                             \
{                                                                               \
    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]:" ;       \
    cerr << "([" << typeid(x).name() << "]" << #x << ")" << x << endl ;         \
}
#define DEBUGARR(l, r)                                                          \
{                                                                               \
    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]:" ;       \
    copy(l, r, ostream_iterator<decltype(*l)>(cerr, " "));                      \
    cerr << endl ;                                                              \
}
#else
#define DEBUGMSG()
#define DEBUGVAR(x)
#define DEBUGARR(l, r)
#endif // LOCAL

int N;
string str;

int main()
{
    int g = 0, p = 0;
    cin >> str ;

    for(string::iterator itr = str.begin(); itr != str.end(); itr++)
        if(*itr == 'p')
            p++;
        else
            g++;

    DEBUGVAR(p);
    DEBUGVAR(g);

    if(p >= g)
        cout << 0 << endl ;
    else
        cout << (g-p)/2 << endl ;

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;

int main(void)
{
    int n;
    ll ans = 0;
    scanf("%d", &n);

    for (int i = 1; i <= n; i++)
    {
        if (i % 3 == 0 || i % 5 == 0)
            continue;
        ans += i;
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main() {
  ll n; cin >> n;
  map<ll, ll> mp;
  ll ans=0;
  for (ll i=1; i<=n; i++) {
    ll h; cin >> h;
    ans += mp[i-h];
    mp[i+h]++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 26216
//submitted by Himj
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;

const int mxn=2e5+1;
ll ans[51][51],n,arr[51][51];
void mul(ll a[51][51],ll b[51][51],int temp)
{
  ll c[51][51];
  ms(c,0);
  ll i,j,k;
 /* fr(i,0,n)
  {
    fr(j,0,n)
    cout<<a[i][j]<<" ";
    cout<<"\n";
  }
  fr(i,0,n)
  {
    fr(j,0,n)
    cout<<b[i][j]<<" ";
    cout<<"\n";
  }*/
  fr(i,0,n)
  {
    fr(j,0,n)
    {
      fr(k,0,n)
      c[i][j]=(c[i][j]+a[i][k]*b[k][j]%mod)%mod;
    //  cout<<a[i][j]<<" ";
    }
   // cout<<"\n";
  }
  fr(i,0,n)
  {
    fr(j,0,n)
  {
    if(temp)
    ans[i][j]=c[i][j];
  else arr[i][j]=c[i][j];
  //cout<<c[i][j]<<" ";
  }
 // cout<<"\n";
}
}
void p(ll n)
{
  while(n)
  {
    if(n&1)
      mul(ans,arr,1);
    mul(arr,arr,0);
    n=n>>1;
  }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

  int t=1;
  //cin>>t;
    while(t--){
      ll k;
      cin>>n>>k;
      ll i,j;
      ms(ans,0);
      fr(i,0,n)
      {
        fr(j,0,n)
      {
        cin>>arr[i][j];
        if(i==j)
          ans[i][j]=1;
      }
    }
   
     p(k);
   // mul(arr,arr,1);
     // cout<<ans[n-1][n-1]<<"\n";
     ll temp=0;
      fr(i,0,n)
      {
        fr(j,0,n)
        {
          //cout<<ans[i][j]<<" ";
          temp=(temp+ans[i][j])%mod;
        }
        //cout<<"\n";
      } 
      cout<<temp;     
       
    }
  return 0;
  }



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll A,B,C,X,Y;
cin>>A>>B>>C>>X>>Y;
ll sum[3];
sum[0]=A*X+B*Y;
sum[1]=min(X,Y)*C*2;
sum[2]=max(X,Y)*C*2;
if(X>Y) sum[1]+=(X-Y)*A;
if(Y>X) sum[1]+=(Y-X)*B;
sort(sum,sum+3);
cout<<fixed<<setprecision(0)<<sum[0];
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long

signed main() {
    int n;
    cin >> n;
    vector<int> aa(n+1);
    int ans = 1;
    aa[0]=3;
    rep(i,n) {
        int a;
        cin >> a;
        a++;
        aa[a]++;
        ans *= aa[a-1];
        ans %= mod;
        aa[a-1]--;
    }
    cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3952
use std::collections::HashMap;

fn main(){
  let n: usize = read();

  for t in 0 .. n {
    let mut sdv: Vec<Vec<u32>> = Vec::new();
    let mut stv: Vec<Vec<char>> = vec![vec![' ';9];9];
  
    for _ in 0 .. 9 {
      sdv.push(read_vec());
    }

    for i in 0 .. 9 {
      let mut hm1: HashMap<u32, (usize, usize)> = HashMap::new();
      let mut hm2: HashMap<u32, (usize, usize)> = HashMap::new();
      for j in 0 .. 9 {
        match hm1.get(&sdv[i][j]) {
          Some(&(u, v)) => {
            stv[i][j] = '*';
            stv[u][v] = '*';
          },
          None => {
            hm1.insert(sdv[i][j], (i, j));
          },
        }
        match hm2.get(&sdv[j][i]) {
          Some(&(u, v)) => {
            stv[j][i] = '*';
            stv[u][v] = '*';
          },
          None => {
            hm2.insert(sdv[j][i], (j, i));
          },
        }
      }
    }
    
    for bi in 0 .. 3 {
      for bj in 0 .. 3 {
        let mut hm: HashMap<u32, (usize, usize)> = HashMap::new();
        for i in 0 .. 3 {
          for j in 0 .. 3 {
            let ii = bi * 3 + i;
            let jj = bj * 3 + j;
            match hm.get(&sdv[ii][jj]) {
              Some(&(u, v)) => {
                stv[ii][jj] = '*';
                stv[u][v] = '*';
              },
              None => {
                hm.insert(sdv[ii][jj], (ii, jj));
              },
            }
          }
        }
      }
    }
    if t > 0 { println!(""); }

    for i in 0 .. 9 {
      for j in 0 .. 9 {
        print!("{}{}", stv[i][j], sdv[i][j]);
        if j == 8 { println!(""); }
      }
    }
  }
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 5032
n,q = map(int,input().split())
MAX = int(10**6)
A = [[0 for i in range(2)] for j in range(MAX)]
head = 0
end = int(n)-1
cnt = 0
for i in range(n):
    A[i][0],A[i][1] = input().split()

while 1:
    if head == end:
        print("{} {}".format(A[head][0],cnt+int(A[head][1])))
        break

    temp = A[head]
    head +=1
    if int(temp[1]) <= q:
        print("{} {}".format(temp[0],cnt+int(temp[1])))
        cnt += int(temp[1])
    else:
        temp[1] = str(int(temp[1]) - q)
        if end+1 == MAX:
            end = 0
        else:
            end += 1
        A[end] = temp
        cnt += q
    





Measured memory_bytes: 111676
using System;
using System.Collections.Generic;
using System.Linq;
class PG{
    public static void Main(string[] args){
        var list=new List<int[]>();
        while(true){
            int[] nums=Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if(nums[0]==0&&nums[0]==nums[1]){
                break;
            }else{
                list.Add(nums);
            }
        }
        foreach(int[] nums in list){
            int count=0;
            int max=nums[0];
            int n=nums[1];
            for(int i=1;i<=max;i++){
                for(int j=i+1;j<=max;j++){
                    for(int k=j+1;k<=max;k++){
                        if(i+j+k==n){
                            count++;
                            break;
                        }else if(i+j+k>n){
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 16440
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String N = sc.next();
    int count = 0;
    for(int i = 0; i < N.length(); i++){
      if(N.charAt(i) == '2') count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23892
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    String a=scan.next();
    String b=scan.next();
    String[] a1=a.split("");
    String[] b1=b.split("");
    boolean flag=true;
    for(int x=0; x<a1.length; x++){
      if(!(a1[x].equals(b1[x]))){
        flag=false;
      }
    }
    if(flag){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 35652
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;

void solve() {
	int a, b, n;
	cin>>a>>b;
	cout<<a*b<<endl;
}
int main() {
    ios_base::sync_with_stdio(0);
    int T=1 ,cas=0;
    while(T--) {
    	solve();
    }
    return 0;
}

// ll, reset, 1, bottom

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve(){
		UL N, M; cin >> N >> M;
		vector<pair<UL, UL>> Q(M); rep(i, M) cin >> Q[i].first >> Q[i].second;
		vector<UL> C(N);
		rep(i, M) { C[Q[i].first - 1]++; C[Q[i].second - 1]++; }
		bool ok = true;
		rep(i, N) { if (C[i] & 1) ok = false; }
		cout << (ok ? "YES" : "NO") << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,a[110];
int read()
{
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;	
}
int main()
{	
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	int lst=1,ans=0;
	for(int i=1;i<=n+1;i++)
		if(a[i]!=a[lst]) ans+=(i-lst)/2,lst=i; 
	printf("%d",ans);	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
c = input()
left = 0
right = N - 1

w_idx = -1
r_idx = -1

ans = 0

while left < right:
    if w_idx == -1 and c[left] == "W":
        w_idx = left
    if w_idx == -1 and c[left] == "R":
        left += 1

    if r_idx == -1 and c[right] == "R":
        r_idx = right
    if r_idx == -1 and c[right] == "W":
        right -= 1

    if w_idx != -1 and r_idx != -1:
        ans += 1
        w_idx = -1
        r_idx = -1
        left += 1
        right -= 1

print(ans)


Measured memory_bytes: 67732
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int a,b;
	    Scanner input = new Scanner(System.in);
	    a = input.nextInt();
	    b = input.nextInt();
	    if(a == 1 && b ==2 || a == 2 && b == 1){
            System.out.println(3);
        }
        if(a == 3 && b ==2 || a == 2 && b == 3){
            System.out.println(1);
        }
        if(a == 3 && b ==1 || a == 1 && b == 3){
            System.out.println(2);
        }
    }
}


Measured memory_bytes: 23764
import sys
import numpy as np
import collections

def parse(inp):
    N=int(next(inp))
    H=np.array(next(inp).split(),dtype=int)
    return H
  
def split(H):
    Splited=np.array([],dtype=int)
    SplitPoint=[]
    for i in range(len(H)):
        if(H[i]==0):
            SplitPoint.append(i)
    
    if(SplitPoint==[]):
        Splited=np.array([H])
        return Splited
            
    Splited=np.split(H,SplitPoint)
    
            
    
    for i in range(len(Splited)):
        if(Splited[i].size==0):
             continue
        elif(Splited[i][0]==0):
            Splited[i]=np.delete(Splited[i],[0])
    
    return Splited
                
def main(H):
    H=collections.deque(H)
#    print(H)

    answer=0
    
    while H:
        Hnow=H.popleft()
        if(Hnow.size==0):
            continue
#        print("now: ",Hnow)
        Hnowmin=Hnow.min()
        answer+=Hnowmin
        for i in range(len(Hnow)):
            Hnow[i]=Hnow[i]-Hnowmin
#        print("decreased: ",Hnow)
        for i in range(len(split(Hnow))):
            if(split(Hnow)[i].size!=0):
#                print("append: ",split(Hnow)[i])
                H.append(split(Hnow)[i])
#        print("H: ",H)
    return answer

print(main(split(parse(sys.stdin))))


Measured memory_bytes: 13328
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
1234
'''


def MAIN():
  # T_IN()
  A()


def A():
  s = IN_S()

  p = ""
  for i in s:
    if len(p) != 0:
      if p == i:
        print("Bad")
        exit()
    p = i

  print("Good")


  return None
 

def B():
  return None


def C():
  return None


MAIN()


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 1000
#define A 100

int top;
int S[N];

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}
int main(){
  int i,j;
  top = 0;
  char s[A];

  while( scanf("%s", s) != EOF){
    if ( s[0] == '+' ){
      i = pop();
      j = pop();
      push(j + i);

    } else if ( s[0] == '-' ){
      i = pop();
      j = pop();
      push(j - i);

    } else if ( s[0] == '*' ){
      i = pop();
      j = pop();
      push(j * i);

    } else {
      push(atoi(s));

    }
  }
  printf("%d\n",pop());

  return 0;
}



Measured memory_bytes: 2100
from sys import stdin
from functools import reduce


def comb_mod(n, a, mod=10**9+7):
    # https://img.atcoder.jp/abc156/editorial.pdf
    # nCk は, k回の積で計算できる
    num = reduce(lambda x, y: x * y % mod, range(n, n - a, -1))
    den = reduce(lambda x, y: x * y % mod, range(1, a + 1))
    # nCk mod = X/Y mod = X * Y^(10**9+7-2) mod
    return num * pow(den, mod - 2, mod) % mod


def get_result(data):
    n, a, b = data[0]
    mod = 10**9+7
    out = pow(2, n, mod) - comb_mod(n, a, mod) - comb_mod(n, b, mod) - 1 
    out %= mod
    return out

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Measured memory_bytes: 3572
import java.util.*;
import java.io.*;

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args) throws IOException{
		NScanner sc = new NScanner(System.in);
		int n = sc.nextInt();
		HashSet<String> dic = new HashSet<String>();
		for(int i = 0; i < n; ++i){
			String com = sc.next();
			String str = sc.next();
			if(com.equals("insert")){
				dic.add(str);
			}else{
				System.out.println(dic.contains(str) ? "yes" : "no");
			}
		}
	}
	
	

}


class NScanner{

	private BufferedReader br;
	private StringTokenizer tok;

	public NScanner(InputStream is) throws IOException{
		br = new BufferedReader(new InputStreamReader(is));
		getLine();
	}

	private void getLine() throws IOException{
		while(tok == null || !hasNext()){
			tok = new StringTokenizer(br.readLine());
		}
	}

	public boolean hasNext(){
		return tok.hasMoreTokens();
	}

	public String next() throws IOException{
		if(hasNext()){
			return tok.nextToken();
		}else{
			getLine();
			return tok.nextToken();
		}
	}

	public int nextInt() throws IOException{
		if(hasNext()){
			return Integer.parseInt(tok.nextToken());
		}else{
			getLine();
			return Integer.parseInt(tok.nextToken());
		}
	}

	public long nextLong() throws IOException{
		if(hasNext()){
			return Long.parseLong(tok.nextToken());
		}else{
			getLine();
			return Long.parseLong(tok.nextToken());
		}
	}

	public double nextDouble() throws IOException{
		if(hasNext()){
			return Double.parseDouble(tok.nextToken());
		}else{
			getLine();
			return Double.parseDouble(tok.nextToken());
		}
	}
}


Measured memory_bytes: 145452
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

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

    cin >> a >> b >> c;

    cout << max(0, c - (a - b)) << endl;
}

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

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

const int N=2e6+5;
vector<int> dp(N);
int n,h,d;
const int mod=1e9+7;
int add(int a,int b)
{
    a+=b;
    if(a>=mod)
        a-=mod;
    return a;
}
int mul(int a,int b)
{
    return (ll)a*b%mod;
}
int sub(int a,int b)
{
    a-=b;
    if(a<0)
        a+=mod;
    return a;
}
int powmod(int x,int k)
{
    int ans=1;
    for(;k;k>>=1,x=mul(x,x))
        if(k&1)
            ans=mul(ans,x);
    return ans;
}
int get(int l,int r)
{
    return sub(dp[l],dp[r+1]);
}
vector<int> fact,ifact(N);
int nCk(int n,int k)
{
    return mul(fact[n],mul(ifact[n-k],ifact[k]));
}
int main()
{
    fact.pb(1);
    for(int i=1;i<N;i++)
        fact.pb(mul(fact.back(),i));
    ifact[N-1]=powmod(fact[N-1],mod-2);
    for(int i=N-2;i>=0;i--)
        ifact[i]=mul(ifact[i+1],i+1);
    scanf("%i %i %i",&n,&h,&d);
    dp[h]=fact[n-1];
    int magic=0;
    for(int i=1;i<=n;i++){
        magic=add(magic,fact[i]);
    }
    for(int i=h-1;i>0;i--)
    {
        dp[i]=mul(get(i+1,i+d),magic);
        dp[i]=add(dp[i],dp[i+1]);
    }
    int sum=get(1,d);
    sum=mul(sum,n);
    printf("%i\n",sum);
    return 0;
}


Measured memory_bytes: 26220
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W; cin >> H >> W;
  vector<vector<string> > vs(H, vector<string>(W));
  FOR(i,0,H) {
    FOR(j,0,W) {
      cin >> vs[i][j];
    }
  }
  FOR(y,0,H) {
    FOR(x,0,W) {
      if(vs[y][x] == "snuke") {
        char c = 'A' + x;
        cout << c << y + 1 << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;

int main() {
    int n;
    map<string,int> mp;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}

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

int main(){
    int n;
    cin >> n;
    int a[110000];
    int fourCount = 0, twoCount = 0, oddCount = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i] % 4 == 0){
            fourCount++;
        }else if(a[i] % 4 == 2){
            twoCount++;
        }else{
            oddCount++;
        }
    }
    string ans = "Yes";
    if(twoCount == 0  &&  fourCount >= n/2){
        cout << ans << endl;
        return 0;
    }
    vector<int> vec;
    for(int i=0; i<twoCount; i++){
        vec.push_back(2);
    }
    for(int i=0; i<n-twoCount; i++){
        if(fourCount > 0){
            vec.push_back(4);
            fourCount--;
        }else{
            vec.push_back(1);
            oddCount--;
        }
        i++;
        if(i==n-twoCount) break;
        if(oddCount > 0){
            vec.push_back(1);
            oddCount--;
        }else{
            vec.push_back(4);
            fourCount--;
        }
    }

    for(auto itr = vec.begin(); itr != vec.end()-1; itr++) {
        if(*itr * *(itr+1) % 4 != 0){
            ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>

using namespace std;
using ll = long long;

int calc(int a, int b, int i);
char pm(int i);

int main() {
	int N;
	cin >> N;
	int a,b,c,d;
	a = N/1000; N = N - a * 1000;
	b = N/100; N = N - b * 100;
	c = N/10; N = N - c * 10;
	d = N;

	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				int ans = 0;
				//ans = calc(calc(a,b,i) , calc(c,d,k), j);
				ans += calc(a,b,i);
				ans += calc(0,c,j);
				ans += calc(0,d,k);
				//cout << ans << endl;
				if (ans == 7) {
					cout << a << pm(i) << b << pm(j) << c << pm(k) << d << "=7" << endl;
					return 0;
				}
			}
		}
	}
}

int calc(int a, int b, int i) {
	if (i == 1) {
		return a - b;
	}
	else {
		return a + b;
	}
}

char pm(int i) {
	if (i == 1) {
		return '-';
	}
	else {
		return '+';
	}
}


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

long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  int n;
  cin>>n;
  if (n == 3) {
    cout<<"2 5 63"<<endl;
    return 0;
  }
  vector<int> ans;
  int rest = n;
  int a = 3;
  while (rest - 2 >= 2 && a + 6 <= 30000) {
    ans.push_back(a);
    ans.push_back(a + 6);
    a += 12;
    rest -= 2;
  }
  int b = 2;
  while (rest > 2) {
    ans.push_back(b);
    ans.push_back(b + 2);
    ans.push_back(b + 4);
    b += 6;
    rest -= 3;
  }
  if (rest == 2) {
    ans.push_back(b);
    ans.push_back(b + 2);
  } else if (rest == 1) {
    ans.push_back(b + 4);
  }

  for (int i=0; i<n; i++) {
    cout<<ans[i];
    if (i != n - 1) {
      cout<<" ";
    }
  }
  cout<<endl;
}

Measured memory_bytes: 512
N, *L = map(int, open(0).read().split())
cost = []
for i,m in enumerate(zip(*[iter(L)]*N)):
  cost.append(list(m))
  cost[i][i] = 10**10
ans = 0
for i in range(N):
  for j in range(i):
    m = min(a+b for a, b in zip(cost[i],cost[j]))
    if m<cost[i][j]:
      print(-1)
      exit()
    if m>cost[i][j]:
      ans += cost[i][j]
print(ans)

Measured memory_bytes: 12972
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
struct Edge {
	int to;
	Edge *nxt;
	Edge(int to, Edge *nxt) : to(to), nxt(nxt) {}
} *head[N];
void add(int x, int y) {head[x] = new Edge(y, head[x]);}
char s[N];
queue <int> q;
int n, mn, sum, f[N], deg[N], del[N];
void topsort() {
	for(int i = 1; i <= n; ++ i) if(deg[i] == 1 && s[i] == 'B') q.push(i);
	while(! q.empty()) {
		int x = q.front(); q.pop();
		del[x] = 1;
		for(Edge *i = head[x]; i; i = i->nxt) {
			deg[i->to] --;
			if(s[i->to] == 'B' && deg[i->to] == 1 && del[i->to] == 0) q.push(i->to);
		}
	}
}
int v(int x) {return (deg[x] & 1) ^ (s[x] == 'W');}
int val(int x) {return (v(x) == 1) ? -2 : 0;}
void dfs(int x, int fa) {
	sum += (v(x) == 1) + 2; f[x] = val(x);
	for(Edge *i = head[x]; i; i= i->nxt) {
		if(i->to == fa || del[i->to]) continue;
		dfs(i->to, x);
		mn = min(mn, f[x] + f[i->to]);
		f[x] = min(f[x], f[i->to] + val(x));
	}
}
signed main() {
	n = read();
	for(int i = 1, x, y; i < n; ++ i) deg[x = read()] ++, deg[y = read()] ++, add(x, y), add(y, x);
	scanf("%s", s + 1); topsort();
	int x; for(x = 1; x <= n; ++ x) if(del[x] == 0) break;
	if(x > n) return puts("0"), 0;
	dfs(x, 0); sum -= 2; printf("%d\n", sum + mn);
	return 0;
}


Measured memory_bytes: 13184
n,m,c = map(int,input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]
ans = s = 0
for i in range(n):
    s=0
    for j in range(m):
        s += a[i][j] * b[j] 
    if s + c > 0:
        ans +=1
print(ans)

Measured memory_bytes: 3064
MAX_N = 50
n = int(input())
C = [[0] * 26 for _ in range(n)]
for i in range(n):
    S = input()
    for s in S:
        C[i][ord(s) - ord('a')] += 1
res = ''
for i in range(26):
    t = MAX_N + 1
    for j in range(n):
        t = min(t, C[j][i])
    res += chr(i + ord('a')) * t
print(res)


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

/* // Ordered Set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define os_find(k) find_by_order(k)
#define os_order(k) order_of_key(k)
*/

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loop1(i,a,b) for(int i=a;i<=b;i++)
#define rloop(i,a,b) for(int i=a;i>b;i--)
#define rloop1(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define ncr(n,r) fact[n]*modInv(fact[r])*modInv(fact[n-r])
#define modInv(a) binExp(a,mod-2)
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)

bool isPrime(int num){
    bool flag=true;
    for(int i = 2; i <=sqrt(num); i++) {
       if(num % i == 0) {
          flag = false;
          break;
       }
    }
    return flag;
}
int dp[100005];
signed main()
{
   int n;
   cin>>n;
   int arr[n+1];
   loop1(i,1,n)cin>>arr[i];
   dp[2]=abs(arr[2]-arr[1]);
   loop1(i,3,n){
    dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
   }
   cout<<dp[n];
}


Measured memory_bytes: 5196
a,b,c=map(int,input().split())
 
ans = 0
 
while a%2 == b%2 == c%2 == 0:
  ans += 1
  newa=b//2+c//2
  newb=a//2+c//2
  newc=a//2+b//2
  a=newa
  b=newb
  c=newc
  if a == b == c:
    print("-1")
    break
else:
  print(ans)

Measured memory_bytes: 9128
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

fn main() {
    input!{
        n: u64,
        y: u64,
    }

    for itiman in 0..(n+1) {
        for gosen in 0..(n - itiman + 1) {
            let sen = n - itiman - gosen;
            if itiman * 10000 + gosen * 5000 + sen * 1000 == y {
                println!("{} {} {}", itiman, gosen, sen);
                return;
            }
        }
    }
    println!("-1 -1 -1");
}


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

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

    long long N;
    scanf("%lld",&N);

    long long L;
    scanf("%lld",&L);

    std::vector<std::string> S(N);
    REP(i, N)
        std::cin >> S[i];

    sort(S.begin(), S.end());

    REP(i, N)
        cout << S[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write('\n'.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
#from decimal import Decimal
from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7



a,b,c=mdata()
k=int(data())
while b<=a:
    b*=2
    k-=1
while c<=b:
    k-=1
    c*=2
if k>=0:
    out("Yes")
else:
    out("No")



Measured memory_bytes: 72940