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

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

int main() {

	int n;
	cin >> n;
	vector<int>a(n);

	rep(i, n)
		cin >> a[i];

	int now = 0;
	rep(i, n)
		if (a[i] != i + 1)
			now++;

	if (now <= 2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int f(int n);

int main()
{
	int n;
	cin >> n;
	int a[10000] = { 0 };
	a[n]++;
	int i = 1;
	while (1) {
		n = f(n);
		i++;
		if (a[n] == 1) {
			cout << i << endl;
			return 0;
		}
		else {
			a[n]++;
		}
	}

	return 0;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




ll N, bit[101];
//---------------------------------------------------------------------------------------------------
string g(int n, int a, int b) {
    if (n == 0) {
        if (N == 0) return "";
        else return "?";
    }

    ll cn = bit[n - 1];
    if (N - cn < 0) {
        string res = "";
        res += char('0' + a);
        return res + g(n - 1, a, b);
    }

    N -= cn;
    string res = "";
    res += char('0' + b);
    return res + g(n - 1, a, b);
}
//---------------------------------------------------------------------------------------------------
string f(int n, int a) {
    rep(b, 0, 10) {
        ll cn;
        if (a == b) cn = (bit[n - 1] - 1) * 9;
        else cn = bit[n - 1];

        if (N - cn < 0) {
            string res = "";
            res += char('0' + b);

            if (a == b) res += f(n - 1, a);
            else res += g(n - 1, min(a, b), max(a, b));
            return res;
        } else N -= cn;
    }
}
//---------------------------------------------------------------------------------------------------
string solve() {
    N--;

    rep(n, 2, 100) rep(a, 1, 10) {
        ll cnt = (bit[n - 1] - 1) * 9;
        if (N - cnt < 0) {
            string ans = "";
            ans += char('0' + a);
            return ans + f(n - 1, a);
        }
        N -= cnt;
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    bit[0] = 1;
    rep(i, 1, 101) bit[i] = bit[i - 1] * 2;

    while (cin >> N) {
        if (N == 0) return;
        auto ans = solve();
        printf("%s\n", ans.c_str());
    }
}



Measured memory_bytes: 3208
#include<cstdio>

int main() {
	char s;
	long long sum = 0;
	while(scanf("%c", &s)) {
		if(s > '9' || s < '0') {
			break;
		}
		sum += s - '0';
	}
	if(sum % 9 == 0) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
}

Measured memory_bytes: 3156
(defn n-105 [n]
  (->> (range 1 (inc n))
       (filter odd?)
       (filter (fn [odd]
                 (let [c (filter (fn [n]
                                   (zero? (rem odd n)))
                                 (filter odd? (range 1 (Math/floor (/ odd 2)))))]
                   (= (inc (count c)) 8))))
       count))
(println (n-105 (read)))

Measured memory_bytes: 66052
#include <bits/stdc++.h>
using namespace std;
bool detect_cycle(vector<vector<int>> &E){
	int N = E.size();
	vector<int> deg(N, 0);
	for (int i = 0; i < N; i++){
		for (int j : E[i]){
			deg[j]++;
		}
	}
	queue<int> Q;
	for (int i = 0; i < N; i++){
		if (deg[i] == 0){
			Q.push(i);
		}
	}
	while (!Q.empty()){
		int v = Q.front();
		Q.pop();
		for (int w : E[v]){
			deg[w]--;
			if (deg[w] == 0){
				Q.push(w);
			}
		}
	}
	for (int i = 0; i < N; i++){
		if (deg[i] != 0){
			return true;
		}
	}
	return false;
}
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E(N);
  for (int i = 0; i < M; i++){
    int s, t;
    cin >> s >> t;
    E[s].push_back(t);
  }
  if (detect_cycle(E)){
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 3160
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        ++$this->pointer;

        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int) $this->next();
    }

    public function nextDouble()
    {
        return (float) $this->next();
    }
}

$sc = new Scanner();
$x = $sc->nextInt();
$n = $sc->nextInt();
$array = [];
for($i=0;$i<$n;$i++){
    $key = $sc->nextInt();
    $array[$key] = 1;
}

if(!array_key_exists($x, $array)){
    $answer = $x;
} else {
    for($i=1;$i<51;$i++){
        if(!array_key_exists($x-$i, $array)){
            $answer = $x-$i;
            break;
        } else {
            if(!array_key_exists($x+$i, $array)){
                $answer = $x+$i;
                break;
            }
        }
    }
}

echo $answer.PHP_EOL;

Measured memory_bytes: 16212
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn=105;
int n;
int a[maxn];
void InsertSort ()
{
    for (int i=0;i<n;i++)
    {
        int temp=a[i];
        int loc=i-1;
        while (loc>=0&&a[loc]>temp)
               {
                   a[loc+1]=a[loc];
                   loc--;
               }
        a[loc+1]=temp;
        for (int j=0;j<n;j++)
            printf("%d%c",a[j],j==n-1? '\n':' ');
    }
}
int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++)
        scanf("%d",&a[i]);
    InsertSort();
    return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

inline int GCD(int x, int y) {
  if (x < y) return GCD(y, x);
  if (y == 0) return x;
  return GCD(y, x % y);
}

int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> as(n);
  for (auto& a : as) cin >> a;
  vector<int> lGCDs(n + 1), rGCDs(n + 1);
  partial_sum(begin(as), end(as), begin(lGCDs) + 1, GCD);
  partial_sum(rbegin(as), rend(as), rbegin(rGCDs) + 1, GCD);
  int maximum = 0;
  for (int i = 0; i < n; i++) {
    maximum = max(maximum, GCD(lGCDs[i], rGCDs[i + 1]));
  }
  cout << maximum << endl;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  Solver(LL n) : n(n){};
  bool calc(LL a, LL b, LL c, LL d) {
    if (d < b) return false;
    if (a < b) return false;
    a -= (a - c - 1) / b * b;
    if (a < b) return false;
    LL g = __gcd(b, d);
    a -= (a - c - 1) / g * g;
    if (a < b) return false;
    return true;
  }
  void solve() {
    LL a, b, c, d;
    for (int i = 0; i < n; ++i) {
      cin >> a >> b >> c >> d;
      cout << (calc(a, b, c, d) ? "Yes" : "No") << "\n";
    }
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 256
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
class comb():
  F = [1, 1]
  Fi = [1, 1]
  I = [0, 1]
  def __init__(self, num, mod):
    self.MOD = mod
    for i in range(2, num + 1):
      self.F.append((self.F[-1] * i) % mod)
      self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
      self.Fi.append(self.Fi[-1] * self.I[i] % mod)
  def com(self, n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD

com = comb(N, MOD)
A.sort()
ans = 0
for i in range(N):
  if i + 1 >= K:
    ans = (ans + A[i] * com.com(i, K - 1) % MOD) % MOD
  if N - i >= K:
    ans = (ans - A[i] * com.com(N - i - 1, K - 1) % MOD)
    if ans < 0:
      ans += MOD

print(ans % MOD)

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

set<int> ins(set<int> a, set<int> b){
  set<int> c{};
  for(auto itr=a.begin(); itr != a.end(); itr++){
    if(b.erase(*itr) == 1) c.insert(*itr);
  }
  return c;
}
  

int main(){
  int N,M;
  cin>>N>>M;
  set<int> ans;
  for(int i=0;i<M;i++){
    ans.insert(i);
  }
  for(int i=0;i<N;i++){
    int K;
    cin>>K;
    set<int> X{};
    for(int j=0;j<K;j++){
      int a;
      cin>>a;
      X.insert(a-1);
    }
    ans = ins(X,ans);
  }
  cout << ans.size() << endl;
}
    

Measured memory_bytes: 256
N = int(input())
s = input()

L = 0
R = s[1:N].count("E")
ans = L + R

for i in range(N-1):
    if s[i] == "W":
        L += 1
    if s[i+1] == "E":
        R -= 1
    
    if L +  R < ans:
        ans = L + R

print(ans)

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<int> a(n);
	for (int i=0; i<n; i++)
		cin>>a[i], a[i]-=(i+1);
	sort(a.begin(), a.end());
	ll ret=0, med=a[n/2];
	for (auto it : a)
		ret+=abs(it-med);
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 1024
while True :
    n = int(input())
    if n == 0 :
        break
    
    s = 1000 - n
    count = 0
    if s >= 500 :
        count += 1
        s = s - 500
    if s >= 100 :
        count += int(s / 100)
        s = int(s % 100)
    if s >= 50 :
        count += 1
        s = s - 50
    if s >= 10 :
        count += int(s / 10)
        s = int(s % 10)
    if s >= 5 :
        count += 1
        s = s - 5
    count += s
    print(count)


Measured memory_bytes: 5588
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, K = iim()
    A = list(iim())

    pos = 1
    if K < N:
        for i in range(K):
            pos = A[pos-1]

        print(pos)
        return

    dp = [-1]*N
    dp1 = [0]*N
    for i in range(N):
        if dp[pos-1] >= 0:
            lp = i - dp[pos-1]
            i0 = i - lp
            print(dp1[i0:][(K-i0) % lp])
            return
        dp1[i] = pos
        dp[pos-1] = i
        pos = A[pos-1]



if __name__ == "__main__":
    resolve()


Measured memory_bytes: 32240
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vlll vector< vector< vector<ll> > >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    ll N, W; cin >> N >> W;
    vl w;
    vl v;
    rep(i, 0, N){
        ll _w, _v; cin >> _w >> _v;
        w.push_back(_w);
        v.push_back(_v);
    }
    ll w0 = w[0];
    rep(i, 0, N){
        w[i] -= w0;
    }
    vlll dp(N+1, vll(301, vl(N+1, 0)));
    /* rep(i, 1, N+1){ */
    /*     dp[i][0][0] = -INF; */
    /* } */
    rep(i, 1, N+1){
        rep(j, 0, 301){
            rep(k, 1, N+1){
                if(j == 2){
                    /* cout << "i: " << i << " j: " << j << " k: " << k << endl; */
                    /* DEBUG(dp[i][j][k]); */
                    /* DEBUG(dp[i-1][j][k]); */
                    /* DEBUG(w[i-1]); */
                    /* DEBUG(v[i-1]); */
                    /* cout << endl; */
                }

                if(j - w[i-1] >= 0){
                    dp[i][j][k] = max(
                            dp[i-1][j][k], dp[i-1][j-w[i-1]][k-1] + v[i-1]
                            );
                } else dp[i][j][k] = dp[i-1][j][k];
                }
            }
        } 
    ll ans = 0;
    rep(j, 0, 3*N+1){
        rep(k, 0, N+1){
            ll weight = k * w0 + j;
            /* DEBUG(j); */
            /* DEBUG(k); */
            /* DEBUG(dp[N][j][k]); */
            /* DEBUG(weight); */
            /* cout << endl; */
            if(weight <= W){
                ans = max(ans, dp[N][j][k]);
            }
        }
    }
    /* DEBUG_VEC(dp[N][2]); */
    /* DEBUG_VEC(dp[0][1]); */
    /* DEBUG_VEC(dp[1][0]); */
    /* DEBUG_VEC(dp[1][1]); */
    /* DEBUG_VEC(dp[2][1]); */
    /* DEBUG_VEC(dp[3][1]); */
    /* DEBUG_VEC(dp[4][1]); */
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 25472
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e15 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const int N = 5e3 + 5;
int dp[N][N], n, Data[N];

int go(int l, int r) {
  if(l > r) return 0;
  int &x = dp[l][r];
  if(x != -INF) return x;
  if((r-l+1)%2 == n%2) {
    x = max(Data[l]+go(l+1, r), Data[r]+go(l, r-1));
  }
  else {
    x = min(-Data[l]+go(l+1, r), -Data[r]+go(l, r-1));
  }
  return x;
}

void solve() {
  for(int i = 1; i < N; i++) for(int j = 1; j < N; j++) dp[i][j] = -INF;
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> Data[i];
  cout << go(1, n) << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);

    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    // #endif
    int t = 1; // cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }
}    


Measured memory_bytes: 196096
def calc_ex(P):
    sum = 0
    for p in range(1, P+1):
        sum += p
    return sum / P

def main():
    N, K = map(int,input().split())
    P = list(map(int,input().split()))
    accumP = [0] * (N + 1)
    for i in range(N):
        accumP[i+1] = accumP[i] + P[i]

    # 最大の区間を求める
    idx = 0
    sum = accumP[idx+K] - accumP[idx] 
    for i in range(0, N-K+1):
        if accumP[i+K] - accumP[i] > sum:
            idx = i
            sum = accumP[i+K] - accumP[i]
    
    
    ans = 0
    for i in range(idx, idx+K):
        ans += calc_ex(P[i])

    print(ans)

if __name__ == "__main__":
    main()

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

int main(){
  long long N,H,ans=0;
  cin >>N>>H;
  long long a,b,a_max=0;
  vector<long long> V;
  
  for(long long i=0;i<N;i++){
    cin>>a>>b;
    a_max=max(a,a_max);
    V.push_back(b);
  }
  
  sort(V.begin(), V.end());
  
  for(long long i=0;i<N;i++){
    if(a_max<V[N-i-1]){
      H-=V[N-i-1];
      ans+=1;
    }
    if(H<=0)break;
  }
  
  if(H>0){
    ans+=ceil(H*1.0/a_max);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1400
<?php
list($n,$h,$w)=explode(" ",trim(fgets(STDIN)));
$ans=0;
$i=0;
while($i<$n){
list($a,$b)=explode(" ",trim(fgets(STDIN)));
if($a>=$h&&$b>=$w){
++$ans;
}
++$i;
}
echo $ans;

Measured memory_bytes: 4728
import sys


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


a = LI()
a.sort()

print(a[0], a[1], a[2])



Measured memory_bytes: 5604
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main(){
    int n;
    cin >> n;
    cout << (n + 1) / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
using namespace std;

int a,b,cnt;
int* p;

void rec(int x,int y){
  if(x==a-1&&y==b-1){cnt++;return;}
  if(x<a-1&&p[(x+1)+y*a]==0)rec(x+1,y);
  if(y<b-1&&p[x+(y+1)*a]==0)rec(x,y+1);
}

int main () {
  while(cin>>a>>b,a|b){
    cnt=0;
    int d[a*b]={};p=d;int k;cin>>k;
    for(int i=0;i<k;++i){
      int x,y;cin>>x>>y;x--;y--;
      d[x+y*a]=1;
    }
    rec(0,0);
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	long long int a[100010];
	a[0] = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	a[n + 1] = 0;
	long long int sum = 0;
	for(int i = 1; i <= n + 1; i++){
		sum += abs(a[i] - a[i - 1]);
	}
	for(int i = 1; i <= n; i++){
		cout << sum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]) << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			int g = __gcd(i, j);
			if (g == 1) {
				ans += n;
				continue;
			}
			for (int k = 1; k <= n; ++k) {
				ans += __gcd(g, k);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3644
import math
import sys
sys.setrecursionlimit(10**5)
n = int(input())
s = int(input())

if n < s:
    print (-1)
    exit()

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b

if s == n:
    print (n+1)
    exit()

if n == 1:
    print (-1)
    exit()

for i in range(2, int(math.sqrt(n))+2):
    if f(i, n) == s:
        print (i)
        exit()

for p in range(int(math.sqrt(n))+1, 0, -1):
    b = (n-s)//p + 1
    if b != 1 and f(b, n) == s:
        print (b)
        exit()
print (-1)

# for i in range(2, 100):
#     print (i, f(i,100))

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		ArrayDeque<Integer> b = new ArrayDeque<Integer>();
		boolean flg = true;
		for(int i = 0; i < n; i++){
		    int a = sc.nextInt();
		    if(flg){
		        b.addLast(a);
		    }else{
		        b.addFirst(a);
		    }
		    flg = !flg;
		}
		
		// 計算
		//int result = 0;
		
		// 出力
		while(!b.isEmpty()){
		    if(flg){
		        System.out.print(b.pollFirst());
		    }else{
		        System.out.print(b.pollLast());
		    }
		    System.out.print(" ");
		}
	}

}

Measured memory_bytes: 94628
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#include<bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
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; }

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

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

    int cnt1 = 0, cnt2 = 0;
    rep(i, m){
        if(a[i]>x) cnt1++;
        if(a[i]<x) cnt2++;
    }
    out(min(cnt1, cnt2));
}

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

using namespace std;

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

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

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

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

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

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	FORR(i, 0, s.size()-1){
		if(i&1){
			continue;
		}
		int m=i/2;
		bool ok=true;
		REP(j, m){
			if(s[j]!=s[j+m]){
				ok=false;
				break;
			}
		}
		if(ok){
			cout<<i<<'\n';
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const int mod=10007;
#define ll long long

int main(){
    int n,sum=0,ans=0;
    cin>>n;
    vector<int>a(n);
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    if(sum%10!=0){
        cout<<sum<<endl;
        return 0;
    }
    rep(i,n){
        int tmp=sum;
        tmp-=a[i];
        if(tmp%10!=0){
            ans=max(ans,tmp);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

    int n, m;
    cin >> n >> m;
    vector<pair<ll, ll> > drink(n);
    REP(i, n) {
        ll a, b;
        cin >> a >> b;
        drink[i] = make_pair(a, b);
    }

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

    ll ans = 0;
    int i = 0;
    while(m > 0) {
        if (drink[i].second <= m) {
            ans += drink[i].first * drink[i].second;
            m -= drink[i].second;
        } else {
            ans += m * drink[i].first;
            break ;
        }
        i++;
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1792
let prim a n =
  let d = Array.make n max_int in
  d.(0) <- 0;
  let b = Array.make n false in
  let z = Array.make n (-1) in
  let rec doit () =
    let (_, _, u) =
      Array.fold_left (fun (i, m, u) e ->
        if b.(i) = false && m > e then (i + 1, e, i) else (i + 1, m, u))
        (0, max_int, (-1)) d in
    if u = (-1) then ()
    else begin
      b.(u) <- true;
      for i = 0 to n - 1 do
        if b.(i) = true || a.(u).(i) = max_int || d.(i) <= a.(u).(i) then ()
        else begin
          d.(i) <- a.(u).(i);
          z.(i) <- u;
        end
      done;
      doit ()
    end in
  doit ();
  Array.fold_left (fun (i, sum) e ->
    (i + 1, sum + if e = (-1) then 0 else a.(i).(e)))
    (0, 0) z
  |> snd

let () =
  let n = read_int () in
  let a = Array.make_matrix n n max_int in
  for i = 0 to n - 1 do
    for j = 0 to n - 1 do
      let x = Scanf.scanf " %d" (fun x -> x) in
      if x <> (-1) then a.(i).(j) <- x;
    done
  done;
  prim a n |> Printf.printf "%d\n"

Measured memory_bytes: 4548
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define all(a) (a).begin(),(a).end()
#define X first
#define Y second
#define inf 1e18+5
using namespace std;
const int mod=1e9+7;
void solve()
{
    int n; cin>>n;
    string s; cin>>s;
    int dp[n]; dp[0]=1;
    for(int i=1;i<n;i++)
    {
        int dp1[n];
        for(int j=0;j<=i;j++)
        {
            if(s[i-1]=='<')
            {
                if(j)dp1[j]=dp[j-1];
                else dp1[j]=0;
            }
            else
            {
                if(j)dp1[j]=(dp[i-1]-dp[j-1]+mod)%mod;
                else dp1[j]=dp[i-1];
            }
        }
        dp[0]=dp1[0];
        for(int j=1;j<=i;j++){dp[j]=dp[j-1]+dp1[j]; dp[j]%=mod;}
    }
    cout<<dp[n-1];
    return;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555;
const double PI = acos(-1.0);

void solve()
{
	int a, b;
	string s;
	cin >> a >> b >> s;
	if(s.size() != a + b + 1){
		cout << "No";
	}
	else{
		if(s[a] != '-'){
			cout << "No";
		}
		else{
			bool ok = 1;
			for(int i = 0; i < a; ++i){
				ok &= (s[i] >= '0' && s[i] <= '9');
			}
			for(int i = a + 1; i < s.size(); ++i){
				ok &= (s[i] >= '0' && s[i] <= '9');
			}
			if(ok) cout << "Yes";
			else cout << "No";
		}
	}
}
 
int main()
{
    Red;
    solve();
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

P,Q,R = inpl()

print(P+Q+R-max(P,Q,R))


Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define REP(i, N) for (int i = 0; i < N; i++)

int main()
{
    int h;
    cin >> h;
    int w;
    cin >> w;

    bool visited[1001][1001];

    for (int i = 0; i < 1001; i++)
    {
        for (int j = 0; j < 1001; j++)
        {
            visited[i][j] = 0;
        }
    }

    queue<pair<pair<int, int>,int>> black_cells;
    int nblack = 0;

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            char a;
            cin >> a;
            if(a=='#'){
                black_cells.push({{i,j},0});
            }
        }
    }

    int ans = 0;

    while (!black_cells.empty() && nblack != w * h)
    {
        pair<int,int> cell = black_cells.front().first;
        int depth = black_cells.front().second;
        int i = cell.first; int j = cell.second;
        black_cells.pop();
        if(visited[i][j]) continue;
        visited[i][j] = true;
        if(ans<depth){ ans = depth; }
        nblack++;
        if (i+1<h && !visited[i+1][j])
        {
            black_cells.push({{i+1,j},depth+1});
        }
        if (j+1<w && !visited[i][j+1])
        {
            black_cells.push({{i,j+1},depth+1});
        }
        if (i>0 && !visited[i-1][j])
        {
            black_cells.push({{i-1,j},depth+1});
        }
        if (j>0 && !visited[i][j-1])
        {
            black_cells.push({{i,j-1},depth+1});
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 25524
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,s[100000];
	scanf("%d",&n);
	for(int i=0; i<n; i++) {
		scanf("%d",&s[i]);
	}
	int ans=0;
	for(int j=0; j<n; j++) {
		if(s[j]==j+1) {
			if(s[j]<s[j+1]) {
				int t=s[j+1];
				s[j+1]=s[j];
				s[j]=t;
				ans++;
			} else {
				if(j>0) {
					int t=s[j-1];
					s[j-1]=s[j];
					s[j]=t;
					ans++;
				} else {
					int t=s[j+1];
					s[j+1]=s[j];
					s[j]=t;
					ans++;
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
# ABC143E - Travel by Car
def floyd_warshall(dist):
    """
    Compute the shortest paths of all pairs and modify dist.
    """
    V = len(dist)
    for i in range(V):  # intermediate point
        for j, c2 in enumerate(dist[j][i] for j in range(V)):  #  source
            for k, (c1, c3) in enumerate(zip(dist[j], dist[i])):  # target
                if c2 + c3 < c1:
                    dist[j][k] = c2 + c3


def main():
    # FW -> once more FW to edges <= L
    N, M, L, *X = map(int, open(0).read().split())
    ABC, ST = X[: 3 * M], X[3 * M + 1 :]
    INF = float("inf")
    dist = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        dist[i][i] = 0
    for v, u, cost in zip(*[iter(ABC)] * 3):
        dist[v][u] = dist[u][v] = cost
    floyd_warshall(dist)

    # assume distance within L as 1 and compute the number of fueling
    modified_dist = [[1 if x <= L else INF for x in d] for d in dist]
    floyd_warshall(modified_dist)
    ans = [
        modified_dist[s][t] - 1 if modified_dist[s][t] != INF else -1
        for s, t in zip(*[iter(ST)] * 2)
    ]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

Measured memory_bytes: 121236
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
double dis(double x1,double y1,double x2,double y2)
{
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
double x[20],y[20];
int len[20];
int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> x[i] >> y[i];
        len[i]=i;
    }
    double ans=0;
    double tot=0;
    do
    {
        double sum=0;
        for(int i=0; i<n-1; i++)
        {
            sum+=dis(x[len[i]],y[len[i]],x[len[i+1]],y[len[i+1]]);
        }
        ans+=sum;
        tot++;
    }
    while(next_permutation(len,len+n));
    printf("%.10lf",ans/tot);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;

map<ll,ll> prime_factor(ll n){ //素因数分解
    map<ll,ll> table;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            table[i]++;
            n/=i;
        }
    }
    if(n!=1) table[n]=1;
    return table;// key->素因数, value->べき乗
}

bool is_prime(int n){ //素数判定
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return true;
    }
    return false;
}

vector<bool> prime_table(int n){ //素数全列挙
    vector<bool> prime(n+1,true);
    prime[0]=prime[1]=false;
    for(int i=2;i*i<=n;i++){
        if(prime[i]!=true) continue;
        for(int j=2*i;j<=n;j+=i){
            prime[j]=false;
        }
    }
    return prime; //i番目の要素が素数の場合trueを返す
}

int main(){
    int N;
    cin >> N;
    vector<bool> prime;
    prime=prime_table(55555);
    int cnt=0;
    for(int i=2;i<=55555;i++){
        if(prime[i]==true&&i%5==1){
            cnt++;
            cout << i << endl;
            if(cnt==N) break;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n, a[110];
    scanf("%d", &n);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    for(int i=0; i<n; i++){
        for(int j=0; j<n-1; j++){
            if(a[j]>a[j+1]){
                int temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
        }
    }
    printf("%d", a[n-1]-a[0]);
    return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<vector>

using namespace std;

int s(int i,int j,int m,char a[200][200],char b[200][200])
{
  int k,l;
  for(k=0;k<m;k++)
    for(l=0;l<m;l++)
      if(a[i+k][j+l]!=b[k][l])
        return 0;
  return 1;
}

int main(void)
{
  char a[200][200]={};
  char b[200][200]={};
  int n,m;
  int i,j;

  cin>>n>>m;
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      scanf(" %c",&a[i][j]);

  for(i=0;i<m;i++)
    for(j=0;j<m;j++)
      scanf(" %c",&b[i][j]);

  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      if(a[i][j]==b[0][0])
        if(s(i,j,m,a,b))
          {
            puts("Yes");
            return 0;
          }
  puts("No");
}






Measured memory_bytes: 384
// Problem : C - Triangular Relationship
// Contest : AtCoder - AtCoder Regular Contest 102
// URL : https://atcoder.jp/contests/arc102/tasks/arc102_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 ll mod_pow(ll x,ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x*x , n / 2);
	if (n & 1) res = res * x ;
	return res;
}

int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N,K;
	cin>>N>>K;
	ll ans=0;
	if(K%2==0 && K/2<=N)
		ans++;
	if(K<=N)
	{
		int val=N/K;
		ans+=mod_pow(val,3);
		if(K%2==0)
		{
			if(N%K>=K/2)
				val++;
			ans+=mod_pow(val,3);
			ans--;
		}
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3672
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

def f(n):
    count=0
    while n:
        count+=n%2
        n//=2
    return count

n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
for bit in range(2**n):
    # if f(bit)%2!=0:
    #     continue
    arr=[]
    for i in range(n):
        if bit >> i & 1:
            arr.append((B[i],i))
        else:
            arr.append((A[i],i))
    i=0;flug=1;tmp=0
    while flug:
        flug=0
        for j in range(n-1,i,-1):
            if arr[j-1][0]>arr[j][0]:
                arr[j-1],arr[j]=arr[j],arr[j-1]
                tmp+=1; flug=1
        i+=1
    stack=[]
    for i in range(n):
        if (abs(arr[i][1]-i)) % 2 != bit >> arr[i][1] & 1:
            stack.append(arr[i][0]*1000+i)
    # if bit == 3:
        # print(tmp,stack,arr,bin(bit))
        # print((abs(arr[1][1]-1)) % 2 , bit >> arr[1][1])
    if len(stack) & 1:
        tmp=1000; stack.pop()
    while stack:
        p=stack.pop(); q=stack.pop()
        if (p-q) & 1:
            tmp+=p-q
            # if bit==3:
                # print(p,q,tmp,mans)
                # print(arr)
        else:
            tmp+=1000
    mans=min(mans,tmp)

print(-1 if mans > 999 else mans)

Measured memory_bytes: 45932
# 2019-11-25 06:26:24(JST)
import sys

def main():
    s, k = sys.stdin.read().split()
    k = int(k)

    if s.count(s[0]) == len(s):
        if len(s) % 2 == 0:
            ans = len(s) // 2 * k
        else:
            if k % 2 == 0:
                ans = len(s) * (k // 2)
            else:
                ans = len(s) * (k // 2) + len(s) // 2
        print(ans)
        sys.exit()

    count = 0
    same = 1
    flag = False 
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            same += 1
        else:
            if not flag: 
                first_same = same
                flag = True 
                # 最初に何文字連続するかだけ記録しておく
                # (最初と最後の文字が同じだった場合の処理のため)
            count += same // 2
            same = 1
    
    bl = False
    if s[-1] == s[0]:
        if same % 2 == 1 and first_same % 2 == 1:
            # ここでのsameは一番最後に連続した文字数
            count += same // 2 + 1
            # この場合は最後だけ調整が必要なので記録しておく
            bl = True
        else:
            count += same // 2
    else:
        count += same // 2

    ans = count * k
    if bl:
        ans -= 1

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
from itertools import groupby

N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
ans=0
X=[[] for i in range(0,K)]
for i in range(0,N):
    X[i%K].append(T[i])
for i in range(0,K):
    X[i]=groupby(X[i])
    for key,group in X[i]:
        g=len(list(group))
        if key=='r':
            ans+=P*((g+1)//2)
        elif key=='s':
            ans+=R*((g+1)//2)
        else:
            ans+=S*((g+1)//2)
print(ans)


Measured memory_bytes: 19956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll money = 1000;
    ll stock = 0;
    for (ll i = 0; i < n; i++) cin >> a[i];
    for (ll i = 0; i < n-1;i++){
        if(a[i]<a[i+1]){
            ll t = money / a[i];
            stock += t;
            money -= t * a[i];
        }
        else if(a[i]>a[i+1]){
            ll t = stock * a[i];
            stock = 0;
            money += t;
        }
        else
            continue;
    }
    cout << money+stock*a[n-1] << endl;
}

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

using namespace std;

typedef long long ll;

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

	int N, K;
	string S;
	cin >> N >> S >> K;

	rep(i, N){
		if(S[i] == S[K-1]) cout << S[i];
		else cout << "*";
	}

	cout << endl;
}


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

vector<int> edge[2001];
int dp[2001][3];
int num[2001];
char op;
void dfs(int x,int p){
	dp[x][1]=dp[x][2]=0;
	dp[x][0]=num[x];
	pair<int,int> tmp=make_pair(0,0);
	for(int i:edge[x]){
		if(i==p)	continue;
		dfs(i,x);
		dp[x][0]+=dp[i][0];
		dp[x][2]+=dp[i][2]+dp[i][0];
		tmp=max(tmp,make_pair(dp[i][2]+dp[i][0],dp[i][1]+dp[i][0]));
	}
	if(tmp.second>dp[x][2]-tmp.first)
		dp[x][1]=tmp.second-(dp[x][2]-tmp.first);
	else
		dp[x][1]=dp[x][2]&1;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>op;
		num[i]=op-'0';
	}
	for(int i=1,x,y;i<n;i++){
		cin>>x>>y;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	int ans = 1e9;
	for(int i=1;i<=n;i++){
		dfs(i,0);
		if(dp[i][1]==0)
			ans=min(ans,dp[i][2]);
	}
	if(ans==1e9)
		cout<<-1<<endl;
	else
		cout<<ans/2<<endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int n, w, h;
    cin >> n >> w >> h;

    vector<pair<int, int> > x2(n), y2(n);
    for(int i=0; i<n; ++i){
        int x, y, d;
        cin >> x >> y >> d;
        x2[i] = make_pair(x - d, x + d);
        y2[i] = make_pair(y - d, y + d);
    }
    sort(x2.begin(), x2.end());
    sort(y2.begin(), y2.end());

    int x = 0;
    int y = 0;
    for(int i=0; i<n; ++i){
        if(x2[i].first <= x)
            x = max(x, x2[i].second);
        if(y2[i].first <= y)
            y = max(y, y2[i].second);
    }

    if(x >= w || y >= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 2580
from __future__ import print_function

o = raw_input()
e = raw_input()

if len(o) - len(e) == 0:
    for i in range(len(o)):
        print (o[i], end='')
        print (e[i], end='')
    print()
else:
    for i in range(len(e)):
        print (o[i], end='')
        print (e[i], end='')
    print (o[len(o)-1], end='')
    print()

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 922337203685477;
ll ans = INF;
ll d[210][210] = {};

int main()
{
    ll n, m, r;
    cin >> n >> m >> r;
    ll rr[r] = {};
    rep(i, r)
    {
        cin >> rr[i];
        rr[i]--;
    }
    sort(rr, rr + r);
    rep(i, n) rep(j, n)
    {
        //if (i != j)
            d[i][j] = INF;
    }
    rep(i, m)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        d[a - 1][b - 1] = c;
        d[b - 1][a - 1] = c;
    }

    for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    bool a = 1;
    ll array[8]={0,1,2,3,4,5,6,7};
    while (a)
    {

        ll temp = 0;
        rep(i, r - 1)
        {
            temp += d[rr[array[i]]][rr[array[i + 1]]];
        }
        ans = min(ans, temp);
        a = next_permutation(array, array + r);
    }

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

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

long long ceil(long long a, long long b){
  return a/b + ((a%b) != 0);
}

int main(){

  long long a[100005], l[100005], r[100005];
  int K;
  cin >> K;
  for(int i=1; i<=K; i++) cin >> a[i];
  l[K] = r[K] = 2;

  for(int i=K-1; i>=0; i--){
    l[i] = 1ll * ceil(l[i+1], a[i+1]) * a[i+1];
    r[i] = 1ll * r[i+1]/a[i+1] * a[i+1] + a[i+1] - 1;
  }

  if(l[0] > r[0]) {
    cout << -1 << endl;
    return 0;
  }
  cout << l[0] << " " << r[0] << endl;
  return 0;
}


Measured memory_bytes: 5980
use std::io;
use std::cmp::Ordering;

fn main() {
    let (a, b) = {
        let i = read::<isize>();
        ((i[0] + 11) % 13, (i[1] + 11) % 13)
    };

    let winner = match a.cmp(&b) {
        Ordering::Equal => "Draw",
        Ordering::Greater => "Alice",
        Ordering::Less => "Bob",
    };

    println!("{}", winner);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N + 1);
  rep(i,1,N + 1) cin >> A[i];

  vector<i64> B(N + 1);
  rev(i, N + 1, 1) {
    i64 sum = A[i];
    for(i64 j = i + i; j <= N; j += i) {
      sum += B[j];
    }
    B[i] = sum & 1;
  }
  cout << count(begin(B), end(B), 1) << endl;
  rep(i,1,N + 1) {
    if(B[i] == 1) cout << i << endl;
  }
}


Measured memory_bytes: 3968
//  SMOKE SHISHA PLAY FIFA  // 
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define lp(start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;

ll n ,m;
vector<ll>adj[100007];
ll ind[100007];
ll dp[100007];
ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

ll fun(ll x)
{
	if(dp[x]!=-1)
	{
		return dp[x];
	}
	for(ll i=0;i<adj[x].size();i++)
	{
		dp[x] = max(dp[x],fun(adj[x][i]) + 1);
	}
	if(dp[x]==-1)
		dp[x]=0;
	return dp[x];
}
int main()
{
	fastio	
	cin >> n >> m;	
	for(ll i=1;i<=m;i++)
	{
		ll u,v;
		cin >> u >> v;
		adj[u].pb(v);
		ind[v]++;
	//	adj[v].pb(u);
	}
	for(ll i=1;i<=n;i++)
	{
		dp[i]=-1;
	}
	ll ans = 0;
	for(ll i=1;i<=n;i++)
	{
		if(ind[i]==0)
		{
			ans = max(ans,fun(i));
		}
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 12032
N, Q = map(int, input().split())
S = str(input())
li = []
cnt = 0

for i in range(N-1):
  if S[i]=='A' and S[i+1]=='C':
    cnt += 1
    li.append(cnt)
  else:
    li.append(cnt)

for i in range(Q):
  l, r = map(int, input().split())
  if l > 1:
    ans = li[r-2] - li[l-2]
  else:
    ans = li[r-2]
  print(ans)


Measured memory_bytes: 11324
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  string a,b,c,d;cin>>a>>b>>c;
  cout<<(char)(a[0]+'A'-'a')<<(char)(b[0]+'A'-'a')<<(char)(c[0]+'A'-'a');
}


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

int main() {
	int N, max= 0; 
	cin >> N;
	for (int i = 1; i < 32; i++) {
		for (int j = 2; j < 10; j++) {
			if (pow(i, j) <= N) {
				if (max < pow(i, j)) max = pow(i, j);
			}
			else break;
		}
		if (pow(i, 2) > N) break;
	}
	cout << max << endl;
}

Measured memory_bytes: 384