akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int n;
vector<vector<int> > to(n + 1000000);
vector<vector<int> > cost(n + 1000000);

int main() {
    /* 入力受け取り */
    cin >> n;
    for (int i = 0; i < n-1; ++i){
      int a,b,w;
      cin >> a >> b >> w;
      a--;
      b--;
      to[a].push_back(b);
      to[b].push_back(a);
      cost[a].push_back(w);
      cost[b].push_back(w);
    }
  
    /* BFS */
    queue<int> que;
    vector<int> ans(n, -1);
    que.push(0);
    ans[0] = 0;
    //キューが0になるまでループ
    while(que.size()){
       //先頭のキューを取ってくる
       int p = que.front();
       que.pop();
       //先頭のキューに繋がっているノードを探索
       for(int i = 0; i < to[p].size(); ++i){
         int u = to[p][i];
         int w = cost[p][i];
         if(ans[u] != -1) continue;
         ans[u] = (ans[p] + w)%2;
         que.push(u);
       }
     }
  
    for(int i = 0; i < n; ++i)cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 54016
import kotlin.*

fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val h = sc.nextInt()
        val w = sc.nextInt()

        val n = sc.nextInt()
        val ab = Array(n) { sc.nextInt() to sc.nextInt() }

        val ans = Array(10) { 0L }

        var zero = (h - 2L) * (w - 2L)
        if(n == 0){
            ans[0] = zero
            println(ans.joinToString("\n"))
            return
        }
        val dx = arrayOf(-1, -1, -1, 0, 0, 0, 1, 1, 1)
        val dy = arrayOf(-1, 0, 1, -1, 0, 1, -1, 0, 1)

        val ls = mutableListOf<Pair<Int, Int>>()
        for (i in 0 until n) {
            for (j in 0 until 9) {
                val aa = ab[i].first + dy[j]
                val bb = ab[i].second + dx[j]
                if (aa <= 1 || aa >= h) continue
                if (bb <= 1 || bb >= w) continue
                val pair = aa to bb
                ls.add(pair)
            }
        }

        ls.sortWith(compareBy({ it.first }, { it.second }))

        var cnt = 1
        for (i in 1 until ls.size) {
            if (ls[i - 1] != ls[i]) {
                ans[cnt]++
                cnt = 0
                zero--
            }
            cnt++
        }
        ans[cnt]++
        zero--
        ans[0] = zero
        println(ans.joinToString("\n"))

    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        if (ptr >= l.size) {
            var s: String
            do {
                s = readLine()!!
            } while (s.isEmpty())
            l = s.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        val s = readLine()!!
        return if (s.isEmpty()) listOf() else s.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 151984
#include <stdio.h>
#include <string.h>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>
#include <math.h>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

int main() {
  long long a;
  scanf("%lld", &a);
 
  long long b = 0;
  long long c = 0;
 
  char next;
  scanf(" %c", &next);
  
  while (next != '.') {
    b *= 10;
    b += next - '0';

    //printf("%lld %d %d\n", b, next, '0');

    scanf("%c", &next);
  }

  scanf("%lld", &c);

  //printf("%lld %lld %lld\n", a, b, c);

  long long first = a * b;
  long long second = a * c;

  printf("%lld",  first + second / 100);
   



  return 0;
}


Measured memory_bytes: 1732
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func main() {
	solve(NewScanner())
}

func solve(s *Scanner) {
	wtr := bufio.NewWriter(os.Stdout)
	N, K := s.nextInt(), s.nextInt()
	formated := strconv.FormatInt(int64(N), K)
	fmt.Fprintln(wtr, len(formated))
	wtr.Flush()
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}


Measured memory_bytes: 640
fn main() {
    let input: Vec<i32> = read_vec();
    let a = input[0];
    let b = input[1];

    println!("{}", solve(a, b));
}

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

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

fn solve(a: i32, b: i32) -> i32 {
    a * b
}


Measured memory_bytes: 2088
from queue import deque

n = int(input())
li = [[] for _ in range(n)]
length = {}
length_path = [0]*n

for i in range(n-1):
    u,v,w = map(int,input().split())
    u,v = u-1,v-1
    length[(u,v)] = w
    li[u].append(v)
    li[v].append(u)

work_queue = deque([])
visited = [False]*n

work_queue.append(0)

while work_queue:
    now = work_queue.popleft()
    visited[now] = True
    for i in li[now]:
        if visited[i]:
            continue
        work_queue.append(i)
        visited[i] = True
        if now < i:
            length_path[i] = length_path[now]+length[(now,i)]
        else:
            length_path[i] = length_path[now]+length[(i,now)]

for i in length_path:
    print(i%2)

Measured memory_bytes: 44248
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<queue>
#include<map>
typedef long long ll;
using namespace std;
int main(){
	string s;
	cin>>s;
	bool f=true;
	if(s.length()&1) f=false;
	for(int i=1;i<=s.length();i++){
		if(s[i-1]!='i'&&!(i&1)){
			f=false;
			break;
		}
		if((i&1)&&s[i-1]!='h'){
			f=false;
			break;
		}
	}
	if(f) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  bool ans=false;
  if(a%3==0){
    ans = true;
  }else if(b%3==0){
    ans = true;
  }else if((a+b)%3==0){
    ans = true;
  }
  
  if(ans){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,X,M=map(int,input().split())
l=[-1]*(M+1)
f=lambda x: (x**2)%M
tmp=X
while l[tmp]==-1:
    res=f(tmp)
    l[tmp]=res
    tmp=res
ans=0
used=[False]*(M+1)
v=X
cnt=0
loop=[]
for cnt in range(1,N+1):
    if used[v]:
        cnt-=1
        break
    used[v]=True
    ans+=v
    v=l[v]
start=v
f=True
dist=0
while f or not v==start:
    f=False
    loop.append(v)
    dist+=v
    v=l[v]
ans+=dist*((N-cnt)//len(loop))
v=start
for _ in range(N-((N-cnt)//len(loop))*len(loop)-cnt):
    ans+=v
    v=l[v]
print(ans)

Measured memory_bytes: 71964
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}
int main(){
	int k;
	cin >> k;

	long long ans=0;
	for(int a=1; a<=k; ++a){
		for(int b=1; b<=k; ++b){
			for(int c=1; c<=k; ++c){
				ans+=gcd(a,gcd(b,c));
			}
		}
	} 
	cout << ans << endl;
}

Measured memory_bytes: 3616
import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read


n = int(input())
l = np.array(readline().split(), dtype=np.int64)
l, c = np.unique(l, return_counts=True)
x = len(l)
ans = 0
for i in range(x-2):
    for j in range(i+1, x-1):
        for k in range(j+1, x):
            if l[i] + l[j] > l[k] :
                ans += c[i] * c[j] * c[k]
print(ans)

Measured memory_bytes: 27316
def solve():
    ans = 0
    N = int(input())
    n = len(list(str(N)))
    if n%2==0:
        for i in range(1,n,2):
            ans += 10**(i-1)*9
    else:
        ans = N
        for i in range(2,n,2):
            ans -= 10**(i-1)*9
    return ans
print(solve())


Measured memory_bytes: 9080
if __name__ == "__main__":
    while True:
        try:
            #a, b = sorted(map(int, input().strip("\n").split(" ")), reverse=True)
            #str = input()
            #rts = str[::-1]
            #print(str)
            #print(rts)
            print(input()[::-1])

        except EOFError:
            break  # escape from while loop

Measured memory_bytes: 6720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    if(n==1)return cout<<"Hello World" , 0;
    ll a,b;cin>>a>>b;
    cout<<a+b;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int n,a,b;cin >>n>>a>>b;
    int ans=min(n*a,b);
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#define s 8 // マス目
#define F 1
#define NF -1

int A[s][s];
int row[s],col[s];
int pos[15],neg[15];


void print()
{
  int i,j;
  
  for(i=0;i<s;i++)
    {
      for(j=0;j<s;j++)
	{
	  if(A[i][j])
	    {
	      if(row[i]!=j) return;
	    }
	}
    }
  
  for(i=0;i<s;i++)
    {
      for(j=0;j<s;j++)
	{
	  if(row[i]==j) printf("Q");
	  else printf(".");
	}
      printf("\n");
    }
}

void putQueen(int i)
{
  int j;
  if(i==s)
    {
      print();
      return;
    }
  for(j=0;j<s;j++)
    {
      if(NF==col[j] || NF==pos[i+j] || NF==neg[i-j+s-1]) continue;
      row[i]=j;
      col[j] = pos[i+j] = neg[i-j+s-1] = NF;
      putQueen(i+1);
      row[i] = col[j] = pos[i+j] = neg[i-j+s-1] = F;
    }
}


int main()
{
  int i,j;
  int r,c,k;

  for(i=0;i<s;i++)
    {
      for(j=0;j<s;j++) A[i][j]=0;
    }

  scanf("%d",&k);
  for(i=0;i<k;i++)
    {
      scanf("%d%d",&r,&c);
      A[r][c] = 1;
    }

  for(i=0 ; i<s ; i++) row[i] = col[i] = F;
  for(i=0 ; i<15 ; i++) pos[i] = neg[i] = F;
   
  putQueen(0);

  return 0;
}







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

int main(){
    ll x;
    ll cnt = 0;
    cin >> x;
    cnt = 1000 * round(x/500);
    x = x%500;
    cnt += 5 * round(x/5);
    cout << cnt << endl;
    return 0;
}

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

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = new int[2].Concat(Console.ReadLine().Split(' ').Select(int.Parse)).ToArray();
        var counts = new int[N + 1];

        for (int i = 2; i <= N; i++)
        {
            var j = A[i];
            counts[j]++;
        }

        Console.WriteLine(string.Join(Environment.NewLine, counts.Skip(1)));
    }
}

Measured memory_bytes: 45020
u, s, e, w, n, d = map(int, input().split())
insts = input()
for inst in insts:
    if inst == 'N':
        u, s, n, d = s, d, u, n
    elif inst == 'E':
        u, e, w, d = w, u, d, e
    elif inst == 'S':
        u, s, n, d = n, u, d, s
    elif inst == 'W':
        u, e, w, d = e, d, u, w
print(u)

Measured memory_bytes: 7676
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main()
{
	int h, n;
	cin>>h>>n;
	
	vector<int> dp(h+1, INF);
	dp[0] = 0; 	
	while(n-- ) {
		int ap, cost;
		cin>>ap>>cost;
		
		for(int health=0; health<=h; health++)
		{
			int j = min(health + ap, h);
			
			dp[j] = min(dp[j], dp[health] + cost);
		}
	}
	cout<<dp[h];
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))


for i in range(N):
    if N == 1:
        print(A[0])
        break
    j = i

    while j > 0 and A[j] < A[j-1]:
        if A[j] > A[j-1]:

            break
        k = A[j]
        l = A[j-1]
        A[j-1] = k
        A[j] = l
        j -= 1

    S = str(A[0])
    for k in range(1,N-1):
        S += " " + str(A[k])

    S = S + " "+str(A[N-1])
    print(S)



Measured memory_bytes: 5592
#include<iostream>

using namespace std;

int main(){
  string S;
  string day[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};

  cin >> S;
  
  for(int i=0; i<7; i++){
    if(S == day[i]){
      cout << 7-i << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define maxn 500010
using namespace std;
int n,m;
int c[maxn],book[maxn],tree[maxn],ans[maxn];
struct node{
	int l,r,seq;
}q[maxn];
int lowbit(int x){
	return x&-x;
}
void add(int pos,int val){
	while(pos<=n){
		tree[pos]+=val;
		pos+=lowbit(pos);
	}
}
int sum(int pos){
	int ret=0;
	while(pos>0){
		ret+=tree[pos];
		pos-=lowbit(pos);
	}
	return ret;
}
int cmp(node a,node b){
	return a.r<b.r;
}
int main(){
	int i,j,start;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)scanf("%d",&c[i]);
	for(i=1;i<=m;i++)scanf("%d%d",&q[i].l,&q[i].r),q[i].seq=i;
	sort(q+1,q+1+m,cmp);
	start=1;
	for(i=1;i<=m;i++){
		for(j=start;j<=q[i].r;j++){
			if(book[c[j]])add(book[c[j]],-1);
			add(j,1),book[c[j]]=j;
		}
		start=q[i].r+1;
		ans[q[i].seq]=sum(q[i].r)-sum(q[i].l-1);
	}
	for(i=1;i<=m;i++)printf("%d\n",ans[i]);
	return 0;
}
 

Measured memory_bytes: 17304
import std;

auto input()
{
    return readln().chomp();
}

void main()
{
    // long[] ary = to!(long[])(split(readln()));
    auto ary = readln().split().to!(long[])();
    // writeln(join(to!(string[])(ary), " "));
    long a = ary[0];
    long b = ary[1];
    long c = ary[2];
    long k = ary[3];
    if (a >= k)
    {
        writeln(k);
    }
    else if (a + b >= k)
    {

        writeln(a);
    }
    else
    {
        writeln(a - (k - a - b));
    }
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MN = 110;
int n;
int l[MN], r[MN];

bool is[MN];

int main() {	
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b; a--;
		l[i] = a; r[i] = b;
	}
	int ba = 31;
	int co = 0;
	for (int i = 0; i < 31; i++) {
		int mi = 1000000;
		int mij = -1;
		for (int j = 0; j < n; j++) {
			if (is[j]) continue;
			if (!(l[j] <= i && i < r[j])) continue;
			if (r[j] < mi) {
				mi = r[j];
				mij = j;
			}
		}
		if (mij == -1) continue;
		ba++;
		is[mij] = true;
	}
	printf("%d\n", ba*50);
    return 0;
}

Measured memory_bytes: 1136
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
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(){
	ll n; cin>>n;
	vector<ll> a(n);
	vector<ll> b(n);
	rep(i,0,n){
		cin>>a[i]>>b[i];
	}
	sort(all(a));
	sort(all(b));
	reverse(all(b));

	if(n%2==1){
		cout<<b[(n-1)/2]-a[(n-1)/2]+1<<endl;
	}else{
		cout<<(b[n/2-1]+b[n/2]) - (a[n/2-1]+a[n/2])+1<<endl;
	}
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> num(n,-1);
    int s, c;
    rep(i,m) {
        cin >> s >> c;
        if (num[s-1] == -1 || num[s-1] == c) {
            num[s-1] = c;
        } else {
            cout << -1 << endl;
            return 0;
        }
    }

    if (n != 1 && num[0] == 0) {
        cout << -1 << endl;
        return 0;
    } else if (n != 1 && num[0] == -1) {
        num[0] = 1;
    }
    for (auto& v : num) {
        if (v == -1) {
            cout << 0;
        } else {
            cout << v;
        }
    }
    cout << endl;
    return 0;
}


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

using namespace std;

const int MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int64_t> counts(N + 10, 0);
  counts[0] = 1;
  for (int i = 0; i < M; i++) {
    int A;
    cin >> A;
    counts[A] = -1;
  }

  for (int i = 0; i <= N; i++) {
    if (counts[i] == -1) continue;
    if (counts[i + 1] != -1) {
      counts[i + 1] = (counts[i + 1] + counts[i]) % MOD;
    }
    if (counts[i + 2] != -1) {
      counts[i + 2] = (counts[i + 2] + counts[i]) % MOD;
    }
  }
  cout << counts[N] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; ++i)

using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll b_numc[n+1];
    rep(i, n+1) b_numc[i] = 0;
    rep(i, n) {
        auto ci_itr = lower_bound(c.begin(), c.end(), b[i]+1);
        size_t ci_pos = distance(c.begin(), ci_itr);
        int cnt_c = n - (int)ci_pos;
        //cout << cnt_c << endl;
        b_numc[i+1] = b_numc[i] + cnt_c;
    }
    //rep(i, n+1) cout << i << ": " << b_numc[i] << endl;

    ll ans = 0;
    rep(i, n) {
        //cout << "ans: " << ans << endl;
        int ai = a[i];
        auto bi_lb = lower_bound(b.begin(), b.end(), ai+1);
        size_t lb_pos = distance(b.begin(), bi_lb);
        //cout << "lb_pos: " << lb_pos << endl;
        ans += (b_numc[n] - b_numc[lb_pos]);

    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define int int64_t

const int MAXN = 2e5;
int a[MAXN], b[MAXN];

main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    set<pair<int, int>> st;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        if (b[i] < a[i]) {
            cout << -1;
            return 0;
        }
        if (b[i] != a[i]) {
            st.insert({b[i], i});
        }
    }
    while (!st.empty()) {
        auto it = st.end();
        it--;
        int ind = it->second;
        int val = it->first;
        int sum = b[(ind + 1) % n] + b[(ind - 1 + n) % n];
        int x = (b[ind] - a[ind]);
        int cnt = x / sum;
        if (cnt == 0) {
            cout << -1;
            return 0;
        }
        ans += cnt;
        b[ind] -= cnt * sum;
        st.erase({val, ind});
        if (b[ind] != a[ind]) {
            st.insert({b[ind], ind});
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 15872
#include <iostream>
using namespace std;
 
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int x=0, max=0;
    for(int i=0; i<n; i++)
    {
        if(s[i]=='I')
        {
            x++;
            if(x>max)
            max=x;
 
        }
        else if(s[i]=='D')
        {
            x--;
        }
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int group[2];
	for (int i = 0; i < 2; i++) {
		int n;
		scanf("%d", &n);
		switch (n)
		{
		case 4:
		case 6:
		case 9:
		case 11:
			group[i] = 1;
			break;
		case 2:
			group[i] = 2;
			break;
		default:
			group[i] = 0;
			break;
		}
	}

	if (group[0] == group[1])	printf("Yes");
	else	printf("No");

	return 0;
}

Measured memory_bytes: 128
from collections import defaultdict,deque
n = int(input())
d = defaultdict(list)
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        d[i].append((x-1,bool(y)))
        
maxi = 0
for i in range(2 ** n):
    honest = [-1]*n
    que = deque([])
    for j in range(n):
        if ((i >> j) & 1):
            que.append(n-1-j)
            honest[n-1-j] = True
    flag = True
    while que and flag:
        v = que.popleft()
        for x,y in d[v]:
            if honest[x] == -1:
                honest[x] = y
                if y:
                    que.append(x)
            elif honest[x] != y:
                flag = False
                break
    if flag:
        maxi = max(maxi,str(bin(i)).count('1'))
print(maxi)

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

main(){
  int r,D;
  int x[20];
  cin >> r >> D >> x[0];

  for(int i=0;i<10;i++){
    x[i+1]=x[i]*r-D;
  }
  
  for(int i=1; i<11; i++) {
    cout << x[i] << endl;
  }
  
  
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


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

  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int p, x;
    cin >> p >> x;
    cout << sum - (A[p - 1] - x) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
# AOJ ITP2_1_D Vector II

from collections import deque
n, q = map(int, input().split())
Q = []

for i in range(n):
    Q.append(deque())
for i in range(q):
    a = input().split()
    t = int(a[1])
    if a[0] == '0':
        Q[t].append(a[2])
    elif a[0] == '1':
        print(*Q[t])
    else:
        Q[t].clear()



Measured memory_bytes: 42824
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const long long MAXN = 100005;
long long n;
long long arr[MAXN];
long long go(long long mid){
    for(long long i=1;i<=n;i++){
        if(arr[i] > mid)return false;
        long long mo = mid / arr[i];
        mid = mo * arr[i];
    }
    return mid;
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    for(long long i=1;i<=n;i++){
        cin>>arr[i];
    }
    long long mn = 2e18;
    long long mx = -2e18;
    long long lo = 2;
    long long hi = 2e18;
    while(lo <= hi){
        long long mid = (lo+hi)/2;
        if(go(mid)<2){
            lo = mid + 1;
        }
        else if(go(mid)>2){
            hi = mid - 1;
        }
        else{
            lo = mid + 1;
            mx = max(mx,mid);
            
        }
    }
    lo = 2; hi = 2e18;
    while(lo <= hi){
        long long mid = (lo+hi)/2;
        if(go(mid)<2){
            lo = mid + 1;
        }
        else if(go(mid)>2){
            hi = mid - 1;
        }
        else{
            hi = mid - 1;
            mn = min(mn,mid);
        }
    }
    if(mx == -2e18 || mn == 2e18){
        cout<<-1; exit(0);
    }
    cout<<mn<<' '<<mx;
    
    
    
    return 0;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  int a[55];
  int b[55];
  vector<int> c(55);
  for(int i=0;i<M;i++){
    cin >> a[i] >> b[i];
  }
  
  for(int i=0;i<N;i++){
    //c[i]=i+1;
    for(int j=0;j<M;j++){
    	if((i+1)==a[j]||(i+1)==b[j]){
          c.at(i)++;
        }
    }
  }
  for(int i=0;i<N;i++){
    cout << c.at(i) << endl;
  }
}

         
    
  
  

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    int n, q;
    cin >> n >> q;
    vector<char> s(n);
    REP(i, n) cin >> s[i];
    vector<char> c(q), t(q);
    REP(i, q) cin >> c[i] >> t[i];
    
    int ans = n;
    
    int left = -1, right = n;
    while (right - left > 1) {
        int mid = (left + right) / 2;
        int now = mid;
        bool flag = false;
        REP(i, q) {
            if (c[i] == s[now]) {
                if (t[i] == 'L') --now;
                else ++now;
                if (now == -1) {
                    flag = true;
                    break;
                }
                if (now == n) {
                    break;
                }
            }
        }
        if (flag) left = mid;
        else right = mid;
    }
    ans -= right;
    
    left = -1; right = n;
    while (right - left > 1) {
        int mid = (left + right) / 2;
        int now = mid;
        bool flag = false;
        REP(i, q) {
            if (c[i] == s[now]) {
                if (t[i] == 'L') --now;
                else ++now;
                if (now == -1) {
                    break;
                }
                if (now == n) {
                    flag = true;
                    break;
                }
            }
        }
        if (flag) right = mid;
        else left = mid;
    }
    ans -= (n - right);
    
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N;
    cin>>N;
    string S;
    cin>>S;
    if(S.at(0)=='W' || S.at(2*N-1)=='W'){
        cout<<0<<endl;return 0;
    }
    vector<int> fro(2*N),bac(0);
    rep(i,2*N){
        if(i%2==0){
            if(S.at(i)=='B'){fro.at(i)=1;}
            else{bac.pb(i);}
        }
        else{
            if(S.at(i)=='W'){fro.at(i)=1;}
            else{bac.pb(i);}
        }
    }
    if(bac.size()!=N){
        cout<<0<<endl;return 0;
    }
    ll count=0;
    ll ans=1;
    for(int i=2*N-1;i>=0;i--){
        if(fro.at(i)){
            ans*=bac.end()-lower_bound(bac.begin(),bac.end(),i)-count;
            ans%=MOD;
            count++;
        }
    }
    rep(i,N){
        ans*=i+1;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1920
#include <stdio.h>
int main(void)
{
    int i,x;

    scanf("%d",&x);

    for(i=1;i<100000;i++){
        printf("Case %d: %d\n",i,x);
        scanf("%d",&x);

        if(x==0)    break;
    }

    return 0;
}


Measured memory_bytes: 2028
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1073741824
#pragma GCC optimization ("O3")
using namespace std;
const int N = 100*1000+5;
#define all(x) begin(x),end(x)
int main()
{
   
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    string s,t;
    cin >> s >>t;
    cout << t << s;
    return 0;
}

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

#define int 		long long
#define vi 			vector <int>
#define si 			set <int>
#define pii 		pair<int,int>
#define fr(n) 		for(__typeof(n) i=0;i<n;i++)
#define rep(i,a,b) 	for(__typeof(b) i=a;i<b;i++)
#define repi(i,b,a) for(__typeof(a) i=b;i>=a;i--)
#define tr(a) 		for(auto it=a.begin();it!=a.end();it++)
#define pb 			push_back
#define mp 			make_pair
#define F 			first
#define S 			second
#define FAST 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define time_passed	1.0 * clock() / CLOCKS_PER_SEC

void solve()
{
	int n;
	cin>>n;
	if(n%2==0)
	{
		cout<<-1;
		return;
	}
	map <int,int> m;
	int ans=1;
	int y=7;
	int x=7%n;
	m[7]++;
	while(x && ans<n)
	{
		y=(y*10)%n;
		x=(x+y)%n;
		if(m.find(x)!=m.end())
		{
			cout<<-1;
			return;
		}
		else
		{
			m[x]++;
		}
		ans++;
	}
	cout<<ans;
}

signed main()
{
	FAST
	int test=1;
	//cin>>test;
	while(test--)
	{
		solve();
	}
	cerr<<endl<<"Time elapsed : "<<time_passed<<endl;
	return 0;
}

Measured memory_bytes: 66292
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 1000000100000000000
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define st size_t
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=1005;
const int NN=1000001;
const ll md=998244353;



int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    str s;
    cin >> s;
    if (s[3]==s[2] && s[5]==s[4]){
        cout << "Yes" << E;
    }else cout << "No" << E;
    r0;
}


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

std::string yesno(bool b) {
    return b ?
//        "Yes" : "No";
        // "YES" : "NO";
        // "yes" : "no";
        "POSSIBLE" : "IMPOSSIBLE";

}

long long gcd(long long a, long long b){
    if(a < b)
        return gcd(b,a);
    if(b == 0)
        return a;
    return gcd(b, a%b);
}

int main() {
    long long n,k;
    std::cin >> n >> k;
    long long maxim = 0;
    long long G = 0;
    for (int i = 0; i < n; ++i) {
        long long tmp;
        std::cin >> tmp;
        maxim = std::max(maxim, tmp);
        G = gcd(tmp, G);
    }
    std::cout << yesno(maxim >= k && k % G == 0) << std::endl;

}


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

#define INF 1000000007
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl << "\n" ;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		int n,m;
		cin >> n >> m;
		int a[n];
		int sum=0;
		for(int i=0;i<n;i++){
			cin >> a[i];
			sum += a[i];
		}
		// cout << sum endl
		sort(a,a+n,greater<int>());
		int m1 = sum/(4*m);
		if(sum%(4*m)!=0) m1++;
		// cout << m1 endl
		int ans=0;
		for(int i=0;i<min(m,n);i++){
			if(a[i]>=m1) ans++;
		}
		if(ans >= m) cout << "Yes" endl
		else cout << "No" endl
	}
	return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, string S, string T) {
    return roundRobin(S, T).map!(to!string).join;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    string S;
    S = input.front.to!string;
    input.popFront;

    string T;
    T = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(N, S, T);
    else {
        auto ans = solve(N, S, T);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
using namespace std;
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 T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
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); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<int> Eratosthenes(const int N)
{
    vector<bool> is_prime(N+1, true);
    vector<int> P;
    for(int i=2; i<=N; i++) {
        if (is_prime[i]) {
            for(int j=2*i; j<=N; j+=i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) {
        cin >> d[i];
    }
    sort(all(d));
    int half = d.size()/2 -1 ;
    // cout << half << endl;
    int res = d[half+1]-d[half];
    cout << res << "\n";
}

Measured memory_bytes: 640
package main

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

type Dice struct {
	Faces []int
	Sides map[int][]int
}

func NewDice(n []int) *Dice {
	d := &Dice{
		Faces: n,
		Sides: make(map[int][]int),
	}

	d.Sides[d.Faces[0]] = []int{d.Faces[1], d.Faces[2], d.Faces[4], d.Faces[3]}
	d.Sides[d.Faces[1]] = []int{d.Faces[0], d.Faces[3], d.Faces[5], d.Faces[2]}
	d.Sides[d.Faces[2]] = []int{d.Faces[0], d.Faces[1], d.Faces[5], d.Faces[4]}
	d.Sides[d.Faces[3]] = reverse(d.Sides[d.Faces[2]])
	d.Sides[d.Faces[4]] = reverse(d.Sides[d.Faces[1]])
	d.Sides[d.Faces[5]] = reverse(d.Sides[d.Faces[0]])

	return d
}

func reverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[len(a)-1-i] = a[i]
	}
	return b
}

func (d *Dice) lookUpLabel(up, front int) int {
	s := d.Sides[up]
	s = append(s, s...)
	for i, v := range s {
		if v == front {
			return s[i+1]
		}
	}
	return 0
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)

	sc.Scan()
	faces := make([]int, 6)
	for i, s := range strings.Split(sc.Text(), " ") {
		faces[i], _ = strconv.Atoi(s)
	}
	d := NewDice(faces)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	for i := 0; i < n; i++ {
		sc.Scan()
		s := strings.Split(sc.Text(), " ")
		up, _ := strconv.Atoi(s[0])
		front, _ := strconv.Atoi(s[1])
		fmt.Println(d.lookUpLabel(up, front))
	}

}



Measured memory_bytes: 1080
import scala.math.BigInt
import scala.io.StdIn

object Main {

  type BI = BigInt

  def main(args: Array[String]): Unit = {
    val s: List[Char] = StdIn.readLine().toList
    println(s"${solve(s, 0, 0)}")
  }

  def solve(s: List[Char], aAlive: BI, ans: BI): BI = {
    s match {
      case Nil => ans
      case 'A' :: t => solve(t, aAlive + 1, ans)
      case 'B' :: 'C' :: t => solve(t, aAlive, ans + aAlive)
      case _ :: t => solve(t, 0, ans)
    }
  }

}


Measured memory_bytes: 44300
#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>;


int main() {
    vector<int> N(5);
    rep(i, 5) cin >> N[i];
    int k;
    cin >> k;

    sort(N.begin(), N.end());
    if (N[4] - N[0] > k) cout << ":(" << endl;
    else cout << "Yay!" << endl;
}

Measured memory_bytes: 3616
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>

using namespace std;
const int64_t INF=10000000000000000;

int main(){
	int64_t h_size,w_size,h,w;
	cin>>h_size>>w_size>>h>>w;
	int64_t ans[h_size][w_size];
	if(h_size%h==0&&w_size%w==0){
		cout<<"No"<<endl;
	}else{
		int64_t sum=0;
		int64_t T=(1000000000-1)/(h*w-1);
		for(int64_t i1=0;i1<h_size;i1++){
			for(int64_t i2=0;i2<w_size;i2++){
				if(i1%h==(h-1)&&i2%w==(w-1)){
					ans[i1][i2]=-((h*w-1)*T+1);
					sum-=((h*w-1)*T+1);
				}else{
					ans[i1][i2]=T;
					sum+=T;
				}
			}
		}
		if(sum>0){
			cout<<"Yes"<<endl;
			for(int64_t i1=0;i1<h_size;i1++){
				for(int64_t i2=0;i2<w_size;i2++){
					cout<<ans[i1][i2]<<" ";
				}
				cout<<endl;
			}
		}else{
			cout<<"No"<<endl;
		}

	}
}


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

int main() {
	int n;
	int in[2][4];
	while(cin >> n, n) {
		for(int t = 0; t < n; t++) {
			for(int i = 0; i < 2; i++) {
				for(int j = 0; j < 4; j++) {
					cin >> in[i][j];
				}
			}

			cout << (in[0][0]*in[1][0] - in[0][1]*in[1][1] - in[0][2]*in[1][2] - in[0][3]*in[1][3]) << " ";
			cout << (in[0][0]*in[1][1] + in[0][1]*in[1][0] + in[0][2]*in[1][3] - in[0][3]*in[1][2]) << " ";
			cout << (in[0][0]*in[1][2] - in[0][1]*in[1][3] + in[0][2]*in[1][0] + in[0][3]*in[1][1]) << " ";
			cout << (in[0][0]*in[1][3] + in[0][1]*in[1][2] - in[0][2]*in[1][1] + in[0][3]*in[1][0]) << endl;
		}
	}
}

Measured memory_bytes: 1160
INF = int(1e9+7)


def main():
    N, M, *a = map(int, open(0).read().split())
    a = set(a)
    dp = [0] * (N + 1)
    dp[:2] = 1, 1 if 1 not in a else 0
    for i in range(2, N + 1):
        if i not in a:
            dp[i] = (dp[i - 1] + dp[i - 2]) % INF
    print(dp[-1])
    return


main()


Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)
 
int32_t main() { 
	boost;
	
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int cycle =0 ;
	int visit[n+1] = {0};
	int cur = 1;
	
	while(!visit[cur]){
		visit[cur] = cycle;
		cur = a[cur];
		cycle++;
	}
	//cout<<cur<<" "<<visit[cur]<<endl;
	cycle -=visit[cur];
	if(cycle == 0){
		cout<<cur<<endl;
		return 0;
	}
	else if(k<visit[cur]){
		cur = 1;	
		while(k>0){
			cur = a[cur];
			k--;
		}
		cout<<cur<<endl;
		return 0;
	}

	k -= visit[cur];
	k%=cycle;
	while(k>0){
		cur = a[cur];
		k--;
	}
	cout<<cur<<endl;

}	

Measured memory_bytes: 6740
#include<bits/stdc++.h>
#define M 200005
using namespace std;
int n,cnt,A[M],B[M],ans[M];
bool f;
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++)scanf("%d",&A[i]);
	for(int i=n; i>=1; i--) {
		for(int j=i+i; j<=n; j+=i)A[i]^=A[j];
		if(A[i])cnt++;
	}
	printf("%d\n",cnt);
	for(int i=1; i<=n; i++)
		if(A[i])printf("%d ",i);
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
l = [input() for _ in range(n)]

def set_str(l):
    return len(l) == len(set(l))
if set_str(l):
    occurrence_No = True
    for i in range(len(l)):
        call_l = l[i]
        if i != 0 and l[i-1][-1] != call_l[0] :
            print("No")
            occurrence_No = False
            break
    if occurrence_No:
        print("Yes")
else:
    print("No")

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    ll N;
    cin >> N;
    ll ans;
    ans = N * (N-1);
    ans /= 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

class pcompare {
public:
	bool operator()(pll a, pll b) {
		return (a.sc < b.sc);
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	ll ans=0;
	cin>>n>>m;
	vl a(m),b(m);
	vector<pll> v(m);
	rep(i,m){
		cin>>a[i]>>b[i];
		v[i]=(pll(a[i],b[i]));
	}
	ll bp=-1;
	sort(all(v),pcompare());
	rep(i,m){
		if(bp<v[i].fs){
			ans++;
			bp=v[i].sc-1;
		}
	}
	cout<<ans<<endl;
}

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

int main(){
  int i,j,cnt=0;
  string s;
  cin>>s;
  string C="CODEFESTIVAL2016";
  for(i=0;i<C.size();i++){
    if(s[i]!=C[i])cnt++;
  }
  cout<<cnt;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p)*(b))%m;
		b=((b)*(b))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	string n;
	cin>>n;
	ll ans=0;
	for(auto x:n)
	{
		ans += (x-'0');
	}
	cout<<(ans%9==0?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
#include <set> 
using namespace std;

typedef long long ll;
typedef pair<ll, int> P;
typedef pair<pair<int, int>, int> PP;

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

const ll INF = 1e15;
const ll MAX = 510000;
const ll MOD = 1000000007;


int main(void) {
	int A, B; cin >> A >> B;
	int sashi = 1;
	int ans = 0;
	while (sashi < B) {
		sashi += A - 1;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
typedef pair<int,int> pii;
#define mp make_pair
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=3010,Mod=1e9+7;
int n,m,f[N][N][2];
int main()
{
	n=gi();m=gi();
	for(int i=0;i<=n;i++)f[0][i][i==0]=1;
	for(int i=1;i<=m;i++)
		for(int j=0;j<=n;j++)
			for(int k=0;k<2;k++)
			{
				if(j)
				{
					f[i][j][k|(j==1)]=(f[i][j][k|(j==1)]+f[i-1][j][k])%Mod;
					f[i][j-1][k|(j==1)]=(f[i][j-1][k|(j==1)]+f[i-1][j][k])%Mod;
				}
				if(j<n)
				{
					f[i][j+1][k]=(f[i][j+1][k]+f[i-1][j][k])%Mod;
					f[i][j][k]=(f[i][j][k]+f[i-1][j][k])%Mod;
				}
			}
	int ans=0;
	for(int i=0;i<=n;i++)ans=(ans+f[m][i][1])%Mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 70784
#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#define eps 0.01
#define pi acos(-1)
#define e exp(1)
using namespace std;
typedef long long ll;
const int maxn = 100;
int n;
ll a[maxn + 10];
int main() {
    while (cin >> n) {
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        ll ans = -1;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                ll num = abs(a[i] - a[j]);
                ans = max(ans, num);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256