akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace AtCoder.Problems
{
    public class ProblemA
    {
        public static void Main(string[] args)
        {
            var s = new SolveA();
            s.Solve();
        }

        public class Scanner
        {
            private string[] _s;
            private int _i;
            private readonly char[] _separators = new char[] {' '};

            public Scanner()
            {
                _s = new string[0];
                _i = 0;
            }

            public string Next()
            {
                if (_i < _s.Length) return _s[_i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();
                _s = st.Split(_separators, StringSplitOptions.RemoveEmptyEntries);
                if (_s.Length == 0) return Next();
                _i = 0;
                return _s[_i++];
            }

            public int NextInt() => int.Parse(Next());
            public long NextLong() => long.Parse(Next());
            public ulong NextULong() => ulong.Parse(Next());
            public double NextDouble() => double.Parse(Next());

            public int[] GetIntArray(int n, int add = 0)
            {
                int[] array = new int[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextInt() + add;
                }
                return array;
            }

            public long[] GetLongArray(int n, long add = 0)
            {
                long[] array = new long[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextLong() + add;
                }
                return array;
            }

            public double[] GetDoubleArray(int n, double add = 0)
            {
                double[] array = new double[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextDouble() + add;
                }
                return array;
            }
        }
    }

    public class SolveA
    {
        public void Solve()
        {
            var cin = new ProblemA.Scanner();
            var s = cin.Next();

            var result = GetAnswer(s);
            Console.WriteLine(result);
        }

        public string GetAnswer(string s)
        {
            var isNotNeed = s.All(c => c == 'A') || s.All(c => c == 'B');
            return isNotNeed ? "No" : "Yes";
        }
    }
}

Measured memory_bytes: 11220
#include<stdio.h>

int ans(int mi,int i);

int A[2000],n;


int main(void)
{
  int q,mi;
  int i,status = 0;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&mi);
    
    status = ans(mi,0);
    if(status){
      puts("yes");
    } else {
      puts("no");
    }
  }
    
  return 0;
}





int ans(int mi,int i){
  int x = 0;
  int calc = 0;
  
  if(mi == 0){
    x =  1;
  } else if(i >= n){
    x =  0;
  } else {
    i++;
    calc = (ans(mi,i) || ans(mi - A[i-1],i));
    x = calc;
  }
  
  return x;
}



Measured memory_bytes: 2108
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let H: usize = read();
    let W: usize = read();
    let mut vec: Vec<Vec<char>> = vec![];
    for _ in 0..H {
        let v: Vec<char> = read::<String>().chars().collect();
        assert_eq!(v.len(), W);
        vec.push(v);
    }
    let ans = solve(vec);
    println!("{}", ans);
}

fn solve(mut v: Vec<Vec<char>>) -> usize {
    use std::collections::VecDeque;
    let mut queue: VecDeque<(usize, usize, usize)> = VecDeque::new();
    for i in 0..v.len() {
        for j in 0..v[i].len() {
            if v[i][j] == '#' {
                queue.push_back((i, j, 0));
            }
        }
    }
    let mut max = 0;
    while let Some((i, j, count)) = queue.pop_front() {
        max = std::cmp::max(count, max);
        // 上
        if j != 0 && v[i][j - 1] == '.' {
            v[i][j - 1] = '#';
            queue.push_back((i, j - 1, count + 1));
        }
        // 下
        if j != v[0].len() - 1 && v[i][j + 1] == '.' {
            v[i][j + 1] = '#';
            queue.push_back((i, j + 1, count + 1));
        }
        // 左
        if i != 0 && v[i - 1][j] == '.' {
            v[i - 1][j] = '#';
            queue.push_back((i - 1, j, count + 1));
        }
        // 右
        if i != v.len() - 1 && v[i + 1][j] == '.' {
            v[i + 1][j] = '#';
            queue.push_back((i + 1, j, count + 1));
        }
    }
    max
}


Measured memory_bytes: 31480
import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

from collections import defaultdict
import bisect

def main():
	s=input().rstrip().decode('utf-8')
	t=input().rstrip().decode('utf-8')

	D=defaultdict(list)

	for i in range(len(s)):
		D[s[i]].append(i+1)

	now=0
	cnt=0

	for i in t:
		if D[i]==[]:
			print(-1)
			exit(0)
		else:
			idx=bisect.bisect_right(D[i],now)
			try:
				now=D[i][idx]
			except:
				now=D[i][0]
				cnt+=1
	print(cnt*len(s)+now)
















if __name__ == "__main__":
	main()


Measured memory_bytes: 8048
#include <stdio.h>

using namespace std;

class LightList
{
private:
	const static int INVALID = -1;
	int front, back, size;
	int *allocate_array;

public:
	LightList(int size) : 
		front(0), back(0), size(0)
	{
		allocate_array = new int[size];
	}
	~LightList()
	{
		delete[] allocate_array;
	}
	void insert(int x)
	{
		allocate_array[front] = x;
		front++;
		size++;
	}
	void remove(int x)
	{
		for (int i = front - 1; i >= back; i--) {
			if (allocate_array[i] == x) {
				allocate_array[i] = INVALID;
				if (i == front - 1)
					front--;
				if (i == back)
					back++;
				break;
			}
		}
	}
	void deleteFirst()
	{
		if (size > 0) {
			front--;
			size--;
		}
	}
	void deleteLast()
	{
		if (size > 0) {
			back++;
			size--;
		}
	}
	void print()
	{
		int i = front - 1;
		while (i >= back && allocate_array[i] == INVALID) i--;
		printf("%d", allocate_array[i]);
		i--;
		for (; i >= back; i--) {
			if (allocate_array[i] != INVALID)
				printf(" %d", allocate_array[i]);
		}
		putchar('\n');
	}
};

int main()
{
	int n, size = 1000020;
	scanf("%d", &n);
	if (n < 1000020) size = n;
	LightList number_list(size);
	char command[12];
	int x;

	for (int i = 0; i < n; i++) {
		scanf("%s", command);
		if (command[0] == 'i') { // insert x
			scanf("%d", &x);
			number_list.insert(x);
		}
		else { // delete???
			switch (command[6]) {
			case '\0': // delete x
				scanf("%d", &x);
				number_list.remove(x);
				break;
			case 'F': // deleteFirst
				number_list.deleteFirst();
				break;
			case 'L': // deleteLast
				number_list.deleteLast();
				break;
			}
		}
	}
	number_list.print();
	return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  static int64_t dp[3333][3333] = {};
  static constexpr int mod = 998244353;

  for (int i = c; i >= a; --i) {
    for (int j = d; j >= b; --j) {
      if (i == c && j == d) {
        dp[i][j] = 1;
      } else if (i == c) {
        dp[i][j] = dp[i][j + 1] * i % mod;
      } else if (j == d) {
        dp[i][j] = dp[i + 1][j] * j % mod;
      } else {
        dp[i][j] = i * dp[i][j + 1] + j * dp[i + 1][j] - (i * j % mod) * dp[i + 1][j + 1];
        dp[i][j] %= mod;
        if (dp[i][j] < 0) {
          dp[i][j] += mod;
        }
      }
    }
  }
  cout << dp[a][b] << endl;

  return 0;
}



Measured memory_bytes: 81748
n,m=map(int,input().split())
mod=10**9+7
m+=1
factorial = [1]
for i in range(1, m):
    factorial.append(factorial[i-1]*i%mod)

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

inverseFactorial = [0] * (m)
inverseFactorial[m-1] = power(factorial[m-1], mod-2)
for i in range(m-2, -1, -1):
    inverseFactorial[i] = inverseFactorial[i+1] * (i+1) % mod

def combi(a,b):
    return factorial[a] * inverseFactorial[b] * inverseFactorial[a-b] % mod

m-=1


sin=-1

ans=0
for i in range(n+1):
    sin*=-1
    nck=combi(n,i)
    npk=(combi(m-i,n-i)*factorial[n-i]) % mod
    tasu=(sin*nck*npk)%mod
    ans+=tasu
    ans%=mod

kake=(combi(m,n)*factorial[n]) % mod

print((ans*kake)%mod)

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

using namespace std;

int main(void) {
	int N;
	cin >> N;
	int counter = 0;
	int res = 0;
	for(int i = 1; i <= N; ++i) {
		int p;
		cin >> p;
		if(p == i) {
			++counter;
		} else {
			res += (counter + 1) / 2;
			counter = 0;
		}
	}
	res += (counter + 1) / 2;
	cout << res << '\n';
	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")
#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 <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int k; cin>>k;

    ll ans = 0;
    for(ll i=1; i<=k; i++){
        for(ll j=1; j<=k; j++){
            for(ll l=1; l<=k; l++){
                ll num = __gcd(i, j);
                num = __gcd(num, l);
                ans += num;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
//g++ -std=c++11 -Wall -O2 -o main.exe main.cpp
//g++ -std=c++14 -Wall -O2 -o main.exe main.cpp
 
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <queue>
#include <stack>
#include <tuple>
 
using namespace std;
 
#define ll long long int
#define sortasc(v, T) sort(v.begin(), v.end(), less<T>())
#define sortdesc(v, T) sort(v.begin(), v.end(), greater<T>())
 
//------
 
int N;
vector<int> A;
 
int main(){
    cin >> N;
 
    int t;
    for(int i = 0; i < N; i++){
        cin >> t;
        A.push_back(t);
    }
 
    sortasc(A, int);
 
    vector<int> less, more;
    for(int i = 0; i < N; i++){
        if(i < (N + 1) / 2){
            less.push_back(A[i]);
        }
        else{
            more.insert(more.begin(), A[i]);
        }
    }

    less.insert(less.begin(), less[less.size() - 1]);
 
    ll sum1 = 0;
    for(int i = 0; i < (N - 1); i++){
        sum1 += more[i / 2] - less[(i + 1) / 2];
    }
 
    sortdesc(A, int);
  
    less.clear(); more.clear();
    for(int i = 0; i < N; i++){
        if(i < (N + 1) / 2){
            less.push_back(A[i]);
        }
        else{
            more.insert(more.begin(), A[i]);
        }
    }
 
    less.insert(less.begin(), less[less.size() - 1]);
 
    ll sum2 = 0;
    for(int i = 0; i < (N - 1); i++){
        sum2 += less[(i + 1) / 2] - more[i / 2];
    }

//    cout << sum1 << ' ' << sum2 << endl;
    cout << max(sum1, sum2) << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
int main(){
    int n, x;
    cin >> n >> x;
    int i,j,k,total=0;
    while(n!=0||x!=0){
        for(i=1;i<n-1;i++){
            for(j=i+1;j<n;j++){
                for(k=j+1;k<n+1;k++){
                    if(x==i+j+k) total+=1;
                }
            }
        }
        cout << total << endl;
        cin >> n >> x;
        total = 0;
    }
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>
#include <queue>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;


// a,bの最小公倍数
ll lcm(ll a, ll b){ll lcm = a * b; ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return lcm /= b;}
// a,bの最大公約数
ll gcd(ll a, ll b){ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return b;}
// MOD
ll modadd(ll a, ll b){return (a%MOD+b%MOD+MOD)%MOD;}
ll modmul(ll a, ll b){return a%MOD*b%MOD%MOD;}
ll modexp(ll a, ll n){if(n==0)return 1; if(n%2==0){ll e=modexp(a,n/2); return modmul(e,e);} return modexp(a,n-1)*a%MOD;}
ll modinv(ll n){return modexp(n%MOD,MOD-2);}
ll modfact(ll n){ll res=1; for (int i=1; i <= n; ++i){res *= i; res %= MOD;} return res;}
ll modncr(ll n, ll r){ll numer=1;ll denom=1;for(int i=1;i<=r;++i){numer=modmul(numer,n-r+i);denom=modmul(denom,i);}return modmul(numer, modinv(denom));}



int main(){

    int n, m;
    cin >> n >> m;
    vector <pair<int,int>> p(m);
    rep(i,m) cin >> p[i].first >> p[i].second;

    vsort(p);

    int ans[n+1];
    rep(i,n+1) ans[i] = 0;
    if (n == 1) {
        ans[1] = 0;
    }
    else {
        ans[1] = 1;
    }

    bool exist = true;
    rep(i,m) {
        ans[p[i].first] = p[i].second;
        if (i < m-1) {
            if (p[i].first == p[i+1].first && p[i].second != p[i+1].second) {
                exist = false; 
            }
        }
    }

    if (ans[1] == 0 && 2 <= n) {
        exist = false;
    }


    if (exist) {
        bool flag = false;
        for (int i = 1; i <= n; ++i) {
            cout << ans[i];
        }
        cout << endl;
    }
    else cout << -1 << endl;



}



//              g++ -std=c++1z


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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> sticks{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    vector<int> can(m);
    for (int i = 0; i < m; i++) cin >> can[i];
    sort(can.begin(), can.end());
    reverse(can.begin(), can.end());

    vector<int> dp(n + 1);//dp[i]=i本でできる最大桁数
    for (int i = 1; i <= n; i++)dp[i] = -1145141919;
    for (int i = 1; i <= n; i++) {
        for (auto x:can) {
            if (i - sticks[x] >= 0)
                dp[i] = max(dp[i], dp[i - sticks[x]] + 1);
        }
    }

    int remain = n;
    while (remain > 0) {
        for (auto x:can) {
            if (dp[remain - sticks[x]] == dp[remain] - 1)
                if (dp[remain - sticks[x]] > 0 || remain - sticks[x] == 0) {
                    remain -= sticks[x];
                    cout << x;
                    break;
                }
        }
    }
    cout << 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 ll;

int main(){
	
	int n;
	cin >> n;
	
	
	int cnt = 0;
	rep(i,n){
		if(i+1 < 10) cnt++;
		if(99 < i+1 && i+1 < 1000) cnt++;
		if(9999 < i+1 && i+1 < 100000) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;
using edge = pair<ll,ll>;
using graph = vector<vector<edge>>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

    
void bfs(graph G, ll root, vec_b& f, vec& ans)
{
    queue<edge> Q;
    Q.push(make_pair(root, 0));
    f[root] = true;
    ans[root] = 0;
    while(!Q.empty()) {
        edge e = Q.front(); Q.pop();
        ll v = e.first;
        FORR(ne,G[v]) {
            ll nv = ne.first, w = ne.second; 
            if(!f[nv]) {
                if(w == 0) ans[nv] = ans[v] % 2;
                else ans[nv] = (ans[v] + 1) % 2;
                Q.push(ne);
                f[nv] = true;
            }
        }
    }
}


int main()
{
    ll N;
    cin >> N;
    ll u, v, w;
    graph G(N);
    REP(i,0,N-1) {
        cin >> u >> v >> w;
        --u; --v;
        w = w % 2;
        G[u].pb(make_pair(v, w));
        G[v].pb(make_pair(u, w));
    }

    vec_b F(N, false);
    vec ans(N);
    bfs(G, 0, F, ans);
    REP(i,0,N) _PR(ans[i]);


    return 0;
}

/*



*/

Measured memory_bytes: 15488
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) int64 x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(a);
    cii(b);
    auto ans = 0;
    rep1(i, 1009){
        if ((int)(i*0.08) == a && (int)(i*0.1) == b){
            ans = i;
            break;
        }
    }
    if (ans == 0) ans = -1;
    co(ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
    return *(long long*)b - *(long long*)a;
}
int main()
{   int n;
    scanf("%d",&n);
    long long a[n];
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    qsort(a,n,sizeof(long long),compare);
    long long w=0,h=0,f=0;
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]&&f==0){
            h=a[i];
            f++;
            i++;
            
        }else if(a[i]==a[i+1]){
            w=a[i];
            
        }
        if(w!=0&&h!=0)break;
    }
    printf("%lld",w*h);
    return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m, d;
  cin >> n >> m >> d;
  ll co = (n - d) * 2;
  if(d == 0) co /= 2;
  double ans = (double)co/((ll)n*n);
  ans *= (m-1);
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 3752
#include <iostream>

using namespace std;

int main()
{
    int x,a,b;
    int n1=0;
    int n2=0;
    cin>>x>>a>>b;
    if(x-a>=0)
    {
     n1=x-a;
    }else if(x-a<0)
    {
        n1=a-x;
    }
    if(x-b>=0)
    {
     n2=x-b;
    }else if(x-b<0)
    {
        n2=b-x;
    }
    if(n1>n2)
    {
        cout<<"B";
    }
    else
    {
        cout<<"A";
    }
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define ld long double
#define ll long long int
#define f(i,g,n) for(int i=g;i<=n;i++)
#define rf(i,g,n) for(int i=n;i>=g;i--)

const int N=1e3+1;

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


	int a,b;
	cin>>a>>b;
	if(a<10 && b<10)
		cout<<a*b;
	else
		cout<<"-1";

	return 0;
}

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

using namespace std;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}

template<typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vll;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define MAX(a, b) ((a)>(b)?(a):(b))
#define MIN(a, b) ((a)<(b)?(a):(b))
#define ALL(a) std::begin(a), std::end(a)
#define IN_REP int _t; cin >> _t ; while(_t--)
#define IOS ios::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)
#define MAXN 1000005
const int MOD = (int) 1e9 + 7;
int n, q, m;
ll a[MAXN];

int main() {
    IOS;
    cin >> n;
    if(n < 1200){
        cout << "ABC" << endl;
    } else if( n < 2800){
        cout << "ARC" << endl;
    } else{
        cout << "AGC" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<vector<int>> a(n,vector<int>(n));
    rep(i,n)rep(j,n) cin>>a[i][j];
    vector<ll> dp(1<<n,0);
    dp[0]=1;
    rep(S,1<<n){
      int cnt=0;
      rep(i,n) if(1<<i & S) cnt++;
      rep(i,n){
        if(!(1<<i & S) && a[cnt][i]){
          (dp[S | 1<<i]+=dp[S])%=mod;
        }
      }
    }
    //cout_vec(dp);
    cout<<dp[(1<<n)-1]<<endl;
}

Measured memory_bytes: 16640
#include<iostream>
#include<cstdlib>
#include<queue>
#include<tuple>
#include<vector>

using namespace std;

struct S{
  int t,y,x,s;
  bool operator<(S s)const{
    return t>s.t;
  }
};
  
int H,W;
char g[52][52];
int INF=1e9;

vector<int> to_pos(int py1,int px1,int ky,int kx){
  vector<int> ps(8,INF);
  queue<tuple<int,int,int> > que1;
  que1.push(make_tuple(0,py1,px1));
  bool u1[50][50]={};
  while(!que1.empty()){
    int t1,y1,x1;
    tie(t1,y1,x1)=que1.front();
    que1.pop();
    if(u1[y1][x1]++)continue;
    for(int i=0;i<8;i++){
      static int dy[]={-1,-1,0,1,2,2,1,0};
      static int dx[]={0,1,2,2,1,0,-1,-1};
      if(y1==ky+dy[i]&&x1==kx+dx[i]){
	ps[i]=t1;
      }
    }
    for(int i=0;i<4;i++){
      const static int d[]={0,1,0,-1,0};
      int ny=y1+d[i];
      int nx=x1+d[i+1];
      if(0<=ny&&ny<H&&0<=nx&&nx<W&&g[ny][nx]!='*'&&!(ky<=ny&&ny<ky+2&&kx<=nx&&nx<kx+2)){
	que1.push(make_tuple(t1+1,ny,nx));
      }
    }
  }
  return ps;
}

vector<int> move_pawns(int py1,int px1,int py2,int px2,int ky,int kx){
  auto p1=to_pos(py1,px1,ky,kx);
  auto p2=to_pos(py2,px2,ky,kx);
  vector<int> r(4);
  for(int i=0;i<4;i++){
    r[i]=min(p1[i*2]+p2[i*2+1],p1[i*2+1]+p2[i*2]);
  }
  return r;
}

int main(){
  for(;cin>>H>>W,H|W;){
    int ky,kx=-1;
    int sy1,sx1=-1,sy2,sx2;
    for(int i=0;i<H;i++){
      cin>>g[i];
      for(int j=0;j<W;j++){
	if(g[i][j]=='X'){
	  if(kx<0){
	    ky=i;
	    kx=j;
	  }
	}else if(g[i][j]=='.'){
	  if(sx1<0){
	    sy1=i;
	    sx1=j;
	  }else{
	    sy2=i;
	    sx2=j;
	  }
	}
      }
    }
    if(g[0][0]=='X'){
      cout<<0<<endl;
    }else{
      auto r=move_pawns(sy1,sx1,sy2,sx2,ky,kx);
      priority_queue<S> que;
      for(int i=0;i<4;i++){
	if(r[i]<INF){
	  que.push({r[i],ky,kx,i});
	}
      }
      bool u[50][50][4]={};
      while(!que.empty()){
	auto c=que.top();
	if(c.y==0&&c.x==0)break;
	que.pop();
	if(u[c.y][c.x][c.s]++)continue;
	const static int dy[]={-1,0,1,0};
	const static int dx[]={0,1,0,-1};
	que.push({c.t+1,c.y+dy[c.s],c.x+dx[c.s],c.s^2});
	const static int py[][2]={{-1,-1},{0,1},{2,2},{1,0}};
	const static int px[][2]={{0,1},{2,2},{1,0},{-1,-1}};
	auto r=move_pawns(c.y+py[c.s][0],c.x+px[c.s][0],c.y+py[c.s][1],c.x+px[c.s][1],c.y,c.x);
	for(int i=0;i<4;i++){
	  if(r[i]<INF){
	    que.push({c.t+r[i],c.y,c.x,i});
	  }
	}
      }
      cout<<(que.empty()?-1:que.top().t)<<endl;
    }
  }
}

Measured memory_bytes: 1272
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>

using namespace std;

string s;
string t;

int main(){
    cin >> t;
    for(int i=0;i<t.size();i++){
        if(t[i] == '?'){
            cout << "D";
        }
        else cout << t[i];
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a,b,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
map<char,ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>s;
    rep(i,Size(s))mp[s[i]]=1;
    ans=LINF;
    for(char c='a';c<='z';c++){
        if(!mp[c])continue;
        string co=s;
        while(1){
            int ok=1;
            rep(i,Size(co)){
                if(co[i]!=c)ok=0;
            }
            if(ok)break;
            string coo="";
            rep(i,Size(co)-1){
                if(co[i]==c||co[i+1]==c)coo+=c;
                else coo+=co[i];
            }
            co=coo;
            cnt++;
        }
        ans=min(ans,cnt);
        cnt=0;
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll s;
  cin>>s;
  vector<bool> judge(1000000,false);
  ll a=s;
  ll ans;
  judge[s]=true;
  for(int i=2;i<10000000;i++){
    if(a%2==0){
      a/=2;
      if(judge[a]){
        ans=i;
        break;
      }
      else{
        judge[a]=true;
      }
    }
    else{
      a=3*a+1;
      if(judge[a]){
        ans=i;
        break;
      }
      else{
        judge[a]=true;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3676
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] A = new int[N];
    int[] B = new int[N];
    int[] C = new int[N];
    String[] sA = sc.nextLine().split(" ");
    String[] sB = sc.nextLine().split(" ");
    String[] sC = sc.nextLine().split(" ");
    for(int i = 0; i < N; i++){
      A[i] = Integer.parseInt(sA[i]);
      B[i] = Integer.parseInt(sB[i]);
      C[i] = Integer.parseInt(sC[i]);
    }
    Arrays.sort(A);
    Arrays.sort(B);
    Arrays.sort(C);
    
    long ans = 0;
    for(int i = 0; i < N; i++){
      int BP = B[i];
	  int lb = 0;
	  int ub = N-1;
      long a = 0;
      if(A[0] >= BP){
        a = 0;
      }else if(A[N-1] < BP){
        a = N;
      }else{
        while(lb != ub-1){
          int cen = (lb+ub)/2;
          if(A[cen] < BP){
            lb = cen;
          }else{
            ub = cen;
          }
        }
        a = ub;
      }
      lb = 0;
	  ub = N-1;
      long c = 0;
      if(C[0] > BP){
        c = N;
      }else if(C[N-1] <= BP){
        c = 0;
      }else{
        while(lb != ub-1){
          int cen = (lb+ub)/2;
          if(C[cen] <= BP){
            lb = cen;
          }else{
            ub = cen;
          }
        }
        c = N-ub;
      }
      ans += a*c;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 71160
(defun _prison (n m lst)
  (let* ((lr (reduce #'(lambda (a b)
                         (let ((a-l (car a))
                               (a-r (cdr a))
                               (b-l (car b))
                               (b-r (cdr b)))
                           ;(print `(:e ,a-l ,a-r ,b-l ,b-r))
                           (cons
                             (max a-l b-l)
                             (min a-r b-r)))) lst :initial-value `(1 . ,n)))
         (max-l (car lr))
         (min-r (cdr lr)))
    ;(print lr)
    (if (> max-l min-r) 0
      (+ (- min-r max-l) 1))))

(defun prison (n m lst)
  (print (_prison n m lst)))

#|
(prison 4 2
         '((1 . 3) (2 . 4)))

(prison 10 2
         '((3 . 6) (5 . 7) (6 . 9)))

(prison 100000 1
         '((1 . 100000)))
|#

(let* ((n (read))
       (m (read))
       (lst (labels ((read-m (my-m rv)
                             (if (= my-m 0) (nreverse rv)
                               (let ((l (read))
                                     (r (read)))
                               (read-m (- my-m 1) (cons (cons l r) rv))))))
              (read-m m nil))))
  ;(print lst)
  (prison n m lst))


Measured memory_bytes: 59876
#include <iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;
int A[MAX];

void merge(int A[], int n, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++)L[i] = A[left + i];
	for (int i = 0; i < n2; i++)R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		cnt++;
		if (L[i] < R[j]) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
		}
	}
}

void mergeSort(int A[], int n, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int main() {
	int n, i;
	cnt = 0;

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

	mergeSort(A, n, 0, n);

	for (i = 0; i < n; i++) {
		if (i)cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 6924
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	unsigned N, C, A;
	cin >> N >> C;
	vector<vector<unsigned> > D(C, vector<unsigned>(C));
	for (unsigned i = 0; i < C; ++i) {
		for (unsigned j = 0; j < C; ++j) {
			cin >> D[i][j];
		}
	}
	vector<vector<unsigned> > distr(3, vector<unsigned>(C));
	for (unsigned i = 0; i < N; ++i) {
		for (unsigned j = 0; j < N; ++j) {
			cin >> A;
			++distr[(i + j) % 3][--A];
		}
	}
	vector<vector<unsigned> > score(3, vector<unsigned>(C));
	vector<vector<unsigned> > ranking(3, vector<unsigned>(C));
	for (unsigned i = 0; i < 3; ++i) {
		for (unsigned j = 0; j < C; ++j) {
			for (unsigned k = 0; k < C; ++k) {
				if (k != j) score[i][j] += distr[i][k] * D[k][j];
			}
			ranking[i][j] = j;
		}
		sort(ranking[i].begin(), ranking[i].end(), [&](int j, int k) { return score[i][j] < score[i][k]; });
	}
	unsigned ret = -1;
	for (unsigned i = 0; i < 3; ++i) {
		for (unsigned j = 0; j < 3; ++j) {
			for (unsigned k = 0; k < 3; ++k) {
				if (ranking[0][i] != ranking[1][j] && ranking[1][j] != ranking[2][k] && ranking[2][k] != ranking[0][i]) {
					ret = min(ret, score[0][ranking[0][i]] + score[1][ranking[1][j]] + score[2][ranking[2][k]]);
				}
			}
		}
	}
	cout << ret << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
struct E{ll to,co,ti;};
struct P{ll ti,id,re;};
bool operator <(const P &a,const P &b){return a.ti>b.ti;}
ll dp[50][5001],c[50],d[50],ans[50],n,m,s;
vector<E> edge[50];
priority_queue<P> que;

int main(){
  cin>>n>>m>>s;
  while(m--){
    ll u,v,a,b;cin>>u>>v>>a>>b;u--;v--;
    edge[u].push_back({v,a,b});
    edge[v].push_back({u,a,b});
  }
  for(ll i=0;i<n;i++)cin>>c[i]>>d[i];
  que.push({1,0,min(2500LL,s)});
  while(que.size()){
    P p=que.top();que.pop();
    if(dp[p.id][p.re])continue;
    dp[p.id][p.re]=p.ti;
    if(!ans[p.id])ans[p.id]=p.ti;
    for(E q:edge[p.id])
      if(p.re>=q.co&&!dp[q.to][p.re-q.co])
        que.push({p.ti+q.ti,q.to,p.re-q.co});
    if(p.re+c[p.id]<=2500)que.push({p.ti+d[p.id],p.id,p.re+c[p.id]});
  }
  for(ll i=1;i<n;i++)cout<<--ans[i]<<endl;
}


Measured memory_bytes: 10516
#include<stdio.h>
int main(void)
{
	int questions,answers,i,question,flag[110000],penalty=0,seikai=0,fuseikai[110000];
	char str[110000],result,trash1,trash2;
	
	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d%d",&questions,&answers);
	for(i=0;i<answers;i++)
	{
		fuseikai[i] = 0;
		flag[i] = 0;
	}
	
	for(i=0;i<answers;i++)
	{
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%d%c%c%c",&question,&trash1,&result,&trash2);
	//	printf("%c\n",result);バグチェック
		
		//WAとACで場合分け、その後その問題を解いたか否かで場合分け
		if(result == 'W')
		{
			if(flag[question-1] == 0)
			{
				fuseikai[question-1]++;
			}else
			{
				//何もしない
			}
		}else
		{
			if(flag[question-1] == 0)
			{
				seikai++;
				penalty += fuseikai[question-1]; 
				flag[question-1]++;
			}else
			{
				//何もしない
			}
		}
	}
	
	printf("%d %d",seikai,penalty);
	
	return 0;
}

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

typedef long long ll;

int main()
{
	priority_queue<ll,vector<ll>,less<ll> > q;
	int n,m;
	ll x;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		q.push(x);
	}
	while(m)
	{
		ll t=q.top()/2;
		q.pop();
		q.push(t);
		m--;
	}
	ll sum=0;
	while(!q.empty())
	{
		sum+=q.top();
		q.pop();
	}
	cout<<sum;
	return 0;
}
 

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
using namespace std;
typedef long long ll;

ll n, x, ans = 0;

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> x;
	ll a, b;
	ans += n;
	a = x, b = n - x;
	while (a && b) {
		if (a < b)
			swap (a, b);
		ans += a / b * 2 * b;
		a %= b;
	}
	ans -= b;
	cout << ans << endl;

	return 0;
}

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

typedef long long ll;
const int N=1e5+10;
int a[N],b[N];
ll sum,ans;

namespace IO {
	int read() {
		int ret=0;
		char c=getchar();
		while(!isdigit(c)) c=getchar();
		while(isdigit(c)) ret=ret*10+(c^48),c=getchar();
		return ret;
	}
	void write(ll x) {
		if(x>9)write(x/10);
		putchar(x%10^48);
	}
	void writeln(ll x) {
		write(x);
		putchar('\n');
	}
}
using namespace IO;

namespace Graph {
	int tot,ban,st,ed,odd;
	int head[N],vis[N],col[N];
	struct Tway {
		int v,nex;
	} e[N<<1];
	void add(int u,int v) {
		e[++tot]=(Tway) {
			v,head[u]
		};
		head[u]=tot;
		e[++tot]=(Tway) {
			u,head[v]
		};
		head[v]=tot;
	}
	void dfs1(int x,int f) {
		vis[x]=1;
		for(int i=head[x]; i; i=e[i].nex) {
			int v=e[i].v;
			if(v==f) continue;
			if(vis[v]) {
				ban=i;
				st=x;
				ed=v;
				if(col[st]==col[ed])odd=1;
			} else col[v]=col[x]^1,dfs1(v,x);

		}
	}
	void dfs2(int x,int f) {
		for(int i=head[x]; i; i=e[i].nex) {
			int v=e[i].v;
			if(v==f || i==ban || (i^1)==ban) continue;
			dfs2(v,x);
			a[x]+=a[v];
			b[x]+=b[v];
		}
	}
}
using namespace Graph;

namespace DreamLolita {
	int n,m,cnt,num[N];
	void failed() {
		puts("-1");
		exit(0);
	}
	void solution() {
		n=read();
		m=read();
		tot=1;
		for(int i=1; i<=m; ++i) add(read(),read());
		col[1]=1;
		dfs1(1,0);
		for(int i=1; i<=n; ++i) a[i]=col[i]?1:-1;
		for(int i=1; i<=n; ++i) sum+=a[i];
		if(m==n-1) {
			if(sum) failed();
		} else if(odd) {
			if(abs(sum)&1) failed();
			a[st]-=sum/2;
			a[ed]-=sum/2;
			ans+=abs(sum/2);
		} else {
			if(sum) failed();
			b[st]=1;
			b[ed]=-1;
		}
		dfs2(1,0);
		for(int i=1; i<=n; ++i)
			if(!b[i]) ans+=abs(a[i]);
			else num[++cnt]=-a[i]; 
		num[++cnt]=0;
		if(cnt) {
			sort(num+1,num+cnt+1);
			int mid=num[(cnt+1)>>1];
			for(int i=1; i<=cnt; ++i) ans+=abs(num[i]-mid);
		}
		writeln(ans);
	}
}

int main() {
	DreamLolita::solution();
	return 0;
}

Measured memory_bytes: 8832
#include<stdio.h>
int solve(int, int,int *,int);
int main()
{
  int i,n,q;
  int A[2000],M[2000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M[i]);
  }

  for(i=0;i<q;i++){
    if(solve(0,M[i],A,n)){
      printf("yes\n");
    }
    else printf("no\n");
  }
  return 0;
}

int solve(int i,int m,int *A,int n)
{ 
  int S=0;
  if(m==0)return 1;
  if(i>=n)return 0;
  else{
  S+=solve(i+1,m,A,n);
  S+=solve(i+1,m-A[i],A,n); 
  }
  return S;
}

  

Measured memory_bytes: 596
#include "bits/stdc++.h"
using namespace std;

int main() {
	int n, h[6] = { 0 };
	float temp;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> temp;

		if (temp < 165.0)
			h[0]++;
		else if (temp < 170.0)
			h[1]++;
		else if (temp < 175.0)
			h[2]++;
		else if (temp < 180.0)
			h[3]++;
		else if (temp < 185.0)
			h[4]++;
		else
			h[5]++;
	}

	for (int i = 0; i < 6; i++) {
		cout << i + 1 << ":";
		for (int j = 0; j < h[i]; j++)
			cout << "*";
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3052
#include<stdio.h>
#include<stdlib.h>
int main(void){
	int n;
	char *s;
	long long x = 0;
	long long r = 0;
	long long g = 0;
	long long b = 0;
	scanf("%d", &n);
	s = (char *)malloc(sizeof(char) * (n+1));
	scanf("%s", s);
	for(int i=0; i<n; i++){
		if(s[i] == 'R'){
			r++;
		}
		else if(s[i] == 'G'){
			g++;
		}
		else if(s[i] == 'B'){
			b++;
		}
	}
	x += r*g*b;
	for(int j=0; j<n-2; j++){
		for(int k=1; k<n; k++){
			if(j+k+k < n){
				if(s[j] != s[j+k] && s[j] != s[j+k+k] && s[j+k] != s[j+k+k]){
					x--;
				}
			}
		}
	}
	printf("%lld\n", x);
	return 0;
}

Measured memory_bytes: 1736
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] x2 = new int[n];
        int[] y2 = new int[m];
        int cnt = 0;
        int cnt2 = 0;
        int a  = 0;


        for(int i = 0;i<n;i++){
            x2[i] = sc.nextInt();
        }
        for(int i = 0;i<m;i++){
            y2[i] = sc.nextInt();
        }

        for(int i =x+1;i<=y;i++){
            
            for(int j =0;j<n;j++){
                if(x2[j]<i){
                    cnt++;
                }
            }
            for(int k =0;k<m;k++){
                if(y2[k]>=i){
                    cnt2++;
                }
            }

            if(cnt==n && cnt2==m){
                a = i;
                break;
            }
            cnt =0;
            cnt2=0;
        }

        //System.out.println(cnt);
      //  System.out.println(cnt2);

        if(cnt==n && cnt2==m){
            System.out.println("No War");
        }else{
            System.out.println("War");
        }
        //System.out.println(a);

    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    string s,t="KIHBR",tmp;
    cin>>s;
    int ins[]={0,3,4,5};
    for(int bit=0;bit<16;++bit){
        tmp=t;
        for(int i=3;i>=0;--i){
            if(bit>>i&1) t.insert(t.begin()+ins[i],'A');
        }
        if(s==t){
            cout<<"YES"<<endl;
            return 0;
        }
        t=tmp;
    }
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	vector<int> vec(10);
	vec[a]++;
	vec[b]++;
	vec[c]++;
	vec[d]++;
	if (vec[1] == 1 && vec[9] == 1 && vec[7] == 1 && vec[4] == 1) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

const ll INF = 1LL << 60;

int main() {
  ll n; cin >> n;
  ll res = INF;

  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ll t1 = n / i;
      ll t2 = (i - 1) + (t1 - 1);
      if (res >= t2) res = t2;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-9;

ll g(ll x) {
	return x * (x + 1) / 2;
}

ll f(ll x) {
	return g((x + 1) / 2) + g(x / 2);
}

vector< vector<ll> > matmul(vector< vector<ll> >& A, vector< vector<ll> >& B) {
	int n = A.size();
	vector< vector<ll> > C(n, vector<ll>(n));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++)
				C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
	return C;
}

vector< vector<ll> > matpow(vector< vector<ll> > A, ll x) {
	int n = A.size();
	vector< vector<ll> > B(n, vector<ll>(n));
	for (int i = 0; i < n; i++) B[i][i] = 1;
	while (x > 0) {
		if (x % 2) B = matmul(B, A);
		x /= 2;
		A = matmul(A, A);
	}
	return B;
}

int main() {
	ll K; cin >> K; K--;
	ll lb = 0, ub = 2000000000;
	while (ub - lb > 1) {
		ll mid = (lb + ub) / 2;
		if (f(mid) <= K) lb = mid;
		else ub = mid;
	}
	K -= f(lb);
	ll n = lb / 2 + 1, x, y;
	if (K < (n + 1) / 2) {
		x = K * 2;
		y = lb - x;
	}
	else {
		K -= (n + 1) / 2;
		x = (n / 2 - K) * 2 - 1;
		y = lb - x;
	}
	vector<vector<ll> > A(2, vector<ll>(2));
	A[0][1] = A[1][0] = A[1][1] = 1;
	cout << (matpow(A, x + 1)[1][1] * matpow(A, y + 1)[1][1]) % MOD << endl;
}

Measured memory_bytes: 3160
#include<stdio.h>
int main(){
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	-100 <= A, B, C <= 100;
	if (C >= A&&C <= B){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
    vector<int> v(100000000,0);
    int X;
    cin >> X;
    if (X >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 393808
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){

    
    stack<int> a;
    int b;
    while(cin>>b){
        if(b==0){
            cout<<a.top()<<endl;
            a.pop();
        }else{
            a.push(b);
        }
        
        
        
        
    }
    
    
    
    
    
    return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	int n,m;
	char sh[55][55];
	int d[9][2]={
		{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}
	};
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++)
		scanf("%s",sh[i]);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(sh[i][j]=='.')
			{
				int s=0;
				for(int k=0;k<8;k++)
				{
					int x=i+d[k][0],y=j+d[k][1];
					if(x<n&&y<m)
					{
						if(sh[x][y]=='#')s++;
					}
				}
				sh[i][j]=s+48+'\0';
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		printf("%s\n",sh[i]);
	}
	
	return 0;
}



Measured memory_bytes: 256
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}
 
int dfs(vector<vector<int>> &graph, vector<bool> &visited, int s){
    if (visited[s])
        return 0;
    int output = 1;
    visited[s] = true;
    for (int i=0;i<graph[s].size();i++){
        output += dfs(graph,visited,graph[s][i]);
    }
    return output;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    vector<vector<int>> graph(n,vector<int>(0));
    for (int i=0;i<m;i++){
        int u,v;
        cin >> u >> v;
        graph[u-1].push_back(v-1);
        graph[v-1].push_back(u-1);
    }
    vector<bool> visited(n,false);
    int ans = 0;
    for (int i=0;i<n;i++){
        if (visited[i])
            continue;
        ans = max(ans,dfs(graph,visited,i));
    }
    cout << ans << "\n";
}


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

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int h,w,g[50][50], c[4];
    int dist[50][50][4];
    while(scanf("%d%d",&w,&h), w){
        rep(i,h)rep(j,w) scanf("%d",&g[i][j]);
        rep(i,4) scanf("%d", &c[i]);
        // d, y, x, dir
        typedef tuple<int,int,int,int> State;
        rep(i,50)rep(j,50)rep(k,4) dist[i][j][k] = 1e9;
        dist[0][0][0] = 0;
        priority_queue<State> q;
        int dx[] = {1,0,-1,0};
        int dy[] = {0,1,0,-1};
        q.emplace(0,0,0,0);
        int ans = -1;
        while(q.size()){
            int d,y,x,dir;
            tie(d,y,x,dir) = q.top();
            q.pop();
            d = -d;
            //printf(" %d %d %d %d\n", d,y,x,dir);
            if(dist[y][x][dir] < d) continue;
            if(y==h-1 && x==w-1){
                ans = d;
                break;
            }
            rep(op,4){
                int nx, ny, nd, ndir;
                int cost = op == g[y][x] ? 0 : c[op];
                nd = d + cost;
                ndir = (dir+op)%4;
                nx = x+dx[ndir], ny = y+dy[ndir];
                if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
                if(dist[ny][nx][ndir] <= nd) continue;
                dist[ny][nx][ndir] = nd;
                q.emplace(-nd,ny,nx,ndir);
            }
        }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 1332