akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

class Mondai
{
    struct Exam
    {
        public string str;
        public int rank;
        public int index;

        public Exam(string s ,int r ,int i)
        {
             str = s;
            rank=r;
            index=i;
        }
    }
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var str = new string[N];
        var tensu = new int[N];
        var ex = new Exam[N];
        for (int i=0;i<N;++i)
        {
            var input = Console.ReadLine().Split(' ').ToArray();
            ex[i] = new Exam(input[0],Int32.Parse(input[1]),i+1);
        }
        var e = ex.OrderBy(x => x.str).ThenByDescending(x => x.rank).ToArray();
        for (int i=0;i<N;++i)
        {
            Console.Write(e[i].index);
            if (i != N - 1) Console.WriteLine();
        }
    }
}

Measured memory_bytes: 13652
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){

        string[] input = ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int saidai = b/a;
        for(int i=saidai;i>=1;i--){
            int wa = i*a;
            int nokori = b-wa;
            if(nokori %i==0){
                WriteLine(i);
                break;
            }
        }
    }
}


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

from copy import deepcopy

MOD = 10 ** 9 + 7
IMAX = 200
JMAX = 2

def dp(n):
    dp = [0 for j in range(JMAX + 1)]
    dp[0] = 1
    for i in reversed(range(IMAX + 1)):
        pre = deepcopy(dp)
        dp[2] += pre[1]
        dp[2] += 2 * pre[2]
        d = ((1 << i) & n) >> i
        if d:
            dp[1] += pre[0]
            dp[2] += pre[1]
        else:
            dp[0] += pre[1]
        dp = take_mod(dp)
    return sum(dp) % MOD

def take_mod(dp):
    res = [x % MOD for x in dp]
    return res

def main():
    n = int(input())
    print(dp(n))

main()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int k;string s;
  cin>>k>>s;
  if(s.length()<=k)
    cout<<s;
  else
  {
    for(int i=0;i<k;i++)
      cout<<s[i];
    cout<<"...";}
    return 0;
  
}

Measured memory_bytes: 3624
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a, val) memset(a, val, sizeof (a))
#define PB push_back
#define endl '\n'
typedef long long ll;

inline int myrand(int l, int r) {
    int ret = rand(); ret <<= 15; ret ^= rand();
    if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
    return ret;
}

template <typename F, typename S>
ostream& operator << (ostream &os, const pair<F, S> &p) {
    return os << "(" << p.first << ", " << p.second << ")"; }

typedef pair<int, int> ii;

template<typename T> using min_pq =
    std::priority_queue<T, vector<T>, greater<T> >;

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

const int maxn = 1e5 + 105;

int h[maxn], dp[maxn], n, k;

int32_t main () {
    // freopen("in", "r", stdin);
    memset(dp, (1 << 7) - 1, sizeof dp);
    cin >> n >> k;
    for(int i = 0; i <= n; i++) {
        cin >> h[i];
    }
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 1; j <= k; j++) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
def smaller(x, y):
	if x < y: return x
	return y

N = int(input())
A = list(map(int, input().split()))
cnt1 = 0
sum1 = 0
for i in range(0, N):
	sum1 += A[i]
	if i%2 == 0:
		if sum1 < 1:
			d = 1 - sum1
			cnt1 += d
			sum1 += d
	else:
		if sum1 > -1:
			d = sum1 + 1
			cnt1 += d
			sum1 -= d
cnt2 = 0
sum2 = 0
for i in range(0, N):
	sum2 += A[i]
	if i%2 == 0:
		if sum2 > -1:
			d = sum2 + 1
			cnt2 += d
			sum2 -= d
	else:
		if sum2 < 1:
			d = 1 - sum2
			cnt2 += d
			sum2 += d
print(smaller(cnt1, cnt2))

Measured memory_bytes: 63344
N = str(input()) #ここで標準入力

car = ''
if N[-1] == '3':
    car = 'bon'
elif N[-1] == '0' or N[-1] == '1' or N[-1] == '6' or N[-1] == '8':
    car = 'pon'
else:
    car = 'hon'



print(car)

Measured memory_bytes: 9020
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h];
		for(int i = 0 ; i < h ; i++) {
			s[i] = sc.next();
		}
		String[][] x = new String[h][w];
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				x[i][j] = "" + s[i].charAt(j);
			}
		}

		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				if(x[i][j].equals(".")) {
					int cnt = 0;
					for(int k = i - 1 ; k <= i + 1 ; k++) {
						for(int l = j - 1 ; l <= j + 1 ; l++) {
							if(k < 0 || k > h - 1 || l < 0 || l > w - 1) {
								continue;
							}
							if(x[k][l].equals("#")) {
								cnt++;
							}
						}
					}
					x[i][j] = String.valueOf(cnt);
				}
			}
		}
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				System.out.print(x[i][j]);
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    string S;
    cin >> N >> S;

    V(V(bool)) lk(N, V(bool)(10, false)), rk(N, V(bool)(10, false));
    rep(i, N) {
        int l = S[i]-'0', r = S[N-1-i]-'0';
        if(i>0) {
            rep(j, 10) {
                lk[i][j] = lk[i-1][j];
                rk[N-1-i][j] = rk[N-1-i+1][j];
            }
        }
        lk[i][l] = true;
        rk[N-1-i][r] = true;
    }

    map<int, int> mp;
    int res = 0;
    FOR(i, 1, N-1) {
        rep(l, 10) {
            if(lk[i-1][l]) {
                int temp = 100*l;
                temp += 10*(S[i]-'0');
                rep(r, 10) {
                    if(rk[i+1][r]) {
                        temp += r;
                        mp[temp]++;
                        temp -= r;
                    }
                }
            }
        }
    }

    for(auto &p : mp) {
        //cout << p.fi << endl;
        res++;
    }
    

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 4608
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val X = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    val sorted = X.sorted()

    val a = Math.floor((1.toDouble() + N.toDouble()) / 2.0).toInt() - 1
    val b = Math.ceil((1.toDouble() + N.toDouble()) / 2.0).toInt() - 1
    for (i in 0 until N) {
        if (X[i] <= sorted[a]) {
            println(sorted[b])
        } else {
            println(sorted[a])
        }
    }
}

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

string BadGood[] = {"Good","Bad"};

int main(void)
{
    string S;
    cin >> S;
    cout << BadGood[int(S[0]==S[1] || S[1]==S[2] || S[2]==S[3])] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long h, a;

//divCeil
long divCeil(long a, long b){
    return (a-1)/b+1;
}

int main(){
    scanf("%ld%ld", &h, &a);
    printf("%ld\n", divCeil(h, a));
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll A,B,C,D,E,F;
    cin>>A>>B>>C>>D>>E>>F;
    double rec=0.0;
    ll ans1=A*100;
    ll ans2=0;
    rep(a,F/(A*100)+2){
        rep(b,F/(B*100)+2){
            ll w = a*A*100+b*B*100;
            if(w==0)continue;
            rep(c,(F-w)/C+2){
                rep(d,(F-w)/D+2){
                    ll s = C*c+D*d;
                    if(w+s==0)continue;
                    double tmp = s/(double)(w+s);
                    if(w+s<=F && tmp <= (double)E/(100.0+E)){
                        if(chmax(rec,tmp)){
                            ans1 = w+s;
                            ans2 = s;
                        }
                    }
                }
            }
        }
    }
    cout<<ans1<<" "<<ans2<<endl;
    return  0;
}


Measured memory_bytes: 256
def main():
	n = int(input())
	total = 0
	max_val = 0
	for i in range(n):
		p = int(input())
		total += p
		if p > max_val:
			max_val = p
	total -= max_val//2
	print(total)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };

ll N[3], K;
ll A[3][1010];
vector<ll>B;
vector<ll>ans;
ll BN;


int check(ll x) {
	ll cnt = 0;
	rep(i, 0, N[0]) {
		ll ind = lower_bound(all(B),x-A[0][i]) - B.begin();
		cnt += BN - ind;
	}
	return K <= cnt;
}



int main() {
	rep(i, 0, 3)cin >> N[i];
	cin >> K;
	rep(i, 0, 3)rep(j, 0, N[i])cin >> A[i][j];
	rep(a, 0, N[1])rep(b, 0, N[2])B.pb(A[1][a] + A[2][b]);
	sort(all(B));
	BN = B.size();

	ll ok = 0; ll ng = inf;
	while (ng - ok > 1) {
		ll mid = (ok + ng) / 2;
		if (check(mid))ok = mid;
		else ng = mid;
	}

	reverse(all(B));
	rep(i, 0, N[0]) {
		rep(j, 0, BN) {
			if (A[0][i] + B[j] > ok)ans.pb(A[0][i] + B[j]);
			else break;
		}
	}

	while (ans.size() < K)ans.pb(ok);

	sort(all(ans));
	reverse(all(ans));
	rep(i, 0, K) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 10604
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        //int[] N = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = int.Parse(Console.ReadLine());
        int[] N = new int[n].Select(x => int.Parse(Console.ReadLine())).ToArray();
        int pos = 1;
        int res = 0;
        while (true)
        {
            if (N[pos - 1] == -1)
            {
                res = -1;
                break;
            }
            int temp = N[pos - 1];
            N[pos - 1] = -1;
            pos = temp;
            res++;
            if (pos == 2) break;
        }
        Console.WriteLine(res);
    }
}

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

int main(){

	LL n, m, k ;
	cin >> n >> m >> k ;

	vector<LL> a(n + 1), b(m + 1) ;
	a[0] = 0LL ;
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i] ;
		a[i] += a[i-1] ;
	}
	b[0] = 0LL ;
	for(int i = 1 ; i <= m ; i++){
		cin >> b[i] ;
		b[i] += b[i-1] ;
	}

	int i, j = m ;
	int mx = 0 ;

	for(i = 0 ; i <= n ; i++){
		if(a[i] > k)
			break ;
		
		while(b[j] > k - a[i])
			j-- ;
		mx = max(mx, i + j) ;
	}

	cout << mx << endl ;

	return 0;
}

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

int main()
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int count = 0;
    for(int i=0;i<=a;i++){
        int x1 = x-500*i;
        for(int j=0;j<=b;j++){
            int x2 = x1 - 100*j;
            if((x2 >= 0) && (x2 % 50 == 0) && (x2/50 <= c)){
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args:Array[String]):Unit = {
    val sc = new Scanner(System.in)
    val a, b = sc.nextInt()

    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
      print("Possible")
    } else {
      println("Impossible")
    }
  }
}

Measured memory_bytes: 27332
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int mark[100001],A[100001];
int main()
{
int n,i,x,c=0;
cin>>n;
for(int i=1;i<=n;i++)
cin>>A[i];
x=1;
c=0;
mark[1]=1;
while(x!=2)
{
c++;
x=A[x];
if(mark[x])
break;
mark[x]=1;
}
if(x==2)
cout<<c;
else
cout<<"-1";
return 0;
}


Measured memory_bytes: 1024
###提出 #10048385

n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
from functools import reduce
def lcm(x,y):
  return (x*y)//gcd(x,y)
mod = 10**9+7
l = reduce(lcm, a) % mod
ans = 0
for i in range(n):
  ans += l * pow(a[i], mod - 2, mod)
  ans %= mod
print(ans)

#頭良すぎて草

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

bool isPrime(int);

int main() {

    int n, t, i, cnt;
    cin >> n;
    cnt = 0;
    for (i = 0; i < n; i++) {
        scanf("%d", &t);
        if (isPrime(t)) cnt++;
    }

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

    return 0;
}

bool isPrime(int n) {
    if (n == 0 || n == 1) return false;
    for (int i = 2; i*i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}




Measured memory_bytes: 3212
#include <iostream>
#include <cstdint>

using namespace std;

int main()
{
    int N;
    int a[3'000];

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

    u_int64_t sum = 0;
    for (int i = 0; i < N; i++)
    {
        sum += a[i];
    }

    cout << sum - N << endl;

    return 0;
}

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

bool solve(int a,int b,int c,int d){
    if(b > min(a,d)) return false;
    if(c >= b) return true;
    int x = __gcd(b,d);
    if(b - x + a%x > c)return false;
    else return true;
}

signed main(){
    int t; cin >> t;
    REP(i,t){
        int a, b, c, d; cin >> a >> b >> c >> d;
        cout << ( solve(a,b,c,d) ? "Yes" : "No" ) << endl;;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    A--; B--; C--; D--;
    string S;
    cin >> S;
    ll ng[200010] = {};
    rep(i,0,N){
        if(S[i] == '#') ng[i] = 1;
    }
    bool ok = true;
    ll pos = A;
    while(1){
        if(pos == C) break;
        if(pos >= N){
            ok = false;
            break;
        }
        if(ng[pos+1] == 0){
            pos++;
        }else if(ng[pos+2] == 0){
            pos += 2;
        }else{
            ok = false;
            break;
        }
    }
    pos = B;
    while(1){
        if(pos == D) break;
        if(pos >= N){
            ok = false;
            break;
        }
        if(ng[pos+1] == 0){
            pos++;
        }else if(ng[pos+2] == 0){
            pos += 2;
        }else{
            ok = false;
            break;
        }
    }
    if(D < C){
        bool ok2 = false;
        rep(i,B,D+1){
            if(S[i-1] == '.' && S[i] == '.' &&  S[i+1] == '.'){
                ok2 = true;
            }
        }
        if(not ok2) ok = false;
    }
    if(ok){
        print("Yes");
    }else{
        print("No");
    }
}

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

#define lli long long int
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL << 50)
#define DEBUG 0
#define mp(a, b) make_pair(a, b)
#define SORT(V) sort(V.begin(), V.end())
#define PI (3.141592653589794)

const string YES = "Yes";
const string NO = "No";

void func(long long N, long long M, std::vector<long long> A)
{
    sort(A.begin(), A.end());
    lli sum = 0;
    REP(i, 0, N)
    sum += A[i];

    lli border = sum / (4 * M);
    if (sum % (4 * M))
        border++;

    lli cnt = 0;
    REP(i, 0, N)
    {
        if (A[i] >= border)
            cnt++;
    }
    if (cnt >= M)
        cout << YES << endl;
    else
        cout << NO << endl;
}

int main()
{
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    func(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main(){

	int h, w;
	while (std::cin >> h >> w, h || w){
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				std::cout << "#";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1152
n = int(input())
A = list(map(int, input().split()))
K = [0]*(10**5+1)
s = 0
for a in A:
  K[a] += 1
  s += a
q = int(input())
for _ in range(q):
  b, c = map(int, input().split())
  t = K[b]
  K[b] = 0
  K[c] += t
  s += t*(c-b)
  print(s)

Measured memory_bytes: 21044
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	elems, err := nextInts(n, sc)
	if err != nil {
		panic(err)
	}
	selectionSort(elems)
}

func selectionSort(elems []int) {
	count := 0
	for i := 0; i < len(elems)-1; i++ {
		mini := i
		for j := i + 1; j < len(elems); j++ {
			if elems[j] < elems[mini] {
				mini = j
			}
		}
		if mini != i {
			count++
			elems[i], elems[mini] = elems[mini], elems[i]
		}
	}
	printInts(elems)
	fmt.Println(count)
}

func printInts(elems []int) {
	elemsStr := make([]string, len(elems))
	for i, v := range elems {
		elemsStr[i] = strconv.Itoa(v)
	}
	fmt.Println(strings.Join(elemsStr, " "))
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextInts(num int, sc *bufio.Scanner) ([]int, error) {
	res := make([]int, num)
	for i, _ := range res {
		x, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		res[i] = x
	}
	return res, nil
}



Measured memory_bytes: 1108
import java.io.*;
import java.util.*;
import java.math.*;

public class Main{
	static final BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static int tc;
	static final int MOD=1_000_000_007;
	public static long[] inputArray(String str){
		String[] s=str.split(" ");
		long[] array=new long[s.length];
		for(int i=0;i<s.length;i++) {
			array[i]=Long.parseLong(s[i]);
		}
		return array;
	}
	public static void main(String[] args)throws IOException {
		//tc=Integer.parseInt(br.readLine());
		tc=1;
		while(tc-->0) {
			String str=br.readLine();
			long sum=0;
			for(int i=0;i<str.length();i++) {
				sum+=str.charAt(i)-'0';
			}
			if(Long.parseLong(str)%sum==0) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 21076
#!/usr/bin/env python3
import sys


def solve(N: int):
    for i in range(1, 10):
        n = int(str(i)*3)
        if N <= n:
            break
    else:
        print("1111")
        return
    print(n)

    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var t = Enumerable.Range(1, n).ToArray();
        var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var cnt = 0;
        for (int i = 0; i < n; i++)
        {
            if (t[i] != p[i]) cnt++;
        }
        if (cnt <= 2)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> S = {"Sunny","Cloudy","Rainy"};
  string s;
  cin >> s;
  for(int i = 0;i < 3;i++) {
    if(S.at(i) == s) {
      cout << S.at((i + 1) % 3) << endl;
    }
  }
}

Measured memory_bytes: 256
S=input()
Flag=True

for i in S[1:100:2]:
  if i=="L" or i=="U" or i=="D":
    pass
  else:
    Flag=False
    
for j in S[0:100:2]:
  if j=="R" or j=="U" or j=="D":
    pass
  else:
    Flag=False

if Flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.split("\n");
var str="";
for(var i=0;i<Arr.length;i++){
var arr=Arr[i].split(" ").map(Number);
var h=arr[0];
var w=arr[1];
if(h===0 && w===0)break;
if(i!==0)str+="\n";
var W=Array(w+1).join("#")+"\n";
str+=Array(h+1).join(W);
}
console.log(str);

Measured memory_bytes: 7908
n = int(input())
ll = list(map(int, input().split()))
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            a,b,c = ll[i], ll[j], ll[k]
            if a == b or b == c or c == a:
                continue
            vs = [a,b,c]
            vs.sort()
            if vs[0] + vs[1] > vs[2]: 
                cnt += 1
                # print(vs)

print(cnt)


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

int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  string ans;
    rep(i,ty-sy) ans+='U'; 
    rep(i,tx-sx) ans+='R';
    rep(i,ty-sy) ans+='D'; 
    rep(i,tx-sx) ans+='L';
    ans+='L'; 
    rep(i,ty-sy+1) ans+='U'; 
    rep(i,tx-sx+1) ans+='R'; 
    ans+='D';
    ans+='R';
    rep(i,ty-sy+1) ans+='D'; 
    rep(i,tx-sx+1) ans+='L'; 
    ans+='U';
  cout<<ans<<endl;
}


Measured memory_bytes: 3616
def solve
  n = gets.to_i
  arr = gets.split.map!(&:to_i)
  arr_grouped_by = arr.group_by(&:itself).map { |key, value| [key, value.count] }.to_h
  total_value = arr_grouped_by.map { |key, value| (value * (value - 1)) / 2 }.inject(&:+)
  n.times do |i|
    index = arr[i]
    total_value_v2 = total_value
    arr_grouped_by[index] = arr_grouped_by[index] - 1
    p total_value_v2 - arr_grouped_by[index]
    arr_grouped_by[index] = arr_grouped_by[index] + 1
  end
end
solve

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

int main(){
    int N;
    int D[110];
    cin >> N;
    for (int i=0; i<N; i++) cin >> D[i];

    set<int> values;
    for (int i=0; i<N; i++) {
        values.insert(D[i]);
    }

    cout << values.size() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int H, W;
	int A[90][90];
	int B[90][90];
	cin >> H >> W;
	REP(i, H) {
		REP(j, W)cin >> A[i][j];
	}
	REP(i, H) {
		REP(j, W)cin >> B[i][j];
	}

	bool dp[82][82][10000] = { false };
	dp[0][0][abs(A[0][0] - B[0][0])] = true;

	REP(i, H) {
		REP(j, W) {
			REP(k,10000){
				if (i != 0 && dp[i - 1][j][k]) {
					if (k + abs(A[i][j] - B[i][j]) < 10000) {
						dp[i][j][k + abs(A[i][j] - B[i][j])] = true;
					}
					if (abs(k - abs(A[i][j] - B[i][j])) < 10000) {
						dp[i][j][abs(k - abs(A[i][j] - B[i][j]))] = true;
					}
				}
				if (j != 0 && dp[i][j - 1][k]) {
					if (k + abs(A[i][j] - B[i][j]) < 10000) {
						dp[i][j][k + abs(A[i][j] - B[i][j])] = true;
					}
					if (abs(k - abs(A[i][j] - B[i][j])) < 10000) {
						dp[i][j][abs(k - abs(A[i][j] - B[i][j]))] = true;
					}
				}
			}

		}
	}
	int ans = INF;
	REP(i, 10000) {
		if (dp[H - 1][W - 1][i])chmin(ans, i);
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 66048
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//#include "atcoder/all"
//using namespace atcoder;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double n, m, d;
	cin >> n >> m >> d;
	double ans = (d == 0 ? 1/n : 2*(n-d)/(n*n)) * (m-1);
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

int imos[32][100005];
int ians[100005];

void solve()
{
  int n, c, is, it, ic;
  cin >> n >> c;
  for(int i = 0; i < n; ++i)
  {
    cin >> is >> it >> ic;
     ic--;
    imos[ic][is - 1]++;
    imos[ic][it]--;
  }

  for(int ci = 0; ci < c; ++ci)
  {
    for(int i = 0; i <= 100000; ++i)
    {
      imos[ci][i + 1] = imos[ci][i] + imos[ci][i + 1];
      imos[ci][i] = min(1, imos[ci][i]);
      ians[i] += imos[ci][i];
    }
  }

  int ans = 0;
  for(int i = 0; i <= 100000; ++i)
  {
    ans = max(ans, ians[i]);
  }

  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 15632
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

Int valid(string s, string t){
  map<char,Int> cnt;
  for(char ch:s) cnt[ch]++;
  for(char ch:t) if(cnt[ch] == 0) return 0;
  return 1;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s, t;
  cin>>s>>t;

  if(!valid(s, t)){
    cout<<-1<<endl;
    return 0;
  }

  Int N = s.size();
  Int M = t.size();
  vector<vector<Int> > Idx(30);
  for(Int i=0;i<N;i++) Idx[s[i] - 'a'].push_back(i);
  for(Int i=0;i<30;i++) Idx[i].push_back(INF);

  auto get = [&](Int ch, Int i){
    return *lower_bound(Idx[ch].begin(), Idx[ch].end(), i);
  };


  Int ans = 0;
  Int I = 0;
  for(Int i=0;i<M;i++){
    Int ch = t[i] - 'a';
    Int to = get(ch, I);
    // pr(ch, to, I);
    if(to == INF){
      I = 0;
      ans += N;
      i--;
      continue;
    }
    I = to+1;

  }

  //pr(ans, I);
  ans += I;
  cout<<ans<<endl;





  return 0;
}


Measured memory_bytes: 1736
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let s = read::<String>();
    let w = read::<i64>();
    let cs = s.chars().collect::<Vec<char>>();
    let first = cs[0];
    let mut ans = cs.into_iter().skip(1).enumerate().filter(|x| (x.0 as i64+1) % w == 0 ).map(|x|x.1).collect::<Vec<char>>();
    ans.insert(0,first);
    for c in ans{
        print!("{}",c);
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
//#include <boost/lexical_cast.hpp>
using namespace std;

#define pb push_back
#define mp make_pair
#define inf 1000000000
#define mod 1000000007

#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define sc(n) scanf("%c",&n)
#define ssc(n) scanf(" %c",&n)

#define pin(n) printf("%d\n",n)
#define pis(n) printf("%d ",n)
#define pln(n) printf("%lld\n",n)
#define pls(n) printf("%lld ",n)
#define pn printf("\n")
#define ps(n) printf("%s",n)
#define psn(n) printf("%s\n",n)

vector<int> primes;  //primes.size() = 78498 //last prime number = 999983
void sieve()
{
    vector<bool> a(1000000,false);
    for(int u=2;u<=1000000;u++)
    {
        if(a[u])continue;
        for(int i=2*u;i<=1000000;i+=u)a[i]=true;
    }
    for(int i=2;i<=1000000;i++)
    {
        if(!a[i])primes.pb(i);
    }
}

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

int digitCount(int n)
{
    int c=0;
    while(n!=0)
    {
        c+=n%10;
        n/=10;
    }
    return c;
}

int parseInt(string str)
{
    int a=0;
    int l=str.length();
    for(int i=0;i<l;i++)
    {
        a*=10;
        a+=str[i]-48;
    }
    return a;
}

long long parseLong(string str)
{
    long long a=0;
    int l=str.length();
    for(int i=0;i<l;i++)
    {
        a*=10;
        a+=str[i]-48;
    }
    return a;
}

int main()
{
    string str;
    cin>>str;

    if(str[0]==str[2])psn("Yes");
    else psn("No");
}


Measured memory_bytes: 256
N, Y = map(int, input().split())
count = 0
list=[]
for i in range(2001):
    if count == 1:
        break
    for j in range(2001):
        k = N - i - j
        if k < 0:
            break
        if 10000*i + 5000*j + 1000*k == Y:
            list +=[i, j, k]
            count += 1
            break
if count == 0:
    print("-1 -1 -1")
else:
    print(*list)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


class UnionFind{
public:
    UnionFind(int n){
        size = n;
        parent = vector<int>(size,-1);
    }
    int getSize(){return size;}
    int getParentElement(int index){return parent[index];}
    void printParent(){
        for(auto v: parent) {cout << v << " ";}
        cout << endl;
    }
    int find(int x){
        int a = x;
        vector<int> children;
        while(parent[a]>=0){
            children.push_back(a);
            a = parent[a];
        }
        for(auto child: children){parent[child] = a;}
        return a;
    }
    int Union(int x,int y){
        int root_x = find(x);
        int root_y = find(y);
        if(root_x != root_y){
            if(parent[root_x]>=parent[root_y]){
                parent[root_x] += parent[root_y];
                parent[root_y] = root_x;
            }else{
                parent[root_y] += parent[root_x];
                parent[root_x] = root_y;
            }
        }
        return parent[root_x];
    }
private:
    int size;
    vector<int> parent;
};

int main(){
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);

    vector<int> a(m), b(m);
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    reverse(all(a));
    reverse(all(b));
    vector<ll> inconvenient(m+1,(ll)n*(n-1)/2);
    for(int i = 0; i < m; i++){
        if(uf.find(a[i]) == uf.find(b[i])){
            inconvenient[i+1] = inconvenient[i];
        }else{
            int old_size_a, old_size_b;
            if(uf.getParentElement(a[i])<0){
                old_size_a = -1*uf.getParentElement(a[i]);
            }else{
                old_size_a = abs(uf.getParentElement(uf.getParentElement(a[i])));
            }
            if(uf.getParentElement(b[i])<0){
                old_size_b = -1*uf.getParentElement(b[i]);
            }else{
                old_size_b = abs(uf.getParentElement(uf.getParentElement(b[i])));
            }
            int newparent = uf.Union(a[i],b[i]);
            int new_size = old_size_a + old_size_b;
            inconvenient[i+1] = inconvenient[i] + (ll)old_size_a*((ll)old_size_a-1)/2 + (ll)old_size_b*((ll)old_size_b-1)/2;
            inconvenient[i+1] -= (ll)new_size*(new_size-1)/2;
           
        }
    }

    for(int i = m-1; i >= 0; i--){
        cout << inconvenient[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3328
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
cnt = 0
for si in s:
    if si == "x":
        cnt += 1

print("YES" if cnt < 8 else "NO")

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

int main() {
    int p, q, r;
    cin >> p >> q >> r;

    if (p >= q && p >= r)
        cout << q+r << endl;
    else if (q >= p && q >= r)
        cout << p+r << endl;
    else if (r >= p && r >= q)
        cout << p+q << endl;

    return 0;
}


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

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto ab = readints;
    int a = ab[0], b = ab[1];

    bool found = iota(1, 3).map!(c => a * b * c).any!(e => e % 2 == 1);
    writeln(found ? "Yes" : "No");
}


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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXST = 3000;

int dp[MAXST + 2][MAXST + 2];
char s[MAXST + 2], t[MAXST + 2];

int main() {
	cin >> s >> t;
	int S = strlen(s), T = strlen(t);
	for(int i = 1; i <= S; i++)
		for(int j = 1; j <= T; j++)
			dp[i][j] = s[i - 1] == t[j - 1] ? dp[i - 1][j - 1] + 1 : max(dp[i][j - 1], dp[i - 1][j]);
	int x = S, y = T, k = T;
	while(dp[x][y]) {
		if(dp[x][y] == dp[x - 1][y]) {
			x--;
		} else if(dp[x][y] == dp[x][y - 1]) {
			y--;
		} else {
			t[--k] = s[x - 1];
			x--; y--;
		}
	}
	cout << &t[k] << endl;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi a(N);
    cin >> a;
    REP(i, N)
    a[i]--;
    int now = 0;
    REP(i, N) {
        now = a[now];
        ans++;
        if (now == 1) {
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3704
fun main() = ABC168A.main()

object ABC168A {
    fun log(message: Any?) {
        println(message)// TODO: ←消す
    }

    fun main() {
        val N= readInt()
        val ans = when(N%10) {
            0 -> "pon"
            1 -> "pon"
            6 -> "pon"
            8 -> "pon"
            3 -> "bon"
            else -> "hon"
        }
        println(ans)
    }


    /*####################################################################################*/

    fun readString() = readLine()!!
    fun readStrings() = readLine()!!.split(" ")
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
    fun readLong() = readLine()!!.toLong()
    fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
    fun readMatrixRows(height: Int) = (1..height).map { readLine()!!.toList() }

    fun Boolean.yesOrNo() = if (this) "Yes" else "No"
    fun Double.toNaturalExpr() = println("%f".format(this))
}

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

int main(){
  int n;
  cin>>n;
  int a[100001];
  for(int i=1;i<=n;i++)cin>>a[i];
  int cnt=0;
  for(int i=1;i<=n;i++){
    if(a[a[i]]==i)cnt++;
  }

      cout<<cnt/2<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int sum=0,f=1;
	char c=getchar();
	for(;c>'9'||c<'0';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) sum=(sum<<1)+(sum<<3)+c-48;
	return sum*f; 
}
int n,z,len,ma,ans;
struct ee
{
	int v,id;
}a[2][100010];
bool mycmp(ee q,ee w)
{
	return q.v>w.v;
}
void init()
{
	n=read();
	for(int i=1;i<=n;i++) {
		z=read();
		ma=max(ma,z);
		a[i%2][z].v++;
		a[i%2][z].id=z;
	}
}
void work()
{
	sort(a[0]+1,a[0]+1+ma,mycmp);
	sort(a[1]+1,a[1]+1+ma,mycmp);
	if(a[0][1].id!=a[1][1].id) ans=n-a[0][1].v-a[1][1].v;
	else ans=max(a[0][1].v+a[1][2].v,a[0][2].v+a[1][1].v),ans=n-ans;
	printf("%d\n",ans);
}
int main()
{
	init();
	work();
	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  int N;
  cin >> N;
  int ans = N;
  char pos, next;
  cin >> pos;
  for(int i = 0; i < N-1; i++){
    cin >> next;
    if (next == pos){
      ans--;
    }
    //else continue;
    pos = next;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int a[3];

int main(void){
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	if(a[0]%2==1 || a[1]%2==1 || a[2]%2==1){
		printf("0\n");
		return 0;
	}
	sort(a,a+3);
	int l=a[1]-a[0];
	int r=a[2]-a[1];
	if(l==0 && r==0){
		printf("-1\n");
		return 0;
	}
	int res=0;
	int k=0;
	while(l%2==0 && l>0){
		l/=2;
		k++;
	}
	res=k;
	k=0;
	while(r%2==0 && r>0){
		r/=2;
		k++;
	}
	if(l!=0 && r!=0)res=min(res,k);
	if(l==0)res=k;
	printf("%d\n",res);
	return 0;
}


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

int main(){
	//入力機構
	std::string S;
	size_t N;
	std::cin>>N>>S;
	//処理機構
	//先頭から1文字ずつ調べていき、両方にあるならsetに入れる。その個数を見ていく。
	size_t ans=0;
	std::set<char> multSet;
	for(size_t i=0;i+1<N;i++){
		//S[i]を見て、分岐
		bool f=S.substr(i+1,std::string::npos).find(S[i])!=std::string::npos;//i+1番目以降の部分文字列の中に、S[i]が入っているか
		if(f){
			//S[i+1]以降にS[i]があるなら、multSetに追加
			multSet.insert(S[i]);
		} else{
			//そうでないなら、multSetからS[i]を除く
			multSet.erase(S[i]);
		}
		size_t size=multSet.size();
		ans=ans<size?size:ans;
	}

	//出力機構
	std::cout<<ans<<std::endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int check(int a)
{
    int  x = 0;
    switch(a){
        case 5:
            x = 1;
            break;
        case 7:
            x = 10;
        	break;
    }
    return x;
}

int main(){
    int a,b,c,x = 0;
    scanf("%d %d %d",&a,&b,&c);
    x = check(a) + check(b) + check(c);
    check(a);
    if(x == 12)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

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

typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1001001001;

using namespace std;

int main() {

    string s;
    cin >> s;

    string ans = "";

    rep(i, s.size()) {
        ans += 'x';
    }

    AA(ans);
}


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

#define REP(n) for(int i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100005

int main(){

    string a,b,c;
    cin >> a >> b >> c;

    if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    
     
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if(s==EOF)exit(0);
	if(s=='-')base=-1,s=getchar();
	while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
	return k*base;
}
inline void write(int x)
{
	static char cnt,num[15];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
int n,k,s;
ll ans,s1;
int main()
{
#ifdef ylx
	freopen("arc91b.in","r",stdin);
	freopen("arc91b.out","w",stdout);
#endif
	n=read();k=read();
	if (k==0)
	{
		ans=(ll)n*n;
		printf("%lld",ans);
		return 0;
	}
	for (int j=k+1;j<=n;j++)
	{
		s=n/j;
		s1=(j-k);
		ans+=(ll)s1*s;
		if (n%j>=k)
		{
			ans+=(ll)(n%j-k+1);
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
  int r, D, x2000;
  cin >> r >> D >>x2000;
  int xi = x2000;
  for (int i = 0; i < 10; i++) {
    xi = r*xi-D;
    cout<<xi<<endl;
  }
  return 0;
}


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

int main(){
    string a,b,c;
    cin >> a >> b;
    int re,bu;
    cin >> re >> bu >> c;
    if(c == a){
        re--;
    }
    else{
        bu--;
    }
    if(re < 0){
        re = 0;
    }
    if(bu < 0){
        bu = 0;
    }
    cout << re << ' ' << bu << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int a = int.Parse(s[0]);
        int b = int.Parse(s[1]);
        Console.WriteLine(a * b % 2 == 0 ? "Even" : "Odd");
    }
}


Measured memory_bytes: 11092
//Popular Vote

#include<bits/stdc++.h>
#define ll long long 
using namespace std;
 
int main(){
    int N, M ;
    double sum=0;
    string Ans = "Yes";
    cin >> N >> M;
    int arr[N];
    for(int i = 0;i<N;i++){
        cin >> arr[i];
        sum = sum + arr[i];
    }
    sort(arr, arr + N, greater<int>());
    for(int i = 0;i<M;i++){
        if(arr[i]<sum/(4*M)){
            Ans="No";
        }
    }
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 256
S = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
if S[0] == 'A':
  if S[2:len(S)-1].count('C') == 1:
    for c in S:
      if (c!='A') and (c!='C') and (c not in abc):
        print('WA')
        exit()
    else:
      print('AC')
  else:
    print('WA')
else:
  print('WA')

Measured memory_bytes: 3060