akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	var taro, hanako int
	for i := 0; i < n; i++ {
		var a, b string
		fmt.Scan(&a, &b)
		if a == b {
			taro++
			hanako++
			continue
		}

		if a > b {
			taro = taro + 3
			continue
		}

		hanako = hanako + 3
	}
	fmt.Printf("%d %d\n", taro, hanako)
}



Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if((A+B) < (C+D)){
    cout << "Right" << endl;
  }else if((A+B) > (C+D)){
    cout << "Left" << endl;
  }else{
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (h, n) = readIntList()
    val a = readIntList()
    if (h - a.sum() <= 0) println("Yes")
    else println("No")
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 47672
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 102;
ll a[N];
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    ll ans = 1e18;
    for(int i=1;i<=100;i++){
            ll trt = 0;
        for(int j=1;j<=n;j++){
            trt+=(a[j]-i)*(a[j]-i);
        }
        ans = min(ans,trt);
    }
    cout<<ans<<endl;

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


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	double a, b, angle;
	cin >> a >> b >> angle;
	double rad = angle * M_PI / 180;
	double S = a * b*sin(rad) / 2;
	double L = sqrt(a*a + b * b - 2 * a*b*cos(rad)) + a + b;
	double H = b * sin(rad);
	printf("%.8f %.8f %.8f\n", S, L, H);
}


Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m; cin>>n>>m;
  bool adj_matrix[n][n];
  vector<int> v,p;
  for(int i=0; i<n; ++i){
    for(int j=0; j<n; ++j){
      adj_matrix[i][j] = false;
    }
    if( i != 0 ) p.push_back(i);
    v.push_back(i);
  }
  for(int i=0; i<m; ++i){
    int a,b; cin>>a>>b;
    adj_matrix[a-1][b-1] = adj_matrix[b-1][a-1] = true;
  }
  int ret=0; bool reached;
  do{
    reached = true;
    for(int i=0; i<n-1; ++i){
      v[i+1] = p[i];
      if( !adj_matrix[v[i]][v[i+1]] ){
        reached =false; break;
      }
    }
    if ( reached) ++ret;
  } while( next_permutation(p.begin(), p.end()));
  cout << ret <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
	int x, a, b;

	cin >> x >> a >> b;

	if (b - a <=0) {
		cout << "delicious" << endl;
	}
	else if (b - a <= x) {
		cout << "safe" << endl;
	}
	else
		cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int x,sm;
int main(){
cin>>x;
sm=x*800;
sm-=x/15*200;
cout<<sm<<endl;
system("pause");
return 0;
}

Measured memory_bytes: 504
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B;
  cin>>A>>B;
  if(A+B>=10) cout<<"error"<<endl;
  else cout<<A+B<<endl;
}


Measured memory_bytes: 3592
from itertools import combinations
N = int(input())
scores = [int(input())for i in range(N)]
sums= sum(scores)
if sums % 10 != 0:
    print(sums)
    exit()
scores.sort()
for i in range(N):
    if (sums-scores[i]) % 10 != 0:
        print(sums - scores[i])
        exit()
print(0)

Measured memory_bytes: 62480
#include <iostream>
#include <ios>
#include <vector>
#include <utility>

using namespace std;

void read_data(int n, vector<vector<int>> & Es){
    int u = 0, k = 0, v = 0;
    while (n--){
        cin >> u;
        cin >> k;
        while (k--){
            cin >> v;
            Es[u - 1].push_back(v - 1);
        }
    }
}

void wfs(int node, vector<int> & dist, vector<vector<int>> & Es){
    int d = 0;
    vector<int> frontiers;
    frontiers.push_back(node);
    while (!frontiers.empty()){
        vector<int> new_frontiers;
        for (auto u : frontiers){
            if (dist[u] == -1){
                dist[u] = d;
                for (auto v : Es[u]){
                    new_frontiers.push_back(v);
                }
            }
        }
        frontiers = move(new_frontiers);
        ++d;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int n = 0;
    cin >> n;
    vector< vector<int> > Es(n);
    vector<int> dist(n, -1);
    read_data(n, Es);
    wfs(0, dist, Es);
    for (int i = 0; i != n; ++i) cout << i + 1 << ' ' << dist[i] << endl;
    
    return 0;
}

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



ll cost(ll arr[],ll n)
{
    ll val[n+1];
    
    val[1]=0;
    for(int i=2;i<=n;i++)
    {
        if(i==2)
        val[i]=abs(arr[i]-arr[i-1])+val[i-1];
        else 
        val[i]=min(abs(arr[i]-arr[i-1])+val[i-1],abs(arr[i]-arr[i-2])+val[i-2]);
    }
    
    cout<<val[n]<<endl;
    
}

int main()
{
    ll n;
    cin>>n;
    ll h[n+1];
    for(ll i=1;i<=n;i++)
    cin>>h[i];
    cost(h,n);

    return 0;
}


Measured memory_bytes: 1792
const main = (input) => {
  const args = input.split(' ').map(v => Number(v))
  const a = args[0]
  const b = args[1]
  const h = args[2]
  const m = args[3]
  const radA = (30.0 * h + m * 0.5) * Math.PI / 180.0
  const radB = m * 6.0 * Math.PI / 180.0
  const ax = a * Math.cos(radA)
  const ay = a * Math.sin(radA)
  const bx = b * Math.cos(radB)
  const by = b * Math.sin(radB)
  console.log(Math.sqrt(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2)))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29848
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

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


int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h, vector<char> (w));
    rep(i, h) {
        rep(j, w) {
            cin >> a.at(i).at(j);
        }
    }
    rep(i, w + 2) {
        cout << "#";
    }
    cout << endl;
    rep(i, h) {
        cout << "#";
        rep(j, w) {
            cout << a.at(i).at(j);
        }
        cout << "#" << endl;
    }
    rep(i, w + 2) {
        cout << "#";
    }
    cout << endl;
}

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

int main() {
  
  string s, t;
  cin >>  s >> t;
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  
  int n = s.size();
  vector<int> u(26);
  vector<int> v(26);
  int j = 0, k = 0;
  
  REP(i,n) {
    u[j]++;
    v[k]++;
    if(s[i] != s[i+1]) j++;
    if(t[i] != t[i+1]) k++;
  }
    
  sort(u.begin(), u.end());
  sort(v.begin(), v.end());
  
  bool ans = true;
  REP(i,26) {
    if (u[i] != v[i]) ans = false;
  }
  
  cout << (ans ? "Yes" : "No") << endl;
    
    
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;

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

  string s;
  cin >> s;
  int t = 0;
  for(int i = 0; i < a + b + 1; i++){
    if(i == a){
      if(s[i] != '-'){
        cout << "No" << endl;
        return 0;
      }
    }else{
      t = s[i] - '0';
      if(t < 0 || 9 < t){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    
    int count[100000];
    count[0] = 0;
    for(int i = 0; i < N - 1; i++) {
        if(S[i] == 'A') {
            if(S[i + 1] == 'C') {
                count[i + 1] = count[i] + 1;
            }
            else {
                count[i + 1] = count[i];
            }
        }
        else {
            count[i + 1] = count[i];
        }
    }
    
    for(int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        cout << count[r - 1] - count[l - 1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1408
N, M = map(int, input().split())
pres = {}
cities = {}

for i in range(1, N + 1):
    pres[i] = []

for i in range(1, M + 1):
    p, y = map(int, input().split())
    pres[p].append(i)
    cities[i] = [p, y]

for i in range(1, N + 1):
    pre = pres[i]
    if len(pre) > 0:
        pre.sort(key=lambda city: cities[city][1])
        for j in range(0, len(pre)):
            cities[pre[j]].append(j + 1)

for i in range(1, M + 1):
    city = cities[i]
    print("{:06d}{:06d}".format(city[0], city[2]))
            


Measured memory_bytes: 56036
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long    // %d=>%lld, 1<<n  => 1LL<<n
#define pb push_back

using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
    return firstEl.second > secondEl.second;
}

const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
// const ll LLINF = 1LL << 50;
const double PI = acos(-1);
const double EPS = 0.000000001;


const int MAX_n = 50;
int n,a[MAX_n],b[MAX_n];

bool solve(int mid){
    for(int i = 0;i < n;i++){
        b[i]=a[i];
    }

    int need=0;

    while(1){
        int maxindx = max_element(b,b+n) - b ;

        if(b[maxindx]>=n){
            need+=b[maxindx]/n;
            for(int j = 0;j < n;j++){
                if(maxindx!=j)
                    b[j]+=b[maxindx]/n;
            }
            b[maxindx]-=b[maxindx]/n *n;
        }


        bool f=1;
        for(int i = 0;i < n;i++){
            if(b[i]>=n){
                f=0;
                break;
            }
        }
        if(f){
            break;
        }
    }



    if(need<=mid)
        return 1;
    else {
        return 0;
    }

}

signed main(){

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

    int ok=LLINF;   // 解が存在する値
    int ng=-1;    // 解が存在しない値

    while (abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        if(solve(mid)){
            ok=mid;
        }else{
            ng = mid;
        }
    }

    cout<< ok<< endl;


    return 0;
}

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

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

	vector<int> p;
	int i = 2;
	int nn = n;
	while( nn % i == 0 ) {
		p.push_back( i );
		nn /= i;
	}
	for( i = 3; i * i <= nn; i += 2 ) {
		while( nn % i == 0 ) {
			p.push_back( i );
			nn /= i;
		}
	}
	if( nn != 1 ) p.push_back( nn );

	cout << n << ":";
	for( int i = 0; i < p.size(); i++ ) {
		cout << " " << p[i];
	}
	cout << endl;
}



Measured memory_bytes: 3168
package main

import (
	"fmt"
)

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	inputs := scanNums(M)
	maxL := 1
	minR := N
	for _, v := range inputs {
		L := v[0]
		R := v[1]
		if maxL <= L {
			maxL = L
		}
		if minR >= R {
			minR = R
		}
		// fmt.Println(L, R, maxL, minR)
	}

	res := minR - maxL + 1
	if res < 0 {
		res = 0
	}
	fmt.Println(res)

}

func scanNums(len int) (nums [][]int) {
	var numL, numR int

	for i := 0; i < len; i++ {
		fmt.Scan(&numL, &numR)
		LR := make([]int, 0)
		LR = append(LR, numL)
		LR = append(LR, numR)
		nums = append(nums, LR)
	}
	return
}


Measured memory_bytes: 12928
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		boolean bool = true;
		loop: for (int i = 1; i <= 1010; i++) {
			int k1 = (int) (i * 0.08);
			int k2 = (int) (i * 0.1);

			if (k1 == a && k2 == b) {
				bool = false;
				System.out.println(i);
				break loop;
			}
		}

		if (bool) {
			System.out.println("-1");
		}

		sc.close();
	}
}

Measured memory_bytes: 21972
#!/usr/bin/env python

def main():
    t = input()
    t_list = ['D']
    cnt = 0
    for s in t:
        if s == '?':
            cnt += 1
        else:
            if cnt > 0:
                t_list.append(cnt)
            cnt = 0
            t_list.append(s)
    if cnt > 0:
        t_list.append(cnt)
    t_list.append('P')

    for i in range(len(t_list)):
        if isinstance(t_list[i], int):
            k = t_list[i] // 2
            if t_list[i] % 2 == 0:
                if t_list[i-1] == 'P':
                    t_list[i] = 'D' + 'PD' * (k-1)
                    if t_list[i+1] == 'P':
                        t_list[i] += 'D'
                    else:
                        t_list[i] += 'P'
                else:
                    t_list[i] = 'PD' * k
            else:
                if t_list[i-1] == 'P':
                    t_list[i] = 'D' + 'PD' * k
                else:
                    t_list[i] = 'PD' * k
                    if t_list[i+1] == 'P':
                        t_list[i] += 'D'
                    else:
                        t_list[i] += 'P'

    print(''.join(t_list[1:-1]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 12940
#include <iostream>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int mat[n][m];
	for(int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> mat[i][j];
		}
	}
	int vec[m];
	for(int i = 0; i< m; i++){
		cin >> vec[i];
	}
	int sigma = 0, answer[m];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			sigma += mat[i][j] * vec[j];
		}
		cout << sigma << endl;
		sigma = 0;
	}
	
}

Measured memory_bytes: 1200
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
from collections import Counter

N = int(input())
A = Counter(inpl())
ans = 0

for k, v in A.items():
    if k < v:
        ans += (v-k)
    elif k > v:
        ans += v

print(ans)

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

int main(){
    int A, B;
    cin >> A >> B;
    int outlet = 1;
    int ans = 0;
    while(outlet < B){
        //cout << A+(A-1)*i << endl;
        outlet--;
        outlet += A;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

namespace AtCoder.Abc
{
    class A_167_Registration
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();
            string t = Console.ReadLine();


            //if (t.Contains(s) == true &&
            //    s.Length + 1 == t.Length)
            //{
            //    Console.WriteLine("yes");
            //}
            //else
            //{
            //    Console.WriteLine("no");
            //}

            string result = "Yes";
            if (t.Length - s.Length != 1)
            {
                result = "No";
            }
            else
            {
                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i] != t[i])
                    {
                        result = "No";
                        break;
                    }
                }
            }


            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25848
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top,S[1000];
void push(int x){
S[++top]=x;
}
int pop(){
top--;
return S[top+1];
}
int main(){
int a,b;
top=0;
char s[100];
while(scanf("%s",s)!=EOF){
if(s[0]=='+'){
a=pop();
b=pop();
push(a+b);
}else if(s[0]=='-'){
a=pop();
b=pop();
push(b-a);
}else if(s[0]=='*'){
a=pop();
b=pop();
push(a*b);
}else{
push(atoi(s));
}
}
printf("%d\n",pop());
return 0;
}



Measured memory_bytes: 2744
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemA solver = new ProblemA();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			char[] s = in.next().toCharArray();
			for (int i = 0; i < s.length; i++) {
				for (int j = i + 1; j < s.length; j++) {
					if (s[i] == 'C' && s[j] == 'F') {
						out.println("Yes");
						return;
					}
				}
			}
			out.println("No");
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

	}
}



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

def solve(N: int, S: str):
    answer = 0
    for i in range(0,1000):
        i = str(i).zfill(3)
        index = 0
        for ss in S:
            if ss == i[index]:
                index += 1
                if index >= 3:
                    answer += 1
                    break

    print(answer)
    return


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
    S = next(tokens)  # type: int
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 1e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

vector<int> divisor(int n){
  vector<int> ret;
  for(int i = 0;i * i <= n;i++){
    ret.push_back(i);
    if(i*i != n) ret.push_back(i);
  }
  sort(ALL(ret));
  return ret;
}

signed main()
{
  ios();
  int A,B;
  cin >> A >> B;
  if(A >= 13) {
    cout << B << endl;
  } else if (A >= 6) {
    cout << B/2 << endl;
  } else {
    cout << 0 << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pr(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define Toggle(n,i) (n^(1<<i))
#define Check(n,i) (n&(1<<i))
#define Set(n,i) (n|(1<<i))
#define Reset(n,i) (n&(~(1<<i)))
#define fo(a,x,y) for(int i=(x);i<=(y);++i){cout<<a[i]<<" ";}cout<<endl;
#define me(arr,val) memset(arr,val,sizeof arr)
#define inf 10e8
#define infd DBL_MAX
#define infl LLONG_MAX
#define mod 1000000007
#define f first
#define s second
#define  g(t,a)  (get<a>(t))
#define pra(a) for(auto i:a){cout<<i<<endl;}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
//int dx[]={+1,-1,0,0};//vertical horizontal
//int dy[]={0,0,+1,-1};//vertical horizontal
//int dx[]={+1,+1,-1,-1,+2,-2,+2,-2};//knights move
//int dy[]={+2,-2,+2,-2,+1,+1,-1,-1};//knights move
//int dx[]={+1,-1,0,0,+1,+1,-1,-1};//vertical horizontal diagonal
//int dy[]={0,0,+1,-1,-1,+1,+1,-1};//vertical horizontal diagonal
using namespace std;
using namespace __gnu_pbds;
/*typedef tree<int, null_type,less<int>, rb_tree_tag,
             tree_order_statistics_node_update>indexed_set;
for set use above*/
typedef tree<pair<int,int>, null_type,less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update> indexed_multiset;


int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    printf("%lld",max(a*c,max(a*d,max(b*c,b*d))));
    return 0;
}



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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;

int main(int argc, char *argv[]) {
    ll a, b, c;
    cin >> a >> b >> c;
    YN(b-a == c-b)
    
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n;
  cin >> k;
  long long res = k;
  for(int i = 1 ; i < n; ++i)res *= k-1;
  cout << res << endl;
  return 0;
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

inline bool is_in(const int x, const int a, const int b) {
    return a <= x && x <= b;
}

int main() {
    int n;
    cin >> n;
    vi h(n);
    string ans = "Yes";
    bool dflg = false;
    int tmp = -1;
    REP(i, n) {
        cin >> h[i];
        if(i > 0) {
            // DBG(tmp);
            int d = h[i] - h[i - 1];
            if(tmp > h[i]) {
                ans = "No";
                break;
            }
            if(d >= 2) tmp = h[i] - 1;
        }
        else tmp = h[i];
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  map<int,long> m;
  int n;
  long k;
  cin>>n>>k;
  rep(i,n){
    int a,b;
    cin>>a>>b;
    m[a] += b;
  }

  long acc = 0;
  for(auto p : m){
    acc += p.se;
    if(acc >= k){
      cout << p.fi << endl;
      return 0;
    }
  }
  assert(false);

  return 0;
}


Measured memory_bytes: 4224
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(m)]
l=[0]*n

for i in range(n):
    for j in range(m):
        if i+1 in a[j]:
            l[i]+=1
for i in range(n):
    print(l[i])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
signed main(){
  ll n,a,b;
  cin>>n;
  if(n>=500){
	a = n / 500;
    b = n - a * 500;
    if(n>=5){
	 b = b / 5;
     cout<<a*1000+b*5<<"\n";
    }else{
     cout<<a*10000<<"\n";
    }
  }else{
    a = n /5;
    cout<<a*5<<"\n";
  }
  return(0);
}  

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadInt;
			var A = cin.ReadLongArray(N);
			long Res = A.Sum(a => Abs(a));
			var hasZero = Enumerable.Range(0, N).Any(i => A[i]==0);
			if(!hasZero) {
				var negas = A.Count(a => a<0);
				if(negas%2!=0)
					Res-=2*A.Select(a => Abs(a)).Min();
			}
			Console.WriteLine(Res);
		}
	}
	static class ExtendClass {
		public static void Swap<T>(this T[] A, int x, int y) {
			var tmp = A[x];
			A[x]=A[y];
			A[y]=tmp;
		}
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		public static IEnumerable<int> Indices<T>(this T[] X) => Enumerable.Range(0, X.Length);
		public static IEnumerable<int> Indices<T>(this T[,] X, int dim)
			=> Enumerable.Range(0, X.GetLength(dim));
		public static string Join<T>(this T[,] X, string separatorD2 = ",", string separatorD1 = "\n")
			=> X.Indices(0).Select(
				i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2)
			).Join(separatorD1);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}

}

Measured memory_bytes: 31196
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a



N = int(input())
A = list(map(int,input().split()))
#単純に最大公約数を算出すればよい

kari = A[0]
for i in range(N):
    kari = gcd(kari, A[i])

 


print(kari)

Measured memory_bytes: 14252
#include <iostream>

using namespace std;

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

  int sum = 0;
  int max = 0;
  int p[11];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    if (p[i] > max)
      max = p[i];
    sum += p[i];
  }

  cout << sum - max / 2 << endl;

  return 0;
}

Measured memory_bytes: 256
// 問題の URL を書いておく
// 

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <numeric>
using namespace std;

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

int main(int, const char**)
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}


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

using namespace std;

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

  int N; cin>>N;
  map<int, int> cards;
  for (int i = 0; i < N; i++) {
    int a; cin>>a;
    cards[a]++;
  }
  map<int, int> ccmap;
  for (auto& c : cards) {
    ccmap[c.second]++;
  }
  vector<int> cd(N+1);
  cd[0] = 0;
  vector<int> ckd(N+1);
  ckd[0] = 0;
  for (int i = 1; i < N+1; i++) {
    cd[i] = cd[i-1] + ccmap[i];
    ckd[i] = ckd[i-1] + i * ccmap[i];
  }

  auto max_len_div = [&](int div) {
    return floor(float(ckd[div] + div*(cd[N] - cd[div])) / div);
  };
  for (int k = 1; k <= N; k++) {
    int l = 1, r = N;
    int res = 0;
    while (l <= r) {
      int c = (l+r)/2;
      if (max_len_div(c) >= k) {
        l = c+1;
        res = c;
      } else {
        r = c-1;
      }
    }
    cout << res << endl;
  }

  return 0;
}


Measured memory_bytes: 30208
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())
F = [0]*N
ans = 0
for i in range(N):
    t = T[i]
    if i < K:
        if t == 'r':
            ans += P
            F[i] = 1
        elif t == 's':
            ans += R
            F[i] = 1
        else:
            ans += S
            F[i] = 1
    elif t == 'r':
        if T[i-K] == 'r':
            if F[i-K] == 0:
                ans += P
                F[i] = 1
        else:
            ans += P
            F[i] = 1
    elif t == 's':
        if T[i-K] == 's':
            if F[i-K] == 0:
                ans += R
                F[i] = 1
        else:
            ans += R 
            F[i] = 1
    else:
        if T[i-K] == 'p':
            if F[i-K] == 0:
                ans += S
                F[i] = 1
        else:
            ans += S 
            F[i] = 1
print(ans)

Measured memory_bytes: 50288
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans=n;
    char temp=s[0];
    for(int i=1;i<n;i++){
        if(temp==s[i]){
            ans--;
        }else{
            temp=s[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>

using namespace std;
using i64 = long long int;
using P = pair<i64, i64>;

i64 gcd(i64 a, i64 b){
    //
    // Euclidean Algorithm (かっこいい) O(logN)
    // i64 a, b: GCDを求める数 a > b を仮定している
    //
    if(a % b == 0) return b;
    else return gcd(b, a % b);
}

i64 lcm(i64 a, i64 b){
    //
    // a * b / gcd(a, b) O(logN)
    //
    return a * b / gcd(a, b);
}

i64 modpow(i64 x, i64 n){
    //
    // 繰り返し二乗法 O(logN)
    // i64 x, n: x^n mod 1e9+7 を求める modの値の変え忘れに注意(modを渡すべき?)
    //
    const i64 mod = 1000000007;
    i64 res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

map<i64, i64> prime_factorize(i64 n){
    // 
    // ひたすら割るやつ O(n^(1/2))
    // i64 n : 素因数を求める数
    // map<i64, i64> は range-based for を使うと楽(C++11~?)
    //
    map<i64, i64> mp;
    for(i64 i = 2;  i * i <= n; ++i){
        while(n % i == 0){
            mp[i]++;
            n /= i;
        }
    }
    if(n != 1) mp[n] = 1;
    return mp;
}

i64 phi(i64 n){
    // 
    // オイラーのトーシェント関数 O(n^(1/2))
    // 素因数ごとに減らしていく感じ
    // prime_factorize が必要
    map<i64, i64> factors = prime_factorize(n);
    i64 res = n;
    for(auto f: factors){
        res -= res / f.first;
    }
    return res;
}

void NTL_1_A(){
    i64 n;
    cin >> n;
    auto factors = prime_factorize(n);
    cout << n << ':';
    for(auto f : factors){
        for(int i = 0; i < f.second; ++ i){
            cout << ' ' << f.first;
        }
    }
    cout << endl;
}

void NTL_1_B(){
    i64 m, n;
    cin >> m >> n;
    cout << modpow(m, n) << endl;
}

void NTL_1_C(){
    i64 n;
    cin >> n;
    vector<i64> a(n);
    i64 ans = 1;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        ans = lcm(ans, a[i]);
    }
    cout << ans << endl;
}

void NTL_1_D(){
    i64 n;
    cin >> n;
    cout << phi(n) << endl;
}

int main(){
    /* NTL_1_A(); /* https://onlinejudge.u-aizu.ac.jp/status/users/kobaryo222/submissions/1/NTL_1_A/judge/3892592/C++14 */
    /* NTL_1_B(); /* https://onlinejudge.u-aizu.ac.jp/status/users/kobaryo222/submissions/1/NTL_1_B/judge/3892552/C++14 */
    /* NTL_1_C(); /* https://onlinejudge.u-aizu.ac.jp/status/users/kobaryo222/submissions/1/NTL_1_C/judge/3892620/C++14 */
    NTL_1_D();
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

using namespace std;

int main()
{
  int N,Y;
  cin>> N>> Y;

  string ret="-1 -1 -1";
  for(int i=0;i<=N;i++)
  for(int j=0;j<=N-i;j++)
  {
    if(i*10000+j*5000+(N-i-j)*1000==Y)ret=to_string(i)+" "+to_string(j)+" "+to_string(N-i-j);
  }
  cout<< ret<< endl;

  return 0;
}


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

long long n, x;
long long v[55];
typedef pair<long long, long long> P;
map<P, long long> m;

long long f(long long a, long long b){
	if(a == 0) return b == 0 ? 0 : 1;
	if(b == 0) return 0;
	if(m.find(P(a, b)) != m.end())
		return m[P(a, b)];
	long long res = 0;
	if(b >= v[a-1] + 2){
		++res;
		res += f(a-1, min(b-v[a-1]-2, v[a-1]));
	}
	res += f(a-1, min(b-1, v[a-1]));
//	cout << a << " " << b << " " << res << "\n";
	m[P(a, b)] = res;
	return res;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> x;
	v[0] = 1;
	for(int i=1; i<=n; ++i)
		v[i] = 2*v[i-1] + 3;
	cout << f(n, x) << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
  int i,num,count,j,sosunum;
  char s[20]="kakikukeko~~";
  char buf[20];
  strcpy(buf,s);
  scanf("%d",&num);
  int a[num];
  double a2[num];
  for(i = 0 ; i< num ; i++){
    scanf("%d",&a[i]);
    if(a[i]< 2) count++;
    else if(a[i] ==2 ) {}
    else if(a[i]% 2 ==0 ) count++;
   else{
     
     for(j = 3 ; j<= sqrt(a[i]); j+=2){
      if(a[i] % j ==0){
      count++;
      break;
      }
    }
  }
  }
  sosunum = num - count;
  printf("%d\n",sosunum);
  return 0;
}


Measured memory_bytes: 2084
from itertools import takewhile


def prime_cnt(x):
    y = x
    ret = 0
    while y <= n:
        z = y
        while True:
            ret += 1
            z //= x
            if z == 0 or z % x:
                break
        y += x
    return ret


n = int(input())
ps = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
pc = list(map(prime_cnt, ps))

l2 = len(list(takewhile(lambda x: x >= 2, pc)))
l4 = len(list(takewhile(lambda x: x >= 4, pc)))
l14 = len(list(takewhile(lambda x: x >= 14, pc)))
l24 = len(list(takewhile(lambda x: x >= 24, pc)))
l74 = len(list(takewhile(lambda x: x >= 74, pc)))
ans = l4 * max(0, l4 - 1) * max(0, l2 - 2) // 2
ans += l14 * max(0, l4 - 1)
ans += l24 * max(0, l2 - 1)
ans += l74

print(ans)


Measured memory_bytes: 3064
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let v = scan!(;;);
    if v[0] == v[1] {
        println!("H")
    } else {
        println!("D")
    }
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll N;
	cin >> N;
	ll K;
	cin >>K;
	vector<ll> v;
	for(int i = 0; i<N;i++)
	{
		ll temp;
		cin >> temp;
		temp--;
		v.push_back(temp);
	}
	ll count = 0;
	int i = 0;
	int arr[N] = {0};
	arr[0] = 1;
	ll cycle = 0;
	while(1)
	{
		i = v[i];
		if(arr[i] == 1)
		{
			cycle = i;
			break;	
		}
		arr[i] = 1;
	}
	ll d = 0;
	i = 0;
	while(cycle != 0)
	{
		i = v[i];
		d++;
		if(i == cycle)
			break;
	}
	i = cycle;
	while (1)
	{
		i = v[i];
		count++;
		if(i == cycle)
			break;
	}
	if(K <= d)
	{
		int ans = 0;
		for(int i = 0; i<K;i++)
		{
			ans = v[ans];
		}
		cout<<ans+1<<endl;
		return 0;
	}
	K -= d;
	K = K%count;
	int ans = cycle;
	while(K--)
	{
		ans = v[ans];
	}
	cout <<ans+1	<<endl;
}


Measured memory_bytes: 5904
#include<cstring>
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
#include<set>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define low(x) (x&(-x)) 
#define maxn 200500
#define inf 1152921504606846976
#define mm 1000000007
#define ll long long
using namespace std;

int read(){
    int x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
struct data{ll x;int id;
bool friend operator <(data a,data b){
	return a.x<b.x||(a.x==b.x&&a.id<b.id);
} 
};
multiset<data> q1,q2,q3;
struct node{ll a,b,c;
}a[maxn];
bool cmp(node a,node b){
	return a.b-a.a>b.b-b.a;
}
int n,x,y,z;
ll ans;
int main(){
//	freopen("in.txt","r",stdin);
	x=read(); y=read(); z=read();
	n=x+y+z;
	rep(i,1,n) {
	//	a[i].a=read(); a[i].b=read(); a[i].c=read();
		scanf("%lld%lld%lld",&a[i].a,&a[i].b,&a[i].c);
		ans+=a[i].a;
	} 
	sort(a+1,a+1+n,cmp);
	rep(i,1,y) ans+=a[i].b-a[i].a,q1.insert((data){a[i].c-a[i].b,i});
	rep(i,y+1,n) q2.insert((data){a[i].b-a[i].a,i}),q3.insert((data){a[i].c-a[i].a,i});
	rep(i,1,z) {
		ll p1=(*q1.rbegin()).x+(*q2.rbegin()).x;
		ll p2=(*q3.rbegin()).x;
		if (p1>p2) {
			ans+=p1;
			int pos=(*q2.rbegin()).id;
			q1.insert((data){a[pos].c-a[pos].b,pos});
			q3.erase(q3.lower_bound((data){a[pos].c-a[pos].a,pos}));
			q1.erase(q1.lower_bound(*q1.rbegin()));
			q2.erase(q2.lower_bound(*q2.rbegin()));
		}
		else {
			ans+=p2;
			int pos=(*q3.rbegin()).id;
			q3.erase(q3.lower_bound(*q3.rbegin()));
			q2.erase(q2.lower_bound((data){a[pos].b-a[pos].a,pos}));
		}
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 16768
#include <stdio.h>
#include <math.h>
 
int main(void){
        int i,n,poi[1000];
        while(1){
                double std,ave=0,a=0;
                scanf("%d",&n);
                if(!n)
                        break;
                for(i=0;i<n;i++){
                        scanf("%d",&poi[i]);
                        ave+=poi[i];
                }
                ave/=n;
                for(i=0;i<n;i++)
                        a+=pow((poi[i]-ave),2);
                a/=n;
                std=sqrt(a);
                printf("%f\n",std);
        }
        return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    string s;
    cin >> s;
    rep(i,3){
        if(s[i]==s[i+1]){
            cout << "Bad\n";
            return 0;
        }
    }
    cout << "Good\n";
    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
map<string,int>m;
int n,top;
string s[200005];
char ch[105];
int main(){
	in(n);
    for(int i=1;i<=n;i++){
        scanf("%s",ch);
        string ss=ch;
        if(!m[ss]){
            s[++top]=ss;
            m[ss]=1;
        }
        else m[ss]++;
    }
    sort(s+1,s+1+top);
    int ans=0;
    for(int i=1;i<=top;i++)ans=max(ans,m[s[i]]);
    for(int i=1;i<=top;i++){
        if(m[s[i]]==ans){
            int len=s[i].size();
            for(int j=0;j<len;j++){
                char cc=s[i][j];
                printf("%c",cc);
            }
            puts("");
        }
    }
	return 0;
}//


Measured memory_bytes: 34816
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {
    
    int n, m; cin >> n >> m;

    int cnt[n+1]; rep(i,n+1) cnt[i] = 0;
    rep(i,m) {
        int a, b; cin >> a >> b;
        ++cnt[a];
        ++cnt[b];
    }
    for (int i = 1; i <= n; ++i) out(cnt[i]);

    
    return 0;
}






Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
def cumsum(a):
    """※ aを破壊する
    l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    n = len(a)
    a.insert(0, 0)
    for i in range(1, n+1):
        a[i] = a[i-1]+a[i]
    return a
cumsum(a)
from collections import Counter
c = Counter([(item%m) for item in a])
ans = sum((v*(v-1)//2) for v in c.values())
print(ans)

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

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

    int n = s.length();

    for(int i=0; i<=7; i++){
        string test = s.substr(0,i) + s.substr(n-7+i,7-i);
        if(test == "keyence"){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3592