akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  long N;
  unsigned long x[200000];

  cin >> N;
  for(long i = 0; i < N; i++) cin >> x[i];

  unsigned long buf[N];
  for(long i = 0; i < N; i++) buf[i] = x[i];
  sort(buf, buf+N);

  //for(long i = 0; i < N; i++) cout << "x:" << x[i] << " buf:" << buf\
[i] << endl;                                                           

  unsigned long l_mid = buf[N/2];
  unsigned long s_mid = buf[N/2 - 1];
  for(long i = 0; i < N; i++){
    unsigned long res;
    if(x[i] <= s_mid) res = l_mid;
    else res = s_mid;

    cout << res << endl;
  }

  return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 100100
#define p 1000000007
#define LL long long

int n, l, r, k;
LL s[AC], C[AC], inv[AC], Cl[AC];//存下每个数第一次出现的地方

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

inline void pre()
{
	n = read(), k = n + 1;
	int x;
	for(R i = 1; i <= k; i ++)
	{
		x = read();
		if(s[x]){l = s[x], r = i; break;}
		s[x] = i;
	}
}

inline void work()
{
	C[0] = inv[1] = Cl[0] = 1;
	for(R i = 2; i <= k; i ++) inv[i] = (p - p / i) * inv[p % i] % p; 
	for(R i = 1; i <= k; i ++) C[i] = C[i - 1] * (k - i + 1) % p * inv[i] % p;
	for(R i = 1; i <= k; i ++) Cl[i] = Cl[i - 1] * (n - r + l - i + 1) % p * inv[i] % p;
	printf("%d\n", n);
	for(R i = 2; i <= k; i ++)
		printf("%lld\n", (C[i] - Cl[i - 1] + p) % p);
}

int main()
{
	//freopen("in.in", "r", stdin);
	pre();
	work();
	//fclose(stdin);
	return 0;
}

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

int n, s, a[2005];
int main() {
	int i, j, k;
	cin >> n;
	for(i=0; i<n; i++) cin >> a[i];
	sort(a, a+n);
	for(i=0; i<n; i++) for(j=i+1; j<n; j++) {
		k = lower_bound(a, a+n, a[i]+a[j]) - a;
		s += max(0, k-1-j);
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var r = ReadIntArray();
            var N = r[0];
            var K = r[1];

            string ret = string.Empty;
            while (N > 0)
            {
                ret += N % K;
                N /= K;
            }

            Console.WriteLine(ret.Length);
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13396
n, a, b, c, d = map(int, input().split())
s = input()
a -= 1
b -= 1
c -= 1
d -= 1

# 2個以上の岩があればNG
if "##" in s[a:max(c,d)]:
    print("No")
    exit()

# AがBを抜けるかどうか
if d < c and not "..." in s[b-1:d+2]:
    print("No")
    exit()

print("Yes")


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	double a , hyaku , jyu , ichi ;
    int b , c ;
	cin >> a  ;
  	b = 0 ;
   	hyaku = a * 0.01 ;
  	b = hyaku;
  	c += b;
  	jyu = a - (b * 100);
  	b = jyu * 0.1;
  	c += b;
  	ichi = jyu - (b * 10) ;
  	b = ichi ;
  	c += b;
  	cout << c << endl ;
  	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;
using P = pair<int,int>;
const int INF = 1001001001;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            if (a == 0 && b == 0)
                break;
            if(a >= 1 && a <= 300){
		if(b >= 1 && b <= 300){
            for (int i = 0; i < a; i++) {
                for (int j = 0; j < b; j++) {
                   int flg = 0;
                   if(j == 0 || j == (b - 1)){
                    flg = 1;
                   }
                   if(i == 0 || i == (a - 1)){
                    flg = 1;
                   }
                   if(flg == 0){  
                    System.out.print(".");
                   }else{
                    System.out.print("#");
                   }
                }
                System.out.println();
            }
            System.out.println();
	    }
	   }
        }
    }
}


Measured memory_bytes: 33924
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int v = scan.nextInt();
		int e = scan.nextInt();
		Group[] groups = new Group[v];
		for(int i = 0; i < v; i++) groups[i] = new Group();
		List<Branch> branches = new ArrayList<>(e);
		for(int i = 0; i < e; i++) {
			branches.add(new Branch(scan.nextInt(),scan.nextInt(),scan.nextInt()));
		}
		Collections.sort(branches);
		int result = 0;
		for(Branch _b : branches) {
			Group g1 = groups[_b.s].getGroup();
			Group g2 = groups[_b.t].getGroup();
			if(g1==g2) continue;
			Group newg = new Group();
			g1.parent = newg;
			g2.parent = newg;
			result += _b.v;
		}
		System.out.println(result);
	}
}

class Group{
	Group parent;
	Group(){
	}
	Group getGroup() {
		return (parent==null)?this:parent.getGroup();
	}
}

class Branch implements Comparable<Branch>{
	int s,t;
	int v;
	Branch(int _s, int _t, int _v) {
		s = _s;
		t = _t;
		v = _v;
	}
	@Override
	public int compareTo(Branch _b) {
		return this.v - _b.v;
	}
}

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

int height, width;
string s[52];

int hasHashKey(int i, int j) {
  if(i < 0 || height - 1 < i || j < 0 || width - 1 < j) return 0;
  else if (s[i][j] == '#') return 1;
  else return 0;
}

int main() {
  cin >> height >> width;
  for (int i = 0; i < height; i++) cin >> s[i];
  for (int i = 0; i < height; i++) {
    for ( int j = 0; j < width; j++) {
      if (s[i][j] == '#') {
        cout << '#';
      }
      else {
        int sum = 0;
        sum += hasHashKey(i - 1, j - 1);// 左上のマス
        sum += hasHashKey(i - 1, j);//     上のマス
        sum += hasHashKey(i - 1, j + 1);// 右上のマス
        sum += hasHashKey(i, j - 1);//     左のマス
        sum += hasHashKey(i, j + 1);//     右のマス
        sum += hasHashKey(i + 1, j - 1);// 左下のマス
        sum += hasHashKey(i + 1, j);//     下のマス
        sum += hasHashKey(i + 1, j + 1);// 右下のマス
        cout << sum;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
#define x first
#define y second
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std;

typedef pair<int, int> pii;

int n, a, b, c, d, q, ans;

int main() {
	INIT
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'A' || s[i] == 'G' || s[i] == 'C' || s[i] == 'T') {
			++a;
			if (a > ans) ans = a;
		}
		else a = 0;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a[5];
	int A;
	cin>>A;
	a[1]=A/1000;
	a[2]=A%1000/100;
	a[3]=A%1000%100/10;
	a[4]=A%10;
	if(a[1]==a[2] && a[2]==a[3])
		cout<<"Yes"<<endl;
	else
	{
		if(a[2]==a[3] && a[3]==a[4])
		    cout<<"Yes"<<endl;
		else
		    cout<<"No"<<endl;
	}    
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace 課題1
{
    class Program
    {
        static void Main(string[] args)
		{
			//まず値を配列に格納する
			string[] strArray = new string[2];
			strArray = Console.ReadLine().Split(" ");

			//配列を数値変換する
			int[] intArray = Array.ConvertAll(strArray, int.Parse);

			//配列要素数
			int intEle = intArray.Length;

			//for文で配列の中身を回す
			for (int i = 0; i < intEle; i++)
			{
				//配列の値が8を上回っていない
				if(intArray[i]>8)
				{

					Console.WriteLine(":(");
					return;
				}
			}

			//出力
			Console.WriteLine("Yay!");
		}
	}
}


Measured memory_bytes: 27504
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;
bool com_b(pair<int, int> a, pair<int, int> b){
    return a.second < b.second;
}
bool com_pair_reverse(pair<int, int> a, pair<int, int> b){
    return a > b;
}
bool com_reverse(int a, int b){
    return a > b;
}

int main(){
    int N;
    cin >> N;
    // edge
    vector<int> edge(N-1);
    vector<vector<int>> node(N);
    vector<int> C;

    int a, b, c;


    for(int i = 0; i < N-1; i++){
        cin >> a >> b;
        // 頂点に入れる
        node[a-1].push_back(b-1);
        node[b-1].push_back(a-1);
    }

    for(int i = 0; i < N; i++){
        cin >> c;
        C.push_back(c);
    }
    // Cは小さい順
    sort(C.begin(), C.end());

    long long int ans = 0;
    for(auto c: C){
        ans += c;
    }
    ans -= C.back();

    //頂点からのキュー
    queue<int> que;
    que.push(0);

    //頂点のスコア
    vector<int> score(N, -1);
    score[0] = C.back();
    C.pop_back();

    while(que.empty() == false){
        // cout << "queue: " << que.front() << endl;
        auto ni = que.front();
        que.pop();
        for(auto nd : node[ni]){
            // cout << "nd: " << nd << ", " << score[nd] << endl;
            if(score[nd] == -1){
                score[nd] = C.back();
                C.pop_back();
                que.push(nd);
            }
        }
    }

    cout << ans << endl;
    for(auto s: score){
        cout << s << " ";
    }
    cout << endl;

    return 0;
}

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

int formula(int x,int y,int z) {
    int ans = x*x+y*y+z*z+x*y+x*z+y*z;
    return ans;
}

int main()
{
    int n;
    cin>>n;
    int x(1),y(1),z(1),formul(0),c(0);
    for (int i=1;i<=n;i++)  {
        for (int x=1;x<=99;x++) {
            for (int y=1;y<=99;y++) {
               for (int z=1;z<=99;z++) {
                    formul=formula(x,y,z);
                    if (formul==i) c++;
                    if (formul>i) break;
                }
            }
        }
        
        cout<<c<<endl;
        c=0;
    }
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main() {
 int k;
 cin >> k ;
 string s ;
 cin >> s ;
 int l= s.size() ;
 if(l<=k)
 cout <<s <<endl ;
 else{
 rep(i,k){
   cout <<s[i] ;
 }
   cout <<"..."<<endl ;
    }   return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,k;
    std::cin >> n>>k;
    
    vector<ll> a(n);
    ll cntn,cnt0,cntp;
    cntn = cnt0 = cntp = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        if(a[i]>0){
            cntp++;
        }else if(a[i]==0){
            cnt0++;
        }else{
            cntn++;
        }
    }
    // std::cout << cntn<< " "<<cnt0<<" "<<cntp << std::endl;
    // std::cout << (cntn*cntp+cnt0*(cntp+cntn)+cnt0*(cnt0-1)/2)  << std::endl;
    sort(a.begin(),a.end());
    
    if(k <= cntn*cntp){
        ll r = 0;
        ll l = -1e18;
        // l以下の数がk以上で最小のl
        while(r-l>1){
            // std::cout << r<<" "<<l << std::endl;
            ll mid = (r+l)/2;
            ll tmp = 0;
            for (int i = 0; i < cntn; i++) {
                ll r2 = cntp;
                ll l2 = -1;
                while(r2-l2>1){
                    // std::cout << " "<<r2<<" "<<l2 << std::endl;
                    ll mid2 = (r2+l2)/2;
                    if(a[n-1-mid2]*a[i]<=mid){
                        l2 = mid2;
                    }else{
                        r2 = mid2;
                    }
                }
                tmp += l2+1;
            }
            if(tmp>=k){
                r = mid;
            }else{
                l = mid;
            }
        }
        std::cout << r << std::endl;
    }else if(k<=cntn*cntp+cnt0*(cntp+cntn)+cnt0*(cnt0-1)/2){
        std::cout << 0 << std::endl;
        return 0;
    }else{
        ll r = 1e18;
        ll l = 0;
        
        sort(a.rbegin(),a.rend());
        
        while(r-l>1){
            // std::cout << r<<" "<<l << std::endl;
            ll mid = (r+l)/2;
            ll tmp = 0;
            for (int i = 0; i < cntp; i++) {
                ll r2,l2;
                r2 = cntp;
                l2 = i;
                
                while(r2-l2>1){
                    ll mid2 = (r2+l2)/2;
                    if(a[mid2]*a[i]<=mid){
                        r2 = mid2;
                    }else{
                        l2 = mid2;
                    }
                }
                tmp += cntp-r2; 
                // std::cout << tmp<<" "<<r2 <<" pp" << std::endl;

            }
            // std::cout << tmp <<" p" << std::endl;
            for (int i = 0; i < cntn; i++) {
                ll r2,l2;
                r2 = cntn;
                l2 = i;
                
                while(r2-l2>1){
                    ll mid2 = (r2+l2)/2;
                    if(a[n-1-mid2]*a[n-1-i]<=mid){
                        r2 = mid2;
                    }else{
                        l2 = mid2;
                    }
                }
                tmp += cntn-r2;
            }
            
            // std::cout << " "<<tmp<<std::endl;
            if(tmp>=k-(cntn*cntp+cnt0*(cntp+cntn)+cnt0*(cnt0-1)/2)){
                r = mid;
            }else{
                l = mid;
            }
        }
        std::cout << r << std::endl;
    }
}



Measured memory_bytes: 1792
import sys
import bisect


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, W = map(int, input().split())
    vsup = 10 ** 3 * N + 2
    dp = [10 ** 12 + 1] * (vsup)  # 価値の総和を i (以上にするための重さの最小値
    dp[0] = 0

    for i in range(N):
        w, v = map(int, input().split())
        for j in range(vsup - 2, -1, -1):
            if j - v >= 0:
                dp[j] = min(dp[j], dp[j - v] + w, dp[j + 1])
            else:
                dp[j] = min(dp[j], dp[j + 1])

    print(bisect.bisect_right(dp, W) - 1)


if __name__ == "__main__":
    main()


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

namespace ABC054
{
    class C
    {
        static bool[,] graph;
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = input[0];
            int M = input[1];

            graph = new bool[N, N];
            for (int i = 0; i < M; i++)
            {
                input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                graph[input[0] - 1, input[1] - 1] = true;
                graph[input[1] - 1, input[0] - 1] = true;
            }

            bool[] visited = new bool[N];
            visited[0] = true;

            Console.WriteLine(DFS(0, N, visited));
        }

        static int DFS(int v, int N, bool[] visited)
        {
            bool all_visited = true;

            for (int i = 0; i < N; i++)
            {
                if (visited[i] == false) all_visited = false;
            }

            if (all_visited) return 1;

            int res = 0;
            for (int i = 0; i < N; i++)
            {
                if (graph[v, i] == false) continue;
                if (visited[i]) continue;

                visited[i] = true;
                res += DFS(i, N, visited);
                visited[i] = false;
            }
            return res;
        }
    }
}


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

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define endl '\n'
#define int long long
#define pb emplace_back
#define range(v) v.begin(),v.end()
#define ff first
#define ss second
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;



int solve() {
	int n = 5;
	vector<int> a(n);
	for (int &i : a) cin >> i;
	for (int i = 1; i <= n; i++)
		if (a[i - 1] == 0) return i;
	return 0;
}

int32_t main() {
	fast
	int t_c = 1;
	// cin >> t_c;
	while (t_c--) {
		auto ans = solve();
		cout << ans << endl;
	}
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int, int>P;
typedef pair<int, pair<int, int>>PP;
typedef long long ll;
ll inf = -1;
ll mod = mod = pow(10, 9) + 7;

int main() {
	int x, a; cin >> x >> a;
	if (x < a) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int student[] = new int[30];
		for (int i = 0; i < 30; i++) {
			student[i] = 0;
		}
		for (int i = 0; i < 28; i++) {
			student[scanner.nextInt() - 1] = 1;
		}
		for (int i = 0; i < 30; i++) {
			if (student[i] == 0) {
				System.out.println(i + 1);
			}
		}
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s,t;
  cin >> s >> t;
  int ans = 0;
  rep(i,sz(s)) {
    if(s[i]!=t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3924
# coding: utf-8
import sys
import itertools


def sr(): return sys.stdin.readline().rstrip()


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
l_list = []
r_list = []
for i in range(M):
    l, r = lr()
    l_list.append(l)
    r_list.append(r)

for i in range(M):
    if i == 0:
        maxL = l_list[i]
        minR = r_list[i]
        continue
    maxL = max(maxL, l_list[i])
    minR = min(minR, r_list[i])
ans = max(minR - maxL + 1, 0)
print(ans)


Measured memory_bytes: 11112
#include"stdio.h"
#include<string>
using namespace std;
#define MAX 25

class Node
{
public:
	enum TYPE{ROOT,INTERNAL_NODE,LEAF};
	Node(int ID, Node* PARENT)
	{
		id = ID;
		parent = PARENT;
	}
	~Node() {};
	Node* parent=0;
	Node* sibling=0;
	Node* left=0;
	Node* right=0;
	int id;
	int degree=0;
	int depth=-1;
	int height=-1;
	TYPE type;
};

class Tree
{
public:
	Tree() { for (int i = 0; i < MAX; i++)nodes[i] = 0; }
	~Tree() { for (int i = 0; i < MAX; i++)if(nodes[i]!=0)delete nodes[i]; }
	void CreateNode(int ID, Node* PARENT) { nodes[ID] = new Node(ID, PARENT); }
	Node* nodes[MAX];
	void SetRoot()
	{
		for (int i = 0; i < MAX; i++)
		{
			if (nodes[i] == 0)break;
			if (nodes[i]->parent == 0)
			{
				nodes[i]->type = Node::ROOT;
				nodes[i]->depth = 0;
				break;
			}
		}
	}
	int SetDepth(Node* NODE)
	{
		if (NODE->type == Node::ROOT)return 0;
		if(NODE->parent->depth!=-1)return NODE->parent->depth + 1;
		else return SetDepth(NODE->parent)+1;
	}
	int SetHeight(Node* NODE)
	{
		if (NODE->type == Node::LEAF)return 0;
		int lh=0,rh=0;
		if (NODE->left != 0)
		{
			if (NODE->left->height != -1)lh = NODE->left->height+1;
			else lh = SetHeight(NODE->left)+1;
		}
		if (NODE->right != 0)
		{
			if (NODE->right->height != -1)rh = NODE->right->height + 1;
			else rh = SetHeight(NODE->right) + 1;
		}
		if (lh > rh)return lh;
		else return rh;
	}
	void Show(Node* NODE)
	{
		string text;
		int sib;
		if (NODE->sibling == 0)sib = -1;
		else sib = NODE->sibling->id;
		if (NODE->type != Node::ROOT)printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", NODE->id, NODE->parent->id, sib,NODE->degree,NODE->depth, NODE->height);
		else printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", NODE->id, -1, sib, NODE->degree, NODE->depth, NODE->height);
		switch (NODE->type)
		{
		case Node::ROOT:
			text = "root";
			break;
		case Node::INTERNAL_NODE:
			text = "internal node";
			break;
		case Node::LEAF:
			text = "leaf";
			break;
		}
		printf("%s\n", text.c_str());
	}
};

int main()
{
	Tree T;
	int n;
	scanf("%d", &n);
	for (int o = 0; o < n; o++)
	{
		int id, l, r;
		scanf("%d%d%d", &id, &l, &r);
		if (T.nodes[id] == 0)T.CreateNode(id, 0);
		if (l != -1)
		{
			T.nodes[id]->degree++;
			if (T.nodes[l] == 0)T.CreateNode(l, T.nodes[id]);
			else T.nodes[l]->parent = T.nodes[id];
			T.nodes[id]->left = T.nodes[l];
			T.nodes[id]->type = Node::INTERNAL_NODE;
		}
		if (r != -1)
		{
			T.nodes[id]->degree++;
			if (T.nodes[r] == 0)T.CreateNode(r, T.nodes[id]);
			else T.nodes[r]->parent = T.nodes[id];
			T.nodes[id]->right = T.nodes[r];
			T.nodes[id]->type = Node::INTERNAL_NODE;
		}
		if (r != -1 && l != -1)
		{
			T.nodes[l]->sibling = T.nodes[r];
			T.nodes[r]->sibling = T.nodes[l];
		}
		else if (r*l == 1)T.nodes[id]->type = Node::LEAF;
	}
	T.SetRoot();
	for (int i = 0; i < MAX; i++)
	{
		if (T.nodes[i] == 0)break;
		else
		{
			T.nodes[i]->depth=T.SetDepth(T.nodes[i]);
			T.nodes[i]->height = T.SetHeight(T.nodes[i]);
			T.Show(T.nodes[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 2848
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll n,k;
    string s, t;
    ll ans;
    double dans;
    string sans;
    ll a[20], b[20], c[19];


    cin  >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n-1) cin >> c[i];

    ans = 0;
    ll before = -100;

    rep(i,n){
        ll dish = a[i];
        ans += b[dish - 1];
        if(before + 1 == dish) ans += c[before - 1];

        before = dish;
    }

    std::cout << ans << endl; 
    // std::cout << sans << endl; 
    
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

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

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

    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200) {
        cout << s;
    } else if (a < 3200) {
        cout << "red";
    }
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_A&lang=jp
#include <bits/stdc++.h>
using namespace std;

struct Diameter {
  Diameter () {}
  Diameter (int n) : G(n) {}

  struct edge {
    edge () {}
    edge (int to, int cost) : to(to), cost(cost) {}

    int to, cost;
  };

  const pair<int, int> id = make_pair(0, -1);
  vector<vector<edge>> G;

  void add_edge(int u, int v, int cost) {
    G[u].push_back(edge(v, cost));
    G[v].push_back(edge(u, cost));
  }

  void add_edge(int u, int v) {
    add_edge(u, v, 1);
  }

  pair<int, int> dfs(int v, int pre) {
    pair<int, int> res = id;
    for (const auto &e : G[v]) {
      if (e.to == pre) continue;
      pair<int, int> p = dfs(e.to, v);
      p.first += e.cost;
      res = max(res, p);
    }

    if (res == id) {
      res = make_pair(0, v);
    }
    return res;
  }

  int dist() {
    pair<int, int> l = dfs(0, -1);
    // cerr << l.second << endl;
    pair<int, int> r = dfs(l.second, -1);
    // cerr << r.second << endl;
    return r.first;
  }
};

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

  Diameter d(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    d.add_edge(u, v, c);
  }

  cout << d.dist() << endl;
}

Measured memory_bytes: 12728
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

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

  int count = 0;
  for (int i = 0; i < N; i++) {
    int h;
    cin >> h;
    if ( h >= K) count += 1;
  }

  cout << count << endl;
  return 0;
}

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

 
int N;
map<pair<int,int>,int>m;
int ara[100001];
int dp(int a,int b,int sum)

{

        if(b>=N){
                return 999999999;
        }
        else if(m.find(make_pair(a,b))!=m.end())return m[make_pair(a,b)];
        else if(b==N-1){
                return sum+=abs(ara[a]-ara[b]);
        }
        else{

                sum+=abs(ara[a]-ara[b]);
 
 
                sum+=min(dp(b,b+1,0),dp(b,b+2,0));
                m[make_pair(a,b)]=sum;
                return sum;
 
 
        }
}
 
int main()
{
       ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
     cin>>N;
     for(int i=0;i<N;i++){
        cin>>ara[i];
     }
 
     int sum=dp(0,0,0);
     cout<<sum<<endl;
     return 0;
}

Measured memory_bytes: 16256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		List<Integer> temp = new ArrayList();
		
		for(int i = 0; i < n; i++) {
			int hoge = sc.nextInt();
			temp.add(hoge);
		}
		
		boolean even = true;
		int time = 0;
		
		List<Integer> newOne = new ArrayList();
		
		while(even) {
			
			
			for(int i = 0; i < temp.size(); i++) {
				int current = temp.get(i);
				if(current % 2 >= 1) {
					even  = false;
					time--;
					break;
				}else {
					newOne.add(current / 2);
				}
			}
			
			temp.clear();
			temp.addAll(newOne);
			newOne.clear();
			time++;
			
		}
		
		System.out.println(time);
		
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
  int S;
  cin >> S;
  int A = S / 100, B = S % 100;
  if (0 < A && A < 13 && 0 < B && B < 13) {cout << "AMBIGUOUS" << endl;}
  else if (0 < B && B < 13) {cout << "YYMM" << endl;}
  else if (0 < A && A < 13) {cout << "MMYY" << endl;}
  else {cout << "NA" << endl;}
}

Measured memory_bytes: 3616
#include <stdio.h>
    
int main(){
     
    int buf1[50],buf2[50];
     
    int k = 0;
    while( scanf( "%d %d",&buf1[k],&buf2[k] ) != EOF ) k++;
     
    for( int i = 0;i < k;i++ ){
        int b1 = buf1[i],b2 = buf2[i];
        int m,n;
        if( b1< b2 ){
            m = b2,n = b1;
        } else if( b1 > b2 ){
            m =  b1,n = b2;
        } else {
            n = 0;
            m = b1;
        }
          
        while( n != 0 ){
            int buf = n;
            n = m % n;
            m = buf;
        }
        printf( "%d ",m );
  
        while( b1 != b2 ){
            if( b1 < b2 ) b1 += buf1[i];
            else             b2 += buf2[i];
        }
        printf( "%d\n",b1 );
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n, m;
	cin >> n >> m;
	
	vector<int> dp(n + 5);
	
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		dp[a]++;
		dp[b + 1]--;
	}
	
	for(int i = 1; i <= n; i++)
		dp[i] += dp[i - 1];
	
	int ans = 0;
	
	for(int i = 1; i <= n; i++)
		if(dp[i] == m)
			ans++;
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  string s;cin>>s;
  bool isHitachi = true;
  for(int i = 0;i < s.size();i += 2){
    if(s[i] == 'h' && s[i+1] == 'i');
    else isHitachi = false;
  }
  print(isHitachi ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

vector<ll> spf;
vector<ll> memo;
ll calc(ll n){
  if(n == 1){
    memo[n] = 1;
    return 1;
  }
  ll t = n / spf[n];
  ll k = t;
  while(k % spf[n] == 0) k /= spf[n];
  memo[n] = memo[t] + memo[k];
  return memo[n];
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n, t; cin >> n;
  spf = vector<ll>(n+1);
  memo = vector<ll>(n+1);
  for(int i = 1; i <= n; i++){
    spf[i] = i;
  }
  for(ll i = 2; i <= sqrt(n); i++){
    if(spf[i] == i){
      t = i;
      while(t <= n){
        spf[t] = min(spf[t], i);
        t += i;
      }
    }
  }
  ll ans = 0;
  for(ll i = 1; i <= n; i++){
    ans += i * calc(i);
  }
  cout << ans << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


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

int main() {
  int64_t n, q;
  std::cin >> n >> q;
  std::string s;
  std::cin >> s;

  std::vector<int64_t> po;
  po.reserve(n);

  for (int64_t i = 0; i + 1 < s.size(); i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      po.push_back(i + 1);
    }
  }

  std::vector<int64_t> ans(q);

  for (int64_t i = 0; i < q; i++) {
    int64_t l, r;
    std::cin >> l >> r;
    const auto first = std::distance(po.cbegin(),
      std::lower_bound(po.cbegin(), po.cend(), l));
    const auto end = std::distance(po.cbegin(),
      std::lower_bound(po.cbegin(), po.cend(), r));
    std::cout << end - first << std::endl;
  }
  return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>
int main()
{
	int a[4][4]={0},b[4][4]={0},n,i,j,p;
	for(i=1;i<=3;i++)	
		for(j=1;j<=3;j++)
			scanf("%d",&a[i][j]);
	scanf("%d",&n);
	for(p=1;p<=n;p++)
	{
		int k;
		scanf("%d",&k);
		for(i=1;i<=3;i++)
		{
			for(j=1;j<=3;j++)
			{
				if(k==a[i][j])
				{
					b[i][j]=1;
				}
			}
		}
	}
	if(b[1][1]==1&&b[1][2]==1&&b[1][3]==1)
		printf("Yes");
	else if(b[1][1]==1&&b[2][1]==1&&b[3][1]==1)
		printf("Yes");
	else if(b[1][1]==1&&b[2][2]==1&&b[3][3]==1)
		printf("Yes");
	else if(b[2][1]==1&&b[2][2]==1&&b[2][3]==1)
		printf("Yes");
	else if(b[3][1]==1&&b[3][2]==1&&b[3][3]==1)
		printf("Yes");
	else if(b[1][2]==1&&b[2][2]==1&&b[2][3]==1)
		printf("Yes");
	else if(b[1][3]==1&&b[2][3]==1&&b[3][3]==1)
		printf("Yes");
	else if(b[1][3]==1&&b[2][2]==1&&b[3][1]==1)
		printf("Yes");	
	else 
		printf("No");		
}

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

#define int ll

signed main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> x(n), y(n), p(n);
    rep(i,n) {
        cin >> x[i] >> y[i] >> p[i];
    }
    
    ll INF = INT64_MAX;
    //xとyで最小歩行距離の前計算 2^n n^2
    vector<vector<int>> x_walk_dist(n);
    vector<vector<int>> y_walk_dist(n);
    for(int bits = 0; bits < (1<<n); bits++){
        vector<int> x_road,y_road;
        rep(i,n) {
            if(bits>>i&1) {
                x_road.push_back(i);
                y_road.push_back(i);
            }
        }
        //最小歩行距離
        rep(i,n) {
            int x_walk = INF, y_walk = INF;
            chmin(x_walk, p[i]*abs(x[i]));
            chmin(y_walk, p[i]*abs(y[i]));
            for(auto road: x_road) {
                chmin(x_walk, p[i]*abs(x[road] - x[i]));
            }
            for(auto road: y_road) {
                chmin(y_walk, p[i]*abs(y[road] - y[i]));
            }
            x_walk_dist[i].push_back(x_walk);
            y_walk_dist[i].push_back(y_walk);
        }

    }
    //n 3^n
    vector<int> min_s(n+1,INF);
    //各集落でヨコに引くかタテに引くか引かないか
    for(int bits = 0; bits < (1<<n); bits++) {
        int one_num = __builtin_popcount(bits);
        //引くか引かないか
        for(int bits2 = 0; bits2 < (1<<one_num); bits2++) {
            int k = (n-__builtin_popcount(bits)) + __builtin_popcount(bits2);
            int bx = 0, by=0;
            int x_i = 0;
            rep(i,n) {
                if(bits>>i&1) {
                    if(bits2>>x_i&1){
                        bx += 1<<i;
                    }
                    x_i++;
                } else {
                    by += 1<<i;
                }
            }
            int s = 0;
            rep(i,n) {
                s += min(x_walk_dist[i][bx], y_walk_dist[i][by]);
            }
            chmin(min_s[k], s);
        }
    }
    rep(i,n+1) {
        cout << min_s[i] << endl;
    }
}


Measured memory_bytes: 11608
listed_str = list(input())
set_str = set(listed_str)
number_str = len(set_str)
count = 0
if(number_str == 2):
  for i in range(3):
    if(listed_str[0] == listed_str[i + 1]):
      count += 1
  if(count == 1):
    print("Yes")
  else:
    print("No")
else:
  print("No")

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  int n,sum_wmax;
  cin >> n >> sum_wmax;
  
  ll w[n],v[n];
  for(int i = 0;i<n;++i){
    cin >> w[i] >> v[i];
  }
  
  ll dp[n+5][sum_wmax+5];
  //初期化
  for(int i = 0;i<n+5;++i){
    for(int sum_w = 0;sum_w<sum_wmax+5;++sum_w){
      dp[i][sum_w] = 0; //初期条件
    }
  }
  
  //ループ
  for(int i = 0;i<n;++i){
    for(int sum_w=0;sum_w<=sum_wmax;++sum_w){
      chmax(dp[i+1][sum_w],dp[i][sum_w]); //品物iを選ばなかった時の価値の下限（初期化）
      if(sum_w - w[i] >= 0){
        chmax(dp[i+1][sum_w],dp[i][sum_w-w[i]]+v[i]);
      }
    }
  }
  ll ans = dp[n][sum_wmax];
  cout << ans;
}

Measured memory_bytes: 82304
# Aizu Problem ITP_1_1_D: Watch
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

sec = int(input())
hour = sec // 3600
sec = sec % 3600
minute = sec // 60
sec %= 60
print("%d:%d:%d" % (hour, minute, sec))

Measured memory_bytes: 7696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

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

  int i = 1;
  int count = 0;
  while (i < N) {
    if (S[i] != S[i-1]) {
      count++;
      i += 2;
    } else i++;
  }

  cout << count << endl;
}


Measured memory_bytes: 3332
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */

#include <iostream>
#include <fstream>

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

class ATenki {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s,t;
        in >> s >> t;
        int ans=0;
        rep(i,3){
            if(s[i]==t[i])ans++;
        }
        out <<ans <<endl;
	}
};


int main() {
	ATenki solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

string a,b;

int main(){
  cin>>a>>b;
  if(a.size()>b.size())cout<<"GREATER"<<endl;
  else if(a.size()<b.size())cout<<"LESS"<<endl;
  else{
    REP(i,a.size()){
      if((a[i]-'0')>(b[i]-'0')){cout<<"GREATER"<<endl;break;}
      else if((a[i]-'0')<(b[i]-'0')){cout<<"LESS"<<endl;break;}
      if(i==a.size()-1)cout<<"EQUAL"<<endl;
    }
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int used[252521];
int num[252521];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, a[252521];
  ll k;
  cin>>n>>k;
  REP(i, n){
    cin>>a[i];
    --a[i];
    used[i]=-1;
  }
  REP(i, n*2+3){
    num[i]=-1;
  }
  used[0]=0;
  num[0]=0;
  int cur=a[0];
  FOR(i, 1, n*2+2){
    num[i]=cur;
    if(used[cur]==-1){
      used[cur]=i;
      cur=a[cur];
    }
    else{
      int s=used[cur];
      if(k<=s){
        cout<<num[k]+1<<'\n';
      }
      else{
        k-=s;
        k%=(i-s);
        cout<<num[s+k]+1<<'\n';
      }
      return 0;
    }
  }
  return 0;
}


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

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define tc ll t;cin >> t;while(t--)

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll k;
	string s;
	cin >> k >> s;
	if(s.length() > k){
		for0(i,k){
			cout << s[i] ;
		}
		cout <<"..." << endl;
	}
	else{
		for0(i,s.length()){
			cout << s[i] ;
		}	
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
struct edge
{
    ll to,cost;
};
const ll MOD = 1000000007;
const ll n_max = 1e5,INF = 1e12;
vector<edge> G[n_max];
ll d[n_max];
void dijkstra(ll s)
{
    priority_queue<P,vector<P>,greater<P> > que;
    d[s] = 0;
    que.push(P(0,s));
    while(!que.empty())
    {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if(d[v] < p.first)
        {
            continue;
        }
        for(ll i = 0;i < G[v].size();i++)
        {
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main()
{
    ll n;
    cin >> n;
    for(ll i = 0;i < n - 1;i++)
    {
        ll u,v,w;
        cin >> u >> v >> w;
        u--;
        v--;
        w %= 2;
        G[u].push_back(edge{v,w});
        G[v].push_back(edge{u,w});
    }
    for(ll i = 0;i < n;i++)
    {
        d[i] = INF;
    }
    dijkstra(0);
    for(ll i = 0;i < n;i++)
    {
        cout << d[i] % 2 << "\n";
    }

    return 0;
}


Measured memory_bytes: 8704
def main():
    s = input()
    week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
    ans = 0
    for i, w in enumerate(week):
        if w == s:
            ans = 7 - i
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

ll a[1000001];

void test(){
	ll k;
	cin>>k;
	f(i,k)a[i]=0;
	ll cur = 0;
	ll cnt = 0;
	bool flag = true;
	while(true){
		cur = cur*10LL;
		cur = cur + 7;
		cnt++;
		if(cur%k==0){
			break;
		}else if(a[cur%k]==1){
			flag = false;
			break;
		}else{
			cur = cur%k;
			a[cur] = 1;
		}
	}
	if(flag)cout<<cnt<<"\n";
	else cout<<"-1\n";
}

int main(){
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


Measured memory_bytes: 11432
import java.util.Comparator;
import java.util.Scanner;
import java.util.Arrays;

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

        Integer[] a = new Integer[n];
        for (int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        int result = 0;
        for (int i = 0; i < n;i++){
            for (int j = 0; j < n; j++){
                a[j] = -a[j];
            }
            result = result - a[i];
        }
        System.out.println(result);


    }
}







Measured memory_bytes: 23124
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
     string[] str1 =Console.ReadLine().Split(' ');
      int H=int.Parse(str1[0]);
      int N=int.Parse(str1[1]);
      string[] waza=Console.ReadLine().Split(' ');
      
      for(int i=0;i<N;i++){
        int damage=int.Parse(waza[i]);
        H-=damage;
      }
      if(H<=0){
        Console.WriteLine("Yes");
      }else{
        Console.WriteLine("No");
      }
  }
  }
}

Measured memory_bytes: 16096
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=input()
    N=len(S)
    
    dp=[[0]*13 for _ in range(N+1)]
    dp[0][0]=1
    
    for i in range(N):
        s=S[i]
        
        for j in range(13):
            temp=dp[i][j]
            if s!="?":
                a=int(s)
                nxt=(j*10+a)%13
                dp[i+1][nxt]+=temp
                
            else:
                for k in range(10):# ?=0~9
                    nxt=(j*10+k)%13
                    dp[i+1][nxt]=(dp[i+1][nxt]+temp)%mod
                    
    print(dp[-1][5])
    
    # for i in range(N+1):
    #     print(dp[i])

main()


Measured memory_bytes: 95920
#include<iostream>

using namespace std;

long long a[200005];

int main(){
    long long n;
    long long sum=0;
    cin>>n;
    for(int i=0; i<n;++i){
        cin>>a[i];
        sum^=a[i];
    }
    for(int i=0; i<n;++i){
        cout<<(sum^a[i])<<' ';
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 5156
from collections import defaultdict
from itertools import product
from sys import stdin
def gen_b(x,B,b_d):
	if x not in b_d:
		if x < 3: lb = 2
		else: lb = x - 1
		if x > B-2: ub = B-1
		else: ub = x + 1
		b_d[x] = xrange(lb,ub+1)
	return b_d[x]
def solve():
	count = defaultdict(int)
	ans = [0]*10
	xb_d = dict(); yb_d = dict() 
	L = map(lambda x:map(int,x.split()),stdin.readlines())
	H,W,N = L[0]
	for i in xrange(1,N+1):
		for x,y in product(gen_b(L[i][0],H,xb_d),gen_b(L[i][1],W,yb_d)):
			count[x+(y<<34)] += 1
	for v in count.itervalues():ans[v] += 1
	ans[0] = (H-2)*(W-2) - sum(ans[1:])
	for c in ans: print c
solve()

Measured memory_bytes: 126104
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
      	// 文字列の入力
		string s = input[0];
		string t = input[1];
      
      	input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
      	int b = int.Parse(input[1]);
      
        string u = Console.ReadLine();
      
        if(u.Equals(s)) a -= 1;
        else if(u.Equals(t)) b -= 1;

		//出力
		Console.WriteLine(a + " " + b);
	}
}

Measured memory_bytes: 11092