akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn gcd(a: usize, b:usize) -> usize {
    if b == 0 { a } else { gcd(b, a % b) }
}

fn lcm(a: usize, b: usize) -> usize {
    a * b / gcd(a, b)
}


fn main() {
    input!{
      n: usize,
      m: usize,
      s: chars,
      t: chars,
    }
    let l = lcm(n, m);
    for i in 0..n {
        let ni = i * l/n;
        if ni % (l/m) == 0 {
            let j = ni / (l/m);
            if s[i] != t[j] {
                println!("{}", -1);
                return;
            }
        }
    }
    println!("{}", l);
}


Measured memory_bytes: 4352
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: i64,
        m: i64,
    }
    println!("{}", n * (n - 1) / 2 + m * (m - 1) / 2);
}


Measured memory_bytes: 4352
#define __mode_debug__
/*   ξ
     ll
   ＿ll＿
 ／  ∞  ＼
│*  Ａ  *│
│*  Ｃ  *│
│*  祈  *│
│*  願  *│
│*      *│
 ￣￣￣￣￣    */
//C++14 (GCC 5.4.1)
#include <bits/stdc++.h>
using namespace std;
#ifdef __mode_debug__
    #define DBG
#else
    #define DBG if(false)
#endif

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)

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

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

//DUMP
//  ostream vector<T> , vector<vector<T>> , set<T> ,queue<T> , priority_queue<T> , pair<T,U> , map<T,U>
template<class T> ostream& operator<<(ostream&os,vector<T>&vec){os<<"{ ";rep(i,vec.size()) os<<((i==0)?"":", ")<<i<<":"<<vec[i];os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,vector<vector<T>>&vec){os<<"{"<<endl;rep(i,vec.size())os<<"\t   "<<i<<":"<<vec[i]<<((i==vec.size()-1)? "":",")<<endl;os<<"\t }";return os;}
template<class T> ostream& operator<<(ostream&os,set<T>&p){os<<"{ ";repi(itr,p)  os<<((itr==p.begin())?"":", ")<<*itr;os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,queue<T>&p){queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.front();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T> ostream& operator<<(ostream&os,priority_queue<T>&p){priority_queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.top();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T,class U> ostream& operator<<(ostream&os,pair<T,U>&p){os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T,class U> ostream& operator<<(ostream&os,map<T,U>&p){os<<"{ ";repi(itr,p)os<<((itr==p.begin())?"":", ")<<itr->first<<":"<<itr->second;os<<" }";return os;}
void dump_f(string &nm){cerr<<endl;}
template<class T,class... Ts> void dump_f(string &nm,T &&x,Ts&&... ts){int l=nm.find_first_of(',');string name(nm,0,l),nx(nm,l+1,-1);cerr<<"  "<<name<<"\t:"<<x<<endl;dump_f(nx,forward<Ts>(ts)...);}
template<class... Ts> void dump_m(int &&ln,string &&nm,Ts&&... ts){cerr<<"[ln:"<<ln<<"]"<<endl;dump_f(nm,forward<Ts>(ts)...);}
#define dump(...) DBG dump_m(__LINE__,#__VA_ARGS__,__VA_ARGS__)

#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(V.begin(),V.end(),c))


int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    ll N,A,B,ans;
    cin >>N>>A>>B;

    //-----------------------------------
    if((B-A)%2==0){
      cout << ((B-A)/2)<<endl;
      return 0;
    }
    ans=B-1;
    chmin(ans,N-A);
    chmin(ans,A+(B-A-1)/2);
    chmin(ans,N-B+1+(N-A-(N-B+1))/2);

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


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main (String[]args){
    Scanner sc = new Scanner(System.in);
    String[] s = sc.nextLine().split(" ");
    int n1 = Integer.parseInt(s[0]);
    int n2 = Integer.parseInt(s[1]);
    int n3 = Integer.parseInt(s[2]);
    int n4 = Integer.parseInt(s[3]);
    
    int st = 0;
    int en = 0;
    if(n1 > n3){
      st = n1;
    }else{
      st = n3;
    }
    
    if(n2 < n4){
      en = n2;
    }else{
      en = n4;
    }
    
    if(en -st > 0){
      System.out.println(en - st);
    }else{
      System.out.println(0);
    }
  }
}

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

using namespace std;

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

    sort(h.begin(), h.end());
    int ans = 1145141919;
    for(int i = 0; i < n-k+1; i++){
        ans = min(ans, h[i+k-1] - h[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <string>
#include <sstream>
#include <iostream>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
using namespace std;

const int LOOP = 100000; //??????????????°
const double EPS = 1e-6; //??????????????¨(?°??????????????????????)
int L;
int N; //???????????±???????????°

//???????????±????????????????????????????????¨?????¨???????¨????????¨??????????
double Evaluate(int r[12]) {
	double val = r[0] + r[N-1];
	for (int i = 0; i < N - 1; i++)
	{
		int a = abs(r[i] - r[i+1]), c = r[i] + r[i+1];
		val += sqrt(c*c - a*a);
	}
	return val;
}

//?????¨?????????????????°???????????¨??????????????????????§???????????±???????
//(????§?????????????true)
bool Changes(int cnt) {
	return cnt < rand()%LOOP;
}

//?????????????????????????????¢??°
//?????????????°??????????????¨?????????????
//int r[12] : ???????????±?????????0??????N-1???????????????????????????????????????????????????????´???????
double Solve(int r[12]) {
	double score = Evaluate(r); //?????¨?????¶???r[]????¨???????????´????????????°
	double mi = score; //???????????§?????¶???????¨???????????°???????????´????????????°
	for (int cnt = 0; cnt < LOOP; cnt++)
	{
		//===============================================
        int a = rand() % N;
        int b = rand() % N;
        swap(r[a],r[b]);
        if(Evaluate(r) <= mi) mi = Evaluate(r);
        else
        {
            if(Changes(cnt)) mi = Evaluate(r);
            else swap(r[a],r[b]);
        }
		//===============================================
	}
	return mi; //????°?????????????
}

//??\?????¢????????????????????¢????????£????????§???????????????
int main() {
    srand(time(NULL));
	while (cin >> L)
	{
		N = 0;
		int r[12];
		string S;
		getline(cin, S);
		stringstream SS(S);
		while (!SS.eof()) SS >> r[N++];

		double ans;
		if (N == 1) ans = r[0]*2;
		else ans = Solve(r);

		if (L - ans + EPS > 0) puts("OK");
		else puts("NA");
	}
	return 0;
}

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


#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int main() {
    int a, b, c;

    cin >> a >> b >> c;

    if (a == b) {
        cout << c << endl;
        return 0;
    } else if (b == c) {
        cout << a << endl;
        return 0;
    } else {
        cout << b << endl;
        return 0;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;

int main() {
  int n,m;
  cin>>n>>m;
  if(n==m)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main(){
  long long n,x,y = 0,z;
  cin >> n;
  long long A[n-1],X[n] = {};
  for(int i = 0;i < n-1;i++){
    cin >> A[i];
  }
  for(int i = 0;i < n;i++){
    if(i == 0)X[i] = A[i]; 
    if(A[i] == A[i+1])X[i+1] = A[i];
    if(A[i] < A[i+1]){
      X[i+1] = A[i];
    }
    if(A[i] > A[i+1]){
      X[i+1] = A[i+1];
    }
    //cout << X[i] << endl;
  }
  for(int i = 0;i < n;i++){
    y += X[i];
  }
  assert(y <= INT_MAX);
  cout << y << endl;
}


Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll N,M;cin>>N>>M;
    //電球iについて、スイッチがkこ
    vi S[M];ll k;
    REP(i,M){
        cin>>k;
        REP(j,k){
            ll s;cin>>s;s--;
            S[i].push_back(s);
        }
    }
    ll p[M];REP(i,M)cin>>p[i];
    ll cnt=0;bool is;
    for(int bit=0;bit<(1<<N);bit++){
        is=true;
        REP(i,M){
            ll on=0;
            for(auto r:S[i]){
                if(bit & (1<<r)) on++;
            }
            if(on%2!=p[i]){is=false;break;}
        }
        if(is)cnt++;
    }
    cout<<cnt<<"\n";
}

Measured memory_bytes: 384
# 竹1, 2, 3, 使わない の4種類
# 4 ** 8 = 65536

import itertools
N,A,B,C = map(int,input().split())
L = [int(input()) for _ in range(N)]

INF = 10 ** 18
answer = INF
for pattern in itertools.product(range(4), repeat = N):
  x = [0] * 4
  MP = 0
  for take, length in zip(pattern, L):
    if take == 3:
      continue
    if x[take] != 0:
      MP += 10
    x[take] += length
  if x[0] == 0 or x[1] == 0 or x[2] == 0:
    continue
  MP += abs(A-x[0])
  MP += abs(B-x[1])
  MP += abs(C-x[2])
  if answer > MP:
    answer = MP
print(answer)


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

double calc(double vi, double t, double ts, double dt) {
    if(t < ts){
        return vi + ts - t;
    }else if(ts + dt < t){
        return vi + t - (ts + dt);
    }else{
        return vi;
    }
}

int main() {
    int N;
    cin >> N;
    vector<double> t(N + 2, .5);
    FOR(i, 1, N + 1) {
        cin >> t[i];
    }
    vector<double> v(N + 2, 0);
    FOR(i, 1, N + 1) {
        cin >> v[i];
    }
    int M = 2*accumulate(ALL(t), (double)0);
    vector<double> res(M, 334);
    res[M - 1] = 0;
    res[0] = 0;
    FOR(i, 1, M - 1) {
        double st = -0.5;
        for(int j = 0;j < N + 2;j++) {
            res[i] = min(res[i], calc(v[j], (double)(i - 1)/2, (double)st, (double)t[j]));
            st += (double)t[j];
        }
    }
    vector<double> d(M, 0);
    FOR(i, 1, M - 1) {
        d[i] = (res[i] + res[i + 1])/4;
    }
    double y = accumulate(ALL(d), (double)0);
    printf("%.9lf\n", y);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    int d;
    cin >> d;
    string a;
    if(d == 25){
        a = "Christmas";
    }
    else if(d == 24){
        a = "Christmas Eve";
    }
    else if(d == 23){
        a = "Christmas Eve Eve";
    }
    else{
        a = "Christmas Eve Eve Eve";
    }
    cout << a << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool N1 = false, S1 = false, E1 = false, W1 = false;
int len = 0, x = 0, y = 0;
char s[1010];
int main() {
	cin>>s + 1;
	for(int i = 1; i <= 1010; i ++) {
		if(s[i] == 'N') N1 = true;
		if(s[i] == 'S') S1 = true;
		if(s[i] == 'E') E1 = true;
		if(s[i] == 'W') W1 = true;
	}

	if((!(N1&S1)&&!(!N1&&!S1))||((!(E1&W1)&&!(!E1&&!W1)))) printf("No\n");
	else printf("Yes\n");
	return 0;
}

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

int main() {
    string T;
    cin >> T;

    string ans = "";
    for (int i = 0; i < T.length(); i++)
    {
        if (T[i] == '?'){
            ans += "D";
        }
        else {
            ans += T[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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

const int mod = 1e9 + 7;
ll n, k;
ll num (int l) {
  return (l*(n-l+1) + 1) % mod;
}

int main() {
  cin >> n >> k;
  ll ans = 0;
  for (int i = k; i <= n+1; i++) {
    ans += num(i);
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    char s[7];
    cin>>s;
    if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]||s[3]==s[4])
        printf("Bad");
    else
        printf("Good");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i = 0; i< N; i++){
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  if(d.at(N/2) -d.at(-1+N/2)==0){
    cout << 0 << endl;
    return 0;
  }
  else{
  int ans = d.at(N/2) -d.at(-1+N/2);
  cout << ans << endl;
}
  
}



Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>
   
using namespace std;
    
void call(int n)
{        
    for(int i = 1; i <= n; i++)
    {
        if ( i % 3 == 0 )
       {
            cout << " " << i;
       }
        else
        {   
            int x = i;
                
            while(x)  //repeat x/10
            {            
                if(x % 10 ==3)
                {
                    cout<<" "<<i;
                    break;
                }
                
                x = x / 10;
            } 
        }
    }
    
  cout << endl;
}
int main()
{
    int n;
    cin>>n;
    
    call(n);
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}


ll i,j,k,ii,jj,n,m;
ll a,b,c,d,e,g,h,r,num,sum,ans;
ll x[500005],y[500005],z[500005];
bool dame;

int main(){
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x[i];
    }
    num = 0;
    ll maxnum = 0;
    while(1){
        ans += (x[num]-1)/(maxnum + 1);
        if((x[num]-1)/(maxnum + 1) > 0 && num != 0){
            x[num] = maxnum;
        }else{
            x[num] -= (maxnum + 1) * ((x[num]-1)/(maxnum + 1));
        }
        maxnum = max(maxnum,x[num]);
        num++;
        if(num == n)break;
        for(i=0;i<n;i++){
            //pe(x[i]);
        }
        //el;
    }
    p(ans);
    
    return 0;
}



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

const int INF=1001001001001001001;
int dp[111111];

signed main(){
	int N;cin>>N;
	vint A(N);rep(i,N)cin>>A[i];
	rep(i,N)A[i]*=-1;
	fill_n(dp,N+1,INF);
	dp[0]=-INF;
	rep(i,N){
		int k=upper_bound(dp,dp+N+1,A[i])-dp;
		dp[k]=A[i];
	}
	cout<<lower_bound(dp,dp+N+1,INF)-dp-1<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<math.h>
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    ll sum = 0;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i == 0){
            sum += abs(a[0]);
        }else{
            sum += abs(a[i - 1] - a[i]);
        }

        if(i == n - 1){
            sum += abs(a[i]);
        }
    }

    ll re = sum;

    for(int i = 0; i < n; i++){
        re = sum;
        if(i == 0){
            re -= abs(a[0]);
            re -= abs(a[0] - a[1]);
            re += abs(a[1]);
        }else if(i != n - 1){
            re -= abs(a[i - 1] - a[i]);
            re -= abs(a[i] - a[i + 1]);
            re += abs(a[i - 1] - a[i + 1]);
        }else{
            re -= abs(a[i - 1] - a[i]);
            re -= abs(a[n - 1]);
            re += abs(a[n - 2]);
        }

        cout << re << endl;
    }

    
}

Measured memory_bytes: 1664
/*
 It's better to sleep happy and tired rather than disappointed and frustrated
 There's only 1 thing that's impossible and that is defeating a man who doesn't give up
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

const int inf=0x3f3f3f3f;
int n , ans , sum , a , b ,arr[mx5];
string str;
 
int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		cin>>n;
		fo(i,n)
		{
			cin>>arr[i];
		}
		fo(i,n)
		{
			Fo(j,i+1,n)
			{
				sum+=(arr[i]*arr[j]);
			}
		}
		cout<<sum;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int N ,M, Q;
vec a(60), b(60) ,c(60), d(60);
ll ans = 0;
void hoge(vec v){
    int V = SZ(v);
    if(V == N){
        ll res = 0;
        rep(i,Q){
            if(v[b[i]]-v[a[i]] == c[i]){
                res += d[i];
            }
        }
        ans = max(ans, res);
        return;
    }
    int start;
    if(V == 0){
        start = 1;
    }
    else{
        start = v[V-1];
    }
    FOR(k,start,M+1){
        vec u = v;
        u.pb(k);
        hoge(u);
    }
}

int main(){
    scanf("%d %d %d", &N, &M, &Q);
    rep(i,Q){
        scanf("%lld %lld %lld %lld", &a[i], &b[i], &c[i], &d[i]);
        a[i]--, b[i]--;
    }
    vec v;
    hoge(v);
    printf("%lld\n", ans);
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;

long long func(long long m, long long n){
    if(n == 1){
        return m;
    }
    if(n % 2 == 0){
        return func(m, n / 2) * func(m, n / 2) % mod;
    } else {
        return m * func(m, n - 1) % mod;
    }
}

int main(){
    long long m, n;
    cin >> m >> n;
    long long ans = func(m, n);
    
    cout << ans << endl;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL gcd(LL a, LL b) {
    return b == 0 ? a : gcd(b, a % b);
}
int main() {
    LL a,b,c,d;
    cin>>a>>b>>c>>d;
    LL lcm=c*d/gcd(c,d);
    a--;
    LL l = a/c+a/d-a/lcm;
    LL r = b/c+b/d-b/lcm;
    cout << (b - r) - (a - l) <<endl; 
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
def check(x):
  s = [(1, a[0])]
  for i in range(N - 1):
    #print(s, x)
    if a[i] < a[i + 1]:
      if s[-1][0] == 1: s.append((1, s.pop()[1] + a[i + 1] - a[i]))
      else: s.append((1, a[i + 1] - a[i]))
    else:
      z = a[i] - a[i + 1]
      while z:
        if s[-1][1] <= z: z -= s.pop()[1]
        else:
          j, k = s.pop()
          s.append((j, k - z))
          z = 0
      if s[-1][0] == x:
        _, k = s.pop()
        if len(s) == 0: return False
        jj, kk = s.pop()
        if jj > x: return False
        if kk > 1: s.append((jj, kk - 1))
        s.append((jj + 1, 1))
        s.append((1, k))
      else:
        j, k = s.pop()
        if j > x: return False
        if k > 1: s.append((j, k - 1))
        s.append((j + 1, 1))
    if len(s) >= 2:
      if s[-1][0] == s[-2][0]: s.append((s[-1][0], s.pop()[1] + s.pop()[1]))
  xx = 0
  while len(s):
    jj, kk = s.pop()
    if jj > x: return False
    xx += kk
  return xx == a[-1]

ok = N
ng = 0
while ok - ng > 1:
  m = (ok + ng) // 2
  if check(m): ok = m
  else: ng = m
print(ok)

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

#define ll             long long
#define LL             long long
#define gcd(a,b)       __gcd(a, b)
#define lcm(a,b)       a * (b / gcd(a, b))
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof a)
#define smax(a, b)     a = max(a, b)
#define smin(a, b)     a = min(a, b)
#define sqr(x)         x * x
#define cube(x)        x * x * x
#define endl           '\n'

int in() {
	int n;
	scanf("%d", &n);
	return n;
}

ll Lin() {
	ll n;
	scanf("%lld", &n);
	return n;
}

double Din() {
	double n;
	scanf("%lf", &n);
	return n;
}

const ll inf = (ll)1e17;
const ll mod = (ll)1e9 + 7;
const int N = 1e5 + 5;

ll dp[N][105];
ll w[105], v[105];

ll call(int pos, ll c) {
	if (c < 0) return -inf;
	if (pos == 0) return 0;
	if (dp[c][pos] != -1) return dp[c][pos];
	return dp[c][pos] = max(call(pos - 1, c - w[pos]) + v[pos], call(pos - 1, c));
}


int solve() {
	int n = in();
	ll c = Lin();
	for (int i = 1; i <= n; i++) {
		w[i] = Lin(), v[i] = Lin();
	}
	fill(dp, -1);
	printf("%lld\n", call(n, c));
	return 0;
}

int main() {
	int test = 1, tc = 0;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}


Measured memory_bytes: 82304
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int x = 0;
    scanf("%d", &x);
    if((x == 7)||(x == 5)||(x == 3)){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}


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

using namespace std;

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

int main() {

	long x;
	cin >> x;

	while (IsPrime(x) == false) {
		x++;
	}
	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>
#include<string>
#include<utility>
#include<queue>

using namespace std;

int main(){
    int x;
    cin >> x;
    int a= x/200;
    cout << 10-a << endl;
    return 0;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

	int n; std::cin >> n;
	vi l(n); rep(i, n) std::cin >> l[i];
	sort(rng(l));
	int ans = 0;
	rep(i, n) srep(j, i+1, n) {
		auto mi = upper_bound(l.begin() + j + 1, l.end(), l[j] - l[i]);
		auto ma = lower_bound(l.begin() + j + 1, l.end(), l[i] + l[j]);
		ans += max((int)(ma - mi), 0);
	}
	std::cout << ans << "\n";
}


Measured memory_bytes: 256
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(n):
    a.append(a[i] + A[i])
for i in range(m):
    b.append(b[i] + B[i])

ans, j = 0, m
for i in range(n + 1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47372
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    public static void main (String[] args)
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int x = 1;
        for(int j=0; j<n ;j++)
            a[j] = s.nextInt();
        Arrays.sort(a);
        for(int j=1; j<n; j++)
        {
            if(a[j]!=a[j-1])
                x++;
        }
//        System.out.println(x);
        int[][] d = new int[x][2];
        d[0][0] = a[0];
        x = 1;
        int r = 1;
        for(int j=1; j<n; j++)
        {
            if(a[j]!=a[j-1])
            {
                d[x][0] = a[j];
                d[x-1][1] = r;
                r = 1;
                x++;
            }
            else
                r++;
        }
        d[x-1][1] = r;
//        for(int j=0; j<d.length; j++)
//            System.out.println(d[j][0]+" "+d[j][1]);
        int c = 0;
        for(int i=0; i<d.length-2; i++)
        {
            for(int j=i+1; j<d.length-1; j++)
            {
                for(int k=j+1; k<d.length; k++)
                {
                    if(d[i][0]+d[j][0]>d[k][0])
                        c+=d[i][1]*d[j][1]*d[k][1];
                }
            }
        }
        System.out.println(c);
    }
}

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

int k[10], t, N, a;
int main(){
	cin>>N;
	for(int i = 0; i < N; i ++){
		cin>>a;
		if(1 <= a && a <= 399)k[0]++;
		else if(400 <= a && a <= 799)k[1]++;
		else if(800 <= a && a <= 1199)k[2]++;
		else if(1200 <= a && a <= 1599)k[3]++;
		else if(1600 <= a && a <= 1999)k[4]++;
		else if(2000 <= a && a <= 2399)k[5]++;
		else if(2400 <= a && a <= 2799)k[6]++;
		else if(2800 <= a && a <= 3199)k[7]++;	
		else if(3200 <= a)t++;
	}
	int x = 0;
	for(int i = 0; i < 8; i ++)if(k[i] > 0)x ++;
	
	int minv, maxv;
	maxv = x + t;
	if(x == 0)minv = 1;
	else minv = x;
	printf("%d %d", minv, maxv);
			
	return 0;
} 

Measured memory_bytes: 256
"""
3
3 1 2
2 5 4
3 6

ans 14
"""


def main():
    N = int(input())
    A = [int(x)-1 for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]

    total_eat_point = 0
    for round_num in range(N):
        total_eat_point += B[A[round_num]]
        if round_num == 0:
            continue
        if A[round_num] - 1 == A[round_num-1]:
            total_eat_point += C[A[round_num-1]]

    print(total_eat_point)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;


int main() {
	int i, j;
	int N, K;
	int ans = 1;
	cin >> N >> K;
	for (i = 0; i < N; ++i) {
		if (ans <K) {
			ans *= 2;
		}
		else {
			ans += K;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

int64_t a;
  cin>>a;
vector<int64_t> vec(3761);
  vec.at(0)=100;
  for(int i=1;i<3761;i++){vec.at(i)=vec.at(i-1)/100+vec.at(i-1);
                         if(vec.at(i)>=a){cout<<i<<endl;break;}
                           }
}

Measured memory_bytes: 3636
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
      	if(N>=1000){
        	System.out.println("ABD");
        }else{
        	System.out.println("ABC");
        }
    }
}

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

int main(void) {
    long long n, d;
    cin >> n >> d;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        long long x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=2e5+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

struct dat {
	int c0,c1;
	bool operator<(const dat &A) const {
		return 1ll*c1*A.c0<1ll*A.c1*c0;
	}
	dat operator+(const dat &A) const {
		return (dat){c0+A.c0,c1+A.c1};
	}
} v[N];

int n,p[N],fa[N];
ll ans;
set<pair<dat,int>> s;

int getf(int x) {
	return x==fa[x]?x:fa[x]=getf(fa[x]);
}

int main() {
	cin>>n;
	for(int i=2;i<=n;i++) p[i]=gi();
	for(int i=1,x;i<=n;i++) x=gi(),v[i]=(dat){x==0,x==1},fa[i]=i,s.insert(mp(v[i],i));
	while(!s.empty()) {
		int u=s.begin()->se;s.erase(s.begin());if(u==1) continue;
		int t=getf(p[u]);
		ans+=1ll*v[t].c1*v[u].c0;fa[u]=t;
		s.erase(mp(v[t],t));v[t]=v[t]+v[u];s.insert(mp(v[t],t));
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 16000
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
using namespace std;
int main(void){
    int N; cin >> N;
    int i = 0;
    int j = 0;
    string answer = "No";
    while(i < 26) {
        j = 0;
        while (j < 15) {
            int tmp = i * 4 + 7 * j;
            if (tmp == N) {
                answer = "Yes";
            }
            j++;
        }
        i++;
    }
    cout << answer << endl;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  int a = 0, b = 0;
  for (int i = 0; i < s.size(); i++) {
    int c = s[i] - '0';
    if (c == i % 2) a++;
    if (c != i % 2) b++;
  }
  cout << min(a, b) << '\n';
}


Measured memory_bytes: 3780
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <functional>

using namespace std;

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

    if(n.find("AC") != string::npos){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
  return 0;
  
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

    public static String Y = "Yes";
    public static String N = "No";
    public static String I = "IMPOSSIBLE";
    public static String B = "Bad";
    public static String G = "Good";
    public static long MOD = (long) (Math.pow(10, 9) + 7);
    public static Scanner sc = new Scanner(System.in);

    static int n;
    static int m;
    static int x;
    static int loopCount = 0;
    static int[][] a;
    static int[] c;
    static int sum_c = 0;
    static int[] sum_c_save;
    static int[] understand;

    public static void main(String[] args) {

        int n = ni();
        int x = ni();

        int now = 0;
        int count = 1;
        for (int i = 0; i < n; i++) {
            now += ni();

            if (now <= x) {
                count++;
            }
        }
        out(count);
    }

    /*
     * 以下メソッド集
     */
    static int ni() {

        return sc.nextInt();
    }

    static long nl() {

        return sc.nextLong();
    }

    static String n() {

        return sc.next();
    }

    static char[] nc() {

        return sc.next().toCharArray();
    }

    static int kaijo(int n) {

        if (n == 0 || n == 1) {
            return 1;
        } else {
            return n * kaijo(n - 1);
        }
    }

    static int fib(int n) {

        return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
    }

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

    static void out(char info) {

        System.out.println(info);
    }

    static void outn(String info) {

        System.out.print(info);
    }

    static void outn(int info) {

        System.out.print(info);
    }

    static void outn(double info) {

        System.out.print(info);
    }

    static void outn(long info) {

        System.out.print(info);
    }

    static void outn(char info) {

        System.out.print(info);
    }

    static int max(int a, int b) {

        return Math.max(a, b);
    }

    static long max(long a, long b) {

        return Math.max(a, b);
    }

    static int min(int a, int b) {

        return Math.min(a, b);
    }

    static long min(long a, long b) {

        return Math.min(a, b);
    }
}


Measured memory_bytes: 23380
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def collatz(n: int):
    if n%2:
        return 3*n+1
    else:
        return n//2
    
s = ni()
numset = set([s])

prev = s
cur = 0
idx = 1
for i in range(2 * 10**6):
    idx += 1
    
    cur = collatz(prev)
    prev = cur
    
    if cur in numset:
        break
    else:
        numset.add(cur)
        
print(idx)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  ll N;
  cin >> N;
  if(N % 2 == 0)
    cout << N << endl;
  else
    cout << N*2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
 
#define REP(i,a,n) for(int i = a;i < n;i++)
 
using namespace std;
 
int main(){
  string s,t;
  cin >> s >> t;

  bool flag1= false;

  REP(i,0,s.size() - t.size() + 1) {
      bool flag2 = true;
      REP(j, 0, t.size()) {
          if (t[t.size()-j-1] != s[s.size()-j-i-1] and s[s.size()-j-i-1] != '?') {
              flag2 = false;
              break;
          }
          
      }

      if (flag2 == true) {
          flag1=true;
          REP(j,0, t.size()) {
              s[s.size()-j-i-1] = t[t.size()-j-1];
          }

          break;
        }
        
    }

    if (flag1==true) {
        REP(i,0,s.size()) {
            if (s[i] =='?') {
                s[i] = 'a';
            }
        }
        cout << s << endl;

    } else {
        cout << "UNRESTORABLE" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    boolean[] C = new boolean[N];
    int A = sc.nextInt();
    for (int i = 0; i < N - 1; i++)
      C[A - 1] = A + 1 == (A = sc.nextInt());
    int result = 0;
    for (int i = 0; i < N; i++)
      result += sc.nextInt();
    for (int i = 0; i < N - 1; i++)
      if (C[i])
        result += sc.nextInt();
      else
        sc.nextInt();
    System.out.println(result);
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define all(c) (c).begin(),(c).end()
#define endl '\n'
using namespace std;

//                                      mdsaqib
signed main(){
    fast;
    int t=1;
    //cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector <int> A(n,0);
        for(int i=0;i<n;i++){
            cin >> A[i];
        }
        vector <int> V(1e5+5,0);
        int sum=0;
        for(int i=0;i<n;i++){
            V[A[i]]++;
            sum+=A[i];
        }
        int q;
        cin >> q;
        for(int i=0;i<q;i++){
            int a,b;
            cin >> a >> b;
            int k=b-a;
            int tr=V[a];
            V[a]=0;
            V[b]+=tr;
            sum+=tr*k;
            cout << sum << endl;
        }
    }
}


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

int main(){
  vector<int> v(8);
  rep(i,8)v[i] = i;

  map< vector<int>, int > steps;
  steps[v] = 0;
  queue< vector<int> > q;
  q.push(v);

  while(q.size()){
    v = q.front(); q.pop();
    int s = steps[v];

    int cur = 0;
    rep(i,8){
      if(v[i] == 0)cur = i;
    }

    if(cur-4>=0){
      swap(v[cur],v[cur-4]);
      if(steps.count(v) == 0){
	steps[v] = s + 1;
	q.push(v);
      }
      swap(v[cur],v[cur-4]);
    }

    if(cur+4<8){
      swap(v[cur],v[cur+4]);
      if(steps.count(v) == 0){
	steps[v] = s + 1;
	q.push(v);
      }
      swap(v[cur],v[cur+4]);
    }

    if(cur%4!=0 && cur-1>=0){
      swap(v[cur],v[cur-1]);
      if(steps.count(v) == 0){
	steps[v] = s + 1;
	q.push(v);
      }
      swap(v[cur],v[cur-1]);
    }

    if(cur%4!=3 && cur+1<8){
      swap(v[cur],v[cur+1]);
      if(steps.count(v) == 0){
	steps[v] = s + 1;
	q.push(v);
      }
      swap(v[cur],v[cur+1]);
    }
  }

  while(cin >> v[0]){
    rep(i,7)cin >> v[i+1];
    cout << steps[v] << endl;
  }
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int main()
{
  int N,K;
  string S;
  cin >> N >> K >> S;
  S[K-1] = S[K-1] - 'A' + 'a';
  cout << S << endl;

  return 0;
}


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

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

int prime1[5600];
int n;
int ans;
int main(){
    cin>>n;
    for(int i=2;i<=5600;i++)    {  if(isprime(i)&&(i%10==1))  prime1[++ans]=i;    }
    //for(int i=1;i<=n;i++)   cout<<prime1[i]<<" ";
    for(int i=1;i<=n;i++) cout<<prime1[i]<<" ";
return 0;
}





Measured memory_bytes: 256