akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
typedef complex<double> P;
 
const double eps = 1e-10;
 
bool equals(double a, double b, double eps = 1e-10) {
  return abs(a-b) < eps;
}
 
double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}
 
double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}
 
int ccw(P p, P a, P b) {
  a -= p;
  b -= p;
  if(cross(a,b) > eps) return 1;
  if(cross(a,b) < -eps) return -1;
  if(dot(a,b) < -eps) return 2;
  if(norm(b)-norm(a) > eps) return -2;
  return 0;
}
 
P getCrossP(P a1, P a2, P b1, P b2) {
  P a = a2 - a1;
  P b = b2 - b1;
  return a1 + a * cross(b, b1 - a1)/cross(b, a);
}
 
double getArea(const vector<P> &ps) {
  int n = ps.size();
  double res = 0;
  for(int i = 0; i < ps.size(); ++i) {
    res += cross(ps[i], ps[(i+1)%n]);
  }
  return res / 2.0;
}
 
vector<P> convex_cut(vector<P> ps, P p1, P p2, int dir = -1) {
  vector<P> v;
  for(int i = 0; i < ps.size(); ++i) {
    P a = ps[i];
    P b = ps[(i+1)%ps.size()];
    if(ccw(p1, p2, a) != dir) v.push_back(a);
    if(ccw(p1, p2, a)*ccw(p1, p2, b) == -1)
      v.push_back(getCrossP(a, b, p1, p2));
  }
  return v;
}
 
int main() {
  int N; cin >> N;
  vector<P> ps(N);
  for(int i = 0; i < N; ++i) {
    cin >> ps[i].real() >> ps[i].imag();
  }
  if(getArea(ps) < 0) reverse(ps.begin(), ps.end());
  double S = getArea(ps);
  double x = 0, y = 0;
  for(int i = 0; i < N; ++i) {
    x += ps[i].real();
    y += ps[i].imag();
  }
  x /= N;
  y /= N;
  P g(x, y);
  bool flag = true;
  for(int k = 0; k < 100000; ++k) {
    double rad = (double)rand()/(double)RAND_MAX * (double)M_PI;
    P t = g + P(cos(rad), sin(rad));
    if(!equals(getArea(convex_cut(ps, g, t)), S/2.0, 1e-3)) {
      flag = false;
      break;
    }
  }
  if(flag) {
    printf("%.10f %.10f\n", g.real(), g.imag());
  } else {
    printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 1264
r, c = [int(i) for i in input().split()]

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

print(" ".join([str(s) for s in sum_row]))

Measured memory_bytes: 7660
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

    vector<vector<int>> x(n+5);
    vector<vector<int>> y(n+5);

    rep(i, n){
        int a;
        cin >> a;
        rep(j, a){
            int dx, dy;
            cin >> dx >> dy;
            dx--;
            x[i].push_back(dx);
            y[i].push_back(dy);
        }
    }


    int ans = 0;

    rep(i, (1<<n)){
        bool flg = true;
        int cnt = 0;
        rep(j, n)if(i&(1<<j)){
            cnt++;
            rep(k, x[j].size()){
                if(y[j][k]==1){
                    if(!(i&(1<<x[j][k])))flg=false;
                }
                else{
                    if(i&(1<<x[j][k]))flg=false;
                }
            }
        }
        if(flg)ans  = max(ans, cnt);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))

A=list(map(lambda  x: x*(-1),A))
heapq.heapify(A)

for j in range(M):
    n=heapq.heappop(A)
    heapq.heappush(A,-(-n//2))

print(sum(list(map(lambda x: x*(-1),A))))

Measured memory_bytes: 14180
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define MAX_N 1000
#define MAX_M 200
typedef pair<int, int> P;

bool comp(const P &p1, const P &p2) {
	return p1.first < p2.first || (p1.first == p2.first&&p1.second < p2.second);
}

bool C(P p1, P p2, int dx, int dy) {
	return (p1.first + dx < p2.first) || (p1.first + dx == p2.first&&p1.second + dy < p2.second);
}

int main() {
	P cel[MAX_N], con[MAX_M];
	int m, n;
	int dx, dy;
	bool made;
	int ub, lb, mid;

	while (true) {
		scanf("%d", &m);
		if (m == 0) break;
		for (int i = 0;i < m;i++) {
			scanf("%d%d", &con[i].first, &con[i].second);
		}
		scanf("%d", &n);
		for (int i = 0;i < n;i++) {
			scanf("%d%d", &cel[i].first, &cel[i].second);
		}

		sort(cel, cel + n, comp);
		sort(con, con + m, comp);
		for (int i = 0;i < n;i++) {
			dx = cel[i].first - con[0].first;
			dy = cel[i].second - con[0].second;
			made = true;
			for (int j = 1;j < m;j++) {
				ub = n; lb = 0;
				while (ub - lb > 1) {
					mid = (ub + lb) / 2;
					if (C(con[j], cel[mid], dx, dy)) {
						ub = mid;
					}
					else {
						lb = mid;
					}
				}
				if (con[j].first + dx != cel[lb].first || con[j].second + dy != cel[lb].second) {
					made = false;
					break;
				}
			}
			if (made) {
				printf("%d %d\n", dx, dy);
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1040
#include <stdio.h>

int main(void)
{
	int n,count;
	char s[110];
	
	count=0;
	
	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		scanf("%c",&(s[i]));
	}
	
	for(int i=0;i<n;i++){
		if(s[i]=='Y'){
			count++;
			break;
		}
	}
	
	if(count!=0){
		printf("Four\n");
	}else{
		printf("Three\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

vector<pair<int, int> > edge;

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int N;
	scanf("%d", &N);
	int t = 1;
	while(t <= N) {
		if(t == N) {
			puts("No");
			return 0;
		}
		t <<= 1;
	}
	for(int i = 1; i < 3; i++) {
		edge.push_back(make_pair(i, i + 1));
		edge.push_back(make_pair(i + N, i + N + 1));
	}
	edge.push_back(make_pair(3, N + 1));
	for(int i = 4; i + 1 <= N; i += 2) {
		edge.push_back(make_pair(1, i));
		edge.push_back(make_pair(i, i + 1));
		edge.push_back(make_pair(1, N + i + 1));
		edge.push_back(make_pair(N + i, N + i + 1));
	}
	if(N % 2 == 0) {
		for(int i = 2; i < N; i++) {
			int a = N ^ i ^ 1, b = i;
			if(1 <= a && a < N) {
				if(a == b) continue;
				if(a & 1) edge.push_back(make_pair(N + a, N));
				else edge.push_back(make_pair(a, N));
				if(b & 1) edge.push_back(make_pair(N + b, 2 * N));
				else edge.push_back(make_pair(b, 2 * N));
				break;
			}
		}
	}
	puts("Yes");
	for(int i = 0; i < (int)edge.size(); i++)
		printf("%d %d\n", edge[i].first, edge[i].second);
	return 0;
}

Measured memory_bytes: 3952
/*input
1 100 1
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	int l, r, d;
	cin >> l >> r >> d;
	cout << r / d - (l - 1) / d << "\n";
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main() {
    int top[3] {};

    for (int i = 0; i < 10; ++i) {
        int h;
        cin >> h;

        if (h > top[2]) {
            if (h > top[1]) {
                top[2] = top[1];
                if (h > top[0]) {
                    top[1] = top[0];
                    top[0] = h;
                }
                else top[1] = h;
            }
            else top[2] = h;
        }

    }

    for (auto t : top) {
        cout << t << endl;
    }
}

Measured memory_bytes: 3080
# coding: utf-8
def main():
    a, b = map(int, input().split())
    c = a*12.5//10 * 10
    for i in range(20):
        if (c+i)*0.08//1 == a and (c+i)*0.1//1 == b:
            print(int(c+i))
            quit()
    print(-1)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<int,int> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}



int n;
int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		Pi tt[11];
		for(int i=0;i<n;i++){
			string t;
			cin>>t;
			int se=t.size()-1;
			int l;
			if(t[se]=='+'){
				l=11;
			}else if(t[se]=='*'){
				l=12;
			}else{
				l=t[se]-'0';
			}
			tt[i]=Pi(se,l);
		}
		stack<Pi> ss;
		for(int i=n-1;i>=0;i--){
			if(tt[i].second!=11&&tt[i].second!=12){
				ss.push(tt[i]);
			}else if(tt[i].second==11){
				int q=0;
				while(ss.size()&&ss.top().first==tt[i].first+1){
					q+=ss.top().second;
					ss.pop();
				}
				ss.push(Pi(tt[i].first,q));
			}else{
				int q=1;
				while(ss.size()&&ss.top().first==tt[i].first+1){
					q*=ss.top().second;
					ss.pop();
				}
				ss.push(Pi(tt[i].first,q));
			}
		}
		cout<<ss.top().second<<endl;
	}
	return 0;
}


Measured memory_bytes: 3144
# coding : utf-8
list = []
for i in range(3000):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        break
    list.append([x, y])
for x, y in list:
    if x < y:
        print (x, y)
    else:
        print (y, x)


Measured memory_bytes: 6132
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 8005*2;

bool check(vector<int> &X, int val){
//	for(int c : X) printf("%d ", c); printf("\n%d\n", val);
	int arr[2][MX] = {};
	int *S = arr[0], *E = arr[1];
	S[MX/2] = 1;
	for(int c : X){
		for(int i = 0; i < MX; i++) E[i] = 0;
		for(int i = 0; i < MX; i++){
			if( i >= c ) E[i] |= S[i-c];
			if( i+c < MX ) E[i] |= S[i+c];
		}
		swap(S, E);
	}
	return S[MX/2 + val];
}

int main()
{
	string D;
	int X, Y;
	cin >> D >> X >> Y;
	vector<int> H, V;
	for(int i = 0; i <= D.size(); i++){
		if( i < D.size() && D[i] == 'F' ) X--;
		else{
			D = D.substr(i, -1);
			break;
		}
	}
	int cnt = 0, flag = 1;
	for(int i = 0; i <= D.size(); i++){
		if( i < D.size() && D[i] == 'F' ) cnt++;
		else{
			if( !cnt );
			else if( flag ) H.push_back(cnt);
			else V.push_back(cnt);
			flag ^= 1; cnt = 0;
		}
	}
	if( check(V, Y) && check(H, X)) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 384
num = int(input())
ab=[]
ab2 = []
ab3 = []

x = list(map(int,input().split()))
y = list(map(int,input().split()))
#x = np.array(x)
#y = np.array(y)
for i in range(num):
    ab.append(abs(x[i]-y[i]))
    ab2.append(abs(x[i]-y[i])**2)
    ab3.append(abs(x[i]-y[i])**3)

print("{:.8f}".format(sum(ab)))
print("{:.8f}".format((sum(ab2))**(1/2)))
print("{:.8f}".format((sum(ab3))**(1/3)))
print("{:.8f}".format(max(ab)))


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

int main(){
    int n, A[5][4][11];//b棟f階r部屋v人数
    for(int b=1;b<=4;b++){
        for(int f=1;f<=3;f++){
            for(int r=1;r<=10;r++){
                A[b][f][r]=0;
            }
        }
    }
    cin>>n;
    int b,f,r,v;
    for(int i=0;i<n;i++){
        cin>>b>>f>>r>>v;
        A[b][f][r]+=v;
    }
    for(int b=1;b<=4;b++){
        if(b!=1)cout<<"####################"<<endl;
        for(int f=1;f<=3;f++){
            for(int r=1;r<=10;r++){
                cout<<" "<<A[b][f][r];
                
            }
            cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String line = sc.nextLine();
		String[] lines = line.split(",");
		for(String i:lines){
			System.out.print(i + " ");
		}
		sc.close();
	}
}


Measured memory_bytes: 9680
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

h,w = li()
grid = [li() for _ in range(h)]
ans_list = []

for hi in range(h):
    for wj in range(w):
        grid[hi][wj] %= 2

for hi in range(h):
    if hi%2 == 1:
        grid[hi] = grid[hi][::-1]
        

        
for hi in range(h):
    for wj in range(w):
        if grid[hi][wj] == 1:
            if wj < w-1:
                grid[hi][wj+1] = (grid[hi][wj+1]+1) % 2
                if hi%2 == 0:
                    ans_list.append((hi+1, wj+1, hi+1, wj+2))
                else:
                    ans_list.append((hi+1,w-wj, hi+1, w-wj-1))
                
            elif wj == w-1:
                if hi == h-1:
                    break
                
                grid[hi+1][0] = (grid[hi+1][0]+1) % 2
                if hi%2 == 0:
                    ans_list.append((hi+1, w, hi+2, w))
                else:
                    ans_list.append((hi+1,1, hi+2, 1))

print(len(ans_list))
for ans in ans_list:
    print(*ans)

Measured memory_bytes: 26596
Module _20191116

    Sub Main()
        'https://atcoder.jp/contests/abc108/tasks/abc108_b

        Dim sRead As String = Console.ReadLine()

        Dim iZahyou1 As Integer() = {Split(sRead, " ")(0), Split(sRead, " ")(1)}
        Dim iZahyou2 As Integer() = {Split(sRead, " ")(2), Split(sRead, " ")(3)}
        Dim iZahyou3 As Integer() = {0, 0}
        Dim iZahyou4 As Integer() = {0, 0}

        '移動距離
        Dim iNagasaX As Integer = iZahyou2(0) - iZahyou1(0)
        Dim iNagasaY As Integer = iZahyou2(1) - iZahyou1(1)

        If iNagasaX <= 0 AndAlso iNagasaY <= 0 Then
            'X方向マイナス、Y方向マイナスの場合はX方向にY移動距離をプラス、Y方向にX移動距離をマイナス
            iZahyou3(0) = iZahyou2(0) + Math.Abs(iNagasaY)
            iZahyou3(1) = iZahyou2(1) - Math.Abs(iNagasaX)
            iZahyou4(0) = iZahyou1(0) + Math.Abs(iNagasaY)
            iZahyou4(1) = iZahyou1(1) - Math.Abs(iNagasaX)
        ElseIf iNagasaX <= 0 AndAlso iNagasaY > 0 Then
            'X方向マイナス、Y方向プラスの場合はX方向にY移動距離をマイナス、Y方向にX移動距離をマイナス
            iZahyou3(0) = iZahyou2(0) - Math.Abs(iNagasaY)
            iZahyou3(1) = iZahyou2(1) - Math.Abs(iNagasaX)
            iZahyou4(0) = iZahyou1(0) - Math.Abs(iNagasaY)
            iZahyou4(1) = iZahyou1(1) - Math.Abs(iNagasaX)
        ElseIf iNagasaX > 0 And iNagasaY <= 0 Then
            'X方向プラス、Y方向マイナスの場合はX方向にY移動距離をプラス、Y方向にX移動距離をプラス
            iZahyou3(0) = iZahyou2(0) + Math.Abs(iNagasaY)
            iZahyou3(1) = iZahyou2(1) + Math.Abs(iNagasaX)
            iZahyou4(0) = iZahyou1(0) + Math.Abs(iNagasaY)
            iZahyou4(1) = iZahyou1(1) + Math.Abs(iNagasaX)
        ElseIf iNagasaX > 0 And iNagasaY > 0 Then
            'X方向プラス、Y方向プラスの場合はX方向にY移動距離をマイナス、Y方向にX移動距離をプラス
            iZahyou3(0) = iZahyou2(0) - Math.Abs(iNagasaY)
            iZahyou3(1) = iZahyou2(1) + Math.Abs(iNagasaX)
            iZahyou4(0) = iZahyou1(0) - Math.Abs(iNagasaY)
            iZahyou4(1) = iZahyou1(1) + Math.Abs(iNagasaX)
        End If

        Console.WriteLine(iZahyou3(0) & " " & iZahyou3(1) & " " & iZahyou4(0) & " " & iZahyou4(1))

    End Sub

End Module

Measured memory_bytes: 13532
#include <iostream>
#include <cstring>

using namespace std;

int main(void)
{
	int n, m, Num[55];
	memset(Num, 0, sizeof(Num));
	cin >> n >> m;
	while (m--)
	{
		int a, b;
		cin >> a >> b;
		Num[a]++;
		Num[b]++;
	}
	for (int i = 1; i <= n; i++)
	{
		cout << Num[i] << endl;
	}
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion
void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    ll N, K;
    cin >> N >> K;
    cout << (ll)(K*pow(K-1, N-1)) << el;
}



Measured memory_bytes: 3936
#include<iostream>
#include<string>

using namespace std;

int main(){
    string s;
    cin >> s;
    for(int i=0;i<s.length();i++){
        if(s[i]==','){
            cout << ' ';
        }
        else{
            cout << s[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 最大値・倍数 - 取得
	int liMax, liRate;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &liMax, &liRate);

	long long llSum = 0;

	// ３つとも倍数のパターン
	long long llCnt = liMax / liRate;
	llSum += llCnt * llCnt * llCnt;

	// ２つの和で倍数のパターン
	if (liRate % 2 == 0) {
		llCnt = (liMax + liRate / 2) / liRate;
		llSum += llCnt * llCnt * llCnt;
	}

	// 結果 - セット
	sprintf(lc1Out, "%lld\n", llSum);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
N = int(input())
nums = list(map(int, input().split(" ")))

acc = [j - i for i, j in zip(nums[0:N - 1], nums[1:N])]
acc.append(nums[0] - nums[-1])
s = sum(nums)

if N == 1:
    print("YES")

else:
    change = N * (N + 1) // 2 #一回の操作で全体から減る分


    if s % change != 0: #何回か行って0になるわけだから 総数をchangeで割り切れなきゃ不可能
        print("NO")
        exit()

    change_kaisu = s // change #回数 = 総数/一回の減少分

    acc = list(map(lambda x: x - change_kaisu, acc))
    c = 0
    for temp in acc:
        if temp == 0:
            continue
        elif -temp % N == 0 and temp < 0:
            c += -temp // N
        else:
            print("NO")
            exit()
    if c == change_kaisu:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 66472
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int main()
{
	string key = "keyence";
	string s;
	cin >> s;
	int len = (int)s.size();
	int l = 0, r = len;
	REP(i, len){
		if (s.substr(i, (int)key.size()) == key){
			if ((l == 0 and r == len) or (i+(int)key.size() == (int)s.size())){
				cout << "YES" << endl;
				return 0;
			}
		}
		l++, r--;
	}

	for (int c_len = 1; c_len < len; c_len++){
		for (int i = 0; i + c_len < len; i++){
			int j = c_len;
//			cout << s.substr(0, i) << " " << s.substr(c_len + i) << endl;
			if (s.substr(0, i) + s.substr(c_len + i) == key){
				cout << "YES" << endl;
				return 0;
			}
		}
	}

	cout << "NO" << endl;
}


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

using namespace std;

int main()
{
#ifdef jcg
    assert(freopen("input.in", "r", stdin));
//    assert(freopen("output.out", "w", stdout));
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int L, R;
    cin >> L >> R;

    int ans = 2019;
    for (int i = L; i <= min(R, L + 2020); ++i)
        for (int j = L; j < i; ++j)
            ans = min(ans, (i % 2019) * (j % 2019) % 2019);

    cout << ans << '\n';

    return 0;
}


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

int main() {
  lint N, M;
  cin >> N >> M;
  vector<lint> A(N);
  for(auto& elem : A) cin >> elem;
  partial_sum(A.begin(), A.end(), A.begin());
  A.insert(A.begin(), 0);

  map<lint, lint> mp;
  for(auto a : A) mp[a%M]++;

  lint ans = 0;
  for(auto [a, count] : mp) {
    ans += count * (count-1) / 2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 7584
#include<bits/stdc++.h>
typedef long long ll;
#define INF 0x3f3f3f3f
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
using namespace std;
const int sz=1001, mod=1e9+7;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin>>n;
    cout<<3*n*n;
}


Measured memory_bytes: 256
local function axiscomp(ary)
  local z = {}
  for i = 1, #ary do
    z[i] = ary[i]
  end
  table.sort(z)
  local ac, acinv = {}, {}
  local cur = 0
  for i = 1, #z do
    if not acinv[z[i]] then
      cur = cur + 1
      ac[cur] = z[i]
      acinv[z[i]] = cur
    end
  end
  return ac, acinv
end

local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end

local tc, tcinv = axiscomp(t)

local ret = 0
for i = 1, n, 2 do
  local v = tcinv[t[i]]
  if v % 2 == 0 then ret = ret + 1 end
end
print(ret)


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

int main() {
  int n;
  cin >> n;
  vector<int> d;
  for ( int i= 0; i < n; i++ ) {
    int tmp;
    cin >> tmp;
    d.push_back(tmp);
  }
  sort(d.begin(), d.end());
  int left, right;
  right = n/2;
  left = right - 1;
  int ans = d[right] - d[left];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 892
n,m,c = gets.chomp.split(" ").map{|e|e.to_i}
b = gets.chomp.split(" ").map{|e|e.to_i}
ans = 0

n.times do
	a = gets.chomp.split(" ").map{|e|e.to_i}
	sum = c
	m.times do |i|
		sum += b[i]*a[i]
	end
	if sum>0 then ans+=1 end
end

p(ans)

Measured memory_bytes: 1788
A, B, C, D, E, F = map(int, input().split())
ans = 0
W = set()
S = set()

for i in range(F):
  x1 = 100 * A * i
  if x1 > F:
    break
  for j in range(F):
    x2 = x1 + 100 * B * j
    if x2 > F or x2 == 0:
      break
    W.add(x2)
for i in range(F):
  y1 = C * i
  if y1 > F:
    break
  for j in range(F):
    y2 = y1 + D * j
    if y2 > F:
      break
    S.add(y2)

W = list(set(W))
S = list(set(S))

for i in range(len(W)):
  for j in range(len(S)):
    tmp = S[j]/W[i]
    tmp1 = S[j] + W[i]
    if tmp1 <= F and ans <= tmp <= E/100:
      ans = tmp
      ans1 = tmp1
      ans2 = S[j]
print(ans1, ans2)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <stack>
 
using namespace std;
 
#define f(i,a,b) for(int i=a;i<b;i++)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int>>
#define ss second
#define ff first
#define ll long long
#define lld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define pqll priority_queue< ll >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define INF 1000000000
#define NINF -1000000000
 
ll maxll(ll a , ll b ){
    return a > b ? a : b;
}
 
ll minll(ll a , ll b){
    return a > b ? b : a;
}

// bool check(ll z){
//     ll temp = k;
//     // cout << z << endl;
//     f(i , 0 , n){
//         ll sub = (ll)z * a[i];
//         if (sub > b[i])
//         temp -= (sub -b[i]);
//         if (temp < 0){
//             return 0;
//         }
//     }
//         // cout << z << endl;
//     sol = z;
//         return 1;
// }


// To count Number of ones in a binary number
// int count_one(int x){
//     x = (x & (0x55555555)) + ((x >> 1) & (0x55555555));
//     x = (x & (0x33333333)) + ((x >> 2) & (0x33333333));
//     x = (x & (0x0f0f0f0f)) + ((x >> 4) & (0x0f0f0f0f));
//     x = (x & (0x00ff00ff)) + ((x >> 8) & (0x00ff00ff));
//     x = (x & (0x0000ffff)) + ((x >> 16) & (0x0000ffff));
//     // cout << x << endl;
//     return x;
// }

// int gcd (int a , int b){
//     return __gcd(a,b);
// }

// void print_vi(vi a){
//     for (int i: a){
//         cout << i << " " ;
//     }
//     cout << endl;
// }

// Best algo to find maximum sum subarray (contiguous)
// ll kadane (vl a){
//     ll curr = 0 , maxi = 0;
//     f(i , 0 , a.size()){
//         curr = max(a[i] , curr + a[i]);
//         maxi = max(maxi , curr);
//     }
//     return maxi;
// }

typedef struct books{
    int time;
    int a;
    int b;
}book;

book boo[200001];
bool compare(book a , book b){
    return a.time > b.time;
}

void solve(){
    
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return;
}

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

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define debug(x) #x << "=" << (x)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc054/tasks/abc054_c

int graph[10][10];

int main() {
    int N, M; cin >> N >> M;
    int a, b;
    REP(i, M) {
        cin >> a >> b;
        graph[a][b] = 1;
        graph[b][a] = 1;
    }

    vector<int> perm(N-1);
    REP(i, N-1) perm[i] = i+2;
    sort(perm.begin(), perm.end());

    int ans = 0;
    do {
        int now = 1;
        for (int i = 0; i < perm.size(); i++) {
            if(!graph[now][perm[i]]) break;
            now = perm[i];
            if (i == perm.size()-1) ans++;
        }
    } while(next_permutation(perm.begin(), perm.end()));

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


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

using ll = long long;
const int INF = 1e9 + 1;

int main() {

	ll a, b, k;
	cin >> a >> b >> k;

	cout << max(a - k, (ll)0) << " ";

	ll c = max(k - a, (ll)0);

	cout << max(b - c, (ll)0) << endl;

	return 0;
}


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

void solution(){
int n;
cin>>n;
cout<<(1000-n%1000)%1000;
}

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


Measured memory_bytes: 3612
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")

#include<bits/stdc++.h>

#define pb push_back
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f(i, a ,b) for(int i = (int)a; i <=(int)(b);i++)
#define endl "\n"
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define int long long
using namespace std;

const int N = 1e5+5,MOD = 1000000007;
const long long INF = 0xFFFFFFFFFFFFFFFL;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void IOS()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
   	cout.precision(10);
   	cout << fixed;
}
int n;
int w[N],v[N],dp[105][N];
	
int rec(int i, int s)
{
	if(s <= 0 or i == n)return 0;
	if(dp[i][s] != -1)return dp[i][s];
	int ans = rec(i+1,s);
	if(s >= w[i])ans = max(ans,v[i]+rec(i+1,s-w[i]));
	return dp[i][s] = ans; 
	
}

int32_t main()
{
	IOS();
	int s;
	memset(dp,-1,sizeof(dp));
	cin >> n >> s;
	f(i,0,n-1)cin >> w[i] >> v[i];			
	cout << rec(0,s);
	return 0;
}

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0277

int main() {
	int arr[4];
	int prices[] = { 6000, 4000, 3000, 2000 };
	for (int i = 0; i < 4; i++) {
		int t, n;
		cin >> t >> n;
		cout << (prices[t - 1] * n) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
#include <functional>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	int N;
	cin >> N;
	set<ll> st;
	REP(i, N) {
		ll A;
		cin >> A;
		if(st.insert(A).second);
		else st.erase(A);	
	}
	
	cout << st.size() << endl;
	//cin >> N;
	return 0;
}


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

inline int gi()
{
	char c = getchar();
	while(c < '0' || c > '9') c = getchar();
	int sum = 0;
	while('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int main()
{
	int n = gi(), t1 = 0, t2, x1 = 0, x2 = 0, y1 = 0, y2;
	for(int i = 1; i <= n; ++i) {
		t2 = gi(); x2 = gi(); y2 = gi();
		//printf("%d\n", abs(x2 - x1) + abs(y2 - y1));
		//printf("%d\n", (((t2 - t1 - abs(x2 - x1) - abs(y2 - y1)) % 2 == 0)));
		if(!(abs(x2 - x1) + abs(y2 - y1) <= t2 - t1 && (((t2 - t1 - abs(x2 - x1) - abs(y2 - y1)) % 2 == 0)))) {printf("No"); return 0;}
		t1 = t2; x1 = x2; y1 = y2;
	}
	printf("Yes");
	return 0;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr char sp=' ';
constexpr ll mod=1000000007;

int N,K;
ll f[200001],res;

ll pw(ll x,int y){
	ll a=1;
	while(y){
		if(y&1)a=a*x%mod;
		x=x*x%mod;
		y/=2;
	}
	return a;
}
 
ll modinv(ll x){
	return pw(x,mod-2);
}

ll comb(int n,int r){
	return f[n]*modinv(f[n-r]*f[r]%mod)%mod;
}

int main(){
	cin>>N>>K;
	K=min(K,N-1);
	f[0]=1;
	for(ll i=1;i<=200000;i++){
		f[i]=f[i-1]*i%mod;
	}
	for(int i=0;i<=K;i++){
		res+=comb(N,i)*comb(N-1,i);
		res%=mod;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 1792
n,k=map(int, input().split())
h=list(map(int, input().split()))

INF=10**23
dp=[INF]*n

dp[0]=0
dp[1]=abs(h[0]-h[1])

for i in range(2,n):
    for j in range(1,k+1):
        if i-j<0:
            break
        dp[i]=min(abs(h[i]-h[i-j])+dp[i-j],dp[i])

print(dp[-1])

Measured memory_bytes: 53600
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;


int main(){
  ll a, b, c; cin >> a >> b >> c;
  if(4*a*b<(c-b-a)*(c-b-a) && c-b-a>=0){
    cout << "Yes"  << endl;
  }
  else cout << "No" << endl;
}


Measured memory_bytes: 256
// 153 B - Common Raccoon vs Monster 2020/01/26
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int hp , n;
    cin >> hp >> n;
    vector<int> skill(n);
    rep(i ,n) cin >> skill[i];
    bool ans = false;
    rep(i ,n){
        hp-=skill[i];
        if(hp <= 0) { ans = true; break; }
    }
    cout << ( ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
#include<stdio.h>

int main (void){

 int W,H,x,y,r;

 scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
 if(x+r<=W&&x-r>=0&&y+r<=H&&y-r>=0){

 

  printf("Yes\n");

}

 else{

 printf("No\n");

}

return 0;

}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

i64 N[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
  i64 K;
  cin >> K;
  cout << N[K - 1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long
#define M 1000000007
using namespace std;
ull n,m,s;
ull f(ull k){for(s=1;k;k--)(s*=k)%=M;return s;}
int main(){
	scanf("%llu%llu",&n,&m);if(n>m)s=n,n=m,m=s;
	if(m-n>1)putchar('0');
	else if(m-n==1)printf("%llu",f(n)*f(m)%M);
	else printf("%llu",f(n)*f(m)*2%M);
	return 0;
}

Measured memory_bytes: 256
from collections import deque

S = input().rstrip('\r\n')
S_list = deque(S)
is_reverse = False

Q = int(input())
for _ in range(Q):
    query = input().rstrip('\r\n')
    t, f, c = '', '', ''
    if len(query) == 1:
        t = query
    else:
        t, f, c = query.split(' ')
    if t == '1':
        is_reverse = not is_reverse
    else:
        if f == '1':
            if is_reverse:
                S_list.append(c)
            else:
                S_list.appendleft(c)
        else:
            if is_reverse:
                S_list.appendleft(c)
            else:
                S_list.append(c)
if is_reverse:
    S_list.reverse()
print(''.join(S_list))

Measured memory_bytes: 8820
def MAP(): return map(int,input().split())

n,k = MAP()
*v, = MAP()

operation = min(n,k) #取り出すMAX回数
ans=0

for i in range(1,operation+1):
    for j in range(i+1):
        A = j   #左側から取り出す回数
        B = i-j    #右側から取り出す回数
        t = v[:A]
        if B>0:
            t+=v[-B:]
        t.sort()

        l = min(k-i,i-1)
        for ll in range(l):
            if t[ll] >= 0:
                l = ll
                break
        s = sum(t[l:])
        ans = max(ans,s)

print(ans)

Measured memory_bytes: 3064
from math import ceil
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = 0
for x, y in zip(a, b):
    if y > x:
        c += ceil((y-x)/2)

if sum(b)-sum(a)>=0 and sum(b)-sum(a)>=c:
    print("Yes")
else:
    print("No")


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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split();
            var n = int.Parse(nk[0]);
            var k = long.Parse(nk[1]);

            var a = Console.ReadLine().Split().Select(int.Parse).ToList();

            if(k <= n)
            {
                var ans = 1;
                for(int i =0; i < k; i++)
                {
                    ans = a[ans - 1];
                }
                Console.WriteLine(ans);
                return;
            }

            var visited = new int[n];
            var now = 1;

            var cycle = 0;
            for(int i = 0; i < k; i++)
            {
                now = a[now - 1];

                if (visited[now - 1] != 0)
                {
                    cycle = i + 1 - visited[now - 1];
                    break;
                }
                else
                {
                    visited[now - 1] = i + 1;
                }
            }

            var mod = (k - visited[now - 1]) % cycle;

            for (int i = 0; i < mod; i++) 
            {
                now = a[now - 1];
            }
            Console.WriteLine(now);
        }
    }
}


Measured memory_bytes: 43772
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define RNG(i,from,to) for(ll i=(from); i<(ll)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll R; cin >> R;
  cout << (double)R*2.0*3.141 << endl;
  return 0;
}


Measured memory_bytes: 3768
#include<map>
#include<string>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<set>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int a1, a2, a3;
	scanf("%d %d %d", &a1, &a2, &a3);
	int n = 0;
	n = abs(a2 - a1) + abs(a3 - a2);
	int k;
	k = abs(a3 - a1) + abs(a2 - a3);
	if (n > k)n = k;
	k = abs(a1 - a2) + abs(a3 - a1);
	if (n > k)n = k;
	k = abs(a3 - a2) + abs(a3 - a1);
	if (n > k)n = k;
	k = abs(a2 - a3) + abs(a1 - a2);
	if (n > k)n = k;
	k = abs(a1 - a3) + abs(a2 - a1);
	if (n > k)n = k;
	printf("%d", n);
	
	
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in();
    vector<ll>a(n),cnt(n+1);
    for(int i=0;i<n;++i)++cnt[a[i]=in()];
    ll sum=0;
    for(int i=0;i<=n;++i)sum+=cnt[i]*(cnt[i]-1)/2;
    for(int i=0;i<n;++i){
        cout<<sum-cnt[a[i]]+1<<endl;
    }
}


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

int main(void)
{
	int u, v;
	map <int, int> m;
	
	while (cin >> u >> v){
		if (u == 0 && v == 0){
			bool flag = true;
			map <int, int> ::iterator it;
			for (it = m.begin(); it != m.end(); it++){
				if (it->first == 1 && it->second % 2 == 0) flag = false;
				else if (it->first == 2 && it->second % 2 == 0) flag = false;
				else if (2 < it->first && it->second % 2 == 1){
					flag = false;
					break;
				}
			}
			if (flag) puts("OK");
			else puts("NG");
			m.clear();
			continue;
		}
		m[u]++;
		m[v]++;
	}
	
	return 0;
}

Measured memory_bytes: 0
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7

def cmb(n, k):
    if k < 0 or k > n: return 0 
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD

def cumprod(arr, MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv

U = 2 * 10 ** 6 + 3  # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)

r1, c1, r2, c2 = lr()
answer = cmb(r2+c2+2, r2+1) - 1
answer -= cmb(r2+c1+1, r2+1) - 1
answer -= cmb(r1+c2+1, c2+1) - 1
answer += cmb(r1+c1, r1) - 1
print(answer % MOD)
# 26

Measured memory_bytes: 90532
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s; cin>>s; bool finish=false;
  for(int i='a'; i<'z'; i++){
    for(int j=0; j<s.size(); j++){
      if(s[j]==i) break;
      if(j==s.size()-1){
        finish=true;
        s.push_back(i);
      }
    }
    if(finish) break;
  }
  string t=s;
  if(finish==false){//全てのアルファベットがある
    if(s=="zyxwvutsrqponmlkjihgfedcba") s="-1";
    else{
      next_permutation(s.begin(), s.end());
      for(int i=0; i<s.size(); i++){
        if(s[i]!=t[i]) s.erase(s.begin()+i+1, s.end());
      }
    }
  }
  cout<<s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
using namespace std;

typedef long long llong; // -2.1e-9 <= int <= 2.1e9 bool compare_by_b(pair<string, int> a, pair<int, int> b) {

bool compare(pair<string, int> &a, pair<string, int> &b)
{
    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return a.first < b.first;
    }
}


int main()
{
    size_t N; cin >> N;
    set<string> S; unordered_map<string, int> dict;
    for (size_t i=0; i<N; i++) {
       string ss; cin >> ss;
       if(S.find(ss) != end(S)) {
           dict[ss]++;
       }
       else {
           S.insert(ss);
           dict[ss] = 1;
       }
    }

    vector<pair<string, int>> vec(dict.size());
    size_t i= 0;
    for (const auto &d: dict) {
        vec[i].second = d.second;
        vec[i].first = d.first;
        i++;
    }
    sort(vec.begin(), vec.end(), compare);
//    for (const auto &v: vec) {
//        cout << v.first << ", " << v.second << endl;
//    }

    cout << vec[0].first << endl;
    int max_cnt = vec[0].second;
    for (size_t i=1; i<vec.size(); i++) {
        if (vec[i].second == max_cnt) {
            cout << vec[i].first << endl;
        }
        else {
            break;
        }
    }
}


Measured memory_bytes: 36552
def selectionsort(A,N):
    cnt = 0
    for i in range(N-1):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        if minj > i:
            A[i],A[minj] = A[minj],A[i]
            cnt += 1
    print(*A)
    print(cnt)

def main():
    N = int(input())
    A = list(map(int,input().split()))
    selectionsort(A,N)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5612
$n = gets.to_i
INF = 1 << 30
$mat = Array.new($n){ Array.new }
$n.times do
  l = gets.split.map(&:to_i)
  l[1].times{ |i| $mat[l[0]] << l[2*(i+1),2] }
end
def dijkstra(x)
  d = Array.new($n, INF)
  d[0] = 0
  v = Array.new($n){|i| i}
  while v.size > 0
    a = Array.new($n,INF)
    v.each{ |i| a[i] = d[i] }
    t = v.delete(a.index(a.min))
    $mat[t].each do |item|
      u, len = item
      d[u] = d[t] + len if d[t] + len < d[u]
    end
  end
  d
end
ret = dijkstra(0)
ret.each_index{ |i| puts "#{i} #{ret[i]}" }

Measured memory_bytes: 8904
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
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)
#define ALL(a) a.begin(), a.end()
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.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i <= n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    vec l(1000005,INF);
    int n;
    cin>> n;
    l[0]=0;
    l[1]=1;
    reps(i,2,n){
        l[i]=l[i-1]+1;
        int a=6;int b=9;
        while(a<=i){
            l[i]=min(l[i-a]+1,l[i]);
            a*=6;
        }
        while(b<=i){
            l[i]=min(l[i-b]+1,l[i]);
            b*=9;
        }
    }
    cout<<l[n]<<endl;
    return 0;
}

Measured memory_bytes: 10984