akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
#else
#define print(...)
#endif


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

    ll n,k;

    cin >> n >> k;
    vector<ll> A(n,0), f(n,-1);


    for(int i=0; i<n; i++){
        ll a=0;
        cin >> a;
        A[i] = a-1;
    }

    ll p = 0, c = 0;
    while(f[p]==-1 && c<k){
        f[p] = c;
        p=A[p];
        c++;
    }

    ll ans = p+1;

    if(c<k){
        ll mod = (k-f[p]) % (c-f[p]);

        for(int i=0; i<mod; i++){
            p = A[p];
        }

        ans = p+1;
    }
    

    cout << ans << endl;

    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = ((1LL<<62)-1)/2;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    ll a,b,q, x, ans; cin >> a >> b >> q;
    vll jinja(a), tera(b);
    rep(i,a) cin >> jinja[i];
    rep(i,b) cin >> tera[i];
    jinja.push_back(infll);
    jinja.push_back(-infll);
    tera.push_back(infll);
    tera.push_back(-infll);
    sort(all(jinja));
    sort(all(tera));

    rep(i,q) {
        ans = infll;
        cin >> x;
        vll pointsjin, pointstera;
        pointsjin.push_back(*--lower_bound(all(jinja), x));
        pointstera.push_back(*--lower_bound(all(tera), x));
        pointsjin.push_back(*upper_bound(all(jinja), x));
        pointstera.push_back(*upper_bound(all(tera), x));
//        ll near_west_jinja, near_west_tera, near_east_jinja, near_east_tera;
//        near_west_jinja = *--lower_bound(all(jinja), x);
//        near_west_tera = *--lower_bound(all(tera), x);
//        near_east_jinja = *upper_bound(all(jinja), x);
//        near_east_tera = *upper_bound(all(tera), x);

        rep(i,2)rep(j,2) {
            ll dist1 = abs(pointsjin[i]-x) + abs(pointstera[j]-pointsjin[i]);
            ll dist2 = abs(pointstera[j]-x) + abs(pointsjin[i]-pointstera[j]);
            chmin(ans, min(dist1, dist2));
        }

        cout << ans << '\n';
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

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

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

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	float n;
	cin>>n;
	float answer=2.00000 * 3.14159265 * n;
	printf("%.5f",answer);
	return 0;
}

Measured memory_bytes: 3804
import java.awt.*;
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt(),m=sc.nextInt();
        int x=n+m;
        System.out.println((n*(n-1)/2)+(m*(m-1)/2));
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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

#define ll long long int
#define hell 998244353
#define vi vector <ll>
#define pb push_back
#define pii pair<ll,ll>
#define vii vector <pii>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
#define inf (ll)(1e16)

using namespace std;

void solve(){
    ll n,k;
    cin>>n>>k;
    vi a(n),dp(n,inf);
    rep(i,0,n)
        cin>>a[i];
    dp[0]=0;
    rep(i,1,n)
    {
        sep(j,i,max((ll)(0),i-k))
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
    }
    cout<<dp.back();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


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

int main(){
    int A,B,C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    while(1){
        C-=B;
        if(C<1){
            printf("Yes\n");
            break;
        }
        A-=D;
        if(A<1){
            printf("No\n");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1644
import collections
 
n = int(input())
s = [str(input()) for _ in range(n)]
ans = []
 
c = collections.Counter(s)

m = max(c.values())
for i in c:
    if c[i] == m:
        ans.append(i)
ans.sort()
 
for i in ans:
    print(i)

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

int main() {
    int N;
    map<string, int> m;
    ll ans;
    cin >> N;
    rep(i, N) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if (m.find(s) != m.end()) {
            ans += m[s];
            m[s]++;
        } else {
            m[s] = 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <stdio.h>
using namespace std;

int A[1000000],n;

int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;
    
    while(left < right){
        mid = (left + right)/2;
        if(key == A[mid]) return 1;
        if(key > A[mid]) left = mid + 1;
        else if(key < A[mid]) right = mid;
    }
    return 0;
}
int main(void){
    int i,q,k,sum = 0;
    
    scanf("%d",&n);
    for(i = 0;i<n;i++){
        scanf("%d",&A[i]);
    }
    
    scanf("%d",&q);
    for(i = 0;i<q;i++){
        scanf("%d",&k);
        if(binarySearch(k)) sum++;
    }
    printf("%d\n",sum);
    
    return 0;
}



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

using namespace std;

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

#define INF 100000000

int N, M;

int main()
{
	cin >> N >> M;
	vi D[N];
	for (int m = 0; m < M; m++)
	{
		int a, b;
		cin >> a >> b;
		a--, b--;
		if (a > b)
			swap(a, b);
		D[a].push_back(b);
	}

	int L = INT_MAX, R = INT_MIN, count = 0;
	for (int n = 0; n < N; n++)
	{
		if (D[n].size() == 0)
			continue;
		int nL = n, nR = *min_element(D[n].begin(), D[n].end())-1;
		if (nR < L || nL > R)
			count++, L = nL, R = nR;
		else
			L = max(L, nL), R = min(R, nR);
	}
	cout << count << endl;
}



Measured memory_bytes: 9084
#include <iostream>
using namespace std;
int main(){
    int k;
    cin >> k;
    int arr[33] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << arr[k - 1];
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC064A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            d = 100 * a + 10 * b + c;

            if (d % 4 == 0)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

            Console.ReadKey();
                
        }
    }
}


Measured memory_bytes: 13140
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()
typedef long long ll;



int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    rep(i,n) cin >> h.at(i);
    
    vector<vector<int>> g(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
    }
    
    int cnt = 0;
    
    rep(i,n){
        bool judge = true;
        int x = h.at(i);
        for(int y : g.at(i)){
            if(x <= h.at(y)){
                judge = false;
                break;
            }
        }
        if(judge == true) cnt++;
    }
    
    dunk(cnt);
    
    return 0;
}


Measured memory_bytes: 11976
#include<iostream>
#include<vector>
#include<string>
#include<tuple>
#include<set>
#include<algorithm>
using namespace std;

int main(){
    int H, W, D;
    cin >> H >> W >> D;
    vector<tuple<int, int, int> > a(H*W);
    int k = 0;
    int a_temp = 0;
    for(int i = 1; i <= H; i++)
    {
        for(int j = 1; j <= W; j++)
        {
            cin >> a_temp;
            a[k] = make_tuple(a_temp, i, j);
            k++;
        }
    }
    sort(a.begin(), a.end());
    int Q;
    cin >> Q;
    vector<int> l(Q), r(Q);
    for(size_t i = 0; i < Q; i++)
    {
        cin >> l[i] >> r[i];
    }
    set<int> calced;
    vector<int> mp(H*W+1, 0);
    for(int i = 0; i < H*W; i++)
    {
        int temp = i;
        if(calced.count(temp) == 0) {
            calced.insert(temp);
            while(temp+D < H*W) {
                temp+=D;
                mp[temp] = mp[temp-D] + abs(get<1>(a[temp])-get<1>(a[temp-D])) + abs(get<2>(a[temp])-get<2>(a[temp-D]));
                calced.insert(temp);
            }
        }
    }
    
    for(size_t i = 0; i < Q; i++)
    {
        cout << mp[r[i]-1] - mp[l[i]-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 9248
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    int x;  cin >> x;
    cout << 1 -x << endl;
    return 0;
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

int n;
vector<int> G[100009];
int dp[100009];
int m;

bool solve(int v, int p) {
    vector<int> a;
    if((int)G[v].size() & 1) a.push_back(0);
    for(int u : G[v]) {
        if(u == p) continue;
        if(!solve(u, v)) return false;
        if(dp[u] != -1) a.push_back(dp[u] + 1);
    }
    sort(ALL(a));
    int sz = (int)a.size();
    if(sz & 1) {
        int ng = -1, ok = sz;
        while(ok - ng > 1) {
            int x = (ng + ok) >> 1;
            int i = 0, j = sz - 1;
            bool b = true;
            while(i < j) {
                if(i == x) i++;
                if(j == x) j--;
                if(a[i] + a[j] > m) {
                    b = false;
                    break;
                }
                i++;
                j--;
            }
            (b ? ok : ng) = x;
        }
        if(ok == sz) return false;
        dp[v] = a[ok];
        return true;
    } else {
        rep(i, sz) if(a[i] + a[sz - 1 - i] > m) return false;
        dp[v] = -1;
        return true;
    }
}

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

    cin >> n;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int ans = 0;
    rep(i, n) ans += (int)G[i].size() & 1;
    cout << ans / 2 << " ";
    int ng = 0, ok = n;
    while(ok - ng > 1) {
        m = (ng + ok) >> 1;
        (solve(0, -1) ? ok : ng) = m;
    }

    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 16768
# D - Blue and Red Balls

N, K = map(int, input().split())
MOD = 10**9 + 7

# nCkを漸化式で求め、メモしておく
combinations_table = [[0]*(N+1) for _ in range(N+1)]
for idx in range(N+1):
    combinations_table[0][idx] = 1
    combinations_table[idx][0] = 1
    combinations_table[idx][1] = idx
for n in range(2, N+1):
    for k in range(2, n+1):
        combinations_table[n][k] = combinations_table[n-1][k-1] + combinations_table[n-1][k]

# 連続した同色のボールの数nと、それらを何分割するか示すaを与えると、分割のパターン数を返す関数
def separate_balls(n,a):
    return combinations_table[n-1][a-1]

# 青いボールを先に並べると赤いボールが両端にあるかどうかで場合分けが必要
# 赤いボールの隙間か両端から一部を選んで青いボールを挿入すれば場合分けが少なくて済む
ans_list = []
for n_separate in range(1,K+1):
    if n_separate > K:
        ans_list.append(0)
    else:
        tmp_insert = combinations_table[N-K+1][n_separate]
        tmp_blue_group = separate_balls(K, n_separate)
        ans_list.append((tmp_insert * tmp_blue_group) % MOD)

for x in ans_list:
    print(x)

Measured memory_bytes: 479484
import math
A, B, H, M = map(int, input().split())
H_rad = ((H*30) + 0.5*M) % 360
M_rad = M*6 % 360
kari_kakudo = max(H_rad,M_rad) - min(H_rad,M_rad)
kakudo = math.radians(min(kari_kakudo,360-kari_kakudo))
ans = (pow(A,2)+pow(B,2))-2 * A * B * (math.cos(kakudo))
print(math.sqrt(ans))

Measured memory_bytes: 9520
#include<stdio.h>
#include<stdlib.h>

int main(){
  int n;
  int i;
  int *A;

  scanf("%d",&n);

  A = malloc(sizeof(int)*(n+1));

  for(i = 0;i<n;i++)
    scanf("%d",&A[i+1]);

  if(n>=3)
    printf("node 1: key = %d, left key = %d, right key = %d, \n",A[1],A[2],A[3]);
  else if(n==2)
    printf("node 1: key = %d, left key = %d, \n",A[1],A[2]);
  else
    printf("node 1: key = %d, \n",A[1]);

  for(i=2; i<n+1;i++){
    printf("node %d: key = %d, parent key = %d, ",i,A[i],A[i/2]);

    if(n>=i*2+1)
      printf("left key = %d, right key = %d, \n",A[i*2],A[i*2+1]);
    else if(n==i*2)
      printf("left key = %d, \n",A[i*2]);
    else 
      printf("\n");
  }
  return 0;
}

Measured memory_bytes: 600
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    pref = defaultdict(list)
    pref_list = [0] * (M + 1)
    for i in range(M):
        p, y = map(int, input().split())
        pref_list[i + 1] = p
        pref[p].append((y, i + 1))
    
    for p in pref: pref[p].sort()
    order = [0] * (M + 1)
    for p in pref:
        for x, (y, i) in enumerate(pref[p]):
            order[i] = x + 1
    
    for i in range(1, M + 1):
        p = pref_list[i]
        x = order[i]
        print("{p:06}{x:06}".format(p=p, x=x))





if __name__ == "__main__":
    main()


Measured memory_bytes: 71644
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void A();

int main()
{
	A();
	fflush(stdout);
	return 0;
}

static void A()
{
	int X;
	get(X);

	int ans = 0;
	if (X >= 1800) {
		ans = 1;
	}
	else if (X >= 1600) {
		ans = 2;
	}
	else if (X >= 1400) {
		ans = 3;
	}
	else if (X >= 1200) {
		ans = 4;
	}
	else if (X >= 1000) {
		ans = 5;
	}
	else if (X >= 800) {
		ans = 6;
	}
	else if (X >= 600) {
		ans = 7;
	}
	else if (X >= 400) {
		ans = 8;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3748
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, d) = readIntegerList()
    var ans = 1
    var last = 2 * d + 1
    for (i in (d + 1)..n) {
        if (i > last) {
            ans++
            last += 2 * d + 1
        }
    }
//    1 2 3 4 5 6 7 8 9 10
//        1         1
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36480
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var A, B, C, X, Y int

func main() {
	sc.Split(bufio.ScanWords)

	A, B, C, X, Y = nextInt(), nextInt(), nextInt(), nextInt(), nextInt()
	if A+B <= 2*C {
		fmt.Println(A*X + B*Y)
		return
	}

	var m, n int
	if maxInt(X, Y) == X {
		m = Y*2*C + (X-Y)*A
		n = X * 2 * C
	} else {
		m = X*2*C + (Y-X)*B
		n = Y * 2 * C
	}

	fmt.Println(minInt(m, n))
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> candy(3);
  for(int i=0;i<3;i++){
    cin>>candy.at(i);
  }
  sort(candy.begin(),candy.end());
  if(candy.at(0)+candy.at(1)==candy.at(2)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>

using namespace std;
typedef long long ll;
typedef tuple<ll, int, ll> TP;

ll B = 0;
ll ans = 0;
ll anspos = 0;
int N, Q;
ll X[200000];

multiset<TP> s;
multiset<ll> cantgo;

int main() {

	cin >> N >> Q;
	for (int i = 0; i < N; i++) {
		ll S, T;
		cin >> S >> T >> X[i];
		S -= X[i], T -= X[i];
		//[S - X, T - X)の区間で道行く人いは止まらざるをえない
		s.insert(make_tuple(S, -1, X[i]));
		s.insert(make_tuple(T, 0, X[i]));
	}
	for (int i = 0; i < Q; i++) {
		ll D;
		cin >> D;
		s.insert(make_tuple(D, 1, 1145141919));
	}



	while (s.size()) {
		auto cur = *s.begin(); s.erase(s.begin());
		if (get<1>(cur) == -1) {
			//追加ならば
			cantgo.insert(get<2>(cur));
		}
		else if (get<1>(cur) == 0) {
			//取り出しならば
			cantgo.erase(cantgo.find(get<2>(cur)));
		}
		else {
			//人についての計算ならば
			ll ans = -1;
			if (cantgo.size() == 0) {
				goto end;
			}

			ans = *cantgo.begin();

		end:;
			cout << ans << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 40960
gets

H = gets.chomp.split(' ').map(&:to_i)

h = H.reverse
h.each_with_index do |item, index|
  next if index == h.length - 1
  if h[index + 1] - item == 1
    h[index + 1] -= 1
  elsif h[index + 1] - item > 1
    puts 'No'
    exit
  else
  end
end

puts 'Yes'


Measured memory_bytes: 10500
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;


int main()
{
	int N;cin >> N;
	vector<ll> right(N,0),left(N,0);
	ll a;
	for (int i=0;i<N;i++)
	{
		cin >> a;
		if (i+a<N) right[i+a]++;
		if (i-a>=0) left[i-a]++;
	}
	ll ans=0;
	for (int i=0;i<N;i++)
	{
		//cout <<right[i] <<" " <<left[i] <<endl;
		ans+=right[i]*left[i];
	}
	cout << ans << endl;

	return 0;

}

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c)

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

int a[2005];

int main()
{
  ios::sync_with_stdio(0);
  int n,m ;
  cin >> n >> m;
  int sum = 0;
  int cnt = 0;
  for(int i = 1; i <= n ; i++)
  {
    cin >> a[i];
    sum += a[i];
  }

  for(int i = 1; i <= n ; i++)
  {
    if(a[i] * 4 * m >= sum )
    {
      cnt++;
    }
  }


  cout << (cnt >= m ? "Yes" : "No") << endl;


  return 0;
}

Measured memory_bytes: 3640
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 3e5+5;
const int M = 11;

int n;
int m;
int A[N];
pair < int , int > Q[N];
int mx[N];
int stp[N];

bool cmp(pair < int , int > a , pair < int , int > b){
    if(a.first > b.first)
        return 1;
    if(a.first == b.first){
        if(a.second > b.second)
            return 1;
    }
    return 0;
}

int main(){
    scanf("%d%d" , &n , &m);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &A[i]);
    }
    sort(A + 1 , A + n + 1);
    /*for(int i = 1; i <= n; i++){
        cout << A[i] << " ";
    }
    cout << endl;*/
    for(int i = 1; i <= m; i++){
        int B , C;
        scanf("%d%d" , &B , &C);
        Q[i] = {C , B};
    }
    sort(Q + 1 , Q + m + 1 , cmp);
    int willstep = 1;
    for(int i = 1; i <= m; i++){
        int curB = Q[i].second;
        int curC = Q[i].first;
        if(willstep <= n){
            mx[willstep] = curC;
            stp[willstep] = curB;
            //cout << curC << " " << curB << " " << willstep << endl;
            willstep += curB;
            willstep = min(willstep , n + 1);
        }
    }
    int I = 0;
    for(int i = 1; i <= n; i++){
        if(mx[i] && !stp[I]){
            I = i;
        }
        if(stp[I] && A[i] < mx[I]){
            A[i] = mx[I];
            stp[I]--;
        }
    }
    long long sm = 0;
    for(int i = 1; i <= n; i++){
        sm += A[i];
    }
    printf("%lld\n" , sm);
}

Measured memory_bytes: 3456
N,K=[int(i) for i in input().split(" " )]
s = []
for i  in  range(N):
  s.append([int(ii) for ii in input().split(" ")])

s.sort( key=lambda x: x[0])  
countPush = 0
for i in s:
   countPush += i[1]
   if(countPush >= K ):
     print(i[0])
     break


Measured memory_bytes: 22872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
struct UnionFind {
    vector<int> par;
    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  int N,M,ans=0; cin>>N>>M;
  UnionFind tree(N);
  vector<int> S(N);
  rep(i,N){
    cin>>S[i];
    S[i]--;
  }
  rep(i,M){
    int x,y; cin>>x>>y;
    x--;
    y--;
    tree.unite(x,y);
  }
  rep(i,N) if(tree.same(i,S[i]))ans++;
  cout<<ans;
}

Measured memory_bytes: 4040
#include<bits/stdc++.h>
#define mod 1000000007
#define mod1 998244353
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
int main()
{
fast_io
li n,s=0,i,j,k;
cin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
for(k=1;k<=n;k++)
s+=__gcd(i,__gcd(j,k));
cout<<s;
  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<vi > vvi;
typedef std::vector<vll > vvll;
typedef std::pair<int,int> ii;
typedef std::pair< ll, ll > lp;
typedef std::vector<ii> vii;
typedef std::vector<vii > vvii;


#define pb push_back 
#define PB pop_back
#define pf push_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)
#define lb(a,b) lower_bound(all(a),b)
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) f(i,0,n-1)cin>>a[i]
#define in1(a,n) f(i,1,n)cin>>a[i]
#define out(a,n) f(i,0,n-1)cout<<fixed<<setprecision(20)<<a[i]<<" ";cout<<"\n"
#define ff first
#define ss second
#define f(i,a,b) for (int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,n) f(i,0,n-1)
#define clr(a) (a).clear()
#define rz resize
#define sqr(a) ((a) * (a))
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin() ,(a).rend()
#define endl '\n'

const int N=(int)1e5+5;

ll dp[N][105];

int main(int argc, char const *argv[])
{
	crap;
	int n, w;
	cin>>n>>w;
	ll val[1+n];
	ll wght[1+n];

	f(i,1,n)
		cin>>wght[i]>>val[i];

	rep(i,N)
		rep(j,105)
			dp[i][j]=(ll)1e12+5;

	rep(i,n)
		dp[0][i]=0;


	f(j,1,n)
	{
		f(i,1,N-1)
		{
			dp[i][j]=dp[i][j-1];
			if (i-val[j] >=0)
			{
				dp[i][j]=min(dp[i][j],dp[i-val[j]][j-1]+wght[j]);
			}
		}
	}

	int ans;

	rf(i,100000,0)
	{
		if (dp[i][n]<=w)
		{
			ans=i;
			break;
		}
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

char a[402][402];
ll ch[402][402],h,w;
ll dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};

void dep(ll cnt,ll i,ll j){
	for(ll k=0;k<4;k++){
		ll nex=i+dx[k];
		ll ney=j+dy[k];
		char now=a[i][j];
		if(nex<0||nex>=h||ney<0||ney>=w){
			continue;
		}
		if(ch[nex][ney]!=-1){
			continue;
		}
		if(now==a[nex][ney]){
			continue;
		}
		ch[nex][ney]=cnt;
		dep(cnt,nex,ney);
	}
}

ll sum[160004];
int main() {
	cin>>h>>w;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin>>a[i][j];
			ch[i][j]=-1;
		}
	}
	ll cnt=0;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			if(ch[i][j]==-1){
				ch[i][j]=cnt;
				dep(cnt,i,j);
				cnt++;
				//cout << cnt <<endl;
			}
		}
	}
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			if(a[i][j]=='.'){
				ll now=ch[i][j];
				sum[now]++;
			}
		}
	}
	ll ans=0;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			if(a[i][j]=='#'){
				ll now=ch[i][j];
				ans+=sum[now];
			}
		}
	}
	cout <<ans;
	return 0;
}

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

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

	if(9 < a || 9 < b) cout << -1 << endl;
	else cout << a*b << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;
#define rep(i, j) for(int i = 0; i < j; i++)
#define f(i, k, j) for(int i = k; i < j; i++)
#define P pair<int, int>
const int INF = (1 << 26);

int N, S;
vector<int> vec;
vector< vector<int> > dp;

int solve(int n, int s){
    if(dp[n][s] != -1) return dp[n][s];
    int next = ((n + 1 >= N)? 0 : n + 1);
    int ret = ((n % 2 == 0)? 0 : 1);
    for(int i = 1; i <= vec[n]; i++){
        if(s - i <= 0) break;
        int nexts = solve(next, s - i);
        if(n % 2 == 0){
            if(nexts == 1) ret = 1;
        } else{
            if(nexts == 0) ret = 0;
        }
    }
    return dp[n][s] = ret;
}

int main(){
    while(cin >>N && N != 0){
        cin >>S;
        N *= 2;
        vec = vector<int>(N);
        rep(i, N) cin >>vec[i];
        dp = vector< vector<int> >(N);
        rep(i, N) dp[i] = vector<int>(S + 1, -1);
        rep(i, N){
            if(i % 2 == 0) dp[i][1] = 0;
            else dp[i][1] = 1;
        }
        cout <<solve(0, S) <<endl;
    }
    return 0;
}

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

int main(){
  int n, A[1000];

  while (1) {
    cin >> n;
    if (n == 0) break;
    int sum = 0;
    for (int i = 0; i < n; i++){
    cin >> A[i];
    sum += A[i];
  }
    double avg = 1.0*sum/n;
    double dist = 0;
    for (int i = 0; i < n; i++){
      dist += (avg - A[i])*(avg - A[i]);
    }

    printf("%lf\n", sqrt(dist/n));
  }

return 0;
}

Measured memory_bytes: 3204
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
#include<numeric>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  string s;
  getline(cin, s);

  ll sum = 0;
  rep (i, s.size()) {
    sum += s[i] - '0';
  }

  cout << ((sum % 9) ? "No" : "Yes") << endl;
}


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

int main(void){
    string s;
    cin >> s;
    bool flg = true;
    for(int i = 0; i < s.size() - 1; i++){
        if(s[i] == s[i + 1]) flg = false;
    }
    if(flg) cout << "Good" << endl;
    else cout << "Bad" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; FOR(cnt, 0, getline(stream,res,sp_word))
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;

int main(){
  int n;
  scanf("%d",&n);
  str s; cin >> s;

  int x = 0,maxi = 0;
  rep(i,n){
    x += (s[i] == 'I' ? 1 : -1);
    maxi = max(x,maxi);
  }

  printf("%d",maxi);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>


void swap(int* a, int* b)
{
	int t = *a;
	*a = *b;
	*b = t;
}


int partition (int arr[], int low, int high)
{
	int pivot = arr[high];
	int i = (low - 1); int j;
	for(j = low; j <= high- 1; j++)
	{

		if (arr[j] <= pivot)
		{
			i++;
			swap(&arr[i], &arr[j]);
		}
	}
	swap(&arr[i + 1], &arr[high]);
	return (i + 1);
}


void quickSort(int arr[], int low, int high)
{
	if (low < high)
	{

		int pi = partition(arr, low, high);


		quickSort(arr, low, pi - 1);
		quickSort(arr, pi + 1, high);
	}

}


int scanArray(int arr[], int size)
{
	int i;
	for (i=0; i < size; i++)
		scanf("%d", &arr[i]);
    return *arr;

}

int main()
{
	int size,x;
	scanf("%d",&size);

	int arr[size];

	scanArray(arr,size);

	quickSort(arr, 0, size-1);

	x=arr[size-1]-arr[0];

	printf("%d\n",x);
	return 0;
}



Measured memory_bytes: 128
#include<stdio.h>

int main(){
	
	int a, b;

	while(1){
		scanf("%d %d",&a, &b);
		if((a == 0) && (b == 0)){
			break;
		}else if(a < b){
			printf("%d %d\n", a, b);
		} else {
			printf("%d %d\n", b, a);
		}
	}

	return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    int i,j;
    int n,q;
    cin >> n >> q;
    vi a(n);
    rep(i,n) cin >> a[i];
    vi sum(n),even(n),odd(n);
    rep(i,n){
        sum[i] = a[i];
        if(i%2)odd[i] = a[i];
        else even[i] = a[i];
    }
    rep(i,n-1){
        sum[i+1] += sum[i];
        odd[i+1] += odd[i];
        even[i+1] += even[i];
    }
    /*
    rep(i,n)cout << " " << sum[i];cout << endl;
    rep(i,n)cout << " " << odd[i];cout << endl;
    rep(i,n)cout << " " << even[i];cout << endl;
    */
    rep(_,q){
        int x;
        cin >> x;
        if(a.back() <= x){
            if(n%2)cout << even[n-1] << endl;
            else cout << odd[n-1] << endl;
            continue;
        }
        if(a[0] > x){
            cout << sum[n-1] - sum[n/2-1] << endl;
            continue;
        }
        int ind = lower_bound(all(a),x) - a.begin();
        //cout << " "  << ind << endl;
        int ok = 0;
        int ng = n-ind;
        while(ng - ok > 1){
            int mid = (ok + ng)/2;
            int diff = a[ind + mid-1] - x;
            int l = lower_bound(all(a), x-diff) - a.begin();
            int num = ind + mid - l;
            //cout << ok << " " << ng << " " << mid << " " << diff << " " << l << " " << num << endl;
            if(mid + num > n){
                ng = mid;
            }else{
                if(x <= a[n - mid - num])ok = mid;
                else ng = mid;
            }
        }
        int b = n - (ind + ok);
        int p = n - b*2;
        int q = ind + ok;
        //cout << p << " " << q << endl;
        int ans = 0;
        ans += sum[n-1] - sum[q-1];
        if(p >= 0){
            if(n%2)ans += even[p];
            else ans += odd[p];
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 4864
cost = list(map(int, input().split()))
size = [1, 2, 4, 8]
N = int(input()) * 4

ans = 0
while N > 0:
    min_ = (N // size[0]) * cost[0]
    q = 0
    for i in range(1,4):
        tmp = (N//size[i]) * cost[i]
        if tmp < min_ and tmp != 0:
            min_ = tmp
            q = i
    ans += min_
    N = N%size[q]
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
    signed long n,i,count;
    scanf("%ld",&n);
    signed char* s = (signed char*) malloc(n * sizeof(signed char));
    scanf("%s",s);
    
    count = 1;
    signed char temp = s[0];
    for(i=1;i<n;i++)
    {
        if(temp != s[i])
        {
            temp = s[i];
            count++;
        }
        
    }
    printf("%ld\n",count);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int X, A, B;
	
	scanf("%d %d %d", &X, &A, &B);
	
	if((B - A) <= 0){
		printf("delicious");
	} else if((B - A) <= X){
		printf("safe");
	} else {
		printf("dangerous");
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 128
//Wrong answer on test inf.
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
#define y1 y1___
using namespace std;
char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
ll read(){
	char ch=gc();ll x=0;int op=1;
	for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
int len,ans;char op[5];
int init(){
    int k=10;
    for(int i=1;i<=9;i++){
        printf("? %lld\n",k);
        fflush(stdout);
        scanf("%s",op);
        if(op[0]=='N') return i;
        k=k*10;
    }
    k=9;
    for(int i=1;i<=9;i++){
        printf("? %lld\n",k);
        fflush(stdout);
        scanf("%s",op);
        if(op[0]=='Y') return i;
        k=k*10+9;
    }
    return 10;
}
int main(){
	len=init();
    if(len==10)
    {
        printf("! %d\n",1000000000);
        return 0;
    }
	for(int i=1;i<len;i++)
    {
        int l=0,r=9,t=0;
        while(l<=r)
        {
            int mid=(l+r)/2;
            printf("? %d\n",ans*10+mid);
            fflush(stdout);
            scanf("%s",op);
            if(op[0]=='Y')
            {
                t=max(t,mid);
                l=mid+1;
            }
            else
                r=mid-1;
        }
        ans=ans*10+t;
    }
	for(int i=(len==1?1:0);i<=9;i++)
    {
        printf("? %lld\n",((ll)ans*10+i)*10);
        fflush(stdout);
        scanf("%s",op);
        if(op[0]=='Y')
        {
            ans=ans*10+i;
            break;
        }
    }
    printf("! %d\n",ans);
	return 0;
}


Measured memory_bytes: 596
s_dash = $stdin.gets.chomp
t = $stdin.gets.chomp

s = s_dash.gsub('?', '.')
answers = []

(s_dash.length - t.length + 1).times do |num|
  substr = s[num, t.length] # '?c???'
  regexp = Regexp.new(substr.gsub('?', '.')) # /.c.../
  if regexp.match(t)
    ans = s_dash.dup
    ans[num, t.length] = t
    answers << ans.gsub('?', 'a')
  end
end

if answers.empty?
  answers << 'UNRESTORABLE'
end
puts answers.sort[0]


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

int main() {
  ll N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;

  ll mn = min({A, B, C, D, E});
  cout << (N + mn - 1) / mn + 4 << endl;
}

Measured memory_bytes: 256
#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()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

struct job
{
	int t,s;
};

bool operator<(job a,job b)
{
	if(a.s!=b.s)return a.s < b.s;
	return a.t > b.t;
}

bool cmp(job a,job b)
{
	return a.t > b.t;
}

int main()
{
	int n,m;
	cin >> n >> m;
	
	vector<job> v(n);
	rep(i,n)
	{
		cin >> v[i].t >> v[i].s;
	}
	sort(ALL(v),cmp);
	ll ans = 0;
	//rep(i,n)cout<<v[i].t<<endl;
	priority_queue<int> pq;
	rep(i,m)
	{
		while(v.back().t<=i+1)
		{
			pq.push(v.back().s);
			v.pop_back();
		}
		//cout<<pq.size()<<endl;
		if(!pq.empty())
		{
			ans = ans + pq.top();
			pq.pop();
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1660
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
 
#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
 
#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
using namespace std;
 
 
/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
 
int n;
 
int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	vector<ll> st;
	for (int i = 0; i < n; ++i) {
		ll x;
		cin >> x;
		while (true) {
			if (st.size() <= 1) {
				st.push_back(x);
				break;
			}
			else {
				ll a = st[st.size() - 2];
				ll b = st[st.size() - 1];
				if (b >= a && b >= x) {
					st.pop_back();
					st.pop_back();
					x += a - b;
				}
				else {
					st.push_back(x);
					break;
				}
			}
		}
	}
	int l = 0;
	int r = st.size() - 1;
	ll ans = 0;
	int sgn = 1;
	while (l <= r) {
		if (st[l] >= st[r])
			ans += sgn * st[l], ++l;
		else
			ans += sgn * st[r], --r;
		sgn *= -1;
	}
	cout << ans << "\n";
	return 0;
}
 
 

Measured memory_bytes: 256
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
c = S()
# 最終的に RR...RWW...WWW という状態になる
# R の個数を r とすると、左から r 個の石のうち R はそのままで W だけ入れ替えたら良い
r = Counter(list(c))['R']
ans = 0
for elem in c[:r]:
    if elem == 'W':
        ans += 1
print(ans)


Measured memory_bytes: 11000
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define LIM 1000007
#define ll long long
using namespace std;
int main() {
  string a, b, c;
  int ai, bi, ci;
  ai = bi = ci = 0;
  cin >> a >> b >> c;
  char n = ' ';
  n = a[0];
  ai++;
  while (1) {
    if (n == 'a') {
      if (ai >= a.size()) {
        cout << 'A' << endl;
        return 0;
      }
      n = a[ai];
      ai++;
    } else if (n == 'b') {
      if (bi >= b.size()) {
        cout << 'B' << endl;
        return 0;
      }
      n = b[bi];
      bi++;
    } else if (n == 'c') {
      if (ci >= c.size()) {
        cout << 'C' << endl;
        return 0;
      }
      n = c[ci];
      ci++;
    }
  }
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, a;
  cin >> n;
  unordered_map<int, int> um;

  rep(i, n) {
    cin >> a;
    um[a]++;
    um[a + 1]++;
    um[a - 1]++;
  }

  int ans = 0;
  for (auto x : um) ans = max(ans, x.second);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
int main(void){
    char a;
    cin >> a;
    int offset;
    offset = a;   //大文字と小文字のASCIIコードの差
     
    
    if(a <= 90)
    {
        cout << 'A' << endl;
    }
    else{
        cout << 'a' << endl;
    }
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define It set<node>::iterator
#define endl '\n'
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n,k;

signed main(){
	cin>>n>>k;
	if(n==k) return puts("0"),0;
	int t=abs(n-k)/k;
	if(n<k){
		n+=t*k;
		cout<<min(n,abs(n-k))<<endl;
	}else{
		n-=t*k;
		cout<<min(abs(n-k),abs(n-2*k))<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
for i in range(n):
    x = i+1
    if (x%3==0):
        print(f" {i+1}",end="")
    else:
        while x:
            if x%10==3:
                print(f" {i+1}",end="")
                break
            x //= 10
print()


Measured memory_bytes: 5884
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
vector<string> p1, p2;
int n, m;

bool comp1(int add_i, int add_j);
bool comp2(int add_i, int add_j);

signed main()
{
    cin >> n >> m;
    p1.assign(n, "");
    p2.assign(m, "");

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

    rep(i, m) {
        cin >> p2[i];
    }

    for (int i = 0; i <= n - m; i++) {
        for (int j = 0; j <= n - m; j++) {
            if (comp1(i, j)) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

bool comp1(int add_i, int add_j)
{
    bool fl = false;
    rep(i, m) {
        rep(j, m) {
            fl = true;
            if (p1[i+add_i][j+add_j] != p2[i][j]) {
                return false;
            }
        }
    }
    return fl;
}



Measured memory_bytes: 256