akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

int main() {
    int a, b, c, r;
    std::cin >> a >> b >> c;
    std::vector<bool> v(b, false);
    r = a;
    while(true) {
        r = r % b;
        if (v[r] || !r) {
            std::cout << "NO" << std::endl;
            break;
        } else if (c % r == 0) {
            std::cout << "YES" << std::endl;
            break;
        } 
        v[r] = true;
        r += a;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;

using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;

auto R(int s, int n) {
    return boost::irange(s, n);
}
auto R(int n) {
    return boost::irange(0, n);
}
void show(const auto& v){
    for(auto i:v) cout << i << " ";
    cout << endl;
}

int main()
{
    int i;
    cin>>i;
    if(i/100==i%10){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n, m, v, p, a[N], up[N];

bool check(int id) {
	long long total = 0;
	int k = up[id], ted = max(v - id - p, 0);
	if (n - k >= p)
		return false;
	for (int i = id + 1; i <= n - p; i++)
		total += min(m, a[id] + m - a[i]);
	return 1LL * m * ted <= total;
}

void read_input() {
	cin >> n >> m >> v >> p;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

void solve() {
	sort(a, a + n);
	for (int i = 0, j = 0; i < n; up[i++] = j)
		while (j < n && a[j] <= a[i] + m)
			j++;
	int L = -1, R = n;
	while (R - L > 1) {
		int mid = L + R >> 1;
		(check(mid)? R: L) = mid;
	}
	cout << n - R;
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input(), solve();
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    ll a,b,x;
    cin>>a>>b>>x;

    ll ans = (b/x);
    if(a) ans -= (a-1LL)/x;
    else ans++; //a==0
    cout << ans << endl;
    return 0;
}

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

int main(){
    int a,count=0;
    std::cin>>a;
    std::vector<int>vec(a);
    for(int i=0;i<a;i++){
        std::cin>>vec[i];
    }
    int flag=1;
    while(flag){
        flag=0;
        for(int i=a-1;i>0;i--){
            if(vec[i-1]>vec[i]){
                std::swap(vec[i-1],vec[i]);
                flag=1;
                count++;
            }
        }
    }
    for(int i=0;i<a;i++){
        std::cout<<vec[i];
        if(i!=a-1)std::cout<<" ";
    }
    std::cout<<std::endl;
    std::cout<<count<<std::endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    vec<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

    if(K==0){
        cout << *max_element(A.begin(),A.end()) << "\n";
        return 0;
    }

    auto check = [&](ll x){
        ll cnt = 0;
        for(int i=0;i<N;i++){
            if(A[i]>x) cnt += (ll) A[i]/x;
        }
        return cnt<=K;
    };

    
    int l = 0,r = 1e9+1;   
    while(l+1<r){
        int m = (l+r)/2;
        (check(m)? r:l) = m;
    }

    cout << r << "\n";
}

Measured memory_bytes: 4712
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,ACsum=0,TLEsum=0,WAsum=0,REsum=0;
    cin >> N;
    string testcase;
    for(int i=0;i<N;i++){
        cin >> testcase;
        if(testcase=="AC")ACsum++;
        if(testcase=="TLE")TLEsum++;
        if(testcase=="WA")WAsum++;
        if(testcase=="RE")REsum++;
    }
    printf("AC x %d\n",ACsum);
    printf("WA x %d\n",WAsum);
    printf("TLE x %d\n",TLEsum);
    printf("RE x %d\n",REsum);

    return 0;
}

Measured memory_bytes: 3720
/* AUTHOR :  SHIVANK JAIN */

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false)
#define itt cin.tie(0)
#define now cout.tie(0)

using namespace std;

#define ll long long
#define li long int

#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define reprev(i,n,a) for(int i=n;i>=a;i--)
#define endl "\n"

#define vi vector<int>
#define vll vector<ll>
#define vpi vector< pair<int , int> >
#define mapi map<int , int>
#define mapll map<ll ,ll >
#define seti set<int> 

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define sort(v) sort(v.begin() , v.end())

#define BIG 1000000007
int gcd(int a, int b) 
{ // builtin function __gcd(a,b)
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
int main(){

     fast;itt;now;
 
//    #ifndef ONLINE_JUDGE
//    // for getting input from input.txt
//    freopen("input.txt", "r", stdin);
//    // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
//    #endif
    
     ll n ; cin>>n;
     vll v(n+1);
     ll sum = 0;
     rep(i,1,n+1){
     	if(i%3 == 0  and i%5 == 0){
     		v[i] = 0;
		 }
		 else{
		 	if(i%3 == 0)
		 	 v[i] = 0;
		 	else{
		 		if(i % 5 == 0)
		 		 v[i] = 0;
		 		else
				  v[i] = i , sum += i;  
			 } 
		 }
	 }
	 cout<<sum<<endl;
}

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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
#define MEM( arr, i ) memset( arr, i, sizeof (arr) )
#define Push push_back
#define Pair make_pair
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
const lli mod = 1000000007;


void precal() {

	return;
}

bool solve() {
	lli n, a, b, c, d;
	string s;
	if ( cin >> n >> a >> b >> c >> d >> s );
	else return false;
	
	bool flag = true;
	
	if ( c < d ) {
		
		for (int i = b; i < d; ++i) {
			if ( s[i] == '#' and s[ i-1 ] == '#' ) {
				flag = false;
			}
		}
		
		for (int i = a; i < c; ++i) {
			if ( s[i] == '#' and s[ i-1 ] == '#' ) {
				flag = false;
			}
		}
	}
	else if ( c > d ) {
		bool flag2 = false;
		
		for (int i = a; i < c; ++i) {
			if ( s[i] == '#' and s[ i-1 ] == '#' ) {
				flag = false;
			}
		}
		
		for (int i = b; i <= d; ++i) {
			if ( s[i] == '.' and s[ i-1 ] == '.' and s[ i-2 ] == '.' ) {
				flag2 = true;
			}
		}
		
		flag &= flag2;
	}
	
	if ( flag ) cout << "Yes\n";
	else cout << "No\n";
	
	return true;
}

int main() {
	precal();
	int t = INT_MAX;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		if ( !solve() ) break;
	}
	return 0;
}


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

int main(void){
    char tmp[1000000];
    //??°?????\????????°?????\???
    fgets(tmp,sizeof(tmp),stdin);
    int loop=atoi(tmp);
    
    //?¶??????°????????\???
    fgets(tmp,sizeof(tmp),stdin);
    int num[10001];
    //???????????????
    num[0]=atoi(strtok(tmp," "));
    //?????????????¨????????°????????????§??????num[0]???
    long sum=num[0];
    int min=num[0];
    int max=num[0];
    //??\?????°?????????
    int i;
    for(i=1;i<loop;i++){
        num[i]=atoi(strtok(NULL," "));
        //????¨??????????
        sum+=num[i];
        //?????¨????????§????????????????????°max?????\??????????°?????????????????????°min?????\??????
        if(max<num[i]){
            max=num[i];
        }else if(min>num[i]){
            min=num[i];
        }
    }
    //??\?????°???????????????
    printf("%d %d ",min,max);
    printf("%ld\n",sum);
return 0;
}

Measured memory_bytes: 616
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

s = sum(B)
for i in range(n):
    diff = min(A[i], B[i])
    A[i] -= diff
    B[i] -= diff
    diff_next = min(A[i+1], B[i])
    A[i+1] -= diff_next
    B[i] -= diff_next

print(s - sum(B))


Measured memory_bytes: 18624
#include <iostream>
using namespace std;
class Dice{
public:
    int n1,n2,n3,n4,n5,n6;

    void East(){
        int t = n1;
        n1 = n4;
        n4 = n6;
        n6 = n3;
        n3 = t;
    }
    void West(){
        int t = n1;
        n1 = n3;
        n3 = n6;
        n6 = n4;
        n4 = t;
    }
    void South(){
        int t=n1;
        n1 = n5;
        n5 = n6;
        n6 = n2;
        n2 = t;
    }
    void North(){
        int t=n1;
        n1 = n2;
        n2 = n6;
        n6 = n5;
        n5 = t;
    }
    void Rotation(){
        int t=n2;
        n2 = n3;
        n3 = n5;
        n5 = n4;
        n4 = t;
    }
};

int main(){
    Dice d[100];
    int n;

    cin>>n;
    for(int i=0; i<n; i++){
        cin>>d[i].n1>>d[i].n2>>d[i].n3>>d[i].n4>>d[i].n5>>d[i].n6;
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(j==i)continue;
            
            for(int k=0; k<6; k++){
                if(k==4){
                    d[i].East();
                }
                if(k==5){
                d[i].East();
                d[i].East();
                }
                for(int l=0; l<4; l++){
                    d[i].Rotation();
                    if(d[i].n1==d[j].n1 && d[i].n2==d[j].n2 && d[i].n3==d[j].n3 &&
                       d[i].n4==d[j].n4 && d[i].n5==d[j].n5 && d[i].n6==d[j].n6){
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
            }

        }

    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3088
/*
 *  author: chw0501
 *  created: 15.04.2020 02:24:00(UTC)
*/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//dp[i][j]: j번째 동전까지 던져서 i번의 앞면이 나올 확률
double dp[3000][3000];
int n;
double p[3000];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%lf",p+i);
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<i;j++){
			dp[j][i]+=dp[j][i-1]*(1.0-p[i]);
			dp[j+1][i]+=dp[j][i-1]*p[i];
		}
	}
	double ans=0;
	for(int i=n/2+1;i<=n;i++){
		ans+=dp[i][n];
	}
	printf("%.9lf",ans);
	return 0;
}

Measured memory_bytes: 70016
import sys

stdin = sys.stdin

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

n = ni()
h = na()

ans = 0
rep = 0
prev = 999999999999
for i in range(n-1,-1,-1):
    if h[i] >= prev:
        rep += 1
    else:
        rep = 0
    prev = h[i]
    ans = max(ans, rep)
print(ans)


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

class Amondai {
    static void Main()
    {
        var str = Console.ReadLine();
        var ans = "Christmas";
        switch (str)
        {
            case "24": ans = "Christmas Eve"; break;
            case "23": ans = "Christmas Eve Eve"; break;
            case "22": ans = "Christmas Eve Eve Eve"; break;
        }
        Console.WriteLine(ans);
    }
}

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

int n, top;
char s[200010], S[200010];

int main() {
	scanf("%s", s);
	n = strlen(s);
	S[top = 1] = s[0];
	for(int i = 1; i < n; i++) {
		if(top && S[top] == 'S' && s[i] == 'T') top--;
		else S[++top] = s[i];
	}

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


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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    if(n % 7 == 0) {
        n /= 7;
    }
    int len = 1e6 + 1;
    int val = 0;
    for(int i = 0; i < len; i++) {
        val = val * 10 + 1;
        if(val % n == 0) {
            cout << i + 1 << endl;
            return 0;
        }
        val %= n;
    }
    cout << -1 << endl;

    return 0;
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;

int main(void){
	string S; cin>>S;
	int num1,num2;
	for(int i = 0; i < S.size(); i++){
		if(S[i] == 'A'){
			num1 = i;
			break;
		}

	}
	for(int t = S.size() - 1; t >= 0; t--){
		if(S[t] == 'Z'){
			num2 = t;
		  break;
		}
	}
	cout<<num2 - num1 + 1;
}


Measured memory_bytes: 640
a, b, c, x, y = [int(i) for i in input().split()]

cost = 0
if a+b > c*2:
    min_xy = min(x,y)
    cost += c*2*min_xy
    x -= min_xy
    y -= min_xy
    
cost += c*2*x if a > c*2 else a*x
cost += c*2*y if b > c*2 else b*y

print(cost)

Measured memory_bytes: 3060
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x: x[0])

DP = [[0] * T for _ in range(N-1)]

for i in range(N-1):
	for j in range(T):
		if i == 0:
			if j >= AB[0][0]:
				DP[i][j] = AB[0][1]
		else:
			if j >= AB[i][0]:
				DP[i][j] = max(DP[i-1][j], DP[i-1][j-AB[i][0]] + AB[i][1])
			else:
				DP[i][j] = DP[i-1][j]

ans = 0
tmp = 0

for i in reversed(range(N-1)):
	tmp = max(tmp, AB[i+1][1])
	ans = max(ans, DP[i][T-1] + tmp)

print(ans)

Measured memory_bytes: 116568
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin>>N;
    string S,T;
    cin>>S;
    cin>>T;
    
    for(int i=0;i<N;i++){
        cout<<S[i]<<T[i];
    }
    cout<<endl;
}


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

using namespace std;

int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	vector<long long> A(n),B(m);
	for(int i=0;i<n;i++)
		scanf("%lld",&A[i]);
	for(int i=0;i<m;i++)
		scanf("%lld",&B[i]);
	long long sum=0; int cnt=0;
	int j=0;
	while(j<n)
	{
		if(sum+A[j]<=k)
		{
			sum+=A[j];
			j++;
			cnt++;
		}
		else
			break;
	}
	int i=0;
	while(i<m)
	{
		if(sum+B[i]<=k)
		{
			sum+=B[i];
			i++;
			cnt++;
		}
		else
			break;
	}
	int res=cnt;
	j--;
	while(j>=0)
	{
		sum-=A[j];
		j--;
		cnt--;
		while(i<m && sum+B[i]<=k)
		{
			sum+=B[i];
			i++;
			cnt++;
		}
		res=max(res,cnt);
	}
	printf("%d\n",res);
}

Measured memory_bytes: 6444
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}



int main(){
	FIO
	
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)cin >> a[i];
	int q;
	cin >> q;
	while(q--){
		int b, m, e;
		cin >> b >> m >> e;
		for(int i = 0; i < m - b; i++)swap(a[b + i], a[e + i]);
	}
	cout << a[0];
	for(int i = 1; i < n; i++)cout << ' ' << a[i];
	cout << '\n';
	return 0;
}



Measured memory_bytes: 3148
#!/usr/bin/env fsharpi

open System;

let readIntN ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int32.Parse

let readInt1 ( str : string ) =
    readIntN str |> fun arr -> arr.[0]

let readInt2 ( str : string ) =
    readIntN str |> fun arr -> (arr.[0],arr.[1])

let readInt3 ( str : string ) =
    readIntN str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let ps = readIntN <| Console.ReadLine()
let sx = ps.[0]
let sy = ps.[1]
let tx = ps.[2]
let ty = ps.[3]
let dist_x = abs <| tx - sx
let dist_y = abs <| ty - sy
let dx = if sx < tx then "R" else "L"
let idx = if sx > tx then "R" else "L"
let dy = if sy < ty then "U" else "D"
let idy = if sy > ty then "U" else "D"

[
    String.replicate dist_y dy;
    String.replicate dist_x dx;
    String.replicate dist_y idy;
    String.replicate (dist_x + 1) idx;
    String.replicate (dist_y + 1) dy;
    String.replicate (dist_x + 1) dx;
    idy;
    dx;
    String.replicate (dist_y + 1) idy;
    String.replicate (dist_x + 1) idx;
    dy;
]
|> String.concat ""
|> Console.WriteLine


Measured memory_bytes: 13268
def main_a():
    y, m, d = map(int, input().split())
    a = (y - 1) // 3
    b = (y - 1) % 3
    c = a * 590 + 195 * b 
    if y % 3:
        a = (m - 1) // 2
        b = (m - 1) % 2
        c += a * 39 + b * 20
    else:
        c += (m - 1) * 20
    c += d - 1
    print(196470 - c)
def a():
    n = int(input())
    for i in range(n):
        main_a()

def main_b():
    s = input()
    ans = []
    for i in range(1,len(s)):
        ans.append(s[:i] + s[i:])
        ans.append(s[i-1::-1] + s[i:])
        ans.append(s[i-1::-1] + s[len(s):i-1:-1])
        ans.append(s[:i] + s[len(s):i - 1:-1])
        ans.append(s[i:] + s[:i])
        ans.append(s[i:] + s[i - 1::-1])
        ans.append(s[len(s):i - 1:-1] + s[i - 1::-1])
        ans.append(s[len(s):i - 1:-1] + s[:i])
    print(len(set(ans)))

def b():
    n = int(input())
    for i in range(n):
        main_b()

def main_c(n, m):
    a = [0] * n
    s = [0] * n
    for _ in range(m):
        skc = list(map(int, input().split()))
        si = skc[0]
        c = skc[2:]
        if skc[1] == 1:
            s[c[0] - 1] += si
        for i in c:
            a[i-1] += si
    an = max(a)
    anindex = a.index(an)

    sm = 10**20
    for i in range(n):
        if i != anindex:
            if sm > s[i]:
                sm = s[i]

    flg = False
 
    for i in range(n):
        if i != anindex:
            if s[i] == 0:
                flg = True
    if flg:
        ans = an + 1
    else:
        ans = an + 1 - sm
    print(ans)


def c():
    while 1:
        n, m = map(int, input().split())
        if n == m == 0:
            return
        main_c(n,m)

c()


Measured memory_bytes: 6080
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
 //   ArrayList<Integer> list = new ArrayList<Integer>();
    int p = 0;
    long ans = 0;
    for(int i = 0; i < s.length(); i++) {
      if(s.charAt(i) == 'W') {
        ans += ((long)(i - p));
        p++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 27336
// ACM-ICPCà\I2008 C. jyjfö

#include <iostream>
#include <string>

using namespace std;

int pos;
string t;

int calc(){
	char c = t[pos++];
	if(isdigit(c)) return c - '0';
	if(c == '-')   return 2 - calc();
	int a = calc();
	char op = t[pos++];
	int b = calc();
	pos++;
	return op == '+' ? max(a,b) : min(a,b);
}

int main(){
	string s;
	while(cin >> s){
		if(s == ".") break;
		int ans = 0;
		for(int P=0;P<3;P++){
			for(int Q=0;Q<3;Q++){
				for(int R=0;R<3;R++){
					t = "";
					pos = 0;
					for(int i=0;i<s.size();i++){
						if(s[i]=='P') t += P + '0';
						else if(s[i]=='Q') t += Q + '0';
						else if(s[i]=='R') t += R + '0';
						else t += s[i];
					}
					ans += calc() == 2;
				}
			}
		}
		cout << ans << endl;
	}
}

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

using namespace std;
using ll = long long;
using P = pair<char, int>;

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i, n) {
    if (s[i] == 'R') a[i] = 0;
    if (s[i] == 'G') a[i] = 1;
    if (s[i] == 'B') a[i] = 2;
  }
  vector<ll> cnt(3);
  rep(i, n) cnt[a[i]]++;
  ll ans = 1;
  rep(i, 3) ans *= cnt[i];
  rep(j, n) rep(i, j) {
    int k = j + (j - i);
    if (k < n) {
      if (a[i] == a[j]) continue;
      if (a[i] == a[k]) continue;
      if (a[k] == a[j]) continue;
      ans--;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3604
def main():
    array = list(input())
    for i in range(len(array)):
        count = 0
        for j in range(len(array)):
            if array[i] == array[j]:
                count += 1
            continue
        if count != 2:
            print('No')
            return
    print('Yes')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
var i,n,k:integer;
    s:array[1..10] of char;
    c:char;

function ifThen(p:boolean;t,f:char):char;
begin
  if p then ifThen := t else ifThen := f
end;

begin
  readln(n);
  for i:=1 to n do read(s[i]);
  readln(k);
  c := s[k];
  for i:=1 to n do write(ifThen(s[i]=c,s[i],'*'));
  writeln
end.

Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

///////////////////////////////////////////////////////////////////////////
int a[2000005] = {};
int n;

int main(){
	cin >> n;
	rep(i,0,n)cin >> a[i];

	for(int i = n-1;i>= 0;i-= 2)cout << a[i] << " ";

	for(int i = (int)n%2;i < n;i+= 2)cout << a[i] << " ";
	cout << endl;

	return  0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename T> struct grid : public vector<vector<T>> {
    int n, m;
    grid(int n, int m) : vector<vector<T>>(n, vector<T>(m)), n(n), m(m) {}
    grid(int n, int m, T zero) : vector<vector<T>>(n, vector<T>(m, zero)), n(n), m(m) {}
    grid(const grid& a) : vector<vector<T>>(a), n(a.n), m(a.m) {}
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    grid<int> lcs(s.size() + 1, t.size() + 1);
    grid<pair<int, int>> suc(s.size(), t.size());
    for(int i = s.size() - 1; i >= 0; i--) {
        for(int j = t.size() - 1; j >= 0; j--) {
            if(s[i] == t[j]) {
                lcs[i][j] = 1 + lcs[i + 1][j + 1];
                suc[i][j] = {i + 1, j + 1};
            } else {
                lcs[i][j] = lcs[i + 1][j];
                suc[i][j] = {i + 1, j};
                if(lcs[i][j] < lcs[i][j + 1]) {
                    lcs[i][j] = lcs[i][j + 1];
                    suc[i][j] = {i, j + 1};
                }
            }
        }
    }
    int i = 0, j = 0;
    while(i != s.size() and j != t.size()) {
        if(s[i] == t[j]) {
            cout << s[i];
        }
        auto p = suc[i][j];
        i = p.first, j = p.second;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 105984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = int(1e5 + 5);

struct SegmentTree {
    int N;
    vector<ll> node;

    SegmentTree(){}
    SegmentTree(int n_){
        init(n_);
    }
    void init(int siz){
        N = 1;
        while (N < siz) N *= 2;
        node.resize(2*N-1, 0);
    }
    void update(int k, ll a) {
        k += N - 1;
        node[k] = a;
        while (k > 0) {
            k = (k-1)/2;
            node[k] = max(node[k*2+1], node[k*2+2]);
        }
    }
    ll getMax(int a, int b) {return getMax(a, b, 0, 0, N);}
    ll getMax(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)
            return 0;
        if (a <= l && r <= b)
            return node[k];
        else {
            ll vl = getMax(a, b, k*2+1, l, (l+r)/2);
            ll vr = getMax(a, b, k*2+2, (l+r)/2, r);
            return max(vl, vr);
        }
    }
};

int main() {
    ll n, a[MAX_N];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    SegmentTree rmq(n+1);
    for(int i=0;i<n;i++){
        rmq.update(a[i], rmq.getMax(0,a[i])+a[i]);
    }
    cout << n*(n+1)/2 - rmq.getMax(0,n+1) << endl;
    return 0;
}


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

#undef TEST

struct testData {
    long long N;
    long long M;
    long long a[100000];
    long long ans;
} td[] =
    {
        {
            2, 50,
            {6, 10},
            2,
        },
        {
            2, 50,
            {4, 10},
            0,
        },
        {
            1, 50,
            {6},
            8,
        },
        {
            3, 100,
            {14, 22, 40},
            0,
        },
        {
            5, 1000000000,
            {6, 6, 2, 6, 2},
            166666667,
        }
};

long long
gcd(long long x, long long y)
{
    long long r;
    while((r = x%y) != 0){
        x=y;
        y=r;
    }
    return y;
}

long long
lcm(long long x, long long y)
{
    return ((x*y)/gcd(x,y));
}

void
solver(long long n, long long m, long long *a)
{
    long long vlcm, maxa=0;
    int i;


    vlcm = a[0];
    maxa = a[0];

    for (i=1; i<n; i++) {
        if ((a[0]>>1)%2 != (a[i]>>1)%2) {
            printf("0\n");
            return;
        }

        vlcm = lcm(a[i], vlcm);
        if (maxa<a[i])  maxa=a[i];
    }

    if (vlcm/2>m) {
        printf("0\n");
        return;
    }
    for (i=0; i<n; i++) {
        if (((vlcm-a[i])/2)%a[i]!=0){
            printf("0\n");
            return;
        }
    }
//    printf("%ld %ld %ld\n", m, target, vlcm);
    printf("%lld\n", (m-vlcm/2)/vlcm+1);
}

int
main(int argc, char *argv[])
{
    long long N, M;
    long long a[100001];
    int i;

#ifdef TEST
    for (i=0; i<5; i++) {
        solver(td[i].N, td[i].M, td[i].a);
        printf("ans %lld\n", td[i].ans);
    }
#else
    scanf("%lld%lld", &N, &M);
    for (i=0; i<N; i++)
        scanf("%lld", a+i);
    
    solver(N, M, a);
#endif
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
 
#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
 
using namespace std;
 
void play(int n,int m){
    int a[105]={0} , b[105]={0};
    int aa = 0 , bb = 0;
    int q;
     
    for(int i = 0 ; i < n ; i++){
        cin >> q;
        a[q]++;
        aa+=q;
    }
     
    for(int i = 0 ; i < m ; i++){
        cin >> q;
        b[q]++;
        bb+=q;
    }
     
    for(int i = 0 ; i < 103 ; i++){
        if(a[i]){
            int dif = bb+2*i-aa;
            if(dif >=0 && dif%2==0 && dif <=200 && b[dif/2]){
                cout << i << " " << dif/2 << endl;
                return;
            }
        }
    }
     
    cout << "-1" << endl;
}
 
main(){
    //freopen("1153-input.txt","r",stdin);
    int n,m;
     
    while(cin >> n >> m){
        if(n == 0) break;
         
        play(n,m);
    }
    #ifdef GEREL
        for(;;);
    #endif
 
    return 0;
}

Measured memory_bytes: 3056
#include <stdio.h>

int main()
{
  int n;
  char s[101],t[101];
  char A[205];

  scanf("%d", &n);
  scanf("%s%s",s,t );

  for(int i=0; i<n; i++)
  {
    A[2*i] = s[i];
    A[2*i+1] = t[i];
    if(i == n-1)
    A[2*n] = '\0';
  }

  printf("%s", A);
  return 0;
}


Measured memory_bytes: 1716
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)


function main()
	n = readline() |> parseInt
	a = chomp(readline())
	b = chomp(readline())
	c = chomp(readline())
	count = 0
	for i in 1:n
		if a[i] != b[i] && b[i] != c[i] && c[i] != a[i]
			count += 2
		elseif a[i] != b[i] || b[i] != c[i] || c[i] != a[i]
			count += 1
		end
	end
	println(count)
end

main()


Measured memory_bytes: 169960
import math
n = int(input())
ans = 0

if n > 2:
  ans += n-1

for i in range(2,math.ceil(n**0.5)+1):
  if n % i == 0:
    j = n // i
    if n % (i-1) == n // (i-1):
      ans += i-1
    if i != j > 1 and n % (j-1) == n // (j-1) :
      ans += j-1
  
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define read(n) cin>>n;
#define write(n) cout<<n;
#define loop(x,n) for(int x = 0; x < n; ++x)
#define vector_loop(x,n) for(int i = 0; x < n; i++)
#define vii vector<int> a(n)
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int main()
{
	FIO;
	
	int a;
	cin >> a;
	cout << a + a*a + a*a*a;




	return 0;
}

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

int main()
{
  int n, k;
  cin >> n >> k;
  int coin = 1;

  long double ans = (1.0/n);
  long double po = 0;
  for (int i = n; i >= 1; i--) {
    while ((i * coin) < k) coin *= 2;
    po += (1.0/coin);
  }
  cout << setprecision(12) << ans * po << endl;
}


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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

llong my_gcd(llong a, llong b) {
    return (a ? my_gcd(b % a, a) : b);
}
llong my_lcm(llong a, llong b) {
    return a * b / my_gcd(a, b);    
}
llong facmod(llong n) {
    if (n == 0) return 1;
    llong res = n;
    for (int i = n - 1; i > 0; --i) {
        res = (res * i) % MOD;
    }

    return res;
}
llong powmod(llong a, llong n) {
    llong res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    }

    return res;
}
llong combmod(llong n, llong k) {
    llong res = 1;
    for (int i = 0; i < k; ++i) {
        res = (res * (n - i)) % MOD;
    } 
    res = (res * powmod(facmod(k), MOD - 2)) % MOD;

    return res;
}

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

    int n, a, b;
    cin >> n >> a >> b;
    if (n == 2) {
        cout << 0 << endl;
        return 0;
    }

    llong ans = powmod(2, n) - 1;
    ans = (ans - combmod(n, a)) % MOD;
    if (ans < 0) ans += MOD;
    ans = (ans - combmod(n, b)) % MOD;
    if (ans <  0) ans += MOD;

    cout << ans % MOD << endl;

    return 0;
}

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

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

class UnionFind {
    public:
    std::vector<ll> parent;
    std::vector<ll> sizes;
    UnionFind(ll N) : parent(N), sizes(N, 1) {
        for(ll i=0; i<N; i++) parent[i]=i;
    }
    ll find(ll x){
        if(x==parent[x]) return x;
        return parent[x]=find(parent[x]);
    }
    void unite(ll x, ll y){
        ll x_class = find(x);
        ll y_class = find(y);
        if(x_class == y_class) return;
        if(sizes[x_class] < sizes[y_class])std::swap(x_class, y_class);
        parent[y_class] = x_class;
        sizes[x_class] += sizes[y_class];
        sizes[y_class] = 0;
    }
    bool same(ll x, ll y){
        return find(x)==find(y);
    }
    ll size(ll x){
        return sizes[find(x)];
    }
};

int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    ll a,b,c,d;
    UnionFind uf(n);
    vector<ll> v(n);
    REP(i,n)v[i]=0;
    REP(i,m){
        cin>>a>>b;
        uf.unite(a-1,b-1);
        v[a-1]--; v[b-1]--;
    }
    REP(i,n)v[i]+=uf.size(i);
    REP(i,k){
        cin>>c>>d;
        if(uf.same(c-1,d-1)){v[c-1]--; v[d-1]--;}
    }
    REP(i,n)cout<<v[i]-1<<" ";
    cout<<endl;
}

Measured memory_bytes: 3200
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, A, B;
int h[100010];

bool d(int x) {
    int rest = x;
    rep(i,0,N) {
        if(A * rest + B * (x - rest) < h[i]) return false;
        int lb = -1, ub = rest;
        while(ub - lb > 1) {
            int mid = (ub + lb) / 2;
            if(A * mid + (x - mid) * B >= h[i]) ub = mid;
            else lb = mid;
        }
        if(rest - ub < 0) return false;
        rest -= ub;
    }
    return true;
}

signed main() {
    cin >> N >> A >> B;
    rep(i,0,N) cin >> h[i];
    sort(h, h+N, greater<int>());

    int lb = 0, ub = 1e10;
    while(ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if(d(mid)) ub = mid;
        else lb = mid;
    }
    cout << ub << endl;
    return 0;
}

Measured memory_bytes: 1024
/* Simplicity and Goodness */
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;


void solve()
{
    int n;
    scn(n);

    vl a(n);

    rep(i, 0, n)
    lscn(a[i]);

    map<ll, ll> pos;

    ll cnt = 0, sum = 0;

    pos[0] = 1;

    rep(i, 0, n) {
        sum += a[i];

        if(pos.count(sum)) {
            cnt += pos[sum];
        }

        pos[sum] ++;
    }

    lprin(cnt);
}

int main()
{
    int t = 1;
    // scn(t);

    while(t --) {
        solve();
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define EPS 1e-10

double dot(P a,P b){return real(conj(a)*b);}
double cross(P a,P b){return imag(conj(a)*b);}

double line2point(P a, P b, P c) {
  if ( dot(b-a, c-a) < EPS ) return abs(c-a);
  if ( dot(a-b, c-b) < EPS ) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}

double dist[5252];
P ps[5252];

int main(){
  int n,m,x,y;
  scanf("%d%d%d%d",&n,&m,&x,&y);
  ps[0]=P(x,y);
  dist[0]=-1;
  REP(i,n){
    scanf("%d%d",&x,&y);
    ps[i+1] = P(x,y);
    dist[i+1] = abs(ps[i+1]-ps[0]);
  }
  double result = 0.0;
  REP(_,m){
    int near = -1;
    REP(i,n+1){
      if(dist[i]==-1)continue;
      if(near==-1){
        near = i;
        continue;
      }
      if(dist[near]>dist[i]+EPS)near = i;
    }
    int from = 0;
    double mindst = abs(ps[near]-ps[0]);
    REPR(i,n+1){
      if(dist[i]!=-1)continue;
      double dst = abs(ps[near]-ps[i]);
      if(dst+EPS < mindst){
        mindst = dst;
        from = i;
      }
    }
    // link from & near
    result += mindst;
    dist[near] = -1;
    REP(i,n+1){
      if(dist[i]==-1)continue;
      dist[i] = min(dist[i],line2point(ps[from],ps[near],ps[i]));
    }
  }
  cout.precision(10);
  cout<<fixed<<result<<endl;
  return 0;
}

Measured memory_bytes: 1412
n = int(input())
an = list(map(int,input().split()))

anset = list(set(an))

andict = {}

for i in range(len(an)):
    if an[i] in andict:
        andict[an[i]] = andict[an[i]] + 1
    else:
        andict.update({an[i]:1})

counter = 0

for i ,j in andict.items():
    if i == j :
        None
    elif i > j:
        counter = counter + j
    elif i < j:
        counter = counter + j - i
    
        
print(counter)

Measured memory_bytes: 20460
#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>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
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;

struct node{
  int key;
  node *left, *right, *p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y; // parent
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
bool find(int k){
  node *x=root;
  while(x!=NULL){
    if(x->key==k) return true;
    if(k<x->key) x=x->left;
    else x=x->right;
  }
  return false;
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  root=NULL;
  FOR(i,0,n){
    string s;
    cin >> s;
    if(s == "insert"){
      int x; cin >> x;
      insert(node(x));
    }
    else if(s == "find"){
      int k; cin >> k;
      cout << (find(k)?"yes":"no") << endl;
    }
    else {
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
    }
  }
}


Measured memory_bytes: 21784
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);

            int result = (A - 1) * (B - 1);

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
using namespace std;
long long a[16][16];
long long dp[16][1<<16];
int main() {
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < (1 << N); i++) {
		for (int j = 0; j < N; j++) {
			if ((i >> j) & 1) {
				for (int k = 0; k < j; k++) {
					if ((i >> k) & 1) {
						dp[0][i] += a[k][j];
					}
				}
			}
		}
	}
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < (1 << N); j++) {
			for (int super = (1 << N) - 1, k = super ^ j; k; k = (k - 1) & (super - j)) {
				dp[i][j | k] = max(dp[i][j | k], dp[i - 1][j] + dp[i - 1][k]);
			}
		}
	}
	long long res = 0;
	for (int i = 0; i < N; i++) res = max(res, dp[i][(1 << N) - 1]);
	cout << res << endl;
}


Measured memory_bytes: 8448
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;

void dykstra(int s, vector<long long>& dist, vector<vector<pair<long long, long long>>>& G) {
  priority_queue<
    pair<long long, long long>,
    vector<pair<long long, long long>>,
    greater<pair<long long, long long>>
    > q;
  dist[s] = 0;
  q.push(make_pair(0LL, static_cast<long long>(s)));
  pair<long long, long long> t;
  long long cur_idx;
  long long cur_dist;
  long long next_idx;
  long long next_dist;
  while (!q.empty()) {
    t = q.top();
    q.pop();
    cur_dist = t.first;
    cur_idx = t.second;
    if (dist[cur_idx] < cur_dist) continue;
    for	(int i = 0; i < G[cur_idx].size(); ++i) {
      t = G[cur_idx][i];
      next_idx = t.first;
      next_dist = t.second;
      if (dist[next_idx] > cur_dist + next_dist) {
        dist[next_idx] = cur_dist + next_dist;
        q.push(make_pair(dist[next_idx], next_idx));
      }
    }
  }
}

void solve(long long N, long long M, std::vector<long long> L, std::vector<long long> R, std::vector<long long> C){
  vector<vector<pair<long long, long long>>> G(N, vector<pair<long long, long long>>());
  for (int i = 0; i < M; i++) {
    G[L[i]-1].emplace_back(R[i]-1, C[i]);
  }
  for (int i = 0; i < N-1; i++) {
    G[i+1].emplace_back(i, 0);
  }
  vector<long long> dist(N, numeric_limits<long long>::max());
  dykstra(0, dist, G);
  if (dist[N-1] == numeric_limits<long long>::max()) {
    cout << -1 << endl;
  } else {
    cout << dist[N-1] << endl;
  }
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> L(M);
  std::vector<long long> R(M);
  std::vector<long long> C(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&L[i]);
    scanf("%lld",&R[i]);
    scanf("%lld",&C[i]);
  }
  solve(N, M, std::move(L), std::move(R), std::move(C));
  return 0;
}


Measured memory_bytes: 11516
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
#import queue
from copy import copy, deepcopy
from operator import itemgetter

import bisect#2分探索
#bisect_left(l,x), bisect(l,x)
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#q=heapq.heapify(l),heappush(q,a),heappop(q)

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

#N = int(input())
A, B = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = quseue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入

for x in range(1,10000):
    a=int(0.08*x)
    b=int(0.1*x)
    if a==A and b==B:
        print(x)
        exit()

print(-1)

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

int main() {
  int N; cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) cin >> S.at(i);
  int ans = 0;
  for (int k = 0; k < N; k++) {
    bool ok = true;
    for (int i = 0; i < N; i++) {
      for (int j = i; j < N; j++) {
        int x1 = k+j;
        if (x1 >= N) x1 -= N;
        int x2 = k+i;
        if (x2 >= N) x2 -= N;
        if (S.at(i).at(x1) != S.at(j).at(x2)) ok = false;
      }
    }
    if (ok) ans += N;
  }
  cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<pair<pair<string, int>, int>> arr(N);
  for (int i = 0; i < N; i++) {
    string s;
    int t;
    cin >> s >> t;
    arr.at(i) = make_pair(make_pair(s,-t),i);
  }
  sort(arr.begin(), arr.end());
  for (int i = 0; i < N; i++) {
    cout << arr.at(i).second + 1 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)
	cin>>a[i];
	int dp[n];
	dp[1]=0;
	dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
	dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	cout<<dp[n];
 } 

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
int n; cin>>n;
ll c,k; cin>>c>>k;
ll t[n];
rep(i,n){
    cin>>t[i];
}
sort(t,t+n);
ll count = 0,ans = 1,time = t[0] + k;
rep(i,n){
    if(time >= t[i]){
        count++;
    }else{
        ans++;
        count = 0;
        time = t[i] + k;
    }
    if(count == c){
        ans++;
        count = 0;
        time = t[i] + k;
    }

//cout<<"time=="<<time<<" t[i]=="<<t[i]<<" count=="<<count<<endl;
}
if(c == 1) ans--;

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


Measured memory_bytes: 4172
N, M = map(int, input().split())
pena= 0
ac = [0]*(10**5)
for _ in range(M):
  tmp = input().split()
  if ac[int(tmp[0])-1] < 1:
    if tmp[1] == "AC":
      pena -= ac[int(tmp[0])-1]
      ac[int(tmp[0])-1] = 1
    else: ac[int(tmp[0])-1] -= 1 #penalty
print(ac.count(1), pena)

Measured memory_bytes: 76140
#include<stdio.h>
int main(void){
  char data[4];
  char* result="";
  int flag=0;
  scanf("%s" , data);
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      if(i==j){
      }else{
        if(data[i]==data[j]){
          flag+=1;
        }
      }
    }
  }
  
  if(flag==4){
      result="Yes";
  }else{
      result="No";
  }
  //printf("%d",flag);
  printf("%s",result);
  return 0;
}

Measured memory_bytes: 128
N,M=map(int,input().split())
#Sをすべて使うとき必要なCの数は2N
if M<2*N:
    print(M//2)
else:
    ans=N#現時点で作ったScc
    m=M-2*N#残りのc
    #Sccを１こ作るのにcは4つ必要
    ans+=m//4
    print(ans)

Measured memory_bytes: 2940