akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double

using namespace std;

    const ll N = 1e5 + 7;
    const ll mod = 1e9 + 7;
    const ld eps = 1e-9;



void solve(){
    ld n , D;
    cin >> n >> D;
    int ans= 0;
    for(int i = 1; i <= n; ++ i){
        ld x , y;
        cin >> x >> y;
        x = sqrt(x * x + y * y);
        if(D >= x){
                ++ ans;
        }
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tt = 1;
    //cin >> tt;
    while(tt --){
            solve();
    }
}

/**

**/


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;
map<int, int> ct;
map<int, int> ct2;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define AFOR(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n, m, l;
int a, b, c;
string s[MN];
string str;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

/*
int N;
cin >> N;
vi vect(N);
FOR(i,N) cin >> vec.at(i);*/
//sort(vec.begin(),vec.end());
//vvi data(N,vi(4));


/*	int bfs(int x, int y,vvi &A,vvi flag) {
		queue<pii> que;
		que.push(pii(x, y));
		while (que.size()) {
			pii p = que.front(); que.pop();
			AFOR(i, 4) {
				int nx = p.first + dx[i]; int ny = p.second + dy[i];
				if (0 <= nx && nx < N && 0 <= ny && ny < N) {
					if (A.at(p.first).at(p.second) + flag.at(p.first).at(p.second) < A.at(nx).at(ny)) {
						A.at(nx).at(ny) = A.at(p.first).at(p.second) + flag.at(p.first).at(p.second);
						que.push(pii(nx, ny));
					}
				}
			}
		}
		return 0;
	}
	*/
	/*int gcd(int p, int q){
		while(q != 0){
		int r = p % q;
		p = q;
		q = r;
		}
	return p;
	}*/
ll N;
ll K;
int A[200100];
int  L[200100];
ll ans = 0;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N ;
	AFOR(i, N) {
		cin >> A[i];
		L[i] = 0;
	}
	AFOR(i, N) {
		L[A[i]-1]++;
	}
	AFOR(i, N) {
		ans += ((ll)L[i] * (ll)(L[i] - 1)) / 2;
		}
	AFOR(i,N){
		cout << ans-L[A[i]-1]+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline bool Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e17;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll m,k;
    cin >> m >> k;
    if (k >= (1<<m)){
        PRINT(-1);
        return 0;
    }
    if (m == 1){
        if (k == 0) cout << 0 << " " << 0 << " " << 1 << " " << 1 << '\n';
        else PRINT(-1);
        return 0;
    }
    vector<ll> ans(1<<(m+1));
    ll len = (1<<m),index = 0;
    rep(i,len){
        if (i == k) continue;
        ans[index] = i;
        ans[2*len-2-index] = i;
        index++;
    }
    ans[len-1] = k;
    ans[2*len-1] = k;
    array_output(all(ans));
}


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string a="CODEFESTIVAL2016";
	string s;
	cin>>s;
	int v=0;
	for (int i=0;i<(int)s.size();i++){
		if (s[i]!=a[i]) v++;
	}
	cout<<v<<endl;
}

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

void prints(int a[], int n) {
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		cout << a[i];
	}
	cout << "\n";
}

void bubbleSort(int a[], int n) {
	int c = 0;
	bool f = true;
	while (f) {
		f = false;
		for (int i = n - 1; i >= 1; i--) {
			if (a[i] < a[i - 1]) {
				swap(a[i], a[i - 1]);
				c++;
				f = true;
			}
		}
	}

	prints(a, n);
	cout << c << "\n";
}

int main()
{
	int n, a[100];
	cin >> n;

	for (int i = 0; i < n; i++) cin >> a[i];

	bubbleSort(a, n);
}


Measured memory_bytes: 3096
#include <cstdio>
#include <algorithm>

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

using namespace std;

const int v[4] = {10, 50, 100, 500};

int n;
int c[4];

int total(){
	int s = 0;
	rep(i, 4){
		s += c[i] * v[i];
	}
	return s;
}

void optimize(int x, int* c){
	for(int i = 3; i >= 0; --i){
		c[i] = x / v[i];
		x %= v[i];
	}
} 

int main(){
	int k = 0;
	while(scanf("%d", &n), n){
		if(k > 0){
			printf("\n");
		}
		
		rep(i, 4){
			scanf("%d", &c[i]);
		}
		int d[4];
		optimize(total() - n, d);
		rep(i, 4){
			if(c[i] > d[i]){
				printf("%d %d\n", v[i], c[i] - d[i]);
			}
		}
		++k;
	}
	return 0;
}

Measured memory_bytes: 1032
# -*- coding: utf-8 -*-
import math
from collections import Counter
N = int(input())
As = list(map(int, input().split()))
M = 10**9 + 7
cnt = Counter(As)
ans = 1
if N%2 == 0:
    for i in range(0,N//2):
        if cnt[i*2+1] != 2:
            print(0)
            exit()

else:
    for i in range(1,N//2):
        if cnt[i*2] != 2:
            print(0)
            exit()
    if cnt[0] != 1:
        print(0)
        exit()

p = N//2
for i in range(p):
    ans = (ans*2) % M

print(ans)

Measured memory_bytes: 14820
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
const int MOD = 1e9+7;

bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; }
    return true;
}

int main() {
	int N,M;
  	cin >> N >> M;
  	vi a(N);
  	vi b(N);
  	vi c(M);
  	vi d(M);
  	vi ans(N);
  	vector<vector<int>> sub(N,vector<int>(M));
  	rep(i,N){
    	cin >> a[i];
      	cin >> b[i];
    }
    rep(i,M){
    	cin >> c[i];
      	cin >> d[i];
    }
  	rep(i,N){
      	int fragi=0;
      	int dis;
    		rep(j,M){
        		dis = abs(a[i]-c[j]) + abs(b[i] - d[j]);
          		if(dis < abs(a[i]-c[fragi]) + abs(b[i] - d[fragi])){
            		fragi = j;
           		}
        	}
      	ans[i] = fragi+1;  
    }
  	rep(i,N) cout << ans[i] << endl;
}

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

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

int main() {
  int n, m;
  cin >> n >> m;
  int L = 0, R = n, l, r;
  rep(i, m) {
    cin >> l >> r;
    L = max(L, l);
    R = min(R, r);
  }
  cout << max(R - L + 1, 0) << endl;
  return 0;
}


Measured memory_bytes: 3596
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int[][] ab = new int[3][3];
		
		ab[0][0] = sc.nextInt();
		ab[0][1] = sc.nextInt();
		ab[0][2] = sc.nextInt();
		ab[1][0] = sc.nextInt();
		ab[1][1] = sc.nextInt();
		ab[1][2] = sc.nextInt();
		ab[2][0] = sc.nextInt();
		ab[2][1] = sc.nextInt();
		ab[2][2] = sc.nextInt();
		

		if(diff_check(ab,0,1,true)&&
				diff_check(ab,0,2,true)&&
				diff_check(ab,1,2,true)&&
				diff_check(ab,0,1,false)&&
				diff_check(ab,0,2,false)&&
				diff_check(ab,1,2,false))
		System.out.println( "Yes");
		else
			System.out.println( "No");
	}

	private static boolean diff_check(int[][] ab, int i, int j, boolean b) {
		
		int point;
		
		if(b){
			point = ab[i][0]-ab[j][0];
			if(point!=ab[i][1]-ab[j][1])	return false;
			if(point!=ab[i][2]-ab[j][2])	return false;
		}else{
			point = ab[0][i]-ab[0][j];
			if(point!=ab[1][i]-ab[1][j])	return false;
			if(point!=ab[2][i]-ab[2][j])	return false;
		}
		
		return true;
		
	}
}

Measured memory_bytes: 22996
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        String S = sc.nextLine();
        sc.close();
        Map<String, Integer> alphabetsMap = getAlphabets();
        String[] alphabets = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
                "S", "T", "U", "V", "W", "X", "Y", "Z" };
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < S.length(); i++) {
            String chara = String.valueOf(S.charAt(i));
            int index = alphabetsMap.get(chara) + N;
            if (index > 26) {
                index -= 26;
            }
            sb.append(alphabets[index - 1]);
        }

        System.out.println(sb.toString());
    }

    private static Map<String, Integer> getAlphabets() {
        Map<String, Integer> ret = new HashMap<>();
        ret.put("A", 1);
        ret.put("B", 2);
        ret.put("C", 3);
        ret.put("D", 4);
        ret.put("E", 5);
        ret.put("F", 6);
        ret.put("G", 7);
        ret.put("H", 8);
        ret.put("I", 9);
        ret.put("J", 10);
        ret.put("K", 11);
        ret.put("L", 12);
        ret.put("M", 13);
        ret.put("N", 14);
        ret.put("O", 15);
        ret.put("P", 16);
        ret.put("Q", 17);
        ret.put("R", 18);
        ret.put("S", 19);
        ret.put("T", 20);
        ret.put("U", 21);
        ret.put("V", 22);
        ret.put("W", 23);
        ret.put("X", 24);
        ret.put("Y", 25);
        ret.put("Z", 26);

        return ret;
    }

}

Measured memory_bytes: 22720
#include<stdio.h>
void merge(int *, int , int, int);
void mergeSort(int *, int, int);
#define MAX 500000
#define INF 2000000000
int cont;
int L[MAX/2+2], R[MAX/2+2];
int main(){
  int i,A[MAX],n;
  
  scanf("%d",&n);
  cont = 0;
  for(i=0;i < n ;i++){
    scanf("%d",&A[i]);
    if(A[i] >= INF){
      return 1;
    }
  }
  
  mergeSort(A,0,n);
  
  for(i=0;i<n;i++){
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",cont);

  
  return 0;
}

void merge(int A[], int left, int mid, int right){
  int n1,n2,i,j,k;
  n1 = mid - left;
  n2 = right - mid;
  for( i = 0; i < n1;i++){
    L[i] = A[left + i];
      }
  for(i = 0; i < n2;i++){
    R[i] = A[mid + i];
  }
    L[n1] = INF;
    R[n2] = INF;
    i = 0;
    j = 0;
    for (k = left ; k < right ;k++){
      cont++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
	}
    else{ 
      A[k] = R[j];
      j = j + 1;
	}
  }
  }
void mergeSort(int A[],int left, int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
      }
}





Measured memory_bytes: 5588
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  long long int n,m,x;
  cin>>n>>m>>x;
  long long int range=0;
  vector<vector<long long int>> books(n,vector<long long int> (m+1));
  for(int i = 0;i<n;i++){
    for(int j = 0;j<m+1;j++){
      cin>>books[i][j];
      if(j==0){
        range+=books[i][j];
      }  
    }
  } 
  long long int ans=LLONG_MAX;
  int numOfSubsets=pow(2,n);
  for(int i=1;i<numOfSubsets;i++){
    long long int cost=0;
    vector<int> skills(m);
    for(int j=0;j<n;j++){
      if((i&1<<j)){
        cost+=books[j][0];
        for(int i = 1;i<m+1;i++){
          skills[i-1]+=books[j][i];
        }
      }
    }
    bool posilbe=true; 
    for(auto s:skills){
      if(s<x){
        posilbe=false;
        break;
      } 
    }
    if(posilbe){
      ans=min(ans,cost);
    }
  }
  if(ans!=LLONG_MAX){
    cout<<ans<<"\n";  
  }
  else{
    cout<<-1<<"\n";  
  }
  return 0; 
}

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

int main(void)
{
    int H, W;
    while(true) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long pw(long long x,long long y)
{
	long long ans=1;
	while(y)
	{
		if(y&1)
		{
			ans*=x;
			ans%=md;
		}
		x*=x;
		x%=md;
		y>>=1;
	}
	return ans;
}
long long ff[2020202],fff[2020202],n,ans=1;
string s;
long long C(long long x,long long y)
{
	return ff[x]*fff[x-y]%md*fff[y]%md;
}
int main()
{
	cin>>n>>s;
	ff[0]=1;
	for(int i=1;i<=2020000;i++)
	{
		ff[i]=ff[i-1]*i;
		ff[i]%=md;
	}
	fff[2020000]=pw(ff[2020000],md-2);
	for(int i=2019999;i>=1;i--)
	{
		fff[i]=fff[i+1]*(i+1);
		fff[i]%=md;
	}
	for(int i=s.size();i<=s.size()+n;i++)
	{
		ans+=C(s.size()+n,i)*pw(25,s.size()+n-i)%md;
		ans%=md;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 35808
#include <iostream>

using namespace std;

int main()
{
    long long a , b, c,minn=0;
    cin>>a;
    for(long long  i=2 ; i*i<=a; ++i)
    {
        if(a%i==0) {
            minn=a/i +i -2;

        }
    }
    if(minn) cout<<minn;
    else
    cout<<a-1;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Save Your Privacy!
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			boolean[][] e = new boolean[n][n+1];
			for(int i=0;i<n;i++){
				int m = sc.nextInt();
				while(m--!=0)e[i][sc.nextInt()]=true;
			}
			boolean[] f = new boolean[n+1];
			int K = sc.nextInt();
			while(K--!=0)f[sc.nextInt()]=true;
			List<Integer> l = new ArrayList<Integer>();
			for(int i=0;i<n;i++){
				boolean ok = true;
				for(int j=1;j<=n;j++)if(f[j]&&!e[i][j])ok=false;
				if(ok)l.add(i+1);
			}
			System.out.println(l.isEmpty()||l.size()>1?-1:l.get(0));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

long long int getMinimumCost(long long int arr[], long long int size, long long int k)
{
    long long int dp[size];
    dp[0] = 0;
    dp[1] = abs(arr[0] - arr[1]);
    for(long long int i = 2 ; i < size ; i++)
    {
        long long int currMin = 1000000000;
        for(long long int j = i-1 ; (j >= i - k) && (j >= 0) ; j--)
        {
            currMin = min(currMin, abs(arr[i]-arr[j]) + dp[j]);
        }
        dp[i] = currMin;
    }
    return dp[size-1];
}

int main(int argc, const char * argv[])
{
    long long int size;
    long long int k;
    cin>>size>>k;
    long long int arr[size];
    for(long long int i = 0 ; i < size ; i++)
    {
        cin>>arr[i];
    }
    cout<<getMinimumCost(arr, size, k)<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,A[100000],sco,ans;
set<ll> se;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>A[i];
    for(ll c=1;c<n;c++){
        se.clear();
        sco=0;
        for(ll x=1;;x++){
            if(c*x>=n)break;
            se.insert(c*x);
            if(se.size()!=2*x-1)break;
            se.insert(n-1-c*x);
            if(se.size()!=2*x)break;
            sco+=A[c*x];
            a=n-1-c*x;
            sco+=A[a];
            //cout<<sco<<a<<c<<endl;
            if(a>c)ans=max(ans,sco);
        }
    }
    cout<<ans<<endl;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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


int main(){
    int n; cin >> n;
    int sum = n;
    vector<vector<int> > flag(101, vector<int>(101, 0));
    vector<int> ans1, ans2;
    if(n % 2 == 0)
        sum++;
    REP(i, 1, n+1){
        REP(l, 1, n+1){
            if(i != l && flag[i][l] == 0 && i + l != sum){
                flag[i][l]++;
                flag[l][i]++;
                ans1.pb(i);
                ans2.pb(l);
            }
        }
    }
    cout << ans1.size() << endl;
    REP(i, 0, ans1.size()){
        cout << ans1[i] << " " << ans2[i] << endl;
    }
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Text;
using static System.Math;
using static System.Console;

namespace AtTest.D_Challenge
{
    class ABC_035
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n=ReadInt();
            int[] array=ReadInts();
            int res=int.MaxValue;
            for(int i=0;i<=100;i++)
            {
                int tmp=0;
                for(int j=0;j<n;j++)
                {
                    tmp+=(i-array[j])*(i-array[j]);
                }
                res=Min(res,tmp);
            }
            WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if(a==b)
cout<<"Draw";
else

if(a!=1  && a>b && b!=1)
cout<<"Alice";
else
if(a==1)
cout<<"Alice";
else
if(b!=1 && b>a)
cout<<"Bob";
else
if(b==1)
cout<<"Bob";


    return 0;
}


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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S[3];
    rep(i, 3) {
        cin >> S[i];
    }
    reverse(S[0].begin(), S[0].end());
    reverse(S[1].begin(), S[1].end());
    reverse(S[2].begin(), S[2].end());

    char winner, player = 'a';
    while (1) {
        if (player == 'a') {
            if (S[0].size() == 0) {
                winner = 'A';
                break;
            } else {
                player = S[0][S[0].size() - 1];
                S[0].pop_back();
            }
        } else if (player == 'b') {
            if (S[1].size() == 0) {
                winner = 'B';
                break;
            } else {
                player = S[1][S[1].size() - 1];
                S[1].pop_back();
            }
        } else {
            if (S[2].size() == 0) {
                winner = 'C';
                break;
            } else {
                player = S[2][S[2].size() - 1];
                S[2].pop_back();
            }
        }
    }

    cout << winner << endl;
    
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
//#define _CRTDBG_MAP_ALLOC
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

const ll LINF = 9187201950435737471;
const ll nLINF = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const int MAXN = 1e5 + 15;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const int BLOCK = 500;
const double PI = acos(-1);
//auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
auto seed = 194113341;
mt19937 rnd(seed);

bool isEqual(double a, double b) {
    return abs(a - b) <= EPS;
}

#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) ((_v) * (_v))
#define vi vector <int>
#define vpi vector <pair <int, int> >
#define eb emplace_back
#define pb push_back
#define mod(x, m) ((x) % m + (x < 0 ? m: 0))


inline void IO() {
#if buyolitsez
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
}

template <typename T>
istream& operator >> (istream& in, vector<T>& a) {
    for (auto& i : a)
        in >> i;
    return in;
}

template <typename T>
ostream& operator << (ostream& out, const vector<T>& a) {
    for (auto& i : a) {
        out << i << " ";
    }
    return out;
}

template <typename T, typename D>
istream& operator >> (istream& in, pair<T, D>& a) {
    in >> a.first >> a.second;
    return in;
}

template <typename T, typename D>
ostream& operator << (ostream& out, const pair<T, D>& a) {
    out << a.first << " " << a.second;
    return out;
}

//#define int int64_t

vi adj[MAXN];
int where[MAXN];

void solve() {
    int n, m;
    cin >> n >> m;
    while (m--) {
        int a, b;
        cin >> a >> b;
        adj[a].eb(b);
        adj[b].eb(a);
    }
    where[1] = 1;
    queue <int> q;
    q.push(1);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto u : adj[v]) {
            if (!where[u]) {
                where[u] = v;
                q.push(u);
            }
        }
    }
    for (int i = 2; i <= n; ++i) {
        if (!where[i]) {
            cout << "No";
            return;
        }
    }
    cout << "Yes\n";
    for (int i = 2; i <= n; ++i) {
        cout << where[i] << "\n";
    }
}

signed main() {
    IO();
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 10520
#include <iostream>
#include <string>

int main()
{

  std::string g;
  int a=0;

  std::cin >> g;

  for (int i=0; i < 3; ++i){
    if (g[i] == '1'){
      a++;
    }
  }

  std::cout << a << std::endl;




}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
	string s;
	cin >> s;
	int flag = 0;
	for (int i = 0; i < (int)s.length(); i++) {
		if (s[i] == 'C') flag = 1;
		else if (s[i] == 'F' && flag == 1) {
			flag = 2;
			break;
		}
	}
	if (flag == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
//knapsack 0-1
#include<bits/stdc++.h>
#define fastIO ios::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define f(i, l, r) for(i = l; i < r; i++)
#define fd(i, l, r) for(i = l; i > r; i--)
#define mod 1000000007
#define pb push_back
using namespace std;
typedef pair <int, int> pi;

int main(){
	fastIO
    int test = 1;
    // cin >> test;
    while(test--){
        int n; cin >> n;
        ll W, weight[n], value[n];
        cin >> W;
        int i;
        f(i,0,n)cin >> weight[i] >> value[i];
        ll dp[n+1][W+1];
        int j;
        f(i,0,n+1){
            f(j,0,W+1){
                if(i == 0 || j == 0)
                    dp[i][j] =0;
                else if(j >= weight[i-1])
                    dp[i][j] = max(dp[i-1][j],value[i-1] + dp[i-1][j-weight[i-1]]);
                else dp[i][j] = dp[i-1][j];
            }
        }
        cout << dp[n][W];
    }
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  ll k,x;
  cin>>k>>x;
  if(k*500ll>=x)cout<<("Yes")<<endl;
  else cout<<("No")<<endl;

}

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

typedef long long LL;

void solve(long long N, long long X) {
  LL remain = X;
  if (N == 0 && X == 1) {
    cout << 1 << endl;
    return;
  }
  LL level = N - 1;
  LL ans = 0;
  for (; level >= 0; level--) {
    bool dec = true;
    LL sum = 1;
    LL pan = 1;
    for (int i = 0; i < level; i++) {
      sum = sum * 2 + 3;
      pan = pan * 2 + 1;
    }
    if (remain >= 2 * sum + 2) {
      cout << ans + pan * 2 + 1 << endl;
      return;
    }
    dec = (remain <= sum + 1);

    if (dec) {
      remain--;
      if (level == 0 && remain == 1) {
        ans += 1;
      }
    } else {
      remain -= sum + 2;
      ans += pan + 1;
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long X;
  scanf("%lld", &X);
  solve(N, X);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define modulo 1000000007
//#define int int64_t
#define float double
#define PI acos(-1)
#define sinDegrees(x) sin((x) * PI / 180.0)
#define cosDegrees(x) cos((x) * PI / 180.0)
#define tanDegrees(x) tan((x) * PI / 180.0)
#define atanDegrees(x) atan(x)* 180.0 / PI
using namespace std;
int power(int x,int y,int m)
{
int temp;
if(y == 0)
return 1;
temp = (power(x, y/2,m))%m;
if (y%2 == 0)
return ((temp%m)*temp);
else
return ((x*temp%m)*temp%m)%m;
}
int inv(int x)
{
return (power(x,modulo-2,modulo))%modulo;
}
bool comp(int a,int b)
{
return a<b;
}
///Solution created by:Ahmadsm2005
int32_t main()
{
//freopen("output.txt","w", stdout);
//freopen("rect.in","r", stdin);
iostream::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
double a,b,h,m;
cin>>a>>b>>h>>m;;
double d=abs(((h+m/60.0)*5)-m);
double angle=min(((d)*6),360-(d*6));
//cout<<angle<<endl;
cout<<fixed<<setprecision(10)<<sqrt(a*a+b*b-2*(a*b)*(cosDegrees(angle)));
return 0;
}


Measured memory_bytes: 4156
// Author : Mohamed sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
const int N = 2e5+9;
int n, m, par[N], Size[N];
int get_par(int u)
{
	return par[u] == u? u: par[u] = get_par(par[u]);
}
void uni(int u, int v)
{
	u = get_par(u);
	v = get_par(v);
	if (u == v)return; 
	par[u] = v;
	Size[v] += Size[u];
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		par[i] = i;
		Size[i] = 1; 
	}
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		u--;v--;
		uni(u, v);
	}
	int ans = 0;
	for (int i = 0; i < n; i++)ans = max(ans, Size[get_par(i)]); 
	cout << ans <<"\n";
}


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

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	int difference,Max;
	Max = max(a,max(b,c));
	difference = 3 * Max - a - b - c;
	if(difference % 2 == 1)
		difference += 3;
	cout << difference / 2 << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main() {
	const int N_MAX = 200000;
	int N, T;
	int t[N_MAX];
	int count = 0;
	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		cin >> t[i];
	}

	for (int i = 0; i < N-1; i++) {
		int diff = t[i + 1] - t[i];
		if (diff > T) {
			count += T;
		}
		else {
			count += diff;
		}
	}
	count += T;

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    int ans = 0;

    vector<int> f;
    char p = '0';
    for (int i = 0; i < n; i++) {
        if (s[i] != p) {
            f.push_back(i);
            p = s[i];
        }
    }
    if (f.empty()) {
        cout << n << endl;
        return 0;
    }
    if (s[n - 1] == '1') f.push_back(n);
    for (int i = 0; i + 2 * k + 1 < f.size(); i += 2) {
        int len = f[i + 2 * k + 1] - f[i];
        if (ans < len) ans = len;
    }
    int t = min(2 * k - 1, (int)f.size() - 1);
    if (ans < f[t]) ans = f[t];
    if (ans < n - f[f.size() - 1 - t]) ans = n - f[f.size() - 1 - t];

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


Measured memory_bytes: 1020
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
    auto N = readln.split[0].to!ulong;
    auto A = readln.split.to!(ulong[]);
    N = A.length;
    auto grps = sort(A.dup).group;
    size_t[ulong] nums;
    
    //grps.array.writeln;
    
    foreach (tup; grps) {
        nums[tup[0]] = tup[1];
    }
    //nums.writeln; 
    
    ulong all_num = grps.map!(a => a[1] * (a[1]-1)).sum / 2;
    ulong all_num_true = nums.values.dup.map!(a => a*(a-1)).sum / 2;
    
    int[] re; re.length = N;
    if (all_num > all_num_true) {
        re[N+1] = 1;    // run-time error
    }
    else if (all_num < all_num_true) {
        if (
            equal( sort(grps.map!(a => a[1]).array), sort(nums.values) ) &&
            !sort(grps.map!(a => cast(ulong) (a[1] * (a[1]-1))).array).array.length == sort(nums.values.map!(a => a * (a-1)).array).array.length
            //equal( sort(grps.map!(a => cast(ulong) (a[1] * (a[1]-1))).array), sort(nums.values.map!(a => a * (a-1)).array) )
        )  writeln("WA");
    }
    
    foreach (k; 0 .. N) {
        writeln( all_num_true - (nums[A[k]] - 1) );
    }
}



Measured memory_bytes: 26512
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

using namespace std;
int MOD = 1000000007;

int main(){
  char c;
  cin >> c;
  char ret = c + 1;
  cout << ret << endl;
  return 0;
}


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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll ans;
	cin >> ans;
	ll a;
	rep(i,n-1){
		cin >> a;
		ans = gcd(ans, a);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

using Graph = vector<vector<int>>;

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

    int n, x, y;
    cin >> n >> x >> y;
    --x;
    --y;

    Graph G(n);

    rep1(i, n){
        G[i-1].push_back(i);
        G[i].push_back(i-1);
    }

    G[x].push_back(y);
    G[y].push_back(x);

    vector<vector<int>> dist(n, vector<int>(n, -1));
    vector<int> res(n+10);
    rep(i, n){
        dist[i][i] = 0;

        queue<int> q;
        q.push(i);

        while(!q.empty()){
            int v = q.front();
            q.pop();

            for (int nv : G[v]) {
                if (dist[i][nv] != -1) continue;
                
                dist[i][nv] = dist[i][v] + 1;
                ++res[dist[i][nv]];
                q.push(nv);
            }

        }
    }

    // rep(i, n){
    //     rep(j, n) cout << dist[i][j];
    //     cout << endl;
    // }

    rep1(i, n){
        cout << res[i]/2 << endl;
    }



    return 0;
}

Measured memory_bytes: 16128
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
#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;
const int INF = 10000000;

int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
    int n, ans = 0;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n - 2; ++i){
        if(s.substr(i, 3) == "ABC") ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//Main(`1000 1 1000`);

function Main(input) {
  const [N, X, Y] = input.trim().split(" ").map(Number);

  const divider = parseInt(N / X, 10);

  if (N % X === 0) {
    console.log(divider * Y);
  } else {
    console.log((divider + 1) * Y);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29616
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <climits>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  ll n;
  cin >> n;
  if (n % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll m = 25;
  ll ans = 0;
  FOR(i, 1, m + 1) { ans += n / ((ll)pow(5LL, (ll)i) * 2LL); }
  cout << ans << endl;
}
//////////////////////////////////////////////


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

 int main (){

	 int p = 700;
	 char s[3];

	 for (int i = 0; i < 3; ++i) {
		 char a;
		 std::cin >> a;
		 s[i] = a;
	 }

	 for (int i = 0; i < 3; ++i) {
		 if (s[i] == 'o') {
			 p += 100;
		 }
		
	 }

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

Measured memory_bytes: 256
#!/usr/bin/perl

my ($A,$B,$M) = map { $_ - 0 } split(/\s+/,<STDIN>);

my @aa = map { $_ - 0 } split(/\s+/,<STDIN>);
my @bb = map { $_ - 0 } split(/\s+/,<STDIN>);

my @s_a = sort { $a <=> $b } @aa;
my @s_b = sort { $a <=> $b } @bb;

my $mn = $s_a[0] + $s_b[0];

for(my $i=0;$i<$M;$i++){
  my ($x,$y,$m) = map { $_ - 0 } split(/\s+/,<STDIN>);
  my $z = $aa[$x - 1] + $bb[$y - 1] - $m;
  $mn = $z if $z < $mn;
}

print "$mn\n";



Measured memory_bytes: 25688
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
  int n;
  scanf("%d",&n);
  char s[n][11];
  int ans=0;
  int a[200001]={};
  for(int i=0;i<n;i++){
    scanf("%s",s[i]);
  }
  qsort(s,n,sizeof(char)*11,strcmp);

  
  int max=0;
  char s2[n][11];
  int s2i=0;
  for(int i=0;i+1<n;i++){
    if(strcmp(s[i],s[i+1])==0){
      a[i+1]=a[i]+1;}}
  //find max
  for(int i=0;i<n;i++){
    if(a[i]>max){
      max=a[i];}}
  //find s[i] with a[i]==max
  for(int i=0;i<n;i++){
    if(a[i]==max){
      strcpy(s2[s2i],s[i]);
      s2i++;}}

  //print
  for(int i=0;i<s2i;i++){
    printf("%s\n",s2[i]);}

  return 0;
}


Measured memory_bytes: 6984
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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 int MOD = 998244353;
const ll INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;


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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	string S; cin >> S;
	COMinit();

	ll ans = 1;
	map<char, int>mp;
	mp['R'] = 0; mp['G'] = 1, mp['B'] = 2;
	vector<int>hav(3), cnt(3);
	int st = 0;
	REP(i, 3 * N) {
		int pos = mp[S[i]];
		int A = (pos + 1) % 3;
		int B = (pos + 2) % 3;

		if ((cnt[A] == 0 && cnt[B] == 0&&st==0)||(hav[pos]>0&&cnt[A]==0&&cnt[B]==0)) {
			cnt[pos]++;
			hav[pos]++;
		}
		else if (hav[A] > 0 && hav[B] > 0) {
			ans *= st;
			ans %= MOD;
			st--;
			hav[A]--, hav[B]--;
		}
		else if (cnt[A] > 0) {
			st++;
			ans *= max((ll)1,cnt[A]);
			ans %= MOD;
			cnt[A]--;
			hav[pos]++;
		}
		else if (cnt[B] > 0) {
			st++;
			ans = mult(ans, max((ll)1,cnt[B]));
			cnt[B]--;
			hav[pos]++;
		}
	}
	ans *= fac[N];
	ans %= MOD;
	if (ans < 0)return 1;
	print(ans);
}



Measured memory_bytes: 5396
#include <stdio.h>

int main(){

int coffee = 0;    
char str[6];    
scanf("%s", &str);    
    
if(str[2]==str[3] && str[4]==str[5]){
   coffee = 1;    
} else {
   coffee = 0;    
}

if(coffee == 0)
  printf("No\n");    
else
  printf("Yes\n"); 


    return 0;
}


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

struct edge {int to, cost; };
using P = pair<int , int>;
int V;
vector <edge> G[100010];
int d[100010];

void dijkstrra(int s){
    priority_queue <P, vector<P>, greater<P> > que;
    fill(d, d + V, 1000000000);
    d[s] = 0;
    que.push(P(0 , s));
    
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first)  continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
    int n;
    cin >> n;
    V = n;
    for(int i = 0; i < n; i++){
        int u, k;
        cin >> u >> k;
        int v,c;
        for(int i = 0; i < k; i++){
            cin >> v >> c;
            G[u].push_back(edge{v, c});
        }
    }
    dijkstrra(0);
    for(int i = 0; i < n; i++)
        cout << i << " " << d[i] << endl;
    return 0;
}

Measured memory_bytes: 5516
/**
  @date Time-stamp: <2019-06-09 21:02:12 tagashira>
  @file a.cpp
  @title A - Airplane
  @brief https://atcoder.jp/contests/abc129/tasks/abc129_a
**/

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  int P, Q, R;
  cin >> P >> Q >> R;

  cout << min(P+Q,min(P+R,Q+R))<< endl;

  return 0;
}


Measured memory_bytes: 256
n= int(input())
S=[]
for _ in range(n):
    S.append(input())
alpha=[[0]*26 for _ in range(n)]
#print(alpha)
for i in range(n):
    for c in S[i]:
        alpha[i][ord(c)-97]+=1
#print(alpha)
answer=''
for j in range(26):
    m=min([el[j] for el in alpha])
    answer+=chr(j+97)*m
print(answer)

Measured memory_bytes: 38768
function Main (input) {
  input = input.split("\n").map(inp => inp.split(" ").map(inp2 => parseInt(inp2, 10)));
  var A = input[0][0];
  var B = input[0][1];
  var M = input[0][2];
  var a = input[1];
  var b = input[2];
  input.shift();
  input.shift();
  input.shift();
  input.pop();
  var x = input;
  var kh = [];
  
  for (var i of x) {
    kh.unshift((a[i[0]-1]+b[i[1]-1]) - i[2]);
  }
  console.log(Math.min(...a) + Math.min(...b) < Math.min(...kh) ? Math.min(...a) + Math.min(...b) : Math.min(...kh))
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 67428
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  int A,B,C;
  long long K;
  cin>>A>>B>>C>>K;
  if(K%2){
    cout<<B-A<<endl;
  }else{
    cout<<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 <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<ll, ll> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}



int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);


	ll a, b, c, k;
	cin >> a >> b >> c >> k;

	ll ans = 0;

	ll mn = min(k, a);
	// cerr << mn << endl;
	ans += mn * 1;

	k -= mn;

	mn = min(k, b);
	// cerr << mn << endl;
	ans += mn * 0;

	k -= mn;

	mn = min(k, c);
	// cerr << mn << endl;
	ans += -1 * mn;


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

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;
  int a[N], b[N], c[N];
  for (int i = 0; i < N; i++) scanf("%d", a + i);
  for (int i = 0; i < N; i++) scanf("%d", b + i);
  for (int i = 0; i < N; i++) scanf("%d", c + i);

  sort(a, a + N);
  sort(c, c + N);

  // bの添え字iを固定して、配列aの中でb[i]より小さくなる個数、配列cの中でb[i]より大きくなる個数を数え上げていく
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll ab = (b[i] <= a[0] ? 0 : lower_bound(a, a + N, b[i]) - a);
    ll bc = (b[i] >= c[N-1] ? 0 : N - (upper_bound(c, c + N, b[i]) - c));
    ans += ab * bc;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1536
class BinomialCoefficient(object):

    def __init__(self, N=510000, MOD=10**9+7):
        self.fac = [1, 1]
        self.finv = [1, 1]
        self.inv = [0, 1]
        self.MOD = MOD
        for i in range(2, N + 1):
            self.fac.append((self.fac[-1] * i) % MOD)
            self.inv.append((-self.inv[MOD % i] * (MOD // i)) % MOD)
            self.finv.append((self.finv[-1] * self.inv[-1]) % MOD)

    def comb(self, n, r):
        if r < 0 or n < r or r < 0:
            return 0
        return self.fac[n] * self.finv[r] * self.finv[n - r] % self.MOD


N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

A.sort()
bc = BinomialCoefficient()
nCk = bc.comb(N, K)
ans = 0
for i in range(N - 1):
    c = nCk - bc.comb(i + 1, K) - bc.comb((N - i - 1), K)
    ans += c * (A[i + 1] - A[i]) % MOD
    ans %= MOD
print(ans)


Measured memory_bytes: 119148
#include <iostream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <string>
#include <vector>
#include <set>
using namespace std;

#define int long long
#define rep(n, i) for (int i = 0; i < n; i++)
#define rep2(m, n, i) for (int i = m; i < n; i++)
#define rep_r(n, i) for (int i = n - 1; i >= 0; i--)

const int INF = 1LL << 60;
const int MOD = 1e9 + 7;

int n, k;
string s;

signed main() {
    cin >> n >> k;
    cin >> s;
    /*
    if (n == 1) {
        if (s == "1" || k >= 1) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    */
    vector<int> pattern;
    pattern.push_back(0);
    rep2(1, n, i) {
        if (s[i] != s[i - 1]) {
            pattern.push_back(i);
        }
    }
    rep(2 * k + 2, i) {
        pattern.push_back(n);
    }
    vector<int> x;
    rep(pattern.size() - (2 * k + 2), i) {
        if (s[pattern[i]] == '0') {
            x.push_back(pattern[i + 2 * k] - pattern[i]);
        } else {
            x.push_back(pattern[i + 2 * k + 1] - pattern[i]);
        }
    }
    cout << *max_element(x.begin(), x.end()) << endl;
    return 0;
}

Measured memory_bytes: 3440
N = int(input())
A = list(map(int, input().split()))


# 毎回1+2+...+N個の石が取り除かれる
Sum = sum(A)
if Sum % (N * (N + 1) // 2) != 0:
    print('NO')
    exit()


# 操作回数
K = Sum // (N * (N + 1) // 2)

Diff = [A[i] - A[(i - 1)] for i in range(N)]
# 変化量-1が(N-1)箇所、+(N-1)が一か所を、すべて-1した後に、一か所+1と置き換える
Diff = [d - K for d in Diff]

for d in Diff:
    if d < 0:
        if d % N != 0:
            print('NO')
            exit()
        else:
            K -= abs(d // N)

if K == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 14260