akhauriyash/Code-Regression huggingface dataset:
// Numeric

// 整数論

#include<vector>
#include<set>

// 素因数分解：力任せ
std::vector<int> prime_factor(const int n) {
    int tmp = n;
    std::vector<int> result;
    for(int i = 2; i * i <= n; ++i) {
        while(!(tmp % i)) {
            tmp /= i;
            result.push_back(i);
        }
    }
    if(tmp != 1) result.push_back(tmp);
    return result;
}

// 素数判定：Sieve of Eratosthenes
std::vector<bool> Eratosthenes(const int n) {
    std::vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; is_prime[i] && i * i <= n; ++i)
        for(int j = i * i; j <= n; j += i)
            is_prime[j] = false;
    return is_prime;
}

// べき乗：繰り返し二乗法
int power(const int m, const int n) {
    if(!n) return 1;
    if(n & 1) return power(m, n - 1) * m;
    return power(m * m, n >> 1);
}

int mod_power(const long long int m, const long long int n, const int mod) {
    if(!n) return 1;
    if(n & 1) return mod_power(m, n - 1, mod) * m % mod;
    return mod_power(m * m % mod, n >> 1, mod) % mod;
}

// 最大公約数：Euclidean algorithm
int gcd(const int m, const int n) {
    return n ? gcd(n, m % n) : m;
}

// 最小公倍数
int lcm(const long long int m, const long long int n) {
    return m * n / gcd(m, n);
}

// 自然数 n と互いに素な n 以下の自然数の個数：Euler's totient function
int phi(const int n) {
    int answer = n;
    auto list = prime_factor(n);
    for(auto i: std::set<int>(list.begin(), list.end())) answer -= answer / i;
    return answer;
}

////////////////////////////////////////////////////////////////////////////////

#include<iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    cout << phi(n) << endl;
}

Measured memory_bytes: 1212
n,m=map(int,input().split())
r=[]
l=[]
for i in range(m):
  L,R=map(int,input().split())
  r.append(R)
  l.append(L)
b=min(r)-max(l)
if b<0:
  print("0")
else:
  print(b+1)

Measured memory_bytes: 10996
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	int n, avg; cin >> n >> avg;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	vector<vector<ll>> dp(n + 1);
	rep(i, 0, n + 1) dp[i].resize(3000, 0);
	dp[0][0] = 1;
	rep(i, 0, n) {
		rep(j, 0, i + 1) {
			int idx = i - j;
			rep(k, 0, 2510) {
				if (dp[idx][k] != 0) dp[idx + 1][k + a[i]] += dp[idx][k];
			}
		}
	}
	ll ans = 0;
	rep(i, 1, n + 1) ans += dp[i][avg * i];
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 	int N,T,cnt,c,bc=0;
  	
  	cin>>N>>T;
  
  	for(int k=0;k<N;k++){
	  	cin>>c;
  		if(c-bc<T)cnt+=(c-bc);
   		else cnt+=T; 
		bc=c;
    }
	cout<<cnt+T<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	int N,X;
	scanf("%d %d",&N,&X);

	int ans = 1,D = 0;
	int tmp;

	for(int i = 0; i < N; i++){

		scanf("%d",&tmp);
		D += tmp;
		if(D <= X){
			ans++;
		}
	}

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

	return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const ll mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x,ll n,ll md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}

bool compare(pll a,pll b){
    return a.first*b.second>a.second*b.first;
}

int main(){
    fastio;
    //clock_t tm = clock();
    ll n,d,z,x,h;
    cin>>n>>d>>z;
    vll c;
    f(i,0,n){
        cin>>x>>h;
        c.pb({x,h});
    }
    sort(all(c));
    vl a(n+1,0);
    ll ans=0,temp;
    f(i,0,n){
        if(i>0)a[i]+=a[i-1];
        if(a[i]>=c[i].second)
            continue;
        x=c[i].second-a[i];
        temp=ceil((x*1.0)/z);
        ans+=temp;
        int r=upper_bound(all(c),mp(c[i].first+2*d,inf))-c.begin();
        a[r]-=temp*z;a[i]+=temp*z;
    }
    cout<<ans<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 6512
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
    	int b = sc.nextInt();
	    
      	if(a+b>=10){
        	System.out.println("error");
        }else{
        	System.out.println(a+b);
        }
    }
}

Measured memory_bytes: 35592
import numpy as np
import copy
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0 or r == n: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under



def main():
    N, A, B = map(int, input().split())

    v = list(map(int, input().split()))

    v = np.sort(v)[::-1]
    ave_max = np.mean(v[:A])

    print(ave_max)


    m = np.sum(v > v[A-1])
    n = np.sum(v == v[A-1])

    if m > 0:
        print(cmb(n, A-m))
    else:
        ans = 0
        for k in range(A, min(B, n)+1):
            ans += cmb(n, k)
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21752
#include<bits/stdc++.h>
#define int long long 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

signed main(){IOS;
	int n ; cin>>n;
	set<int>st;
	for(int i=0;i<n;i++){
		int a; cin>>a;
		st.insert(a);
	}
	cout<<( n==(int)st.size() ? "YES" : "NO" ) <<endl;
	return 0;
}


Measured memory_bytes: 9600
# coding: utf-8
# Your code here!

n = int(input())
A = list(map(int,input().split()))
a = len(A)
q = int(input())
m = list(map(int,input().split()))

Lis = set([])

for i in range(2**a):
    su = 0
    for j in range(n):
        if ((i >> j) & 1):
            su += A[j]
    Lis.add(su)

for i in m:
    if i in Lis:
        print("yes")
    else:
        print("no")
        


Measured memory_bytes: 5660
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Data.Char
import           Data.List
import           System.IO.Error

main :: IO ()
main = solve =<< readLn

solve :: Int -> IO ()
solve len = do
  xs :: [Int] <- replicateM len readWd
  putStrLn $ intercalate " " $ show <$> reverse xs

readWd :: Read a => IO a
readWd = getWord >>= readIO

getWord :: IO String
getWord = handle handleEOF $ do
  c <- getChar
  if isSpace c then pure [] else (c:) <$> getWord
  where
    handleEOF e = if isEOFError e then pure [] else throwIO e



Measured memory_bytes: 4168
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

const int mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> dp(n, 0);
  for (int i = 0; i < m; i ++) {
    int t; cin >> t;
    t --;
    dp[t] = -1;
    if (i > 0 && dp[t] == -1 && dp[t - 1] == -1) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (dp[0] == -1) dp[1] = 1;
  else if (dp[1] == -1) dp[0] = 1;
  else dp[0] = 1, dp[1] = 2;

  for (int i = 2; i < n; i ++) {
    if (dp[i] == -1) continue;
    else if (dp[i - 1] == -1) dp[i] = dp[i - 2] % mod;
    else if (dp[i - 2] == -1) dp[i] = dp[i - 1] % mod;
    else dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
  }
  cout << dp[n - 1] << endl;
}

Measured memory_bytes: 640
#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>;
typedef vector<int> vi;

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; a++) {
    int rem = X - a * 500; // 残金
    // 区間の上端 - 区間の下端
    res += max(0, min(rem / 100 + 1, B + 1)) - max(0, min((rem - (C - 1) * 50) / 100, B + 1));
  }
  cout << res << endl;

  return 0;
}

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

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (int i = 0; i < h; i++)
  {
    cin >> s[i];
  }

  int ans = 1000000;
  vector<int> id(h);
  for (int bit = 0; bit < (1<<(h-1)); bit++)
  {
    int g = 0;
    for (int i = 0; i < h; i++)
    {
      id[i] = g;
      if(bit&(1<<i)) g++;
    }
    g++;

    vector<vector<int>> c(g,vector<int>(w));
    for (int i = 0; i < h; i++)
    {
      for (int j = 0; j < w; j++)
      {
        c[id[i]][j] += s[i][j]-'0';
      }
    }

    bool ok = true;
    for (int i = 0; i < g; i++)
    {
      for (int j = 0; j < w; j++)
      {
        if(c[i][j]>k) ok=false;
      }
    }
    if(!ok) continue;

    vector<int> now(g);
    int cnt = g-1;
    for (int j = 0; j < w; j++)
    {
      for (int i = 0; i < g; i++)
      {
        now[i] += c[i][j];
        if(now[i]>k) ok = false;
      }
      if(!ok){
        ok=true;
        cnt++;
        now = vector<int>(g);
        for (int i = 0; i < g; i++)
        {
          now[i] = c[i][j];
        }
      }      
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    ll n; cin >> n;
    ll a[10][10];
    rep(i,10) rep(j,10) a[i][j] = 0;
    for(int i=1;i<n+1;i++){
        if(i%10 == 0) continue;
        ll t,b; b = i%10;
        t = i;
        while(10 <= t) t = t / 10;
        a[t][b]++;
    }
    ll ans = 0;
    FOR(i,1,10) FOR(j,1,10) ans = ans + a[i][j]*a[j][i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
w,h,n=gets.split.map(&:to_i)
xya=[]
n.times do
  xya.push gets.split.map(&:to_i)
end
xt = w
yt = h
xb = 0
yb = 0
xya.each do |e|
  x = e[0]
  y = e[1]
  a = e[2]
  case a
  when 1
    xb = [x, xb].max
  when 2
    xt = [x, xt].min
  when 3
    yb = [y, yb].max
  when 4
    yt = [y, yt].min
  end
end
dx = xt - xb
dy = yt - yb
if dx < 0 || dy < 0
  puts 0
else
  puts dx * dy
end


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

using ll  = long long;
using pii = pair<int,int>;
#define dbg(n) cout<<'\n'<<#n<<" is "<<n<<'\n';
#define pb push_back
#define all(v) v.begin(), v.end()
#define cs(i) cout<<"Case "<<i+1<<": \n"; 
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

const int N   = 1e5+5;
const int INF = 0x7fffffff;



int main(){
    int n,t,hold=0;

    cin>>n>>t;
    int dp[N];
    int h[N];
    memset(dp,-1,sizeof dp);

    for(int i=0;i<n;i++)
        cin>>h[i];
    
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);

    for(int i=0;i<n;i++){
        for(int j=1; i+j<n and j<=t;j++){
            if(dp[i+j]==-1)
                dp[i+j]=abs(h[i]-h[i+j])+dp[i];
            else
                dp[i+j]=min(dp[i+j],abs(h[i]-h[i+j])+dp[i]);
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,x) for(int i=0; i<(int) (x); i++)
#define intvec(name, size) vector<int> name;name.resize(size);
#define PI 3.14159265359
#define END "\n"
using namespace std;

int main()
{
	int x;cin>>x;
	if(x==0)
		cout << 1 << END;
	else
		cout << 0 << END;
	//////////////////////////////////
	//--------end--------
	//
	return 0;
}

Measured memory_bytes: 3564
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
//import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
//import java.util.Set;
//import java.util.stream.Collectors;
//import java.util.stream.IntStream;

public class Main {
	
	public static void main(String[] args) {
		// 入力
		final int n, a;
		final int[] x;
		try(Scanner scan = new Scanner(System.in)) {
			n = scan.nextInt();	// 1≤N≤50
			a = scan.nextInt();	// 1≤N≤50
			x = new int[n];
			for (int i = 0; i < n; i++) {
				// 平均値計算用の値に換算しておく
				x[i] = scan.nextInt() - a;	// 1≤xi≤50
			}
		}
		
		//x[]の総和が0になる組み合わせの数を求める。
		// 絶対値の和はたかだか2500以下
		int[] positive = Arrays.stream(x).filter(i -> i > 0).toArray();
		Arrays.sort(positive);
		int[] zero = Arrays.stream(x).filter(i -> i == 0).toArray();
		int[] negative = Arrays.stream(x).filter(i -> i < 0).map(i -> -i).toArray();	//符号反転させておく
		Arrays.sort(negative);
		
		// positiveとnegativeの合計が等しくなる組み合わせに最後に2^zero.lengthをかける。
		// ここからpositiveとnegativeについて動的計画法をかける?
		// key がとりうる合計値、value が場合の数
		Map<Integer, Long> positiveSum = sumCount(positive);
		Map<Integer, Long> negativeSum = sumCount(negative);
		
		
		long result = positiveSum.keySet().stream()
				.mapToLong(i -> positiveSum.get(i) * negativeSum.getOrDefault(i, 0L))
				.sum(); // < 2^50
		result = result << zero.length;
		
		// カードが0枚の場合を除く
		result--;

		
		// 出力
		try (PrintWriter out = new PrintWriter(System.out)) {
			out.println(result);
		}

	}
	
	static Map<Integer, Long> sumCount(int[] x) {
		Map<Integer, Long> result = new HashMap<>();
		result.put(0, 1L);
		for (int i: x) {
			List<Integer> keySet = new ArrayList<>(result.keySet());
			keySet.sort((k, l) -> l - k);
			// 大きい方から順番に処理すれば、重複しない。
			for (Integer j : keySet) {
				//iを加える場合
				result.put(j + i, result.getOrDefault(j + i, 0L) + result.get(j));
				
				//iを加えない場合
				//result.put(j, result.get(j) * 2L);
			
			}
		}
		return result;
	}

}


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

int main(){
	
	int P,Q,R;
	cin>>P>>Q>>R;
	
	int min;
	min=P+Q;
	
	if(min>Q+R)
		min=Q+R;
	if(min>R+P)
		min=R+P;
	
	cout<<min<<endl;
	
	
	return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    cin >> skipws;
    for (;;) {
        int e; cin >> e;
        if (!e) break;

        int ans = 0x3f3f3f3f;

        for (int i = 0; i * i * i <= e; i++) {
            int rem = e - i * i * i;
            int y = floor(sqrt((long double)(rem)));
            int x = rem - y * y;
            ans = min(ans, i + y + x);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll mini = 1e9;
  for (ll i = 1; i <=100; i++) {
    ll temp = 0;
    for (ll j = 0; j < n; j++) {
      temp+= (a[j]-i)*(a[j]-i);
    }
    mini = min(mini,temp);
  }
  cout << mini;
}


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

using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 
  
  int a, b;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b)) << "\n";
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;
template<int64_t M = 1000000007>
class ModInt {
public:
	ModInt() : val_(0) {};

	ModInt(int64_t val) {
		this->val_ = val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0)  this->val_ += M;
	}

	operator int64_t() const {
		return this->val_;
	}

	ModInt& operator += (int64_t val) {
		this->val_ += val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator -= (int64_t val) {
		this->val_ -= val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator *= (int64_t val) {
		this->val_ *= val;
		this->val_ %= M;

		return *this;
	}

	ModInt& operator /= (int64_t val) {
		ModInt v = ModInt::pow(val, M - 2);
		*this *= v;

		return *this;
	}

	ModInt operator + (int64_t v) const {
		ModInt ret = *this;
		return (ret += v);
	}

	ModInt operator - (int64_t v) const {
		ModInt ret = *this;
		return (ret -= v);
	}

	ModInt operator * (int64_t v) const {
		ModInt ret = *this;
		return (ret *= v);
	}

	ModInt operator / (int64_t v) const {
		ModInt ret = *this;
		return (ret /= v);
	}

	static ModInt pow(ModInt n, int64_t m) {
		if (m == 0) {
			ModInt ret(1);
			return ret;
		}
		if (m == 1) {
			return n;
		}

		ModInt v = pow(n, m / 2);
		ModInt ret = v * v;
		if (m & 1) {
			ret *= n;
		}
		return ret;
	}

	ostream& operator << (ostream& out) {
		out << this->val_;
		return out;
	}

private:
	int64_t val_;
};

ModInt<> dp[1000001][4];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	dp[0][0] = 8;
	dp[0][1] = 1;
	dp[0][2] = 1;
	dp[0][3] = 0;

	FOR_LT(i, 1, n) {
		dp[i][0] = dp[i - 1][0] * (int64_t)8;
		dp[i][1] = dp[i - 1][0] + dp[i - 1][1] * (int64_t)9;
		dp[i][2] = dp[i - 1][0] + dp[i - 1][2] * (int64_t)9;
		dp[i][3] = dp[i - 1][1] + dp[i - 1][2] + dp[i - 1][3] * (int64_t)10;
	}
	cout << dp[n - 1][3] << endl;

	return 0;
}

Measured memory_bytes: 34912
n = int(input())
inp = [int(input()) for i in range(n)]

checked = [0 for _ in range(n)]

cnt = 0
light = 0

while(True):
    if checked[light]:
        print(-1)
        break
    checked[light] = True
    light = inp[light] - 1
    cnt += 1
    if light == 1:
        print(cnt)
        break


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

int main() {
    int A,B,N,s;
    cin >> A >> B;
    int ans = 0, flag = 1;
    N = A;
    string n;

    for (int i = 0; i < B-A+1; i++)
    {
        n = to_string(N);
        s = n.length();
        for (int j = 0; j < s/2; ++j)
        {
            if(n[j] != n[s-j-1])
            {
                flag = 0;
                break;
            }
        }
        if (flag == 1){
            ++ans;
        }
        flag = 1;
        ++N;
    };

    cout << ans << endl;
    
}


Measured memory_bytes: 256
"""
A - Rated for Me
プログラミングコンペティションサイト AtCode は、プログラミングコンテストを定期的に開催しています。
AtCode で次に開催されるコンテストは ABC と呼ばれ、レーティングが 1200
未満の参加者のレーティングが変動します
その次に開催されるコンテストは ARC と呼ばれ、レーティングが 2800
未満の参加者のレーティングが変動します。
そのさらに次に開催されるコンテストは AGC と呼ばれ、すべての参加者のレーティングが変動します。
高橋くんの AtCode でのレーティングは R
です。彼のレーティングが変動する次のコンテストは何でしょうか？
"""

R = int(input())

if R < 1200:
    print("ABC")
elif R < 2800:
    print("ARC")
else:
    print("AGC")

Measured memory_bytes: 3060
// https://atcoder.jp/contests/dp/tasks/dp_c
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
    int N;
    cin >> N;
    int a[100100];
    int b[100100];
    int c[100100];
    int dp[100100][3]; 
    rep(i,N) cin >> a[i] >> b[i] >> c[i];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    
    for(int i=1;i<N;i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][2],dp[i-1][0]) + b[i];
        dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c[i];
    }
    
    int ans = max(dp[N-1][0],dp[N-1][1]);
    ans = max(ans,dp[N-1][2]);
    cout << ans << endl;
}

Measured memory_bytes: 2560
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	var ans int
	switch s {
	case "SUN":
		ans = 7
	case "MON":
		ans = 6
	case "TUE":
		ans = 5
	case "WED":
		ans = 4
	case "THU":
		ans = 3
	case "FRI":
		ans = 2
	case "SAT":
		ans = 1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

int func(int A, int B, int C) {
    if (A%2 == 1 || B%2 == 1 || C%2 == 1) {
        return 0;
    }
    if (A == B && A == C) {
        return -1;
    }
    
    return func((B+C)/2, (C+A)/2, (A+B)/2) + 1;
}

int main() {
    // input
    int A, B, C;
    cin >> A >> B >> C;
    
    int ans = func(A, B, C);
    cout << ans << "\n";
    return 0;
}




Measured memory_bytes: 256
import math
import heapq
n,m = map(int, raw_input().split(' '))

heap = [-e for  e in map(int, raw_input().split(' '))]
heapq.heapify(heap)
while(m and heap):
	u = heapq.heappop(heap)
	u *= -1
	u /=2
	if u:
		heapq.heappush(heap, -u)
	m-=1
	"""

	q = int(math.ceil(math.log(u,2)))
	if 2 ** q <= u: q +=1
	if q <= m:
		m-= q
	else:
		u /= 2
		m -=1
		if u:
			heapq.heappush(heap, -u)

	"""
print -sum(heap or [0])


Measured memory_bytes: 40532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

bool check(ll n, ll k){
    if (n == 1) return true;
    if (n < k) return false;
    if (n % k == 0) {
        return check(n/k,k);
    } else {
        return check(n%k,k);
    }
}

vector<ll> get_div(ll n){
    vector<ll> res;
    for (ll d = 2; d*d <= n; d++) {
        if(n % d == 0){
            res.push_back(d);
            if (d < n/d) {
                res.push_back(n/d);
            }
        }
    }
    return res;
}

int main(void){
    ll n;
    cin >> n;
    if (n == 2) {
        cout << 1 << endl;
        return 0;
    }
    set<ll> res;
    auto divs = get_div(n);
    for (ll d : divs){
        if (check(n,d)) res.insert(d);
    }
    auto divs2 = get_div(n-1);
    for (ll d : divs2){
        if (check(n,d)) res.insert(d);
    }
    if (check(n,n)) res.insert(n);
    if (check(n,n-1)) res.insert(n-1);
    cout << res.size() << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int n;
double a[105];
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		a[i] = 1.0 / a[i];
	}
	double sum = 0;
	for (int i = 0; i < n; i++)sum += a[i];
	cout << fixed << setprecision(10) << 1.0 / sum << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second


int main(){
    ll h,w,k;
    cin >> h >> w >> k;
    
    ll cnt[w] = {};
    char c[h][w] = {};

    rep(i,0,h){
        rep(j,0,w){
            cin >> c[i][j];
            if(c[i][j] == '#') cnt[j]++;
        }
    }

    ll memo = 1;
    ll ans[h][w] = {};
    rep(i,0,h) rep(j,0,w) ans[i][j] = LINF;
    bool flag = false;

    rep(j,0,w){
        ll memo2 = 1;
        rep(i,0,h){
            if(cnt[j] != 0){
                flag = true;
                ans[i][j] = memo;
                if(c[i][j] == '#' && memo2 != cnt[j]){
                    memo++;
                    memo2++;
                }
            }
            else if(j != 0 && flag){
                ans[i][j] = ans[i][j-1];
            }
            else break;
        }
        if(flag && j < w-1 && cnt[j+1] != 0) memo++;
    }

    rep(k,1,w){
        rep(i,0,h){
            ll j = w-k-1;
            if(ans[i][j] == LINF) ans[i][j] = ans[i][j+1];
        }
    }

    rep(i,0,h){
        rep(j,0,w){
            cout << ans[i][j] << ((j != w-1)?" ":"\n");
        }
    }
    return 0;
}


Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

int SX,SY,TX,TY;

void printc(char c,int n){
	REP(i,n){
		printf("%c",c);
	}
}

int main(){
	cin>>SX>>SY>>TX>>TY;
	printc('U',TY-SY);
	printc('R',TX-SX);
	printc('D',TY-SY);
	printc('L',TX-SX);
	printf("L");
	printc('U',TY-SY+1);
	printc('R',TX-SX+1);
	printf("D");
	printf("R");
	printc('D',TY-SY+1);
	printc('L',TX-SX+1);
	printf("U");
	return 0;
}


Measured memory_bytes: 384
x = int(input())
y = [int(n) for n in input().split()]

ini = 0

def search(li):
    L = len(li)
    for i in range(L):
        if li[i]%2 != 0:
            return False
        else:
            li[i] = li[i]//2
    return True


while True:
    if search(y):
        ini += 1
    else:
        break

print(ini)



Measured memory_bytes: 9172
#include <stdio.h>

int isPrime(int x);

int main(void){
    int n,max,min;
    
    while (scanf("%d",&n)!=EOF){
        for (max=n-1; !isPrime(max); max--);
        for (min=n+1; !isPrime(min); min++);
        printf("%d %d\n", max, min);
    }
    return 0;
}

int isPrime(int x){    
    for (int p=2;p*p<=x; p++){
        if (x%p==0) return 0;
    }
    return 1;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    lint A, B, M;
    cin >> A >> B >> M;
    vector<lint> a(A, 0), b(B, 0);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];

    lint mi = INF;
    rep(i, M) {
        lint x, y, c;
        cin >> x >> y >> c;
        x--, y--;
        lint sum = 0;
        sum      = a[x] + b[y] - c;
        mi       = min(mi, sum);
    }
    sort(all(a));
    sort(all(b));
    mi = min(a[0] + b[0], mi);
    cout << mi << endl;
    return 0;
}

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

using namespace std;
int n,cnt,ans;
string s;
int main() {
    scanf("%d",&n);
    cin>>s;
    for(int i=0;i<n;i++)
        if(s[i]=='W')
            cnt++;
    for(int i=n-cnt;i<n;i++)
        if(s[i]!='W')
            ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3932
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(void) {
    
    int n;
    cin>>n;
    if(n%2==0)fin(n);
    else fin(n*2);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MAXN 200005
#define REP(temp, init_val, end_val) for (int temp = init_val; temp <= end_val; ++temp)
#define REPR(temp, init_val, end_val) for (int temp = init_val; temp >= end_val; --temp)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> intpair;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while (c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
inline int lowbit(int x){
    return x & (-x);
}
inline int modadd(int x, int y){
    return (x + y >= MOD ? x + y - MOD: x + y);
}
inline int sgn(int x){
    return (x < 0 ? -1: (x > 0 ? 1: 0));
}
template<typename T>
T gcd(T a, T b){
    return (!b) ? a: gcd(b, a % b);
}
int poww(int a, int b){
    int res = 1;
    while (b > 0){
        if (b & 1) res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD, b >>= 1;
    }
    return res;
}
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/

int n;
char s[200005];
void init(){
    scanf("%s", s);
    n = strlen(s);
}
void solve(){
    ll ans = 0;
    int prea = 0, cur = 0;
    while (cur < n && s[cur] == 'A')
        ++prea, ++cur;
    for (; ; ){
        int postbc = 0;
        while (cur < n - 1 && s[cur] == 'B' && s[cur + 1] == 'C')
            ++postbc, cur += 2;
        ans += 1ll * prea * postbc;

        if (cur == n) break;
        
        if (s[cur] != 'A'){
            prea = 0;
            while (cur < n && s[cur] != 'A')
                ++cur;
        }
        while (cur < n && s[cur] == 'A')
            ++prea, ++cur;
    }
    printf("%lld\n", ans);
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 3948
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using namespace std;
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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

ll S(ll n){
  ll ret = 0;
  while(n > 0){
    ret += n%10;
    n /= 10;
  }
  return ret;
}
double f(ll n){
  return ((double)(n)/(double)S(n));
}
ll K;
vector<ll> res;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> K;
  ll base = 1;
  for(int i = 0 ; i < 15 ; i++){
    for(int j = 1 ; j < 150 ; j++){
      res.push_back(base * (j+1) - 1);
    }
    base *= 10;
  }
  sort(res.begin(),res.end());
  res.erase(unique(res.begin(),res.end()),res.end());

  for(ll i = 0 ; i < res.size(); i++){
    for(ll j = i+1 ; j < res.size(); j++){
      if(f(res[i]) > f(res[j])){
        res.erase(res.begin() + i--);
        break;
      }
    }
  }

  for(ll i = 0 ; i < K ; i++){
    cout << res[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
time = [0 for _ in range(n)]
def nex(time):
  for i in range(n):
    if time[i] == 0:
      time[i] = 1
      return time
      break
    else:
      time[i] = 0
  else:
    return 'over'
#print(nex([0,0,0]),nex([1,1,1]),nex([1,1,0]))
wit = []
for i in range(n):
  a = int(input())
  add = [2 for _ in range(n)] 
  add[i] = 1
  for _ in range(a):
    x,y = map(int,input().split())
    x -= 1
    add[x] = y
  wit.append(add)
can = []
while time != 'over':
  for i in range(n):
    if time[i] == 1:
      for j in range(n):
        if wit[i][j] == 1 - time[j]:
          break
      else:
        continue
      break
  else:
    can.append(sum(time))
  time = nex(time)
#print(wit)
print(max(can))
#print(can)

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<vector<int>>f(n,vector<int>(10)); for(auto&i:f)for(auto&j:i)cin>>j;
	vector<vector<int>>p(n,vector<int>(11)); for(auto&i:p)for(auto&j:i)cin>>j;
	int64_t ans=(1L<<63);
	for(int i=1;i<(1<<10);++i){
		int64_t tans=0;
		for(int j=0;j<n;++j){
			int cnt=0;
			for(int k=0;k<10;++k){
				if(i&(1<<k)&&f.at(j).at(k))++cnt;
			}
			tans+=p.at(j).at(cnt);
		}
		ans=max(ans,tans);
	}
	cout<<ans<<"\n"s;
}

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

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

  ll N; cin >> N;
  set<ll> st;
  for (int i = 0; i < N; i++) {
    ll a; cin >> a;
    st.insert(a);
  }
  ll ans = st.size();
  if (ans % 2 == 0) ans--;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 4992
n, m = map(int, input().split())
G = [[] for _ in range(n)]
ST = tuple(tuple(map(lambda x:int(x)-1, input().split())) for _ in range(m))
for s, t in ST:
  G[s].append(t)
#枝(s, t)を塞いだ時にそれぞれそこからあと何手かかるかを求める
def f(s, t):
  dp = [0]*n #そこからあと何手かかるかの期待値
  for i in range(n-2, -1, -1):
    temp = 0
    for v in G[i]:
      temp += dp[v]
    if i==s:
      temp -= dp[t]
      dp[i] = temp/(len(G[i])-1) + 1
    else:
      dp[i] = temp/len(G[i]) + 1
  return dp
T = f(-1, -1)
ans = T[0]
for i in range(n-1):
  if len(G[i]) == 1:
    continue
  m = 0
  t = -1
  for v in G[i]:
    if T[v] > m:
      m = T[v]
      t = v
  temp = f(i, t)[0]
  ans = min(ans, temp)
print(ans)

Measured memory_bytes: 104500
#include<math.h>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define    ll   long long int
#define    py   printf("Yes\n")
#define    pn   printf("No\n")
using namespace std;

ll hako[200000];


int main()
{


    ll  s,i;

    cin>>s;
    hako[s]=1;
    for(i=2; i<=10000; i++)
    {
        if(s%2==0)
        {
            s/=2;
        }
        else
        {
            s=3*s+1;
        }
        if(hako[s]==0)
        {
            hako[s]=1;
        }
        else
        {
            cout<<i<<endl;
            return 0;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
#endif

int main(){
    // chrono::steady_clock clk;
    // auto start = clk.now();
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    string s; cin >> s;
    vector<int> ss(n);
    for(int i=0;i<n;i++){
        ss[i] = s[i] == 'A';
    }
    bool flip = false, fflip = false;;
    int idx = 0;
    for(int i=0;i<k;i++){
        if(flip ^ ss[idx]){
            // ss[idx] = !ss[idx];
            ss[idx] ^= 1;
        }else{
            // flip = !flip;
            flip ^= 1;
            idx++;
            if(idx == n){ idx = 0; }
        }
        // if(i % 1000000 == 0 && clk.now() - start > 1900ms){
        //     if(n % 2 && (k - i - 1) % 2){
        //         fflip = true;
        //     }
        //     break;
        // }
    }
    cout << (fflip ^ flip ^ ss[idx] ? 'A' : 'B');
    for(int i=1;i<n;i++){
        cout << (flip ^ ss[(idx + i) % n] ? 'A' : 'B');
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 1532
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Vector;
import java.util.Scanner;
import java.util.Stack;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AEroui
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            char[] arr = in.next().toCharArray();

            StringBuilder sb = new StringBuilder();
            Stack<Character> stk = new Stack<>();
            StringBuilder ans = new StringBuilder();
            for (char c : arr) {
                sb.append(c);
                if (c == '(') {
                    stk.push(c);
                } else if (!stk.isEmpty()) {
                    stk.pop();
                } else {
                    ans.append('(');
                }
            }

            while (!stk.isEmpty()) {
                sb.append(')');
                stk.pop();
            }

            out.println(ans.toString() + "" + sb.toString());

        }

    }
}



Measured memory_bytes: 22996
#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <cmath>

using namespace std;

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

typedef long long ll;
typedef unsigned int uint;
typedef long double ld;

const int INT_INF=1e9;
const ll LONG_INF=1e18;
const double pi = acos(-1);
const int MAXN = 1e6;
const int MAXM = 1e6;
const ll MOD = 1e9 + 7;

void solve() {
    int n;
    cin >> n;
    ll ans = 0;
    ll sum = 0;
    vector<ll> inp(n);
    for (int i = 0; i < n; ++i) {
        cin >> inp[i];
        sum += inp[i];
    }
    sum %= MOD;
    for (int i = 0; i < n; ++i) {
        sum = (sum - inp[i] + MOD) % MOD;
        ans = (ans + inp[i] * sum) % MOD;
    }
    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(9);
#ifdef LOCAL
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
#endif
    solve();

#ifdef LOCAL
    cout << "Time:\n";
    cout << static_cast<double>(clock()) / CLOCKS_PER_SEC << '\n';
#endif

}


Measured memory_bytes: 4780
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

struct Node{
    int key;
    Node *prev, *next;
};

Node *nil;

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void printList(){
  Node *cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0){
        printf(" ");
    }    
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(Node *t){
  if(t == nil){
      return;
  }
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  //Node *t = nil->next;
  //if ( t == nil ) return;
  deleteNode(nil->next);
}

void deleteLast(){
  //Node *t = nil->prev
  deleteNode(nil->prev);
}

void deletekey(int key){
  /* your code */
  deleteNode(listSearch(key));
}


void insert(int key){
  
  Node *x = (Node *)malloc(sizeof(struct Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;

}


int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	deletekey(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 34012
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int A, B;
  cin >> A >> B;
  for (int i = 1; i < 1100; i++) {
    if ((i*8/100 == A) && (i*10/100 == B)) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}

Measured memory_bytes: 3636
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    a, b = il()
    return a + b if b % a == 0 else b - a


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


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

using namespace std;

#define MOD 1000000007

typedef long long int llint;

llint N;

int main() {
	cin >> N;
	vector<llint> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	llint ans = 0;
	llint sum = A[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		ans += (A[i] * sum) % MOD;
		ans %= MOD;
		sum = (sum + A[i]) % MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4364
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <set>
using namespace std;

struct RollingHash {
	const unsigned P = 1000000007U;
	vector<unsigned long long> pow, phash;
	template<typename T> void init(const T *s, int n, unsigned long long Q = 1) {
		pow.resize(n + 1); phash.resize(n + 1);
		pow[0] = Q; phash[0] = 0;
		for(int i = 0; i < n; i++) {
			pow[i + 1] = pow[i] * P;
			phash[i + 1] = s[i] + phash[i] * P;
		}
	}
	unsigned long long h(int i) const { return phash[i]; }
	unsigned long long h(int i, int j) const { return h(j) - h(i) * pow[j - i]; }
};
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, m;
	string s;
	cin >> n >> m >> s;

	RollingHash rh;
	rh.init(s.c_str(), n);

	set<unsigned long long> set;
	int l = 0, r = 0;
	for(int i = 0; i < m; i++) {
		string q;
		cin >> q;
		if(q == "L++") l++;
		if(q == "L--") l--;
		if(q == "R++") r++;
		if(q == "R--") r--;
		//cout << l + 1 << " " << r + 1 << " " << rh.h(l, r + 1) << endl;

		set.insert(rh.h(l, r + 1));
	}

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

Measured memory_bytes: 21992
num = [0] * 100
mode = 0
while True:
    try:
        a = int(input())
        num[a-1] += 1
        if num[a-1] > mode:
            mode = num[a-1]
    except:
        break
for i, n in enumerate(num):
    if n == mode:
        print(i+1)

Measured memory_bytes: 5600
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b;
    if (a + b == 3) {
        c = 3;
    } else if (a + b == 4) {
        c = 2;
    } else if (a + b == 5) {
        c = 1;
    }
    cout << c;

    return 0;
}


Measured memory_bytes: 256