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

using namespace std;

int main()
{
	int n;
	string s;
	cin >> n >> s;
	
	vector<int> r(n), g(n), b(n);
	for (int i = 0; i < n; i++) {
		switch (s[i]) {
		case 'R':
			r[i] = 1;
			break;
		case 'G':
			g[i] = 1;
			break;
		case 'B':
			b[i] = 1;
			break;
		}
	}
	for (int i = 1; i < n; i++) {
		r[i] += r[i - 1];
		g[i] += g[i - 1];
		b[i] += b[i - 1];
	}

	long long ans = 0;
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			switch (s[i]) {
			case 'R':
				if (s[j] == 'G') {
					if (j + j - i < n && s[j + j - i] == 'B') {
						ans += b[n - 1] - b[j] - 1;
					}
					else {
						ans += b[n - 1] - b[j];
					}
				}
				else if ((s[j] == 'B')) {
					if (j + j - i < n && s[j + j - i] == 'G') {
						ans += g[n - 1] - g[j] - 1;
					}
					else {
						ans += g[n - 1] - g[j];
					}
				}
				break;
			case 'G':
				if (s[j] == 'R') {
					if (j + j - i < n && s[j + j - i] == 'B') {
						ans += b[n - 1] - b[j] - 1;
					}
					else {
						ans += b[n - 1] - b[j];
					}
				}
				else if ((s[j] == 'B')) {
					if (j + j - i < n && s[j + j - i] == 'R') {
						ans += r[n - 1] - r[j] - 1;
					}
					else {
						ans += r[n - 1] - r[j];
					}
				}
				break;
			case 'B':
				if (s[j] == 'G') {
					if (j + j - i < n && s[j + j - i] == 'R') {
						ans += r[n - 1] - r[j] - 1;
					}
					else {
						ans += r[n - 1] - r[j];
					}
				}
				else if ((s[j] == 'R')) {
					if (j + j - i < n && s[j + j - i] == 'G') {
						ans += g[n - 1] - g[j] - 1;
					}
					else {
						ans += g[n - 1] - g[j];
					}
				}
				break;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include <time.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n)
#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);

//---------------------------------------------------------------------------------------------//
ll n;
int main2(ll b) {
	int a = 0;
	while (b > 0) {
		b /= 10;
		a++;
	}
	return a;
}
int main() {
	cin >> n;
	int ans = main2(n);
	for (ll i = 2LL; i*i <= n; i++) {
		if (n%i == 0) {
			ans = min(ans, max(main2(i), main2(n / i)));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    while (in.next.head != 0) {
        var m = 0.0
        var mean = 0.0
        var n = 0
        for (d <- in.next) {
            m += (d - (d + n * mean) / (n + 1)) * (d - mean)
            mean += (d - mean) / (n + 1)
            n += 1
        }
        println(math.sqrt(m / n))
    }
}

Measured memory_bytes: 44656
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				String str=sc.nextLine();
				if(str.equals("END OF INPUT")) {
					break;
				}
				String[] t=str.split(" ");
				for(int i=0; i<t.length; i++) {
					System.out.print(t[i].length());
				}
				System.out.println();
			}
		}
	}
}


Measured memory_bytes: 26100
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	string s;
	cin >> s;
	if (s[s.size() - 1] == 's') {
		string ans = s + "es";
		cout << ans;
	}
	else {
		string ans = s + "s";
		cout << ans;
	}
}

Measured memory_bytes: 3604
def solve():
    n = int(input())
    w = list(input() for _ in range(n))
    if len(set(w)) != n:
        return "No"
    for i in range(n - 1):
        if w[i][-1] != w[i + 1][0]:
            return "No"
    return "Yes"


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>

using namespace std;

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

const ll INF = 1LL << 60;

int main()
{
  int N;
  cin >> N;
  cout << (N + 1) / 2 << endl;
}


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;

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; }
constexpr int mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  friend ostream &operator<<(ostream &os, const mint &a) { return (os << a.x); }
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  priority_queue<int> p;
  priority_queue<int> q;
  priority_queue<int> r;
  for (int i = 0; i < a; ++i) {
    int in;
    cin >> in;
    p.push(in);
  }
  for (int i = 0; i < b; ++i) {
    int in;
    cin >> in;
    q.push(in);
  }
  for (int i = 0; i < c; ++i) {
    int in;
    cin >> in;
    r.push(in);
  }

  ll num = 0;
  int na = 0;
  int nb = 0;
  int nc = 0;

  while (na + nb + nc < x + y) {
    int M = 0;
    if (p.size() > 0 && na < x) M = max(M, p.top());
    if (q.size() > 0 && nb < y) M = max(M, q.top());
    if (r.size() > 0) M = max(M, r.top());

    if (p.size() > 0 && na < x && M == p.top()) {
      num += p.top();
      p.pop();
      na++;
      continue;
    }
    if (q.size() > 0 && nb < y && M == q.top()) {
      num += q.top();
      q.pop();
      nb++;
      continue;
    }
    if (r.size() > 0 && M == r.top()) {
      num += r.top();
      r.pop();
      nc++;
      continue;
    }
  }
  cout << num << endl;
}


Measured memory_bytes: 1784
#include<vector>
#include<algorithm>
#include <iostream>
using namespace std;

int main()
{
	int n, x;
	cin >> n >> x;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
	}
	int l = 0;
	int count = 1;

	for (int i = 0; i < n; i++) {
		l += vec.at(i);
		if (l > x)
			break;
		else
			count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#import <stdio.h>
typedef long long Int;
int main() {
	Int n,a,b,c,d;
	scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&c,&d);
	for(Int i=0;i<=n;i++){
	    Int x = -(n-1-i)*d + i*c;
		Int y = -(n-1-i)*c + i*d;
		if(x <= b-a && b-a <= y){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 6224
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n, t;
  cin >> n >> t;
  ll a[n];
  REP(i, n) cin >> a[i];

  ll d = 0;

  REP(i, n - 1){
    if(a[i + 1] < a[i] + t) d += a[i] + t - a[i + 1];
  }

  cout << n * t - d << endl;
  return 0;
}


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

using namespace std;

int n;
int x[8], y[8];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx*dx + dy*dy, 0.5);
}

void solve() {
    cin >> n;
    for (int i=0; i<n; ++i)
        cin >> x[i] >> y[i];
    double sum = 0.0;
    
    for (int i=0; i<n; ++i) 
        for (int j=0; j<n; ++j)
            if (i != j) {
                sum += dist(i, j);
            }
    cout << fixed << setprecision(10) << sum/n << '\n';
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 512
n = int(input())
nums = [int(i) for i in input().split()]
box = [0] * n
for i in range(1, n + 1)[::-1]:
    c = i * 2
    ball = nums[i - 1]
    while c <= n:
        ball = ball ^ box[c - 1]
        c += i
    box[i - 1] = ball

ans = box.count(1)
print(ans)
ball = []
for i in range(n):
    if box[i] == 1:
        ball.append(i + 1)
print(*ball)


Measured memory_bytes: 77156
//1431
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;

int dec(string s){
	int ans=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='m'){
			if(i>0 && s[i-1]>='1' && s[i-1]<='9'){
				ans+=1000*(s[i-1]-'0');
			}else{
				ans+=1000;
			}
		}
		if(s[i]=='c'){
			if(i>0 && s[i-1]>='1' && s[i-1]<='9'){
				ans+=100*(s[i-1]-'0');
			}else{
				ans+=100;
			}
		}
		if(s[i]=='x'){
			if(i>0 && s[i-1]>='1' && s[i-1]<='9'){
				ans+=10*(s[i-1]-'0');
			}else{
				ans+=10;
			}
		}
		if(s[i]=='i'){
			if(i>0 && s[i-1]>='1' && s[i-1]<='9'){
				ans+=1*(s[i-1]-'0');
			}else{
				ans+=1;
			}
		}
	}
	return ans;
}
string enc(int a){
	string ret;
	if(a/1000==1) ret+='m';
	if(a/1000>1){
		ret+=('0'+a/1000);
		ret+='m';
	}
	a%=1000;
	if(a/100==1) ret+='c';
	if(a/100>1){
		ret+=('0'+a/100);
		ret+='c';
	}
	a%=100;
	if(a/10==1) ret+='x';
	if(a/10>1){
		ret+=('0'+a/10);
		ret+='x';
	}
	a%=10;
	if(a/1==1) ret+='i';
	if(a/1>1){
		ret+=('0'+a/1);
		ret+='i';
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	string a,b;
	int i;
	for(i=0;i<n;i++){
		cin >> a >> b;
		cout << enc(dec(a)+dec(b)) << endl;
	}
	
	return 0;
}
	

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

#define N_MAX 100

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

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    int a, b;
    cin >> a >> b;
    if (1 <= a && a <= 9)
    {
        if (1 <= b && b <= 9)
        {
            cout << a*b << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
	int n,x,i,cnt,max1;
	
	cin>>n;
	
	max1=0,cnt=0;
	for(i=0;i<n;i++){
			cin>>x;
			if(x==1) cnt++;
			else cnt=0;
			max1=max(max1,cnt);
	}
	cout<<max1+1<<endl;
}	


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <string>
#include <queue>

int N, M;
// std::vector<int> A, B;
int A, B;
std::vector<std::vector<int>> adj_list;
std::vector<int> sign;
std::queue<int> que;

int main() {
  std::cin >> N >> M;
  // A.assign(M, 0);
  // B.assign(M, 0);
  adj_list.assign(N, std::vector<int>());
  sign.assign(N, -1);
  for (int j = 0; j < N; j++) {
    adj_list.at(j).reserve(N);
  }

  for (int i = 0; i < M; i++) {
    std::cin >> A >> B;
    --A;
    --B;
    adj_list.at(A).push_back(B);
    adj_list.at(B).push_back(A);
  }
  que.push(0);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int nv : adj_list.at(v)) {
          if (sign.at(nv) == -1) {
            sign.at(nv) = v;
            que.push(nv);
          }
      }
  }

  std::cout << "Yes" << std::endl;
  for(int j = 1; j < N; j++) {
    std::cout << sign.at(j)+1 << std::endl;
  }
}


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

#define int long long
/**
 * RRRR LLLL
 *  i 
 *    ?????????????????????????????, ???????????????L?????. 
 * L?????
*/
void countAround(int i, int N, string s, vector<int>& v) {
    int ri = i;
    while(ri >= 0 && s[ri] == 'R') {
        if ((i - ri) % 2 == 0) v[i]++;
        else v[i + 1]++;
        ri--;
    }
    int li = i + 1;
    while(li < N && s[li] == 'L') {
        if ((li - i - 1 ) % 2 == 0) v[i + 1]++;
        else v[i]++;
        li++;
    }
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    string s;
    cin >> s;
    int N = s.length();
    vector<int> v(N, 0);
    /**
     * RRRR LLLL
     *  o o 
     *    ?????????????????????????????, ???????????????L?????. 
     * L?????
     */
    for (int i = 0; i < N - 1; i++) {
        if (s[i] == 'R' && s[i + 1] == 'L') countAround(i, N, s, v);
    }
    
    for (int i = 0; i < N; i++) {
        cout << v[i] << " ";
    }
    cout << endl;
    return 0;
}


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

using ll=long long;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<pair<string,string>> fr(1<<n);
    for(int i=0;i<(1<<n);i++){
        string yc;
        string nc;
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                yc+={s[j]};
            }
            else{
                nc+={s[j]};
            }
        }
        fr[i]=make_pair(yc,nc);
    }
    map<pair<string,string>,ll> cntbk;
    for(int i=0;i<(1<<n);i++){
        string yc;
        string nc;
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                yc+=s[j+n];
            }
            else{
                nc+=s[j+n];
            }
        }
        cntbk[make_pair(yc,nc)]++;
    }
    ll res=0;
    for(int i=0;i<fr.size();i++){
        reverse(fr[i].first.begin(),fr[i].first.end());
        reverse(fr[i].second.begin(),fr[i].second.end());
        auto idx=make_pair(fr[i].first,fr[i].second);
        if(cntbk.count(idx)){
            res+=cntbk[idx];
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 79616
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()


using namespace std;

const ll N = 1;
const ll big = 1e18;
const ll block = 800;
const ll mod = 1e6;

int main() {
	string a;
	cin >> a;
	ll s = 0, mx = 0;
	for(int i = 0; i < a.size(); i++) {
		mx = max(s, mx);
		if(a[i] == 'R')
			s++;
		else
			s = 0;
	}
	mx = max(s, mx);
	cout << mx << '\n';
}

/*

*/



Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;
int main() {
  string N;
  cin >>N;
  if(N[1]!=N[2]) cout<<"No"<<endl;
  else if(N[0]==N[1] || N[2]==N[3]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}


Measured memory_bytes: 256
/*
        FFFFFFFFFFFFFFFFFFFFFF
        F::::::::::::::::::::F
        F::::::::::::::::::::F
        FF::::::FFFFFFFFF::::F
          F:::::F       FFFFFF
          F:::::F
          F::::::FFFFFFFFFF
          F:::::::::::::::F
          F:::::::::::::::F
          F::::::FFFFFFFFFF
          F:::::F
          F:::::F
        FF:::::::FF
        F::::::::FF
        F::::::::FF
        FFFFFFFFFFF
*/
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define int long long
#define mod 1000000007
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define nl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<nl
#define cout2(a,b) cout<<a<<" "<<b<<nl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<nl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<nl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<nl
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define ms(v,n) memset((v),n,sizeof(v));
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod 
#define ad(a,b)  (a%mod+b%mod+mod)%mod
#define inf 1e18
#define cases ll T;cin>>T;while(T--)
#define BLOCK 500
//const double PI = 3.141592653589793238460;
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
 
using namespace std;

int main()
{
    
    fast

    string s;
    cin>>s;
    ll f=0;
    string a,b;
    cases{
        ll t;
        cin>>t;
        if(t==1)
        {
            if(f==0)
            f=1;
            else
            f=0;
        }
        if(t==2)
        {
            ll w;
            char c;
            cin>>w>>c;
            if((w==1 and f==0)||(w==2 and f==1))
            {
                // s=c+s;
                a=c+a;
            }
            else {
                // s=s+c;
                b+=c;
            }
        }
    }

    // reverse(all(a));
    s=a+s;
    s+=b;
    if(f==1)
    reverse(all(s));

    cout<<s<<nl;
    
    
    





    

    return 0;
    
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll h,w,ans=1,x,y,z,a[1005],b[1005];
int main(void){
    cin>>h>>w;
    for(int i=0;i<h;i++)cin>>a[i];
    for(int j=0;j<w;j++)cin>>b[j];
    sort(a,a+h,greater<ll>());
    sort(b,b+w,greater<ll>());
    ll p=h*w;
    int l=0,r=0;
    for(;p>0;p--){
        if(a[l]==p&&b[r]==p){
            if(x==h||y==w)ans=0;
            l++;
            r++;
            z+=x+y;
            x++;
            y++;
        }else if(a[l]==p){
            if(x==h)ans=0;
            l++;
            x++;
            ans=ans*y%M;
            z+=y-1;
        }else if(b[r]==p){
            if(y==w)ans=0;
            r++;
            y++;
            ans=ans*x%M;
            z+=x-1;
        }else{
            ans=ans*z%M;
            z--;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
s=str(input())
k=int(input())
n=len(s)
if s[0]!=s[-1] or k==1:
    ans=0
    a=0
    c='0'
    for i in range(n):
        if s[i]==c:
            a+=1
        else:
            c=s[i]
            ans+=-(-a//2)
            a=0
    ans+=-(-a//2)
    print(ans*k)
elif n==1:
    print(k//2)
elif len(set(s))==1:
    print(k*len(s)//2)
else:
    ans=0
    a=0
    c='0'
    for i in range(n):
        if s[i]==c:
            a+=1
        else:
            c=s[i]
            ans+=-(-a//2)
            a=0
    ans+=-(-a//2)
    ANS=0
    a=0
    c='0'
    s+=s
    for i in range(2*n):
        if s[i]==c:
            a+=1
        else:
            c=s[i]
            ANS+=-(-a//2)
            a=0
    ANS+=-(-a//2)
    print(ans+(ANS-ans)*(k-1))

Measured memory_bytes: 38384
//testing
#include <bits/stdc++.h>
using namespace std;
 
const long long int MOD = 1000000007;
 
long long int N, M, K, H, W, L, R;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> H >> W;
	vector<string>r(H);
	vector<string>c(W);
	for (int i = 0; i < H; i++) {
		cin >> r[i];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			c[j].push_back(r[i][j]);
		}
	}
	for (int i = 0; i < H; i++) {
		sort(r[i].begin(), r[i].end());
	}
	for (int i = 0; i < W; i++) {
		sort(c[i].begin(), c[i].end());
	}
 
	int rood = 0;
	vector<int>ro(13);
	for (int i = 0; i < H; i++) {
		int cnt = 0;
		for (int j = 0; j < H; j++) {
			if (r[i] == r[j]) {
				cnt++;
			}
		}
		ro[cnt]++;
	}
	int cood = 0;
	vector<int>co(13);
	for (int i = 0; i < W; i++) {
		int cnt = 0;
		for (int j = 0; j < W; j++) {
			if (c[i] == c[j]) {
				cnt++;
			}
		}
		co[cnt]++;
	}
	for (int i = 1; i <= 11; i += 2) {
		rood += ro[i] / i;
	}
	for (int i = 1; i <= 11; i += 2) {
		cood += co[i] / i;
	}
	if ((H & 1) < rood || (W & 1) < cood) {
		cout << "NO\n";
		return 0;
	}
	if ((!(H & 1) && rood) || (!(W & 1) && cood)) {
		cout << "NO\n";
		return 0;
	}
	if (H >= 7 && H < 9 && W >= 7 && W < 9 && ro[H] && co[W]) {
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	return 0;
}


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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

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



int32_t main()
{
    IOS

    ll n,w;
    cin>>n>>w;

    ll v[n],wt[n];

    for(ll i=0;i<n;i++)
    {
    	cin>>wt[i]>>v[i];
    }

    ll dp[n+1][w+1];

    for(ll i=0;i<=n;i++)
    {
    	for(ll j=0;j<=w;j++)
    	{
    		if(i==0||j==0)
    			dp[i][j]=0;

    		else if(wt[i-1]>j)
    			dp[i][j]=dp[i-1][j];

    		else
    			dp[i][j]=max(v[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
    	}
    }

    cout<<dp[n][w]<<endl;

    
    return 0;
}

Measured memory_bytes: 79104
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << 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...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
char s[N << 1], t[N];
int nxt[N << 1][26];

int main() {
  scanf("%s%s", s, t);
  int n = strlen(s), m = strlen(t);
  copy(s, s + n, s + n);
  vector<int> last(26, -1);
  for (int i = n * 2 - 1; i >= 0; --i) {
    copy(last.begin(), last.end(), nxt[i]);
    last[s[i] - 'a'] = i;
  }

  int k = 0;
  for (; k < n && s[k] != t[0]; ++k);
  if (k == n) {
    puts("-1");
    return 0;
  }
  int64 ret = k + 1;
  bool found = false;
  for (int i = 1; i < m; ++i) {
    int x = t[i] - 'a';
    int u = nxt[k][x];
    if (u < 0) {
      found = true;
      break;
    }
    // trace(k, u);
    ret += u - k;
    k = u >= n ? u - n : u;
  }
  if (found) {
    puts("-1");
  } else {
    printf("%lld\n", ret);
  }
  return 0;
}


Measured memory_bytes: 20864
#include <bits/stdc++.h>
using namespace std;
const int maxk = 1e5+5;
const int maxn = 100+5;
int A[maxn];
bool dp[maxk];
int main(int argc, char const *argv[])
{
	int n, k, x; scanf("%d%d", &n, &k);
	memset(dp, false, sizeof dp);
	for(int i = 0; i < n; i++){
		scanf("%d", &A[i]);
		dp[A[i]] = true;
	}

	for(int i = 1; i <= k; i++){
		if(!dp[i]){
			for(int j = 0; j < n; j++){
				if(i - A[j] >= 0 && !dp[i-A[j]]){
					dp[i] = true;
					break;
				}
			}
		}
	}

	if(dp[k]) printf("First\n");
	else printf("Second\n");
	return 0;
}

Measured memory_bytes: 3852
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Thu Dec  6 00:31:35 2018
//
package main

import "fmt"

var l int

type line struct {
	from   int
	weight int
}

func pow(n int) int {
	ret := 1
	for i := 0; i < n; i++ {
		ret *= 2
	}
	return ret
}

func main() {
	fmt.Scan(&l)

	var n int
	for i := 1; pow(i)-1 < l; i++ {
		n = i
	}

	maxWeights := pow(n) - 1
	var lines []line
	for i := n - 1; i >= 0; i-- {
		weight := pow(i) - 1
		newWeigts := (maxWeights + 1) + weight
		if newWeigts < l {
			lines = append(lines, line{from: i, weight: maxWeights + 1})
			maxWeights = newWeigts
		}
	}

	fmt.Println(n+1, 2*n+len(lines))
	for i := 0; i < n; i++ {
		if i+1 <= n {
			fmt.Println(i+1, i+1+1, pow(i))
			fmt.Println(i+1, i+1+1, 0)
		}
	}

	for _, line := range lines {
		fmt.Println(line.from+1, n+1, line.weight)
	}
}


Measured memory_bytes: 512
n=int(input())
p=[int(i) for i in input().split()]
ans = p[:]
ans.sort()
for i in range(n):
  for j in range(n):
    p[i],p[j]=p[j],p[i]
    if p==ans:
      print("YES")
      exit()
    p[i],p[j]=p[j],p[i]
print("NO")

Measured memory_bytes: 3060
import java.util.*;

class Main {
	public static void main(String[] arg){
		Scanner in = new Scanner(System.in);
		while(true){
			int x = in.nextInt();	
			int y = in.nextInt();
			if (x == 0 && y == 0)break;
			StringBuilder sb = new StringBuilder();
			for(int i = 0;i < x;i++){
				for(int j=0;j < y;j++){
					if( i == 0 || i == (x-1) || j == 0 || j == (y-1) ){
						sb.append("#");
					}
					else{
						sb.append(".");
					}
				}
				sb.append("\n");
			}
			System.out.println(sb);
		}	
	}
}

Measured memory_bytes: 20536
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep0(i, b, s) for(int i=b;i<s;i++)
typedef long long ll;

const int N_MAX=50;
const ll INF=1e20;
pair<int, int> point[N_MAX];
int N, K;

ll calc_S(int i, int j, int k, int l){
    ll x[4] = {point[i].first, point[j].first, point[k].first, point[l].first};
    ll y[4] = {point[i].second, point[j].second, point[k].second, point[l].second};
    ll *x_min, *x_max, *y_min, *y_max;
    x_min = min_element(x, x+4);
    x_max = max_element(x, x+4);
    y_min = min_element(y, y+4);
    y_max = max_element(y, y+4);

    int count=0;
    rep(m, N){
        if (point[m].first >= *x_min && point[m].first <= *x_max)
            if (point[m].second >= *y_min && point[m].second <= *y_max) count++;
    }

    if (count >= K) return (*x_max-*x_min) * (*y_max-*y_min);
    else return INF;
}

int main(){
    ll ans = INF;
    cin >> N >> K;

    rep(i, N){
        cin >> point[i].first >> point[i].second;
    }

    rep(i, N){
        rep(j, N){
            rep(k, N){
                rep(l, N)
                    if (ans > calc_S(i,j,k,l)) ans = calc_S(i,j,k,l);
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[100010];
int num[100010];

int main()
{
	int l,r,i,j,n;
	int x0=0,x1=0,x2=0;
	ios::sync_with_stdio(false);
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		while(a[i]%2==0&&a[i]!=0)
		{
			a[i]/=2;
			num[i]++;
		}
		if(num[i]==0) x0++;
		else if(num[i]==1) x1++;
		else x2++;
	}
	l=x0;
	if(x1>0) l++;
	r=x2;
	if(r+1>=l) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner input = new Scanner(System.in);
    
    while (input.hasNext()) {
      String s = input.next();
      String t = input.next();
      int[][] dp = new int[s.length() + 1][t.length() + 1];
      
      for (int i = 1; i < dp.length; ++i) {
        for (int j =  1; j < dp[i].length; ++j) {
          dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]);
                              
          if(s.charAt(i - 1) == t.charAt(j - 1)) {
            dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - 1] + 1);
          }
        }
      }
      
      StringBuilder LCS = new StringBuilder();
      int i = dp.length - 1;
      int j =  dp[0].length - 1;
      while (i >= 1 || j >= 1) {
        if (i >= 1 && j >= 1 && dp[i][j] == dp[i - 1][j - 1] + 1 && s.charAt(i - 1) == t.charAt(j - 1)) {
          LCS.append(s.charAt(i - 1));
          --i;
          --j;
        } else if (i >= 1 && dp[i][j] == dp[i - 1][j]) {
          --i;
        } else {
          --j;
        }
      }
                              
      System.out.println(LCS.reverse());
    }
  }
}

Measured memory_bytes: 77600
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int c = scanner.nextInt();
        String s = scanner.next();
        int[] dpLeftToRight = new int[n];
        dpLeftToRight[0] = s.charAt(0) == 'x' ? 0 : 1;
        for (int i = 1; i < s.length(); ++i) {
            if (s.charAt(i) == 'x') {
                dpLeftToRight[i] = dpLeftToRight[i - 1];
            } else {
                if (i - c - 1 >= 0) {
                    dpLeftToRight[i] = Math.max(dpLeftToRight[i - 1], dpLeftToRight[i - c - 1] + 1);
                } else {
                    dpLeftToRight[i] = Math.max(dpLeftToRight[i - 1], 1);
                }
            }
        }
        if (dpLeftToRight[n - 1] > k || dpLeftToRight[n - 1] < k) {
            return;
        }

        int[] dpRightToLeft = new int[n];
        dpRightToLeft[n - 1] = s.charAt(n - 1) == 'x' ? k + 1 : k;
        for (int i = s.length() - 2; i >= 0; --i) {
            if (s.charAt(i) == 'x') {
                dpRightToLeft[i] = dpRightToLeft[i + 1];
            } else {
                if (i + c + 1 < n) {
                    dpRightToLeft[i] = Math.min(dpRightToLeft[i + 1], dpRightToLeft[i + c + 1] - 1);
                } else {
                    dpRightToLeft[i] = Math.min(dpRightToLeft[i + 1], k);
                }
            }
       //     System.out.println("dpRightToLeft[" + i + "]: " + dpRightToLeft[i]);
        }
        int[] earliestWorkDays = new int[n + 1];
        int[] latestWorkDays = new int[n + 1];


        for (int i = 0; i < n; ++i) {
            if (earliestWorkDays[dpLeftToRight[i]] == 0) {
                earliestWorkDays[dpLeftToRight[i]] = i + 1;
            }
        }
        for (int i = n - 1; i >= 0; --i) {
            if (latestWorkDays[dpRightToLeft[i]] == 0) {
                latestWorkDays[dpRightToLeft[i]] = i + 1;
            }
        }
        for (int i = 0; i < n; ++i) {
            if (earliestWorkDays[dpLeftToRight[i]] == latestWorkDays[dpRightToLeft[i]] &&
                earliestWorkDays[dpLeftToRight[i]] == i + 1
            ) {
                System.out.println(i + 1);
            }
        }
    }
}


Measured memory_bytes: 48060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int[] arr = { A, B, A + B };
    boolean isPossible = false;

    for (int num : arr) {
      if (num >= 3 && num % 3 == 0) isPossible = true;
    }

    System.out.println(isPossible ? "Possible" : "Impossible");
  }
}


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

int main(){
    int ans=0,n;
    cin >> n;
    vector<int> a(n);
    vector<pair<bool,int>> b(n+1);
    for(int i=0;i<n+1;i++){
        b.at(i).first=false;
        b.at(i).second=0;
    }

    for(int i=0;i<n;i++){
        cin >> a.at(i);
        b.at(a.at(i)).first=true;
        if(b.at(a.at(i)-1).first==true){
            b.at(a.at(i)).second=b.at(a.at(i)-1).second+1;
        }
    }
    for(int i=1;i<n+1;i++){
        if(ans<b.at(i).second){
            ans=b.at(i).second;
        }
    }
    cout << n-ans-1 << endl;
     
}

Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int len = Integer.parseInt(sc.nextLine());
		if (len == 1) {
			System.out.println(0);
		}else {
			int[] line = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
			Arrays.sort(line);
			long min = 1000000000000000000L;
			long ans = 0;
			if (line[0] == line[len-1]) {
				System.out.println(0);
			}else {
				for (int i = line[0]; i < line[len - 1]; i++) {
					ans = 0;
					for (int j = 0; j < len; j++) {
						ans += (line[j] - i)*(line[j] - i);
					}
					if (ans < min) {
						min = ans;
					}
				}
				System.out.println(min);
			}
		}

	}
}


Measured memory_bytes: 35888
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 998244353;
constexpr int INF = 2147483647;
constexpr double PI = 3.1415926535;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N, S;
    cin >> N >> S;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    vector<vector<lint>> dp(N+1, vector<lint>(S+1));
    dp[0][0] = 1;
    dp[1][0] = 1;
    REP(i, N) {
        REP(j, S+1) {
            dp[i+1][j] = dp[i][j]*2%MOD;
            if(j-A[i] >= 0) dp[i+1][j] = (dp[i+1][j] + dp[i][j-A[i]]) % MOD;
        }
    }
    cout << dp[N][S] << endl;
}

Measured memory_bytes: 73652
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 3e3 + 1;
string  s , t , ans;
int dp[N][N];
void build(int ss , int tt , int val){
	if(ss == 0 || tt == 0) return;
	if(s[ss-1] == t[tt-1])ans += s[ss-1] , build(ss-1,tt-1,val-1);
	else if(dp[ss][tt] == dp[ss-1][tt])build(ss-1,tt,val);
	else build(ss,tt-1,val);
}
int main(){
	cin >> s >>t;
	for (int i = 0; i < s.size(); ++i){
		for (int j = 0; j < t.size(); ++j){
			if(s[i] == t[j]){
				//cout << i+1 << " " << j+1 <<endl;
				dp[i+1][j+1] = dp[i][j]+1;
			}
			else dp[i+1][j+1] = max(dp[i+1][j] , dp[i][j+1]);
		}
	}
	//cout << dp[s.size()][t.size()] <<endl;
	build(s.size(),t.size(),dp[s.size()][t.size()]);
	reverse(all(ans));
	cout << ans <<endl;




}	

Measured memory_bytes: 38772
def execute(n, tn, m, pxm):
    result = []
    for px in pxm:
        cp = tn[:]
        cp[px[0] - 1] = px[1]
        result.append(sum(cp))
    return result


if __name__ == '__main__':
    n = int(input())
    tn = list(map(int, input().split()))
    m = int(input())
    pxm = []
    for _ in range(m):
        p, x = map(int, input().split())
        pxm.append([p, x])
    result = execute(n, tn, m, pxm)
    print("\n".join(map(str, result)))


Measured memory_bytes: 3064
import java.io.{PrintWriter, _}
import java.util
import java.util._


object Main {
  def main(args: Array[String]): Unit = {
    val inputStream = System.in
    val outputStream = System.out
    val in = new InputReader(inputStream)
    val out = new PrintWriter(outputStream)
    val solver = new Task
    solver.solve(1, in, out)
    out.close()
  }

  class Task {
    def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {
      val n = in.nextInt
      val k = in.nextInt
      var res = 1
      for (_ <- 1 to n){
        if (res * 2 < res + k) res *= 2 else res += k
      }
      out.println(res)

    }
  }

  class InputReader(val stream: InputStream) extends AutoCloseable {
    //reader = new BufferedReader(new FileReader(stream), 32768);
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer = new StringTokenizer("")


    def next: String = {
      while ( {
        tokenizer == null || !tokenizer.hasMoreTokens
      }) try
        tokenizer = new StringTokenizer(reader.readLine)
      catch {
        case e: IOException =>
          throw new RuntimeException(e)
      }
      tokenizer.nextToken
    }

    def nextLine: String = {
      try
        return reader.readLine
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      ""
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    override def close(): Unit = {
    }
  }

}


Measured memory_bytes: 25544
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

/*
 * Dependencies: typedef long long ll
 * Headers: iostream
 * Verified by: ARC099-F
 *              https://beta.atcoder.jp/contests/arc099/submissions/2743855
 */

template<ll mod = (ll)1e9 + 7>
struct ModInt {
  ll x;
  ModInt(void): x(0) {}
  ModInt(ll x): x(x % mod){}
  ModInt(const ModInt &x): x(x.x) {}
  ModInt operator+(ModInt o) const {
    ll y = x + o.x;
    if (y >= mod) y -= mod;
    return ModInt(y);
  }
  ModInt operator-(ModInt o) const {
    ll y = x - o.x + mod;
    if (y >= mod) y -= mod;
    return ModInt(y);
  }
  ModInt operator*(ModInt o) const {
    return ModInt((x * o.x) % mod);
  }
  void operator+=(ModInt o) { *this = *this + o; }
  void operator-=(ModInt o) { *this = *this - o; }
  void operator*=(ModInt o) { *this = *this * o; }
  ModInt operator-(void) const { return ModInt() - *this; }
  ll to_ll() const {
    return x;
  }
  bool operator<(ModInt o) const {
    return x < o.x;
  }
  ModInt pow(ll e) {
    assert (e >= 0);
    ModInt sum = 1;
    ModInt cur = *this;
    while (e > 0) {
      if (e % 2) {
        sum = sum * cur;
      }
      cur = cur * cur;
      e /= 2;
    }
    return sum;
  }
  ModInt inv(void) {
    return pow(mod - 2);
  }
};

template<ll mod>
ostream &operator<<(ostream &os, ModInt<mod> mi) {
  return os << mi.x;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VL c(n);
  REP(i, 0, n) cin >> c[i];
  sort(c.rbegin(), c.rend());
  ModInt<> tot = 0;
  REP(i, 0, n) {
    ModInt<> tmp = 4;
    tmp = tmp.inv() * (i + 2) * c[i];
    tot += tmp;
  }
  tot *= ModInt<>(2).pow(2 * n);
  cout << tot << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int n,p;//~50
	int stone,player[50]={};
	int winner;
	int i;
	
	scanf("%d%d",&n,&p);
	while(1){
	for(i=0;i<50;i++){
		player[i]=0;
	}
	stone=p;
	for(i=0;;i++){
		if(stone==0){
			stone=player[i%n];
			player[i%n]=0;
		}
		else{
			stone-=1;
			player[i%n]+=1;
		}
		if((stone==0)&&(player[i%n]==p)){
			winner=i%n;
			break;
		}
	}
	printf("%d\n",winner);
	scanf("%d%d",&n,&p);
	if((n==0)&&(p==0)){break;}
	}
	return 0;
}

Measured memory_bytes: 1188
var a,c,ans:array[0..2050000]of longint;
    i:longint;
    n:longint;
procedure qs(l,r:longint);
var i,j,m,t:longint;
begin
  i:=l;
  j:=r;
  m:=a[(l+r)>>1];
  repeat
    while a[i]<m do inc(i);
    while a[j]>m do dec(j);
    if i<=j then
    begin
      t:=a[i];a[i]:=a[j];a[j]:=t;
      t:=c[i];c[i]:=c[j];c[j]:=t;
      inc(i);
      dec(j);
    end;
  until i>j;
  if l<j then qs(l,j);
  if i<r then qs(i,r);
end;
begin
  read(n);
  for i:=1 to n do
  begin
    read(a[i]);
    c[i]:=i;
  end;
  qs(1,n);
  for i:=1 to n do
  if i>n div 2 then ans[c[i]]:=a[n div 2] else ans[c[i]]:=a[n div 2+1];
  for i:=1 to n do
  writeln(ans[i]);
end.

Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define MOD 1e9+7
#define EPS 1e-8
#define INF 1e9+10
typedef long long ll;
using namespace std;
int main()
{
  int A,B;
  cin >> A >> B;
  if(A>=10||B>=10){
    cout << -1 << endl;
  }else{
    cout << A*B << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>

#define div 1000000000+7

typedef long long ll;

using namespace std;

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

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

using namespace std ;
using ll = long long;
constexpr int SIZE = 50;
constexpr ll inf = 1e18;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,a,b;
    cin>>n>>a>>b;
    if(!((a-b)&1)){
        cout<<"Alice\n";
    }else{
        cout<<"Borys\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No");

    return 0;
}

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

using namespace std;

#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define pf emplace_front
#define mp make_pair
#define ld long double
#define all(x) x.begin(), x.end()
#define uniq(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())

const int maxn = 1e6 + 9;
int g[maxn][26];
int dp[maxn][26];
int cnt[maxn];
string s[maxn];
int n, cnt_v;
bool used[maxn];

void add_ver()
{
    for (int j = 0; j < 26; j++)
        g[cnt_v][j] = -1;
    cnt_v++;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    add_ver();
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        reverse(all(s[i]));
        int v = 0;
        vector<int> cur;
        cur.pb(v);
        for (int e = 0; e < (int)s[i].size(); e++)
        {
            if (g[v][s[i][e] - 'a'] == -1)
            {
                g[v][s[i][e] - 'a'] = cnt_v;
                add_ver();
            }
            v = g[v][s[i][e] - 'a'];
            cur.pb(v);
        }
        cnt[v]++;
        for (int j = 0; j < 26; j++)
            used[j] = 0;
        for (int e = (int)s[i].size() - 1; e >= 0; e--)
        {
            if (!used[s[i][e] - 'a'])
            {
                dp[cur[e]][s[i][e] - 'a']++;
                used[s[i][e] - 'a'] = 1;
            }
        }
    }
    for (int v = cnt_v - 1; v >= 0; v--)
        for (int j = 0; j < 26; j++)
            for (int e = 0; e < 26; e++)
                dp[v][e] += (g[v][j] >= 0 ? dp[g[v][j]][e] : 0);
    int ans = 0;
    for (int v = 0; v < cnt_v; v++)
        for (int j = 0; j < 26; j++)
            ans += (g[v][j] >= 0 ? cnt[g[v][j]] * (dp[v][j] - cnt[g[v][j]]) : 0);
    for (int i = 0; i < cnt_v; i++)
        ans += cnt[i] * (cnt[i] - 1) / 2;
    cout << ans;
}


Measured memory_bytes: 446340
#include <iostream>
using namespace std;
int main()
{
	int n, m, l;
	long long **a, **b, **c;
	cin >> n >> m >> l;

	a = new long long*[n];
	for(int i=0; i<n; ++i)
	{
		a[i] = new long long[m];
		for(int j=0; j<m;++j)
			cin >> a[i][j];
	}

	b = new long long*[m];
	for(int i=0; i<m; ++i)
	{
		b[i] = new long long[l];
		for(int j=0; j<l;++j)
			cin >> b[i][j];
	}
		
	c = new long long*[n];
	for (int i = 0; i < n; ++i)
	{
		c[i] = new long long[l];
		for (int j = 0; j < l; ++j)
		{			
			for (int k = 0; k < m; ++k)
				c[i][j] +=a[i][k] * b[k][j];			
		}
	}

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

Measured memory_bytes: 3372
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int a,b;
	cin>>a>>b;
	if(  a < b  ){
		cout<<"a < b"<<endl;
	}
	if(  a > b  ){
		cout<<"a > b"<<endl;
	}
	if(  a == b ){
		cout<<"a == b"<<endl;
	}
}

Measured memory_bytes: 3076