akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

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

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

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__


void solve(void){
  
  string S;
  cin >> S;
  
  vector<int> C(S.size(),0);
  
  int nR,nL,nN, nS;
  char f='L';
    
  REP(i,S.size()){
	if(f=='L'){
      if(S[i]=='R'){
        if(i!=0){
          // L-R sequence = renew counter 
          if(nN %2==0){
            C[nR]=nN/2;
            C[nL]=nN/2;
          }
          else
          {
            if((nR-nS)%2==0){
              C[nR]=nN/2+1;
              C[nL]=nN/2; 
            }
            else
            {
              C[nR]=nN/2;
              C[nL]=nN/2+1;
            }
          }
        }
        f='R';
        //start fragment L-R sequence
        nS=i;
		nN=1;
      }
      else
      {
        // L-L sequence
        nN++;
      }
    }
    else
    {
      if(S[i]=='L'){
        // change point  R-L sequence
        f='L';
        nR=i-1;
        nL=i;
        nN++;
      }
      else
      {
        // R-R sequence
        nN++;
      }
    }
  }
  // count last
    if(nN %2==0){
      C[nR]=nN/2;
      C[nL]=nN/2;
    }
    else
    {
      if((nR-nS)%2==0){
        C[nR]=nN/2+1;
        C[nL]=nN/2; 
      }
      else
      {
        C[nR]=nN/2;
        C[nL]=nN/2+1;
      }
    }
  
  REP(i,C.size()-1){
    cout << C[i] << " ";
  }
  cout << C[C.size()-1] << endl;

 
  
  return;
   
}

#define TESTCASES	1

int main(int argc, const char * argv[]) {

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

  	REP(i,TESTCASES){
    	solve();
    } 
  
    return 0;
}



Measured memory_bytes: 1104
#include <stdio.h>

int j, y, ny = 0, nj = 0;
char s[15];

int saiki(int n) {
  if(n == j + y) {
    printf("%s\n", s);
    return 0;
  }
  s[n] = 'A';
  nj++;
  if(nj <= j) saiki(n + 1);
  nj--;
  ny++;
  s[n] = 'B';
  if(ny <= y) saiki(n + 1);
  ny--;
  return 0;
}

int saiki5(int n) {
  if(n == j + y) {
    printf("%s\n", s);
    return 0;
  }
  s[n] = 'A';
  nj++;
  if(nj <= j && !(nj == 5 && ny < 4)) saiki5(n + 1);
  nj--;
  ny++;
  s[n] = 'B';
  if(ny <= y && !(ny == 5 && nj <4)) saiki5(n + 1);
  ny--;
  return 0;
}

int main(void) {
  int i;
  scanf("%d%d", &j, &y);
  s[j + y] = 0;
  if(j == 5 && y != 5) {
    s[j + y - 1] = 'A';
    j--;
    saiki(0);
  } else if(j != 5 && y == 5) {
    s[j + y - 1] = 'B';
    y--;
    saiki(0);
  } else if(j == 5 && y == 5) {
    saiki5(0);
  } else if(j == 6) {
    s[j + y - 1] = 'A', s[j + y - 2] = 'A';
    j = 4;
   saiki(0);
  } else if(y == 6) {
    s[j + y - 1] = 'B', s[j + y - 2] = 'B';
    y = 4;
   saiki(0);
  } else saiki(0);
  return 0;
}


Measured memory_bytes: 2604
#include <cstdio>
#include <map>

using namespace std;

typedef pair<int, int> frac;


frac sub(frac a, int den) {
	return frac(a.first * den - a.second, a.second * den);
}

int count(frac x, int acc, int max, int den, int n) {
	if (x.first == 0) return 1;
	if (n == 0) return 0;

	int result = 0;
	for (int i = den; acc * i <= max; i++) {
		frac y = sub(x, i);
		result += count(y, acc * i, max, i, n - 1);
	}

	return result;
}

int main() {
	while (true) {
		int p, q, a, n;

		scanf("%d %d %d %d", &p, &q, &a, &n);

		if (p == 0) break;

		printf("%d\n", count(frac(p, q), 1, a, 1, n));
	}
	return 0;
}

Measured memory_bytes: 1028
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String s = sc.nextLine();
    String t = sc.nextLine().substring(0,s.length());
    System.out.println(s.equals(t) ? "Yes" : "No");
  }
}

Measured memory_bytes: 35548
#include <iostream>

int main(void){
  int M, D;
  std::cin >> M >> D;

  int count = 0;
  for(int m=1; m<=M; m++){
    for(int d=1; d<=D; d++){
      if(d%10 == 1) continue;
      if(d/10 == 1) continue;
      int temp = (d%10) * (d/10);
      if(temp == m) count++;
    }
  }

  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include<cstring>
#include <algorithm>
#include <cmath>
typedef  long long LL;
using namespace std;

int main()
{
    char a,b;
    cin>>a>>b;

    if(a>='A')
    {
        a=a-'A'+'9'+1;
    }
    if(b>='A')
    {
        b=b-'A'+'9'+1;
    }
    if(a>b)
        cout<<">";
    else
        if(a==b)
        cout<<"=";
    else
        cout<<"<";
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let d: usize = scan(tokens);
    let x: Vec<Vec<i64>> = vec(n, |_| vec(d, |_| scan(tokens)));
    let mut ans: usize = 0;
    for i in 0..n {
        for j in i + 1..n {
            let mut d2 = 0;
            for k in 0..d {
                d2 += (x[i][k] - x[j][k]).pow(2);
            }
            if is_square(d2) {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

fn is_square(x: i64) -> bool {
    if x< 0 {
        return false;
    }
    if x <= 1 {
        return true;
    }
    let mut a = 0;
    let mut b = x;
    while a + 1 < b {
        let c = (a + b) / 2;
        if c * c == x {
            return true;
        } else if c * c < x {
            a = c;
        } else {
            b = c;
        }
    }
    return false;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int N = 410, M = 100010;
int n, m, X[M], Y[M], ans;
bool k[N][N], vis[N];

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++) scanf("%d%d", &X[i], &Y[i]);
	for(int i = 1; i <= n; i++) {
		k[i][i] = 1;
		for(int j = m; j; j--) {
			bool x = k[i][X[j]], y = k[i][Y[j]];
			if(x && y) { vis[i] = 1; break; }
			else if(x) k[i][Y[j]] = 1; else if(y) k[i][X[j]] = 1;
		}
	}
	for(int i = 1; i < n; i++) {
		if(vis[i]) continue;
		for(int j = i + 1; j <= n; j++) {
			if(vis[j]) continue;
			bool flag = 1;
			for(int h = 1; h <= n; h++)
				if(k[i][h] && k[j][h]) { flag = 0; break; }
			ans += flag;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  int n,m,l;
  double p[100];
  int t[100],v[100];
  double time[100][51],prob[100][51];

  cin >> n >> m >> l;
  for(int i=0;i<n;i++)cin >> p[i] >> t[i] >> v[i];

  
  for(int i=0;i<n;i++){
    for(int j=0;j<=m;j++)time[i][j] = (double)l/v[i] + t[i]*j;
  }
  
  double k = 1.0;
  for(int i=0;i<m;i++)k*=100.0;

  for(int i=0;i<n;i++){
    prob[i][0] = pow((double)(100-p[i]),m);
    prob[i][0] /= k;
    double c = m;
    for(int j=1;j<=m;j++){
      prob[i][j] = c * pow((double)(100-p[i]),m-j) * pow((double)p[i],j);
      prob[i][j] /= k;
      c *= m-j;
      c /= j+1;
    }
  }
  /*
  for(int i=0;i<n;i++){
    for(int j=0;j<=m;j++){
      if(prob[i][j] < 0)cout << i << " " << j << endl;;
    }
  }
  */
  for(int i=0;i<n;i++){
    double ans = 0.0;
    if(!v[i])printf("%.8lf\n",ans);
    else{
      for(int j=0;j<=m;j++){
	double tmp = 1.0;
	for(int k=0;k<n;k++){
	  if(k!=i){
	    double hoge = 0.0;
	    for(int l=m;l>=0;l--){
	      if(time[k][l] > time[i][j]){
		hoge += prob[k][l];
	      }
	    }
	    tmp *= hoge;
	  }
	}
	ans += tmp*prob[i][j];
      }
      printf("%.8lf\n",ans);
    }
  }
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >>n >>m;
  
  int roadb, roade;
  vector<int> city(n, 0);

  for (int i = 0; i < m; i++) {
    cin >> roadb >> roade;
    city[roadb-1] ++;
    city[roade-1] ++;
  }
    
  for (int x : city)
    cout << x << endl;
}

Measured memory_bytes: 3580
import java.util.Scanner;

class Main {

	private static final String SPLIT_STR = " ";
	private static final String SPACE = " ";
	private static final String OPERATOR_SMALL = "<";
	private static final String OPERATOR_BIG = ">";
	private static final String OPERATOR_EQUAL = "==";
	private static final String OUTPUT_RIGHT = "a";
	private static final String OUTPUT_LEFT = "b";

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String x = sc.nextLine();

		sc.close();

		String[] split = x.split(SPLIT_STR);
		int a = Integer.parseInt(split[0]);
		int b = Integer.parseInt(split[1]);

		String comparisonOperator = OPERATOR_EQUAL;

		if (a < b) {
			comparisonOperator = OPERATOR_SMALL;
		} else if (a > b) {
			comparisonOperator = OPERATOR_BIG;
		}

		System.out.println(OUTPUT_RIGHT + SPACE + comparisonOperator + SPACE + OUTPUT_LEFT);
	}
}



Measured memory_bytes: 26328
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MN 100005
#define Mod 1000000007
int ksm(int a,int x){
	LL ans=1,w=a;
	while(x){
		if(x&1) ans=ans*w%Mod;
		w=w*w%Mod;
		x>>=1;
	}
	return ans;
}
int n,k,fac[MN],dfac[MN];
pair<int,int>v[MN];
int C(int n,int m){
	if(n>m)return 0;
	return (LL)fac[m]*dfac[n]%Mod*dfac[m-n]%Mod;
}
char a;
int main(){
	cin>>a;
	cout<<(char)(a+1)<<endl;
	return 0;
}


Measured memory_bytes: 256
n,a,b = map(int,input().split())
iamsum = 0


def division(x):
    tmp = 0
    while x > 0:
        shou,amari = divmod(x,10)
        tmp += amari
        x = shou
    return tmp


    
for i in range(n+1):
    z = division(i)
    if a <= z <= b:
        iamsum += i
print(iamsum)    


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

int main() {
  int N;
  cin >> N;
  unsigned long long int A[N];
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  unsigned long long int sum = 0ull;
  unsigned long long int sum_j = 0ull;
  for (int j=1; j<N; j++) {
    sum_j = (sum_j + A[j]) % 1000000007ull;
  }
  for (int i=0; i<N-1; i++) {
    sum = (sum + A[i] * sum_j) % 1000000007ull;
	sum_j = (sum_j - A[i+1] + 1000000007ull) % 1000000007ull;
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 5076
#include <stdio.h>
int main() {
    int N;
    scanf("%d", &N);
    for (int i = N; i <= 999; i++) {
        if (i/100 == (i/10)%10 && (i/10)%10 == i%10) {
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N;
  cin >> N;
  vector<int> A(N);
  int XOR = 0;
  rep(i, N) {
    cin >> A[i];
    XOR ^= A[i];
  }
  rep(i, N) { cout << (XOR ^ A[i]) << " "; }
  cout << endl;
  return 0;
}


Measured memory_bytes: 4040
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n+1);
	reps(i,n){
		cin >> a[i];
	}
	sort(all(a));
	vector<int> dp(n+1);
	reps(i,n){
		dp[i] = dp[i-1] + a[i];
	}
	int cnt = 1;
	for(int i = n;i > 1;--i){
		if(a[i] > dp[i-1] * 2) break;
		++cnt;
	}
	cout << cnt << '\n';
	return 0;
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
string ok="Yes";
string no="No";
int main(){
    string s;
    cin>>s;
    if(s[0]=='9'||s[1]=='9')cout<<ok<<endl;
    else cout<<no<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b;
	scanf("%d%d", &a, &b);
	if(a%3==0){
		printf("Possible\n");
	}else if(b%3==0){
		printf("Possible\n");
	}else if((a+b)%3 == 0){
		printf("Possible\n");
	}else{
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = 0
b = 0
ans = 0
mae = 0
b = [0] * 40
for i in range(40):
    for k in x:
        b[i] += (k & (1 << i)) >> i
c = [0] * 40
for i in range(1,40):
    if b[i-1] > n - b[i-1]:
        c[i] = c[i - 1] + (b[i - 1] << i - 1)
    else:
        c[i] = c[i - 1] + (n - b[i - 1] << i - 1)
for i in range(39, -1, -1):
    if m & (1 << i):
        ansb = mae
        ansb += b[i] << i
        ansb += c[i]
        if ans < ansb:
            ans = ansb
        mae += n-b[i] << i
    else:
        mae += b[i] << i
ans = max(ans, mae)
print(ans)


Measured memory_bytes: 63504
#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;
using usize = ::std::size_t;
//using u64 = ::std::int_least64_t;
using u64 = long long;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;


int main(int argc, char *argv[])
{
    
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    u64 ans = 0;
    for (int i = 1; i < N; i++) {
        ans += (u64) (N - 1) / i;
    }
    
    cout << ans << endl;
    
    return 0;
    
}


Measured memory_bytes: 3632
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: usize = s.trim().parse().unwrap();
    if n >= 3200 {
        s.clear();
        std::io::stdin().read_line(&mut s).unwrap();
        println!("{}", s.trim());
    } else {
        println!("red");
    }
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using Graph = vector<vector<int>>;
using ll = long long;


int main() {
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int> (m));
    vector<int> max(m,0);
    rep(i,n){
        cin>>c.at(i);
        rep(j,m){
            cin>>a.at(i).at(j);
        }
    }
    int ans=1001001001;
    rep(i,1<<n){
        int cost=0;
        vector<int> d(m);
        bool ok=true;
        rep(j,n){
            if(i>>j&1){
                cost+=c.at(j);
                rep(k,m){
                    d.at(k)+=a.at(j).at(k);
                }
            }
        }
        rep(k,m){
            if(d.at(k)<x){
                ok=false;
            }
        }
        if(ok) ans=min(ans,cost);
    }
    if(ans==1001001001){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
}

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

int main() {
  int N, M, fN = 0;
  cin >> N;
  M = N;
  for(int i = 0; i < 8; i++) {
    fN += N % 10;
    N /= 10;
    if (N == 0) {
      break;
    }
  }
  if(M % fN == 0){
    cout << "Yes" << endl;
  }
  else {
      cout << "No" << endl;
  }
}

Measured memory_bytes: 256
# include <iostream>
#include<bits/stdc++.h>
using namespace std;
int  main()
{
   long long n,k,total=0,sum=0;
   cin>>n>>k;
   int arr[n];
   for(int i=0;i<n;i++)
   {
       cin>>arr[i];
       total+=arr[i];
   }
   if(k>n)
   {
       cout<<0;
       return 0;
   }
   else if(k==0)
   {
       cout<<total;
       return 0;
   }
   else
   {
       sort(arr,arr+n);
       reverse(arr,arr+n);
       for(int i=0;i<k;i++)
       {
           sum+=arr[i];
       }
       cout<<total-sum;
   }
    return 0;
}


Measured memory_bytes: 1024
S = input()

words = ["dream", "dreamer", "erase", "eraser"]
ans = "YES"
r = len(S)

while r > 0:
    ok = False
    for w in words:
        l = r - len(w)
        if l < 0:
            continue
        if S[l:r] == w:
            r = l
            ok = True
            break
    if not ok:
        ans = "NO"
        break

print(ans)


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

#define rep(i, n) for (int i = 0; i < n; i ++)
 
int main() {
  string N;
  cin >> N;
  if (N.at(0) == N.at(1) && N.at(1) == N.at(2)) {
    cout << "Yes" << endl;
  } else if (N.at(1) == N.at(2) && N.at(2) == N.at(3)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class  Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int a,b;
    a=scan.nextInt();
    b=scan.nextInt();
    if(a<b){
      System.out.println("a < b");
    }else if (b<a) {
      System.out.println("a > b");
    }else{
      System.out.println("a == b");
    }
  }

}


Measured memory_bytes: 26236
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
#define MOD 1000000007
#define EPS 10e-8
int main(){
  int  N,A[107],B;
  B=0;
  cin >> N;
  rep(i,N){
     cin >> A[i];
  }
  sort(A,A+N);
  rep(i,N){
     if(i%2==0) B+=A[N-i-1];
     else B-=A[N-i-1];
     }
  cout << B << endl;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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; }


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

    int MAX = max(A, max(B,C));
    int ans = 0;

    while( A < MAX || B < MAX || C < MAX )
    {
        //cout << A << " " << B << " " << C << endl;
        if( A==B && A == MAX && C+1 == MAX )
        {
            ans += 2;
            break;
        }
        else if( A==C && A == MAX && B+1 == MAX )
        {
            ans += 2;
            break;
        }
        else if( B==C && B == MAX && A+1 == MAX )
        {
            ans += 2;
            break;
        }
        
        if( A < MAX && B < MAX )
        {
            A++;
            B++;
            ans++;
        }
        else if( A < MAX && C < MAX )
        {
            A++;
            C++;
            ans++;
        }
        else if( B < MAX && C < MAX )
        {
            B++;
            C++;
            ans++;
        }
        else if( A + 2 <= MAX )
        {
            A += 2;
            ans++;
        }
        else if( B + 2 <= MAX )
        {
            B += 2;
            ans++;
        }
        else if( C + 2 <= MAX )
        {
            C += 2;
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		sc.fill(a);

		List<Integer> before = new ArrayList<>();
		List<Integer> after = new ArrayList<>();
		for (int i = 0; i < a.length; i++) {
			if (i % 2 == 0) {
				after.add(a[i]);
			} else {
				before.add(a[i]);
			}
		}

		Stream<Integer> concat;
		if (a.length % 2 == 0) {
			Collections.reverse(before);
			concat = Stream.concat(before.stream(), after.stream());
		} else {
			Collections.reverse(after);
			concat = Stream.concat(after.stream(), before.stream());
		}

		System.out.println(
				concat.map(v -> Integer.toString(v))
						.collect(Collectors.joining(" ")));
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

Measured memory_bytes: 55204
Num = input()
op = -1
A = int(Num[0])
B = int(Num[1])
C = int(Num[2])
D = int(Num[3])
sign = []

for i in range(2):
    for j in range(2):
        for k in range(2):
            if(A+B*op**i+C*op**j+D*op**k == 7):
                sign.append(i)
                sign.append(j)
                sign.append(k)

for n in range(3):
    if(sign[n] == 0):
        sign[n] = "+"
    else:
        sign[n] = "-"

print(Num[0]+sign[0]+Num[1]+sign[1]+Num[2]+sign[2]+Num[3]+"=7")

Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_set>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;

        int count = 0;
        unordered_set<int> occurred;
        auto process = [&occurred](int n) {
            auto s = to_string(n);
            if (s.size() == 1) {
                return n;
            }
            int max_ = 0;
            for (int j = 0; j < s.size() - 1; ++j) {
                auto l = stoi(s.substr(0, j + 1));
                auto r = stoi(s.substr(j + 1));
                max_ = max(max_, l * r);
            }
            if (occurred.find(max_) != end(occurred)) {
                return -1;
            }
            return max_;
        };
        while (true) {
            if (0 <= n && n <= 9) {
                break;
            }
            else if (n < 0) {
                count = -1;
                break;
            }
            n = process(n);
            count += 1;
        }
        cout << count << endl;
    }
}


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


typedef long long ll;
#define reg register
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)


char IO;
inline ll rd(){
	ll s=0,f=0;
	while(!isdigit(IO=getchar())) if(IO=='-') f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(isdigit(IO=getchar()));
	return f?-s:s;
}


const int N=1e5+10;

int n,m,k;
int a[N],b[N],w[N];
ll dis[N];


int main(){
	n=rd(),m=rd(),k=rd();
	rep(i,1,m) a[i]=rd(),b[i]=rd(),w[i]=rd()-k;
	rep(i,2,n) dis[i]=-1e15;
	int cnt=0,f=1;
	do {
		f=0;
		rep(i,1,m) if(dis[a[i]]>-1e12&&dis[b[i]]<dis[a[i]]+w[i]) dis[b[i]]=dis[a[i]]+w[i],f=1;
		cnt++;
	} while(cnt<=n+2&&f);
	if(dis[n]<-1e9) return puts("0"),0;
	ll t=dis[n];
	rep(t,1,n) rep(i,1,m) if(dis[a[i]]>-1e9&&dis[b[i]]<dis[a[i]]+w[i]) dis[b[i]]=dis[a[i]]+w[i],f=1;
	if(dis[n]>t) return puts("-1"),0;
	printf("%lld\n",max(0ll,dis[n]));
}




Measured memory_bytes: 384
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,m,k;
int main()
{
	getiii(n,m,k);
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if(i*m+j*n-i*j*2==k)
			{
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

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

int main() {

	string s;

	cin >> s;

	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else {
		cout << "Sunny" << endl;
	}

	return 0;
}


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

//pow(A, 5)

int main() {
    ll X, A, B;
    cin >> X;
    bool flag = false;
    REP(i,500){
        REP(j,500){
            if(pow(i,5) - pow(j, 5) == X){
                A = i;
                B = j;
                flag = true;
            } else if(pow(i, 5) - pow(-j, 5) == X) {
                A = i;
                B = -j;
                flag = true;
            } else if(pow(-i, 5) - pow(j, 5) == X) {
                A = -i;
                B = j;
                flag = true;
            } else if(pow(-i, 5) - pow(-j, 5) == X) {
                A = -i;
                B = -j;
                flag = true;
            }
            if(flag == true)
                break;
        }
        if(flag == true)
            break;
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 4064
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 99999
using namespace std;

int main(){

  int A[N],B[N],C_0[N],C_1[N],K;
  string a,b;

  cin >> a >> b >> K;

  memset(A,0,sizeof(A));
  memset(B,0,sizeof(B));
  memset(C_0,0,sizeof(C_0));
  memset(C_1,0,sizeof(C_1));
  int hh=0;
  for(int i=a.length()-1;i>=0;i--){
    A[i] = a[(a.length()-1)-i] - '0';
    if(i >= b.length()){
    B[i] = 0;
    hh++;
    }
    else B[i] = b[(a.length()-1)-i-hh] - '0';
  }

  int br[N];
  br[0] = 0;
  for(int i=0;i<a.length();i++)
    {
      //cout << "br[" << i << "] = " << br[i] << endl;
      if(br[i] == 0)
	{
	  if(A[i] - 0 >= B[i]){
	    C_0[i] = A[i] - 0 - B[i];
	    br[i+1]=0;
	  }else if(A[i] - 0 < B[i]){
	    C_0[i] = A[i] - 0 + 10 - B[i];
	    br[i+1]=1;
	  }
	  if(A[i] - 1 >= B[i]){
	    C_1[i] = A[i] - 1 - B[i];
	  }else if(A[i] - 1 < B[i]){
	    C_1[i] = A[i] - 1 + 10 - B[i];
	  }
	}

      else if(br[i] == 1)
	{
	  if(A[i] - 0 >= B[i]){
	    C_0[i] = A[i] - 0 - B[i];
	  }else if(A[i] - 0 < B[i]){
	    C_0[i] = A[i] - 0 + 10 - B[i];
	  }
	  if(A[i] - 1 >= B[i]){
	    C_1[i] = A[i] - 1 - B[i];
	    br[i+1] = 0;
	  }else if(A[i] - 1 < B[i]){
	    C_1[i] = A[i] - 1 + 10 - B[i];
	    br[i+1] = 1;
	  }
	}
      //cout << "C_0[" << i <<  "] = "  << C_0[i] << endl;
      //cout << "C_1[" << i <<  "] = "  << C_1[i] << endl;


    }
  int fl=0;
  for(int i=a.length()-1;i>=0;i--){
    
    if(br[i] == 1 && C_0[i] > C_1[i] && K > 0){
      if(C_0[i] == 0 && fl == 0) continue;
      else {
	fl = 1;
	cout << C_0[i];
	K--;
      }
    }else if(br[i] == 1){
      if(C_1[i] == 0 && fl ==0) continue;
      else {
	fl =1;
	cout << C_1[i];
      }
    }
    else if(br[i] == 0){
      if(C_0[i] == 0 && fl == 0)continue;
      else{
	cout << C_0[i];
	fl = 1;
      }
    }
  }
  cout <<endl;

  


}

Measured memory_bytes: 0
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
#define MN 200000
#define mod 1000000007
using namespace std;
char s[MN+5];int n,cnt=2,ha[MN+5],pw[MN+5];
ll l,r,len[105],num[105][27],ans[27];
inline int Ha(int l,int r){return (ha[r]-1LL*ha[l-1]*pw[r-l+1]%mod+mod)%mod;}
void Calc(ll l,int x,int v)
{
	if(x<=1)
	{
		for(int j=1;j<=l;++j) ans[s[j]-'a']+=v;
		return;	
	}
	if(l<=len[x-1]) Calc(l,x-1,v);
	else 
	{
		for(int j=0;j<26;++j) ans[j]+=v*num[x-1][j];
		Calc(l-len[x-1],x-2,v);	
	}
}
int main()
{
	scanf("%s%lld%lld",s+1,&l,&r);n=strlen(s+1)/2;pw[0]=1;
	for(int i=1;i<=n;++i) pw[i]=31LL*pw[i-1]%mod,ha[i]=(31LL*ha[i-1]+s[i]-'a'+1)%mod;
	for(int i=2;i<=n+1;++i) if(i>n||Ha(i,n)==Ha(1,n-i+1))
	{
		len[1]=n;len[2]=n+i-1;
		for(int j=1;j<=n;++j) ++num[1][s[j]-'a'],num[2][s[j]-'a']+=1+(j<i);
		break;	
	}
	while(len[cnt]<r)
	{
		++cnt;len[cnt]=len[cnt-1]+len[cnt-2];
		for(int j=0;j<26;++j) num[cnt][j]=num[cnt-1][j]+num[cnt-2][j];
	}
	Calc(r,cnt,1);Calc(l-1,cnt,-1);
	for(int i=0;i<26;++i) printf("%lld ",ans[i]);
	return 0;
}



Measured memory_bytes: 1280
n,m=map(int,input().split())
s=list(map(int,input().split()))
s.sort(reverse=True)
total_vote=0
for i in range(n):
    total_vote += s[i]

count = 0
while count != m:
    if total_vote * (1/(4*m)) > s[count]:
        print("No")
        exit()
    else:
        count+=1
print("Yes")

Measured memory_bytes: 3064
// Problem : D - Teleporter
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

vector<long> a, depths;
vector<bool> visited;
vector<long> chain;

long preCycle, cycleLen;

void dfs(long node, long depth) {
    if (visited[node]) {
        preCycle = depths[node];
        cycleLen = depth - preCycle;
    } else {
        visited[node] = true;
        depths[node] = depth;
        chain.push_back(node);
        dfs(a[node], depth + 1);
    } 
}


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

    long long n, k;
    cin >> n >> k;
    a.resize(n + 1, 0);
    depths.resize(n + 1, 0);
    visited.resize(n + 1, false);
    for (long i = 1; i <= n; i++) cin >> a[i];
    dfs(1, 0);
    if (k <= preCycle) cout << chain[k] << "\n";
    else cout << chain[(k - preCycle) % cycleLen + preCycle] << "\n";
    
    return 0;
}


Measured memory_bytes: 14120
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    i64 x,y;
    cin>>x>>y;
    i64 cnt=0;
    while(x<=y){
        x *=2;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}



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

int main() {
	int n;
	cin >> n;
	ll ans = 0;
	ll b_a = 0;
	ll b_x = 0;
	ll x_a = 0;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < s.length()-1; j++) {
			if (s.at(j) == 'A' && s.at(j + 1) == 'B')ans++;
		}
		if (s.at(0) == 'B' && s.at(s.length() - 1) == 'A')b_a++;
		else if (s.at(0) == 'B')b_x++;
		else if (s.at(s.length() - 1) == 'A')x_a++;
	}
	ll x = 1;
	if (x_a == 0) {
		if (b_a == 0)ans += 0;
		else {
			if (b_x == 0)ans += b_a - 1;
			else ans += b_a;
		}
	}
	else ans += b_a + min(x_a, b_x);
	cout << ans << endl;

}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

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

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;
    vector<ll> b(n);
    REP(i, n) cin >> b[i];

    vector<vector<ll>> ans;
    vector<ll> v;
    ll now = 1;
    REP(i, n) {
        if(now == b[i]) {
            v.push_back(b[i]);
            now++;
        } 
        // else if(now > b[i] && b[i] == 1) {
        //     ans.push_back(v);
        //     v.clear();
        //     v.push_back(b[i]);
        //     now = 2;
        // } 
        else if(now > b[i]) {
            // vのb[i]番目に入れる
            vector<ll> nv;
            REP(j, b[i]-1) {
                nv.push_back(v[j]);
            }
            nv.push_back(b[i]);
            FOR(j, b[i]-1, v.size()) {
                nv.push_back(v[j]);
            }
            // cout << "nv=" << nv << endl;
            v = nv;
            now++;
        } else {
            cout << -1 << endl;
            return 0;
        }
        // cout << v << endl;
    }
    ans.push_back(v);

    // cout << ans << endl;

    // reverse(ALL(ans));
    // for(auto i: ans) {
    //     for(auto j: i) {
    //         cout << j << endl;
    //     }
    // }

    for(auto i: v) cout << i << endl;
    
    return 0;
}


Measured memory_bytes: 256
/*input
31415926535
1
*/
#include <bits/stdc++.h>
using namespace std;
#define TEMPLATE

#ifdef TEMPLATE
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }
#endif

ll gauk(ll n, ll b) {
	ll ret = 0;
	while (n >= b) {
		ret += n % b;
		n /= b;
	}

	return ret + n;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll N, S;
	cin >> N >> S;

	if (N == S)
		return !printf("%lld\n", N + 1);

	for (ll i = 2; i * i <= N; ++i)
	{
		if (gauk(N, i) == S)
			return !printf("%lld\n", i);
	}

	vl dar;
	for (ll i = 1; i * i <= (N - S); ++i)
	{
		if ((N - S) % i == 0) {
			if (gauk(N, i + 1) == S)
				return !printf("%lld\n", i + 1);
			dar.push_back((N - S) / i + 1);
		}
	}
	for (int i = dar.size() - 1; i >= 0; --i)
	{
		if (gauk(N, dar[i]) == S)
			return !printf("%lld\n", dar[i]);
	}
	printf("-1\n");
}


/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int d[100010];

int main() {
    int k;
    cin >> k;
    fill(d, d + k, INF);
    d[1] = 1;
    deque<int> q;
    q.push_front(1);
    while (!q.empty()) {
        int v = q.front(); q.pop_front();
        int to = (v + 1) % k;
        if (d[to] > d[v] + 1) {
            d[to] = d[v] + 1;
            q.push_front(to);
        }
        to = (v * 10) % k;
        if (d[to] > d[v]) {
            d[to] = d[v];
            q.push_back(to);
        }
    }

    cout << d[0] << endl;

    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define sio(); ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fio(); freopen("input","r",stdin); freopen("output","w",stdout);
using namespace std;
int main()
{
    double d,t,k;
    cin>>d>>t>>k;
    if(d/k<=t)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e16;
typedef long long ll;
ll mod = 1e9+7;
long double fast_exp(long double a, long long b)
{
    if(b == 0)
	   return 1;
    else
    {
	   long double res = 1;
	   res = fast_exp(a,b/2);
	   res = (res*res);
	   if(b%2 == 1)
		  res = (res*a);
	   return res;
 
    }
}


int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int n;
	cin>>n;
	string s;
	cin>>s;

	for(int i = 0; i<(int)s.size() ; i++)
	{
		int cur = s[i]-'A';
		cur = (cur+n)%26;
		s[i] = (char)((int)'A' + cur );
	}

	cout<<s<<endl;
	

	return 0;
	
}

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
typedef pair<ll, ll> Pair;

ll big = (ll)(1e18);
// Pair big = make_pair(i_big, 0);

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  ll N, M, L; cin >> N >> M >> L;
  // vector<int> A(M), B(M), C(M);
  vector<vector<ll>> dist1(N, vector<ll>(N, big));
  vector<vector<ll>> dist2(N, vector<ll>(N, big));
  for (int i = 0; i < M; i++) {
    int a, b, c; cin >> a >> b >> c; a--; b--;
    /*
    A.at(i) = a;
    B.at(i) = b;
    C.at(i) = c;
    */
    dist1.at(a).at(b) = dist1.at(b).at(a) = c;
  }
  for (int i = 0; i < N; i++) dist1.at(i).at(i) = 0;

  /*
  auto conc = [&](Pair x, Pair y) -> Pair {
    ll x1 = x.first;
    ll x2 = x.second;
    ll y1 = y.first;
    ll y2 = y.second;
    if (x2 + y2 <= L) return make_pair(x1 + y1,     x2 + y2);
    else              return make_pair(x1 + y1 + 1, x2 + y2 - L);
  };
  */

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
	dist1.at(i).at(j) = min(dist1.at(i).at(j),
				dist1.at(i).at(k) + dist1.at(k).at(j));
      }
    }
  }

  for (int i = 0; i < N; i++) {
    dist2.at(i).at(i) = 0;
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      if (dist1.at(i).at(j) <= L) dist2.at(i).at(j) = 1;
      else                        dist2.at(i).at(j) = big;
    }
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
	dist2.at(i).at(j) = min(dist2.at(i).at(j),
				dist2.at(i).at(k) + dist2.at(k).at(j));
      }
    }
  }

  int Q; cin >> Q;
  for (int i = 0; i < Q; i++) {
    int s, t; cin >> s >> t; s--; t--;
    ll d = dist2.at(s).at(t);
    if (d > (int)(1e9)) d = -1;
    else d = d - 1;
    cout << d << "\n";
  }

  return 0;
}



Measured memory_bytes: 2048
N,K=map(int,input().split())
A=list(map(int,input().split()))
kari=set()
hako=set()
count=1
cnt=1
zahyo=0
ans=0
kari.add(zahyo)
if K<=10**6:
    for i in range(K):
        ans=A[ans]-1
    print(ans+1)
    exit()
for i in range(N):
    zahyo=A[zahyo]-1
    if zahyo not in kari:
        kari.add(zahyo)
        count+=1
    else:
        break

hako.add(zahyo)
for i in range(N):
    zahyo=A[zahyo]-1
    if zahyo not in hako:
        hako.add(zahyo)
        cnt+=1
    else:
        break
count=len(kari)
cnt=len(hako)
kaisu=K-count
#print(zahyo)
if kaisu>N:
    kaisu=kaisu%cnt
for i in range(kaisu):
    zahyo=A[zahyo]-1
#print(zahyo,kaisu,count,cnt)
#print(kari,hako)
print(zahyo+1)

Measured memory_bytes: 35948
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<vector<int>>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int,int> pii;
typedef std::pair<int,double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;



void solve(){
    int n,k;
    cin >> n >> k;
    vector<double> a(n);
    rep(i,n) cin >> a[i];
    
    double r = *max_element(begin(a),end(a));
    double l = 0;
    
    rep(ii,100){
        double m = 0.5*l + 0.5*r;
        int cnt = 0;
        for(int i = 0; i < n; i++){
            cnt += ceil(a[i]/m)-1;
        }
        if (cnt > k) l = m;
        else r = m;
    }
    
    int ans = (int) ceil(r);
    cout << ans;
}


int main(){
    int T;
    //cin >> T;
    T = 1;
    while(T--){
        solve();
        cout << endl;
    }
}











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

using namespace std;

#define ll long long
#define endl '\n'

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3644
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		long[] A = new long[N * 3];

		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextLong();
		}

		Arrays.sort(A);

		long sum = 0;

		for (int i = N; i < A.length; i+=2) {
			sum += A[i];
		}

		System.out.println(sum);

	}
}


Measured memory_bytes: 62356
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

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

int main(){
	int N;
	std::cin >> N;
	std::vector<ll> L(N);
	rep(i, N){
		std::cin >> L[i];
	}
	int sz = L.size();
	ll ans = 0;
	for(int i=0; i<sz; i++){
		for(int j=i+1; j<sz; j++){
			for(int k=j+1; k<sz; k++){
				bool ok = false;
				if(L[i] != L[j] && L[j] != L[k] && L[i] != L[k]){
					if(L[i] + L[j] > L[k] && abs(L[i] - L[j]) < L[k]){
						ok = true;
					}
					if(L[k] + L[i] > L[j] && abs(L[k] - L[i]) < L[j]){
						ok = true;
					}
					if(L[j] + L[k] > L[i] && abs(L[j] - L[k]) < L[i]){
						ok = true;
					}
					if(ok) ans++;
				}
			}
		}
	}
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 3628