akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
#define DRT() int t; si(t); while(t--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//# define M_PI           3.14159265358979323846264338327950288
// DSU
void IO(){
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
}
LL n,k;
VL arr;
bool f(LL mid){
	LL op = 0;
	rep(i,0,n){
		op += (arr[i] + mid-1)/mid  - 1;
	}
	return op <= k;
}
int main(){
	IO();
	cin>>n>>k;
	arr.resize(n);
	rep(i,0,n){
		cin>>arr[i];
	}
	LL l = 1, h = (LL)1e9;
	LL ans;
	while(l <= h){
		LL mid = l + (h-l)/2;
		if(f(mid)){
			ans = mid;
			h = mid - 1;
		}
		else{
			l = mid+1;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4816
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
#include <functional>
using namespace std;

int main() {
	struct Ai
	{
		int h, w;
	};
	int H, W, D, Q, L, R;
	Ai A[100000];
	int a;
	int sum[100000];
	cin >> H >> W >> D;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> a;
			A[a - 1].h = i;
			A[a - 1].w = j;
		}
	}
	for (int i = 0; i < D;i++) {
		sum[i] = 0;
	}
	for (int i = D; i < H*W; i++) {
		sum[i] = sum[i - D] + abs(A[i].w - A[i - D].w) + abs(A[i].h - A[i - D].h);
	}
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> L >> R;
		cout << sum[R-1] - sum[L-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
  ll n, ans = 0;
  cin >> n;
  ans = (1 + n - 1) * (n - 1) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
inpl = lambda: list(map(int,input().split()))
N, X, M = inpl()
hisS = [0] * M
pos = [-1] * M
c = S = hisS[0] = X
pos[X] = 0
for i in range(1, min(M+1,N)):
    c = c * c % M
    S += c
    if pos[c] >= 0:
        prev = pos[c]
        period = i - prev
        q = (N - prev) // period
        r = (N - prev) % period
        if prev == 0 and r == 0:
           ans = (S - hisS[prev]) * q
        else:
            ans = (S - hisS[prev]) * q + hisS[prev+r-1]
        print(ans)
        break
    else:
        hisS[i] = S
        pos[c] = i
else:
    print(S)
    exit()


Measured memory_bytes: 65320
import java.util.*;

class A {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int Q = sc.nextInt();
        final int H = sc.nextInt();
        int S = sc.nextInt();
        int D = sc.nextInt();
        final int N = sc.nextInt();
        S = Math.min(S, 2 * Math.min(H, 2 * Q));
        D = Math.min(D, 2 * S);
        System.out.println((long) N / 2 * D + N % 2 * S);
    }
}
public class Main {
    public static void main(String... args) {
        A.main();
    }
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n;
ll a[maxn];

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

  cin>>n;
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  ll best = 8e18;


  for (ll x: {-1,+1}) {
    ll acc=0;
    ll ans=0;
    if (a[0] == 0) {
      ans = 1;
      acc = x;
    } else {
      if (x*a[0] < 0) {
	acc = x;
	ans = abs(x-a[0]);
      } else {
	acc = a[0];
      }
    }

    ll prev=acc;
    for (int i=1; i<n; i++) {
      acc += a[i];
      ll need = prev>0 ? -1 : +1;
      if (acc == 0) {
	ans++;
	acc = need;
      } else {
	if (need * acc < 0) {
	  ans += abs(acc-need);
	  acc = need;
	}
      }
      prev = acc;
    }

    best = min(best, ans);
  }
  

  cout<<best<<endl;
  return 0;
}
// don't forget to read in the input :^)


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


typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int N;

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

  cin >> N;
  vector<int> c(N-1),s(N-1),f(N-1); //c:かかる時間,s:発車時刻,f:発車間隔
  
  vector<vector<int>> t(N-1);
  
  rep(i,N-1){
    cin >> c[i] >> s[i] >> f[i];
    rep(j,130000){
      t[i].PB(s[i]+j*f[i]);
    }
  }
  
  int time = 0,now = 0;
  
  rep(i,N-1){    //i: iからのスタート(0 ~ N-2)
    //now以降で初めて列車iが発車する時刻を求める
    now = t[i][0];
    for(int j = i+1;j < N - 1;j++){    //j: 通過点(i+1 ~ N-2)
      now += c[j-1];  //
      auto itr = lower_bound(ALL(t[j]),now); //t[j]のなかでnow以上で最小のものを探す
      now = *itr;
    }
    cout << now + c[N-2] << endl;
  }
  cout << 0 << endl;
  
  
}

Measured memory_bytes: 254072
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;

#define ll int64_t
const ll MOD = 1e9 + 7;


int main()
{

  ll n, m;
  cin >>  n;

  vector<long> a(n);
  vector<long> accum(n);
  vector<long> accumR(n);

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i > 0)accum[i] = accum[i - 1] + a[i];
    if (i == 0)accum[i] = a[i];
  }

  long ans = 10000000000;

  for (int i = n - 1; i >= 0 ; --i) {
    if (i == n - 1)accumR[i] = a[i];
    if (i < n - 1)accumR[i] = accumR[i + 1] + a[i];
  }

  for (int i = 0; i < n; ++i) {
    if (i < n - 1) {
      cerr << accum[i]<<"  :   " << accumR[i + 1] <<"  :abs   "<< abs(accum[i] - accumR[i + 1]) <<endl;
      if (abs(accum[i] - accumR[i + 1]) < ans ) {
        ans = abs(accum[i] - accumR[i + 1]);
      }
    }
  }

  //境界条件判定
  // if (abs(0 - accumR[0]) < ans ) {
  //   ans = abs(0 - accumR[0]);
  // }
  // if (abs(accum[n - 1] - 0) < ans ) {
  //   ans = abs(accum[n - 1] - 0);
  // }


  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
				while(true){
					String tmp = scan.nextLine();
					int m,f,r;
					m = Integer.parseInt(tmp.split(" ")[0]);
					f =Integer.parseInt(tmp.split(" ")[1]);
					r = Integer.parseInt(tmp.split(" ")[2]);
					if(m == -1 && f == -1 && r == -1){
						break;
					}
					if(m == -1 || f == -1){
						System.out.println("F");
						continue;
					}
					if(m + f < 30){
						System.out.println("F");
						continue;
					}
					if(m + f >= 30 && m + f < 50){
						if(r >= 50){
							System.out.println("C");
							continue;
						}else{
							System.out.println("D");
							continue;
						}
					}
					if(m + f >= 50 && m + f < 65){
						System.out.println("C");
						continue;
					}
					if(m + f >= 65 && m + f < 80){
						System.out.println("B");
						continue;
					}
					if(m + f >= 80){
						System.out.println("A");
						continue;
					}
				}

    }

}



Measured memory_bytes: 26128
from math import sqrt
from random import randint
def Divisor_Set(n):
    s = set()
    for i in range(1, int(sqrt(n))+2):
        if n%i == 0:
            s.add(i)
            s.add(n//i)
    return s

def main1():
    n = int(input())
    a = list(map(int, input().split()))
    dic = {}
    for x in a:
        if x in dic:
            dic[x] += 1
        else:
            dic[x] = 1
    ans = 0
    a.sort()
    for i in range(n):
        v = a[i]
        if dic[v] > 1:
            continue
        lim = v//2 + 1
        f = True
        for j in range(i):
            if a[j] > lim:
                break
            if a[i] % a[j] == 0:
                f = False
                break
        if f:
            ans += 1
    print(ans)

def main2():
    n = int(input())
    a = list(map(int, input().split()))
    dic = {}
    for x in a:
        if x in dic:
            dic[x] += 1
        else:
            dic[x] = 1
    ans = 0
    for v in a:
        if dic[v] > 1:
            continue
        tmp = Divisor_Set(v)
        tmp.remove(v)
        f = True
        for x in tmp:
            if x in dic:
                f = False
                break
        if f:
            ans += 1
    print(ans)

if __name__ == "__main__":
    if randint(1, 2) == 1:
        main1()
    else:
        main2()


Measured memory_bytes: 134640
#include<stdio.h>
int main()
{
  	int H,N;
    int i=0;
  	scanf("%d %d",&H,&N);
  	int A[N];
  	for(i=0;i<N;i++)
    {
  	scanf("%d",&A[i]);
    }
  	int sum=0;
  	for(i=0;i<N;i++){
      sum=sum+A[i];
    }
  	if(sum<H)
    {
  	printf("No");
    }
  	else
    {
    printf("Yes");
    }
  	return 0;
}


Measured memory_bytes: 512
n = int(input())
x = list(map(int,input().split()))
x_sorted = sorted(x)
mid = n//2
m1 = x_sorted[mid-1]
m2 = x_sorted[mid]
for i in range(n):
    if x[i] <= m1:
        print(m2)
    else:
        print(m1)



Measured memory_bytes: 26180
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools
import heapq

readline = stdin.buffer.readline

INF = 10 ** 10

# M日後まで得られる報酬の合計の最大値
N, M = [int(x) for x in readline().split()]

#Ai日後にBiの金
#AB = [tuple(map(int, readline().split())) for _ in range(N)]

jobs = [[] for _ in range(M+1)]

for _ in range(N):
    A, B = [int(x) for x in readline().split()]
    if A <= M:
        jobs[A].append(B)

# priority queue
pq = [] 

ans = 0

# i = 1 to M
for i in range(1, M+1):
    for job in jobs[i]:
        heapq.heappush(pq, -job)
    
    if(pq):
        ans += -heapq.heappop(pq)

print(ans)   


Measured memory_bytes: 88988
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  vector<int> a(N);
  vector<int> b(M);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  for(int i=0;i<M;i++){
    cin>>b.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  sort(b.begin(),b.end());
  int Z = Y - X;
  bool ok = false;
  for(int i=1;i<=Z;i++){
  if(b.at(0)>=X+i && a.at(0)<X+i){
    ok = true;
  }
  }
  if(ok){
    cout<<"No War"<<endl;
  }
  else{
    cout<<"War"<<endl;
  }
  return 0;
}
    

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def mi(): return map(int, input().split())


def li(): return list(mi())


def li_(): return [int(x) - 1 for x in input().split()]


def lin(n: int): return [input() for _ in range(n)]


def llin(n: int): return [li() for _ in range(n)]


def llin_(n: int): return [li_() for _ in range(n)]


def lli(): return [list(map(int, l.split())) for l in input()]


def inp(): return int(input())


def f(): return float(input())


def s(): return input().replace('\n', '')


def main():
    N = inp()
    h = li()
    dp = [0] * N
    dp[1] = abs(h[0]-h[1])
    for i in range(2, N):
        dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]),
                    dp[i - 2] + abs(h[i - 2] - h[i]))
    print(dp[N-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 52256
H, W = map(int, input().split())
C = [list(map(int, input().split())) for i in range(10)]
G = [list(map(int, input().split())) for i in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])

ans = 0
for row in G:
    for x in row:
        if x >= 0:
            ans += C[x][1]

print(ans)


Measured memory_bytes: 40668
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll A, B, C, D;
  cin >> A >> B >> C >> D;

  if(A + B > C + D)
    cout << "Left" << endl;
  else if(A + B < C + D)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,sum;
  cin >> n;
  sum = 0;
  vector<long long> vec(n);
  for(long long i=0;i<n;i++){
    cin >> vec.at(i);
  }
  for(long long i=0;i<n-1;i++){
    long long h=0;
    if(vec.at(i) > vec.at(i+1)){
      h += vec.at(i)-vec.at(i+1);
      sum += h;
      vec.at(i+1) += h;
    }
  }
  cout << sum << endl;
}

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

int main() {
  int N, A;
  int ans = 10000000;
  
  cin >> N;
  
  for(int i=0; i <N; i++){
    int cnt =0;
    cin >> A;
    while(A%2 ==0){
      A /=2;
      cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
A.sort()
c = Counter(A)
lst = [1] * (10**6+1)
res = 0

for i,a in enumerate(A):
  if lst[a] == 0: continue
  if i==N-1 or A[i+1] != a:
    res += 1
  for j in range(a, 10**6+1, a):
    lst[j] = 0

print(res)


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

using namespace std;

const int N = 200000 + 10;

int a[N];

int main()
{
	int sum, n, i;
	cin>>n;
	sum = 0;
	for (i=0; i<n; i++)
	{
		cin>>a[i];
		sum ^= a[i];
	}
	for (i=0; i<n; i++) cout<<(sum^a[i])<<" ";
	cout<<endl;
	return 0;
}

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

int main()
{
    int n,a,b,minfare=0;
    scanf("%d %d %d",&n,&a,&b);
    if(n<1 || a<1 || b<1)
        return;
    if(n>20 || a>50 || b>50)
        return;
    if(n*a <= b)
        minfare=n*a;
    else
        minfare=b;
    printf("%d",minfare);
    return 0;
}


Measured memory_bytes: 128
while True:
    H,W = (int(x) for x in input().split())
    if H == 0 and W == 0:
        break
    
    for i in range(H):
        if i % 2 == 0:
            for j in range(W):
                if j % 2 == 0:
                    print('#',end='')
                else:
                    print('.',end='')
        else:
            for j in range(W):
                if j % 2 == 0:
                    print('.',end='')
                else:
                    print('#',end='')
        
        print()
        
    print()


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

int main(){
    int n;cin>>n;
    string s;cin>>s;
    string ans="Yes";
    if(n%2==0){
        for(int i=0;i<n/2;i++){
            if(s[i]!=s[i+n/2]){
                ans="No";
                break;
            }
        }
    }
    else ans="No";
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
S = list(input())
s_c = Counter(S)

a = s_c["R"] * s_c["B"] * s_c["G"]

for i in range(N):
    for j in range(i + 1, N):
        k = 2 * j - i
        if k >= N:
            break
        elif (S[i] != S[j] and S[i] != S[k] and S[j] != S[k]) and \
            not (j - i != k - j):
            a -= 1
print(a)

Measured memory_bytes: 68884
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;
string s;
int a[100];
ll ans=0;
int main()
{
	cin>>s;
	for(int i=0;i<pow(2,s.size()-1);i++)
	{
		memset(a,0,sizeof(a));
		ll t=i,cnt=0;
		while(t)
		{
			a[cnt++]=t%2;
			t/=2;
		}
		ll sum=0;
		t=s[0]-'0';
		for(int j=0;j<s.size()-1;j++)
		{
			if(a[j])
			{
				sum+=t;
				t=s[j+1]-'0';
			}else
			t=t*10+(s[j+1]-'0');
		}
		ans+=sum;
		ans+=t;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


int main() {
    ll n;
    cin>>n;

    vector<ll>a(n),L(n),R(n);
    rep(i,n)cin>>a[i];

    L[0]=a[0];
    R[n-1]=a[n-1];


    rep2(i,1,n-1){
        L[i]=L[i-1]+a[i];
    }
    repr(i,n-2,0){
        R[i]=R[i+1]+a[i];
    }

    ll ans=inf;

    rep(i,n-1){
        ans=min(abs(L[i]-R[i+1]),ans);
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 4992
// https://atcoder.jp/contests/abc090/tasks/arc091_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long x, y;
    cin >> x >> y;
    if (x >= 2) {
        x -= 2;
    }
    if (y >= 2) {
        y -= 2;
    }

    cout << x * y << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int N;
      cin >> N;
      int ans=0;
      for(int i=1;i<=N;i++){
        int count=0;
        for(int j=1;j<=i;j++){
         if(i%j==0) count++;
        }
        if(count==8 && i%2==1){
          ans++;
        }
      }
      cout << ans << endl;
      return 0;}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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 int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll ans=INF;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll dp(n+1,n);
  dp[0]=0;
  rep(i,n){
    for(ll pow=1;pow+i<=n;pow*=6) chmin(dp[i+pow],dp[i]+1);
    for(ll pow=1;pow+i<=n;pow*=9) chmin(dp[i+pow],dp[i]+1);
  }
  cout<<dp[n]<<endl;
}

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


int main() {

  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());

  if (s < t)
    cout << "Yes";
  else
    cout << "No" ;
    
  return 0;
}

Measured memory_bytes: 256
/**********************************************************
* @Author: 			   Kirito
* @Date:   			   2020-04-12 20:24:35
* @Last Modified by:   Kirito
* @Last Modified time: 2020-04-12 20:35:12
* @Remark: 
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

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

const int maxn=111111;
char str[maxn];

int main()
{
	FAST;
	int n;
	cin >> n >> str;
	ll r = 0, g = 0, b = 0;
	for(int i = 0; i < n; i++)
	{
		if(str[i] == 'R') r++;
		else if(str[i] == 'G') g++;
		else b++;
	}
	ll ans  = r * g * b;
	for(int d = 1; 2 * d < n; d++)
	{
		for(int i = 0; i + 2 * d < n; i++)
		{
			if(str[i] != str[i + d] && str[i + d] != str[i + 2 * d] && str[i] != str[i + 2 * d])
			{
				ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i, j, k, n;
		Boolean flag = false;
		int[] diceA = new int[6];
		int[] diceB = new int[6];
		Dice d = new Dice();
		try (Scanner sc = new Scanner(System.in)) {
			n = sc.nextInt();
			int[][] dice = new int[n][6];
			for(i = 0; i < n; i++) {
				for(j = 0; j < 6; j++) {
					d.dice_make(j, sc.nextInt());
					dice[i][j] = d.getDice(j);
				}
			}
			for(i = 0; i < n - 1; i++) {
				for(j = i + 1; j < n; j++) {
					for(k = 0; k < 6; k++) {
						diceA[k] = dice[i][k];
						diceB[k] = dice[j][k];
					}
					if(d.compare(diceA, diceB)) {
						flag = true;
					}
				}
			}

			if(flag) {
				System.out.println("No");
			}else {
				System.out.println("Yes");
			}
		}
	}
}
class Dice{
	private int[] dice = new int[6];
	public void dice_make(int i, int dice_spot){
		dice[i] = dice_spot;
	}
	public void rotation(String direction) {
		switch(direction) {
		case "E": dice = new int[] {dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]};break;
		case "N": dice = new int[] {dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]};break;
		case "S": dice = new int[] {dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]};break;
		case "W": dice = new int[] {dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]};break;
		case "T": dice = new int[] {dice[0],dice[3],dice[1],dice[4],dice[2],dice[5]};break;
		default : dice = new int[] {};break;
		}
	}
	public void same(int a, int b) {
		int i = 0;
		for(i = 0; i < 6; i++) {
			if(i % 2 == 0) {
				rotation("E");
			}else {
				rotation("N");
			}
			if(dice[0] == a) {
				for(i = 0; i < 4; i++) {
					rotation("T");
					if(dice[1] == b) {
						return;
					}
				}
			}
		}		
	}
	public boolean compare(int[] diceA, int[] diceB) {
		int i, j, k;
		dice = diceA;
		for(i = 0; i < 6; i++) {
			for(j = 0; j < 4; j++) {
				rotation("T");
				int counter = 0;
				for(k = 0; k < 6; k++) {
					if(dice[k] == diceB[k]) {
						counter++;
					}
				}
				if(counter == 6) {
					return true;
				}
			}
			if(i % 2 == 0) {
				rotation("E");
			}else {
				rotation("N");
			}
		}
		return false;
	}
	public int getDice(int i) {
		return dice[i];
	}
	public int[] getDice_array() {
		return dice;
	}
}


Measured memory_bytes: 36580
#include <iostream>

int ans;
int count(int change)
{
	if(!change)
		return 0;
	if(change >= 500){
		ans += change / 500;
		count(change % 500);
	}
	else if(change >= 100){
		ans += change / 100;
		count(change % 100);
	}
	else if(change >= 50){
		ans += change / 50;
		count(change % 50);
	}
	else if(change >= 10){
		ans += change / 10;
		count(change % 10);
	}
	else if(change >= 5){
		ans += change / 5;
		count(change % 5);
	}
	else if(change >= 1){
		ans += change / 1;
		count(change % 1);
	}
}

int main()
{
	int pay;
	while(1){
		ans=0;
		std::cin >> pay;
		if(!pay)
			break;

		int change = 1000 - pay;

		count(change);

		std::cout << ans << std::endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MOD=1000000007;

int main() {
  int a, b;
  cin >> a >> b;
  cout << max(a+b,max(a-b,a*b)) << endl;
}


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

int N, L[2005];

int main() {
    cin >> N;

    for(int i = 0; i < N; i++)
        cin >> L[i];

    sort(L, L + N);

    int ans = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            for(int k = j + 1; k < N; k++) {
                if(L[i] + L[j] > L[k]) ans++;
            }
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;
    int k = 1, sum = 0;
    while (sum < N) {
        sum += k;
        k++;
    }

    if (sum != N) {
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";
    cout << k << '\n';

    vector<vector<int>> S(k);
    int cnt = 1;
    for (int i = k - 1; i >= 0; --i) {
        for (int j = i - 1; j >= 0; --j) {
            S[i].push_back(cnt);
            S[j].push_back(cnt);
            cnt++;
        }
        cout << k - 1 << ' ';
        for (auto j : S[i])
            cout << j << ' ';
        cout << '\n';
        S.pop_back();
    }

    return 0;
}


Measured memory_bytes: 1792
def main(n: int, w: list) -> None:
    if len(set(w)) != n:
        print("No")
        return

    last_letter = ""

    for w_n in w:
        if last_letter == "":
            last_letter = w_n[-1]
            continue

        if last_letter != w_n[0]:
            print("No")
            return

        last_letter = w_n[-1]

    print("Yes")


if __name__ == "__main__":
    n = int(input())
    w = [input() for _ in range(n)]

    main(n, w)


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

int main()
{
    int q, cmd, v;
    vector<int> vec;

    cin >> q;

    for (int i = 0; i != q; ++i)
    {
        cin >> cmd;

        switch (cmd)
        {
            case 0:
            {
                cin >> v;
                vec.push_back(v);
                break;
            }
            case 1:
            {
                cin >> v;
                cout << vec[v] << endl;
                break;
            }
            case 2:
            {
                vec.pop_back();
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3840
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]

p arr[gets.to_i - 1]

Measured memory_bytes: 1788
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
#include <assert.h>
#include <complex.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define FILL(A,val) memset(A,val,sizeof(A))

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double Pi = acos(-1.0);
const int INF = 1000000000;
const Int INF2 = Int(INF) * 5000;
const Int INF3 = Int(INF) * INF;
const int MAX = 100007;
const int MAXE = 2007000;
const int MAXV = 5000;
const int BASE = 1000000000;
const int ST = 1000000007;

const int MOD = 1000000007;

Int gcd(Int a , Int b)
{
    if (!b) return a;
    return gcd(b , a % b);
}

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


    int t;
    cin >> t;
    FOR(tt,0,t)
    {
        Int a , b , c , d;
        cin >> a >> b >> c >> d;
        if (a < b)
        {
            cout << "No" << endl;
            continue;
        }
        if (d < b)
        {
            cout << "No" << endl;
            continue;
        }
        if (c >= b - 1)
        {
            cout << "Yes" << endl;
            continue;
        }

        Int g = gcd(b , d);

        if (b - 1 - (c + 1) + 1 >= g)
        {
            cout << "No" << endl;
            continue;
        }

        Int l = (c + 1) % g;
        Int r = (b - 1) % g;
        Int x = a % g;

        if (r >= l && x >= l && x <= r)
        {
            cout << "No" << endl;
            continue;
        }
        if (l > r && (x <= r) || (x >= l))
        {
            cout << "No" << endl;
            continue;
        }
        cout << "Yes" << endl;

    }

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
  int N, Y;
  cin >> N >> Y;
  Y /= 1000;
  int a = Y / 10;
  for (int i = 0; i <= a; i ++) {
    for (int j = 0; j <= N - i; j ++) {
      int k = N - i - j;
      if (i * 10 + j * 5 + k == Y) {
        cout << i << ' ' << j << ' ' << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}




Measured memory_bytes: 256
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n;
            cin>>n;
            int flag=0;
            while(n>0)
            {
                if(n%10==7)
                    flag=1;
                n=n/10;
            }
            if(flag)
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

void Main() {
  Cin(string, s);
  if (s[0] != 'A') {
    puts("WA");
    return;
  }
  if (!('a' <= s[1] && s[1] <= 'z')) {
    puts("WA");
    return;
  }
  if (!('a' <= s.back() && s.back() <= 'z')) {
    puts("WA");
    return;
  }
  int C = 0;
  for (int i = 2; i < sz(s) - 1; ++i) {
    if (s[i] == 'C')
      C++;
    else {
      if (!('a' <= s[i] && s[i] <= 'z')) {
        puts("WA");
        return;
      }
    }
  }
  puts(C == 1 ? "AC" : "WA");
  return;
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	string str;
	string str2;
	int ans=0;
	while(cin >> str){
		str2=str;
		reverse(str.begin(),str.end());
		if(str==str2)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 0
from collections import deque
k = int(input())
d = deque([i for i in range(1,10)])

count = 0
while True:
    num = d.popleft()
    count += 1
    if count == k:
        break
    str_num = str(num)
    next_digit_ls = [int(str_num[-1]) - 1, int(str_num[-1]), int(str_num[-1]) + 1]
    for digit in next_digit_ls:
        if 0<= digit <= 9:
            d.append(int(str_num + str(digit)))
print(num)

Measured memory_bytes: 10904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,M;
ll A[100100];
P B[100100];
ll K[100100];
int main(){
	cin >> N >> M;
	for(int i=0;i<N;i++)cin >> A[i];
	ll sum = 0ll;
	ll rem = N;
	for(int i=0;i<M;i++){
		cin >> B[i].sec >> B[i].fi;
	}
	sort(A,A+N);
	sort(B,B+M);
	for(int i=M-1;i>=0;i--){
		for(int j=0;j<min(rem,B[i].sec);j++){
			K[rem-1-j]=B[i].fi;
		}
		rem -= min(rem,B[i].sec);
	}
	reverse(K,K+N);
	ll ans = 0ll;
	for(int i=0;i<N;i++){
		ans += max(A[i],K[i]);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    long long A, B, C, K;
    std::cin >> A >> B >> C >> K;

    if (A >= K) {
        std::cout << K << std::endl;
        return 0;
    }
    else if (K > A && K <= (A + B)) {
        std::cout << A << std::endl;
        return 0;
    }
    else if (K > (A + B) && K <= (A + B + C)) {
        std::cout << A - (K - A - B) << std::endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 3636
n=int(input())
s = [input() for i in range(n)]

ans = 0

for i in range(n):
    for j in range(len(s[i]) - 1):
        if s[i][j] == 'A' and s[i][j+1] == 'B':
            ans += 1


a = 0
b = 0
c = 0
for i in range(n):
    if s[i][0] == 'B':
        a += 1
    if s[i][-1] == 'A':
        b += 1
    if s[i][0] == 'B' and s[i][-1] == 'A':
        c += 1

if c == a == b:
    print(ans + max([0, c - 1]))
else:
    print(ans + min([a, b]))


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define push_back pb
#define make_pair mp
using ll = long long;
const int INF = 0x3f3f3f3f;
const int MAX_N = 2e5+10;

long long N;

void solve()
{
	if(N==1) cout << 0 << endl;
	else{
		N--;
		cout << N*(N+1)/2<< endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define tam 220010
#define offset 220010
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> ii;
typedef pair<double,double> iib;
typedef pair<ll,ii> iii;
typedef pair<map<ll,ll> ,ll> mi;
typedef pair<ii,ii> iiii;
typedef vector<ll> vi;
int findpa(int num,vector<int> &arrpa)
{
    if (arrpa[num]==num)
        return num;
    else return arrpa[num]=findpa(arrpa[num],arrpa);
}
ll cant[tam],ans[tam];
vector<int> grafo[tam];
int  main()
{
    int N,K,L;
    cin>>N>>K>>L;
    int iz,der;
    int pa1,pa2;
    vector<int> arrpa1(N),arrpa2(N);
    forr(i,0,N)
    arrpa2[i]=arrpa1[i]=i;
    forr(i,0,K)
    {
        cin>>iz>>der;iz--,der--;
        pa1=findpa(iz,arrpa1);
        pa2=findpa(der,arrpa1);
        arrpa1[pa1]=pa2;
    }
    forr(i,0,L)
    {
        cin>>iz>>der;iz--,der--;
            pa1=findpa(iz,arrpa2);
            pa2=findpa(der,arrpa2);
        arrpa2[pa1]=pa2;
    }
    forr(i,0,N)
    {
        grafo[findpa(i,arrpa1)].pb(i);
    }
    memset(cant,0,sizeof cant);
    int nodo;
    forr(i,0,N)
    {
        forr(j,0,grafo[i].size())
        {
            nodo=grafo[i][j];
            cant[findpa(nodo,arrpa2)]++;
        }
        forr(j,0,grafo[i].size())
        {
            nodo=grafo[i][j];
            ans[nodo]=cant[findpa(nodo,arrpa2)];
        }
        forr(j,0,grafo[i].size())
            nodo=grafo[i][j],cant[findpa(nodo,arrpa2)]=0;
    }
    forr(i,0,N)
    {
        cout<<ans[i]<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 16512
#include <stdio.h>
#include <string.h>

int LENGTH = 100000;

void reverse(char *s) {
  int len = strlen(s);
  
  for (int i=0; i < len / 2; i ++) {
    char t = s[i];
    s[i] = s[len - 1 - i];
    s[len - 1 -i] =t;
  }
}

int main(void) {

  char S[LENGTH+1];
  char s[4][8] = {"dream","dreamer","erase","eraser"};
  scanf("%s",S);

  int len = strlen(S);
  int t = 0;

  for (int i = 0; i < 4; i++) {
    reverse(s[i]);
  }
  reverse(S);

    while (t < len) {
      int k = -1;
      for (int i=0;i < 4; i++) {
        if (!strncmp(S+t,s[i],strlen(s[i]))) {
          k = strlen(s[i]);
          break;
        }
      }
      if ( k < 0 ) {
        printf("NO");
        return 0;
      }
      t += k;
    }
    printf("YES");
    return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    int n;
    string s;
    cin>>n>>s;

    if( n%2 == 1 )
        cout<<"No\n";
    else
    {
        int half = n/2, f = 0;
        for(int i=0;i<half;i++)
        {
            if( s[i] != s[half+i] )
            {
                f = 1;
                break;
            }
        }
        puts( f ? "No" : "Yes" );
    }

    return 0;
}

Measured memory_bytes: 256
s = list(input())
q = int(input())
ss = list()
flip = False
for i in range(q):
    tfc = input()
    if tfc[0] == '1':
        flip = not flip
    else:
        if flip:
            if tfc[2] == '1':
                s.append(tfc[4])
            else:
                ss.append(tfc[4])
        else:
            if tfc[2] == '1':
                ss.append(tfc[4])
            else:
                s.append(tfc[4])
ss.reverse()
s = ss + s
if flip:
    s.reverse()
print("".join(s))

Measured memory_bytes: 7836
N,K = map(int, input().split())
As  = list(map(int, input().split()))
# 約数
As = sorted(As)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

divs = sorted(make_divisors(sum(As)),reverse=True)

from itertools import accumulate
for div in divs:
    # 足す側と引かれる側を分け
    # 小さい順にソートして、足し引きのプラマイが0になれば良い。
    # ただし、足す大きさ(=引く大きさ)がKを超えるといけない
    bs_plus = sorted([a%div for a in As])
    bs_minus = [(div-a)%div for a in bs_plus]
    acc_bs_p = list(accumulate(bs_plus))
    acc_bs_m = list(accumulate(bs_minus))
    for i in range(N):
        plus = acc_bs_p[i]
        minus = acc_bs_m[N-1]-acc_bs_m[i]
        if plus == minus and plus <= K:
            # print("ok",div,plus,minus)
            print(div)
            exit(0)
        


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

int W, H;
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

void dfs(int h, int w, vector<vector<int>> &G, vector<vector<bool>> &S)
{
    // printf("h = %d, w = %d\n", h, w);
    S[h][w] = true;
    rep(i, 8)
    {
        int nh = h + dy[i];
        int nw = w + dx[i];
        if (nh < 0 || nh >= H || nw < 0 || nw >= W)
            continue;
        if (G[nh][nw] == 0 || S[nh][nw])
            continue;
        dfs(nh, nw, G, S);
    }
}

int main()
{
    while (cin >> W >> H)
    {
        if (W == 0 && H == 0)
            break;
        vector<vector<int>> G(H, vector<int>(W));
        vector<vector<bool>> S(H, vector<bool>(W));
        rep(h, H)
        {
            rep(w, W)
            {
                cin >> G[h][w];
            }
        }
        int ans = 0;
        rep(h, H)
        {
            rep(w, W)
            {
                if (G[h][w] == 1 && !S[h][w])
                {
                    dfs(h, w, G, S);
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3348
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	SA, _ := reader.ReadString(' ')
	SB, _ := reader.ReadString('\n')
	A, _ := strconv.Atoi(SA[:len(SA)-1])
	B, _ := strconv.Atoi(SB[:len(SB)-1])

	n := (B - 1) / (A - 1)
	if (B-1)%(A-1) > 0 {
		n++
	}
	fmt.Println(n)
}


Measured memory_bytes: 640
#ifdef _MSC_VER
#  define _CRT_SECURE_NO_WARNINGS
#  define _USE_MATH_DEFINES
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double;
using u32 = unsigned int; using u64 = unsigned long long int; using str = string;
template <typename T> using vec = vector<T>; void in() { }
template <typename T, typename...TS> void in(T &&x, TS &&...xs) { cin >> x; in(move(xs)...); }
template <typename T> void out(T &&x) { cout << x << "\n"; }
template <typename T, typename...TS> void out(T &&x, TS &&...xs) { cout << x << " "; out(move(xs)...); }
#define indef(t, ...) t __VA_ARGS__; in(__VA_ARGS__)
#define get(t) []{ t x; cin >> x; return x; }()
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define even(x) ((abs(x) & 1) == 0)
#define odd(x) ((abs(x) & 1) == 1)
#define bit(x, i) (((x) >> i) & 1)
#define append emplace_back
#define bisect_left lower_bound
#define bisect_right upper_bound
#define bound(a, x, b) (a <= x && x <= b)
const i64 MOD = 1000000007ll;
const f64 EPS = 1e-10;

template <typename T> T gcd(T a, T b) { while (b!=0) { swap(a, b); b = b%a; } return abs(a); }

bool solve() {
    indef(i32, n, k);
    vec<i32> a(n);
    times(n, i) {
        in(a[i]);
        if (a[i] == k) return true;
    }
    sortall(a);
    if (a[n-1] < k) return false;

    i32 g = a[0];
    times(n, i) {
        g = gcd(g, a[i]);
    }
    return (k % g) == 0;
}

i32 main()
{
    ios::sync_with_stdio(false);

#ifdef _MSC_VER
    /**
    ifstream fin("input.txt"); cin.rdbuf(fin.rdbuf()); assert(fin);
    ofstream fout("output.txt"); cout.rdbuf(fout.rdbuf()); assert(fout);
    /**/
#endif

    cout << fixed << setprecision(9);
    out(solve() ? "POSSIBLE" : "IMPOSSIBLE");

    return 0;
}

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

#define FOR(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define all(x) (x).begin(),(x).end()

int main(){
  int n;
  cin >>n;
  vec<int> d(n);
  REP(i,n) cin >>d[i];

  set<int> values;
  REP(i,n) values.insert(d[i]);

  cout <<values.size() <<endl;
}


Measured memory_bytes: 256
def main
  # b**p <= 1000
  # の場合、最大の b は31

  base_nums = (1..31).to_a

  lim = ARGF.gets.to_i
  # puts("Error") if n <= 0

  max_num = 1
  base_nums.each do |n|

    2.upto(10) do |p|
      cur = n**p
      break if lim < cur

      if max_num < cur
        max_num = cur
      end
    end
  end

  puts max_num
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 1788
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int x = int.Parse(Console.ReadLine());
			int a = int.Parse(Console.ReadLine());
			int b = int.Parse(Console.ReadLine());

			x -= a;
			int ans = x % b;
			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 13140