akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = list(input())

same = 0
for i in range(N):
    for j in range(1, N):
        if i+j*2 > N-1:
            break
        if S[i] != S[i+j] and S[i] != S[i+j*2] and S[i+j] != S[i+j*2]:
            same += 1

cnt = {'R': 0, 'G': 0, 'B': 0}
for c in S:
    cnt[c] += 1

print(cnt['R'] * cnt['G'] * cnt['B'] - same)


Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

ll dp[100001];//dp[i]...価値iを実現する最低の重さ
ll w[100];
ll v[100];

int main()
{
	int n;
	ll maxw;
	int ans=0;
	cin>>n>>maxw;
	for(int i=0;i<n;i++)
		cin>>w[i]>>v[i];
	fill(dp,dp+100001,1e15-1);

	dp[0]=0;
	//ここからDP
	for(int i=0;i<n;i++)
	{
		for(int j=100000;j>-1;j--)
		{
			//初期値じゃない重さのところがあれば
			if(dp[j]!=1e15-1 && j+v[i]<100001)
			{
				dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);//重さを更新する
				//cerr<<j+v[i]<<" "<<dp[j+v[i]]<<endl;
			}
		}
	}
	//ここまでDP
	//条件を満たす最大の価値を探す
	for(int i=100000;i>-1;i--)
	{
		if(dp[i]<=maxw)
		{
			//cerr<<dp[i]<<endl;
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)(a).size()

using namespace std;

void solve(){
    int k , s ;
    cin >> k >> s ;
    int ans = 0 ;
    int a ;
    for(int i = 0 ; i <= min(k,s)  ; i++ ){
        for( int j = 0 ; j <= min(k,s) ; j++ ){
            a = s - i - j;
            if(a>=0 && a <= min(k,s)){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed;
    cout.precision(10);

    int q = 1 ;
    // cin >> q ;
    while(q--){
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    char C;
    cin >> C;
    cout << char(C+1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
main(){
  while(1){
    long long h,w;
    int cnt[105]={0};
    cin>>h>>w;
    if(h==0&&w==0) break;
    for(int i=0;i<h;i++){
      for(int j=1;j<=w;j++){
	int num;
	cin>>num;
	if(num==1){
	  cnt[j]++;
	}
      }
    }
    priority_queue<P,vector<P>,greater<P> >que;
    for(int i=1;i<=w;i++){
      que.push(P(-cnt[i],i));
    }
    bool c=false;
    while(!que.empty()){
      if(c){
	cout<<" ";
      }
      else{
	c=true;
      }
      cout<<que.top().second;
      que.pop();
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3056
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, M = mi()
 
l = [i for i in range(1, N+1)]
 
if N % 2:
    for i in range(M):
        print(N//2-i, N//2+i+1)
else:
    for i in range(M//2, M):
        print(1+i-M//2, N-i+M//2)
    for i in range(M//2):
        print(N//2-i, N//2+i+2)


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

int main() {
	int n;
	cin >> n;
	int a[110000] = {};
	for (int i = 0;i < n;i++) {
		int p;
		cin >> p;
		a[p]++;
	}
	long long ans = 0;
	int num[4] = {};
	for (int i = 1;i <= 100000;i++) {
		while (a[i] >= 3)a[i] -= 2;
		num[a[i]]++;
	}
	ans = num[1] + num[2] - num[2] % 2;
	cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define per(i,a,b) for(ll i=(a)-1; i>=(b); i--)
const ll maxn=2e5+5;
ll k,n,a[maxn];
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>k>>n;
    rep(i,0,n) cin>>a[i];
    a[n]=k+a[0];
    ll ans=k;
    rep(i,1,n+1) ans=min(ans, k-a[i]+a[i-1]);
    cout<<ans<<"\n";
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>

using namespace std;
typedef long long ll;

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

int main() {

    ll N;
    cin >> N;
    pair<ll,ll> C[N];
    rep(i,N){
        ll A,B;
        cin >> A >> B;
        C[i].first = B;
        C[i].second = A;
    }
    sort(C,C+N);
    ll a = 0;
    ll b = 0;
    string out = "Yes";
    rep(i,N){
        b = C[i].first;
        a += C[i].second;
        if(b<a){
            out = "No";
            break;
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3328
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

#n,*a = map(int,read().split())

s = input()
l = len(s)

if l==2:
    if s[0]==s[1]: print(1,2)
    else: print(-1,-1)
    exit()

for i in range(l-2):
    t = s[i:i+3]
    #print(t)
    if t[0]==t[1] or t[1]==t[2] or t[2]==t[0]:
        print(i+1,i+3)
        break

else:
    print(-1,-1)
    




Measured memory_bytes: 9088
#include <iostream>

int main(){
	unsigned long long int s = 0;
	int n;
	std::cin >> n;

	for(int i = 1; i <= n; ++i){
		if(i % 3 != 0 && i % 5 != 0)s+=i;
	}

	std::cout << s << std::endl;

	return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    string S;
    int Q;
    cin >> S >> Q;
    bool rev = false;
    deque<char> deq;
	for(auto e:S) deq.push_back(e);
    rep(i, Q) {
        int q = 0;
        cin >> q;
        if (q == 1) {
            rev = !rev;
            continue;
        }
        int F;
        char C;
        cin >> F >> C;
        if (!rev) {
            if (F == 1)
                deq.push_front(C);
            else
                deq.push_back(C);

        } else {
            if (F == 1)
                deq.push_back(C);
            else
                deq.push_front(C);
        }
    }

    if(!rev){
		for(auto e:deq) cout << e;
	} else {
        reverse(all(deq));
		for(auto e:deq) cout << e;
	}
	cout << endl;
}

Measured memory_bytes: 976
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
#define ALL(c) (c).begin(), (c).end()

using namespace std;
using ll = long long;
using pli = pair<ll, int>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;


int N, A, B;

int main() {
	cin >> N >> A >> B;
	cout << min(A, B) << " " << max(0, (A + B) - N);
	return 0;
}


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

int main()
{
  int A,B,ans;
  
	cin >> A;
    cin >> B;
      
  if(A >= 13) {
    ans = B;
  }
  else if(A >= 6 && A <= 12) {
    ans = B /2;
  } else {
    ans = 0;
  }
  cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int hp = scanner.nextInt();
        int kinds = scanner.nextInt();
        int[] a = new int[kinds];
        for(int i = 0; i < kinds; i++) {
            a[i] = scanner.nextInt();
        }
        scanner.close();
 
        int sum = 0;
        for(int _a : a) {
            sum += _a;
        }
 
        System.out.println(hp <= sum ? "Yes" : "No");
    }
}

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

int n;

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

    cin >> n;
    for (int i = 111; i <= 999; i += 111) {
        if (i >= n) {
            cout << i << "\n";
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef struct eq
{
	int a;
	int b;
	int c;
} eq_t;

int main(){
	eq_t eq1, eq2;
	double ans_x, ans_y;
	
	while(scanf("%d %d %d %d %d %d", &eq1.a, &eq1.b, &eq1.c, &eq2.a, &eq2.b, &eq2.c)==6)
	{
		if(eq1.b == 0)
		{
			ans_x = (double)(eq1.c / eq1.a);
			ans_y = (double)(( eq2.c - eq2.a * ans_x ) / eq2.b);
		}
		else if(eq1.a == 0)
		{
			ans_y = (double)(eq1.c / eq1.b);
			ans_x = (double)(( eq2.c - eq2.b * ans_y ) / eq2.a);
		}
		else
		{
			if(eq2.b == 0)
			{
				ans_x = (double)(eq2.c / eq2.a);
				ans_y = (double)(( eq1.c - eq1.a * ans_x ) / eq1.b);
			}
			else if(eq2.a == 0)
			{
				ans_y = (double)(eq2.c / eq2.b);
				ans_x = (double)(( eq1.c - eq1.b * ans_y ) / eq1.a);
			}
			else
			{
				ans_x = (double)( eq1.c * eq2.b - eq1.b * eq2.c );
				ans_x = ans_x / ( eq1.a * eq2.b - eq1.b * eq2.a );
				ans_y = (double)(( eq1.c - eq1.a * ans_x ) / eq1.b);
			}
		}

		ans_x = ans_x + 0.000499999999;
		ans_y = ans_y + 0.000499999999;

		printf("%.3f %.3f\n", ans_x, ans_y);
	}
	
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define vl vector<ll>
const int INF = 1001001001;

int main() {

    int H, W, K;
    cin >> H >> W >> K;

    vector<string> S(11);
    rep(i, H) cin >> S[i];

    int ans = INF;
    rep(div, 1<<(H-1)) {
        int g = 0;
        vector<int> id(H);
        rep(i, H) {
            id[i] = g;
            if (div>>i&1) ++g;
        }
        ++g;

        vector<vector<int>> c(g, vector<int>(W, 0));
        rep(i, H) rep(j, W) c[id[i]][j] += (S[i][j] - '0');

        int num = g-1;
        vector<int> now(g);
        auto add = [&](int j) {
            rep(i, g) now[i] += c[i][j];
            rep(i, g) if (now[i] > K) return false;
            return true;
        };
        rep(j, W) {
            if (!add(j)) {
                num++;
                now = vector<int>(g);
                if (!add(j)) {
                    num = INF;
                    break;
                }
            }
        }
        ans = min(ans, num);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

bool test = true;
#define log(x) cout << "#x" << " : " << x << "\n";

int main()
{
    FIO;
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    int sum = 0;
    for(int i=0; i<n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    for(int i=0; i<k; i++) {
        sum+=v[i];
    }
    cout << sum << "\n";
}



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

// WIP
int main() {
    int n, k;
    cin >> n >> k;

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

    int ans = 1e9;

    for (int i = 0; i <= n - k; i++) {
        int a = x[i];
        int b = x[i + k - 1];

        if (a >= 0) {
            ans = min(ans, b);
        } else if (b <= 0) {
            ans = min(ans, -a);
        } else {
            int t;
            if (abs(a) > abs(b)) {
                t = b * 2 - a;
            } else {
                t = -a * 2 + b;
            }
            ans = min(ans, t);
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define int long long
#define endl "\n"
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("output.txt","w",stdout);

const int N = 2e5 + 5;
const double pi = 3.141592653589793238;

int32_t main()
{
    IOS;
    int a;
    cin >> a;
    a = a + (a*a) + (a*a*a);
    cout << a << endl;
}



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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

struct less_key {
    bool operator()(const std::pair<i64,i64> &left, const std::pair<i64,i64> &right) {
        return left.first < right.first;
    }
};

const i64 MAXN = 300005;

i64 n, k;
i64 a[MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> k;
    if (n * 500 >= k) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[37]:


N = int(input())
a = list(map(int, input().split()))


# In[38]:


a_list = a
a_plus = [item+1 for item in a]
a_minus = [item-1 for item in a]
# print(a)
# print(a_plus)
# print(a_minus)


# In[39]:


mylist = a_list + a_plus + a_minus


# In[40]:


import collections


# In[41]:


counted = collections.Counter(mylist)
ans = max(counted.values())
print(ans)


# In[ ]:






Measured memory_bytes: 29896
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] chs = in.nextLine().toCharArray();
        String ans = "No";
        in.close();
        if ( (chs[0] == chs[1] && chs[2] == chs[3] && chs[0] != chs[2])
                || (chs[0] == chs[2] && chs[1] == chs[3] && chs[0] != chs[1])
                || (chs[0] == chs[3] && chs[1] == chs[2] && chs[0] != chs[1]) ) {
            ans = "Yes";
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21076
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
 
int main()
{
int A ;
  int B ;
  cin >> A ;
  cin >> B ;
  if(A<9 && B<9) {
    cout << "Yay!" << endl;
  }
  else{
        cout << ":(" << endl;
  }
    ;

    return 0;
}

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

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}


int main(int argc, char const* argv[])
{
    string s;
    cin >> s;

    int k;
    cin >> k;

    vector<string> strs;
    for (int i = 0; i < (int)s.size(); i++) {
        for (int j = 1; j < k+1; j++) {
            strs.push_back(s.substr(i, j));
        }
    }

    sort(strs.begin(), strs.end());
    strs.erase(unique(strs.begin(), strs.end()), strs.end());

    // printvector(strs);
    cout << strs[k-1] << endl;

    return 0;
}

Measured memory_bytes: 1660
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
//#define int long long
#define ALL(x) begin(x),end(x)
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
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);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
/*signed*/int main(void) {   
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) {
        int tmp; cin >> tmp;
        a[i] = tmp / 400;
    }
    sort(a.begin(),a.end());
    int ans = 1;
    int cc = 0;
    rep(i, n - 1)if (a[i + 1] != a[i] && a[i + 1] < 8)++ans;
    rep(i, n)if (a[i] >= 8)++cc;
    if (cc == n)--cc;
    cout << ans << " " << ans + cc << endl;
    return 0;
}

Measured memory_bytes: 3540
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main() {//B問題
	int N;
	int *a;
 
	int Alice_Point = 0;
	int Bob_Point = 0;
 
	cin >> N;
	a = new int[N];
	
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
 
	sort(a, a + N);
 
	for (int j = N - 1; j >= 0; j--) {
		int Alice_Turn = (N-1) % 2;
 
		if (j%2==Alice_Turn) {
			Alice_Point += a[j];
			//cout << "A," << j << "," << a[j];
		}
		else {
			Bob_Point += a[j];
			//cout << "B," << j << "," << a[j];
		}
	}
 
	cout << Alice_Point - Bob_Point << endl;
	
	return 0;
}

Measured memory_bytes: 256
import queue
import sys

readline = sys.stdin.readline


def main():
    n_rooms, n_passages = map(int, input().split())
    passages = (map(int, readline().strip().split()) for _ in range(n_passages))

    # n_rooms, n_passages, *passages = map(int, open(0).read().split())

    connections = [set() for _ in range(n_rooms+1)]  # type: list
    for a, b in passages:
        connections[a].add(b)
        connections[b].add(a)

    que = queue.Queue()
    que.put((0, 1))  # parent, current

    signs = [-1] * (n_rooms + 1)

    while not que.empty():
        parent, current = que.get()

        if signs[current] != -1:
            continue

        signs[current] = parent

        for room in connections[current]:
            if signs[room] == -1:
                que.put((current, room))

    print('Yes')
    print('\n'.join(map(str, signs[2:])))


if __name__ == "__main__":
    main()


Measured memory_bytes: 71228
x, y = map(int, input().split())
x -= 1
y -= 1

d = [300000, 200000, 100000]

if x == y == 0:
    print(d[x] + d[y] + 400000)
else:
    s = 0

    if x < 3:
        s += d[x]
    if y < 3:
        s += d[y]

    print(s)

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

int main(){
	string S;
	getline(cin,S);
	for(int i=0;i<S.length();++i){
		if(S[i]>='a' && S[i]<='z')S[i]-=0x20;
		else if(S[i]>='A' && S[i]<='Z')S[i]+=0x20;
	}
	cout<<S<<endl;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

struct UnionFind {
    vector< int > data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};

struct info {
    int cost, first, second;

    bool operator<(const info &a) const { return a.cost < cost; }
};

signed main() {
    int N;
    cin >> N;
    set<pair<int, int>> tempX, tempY;
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        tempX.emplace(x, i);
        tempY.emplace(y, i);
    }
    priority_queue<info> check;
    {
        auto itr = tempX.begin();
        while (itr != next(tempX.end(), -1)) {
            int dif = abs(itr->first - next(itr, 1)->first);
            check.push({dif, itr->second, next(itr,1)->second});
            itr++;
        }
    }
    {
        auto itr = tempY.begin();
        while (itr != next(tempY.end(), -1)) {
            int dif = abs(itr->first - next(itr, 1)->first);
            check.push({dif, itr->second, next(itr, 1)->second});
            itr++;
        }
    }
    auto uf = UnionFind(N + 1);
    int ans = 0;
    while (!check.empty()) {
        auto now = check.top();
        check.pop();
        if (uf.find(now.first) != uf.find(now.second)) {
            ans += now.cost;
            uf.unite(now.first, now.second);
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 20976
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX (ll)(1e9)
int main() {
	ll L, R;
	cin >> L >> R;
	map<ll,int> vis;
	ll minn = MAX;
	for(ll i = L; i <= R; i++)
	{
		vis[i%2019]=1;
		for(ll j = i+1; j <= min(i+2019,R); j++)
		{
			minn = min((i*j)%2019,minn);
		}
		if(vis.size()>=2019) break;
	}
	cout << minn << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<math.h>
//#include<map>                                                                                                        
using namespace std;

int main()
{
  // 入力                                                                                                              
  int A, B;
  cin >> A >> B;

  double ans;

  ans = (double)(A + B) / 2;

  // ansが整数でない場合、答えは存在しない                                                               
  if((ans - (double)floor(ans)) > 0.0) cout << "IMPOSSIBLE" << endl;
  else cout << (int)ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

cplus = 0

for i in range(N-1):
    if A[i+1] == A[i]+1:
        cplus += C[A[i]-1]

print(sum(B) + cplus)

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

typedef long long ll;
typedef unsigned long long ull;

typedef array<ll,2> XY;

class UnionFind{
public:
    UnionFind(size_t n){
        m_parent.resize(n);
        iota(m_parent.begin(), m_parent.end(), 0);

        m_rank.resize(n);
        fill(m_rank.begin(), m_rank.end(), 0);
    }

    int Find(int x){
        if(m_parent[x] == x){
            return x;
        }else{
            m_parent[x] = Find(m_parent[x]);
            return m_parent[x];
        }
    }

    void Union(int x, int y){
        auto xroot = Find(x);
        auto yroot = Find(y);
        if(m_rank[xroot] > m_rank[yroot]){
            m_parent[yroot] = xroot;
        }else if(m_rank[xroot] < m_rank[yroot]){
            m_parent[xroot] = yroot;
        }else if(xroot != yroot){
            m_parent[yroot] = xroot;
            m_rank[xroot] = m_rank[xroot] + 1;
        }
    }
    std::vector<int> m_parent;
    std::vector<int> m_rank;
};

int main()
{
    ll N;
    cin >> N;
    ll xi, yi;
    vector<XY> xy;
    UnionFind uf(200000);
    for(int i=0;i<N;i++){
        cin >> xi >> yi;
        uf.Union(xi-1, 100000+yi-1);
        xy.push_back(array<ll,2>{xi, yi});
    }
    map<ll, set<ll>> Gx;
    map<ll, set<ll>> Gy;
    map<ll, ll> Ge;
    for(auto v : xy){
        auto root = uf.Find(v[0]-1);
        if(Gx.count(root)==0) Gx[root]=set<ll>();
        if(Gy.count(root)==0) Gy[root]=set<ll>();
        if(Ge.count(root)==0) Ge[root]=0;
        Gx[root].insert(v[0]);
        Gy[root].insert(v[1]);
        Ge[root]++;
    }
    ll res=0;
    for(auto m : Ge){
        auto ig = m.first;
        if(Gx[ig].size() >= 2 && Gy[ig].size() >= 2){
            res += Gx[ig].size() * Gy[ig].size() - Ge[ig];
        }
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 8048
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MOD 1000000007
int i, j, k;
 
int main(){
  int N, H[100000];
  scanf("%d", &N);
  for(i=0;i<N;i++){
    scanf("%d", &H[i]);
  }
  for(i=0;i<N-1;i++){
    if(H[i] >= H[i+1]){
   	 if(H[i] - H[i+1] >= 2){
 	     puts("No");
 	     exit(0);
	    }else if(H[i] - H[i+1] == 1){
	      --H[i];
	    }else if(H[i] - H[i+1] == 0){
	      if(i == 0) --H[i];
       		else if(i>0 && H[i-1] != H[i]) --H[i];
     	}
 	 }
  }
  for(i=0;i<N-1;i++){
    if(H[i]>H[i+1]){
      puts("No");
      exit(0);
    }
  }
  puts("Yes");
  
  return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin >> N;
	int i = 1;
	while (i * 1000 < N) {
		i++;
	}
	cout << i * 1000 - N << '\n';
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int i,j,a[10],n,b,c,l,k;
int main()
{
  for(cin>>n;i<n;i++)cin>>a[i];
  sort(a,a+n,greater<int>());
  c+=a[0]/2;
  for(i=1;i<n;i++)c+=a[i];
  cout<<c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int mod=1000000007;
int cnt[27];
int main(){
    int n;
    string s;
    cin>>n>>s;
    rep(i,n){
        ++cnt[s[i]-'a'];
    }
    ll ans=1;
    rep(i,26)if(cnt[i]>0){
        ans*=(cnt[i]+1);
        ans%=mod;
    }
    cout<<(ans-1+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>                                                      
using namespace std;                                                     
                                                                         
int main() {                                                             
  while (true) {                                                         
    int x, y;                                                            
    cin >> x >> y;                                                       
    if (x==0 && y==0) {                                                  
      break;                                                             
    }                                                                    
    if (x>y) {                                                           
     swap(x,y);                                                          
    }                                                                    
    cout << x << " " << y << endl;                                       
  }                                                                      
  return 0;                                                              
}                                                                        
                  

Measured memory_bytes: 2984
#include<bits/stdc++.h>
using namespace std;
using P = pair<int64_t,int64_t>;
int main(){
  int64_t W, H;
  cin >> W >> H;
  vector<int64_t> w(W);
  vector<int64_t> h(H);
  for(int i=0; i<W; i++){
    cin >> w[i];
  }
  for(int i=0; i<H; i++){
    cin >> h[i];
  }
  
  vector<P> vec(H+W);
  for(int i=0; i<H+W; i++){
    P p;
    if(i < W){
      p = {w[i],0};
    }
    else{
      p = {h[i-W],1};
    }
    vec[i] = p;
  }
  
  sort(vec.begin(),vec.end());
  int64_t CH = H+1;
  int64_t CW = W+1;
  int64_t ans = 0;
  for(int i=0; i<H+W; i++){
    P p = vec[i];
    if(p.second == 0){
      ans += p.first*CH;
      CW--;
    }
    else{
      ans += p.first*CW;
      CH--;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cout.tie(NULL);
	int h1,m1,h2,m2,k;
  	cin>>h1>>m1>>h2>>m2>>k;
  	cout<<(h2-h1)*60+m2-m1-k<<endl;
}

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

class Point {
public:
	int x;
	int y;
	Point() {
		x = 0;
		y = 0;
	}
};

class Robot {
public:
	int x;
	int y;
	int h;
	Robot(int N, Point* r) {
		x = 10;
		y = 10;
		h = 0;
		for (int i = 0; i < N; i++) {
			if (x == r[i].x&&y == r[i].y)h++;
		}
	}
	void e() { x++; }
	void n() { y++; }
	void w() { x--; }
	void s() { y--; }
};


int main() {
	int N;
	while (cin >> N&&N) {
		Point ruby[20];
		for (int i = 0; i < N; i++) cin >> ruby[i].x >> ruby[i].y;
		int M;
		cin >> M;
		Robot robot(N, ruby);
		for (int i = 0; i < M; i++) {
			char o;
			int t;
			cin >> o >> t;
			switch (o) {
			case 'N':
				for (int j = 0; j < t; j++) {
					robot.n();
					for (int k = 0; k < N; k++)if (robot.x == ruby[k].x&&robot.y == ruby[k].y) {
						robot.h++; ruby[k].x = -1; ruby[k].y = -1;
					}
				}
				break;
			case 'S':
				for (int j = 0; j < t; j++) {
					robot.s();
					for (int k = 0; k < N; k++)if (robot.x == ruby[k].x&&robot.y == ruby[k].y) {
						robot.h++; ruby[k].x = -1; ruby[k].y = -1;
					}
				}
				break;
			case 'E':
				for (int j = 0; j < t; j++) {
					robot.e();
					for (int k = 0; k < N; k++)if (robot.x == ruby[k].x&&robot.y == ruby[k].y) {
						robot.h++; ruby[k].x = -1; ruby[k].y = -1;
					}
				}
				break;
			case 'W':
				for (int j = 0; j < t; j++) {
					robot.w();
					for (int k = 0; k < N; k++)if (robot.x == ruby[k].x&&robot.y == ruby[k].y) {
						robot.h++; ruby[k].x = -1; ruby[k].y = -1;
					}
				}
				break;
			default:break;
			}
		//	cout << robot.h << endl;
		}
		if (robot.h == N)puts("Yes");
		else puts("No");


	}
	return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    ll a,b,c,k,ans=0;
    cin >> a >> b >> c >> k;

    if(k<=a){
        ans += k;
    }else if(a < k && k <= b){
        ans += a;
    }else{
        ans += a;
        ans -= (k-a-b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    a, b = gets.split.map(&:to_i)

    ans = 0
    a.upto(b) do |i|
      s = i.to_s
      sr = s.reverse

      ans += 1 if s == sr
    end

    puts ans
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2428
using System;

class A{
  public static void Main(){
    int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    Array.Sort(Ar);
    Array.Reverse(Ar);
    int c = 0;
    c += Math.Abs(Ar[0]-Ar[1]);
    c += Math.Abs(Ar[1]-Ar[2]);
    Console.WriteLine(c);
  }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    map<int, int>d;
    d[N] = 1;
    int b_a = N;
    int num = 2;
    while (true) {
        int ans;
        if (b_a % 2 == 0) {
            ans = b_a /2;
        } else {
            ans = (3 * b_a) + 1;
        }

        if (d.count(ans) > 0) {
            break;
        } else {
            d[ans] = num;
        }

        b_a = ans;
        num++;
    }

    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>

using namespace std;

const int mod = 1000000007;

int solve(int n, int offset, set<int> &blacklist, vector<int> &memo) {
  if (offset == n) {
    return 1;
  }

  if (memo[offset] < 0) {
    int ans = 0;
    if (blacklist.count(offset + 1) == 0) {
      ans = (ans + solve(n, offset + 1, blacklist, memo)) % mod;
    }

    if (offset + 2 <= n && blacklist.count(offset + 2) == 0) {
      ans = (ans + solve(n, offset + 2, blacklist, memo)) % mod;
    }

    memo[offset] = ans;
  }

  return memo[offset];
}

int main(int argc, const char *argv[])
{
  int n, m;
  cin >> n >> m;

  vector<int> memo(n + 1, -1);
  set<int> blacklist;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    blacklist.insert(a);
  }

  cout << solve(n, 0, blacklist, memo) << "\n";
  
  return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
    int a, b, c; cin >> a >> b >> c;
    if((a * 100 + b * 10 + c) % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int a = stdin.nextInt();
        int b = stdin.nextInt();
        if (a > b) {
            int temp = a;
            a = b;
            b = temp;
        }

        int c = Math.abs(a - b);
        if (c % 2 == 0) {
            System.out.println(b - c / 2);
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }

}


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


int main(void){
	int n,a,b,c;
	cin>>n>>a;
	c=a;
	
	for(int i=0;i<n-1;i++){
		cin>>b;
		c+=b;
		if(a<b){
			a=b;
		}
	}
	
	if(a<c-a){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}	


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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,d;
    cin >> n >> d;
    vector<vector<int>> x(n,vector<int> (d));
    rep(i,0,n){
        rep(j,0,d){
            cin >> x[i][j];
        }
    }
    // rep(i,0,n){
    //     rep(j,0,d){
    //         cout << x.at(i).at(j) <<" ";
    //     }
    //     cout ENDL;
    // }

    double dist=0;
    int cnt=0;
    rep(i,0,n){
        rep(j,i+1,n){
            rep(k,0,d){
                //cout << "xid: " << x.at(i).at(k) << ":: xjd: " << x.at(j).at(k) ENDL;
                dist+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                //cout <<"dist: "<< dist ENDL;
            }
            bool flag=0;
            repe(h,0,dist){
                if(h*h==dist) flag=1; 
            }
            if(flag) cnt++;
            // dist=sqrt(dist);
            // //cout <<"dist: "<< dist ENDL;

            // int dist2=dist;
            // //cout <<"dist2: "<< dist2 ENDL;
            // if(dist2%10==0) cnt++;
            dist=0.0;
        }
    }
    cout << cnt ENDL;
    return 0;
}

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

int main(){
	int A, B, C;
  cin >> A >> B >> C;
  
  if (A == 5 && B == 5 && C == 7){
    cout << "YES" << endl;
  }
  else if (A == 5 && B == 7 && C == 5){
      cout << " YES" << endl;
  }
  else if ( A== 7 && B == 5 && C == 5){
      cout << "YES"<<  endl;
  } 
  else {
  cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n,t,a;
	scanf("%lld%lld%lld",&n,&t,&a);
	ll ans;
	double m=1e10;
	rep(i,1,n+1){
		ll h;
		scanf("%lld",&h);
		double diff=fabs(a-(t-0.006*h));
		if(diff<m){
			m=diff;
			ans=i;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
#import sys
#input = sys.stdin.readline
import heapq
def main():
    N = int( input())
    A = list( map( int, input().split()))
    B = list( map( int, input().split()))
    C = [(-B[i],i) for i in range(N)]
    heapq.heapify(C)
    ans = 0
    check = 0
    while check < N:
        a,i = heapq.heappop(C)
        a *= -1

        if B[i] == A[i]:
            check += 1
            continue
        cnt = (B[i] - A[i])//(B[i-1] + B[(i+1)%N])
        if cnt == 0:
            print(-1)
            return
        ans += cnt        
        a -= (B[i-1] + B[(i+1)%N])*cnt
        B[i] = a
        if B[i] == A[i]:
            check += 1
        elif B[i] > A[i]:
            heapq.heappush(C, (-a, i))
        else:
            print(-1)
            return

    print(ans)
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 124568
<?php
        fscanf(STDIN, "%d", $N);
        fscanf(STDIN, "%d", $min);
        for ($i=0; $i < 4; $i++) { 
            fscanf(STDIN, "%d", $now);
            if ($min > $now) {
                $min = $now;
            }
        }
        $result = 4 + ceil($N / $min);
     
        printf("%d\n", $result);

Measured memory_bytes: 4604
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left
from heapq import *
import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 998244353

def check(mid, points, origin, rotate):
    height = origin * math.cos(math.radians(rotate))
    # print(height)
    cs = math.cos(math.radians(rotate))
    sn = math.sin(math.radians(rotate))
    for px, py in points:
        py = py - origin
        rx, ry = px*cs - py * sn, px * sn + py * cs
        if abs(rx) > height + 0.0000001 or abs(ry) > height + 0.0000001:
            # print("FALSE", rotate)
            return False

    return True


class Segtree_op():
    def __init__(self, n):
        self.size = 1
        while (n >= 1):
            self.size = self.size << 1
            n = n // 2

        self.arr = [self.unit() for i in range(self.size * 2)]

    def op(self, lch, rch):
        return lch + rch

    def unit(self):
        return 0

    def update(self, k, val):
        k += self.size - 1
        self.arr[k] = val
        while (k):
            k = (k - 1) // 2
            self.arr[k] = self.op(self.arr[k * 2 + 1], self.arr[k * 2 + 2])

    def query(self, l, r):
        L = l + self.size
        R = r + self.size
        s = self.unit()
        while L < R:
            if R & 1:
                R -= 1
                s = self.op(s, self.arr[R - 1])

            if L & 1:
                s = self.op(s, self.arr[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def show(self):
        idx = 1
        while (idx <= self.size):
            print(self.arr[idx - 1:idx * 2 - 1])
            idx *= 2


def solve():
    n = input().strip()
    if int(n[-1]) in [2,4,5,7,9]:
        print("hon")
    elif int(n[-1]) in [0,1,6,8]:
        print("pon")
    else:
        print("bon")


def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    solve()



Measured memory_bytes: 68072
s=input()
t=input()
a=[]
b=[]
for i in range(len(s)):
    a.append(s[i])
    a.sort()
for i in range(len(t)):
    b.append(t[i])
    b.sort(reverse=True)
c=[a,b]
c.sort()
if c[0]==a and a!=b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

struct Segtree {
	ll a[N_SIZE];
	ll seg[N_SIZE * 2];
	ll lazy[N_SIZE * 2];
	ll gt;
	void init(int n) {
		gt = 1;
		while (n > gt)gt *= 2;
		REP(i, n)a[i] = 0;
		REP(i, N_SIZE) {
			seg[i] = 0;
			lazy[i] = 0;
		}
		REP(i, n)seg[i + gt - 1] = a[i];
	}

	void lazy_evaluate(int k, int l, int r) {
		seg[k] += lazy[k] * (r - l);
		if (gt > k) {
			lazy[2 * k + 1] += lazy[k];
			lazy[2 * k + 2] += lazy[k];
		}
		lazy[k] = 0;
	}

	//[a,b)
	void update(int a, int b, int x) { update(a, b, 0, 0, gt, x); }
	void update(int a, int b, int k, int l, int r, int x) {
		if (r <= a || b <= l)return;
		if (a <= l&&r <= b)lazy[k] += x;
		else {
			update(a, b, 2 * k + 1, l, (l + r) / 2, x);
			update(a, b, 2 * k + 2, (l + r) / 2, r, x);
			if (gt > k) {
				seg[k] = seg[2 * k + 1] + lazy[2 * k + 1] * (r - l) / 2
					+ seg[2 * k + 2] + lazy[2 * k + 2] * (r - l) / 2;
			}
		}
	}

	//[a,b???min
	ll query(int a, int b) { return query(a, b, 0, 0, gt); }
	ll query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return 0;
		if (a <= l&&r <= b) {
			return seg[k] + (r - l)*lazy[k];
		}
		else {
			lazy_evaluate(k, l, r);
			return query(a, b, 2 * k + 1, l, (l + r) / 2)
				+ query(a, b, 2 * k + 2, (l + r) / 2, r);
		}
	}

	void print() {
		REP(i, gt * 2)cout << "!" << i << " " << seg[i] << " " << lazy[i] << endl;
	}
};

int n, q;
Segtree tr;

int main() {
	cin >> n >> q;
	tr.init(n);
	REP(i, q) {
		bool f;
		int a, b, c;
		cin >> f;
		if (!f) {
			cin >> a >> b >> c;
			a--; b--;
			tr.update(a, b + 1, c);
		}
		else {
			cin >> a >> b;
			a--; b--;
			cout << tr.query(a, b + 1) << endl;
		}
		//tr.print();
	}
}

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

using namespace std;

const int maxn=2e4+10;
int tot=1,last=1,c[maxn],a[maxn],dp[maxn];
int k;
string s;

struct SAM{
	int link,len;
	int ch[26];
}sam[maxn];

void build(int x){
	int cur=++tot,p=last;
	sam[cur].len=sam[p].len+1;
	for(;p&&!sam[p].ch[x];p=sam[p].link)
		sam[p].ch[x]=cur;
	if(!p) sam[cur].link=1;
	else{
		int q=sam[p].ch[x];
		if(sam[q].len==sam[p].len+1) sam[cur].link=q;
		else{
			int clone=++tot;
			sam[clone]=sam[q],sam[clone].len=sam[p].len+1;
			for(;p&&sam[p].ch[x]==q;p=sam[p].link)
				sam[p].ch[x]=clone;
			sam[q].link=sam[cur].link=clone;
		}
	}last=cur;
}

void cal(){
	for(int i=1;i<=tot;i++) c[sam[i].len]++;
	for(int i=1;i<=tot;i++) c[i]+=c[i-1];
	for(int i=1;i<=tot;i++) a[c[sam[i].len]--]=i;
	for(int i=tot;i;i--){
		dp[a[i]]=1; 
		for(int j=0;j<26;j++)
			if(sam[a[i]].ch[j])
				dp[a[i]]+=dp[sam[a[i]].ch[j]];
	}
	dp[1]--;	int now=1;
	while(k){
		for(int i=0;i<26;i++){
			if(sam[now].ch[i]&&dp[sam[now].ch[i]]<k)
				k-=dp[sam[now].ch[i]];
			else if(sam[now].ch[i]){
				printf("%c",(char)i+'a');
				now=sam[now].ch[i];k--;
				goto end;
			}
		}
		return ;
		end:;
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin>>s>>k;
	for(int i=0;i<s.size();i++)
		build(s[i]-'a');
	cal();
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <string.h>
#include <math.h>
typedef long long ll;
#define INF			100000
#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REP(i,x,y)	for (int (i)=(x);(i)<(y);(i)++)
#define REP_(i,x,y)	for ((i)=(x);(i)<(y);(i)++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef pair<int, int> Point;
typedef vector<vector<Point>> Graph;

int A,B,K;

int main() {
	
	cin >> A >> B >> K;

	REP(i,A,MIN(A+K,B+1)) cout << i << endl;
	REP(i,MAX(B-K+1,A+K),B+1) cout << i << endl;

	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int i,j,miji,n,temp,count=0,A[100];
  scanf("%d",&n);

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

  for(i=0;i<n-1;i++){
    miji=i;
  for(j=i;j<=n-1;j++){
    if(A[j] < A[miji]){
      miji = j;
    }
  }
      temp = A[i];
      A[i] = A[miji];
	A[miji] = temp;
	if(i != miji)	count++;
    }
    
  
  
  
  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[i],count);

  return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main() {
    int sum = 0, quantity = 0, count = 0;
    int a, b;
    char c;
    while (cin >> a >> c >> b) {
        sum += a * b;
        quantity += b;
        count ++;
    }
    cout << sum << endl;
    cout << quantity / count + ((quantity % count) * 2 >= count ? 1 : 0) << endl;

    return 0;
}

Measured memory_bytes: 1160