akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int A1 = 0;
		int B1 = 0;
		int sum = 0;
		sc.close();
	if(A > B) {
		A1 = A - 1 ;
		if (A1 > B) {
			sum = A + A1;
		}
		else {
			sum = A + B;
		}
	}
	
	else if(A < B) {
		B1 = B - 1;
		if(B1 >A) {
			sum = B + B1;
		}
		else {
			sum = A + B;
		}
	}
	else {
		sum = A+B;
	}
		System.out.print(sum);
	}
}

Measured memory_bytes: 23764
#include<iostream>
using namespace std;
int main(void){
  int c(0);
  for(int i(0);i<4;i++){
    char s;
    cin>>s;
    if(s=='+'){
      c++;
    }else{
      c--;
    }
  }
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;
int N;
int A[25], C[25];

int main(void) {
    scanf("%d", &N);
    REP(i, 0, N) scanf("%d", &A[i]);
    REP(i, 0, N) {
    	int B;
    	scanf("%d", &B);
    	ans += B;
    }
    REP(i, 0, N-1) scanf("%d", &C[i]);

    REP(i, 0, N-1) {
    	if (A[i]+1 == A[i+1]) ans += C[A[i]-1];
    }
   

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

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;


using namespace std;


const int MAX = 1000000;

int list[MAX];

int main()
{
  
  for(int i=2;i<MAX;i++){
    list[i]=0;
  }

  //1が素数-1は除外された数;
  for(int i=2;i<MAX;i++){

    if(list[i]!=-1) list[i]=1;{

      for(int k=2;k<MAX;k++){
        if(i*k>=MAX) break;
        list[i*k]=-1; 
      }
    }
  //  cout << i << "=" << list[i] << endl << endl;

  }
 

  while(true){
    int a,d,n;

    cin >> a >> d >> n;

    if(a==0&&d==0&&n==0) break;

    int count=0;
    for(int i=0;(a+d*i)<MAX;i++){
      

      if(list[a+d*i]==1) count++;

      if(count==n){
        cout << a+d*i << endl;
        break;
      }

    }
  }
  return 0;
}

Measured memory_bytes: 5060
t,x,y,f=0,0,0,1
for i in [0]*int(input()):
    a,b,c=map(int,input().split())
    d=abs(x-b)+abs(y-c)
    e=abs(t-a)
    if e<d or e%2!=d%2:f=0
    else:t,x,y=a,b,c
print(['No','Yes'][f])

Measured memory_bytes: 3828
s = int(input())

a = [s]

for i in range(1000000):
  n = a[-1]
  fn = 0
  
  if n % 2 == 0:
    fn = n / 2
  else:
    fn = 3*n + 1
  
  if fn in a:
    print(i+2)
    break
  else:
    a.append(fn)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
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[0].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;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}

template<typename T>
T gcd(T x, T y){
    if (x == 0 || y == 0) {
        return 0;
    }

    while (x != y){
        if (x > y) {
            x -= y;
        }else{
            y -= x;
        }
    }
    return x;
}

// }}}
/* vim:set foldmethod=marker: */

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

    for (int i = 0; i < 30; i++) {
        for (int j = 0; j < 20; j++) {
            if (4 * i + 7 * j == n) {
                cout << "Yes" << endl;
                return;
            }
        }
    }

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

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


// map の key, value を全て抜き出す。
// for (auto itr = mp.begin(); itr != mp.end(); itr++) {
//     cout << "key" << itr->first << " value" << itr->second << endl;
// }

// 文字列の検索
// string s="abc";
// if (s.find('d') == string::npos){
//     cout << "find" << endl;
// }else{
//     cout << "not find" << endl;
// }


Measured memory_bytes: 256
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

//vector//
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

typedef pair<int,int> P;  //q(p.first,p.second)

int solve(int n, int i, int m,vector<int> &a){
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(n,i+1,m,a)||solve(n,i+1,m-a[i],a);
    return res;
}

int main (){
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }
    int q;
    cin >> q;
    vector<int> m(q);
    REP(i,q){
        cin >> m[i];
    }

    REP(i,q){
        if(solve(n,0,m[i],a) == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}


Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 2010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    PRINT(a*b/gcd(a,b));
}


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

int main(void){
    int a,b;
    std::cin >> a >> b;
    int average = std::ceil(double(a+b)/2.0);

    std::cout << average;
    return 0;
}



Measured memory_bytes: 888
/*
██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗
██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗
█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║
██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║
██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝
╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝
Believe in yourself ,( try and try and then try ), You can do it  
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define clr(arr, x) memset(arr, x, sizeof arr)
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define OO 0x3f3f3f3f3f3f3f3fLL
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
ll gcd(ll a, ll b) {
	return b == 0 ? abs(a) : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
int n, w;
vector<pair<ll,ll>>arr;
ll dp[101][100005];
ll sol(int idx,int cap){
	if (idx == n)
		return 0;
	ll &ret = dp[idx][cap];
	if (~ret)
		return ret;
	ll ch1 = sol(idx + 1, cap), ch2 = 0;
	if (cap - arr[idx].first >= 0){
		ch2 = sol(idx + 1, cap - arr[idx].first) + arr[idx].second;
	}
	return ret=max(ch1, ch2);
}
int main(){
	K_K();
	cin >> n >> w;
	arr.resize(n);
	clr(dp, -1);
	for (int i = 0; i < n; i++)
		cin >> arr[i].first >> arr[i].second;
	cout << sol(0, w);
}

Measured memory_bytes: 79232
#include<iostream>

using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int s[]={0,1,3,1,2,1,2,1,1,2,1,2,1};
  if(s[a]==s[b])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main(){
  int n;
  scanf("%d",&n);
  int coutOUT=0, coutHIT=0, point = 0;;
  char event[10];
  while(n){
    while(coutOUT<3){
      scanf("%s", event);
      if(strcmp(event, "HIT") == 0){
        coutHIT += 1;
        if(coutHIT==4){
          point += 1;
          coutHIT = 3;
        }
      }
      if(strcmp(event, "OUT") == 0){
        coutOUT += 1;
      }
      if(strcmp(event, "HOMERUN") == 0){
        point += coutHIT + 1;
        coutHIT = 0;
      }
    }
    printf("%d\n", point);
    coutHIT = 0;
    coutOUT = 0;
    point = 0;
    n -= 1;
  }
  return 0;
}

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

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

int main(void)
{
    string s; cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 100000
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
set<int> st;
signed main(){
	int s;
	cin>>s;
	st.insert(s);
	rep(i,10000000){
		if(s%2){
			if(st.find(3*s+1)!=st.end()){
				cout<<i+2<<endl;
				return 0;
			}
			st.insert(3*s+1);
			s=3*s+1;
		}
		else{
			if(st.find(s/2)!=st.end()){
				cout<<i+2<<endl;
				return 0;
			}
			st.insert(s/2);
			s/=2;
		}
	}
	return 0;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s;
    cin >> s;

    map<char, bool> a;
    REP(i, 26) a['a' + i] = false;
    int n = s.size();
    REP(i, n) a[s[i]] = true;

    int cnt = 0;
    for (auto i : a)
        if (i.second == true) cnt++;

    string ans;
    if (cnt != 26) {
        char c;
        for (auto i : a)
            if (i.second == false) { c = i.first; break ; }
        ans = s + c;
    } else if (cnt == 26) {
        int index = n - 1;
        for (int i = n - 1; i > 0; i--) {
            if (s[i - 1] - s[i] > 0) index = i - 1;
            else break ;
        }
        if (index == 0) ans = "-1";
        else {
            string tmp = s.substr(index);
            sort(tmp.begin(), tmp.end());
            char c;
            REP(i, tmp.size())
                if (tmp[i] > s[index - 1]) { c = tmp[i]; break ; }
            s.erase(index - 1);
            ans = s + c;
        }
    }

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


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


class Program
{


    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        int n = sc.intarr[0];
        string s = sc.str;
        int[] ruiE = new int[n+1];
        int[] ruiW = new int[n+1];
        ruiE[0] = 0;
        ruiW[0] = 0;

        int ans = 1000000;

        for(int i = 1; i <= n; ++i)
        {
            ruiE[i] = ruiE[i - 1];
            ruiW[i] = ruiW[i - 1];

            if (s[i-1] == 'E') ruiE[i]++;
            else ruiW[i]++;
        }

        for (int i = 0; i < n; ++i)
        {
            int sum = ruiW[i] + ruiE[n] - ruiE[i+1];
            ans = Math.Min(ans, sum);
        }
        wr.wri(ans);
    }


}
    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


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

long long pw[20], ret, f[100069];
long long mod = 1e9+7;
long long pwr(long long x, long long y){
    pw[0]=x;
    for(int i=1; i<20; i++){
        pw[i]=(pw[i-1]*pw[i-1])%mod;
    }
    x=0;
    ret = 1;
    while(y>0){
        if(y%2==1){
            ret = (ret*pw[x])%mod;
        }
        x++;
        y = y/2;
    }
    return ret;
}

int main(){
    long long n, k;
    cin >> n >> k;
    f[k] = 1;
    for(int i=k-1; i>0; i--){
        f[i] = pwr((k/i), n);
        for(int j=2; j*i<=k; j++){
            f[i] = (f[i]+mod-f[j*i])%mod;
        }
    }
    long long ans=0;
    for(int i=1; i<=k; i++){
        ans = (ans + i*f[i])%mod;
    }
    cout << ans << endl;
}


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

#define endl '\n'

#define PI 2 * acos(0.0);
#define INFLL 1e18
#define CLEAR(v, val) memset(v, val, sizeof(v))
#define print(x) cout << x << endl, exit(0)
#define watch(x) cerr << #x << " -> " << x << endl
// #define int long long

typedef long long ll;
typedef long double ld;

typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007; // 998244353

signed main() {  
   ios::sync_with_stdio(false);
   cin.tie(nullptr);
   char c;
   cin >> c;
   cout << (char)(c+1) << endl;
   return 0;
}

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

using namespace std;

int main()
{
    int N;
    double a;

    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];

    a = 0.0;
    for(int i=0; i<N; ++i) a += 1.0 / A[i];
    a = 1.0 / a;

    cout << setprecision(16) << a << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
# SimpleQueue でOKなのだが AOJ の環境では Python3.7 が使えない
from queue import Queue


class BFS():
    INFTY = sys.maxsize

    def __init__(self, M, n, debug=False):
        self.M = M
        self.n = n
        # 距離で訪問状態(color)を管理する
        self.d = [self.INFTY] * n
        self.debug = debug

    def bfs(self, s):
        q = Queue()
        q.put(s)
        self.d[s] = 0
        self.debug_print(q)

        while not q.empty():
            u = q.get()
            for v in range(self.n):
                if self.M[u][v] == 0:
                    continue
                if self.d[v] != self.INFTY:
                    continue
                self.d[v] = self.d[u] + 1
                q.put(v)
                self.debug_print(q)

        for i in range(self.n):
            if self.d[i] == self.INFTY:
                d = -1
            else:
                d = self.d[i]
            print(f'{i+1} {d}')

    def debug_print(self, q):
        if not self.debug:
            return
        print('d: ', self.d)
        print('q: ', q.queue)
        print('-------------------------')


def main():
    n = int(input())
    M = [[0] * n for _ in range(n)]

    for i in range(n):
        line = input()
        inputs = [int(x) for x in line.split(' ')]
        u = inputs.pop(0)
        u -= 1                  # 0 オリジンへ変換
        _ = inputs.pop(0)       # k （使わない...）
        for v in inputs:
            v -= 1              # 0 オリジンへ変換
            M[u][v] = 1

    BFS(M, n).bfs(0)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7084
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
	int n;
	scanf("%i",&n);
	int a[n+1],b[n+1];
	for(int i=1;i<=n;i++)
	{
		scanf("%i",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	//int l=1,r=n,mid=l+(r-l)/2,fi=0;
	for(int i=1;i<=n;i++)
	{
		/*while(l<r)
		{
			if(b[mid]<a[i])
			{
				l=mid;
			}
			else if(b[mid]>a[i])
			{
				r=mid;
			}
			else
			{
				fi=a[i];
				break;
			}
			mid=l+(r-l)/2
		}*/
		if(a[i]<=b[n/2])	printf("%i\n",b[n/2+1]);
		else	printf("%i\n",b[n/2]);
	}
	return 0;
}


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


int main(){
    
    string s;
    int n;
    cin >>n;
    cin >> s;
    vector<int> v(s.size());
    rep(i,s.size()){
        v[i] = s[i]-'a';
    }
    int ans = 0;
    for(int i=1;i<=s.size()-1;i++){
        vector<int> a,b;
        a = vector<int>(v.begin(),v.begin()+i+1);
        b = vector<int>(v.begin()+i+1,v.end());
        set<int> sa,sb;
        for(auto v:a) sa.insert(v);
        for(auto v:b) sb.insert(v);

        vector<int> p;
        for(auto v:sa) p.push_back(v);
        for(auto v:sb) p.push_back(v);
        sort(p.begin(),p.end());
        int temp = 0;
        for(int i=0;i<p.size()-1;i++){
            if(p[i]==p[i+1]) temp++;
        }
        ans = max(ans,temp);
    }

    cout << ans << endl;


}

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

using namespace std;

int calc (char x, string s) {
   bool ok = 0;        
   for (int i = 1;i < s.size ();i ++) {
   	if (s[i] != s[i - 1]) ok = 1;
   }
   if (!ok) return 0;
	string t = "";
	for (int i = 0;i < s.size () - 1;i ++) {
		if (s[i] == x || s[i + 1] == x) t += x;
		else t += s[i];
	}
	return calc (x, t) + 1;	        
}

int main () {
	string s;
	cin >> s;
	int ans = 1e9 + 7;      
	for (char x = 'a';x <= 'z';x ++) {
		ans = min (ans, calc (x, s));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
void co() { cout << endl; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << endl; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18L+1;
constexpr ll MOD = 1e9L+7;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
    ll n, q;
    cin >> n >> q;
    Vec a(n);
    rep(i, n) cin >> a[i];
    fenwick_tree<ll> ft(n);
    rep(i, n) ft.add(i, a[i]);
    while(q--){
        ll t, a, b;
        cin >> t >> a >> b;
        if (t == 0) ft.add(a, b);
        else
            co(ft.sum(a, b));
    }

    return 0;
}


Measured memory_bytes: 12392
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.1415926535


int main()
{
    ll n;
    cin >> n;
    ll a = (n + 1) / 2;
    double ans = (double) a / n;
    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a;
    string str ="No";
    cin >> a;
    if(a==1)str ="Yes";

    for (int i = 2; i < 10; i++)
    {
    if((a%i==0)and(a/i<10)) str = "Yes";
    }
    
    // 出力
    cout << str;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cin, cout の高速化
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)

#define MAX_N 10000000

int main()
{
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2>>y2;

    int a = x2-x1;
    int b = y2-y1;
    int x3 = x2-b;
    int y3 = y2+a;
    int x4 = x3-a;
    int y4 = y3-b;
    cout << x3 << " " << y3 << " " << x4 << " "<< y4 << endl;
}

Measured memory_bytes: 256
from collections import Counter

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
init=sum(A)
A=Counter(A)

for _ in range(Q):
    B,C=map(int,input().split())
    A[C]+=A[B]
    init=init-(B*A[B])+(C*A[B])
    print(init)
    A[B]=0

Measured memory_bytes: 23196
# from math import factorial
# from collections import defaultdict, deque
#  from heapq import heappush, heappop

# A, B = [int(i) for i in input().split(" ")]
# A = int(input())
# As = [int(i) for i in input().split(" ")]
# Ss = ["".join(sorted(input())) for _ in range(N)]

N = int(input())

print((N * (N-1)) // 2)


Measured memory_bytes: 2940
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int correct=0;
		int penality=0;
		int[] a = new int[N+1]; 
		while(M-->0)
		{
			int i = sc.nextInt();
			String j = sc.next();
			if(j.contentEquals("AC")&&a[i]!=-1)
			{
				correct++;
				penality+=a[i];
				a[i]=-1;
			}
			else if(a[i]!=-1) {
				a[i]++;
			}
		}
		
		System.out.println(correct+" "+penality);
	}
}


Measured memory_bytes: 63424
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		if(C >= A && C <= B) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		scan.close();

	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    int n,x,t;
    cin >> n >> x >> t;
    cout << ((n+x-1)/x)*t << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main(){
  int a,i,j=1;
  int ans[100000];
  while(1){
    scanf("%d",&a);
    if(a==0){
      break;
    }
    ans[j]=a;
    j++;
  }
  for(i=1;i<j;i++){
    printf("Case %d: %d\n",i,ans[i]);
  }
  return(0);
}

Measured memory_bytes: 648
while(1):
    n=int(raw_input())
    if n==0:
        break
    else:
        Slist=[]
        Blist=[0 for i in range(1001)]
        ans=[]
        allb=0
        thres=3
        
        for k in range(n):
            S=[int(x) for x in raw_input().split()]
            Slist.append(S)
        Slist.sort(key = lambda x:x[0])
        Slist.sort(key = lambda x:x[3])
        Slist.sort(key = lambda x:x[2],reverse=True)
        
        for i in range(n):
            if allb==10:
                thres=2
            elif allb==20:
                thres=1
            elif allb==26:
                break
            
            bd=Slist[i][1]
            if Blist[bd]<thres:
                ans.append(Slist[i][0])
                Blist[bd]+=1
                allb+=1
        for a in ans:
            print a
            

Measured memory_bytes: 6336
import sys

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

win_choice = {'s':'r', 'p':'s', 'r':'p'}
janken_point = {'r':r, 's':s, 'p':p}

dp = []
# a: 相手の手, x:自分が出せない手
def point(a, x=None):
    if x == win_choice[a]: return 0
    else: return janken_point[win_choice[a]]

score = 0
flag = [('0', 1)] * k
for i in range(n):
    if flag[i % k][0] != t[i]:
        score += point(t[i])
        flag[i % k] = (t[i], -1)
    elif flag[i % k][0] == t[i] and flag[i % k][1] == 1:
        score += point(t[i])
        flag[i % k] = (t[i], -1)
    else:
        flag[i % k] = (t[i], 1)

print(score)


Measured memory_bytes: 9460
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

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

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <queue>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(n);
    REP(i, 0, n) {
        cin >> a[i] >> b[i];
    }

    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int i, int j) {
        if (a[i] != a[j]) return a[i] < a[j];
        return b[i] < b[j];
    });
    ll ans = 0;
    priority_queue<ll> pq;
    int cnt = 0;
    for (int i = m; i >= 0; i--) {
        while (cnt < n && i + a[ord[cnt]] <= m) {
            pq.emplace(b[ord[cnt++]]);
        }
        if (pq.size()) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3320
def main():
    n = int(input())
    ary = [int(i) for i in input().split()]
    ary = sorted(ary)

    if ary[0] == 0:
        print(0)
        return

    prod = 1
    for i in reversed(range(n)):
        prod *= ary[i]
        if prod > 1000000000000000000:
            print(-1)
            return

    print(prod)
main()


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

  
int main(){
 int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  VI count(n);
 rep(i,n){
   rep(j,1000){
   if(a.at(i)%2==0){
     a.at(i)/=2;
     count.at(i)++;
   }
   else break;
   }
 }
  int minn=1000;
  rep(i,n){
    minn=min(minn,count.at(i));
  }
  cout << minn <<endl;
    
       
   
 
}
  

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt(),m = scanner.nextInt();
		int[] studentx = new int[n];
		int[] studenty = new int[n];
		int[] checkx = new int[m];
		int[] checky = new int[m];
		for(int i=0;i<n;i++){
			studentx[i] = scanner.nextInt();
			studenty[i] = scanner.nextInt();
		}
		for(int i=0;i<m;i++){
			checkx[i] = scanner.nextInt();
			checky[i] = scanner.nextInt();
		}
		int[] result = new int[n];
		for(int i=0;i<n;i++){
			int min = Integer.MAX_VALUE;
			int x = 0;
			for(int j=0;j<m;j++){
				int dis = Math.abs(studentx[i] - checkx[j]) + Math.abs(studenty[i] - checky[j]);
				if(dis < min){
					min = dis;
					x = j;
				}
			}
			result[i] = x + 1;
		}
		for(int i=0;i<n;i++){
			System.out.println(result[i]);
		}
	}

}


Measured memory_bytes: 22484
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
#include<queue>
using namespace std;
int n,m,res[100001],cnt=0;
int book[100001],jud=1;
string s;


void dfs(int x){
	if(x==0){
		for(int i=cnt-1;i>=0;i--){
			if(i!=cnt-1) cout<<" ";
			cout<<res[i];
		}
		jud=0;
		return;
	}
	for(int i=m;i>0;i--){
		if(x-i>=0&&s[x-i]=='0'){
			res[cnt++]=i;
			dfs(x-i);
			return;
		}
	}
}	
int main(){
	cin>>n>>m>>s;
	if(s[0]=='1'){
		cout<<"-1";
		return 0;
	}
	dfs(n);
    if(jud) cout<<"-1";
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Arrays;
// Solution Starts here
public class Main{
    public static void main(String[] args) {
        FastScanner in = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int a[]=in.readArray(5);
        int c=0;
        for(int i=0;i<5;i++)
            if(a[i]==0)
                c=i;
                
        out.println(c+1);
        out.close();
    }
    // solution ends here
    static class FastScanner{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer sr = new StringTokenizer("");
        String next(){
            while(!sr.hasMoreTokens()){
                try{
                    sr=new StringTokenizer(br.readLine());
                }catch(IOException e){
                    e.printStackTrace();
                }
            }
            return sr.nextToken();
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
        int[] readArray(int n){
            int a[]=new int[n];
            for(int i=0;i<n;i++)
                a[i]=nextInt();
            return a;
        }
        long nextLong(){
            return Long.parseLong(next());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }
    }

}

Measured memory_bytes: 32900
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>

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

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


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

    int i = 0, j = n-1;
    int cnt = 0;
    while(i<j){
        if(s[i] == 'W' && s[j] == 'R'){
            s[i] = 'R'; s[j] = 'W';
            i++; j--;
            cnt++;
        }else if(s[i] == 'W' && s[j] == 'W') j--;
        else if(s[i] == 'R' && s[j] == 'R') i++;
        else {
            i++; j--;
        }
    }

    cout << cnt << endl;
}

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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 10){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int N = input();

  cout << N - input() + 1 << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}


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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

int main()
{
    canhazfast();

    ll a, b, c, d, e, ans;

    cin >> a >> b >> c >> d;
    --a;
    ans = b-a;
    ans -= b/c-a/c;
    ans -= b/d-a/d;\
    e = c/gcd(c, d)*d;
    ans += b/e-a/e;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, T;
  cin >> N >> T;
  long long res = 0LL;
  long long t = 0LL;
  for(int i = 0; i < N; i++){
    long long a;
    cin >> a;
    if(a <= t+T) res += a-t;
    else res += T;
    t = a;
  }
  res += T;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int day[n];
    for (int i=0;i<n;i++){
        cin >> day[i];
    }
    for(int j=n-1;j>-1;j--){
        if(j!=n-1){
            cout<<" "<<day[j];
        }else{
            cout << day[j];
        }
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 3088
import math

nk = list(map(int, list(input().split())))

n = nk[0]
k = nk[1]

countSplit = 1
countPut = n - k + 1

for i in range(k):
    if i == 0:
        print(n - k + 1)
    elif i <= n - k:

        countSplit = math.factorial(k - 1) // math.factorial(k - 1 - i) // math.factorial(i)
        countPut = math.factorial(n - k + 1) // math.factorial(n - k - i) // math.factorial(i + 1)
        """
        countSplit = int(countSplit * (k - i) / i)
        countPut = int(countPut * (n - k + 1 - i) / (i + 1))
        """
        print((countPut * countSplit) % (10 ** 9 + 7))

    else:
        print(0)

Measured memory_bytes: 3316
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n;
  long m;
  readf (" %d %d", &n, &m);
  auto a = new int[n];
  foreach (t; 0 .. n) {
    readf (" %d", &a[t]);
  }
  auto e = sort (a);
  debug stderr.writeln (e);
  long c1, c2;
  bool check (const int x) {
    c1 = c2 = 0;
    foreach (y; a) {
      const int t = x - y;
      //c1 += e.upperBound (t).length;
      auto w = e.trisect (t);
      c1 += w[2].length;
      c2 += w[1].length;
    }
    return c1 + c2 >= m;
  }
  int l = 0, r = a.back + a.back + 1;
  while (r - l > 1) {
    int x = (l + r) >> 1;
    bool checkx = check (x);
    debug stderr.writefln ("check(%d) = %s", x, checkx);
    if (checkx) {
      l = x;
    } else {
      r = x; 
    }
  }
  check (l);
  debug stderr.writeln ("l = ", l);
  debug stderr.writeln ("c1 = ", c1);
  debug stderr.writeln ("c2 = ", c2);
  assert (c1 + c2 >= m);
  c2 = (m - c1);
  auto s = new long[n+1];
  foreach (i; 0 .. n) {
    s[i+1] = s[i] + a[i];
  }
  long res;
  foreach_reverse (y; a) {
    const int t = l - y;
    auto w = e.trisect (t);
    long l1 = w[2].length, l2 = w[1].length;
    c1 -= l1;
    assert (c1 >= 0);
    long u = l1;
    long q = min (c2, l2);
    c2 -= q;
    u += q;
    assert (c2 >= 0);
    res += u * y;
    assert (u <= n);
    res += s[n] - s[n-u];
  }
  assert (c1 == 0);
  assert (c2 == 0);
  writeln (res);
}



Measured memory_bytes: 3452
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;
 
void solve(){
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	vector<vector<int>> g(n);
	vector<int> ans(n,-1);
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	queue<int> q;
	q.emplace(0);
	ans[0] = 0;
	while (!q.empty())
	{
		int x = q.front();
		q.pop();
		for (auto v : g[x])
		{
			if(ans[v]==-1){
				ans[v] = x;
				q.emplace(v);
			}
		}
	}
	cout << "Yes\n";
	REP(i,1,n){
		cout << ans[i] + 1 << "\n";
	}
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}

Measured memory_bytes: 11680
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e+9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){

    string S;
    cin >> S;
    deque<char> dS(S.size());
    for(int i=0; i<S.size(); i++) dS[i] = S[i];

    int Q; cin >> Q;
    int rev = 0;
    for(int i=0; i<Q; i++)
    {
        int type; cin >> type;
        if(type == 2)
        {
            int f; char c;
            cin >> f >> c; f--;//fを0 or 1に変換
            if(rev) f = 1 - f;//反転状態だったら，フラグを反転
            if(f == 0)dS.push_front(c);
            else dS.push_back(c);
        }
        else rev = 1 - rev;
    }
    if (rev) reverse(dS.begin(), dS.end());
    for (auto c : dS) cout << c;
    cout << endl;

    return 0;
}

Measured memory_bytes: 896
while(True):
    n = int(input())
    if n==0:
        exit()
    l = list(map(int,input().split()))
    l.sort()
    s = sum(l)/n
    res = 0
    if l[-1]==l[0]:
        print(n)
        continue
    for i in range(n):
        if l[i]>s:
            print(i)
            break


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

using ll=long long;
using ld=long double;

void solve(){
	string s;
	cin>>s;
	cout<<s.substr(0,3)<<"\n";
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	solve();
	return 0;
}

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

int main() {

  int A, B, K;
  cin >> K >> A >> B;

  for(int i = A; i <= B; i++){
    if(i % K == 0){
      cout << "OK" << endl;
      return 0;
    }
  }

  cout << "NG" << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    if(a>b ){
        cout << 0 << endl;
        return 0;
    }
    else if(n == 1){
        if(a == b){
            cout << 1 << endl;
            return 0;
        }
        else{
            cout << 0 << endl;
            return 0;
        }
    }
    else{
        n -= 2;
        ll c;
        c = b*n - a*n + 1;
        cout << c << endl;
        return 0;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 100009
#define INF 1000000007
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
PII arr[MAXN];
int main()
{
  int n,m;
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++) scanf("%d %d",&arr[i].first,&arr[i].second);
	sort(arr,arr+m);

	int ans=0,mn=INF;
	for(int i=0;i<m;i++)
  {
		umin(mn,arr[i].second);
		if(arr[i].first>=mn)
    {
			ans++;
			mn=arr[i].second;
		}
		else
    {
      umin(mn,arr[i].second);
    }
	}
	printf("%d\n",ans+1);
	return 0;
}

Measured memory_bytes: 1024
N,M,Q = map(int,input().split())
 
train = [[0 for i in range(N+1)] for j in range(N+1)]
for m in range(M):
    L,R = map(int,input().split())
    train[L][R] += 1
 
c = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
    cnt = 0
    for j in range(1,N+1):
        cnt += train[i][j]
        c[i][j] = cnt


for x in range(Q):
    p,q = map(int,input().split())
    cnt2 = 0
    for i in range(p,q+1):
        cnt2 += c[i][q] - c[i][p-1]
    print(cnt2)

Measured memory_bytes: 56096
N , K  = map ( int  ,input().strip().split(" ") ) 
list0 = list( map ( int  , input().strip().split(" ") ) ) ;

set1  = set([0]) ; 
list1 = [0] ;

for x in range ( N ) :
	p = list0[list1[-1]] -1 ;
	if p in  set1 : 
		break ;
	set1.add ( p )  ;
	list1.append( p ) ;

if K < len( list1 ) :
	print ( list1[K] +1 ) ;
else :
	c0 = list1.index( p ) ;
	K -= c0 ;
	c = K % ( len(list1) - c0 ) ;
	print ( list1[c0 + c] + 1) ;




Measured memory_bytes: 35572
package main

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

var (
	N   int
	A   []int
	cnt map[int]int = make(map[int]int)
)

func main() {
	readVariables()
	s := 0
	for _, v := range cnt {
		s += c2(v)
	}
	for i := 0; i < N; i++ {
		ans := s - delta(cnt[A[i]])
		fmt.Println(ans)
	}
}

func readVariables() {
	N = nextInt()
	A = make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		cnt[A[i]]++
	}
}

func c2(x int) int {
	if x < 2 {
		return 0
	}
	return x * (x - 1) / 2
}

func delta(ct int) int {
	return c2(ct) - c2(ct-1)
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 17468
X = int(input())

def binary_search(b):
    l, r = -10 ** 9, 10 ** 9
    while r-l > 1:
        m = (l+r)//2
        x = m**5 - b**5
        if x < X:
            l = m
        else:
            r = m
    return r

for b in range(-200, 200):
    a = binary_search(b)
    if a ** 5 - b ** 5 == X:
        print(a, b)
        break


Measured memory_bytes: 85136