akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector <long long> a(n);
    cin >> a;
    forn (i, 0, k) {
        bool need_to_stop = true;
        forn (j, 0, n)
            if (a[j] < n)
                need_to_stop = false;
        if (need_to_stop) {
            cout << a;
            return 0;
        }
        vector <long long> delta(n + 1);
        forn (j, 0, n) {
            delta[max(0LL, j - a[j])]++;
            delta[min(1LL * n, j + a[j] + 1)]--;
        }
        long long cur = 0;
        forn (j, 0, n) {
            cur += delta[j];
            a[j] = cur;
        }
        cerr << a << "\n";
    }
    cout << a;
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}
//--------------------------------------------------//
const int MOD = 1e9 + 7;
int choose[2010][2010];
int main() {
  use_cio();
  int n, k;
  cin >> n >> k;
  choose[0][0] = 1;
  repp(i, 1, 2010) {
    choose[i][0] = 1;
    repp(j, 1, 2010) choose[i][j] = (choose[i - 1][j - 1] + choose[i - 1][j]) % MOD;
  }
  repp(i, 1, k + 1) cout << (1LL * choose[k - 1][i - 1] * choose[n - k + 1][i]) % MOD
                         << endl;
}


Measured memory_bytes: 16000
#include <cstdio>
#include <cstring>
#define rng(x, y) (0 <= x && x < W && 0 <= y && y < H)
int H, W, n, gx, gy, x[12][12], d[4] = { 1, 0, -1, 0 };
int solve(int sx, int sy, int depth) {
	if (depth == n) {
		if (sx == gx || sy == gy) return 1;
		return 0;
	}
	int ret = 0;
	for (int i = 0; i < 4; i++) {
		int tx = sx + d[i], ty = sy + d[i ^ 1];
		while (rng(tx, ty)) {
			if (x[ty][tx] == 1) {
				x[ty][tx] = 0;
				ret += solve(tx, ty, depth + 1);
				x[ty][tx] = 1;
				break;
			}
			tx += d[i];
			ty += d[i ^ 1];
		}
	}
	return ret;
}
int main() {
	while (scanf("%d%d", &W, &H), W | H) {
		n = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				scanf("%d", &x[i][j]);
				if (x[i][j] == 1) n++;
				if (x[i][j] == 2) gx = j, gy = i;
			}
		}
		printf("%d\n", solve(gx, gy, 0));
	}
	return 0;
}

Measured memory_bytes: 2576
package main

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

type vacation struct {
	a int
	b int
	c int
}

func main() {
	n := readi()
	vacations := make([]vacation, n)
	for i := 0; i < n; i++ {
		vacations[i].a = readi()
		vacations[i].b = readi()
		vacations[i].c = readi()
	}

	dp := make([][3]int, n)
	dp[0][0] = vacations[0].a
	dp[0][1] = vacations[0].b
	dp[0][2] = vacations[0].c
	for i := 1; i < n; i++ {
		for ii := 0; ii < 3; ii++ {
			for iii := 0; iii < 3; iii++ {
				if iii != ii {
					switch ii {
					case 0:
						chmax(&dp[i][0], vacations[i].a+dp[i-1][iii])
					case 1:
						chmax(&dp[i][1], vacations[i].b+dp[i-1][iii])
					case 2:
						chmax(&dp[i][2], vacations[i].c+dp[i-1][iii])
					}
				}
			}
		}
	}

	fmt.Println(max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]))
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 7040
import java.io.*;

class Main {
	public static void main(String args[]) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s;
			s = reader.readLine();
			for(int i = s.length()-1;i >=0;i--) {
				System.out.print(s.charAt(i));
			}
			System.out.println("");
		}
		catch(IOException e) {
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 16928
import sys
input=sys.stdin.readline
D=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(D):
    sub=list(map(int,input().split()))
    s.append(sub)
t=[]
for i in range(D):
    t.append(int(input()))

h=0
last=[-1]*26

for i in range(D):
    h+=s[i][t[i]-1]
    last[t[i]-1]=i
    for j in range(26):
        h-=c[j]*(i-last[j])

m=int(input())
for _ in range(m):
    d,q=map(int,input().split())
    h+=s[d-1][q-1]-s[d-1][t[d-1]-1]
    o=t[d-1]
    t[d-1]=q

    pre=1
    for i in range(d-2,-1,-1):
        if t[i]==o:
            break
        pre+=1
    post=1
    for j in range(d,D):
        if t[j]==o:
            break
        post+=1
    h-=c[o-1]*pre*post

    pre = 1
    for i in range(d - 2, -1, -1):
        if t[i] == q:
            break
        pre += 1
    post = 1
    for j in range(d, D):
        if t[j] == q:
            break
        post += 1
    h += c[q - 1] * pre * post

    print(h)




Measured memory_bytes: 76328
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		int K = Integer.parseInt(in.nextLine());
		in.close();
		Set<String> targetStrs = getTargetStrs(s);
		Set<String> subStrs = new TreeSet<>();
		for (String targetStr : targetStrs) {
			subStrs.addAll(getSubStrs(targetStr)[1]);
		}
		List<String> subStrList = new ArrayList<>();
		subStrList.addAll(subStrs);
		Collections.sort(subStrList);
		System.out.println(subStrList.get(K - 1));
	}

	public static Set<String> getTargetStrs(String s) {
		Set<Character> headChars = new TreeSet<>();
		for (int i = 0; i < s.length(); ++i) {
			headChars.add(s.charAt(i));
		}
		List<Character> list = new ArrayList<>();
		list.addAll(headChars);
		Collections.sort(list);
		Character limitChar = list.get(Math.min(4, headChars.size() - 1));
		Set<String> result = new HashSet<>();
		for (int i = 0; i < s.length(); ++i) {
			if (s.charAt(i) <= limitChar) {
				result.add(s.substring(i, Math.min(i + 5, s.length())));
			}
		}
		return result;
	}

	/**
	 * [0]: 今回生成したもの [1]: 全体
	 * 
	 * @param s
	 * @return
	 */
	public static Set<String>[] getSubStrs(String s) {
		Set<String>[] result = new Set[2];
		if (s.length() == 1) {
			result[0] = new HashSet<String>();
			result[1] = new HashSet<String>();
			result[0].add(s);
			result[1].add(s);
			return result;
		} else {
			Set<String>[] subStrs = getSubStrs(s.substring(1, s.length()));
			result[1] = subStrs[1];
			result[0] = new HashSet<String>();
			String head = s.substring(0, 1);
			result[0].add(head);
			for (String subStr : subStrs[0]) {
				result[0].add(head + subStr);
			}
			result[1].addAll(result[0]);
			return result;
		}
	}
}

Measured memory_bytes: 29004
#include<iostream>
using namespace std;
int main()
{
	int S;
	cin>>S;
	int h;
	h = S / 3600;
	int m;
	m = S % 3600 / 60;
	int s;
	s = S % 3600 % 60;
	cout<< h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <boost/math/common_factor_rt.hpp>

#define ll long long

using namespace std;

int main() {
	ll n;
	ll ans = 1000000;
	cin >> n;

	for (int i = 1; i < n; i++)
	{
		ll sum = 0;
		ll dig = 0;
		ll a = i;
		ll b = n - a;

		while (a) {
			dig = a % 10;
			sum = sum + dig;
			a = a / 10;
		}

		ll A = sum;

		sum = 0;
		dig = 0;

		while (b) {
			dig = b % 10;
			sum = sum + dig;
			b = b / 10;
		}

		ll B = sum;

		ans = min(ans, A + B);

	}

	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = (1<<30);
ll inf = (1LL<<60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int divisor[1100];
void prime_fact(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i != 0) continue;
		while (x % i == 0) {
			x /= i;
			divisor[i]++;
		}
	}
	divisor[x]++;
	return;
}
int main() {
	int n;
	cin >> n;
	int i;
	ll ans = 1;
	for (i = n; i > 1; i--) {
		prime_fact(i);
	}
	for (i = 2; i < 1100; i++) {
		ans *= (divisor[i] + 1);
		ans %= 1000000007;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vec{
    double x, y;
};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
     return false;
}
template<class T>
T min(T a, T b)
{
    if (a < b) return a;
    return b;
}
template<class T>
T max(T a, T b)
{
    if (a > b) return a;
    return b;
}
using namespace std;
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    int X;
    cin >> X;
    if (X < 30) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

long long N, A, B, C;
vector<long long> l(10);

int dfs(int cur, int a, int b, int c) {
  if (cur == N)
    return (min({a,b,c}) > 0 ? (abs(a - A) + abs(b - B) + abs(c - C) - 30) : 100000000 );
  int ret0 = dfs(cur + 1, a, b, c);
  int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;
  int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;
  int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;
  return min({ret0, ret1, ret2, ret3});
}

int main() {
  cin >> N >> A >> B >> C;
  for (int i=0; i<N; i++) cin >> l.at(i);
  cout << dfs(0,0,0,0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  cout << min(N * A, B) << endl;
  return 0;
}


Measured memory_bytes: 256
# input で空白をいれて複数数値を入れると、複数とれる
i = input()

# listを使って[x,y]が作れる
# i.split で、複数に分けれる
# map を使うとlist の中身をとれる
a,b = list(map(int, i.split()))
#a,b = map(int, i.split())


# 面積 a * b
print(a*b,2*(a+b))


Measured memory_bytes: 5580
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int base = 100000;
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int next = (int) ((base * 1.05) / 1000) * 1000;
            if ((base * 1.05) % 1000 > 0){
                next += 1000;
            }
            base = next;
        }
        System.out.println(base);
    }
}

Measured memory_bytes: 26128
n = gets.to_i
a = gets.split.map(&:to_i)
gets
m = gets.split.map(&:to_i)

list = {}
(1..n).each do |i|
  a.combination(i).each do |e| 
    list[e.reduce(&:+)] = nil
  end
end
m.each do |e|
  puts list.key?(e) ? 'yes' : 'no'
end

Measured memory_bytes: 9692
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    //Map<String, Integer> map = new HashMap<String, Integer>();
    int n = sc.nextInt();
    int t = sc.nextInt();
    int a = sc.nextInt();
    int findID = 0;
    double min = 1000000.0;

    for(int i = 0; i < n; i++){
      int h = sc.nextInt();
      double d = Math.abs(a-(t-0.006*h));
      if(min >= d){
        min = d;
        findID = i+1;
      }
    }

    System.out.println(findID);

  }
}


Measured memory_bytes: 24148
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,l;
  cin >> n >> l;
  vector<string> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  for(int i = 0; i < n; i++){
    cout << v[i];
  }
  cout << '\n';
 
  
}

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

const int mod = 1000000007;
struct mint
{
	ll x; // typedef long long ll;
	mint(ll x = 0) : x((x % mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint &operator+=(const mint a)
	{
		if ((x += a.x) >= mod)
			x -= mod;
		return *this;
	}
	mint &operator-=(const mint a)
	{
		if ((x += mod - a.x) >= mod)
			x -= mod;
		return *this;
	}
	mint &operator*=(const mint a)
	{
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const
	{
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const
	{
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const
	{
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const
	{
		if (!t)
			return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1)
			a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const
	{
		return pow(mod - 2);
	}
	mint &operator/=(const mint a)
	{
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const
	{
		mint res(*this);
		return res /= a;
	}
};

struct combination
{
	vector<mint> fact, ifact;
	combination(int n) : fact(n + 1), ifact(n + 1)
	{
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i)
			fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i)
			ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k)
	{
		if (k < 0 || k > n)
			return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};

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

	combination c(n+5);
	mint ans = 0;

	rep(ri,2) {
		rep(i,n) {
			mint now = c(i,k-1);
			if (ri == 1) now = -now;
			ans += now*a[i];
		}
		reverse(a.begin(), a.end());
	}
	cout << ans.x << endl;
	return 0;
}


Measured memory_bytes: 2176
//Author- VMAX


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*


int main()
{
    fast
    
  
    ll x,a;
    cin>>x>>a;
    
    if(x<a)
    {
        o("0")
    }
    
    else
    {
        o("10")
    }
    
     
    
    re
}

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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(void){
    // Your code here!
    long long n;
    bool prime[100005] = {};
    long long cumsum[100005] = {};
    
    for(int i = 1; i <= 100000; i++)
        prime[i] = IsPrime(i);
    
    for(int i = 1; i <= 100000; i++){
        cumsum[i] = cumsum[i-1];
        if(prime[i] && prime[(i+1)/2])
            cumsum[i]++;
    }
    
    cin >> n;
    for(int i = 0; i < n; i++){
        long long l, r;
        cin >> l >> r;
        cout << cumsum[r] - cumsum[l-1] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1536
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint a, b; cin >> a >> b;
    cout << (a + b) / 2 + ((a + b) % 2 == 1 ? 1 : 0) << "\n";
}

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

using namespace std;

typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0;; i++) {
        int start = 1 + i;
        int end = m + 1 - i;
        if (start >= end)
            break;
        cout << start << ' ' << end << endl;
    }
    for (int i = 0;; i++) {
        int start = m + 2 + i;
        int end = 2 * m + 1 - i;
        if (start >= end)
            break;
        cout << start << ' ' << end << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect_left

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A, B, Q = MAP()
s = [-INF]+[INT() for _ in range(A)]+[INF]
t = [-INF]+[INT() for _ in range(B)]+[INF]
x = [INT() for _ in range(Q)]

for q in x:
	b, d = bisect_left(s, q), bisect_left(t, q)
	res = INF
	for S in [s[b-1], s[b]]:
		for T in [t[d-1], t[d]]:
			d1, d2 = abs(S-q) + abs(T-S), abs(T-q) + abs(S-T)
			res = min(res, d1, d2)
	print(res)


Measured memory_bytes: 18368
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;

const ll MOD = 998244353;
const ll INF = 1e+9;
const ld PI = acos((long double)(-1));

#define no "no"
#define No "No"
#define NO "NO"
#define yes "yes"
#define Yes "Yes"
#define YES "YES"
#define next '\n'
#define sp " "
#define print(x) cout << (x) << endl;
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define view(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e)
#define EPS 0.00000001

int main() {
    FAST;

    int n, k;
    cin >> n >> k;
    vector<int> p;

    rep(i, n){
        int a; cin >> a;
        p.pb(a);
    }
    sort(ALL(p));

    int ans = 0;
    rep(i, k){
        ans += p[i];
    }

    print(ans);
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n=in(); 
  vi a(n);
  rep(i,n) cin >> a[i];
  vector<pii> b(n);
  rep(i,n) b[i] = mp(a[i],i);
  sort(all(b));
  int imax = b.back().second;
  int amax = b.back().first;
  rep(i,n){
    if(i==imax){
      cout << b[n-2].first << endl;
    } else 
      cout << amax << endl;
  }
  return 0;
}


Measured memory_bytes: 3968
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;



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

	cin >> N >> M;
	vector<int>v(M);
	int edge = 0;
	bool odd = false;
	for (auto &i : v) {
		cin >> i;
		edge += i / 2;
		odd |= i & 1;
	}
	if (edge + N / 2 < N - 1) {
		cout << "Impossible\n";
		return 0;
	}
	if (!odd) {
		for (auto i : v)cout << i << " ";
		cout << endl;
		cout << v.size() + 1 << endl;
		cout << 1 << " ";
		for (int i = 0; i < M - 1; i++) {
			cout << v[i] << " ";
		}
		cout << v.back() - 1 << endl;
		return 0;
	}
	if (v.size() == 1) {
		if (v[0] == 1) {
			cout << 1 << endl;
			cout << 1 << endl;
			cout << 1 << endl;
			return 0;
		}
		cout << v[0] << endl;
		cout << 2 << endl;
		cout << v[0] - 1 << " " << 1 << endl;
		return 0;
		return 0;
	}
	if (accumulate(v.begin(), v.end(), 0) & 1) {
		for (int i = 0; i < M; i++) {
			if (v[i] & 1)swap(v[i], v[0]);
		}
		for (auto i : v)cout << i << " ";
		cout << endl;
		cout << v.size() << endl;
		cout << v[0] + 1 << " ";
		for (int i = 1; i < M - 1; i++)cout << v[i] << " ";
		cout << v.back() - 1 << endl;
		return 0;
	}
	for (int i = 0; i < M; i++) {
		if (v[i] & 1) {
			swap(v[i], v[0]);
			for (int j = i + 1; j < M; j++) {
				if (v[j] & 1) {
					swap(v[j], v.back());
				}
			}
			break;
		}
	}
	for (auto i : v)cout << i << " ";
	cout << endl;
	cout << v.size() - 1 + (v.back() != 1) << endl;
	cout << v[0] + 1 << " ";
	for (int i = 1; i < M - 1; i++) {
		cout << v[i] << " ";
	}
	if (v.back() > 1)cout << v.back() - 1;
	cout << endl;
	return 0;
};

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Maxn 300
using namespace std;
int a[Maxn];

int main()
{
	int H;
	scanf("%d", &H);
	for(int i = 1; i <= H; i++) scanf("%d", &a[i]);
	
	for(int i = 1; i <= H; i++){
		printf("node %d: key = %d, ", i, a[i]);
		if(i / 2) printf("parent key = %d, ", a[i / 2]);
		if(2 * i <= H) printf("left key = %d, ", a[i * 2]);
		if(2 * i + 1 <= H) printf("right key = %d, ", a[i * 2 + 1]);
		printf("\n");
	}
	return 0;
} 


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define setval(arr,v) memset(arr,v,sizeof(arr));
#define lli long long int
#define ll long long
#define mod 1000000009
#define v vector
#define pb push_back
#define pf pop_front;
#define fi first
#define se second
using namespace std;



void solve()
{
	int n;
	cin>>n;
	lli a[n];
	lli sum = 0;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		sum += a[i];
	}
	lli cnt = 0;
	stack<int> st;
	cnt += a[0];
	st.push(a[0]);
	for (int i = 1; i < n; ++i)
	{
		if(a[i] < st.top())
			cnt += st.top();
		else
		{
			st.top() = a[i];
			cnt += st.top();

		}
	}
	lli diff = -sum+cnt;
	cout<<diff;



    
}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();

    }
    return 0;

}



Measured memory_bytes: 5180
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9

bool primes[10010];
void make_prime(){
	primes[0]=primes[1]=true;
	for(int i=2; i*i<=10010; i++)if( !primes[i] )
		for(int j=i*2; j<10010; j+=i)primes[j]=true;
}
int main(){
	int n;
	make_prime();
	while(~scanf("%d",&n)){
		int ans = 0;
		for(int i=1; i<=n; i++)if( !primes[i] && !primes[n-i+1] ){
			ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
c = [0, 0, 0, 0]
for i in range(N):
  add_s = input()
  if add_s == "AC": c[0] += 1
  elif add_s == "WA": c[1] += 1
  elif add_s == "TLE": c[2] += 1
  else: c[3] += 1

print("AC x " + str(c[0]))
print("WA x " + str(c[1]))
print("TLE x " + str(c[2]))
print("RE x " + str(c[3]))


Measured memory_bytes: 69828
n = int(input())
l = input().split()
int_l = []

for i in range(2*n):
	int_l.append(int(l[i]))

int_l.sort(reverse=True)

sum = 0

for i in range(n):
	sum += min(int_l[2*i],int_l[2*i+1])

print(sum)

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

int main(){
    int N;
    cin >> N;
    long long A[100001];
    long long P=1;

    for(int i=0; i<N; i++){
        cin >> A[i];
        if(A[i]==0){
            P=0;
            break;
        }
    }
    
    long double C=1000000000000000000;

    if(P==1){
            for(int i=0; i<N; i++){
            P=P*A[i];
            C=C/A[i];
            if(C<1){
                P=-1;
                break;
            }
       }
    }
    

    cout << P << endl;

    return 0;
}

Measured memory_bytes: 4364
import java.util.*;
import java.io.*;

public class Main {

	public static void main (String[] args) {
	   InputReader in = new InputReader(System.in);
	   int n = in.readInt(); 
	   HashMap<Integer,Integer> map = new HashMap<>();
	   for(int i = 0; i<n; i++) {
		   int key = in.readInt();
		   if(map.containsKey(key)) 
			   map.put(key, map.get(key)+1); 
		   else map.put(key, 1);
	   }
	   long sum = 0; 
	   for(Map.Entry<Integer, Integer> i : map.entrySet()) {
		   if(i.getKey() < i.getValue()) {
			 sum +=  i.getValue()-i.getKey();
		   }
		   else if(i.getKey() > i.getValue()){
			   sum += i.getValue();
		   }
	   }
	   System.out.println(sum); 
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 27988
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    ll k,x,y;
    in>>k>>x>>y;
    if((1^k&1)&&((x+y)&1)) return cout<<-1<<endl,0;
    short sx=1,sy=1;
    bool f{};
    if(x<0) sx=-1,x=-x;
    if(y<0) sy=-1,y=-y;
    if(x<y) f=true,swap(x,y);
    ll c=k-(x+y)%k;
    if(c==k) c=0;
    vector<pair<ll,ll>> ans;
    if(x+y==k){
        ans.emplace_back(x,y);
    }
    else if(x+y<k&&((x+y)&1)){
        ans.emplace_back(x,x-k);
        ans.emplace_back((k+x-y)/2,k-(k+x-y)/2);
        ans.emplace_back(-(k+x-y)/2,(k+x-y)/2-x+y);
    }
    else{
        ll n;
        if(x+y<k) n=2;
        else if(c&1) n=(x+y-1)/k+2;
        else n=(x+y-1)/k+1;
        ans.resize(n);
        ll i=0,a=0,b=0;
        while(a-k>=-(k*n-x-y)/2){
            ans[i++]={0,-k};
            a-=k;
        }
        ans[i]={0,-a-(k*n-x-y)/2};
        a=-(k*n-x-y)/2;
        ans[i].first=k+ans[i].second;
        b+=k+ans[i].second;
        ++i;
        while(b+k<=x){
            ans[i++]={k,0};
            b+=k;
        }
        ans[i]={x-b,0};
        b=x;
        ans[i].second=k-ans[i].first;
        a+=k-ans[i].first;
        ++i;
        while(a<y){
            ans[i++]={0,k};
            a+=k;
        }
    }
    cout<<ans.size()<<endl;
    fr(i,ans.size()-1){
        ans[i+1].first+=ans[i].first;
        ans[i+1].second+=ans[i].second;
    }
    for(auto&p:ans){
        tie(x,y)=p;
        if(f) swap(x,y);
        x*=sx;
        y*=sy;
        cout<<x<<" "<<y<<endl;
    }
}

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class FPure {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> E(n + 1);
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        E[a].push_back(b);
    }

    auto bfs = [&](int v){
        queue<int> Q;
        Q.push(v);
        vector<bool> visited(n + 1);
        vector<int> pre(n + 1, -1);

        while (!Q.empty()){
            int u = Q.front(); Q.pop();
            for (const auto &e: E[u]){
                if (visited[e])
                    continue;
                visited[e] = true;
                pre[e] = u;
                Q.push(e);
            }

        }

        vector<int> res;
        if (pre[v] == -1)
            return res;
        int cur = v;
        res.push_back(v);
        while (pre[cur] != v){
            cur = pre[cur];
            res.push_back(cur);
        }

        return res;
    };

    vector<int> ans(n + 1);
    for (int i = 1; i <= n; i++){
        vector<int> tmp = bfs(i);
        if (!tmp.empty() and tmp.size() < ans.size())
            ans = move(tmp);
    }

    if (ans.size() > n){
        cout << -1 << endl;
        return;
    }

    cout << ans.size() << endl;
    copy(ans.begin(), ans.end(), ostream_iterator<int>(cout, "\n"));
}
};

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


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int N = 500100;
int bit[26][500100];

void add(int i, int a, int w) { 
    for (int x = a; x <= N; x += (x & -x)) bit[i][x] += w;
}

int sum(int i, int a) {
    int res = 0;
    for (int x = a; x > 0; x -= (x & -x)) res += bit[i][x];
    return res;
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    rep(i, s.size()) {
        add(s[i]-'a', i+1, 1);
    }

    int q; cin >> q;
    rep(_, q) {
        int type; cin >> type;
        if (type == 1) {
            int i; char c; cin >> i >> c;
            i--;
            if (s[i] == c) continue;
            else {
                add(s[i]-'a', i+1, -1);
                s.replace(i, 1, string(1, c));
                add(c-'a', i+1, 1);
            }
        } else {
            int l, r; cin >> l >> r;
            l--; r--;
            int res = 0;
            rep(i, 26) {
                if (sum(i, r+1) - sum(i, l) > 0) {
                    res++;
                }
            }
            cout << res << endl;
        }
    }

    return 0;
}


    


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

public static partial class Program
{
    public static void Main()
    {
        var nm = CRL().ArrayInts();
        var n = nm[0];
        var m = nm[1];

        var memo = new int[n + 1];
        for (int i = 0; i < m; i++)
        {
            var p = CRL().ArrayInts();
            memo[p[0] - 1]++;
            memo[p[1]]--;
        }

        for (int i = 0; i < memo.Length - 1; i++)
        {
            memo[i + 1] += memo[i];
        }
        
        CWL(memo.Count(x => x == m));
    }
}

public static partial class Program
{
    //テンプレここから
    public static int Sigma(int n, int next = 1, int val = 0) => next > n ? val : Sigma(n, next + 1, val + next);
    public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
    public static int GCD(int a, int b) => b == 0 ? a : GCD(b, a % b);
    public static long LCM(long a, long b) => a * b / GCD(a, b);
    public static int LCM(int a, int b) => a * b / GCD(a, b);
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static int ToInt(this double d) => (int) d;
    public static long ToLong(this double d) => (long) d;
    public static int ToInt(this string str) => int.Parse(str);
    public static long ToLong(this string str) => long.Parse(str);
    public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static int[] ArrayInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static readonly int[] Dx = new[] {0, -1, 0, 1};
    public static readonly int[] Dy = new[] {-1, 0, 1, 0};
    public const int Mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array) => array.OrderBy(x => x).ToArray();
    public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray();
    public static long[] DSort(this long[] array) => array.OrderByDescending(x => x).ToArray();
    public static int[] DSort(this int[] array) => array.OrderByDescending(x => x).ToArray();
    public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
    public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);

    public static string JoinToStr(this IEnumerable<int> array, string sep = "")
        => array.Select(x => x.ToString()).Join(sep);

    //テンプレここまで
}

Measured memory_bytes: 17632
N, K = map(int, input().split())
A = [int(a) - 1 for a in input().split()]

if K <= N:
    p = 0
    for i in range(K):
        p = A[p]
    print(p + 1)
    exit()

p = 0
t = [-1] * N
t[0] = 0
for i in range(1, N):
    p = A[p]
    if t[p] != -1:
        break
    t[p] = i

d = i - t[p]
K -= i
K %= d

for i in range(K):
    p = A[p]
print(p + 1)

Measured memory_bytes: 32316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> t(n);
	rep(i, n) cin >> t[i];
	ll ans = t[0];
	rrep(i, n) ans = lcm(ans, t[i]);
	printf("%lld\n", ans);
	return 0;
}


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

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int32 tx[90100][20] = {}, ty[90100][20] = {};
int main(void){
  int32 h, w, d;
  int32 A[310][310];
  map<int32, int32> x, y;
  cin >> h >> w >> d;
  REP(i, h){
    REP(j, w){
      cin >> A[i][j];
      A[i][j]--;
      x[A[i][j]] = j;
      y[A[i][j]] = i;
    }
  }
  REP(i, h*w){
    if(i < h*w-d){
      if(i+d >= 90100) continue;
      tx[i][0] = abs(x[i+d]-x[i]);
      ty[i][0] = abs(y[i+d]-y[i]);
    }
  }
  REP(j, 19){
    REP(i, h*w){
      if(i+d*(1<<j) >= 90100) continue;
      tx[i][j+1] = tx[i][j]+tx[i+d*(1<<j)][j];
      ty[i][j+1] = ty[i][j]+ty[i+d*(1<<j)][j];
    }
  }
  int32 Q;
  cin >> Q;
  REP(q, Q){
    int32 l, r;
    cin >> l >> r;
    int32 rx = 0, ry = 0;
    int32 now = 19;
    l--; r--;
    while(r-l){
      if(d*(1<<now) <= r-l){
        rx += tx[l][now];
        ry += ty[l][now];
        l += d*(1<<now);
      }
      now--;
    }
    cout << rx+ry << endl;
  }
}

Measured memory_bytes: 41216
#include <bits/stdc++.h>
using namespace std;
#define MAX 105
#define INFTY -1

int n, G[MAX][MAX], d[MAX];

void bfs(int s) {
	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	while (!Q.empty()) {
		int u = Q.front();
		Q.pop();
		for (int v = 1; v <= n; v++) {
			if (G[u][v] == 0) continue;
			if (d[v] != INFTY) continue;
			d[v] = d[u] + 1;
			Q.push(v);
		}
	}
}

int main(void) {
	int i, j, u, k, v;
	for (i = 0; i < MAX; i++) {
		d[i] = INFTY;
	}
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		for (j = 0; j < k; j++) {
			cin >> v;
			G[u][v] = 1;
		}
	}

	bfs(1);
	
	for (i = 1; i <= n; i++) {
		cout << i << " " << d[i] << endl;
	}
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 1010;
char grid[N][N];
int r[N] , r2[N];
int n;


string tmp[] = {"aabbi","ccf.i","ddfee","..ghj","..ghj"};

string tmp2[] = {"aabbcc.","ddee..l","ffgg..l","....hjm","....hjm","....ikn","....ikn"};

int main(){
	cin >> n;
	for(int i = 0 ;i < n;i++) for(int j = 0 ;j < n;j++) grid[i][j] ='.';
	for(int i = 0 ;i < n;i++) grid[i][n] = '\0';
	if(n == 2){
		puts("-1");
		return 0;
	}
	if(n == 7){
		for(int i = 0 ;i < n;i++)
			puts(tmp2[i].c_str());
		return 0;
	}
	if(n == 5){
		for(int i = 0 ;i < n;i++)
			puts(tmp[i].c_str());
		return 0;
	}
	if(n % 3 == 0){
		for(int i = 0 , j = 0;i < n;i+=3,j+=3){
			grid[i][j] = grid[i][j + 1] = 'a';
			grid[i + 1][j + 2] = 'b';
			grid[i + 2][j + 2] = 'b';
		}
		for(int i = 0; i < n;i++)
			puts(grid[i]);
		return 0;
	}
	if(n % 2 == 0 && n != 2){
		for(int i = 0 , j = 0;i < n;i+=2, j += 2){
			grid[i][j] = grid[i][j + 1] = 'a';
			grid[i + 1][j] = grid[i + 1][j + 1] = 'b';
		}
		for(int i = 0 , j = 2;j < n;i += 2, j += 2){
			grid[i][j] = grid[i + 1][j] = 'c';
			grid[i][j + 1] = grid[i + 1][j + 1] = 'd'; 
		}
		grid[n - 2][0] = grid[n - 1][0] = 'c';
		grid[n - 2][1] = grid[n - 1][1] = 'd';
		for(int i = 0 ;i < n;i++)
			puts(grid[i]);
		return 0;
	}
	else if(n % 2 == 1){
		for(int i = 0 ;i < 5;i++) for(int j = 0 ;j < 5;j++) grid[i][j] = tmp[i][j];
		for(int i = 5 , j = 5; i < n;i+=2,j+=2){
			grid[i][j] = grid[i][j + 1] = 'a';
			grid[i + 1][j] = grid[i + 1][j + 1] = 'b';
		}
		for(int i = 5 , j = 7;j < n;i += 2, j += 2){
			grid[i][j] = grid[i + 1][j] = 'c';
			grid[i][j + 1] = grid[i + 1][j + 1] = 'd'; 
		}
		grid[n - 2][5] = grid[n - 1][5] = 'c';
		grid[n - 2][6] = grid[n - 1][6] = 'd';
		for(int i = 0 ;i < n;i++)
			puts(grid[i]);
		return 0;
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 2176
N, K = map(int, input().split())

A = [False]*(N+1)
for i in range(K):
    dk = int(input())
    ad = list(map(int,input().split()))
    for a in ad:
        A[a] = True

count = 0
for a in A[1:]:
    if not a:
       count += 1 

print(count)

Measured memory_bytes: 9124
#include<iostream>
#include<string.h>
using namespace std;
int main() {
	int a, b, c[10] = { 0 }, i, j;
	while (1) {
		cin >> a;
		if (a == 0) 
			return 0;
		for (i = 0; i < a; i++) {
			cin >> b;
			c[b]++;
		}
		for (i = 0; i < 10; i++) {
			for (j = 0; j < c[i]; j++) 
				cout << "*";
			if (j == 0) {
				cout << "-";
			}
			cout << endl;
		}
		memset(c, 0, sizeof(c));
	}
}

Measured memory_bytes: 3088