akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <numeric>//accumulate(v.begin(), v.end(), 0);
#include <algorithm>//sort(v.begin(),v.end());
#include <string>//
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

const int limit = 50;

int n, m;
int a[limit], b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v) {
        visited[v] = true;
        for (int v2 = 0; v2 < n; ++v2) {
                if (graph[v][v2] == false) continue;
                if (visited[v2] == true) continue;
                dfs(v2);

        }

}

int main(void) {
        cin >> n >> m;
        for (int i = 0; i < m; ++i) {
                cin >> a[i] >> b[i];
                a[i]--, b[i]--;
                graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;

        }

        int ans = 0;

        for (int i = 0; i < m; ++i) {
                graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

                for (int j = 0; j < n; ++j) visited[j] = false;

                dfs(0);

                bool bridge = false;
                for (int j = 0; j < n; ++j) if (visited[j] == false) bridge = true;
                if (bridge) ans += 1;
                graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
        }
        cout << ans << endl;

        return 0;
}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    create_mod_tables(N);
    if(B%2){
        cout << 0 << endl;
        return 0;
    }
    B /= 2;
    int64_t ans = 0;
    for(int a=0; a<=A; a++) for(int b=0; a+3*b<=C; b++){
        int c = A-a;
        int64_t res = perm_mod(a+b+c+B, a+b+c);
        mul(res, fact_inv[a]);
        mul(res, fact_inv[b]);
        mul(res, fact_inv[c]);
        int n3 = C - a - 3*b;
        if(B == 0 && n3) continue;
        if(B) mul(res, comb_mod(B-1+n3, n3));
        add(ans, res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
MOD = 10 ** 9 + 7
K = int(input())
M = len(input())
N = M + K

pow25 = [1] * (N + 1)
fac = [1] * (N + 1)
inv = [1] * (N + 1)
for x in range(1, N + 1):
    fac[x] = fac[x - 1] * x % MOD
    pow25[x] = pow25[x - 1] * 25 % MOD
inv[N] = pow(fac[N], MOD-2, MOD)
for x in range(N - 1, -1, -1):
    inv[x] = inv[x + 1] * (x + 1) % MOD

def binom(n, k):
    return fac[n] * inv[n - k] % MOD * inv[k] % MOD

ans = 0
for k in range(M, N + 1):
    ans += binom(N, k) * pow25[N - k] % MOD
    ans %= MOD
print(ans)

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

int main() {
	// your code goes here
	int n;cin >> n;
	int arr[n];
	int dp[n];
	for(int i = 0;i<n;i++)cin >> arr[i];
	
	dp[0] = 0;
	dp[1] = abs(arr[0]-arr[1]);
	
	for(int i = 2;i<n;i++){
		dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]) , dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    vec.at(a - 1)++;
  }
  for(int i = 0; i < n; i++) {
    cout << vec.at(i) << endl;
  }
}

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

#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()

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

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

const int MAX = 2010;
int dpL[MAX][MAX];
int dpR[MAX][MAX];
int dpU[MAX][MAX];
int dpD[MAX][MAX];

int main(){
    int H, W; cin >> H >> W;
    vector<string> grid( H );
    REP( i, H ) cin >> grid[i];

    for( int i = 0; i < H; i++ ){
        for( int j = 0; j < W; j++ ){
            if( grid[i][j] == '#' ) continue;
            dpL[i][j] = ( j ? dpL[i][j - 1] : 0 ) + 1;
            dpU[i][j] = ( i ? dpU[i - 1][j] : 0 ) + 1;
        }
    }

    for( int i = H - 1; i >= 0; i-- ){
        for( int j = W - 1; j >= 0; j-- ){
            if( grid[i][j] == '#' ) continue;
            dpR[i][j] = ( j + 1 < W ? dpR[i][j + 1] : 0 ) + 1;
            dpD[i][j] = ( i + 1 < H ? dpD[i + 1][j] : 0 ) + 1;
        }
    }

    int ans = 0;
    REP( i, H ){
        REP( j, W ){
            if( grid[i][j] == '.' ){
                chmax( ans, dpL[i][j] + dpR[i][j] + dpU[i][j] + dpD[i][j] - 3 );
            }
        }
    }

    cout << ans << endl;
}

/*

*/

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

int main() {
  int N,H,W;
  cin >> N >> H >> W;
  int sum=0;
  for(int i=0;i<N;i++){
    int a,b;
    cin >> a >> b;
    sum+=min((a/H)*(b/W),1);
  }
  cout << sum;
}


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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

#define REPISE (s,e) for(int i=s,i<e;i++)
#define REPJSE (s,e) for(int j=s,j<e;j++)

using namespace std;

int main ()
{
  int A,B,res,port;

  cin >> A >> B;
  res = 1;
  port = A;

  if (B == 1)
  {
    cout << 0 << endl;
    return 0;
  }
  
  while (port < B)
  {
    res++;
    port += A - 1;
  }
  
  cout << res << endl;


  return 0;
}

Measured memory_bytes: 3628
a,b = map(int,input().split())

def gcd(a, b):
    if a < b:
        a,b = b,a
    while (a%b)!=0:
        a,b = b,a%b
    return b

# print(gcd(a,b))

def lcm(a, b):
    return (a*b)//gcd(a, b)

print(lcm(a,b))

Measured memory_bytes: 3060
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    x, k, d = ns()
    x = abs(x)
    ans = INF
    base = 0

    if x - k * d > 0:
        ans = x - k * d
    else:
        remain_k = k - (x // d)
        base = x % d
        if remain_k % 2:
            ans = abs(base - d)
        else:
            ans = base
    print(ans)


if __name__ == '__main__':
    main()


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

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

using namespace std;
using lint=long long;

const lint INF=1LL<<61;

template<class T>
class segment_tree{
	int n;
	vector<T> dat;

	T query(int l,int r,int a,int b,int u){
		if(l<=a && b<=r) return dat[u];

		T res=INF;
		int c=(a+b)/2;
		if(l<c && a<r) res=min(res,query(l,r,a,c,2*u+1));
		if(l<b && c<r) res=min(res,query(l,r,c,b,2*u+2));
		return res;
	}

public:
	segment_tree(int N){
		for(n=1;n<N;n*=2);
		dat.assign(2*n-1,INF);
	}

	void update(int u,T v){
		u+=n-1;
		dat[u]=min(dat[u],v);
		while(u>0) u=(u-1)/2, dat[u]=min(dat[2*u+1],dat[2*u+2]);
	}

	T query(int l,int r){ return query(l,r,0,n,0); }
};

struct interval{
	int l,r;
	lint wt;
	bool operator<(const interval& I)const{ return r<I.r; }
};

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<interval> I(m);
	rep(i,m){
		scanf("%d%d%lld",&I[i].l,&I[i].r,&I[i].wt);
		I[i].l--;
	}

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

	segment_tree<lint> S(n);
	S.update(0,0);
	rep(i,m){
		lint d=S.query(I[i].l,I[i].r);
		S.update(I[i].r-1,d+I[i].wt);
	}

	lint ans=S.query(n-1,n);
	printf("%lld\n",ans<INF?ans:-1);

	return 0;
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

//最短経路（負閉路検出）Eが小さい時
void BellmanFord(Graph &G, ll s, Array &d, Array &negative) { //O(|E||V|)
    d.resize(G.size());
    negative.resize(G.size());
    REP(i, d.size())
    d[i] = INF;
    REP(i, d.size())
    negative[i] = false;
    d[s] = 0;
    REP(k, G.size() - 1) {
        REP(i, G.size()) {
            REP(j, G[i].size()) {
                if(d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {
                    d[G[i][j].to] = d[i] + G[i][j].cap;
                }
            }
        }
    }
    REP(k, G.size() - 1) {
        REP(i, G.size()) {
            REP(j, G[i].size()) {
                if(d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {
                    d[G[i][j].to] = d[i] + G[i][j].cap;
                    negative[G[i][j].to] = true;
                }
                if(negative[i] == true)
                    negative[G[i][j].to] = true;
            }
        }
    }
}

void solve() {
    ll n, m;
    cin >> n >> m;
    Graph g(n);
    REP(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        add_edge(g, a, b, -c, false, 0);
    }

    Array d, negative;
    BellmanFord(g, 0, d, negative);
    if(negative[n - 1]) {
        cout << "inf" << en;
    } else {
        cout << -d[n - 1] << en;
    }
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3792
L, R = map(int, input().split())
min = 2019

if R -L >= 2019:
	min = 0
else:

	for i in range(L, R+1):
		for j in range(i+1, R+1):
			num = i * j % 2019
			if j > i and num < min:
				min = num

print(min)

Measured memory_bytes: 3316
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  int n;
  cin >> n;
  if (n > 81) {
    cout << "No" << endl;
    return 0;
  }
  for (int i=1; i<=9; i++){
    if (n%i == 0 && n/i < 10) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3100
N, K = map(int, input().split())
S = list(input())
left = 0
right = 0
onecnt = 0
zerocnt = 0
zeroflag = False
leftflag = False
ans = 0

while right < N:
    if S[right] == '0' and not zeroflag:
        zerocnt += 1
        zeroflag = True
    elif S[right] == '1' and zeroflag:
        zeroflag = False
        
    if zerocnt > K and zeroflag:
        tmp = right - left
        if tmp > ans:
            ans = tmp
        while True:
            if S[left] == '0' and not leftflag:
                leftflag = True
            elif S[left] == '1' and leftflag:
                leftflag = False
                break
            left += 1
        zerocnt -= 1
    right += 1

if right - left > ans:
    ans = right - left

print(ans)

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

#define eb emplace_back
#define pb push_back
#define INF LLONG_MAX
#define FLT_INF pow(10.0, 16)


using ll = long long;
using vll = vector<ll>;
using ull = unsigned long long;
using int2 = pair<ll, ll>;
using int3 = tuple<ll, ll, ll>;

template <typename A> string to_string(const A& v);
string to_string(const string& s) { return '"'+ s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B> string to_string(const pair<A, B>& p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C> string to_string(const tuple<A, B, C>& p) {
  return "(" + to_string(std::get<0>(p)) + ", " + to_string(std::get<1>(p)) +  ", " + to_string(std::get<2>(p)) + ")";
}

template <typename A> string to_string(const A& v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename T>
void sort(vector<T>& val) {
  sort(val.begin(), val.end());
}

template <typename T>
void reverse(vector<T>& val) {
  reverse(val.begin(), val.end());
}

template <typename T>
void sort_b(vector<T>& val) {
  sort(val.begin(), val.end(), greater<T>());
}

template <typename T>
T pair_sum(pair<T, T>& val) {
  return val.first + val.second;
}


template <typename T>
T min(T a, T b, T c) {
  return min(min(a, b), c);
}

template <typename T>
T max(T a, T b, T c) {
  return max(max(a, b), c);
}


template <typename T>
T mul_mod(T a, T b, T mod) {
  T res = 0;
  a %= mod;
  while (b) {
    if (b & 1) {
      res = (res + a) % mod;
    }
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...);
#endif

#define COMMON_MOD pow(10, 9) + 7
#define PI 3.14159265

// sort(a.begin(), a.end(), less<ll>()); greater<ll>()
// cout<<fixed<<setprecision(20)<<(s/kl)*2;
/* printf("%lld %lld \n", cur_n, m / 2 + 1);
*/

class mytask {
public:

  mytask() { }



  int solve() {


    ll n;

    cin >> n;
    ll a_min = n+1;
    ll min_count = 0;
    for (ll i = 0; i < n; i++) {
      ll a;
      cin >> a;
      if (a < a_min) {
        min_count++;
        a_min = a;
      }
    }
    cout << min_count;

    return 0;
  }

};


int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  auto task = mytask();
  task.solve();

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
#define MOD 1000000007
#define MAX_V 100010
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}

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

ll junnretu(ll n){
    ll ans=1;
    for (ll i=1;i<=n;i++){
        ans*=i;
    }
    return ans;
}

map<ll,ll> prime_factor(ll n){
    map<ll,ll> mp;
    for(ll i=2; i*i<=n; i++){
        while(n % i == 0){
            mp[i]++;
            n /= i;
        }
    }
    if(n != 1) mp[n] = 1;
    return mp;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n;
    cin >> n;
    pair<pair<string,ll>,int> x[110];
    for (ll i=0;i<n;i++){
        ll p;
        string s;
        cin >> s >> p;
        auto z=make_pair(s,-p);
        x[i]=make_pair(z,i+1);
    }
    sort(x,x+n);
    for (ll i=0;i<n;i++){
        cout << x[i].second << endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
#include <cmath>

using namespace std;

char arr[100010];

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, i;
    scanf("%s", arr + 1);
    n = strlen(arr + 1);

    if(arr[1] == '0' || arr[n - 1] == '0' || arr[n] == '1')
    {
        puts("-1");
        return 0;
    }

    for(i = 1; i < n - i; i++)
    {
        if(arr[i] != arr[n - i])
        {
            puts("-1");
            return 0;
        }
    }

    if(n == 2)
    {
        puts("1 2");
        return 0;
    }

    int p = 3, pp = 1, c = 4;
    vector<pair<int, int>> res;
    res.push_back({ 1, 2 });
    res.push_back({ 1, 3 });
    int x = 1;
    for(i = 2; i <= n / 2; i++)
    {
        if(arr[i] == '1')
        {
            res.push_back({ p, c });
            x = p;
            pp = p;
            p = c;
            c++;
        }
        else
        {
            res.push_back({ pp, c });
            x = pp;
            p = c;
            c++;
        }
    }

    assert(c <= n + 1);
    while(c <= n)
    {
        res.push_back({ x, c });
        c++;
    }

    for(auto e : res)
        printf("%d %d\n", e.first, e.second);
    return 0;
}

Measured memory_bytes: 2420
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long N = lread();
    auto F = new uint[](N);
    auto P = new long[10][](N);
    foreach (i; 0 .. N)
    {
        auto a = aryread();
        foreach (j; 0 .. 10)
            F[i] |= a[j] << j;
    }
    foreach (i; 0 .. N)
        P[i][] = aryread()[0 .. 10];

    long ans = long.min;
    foreach (x; 1 .. (1 << 10))
    {
        long sum;
        foreach (i, f; F)
        {
            sum += P[i][popcnt(x & f)];
        }
        ans = ans.max(sum);
    }
    // foreach (f; F)
    //     writefln("%011b", f);
    // writeln(P);
    writeln(ans);
}


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

using namespace std;

int func(int n){
    if(n%2 == 1){
        return 3*n+1;
    }else{
        return n/2;
    }
}

int main(void){
    map<int,int> mp;
    int s;
    cin >> s;
    mp[s]++;
    int a;
    int b = s;
    int i=2;
    while(true){
        a = func(b);
        if(mp[a] == 0){
            mp[a]++;
        }else{
            cout << i << endl;
            return 0;
        }
        b = a;
        i++;
    }

    return 0;
}

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

using namespace std;


void solve(long long N, long long M, std::vector<long long> A){
  long long total = 0;
  long long pop = 0;
  for (int i = 0; i < N; i++) {
    total += A[i];
  }

  for (int i = 0; i < N; i++) {
    if (4 * M * A[i] >= total) pop++;
  }

  if (pop >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
multiset<ll,greater<ll>> st[200000];
multiset<ll> ss;
ll N,K,M;
ll A[80][20];
ll B[80];

int main() {
    cin >> N;
    M = 1000;
    for(int i=0;i<N;i++){
        cin >> B[i];
    }
    for(int i=0;i<N-1;i++){
        if(B[i]<B[i+1]){
            K += M / B[i];
            M %= B[i];
        }
        if(B[i]>B[i+1]){
            M += K*B[i];
            K = 0;
        }
    }
    cout << M + K*B[N-1] << endl;
}


Measured memory_bytes: 13012
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int h,w,n;
    cin >> h >> w >> n;
    
    int temp=0;
    int answer = 0;
    while(temp < n){
        temp+=max(h,w);
        answer++;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

#define def 0
template<class V, int NV> struct SegTree { //[l,r)
    V comp(V& l, V& r) { return max(l, r); };
 
    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1) {
        if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2); 
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v) {
        i += NV; val[i] = v;
        while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};

int main() {
    int n;
    cin >> n;
    vector<int> h(n), a(n);
    SegTree<ll, 1<<18> dp;
    rep(i, n) cin >> h[i];
    rep(i, n) cin >> a[i];

    rep(i, n) {
        ll opt = dp.get(0, h[i]) + a[i];
        dp.update(h[i], max(dp[h[i]], opt));
    }
    cout << dp.get(0, 1<<18) << endl;
}

Measured memory_bytes: 5888
#include <stdio.h>

int main(void)
{
 int n,i,a=1,b=1,c=1;

 scanf("%d",&n);

 for(i=0;i<n-1;i++){
  a=b+c;
  c=b;
  b=a;
 }

 printf("%d\n",a);

 return 0;
}

Measured memory_bytes: 1852
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int N; cin >> N;
    Int cnt[10][10] = {};
    Int ans = 0;
    for (int i = 1; i <= N; i++) {
        int a = i % 10;
        int b = i;
        while (b >= 10) b /= 10;
        cnt[a][b]++;
    }
    for (int a = 1; a <= 9; a++) {
        for (int b = 1; b <= 9; b++) {
            ans += cnt[a][b] * cnt[b][a];
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int cntb = 0;
  int cntw = 0;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    if (s[i] == '#') {
      if (i != 0 && s[i - 1] == '.') {
        v.push_back({cntb, cntw});
        cntb = 1;
        cntw = 0;
      } else {
        cntb++;
      }
    } else {
      cntw++;
    }
  }
  v.push_back({cntb, cntw});
  int m = v.size();
  int ans = 1e9;
  for (int k = 0; k <= m; k++) {
    int tmp = 0;
    for (int i = 0; i < k; i++) {
      tmp += v[i].first;
    }
    for (int i = k; i < m; i++) {
      tmp += v[i].second;
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) lower_bound(all(v),k)-v.begin()
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
ll inf=100100100100;
const int mod=1000000007;
//abc137e
   bool from1[2500],ton[2500];
   void fromdfs(int i,int c,vector<vector<P>> v){
      for(auto x: v[i]){
         if(from1[x.first])continue;
         from1[x.first]=true;
         fromdfs(x.first,i,v);
      }
   }
   void todfs(int i,int c,vector<vector<P>> v){
      for(auto x: v[i]){
         if(ton[x.first])continue;
         ton[x.first]=true;
         todfs(x.first,i,v);
      }
   }
int main(){
   int n,m,p;cin>>n>>m>>p;
   rep(i,n){
      from1[i]=false;
      ton[i]=false;
   }
   vector<vector<P>> x(n);
   vector<vector<P>> y(n);
   vector<vector<P>> v(n);
   vi dis(n,inf);
   dis[0]=0;
   rep(i,m){
      int a,b,c;cin>>a>>b>>c;
      a--;b--;c*=-1;
      x[a].pb(P(b,c+p));
      y[b].pb(P(a,c+p));
   }
   from1[0]=true;
   ton[n-1]=true;
   fromdfs(0,-1,x);
   todfs(n-1,n,y);
   rep(i,n){
      if(from1[i]==false||ton[i]==false)continue;
      for(auto d:x[i]){
         if(from1[d.first]&&ton[d.first]){
            v[i].eb(d.first,d.second);
         }
      }
   }
   bool dif=true;
   int step=0;
   while(dif){
      dif=false;
      rep(i,n){
         if(dis[i]==inf)continue;
         for(auto d: v[i]){
            if(dis[d.first]>dis[i]+d.second){
               dis[d.first]=dis[i]+d.second;
               dif=true;
            }
         }
      }
      step++;
      if(step>n){
         cout<<-1<<endl;
         return 0;
      }
   }
   cout<<max(-dis[n-1],(ll)0);
}


Measured memory_bytes: 344832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x,y) for(ll i=x;i<=y;i++)
#define imin INT_MIN
#define imax INT_MAX
int mod =1e9+7;

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

	string s;
	cin>>s;
	int n = s.size();
	int cnt=0,dcnt=0;
	for(int i=0; i<n; i++){
		if(s[i]=='R'){
			cnt++;
		}
	}
	if(cnt==3){
		cout<<3<<"\n";
	}else if(cnt==2){
		if(s[1]=='S'){
			cout<<1<<"\n";
		}else{
			cout<<2<<"\n";
		}
	}else if(cnt==1){
		cout<<1<<"\n";
	}else if(cnt==0){
		cout<<cnt<<"\n";
	}
	
	return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N;
    cin >> N;
    vvi g(N);
    REP(i, N) {
        int u, k;
        cin >> u >> k;
        u--;
        vi v(k);
        REP(j, k) {
            int t;
            cin >> t;
            t--;
            v[j] = t;
        };

        g[u] = v;
    }

    vi dist(N, -1);
    dist[0] = 0;
    queue<int> q;
    q.push(0);

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

        for (int nv : g[v]) {
            if (dist[nv] == -1) q.push(nv);
            if (dist[nv] == -1) dist[nv] = dist[v] + 1;
            else dist[nv] = min(dist[nv], dist[v] + 1);
        }
    }

    REP(i, N) {
        cout << i+1 << " " << dist[i] << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3168
#include<iostream>
#include<vector>
#include<cmath>
#include<cstdio>
using namespace std;
vector<pair<int, double>>X[12000];
int N, M, a, b; double x[12000], y[12000], d[12000]; int g[12000];
int main() {
	cin >> N >> M; double S = 0;
	for (int i = 1; i <= N; i++)cin >> x[i] >> y[i];
	for (int i = 1; i <= M; i++) {
		cin >> a >> b;
		double c = pow((x[a] - x[b]), 2) + pow(y[a] - y[b], 2);
		c = sqrt(c); X[a].push_back(make_pair(b, c)); S += c;
		X[b].push_back(make_pair(a, c));
	}
	for (int t = 1; t <= N; t++) {
		if (g[t] >= 2)continue;
		d[t] = 0; g[t] = 1;
		while (true) {
			int OK = 1;
			for (int i = 1; i <= N; i++) {
				if (g[i] == 1)OK = 0;
			}
			if (OK == 1)break;
			double maxn = -1; int maxid = 0;
			for (int i = 1; i <= N; i++) {
				if (g[i] == 1 && maxn < d[i]) {
					maxn = d[i]; maxid = i;
				}
			}
			g[maxid] = 2;
			for (int i = 0; i < X[maxid].size(); i++) {
				int to = X[maxid][i].first; double dist = X[maxid][i].second;
				if (g[to] <= 1 && d[to] < dist) {
					d[to] = dist; g[to] = 1;
				}
			}
		}
	}
	double sum = 0;
	for (int i = 2; i <= N; i++) {
		sum += d[i];
	}
	printf("%.50f", S - sum);
	return 0;
}

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

using namespace std;
typedef long long lint;

#define RPT(i, b, e) for (int i = ((int)b); i <= ((int)e); i++)
#define RPT0(i, n) RPT(i, 0, ((int)n) - 1)
#define RPT1(i, n) RPT(i, 1, (n))
#define EACH(it, v) for (const auto& it : v)
#define ALL(v) v.begin(), v.end()

void resolve()
{
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int t1 = H1 * 60 + M1;
    int t2 = H2 * 60 + M2;
    int ans = (t2 - K) - t1;
    cout << ans << endl;
}

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


Measured memory_bytes: 3652
from collections import deque

N = int(input())
c = list(str(input()))
dw = deque()
dr = deque()

for i, c in enumerate(c, 1):
    if c == 'W':
        dw.append(i)
    else:
        dr.appendleft(i)

ans = 0
while dw and dr:
    w = dw.popleft()
    r = dr.popleft()
    if w < r:
        ans += 1

    else:
        break
print(ans)

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

long long GetGreatestCommonDivisor(long long a, long long b)
{
	long long m = a;
	long long n = b;
	long long temp;

	while (m % n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int main() {

	long long n; cin >> n;

	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++){
				vector<int> vec;
				vec.push_back(i);
				vec.push_back(j);
				vec.push_back(k);
				long long tmp = vec[0];
				tmp = GetGreatestCommonDivisor(tmp, vec[1]);
				tmp = GetGreatestCommonDivisor(tmp, vec[2]);
				
				ans += tmp;
			}

		}

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

}

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


void solve(long long R, long long G){
    cout << 2 * G - R << endl;
}

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


Measured memory_bytes: 256
def solve():
	h,w,d,*l=map(int,open(0).read().split())
	s=h*w+1;x=[0]*s;y=[0]*s;k=[0]*s
	for i,a in enumerate(l[:s-1]):x[a]=i//w;y[a]=i%w
	for i in range(d+1,s):k[i]=k[i-d]+abs(x[i]-x[i-d])+abs(y[i]-y[i-d])
	for l,r in zip(l[s::2],l[s+1::2]):print(k[r]-k[l])
if __name__=="__main__":
	solve()

Measured memory_bytes: 34396
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 100;

void trace( int A[], int N )
{
    for ( int i = 0; i < N; i++ )
    {
        if ( i > 0 ) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void insertionSort( int A[], int N )
{
    for ( int i = 1; i < N; i++ )
    {
        int v = A[i];
        int j = i - 1;
        while( j >= 0 && A[j] > v )
        {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace( A, N );
    }
}

int main(void)
{
    int A[MAX], N;

    cin >> N;
    for ( int i = 0; i < N; i++ )
    {
        cin >> A[i];
    }


  trace( A, N );
    insertionSort( A, N );


    return 0;
}



Measured memory_bytes: 3080
#include<cstdio>
#include<iostream>
#include<fstream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define Set(a) memset(a,0,sizeof(a))
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define openf(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define re register
#define ri re int
#define il inline
typedef long long ll;
typedef unsigned long long ull;
template<typename T> inline T rd(T& x)
{
	T f=1;x=0;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(T)(c-'0');
	x*=f;
	return x;
}
ll rd(){ll x;rd(x);return x;}
const int inf=1<<30;

ll _a[410];ll *a=_a+205;
int main()
{
	F(i,-200,200) a[i]=1ll*i*i*i*i*i;
	ll x=rd();
	F(i,-200,200) F(j,i+1,200) if(a[j]-a[i]==x) {cout<<j<<' '<<i<<endl;return 0;}
	return 0;
}

Measured memory_bytes: 3632
// AOJ 1160 "島はいくつある？" (ICPC国内予選 2009 Problem B)
import java.util.Scanner;

public class Main {
    static int[][] field;
    static int ans;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int w = sc.nextInt();
            int h = sc.nextInt();
            if (w == 0) {
                break;
            }
            
            field = new int[h][w];
            ans = 0;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    field[i][j] = sc.nextInt();
                }
            }
            solve();
            System.out.println(ans);
        }
    }
    
    public static void solve() {
        for (int i = 0; i < field.length; i++) {
            for (int j = 0; j < field[i].length; j++) {
                if (field[i][j] == 1) {
                    ans++;
                    dfs(j, i);
                }
            }
        }
    }
    
    public static void dfs(int x, int y) {
        field[y][x] = 0;
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                if (x + j >= 0 && x + j < field[y].length &&
                    y + i >= 0 && y + i < field.length &&
                    field[y+i][x+j] == 1) {
                    dfs(x + j, y + i);
                }
            }
        }
    }
}

Measured memory_bytes: 43008
import java.util.Scanner

object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val cubes = sc.next()
    cubes
  }

  def step(n: (Int, Int), cube: Char): (Int, Int) = {
    val (n0, n1) = n
    if (cube == '0') {
      if (n1 != 0) {
        return (n0, n1 - 1)
      } else {
        return (n0 + 1, n1)
      }

    } else if (cube == '1') {
      if (n0 != 0) {
        return (n0 - 1, n1)
      } else {
        return (n0, n1 + 1)
      }
    }
    throw new IllegalArgumentException()
  }

  def solve(cubes: String): Int = {
    val (n0,n1) = cubes.foldLeft[(Int, Int)](0,0)(step)
    cubes.length - Math.max(n0, n1)
  }


  def main(args: Array[String]): Unit = {
    val cubes = read()
    println(solve(cubes))
  }
}

Measured memory_bytes: 33504
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        StringBuilder a = new StringBuilder(scan.next());
        StringBuilder b = new StringBuilder(scan.next());
        StringBuilder c = new StringBuilder(scan.next());
        boolean hantei = true;
        char turn = a.charAt(0);
        a.deleteCharAt(0);
        char ans = ' ';

        while(hantei){
        	if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	}

        	if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	}

        	if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	}

        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define ll long long
#define MAX 100005
#define pb push_back
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;
vector<int>adj[100005];
int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}

ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

int main()
{
    int a,b,k;
    cin>>a>>b>>k;
    int p = __gcd(a,b);
    vector<int>divisors;
    for(int i=1;i<=sqrt(p);i++)
    {
        if(p%i==0)
        {
            divisors.pb(i);
            if(i*i!=p)
                divisors.pb(p/i);
        }
    }
    sort(divisors.rbegin(),divisors.rend());
    //int nn = divisors.size();
    cout<<divisors[k-1]<<"\n";
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=true;
// const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMInit(void){
    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(long long n, long long k){
    if (n < k){return 0;}
    if (n < 0 || k < 0){return 0;}
    return fac[n]*(finv[k] * finv[n-k]%MOD)%MOD;
}

int main(void) {
    ll n,m,k;
    cin >> n >> m >> k;
    COMInit();
    ll res = COM(n*m-2, k-2);
    ll tmp=0;
    for(ll i=1;i<=n-1;i++){
        tmp += i*(n-i)%MOD*m*m%MOD;
        tmp %= MOD;
    }
    for(ll i=1;i<=m-1;i++){
        tmp += i*(m-i)%MOD*n*n%MOD;
        tmp %= MOD;
    }
    cout << res*tmp%MOD << endl;
    return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
// 1 2 4 8 16 32 64 128 256
int main() {
    int n;
    cin >> n;
    int ans = 0;
    if(n>=64) ans = 64;
    else if(n >= 32) ans = 32;
    else if(n>=16) ans = 16;
    else if(n >= 8) ans = 8;
    else if(n>=4) ans = 4;
    else if(n>=2) ans = 2;
    else ans = 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a[4];
    int c[4];
    while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>c[0]>>c[1]>>c[2]>>c[3]){
        int h=0,b=0;
        for(int i=0;i<4;i++){
            if(a[i]==c[i])
                h++;
            else{
                for(int j=0;j<4;j++){
                    if(a[i]==c[j]){
                        b++;
                        break;
                    }
                }
            }
        }
        cout<<h<<" "<<b<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
#define MAX 100005
#define NIL -1

struct Node{
  int p,l,r,cn;
  int *chil;
  //int chil[100];
};

struct Node T[MAX];

int getDepth(int u){
  int d = 0;
  while(T[u].p != NIL){
    u = T[u].p;
    d++;
  }
  return d;
}

void printChildren(int u){
  int i;

  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,getDepth(u));

  if(T[u].p == NIL) printf("root, [");
  else if(T[u].l == NIL) printf("leaf, [");
  else printf("internal node, [");

  if (T[u].cn == 0) printf("]\n");
  else {
    for(i=0; i<T[u].cn-1; i++){
      printf("%d, ",T[u].chil[i]);
    }
    printf("%d]\n",T[u].chil[i]);
  }
}

int main(){
  int i,j;
  int n,num,quo;
  int l;

  scanf("%d",&n);

  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i=0; i<n; i++){
    scanf("%d%d",&num,&quo);
    T[num].cn = quo;
    if (T[num].cn > 0){
      T[num].chil = (int *)malloc(T[num].cn*sizeof(int));
    }
    for(j=0; j<quo; j++){
      scanf("%d",&T[num].chil[j]);
      if(j == 0) T[num].l = T[num].chil[j];
      else T[l].r = T[num].chil[j];
      l = T[num].chil[j];
      T[T[num].chil[j]].p = num;
    }
  }
  
  for(i=0; i<n; i++) printChildren(i);

  return 0;
}



Measured memory_bytes: 4556
/*
[dwacon5th-prelims] D - Square Rotation
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 1e5;
const int MAX_D = 1000;

int N, D;
int x[MAX_N], y[MAX_N];
int c[MAX_D][MAX_D];
int s[3][MAX_D * 2 + 1][MAX_D * 2 + 1];

bool can(int q) {
    for (int a = 0; a < D; a++) {
        for (int b = 0; b < D; b++) {
            bool is_ok =
                (s[2][a + q + 1][b + q + 1] - s[2][a + q + 1][b] -
                     s[2][a][b + q + 1] + s[2][a][b] ==
                 0) &&
                (s[1][a + q + 1][b + D] - s[1][a + q + 1][b + q + 1] -
                     s[1][a][b + D] + s[1][a][b + q + 1] ==
                 0) &&
                (s[1][a + D][b + q + 1] - s[1][a + D][b] -
                     s[1][a + q + 1][b + q + 1] + s[1][a + q + 1][b] ==
                 0) &&
                (s[0][a + D][b + D] - s[0][a + D][b + q + 1] -
                     s[0][a + q + 1][b + D] + s[0][a + q + 1][b + q + 1] ==
                 0);
            if (is_ok) {
                return true;
            }
        }
    }

    return false;
}

ll solve() {
    int p = 0;
    for (int i = 0; i < N; i++) {
        c[x[i] % D][y[i] % D]++;
    }
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < D; j++) {
            while ((p + 1) * (p + 1) < c[i][j]) {
                p++;
            }
        }
    }

    int thresh[3] = {p * p, p * (p + 1), (p + 1) * (p + 1)};
    for (int k = 0; k < 3; k++) {
        for (int i = 0; i < D; i++) {
            for (int j = 0; j < D; j++) {
                if (c[i][j] > thresh[k]) {
                    s[k][1 + i][1 + j]++;
                    s[k][1 + i + D][1 + j]++;
                    s[k][1 + i][1 + j + D]++;
                    s[k][1 + i + D][1 + j + D]++;
                }
            }
        }
    }

    for (int k = 0; k < 3; k++) {
        for (int i = 1; i <= 2 * D; i++) {
            for (int j = 0; j <= 2 * D; j++) {
                s[k][i + 1][j] += s[k][i][j];
            }
        }
        for (int i = 0; i <= 2 * D; i++) {
            for (int j = 1; j <= 2 * D; j++) {
                s[k][i][j + 1] += s[k][i][j];
            }
        }
    }

    int ng = -1, ok = D - 1;
    while (ok - ng > 1) {
        int m = (ok + ng) / 2;
        if (can(m)) {
            ok = m;
        } else {
            ng = m;
        }
    }

    ll ans = p * D + ok;
    return ans;
}

int main() {
    cin >> N >> D;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 51840