akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

long long Find(long long a, long long b) {
    if (a > b)
        swap(a, b);
    if (b % a != 0)
        return 2 * a * (b / a)+ Find(a, b % a);
    else
        return b + a * (b / a - 1);
}

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

    long long n;
    long long x;

    cin >> n >> x;
    cout << n + Find(x, n - x) << endl;

    return 0;
}

Measured memory_bytes: 256
def main():

	n,k = map(int, input().split())
	h = list(map(int, input().split()))
	c = 0
	for i in range(1, n+1):
		if h[i-1] >= k:
			c= c+1
	
	print(c)


if __name__ == "__main__":
	main()

Measured memory_bytes: 11908
#include<stdio.h>

int main(void){
        while(1){
                char s[201], c;
                int l=0;
                while((c=getchar())!='\n') s[l++] = c;
                if(s[0]=='-') break;

                int n, sm=0;
                scanf("%d", &n);
                for(int i=0; i<n; i++){
                        int tmp;
                        scanf("%d", &tmp);
                        sm += tmp;
                }

                for(int i=0; i<l; i++) putchar(s[(sm+i)%l]);
                puts("");
                getchar();
        }
        return 0;
}


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

int main() {
	long long A, B, C, K; cin >> A >> B >> C >> K;
	long long k = 0;
	while (A >= B) {
		B *= 2;
		k++;
	}
	while (B >= C) {
		C *= 2;
		k++;
	}
	if (k <= K) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
 	}
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <iostream>
#include <iomanip> 
#include <algorithm>
#include <queue>
#include <list>
#include <numeric>
#include <stack>
#include <unordered_map>
#include <map>
#include <set>

using namespace std;

#define sz(a) int((a).size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define watch(x) cout << #x << " : " << x << endl;

#define FastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

const int N = int(2e3)+10;
const int K = int(1e6)+10;
// const int MOD = int(1e9)+7;
const int INF = int(1e9)+5;
const ll INF64 = 2e18;

const ll MOD = 1e9+7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

int s[N],t[N];
ll dp[N][N],preSum[N][N];

void solve () {
    int n,m;cin>>n>>m;
    for (int i=1;i<=n;i++) cin>>s[i];
    for (int i=1;i<=m;i++) cin>>t[i];
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=m;j++) {
            if (s[i] == t[j]) dp[i][j] = add(1,preSum[i-1][j-1],MOD);
            else dp[i][j] = 0ll;
            preSum[i][j] = add(preSum[i-1][j],add(preSum[i][j-1],add(MOD-preSum[i-1][j-1],dp[i][j],MOD),MOD),MOD);
        }
    }
    ll ans = 1;
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=m;j++) {
            ans = add(ans,dp[i][j],MOD);
        }
    }
    cout<<ans<<endl;
}

int main () {
    FastIO
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int t;
    // cin>>t;
    t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 66460
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n,W;
	cin>>n>>W;
	ll v[n],w[n];
	ll mx=0;
	ll mx2=0;
	for(int i=0;i<n;i++)
	{
		cin>>w[i]>>v[i];
		mx+=w[i];
		mx2+=v[i];
	}
	ll dp[mx2+1][n+1];
	for(int i=0;i<=mx2;i++)
	{
		for(int j=0;j<=n;j++)
		{
			dp[i][j]=mx;
		}
	}
	for(int i=0;i<=n;i++)
	{
		dp[0][i]=0;
	}
	for(int j=1;j<=mx2;j++)
	{
		for(int i=1;i<=n;i++)
		{
			if(j>=v[i-1])
			{
			dp[j][i]=min(dp[j][i-1],min(dp[j][i],w[i-1]+dp[j-v[i-1]][i-1]));
			}
			else
			{
				dp[j][i]=min(dp[j][i-1],dp[j][i]);
			}
		}
	}
	ll ans=0;
		for(int j=0;j<=mx2;j++)
	{
		for(int i=n;i>=0;i--)
		{
			if(dp[j][i]<=W)
			{
				if(j>ans)
				{
					ans=j;
				//	cout<<ans<<"\n";
				}
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 82408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	string A, B, C;
	cin >> A >> B >> C;
	if(A[A.size()-1] == B[0] && B[B.size()-1] == C[0]){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 3580
def print_list(A):
    print(*A, sep=" ")

def swap(a, b):
    return b, a

def bubble_sort(A, n):
    flg = 1 #逆の隣接要素が存在する
    i = 0
    replace_num = 0
    while flg:
        flg = 0
        for j in range(n-1, i, -1):
            if A[j-1] > A[j]:
                A[j-1], A[j] = swap(A[j-1], A[j])
                flg = 1
                replace_num += 1 #交換回数
        i += 1
    print_list(A)
    print(replace_num)

n = int(input())
A = list(map(int,input().split()))

bubble_sort(A, n)


Measured memory_bytes: 5608
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=float("inf")
for i in xrange(1<<n):
    cnt=0
    li=[]
    for j in xrange(1,n):
        if i>>j&1:
            cnt+=1
            li.append(j)
    if cnt<k-1:continue
    tmp=0
    h=a[0]
    for j in li:
        for l in xrange(j):
            h=max(h,a[l])
        tmp+=max(h+1-a[j],0)
        h=max(h+1,a[j])
    ans=min(ans,tmp)
print ans

Measured memory_bytes: 2692
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;

int main() {

	Int a, b;
	cin >> a >> b;
	Int ans = 0;
	Int temp = max(a, b);

	if (a != b)ans = temp + temp - 1;
	else ans = a + b;

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  string a, b, c;
  cin >> a >> b >> c;
 
  cout << (char)(a.at(0) - 32) << (char)(b.at(0) - 32) << (char)(c.at(0) - 32) << endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
macro_rules! maxs {
    ($x:expr, $($y:expr), *) => {{
        let mut ret = $x;
        $(
            ret = max(ret, $y);
        )*
        ret
    }};
}
fn main() {
    input!(a: i64, b: i64, c: i64, d: i64);
    let ans = maxs!(a * c, b * d, a * d, b * c);
    println!("{}", ans);
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define assign(x,val) memset(x,val,sizeof(x))
#define motherfucker  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define for0(i,n) for(ll i=0;i<n;++i)
#define for1(i,n) for(ll i=1;i<=n;++i)
#define ford(i,n) for(ll i=n;i>=1;--i)
#define forg(i,a,b) for(ll i=a;i<b;++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpl;
long long mod = 1000000007;
const long double PI = (long double)(3.1415926535897932384626433832795);
 
 
void solve(){
	int n;cin>>n;
	string s;cin>>s;
	int ctn = 0;
	for0(i, n-2){
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
			ctn++;
		}
	}
	cout<<ctn<<endl;
}
 
int main(){
	
	motherfucker
	ll t = 1;
	//cin>>t;
	for0(i, t){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define print(x) cout<<(x)<<'\n'
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pl=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vvi=vector<vi>;
using vvl=vector<vl>;
using vs=vector<string>;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

void solve() {
    string s;
    cin >> s;
    int len = s.size();
    ll ans = 0;
    for(int bit=0; bit < (1<<(len-1)); bit++) {
        ll num = s[0] - '0';
        rep(j, len-1) {
            if(bit & (1<<j)) {
                ans += num;
                num = 0;
            }
            num = num * 10 + (s[j+1] - '0');
        }
        ans += num;
    }
    print(ans);
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>

using namespace std;

int r[10];

int ntoi(int i, int c[10][10]) {
  int min_d = 1000, n = 0;
  
  for (int j = 0; j < 10; j++){
    if (min_d < c[j][i] && i != j){
      n = j;
      min_d = c[j][i];
    }
  }

  return n;
}

int main(){
  int H, W;
  int c[10][10];
  cin >> H >> W;
  int A[H][W];

  for (int i = 0; i < 10; i++){
    for (int j = 0; j < 10; j++){
      cin >> c[i][j];
    }
  }

  for (int k = 0; k < 10; k++){
    for (int i = 0; i < 10; i++){
      for (int j = 0; j < 10; j++){
        if (c[i][j] > c[i][k] + c[k][j]) c[i][j] = c[i][k] + c[k][j];
      }
    }
  }

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> A[i][j];
    }
  }

  int mp = 0;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if(A[i][j] != -1) mp += c[A[i][j]][1];
    }
  }

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

}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
#define ll long long int
#define pb(i) push_back(i)
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n,x,t;
        cin>>n>>x>>t;
        int times=ceil((n+0.0)/(x+0.0));
        //cout<<times;
        cout<<times*t;
    }
}


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

using namespace std;

const int SIZE = 1 << 17;
int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0;
    char ch = Advance();
    while (!isdigit(ch))
        ch = Advance();
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer;
}

const int MAXN = 1000000;
const int MAXM = 500000;
const int MOD = 998244353;

int factorial[1 + MAXN + 3 * MAXM], inverse[1 + MAXN + 3 * MAXM];

void Add(int &x, int y) {
    x += y;
    if (x >= MOD)
        x -= MOD;
}

void Subtract(int &x, int y) {
    x -= y;
    if (x < 0)
        x += MOD;
}

int RaiseToPower(int base, int power) {
    int answer = 1;
    while (power) {
        if (power % 2)
            answer = (1LL * answer * base) % MOD;
        base = (1LL * base * base) % MOD;
        power /= 2;
    }
    return answer;
}

void Precompute(int n) {
    factorial[0] = inverse[0] = 1;
    for (int i = 1; i <= n; i++)
        factorial[i] = (1LL * factorial[i - 1] * i) % MOD;
    inverse[n] = RaiseToPower(factorial[n], MOD - 2);
    for (int i = n - 1; i >= 1; i--)
        inverse[i] = (1LL * (i + 1) * inverse[i + 1]) % MOD;

}

int Combinations(int n, int k) {
    int answer = (1LL * inverse[n - k] * inverse[k]) % MOD;
    answer = (1LL * answer * factorial[n]) % MOD;
    return answer;
}

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int n, m;
    scanf("%d%d", &n, &m);
    Precompute(n + 3 * m);
    int total = 0, bad = 0;
    for (int i = m % 2; i <= n && i <= m; i += 2)
        Add(total, (1LL * Combinations(n, i) * Combinations((3 * m - i) / 2 + n - 1, n - 1)) % MOD);
    for (int i = (m % 2) ^ 1; i + 1 <= n && i + 1 <= m; i += 2)
        Add(bad, (1LL * Combinations(n - 1, i) * Combinations((m - 1 - i) / 2 + n - 1, n - 1)) % MOD);
    for (int i = m % 2; i + 1 <= n && i + 2 <= m; i += 2)
        Add(bad, (1LL * Combinations(n - 1, i) * Combinations((m - 2 - i) / 2 + n - 1, n - 1)) % MOD);
    bad = (1LL * bad * n) % MOD;
    Subtract(total, bad);
    printf("%d\n", total);
    return 0;
}


Measured memory_bytes: 19712
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut x = vec![0; n];
    let mut ans: usize = 0;
    for i in 0..n {
        let ai = a[i];
        if i+ai<n {
            x[i+ai] += 1;
        }
        if i>=ai {
            ans += x[i-ai];
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 6596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll h, a;
  cin >> h >> a;
  cout << (h + a - 1) / a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,m;cin>>n>>m;
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>> > que;
    rep(i,n){
        ll a,b;cin>>a>>b;
        que.push({a,b});
    }
    ll res=0;
    while(que.size()&&m>0){
        ll a=que.top().first,b=que.top().second;que.pop();
        //cout<<a<<" "<<b<<endl;
        res+=min(m,b)*a;
        m-=b;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 5308
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc()) 
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

namespace flow {
  const int N = 2010, M = 10010, INF = 0x3f3f3f3f;
  const ll LLINF = 1ll << 60;
  struct edge {
    int la,b,cap;
    ll w;
  } con[M << 1];
  int tot = 1, fir[N];
  void add_edge(int from,int to,int capc,int co) {
    con[++tot] = (edge) {fir[from], to, capc, co};
    fir[from] = tot;
    con[++tot] = (edge) {fir[to], from, 0, -co};
    fir[to] = tot;
  }
  int st, en, vis[N], n;
  ll cur, ans, dis[N];
  int dfs(int pos,int imp) {
    if (pos == en || !imp) return ans += imp * cur, imp;
    vis[pos] = 1;
    int ret = 0, tmp;
    for (int i = fir[pos]; i; i = con[i].la) {
      if (vis[con[i].b]) continue;
      if (con[i].w == 0) {
	tmp = dfs(con[i].b, min(con[i].cap, imp));
	con[i].cap -= tmp;
	con[i^1].cap += tmp;
	imp -= tmp;
	ret += tmp;
	if (!imp) break;
      }
    }
    return ret;
  }
  int inq[N];
  bool spfa() {
    queue<int> q;
    rep (i, 1, n) dis[i] = LLINF;
    dis[st] = 0;
    q.push(st), inq[st] = 1;
    for (int pos; !q.empty(); q.pop()) {
      pos = q.front();
      inq[pos] = 0;
      for (int i = fir[pos]; i; i = con[i].la) {
	if (con[i].cap && dis[con[i].b] > dis[pos] + con[i].w) {
	  dis[con[i].b] = dis[pos] + con[i].w;
	  if (!inq[con[i].b])
	    q.push(con[i].b), inq[con[i].b] = 1;
	}
      }
    }
    if (dis[en] == LLINF) return false;
    cur += dis[en];
    rep (pos, 1, n) {
      for (int i = fir[pos]; i; i = con[i].la) {
	con[i].w += dis[pos] - dis[con[i].b];
      }
    }
    return true;
  }
  ll solve() {
    while (spfa()) {
      do memset(vis, 0, sizeof vis);
      while (dfs(st, INF));
    }
    return ans;
  }
}

int n;
int main() {
  int x,y,z;
  flow::n = 4;
  flow::st = ++ flow::n;
  flow::en = ++ flow::n;
  read(n);
  rep (i, 1, n) {
    read(x), read(y), read(z);
    int id = ++ flow::n;
    flow::add_edge(flow::st, id, z, 0);
    flow::add_edge(id, 1, z, x+y);
    flow::add_edge(id, 2, z, x-y);
    flow::add_edge(id, 3, z, -x-y);
    flow::add_edge(id, 4, z, -x+y);
  }
  rep (i, 1, n) {
    read(x), read(y), read(z);
    int id = ++ flow::n;
    flow::add_edge(id, flow::en, z, 0);
    flow::add_edge(1, id, z, -x-y);
    flow::add_edge(2, id, z, -x+y);
    flow::add_edge(3, id, z, x+y);
    flow::add_edge(4, id, z, x-y);
  }
  cout << -flow::solve() << endl;
  return 0;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e7 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;


int main() {
    int n;
    cin >> n;
    map<string, int> m;
    while (n--) {
        string s;
        cin >> s;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

vector<int> pos[26];

void solve() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    int idx = s[i] - 'a';
    pos[idx].push_back(i);
  }

  int x = 0;
  int times = 0;
  for (int i = 0; i < t.size(); i++) {
    int idx = t[i] - 'a';
    const auto &p = pos[idx];
    if (p.size() == 0) {
      cout << -1 << endl;
      return;
    }

    auto itr = lower_bound(p.begin(), p.end(), x);
    if (itr == p.end()) {
      x = 0;
      times++;
      itr = lower_bound(p.begin(), p.end(), x);
    }
    x = (*itr) + 1;
  }
  cout << s.size() * times + x << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

int main(){
	string s; cin>>s;
	int k=s.size()-1;
	bool flg=false;
	rep(i,k){
		if(s[i]=='A'&&s[i+1]=='C') flg=true;
	}
	cout<<(flg?"Yes":"No")<<endl;
}

Measured memory_bytes: 3628
# include <bits/stdc++.h>  
using namespace std;  
  
const int N = 100010;  
char s[N], t[N];  
int sp[N], tp[N], q, a, b, c, d;
int main() {  
    scanf("%s%s%d", s + 1, t + 1, &q); 
    for (int i = 1; s[i]; ++i) {
        sp[i] = sp[i - 1] + s[i] - 'A' + 1;  
    }
    for (int i = 1; t[i]; ++i) {
        tp[i] = tp[i - 1] + t[i] - 'A'  + 1;  
    }
    while(q--) {  
        scanf("%d%d%d%d", &a, &b, &c, &d);  
        if ( (sp[b] - sp[a - 1]) % 3 == (tp[d] - tp[c - 1]) % 3) {
            printf("YES\n");
        }
        else {
            printf("NO\n"); 
        }
    }  
    return 0;  
}

Measured memory_bytes: 1536
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::vector;
using std::queue;
using std::priority_queue;
using std::greater;
using std::max;
using std::min;

using lli = long long int;
using ulli = unsigned long long int;

//#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

int N;
int main(){
	cin.tie(0);
	std::ios::sync_with_stdio(false);
	cin >> N;
	cout << "ABC" << N << "\n";
  return 0;
}


Measured memory_bytes: 256
def main():
    import numpy as np
    n,t=map(int,input().split())
    F=[tuple(map(int,input().split())) for _ in range(n)]
    F.sort(key=lambda x:x[0])

    dp=np.zeros([n+1,t],dtype=np.int64)
    for i in range(n):
        a1=F[i][0]
        b1=F[i][1]
        dp[i+1][:a1]=dp[i][:a1]
        dp[i+1][a1:]=np.maximum(dp[i][a1:],dp[i][:-a1]+b1)
    
    ans=0
    for i in range(n):
        ans=max(ans,dp[i][-1]+F[i][1])
    print(ans)
         
if __name__=='__main__':
    main()

Measured memory_bytes: 82820
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int n,c;
  cin >> n >> c;
  vector<vector<int>> d(c,vi(c,0));
  rep(i,c){
    rep(j,c){
      cin >> d.at(i).at(j);
    }
  }
  vector<vector<int>> r(3);
  rep(i,n){
    rep(j,n){
      int tmp;
      cin >> tmp;
      tmp--;
      r.at((i+j+2)%3).push_back(tmp);
    }
  }
  vector<vector<long>> cost(3,vector<long>(c,0));
  rep(i,3){
    rep(k,c){
      rep(j,r.at(i).size()){
        int tmp = r.at(i).at(j);
        cost.at(i).at(k) += d.at(tmp).at(k);
      }
    }
  }
  long ans = 1e15;
  rep(i,c){
    rep(j,c){
      rep(k,c){
        if(i==j || j==k || k==i) continue;
        ans = min(ans,cost.at(0).at(i) + cost.at(1).at(j) + cost.at(2).at(k));
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
  char c;
  cin >> c;
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout<< "vowel" <<endl;
  }
  else{
    cout<< "consonant" <<endl;
  }
 
}


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

int main(){
  int n, m, s=0, cnt=0; cin>>n >>m;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    s+=a[i];
  }
  
  for(int i=0;i<n;i++){
    if(4*m*a[i]>=s)cnt++;
  }
  
  if(cnt>=m){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
n=int(input())
list1=[]
for i in range(n):
    list1.append(input())
dict1={}
for i in list1:
    if i in dict1:
        dict1[i]+=1
    else:
        dict1[i]=1
dict2={}
for i in dict1:
    if dict1[i] in dict2:
        dict2[dict1[i]].append(i)
    else:
        dict2[dict1[i]]=[]
        dict2[dict1[i]].append(i)
l=sorted(dict2,reverse=True)
for i in l:
    l=sorted(dict2[i])
    break
for i in l:
    print(i)

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

#define ll long long int
#define Mod 1000000007

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<pair<int,int>>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i].second>>v[i].first;
    }
    sort(v.begin(),v.end());
    int sum=0;
    for(int i=0;i<n;i++)
    {
        sum+=v[i].second;
        if(sum>v[i].first)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N];
  int ans[N];
  for(int i=0;i<N;i++){
    ans[i]=0;
  }
  for(int i=1;i<N;i++){
    cin >> A[i];
    ans[A[i]-1]++;
  }
  for(int i=0;i<N;i++){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)


int main(){
	
	string S;
	cin>>S;
	int D;
	cin>>D;
	
	vector<vector<vector<int>>> dp(S.size(),vector<vector<int>> (D,vector<int> (2,0))); //dp[i][j][k] 上からi+1桁、Dで割るとj余る、k=0:制限有 k=1:制限無
	
	int a = S[0] - '0';
	for(int i=0;i<a;i++){
		dp[0][i%D][1] = dp[0][i%D][1]+1;
	}
	dp[0][a%D][0] = 1;
	
	for(int i=1;i<S.size();i++){
		for(int j=0;j<D;j++){
			int b = S[i] - '0';
			dp[i][j][0] = dp[i-1][(j-b+10*D)%D][0];
			for(int k=0;k<b;k++){
				dp[i][j][1] = mod(dp[i-1][(j-k+10*D)%D][0]+dp[i][j][1]);
			}
			for(int k=0;k<10;k++){
				dp[i][j][1] = mod(dp[i][j][1] + dp[i-1][(j-k+10*D)%D][1]);
			}
		}
	}
	
	cout<<mod(dp[S.size()-1][0][0]+dp[S.size()-1][0][1]-1+modulo)<<endl;
	
	return 0;
}


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

using namespace std;

typedef long long ll;

bool reversecompare(int a, int b)
{
    return a > b;
}

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

    int lastx, lastt, lasty, t, x, y, dist, deltat, N;
    bool bisa;

    cin >> N;

    lastx = 0;
    lasty = 0;
    lastt = 0;
    bisa = true;


    for (int i = 0; i < N; i++)
    {
        cin >> t >> x >> y;
        dist = abs(x-lastx) + abs(y-lasty);
        deltat = t-lastt;

        if (dist != deltat)
        {
            if (dist > deltat)
            {
                bisa = false;
                break;
            }
            else if ((deltat - dist)%2 != 0)
            {
                bisa = false;
                break;
            }
        }
        lastx = x;
        lasty = y;
        lastt = t;
    }

    if (bisa)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int S[10000];
 
int main(){
 
  int n, q;
  int tmp;
  int count=0;
 
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> S[i];
  }
 
  cin >> q;
  for(int i=0; i<q; i++){
    cin >> tmp;
for(int j=0; j<n; j++){
if(tmp == S[j]){
count++;
break;
}
}
  }
 
  cout << count << "\n";
 
return 0;
 
}

Measured memory_bytes: 1204
#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
    const int N=(int)1e5+100;
    const int M=(int)2e6+100;
    const int inf=(int)1e9+100;
#define filename ""
    int a[2][20];
    int n;
    bool was[(1<<18)][51];
    int table[(1<<18)][51];
int f(int mask,int x)
{
    int d=__builtin_popcount(mask);
    if (d==n)
    {
        re 0;
    }
    if (was[mask][x]) re table[mask][x];
    was[mask][x]=1;
    int o=inf;
    int c=0,i;
    fo(i,n)
    {
        if (mask&(1<<i))
        {
            d--;
            continue;
        }
        if (a[(d+c)%2][i]>=x)
        {
            o=min(o,f(mask|(1<<i),a[(d+c)%2][i])+c);
        }
        c++;
    }
    re table[mask][x]=o;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int i;
    cin>>n;
    fo(i,n)
    {
        cin>>a[0][i];
    }
    fo(i,n)
    {
        cin>>a[1][i];
    }
    i=f(0,0);
    if (i==inf)
    {
        cout<<-1;
    }
    else
    {
        cout<<i;
    }
}


Measured memory_bytes: 65536
#include <iostream>
#include <cstdio>
using namespace std;
bool mp[2020][2020];
int row[2020][2020], column[2020][2020], ans, n, m;
int main(){
	scanf("%d%d", &n, &m);
	for( int i = 1; i <= n; ++i ){
		int sum = 0;
		for( int j = 1; j <= m; ++j ){
			char c;
			cin >> c;
			if( c == '#' ){
				mp[i][j] = true;
				for( int k = j-1; !mp[i][k]&&k>=1; --k )
					row[i][k] = sum;
				sum = 0;
			} else if( c == '.' )
				++sum;
		}
		if( sum )
			for( int k = m; !mp[i][k]&&k>=1; --k )
				row[i][k] = sum;
	}
	for( int j = 1; j <= m; ++j ){
		int sum = 0;
		for( int i = 1; i <= n; ++i )
			if( mp[i][j] ){
				for( int k = i-1; !mp[k][j]&&k>=1; --k )
					column[k][j] = sum;
				sum = 0;
			} else
				++sum;
		if( sum )
			for( int k = n; !mp[k][j]&&k>=1; --k )
				column[k][j] = sum;
	}
	for( int i = 1; i <= n; ++i )
		for( int j = 1; j <= m; ++j ){
			//printf("%d %d %d %d %d\n", i, j, row[i][j], column[i][j], row[i][j] + column[i][j] - 1);
			if( !mp[i][j] ){
				int t = row[i][j] + column[i][j] - 1;
				ans = max(ans, t);
			}
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 36096
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

    int n,m;
    cin>>n>>m;

    cout<<n*(n-1)/2 + m*(m-1)/2;
    
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

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

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b && b<c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
bool issame(vector<pair<int,int>> &v, int i)
{
	return v[i].first==v[i].second;
}
int main() {
	// your code goes here
	int n;
	cin>>n;
	bool flag=false;
	vector<pair<int,int>> v(n);
	for(int i=0;i<n;i++)
	cin>>v[i].first>>v[i].second;
	for(int i=1;i<n-1;i++)
	{
		if(issame(v,i-1) && issame(v,i) &&issame(v,i+1))
		flag=1;
	}
	if(flag)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3628
N,M=map(int,input().split())
import collections
table=collections.defaultdict(int)
for i in range(M):
  a,b=map(int,input().split())
  table[a]+=1
  table[b]+=1
flag=True
for x in table:
  if table[x]%2==1:
    flag = False
    break
if flag:
  print("YES")
else:
  print("NO")

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

int n;
const int M = 110;
const int N = 2;
int grid[N][M];

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int I[] = {+1, +0};
const int J[] = {+0, +1};

bool vis[N][M];

//int run(int i, int j) {
//    priority_queue<iii> q;
//
//    q.push(iii(grid[i][j], ii(i, j)));
//
//    int ans = 0;
//
//    while (!q.empty()) {
//        auto t = q.top();
//        i = t.second.first;
//        j = t.second.second;
//        q.pop();
//
//        if (vis[i][j])
//            continue;
//        vis[i][j] = true;
//
//        if (i == N-1 && j == n-1) {
//            ans = t.first;
//        }
//
//        for (int k = 0; k < 4; k++) {
//            int di = i + I[k];
//            int dj = j + J[k];
//
//            if (0 <= di && di < N && 0 <= dj && dj < n) {
//                q.push(iii(t.first + grid[di][dj], ii(di, dj)));
//            }
//        }
//    }
//
//    return ans;
//}

int run(int i, int j, int candies) {
    if (i == N-1 && j == n-1)
        return candies;

    if (i == N-1)
        return run(i, j+1, candies + grid[i][j+1]);
    else if (j == n-1)
        return run(i+1, j, candies + grid[i+1][j]);
    else
        return max(run(i, j+1, candies + grid[i][j+1]),
                run(i+1, j, candies + grid[i+1][j]));
}

int main() {
    cin >> n;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < n; j++) {
            cin >> grid[i][j];
        }
    }

    cout << run(0,0, grid[0][0]) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define LEN 100005

typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min_queue(int a, int b){ return a < b ? a : b; }

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for (i=1; i<=n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1; tail = n + 1;

  while(head != tail){
    u = dequeue();
    c = min_queue(q, u.t);
    u.t -= c;
    elaps += c;
    if (u.t > 0) enqueue(u);
    else {
      printf("%s %d\n", u.name, elaps);
    }
  }
}

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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int N, vector<int>& W) {
    int answer = INT_MAX;
    REP(T,0,N) {
        int s1 = 0, s2 = 0;
        REP(i,0,T) {
            s1 += W[i];
        }
        REP(i,T,N) {
            s2 += W[i];
        }
        answer = min(answer, abs(s1 - s2));
    }

	stringstream ss;
    ss << answer;
	cout << ss.str() << '\n';

    return;
}

signed main() {
    int N;
    cin >> N;
    
    vector<int> W(N);
    REP(i,0,N) cin >> W[i];
    
    solve(N, W);

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
 
#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
 
struct UnionFind {
  vector<int>par;
  vector<int>rank; 
 
  UnionFind(int n=1){
    init(n);
  }
  void init(int n=1) {
    par.resize(n);rank.resize(n);
    for(int i=0;i<n;++i)par[i]=i,rank[i]=0;
  }
  int root(int x){
    if(par[x]==x)return x;
    else{
      int r=root(par[x]);
      return par[x]=r;
    }
  }
  bool issame(int x,int y) {
    return root(x)==root(y);
  }
  bool merge(int x,int y) {
    x=root(x);y=root(y);
    if(x==y) return false;
    if(rank[x]<rank[y])swap(x, y);
    if(rank[x]==rank[y])++rank[x];
    par[y]=x;
    return true;
  }
};
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
 
  int N,M;
  cin>>N>>M;
  vector<int>X(M),Y(M),Z(M);
  for(int i=0;i<M;i++)cin>>X[i]>>Y[i]>>Z[i];
  for(int i=0;i<M;i++)X[i]--,Y[i]--;
  UnionFind uf(N);
  for(int i=0;i<M;i++)uf.merge(X[i],Y[i]);
  int ans=0;
  for(int i=0;i<N;i++)if(uf.par[i]==i)ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2176
n = int(input())
a = list(map(int, input().split()))
x = 1
l = [0] * n
for k in range(n):
    xl = l[a[k]]
    if a[k] == 0:
        xs = 3
    else:
        xs = l[a[k] - 1]
    if xs + 1 != xl:
        x = x * (xs - xl) % 1000000007
    l[a[k]] = l[a[k]] + 1
print(x)


Measured memory_bytes: 13964
#define rep(i,n) for (int i=0; i<(int)(n); ++i)

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

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

    long int sum = 0;

    for(long int i=1; i<=N; ++i){
        if((i%3 == 0) && (i%5 == 0)) ;
        else if(i%3 == 0) ;
        else if(i%5 == 0) ;
        else sum += i;
    }

    cout << sum << endl;
}

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

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

const int maxn = 2e5+7;
const int mod  = 1e9+7;
const int inf  = 2e9;

int get_len()
{
    string test="1";
    string ans;
    cout<<"? "<<test<<endl;
    while(cin>>ans,ans=="Y")
    {
        if(test.length()>10) return -1;
        test+='0';
        cout<<"? "<<test<<endl;
    }
    return test.length()-1;
}

int main()
{
#ifdef LOCAL
    freopen("sample.in","r",stdin);
#endif
    //ios::sync_with_stdio(false);
    int len=get_len();
    string ans="";
    string re;
    if(len==-1)
    {
        ans="2";
        cout<<"? "<<ans<<endl;
        cin>>re;
        if(re=="Y")
        {
            cout<<"! "<<1<<endl;
            return 0;
        }
        ans="1";
        for(int i=0;i<=10;i++)
        {
            string temp=ans;
            temp+='1';
            cout<<"? "<<temp<<endl;
            cin>>re;
            if(re=="Y")
            {
                cout<<"! "<<ans<<'0'<<endl;
                return 0;
            }
            ans+='0';
        }
    }
    if(len==1)
    {
        ans+="19";
        for(int i=1;i<=9;i++)
    {
        ans[len-1]=(i+'0');
        cout<<"? "<<ans<<endl;
        cin>>re;
        if(re=="Y")
        {
            ans[len]='\0';
            cout<<"! "<<ans<<endl;
            return 0;
        }
    }
    }
    for(int i=1;i<len;i++)
    {
        int l=0,r=9;
        int mid;
        while(l<r)
        {
           string temp=ans;
           mid=(l+r)/2+1;
           temp+=(mid+'0');
           cout<<"? "<<temp<<endl;
           cin>>re;
           if(re=="Y")
               l=mid;
           else 
               r=mid-1;
        }
        ans+=(l+'0');
    }
    ans+="09";
    for(int i=0;i<=9;i++)
    {
        ans[len-1]=(i+'0');
        cout<<"? "<<ans<<endl;
        cin>>re;
        if(re=="Y")
        {
            ans[len]='\0';
            cout<<"! "<<ans<<endl;
            return 0;
        }
    }
    return 0;
}




Measured memory_bytes: 668
n = int(input())
h = list(map(int,input().split()))

for i in range(1,n):
    if h[-i] + 1 == h[-(i+1)]:
        h[-(i+1)] -= 1

h_new=sorted(h)
        
if h == h_new:
    print('Yes')
else:
    print('No')
        


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

int main() {
    ll q,h,s,d,n;
    cin >> q >> h >> s >> d >> n;
    s = min(s,min(h*2, q*4));
    if(s*2 > d) {
        if(n % 2 == 0) cout << (n/2)*d;
        else {
            cout << (n/2)*d+s << endl;    
        }
    } else {
        cout << s*n << endl;    
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn       cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;


int main()
{
    int n,x;
    cin>>n>>x;
    int a[n],mi=INF,sum=0;
    rep(i,n)cin>>a[i],sum+=a[i],mi=min(mi,a[i]);
    cout<<n+(x-sum)/mi<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
  
int main(){
  ll a,b,c,k;
  cin >> a>> b>> c>> k;
  ll sum=0;
  if(k<=a) sum += k;
  else if(k>a&&k<=a+b) sum += a;
  else sum = a-(k-a-b);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3640
/*
 * written by Yaqi Zhang (zhang623@wisc.edu)
 * University of Wisconsin-Madison
 * 2019
 */
#include <bits/stdc++.h>

#define INF 0x3f3f3f3f

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    long long k;
    cin >> n >> k;
    vector<int> A(n);
    for(int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        A[i] = x - 1;
    }
    vector<int> memo(n, -1);
    int idx = 0;
    int cur_step = 0;
    while(k-- > 0) {
        // cout << idx + 1 << endl;
        if(memo[idx] != -1) {
            // period
            int period = cur_step - memo[idx];
            k %= period;
        }
        memo[idx] = cur_step;
        idx = A[idx];
        ++cur_step;
    }
    cout << idx + 1 << endl;
    return 0;
    
}



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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, P;
    cin >> N >> P;

    vector<ll> A(N);
    rep (i, N) {
        cin >> A[i];
    }

    ll odd = 0;
    rep (i, N) {
        if (A[i]%2 != 0) {
            odd++;
        }
    }

    if (odd) {
        cout << setprecision(64) << pow(2, N-1) << endl;
    } else {
        if (P) {
            cout << 0 << endl;
        } else {
            cout << setprecision(64) << pow(2, N) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        n: usize, k: usize,
        mut p: [usize; n]
    }
    let mut ans = 0;

    p.sort();
    for i in 0..k {
        ans += p[i];
    }

    println!("{}", ans);
}


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

#define ii pair<int, int>
#define lli long long int
#define ll pair<lli, lli>
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

lli bigmod = 1000000007, faktorial[1000005];

lli exp(lli a, lli b) {
	lli ret;
	if (b == 0)
		return 1;
	ret = exp(a, b / 2);
	ret = (ret * ret) % bigmod;
	if (b & 1)
		ret = (ret * a) % bigmod;
	return ret;
}

lli combine(lli a, lli b) {
	lli ret = faktorial[a], temp;
	temp = exp(faktorial[b], bigmod - 2);
	ret = (ret * temp) % bigmod;
	temp = exp(faktorial[a - b], bigmod - 2);
	ret = (ret * temp) % bigmod;
	return ret;
}

int main() {
	lli x, y, a, ans;
	scanf("%lld %lld", &x, &y);
	faktorial[0] = 1;
	for (lli i = 1; i < 1000001; i++)
		faktorial[i] = (faktorial[i - 1] * i) % bigmod;
	if ((x + y) % 3)
		ans = 0;
	else {
		a = (x + y) / 3;
		if ((x < a) || (x > a + a) || (y < a) || (y > a + a))
			ans = 0;
		else
			ans = combine(a, min(x, y) - a);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 8064
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    val arr = readLine()!!.split(' ').map{it.toInt()}
    var ans = 0
    for (i in (0..n - 1)) {
        val adist = arr[i] * 2
        val bdist = (k - arr[i]) * 2
        ans += if (adist < bdist) adist else bdist
    }
    println(ans)
}


Measured memory_bytes: 38292
import sys


x = int(input())

a = 10 ** 5

ans = x
if ans == 1:
    print(1)
    sys.exit()

for i in range(a):
    flag = True
    for j in range(2,int(ans**0.5)+1):
        if ans % j == 0:
            flag = False
    
    if flag:
        print(ans)
        sys.exit()
    else:
        ans = ans + 1

Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef int ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j) vector<vector<ll>> name(i,vector<ll>(j))
#define vec2f(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k)))
#define vec3f(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define vec4(name,i,j,k,l) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l))))
#define vec4f(name,i,j,k,l,m) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l,m))))
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000 //8
#define N 210000

vector<ll> dx={-1,0,1,0};
vector<ll> dy={0,-1,0,1};
vector<vector<ll>> dist;
vector<string> field;
ll h, w, k;

void bfs(ll xs, ll ys){
    queue<P> q;
    dist[xs][ys]=0;
    q.push(P(xs,ys));
    while(!q.empty()){
        ll nowx = q.front().first; ll nowy = q.front().second;
        //cout << nowx << "now" << nowy << endl;
        q.pop();
        REP(i,4){
            FOR(j,1,k){
                ll nex = nowx+j*dx[i]; ll ney = nowy+j*dy[i];
                //cout << nex << "next" << ney << endl;
                if (nex<0||nex>=h||ney<0||ney>=w) break;
                if (field[nex][ney]=='@') break;
                if (dist[nex][ney]!=-1&&dist[nex][ney]<=dist[nowx][nowy]) break;
                if (dist[nex][ney]==dist[nowx][nowy]+1) continue;
                dist[nex][ney]=dist[nowx][nowy]+1;
                q.push(P(nex,ney));
            }
        }
    }
}

int main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    cin >> h >> w >> k;
    dist = vector<vector<ll>>(h,vector<ll>(w,-1));
    field = vector<string>(h);
    ll xs, ys, xg, yg; cin >> xs >> ys >> xg >> yg;xs--;ys--;xg--;yg--;
    REP(i,h) cin >> field[i];
    bfs(xs,ys);
    cout << dist[xg][yg] << endl;
    /*REP(i,h){
        REP(j,w) cout << dist[i][j] << " ";
        cout << endl;
    }*/
}


Measured memory_bytes: 11100