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

const int mod = 1e9 + 7;

vector<int> mem;
int Pow(int a, int b) {
    if (b < 0) return 0;
    if (b == 0) return 1;
    if (mem[b]) return mem[b];

    int ret = 3 * Pow(a, b - 1) % mod;
    return mem[b] = ret;
}
signed main() {
    string S;
    cin >> S;

    const int n = S.size();
    mem.resize(n + 1);
    Pow(3, n);

    vector<int> a(n), c(n), l(n), r(n);
    for (int i = 0; i < n; i++) {
        a[i] = a[i - !!i] + (S[i] == 'A');
        l[i] = l[i - !!i] + (S[i] == '?');

        int idx = n - i - 1;
        c[idx] = c[idx + !!i] + (S[idx] == 'C');
        r[idx] = r[idx + !!i] + (S[idx] == '?');
    }

    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
        if (S[i] != 'B' && S[i] != '?') continue;
        ans += a[i - 1] * c[i + 1] * Pow(3, l[i - 1] + r[i + 1]) % mod; // ABC
        ans += a[i - 1] * r[i + 1] * Pow(3, l[i - 1] + r[i + 1] - 1) % mod; // AB?
        ans += l[i - 1] * c[i + 1] * Pow(3, l[i - 1] + r[i + 1] - 1) % mod; // ?BC
        ans += l[i - 1] * r[i + 1] * Pow(3, l[i - 1] + r[i + 1] - 2) % mod; // ?B?
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

ll min(ll a,ll b)
{
    if (a<b)
    {
        return a;
    }
    return b;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k;
    cin>>n>>k;
    cout<<min(n%k,k-(n%k));
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = input().split()
# print(A)
A_list = list(map(float, A))
sa = 0
for i in range(N-1):
    # print(i)
    if A_list[i] > A_list[i+1]:
        sa += A_list[i] - A_list[i+1]
        A_list[i+1] = A_list[i]
print(int(sa))


Measured memory_bytes: 32272
/*
ID: alec3
LANG: C++14
PROG:
*/


#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define all(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

int pct(int x) { return __builtin_popcount(x); }



using namespace std;


int main()
{
    io;
    string n;
    cin >> n;

    int s = 0;
    for (int i= 0; i < n.size(); i++)
        s += (n[i] - '0');

    if (s % 9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;



    return 0;

}


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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD   = 1e9 + 7;
const double PI = acos(-1.0);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
const int INF   = 1e18;

#define fastio            ios_base::sync_with_stdio(false);cin.tie(0)
#define sz(a) int((a).size())
#define rsz resize
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define f first
#define s second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define spc " "
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

void solve(){

    int x;
    cin >> x;
    x = 1 - x;
    cout << x << endl;
}

signed main(){
    fastio;

    solve();

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FOR(a,b,c) for(int a = (b); a <= (c); a++)
#define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
#define all(x) (x).begin(), (x).end()
#define vi vector <int>
#define vvi vector <vi>
#define ll long long
#define vll vector <ll>
#define vvl vector <vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ep emplace
#define fs first
#define sd second
#define mod 998244353
using namespace std;

int main() {
	FIO;
	ll a, b;
	cin >> a >> b;
	if (min(a, b) == 1) return cout << 1 << '\n', 0;
	ll ans = 0;
	ans += (a / 2) * b;
	if (a & 1) ans += (b + 1) / 2;
	cout << ans << '\n';
	return 0;
}

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

int main(){
	string t;
  	cin >> t;
  	int ans = 0, ctr = 0;
  	for(int i=0; i<t.size(); i++){
    	if(t[i] == 'R'){
     		ctr++;     
        }
      	else {
          	ctr = 0;
        }
      	if(ctr > ans){
          	ans = ctr;
        }
    }
  	cout << ans << endl;
    return 0;
}

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

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

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

int main(){
  long N, M, a;
  vector<long> A;
  cin >> N >> M;
  for(int i=0; i<N; i++){
    long a; cin >> a;
    A.push_back(a);
  }
  long count=0;
  long tmp=A[0];
  while(tmp>0 && tmp%2==0){
    tmp/=2;
    count++;
  }
  for(int i=1; i<N; i++){
    long c=0;
    tmp = A[i];
    while(tmp>0 && tmp%2==0){
      tmp/=2;
      c++;
    }
    if(c!=count){
      cout << '0' << endl;
      return 0;
    }
  }
  for(int i=0; i<N; i++){
    A[i]/=2;
  }
  long l=1;
  for(int i=0; i<N; i++){
    l = lcm(l,A[i]);
  }
  long ans = M/l;
  if(ans%2==0){
    cout << ans/2 << endl;
    return 0;
  }
  cout << (ans+1)/2 << endl;
  return 0;
}

Measured memory_bytes: 1400
from sys import stdin

n = int(input())
a = stdin.read().splitlines()
b = [[int(i) for i in line.split()] for line in a]

d, f, g = b[0]  # -> ends with activity 1,2,3 respectively

for i in range(1, n):
    d, f, g = max(f, g) + b[i][0], max(d, g) + b[i][1], max(d, f) + b[i][2]

print(max(d, f, g))


Measured memory_bytes: 89492
# -*- coding: utf-8 -*-

text = map(str, raw_input().split())
for i in range(len(text)):
    if "apple" in text[i]:
        text[i] = text[i].replace("apple", "peach")
    elif "peach" in text[i]:
        text[i] = text[i].replace("peach", "apple")
print " ".join(map(str, text))

Measured memory_bytes: 6436
N,M = map(int, input().split())
X = [int(x) for x in input().split()]

num = [0]*(max(X)+1)
R = [0]*M
for x in X:
    num[x] += 1
    R[x%M] += 1

ans = R[0]//2
for i in range(1, M//2+1):
    ans += min(R[i], R[M-i])
if M%2 == 0:
    ans -= R[M//2]-R[M//2]//2

for i in range(len(num)):
    if num[i] < 2 or i%M == 0:
        continue
    d = R[i%M]-R[M-i%M]
    if d < 2:
        continue
    t = min(d, num[i])//2
    ans += t
    R[i%M] -= 2*t

print(ans)

Measured memory_bytes: 20628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M){
    if(N==M){
        cout << YES << endl;
    }else{
        cout << NO << endl;
    }

}

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


Measured memory_bytes: 256
def main():
    cells, can_jump = [int(x) for x in input().split()]
    jumps_from = [int(x) - 1 for x in input().split()]
    score_on = [int(x) for x in input().split()]

    ans = - 10**10
    for start in range(cells):
        route = []
        position = start
        while True:
            route.append(score_on[position])
            position = jumps_from[position]
            if position == start:  # Looped
                break

        length = len(route)
        total = sum(route)
        accum_tmp = 0
        for jumping, score in enumerate(route):
            accum_tmp += score
            if jumping + 1 > can_jump:
                break
            accum = accum_tmp
            if total > 0:
                accum += total * ((can_jump - (jumping + 1)) // length)
            ans = max(ans, accum)
    return ans


if __name__ == '__main__':
    ans = main()
    print(ans)


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

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

    int n;
    cin >> n;

    queue<int> q;

    ll sum = 0;

    rep(i,n) {
        int a;
        cin >> a;
        sum += ll(a);
        q.push(a);
    }

    ll sunuke = 0;
    ll arai = sum;
    // ll ans = abs(arai-sunuke);
    ll ans = 1e16;

    while((int)q.size() > 1) {
        sunuke += q.front();
        arai -= q.front();
        q.pop();
        ans = min(ans, abs(arai - sunuke));
    }

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

Measured memory_bytes: 3956
#064_D
n = int(input())
s = input()

right = 0
left = 0
for i in range(n):
    if s[i] == '(':
        left += 1
    else:
        right += 1
        
        if left > 0:
            right -= 1
            left -= 1
            
print('(' *right + s + ')'* left)

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int n, m; scanf("%d %d", &n, &m);
  vector<ll> X(n), Y(m);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &X[i]);
  }
  for (int i = 0; i < m; ++i) {
    scanf("%lld", &Y[i]);
  }

  ll val1 = 0;
  for (int i = 0; i < n; ++i) {
    val1 += (2 * i + 1 - n) * X[i];
    val1 %= MOD;
  }
  ll val2 = 0;
  for (int i = 0; i < m; ++i) {
    val2 += (2 * i + 1 - m) * Y[i];
    val2 %= MOD;
  }
  ll ans = (val1 * val2) % MOD;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<algorithm>
#include<deque>
#include<cstdio>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 80100;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
inline int getint2() {
	int pn = 1;
	if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
	int A = ct - '0';
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return pn * A;
}

ll dat[10200];
bool yatta[5000];
int P[5000], C[5000];

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


	fread(cn, 1, cm, stdin);

	int N = getint(), K = getint();
	rep(i, N) P[i] = getint() - 1;
	rep(i, N) C[i] = getint2();

	ll kotae = -2e18;
	rep(i, N) if (!yatta[i]) {
		int L = 0;
		auto kari = dat;
		kari[0] = 0;
		int j = i;
		while (!yatta[j]) {
			yatta[j] = 1;
			kari[L + 1] = kari[L] + C[j];
			L++;
			j = P[j];
		}
		ll hue = kari[L];
		for (int j = L + 1; j <= L + L; j++) {
			kari[j] = kari[j - L] + hue;
		}
		ll amari = K % L;
		ll wari = K / L;
		if (hue > 0) {
			if (amari > 0) {
				deque<int> dq;
				rep1(i, L + amari - 1) {
					while (dq.size() && kari[dq.back()] <= kari[i]) dq.pop_back();
					dq.push_back(i);
					if (i < amari) continue;
					while (dq.size() && dq.front() <= i - amari) dq.pop_front();
					chmax(kotae, hue * wari + kari[dq.front()] - kari[i - amari]);
				}
			}			
			if (wari > 0) {
				deque<int> dq;
				rep1(i, L + L - amari - 1) {
					while (dq.size() && kari[dq.back()] <= kari[i + amari]) dq.pop_back();
					dq.push_back(i + amari);
					if (i < L - amari) continue;
					while (dq.size() && dq.front() <= i + amari - L) dq.pop_front();
					chmax(kotae, hue * (wari - 1) + kari[dq.front()] - kari[i + amari - L]);
				}
			}
		}
		else {
			deque<int> dq;
			int are = min(K, L);
			rep1(i, L + are - 1) {
				while (dq.size() && kari[dq.back()] <= kari[i]) dq.pop_back();
				dq.push_back(i);
				if (i < are) continue;
				while (dq.size() && dq.front() <= i - are) dq.pop_front();
				chmax(kotae, kari[dq.front()] - kari[i - are]);
			}
		}
	}

	printf("%lld\n", kotae);


	Would you please return 0;
}

Measured memory_bytes: 3384
N,M = list(map(int,input().split()))
V = 10**9 + 7
a = [int(input()) for _ in range(M)]
A =set(a)
ANS = [0 for _ in range(N+2)]

ANS[0] = 1
for i in range(N):
    ANS[i]%= V
    if not i+1 in A:
        ANS[i+1] += ANS[i]
    if not i+2 in A:
        ANS[i+2] += ANS[i]

print(ANS[N]% V)

Measured memory_bytes: 13216
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;
ll N;
ll ans;

void func(ll cur,int use, ll &counter){
    if(cur > N) return;
    if(use == 0b111) ++counter;
    func(cur*10+7,use | 1,counter);
    func(cur*10+5,use | 2,counter);
    func(cur*10+3,use | 4,counter);
}

int main(){
  cin >> N;
  //cur：現在の値 use : どれを使ったか,counter：個数
  ll res = 0;
  func(0,0,res);
  cout << res << endl;
}

Measured memory_bytes: 256
from math import factorial
from collections import Counter
def combination(a,b):
    if a < b:
        a, b = b, a
    comb = 1
    for i in range(b):
        comb *= a-i
    comb //= factorial(b)
    return comb

N, A, B = map( int, input().split())
V = list( map( int, input().split()))
V.sort(reverse = True)
print( sum(V[:A])/A)
S = list( set(V))
S.sort(reverse = True)
CV = Counter(V)
ans = 0
K = CV[S[0]]
if A <= K:
    for i in range(A, min(K, B)+1):
        ans += combination(K, i)
else:
    cnt = A
    for x in S:
        if cnt <= CV[x]:
            ans += combination(CV[x],cnt)
            break
        else:
            cnt -= CV[x]
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	vector<int>V;
	for (int i = 2; i <= min(A,B); ++i) {
		if (A%i == 0 && B%i == 0) {
			V.push_back(i);
		}
	}
	V.push_back(1);
	sort(V.begin(), V.end(),greater<int>());
	cout << V[K - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>


int main() {
	int N;
	double ans = 0;

	std::cin >> N;

	double a;

	for (int i = 0; i < N; i++) {
		std::cin >> a;

		ans += 1 / a;

	}

	std::cout << 1 / ans << std::endl;


}

Measured memory_bytes: 256
L=[x for x in input()]
r=0
acount=0
for i in range(len(L)-2):
    if L[i]=="A":
        acount+=1
        if L[i:i+3]==["A","B","C"]:
            r+=acount
            L[i+2]="A"
            acount-=1
        elif L[i+1]!="A":
            acount=0
    
print(r)


Measured memory_bytes: 5096
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265359

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ld a, b, x;
  cin >> a >> b >> x;
  ld max_v2 = a * a * b / 2.0;
  ld ans;
  if(x >= max_v2) {
    ld x2 = x - max_v2;
    ld l = (max_v2 - x2) * 2.0 / (a * a);
    ans = (atan2(l, a) * 180.0 / PI);
  } else {
    ld a2 = 2.0 * x / (a * b);
    ans = (atan2(b, a2) * 180.0 / PI);
  }
  cout << fixed << setprecision(15) << ans << endl;
  return 0;
}


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

int main() {
  ll n;cin>>n;
  ll mod=1e9+7,cnt1=1,cnt2=1,cnt3=1;
  rep(i,n){
    cnt1*=10;
    cnt1%=mod;
    cnt2*=9;
    cnt2%=mod;
    cnt3*=8;
    cnt3%=mod;
  }
  ll ans=cnt1-2*cnt2%mod+cnt3;
  if(ans<0)ans+=mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
 
int main() {
    int n, m;
    int in[10010][2];
    bool a[10010];
    bool b[10010];
 
    while(cin >> n >> m, n | m) {
        for(int i = 0; i < 10010; i++) {
            a[i] = false;
            b[i] = false;
        }
 
        for(int i = 0; i < m; i++) {
            cin >> in[i][0] >> in[i][1];
        }
 
        for(int i = 0; i < m; i++) {
            if(in[i][0] == 1) {
                a[in[i][1]] = true;
            }
            else if(in[i][1] == 1) {
                a[in[i][0]] = true;
            }
        }
 
        for(int i = 0; i <= n; i++) {
            if(a[i]) {
                b[i] = true;
                for(int j = 0; j < m; j++) {
                    if(in[j][0] == i) {
                        b[in[j][1]] = true;
                    }
                    else if(in[j][1] == i) {
                        b[in[j][0]] = true;
                    }
                }
            }
        }
 
        int ans = 0;
        for(int i = 2; i <= n; i++) {
            if(b[i]) {
                ans++;
            }
        }
 
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3128
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long output = 1;
        boolean[] use = new boolean[1000];
        use[0]=true;
        long tmp=0;
        for(int i=0;i<n;i++){
            if(use[i])continue;
            for(int j=i;j<1000;j+=(i+1)){
                use[j]=true;
            }
            for(int j=1;j<Math.log(1000)/Math.log(i+1);j++){
                tmp+=n/Math.pow(i+1, j);
            }
            output*=tmp+1;
            output%=1000000007;
            tmp=0;
        }
        System.out.println(output);
    }
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
const int inf = pow(2, 31) - 1;
long long cnt;
void merge(int a[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    int l[n1 + 1], r[n2 + 1];
    rep(i,n1)l[i] = a[i + left];
    rep(i,n2)r[i] = a[i + mid];
    l[n1] = inf;
    r[n2] = inf;
    int i = 0, j = 0 ;
    REP(k,left, right){
        if(l[i] <= r[j]){
            a[k] = l[i];
            i++;
        }else {
            cnt += n1 - i;
            a[k] = r[j];
            j++;
        }
    }
}
void merge_sort(int a[], int left, int right){
    int mid = (left + right) / 2;
    if(left + 1 < right){
        merge_sort(a, left, mid);
        merge_sort(a, mid, right);
        merge(a, left, mid, right);
    }
}

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    merge_sort(a, 0, n);
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=105,INF=1<<30;

struct data{
    int h;
    int w;
    int d;
    int f;
    int r;
};

bool can[MAX][MAX][7][7][7];
vector<data> G[MAX][MAX][7][7][7];

int S[MAX][MAX];
int H,W;

void DFS(data u,data p){
    for(data to:G[u.h][u.w][u.d][u.f][u.r]){
        if(to.h==p.h&&to.w==p.w&&to.d==p.d&&to.f==p.f&&to.r==p.r) continue;
        
        if(to.h<0||to.h>=H||to.w<0||to.w>=W) continue;
        
        if(to.d!=S[to.h][to.w]) continue;
        
        if(can[to.h][to.w][to.d][to.f][to.r]) continue;
        
        can[to.h][to.w][to.d][to.f][to.r]=1;
        DFS(to,u);
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>H>>W;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            char c;cin>>c;
            if(c=='#') S[i][j]=0;
            else S[i][j]=c-'0';
        }
    }
    
    can[0][0][6][2][3]=1;
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int d=1;d<=6;d++){
                for(int f=1;f<=6;f++){
                    for(int r=1;r<=6;r++){
                        if(d==f) continue;
                        if(d==r) continue;
                        if(f==r) continue;
                        
                        G[i][j][d][f][r].push_back({i+1,j,f,7-d,r});
                        G[i][j][d][f][r].push_back({i,j+1,r,f,7-d});
                        G[i][j][d][f][r].push_back({i-1,j,7-f,d,r});
                        G[i][j][d][f][r].push_back({i,j-1,7-r,f,d});
                    }
                }
            }
        }
    }
    
    DFS({0,0,6,2,3},{-1,-1,-1,-1,-1});
    
    bool ok=false;
    
    for(int f=1;f<=6;f++){
        for(int r=1;r<=6;r++){
            if(can[H-1][W-1][S[H-1][W-1]][f][r]) ok=true;
        }
    }
    
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}




Measured memory_bytes: 206176
#include<iostream>
#include<string>
#include<map>
#include<vector>

using namespace std;

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

Measured memory_bytes: 256
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    edge_list = [li() for _ in range(n - 1)]
    c_list = li()

    tree_dict = {}
    for edge in edge_list:
        if edge[0] not in tree_dict:
            tree_dict[edge[0]] = [edge[1]]
        else:
            tree_dict[edge[0]].append(edge[1])
        if edge[1] not in tree_dict:
            tree_dict[edge[1]] = [edge[0]]
        else:
            tree_dict[edge[1]].append(edge[0])

    dim1_list = []
    for key, value in tree_dict.items():
        if len(value) == 1:
            dim1_list.append(key)

    c_list.sort()

    score = sum(c_list) - c_list[-1]
    cost_dict = {}
    # print(dim1_list)
    # print(tree_dict)
    # print(cost_dict)
    # print()
    for c in c_list[:-1]:
        node = dim1_list.pop()
        cost_dict[node] = c
        connected = tree_dict[node][0]
        tree_dict[connected].remove(node)
        if len(tree_dict[connected]) == 1:
            dim1_list.append(connected)
    node = dim1_list.pop()
    cost_dict[node] = c_list[-1]

    print(score)
    for i in range(1, n):
        print(cost_dict[i], end=" ")
    print(cost_dict[n])


Measured memory_bytes: 7820
#include <bits/stdc++.h>
using namespace std;
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define pii pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (ll i = a; i <= (ll)b; ++i)
#define per(i, a, b) for (ll i = a; i >= (ll)b; --i)
#define ll long long
#define lowbit(x) ((x) & (-x))
#define debug(...) fprintf(stderr, __VA_ARGS__)
inline int __gcd(int a,int b) {return b>0 ? __gcd(b,a%b):a;}

const int mod=1e9+7;
const int maxn=1e5+5;

void solve()
{
    int a,b,c; cin>>a>>b>>c;
    swap(a,b); swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<"\n";
}
int main()
{
    #ifndef local
    IOS
    #endif
    cout<<fixed<<setprecision(10);
    int t=1; 
    //cin>>t; 
    while(t--) {
        solve();
    }
}




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

int main(){
	int N, i;
	cin >> N;
	int p[N], sum=0, Max=0;
	for(i=0; i<N; i++){
		cin >> p[i];
		sum+=p[i];
		if(Max<p[i])	Max=p[i];
	}
	
	cout << sum-Max/2 << endl;
	return 0;
}


Measured memory_bytes: 256
#import numpy as np
#from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def array(size, init=0):
    return [[init for j in range(size[1])] for i in range(size[0])]


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


def permutate(x, A):
    n = len(x)
    res = [-1]*n
    for i in range(n):

        res[i] = x[A[i]]
    return res


def generate_bin(digit):
    for b in range(2**digit):
        b = bin(b)
        tmp = b[2:].zfill(digit)
        yield list(map(int, tmp))
        # b=list(map(int,list(b[2:].zfill(digit))))
        # yield b


H, W, M = acinput()

Bh = [[0, i] for i in range(H+1)]
Bw = [[0, i] for i in range(W+1)]
B = {}
for i in range(M):
    h, w = acinput()
    Bh[h][0] += 1
    Bw[w][0] += 1
    B[(h, w)] = 1

Bh = sorted(Bh,  reverse=True)
Bw = sorted(Bw,  reverse=True)

Hidx = []
Widx = []
k = 0
while True:
    Hidx.append(k)
    if Bh[k][0] > Bh[k+1][0]:
        break
    k += 1
    if k >= len(Bw):
        break

k = 0
while True:
    Widx.append(k)
    if Bw[k][0] > Bw[k+1][0]:
        break
    k += 1
    if k >= len(Bw):
        break

""" print(Bh)
print(Hidx)
print(Bw)
print(Widx) """

for hi in Hidx:
    h = Bh[hi][1]
    for wi in Widx:
        w = Bw[wi][1]
        if not((h, w) in B):
            res = Bh[0][0]+Bw[0][0]
            print(res)
            #print(h, w)
            sys.exit()


print(Bh[0][0]+Bw[0][0]-1)

# print("cross")

'''
h=0
w=0
while True:
    if not((h, w) in B) or Bh[h] > Bh[h + 1] or Bw[w] > Bw[w + 1]:
        res=Bh[h]+Bw[w]+a
        break

    res=Bh[h]+Bw[w]+1
    
'''


Measured memory_bytes: 212564
object Main extends App {
  val (r, d, x) = scala.io.StdIn.readLine.split(' ').map(_.toInt) match { case Array(ir, id, ix) => (ir, id, ix) }

  (1 to 10).foldLeft(Seq.empty[Int])((results, i) => results :+ (r * results.lastOption.getOrElse(x) - d)).foreach(println)
}


Measured memory_bytes: 27076
#include <stdio.h>

int main()
{
    int a, b;
    char op;
    scanf("%d %c %d", &a, &op, &b);
    while (op != '?')
    {
        switch (op)
        {
        case '+':
            printf("%d\n", a + b);
            break;
        case '-':
            printf("%d\n", a - b);
            break;
        case '*':
            printf("%d\n", a * b);
            break;
        case '/':
            printf("%d\n", a / b);
            break;
        }
        scanf("%d %c %d", &a, &op, &b);
    }
    return 0;
}


Measured memory_bytes: 2040
w = input()

d = {}

for i in range(len(w)):
  if not(w[i] in d):
    d.setdefault(w[i], 1)
    
  elif w[i] in d :
    d[str(w[i])] += 1
    
c = 0
for i in d.values():
  if i % 2 ==0:
    c +=1
    

    
if c == len(d):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>

constexpr int X = 1 << 20;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> cnt(X + 1, 0);
    cnt[0] = 1;
    int low = 0;
    while (n--) {
        int x;
        std::cin >> x;
        x = std::min(x, X);

        if (x < low) {
            std::cout << "No" << std::endl;
            continue;
        }

        std::cout << "Yes" << std::endl;

        int y = x;
        while (cnt[y] == 0) --y;
        --cnt[y];
        while (y < x) {
            ++y;
            ++cnt[y];
        }

        while (low <= X && cnt[low] == 0) ++low;
    }
}

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

    solve();

    return 0;
}



Measured memory_bytes: 7060
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main() {
    long long l, r; cin >> l >> r;
    long long ans = 0;
    // x ⊂ y
    // (0, 0), (0, 1), (1, 1)
    for (int k = 0; k < 62; k++) {
        long long c = 1LL << k;
        long long d = 1LL << (k+1);
        if (l >= d || c > r) continue;
        long long dp[k+1][4];
        // 0: l < curr && r > curr, 1: l <= curr, 2: r >= curr
        memset(dp, 0, sizeof(dp));
        int s = 0;
        if (c <= l && l < d) s += 1 << 0;
        if (c <= r && r < d) s += 1 << 1;
        dp[k][s]++;
        long long prev = ans;
        for (int i = k-1; i >= 0; i--) {
            if (i < 0) continue;
            bool lb = l & (1LL << i);
            bool rb = r & (1LL << i);
            
            // dp[i+1][0]
            dp[i][0] += dp[i+1][0] * 3 % mod;
            
            // dp[i+1][1]
            if (lb) {
                dp[i][1] += dp[i+1][1];
            } else {
                dp[i][0] += dp[i+1][1];
                dp[i][1] += dp[i+1][1] * 2 % mod; 
            }
            
            // dp[i+1][2]
            if (rb) {
                dp[i][2] += dp[i+1][2] * 2 % mod;
                dp[i][0] += dp[i+1][2];
            } else {
                dp[i][2] += dp[i+1][2];
            }
            
            // dp[i+1][3]
            if (lb == rb) {
                dp[i][3] += dp[i+1][3];
            } else if (rb) {
                dp[i][1] += dp[i+1][3];
                dp[i][2] += dp[i+1][3];
                dp[i][3] += dp[i+1][3];
            }
        }

        for (int j = 0; j < 4; j++) {
            ans = (ans + dp[0][j]) % mod;
        }
    }

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

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

using namespace std;

#define int 		long long
#define endl		"\n"
#define mod			1000000007
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

	IOS;

	int n, w;
	cin >> n >> w;

	vector<vector<int>> v(n, vector<int>(2));

	for (int i = 0; i < n; i++)
		cin >> v[i][0] >> v[i][1];

	sort(v.begin(), v.end());
	vector<vector<int>> dp(w + 1, vector<int>(n + 1));

	for (int i = 1; i <= w; i++) {
		for (int j = 1; j <= n; j++) {
			if (v[j - 1][0] > i)
				dp[i][j] = dp[i][j - 1];
			else
				dp[i][j] = max(dp[i][j - 1], v[j - 1][1] + dp[i - v[j - 1][0]][j - 1]);
		}
	}

	cout << dp[w][n] << endl;
	return 0;
}

Measured memory_bytes: 83968
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
#define Reps(i, x, N) for(int i = x; i < N; i++)

const int LLINF = 1LL << 60;

signed main()
{
  int N;

  while(cin >> N, N) {

    int sum = 0;
    int p = 1, cnt = 0;

    Reps(i, 1, N / 2 + 2) {
      sum += i;
      while(sum >= N) {
	if(p != i && sum == N) cnt++;
	sum -= p, p++;
      }
    }

    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    std::string s;
    std::cin >> s;

    std::string s0, s1, s2;
    s0 = s.substr(0, 5);
    s1 = s.substr(6, 7);
    s2 = s.substr(14, 5);

    std::cout << s0 << " " << s1 << " " << s2 << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    int n = s.length();

    vector<vector<ll>> dp(n+1, vector<ll>(2, 0));
    dp[0][0] = 1;
    for(int i=0;i<n;++i) {
        if(s[i] == '1') {
            dp[i+1][0] = (dp[i][0] * 2) % MOD;
            dp[i+1][1] = (dp[i][1] * 3 + dp[i][0]) % MOD;
        } else {
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = (dp[i][1] * 3) % MOD;
        }
    }

    cout << (dp[n][0]+dp[n][1]) % MOD << endl;
}


Measured memory_bytes: 5840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str1 = br.readLine();
		String str2 = br.readLine();

		int a = Integer.parseInt(str1);

		if (a < 3200) {
			System.out.println("red");
		} else
			System.out.println(str2);
	}
}


Measured memory_bytes: 21204
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	string a;
	cin >> a;
	if (a == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else {
		if (a == "Cloudy") {
			cout << "Rainy" << endl;
		}
		else {
			cout << "Sunny" << endl;
		}
	}
}

Measured memory_bytes: 3572
#!/usr/bin/env python

import sys

n,m= [ int(x) for x in sys.stdin.readline().split() ]
baito=[ [] for _ in range(m) ]
for _ in range(n):
    ai,bi = [ int(x) for x in sys.stdin.readline().split() ]
    ai-=1
    if ai<m: baito[ai].append(bi)
#
for i in range(m):
    if baito[i]: baito[i].sort()
#
tot=0
cur=[]
for i in range(m):
    ref= baito[i]
    if ref:
        if not cur:
            cur= ref
        else:
            if ref[-1]<=cur[0]:
                cur= ref + cur
            elif cur[-1]<=ref[0]:
                cur= cur + ref
            else:
                cur+= ref
                cur.sort()
    #
    if not cur: continue
    tot+= cur.pop()
#
print( tot )


Measured memory_bytes: 18524
N, M = map(int, input().split())

c_min = 1
c_max = 10 ** 5
for i in range(M):
    LM = list(map(int, input().split()))
    c_min = max(c_min, LM[0])
    c_max = min(c_max, LM[1])

if c_min > c_max:
    print(0)
else:
    print(c_max - c_min + 1)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int a;
  int x=0;
  int y=0;
  int z=0;
  for(int i=1;i<=10;i++){
    cin >> a;
    if(a>x){
      z=y;
      y=x;
      x=a;
    }else if(y<a && a<=x){
      z=y;
      y=a;
    }else if(z<a && a<=y){
      z=a;
    }
  }
  cout << x << endl;
  cout << y << endl;
  cout << z << endl;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();

        if (n > k) {
            System.out.println(k * x + (n - k) * y);
        } else {
            System.out.println(n * x);
        }

    }
}

Measured memory_bytes: 24148
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#pragma gcc target ("avx2")
#pragma gcc optimization ("Ofast")
#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	ll n;
	scanf("%lld", &n);
	string ans;
	while (n) {
		--n;
		ans += ('a' + (n % 26));
		n /= 26;
	}
	reverse(all(ans));
	prints(ans);

	Please AC;
}

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

int main(){
    
    int a,b;
    
    while(1){
        int tmp;
        cin >> a >> b;
        
        if(a == 0 && b == 0){
            break;
        }
        
        if( a > b){
            tmp = a;
            a = b;
            b = tmp;
        }
        
        cout << a << " " << b << endl;
    }
    
    
    return 0;
    
}

Measured memory_bytes: 1160
s = input()

kisu = ['R', 'U', 'D']
gusu = ['L', 'U', 'D']
fl = True
ans = 'Yes'
for i in s:
  if fl:
    fl = False
    if kisu.count(i) == 0:
      ans = 'No'
      break
  else:
    fl = True
    if gusu.count(i) == 0:
      ans = 'No'
      break

print(ans)

Measured memory_bytes: 3060
# encoding: utf-8                                                            

def solve2 n
  if n <= 1000
    n + 1
  else
    1000 - n % 1001
  end
end

def solve n
  ans = 0
  (0..n).each do |k|
    if n - k <= 2000 and k <= 2000
      ans += solve2(k) * solve2(n - k)
    end
  end  
  ans
end

while n = gets
  n = n.rstrip.to_i
  puts "#{solve(n)}"
end

Measured memory_bytes: 6100
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int a,b; cin >> a >> b;
    vector<string> ans(2);
    rep(i,b) ans[0] += char(a+'0');
    rep(i,a) ans[1] += char(b+'0');
    sort(all(ans));
    cout << ans[0] << endl;
}

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

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N;
    cin >> N;

    string S;
    cin >> S;

    string ret = S;
    int cnt = 0;
    rep(i, S.size()) {
	if (S[i] == '(') {
	    cnt++;
	} else {
	    cnt--;
	    if (cnt == -1) {
		cnt = 0;
		ret = '(' + ret;
	    }
	}
    }

    cnt = 0;
    for (int i = S.size() - 1; i >= 0; i--) {
	if (S[i] == ')') {
	    cnt++;
	} else {
	    cnt--;
	    if (cnt == -1) {
		cnt = 0;
		ret += ')';
	    }
	}
    }

    cout << ret << endl;

    return 0;
}


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

   typedef long long ll;
   typedef pair<ll, ll> P;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   int gcd(int a,int b){return b?gcd(b,a%b):a;};

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

ll N;
string S;

typedef pair<string, string> PS;

void solve(){
    //v1 = 前半n文字を(赤, 青)に割り振った文字列のペア
    //v2 = 紅斑n文字を(赤, 青)に割り振った文字列のペア　後半は後ろから読む
    vector<PS> v1, v2;
    REP(j, 1 << N){
        string s1_red, s1_blue, s2_red, s2_blue;
        REP(i, N){
            if ((j >> i) & 1){
                s1_red += S[i];
                s2_red += S[2 * N - 1 - i];
            }
            else {
                s1_blue += S[i];
                s2_blue += S[2 * N - 1 - i];
            }
        }
        v1.pb(mp(s1_red, s1_blue));
        v2.pb(mp(s2_blue, s2_red));
    }
    SORT(v1); SORT(v2);
    ll ans = 0;
    REP(i, v1.size()){
        ans += upper_bound(ALL(v2), v1[i]) - lower_bound(ALL(v2), v1[i]);
    }
    cout << ans << endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    //input
    cin >> N >> S;

    solve();

    return 0;
}

Measured memory_bytes: 67288
#include <bits/stdc++.h>
#define int long long

using namespace std;

int n,x;
int a[2005];
int m[2005][2005];
signed main() {
  cin >> n >> x;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    m[0][i] = a[i];
  }

  for(int i = 1; i < n; i++) {
    for(int j = 0; j < n; j++) {
      int k = i;
      if(j- k < 0) m[i][j] = min(m[i-1][j],a[n+j-k]);
      else m[i][j] = min(m[i-1][j],a[j-k]);
    }
  }
  int ans = 1e14;
  for(int i = 0; i < n; i++) {
    int sum = 0;
    for(int j = 0; j < n; j++) sum += m[i][j];
    ans = min(ans, sum + i * x);
    //  cout << sum << endl;
  }

  cout << ans << endl;
}
    

  
  


Measured memory_bytes: 31616
#include <cstdio>
#include <string>
using namespace std;
int main() {
	int H, W;
	while(true) {
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0) {
				break;
		}
		for (int i=0; i < H; i++) {
			for (int j=0; j < W; j++) {
				if ((i+j)%2 == 0) {
					printf("%c", '#');
				} else {
					printf("%c", '.');
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

bool isreverse(char a, char b){
  if((a == 'i' && b == 'i') || (a == 'w' && b == 'w') ||
     (a == '(' && b == ')') || (a == ')' && b == '(')) return true;
  return false;
}

int main(){
  string iwi;
  string left, right;
  int ans = 0;
  cin >> iwi;
  
  if(iwi.size() % 2 == 1){
    for(int i = 0 ; i < iwi.size() ; i++){
      if(i < iwi.size()/2) left += iwi[i];
      else if(i > iwi.size()/2) right += iwi[i];
      else{
	if(iwi[i] == ')' || iwi[i] == '(') ans++;
      }
    }
  }
  else{
    for(int i = 0 ; i < iwi.size() ; i++){
      if(i < iwi.size()/2) left += iwi[i];
      else right += iwi[i];
    }
  }
  reverse(right.begin(), right.end());
  
  for(int i = 0 ; i < left.size() ; i++){
    if(!isreverse(left[i], right[i])) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1188