akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<string>

using namespace std;


int main() {
	int N,A,B;
	cin >> N>>A>>B;
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int a = 0;
		int b = i;
		while (b > 0) {
			cerr << b << " " << flush;
			a += b%10;
			b /= 10;
		}
		if (A <= a && a <= B)ans+=i;
	}
	cout << ans;
	return 0;
}



/*int binSearch(vector<int> A, int key) {
	int left = 0, right = A.size();
	int abort = 0;
	sort(A.begin(), A.end());
	while (left + 1 < right) {// || [left,right) || > 1
		int mid = (left + right) / 2;
		if (A[mid] > key)right = mid;
		else
			left = mid;
	}
	return left || A[left] == key ? left : -1;
}*/


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e+18
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int k;
long long int a[100001], mi, ma;

int main(){
	cin >> k;
	for(int i = k-1;i >= 0;i--){
		cin >> a[i];
	}
	mi = 2;
	ma = 3;
	if(a[0]!=2){
		cout << -1 << endl;
		return 0;
	}
	for(int i = 1;i < k;i++){
		mi = (mi-1)/a[i]*a[i]+a[i];
		if(mi>ma){
			cout << -1 << endl;
			return 0;
		}
		ma = ma/a[i]*a[i]+a[i]-1;
	}
	cout << mi << " " << ma << endl;
	return 0;
}

Measured memory_bytes: 1024
import math
N=int(input())
q=int(math.sqrt(N*2))
if N*2!=q*q+q:print("No");exit()
S=[list(range(1,q+1))]
for j in range(1,q+1):S.append([j])
last=q
for i in range(1,q):
	r=list(range(last+1,last+1+q-i))
	S[i]+=r
	for j in range(q-i):S[i+j+1]+=[r[j]]
	last=r[-1]
print("Yes")
print(len(S))
for s in S:print(len(s)," ".join(map(str,s)))

Measured memory_bytes: 9204
# -*- coding: utf-8 -*-
"""
Created on Mon Apr  1 22:23:40 2019

@author: Owner
"""
a = []
b = str(input())

for item in b:
    if item == "A":
        item_mod = item.replace("A","T")
    if item == "G":
        item_mod = item.replace("G","C")
    if item == "T":
        item_mod = item.replace("T","A")
    if item == "C":
        item_mod = item.replace("C","G")
    a.append(item_mod)
print(a[0])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
char a,b; 
using namespace std;

int main()
{
  while(cin>>a>>b)
  {
   if(a>b)
     printf(">\n");
   else if(a<b)
     printf("<\n");
   else 
     printf("=\n");
  } 
return 0;
}


Measured memory_bytes: 256
use std::cmp::max;
#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//usage
//input! {
//  h: i32;
//  v: [i32; n]
//  x: [[i32; n]; m]
//  f: chars <- Vec<char>
//}

fn main() {
    input!{
        n: usize, w: usize,
        items: [(i64, i64); n]
    }

    // dp[i][j] = i番目までの品物の中でj以下の重さが保証されている中での価値の最大値
    // dp[i + 1][j] = max(dp[i][j] <= not select, dp[i][j - weight[i]] + value)
    let mut dp = vec![vec![0; w + 5]; n + 5];

    for i in 0..n {
        for j in 0..w + 1 {
            if items[i].0 <= j as i64 {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - items[i].0 as usize] + items[i].1);
            }
            else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    println!("{}", dp[n][w]);
}

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

//N個の整数を読み込み、選択ソートのアルゴリズムで昇順に並び替え出力するプログラムを作成してください。
int main(){
    int N, i, min, prev, count = 0, array[100] = {};
    cin >> N;

    //N個の整数を配列に格納
    i = 0;
    while(i < N){
        cin >> array[i];
        i++;
    }

    //選択ソート
    for(int i=0; i <= N-1; i++){
        min = i;
        for(int j = i; j <= N-1; j++){
            if (array[j] < array[min]) min = j;
        }
        prev = array[i]; array[i] = array[min]; array[min] = prev;
        if (min != i) count++;

    }

    i = 0;
    while(i < N){
        cout << array[i];
        if (i < N-1) cout << ' ';
        i++;
    }
    cout << endl;
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3116
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		long n = scanner.nextLong();
		int ans = 0;
		long a = 0;
		long i;
		long j = 0;
		for(i = 1; i*i <= n; i++){
			if(n % i == 0){
				a = (int) (n / i);
				j = i;
			}
		}
		int p = String.valueOf(a).length();
		int q = String.valueOf(j).length();
		if(p < q){
			System.out.println(q);
		}else{
			System.out.println(p);
		}
	}
}

Measured memory_bytes: 21716
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
using namespace std;

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

	cout << (a+b)%24 << endl;

	return 0;
}


Measured memory_bytes: 256
def gcd(a,b):
    while b:
        a, b = b, a % b
    return a

N = int(input())
ans = 0
for a in range(1,N+1):
    for b in range(1,N+1):
        ab = gcd(a,b)
        for c in range(1,N+1):
            ans += gcd(ab,c)
print(ans)


Measured memory_bytes: 68436
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

class ANextAlphabet {
public:
	void solve(std::istream& in, std::ostream& out) {
        char x;in >> x;
        out << (char)(x+1) << "\n";
	}
};


int main() {
	ANextAlphabet solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main(){
	int h, w;
	string str;
	cin>>h>>w;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin>>str;
			if(str=="snuke"){
				cout<<char('A'+j)<<i+1<<endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
int n;
scanf("%d\n",&n);
int *nums;
nums=(int)malloc(n);
int i;
for(i=0;i<n;i++){
if(i!=n-1){
scanf("%d ",&nums[i]);
}
else{
scanf("%d",&nums[i]);
}
}
int j;
for(j=1;j<n;j++){
printf("%d ",nums[n-j]);
}
printf("%d\n",nums[0]);
return 0;
}




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

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

    int b[n];
    fill_n(b, n, 0);

    for(int i = 0; i < n; i++){
        cin >> b[i];
    }

    
    int num = 1;
    int count = 0;
    while(true){
        num = b[num-1];
        count++;
        if(num == 2){
            cout << count << endl;
            return 0;
        }
        else {
            if(count > n){
                cout << -1 << endl;
                break;
            }
        }
    }


}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int sum(vector<int> A){
    int res = 0;
    for (int a : A) res += a;
    return res;
}


int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i,N) cin >> L[i];
    int sum_L = sum(L);
    rep(i,N){
        if (L[i] >= (sum_L - L[i])){ 
            cout << "No" << endl;
            return 0;
        }
         
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio> 
#include<cstring>
using namespace std;
int main()
{
	int n,k,x,y,z;
	cin>>n>>k>>x>>y;
	if(n>k)
	{
		z=k*x+(n-k)*y;
		
	}
	else
		z=n*x;
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 256
(* O(n) *)
let find_btw f from n =
  let rec find i = if i >= n || f i then i else find (i + 1) in find from

(* O(|a_s|^2) *)
let solve a_s k =
  let n = Array.length a_s in
  if n = find_btw
    (fun i -> n > find_btw (fun j -> a_s.(j) - a_s.(i) > k) (i + 1) n)
    0
    n then "Yay!" else ":("

let read_int_array n = Array.init n (fun _ -> read_int ())

let _ =
  match read_int_array 6 with
  | [|a; b; c; d; e; k|] -> solve [|a; b; c; d; e|] k |> print_endline
  | _ -> ()

Measured memory_bytes: 4480
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    int a;
    string s;
    cin>>a>>s;

    if(a>=3200){
        cout<<s<<endl;
    }
    else{
        cout<<"red"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vs vector<string>
#define vvi vector<vector<int>>
#define mii map<int,int>
#define msi map<string,int>
using namespace std;
int main()
{
    long long int n,ans=0,m,temp;
    cin>>n;
    long int a[n];
    map<ll,ll> b;
    for(long int i=0;i<n;i++)
    {
    	cin>>a[i];
    	b[a[i]]+=1;
	}
	map<long long int, long long int>::iterator itr; 
	for(itr=b.begin();itr!=b.end();itr++)
	{
		long int v=itr->second;
		ans+=((v)*(v-1))/2;
	}
	
	for(long int i=0;i<n;i++)
	{
		temp=ans;
		
		m=b[a[i]];
		m=(m*(m-1))/2;
		ans=ans-m;
		
		m=b[a[i]];
		m=((m-1)*(m-2))/2;
		ans=ans+m;
		
		cout<<ans<<endl;
		ans=temp;
	}
    return 0;
}

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

int main() {
  int N;
  cin>>N;
  int n=N;
  int sum=0;
  while(n!=0){
    int m=n%10;
    n=(n-m)/10;
    sum+=m;
  }
  if(N%sum==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

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

	if(n % k == 0) cout << 0 << endl;
	else{
		ll tmp = n % k;
		cout << min(tmp, k - tmp) << endl;
	}

	return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M,V,K;
const int MAX_N = 10000,MAX_V = 30017;
vector<int> A,W;
vector<int> ball [MAX_N];
struct edge{
	int to,cap,rev;
	ll cost;
};
vector<edge> G [MAX_V];
ll h [MAX_V],minCost [MAX_V];
int prevv [MAX_V],preve [MAX_V];
const ll INF = 1e9,INFLL = 1e18;

inline void add_edge(int from,int to,int cap,ll cost)
{
	G [from].push_back(edge{to,cap,int(G [to].size()),cost});
	G [to].push_back(edge{from,0,int(G [from].size()) - 1,-cost});
}

ll min_cost_flow(int s,int t,int f)
{
	ll res = 0;
	memset(h,0,sizeof(h));
	while(f > 0){
		fill(minCost,minCost + MAX_V,INFLL);
		priority_queue< pair<ll,int>,vector< pair<ll,int> >,greater< pair<ll,int> > > pq;
		minCost [s] = 0;
		pq.push(make_pair(0ll,s));
		while(pq.empty() == false){
			ll cost = pq.top().first;
			int curr = pq.top().second;
			pq.pop();

			if(minCost [curr] < cost) continue;
			FOR(i,0,G [curr].size()){
				edge& e = G [curr] [i];
				if(e.cap > 0 && chmin(minCost [e.to],cost + e.cost + h [curr] - h [e.to])){
					prevv [e.to] = curr;
					preve [e.to] = i;
					pq.push(make_pair(minCost [e.to],e.to));
				}
			}
		}
		if(minCost [t] >= INFLL) return -1;
		FOR(i,0,V) h [i] += minCost [i];
		int d = f;
		for(int v = t;v != s;v = prevv [v]){
			chmin(d,G [prevv [v]] [preve [v]].cap);
		}
		res += h [t] * d;
		f -= d;
		for(int v = t;v != s;v = prevv [v]){
			edge& e = G [prevv [v]] [preve [v]];
			e.cap -= d;
			G [e.to] [e.rev].cap += d;
		}
	}
	return res;
}

int main()
{
	scanf("%d%d%d",&M,&N,&K);
	W.assign(N,0);
	A.assign(K,0);
	FOR(i,0,N){
		scanf("%d",&W [i]);
	}
	FOR(i,0,K){
		scanf("%d",&A [i]);
		A [i]--;
		ball [A [i]].push_back(i);
	}

	V = K * 3 + 2;
	int s = K * 3,t = K * 3 + 1;
	add_edge(s,0,INF,0);
	add_edge(K - 1,t,INF,INF);
	add_edge(K * 3 - 1,t,1,0);
	FOR(i,0,K){
		add_edge(i,i + K,1,W [A [i]]);
		add_edge(i + K,i + K * 2,1,0);
		if(i + 1 < K){
			add_edge(i,i + 1,INF,INF);
			add_edge(i + K * 2,i + 1,1,0);
		}
	}
	FOR(i,0,N) FOR(j,1,ball [i].size()){
		int x = ball [i] [j - 1],y = ball [i] [j];
		add_edge(x + K * 2,y + K,1,(y - x - 1) * INF);
	}

	ll ans = min_cost_flow(s,t,M) - INF * (M - 1) * K;
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 8696
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  if(N==1) {
    if(A[0] == 0) {
      cout << 3 << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }
  if(A[0] != 0) {
    cout << 0 << endl;
    return 0;
  }
  vl rgb(3,0);
  rgb[0] = 1;
  ll ans = 3;
  srep(i,1,N) {
    ll cnt = 0;
    int k = -1;
    rep(j,3) {
      if(A[i] == rgb[j]) {
        cnt++;
        k = j;
      }
    }
    if(cnt == 0) {
      cout << 0 << endl;
      return 0;
    }
    ans *= cnt;
    ans %= MOD;
    rgb[k]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

long long M  = 1e9+7;
 
signed main(){
    fast;
    int n,m; cin >> n >> m;
    vector <pii> ans;
    int x = 1, y = n;
    if(n%2 == 1){
        for(int i=0 ; i<m ; i++){
            //cout << "*" << endl;
            ans.pb({x++,y--});
        }
    }
    else{
        int c = ((n-1)/2+1)/2; 
        for(int i=0 ; i<min(c,m) ; i++){
            ans.pb({x++,y--});
        }
        y--;
        for(int i=0 ; i<m-c ; i++){
            ans.pb({x++,y--});
        }
    }
    for(auto x : ans){
        cout << x.f << " " << x.s << endl;
    }
}


Measured memory_bytes: 5304
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int n = 0, i;
	char s[101] = "", t[101] = "";
	while (cin >> s)
	{
		if (cin.eof()) break;
		for (i = strlen(s)-1; i >= 0; i--)
		{
			t[strlen(s)-1-i] = s[i];
		}
		t[strlen(s)] = '\0';
		if (strcmp(s, t) == 0) n++;
	}
	cout << n << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n,L;
	int a[10];
	int ans=INF;
	string s;
	cin>>s;
	L=s.size();
	for(int i=0;i<L-2;i++){
		a[i]=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
		//cout<<a[i]<<endl;
	}
	for(int i=0;i<L-2;i++){
		ans=min(ans,abs(753-a[i]));
	}
	cout<<ans<<endl;;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())
L = ["0","1","2","3","4","5","6","7","8","9"]
cnt = 0
for a in L:
    for b in L:
        for c in L:
            target = [a,b,c]
            T = 0
            for i in range(N):
                see = S[i]
                if target[T]==see:
                    T+=1
                    if T==3:
                        cnt += 1
                        break
print(cnt)

Measured memory_bytes: 42972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define each(i, a) for(auto &i : a)

constexpr ll INF = 1000000000;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

using dat = pair<int, int>;
int main() {
    init();

    int x, y, z, n, m, s, t; cin >> x >> y >> z >> n >> m >> s >> t;
    --s, --t;

    vector<VI> g(x + y + z + n + m);
    FOR(i, 0, n) {
        int a, b; cin >> a >> b;
        --a, --b;
        g[x + y + z + i].push_back(a);
        g[a].push_back(x + y + z + i);
        g[x + y + z + i].push_back(x + b);
        g[x + b].push_back(x + y + z + i);
    }
    FOR(i, 0, m) {
        int c, d; cin >> c >> d;
        --c, --d;
        g[x + y + z + n + i].push_back(x + c);
        g[x + c].push_back(x + y + z + n + i);
        g[x + y + z + n + i].push_back(x + y + d);
        g[x + y + d].push_back(x + y + z + n + i);
    }

    VI dis(x + y + z + n + m, INF);
    dis[x + y + z + s] = 0;
    PQ<dat> dik;
    dik.emplace(0, x + y + z + s);
    while (!dik.empty()) {
        int d, now;
        tie(d, now) = dik.top();
        dik.pop();
        if (dis[now] < d)continue;
        each(to, g[now]) {
            if (!chmin(dis[to], dis[now] + 1))continue;
            dik.emplace(dis[to], to);
        }
    }

    cout << (dis[x + y + z + n + t] == INF ? -1 : dis[x + y + z + n + t] / 2) << "\n";
}


Measured memory_bytes: 29996
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    rep(i,h){
        rep(j,w){
            string temp;
            cin >> temp;
            if(temp=="snuke"){
                cout << (char)('A'+j) << (i + 1) << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

ll ds(ll n){
    ll res=0;
    while(n){res+=n%10; n/=10;}
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K; cin >> K;
    ll a=0,cnt=0,i=1,last=0;
    while(K){
        ll n=(ll)i*pow(10,cnt)+a;
        if (n<=last){++i; continue;}
        if (n<=(ll)pow(10,cnt)*ds(n)){
            cout << n << endl;
            ++i,--K,last=n;
        }
        else {++cnt,i=1; a*=10,a+=9;}
    }
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; ++i)

struct BIT {
    vector<ll> data;
    int N;

    BIT(int n) {
        N = 1;
        while (N <= n) N *= 2;
        N *= 2;
        data = vector<ll>(N+1);
    }

    void update(int i, ll x) {
        for (int k = i; k <= N; k += k&-k) data[k] = max(data[k], x);
    }

    ll getMax(int i) {
        ll res = 0;
        for (int k = i; k > 0; k -= k&-k) res = max(res, data[k]);
        return res;
    }
};

const int MAX = 2e5+10;
int N;
int H[MAX], A[MAX];
BIT bit(MAX);

int main () {
    cin >> N;
    REP (i, N) cin >> H[i];
    REP (i, N) cin >> A[i];

    REP (i, N) {
        ll m = bit.getMax(H[i]);
        bit.update(H[i], m+A[i]);
    }
    cout << bit.getMax(N) << endl;
}

Measured memory_bytes: 5888
#include<iostream>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
bool cmp(pair<int,int> a,pair<int,int> b)
{
	if(a.second!=b.second)
	return a.second<b.second;
	return a.first<b.first;
}
int main()
{
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		arr[i]=arr[i]-i+1;
	}
	sort(arr,arr+n);
	int m=arr[n/2];
	long long int ans=0;
	for(int i=0;i<n;i++)
		ans+=abs(arr[i]-m);
	cout<<ans<<"\n";
}

Measured memory_bytes: 1024
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################
X = int(input())
C =100
cnt = 0
while True:
    C += C//100
    cnt += 1
    if C>=X:
        break
print(cnt)





Measured memory_bytes: 9164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int S = Integer.parseInt(line);
		int h = S / 3600;
		int m = (S % 3600) / 60;
		int s = (S % 3600) % 60;
		System.out.println(h + ":" + m + ":" + s);

	}

}

Measured memory_bytes: 26152
import sys

for line in sys.stdin:
    [a, b, c, d, e, f] = [float(x) for x in line.split()]
    determinant = a * e - d * b
    x = e * c - b * f
    y = -d * c + a * f
    x /= determinant
    y /= determinant
    if "%.3f" % (x) == "-0.000":
        result_x = "0.000"
    else:
        result_x = "%.3f" % (x)

    if "%.3f" % (y) == "-0.000":
        result_y = "0.000"
    else:
        result_y = "%.3f" % (y)

    print result_x, result_y

Measured memory_bytes: 6260
n = int(input()); #泊まる日数
k = int(input()); #k泊まで
x = int(input()); #k泊まで1泊の値段
y = int(input()); #k泊以降1泊の値段
ans = 0;

for i in range(n):
    if((i+1) <= k):
        ans += x;
    else:
        ans += y;

print(ans);

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    int a,b,c,k;cin>>a>>b>>c>>k;
    int count1=0,count2=0;
    while(true) {
        if(a>=b) {
            b *=2;
            count1++;
        }
        else if(b>=c) {
            c*=2;
            count2++;
        }
        else {
            break;
        }
    }
    if(k>=(count1+count2)) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}

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

using namespace std;

int main() {
    int a,b,a2,b2;
    int lcm,gcd;
    while(cin >> a >> b){
        a2=a;
        b2=b;
        while(a != b){
        if(a>b){a = a-b;}
        else{b=b-a;}
        }
        lcm = a;
        gcd=a2 / lcm * b2;
        cout << lcm << " " << gcd << endl;
    }

}

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

typedef long long LL;

const int N = 110;
const int W = 100010;

int wt[N], val[N];
LL f[W][N]; 

LL dp(int remaining_capacity, int n) {
	if(f[remaining_capacity][n] != -1) {
		return f[remaining_capacity][n];
	}
	if(remaining_capacity <= 0) return 0;
	if(n < 0) return 0;
	if(n == 0 and remaining_capacity >= wt[n]) {
		return (f[remaining_capacity][n] = val[n]);
	}
	if(remaining_capacity >= wt[n]) {
		LL v1 = val[n] + dp(remaining_capacity - wt[n], n - 1);
		LL v2 = dp(remaining_capacity, n - 1);
		// cout << remaining_capacity << ", " << n << ", " << v1 << ", " << v2 << "\n";
		return (f[remaining_capacity][n] = max(v1 , v2));
	} else {
		return (f[remaining_capacity][n] = dp(remaining_capacity, n - 1));
	}
}

int main() {	
	for(int i = 0 ; i < W ; i++) {
		for(int j = 0 ; j < N ; j++) {
			f[i][j] = -1;
		}
	}
	int n; cin >> n;
	int w; cin >> w;
	for(int i = 0 ; i < n ; i++) {
		cin >> wt[i] >> val[i];
	}
	cout << dp(w, n - 1);
}


Measured memory_bytes: 86144
#include <iostream>

using namespace std;

int main()
{
  char s[3];
  
  cin >> s;
  
  for (int i = 0; i < 3; i++) {
    if (s[i] == '7') {
      cout << "Yes" << endl;
      return (0);
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
volatile int a[200];
volatile int b[200];
volatile int n;

void shuffle(int k){
	int i,j;
	for (i=0;i<(2*n);i++){
		b[i]=a[i];
	}
	if (k!=0){
		for (i=0;i<(2*n-k);i++){
			a[i]=b[i+k];
		}
		for (i=2*n-k;i<(2*n);i++){
			a[i]=b[i-(2*n-k)];
		}
	}else{
		for (i=0;i<(2*n);i+=2){
			a[i]=b[i/2];
		}
		for (i=1;i<(2*n);i+=2){
			a[i]=b[n+(i-1)/2];
		}
	}
}

int main(void){
	int i;
	for (i=0;i<200;i++){
		a[i]=0;
		b[i]=0;
	}
	
	scanf("%d",&n);
	for(i=0;i<(2*n);i++){
		a[i]=i+1;
	}
	int m,j;
	scanf("%d",&m);
	for (i=0;i<m;i++){
		scanf("%d",&j);
		shuffle(j);		
	}
	for (i=0;i<(2*n);i++){
		printf("%d\n",a[i]);
	}
	
	return 0;
}

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int n;  cin >> n;
  cout << (n+1000-1)/1000*1000 - n << "\n";
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int k;
    cin>>k;
    string str;
    cin>>str;
    for (int i=0;i<str.size();i++){
        str[i]+=k;
        if (str[i]>'Z'){
            str[i]=64+(str[i]-'Z');
        }
    }
    cout<<str<<endl;
}

Measured memory_bytes: 3596
import math

a, b, h, m = map(int, input().split())
radA = (360 // 12) * h + 30 * (m / 60)
radB = (360 // 60) * m
radAB = abs(radA - radB)
radAB = radAB / 180 * math.pi
c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(radAB)
print(math.sqrt(c2))


Measured memory_bytes: 9500
n = int(input())
a = list(map(int, input().split()))
cnt = 1
b = [0] + a
c = [(i-j)//abs(i-j) for i, j in zip(a, b) if i != j]
del c[0]
if c:
  mae=c[0]
  d=iter(c)
  for x in d:
    if x != mae:
      cnt += 1
      try:
        mae = d.__next__()
      except StopIteration:
        break
print(cnt)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;

int main()
{
  int n;
  cin >> n;
  vector<unsigned int> a(n);

  rep(i, n) {
    cin >> a[i];
  }

  int r = 0;
  ll ans = 0;
  unsigned int val = a[0];
  for (int l = 0; l < n; l++) {
    if (l > r) {
      r++;
      val += a[l];
    }

    while (r < n-1 && ((val ^ a[r+1]) == (val + a[r+1]))) {
//      cerr << (val ^ a[r+1]) << "  " << val + a[r+1] << "  val: " << val << endl;
      r++;
      val += a[r];
//      cerr << "val: " << val << endl;
    }
//    cerr << "l: " << l << "  r: " << r << endl;
    ans += r - l + 1;
    val -= a[l];
  }

  cout << ans << endl;

  return 0;
}


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

int main(void) {
  int N;
  cin >> N;
  
  vector<int> H(N);
  rep(i, N) {
    cin >> H[i];
  }

  reverse(H.begin(), H.end());
  int prev = H[0];
  for(int i = 1; i < N; ++i) {
    if (prev < H[i]) {
      if (prev < --H[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
    prev = H[i];
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 768
S = input()
N = len(S)
ans = [0]*N
left = 0
center = 0
right = 0
while (right < N - 1):

    while (S[center] == "R"):
        center += 1
    right = center
    while (S[right] == "L"):
        if right == N - 1:
            break
        right += 1
    if S[right] != "L":
        right -= 1

    for i in range(left, center):
        if (center - i) % 2 == 0:
            ans[center] += 1
        else:
            ans[center - 1] += 1

    for k in range(center, right + 1):
        if (k - center) % 2 == 0:
            ans[center] += 1
        else:
            ans[center - 1] += 1

    left = right + 1
    center = left
print(*ans)


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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < (1<<4); i++) {
    int tmp = s[0] - '0';
    for (int j = 1; j < 4; j++) {
      if (i & (1<<j)) {
        tmp -= (s[j] - '0');
      } else {
        tmp += (s[j] - '0');
      }
    }
    if (tmp == 7) {
      cout << s[0];
      if (i & (1<<1)) {
        cout << '-';
      } else {
        cout << '+';
      }
      cout << s[1];
      if (i & (1<<2)) {
        cout << '-';
      } else {
        cout << '+';
      }
      cout << s[2];
      if (i & (1<<3)) {
        cout << '-';
      } else {
        cout << '+';
      }
      cout << s[3] << "=7" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main( )
{
    int n,x;
    cin>>n>>x;
    int D[n+1],L[n+1];
    for(int i=1;i<=n;i++)
        cin>>L[i];
    D[0]=L[0]=0;
    for(int i=1;i<=n;i++)
        D[i]=D[i-1]+L[i];
   // for(int i=0;i<=n;i++)
   //     cout<<D[i]<<endl;
   int count=0;
   for(int i=0;i<=n;i++)
   {
       if(x>=D[i])
        count++;
   }
   cout<<count<<endl;
    return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    if (n < 26) {
        char c;
        for (c = 'a'; c <= 'z'; c++) {
            if (s.find(c) == string::npos) {
                break;
            }
        }
        s += c;
        cout << s << endl;
        return 0;
    } else {
        if (s == "zyxwvutsrqponmlkjihgfedcba") {
            cout << -1 << endl;
            return 0;
        } else {
            string t = s, ans;
            next_permutation(s.begin(), s.end());
            for (int i = 0; i < n; i++) {
                ans += s[i];
                if (t[i] != s[i]) {
                    break;
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import math

N,K=map(int,input().split())

v=0
prev_num=0
for i in range(N):
    if i+1==K:
        v+=N-K+1
        break
    KK=K/(i+1)
    num=math.ceil(math.log2(KK))
    if i==0:
        term=0.5**num
    else:
        term*=2**(prev_num-num)
    #print("i,KK,prev_num,num,v",i,KK,prev_num,num,v)
    v+=term
    prev_num=num
v/=N
print(v)

Measured memory_bytes: 3444
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x

t = int(input())
a = []
d = 0
for i in range(t):
  a.append(list(map(int,input().split())))
for j in a:
  if j[0] < j[1] or j[1] > j[3]:
    print("No")
  else:
    b = j[0] % j[1]
    k = gcd(j[1],j[3])
    c = j[0] % k
    d = j[2] % k
    if c > d:
      e = j[2] + c - d
    else:
      e = j[2] + k + c - d

    if j[1] > e:
      print("No")
    else:
      print("Yes")
    
    
    

Measured memory_bytes: 3064
#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[i];
	}
	set<int> anko;
	for(int i = 0; i < n; ++i){
		anko.insert(d[i]);
	}
	cout << anko.size() << endl;
	return 0;
}

Measured memory_bytes: 256
N, K, C = map(int, input().split())
S = input()

latest = []
i = len(S)+C
for j in range(K):
  i = S.rindex("o", 0, i-C)
  latest.append(i)

if i<=C or "o" not in S[:i-C]:
  i = -C-1
  for j in range(K):
    i = S.index("o", i+C+1)
    if i == latest.pop():
      print(i+1)


Measured memory_bytes: 11496
program main
  implicit none
  integer :: n, i
  integer, allocatable :: a(:), b(:)
  read (*, *) n
  allocate (a(n), b(n))
  read (*, *) a
  b(:) = 0
  do i = n, 1, -1
    if (mod(sum(b(i:n:i)), 2) /= a(i)) b(i) = 1
  end do
  write (*, "(i0)") sum(b)
  do i = 1, n
    if (b(i) == 1) write (*, "(i0)") i
  end do
end program main


Measured memory_bytes: 2816
#include <iostream>
#include <ctime>
#include <fstream>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <utility>
#include <cctype>
#include <list>
#include <bitset>
#include <unordered_set>

using namespace std;

#define FORALL(i,a,b) for(int i=(a);i<=(b);++i)
#define FOR(i,n) for(int i=0;i<(n);++i)
#define FORB(i,a,b) for(int i=(a);i>=(b);--i)

typedef long long ll;
typedef long double ld;
typedef complex<ld> vec;

typedef pair<ll,int> plli;
typedef pair<int,int> pii;
typedef map<int,int> mii;

#define pb push_back
#define mp make_pair

int main() {
  int A,B,C,X,Y;
  scanf("%d%d%d%d%d",&A,&B,&C,&X,&Y);

  ll ans = 100000000000000000ll;
  FORALL(R,0,200000) {
    if (R%2) continue;
    int P = max(0, X - R/2);
    int Q = max(Y - R/2, 0);

    ll sum = 1ll*A*P + 1ll*B*Q + 1ll*C*R;
    ans = min(ans, sum);
  }

  cout << ans << endl;
}














Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
 long long a,b;
 cin>>a>>b;
 if(b>=2*a&&b<=4*a)
 {
     if(b%2==0||b%4==0)
        cout<<"Yes"<<endl;
     else
        cout<<"No"<<endl;
 }
 else
 {
     cout<<"No"<<endl;
 }
}

Measured memory_bytes: 3592
def t(s):
    a = tuple(enumerate(s))
    return 'No' if 'R' in [j for i, j in a if i % 2 != 0] or 'L' in [j for i, j in a if i % 2 == 0] else 'Yes'


if __name__ == "__main__":
    print(t(input()))


Measured memory_bytes: 2940
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int N;
    vector<int> a;

    cin >> N;

    int x;
    for (int i = 0; i < N; i++){
        cin >> x;
        a.push_back(x);
    }
    int sum = 0;

    for (int i = 0; i < N; i++){
        int k = i;
        for (; k < N-1; k++){
            if (a[k] != a[k+1]){
                break;
            }
        }

        if (a[k] > a[k+1]){
            for (; k < N-1; k++){
                if (a[k] < a[k+1]) break;
            }
        } else {
            for (; k < N-1; k++){
                if (a[k] > a[k+1]) break;
            }
        }

        sum++;
        i = k;
    }
    cout << sum << endl;

}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <queue>
#include <utility>

#define ll long long
#define P pair<ll,ll>
#define MAX 300010
#define INF 100000000000
using namespace std;

vector<ll> G[MAX],H[MAX];
vector<P> E[1000010];
ll dist[MAX],did[MAX];
bool used[MAX];
queue<P> que;
ll so = 100000,ans;

void bfs(int s){
	que.push({0,s});
	while(!que.empty()){
		P p = que.front();
		que.pop();
		ll x = p.first,y = p.second;
		if(used[y]) continue;
		used[y] = true; dist[y] = x;
		for(int i=0;i<G[y].size();i++){
			if(!used[G[y][i]]){
				que.push({x+1,G[y][i]});
			}
		}
	}
}

void dfs(ll cur, ll p){
	if(did[cur]==p) return;
	did[cur] = p;
	G[so].push_back(cur);
	G[cur].push_back(so);
	for(int i=0;i<H[cur].size();i++){
		dfs(H[cur][i],p);
	}
}

int main(){
	ll i,j,n,m;
	cin >> n >> m;
	for(i=0;i<m;i++){
		ll p,q,c;
		cin >> p >> q >> c;
		p--; q--;
		E[c].push_back({p,q});
	}
	for(i=0;i<MAX;i++){
		did[i] = -1;
		dist[i] = -2;
		used[i] = false;
	}
	
	for(i=0;i<1000010;i++){
		vector<ll> v;
		for(auto& e:E[i]){
			H[e.first].push_back(e.second);
			H[e.second].push_back(e.first);
			v.push_back(e.first);
			v.push_back(e.second);
		}
		
		for(auto& r:v){
			if(did[r]!=i){
				dfs(r,i);
				so++;
			}
		}
		for(auto& e:E[i]){
			H[e.first].clear();
			H[e.second].clear();
		}
	}
	
	bfs(0);
	ans = dist[n-1]/2;
	cout  << ans << endl;
}
		

Measured memory_bytes: 65408
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long lint;

int N;
const int MAX_N = 100005;
const lint MOD = 1e9+7;

int a[MAX_N],chk[MAX_N];
int x,y;

lint fac[MAX_N], inv[MAX_N];

lint pw(lint x,lint y){
	lint ret = 1;
	while(y){
		if(y&1)ret = ret*x%MOD;
		x = x*x%MOD;
		y >>= 1;
	}
	return ret;
}

void init(){
	for(int i=0;i<N+1;i++){
		if(chk[a[i]]){
			x = chk[a[i]]-1;
			y=N-i;
			break;
		}
		chk[a[i]]=i+1;
	}

	fac[0] = 1;
	for(int i=1;i<=N+1;i++){
		fac[i] = fac[i-1]*i%MOD;
	}
	inv[N+1] = pw(fac[N+1],MOD-2);
	for(int i=N;i>=0;i--){
		inv[i] = inv[i+1]*(i+1ll)%MOD;
	}
}

lint nCr(lint n,lint r){
	if(n<r||r<0)return 0;
	return (fac[n]*inv[r]%MOD)*inv[n-r]%MOD;
}

void input(){
	cin>>N;
	for(int i=0;i<N+1;i++){
		cin>>a[i];
	}
}

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

	input();
	init();
	
	lint ans;
	for(int i=1;i<=N+1;i++){
		ans = nCr(N+1,i)-nCr(x+y,i-1);
		ans = (ans+MOD)%MOD;
		cout << ans << "\n";
	}

	return 0;
}

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

int main()
{
    int n, l;
    cin >> n >> l;
    vector<string> vec = vector<string>(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    string ans = "";
    for (int i = 0; i < n; i++)
    {
        ans += vec[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n , k;
    cin >> n >> k;
    ll a;
    vector<ll> b(n+1, 0);
    for(int i=0;i<n;i++){
    	cin >> a;
    	a++;
    	b[i+1] = b[i] + a;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
    	if(i+k > n) break;
    	ans = max(ans, b[i+k] - b[i]);
    }
    doublecout(double(ans) / 2.0);
    return 0;
}


Measured memory_bytes: 4768
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){

    string s; cin >> s;

    int n = s.size() - 1;

    ll ans = 0;
    for(int bit = 0; bit < (1<<n); bit++){
        
        string st;
        for(int i=0; i<n; i++){
            st += s[i];
            if(bit & (1<<i)){
                ans += stoll(st);
                st.clear();
            }
        }
        st += s[n];
        ans += stoll(st);
        st.clear();
    }

    cout << ans;

    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int n, ans;
bool b[1000];

int main() {
	cin >> n;
	b[105] = 1;
	b[135] = 1;
	b[165] = 1;
	b[189] = 1;
	b[195] = 1;
	for (int i = 0;i <= n;i++) {
		if (b[i])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
	int N=1 , sum=0;
	cin>>N;
	for(int i = 1 ; i <= N ; i++)
	{
		sum = sum + i;
	}
	cout<<sum<<endl;
	return 0;
}
	

Measured memory_bytes: 256
S=input()
a=int(S[0]+S[1])
b=int(S[2]+S[3])
if 0<a<13 and 0<b<13:
    print('AMBIGUOUS')
elif 0<a<13:
    print('MMYY')
elif 0<b<13:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
n = int(input())
A = [list(map(int,input().split())) for i in range(n)]

D = [[0] * 3 for i in range(n)]

D[0] = A[0]
for i in range(1, n):
    for j in range(3):
        D[i][j] = max(D[i-1][(j+1)%3], D[i-1][(j+2)%3]) + A[i][j]
print(max(D[-1]))


Measured memory_bytes: 102552
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int x = sc.nextInt();
		long len[] = new long[num];
		for(int i = 0; i < num; i ++) {
			len[i] = sc.nextLong();
		}
		long tmp = 0;
		int count = 1;
		for(int i = 0; i < num; i ++) {
			tmp += len[i];
			if(tmp > x) { break; }
			count ++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23764
def check_n(list_n, count = 0):
    new_list_n = [x/2 for x in list_n if x % 2 == 0]
    if len(new_list_n) != len(list_n):
        return count
    else:
        new_count = count + 1
        return check_n(new_list_n, new_count)
      
      
n = int(input())
nums = [int(x) for x in input().split()]
print(check_n(nums))

Measured memory_bytes: 3188
N = int(input())
A = list(map(int,input().split()))+[0]
kane = 1000
kabu = 0

baibai = [] 
#1は買い時、-1は売り時、0は無視
for i in range(N):
    sa = A[i+1] -A[i]
    if sa == 0:
        baibai.append(0)
    elif sa != abs(sa):
        baibai.append(-1)
    else:
        baibai.append(1)


#baibai通りに売買(最後の売り時で打ち切り)
for j in range(N):
    if baibai[j] > 0:
        kabu += (kane//A[j])
        kane -= A[j] * (kane//A[j])
    elif baibai[j] < 0:
        kane += A[j] * kabu
        kabu = 0

print(kane)

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    int n;
    cin >> n;
    set<string> s;
    vector<pair<char, char>> v;
    for (int i = 0; i < n; ++i) {
        string in;
        cin >> in;
        s.insert(in);
        v.push_back({ in.front(), in.back() });
    }

    if (s.size() != n) {
        cout << "No";
        return 0;
    }
    else {
        for (int i = 1; i < n; ++i) {
            if (v[i].first != v[i - 1].second) {
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int M[55][55],N[55][55];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	char a;
	for(int i=1;i<=n;i++)
	{
		char s[50];
		scanf("%s",s);
		for(int j=0;j<n;j++)
		if(s[j]=='#') N[i][j+1]=1;
	}
	for(int i=1;i<=m;i++)
	{
		char s[50];
		scanf("%s",s);
		//printf("%c",s[0]);
		for(int j=0;j<m;j++)
		if(s[j]=='#') M[i][j+1]=1;
	}
/*	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
		printf("%d",N[i][j]);
		printf("\n");
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=m;j++)
		printf("%d",M[i][j]);
		printf("\n");
	}
*/
	int l=n-m+1;bool OK=0;
	for(int u=1;u<=l;u++)
	for(int v=1;v<=l;v++){
		if(OK) break;
		bool ok=0;
		for(int k=u+m-1;k>=u;k--)
		for(int j=v+m-1;j>=v;j--)
		if(ok) break;
		else  {
			//printf("%d %d\n",M[k-u+1][j-v+1],N[k][j]);
			if(M[k-u+1][j-v+1]!=N[k][j]) ok=1;
		}
		//printf("%d",ok);
		if(ok==0) {
			printf("Yes");
			OK=1;
		}
	}
	if(!OK)printf("No");
	return 0;
}

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

using namespace std;

const int INF = 1e9 + 5;

int dist[100005][3];

int main () {
  int n, m;
  scanf("%d %d", &n, &m);

  vector<vector<int>> to(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b); --a; --b;
    to[a].push_back(b);
  }

  int s, t;
  scanf("%d %d", &s, &t); --s; --t;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 3; ++j) dist[i][j] = INF;

  queue<pair<int, int>> q;
  q.push(make_pair(s, 0));
  dist[s][0] = 0;
  while (!q.empty()) {
    int v = q.front().first;
    int l = q.front().second;
    q.pop();
    for (int u: to[v]) {
      int nl = (l + 1) % 3;
      if (dist[u][nl] != INF) continue;
      dist[u][nl] = dist[v][l] + 1;
      q.push(make_pair(u, nl));
    }
  }
  int ans = dist[t][0];
  if (ans == INF) ans = -1;
  else ans /= 3;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 6912