akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;};
/*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/

typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p == NIL  /*ここを埋める (fill this blank)*/) printf("root, ");
  else if( T[u].l == NIL /*ここを埋める(fill this blank)*/) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if( T[u].r != NIL   /*ここを埋める(fill this blank)*/) calcDepth( T[u].r, p  /*ここを埋める(fill this blank)*/);
  if( T[u].l != NIL   /*ここを埋める(fill this blank)*/) calcDepth( T[u].l , p+1 /*ここを埋める(fill this blank)*/);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  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", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 6420
H,W = map(int,input().split())

def sub(a,k,b,l):
    list = sorted([a*l,(k-a)*b,(k-a)*(l-b)])
    return list[2]-list[0]

if H*W % 3 == 0:
    print(0)
else:
    a = W//3
    b = H//2
    g1 = 99999999999999999999999999
    for i in [a,a+1]:
        if H%2==0:
            g1 = min(g1,sub(i,W,H//2,H))
        for j in [b,b+1]:
            g1 = min(g1,sub(i,W,j,H))

    c = H//3
    d = W//2
    g2 = 99999999999999999999999999
    for i in [c,c+1]:
        if W%2==0:
            g2 = min(g2,sub(i,H,W//2,W))
        for j in [b,b+1]:
            g2 = min(g2,sub(i,H,j,W))
    print(min(g1,g2,H,W))

Measured memory_bytes: 3064
n, p = map(int, input().split())
s = input()

def twofive(n, p, s):
    res = 0
    for i in range(n):
        mostlow = int(s[i])
        if mostlow%p==0:
            res += i+1
    return res

def others(n, p, s):
    from collections import Counter
    res = 0
    
    num = 0
    amari = [0 for _ in range(n+1)]
    for i in range(n)[::-1]:
        j = n-1-i
        num += int(s[i]) * pow(10, j, p) %p
        num %= p
        amari[j+1] = num
    
    amaricnt = Counter(amari)
    for val in amaricnt.values():
        if val == 1:
            continue
        else:
            res += val*(val-1)//2
    
    return res

if p == 2 or p==5:
    print(twofive(n, p, s))
else:
    print(others(n, p, s))

Measured memory_bytes: 53216
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

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

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

    if(A[0] != 0){
        cout << -1 << endl;
        return 0;
    }

    for(int i = 0; i < N-1; ++i){
        if(A[i+1] > A[i] + 1){
            cout << -1 << endl;
            return 0;
        }
    }

    int64_t ans = 0;
    for(int i = N-1; i > 0; --i){
        if(A[i-1] + 1 == A[i]){
            ++ans;
        } else {
            ans += A[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  ld a;
  cin >> a;
  cout << fixed << setprecision(12);
  cout << (a*a*a)/27.0 << endl;
  return 0;
}


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

typedef unsigned long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

ll a,b,c,d;
map<ll,ll> mp;
ll solve(ll n){
    if(n == 0) return d;
    if(n == 1) return d;
    if(mp.count(n)) return mp[n];

    ll ans = INF;
    if(ans/d > n) ans = d*n;

    ll la = (n/2)*2;
    ll ua = ((n+1)/2)*2;
    ll lb = (n/3)*3;
    ll ub = ((n+2)/3)*3;
    ll lc = (n/5)*5;
    ll uc = ((n+4)/5)*5;

    ans = min(ans,llabs(n-la)*d+a+solve(la/2));
    ans = min(ans,llabs(n-ua)*d+a+solve(ua/2));

    ans = min(ans,llabs(n-lb)*d+b+solve(lb/3));
    ans = min(ans,llabs(n-ub)*d+b+solve(ub/3));
    
    ans = min(ans,llabs(n-lc)*d+c+solve(lc/5));
    ans = min(ans,llabs(n-uc)*d+c+solve(uc/5));
    
    mp[n] = ans;
    return ans;
}

int main(){
    int t;
    cin >> t;
    for(int i = 0; i < t; i++){
        mp.clear();
        ll n;
        cin >> n >> a >> b >> c >> d;
        ll ans = solve(n);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4364
#!/usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


def LI(): return list(map(int, input().split()))


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def S(): return input().rstrip()


def LS(): return S().split()


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


mod = 1000000007
inf = 1e10

#solve


def solve():
    k, n = LI()
    
    a = LI()
    a = a + list(map(lambda x: x + k, a))
    ans = inf
    for i in range(n):
        ans = min(ans, a[i + n] - a[i] , k - (a[i + 1] - a[i]))
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 88524
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

const int MAX = 20000;
int p[MAX], a[MAX], b[MAX], c[MAX];
signed main(){
	int n;
	scanf("%lld", &n);
	rep(i,n){scanf("%lld", &p[i]);p[i]--;}
	a[0] = 1;
	repi(i,1,n)a[i] = a[i-1]+n;
	b[n-1] = 1;
	drep(i,n-2,0)b[i] = b[i+1]+n;
	rep(i,n)a[p[i]] += i;
	
	rep(i,n)printf("%lld%c", a[i], " \n"[i == n-1]);
	rep(i,n)printf("%lld%c", b[i], " \n"[i == n-1]);
	//rep(i,n)printf("%lld%c", a[i]+b[i], " \n"[i == n-1]);
	return 0;
}






Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
const long double pi = 3.14159265358979323846264338327950288;
bool a[1001];
int b[1001];
int main() {
	fill(a, a + 1001, true);
	a[0] = false, a[1] = false;
	for (int i = 0; i < 1001; i++) {
		if (a[i]) {
			int j = i * 2;
			while (j < 1001) {
				a[j] = false;
				j += i;
			}
		}
	}
	int n;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		int c = i;
		for (int j = 0; j <= i; j++) {
			if (!a[j]) continue;
			while (c%j == 0) {
				c /= j;
				b[j]++;
			}
		}
	}
	ll sum = 1;
	for (int i = 0; i <= n; i++) {
		if (a[i]) {
			sum *= (b[i]+1);
			sum %= 1000000007;
		}
	}
	cout << sum << endl;
	cin >> n;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int Selection_sort(int dat[],int size){
    int min,count=0;
    for(int i=0;i<size;++i){
        min=i;
        for(int j=i;j<size;++j){
            if(dat[j]<dat[min]) min=j;
        }
        if(min!=i) ++count;
       swap(dat[i],dat[min]);
    }
    return count;
}


int main(){
    const int max=100;
    int size,dat[max],count;
    cin >> size;
    for(int i=0;i<size;++i){
        cin >> dat[i];
    }
    count=Selection_sort(dat,size);
    for(int i=0;i<size;++i){
        if(i)cout<<" ";
        cout<<dat[i];
    }
    cout<<endl;
    cout<<count<<endl;
    return 0;
}

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

public class Main {
    
    class Answer {
        int N;
        String str;
        
        public int solve() {
            StringBuilder sb1 = new StringBuilder(str);
            StringBuilder sb2 = new StringBuilder();
            
            int max = -1;
            for (int i = N-1; i >= 1; i--) {
                char ch = sb1.charAt(i);
                sb1.deleteCharAt(i);
                sb2.append(ch);
                max = Math.max(max, count(sb1, sb2));
            }
            
            return max;
        }
        
        private int count(StringBuilder sb1, StringBuilder sb2) {
            HashSet<Character> set = new HashSet<>();
            
            int count = 0;
            for (int i = 0; i < sb2.length(); i++) {
                if ( sb1.indexOf( String.valueOf(sb2.charAt(i)) ) >= 0 ) {
                    if ( set.add(sb2.charAt(i)) ) {
                        count++;
                    }
                }
            }
            
            return count;
        }
        
        public void main(FastScanner in, PrintWriter out) {
            N = in.nextInt();
            str = in.next();
            out.println( solve() );
        }
    }

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        
        Main main = new Main();
        Answer ans = main.new Answer();
        ans.main(in, out);
        
        out.close();
        in.close();
    }
    
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try { st = new StringTokenizer(br.readLine()); } 
                catch (IOException e) { e.printStackTrace(); }
            }
            return st.nextToken();
        }
        public String nextLine() {
            String str = "";
            try { str = br.readLine();
            } catch (IOException e) { e.printStackTrace(); }
            return str;
        }
        public void close() throws IOException { br.close(); }
    }
}


Measured memory_bytes: 23252
#include <stdio.h>
#include <algorithm>
#include <complex>
#include<vector>

int main()
{
    int n, table[128]{}, max = 0;
    char s[128];

    scanf("%d%s", &n, s);

    for (char c = 'a'; c <= 'z'; ++c)
    {
        int left, right;
        for (left = 0; left < n; ++left)
        {
            if (s[left] == c) break;
        }
        for (right = n - 1; right >= 0; --right)
        {
            if (s[right] == c) break;
        }
        for (int i = left; i < right; ++i)
        {
            table[i]++;
        }
    }
    for (int i = 0; i < n; ++i)
        if (table[i] > max)
            max = table[i];

    printf("%d\n", max);

    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Hello
{
    public static void Main()
    {
        int N = NextInt();
        int K = NextInt();
        double[] HalfP = new double[100010];
        HalfP[0] = 1;
        HalfP[1] = 0.5;
        for (int i = 2; i <= 100000; i++)
            HalfP[i] = HalfP[i - 1] / 2.0;
        double ans = 0.0;
        for (int i = 1; i <= N; i++)
        {
            //今サイコロの目はiである
            int count = 0;
            int m = i;
            while (m < K) { m *= 2; count++; }
            ans += 1 / (N + 0.0) * HalfP[count];
        }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); }
    public static string NextString() { Confirm(); return queue.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13244
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;

int N;
set<int> st;
int main(){
	// debug;
	ios;

	cin>>N;
	for(int i = 1;i<=N;i++){
		int cur; cin>>cur;
		st.insert(cur);
	}
	if(N != st.size()) cout<<"NO\n";
	else cout<<"YES\n";

	return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int n;
	cin>>n;
	vi v(n);
	rep(i, n) cin>>v[i], --v[i];
	vi u(n);
	rep(i, n) u[v[i]] = i;
	set<int> sp, sn;
	sp.insert(n);
	sn.insert(1);
	ll ans = 0LL;
	//rep(i, n) cout<<"  "<<v[i];
	//cout<<endl;
	for(int i = 0; i < n; i++){
		int r = (*(sp.upper_bound(u[i])))-u[i];
		int l = (*(sn.upper_bound(-u[i])))+u[i];
		sp.insert(u[i]);
		sn.insert(-u[i]);
		ans += (ll)l*r*(i+1);
		//cout<<l<<" "<<r<<endl;
		//cout<<" "<<*(sp.upper_bound(u[i]))<<" "<<*(sn.upper_bound(-u[i]))<<endl;
	}
	cout<<ans<<endl;

}

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

int main() {
  int N, M;
  int count=0;
  int T =0;
  cin >>N>> M ;
  vector<int> S(N);
  for(int i=0; i<N; i++){
    cin>>S.at(i);
    T+=S.at(i);  
  }

  for(int i=0; i<N; i++){
    if(S.at(i)*4*M>=T){
      count++;
    }
  }

  if(count>=M){
  cout <<"Yes"<< endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  double ans = 0.0, A;
  cin >> N;
  for(int i = 1; i <= N; ++i){
  cin >> A;
  ans += 1.0 / A;
  }
  ans = 1.0 / ans;
  cout << setprecision(16) << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

x, y = [int(i) for i in input().split()]

MOD = 10 ** 9 + 7

import functools
import math

def mpow(x, n):
    result = 1
    while n > 0:
        if (n & 1):
            result = (result * x) % MOD
        x = (x * x) % MOD
        n >>= 1
    return result

# 方程式を解けば解が一意に定まるため、全パターンを試すのは無駄
def solver_not_good():
    factorial = [0] * (10 ** 6 + 1)
    inverse = [0] * (10 ** 6 + 1)
    factorial[0] = 1
    inverse[0] = 1
    for i in range(1, 10 ** 6 + 1):
        factorial[i] = (i * factorial[i-1]) % MOD
        inverse[i] = mpow(factorial[i], MOD - 2) % MOD

    total = 0
    twopath_maxnum = x // 2
    for twopath_num in range(twopath_maxnum + 1):
        onepath_num = x - twopath_num * 2
        if (onepath_num * 2 + twopath_num * 1) == y:
            a = factorial[onepath_num + twopath_num]
            b = inverse[onepath_num]
            c = inverse[twopath_num]
            total += (a * b * c) % MOD
    return total

def solver_better():
    # 剰余演算を都度挟みたいため、math.factorialは使えない
    factorial = [0] * (10 ** 6 + 1)
    factorial[0] = 1
    for i in range(1, 10 ** 6 + 1):
        factorial[i] = (i * factorial[i-1]) % MOD

    # x + y が3の倍数でないときは到達できない
    if ((x + y) % 3) != 0:
        return 0

    a = (2 * x - y) // 3
    b = (2 * y - x) // 3

    # x座標/y座標のどちらかに先に到達してしまう
    if a < 0 or b < 0:
        return 0

    return (factorial[a+b] * (mpow(factorial[a], MOD - 2) % MOD) * (mpow(factorial[b], MOD -2) % MOD)) % MOD

#solver = solver_not_good
solver = solver_better
print(solver())


Measured memory_bytes: 43228
#include<stdio.h>

int n, i;
int a[20], c[20];
int b, s;
int main(void){
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", a+i);
	}
	for(i=0; i<n; i++){
		scanf("%d", &b);
		s+=b;
	}
	for(i=0; i<n-1; i++){
		scanf("%d", c+i);
	}
	for(i=0; i<n-1; i++){
		if(a[i]+1==a[i+1]){
			s+=c[a[i]-1];
		}
	}
	printf("%d\n", s);
}


Measured memory_bytes: 128
(defun split (input stack-string output-list)
  (let ((chara (car input)))
    (case chara
          ((nil) (append output-list (list stack-string)))
          (#\space (split (cdr input)
                                  '()
                                  (append output-list (list stack-string))))
          (otherwise (split (cdr input)
                                    (concatenate 'string stack-string (list chara))
                                    output-list)))))

(defun input-to-list (input)
  (mapcar #'parse-integer (split (concatenate 'list input)
                                 '()
                                 '())))

(defparameter inp (input-to-list (read-line)))
(let ((pq (+ (car inp) (cadr inp)))
      (qr (+ (cadr inp) (caddr inp)))
      (pr (+ (car inp) (caddr inp))))
  (format t "~d" (min pq qr pr)))

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

#define LL long long
#define COIN const int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define LEN(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/

using namespace std;

int n,m,d[3]={11,11,11},a,b,i;
bool ok=0;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >>n >>m;
	REP(i,m)
	{
		cin >>a >>b;
		if (d[a-1]!=b)
		{
			if (d[a-1]==11)
				d[a-1]=b;
			else
			{
				cout <<"-1"<<endl;
				return 0;
			}
		}
	}
	if (n==1 && d[0]==11)
	{
		cout <<"0"<<endl;
		return 0;
	}
	REP(i,n)
	{
		if (d[i]!=11) ok=1;
	}
	if (ok==0)
	{
		REP(i,n)
		{
			if (i==0) cout <<"1";
			else cout <<"0";
		}
		cout <<endl;
		return 0;
	}
	if (n!=1 && d[0]==0)
	{
		cout <<"-1"<<endl;
		return 0;
	}
	REP(i,n)
	{
		if (d[i]==11)
		{
			if (i!=0) cout <<"0";
			else cout <<"1";
		}
		else
			cout <<d[i];
	}
	cout <<endl;
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 256
#include<stdio.h>
long a[100000];

int main(int argc, char const *argv[]){
	long sum,bsum,ans=0,n,i,f=0,min=1;
	scanf("%ld",&n);
	scanf("%ld",&a[0]);
	if(a[0]==0){
		ans++;
		sum=1;
		f=1;
	}else sum=a[0];
	for(i=1;i<n;i++){
		scanf("%ld",&a[i]);
		bsum=sum;
		sum+=a[i];
		if(bsum>0){
			if(sum>=0){
				ans+=sum+1;
				sum=-1;
			}
		}else{
			if(sum<=0){
				ans+=1-sum;
				sum=1;
			}
		}
	}
		if(a[0]>=0){
			min=a[0]+1;
			sum=-1;
		}else{
			min=1-a[0];
			sum=1;
		}
		for(i=1;i<n;i++){
			bsum=sum;
			sum+=a[i];
			if(bsum>0){
				if(sum>=0){
					min+=sum+1;
					sum=-1;
				}
			}else{
				if(sum<=0){
					min+=1-sum;
					sum=1;
				}
			}
		}
		if(ans<min) printf("%ld\n",ans);
		else printf("%ld\n",min);
	return 0;
}

Measured memory_bytes: 896
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = input().rstrip()
    B = input().rstrip()
    C = input().rstrip()

    ans = 0
    for a, b, c in zip(A, B, C):
        ans += len(set([a, b, c])) - 1

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

ll dp[100005][2];

void Main() {
    string L;
    cin >> L;
    int N = L.length();
    dp[0][0] = 1;
    rep(i, N) {
        if (L[i] == '0') {
            dp[i+1][0] += dp[i][0];
            dp[i+1][1] += dp[i][1] * 3;
        }else{
            dp[i+1][0] += dp[i][0] * 2;
            dp[i+1][1] += dp[i][0];
            dp[i+1][1] += dp[i][1] * 3;
        }
        dp[i+1][0] %= MOD;
        dp[i+1][1] %= MOD;
    }
    cout << (dp[N][1] + dp[N][0]) %MOD << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 2000
n = int(input())
h = list(map(int,input().split()))
tmp = h[0]
isOK = True
for i in range(1,n):
    #print(tmp,h[i])
    if tmp < h[i]:
        tmp = h[i] - 1
    elif tmp == h[i]:
        tmp = h[i]
    else:
        isOK = False
        break
if isOK:
    print('Yes')
else:
    print('No')

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

using namespace std;

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

using ll = long long;

const int Inf = 1e9;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int first = (s[0] - '0') * 10 + (s[1] - '0');
	int second = (s[2] - '0') * 10 + (s[3] - '0');
	if ((first >= 1 && first <= 12) && (second >= 1 && second <= 12)) {
	  cout << "AMBIGUOUS" << endl;
	} else if (first >= 1 && first <= 12) {
	  cout << "MMYY" << endl;
	} else if (second >= 1 && second <= 12) {
	  cout << "YYMM" << endl;
	} else {
	  cout << "NA" << endl;
	}
	
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
long cmp(const void *a,const void *b){
  return *(long*)a-*(long*)b;
}

int main(){
  long n = 0;
  long a[100010] = {};
  long i = 0;
  long flag = 0;
  long tflag = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  qsort(a,n,sizeof(long),cmp);
  if(n % 3 == 0){
    for(i=0;i<n/3-1;i++){
      if(!(a[i] == a[i+1] && a[i+(n/3)] == a[i+1+(n/3)]
         && a[i+((2*n)/3)] == a[i+1+((2*n)/3)])){
        tflag = 1;
        break;
      }
    }
    if(!tflag){
      if(a[2*(n/3)] == (a[(n/3)]^a[0])){
        flag = 1;
        //printf("#");
      }else{
        flag = 0;
      }
    }
  }else{
    for(i=0;i<n-1;i++){
      if(a[i] != 0){
        tflag = 1;
        break;
      }
    }
    if(tflag){
      flag = 0;
    }else{
      flag = 1;
    }
  }
  //printf("%d %d %d %d",a[0],a[n/3],a[2*(n/3)]),a[(n/3)]^a[0];
  if(flag){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}
      
        
        
  
  

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(100001);
    int a = 0;
    long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> a;
        A.at(a)++;
        sum += a;
    }

    int Q;
    cin >> Q;

    vector<int> B(Q);
    vector<int> C(Q);
    for (int i = 0; i < Q; i++)
    {
        cin >> B.at(i) >> C.at(i);
    }

    int b = 0;
    for (int i = 0; i < Q; i++)
    {
        b = A.at(B.at(i));
        A.at(B.at(i)) = 0;
        A.at(C.at(i)) += b;
        sum = sum - (long)(B.at(i) * b - C.at(i) * b);
        cout << sum << endl;
    }
    return 0;
}

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

using namespace std;

static const int MAX = 205;
static const long long inf = (1LL<<50);

int n;
long long d[MAX][MAX];

void floyd() {
	for(int k = 0; k < n; k++ ){
		for(int i = 0; i < n; i++){
			if(d[i][k] == inf) continue;
			for(int j = 0; j < n; j++){
				if(d[k][j] ==inf)continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main() {
	int e, u, v, c, r;
	cin >> n >> e >> r;
	vector<int> R(r);
	for(int i = 0; i < r; i++){
		cin>>R[i];
		R[i]--;
	}
	sort(R.begin(),R.end());
	for(int i = 0; i <n ;i++){
		for(int j = 0; j < n; j++){
			d[i][j] = ( (i == j)? 0 :inf);
		}
	}
	for(int i = 0; i < e; i++){
		cin >> u >> v >> c;
		--u,--v;
		d[u][v] = c;
		d[v][u] = c;
	}
	floyd();

	long long ans = inf;
	do{
		long long now = 0;
		for(int i = 0; i < r-1; i++){
			now += d[R[i]][R[i+1]];
		}
		ans = min(ans,now);
	} while(next_permutation(R.begin(),R.end()));
	cout << ans << endl;
}


Measured memory_bytes: 512
n = input()
R = [input() for i in xrange(n)]

Rmin = n
maxdif = R[1] - R[0]

while Rmin > 0:
    tRmin = R.index(min(R[0:Rmin]))
    Rmax = R.index(max(R[tRmin:Rmin]))
    if tRmin == Rmax:
        if tRmin == n-1:
            tRmin-=1
        elif tRmin < n-1:
            Rmax = tRmin + 1
    Rmin = tRmin
    if (R[Rmax] - R[Rmin]) > maxdif:
        maxdif = R[Rmax] - R[Rmin]

print maxdif

Measured memory_bytes: 14188
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using LD=long double;

int N,d1,x;

LD solve(int N,LD s,LD d)
{
    if(!N)return 0;
    return s+N*d-d/2+solve(N-1,s+(s*2+5*d)/N/2,d+2*d/N);
}

int main()
{
    ios::sync_with_stdio(0);
    cin>>N>>d1>>x;
    cout<<fixed<<setprecision(12)<<solve(N,d1,x)<<endl;
    return 0;
}

Measured memory_bytes: 12800
h,w=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]
a=[list(map(int,input().split())) for i in range(h)]
lst=[0]*10
for i in range(h):
    for j in range(w):
        A=a[i][j]
        if A!=-1:
            lst[A]+=1
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])
lst[1]=0
ans=0
for i in range(10):
    ans+=c[i][1]*lst[i]
print(ans)




Measured memory_bytes: 40412
n = int(input())
s = input()

a = ['SS','SW','WS','WW']

for j in range(len(a)):
    for i in range(1,n-1):
        if s[i]=='x':
            if a[j][i]==a[j][i-1]:
                a[j]+='W'
            else:
                a[j]+='S'
        else:
            if a[j][i]==a[j][i-1]:
                a[j]+='S'
            else:
                a[j]+='W'
    flag = 0
    if (s[-1] == 'x' and a[j][-1]=='S') or (s[-1] == 'o' and a[j][-1]=='W'):
        if a[j][-2] != a[j][0]:
            flag += 1
    else:
        if a[j][-2] == a[j][0]:
            flag += 1
    if (s[0] == 'x' and a[j][0]=='S') or (s[0] == 'o' and a[j][0]=='W'):
        if a[j][-1] != a[j][1]:
            flag += 1
    else:
        if a[j][-1] == a[j][1]:
            flag += 1
    if flag == 2:
        print(a[j])
        exit()

print(-1)


Measured memory_bytes: 3828
n = int(input())
x = []
y = []
h = []

for i in range(0, n):
    xi, yi, hi = [int(i) for i in input().split(" ")]
    x.append(xi)
    y.append(yi)
    h.append(hi)

#n = 10
#x = [10, 0, 1, 5, 2, 1, 0, 2, 0, 0]
#y = [10, 0, 0, 6, 0, 1, 2, 2, 8, 1]
#h = [0, 0, 1, 0, 0, 2, 0, 0, 0, 1]

for cx in range(0, 101):
    for cy in range(0, 101):
        hd = -1
        f = False
        for i in range(0, n):
            if h[i] > 0:
                ht = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
                if hd == -1 or hd == ht:
                    hd = ht
                else:
                    f = True
                    break
                    
        for i in range(0, n):
            if h[i] == 0:
                if max(hd - abs(x[i] - cx) - abs(y[i] - cy), 0) != 0:
                    f = True
                    break
        
        if not f:
            print(cx, cy, hd)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main() {
    int N;
    cin >> N;
    int b[N-1];

    for(int i = 0; i < N-1; i++){
        cin >> b[i];
    }

    int sum = 0;
    sum += b[0];
    // cout << b[0] << endl;
    for(int i=0; i < N-2; i++){
        sum += min(b[i],b[i+1]);
        // cout << min(b[i],b[i+1]) << endl;
    }
    sum += b[N-2];
    cout << sum << endl;

}


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

class unionfind {
  vector<int> par;
  
public:
  void init(int n) {
    for (int i = 0; i < n; i++) par.push_back(i);
  }
  
  int find(int i) {
    if (par.at(i) == i) return i;
    return par.at(i) = find(par.at(i));
  }
  
  void merge(int i, int j) {
    par.at(find(i)) = find(j);
  }
};

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> x, y;
  vector<tuple<int, int, int>> p;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    x.emplace_back(a, i);
    y.emplace_back(b, i);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  for (int i = 0; i < n - 1; i++) {
    p.emplace_back(x.at(i + 1).first - x.at(i).first, x.at(i).second, x.at(i + 1).second);
    p.emplace_back(y.at(i + 1).first - y.at(i).first, y.at(i).second, y.at(i + 1).second);
  }
  sort(p.begin(), p.end());
  long ans = 0;
  unionfind network;
  network.init(n);
  for (auto r : p) {
    int d = get<0>(r), x1 = get<1>(r), x2 = get<2>(r);
    if (network.find(x1) != network.find(x2)) {
      ans += d;
    }
    network.merge(x1, x2);
  }
  cout << ans << endl;
}


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

class Dice{
private:
  int tmp;
public:
  int q[6];
  void roll(char d){
    if(d=='N'){
      tmp = q[4];
      q[4] = q[0];
      q[0] = q[1];
      q[1] = q[5];
      q[5] = tmp;
    } else if(d=='E'){
      tmp = q[2];
      q[2] = q[0];
      q[0] = q[3];
      q[3] = q[5];
      q[5] = tmp;
    } else if(d=='W'){
      tmp = q[3];
      q[3] = q[0];
      q[0] = q[2];
      q[2] = q[5];
      q[5] = tmp;
    } else if(d=='S'){
      tmp = q[1];
      q[1] = q[0];
      q[0] = q[4];
      q[4] = q[5];
      q[5] = tmp;
    }
  }
};


int main(){
  Dice d;
  for(int i=0; i<6; i++){
    cin >> d.q[i];
  }
  int n;
  int a, b;
  int r;
  int ans;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a >> b;
    for(int i=0; i<=6;i++){
      //cout << "a";
      if(i==5){
        d.roll('E');
      } else if(i==6) {
        d.roll('E');
        d.roll('E');
      } else d.roll('N');
      //cout << d.q[0] << " " << d.q[1] << endl;
      if(d.q[0]==a)break;
    }
    for(int i=0; i<=4;i++){
      //cout << "b";
      d.roll('E');
      d.roll('N');
      d.roll('W');
      //cout << d.q[0] << " " << d.q[1] << endl;
      if(d.q[0]==a&&d.q[1]==b)break;
    }
    cout << d.q[2] << endl;
    //cout << ans << endl;
  }
}



Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP(a, b) make_pair(a, b)
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n, m;
vector<pi>s;
int dp[1024];

int main(){
  while(scanf("%d", &n) && n){
    s.clear();
    int h, r;
    rep(i, n){
      scanf("%d%d", &h, &r);
      s.push_back(MP(h, r));
    }
    scanf("%d", &m);
    rep(i, m){
      scanf("%d%d", &h, &r);
      s.push_back(MP(h, r));
    }

    sort(s.begin(), s.end());
    memset(dp, 0, sizeof(dp));

    int res = 0;
    rep(i, s.size()){
      dp[i] = 1;
      rep(j, i) if(s[j].F < s[i].F && s[j].S < s[i].S){
	dp[i] = max(dp[i], dp[j] + 1);
      }
      res = max(res, dp[i]);
    }
    printf("%d\n", res);
  }
  return 0;
}

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

#ifdef __WIN32
#define LLFORMAT "I64"
#else
#define LLFORMAT "ll"
#endif

using namespace std;

const int mod = 1e9 + 7, maxn = 610;

int f[maxn][maxn], g[maxn][maxn];

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(2 * n);
	vector<int> state(2 * n + 1, 0);
	for (int i = 0; i < 2 * n; ++i) {
		cin >> a[i];
		if(a[i] != -1) state[a[i]] = 1;
	}
	for (int i = 0; i < n; ++i) if(a[2 * i] != -1 && a[2 * i + 1] != -1) state[a[2 * i]] = state[a[2 * i + 1]] = -1;
	f[0][0] = 1;
	for (int x = 1; x <= 2 * n; ++x) {
		if(state[x] == -1) continue;
		memset(g, 0, sizeof g);
		if(state[x] == 0) {
			for (int i = 0; i <= 2 * n; ++i) for (int t, j = 0; j <= 2 * n; ++j) if(t = f[i][j]) {
				g[i + 1][j] = (g[i + 1][j] + t) % mod;
				g[i][j + 1] = (g[i][j + 1] + t) % mod;
				if(j) g[i][j - 1] = (g[i][j - 1] + t) % mod;
			}
		}
		else {
			for (int i = 0; i <= 2 * n; ++i) for (int t, j = 0; j <= 2 * n; ++j) if(t = f[i][j]) {
				if(i) g[i - 1][j] = ((long long) t * i + g[i - 1][j]) % mod;
				g[i][j + 1] = (g[i][j + 1] + t) % mod;
			}
		}
		memcpy(f, g, sizeof f);
	}
	int ans = f[0][0];
	for (int cnt = 0, i = 0; i < n; ++i) if(a[i * 2] == -1 && a[i * 2 + 1] == -1) ++cnt, ans = (long long) ans * cnt % mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3200
s = input()
flag = 0
count = 0
for i in range(97,97+26):
    flag = 0
    for j in range(len(s)):
        if chr(i) == s[j]:
            flag = 1
            break
    if flag == 0:
        print(chr(i))
        break
    count += 1

if count == 26:
    print('None')

    

Measured memory_bytes: 3188
import math
import fractions
import copy
import numpy as np
#以下てんぷら
def j(q):
    if q==1: print("POSSIBLE")
    elif q == 0:print("IMPOSSIBLE")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
n,m= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
#これを消すとなぜかWAになる呪い

a = []
for i in range(m):
    b = [int(i) for i in input().split()]
    b.append(i)
    a.append(b)
a.sort()
city = a[0][0]
ct = 0
c = []
for i in range(m):
    if city != a[i][0]:
        city = a[i][0]
        ct =1
    else:ct+=1
    cna = str(city)
    cnb = str(ct)
    cna = cna.zfill(6)
    cnb = cnb.zfill(6)
    name = ''.join([cna,cnb])
    c.append([a[i][2],name])
c.sort()
for i in range(m):
    print(c[i][1])

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

int main(){
  int N, M;
  string s[100];
  string t[100];
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> s[i];
  }
  cin >> M;
  for(int i=0; i<M; i++){
    cin >> t[i];
  }
  int max=0;
  for(int i=0; i<N; i++){
    int pay=0;
    for(int j=0; j<N; j++){
      if(s[i]==s[j]) pay++;
    }
    for(int j=0; j<M; j++){
      if(s[i]==t[j]) pay--;
    }
    if(max<pay) max=pay;
  }
  if(max<0){
    cout << "0" << endl;
    return 0;
  }
  cout << max << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int l, r;
  int sum = 0;
  for(int i = 0; i < N;i++){
    cin >> l >> r;
    sum += (r - l) + 1;  
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int d;
	cin>>d;
	if(d==25)cout<<"Christmas"<<endl;
	else if(d==24)cout<<"Christmas Eve"<<endl;
	else if(d==23)cout<<"Christmas Eve Eve"<<endl;
	else cout<<"Christmas Eve Eve Eve"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<bool, bool> pbb;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= k; i ++)
#define open(i, j, k) for(int i = j; i <  k; i ++)
#define dec(i, j, k)  for(int i = j; i >= k; i --)
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
template <class T> bool chkmin(T &x, T y)
{ return y < x ? x = y, true : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? x = y, true : false; }
int _()
{
	int ret = 0; bool f = true; char ch = getchar();
	while(!isdigit(ch)) { if(ch == '-') f = false; ch = getchar(); }
	do { ret = ret * 10 + ch - '0'; ch = getchar(); } while(isdigit(ch));
	return f ? ret : -ret;
}
void _(int x)
{
	if(x < 10) { putchar(x + '0'); return ; }
	_(x / 10); putchar(x % 10 + '0');
}
void __init()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(16);
	srand(time(0) ^ ui(ul(new char)));
}
/* default code ends here */

int main()
{
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
	__init();
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << ' ' << max(-(n - a - b), 0) << '\n';
	return 0;
}

















































Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long x,k,d;
int main()
{
	cin>>k>>x>>d;
	k=abs(k);
	if(x*d>0 && x*d<=k)
	{
		cout<<k-x*d<<endl;
		return 0;
	}
	if((x-k/d)%2==0)
	{
		cout<<k%d<<endl;
	}
	else
	{
		cout<<d-k%d<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 xx;
	cin >> xx;
	bool flag;
	if(xx == 2)
	{
		cout << '2' << endl;
		return 0;
	}
	while(true)
	{
		flag = true;
		for(int64 ii = 2;ii < sqrt(xx) + 1;ii++)
		{
			if(xx % ii == 0)
			{
				flag = false;
				break;
			}
		}
		if(flag)
		{
			cout << xx << endl;
			return 0;
		}
		xx++;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>


using namespace std;

int main() {
	int a, b, c, d, e;
	int x = -1050;

	cin >> a >> b;

	c = a + b;
	d = a - b;
	e = a * b;

	if (x <= c) x = c;
	if (x <= d) x = d;
	if (x <= e) x = e;

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long int n,m;
	cin>>n>>m;
	long int i,l[m],r[m],a,b;
	for( i=0;i<m;i++)
	{
		cin>>l[i]>>r[i];
	}
	a=l[0];
	b=r[0];
	for(i=0;i<m;i++)
	{
		if(a<=l[i])
		{
			a=l[i];
		}
		if(b>=r[i])
		{
			b=r[i];
		}
	}
	if(b>=a)
	{
		b=b-a+1;
	}
	else
	{
		b=0;
	}
	if(b<n)
	{
		cout<<b<<endl;
	}
	else
	{
		cout<<n<<endl;
	}
	
}

Measured memory_bytes: 5156
from collections import defaultdict

def main():
    num = int(input())
    ligh_dic = defaultdict(int)
    for i in range(num):
        a = int(input())
        ligh_dic[i + 1] = a

    visit_flg = [0 for i in range(num + 1)]

    ans = 0
    now_num = 1
    visit_flg[now_num] = 1
    while 1:
        ans += 1
        now_num =ligh_dic[now_num]
        if visit_flg[now_num]:
            ans = -1
            break
        visit_flg[now_num] = 1
        if now_num == 2:
            break

    print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 61528
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int total_test_cases;
  while(~scanf("%d",&total_test_cases)){
    for(int test_i = 0; test_i < total_test_cases; test_i++){
      vector<int> gates;
      vector<int> jukky;
      for(int i = 0; i < 9; i++){
        int card;
        scanf("%d",&card);
        gates.push_back(card);
      }
      for(int i = 0; i < 9; i++){
        int card;
        scanf("%d",&card);
        jukky.push_back(card);
      }

      sort(gates.begin(),gates.end());
      int jukky_win = 0;
      int gates_win = 0;
      int total_games = 0;
      do {
        int jukky_score = 0;
        int gates_score = 0;

        for(int i = 0; i < gates.size(); i++){
          if(jukky[i] > gates[i]){
            jukky_score += jukky[i] + gates[i];
          }
          else if(jukky[i] < gates[i]){
            gates_score += jukky[i] + gates[i];
          }
        }

        if(jukky_score > gates_score){
          jukky_win++;
        }
        else if(jukky_score < gates_score){
          gates_win++;
        }
        total_games++;
      }while(next_permutation(gates.begin(),gates.end()));

      printf("%.5lf %.5lf\n",
             (double)gates_win/(double)total_games,
             (double)jukky_win/(double)total_games);
    }
  }
}

Measured memory_bytes: 1244
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define N 100005
using namespace std;
typedef long long ll;

ll n, m, ans, gr, a[N], pr[N];
vector<ll> fr[N], all;

ll fnd(ll p) {
	if(pr[p]==p) return p;
	return pr[p] = fnd(pr[p]);
}

int main() {
	ll i, j, x, y;
	cin >> n >> m;
	for(i=0; i<n; i++) {
		scanf("%lld", &a[i]);
		pr[i] = i;
	}
	for(i=0; i<m; i++) {
		scanf("%lld%lld", &x, &y);
		x = fnd(x);
		y = fnd(y);
		pr[x] = y;
	}
	for(i=0; i<n; i++) fr[fnd(i)].push_back(a[i]);
	for(i=0; i<n; i++) {
		if(fr[i].empty()) continue;
		gr++;
		sort(fr[i].begin(), fr[i].end());
		ans += fr[i][0];
		for(j=1; j<fr[i].size(); j++) all.push_back(fr[i][j]);
	}
	if(gr==1) return puts("0")*0;
	if((int)all.size() < 2*(n-m-1)-gr) return puts("Impossible")*0;
	sort(all.begin(), all.end());
	for(i=0; i<2*(n-m-1)-gr; i++) ans += all[i];
	cout << ans;
	return 0;
}

Measured memory_bytes: 7296
var Baseball = function(attackCount) {
  this.attackCount = +attackCount;
  this.outCount = 0;
  this.endCount = attackCount * 3;
  this.runners = [];
  this.score = 0;
  this.isChanged = false;
};
Baseball.prototype.isEnd = function() {
  return this.outCount === this.endCount;
};
Baseball.prototype.echo = function() {
  console.log(this.score);
  this.score = 0;
  this.runners = [];
};
Baseball.prototype.action = function(command) {
  switch(command) {
    case 'HIT':
      this.runners.push(0);
      this.runners = this.runners.map(function(r) { return r + 1; });
      if (this.runners[0] === 4) {
        this.score += 1;
        this.runners.shift();
      }
      break;
    case 'HOMERUN':
      this.score += this.runners.length + 1;
      this.runners = [];
      break;
    case 'OUT':
      this.outCount += 1;
      if (this.outCount % 3 === 0) return 'change'
      break;
  }
  return 'next';
};

var d = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n');
var bb = new Baseball(d.shift());

while (true) {
  if (bb.action(d.shift()) === 'change') {
    bb.echo();
    if (bb.isEnd()) break;
  }
}

Measured memory_bytes: 7640