akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class Abc_085_C
    {
        // https://atcoder.jp/contests/abc085/tasks/abc085_c
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputIntArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            string result = "-1 -1 -1";

            int N = inputIntArray[0];

            int Y = inputIntArray[1];

            for (int x = 0; x <= N; x++)
            {
                for (int y = 0; x + y <= N; y++)
                {
                    int z = N - (x + y);
                    int total = 10000 * x + 5000 * y + 1000 * z;
                    if (total == Y)
                    {
                        result = x + " " + y + " " + z;
                        Console.WriteLine(result);
                        Console.Out.Flush();
                        return;
                    }
                }
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
bool CheckOdd(int n){
    int cnt =0;
    while(n>0){n/=10;cnt++;}
    return (cnt%2==1?true:false);
}
int ans=0;
int num;
int main(){
    cin>>num;
    for(int i=0;i<=num;i++){
        if(CheckOdd(i))ans++;
    }
    cout<<ans<<endl;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    int v[] = {a,b,c};
    sort(v,v+3);
    int cnt = 0;
    while(v[0]!=v[1] || v[1]!=v[2]){
        int d1 = v[2] - v[1], d2 = v[2] - v[0];
        if(d1%2!=0 || d2%2!=0){
            v[1]++;
            v[0]++;
            ++cnt;
        }else{
            cnt += d1 / 2 + d2 / 2;
            v[0] += d2;
            v[1] += d1;
        }
        sort(v,v+3);
    }
    cout<<cnt<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	ll a, v, b, w, t;
	cin >> a >> v >>b>>w>>t;
	bool can = true;
	if (v <= w) can = false;
	ll dis = abs(a-b);
	ll run = (v-w) * t;
	if (run < dis) can = false;
	
	if (can) cout << "YES" << endl;
	else cout << "NO" << endl; 
	return 0;
}

Measured memory_bytes: 3672
import queue
import sys
input = sys.stdin.readline


def toab(s, ab, node):
    toa, tob = False, False
    for k in ab:
        if k not in node:
            continue
        if s[k - 1] == 'A':
            toa = True
            if tob:
                return True
        elif s[k - 1] == 'B':
            tob = True
            if toa:
                return True
    return False


ab = {}
node = {}
N, M = map(int, input().split())
s = input()
for i in range(M):
    a, b = map(int, input().split())
    if a not in ab:
        ab[a] = {}
    ab[a][b] = True
    if b not in ab:
        ab[b] = {}
    ab[b][a] = True
    node[a] = True
    node[b] = True

for i in range(N + 1):
    if i not in node:
        continue
    q = queue.Queue()
    q.put(i)
    while not q.empty():
        j = q.get()
        if j in node and not toab(s, ab[j], node):
            node.pop(j)
            for k in ab[j]:
                if k in node:
                    q.put(k)

if not node:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 124504
'use strict';
(function(stdin) {
	var lines  = stdin.toString().split('\n');
	var result = (function(params,data) {

		var table = data.slice(0,params[0]).map(function(v) {
			var tmp = v.split(' ').slice(0,params[1]).map(Number);
			tmp.push(tmp.reduce(function(a,b){ return a + b; }));
			return tmp;
		});

		var line = table[0].map(function(col, i) { 
			return table.map(function(row) { 
				return row[i] 
			})
			.reduce(function(a,b){return a + b});
		});

		table.push(line);

		return (table.join('\n').replace(/,/g,' '));

	}(
		lines.shift().split(' ').map(Number)
		,lines
		));

	console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

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

   if (isupper(s))
   {
       cout << "A" << endl;
   }
   else
   {
       cout << "a" << endl;
   }

   return 0;
}


Measured memory_bytes: 3620
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, k = map(int, input().split())
if n%2==1:
    if (n-1)//2 >= k-1: print('YES')
    else: print('NO')
else:
    if n//2 >= k: print('YES')
    else: print('NO')
      

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>

#define ll long long
#define pb push_back
#define for(i,a,b) for(ll i=a;i<b;i++)

using namespace std;


int main(void)
{
    ll x;
    scanf("%lld",&x);
    ll h=0;
    h+=1000*(x/500);
    x=x%500;
    h+=5*(x/5);
    printf("%lld",h);

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int a = sc.nextInt();
    		final String s = sc.next();
    		
    		if (a>=3200) {
    			System.out.println(s);
    		} else {
    			System.out.println("red");
    		}

    	} finally {
    		sc.close();
    	}
    }
}



Measured memory_bytes: 21332
n,m = map(int, input().split())
x = sorted(list(map(int, input().split())))

if n >= m: print(0)
else:
  nums = [0]*(m-1)
  for i in range(m-1): nums[i] = x[i+1] - x[i]
  nums.sort()
  print(sum(nums[:m-n]))

Measured memory_bytes: 20408
while true
    a,op,b = gets.split(" ")
    break if op == "?"
    if op == "+"
        result = a.to_i + b.to_i
    elsif op == "-"
        result = a.to_i - b.to_i
    elsif op == "*"
        result = a.to_i * b.to_i
    elsif op == "/"
        result = a.to_i / b.to_i
    end
    puts result
end


Measured memory_bytes: 6852
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int n; cin >> n;
    auto g = make_v(n, n, -1);

    REP(i, n) {
        int a; cin >> a;

        REP(j, a) {
            int x, y; cin >> x >> y;
            --x;
            g[i][x] = y;
        }
    }

    int ans = 0;
    REP(b, bit(n)) {
        bool f = true;

        REP(i, n)REP(j, n){
            if (((b >> i) & 1) && g[i][j] != -1) {
                if (((b >> j) & 1) != g[i][j]) f = false; 
            } 
        }

        if (f) {
            ans = max(ans, __builtin_popcount(b));
        }
    }

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


Measured memory_bytes: 256
def is_palindromic(n: int) -> bool:
    s = str(n)
    l = len(s)
    for i in range(l//2):
        if s[i] != s[-(i+1)]:
            return False
    return True


def palindromic_numbers(A: int, B: int) -> int:
    return sum(is_palindromic(n) for n in range(A, B+1, 1))


if __name__ == "__main__":
    A, B = map(int, input().split())
    ans = palindromic_numbers(A, B)
    print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int h, n;
    cin >> h >> n;
    int sum = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        sum += a;
    }
    if(sum >= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int IN(void)
{
  int x=0;short f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
signed main(void)
{
  int N=IN(),a=0,count=0,max=0,check[1000001]={0};
  for(int i=0;i<N;i++){a=IN();check[a]++;max=a>max?a:max;}
  for(int i=1;i<=max;i++)
  {
    if(check[i]==1){count++;}if(check[i]){for(int j=2;i*j<=max;j++)check[i*j]=0;}
  }
  return printf("%d\n",count),0;
}

Measured memory_bytes: 5508
import math

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

MOD = 10**9 + 7

if abs(N-M) > 1:
    ans = 0
elif abs(N-M) == 1:
    ans = math.factorial(N) * math.factorial(M)
else:
    ans = math.factorial(N) * math.factorial(M) * 2

print(ans % MOD)

Measured memory_bytes: 5184
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(n):
  if p[i] == i+1:
    continue
  p[p[i]-1] = p[i]
  p[i] = i+1
  cnt += 1
print('YES' if cnt <= 1 else 'NO')

Measured memory_bytes: 9060
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import Data.List (group)

main :: IO ()
main = do
  let
    f :: Int -> Int -> Int
    f k m = (2 * k) `min` (m - 1)
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  ds <- map ('R' ==) . T.unpack <$> T.getLine :: IO [Bool]
  let
    (m, s) = ((,) <$> length <*> sum . map (pred . length)) . group $ ds :: (Int, Int)
  print $ s + f k m

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 10848
import numpy as np
import math
import collections

T = int(input())
for i in range(T):
    x = 0
    L0 = [0]
    ans = 0
    N = int(input())
    A = list(map(int, input().split()))
    S = input()
    for i, s in enumerate(reversed(S)):
        tmp = A[N - 1 - i]
        for l0 in L0:
            if tmp ^ l0 < tmp:
                tmp = tmp ^ l0
        if tmp > 0:
            if s == "1":
                ans = 1
                break
            L0.append(tmp)
    print(ans)


Measured memory_bytes: 27036
import java.util.*;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int cnt = 0;
		for (int i = 1 ; i < b - a ; i++) {
			cnt = cnt + i;
		}
		System.out.println(cnt - a);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using vs = vector<string>;
#define rep(i,n) range(i,0,n)
#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 (1000000007)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.141592653589793

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;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	while (cin >> n >> m, n) {
		vi v(n);
		ll max = -1;
		rep(i, n) {
			cin >> v[i];
		}
		rep(i, n) {
			rep(j, n) {
				if (i == j) continue;
				if (v[i] + v[j] > max&&v[i] + v[j] <= m) {
					max = v[i] + v[j];
				}
			}
		}
		if (max == -1) {
			cout << "NONE" << endl;
		}
		else {
			cout << max << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    map<char,char> smap,tmap;
    bool ok = true;
    rep(i,s.length()){
        char ws = s[i],wt=t[i];
        if (smap.count(ws)){
            if (smap[ws] != wt){
                ok = false;
                break;
            }
        }
        if (tmap.count(wt)){
            if (tmap[wt] != ws){
                ok = false;
                break;
            }
        }
        smap[ws] = wt;
        tmap[wt] = ws;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 776
package main

import (
	"fmt"
	"math"
)

func main() {
	var A, B, C, ans int
	fmt.Scan(&A, &B, &C)
	m := max(A, B, C)

	A = m - A
	B = m - B
	C = m - C

	ans = (A + B + C) / 2
	if (A+B+C)%2 != 0 {
		ans += 2
	}

	fmt.Println(ans)
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return abs(a[i]) > abs(a[j]) }


Measured memory_bytes: 512
gets.to_i.times do
  p0, p1, p2, p3 = gets.split.map(&:to_i).each_slice(2).map {|a, b| a + b * 1i }
  u, v, w = p1 - p0, p3 - p2, p2 - p0, p3 - p0
  t = (Complex(*v.rect.reverse!) * w).real.to_f / (u.conj * v).imag
  puts '%.8f %.8f' % (p0 + t * u).rect
end

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

using namespace std;

#define MAX_N 100
#define MAX_H 25
#define INF (1<<29)

struct Edge {
    int to, c, h, r;
    Edge (int to, int c, int h, int r) :
        to(to), c(c), h(h), r(r) {}
};

struct State {
    int c, v, h;
    State (int c, int v, int h) :
        c(c), v(v), h(h) {}

    bool operator < (const State &s) const {
        return c > s.c;
    }
};

int main()
{
    int N, M, H, K, S, T, P;
    while (cin >> N >> M >> H >> K, N) {
        vector<Edge> G[MAX_N];
        for (int i = 0; i < M; i++) {
            int a, b, c, h, r;
            cin >> a >> b >> c >> h >> r;
            a--; b--; r--;
            G[a].push_back(Edge(b, c, h, r));
            G[b].push_back(Edge(a, c, h, r));
        }
        cin >> S >> T >> P; S--; T--;
        vector<int> d(P), bit(P);
        for (int i = 0; i < P; i++) {
            int l, k;
            cin >> l >> d[i];
            for (int j = 0; j < l; j++) {
                cin >> k; k--;
                bit[i] |= (1<<k);
            }            
        }

        int dp[1<<8];
        fill(dp, dp + (1<<8), INF);
        dp[0] = 0;
        for (int i = 0; i < (1<<K); i++) {
            if (dp[i] == INF) continue;              
            for (int j = 0; j < P; j++) {
                int ni = (i | bit[j]);
                dp[ni] = min(dp[ni], dp[i] + d[j]);
            }
        }
       
        int res = INF;
        for (int i = 0; i < (1<<K); i++) {
            int d[MAX_N][MAX_H];
            for (int j = 0; j < N; j++) {
                for (int k = 0; k <= H; k++) {
                    d[j][k] = INF;
                }
            }

            d[S][H] = 0;
            
            priority_queue<State> Q;
            Q.push(State(0, S, H));
            
            while (!Q.empty()) {
                State s = Q.top(); Q.pop();
                int v = s.v, h = s.h;
                int cost = s.c;
                
                if (v == T) {
                    res = min(res, cost + dp[i]);
                    break;
                }

                for (int j = 0; j < (int)G[v].size(); j++) {
                    Edge &e = G[v][j];
                    int nh = h - e.h;
                    if (nh < 0) continue;
                    
                    int ncost = cost;
                    if (!(i >> e.r & 1)) {
                        ncost += e.c;
                    } 
                    if (ncost < d[e.to][nh]) {
                        d[e.to][nh] = ncost;
                        Q.push(State(ncost, e.to, nh));
                    }
                }
            }            
        }
        cout << (res == INF ? -1 : res) << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int N;
vector<int> g[100010];
int a[100010];
int res=0;

void dfs(int v,int pre){
  int cnt[20];
  memset(cnt,0,sizeof(cnt));
  for(int nv : g[v]){
    if(nv==pre)continue;
    dfs(nv,v);
    rep(i,20){
      if((a[nv]>>i)&1)cnt[i]++;
    }
  }
  int lst=-1;
  for(int i=19;i>=0;i--){
    if(cnt[i]>=2){
      lst=i; break;
    }
  }
  repl(i,lst+1,20){
    if(cnt[i]==0){
      int mask=(1<<i);
      maxch(res,i);
      repl(j,i+1,20){
        if(cnt[j]>0)mask|=1<<j;
      }
      a[v]=mask; return ;
    }
  }
}

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

  cin>>N;
  rep(i,N-1){
    int b,c;
    cin>>b>>c;
    b--;c--;
    g[b].push_back(c); g[c].push_back(b); 
  }

  dfs(0,-1);
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 17536
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
using namespace std;

long long  H[100002] = {0};
long long  G[100002] = {0};

int main(int argc, char* argv[]){
	int N, M;

	cin >> N >> M;
	for(int i=1; i<=N; i++){
		cin >> H[i];
		G[i] = 1;
	}

	for(int i=1; i<=M; i++){
		int a, b;
		cin >> a >> b ;
		if( H[a]>H[b] ){
			G[b] = 0;
		}
		else if( H[a]<H[b] ){
			G[a] = 0;
		}
		else{
			G[a] = 0;
			G[b] = 0;
		}
	}
	int ans = 0;
	for(int i=1; i<=N; i++){
		ans += G[i];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5300
N = int(input())

A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

acc1 = acc2 = 0
for i in range(N):
    acc1 += A1[i]
    acc2 = max(acc1, acc2) + A2[i]
print(acc2)


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr const char* YES = "Yes";
static constexpr const char* NO = "No";

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  string s, t;
  cin >> s >> t;

  map<ll, ll> a, b;
  vector<ll> sv, tv;
  rep(i, 0, sz(s)) {
    a[s[i]]++;
    b[t[i]]++;
  }

  for (auto p : a) sv.pb(p.second);
  for (auto p : b) tv.pb(p.second);
  sort(all(sv));
  sort(all(tv));

  if (sz(sv) != sz(tv)) {
    put(NO);
    return 0;
  }

  rep(i, 0, sz(sv)) {
    if (sv[i] != tv[i]) {
      put(NO);
      return 0;
    }
  }

  put(YES);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

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


Measured memory_bytes: 776
#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() {
  int k, t;
  cin >> k >> t;
  vector<int> a(t);
  rep(i, t) cin >> a[i];

  sort(a.rbegin(), a.rend());
  int ans = max(0, a[0] - (k - a[0]) - 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque

def push(t, x):
    global Slist
    Slist[t].append(x)

def top(t):
    global Slist
    if Slist[t] != deque():
        print(Slist[t][-1])

def pop(t):
    global Slist
    if Slist[t] != deque():
        Slist[t].pop()
    


n, q = map(int, input().split())
Slist =[]
for i in range(n):
    S = deque()
    Slist.append(S)

for j in range(q):
    queryi = list(map(int, input().split()))
    
    if queryi[0] == 0:
        push(queryi[1], queryi[2])

    elif queryi[0] == 1:
        top(queryi[1])

    else: 
        pop(queryi[1])


Measured memory_bytes: 14532
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
}

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

#define fi first
#define se second
#define all(X) X.begin(),X.end()
#define pb push_back

using namespace std;

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

const int maxn = 500 +5;
const int lg = 20;
const int mod = 1e9 + 7;

template<class T>
void smin(T &_x, const T &_y){
	_x = min(_x, _y);
}
template<class T>
void smax(T &_x, const T &_y){
	_x = max(_x, _y);
}
bool a[maxn][maxn], b[maxn][maxn];// c[maxn][maxn];

int main(){
	ios_base::sync_with_stdio(false);cin.tie();
	int n, m;
	cin>>n>>m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++){
			char c;
			cin>>c;
			if(c == '#'){
				a[i][j] = b[i][j] = 1;
			}
		}
	for(int i = 0; i < m; i++) {
		a[0][i] = b[n - 1][i] = 1;
		if(i % 2) for(int j = 0; j < n - 1; j++) a[j][i] = 1;
		else for(int j = 1; j < n; j++) b[j][i] = 1;
	}
	for(int i = 0; i < n; i++, cout<<endl)
		for(int j = 0; j < m; j++){
			if(a[i][j]) cout<<'#';
			else cout<<'.';
		}
	cout<<endl;
	for(int i = 0; i < n; i++, cout<<endl)
		for(int j = 0; j < m; j++){
			if(b[i][j]) cout<<'#';
			else cout<<'.';
		}

}

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

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

signed main()
{
    int n,m; cin >> n >> m;
    vector<int> a(m,0);

    rep(i,n){
        int k; cin >> k;
        rep(j,k){
            int tmp; cin >> tmp;
            ++a[tmp-1];
        }
    }

    int ans=0;
    rep(i,m)
        if(a[i]==n) ++ans;
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;public class Main {static{Scanner s = new Scanner(System.in);while(s.hasNext()){double x = s.nextDouble();System.out.println(x<=48?"light fly":x<=51?"fly":x<=54?"bantam":x<=57?"feather":x<=60?"light":x<=64?"light welter":x<=69?"welter":x<=75?"light middle":x<=81?"middle":x<=91?"light heavy":"heavy");}System.exit(0);}}

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

    int main()
    {


        string s;
        long long int i,j,k,l,n;
        cin>>n;
        cin>>s;
        string arr[26];
      for(i=0;i<26;i++)
      {
          arr[i]=i+'A';
      }
      for(i=0;i<s.size();i++)
      {
            if(n+s[i]-'A'<26)
          s[i]=abs(s[i]+n);
          else
          s[i]=abs(26-s[i]-n);
      }

cout<<s;



        /*1
       string arr[7];
       arr[0]="SAT";
       arr[1]="SUN";
       arr[2]="MON";
       arr[3]="TUE";
       arr[4]="WED";
       arr[5]="THU";
       arr[6]="FRI";
       string s;
       cin>>s;
       for(int i=0;i<7;i++)
       {
           if(s=="SUN")
           {
               cout<<7;
               return 0;
           }
           if(s==arr[i])
            cout<<abs(i-1);

       }*/
        return 0;
    }


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

int main() {
    
    while(1) {
        int a, b;
        char op;
        
        cin >> a >> op >> b;
        if (op == '?') {
            break;
        }
        else if(op == '+') {
            cout << a + b << endl;
        }
        else if(op == '-') {
            cout << a - b << endl;
        }
        else if(op == '*') {
            cout << a * b << endl;
        }
        else {
            cout << a / b << endl;
        }
    }
    
    
    return 0;
}



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

const int INF = 1000000000;

int main()
{
	while(true){
		int n, m;
		cin >> n >> m;

		if(n==0 && m==0)
			break;

		int Cost[100][100];
		int Time[100][100];
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				if(i==j){
					Cost[i][j] = Time[i][j] = 0;
				}
				else{
					Cost[i][j] = Time[i][j] = INF;
				}
			}
		}

		for(int i=0; i<n; i++){
			int a, b, c, t;
			cin >> a >> b >> c >> t;

			Cost[a-1][b-1] = Cost[b-1][a-1] = c;
			Time[a-1][b-1] = Time[b-1][a-1] = t;
		}
    for(int i =0;i<m;i++){
      for(int j =0;j<m;j++){
        for(int k = 0;k<m;k++){
          if(Cost[j][k]>Cost[j][i]+Cost[i][k]){
            Cost[j][k]=Cost[j][i]+Cost[i][k];
          }
          if(Time[j][k]>Time[j][i]+Time[i][k]){
            Time[j][k]=Time[j][i]+Time[i][k];
          }
        }
      }
    }
    int k;
    cin >>k;
    for(int i =0;i<k;i++){
      int p,q,r;
      cin >>p>>q>>r;
      if(r)cout << Time[p-1][q-1]<<endl;
      else cout << Cost[p-1][q-1]<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3144
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================



	string S, T;
	cin >> S >> T;

	ll S_begin = 0;
	ll roop = 1;

	vvll pos(30);
	for (ll i = 0; i < S.length(); i++)
	{
		pos[ll(S[i]) - ll('a')].emplace_back(i);
	}

	for (ll i = 0; i < T.length(); i++)
	{

		ll target = ll(T[i]) - ll('a');

		if (pos[target].size() == 0)
		{
			cout << -1 << endl;
			return 0;
		}

		//key以上の要素のうちの最も左側のイテレータを返す
		auto Iter = lower_bound(pos[target].begin(), pos[target].end(), S_begin);
		ll idx = Iter - pos[target].begin();

		if (idx < pos[target].size())
		{
			S_begin = pos[target][idx] + 1;
		}
		else
		{
			S_begin = pos[target][0] + 1;
			roop++;
		}
	}

	ll ans = (roop - 1) * S.length() + S_begin;

	cout << ans << endl;


}





Measured memory_bytes: 1736
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define MOD 1000000007
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;
typedef unordered_map<int, int> Hash;

// ---
int N, M;

void pr(int a, int b) {
  while (a < b && M > 0) {
    cout << a << " " << b << endl;
    a++;
    b--;
    M--;
  }
}

signed main() {
  cin >> N >> M;

  int n1 = N/2;
  int n2 = N - n1;

  if (n1 == n2) {
    pr(1, n1);
    pr(n1+1, N-1);
  } else {
      pr(1, n1);
      pr(n1+1, N);
  }

  return 0;
}


Measured memory_bytes: 3232
/*
author:lingling
date:2017.06.02
description: ??°??????????????????????¢?????????§??¬?????°
*/
#include<iostream>
using namespace std;
int mygcd(int,int);
int main() {
    int x,y;
    while(cin>>x>>y) {
        int a=max(x,y);
        int b=min(x,y);
        cout<<mygcd(a,b)<<endl;
    }
    return 0;
}
int mygcd(int x, int y) {
    if(x>=y) {
         if(y==0) return x; 
         else return mygcd(y,x%y);
    }
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main()
{
    int n;
    cin >> n;
    map<string, int> mp;
    vector<int> a(n);
    rep(i, n)
    {
        string s;
        cin >> s >> a[i];
        mp[s] = i;
    }
    string x;
    cin >> x;
    int ans = 0;
    rep(i, mp[x] + 1, n)
    {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;

int main() {
    int N, A; cin >> N >> A;
    vector<int> X(N);
    rep(i, N) cin >> X[i];
    vector<vector<i64>> dp(N + 1, vector<i64>(2510, 0));
    dp[0][0] = 1LL;
    rep(i, N) {
        auto dp_ = dp;
        int x = X[i];
        rep(j, N) REP(k, x, 2510) {
            dp_[j + 1][k] += dp[j][k - x];
        }
        dp = dp_;
    }
    i64 ans = 0LL;
    REP(i, 1, N + 1)
      ans += dp[i][i * A];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2320
n=int(input())
l=list(map(int,input().split()))
ans=[0,abs(l[1]-l[0])]
for i in range(2,n):
    ans.append(min(abs(l[i]-l[i-2])+ans[-2],abs(l[i]-l[i-1])+ans[-1]))
print(ans[-1])
    

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

int n, d, x;

int main(void){
	cin >> n >> d >> x;
	vector<int> a(n);
	int ans = 0;
	rep(i, n){
		int a;
		cin >> a;
		ans += (d-1)/a+1;
	}
	cout << ans+x << endl;
	return 0;
}


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

const int MaxN = 1e5 + 15;
const int MOD = 1e9 + 7;

void good()
{
    cout << "Yes\n";
    exit(0);
}

void bad()
{
    cout << "No\n";
    exit(0);
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdou);

    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin >> s;
    if(s[1] == s[2])
    {
        if(s[0] == s[1] || s[3] == s[2])
            good();
    }
    bad();
}


Measured memory_bytes: 764
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
public static class P
{
    public static void Main()
    {
        var nq = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nq[0];
        var q = nq[1];
        UnionFind uf = new UnionFind(n);
        for (int i = 0; i < q; i++)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            uf.TryUnite(ab[0] - 1, ab[1] - 1);
        }
        Console.WriteLine(uf.GroupCount - 1);
    }
}


class UnionFind
{
    public int Size { get; private set; }
    public int GroupCount { get; private set; }
    public IEnumerable<int> AllRepresents => Parent.Where((x, y) => x == y);
    int[] Sizes;
    int[] Parent;
    public UnionFind(int count)
    {
        Size = count;
        GroupCount = count;
        Parent = new int[count];
        Sizes = new int[count];
        for (int i = 0; i < count; i++) Sizes[Parent[i] = i] = 1;
    }
    public bool TryUnite(int x, int y)
    {
        int xp = Find(x);
        int yp = Find(y);
        if (yp == xp) return false;
        if (Sizes[xp] < Sizes[yp]) { var tmp = xp; xp = yp; yp = tmp; }
        GroupCount--;
        Parent[yp] = xp;
        Sizes[xp] += Sizes[yp];
        return true;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int GetSize(int x) => Sizes[Find(x)];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int Find(int x)
    {
        while (x != Parent[x]) x = (Parent[x] = Parent[Parent[x]]);
        return x;
    }
}


Measured memory_bytes: 42184
#include<iostream>
#include<stdio.h>
#include<stack>
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;

string str;
stack<int> stk;

void push(string s)
{
    int n = 0;
    rep(i,s.size()) n = n*10 + s[i] - '0';
    stk.push(n);
    return;
}

void push(int n)
{
    stk.push(n);
    return;
}

void add()
{
    int x = stk.top(); stk.pop();
    int y = stk.top(); stk.pop();
    stk.push(x+y);
    return;
}

void subt()
{
    int x = stk.top(); stk.pop();
    int y = stk.top(); stk.pop();
    stk.push(y-x);
    return;
}

void mult()
{
    int x = stk.top(); stk.pop();
    int y = stk.top(); stk.pop();
    stk.push(x*y);
    return;
}

int main(void)
{
    while(cin >> str){
        if(str == "+") add();
        else if(str == "-") subt();
        else if(str == "*") mult();
        else push(str);
    }

    cout << stk.top() << endl;

    return 0;
}




Measured memory_bytes: 3184
#include <stdio.h>
#include <math.h>

int main() {
	double l, r = 90, nr;
	double pos_x = 0, pos_y = 0;
	while(1) {
		scanf("%lf,%lf", &l, &nr);;
		pos_x -= l * cos(r / 180 * M_PI);
		pos_y += l * sin(r / 180 * M_PI);
		r += nr;
		if(l == 0 && nr == 0) break;
	}
	printf("%d\n%d\n", (int)pos_x, (int)pos_y);
	return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  string ans = "Yes";
  if (n%2 == 1){
    ans = "No";
  }
  else{
    for (int i = 0; i < n/2; i++){
      if (s[i] != s[i+n/2]){
        ans = "No";
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        string line; //??\?????????????????????????????°?????£?¨?
        while (true)
        {
            line = Console.ReadLine(); //??\???????????????
            int judge = int.Parse(line); //???????????£????????????int????????????????????°?????????
            if (judge == 0) break; //0?????´???break


            int[] score = new int[judge]; //score?????\?????????????????£?¨?
            int sum = 0; //?????°????¨????????????£?¨?

            for (int i = 0; i < judge; i++)
            {
                score[i] = int.Parse(Console.ReadLine()); //score??????????????°?????\????????????
                sum += score[i]; //?????????????¨????????¨????
            }
            int max, min;
            min = max = score[0];
            for (int i = 0; i < judge; i++)
            {
                if (score[i] < min) min = score[i]; //????°?????±???????
                if (score[i] > max) max = score[i]; //?????§????±???????
            }
            int average = (sum - max - min) / (judge - 2); //??????????±???????
            Console.WriteLine(average); //????????????
        }
    }
}

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

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

    int t = stoi(a + b);

    double target = pow(t, 0.5);

    string ans = "No";
    if (target == floor(target)) {
        ans = "Yes";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool yakusu(int S) {
  int ans = 1;
  for(int i = 1; i < S; i++) {
    if(S % i == 0) {
      ans++;
    }
  }
  if(ans == 8) return true;
  else return false;
}
int main () {
  int N;
  cin >> N;
  int sasa = 0;
  for(int i = 1; i <= N; i+=2) {
    if(yakusu(i)) sasa++;
  }
  cout << sasa << endl;
}

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

// UnionFind tree(N);でUnion-Find木を生成
// tree.root(X);で親ノード番号を返す
// tree.unite(X, Y);でノードを結合する
// tree.same(X, Y);でXノード、Yノードが結合しているかどうか返す
// tree.size(X);でXノードが結合しているノード数を返す
struct UnionFind{
  vector<int> par;
  vector<int> sizes;

  UnionFind(int N) : par(N), sizes(N, 1){
    for(int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x){
  if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    if(sizes[rx] < sizes[ry]) swap(rx, ry);
    par[ry] = rx;
    sizes[rx] += sizes[ry];
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

  int size(int x){
    return sizes[root(x)];
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int V, E; cin >> V >> E;
  UnionFind tree(V);
  priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >, greater<pair<int, pair<int, int > > > > pq;
  REP(i, E){
    int s, t, w; cin >> s >> t >> w;
    pq.push({w, {s, t}});
  }
  int ans = 0;
  while(!pq.empty()){
    auto tmp = pq.top(); pq.pop();
    int x = tmp.second.first, y = tmp.second.second;
    if(!tree.same(x, y)){
      ans += tmp.first;
      tree.unite(x, y);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4648
#include <cstdio>
int A, G, N;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  scanf("%d", &N);
  int G = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A);
    G = gcd(A, G);
  }
  printf("%d\n", G);
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> button(N);
  for (int i=0; i < N; i++) {
    cin >> button.at(i);
    button.at(i) = button.at(i) - 1;
  }
  int ans, kasu, TLE;
  ans = 0;
  kasu = button.at(0);
  TLE = N + 10;
  for (int i=0; i < TLE; i++) {
    ans = i + 1;
    if (kasu == 1) {
      cout << ans << endl;
      break;
    }
    kasu = button.at(kasu);
  }
  if (ans == TLE) {
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 3748
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0

for i in range(a+1):
	for j in range(b+1):
		for k in range(c+1):
			if i*500 + j*100 + k*50 == x :
				ans += 1
print(ans)

Measured memory_bytes: 9164
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;

const int MAX_N = 1E+05;

int N;

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

    cin >> N;

    unordered_map<int, int> m;
    int en = 0;

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (m.count(a)) {
            m[a]++;
            if (m[a] & 1) {
                en--;
            } else {
                en++;
            }
        } else {
            m.insert(make_pair(a, 1));
        }
    }

    int ans = m.size() - (en & 1);

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 7308
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	string a, b, c,s;
	cin >> a >> b>>c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def resolve():
    N,K = map(int,input().split())
    A= list(map(int,input().split()))

    S = sum(A)
    
    divs = make_divisors(S)

    for d in divs[::-1]:
        r=[i%d for i in A]
        r.sort() 
        ruiseki = list(itertools.accumulate(r))
        for i,v in enumerate(ruiseki):
            b = ruiseki[-1]-v
            bb = (N-1-i)*d-b
            if v <= K and v == bb:
                print(d)
                return




resolve()


Measured memory_bytes: 41836
#include<stdio.h>
#include<vector>
#include<algorithm>
int map[100][100];
int main()
{
	int mx, my;
	scanf("%d%d", &mx, &my);
	int c = 0;
	for (int i = 0; i < mx; i++)
	{
		for (int j = 0; j < my; j++)
		{
			char z;
			scanf(" %c", &z);
			if (z == '#')map[i][j] = 1, c++;;
		}
	}
	int x = 0, y = 0;
	bool f = false;
	for (;;)
	{
		if (x == mx - 1 && y == my - 1)
		{
			f = true;
			break;
		}
		if (map[x + 1][y] + map[x][y + 1] == 1)
		{
			if (map[x + 1][y])x++;
			else y++;
		}
		else break;
	}
	if (f && (c == mx + my - 1))printf("Possible\n");
	else printf("Impossible\n");
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
typedef long long ll;

ll n;
char s[444444];
ll SR[444444], SB[444444], SG[444444];
ll Out;

int main(){
	scanf("%lld", &n);
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++){
		SR[i] = SR[i - 1]; 
		SB[i] = SB[i - 1]; 
		SG[i] = SG[i - 1]; 
		if(s[i] == 'R') SR[i]++;
		else if(s[i] == 'B') SB[i]++;
		else SG[i]++;
	}
	for(int i = 1; i < n - 1; i++){
		for(int j = i + 1; j <= n - 1; j++){
			int Dis = j - i;
			if( (s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')){
				Out += (SG[n] - SG[j]);
				if(s[j + Dis] == 'G') Out--;
			}
			else if( (s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R') ){
				Out += (SB[n] - SB[j]);
				if(s[j + Dis] == 'B') Out--;
			}
			else if( (s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G') ){
				Out += (SR[n] - SR[j]);
				if(s[j + Dis] == 'R') Out--;
			}
		}
	}
	printf("%lld\n", Out);
	return 0;
}

Measured memory_bytes: 1832
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



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


Measured memory_bytes: 3552
import java.util.Scanner;
class Main {
	int a,b,c,i;
	private int[] sei = new int[3];
	public void suzuki(){
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		if(a < b){
			if(b < c){
				sei[0] = a;
				sei[1] = b;
				sei[2] = c;
				System.out.println(sei[0] + " " + sei[1] + " " + sei[2]);
			}else if(a < c){
				sei[0] = a;
				sei[1] = c;
				sei[2] = b;
				System.out.println(sei[0] + " " + sei[1] + " " + sei[2]);
			}else{
				sei[0] = c;
				sei[1] = a;
				sei[2] = b;
				System.out.println(sei[0] + " " + sei[1] + " " + sei[2]);
			}
		}else if(a < c){
			sei[0] = b;
			sei[1] = a;
			sei[2] = c;
			System.out.println(sei[0] + " " + sei[1] + " " + sei[2]);
		}else if(b < c){
			sei[0] = b;
			sei[1] = c;
			sei[2] = a;
			System.out.println(sei[0] + " " + sei[1] + " " + sei[2]);
		}else{
			sei[0] = c;
			sei[1] = b;
			sei[2] = a;
			System.out.println(sei[0] + " " + sei[1] + " " + sei[2]);
		}
	}
	public static void main(String[] args){
		new Main().suzuki();
	}
}

Measured memory_bytes: 17320
# n, k = map(int, input().split())
# from collections import OrderedDict
# d = OrderedDict()
# a = list(input().split())
# b = list(map(int, input().split()))
# print(r + max(0, 100*(10-n)))
# print("Yes" if 500*n >= k else "No") 
# s = input()
a = int(input())
b = int(input())
c = int(input())
print((c+max(a, b)-1)//max(a, b))

Measured memory_bytes: 61684
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define ms(a,v) memset(a,v,sizeof a)
/* * * *   * * *   	* * * */
/* *
 *
 * Author: OakenSh1eld
 *
 * */
 int l[2010], sticks[2010][1010];
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin>>n;
	ms(sticks, 0);
	for(int i=0; i<n; ++i) cin>>l[i];
	sort(l, l+n);
	for(int i=0; i<n; ++i){
		for(int j = 0; j<i; ++j) sticks[j][l[i]]++;
	}
	for(int i=0; i<n; ++i) for(int j = 1; j<=1000; ++j) sticks[i][j]+=sticks[i][j-1];
	int ans = 0;
	for(int i=0; i<n; ++i){
		for(int j=i+1;j<n; ++j){
			int a = l[i], b = l[j];
			ans+= sticks[j][min(1000, a+b-1)];
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 8192