akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,d;
ll x[110][110];

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>d;
    rep(i,n){
        rep(j,d){
            cin>>x[i][j];
        }
    }
    ll ans = 0;
    rep(i,n){
        if(i==n-1)continue;
        repi(j,i+1,n){
            double tmp = 0.0;
            rep(k,d){
                tmp += (double)(x[i][k]-x[j][k])*(double)(x[i][k]-x[j][k]);
            }
            if(sqrt(tmp)==ceil(sqrt(tmp)))ans++;
        }
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		System.out.println((N - 1) / 2);
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

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

#define ll long long
#define pb push_back

using namespace std;


ll pow5(ll n)
{
    return n * n * n * n * n;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n, i, j, a, b;

    cin >> n;

    for(i = -120; i <= 120; i++)
        for(j = -120; j <= 120; j++)
            if(pow5(i) - pow5(j) == n) {
                cout << i << " " << j << endl;
                return 0;
            }

    return 0;
}




Measured memory_bytes: 3596
n = gets.chop.to_i
a = gets.chop.split.map(&:to_i)

cnt_4 = 0
cnt_2 = 0
a.each do |num|
  if num % 4 == 0
    cnt_4 += 1
  elsif num % 4 !=0 && num % 2 == 0
    cnt_2 +=1
  end
end

if cnt_4 + cnt_2/2 >= n/2
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 9476
L, R= list(map(int, input().split()))
# array = np.arange(L, R+1)


# flg = True

def get_amari():
    min_ = 2019
    for i in range(L,R):
        for j in range(i+1, R+1):
            # if (i*j)%2019==0:
            #     print(0)
            #     flg = False
            #     break
            # elif (i*j)%2019 < min_:
            #     min_ = (i*j)%2019
            if (i*j)%2019 < min_:
                min_ = (i*j)%2019
    return min_
#     if flg:
        # print(min_)
                
def get_flg3():
    if R-L >= 3:
        return True
    elif R//3 != L//3:
        return True
    else:
        return False
    

def get_flg673():
    if R-L >= 673:
        return True
    elif R//673 != L//673:
        return True
    else:
        return False

def mataganai_2019():
    return (L*(L+1))//2019 == ((R-1)*R)//2019
        
if get_flg3() & get_flg673():
    print(0)
else:
    print(get_amari())

Measured memory_bytes: 3064
#!/usr/bin/env python3
from collections import Counter
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, s: "List[str]", M: int, t: "List[str]"):
    ctr = Counter(s)
    ctr.subtract(t)
    ((_key, cnt),) = ctr.most_common(1)
    print(max(0, cnt))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    M = int(next(tokens))  # type: int
    t = [next(tokens) for _ in range(M)]  # type: "List[str]"
    solve(N, s, M, t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
from itertools import combinations_with_replacement


n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
    
numbers = range(1, m+1)
arrays = list(combinations_with_replacement(numbers, n))
ans = []


for i in range(len(arrays)):
    dm = 0
    l = arrays[i]
    for j in range(q):
        if l[b[j]-1] - l[a[j]-1] == c[j]:
            dm = dm+d[j]
    ans.append(dm)
    
print(max(ans))

Measured memory_bytes: 25076
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int n, a, b;
    scan(n, a, b);
    writeln(min(a*n, b));
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

bool check(ll a, ll b, ll x) { return a * a * a * a * a - b * b * b * b * b == x; }

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

  ll x;
  cin >> x;
  REP(a, 1001) {
    REP(b, 1001) {
      if (check(a, b, x)) {
        cout << a MM b << endl;
        return 0;
      } else if (check(-a, -b, x)) {
        cout << -a << " " << -b << endl;
        return 0;
      } else if (check(-a, b, x)) {
        cout << -a MM b << endl;
        return 0;
      } else if (check(a, -b, x)) {
        cout << a << " " << -b << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5;
int N,M;
int par[MAX_N];
int outdeg[MAX_N];
vector<int> rG[MAX_N],G[MAX_N];
int main(){
	cin>>N>>M;
	REP(i,N-1+M){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		G[a].push_back(b);
		rG[b].push_back(a);
		outdeg[a]++;
	}
	memset(par,-1,sizeof(par));
	queue<int> que;
	REP(i,N){
		if(outdeg[i]==0){
			que.push(i);
		}
	}
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(auto e:G[v]){
			if(par[e]==-1){
				par[e]=v;
			}
		}
		for(auto e:rG[v]){
			outdeg[e]--;
			if(outdeg[e]==0){
				que.push(e);
			}
		}
	}
	REP(i,N){
		cout<<par[i]+1<<endl;
	}
}

Measured memory_bytes: 12544
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn] , b[maxn];
queue<int> Q;
int main()
{
    ios::sync_with_stdio(false);
    int n; cin >> n;
    for (int i = 1 ; i <= n ; i++) cin >> a[i];
    for (int i = 1 ; i <= n ; i++) cin >> b[i];
    reverse(b + 1 , b + 1 + n);
    int l = -1;
    for (int i = 1 ; i <= n ; i++) {
        if (a[i] != b[i]) continue;
        l = i;
        break;
    }
    if (l == -1){
        cout << "Yes" << endl;
        for (int i = 1 ; i <= n ; i++) cout << b[i] << " ";
        cout << endl;
        return 0;
    }
    int r = -1;
    for (int i = n ; i >= 1 ; i --){
        if (a[i] != b[i]) continue;
        r = i;
        break;
    }
    for (int i = 1 ; i <= n ; i++){
        if (b[i] == b[l] || a[i] == b[l]) continue;
        Q.push(i);
    }
    if (r - l + 1 > (int)Q.size()) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = l ; i <= r ; i++){
        int t = Q.front();Q.pop();
        swap(b[t],b[i]);
    }
    cout << "Yes" << endl;
    for (int i = 1 ; i <= n ; i++) cout << b[i] << " ";
    cout << endl;
    return 0;
}

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

int main(){
    int n, i;
    cin>>n;
    int kati[n];
    int hiyo[n];
    int kei = 0;
    for(i=0; i<n; i++){
        cin>>kati[i];
    }
    for(i=0; i<n; i++){
        cin>>hiyo[i];
        if(kati[i]-hiyo[i]>0){
            kei += kati[i] - hiyo[i];
        }
    }
    cout<<kei<<endl;

    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

int dp[1000005][2];

void solve(istream& cin, ostream& cout) {
  string s;
  cin >> s;
  REVERSE(s);
  s += '0';
  int n = s.size();
  REP(i, n+1) REP(j, 2) dp[i][j] = MOD;
  dp[0][0] = 0;
  REP(i, n+1) REP(j, 2) {
    int x = s[i] - '0';
    x += j;
    REP(a, 10) {
      int ni = i+1, nj = 0;
      int b = a-x;
      if (b < 0) {
        nj = 1;
        b += 10;
      }
      dp[ni][nj] = min(dp[ni][nj], dp[i][j]+a+b);
    }
  }
  int ans = dp[n][0];
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 9116
import sys
import time
st = time.perf_counter()
def inpl():
    return list(map(int, input().split()))
# ------------------------------

N, K = map(int, input().split())
A = list(map(lambda a: int(a)-1, input().split()))
T = [A]

for i in range(59):
    prev = T[-1]
    T.append([prev[a] for a in prev])

now = 0
for k,v in enumerate(T):
    if ((1<<k)&K)>0:
        now = v[now]
print(now+1)


# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


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

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


Measured memory_bytes: 13968
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, ans = 0;
	vector<int> B, A;
	
	cin>>N;
	
	A.resize(N+1,  INF);
	B.resize(N);
	
	for(int i = 1; i < N; i++){
		cin>>B[i];
		A[i] = min(B[i], A[i]);
		A[i+1] = min(B[i], A[i+1]);
	}
	for(int i = 1; i <= N; i++){
		ans += A[i];
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;


int main(){
    int n;
    cin>>n;
    int k=n%10;
    if(k==3){
        cout<<"bon"<<endl;
    }
    else if(k==0 || k==1 || k==6 || k==8){
        cout<<"pon";
    }
    else
        cout<<"hon";
    return 0;
}
    

Measured memory_bytes: 3612
people = int(input()) - 1
boss = input().split(' ')
boss = list(map(int,boss))
dict_boss = {}
for i in range(people):
	if boss[i]-1 not in dict_boss:
		dict_boss[boss[i]-1] = 1
	else:
		dict_boss[boss[i]-1] += 1
boss = [0] * (people + 1)
for key in dict_boss:
	boss[key] = dict_boss[key]
for i in boss:
	print(i)

Measured memory_bytes: 38768
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a;
	int ans = 0;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> a;
		if(i % 2 == 0 && a % 2 == 1){
			ans += 1;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        Array.Sort(ar);
        var sum = 0;
        for(var i = 0; i < num - 1; i++)
        {
            sum += ar[i];
        }
        WriteLine(sum > ar[num - 1] ? "Yes" : "No");
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {

  static Scanner sc = new Scanner(System.in);
  static int a;
  static int b;


  public static void main(String[] args) {
    a = sc.nextInt();
    b = sc.nextInt();
    int answer = output(a, b);
    System.out.println(answer);
  }

  private static int output(int a, int b) {
    int answer = 0;
    for (int i = a; i <= b; i++) {
      String num = String.valueOf(i);
      if (check(num)) {
        answer++;
      }
    }
    return answer;
  }

  private static boolean check(String num) {
    int length = num.length();
    for (int i = 0; i < length / 2; i++) {
      String s = num.substring(i, i + 1);
      String s2 = num.substring(length - i - 1, length - i);
      if (!s.equals(s2)) {
        return false;
      }
    }
    return true;
  }
}


Measured memory_bytes: 37356
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::min;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<i64>();
    let sqn = (n as f64).sqrt() as i64;
    let mut ret = 1i64 << 60;
    for i in 1..sqn+1 {
        if n % i == 0 {
            ret = min(ret, n / i - 1 + i - 1);
        }
    }
    println!("{}", ret);
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        tmp = []
        if n % i == 0:
            tmp.append(i)
            tmp.append(n//i)
        if(len(tmp)>0):
            divisors.append(sum(tmp))
    return divisors
def main5():
    n = int(input())
    k = make_divisors(n)
    print(min(k)-2)


if __name__ == '__main__':
    main5()


Measured memory_bytes: 9432
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################

#check = [int(("1"*i))*7 for i in range(10**6 + 2)]
#print(check)
n = int(input())
temp = 7
for i in range(1,10**7):
	#print(temp)
	if temp%n == 0:
		print(i)
		exit()
	else:
		temp = ((temp*10) + 7)%n
print(-1)


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

#define sc second
#define fr first
#define mk make_pair
#define pb push_back
#define int long long

using namespace std;

const int N = (1e6 + 5);
const int inf = (1e9 + 7);

main () {
    int n;
    string a,b;
    cin >> n >> a >> b;
    
    for (int i = 0; i < n; i ++)
        cout << a[i] << b[i];

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	ll k;
	
	cin >> k;
	
	if(k == 0)
	{
		cout << 4 << endl;
		cout << "0 0 0 0" << endl;
		return 0;
	}
	if(k == 1)
	{
		cout << 4 << endl;
		cout << "5 1 1 1" << endl;
		return 0;
		
	}
	if(k <= 50)
	{
		cout << k << endl;
		REP(i,k)
		{
			cout << k << ' ';
		}
		cout << endl;
		return 0;
	}
	
	ll tmp = k / 50;
	int ama = k % 50;
	
	ll ret[50];
	REP(i,50)
	{
		ret[i] = tmp + 49 - ama;
	}
	REP(i,ama)
	{
		ret[i] += 50;
	}
	
	cout << 50 << endl;
	REP(i,49)
	{
		cout << ret[i] << ' ';
	}
	cout << ret[49] << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

n,k=rm()
a=rl()
for i in range(k,n):
    if a[i]-a[i-k] >0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 98032
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(:5.10);
use utf8;

my $N = <STDIN>;

my @music;
for(my $i=1;$i<=$N;$i++){
    my $line = <STDIN>;
    chomp $line;
    push(@music, $line);
}

my $last = <STDIN>;
chomp $last;

my $total = 0;
my $sleep = 0;
for(@music){
    if (/^$last\s/){
        $sleep = 1;
    }
    elsif ($sleep){
        my ($name, $time) = split(/\s/);
        $total += $time;
    }
}
say $total;


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


void f(vs a,int &x,int &y,int &X,int &Y){
	for(int i=0;i<a.size();i++){
		for(int j=0;j<a[i].size();j++){
			if(isalpha(a[i][j])) x=i,y=j;
			if(a[i][j]=='%') X=i,Y=j;
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int h,w;
		cin>>w>>h;
		if(h==0) break;
		vs a(h),b(h);
		for(int i=0;i<h;i++) cin>>a[i]>>b[i];
		int sx,sy,gx,gy,SX,SY,GX,GY;
		f(a,sx,sy,gx,gy);
		f(b,SX,SY,GX,GY);
		queue<array<int,4>> q;
		q.push(array<int,4>{sx,sy,SX,SY});
		bool c[50][50][50][50];
		for(int i=0;i<50;i++) for(int j=0;j<50;j++) for(int k=0;k<50;k++) for(int l=0;l<50;l++) c[i][j][k][l]=0;
		c[sx][sy][SX][SY]=1;
		bool flag=0;
		while(!q.empty()){
			auto arr=q.front();
			q.pop();
			int x=arr[0],y=arr[1],X=arr[2],Y=arr[3];
//			cout<<x<<' '<<y<<' '<<X<<' '<<Y<<endl;
			for(int i=0;i<4;i++){
				int cx=x+dx[i],cy=y+dy[i],CX=X+dx[i],CY=Y+dy[(i+2)%4];
				int mx=1,my=1;
				if(cx<0||cx>=h||cy<0||cy>=w||a[cx][cy]=='#') cx=x,cy=y,mx=0;
				if(CX<0||CX>=h||CY<0||CY>=w||b[CX][CY]=='#') CX=X,CY=Y,my=0;
				if(cx==gx&&cy==gy&&CX==GX&&CY==GY&&mx&&my){
					flag=1;
					break;
				}
				if(cx==gx&&cy==gy||CX==GX&&CY==GY) continue;
				array<int,4> tmp={cx,cy,CX,CY};
				if(!c[cx][cy][CX][CY]){
					c[cx][cy][CX][CY]=1;
					q.push(tmp);
				}
			}
			if(flag) break;
		}
		cout<<(flag?"Yes":"No")<<endl;
	}
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

struct edge{
	ll to, idx;
};

using Graph = vector<vector<edge>>;

ll dfs(ll now, ll par, ll dst, Graph &G){
	ll res = 0;
	for(auto e: G[now]){
		if(e.to == par) continue;
		if(e.to == dst){
			res += (1ll<<e.idx);
			return res;
		}
		ll tmp = dfs(e.to, now, dst, G);
		if(tmp>0){
			res = tmp + (1ll<<e.idx);
		}
	}
	return res;
}

ll powLL(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res *= a;
        }
        a = a*a;
        n >>= 1;
    }
    return res;
}

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

    ll N;
    cin >> N;
    Graph G(N);
    REP(i, N-1){
    	ll a, b;
    	cin >> a >> b;
    	a--, b--;
    	edge e = {b, i};
    	edge f = {a, i};
    	G[a].push_back(e);
    	G[b].push_back(f);
    }

    ll M;
    cin >> M;
    vector<ll> u(M), v(M);
   	REP(i, M) cin >> u[i] >> v[i];
    REP(i, M) u[i]--, v[i]--;

    vector<ll> masks(M, 0);
    REP(i, M){
    	masks[i] = dfs(u[i], -1, v[i], G);
    }

    //cerr << masks << endl;

    ll res = 0;
    REP(mask, 1ll<<M){
    	//dump(num2bit(mask, M))
    	ll tmp = 0;
    	REP(i, M){
    		if(mask>>i & 1){
    			tmp |= masks[i];
    		}
    	}
    	//dump(tmp)
    	ll kosu = __builtin_popcountll(tmp);
    	ll val = powLL(2, N-1-kosu);

    	ll hu = __builtin_popcountll(mask);
    	if(hu%2==0) res += val;
    	else res -= val;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
using namespace std;

int main() {
  ll K, N, max = 0;
  cin >> K >> N;
  vector<ll> A(N);
  for(ll i = 0; i < N; i++) {
    cin >> A.at(i);
    if(i != 0) {
      if(max <= A.at(i) - A.at(i - 1)) max = A.at(i) - A.at(i - 1);
    }
  }
  if(max <= K - A.at(N - 1) + A.at(0)) max = K - A.at(N - 1) + A.at(0);
  cout << K - max << endl;
}


Measured memory_bytes: 1920
n = int(input())

def rot(dice,rotation):
    if rotation == "E":
        dice = (dice[3],dice[1],dice[0],dice[5],dice[4],dice[2])
    elif rotation == "W":
        dice = (dice[2],dice[1],dice[5],dice[0],dice[4],dice[3])
    elif rotation == "N":
        dice = (dice[1],dice[5],dice[2],dice[3],dice[0],dice[4])
    elif rotation == "S":
        dice = (dice[4],dice[0],dice[2],dice[3],dice[5],dice[1])
    return dice

def make_all_pattern(dice):
    pattern = {dice}
    pattern2 = pattern
    while True:
        pattern2 = pattern.union({rot(d,r) for d in pattern for r in list("NEWS")})
        if pattern2 == pattern:
            break
        pattern = pattern2
    return pattern

dice = [0 for i in range(n)]
for i in range(n):
    dice[i] = tuple(map(int,input().split()))


pattern = set()
for i in range(n-1):
    pattern = pattern.union(make_all_pattern(dice[i]))
    if dice[i+1] in pattern:
        print("No")
        break

else:
    print("Yes")
    

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

#define rep(i, a, b) for (int i = a, i##end = b; i <= i##end; ++i)
#define per(i, a, b) for (int i = a, i##end = b; i >= i##end; --i)
#define rep0(i, a) for (int i = 0, i##end = a; i < i##end; ++i)
#define per0(i, a) for (int i = (int)a-1; ~i; --i)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define chkmax(a, b) a = max(a, b)
#define chkmin(a, b) a = min(a, b)
#define x first
#define y second
#define enter putchar('\n')

typedef long long ll;
typedef double DB;

const DB eps = 1e-12;
const DB PI = acos(-1);

int sgn(DB x) { return fabs(x) < eps ? 0 : (x > 0 ? 1 : -1); }

struct Point {
	DB x, y;
	Point(DB x = 0, DB y = 0) : x(x), y(y) {}
	Point operator + (Point a) { return Point(x + a.x, y + a.y); }
	Point operator - (Point a) { return Point(x - a.x, y - a.y); }
	Point operator - () { return Point(-x, -y); }
	friend Point operator * (DB k, Point a) { return Point(k * a.x, k * a.y); }
	DB operator % (Point a) { return x * a.x + y * a.y; }
	DB operator / (Point a) { return x * a.y - y * a.x; }
	operator DB() { return sqrt(x*x + y*y); }
};

Point gp() { Point a; scanf("%lf%lf", &a.x, &a.y); return a; }
void wp(Point a) { printf("%.10lf %.10lf ", a.x, a.y); }

struct Poly {
	std::vector<Point> a;
	Poly(int n = 0) { a.resize(n); rep0(i, n) a[i] = gp(); }
	int size() { return a.size(); }
	Point &operator [] (int i) { int n = size(); return a[i >= n ? i-n : i]; }
};

int Direct1(Point P, Point P1, Point P2) { return sgn((P1-P)%(P2-P)); }
int Direct2(Point P, Point P1, Point P2) { return sgn((P1-P)/(P2-P)); }

DB Area(Poly A) {
	DB res = 0;
	rep(i, 2, A.size()-1) res += (A[i]-A[0])/(A[i-1]-A[0]);
	return fabs(res)/2;
}

bool IsConvex(Poly A) {
	bool f1 = 1, f2 = 1;
	rep0(i, A.size()) {
		int t = sgn((A[i+1]-A[i])/(A[i+2]-A[i+1]));
		t && (t == 1 ? f1 = 0 : f2 = 0);
	}
	return f1 || f2;
}

bool IsSegInter(Point P1, Point P2, Point Q1, Point Q2) {
	if (min(P1.x, P2.x) <= max(Q1.x, Q2.x) && max(P1.x, P2.x) >= min(Q1.x, Q2.x) && min(P1.y, P2.y) <= max(Q1.y, Q2.y) && max(P1.y, P2.y) >= min(Q1.y, Q2.y))
		if (Direct2(P1, P2, Q1) * Direct2(P1, P2, Q2) <= 0 && Direct2(Q1, Q2, P1) * Direct2(Q1, Q2, P2) <= 0) return 1;
	return 0;
}

int IsInPoly(Poly A, Point P) {
	DB angle = 2.0*PI*rand()/RAND_MAX; Point Q = P+1e5*Point(cos(angle), sin(angle));
	//wp(Q);enter;
	int cnt = 0;
	rep0(i, A.size()) {
		if (!Direct2(P, A[i], A[i+1]) && Direct1(A[i], A[i+1], P) * Direct1(A[i+1], A[i], P) >= 0) return -1;
		cnt ^= IsSegInter(A[i], A[i+1], P, Q);
	}
	return cnt;
}

/*
Poly GetConvex(Point P[]) {

}
*/

int n, q;
Poly A;

int main() {
	srand(time(0));
	scanf("%d", &n); A = Poly(n);
	scanf("%d", &q);
	while (q--) {
		Point P = gp();
		int t = IsInPoly(A, P);
		printf("%d\n", t == 1 ? 2 : (t == -1 ? 1 : 0));
	}
	/*
	scanf("%d", &q);
	while (q--) {
		Point P1 = gp(), P2 = gp(), Q1 = gp(), Q2 = gp();
		printf("%.10lf\n", SegDist(P1, P2, Q1, Q2));
		//wp(GetSegInter(P1, P2, Q1, Q2)); enter;
		//printf("%d\n", IsInter(P1, P2, Q1, Q2));
		//wp(Proj(P, P1, P2)); enter;
	}*/
	return 0;
}


Measured memory_bytes: 3648
k, x = map(int,input().split())
lst = [x]
if k>1:
    for i in range(k-1):
        lst.append(x-i-1)
    for i in range(k-1):
        lst.append(x+i+1)

lst.sort()
ans = ''
for i in range(len(lst)):
    num = lst[i]
    ans += str(num)
    ans += ' '

print(ans)

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int fst , sec ,thd;

    if(a < b && a < c) {
        fst = a;
        if (b < c) {
            sec = b;
            thd = c;
        } else {
            sec = c;
            thd = b;
        }
    } else if (b < a && b < c) {
        fst = b;
        if (a < c) {
            sec = a;
            thd = c;
        } else {
            sec = c;
            thd = a;
        }
    } else {
        fst = c;
        if ( a < b) {
            sec = a;
            thd = b;
        } else {
            sec = b;
            thd = a;
        }
    }

    cout << fst << ' ' << sec << ' ' << thd << endl;
    return 0;
}


Measured memory_bytes: 3052
st = input()

sample = ['dream', 'dreamer', 'erase', 'eraser']
sample_edit = ['dream', 'eraser','erase', 'er']
sample_er = ['er']
sample_dr = ['dream']
sample_ase = ['ase', 'aser']

ret = 'NO'
reg_len = 0
fd_word = ''
dream_flg = False
end_flg = False

word = ''
length = len(sample_edit)

#while( len(st) != 0 ):
while( True ):
  if reg_len == len(st):
    break
  
  reg_len = len(st)
  for i in range(length):
    word = sample_edit[i]
    fd = st.startswith(word)
    
    if fd > 0:
      
      #print(st,i,dream_flg)
      #st = ''.join(st[len(word):len(st)])
      st = st[len(word):len(st)]
        
      if word == 'dream':
        dream_flg = True
      elif word == 'er':
        if dream_flg == False:
          end_flg = True
        else:
          dream_flg = False
      
      break
    
        
  if end_flg == True:
    break
    
  if len(st) == 0:
    ret = 'YES'
    break
    
  #print(st)
  #print(len(st))

print( ret )

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  int ans=0;
  if(a>=b){
    ans+=a;
    a-=1;
  }
  else{
    ans+=b;
    b-=1;
  }
  if(a>=b){
    ans+=a;
    a-=1;
  }
  else{
    ans+=b;
    b-=1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3608
#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"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    int N = s.size(), ans = N;
    rep(0, i, 26)
    {
        char a = (char)((int)'a' + i);
        int r = 0, l, d = 0;
        rep(0, j, N)
        {
            if (s.at(j) == a)
            {
                l = j;
                d = max(d, l - r);
                r = l + 1;
            }
        }
        d = max(d, N - r);
        ans = min(ans, d);
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

int main(){
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> net(n);
    for(int i = 0; i < m; ++i){
        ll ai, bi;
        cin >> ai >> bi;
        ai--; bi--;
        net.at(ai).push_back(bi);
        net.at(bi).push_back(ai);
    }

    for(ll mid : net.at(0)){
        if(mid == n - 1){
            cout << "POSSIBLE" << endl;
            return 0;
        }
        for(ll nxt : net.at(mid)){
            if(nxt == n - 1){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 12776
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int maxn = 130 * 130 * 2;

int prime[maxn];
int cnt = 0;
bool check[maxn];

void getPrime() {
	for (int i = 2; i < maxn; i++) {
		if (check[i] == false) {
			prime[cnt++] = i;
		}
		for (int j = i + i; j < maxn; j += i) {
			check[j] = true;
		}
	}
}

int gao(int n) {
	int res = 0;
	for (int i = 0; prime[i] <= n / 2; i++) {
		if (check[n-prime[i]] == false) {
			res++;
		}
	}
	return res;
}

int main() {
	int n; getPrime();
	while (scanf("%d", &n) != EOF) {
		if (n == 0) {
			break;
		}
		printf("%d\n", gao(n));
	}
	return 0;
}

Measured memory_bytes: 1232
#                         author:  kagemeka 
#                         created: 2019-11-08 14:51:29(JST)
## internal modules
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version) 

def main():
    n = int(sys.stdin.readline().rstrip())
    print(n if n % 2 == 0 else n * 2)


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
const int INF = 1001001001;

int main()
{
    string s; cin >> s;
    Sort(s);
    set<char> c;
    rep(i,s.size()) c.insert(s[i]);
    rep(i,26){
        if(c.find('a'+i) == c.end()){
            cout << (char)('a'+i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 105;
inline int read()
{
	rg int res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int n, len;
ll ans;
struct str
{
	int x, y;
} v[Maxn];
ll dis(ll x, ll y) { return x * x + y * y; };
void Search2(rg int x, rg int cx, rg int cy)
{
	if (x > n)
	{
		ans = max(ans, dis(cx, cy));
		return;
	}
	Search2(x + 1, cx + v[x].x, cy + v[x].y);
	Search2(x + 1, cx, cy);
}
void Search1(rg int x, rg int cx, rg int cy)
{
	if (x > len)
	{
		rg ll tmp, res = dis(cx, cy);
		for (int i = len + 1; i <= n - len; i++)
			if ((tmp = dis(cx + v[i].x, cy + v[i].y)) > res)
			{
				res = tmp;
				cx += v[i].x;
				cy += v[i].y;
			}
		Search2(n - len + 1, cx, cy);
		return;
	}
	Search1(x + 1, cx + v[x].x, cy + v[x].y);
	Search1(x + 1, cx, cy);
}
int main()
{
	rg ll tmp;
	cin >> n;
	len = (n <= 20) ? n / 2 : 10;
	for (int i = 1; i <= n; i++)
	{
		v[i].x = read();
		v[i].y = read();
	}
	for (rg int t = 1; t <= 100; t++)
	{
		random_shuffle(v + 1, v + n + 1);
		Search1(1, 0, 0);
	}
	printf("%.10f\n", sqrt(ans));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[MAX];
int cs[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n;
    cin>>n;
    n--;
    cout<<(n*(n+1))/2<<endl;

     return 0;
}


Measured memory_bytes: 3480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=500003,INF=1<<30;
vector<pair<int,int>> S[MAX];
int dis[MAX];

void dijkstra(int u){
    dis[u]=0;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> PQ;
    
    PQ.push(make_pair(0,u));
    while(!PQ.empty()){
        int a=PQ.top().first;
        int b=PQ.top().second;
        PQ.pop();
        if(dis[b]<a) continue;
        for(int i=0;i<S[b].size();i++){
            int c=S[b][i].first;
            int d=S[b][i].second;
            if(dis[c]>dis[b]+d){
                dis[c]=dis[b]+d;
                PQ.push(make_pair(dis[c],c));
            }
        }
    }
    return;
}//a,dが長さ


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int X,Y,Z,N,M,s,t;cin>>X>>Y>>Z>>N>>M>>s>>t;
    s--;t--;
    for(int i=0;i<MAX;i++) dis[i]=INF;
    
    for(int i=0;i<N;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        S[i].push_back({200000+a,1});
        S[200000+a].push_back({i,0});
        
        S[i].push_back({300000+b,1});
        S[300000+b].push_back({i,0});
    }
    
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        
        S[100000+i].push_back({300000+a,1});
        S[300000+a].push_back({100000+i,0});
        
        S[100000+i].push_back({400000+b,1});
        S[400000+b].push_back({100000+i,0});
    }
    
    dijkstra(s);
    
    if(dis[100000+t]==INF) cout<<-1<<endl;
    else cout<<dis[100000+t]<<endl;
}





Measured memory_bytes: 33612
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (b <= c || d <= a)
    cout << 0 << endl;
  else
    cout << min(b, d) - max(a, c) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int r,g,b;
	scanf("%d %d %d",&r,&g,&b);
	if((r*100+g*10+b)%4==0){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#define MAX 100005
#define NIL -1
 
int D[MAX],H[MAX];
int n;
int A;
/*
 p: parent
 l: left-child
 r: right sibling
 */
void print(int);
 
struct Node{ int p, l, r;};
struct Node T[MAX]; // Tree
 
int getDepth(int u);
void tree(int a);
void hairetu(int);
int parent(int);
int sibling(int);
int degree(int);
int height(int);
 
 
void hairetu(int a){
  int leaf;
   
  if(getDepth(a) == 0){
    printf("root\n");
  }
// leaf
  else if(T[a].r ==NIL && T[a].l ==NIL){
      printf("leaf\n");
    }
  
  // internal node
  else if(T[a].r!=NIL || T[a].l!= NIL){
    printf("internal node\n"); 
  }
}
 
 
int getDepth(int u){
  int d = 0;
  int i;
  if(u == A) return 0;
  else{
    i = n-1;
    while(1){
      if(u == A) break;
      if(T[i].l == u || T[i].r == u){
    d++;
    u = T[i].p;
      }
      i--;
      if(i<0) i = n-1;
    }
    return d;
  }
   
}
 
int parent(int a){
  int i;
  if(a==A) return -1;
  else {
  for(i=0;i<n;i++){
    if(T[i].l==a || T[i].r == a){
      return T[i].p;
      break;
  }
  }
  }
}
 
int sibling(int b){
  int i;
  if(b==A) return -1;
  else {
    for(i=0;i<n;i++){
      if(T[i].l == b){
    return T[i].r;
      }
      if(T[i].r == b){
    return T[i].l;
      }
    }
  }
}
 
int degree(int d){
  if(T[d].l==-1 && T[d].r == -1){
    return 0;
  }
  else if(T[d].l != -1 && T[d].r != -1){
    return 2;
  }
  else if((T[d].l == -1 && T[d].r != -1) || (T[d].l != -1 && T[d].r == -1)){
    return 1;
  }
  
}
int height(int c){
  int l=0;
  int r=0;
 
  if(T[c].l==-1 && T[c].r == -1){
    return 0;
  }
  if(T[c].l!=-1 && T[c].r != -1){
    l = height(T[c].l)+1;
    r = height(T[c].r)+1;
    if(l<r){
      return r;
    }
    else return l;
  }
  else if(T[c].l==-1&&T[c].r!=-1){
      return height(T[c].r)+1;
    }
  else if(T[c].l!=-1&&T[c].r==-1){
      return height(T[c].l)+1;
    }
}
void print(int u){
  
   
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",u,parent(u),sibling(u),degree(u),D[u],height(u));
  hairetu(u);
}
 
 
main(){
  int i, j, d, v, c, l;
  int t;
  int flag=0;
 
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
 
  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &v, &d, &c);
 
    T[v].p = v;
     
    T[v].l = d;
 
    T[v].r = c;
     
 
  }
  A = 0;
  for(i=n-1;i>0;i--){
    if(T[i].l==A || T[i].r==A){
      A = T[i].p;   
      flag++;
      if(A == 0){
    break;
      }
    else {
      i = n-1;
    }
    } 
  }

  if(flag == 0){
    A= 0;
  }
  
  
  for(i=0;i<n;i++){
    D[i] = getDepth(i);
  }
 
  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}
   

Measured memory_bytes: 620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  int n;
  cin >> n;

  int cnt=0;
  for(int i=1; i<=n; i++){
    string s=to_string(i);
    if(s.size()%2==1) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
N = int(input())
remarks = []
for i in range(N):
    w = []
    for j in range(int(input())):
        w.append(list(map(int, input().split())))
    remarks.append(w)

def power2(n):
    if n == 1:
        return [[1], [0]]
    res = []
    for l in power2(n-1):
        res.append([1] + l)
        res.append([0] + l)
    return res

ans = 0
patterns = power2(N)
for p in patterns:
    flag = True
    for i, remark in enumerate(remarks):
        if p[i] == 0: #不親切者の発言を無視
            continue
        else:
            for w in remark:
                if p[w[0]-1] != w[1]: #発言の矛盾を判定:
                    flag = False 
                    break
                # print(w)
    if flag: #すべての発言で矛盾がなかった場合
        ans = max(ans, p.count(1))

print(ans)
    


Measured memory_bytes: 12660
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

string s;
int dp[100010];

const vector<string> kw = {
    "dream", "dreamer", "erase", "eraser"
};

int main() {
    while (cin >> s) {
        memset(dp, 0, sizeof dp);
        dp[0] = true;
        int n = s.size();
        for (int i = 0; i < n; ++i) {
            if (dp[i]) {
                for (auto &k : kw) {
                    if (s.substr(i, k.size()) == k) {
                        dp[i + k.size()] = true;
                    }
                }
            }
        }
        cout << (dp[n] ? "YES" : "NO") << endl;
    }
}

Measured memory_bytes: 1148
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    s = input().strip()

    cnt = [0] * n
    for i in range(n):
        if i == 0 and s[0] == '#':
            cnt[0] = 1

        if i>0 :
            if s[i]=='#':
                cnt[i] = 1 + cnt[i-1]
            else:
                cnt[i] = cnt[i-1]
    
    ans = 2e5+5
    for i in range(n):
        ans = min(ans, cnt[i] + n + cnt[i] - cnt[n-1] - (i+1))
    
    ans = min(ans, n - cnt[n-1])
    print(ans)
        

solve()


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

using i64 = int64_t;

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    int cnt = 0;
    for(int i=min(a,b);i>0;--i){
        if(a%i == 0 && b%i == 0){
            cnt++;
            if(cnt == k){
                cout << i << endl;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
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();
    if(a <= b){
      System.out.println(a);
    }else{
      System.out.println(a - 1);
    }
  }
}


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

int main()
{
  int a[5];
  int temp;
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

  for(int i=0; i<4; i++){
    for(int j=i+1; j<5; j++){
      if( a[i]<a[j] ){
      temp = a[i];
      a[i] = a[j];
      a[j] = temp;
      }
    }
  }
  cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << " " << a[4] << endl;

  return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#define N 100

int main(void)
{
	int i,j,n,a[N],temp;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
  printf("%d",a[0]);
	for(j=1;j<n;j++)
		printf(" %d",a[j]);
	printf("\n");
	for(i=1;i<n;i++){
		temp = a[i];
		for(j=i-1;j>=0 && a[j]>temp;j--)
			a[j+1] = a[j];
		a[j+1] = temp;
		printf("%d",a[0]);
		for(j=1;j<n;j++)
			printf(" %d",a[j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1828