akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
b = a[:]
cnt1, cnt2 = 0, 0
s = 0
for i in range(n):
  if (i%2==0 and s+a[i]<=0) or (i%2==1 and s+a[i]>=0) :
    cnt1 += abs(s+a[i])+1
    if i%2:
      s = -1
    else:
      s = 1
  else:
    s += a[i]
s = 0
for i in range(n):
  if (i%2==1 and s+a[i]<=0) or (i%2==0 and s+a[i]>=0) :
    cnt2 += abs(s+a[i])+1
    if i%2:
      s = 1
    else:
      s = -1
  else:
    s += a[i]
print(min(cnt1, cnt2))

Measured memory_bytes: 14468
MAX = 100
INF = 1000000
WHITE = 0
GRAY = 1
BLACK = 2
n = int(raw_input())

M = [[INF for i in range(n)]for j in range(n)]
d = [INF for i in range(MAX)]
Color = [WHITE for i in range(MAX)]
for i in range(n):
    tmp = map(int,raw_input().split())
    u = tmp[0]
    k = tmp[1]
    for j in range(1, k + 1):
        v = tmp[j * 2]
        c = tmp[j * 2 + 1]
        M[u][v] = c

#def dijkstra():
d[0] = 0
Color[0] = GRAY
    
while True:
    minv = INF
    u = -1
    for i in range(n):
        if minv > d[i] and Color[i] != BLACK:
            u = i
            minv = d[i]
    if u == -1:
        break
    Color[u] = BLACK
    for v in range(n):
        if Color[v] != BLACK and M[u][v] != INF:
            if d[v] > d[u] + M[u][v]:
                d[v] = d[u] + M[u][v]
                Color[v] = GRAY
for i in range(n):
    print i,
    if d[i] == INF:
        print -1
    else:
        print d[i]

Measured memory_bytes: 6460
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
V, E = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(E)]
X = sorted(X, key = lambda x:x[2])
UF = UnionFind(V)
ans = 0
for i in range(E):
    a, b = X[i][0]+1, X[i][1]+1
    if not UF.same_check(a, b):
        UF.union(a, b)
        ans += X[i][2]
print(ans)
        



Measured memory_bytes: 28988
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using lli = long long int;
int main(){
  int n;
  std::cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) std::cin >> a[i];
  for (int i = 0; i < n; i++) std::cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  lli ans = 1, mod = 1e9 + 7;
  for (int i = 0; i < n; i++) {
    int pos, prev;
    if(a[i] < b[i]){
      pos  = *lower_bound(b.begin() + i, b.end(), a[i]);
      prev = lower_bound(a.begin(), a.end(), pos) - a.begin() - i;
    }else{
      pos  = *lower_bound(a.begin() + i, a.end(), b[i]);
      prev = lower_bound(b.begin(), b.end(), pos) - b.begin() - i;
    }
    ans *= prev;
    ans %= mod;
  }
  std::cout << ans << std::endl;
  return 0;
}


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

typedef long long ll;

int n;
string str;

int main()
{
    cin >> str;

    if(str == "SSS") n = 0;
    if(str == "SSR") n = 1;
    if(str == "SRS") n = 1;
    if(str == "SRR") n = 2;
    if(str == "RSS") n = 1;
    if(str == "RSR") n = 1;
    if(str == "RRS") n = 2;
    if(str == "RRR") n = 3;

    printf("%d", n);

    return 0;
}


Measured memory_bytes: 3748
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,q,res;
int a[55],b[55],c[55],d[55], aa[10];
int check(){
	int res=0;
	for(int i=0;i<q;i++)
		if(aa[b[i]]-aa[a[i]]==c[i]) res+=d[i];
	return res;
}

void solve(int x){
	if(x==n){
        res=max(res,check());
        return;
    }
	for(int i=aa[x-1];i<=m;i++){
		aa[x]=i;
		solve(x+1);
	}
}

int main(){
	scanf("%d%d%d", &n,&m,&q);
	for(int i=0;i<q;i++){
        scanf("%d%d%d%d", &a[i],&b[i],&c[i],&d[i]);
		a[i]--;
            b[i]--;
	}
	aa[0]=1;
	solve(1);
	printf("%d\n", res);
}


Measured memory_bytes: 3816
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

int n;
ll ans;
vector<ll>arr;
int main()
{
    cin>>n;
    arr.resize(n);
    for(ll &i:arr)cin>>i;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            ans+=arr[i]*arr[j];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
x,n = [int(i) for i in input().split()]
if n == 0:
  print(x)
  exit()
p = [int(i) for i in input().split()]

num = list(range(102))
nums = []
for i in num:
  if not(i in p):
    nums.append(i)
#print(nums)
p2 = [abs(nums[i]-x) for i in range(len(nums))]
p2min = min(p2)
for i in range(len(p2)):
  if p2[i] == p2min:
    print(nums[i])
    exit()


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

int main() {
    int a[10];

    int d, n = 0;

    while ( scanf("%d", &d) != EOF ) {
        if ( d ) {
            a[n++] = d;
        } else {
            printf("%d\n", a[--n]);
        }
    }

    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define kill _z_kill
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
#define User_Time ((double)clock()/CLOCKS_PER_SEC)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
//int Pow(int x,int y){
//	int ans=1;
//	for (;y;y>>=1,x=(LL)x*x%mod)
//		if (y&1)
//			ans=(LL)ans*x%mod;
//	return ans;
//}
//void Add(int &x,int y){
//	if ((x+=y)>=mod)
//		x-=mod;
//}
//void Del(int &x,int y){
//	if ((x-=y)<0)
//		x+=mod;
//}
//int Add(int x){
//	return x>=mod?x-mod:x;
//}
//int Del(int x){
//	return x<0?x+mod:x;
//}
//void ckmax(int &x,int y){
//	if (x<y)
//		x=y;
//}
//void ckmin(int &x,int y){
//	if (x>y)
//		x=y;
//}
const int N=200005;
int n;
vi e[N],v[3],u[2];
void dfs(int x,int pre,int d){
	u[d].pb(x);
	for (auto y : e[x])
		if (y!=pre)
			dfs(y,x,d^1);
}
int res[N];
void gao(vi &a,vi &b){
	while (!a.empty()&&!b.empty()){
		res[a.back()]=b.back();
		a.pop_back();
		b.pop_back();
	}
}
int main(){
	n=read();
	For(i,1,n-1){
		int x=read(),y=read();
		e[x].pb(y),e[y].pb(x);
	}
	For(i,1,n)
		v[i%3].pb(i);
	dfs(1,0,0);
	if (u[1].size()<u[0].size())
		swap(u[0],u[1]);
	if (v[2].size()<v[1].size())
		swap(v[1],v[2]);
	if (u[0].size()<=v[0].size()){
		gao(u[0],v[0]);
		For(i,0,2)
			gao(u[1],v[i]);
	}
	else {
		gao(u[0],v[1]);
		gao(u[0],v[0]);
		gao(u[1],v[0]);
		gao(u[1],v[2]);
	}
	For(i,1,n)
		printf("%d ",res[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 22296
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int n, m;

void init() {

}

void input() {

}

void solve() {
  cin >> n >> m;
  vector<int> y;
  for(long long i=1; i*i<=m; i++){
      if(m%i == 0){
          y.push_back(i);
          if(i != m/i) y.push_back(m/i);
      }
  }
  sort(ALL(y));
  REP(i, SZ(y)) if(y[i] >= n){
    cout << m/y[i] << endl;
    return;
  }
}

int main() {
	init();
	input();
	solve();
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  string s;cin>>s;
  int l=s.length();
  REP(i,l/2){
    if (s[i]!=s[l-1-i])
    ans++;
  } 
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<set>
#include<iostream>
using namespace std;
int main()
{
    set<long long int>s;
    long long int n,x,i,c;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x;
        if(s.find(x)!=s.end())
        {
            s.erase(x);
        }
        else
        {
            s.insert(x);
        }
    }
    long long int l=s.size();
    cout<<l<<endl;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>

typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int a,b=0;
  a=s.length();
  if(s[0]=='A'){
    for(int i=2;i<a-1;i++){
      if(s[i]=='C'){
        for(int j=0;j<a;j++){
          if(s[j]>='A' && s[j]<='Z'){
            b++;
          }
        }
        if(b==2){
          cout << "AC" << endl;
          return 0;
        }
      }
    }
  }
  cout << "WA" << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
  int n;
  cin >> n;
  int count = 0;
  for( int i=0; i<4; ++i){
    if ( n%10 == 2 ) ++count;
    n /= 10;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n, m;
    cin >> n;
    map<string ,int> mp;
    rep(i, n) {
        string tmp_s;
        cin >> tmp_s;
        mp[tmp_s]++;
    }
    cin >> m;
    rep(i, m) {
        string tmp_s;
        cin >> tmp_s;
        mp[tmp_s]--;
    }
    int ans = 0;
    for ( auto tmp_mp : mp){
        ans = max(ans, tmp_mp.second);
    }
    cout << max(0, ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

int main()
{
    ll a=in(),b=in();
    cout<<(a<=9&&b<=9?a*b:-1)<<endl;
}


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

int main(){
    int n;
    cin >> n;
    char s[n+1];
    int e[n];
    int w[n];
    for(int i = 0; i < n; i++){
        cin >> s[i];
        if(s[i] == 'W'){
            if(i == 0){
                w[i] = 1;
            }
            else{
                w[i] = w[i-1] + 1;
            }
        }
        else{
            if(i == 0){
                w[i] = 0;
            }
            else{
                w[i] = w[i-1];
            }
        }
    }
    int min = 1000000;
    for(int i = n-1; i >= 0; i--){
        if(s[i] == 'E'){
            if(i == n-1){
                e[i] = 1;
            }
            else{
                e[i] = e[i+1] + 1;
            }
        }
        else{
            if(i == n-1){
                e[i] = 0;
            }
            else{
                e[i] = e[i+1];
            }
        }
        if(i == 0){
            if(e[i+1] < min)min = e[i+1];
        }
        else if(i == n-1){
            if(w[i-1] < min)min = w[i-1];
        }
        else{
            if((e[i+1] + w[i-1]) < min)min = (e[i+1] + w[i-1]);
        }
    }
    

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 2944
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY  (1 << 30)

int h,A[MAX+1];

void maxHeapfy(int i){
    int l,r,largest;
    l = 2*i;
    r = 2*i+1;
    
    if(l <= h && A[l] > A[i]){
        largest = l;
    }else{
        largest = i;
    }
    if(r <= h && A[r] > A[largest]){
        largest = r;
    }
    if(largest != i){
        swap(A[i],A[largest]);
        maxHeapfy(largest);
    }
}

int extract(){
    int maxv;
    if (h < 1) return -INFTY;
    maxv = A[1];
    A[1] = A[h--];
    maxHeapfy(1);
    return maxv;
}

void increaseKey(int i, int key){
    if (key < A[i]) return;
    A[i] = key;
    while( i > 1 && A[i/2] < A[i]){
        swap(A[i],A[i/2]);
        i = i/2;
    }
}
void insert(int key){
    h++;
    A[h] = -INFTY;
    increaseKey(h,key);
}

int main(){
    int key;
    char com[10];

    while(1){
        scanf("%s",com);
        if(com[0]=='e'&& com[1] == 'n')break;
         if(com[0] == 'e' && com[1] == 'x'){
            printf("%d\n", extract());
        }else{
            scanf("%d",&key);
            insert(key);
        }
    }
    return 0;
}



Measured memory_bytes: 6588
s = list(input())
ans = 0
l = 0
r = len(s)-1
while l < r:
    if s[l] != s[r]:
        if s[l] == "x":
            ans += 1
            r += 1
        elif s[r] == "x":
            ans += 1
            l -= 1
        else:
            print(-1)
            exit()
    l += 1
    r -= 1
print(ans)

Measured memory_bytes: 9744
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;

class Program
{
   

    static void Main(string[] args)
    {
        string n = crS();
        int sum = 0;
        for (int i = 0; i < n.Length; i++)
        {
            sum += int.Parse(n.Substring(i, 1));
        }
        if (sum % 9 == 0) Console.WriteLine("Yes");
        else Console.WriteLine("No");
        
    }

   
   

    //入力受け取り用
    static string crS() { return Console.ReadLine(); }
    static int crI() { return int.Parse(Console.ReadLine()); }
    static int[] arrInt(){return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();}
    static long[] arrLong(){ return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); }
    static string[] arrStr(){return Console.ReadLine().Split(' ').ToArray();}
    static List<int[]> mapInt(int h)
    {
        List<int[]> mapInt = new List<int[]>();
        for (int i = 0; i < h; i++)
        {
            mapInt.Add(arrInt());
        }
        return mapInt;
    }

    static List<string[]> mapStr(int h)
    {
        List<string[]> mapStr = new List<string[]>();
        for (int i = 0; i < h; i++)
        {
            mapStr.Add(arrStr());
        }
        return mapStr;
    }

    static List<char[]> mapChar(int h)
    {
        List<char[]> mapChar = new List<char[]>();
        for (int i = 0; i < h; i++)
        {
            string s = crS();
            mapChar.Add(s.ToCharArray());
        }
        return mapChar;
    }

    static List<char[]> mapCharCopy(List<char[]> map)
    {
        List<char[]> copyMap = new List<char[]>();
        foreach (var arr in map)
        {
            List<char> list = new List<char>();
            foreach (var ele in arr)
            {
                list.Add(ele);
            }
            copyMap.Add(list.ToArray());
        }
        return copyMap;
    }
}

Measured memory_bytes: 32652
#include <stdio.h>
int main(){

  int n,x,r,i,j,k;

  while(1){

    scanf("%d %d",&n,&x);
	  
    if (n != 0 || x != 0){

      r=0;
      
      for(i = 0; i < n; i++){
	
	for(j = 0; j < i; j++){
	  
	  for(k = 0; k < j; k++){
	    
	    if (i+j+k+3 == x){
	      
	      r++;
	      
	    }
	    
	  }
	  
	}
	
      }
      
      printf("%d\n",r);
      
    } else {
      
      break;

    }
    
  }

  return 0;

}

Measured memory_bytes: 600
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

a, b = nl()

if (a + b) % 2 == 1:
    print((a+ b) // 2 + 1)
else:
    print((a+b)//2)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;;
const int N=100010;
int a[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') ch=getchar(),o=-1;
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi();
    bool flg=0;
    ll l=1,r=1LL<<60,L;
    while(l<=r) {
	ll mid=(l+r)>>1,x=mid;
	for(int i=1;i<=n;i++) x-=x%a[i];
	if(x==2) flg=1;
	if(x<2) l=mid+1;
	else r=mid-1;
    }
    L=l;
    if(!flg) return puts("-1"),0;
    l=1,r=1LL<<60;
    while(l<=r) {
	ll mid=(l+r)>>1,x=mid;
	for(int i=1;i<=n;i++) x-=x%a[i];
	if(x<=2) l=mid+1;
	else r=mid-1;
    }
    cout<<L<<' '<<r;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(int argc, char const *argv[])
{
  int n; cin >> n;
  vector<double> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(),v.end());
  rep(i,n-1) {
    v[i+1] = (v[i]+v[i+1])*0.5;
  }
  cout << v[n-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N,T;
	cin >> N >> T;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	int minium = INF;
	int maxium = 0;
	for(int i = 1;i < N;i++) {
		minium = min(minium,vec.at(i - 1));
		maxium = max(maxium,vec.at(i) - minium);
	}
	minium = INF;
	int ret = 0;
	for(int i = 1;i < N;i++) {
		minium = min(minium,vec.at(i - 1));
		if(vec.at(i) - minium == maxium) {
			ret++;
		}
	}
	cout << ret << endl;
}

Measured memory_bytes: 1024
def intminus(a):
    return int(a) - 1


N = int(input())
A = list(map(intminus, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


ans = B[A[0]]
pre = A[0]
for i in range(1, N):
    ans += B[A[i]]
    if A[i] == pre + 1:
        ans += C[pre]
    pre = A[i]

print(ans)


Measured memory_bytes: 3064
# Your code here!
n = gets.to_i
a = []

n.times do 
  a << gets.chomp.chars.sort.join("")
end

count = Hash.new(0)
a.each do |elem|
  count[elem] += 1
end

def factorial(n)
  return 1 if n == 0
  (1..n).inject(:*)
end

def permutation(n, r)
  return 1 if n == 0
  s = n - r + 1
  (s..n).inject(:*)
end

def combination(n, r)
  r = [r, n - r].min
  return n if r == 1
  return 1 if r == 0
  permutation(n, r) / factorial(r)
end
cnt = 0
count.values.each do |i|
    if i >= 2
        cnt += combination(i, 2)
    end
end

p cnt

Measured memory_bytes: 32764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


void solve() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  string s;
  cin >> s;

  int cnt = 0;
  // 最初の幸福度
  rep(i, sz(s)) {
    if (s[i] == 'L' && i - 1 >= 0 && s[i - 1] == 'L') cnt++;
    if (s[i] == 'R' && i + 1 < n && s[i + 1] == 'R') cnt++;
  }
  // cout << cnt << endl;

  // 1 回の操作で 2 人までしか増やせない
  int ans = cnt;
  cnt = 0;
  rep(i, sz(s) - 1) {
    if (s[i] != s[i + 1]) cnt++;
  }
  // cout << cnt << endl;
  ans += min(k * 2, cnt);
  cout << ans << endl;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
MAX_N = 2 * 10**5 + 10

fac = [1] + [0] * MAX_N
for i in range(1, MAX_N+1):
    fac[i] = fac[i-1] * (i) % MOD

fac_inv = [1] + [0] * MAX_N
fac_inv[MAX_N] = pow(fac[MAX_N], MOD-2, MOD)
for i in range(MAX_N, 1, -1):
    fac_inv[i-1] = fac_inv[i] * i % MOD

def mod_nCr(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD

n, k = [int(item) for item in input().split()]
ans = 0
for zero_num in range(min(n, k+1)):
    ans += mod_nCr(n-1, zero_num) * mod_nCr(n, zero_num)
    ans %= MOD

print(ans)

Measured memory_bytes: 43988
import fractions
A,B = map(int,input().split())
gcd = fractions.gcd(A,B)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
prime_num = prime_factorize(gcd)
print(len(set(prime_num))+1)

Measured memory_bytes: 5048
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# greedy

N,C,K,*T = map(int,read().split())

T.sort()

bus_t = -K - 100
bus_c = C
answer = 0
for t in T:
    bl = (bus_t + K >= t) and (bus_c + 1 <= C)
    if bl:
        bus_c += 1
        continue
    answer += 1
    bus_t = t
    bus_c = 1

print(answer)

Measured memory_bytes: 12508
#pragma GCC optimize("Ofast")

// #define _GLIBCXX_DEBUG

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

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
// #define NP next_permutation;
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
// typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
// using vvvi=vector<vvi>;
/*
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
*/
template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
// template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
/*
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){ll c; while(b!=0){c=a%b; a=b; b=c;} return a;}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a * c%mod;} a=a * a%mod; b>>=1;} return c;}
vi calc(ll x){vi res; while(x>0){res.eb(x%10); x/=10;} reverse(all(res)); return res;}
*/
void solve() {
  string S,T,data; cin>>S>>T;
  ll a,b; cin>>a>>b;
  cin>>data;
  if(data==S) a--;
  else b--;
  cout<<a<<" "<<b<<endl;
}

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


Measured memory_bytes: 256
def build_stairs(n,a):
    if n == 1:
        return "Yes"

    k = n - 1
    for i in range(k,1,-1):
        if a[i-1] > a[i]:
            a[i-1] = a[i-1] - 1

    flag = False
    for i in range(1,k):
        if a[i-1] > a[i]:
            flag = False
            break
        else:
            flag = True

    if flag == True:
        return "Yes"
    if flag == False:
        return "No"

if __name__ == '__main__':
    n = int(input())
    a = list(map(int,input().split()))

    print("%s" %(build_stairs(n,a)))

Measured memory_bytes: 14396
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b){ if (a<b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if (b<a){ a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int W, H, x, y;
  cin >> W >> H >> x >> y;

  double ans1 = double(W) * double(H) / 2;
  int ans2 = (x+x == W && y+y == H) ? 1 : 0;
  cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    string s;
    while (getline(cin, s)) {
        istringstream sin(s);
        vector<double> v;
        string w;
        while (sin >> w) {
            if (w.size() > 1 || isdigit(w[0])) v.push_back(atof(w.c_str()));
            else {
                const double a = v[v.size()-2];
                const double b = v[v.size()-1];
                v.pop_back();
                v.pop_back();
                if (w[0] == '+') v.push_back(a+b);
                if (w[0] == '-') v.push_back(a-b);
                if (w[0] == '*') v.push_back(a*b);
                if (w[0] == '/') v.push_back(a/b);
            }
        }
        printf("%.6f\n", v[0]);
    }
    return 0;
}

Measured memory_bytes: 0
# coding:utf-8
import sys
def main():
    N = int(input())
    lists = list(map(float, input().split()))
    lists.sort()

    for i in range(N-1):
        new_guzai = (lists[0] + lists[1]) / 2.0

        for _ in range(2):
            lists.pop(0)

        lists.append(float(new_guzai))
        lists.sort()
        if len(lists) ==1:
            print(lists[0])
            sys.exit()


if __name__ == '__main__' :
    main() 

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main () {
  int K, T;
  cin >> K >> T;
  int ma = 0;
  for (int i = 0; i < T; i ++) {
    int a;
    cin >> a;
    ma = max(ma, a);
  }
  int kj = K - ma;
  cout << max(ma - kj - 1, 0) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    int temp;
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<n-i-1;j++)
        {
            if(a[j]>a[j+1])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
    int sum=0;
    for(int i=0;i<k;i++)
    {
        sum+=a[i];
    }
    printf("%d",sum);
}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
int we[110], v[110];
long long dp[100010];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, w;
    cin >> n >> w;
    for (int i = 1; i <= n; ++i) {
        cin >> we[i] >> v[i];
        for (int j = w; j >= 1; --j) {
            if (j - we[i] >= 0) {
                dp[j] = max(dp[j], dp[j - we[i]] + v[i]);
            }
        }
    }
    cout << *max_element(dp + 1, dp + 1 + w);
}

Measured memory_bytes: 4404
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <stdio.h>
#include <sstream>
#include <algorithm>

using namespace std;
//

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

	int data[200000] = { 0 };
	for (int i = 0; i < numOfDice; ++i)
	{
		cin >> data[i];
	}

	int maxv = -2000000001;
	int minv = data[0];
	for (int i = 1; i < numOfDice; ++i)
	{
		maxv = max(maxv, data[i] - minv);
		minv = min(minv, data[i]);
	}

	cout << maxv << endl;

	return 0;
}





Measured memory_bytes: 3904
import sys #追加
sys.setrecursionlimit(500*500) #再起上限回数突破

class Node:
    def __init__(self, data):
        self.data = data
        self.f_search = False
        
    def __repr__(self):
        return str(self.data) + "," + str(self.f_search)
        

data_set = list()

while(1):
    w, h = map(int, input().split() )
    if w == 0 and h == 0:
        break

    aa = list()
    for _ in range(h):
        a = list()
        for d in map(int, input().split() ):
            a.append(Node(d))
        aa.append(a)

    data_set.append(aa)


search_vec = [(1,0), (-1,0), (0,1), (0,-1), (1,1), (-1,1), (1,-1), (-1,-1)]

iland_cnt = 0
def search_iland(iland_data):
    global iland_cnt
    for y in range(len(iland_data)):
        for x in range(len(iland_data[0])):
            if iland_data[y][x].f_search == True \
            or iland_data[y][x].data == 0:
                continue
            iland_cnt += 1
            iland_data[y][x].f_search = True
            for (dx,dy) in search_vec:
                if x+dx < 0 or y+dy < 0 \
                or x+dx >= len(iland_data[0]) \
                or y+dy >= len(iland_data): continue
                search_iland_area(iland_data, x+dx, y+dy)
            
            

def search_iland_area(iland_data, sx, sy):  
    if iland_data[sy][sx].f_search == True \
    or iland_data[sy][sx].data == 0:
        return 
    iland_data[sy][sx].f_search = True
    for (dx,dy) in search_vec:
        if sx+dx < 0 or sy+dy < 0 \
        or sx+dx >= len(iland_data[0]) \
        or sy+dy >= len(iland_data): continue
        search_iland_area(iland_data, sx+dx, sy+dy)
            
for iland in data_set:
    iland_cnt = 0
    search_iland(iland)
    print(iland_cnt)



Measured memory_bytes: 11272
#include <stdio.h>
#include <string.h>

int main(){

	long long int  i,j;
	long long N;
	long long sum=0;
	scanf("%lld",&N);

	for(i=1;i<=N;i++){
		if(i%3==0||i%5==0){
		}
		else {
			
			sum += i;
		}
	}
	
	printf("%lld\n",sum);
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


int main(){
    int n;
    cin>>n;
    vector<int>x(n);
    rep(i,n)cin>>x[i];
    ll mini = INF;

    repi(i,1,101){
        ll cmp = 0;
        rep(j,n){
            cmp += pow(x[j]-i,2);
        }
        mini = min(mini,cmp);
    }
    cout<<mini<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    map<ll, ll> a, b;
    for (ll i = 0; i < n / 2; i++)
    {
        ll p, q;
        cin >> p >> q;
        a[p]++;
        b[q]++;
    }
    priority_queue<pair<ll, ll> > p, q;
    for (auto i : a)
    {
        p.push(make_pair(i.second, i.first));
    }
    for (auto i : b)
    {
        q.push(make_pair(i.second, i.first));
    }

    if (p.top().second != q.top().second)
    {
        cout << n - p.top().first - q.top().first << endl;
    }
    else
    {
        ll c, d;
        auto temp = p.top();
        p.pop();

        c = n - (p.empty() ? 0 : p.top().first) - q.top().first;
        q.pop();
        d = n - temp.first - (q.empty() ? 0 : q.top().first);
        cout << min(c, d) << endl;
    }
}

Measured memory_bytes: 8824
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){a%=mod;b%=mod;return a*b%mod;}
inline int power(int a,int b,int MOD){a%=mod;int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     SPEED;
     int n;
     cin>>n;
     if(n&1)
     {
         cout<<0<<endl;
         return 0;
     }
     n/=2;
     int res=0;
     while(n>0)
     {
          res+=n/5;
          n/=5;
     }
     cout<<res<<endl;
     time();
     return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    long long sum = 0;
    for(int i=1;i<=n;i++){
        if(i%3==0||i%5==0){
            continue;
        }
        sum +=i;
    }
    printf("%lld",sum);
}


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

using namespace std;

#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";
#define FIO ios_base::sync_with_stdio(false);cout.setf(ios::fixed);cout.precision(10);cout.tie(nullptr);cin.tie(nullptr);

int dx[] = { 0,0,1,-1,-1,-1,1,1 };
int dy[] = { 1,-1,0,0,-1,1,1,-1 };

template < class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template < class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template < class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }
template < class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); }return a; }

template <class T> inline T bigmod(T p, T e, T m) {
	T ret = 1;
	for (; e > 0; e >>= 1) {
		if (e & 1) ret = (ret * p) % m; p = (p * p) % m;
	} return (T)ret;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif

void solve()
{
	int n;
	cin>>n;

	long long sum=0;
    map<long long,long long> mp;

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

	int q;
	cin>>q;

	while(q--){

		long long u,v;
		cin>>u>>v;

		if(mp.count(u)){

			long long cnt=mp[u];
			long long par=(v-u)*cnt;
			sum+=par;
			mp.erase(u);
			mp[v]+=cnt;
		}
		cout<<sum<<nl;
	}
}

int main()
{
	FIO;

	int t = 1;

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

	return 0;
}


Measured memory_bytes: 7568
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))
if __name__ == "__main__":
    n = list(input())
    if n[-1] == "3":print("bon")
    elif n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8":
        print("pon")
    else:print("hon")

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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n,x;
    cin >> n >> x;
    if(n==0) return 0;
    int c=0;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        for(int k=j+1;k<=n;k++){
          if(i+j+k==x){
            c++;
          }
        }
      }
    }
    cout << c << endl;
  }
  return 0;
}



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

vector<int> inv(vector<int> a) {
  int n = (int) a.size();
  vector<int> ret(n);
  for (int i = 0; i < n; i++) {
    ret[a[i]] = i;
  }
  return ret;
}

vector<int> mul(vector<int> a, vector<int> b) {
  int n = (int) a.size();
  vector<int> ret(n);
  for (int i = 0; i < n; i++) {
    ret[i] = a[b[i]];
  }
  return ret;
}

vector<int> power(vector<int> a, int b) {
  int n = (int) a.size();
  vector<int> ret(n);
  iota(ret.begin(), ret.end(), 0);
  while (b) {
    if (b & 1) {
      ret = mul(ret, a);
    }
    b >>= 1;
    a = mul(a, a);
  }
  return ret;
}

void output(vector<int> a) {
  for (int i = 0; i < (int) a.size(); i++) {
    if (i) {
      cout << " ";
    }
    cout << a[i] + 1;
  }
  cout << '\n';
  
  exit(0);
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    b[i]--;
  }
  if (k == 1) {
    output(a);
  }
  vector<int> A = inv(a);
  vector<int> B = inv(b);
  vector<int> bABa = mul(b, mul(A, mul(B, a)));
  vector<int> AbaB = mul(A, mul(b, mul(a, B)));

  vector<int> l[6];
  l[0] = b;
  l[1] = mul(b, A);
  l[2] = mul(b, mul(A, B));
  l[3] = mul(bABa, B);
  l[4] = mul(bABa, mul(a, B));
  l[5] = mul(bABa, mul(b, mul(a, B)));

  vector<int> f = power(AbaB, (k - 2) / 6);
  f = mul(l[(k - 2) % 6], f);
  f = mul(power(bABa, (k - 2) / 6), f);
  output(f);
  return 0;
}


Measured memory_bytes: 8184
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <bitset>
#define INF 0x3f3f3f3f
#define maxn 105000
#define maxnn 6000
#define juzheng 300
#define line cout << "-------------------------" << endl;
#define PI acos(-1.0)
#define mem(a,b) memset(a,b,sizeof(a))
#define fill_(a,b,n) fill(a,a + n,b)
#define esp 1e-9
#define	pr_line(arr,s,e) for(ll abc = s;abc < e;abc++){ if(abc != s) printf(" ");cout << arr[abc];}puts("");
 
#define ri(n) scanf("%d",&n)
#define ri2(a,b) scanf("%d %d",&a,&b)
#define ri3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define rd(n) scanf("%lf",&n)
#define rd2(a,b) scanf("%lf %lf",&a,&b)
#define rd3(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define rl(n) scanf("%lld",&n)
#define rl2(a,b) scanf("%lld %lld",&a,&b)
#define rl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define rui(n) scanf("%u",&n)
#define rui2(a,b) scanf("%u %u",&a,&b)
#define rui3(a,b,c) scanf("%u %u %u",&a,&b,&c)
#define rs(str) scanf("%s",str)
#define pr(n) cout << n << endl
#define debug(str,x) cout << str << ":" << x << endl
#define ll long long
#define int64 __int64
#define ui unsigned int

using namespace std;

const ll mod = 1e9 + 7;

//Date:2018-9-29 
//Author：HarryBlackCat

string str;
 
int main() {
	//cin.sync_with_stdio(false);//降低cin，cout时间
	while(cin >> str){
		for(int i = 0;i < str.size();i++){
			if(str[i] == '1')
				printf("9");
			else
				printf("1");
		}
		
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main(){
	
	int m,n;
	string s;
	int si;
	bool f;
	int player[1001];
	int np;
	int nc;

	while(1){

		cin>>m>>n;
		if(m==0&&n==0) break;

		for(int i=1;i<m;i++){
			player[i]=i+1;
		}
		player[m]=1;
		np=1;
		nc=m;

		for(int i=1;i<=n;i++){
			cin>>s;
			if(nc!=1){
				f=true;
				if(s=="Fizz"){
					if(i%3!=0){
						f=false;
					}
				}
				else if(s=="Buzz"){
					if(i%5!=0){
						f=false;
					}
				}
				else if(s=="FizzBuzz"){
					if(i%15!=0){
						f=false;
					}
				}
				else{
					si=0;
					for(int j=0;j<s.size();j++){
						if(s[s.size()-1-j]<'0'&&s[s.size()-1-j]>'9'||si>i){
							f=false;
							break;
						}
						si+=(s[s.size()-1-j]-'0')*pow(10,j);
					}
					if(i!=si||si%3==0||si%5==0) f=false;
				}
				if(!f){
					for(int j=1;j<=m;j++){
						if(player[j]==np){
							player[j]=player[np];
							player[np]=-1;
							np=player[j];
							break;
						}
					}
					nc--;
				}
				else np=player[np];
			}
		}

		for(int i=1;i<=m;i++){
			if(player[i]!=-1){
				cout<<i;
				nc--;
				if(nc!=0) cout<<" ";
				else cout<<endl;
			}
		}
	}

}

Measured memory_bytes: 1260
#include <stdio.h>

  main(){
    int N,X,i,c=1,D=0;  //一回目を無視する
    
    scanf("%d %d",&N,&X);
    int L[N];
    for(i=0;i<N;i++){
      scanf("%d",&L[i]);
      D=D+L[i];
      if(D>X)
        break;
      c++;
    }
    printf("%d",c);
}  

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vector<string> x, y;
    x = a;
    y = a;
    for (int i = 0; i < n; ++i)
    {
        if (i % 2 == 0)
            for (int j = 0; j < m - 1; ++j)
                x[i][j] = '#';
        else
            x[i][0] = '#';
    }
    for (int i = 0; i < n; ++i)
    {
        if (i % 2 == 1)
            for (int j = 1; j < m; ++j)
                y[i][j] = '#';
        else
            y[i][m - 1] = '#';
    }
    for (int i = 0; i < n; ++i)
        cout << x[i] << endl;
    for (int i = 0; i < n; ++i)
        cout << y[i] << endl;
    return 0;
}


Measured memory_bytes: 1536