akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
const ll MOD = 1e9+7;

set<ll> A;
set<ll> B;
ll AA[1100];
ll BB[1100];

int main(){
    int N, M;
    cin >> N >> M;
    REP(i,N){
        ll x;
        cin >> x;
        A.insert(x);
        AA[i] = x;
    }
    REP(i,M){
        ll x;
        cin >> x;
        B.insert(x);
        BB[i] = x;
    }

    sort(AA, AA+N);
    sort(BB, BB+M);

    if(A.size() != N || B.size() != M){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    int put = 0;
    for(int x = N*M; x > 0; x--){
        bool afind = false, bfind = false;
        if(A.find(x) != A.end()) afind = true;
        if(B.find(x) != B.end()) bfind = true;
        //int bnum = distance(B.lower_bound(x), B.end());
        //int anum = distance(A.lower_bound(x), A.end());
        int bnum = BB+M - lower_bound(BB, BB+M, x);
        int anum = AA+N - lower_bound(AA, AA+N, x);
        if(afind && bfind){
            ; 
        }
        else if(afind){
            ans *= bnum;
        }
        else if(bfind){
            ans *= anum;
        }
        else if(anum == N && bnum == M){
            ans *= N*M-put;
        }
        else if(bnum > 0 || anum > 0){
            ans *= anum*bnum-put;
        }
        else{
            ans = 0;
        }
        //printf("%d;%lld\n", x, ans);
        ans %= MOD;
        put++;
    }

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
#define endl '\n'
using namespace std;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 112345;
int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    int ans = n+k;
    ans = max(ans, 2*n-1);
    ans = max(ans, 2*k-1);
    printf("%d\n", ans);
}


Measured memory_bytes: 256
import heapq
def hq(x,y,z):
    return (-A[x-1]-B[y-1]-C[z-1],x,y,z)
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

visited=[hq(1,1,1)]
ans=[]
q=[]
heapq.heappush(q,hq(1,1,1))
for _ in range(K):
    e,x,y,z=heapq.heappop(q)
    ans.append(-e)
    if x+1<=X and hq(x+1,y,z) not in visited:
        heapq.heappush(q,hq(x+1,y,z))
        visited.append(hq(x+1,y,z))
    if y+1<=Y and hq(x,y+1,z) not in visited:
        heapq.heappush(q,hq(x,y+1,z))
        visited.append(hq(x, y+1, z))
    if z+1<=Z and hq(x,y,z+1) not in visited:
        heapq.heappush(q,hq(x,y,z+1))
        visited.append(hq(x, y, z+1))

for i in ans:
    print(i)



Measured memory_bytes: 4980
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <map>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;


int main()
{
    ll N, M;
    std::cin >> N >> M;

    std::vector<ll> H(N,0);
    for (auto i=0; i<N; ++i)
        std::cin >> H[i];

    ll result = 0;
    std::vector<ll> lessEqualThanCount(N, 0);
    for (auto i=0; i<M; ++i)
    {
        ll a, b;
        std::cin >> a >> b;
        a--;
        b--;

        if (H[a] < H[b])
            lessEqualThanCount[a]++;
        else if (H[b] == H[a])
        {

            lessEqualThanCount[a]++;
            lessEqualThanCount[b]++;
        }
        else if (H[b] < H[a])
            lessEqualThanCount[b]++;
    }

    for (auto i=0; i<N; ++i)
    {
        if (lessEqualThanCount[i] == 0)
            result++;
    }

    std::cout << result << std::endl;
}


Measured memory_bytes: 4828
'''
問題：
    縦 2 マス、横 3 マスのマス目が与えられます。
    上から i 行目、左から j 行目のマスの色は、Cij で表されます。

    このマス目を 180 度回転させたとき、
    元のマス目と一致するなら YES を、そうでないなら NO を出力するプログラムを作成してください。
'''

'''
制約：
    Cij（1 ≦ i ≦ 2、 1 ≦ j ≦ 3）は英小文字である。
'''

# 標準入力から Cij、Cji を取得する
cij = str(input())
cji = str(input())

reverse_cij = cij[2] + cij[1] + cij[0]  # cij を180度回転させた文字列

result = ""
if cji == reverse_cij:
    result = "YES"
else:
    result = "NO"

print(result)


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

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long

const int upper = 1e5 + 20;
const int M = (int) 1e9 + 7;
const int inf = (int) 1e15;
const double eps =  1e-8;

vector<pair<int, int> > cities[(int) 1e5 + 1];
vector<string> answer;

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif		

	int n, m; cin >> n >> m;
	answer.resize(m + 1);

	for (int i = 1; i <= m; i += 1) {
		int p, y; cin >> p >> y;
		cities[p].push_back(MP(y, i));
	}

	for (int p = 1; p <= n; p += 1) {
		sort(all(cities[p]));
		string pre = to_string(p);
		while (len(pre) < 6) pre = '0' + pre;
		for (int i = 0; i < len(cities[p]); i += 1) {
			string post = to_string(i + 1);
			while (len(post) < 6) post = '0' + post;

			answer[cities[p][i].second] = pre + post;
		}
	}

	for (int i = 1; i <= m; i += 1) {
		cout << answer[i] << endl;
	}
 	end_routine();	
}

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

class SegmentTree {
public:
    static const int MAX_N = 1 << 17;
    int n, dat[2*MAX_N-1];

    SegmentTree(int n) {
        int t = 1;
        while (t < n) t *= 2;
        this->n = t;
        for (int i = 0; i < 2*t-1; i++) dat[i] = INT_MAX;
    }

    void update(int i, int x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1)/2;
            dat[i] = min(dat[i*2 + 1], dat[i*2 + 2]);
        }
    }

    // return the minimum value of [a, b)
    int find(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return INT_MAX;

        if (a <= l && r <= b) return dat[k];
        else {
            int vl = find(a, b, k*2 + 1, l, (l + r)/2);
            int vr = find(a, b, k*2 + 2, (l + r)/2, r);
            return min(vl, vr);
        }
    }
};

int main(void) {

    int n, q; cin >> n >> q;
    SegmentTree st(n);
    for (int i = 0; i < q; i++) {
        int com, x, y; cin >> com >> x >> y;
        if (com == 0) {
            st.update(x, y);
        } else {                // com == 1
            cout << st.find(x, y+1, 0, 0, st.n) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4116
{-# LANGUAGE ViewPatterns, ScopedTypeVariables #-}

import qualified Data.ByteString.Lazy.Char8 as B
-- import qualified Data.Map.Strict as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Data.List
import Data.Maybe
import Control.Monad
import Control.Monad.ST
import Debug.Trace

traceQ :: (Show a) => String -> a -> a
traceQ label a = trace (label ++ ": " ++ show a) a
-- traceQ _ a = a

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

num_digits :: Int -> Int -> Int
num_digits k n = ceiling (logBase (fromIntegral k) ((fromIntegral n) + 0.5))

power_int :: Int -> Int -> Int
power_int x y = round ((fromIntegral x) ** (fromIntegral y))

nextPower :: Int -> Int
nextPower n = 10 `power_int` (num_digits 10 n)

sumColumns :: Int -> Int
sumColumns n | n < 10    = n
sumColumns n | otherwise = (n `mod` 10) + sumColumns (n `div` 10)
  
solve :: Int -> Int
solve valK = runST act
  where
    act :: forall s. ST s Int
    act = do
      vDist <- VM.replicate valK valK
      vSw <- VM.replicate valK False
      VM.write vDist 0 0
      VM.write vSw 0 True
      act1 valK (Q.fromList [0]) vDist vSw

    act1 :: forall s. Int -> Q.Seq Int -> VM.MVector s Int -> VM.MVector s Bool
            -> ST s Int
    act1 minDist (Q.viewl -> Q.EmptyL) _ _ = return minDist
    act1 minDist (Q.viewl -> carry Q.:< queue) vDist vSw = do
      VM.write vSw carry False
      dist <- VM.read vDist carry 
      if dist >= minDist - 1
        then act1 minDist queue vDist vSw
        else do
        aqs <- forM [0 .. 9] (procBranch dist)
        let candNmd = dist + (sumColumns carry)
            newMinDist = if candNmd == 0 then minDist
                         else min minDist candNmd
        act1 newMinDist (queue Q.>< Q.fromList (concat aqs)) vDist vSw
          where
            procBranch :: Int -> Int -> ST s [Int]
            procBranch dist k = do
              let x = carry + k * valK
                  newCarry = x `div` 10
                  newDist = dist + (x `mod` 10)
              oldDist <- VM.read vDist newCarry
              if newDist < minDist - 1 && newDist < oldDist
                then do
                  VM.write vDist newCarry newDist
                  sw <- VM.read vSw newCarry
                  let ret = if sw then [] else [newCarry]
                  VM.write vSw newCarry True
                  return ret
                else return []

main :: IO ()
main = do
  conts <- B.getContents
  let [valK] = bsReadInts conts
      x = solve valK
  putStrLn $ show x
  


Measured memory_bytes: 9468
n = int(input())
a = list(map(int,input().split()))

print(2*n - 2)

M = a.index(max(a))
m = a.index(min(a))
if abs(a[m]) <= abs(a[M]):
    for i in range(n):
        if i != M:
            print(M+1,i+1)
    for i in range(n-1):
        print(i+1,i+2)
else:
    for i in range(n):
        if i != m:
            print(m+1,i+1)
    for i in range(1,n)[::-1]:
        print(i+1,i)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a,s,c;
  while(cin >> a >> s >> c){
    TSTART();
    string ans = "A";
    ans = ans + s[0] ;
    ans = ans + "C";
    cout << ans << endl;
    TSTOP();
  }
    return 0;
}



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

#define rep(i,k,n) for(int (i)=(k);(i)<(n);(i)++)
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define abs(a) (a)>0 ?(a):-(a)
#define llong long long

int main(){
	llong N,K; scanf("%lld %lld",&N,&K);
	int a[N],flag[N];
	rep(i,0,N){
		int k; scanf("%d",&k);
		k--;
		a[i]=k;
		flag[i]=-1;	// 0から何回の移動でそこに行く？
	}
	int num=0;
	rep(i,0,K){
		if( flag[num]==-1 ){	// 未到達点
			flag[num] = i;
			num = a[num];
		}else{
			int k = i - flag[num];	// 周期
			K = (K-flag[num])%k + flag[num];
			num = 0;
			rep(j,0,K){
				num = a[num];
			}
			break;
		}
	}
	printf("%d",num+1);
	return 0;
}


Measured memory_bytes: 3292
from sys import stdin
N, D = [int(x) for x in stdin.readline().rstrip().split()]
X = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]

cnt = 0
for j in range(N):
    for k in range(j, N):
        dis = 0
        for d in range(D):
            dis += (X[j][d] - X[k][d]) ** 2
        if dis > 0 and (dis ** 0.5) % 1 == 0:
            cnt += 1

print(cnt)


Measured memory_bytes: 38384
=begin
N
=end
N = gets.chomp.to_i

S = "abcdefghij".each_char.to_a

A = []

def rec(a, max, index)
  if index >= N
    s = a.map {|i| S[i] }.join
    puts s
    # A << s
  else
    for i in (0..(max + 1)) do
      max2 = [i, max].max
      rec(a + [i], max2, index + 1)
    end
  end
end

rec([], -1, 0)

# A.sort!.each do |s|
#   puts s
# end


Measured memory_bytes: 3196
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
    int n, m, x;
    scanf("%d %d %d", &n, &m, &x);
    int costToZero = 0;
    int a;
    while(1) {
        scanf("%d", &a);
        if(a < x) costToZero++;
        else break;
    }
    int costToN = m - costToZero;
    printf("%d\n", costToZero < costToN ? costToZero : costToN);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(x-r<0||x+r>W||y-r<0||y+r>H){
  	printf("No\n");
  }else{
  	printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 584
import numpy as np

h,w,m = map(int,input().split())
t = list(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(m))

H = [0] * h
W = [0] * w
for x,y in t:
    H[x] += 1
    W[y] += 1
H_max = max(H)
W_max = max(W)

H_index = [x for x,i in enumerate(H) if i == H_max]
W_index = [y for y,j in enumerate(W) if j == W_max]

ans = H_max + W_max

t = set(t)
for r in H_index:
    for c in W_index:
        if (r, c) not in t:
            print(ans)
            exit()
print(ans - 1)

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

std::vector<std::vector<long long> > comb(int n, int r) {
  std::vector<std::vector<long long> > v(n + 1,std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}


int main(){
    long long n, p;
    cin >> n >> p;

    long long even = 0, odd = 0;
    for(long long i = 0; i < n; i++){
        long long a;
        cin >> a;
        if(a % 2 == 0){
            even++;
        }
        else{
            odd++;
        }
    }

    long long ans = 0;
    if(p == 0){

        long long i = 0;
        while(i <= odd){
            vector<vector<long long> > v;
            v = comb(odd, i);
            ans = ans + v[odd][i];
            i += 2;
        }
        ans = ans*pow(2, even);
    }
    else{
        long long i = 1;
        while(i <= odd){
            vector<vector<long long> > v;
            v = comb(odd, i);
            ans = ans + v[odd][i];
            i += 2;
        }
        ans = ans*pow(2, even);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	ll m;
	cin>>m;
	if(n==m)
	{
		cout<<"Yes"<<"\n";
	}
	else
	{
		cout<<"No"<<"\n";
	}
	return 0;
	
}

Measured memory_bytes: 3644
N = int(input())
S = input()

cd = []
q = []
for s in S:
    if q and q[-1]=="(":
        if s==")":
            q.pop()
        else:
            q.append(s)
    else:
        q.append(s)
sl = []
sr = []
for s in q:
    if s==")":
        sl.append("(")
    else:
        sr.append(")")

print("".join(sl)+S+"".join(sr))

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

int main(){
    int n,k;
    cin >> n >> k;
    int l[50];
    int ans=0;
    for(int i=0;i<n;i++)cin >> l[i];
    sort(l,l+n);
    for(int i=0;i<k;i++)ans+=l[n-1-i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)
#define pb push_back
#define MAX 1000000000
#define MOD 1000000007
int kekka = 0;
vector<int> arr;
bool seracharr(){
  rep(i,arr.size()-1){
    if(arr[i] == arr[arr.size()-1])return true;
  }
  return false;
}

int f(int n){
  kekka++;
  if(n % 2 == 0){
    arr.push_back(n/2);
    if(seracharr())return kekka;
    else f(n/2);
  }else {
    arr.push_back(n*3+1);
    if(seracharr())return kekka;
    else f(n*3+1);
  }
}
int main(){
  int s;cin>>s;
  arr.push_back(s);
  cout << f(s)+1 << endl;
  return 0;
}

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

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

struct edge {
    int s, t, w;
};

template<typename T = ll>
pair<bool, vector<T>> bellman_ford(int n, int s, const vector<edge>& edges) {
    constexpr T inf = numeric_limits<T>::max();
    vector<T> d(n, inf);
    bool n_cycle = false;

    d[s] = 0;
    REP(i, n) {
        bool update = false;
        for (const edge & e : edges) {
            if (d[e.s] != inf && d[e.s] + e.w < d[e.t]) {
                d[e.t] = d[e.s] + e.w;
                update = true;
            }
        }

        if (i == n-1 && update) {
            vector<bool> neg(n, false);

            REP(i, n) {
                for (const edge& e : edges) {
                    if (d[e.s] != inf && d[e.s] + e.w < d[e.t] || neg[e.s]) {
                        neg[e.t] = true;
                    }
                }
            }

            n_cycle = neg[n - 1];
        }
    }

    return {n_cycle, d};
}

int main() {
    int n, m; cin >> n >> m;
    vector<edge> edges(m);

    REP(i, m) {
        int a, b, c; cin >> a >> b >> c;
        --a; --b;
        edges[i] = {a, b, -c};
    }

    auto ret = bellman_ford(n, 0, edges);

    if (!ret.first) {
        cout << -ret.second[n-1] << endl;
    } else {
        cout << "inf" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    int wa=0,re=0,tle=0,ac=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(s=="AC") ac++;
        else if(s=="TLE") tle++;
        else if(s=="RE") re++;
        else if(s=="WA") wa++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(void) {
    int n;
    cin >> n;
    int p[n];
    rep(i, n) cin >> p[i];
    rep(i, n) p[i]--;

    int idx[n+1];
    rep(i, n) idx[p[i]] = i;

    int dp[n+1];
    dp[0] = 1;
    rep(i, n) {
        if (not i) i ++;
        dp[i] = idx[i] > idx[i-1] ? dp[i-1]+1 : 1;
    }

    int m = 0;
    rep(i, n)  m = max(m, dp[i]);
    cout << n-m << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<math.h>
#include<set>
#include<iomanip>
#include<stdio.h>
#include<deque>
#include<stack>
#include<map>
#include<queue>
#include<cstring>
#include<unordered_map>
#define M 1000000007
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	n--;
	int o=(n*(n+1))/2;
	cout<<o<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int N;
const int MAX_N = 200010;

char a[MAX_N],b[MAX_N];
int dp[MAX_N],path[MAX_N];

int pos[26][MAX_N];

int main(){
	
	scanf("%s",a);
	N=strlen(a);

	for(int i=0;i<26;i++)pos[i][N]=N+1;
	for(int i=N-1;i>=0;i--){
		for(int j=0;j<26;j++){
			pos[j][i]=pos[j][i+1];
		}
		pos[a[i]-'a'][i]=i;
	}
	dp[N]=1;

	for(int i=N-1;i>=0;i--){
		dp[i]=1e9;
		for(int j=0;j<26;j++){
			if(dp[i]>dp[pos[j][i]+1]+1){
				dp[i]=dp[pos[j][i]+1]+1;
				path[i]=pos[j][i]+1;
				b[i]=j+'a';
			}
		}
	}

	for(int i=0;i<N;i=path[i]){
		putchar(b[i]);
	}
	puts("");

	return 0;
}


Measured memory_bytes: 22528
#include <stdio.h>

int main()
{
  int n, h, w;
  scanf("%d%d%d", &n, &h, &w);

  int ans=0;
  while(n--)
  {
    int a, b;
    scanf("%d%d", &a, &b);
    if ( a>= h && b >= w ) ans++;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <iostream>

int main()
{
  using namespace std;

  int n, acc;
  char c1, c2;

  cin >> n;

  cin >> c1;
  acc = 1;

  for (int i = 1; i < n; i++) {
    cin >> c2;
    if (c1 != c2) acc++;
    c1 = c2;
  }

  cout << acc << endl;

  return 0;
}


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

    int n,i;
    int x;
    cin>>n;
    deque<int>q;
    for(i=1; i<=n; i++)
    {
        cin>>x;
        if(i%2==0)
            q.push_back(x);
        else
            q.push_front(x);
    }
    if(n%2==0)
        reverse(q.begin(),q.end());
    for(auto it=q.begin(); it!=q.end(); it++)
        cout<<*it<<' ';
    puts("");
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    multiset<int> st;

    rep(i, n) {
        int a;
        cin >> a;
        st.insert(a);
    }

    int ans = 0;
    while(st.size()) {

        auto it = st.end();
        it--;

        int a = *it;

        st.erase(it);

        int b = 1;
        while(b <= a) {
            b *= 2;
        }

        b -= a;

        auto jt = st.find(b);

        if(jt != st.end()) {
            ans++;
            st.erase(jt);
        }
    }

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

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  int ans = 0;
  for (int i=0; i<n; i+=2){
    if (a[i] % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int a; cin >> a;
    cout << (a + a*a + a*a*a) << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>

int main(void)
{
	int N,i,ret,k;
	while(1){
		scanf("%d", &N);
		if (!N)
			break;
		ret = 0;
		for(i = 2;i <= 44;i++){
			if ((N << 1) % i == 0) {
				if ((k = ((N << 1) / i - i)) & 1) {
					if (k > 0) {
						ret++;
					}
					else
						break;
				}
			}
		}
		printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <stdlib.h>

struct{
  char mark;
  int value;
}typedef Card;


main(){
  Card C[36], C2[36], list[36];
  int i, j, k, min, n, c = 0, l, f = 0, f2 = 0;
  char m;
  
  scanf("%d", &n);
  scanf(" %c %d ", &C[0].mark,&C[0].value);
  for(i = 1;i < n-1;i++) scanf("%c %d ", &C[i].mark,&C[i].value);
  scanf("%c %d", &C[i].mark,&C[i].value);

  for(i = 0;i < n;i++){
    C2[i]=C[i];
  }

  for(i = 0;i < n;i++){
    for(j = i + 1;j < n-1;j++){
      if(C[i].value == C[j].value && C[j].value !=  f2){
	list[c].mark = C[i].mark;
	list[c].value = C[i].value;
	c++;
	f2 = C[i].value;
	break;
      }
    }
  }


  for(i = 0;i < n;i++){
    for(j = n-1;j > i;j--){
      if(C[j].value < C[j - 1].value){
	k = C[j].value;
	C[j].value = C[j-1].value;
	C[j-1].value = k;
	m = C[j].mark;
	C[j].mark = C[j-1].mark;
	C[j-1].mark = m;

      }
    }
  }
  
  for(i = 0;i < n;i++){
    min = i;
    for(j = i;j < n;j++){
      if(C2[j].value < C2[min].value){
	min = j;
      }
    }
    k = C2[i].value;
    C2[i].value = C2[min].value;
    C2[min].value = k;
    m = C2[i].mark;
    C2[i].mark = C2[min].mark;
    C2[min].mark = m;
  }
  
  for(i = 0;i < n - 1;i++){
    printf("%c%d ", C[i].mark, C[i].value);
  }
  printf("%c%d\n", C[i].mark, C[i].value);

  for(i = 0, f = 0;i < n - 1;i++){
    if(list[f].value == C[i].value){
      if(C[i].mark == list[f].mark){
	f++;
      }
    }
  }   

  if(f >= 1 || c == 0) printf("Stable\n");
  else printf("Not stable\n");

  for(i = 0;i < n - 1;i++){
    printf("%c%d ", C2[i].mark, C2[i].value);
  }
  printf("%c%d\n", C2[i].mark, C2[i].value);
  
  for(i = 0, f = 0;i < n - 1;i++){
    if(l == C2[i].value){
      if(C2[i].mark == list[f].mark){
	f++;
      }
    }
  } 
  
  if(f >= 1 || c == 0) printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}

Measured memory_bytes: 608
#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"

using namespace std;

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

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



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

	cin >> N >> M >> K;
	if (N > M)swap(N, M);
	if (N > K)swap(N, K);
	if (M > K)swap(K, M);
	if (N % 2 && M % 2 && K % 2) {
		cout << N * M << endl;
		return 0;
	}
	cout << 0 << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,k;
vector<int> mp[2001];
int tim[2001][2001];
vector<int> sidea,sideb;
void dfs(int x,int from,int root,int d)
{
	int i,t;
	tim[root][x]=d;
	for(i=0;i<mp[x].size();i++)
	{
		t=mp[x][i];
		if(t!=from)
			dfs(t,x,root,d+1);
	}
}
int main()
{
	int ans,now,a,b,i,j;
	cin>>n>>k;
	for(i=1;i<n;i++)
	{
		cin>>a>>b;
		mp[a].push_back(b);
		mp[b].push_back(a);
		sidea.push_back(a);
		sideb.push_back(b);
	}
	for(i=1;i<=n;i++)
		dfs(i,-1,i,0);
	ans=0;
	for(i=1;i<=n;i++)
	{
		now=0;
		for(j=1;j<=n;j++)
			if(2*tim[i][j]<=k)
				now++;
		ans=max(ans,now);
	}
	for(i=0;i<sidea.size();i++)
	{
		a=sidea[i];
		b=sideb[i];
		now=0;
		for(j=1;j<=n;j++)
			if(2*min(tim[j][a],tim[j][b])+1<=k)
				now++;
		ans=max(ans,now);
	}
	cout<<n-ans<<endl;
	return 0;
}

Measured memory_bytes: 16128
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

int main(){
    int N;
    cin>>N;
    int cnt=0,maxi=0;
    REP(i,N){
        int D1,D2;
        cin>>D1>>D2;
        if(D1==D2){
            cnt++;maxi=max(maxi,cnt);
        }else{
            cnt=0;
        }
    }
    if(maxi>=3)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3672
# 標準出力を取得（strデータ）
A, B = input().split()

# A, B を integerに変換
A = int(A)
B = int(B)

# OAタップの数を表す変数の初期値を 1 とする
num = 1


if B == 1:
    num = 0
else:
    while (A - 1) * (num - 1) + A < B:
        num = num + 1

# 結果を出力
print(num)

Measured memory_bytes: 9156
from collections import deque
h, w = list(map(int, input().split()))
s = [input() for _ in range(h)]

dxs = [1, 0, -1, 0]
dys = [0, 1, 0, -1]

dists = [[3000]*w for _ in range(h)]
dists[0][0] = 1
que = deque([(0, 0, 1)])
while len(que) > 0:
    i, j, score = que.popleft()
    
    for dy, dx in zip(dys, dxs):
        i_next, j_next = i+dy, j+dx
        if i_next < 0 or i_next >= h or j_next < 0 or j_next >= w:
            continue
        if s[i_next][j_next] == '#':
            continue
        if dists[i_next][j_next] <= score+1:
            continue
        dists[i_next][j_next] = score+1
        que.append((i_next, j_next, score+1))
# for d in dists: print(d)

if dists[h-1][w-1] == 3000:
    print(-1)
    exit()
d_min = dists[h-1][w-1]
n_black = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            n_black += 1
print(h*w - n_black - d_min)


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

int main(){
    string N; cin >> N;
    int n = N.size();

    int sum_9 = 0;
    rep(i,n){
        sum_9 += N[i]-'0';
        sum_9 %= 9;
    }

    YesNo(!sum_9);
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  
  int N, K;
  cin >> N >> K;
  int count = 0;
  double a = 1;
  double ans = 0;
  
  for (int i = 1; i <= N; i++) {
    int j = i;
    while (j <= K - 1) {
      j = j * 2;
      count++;
    }
    for (int l = 1; l <= count; l++) {
      a /= 2;
    }
    ans = ans + a / N;
    count = 0;
    a = 1;
  }
  
  cout << setprecision(13) << ans << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int A[9], b[10], bingo[9];
	for (int i = 0; i < 9; i++) {
		cin >> A[i];
	}
	int N;
	cin >> N;
	for (int j = 0; j < N; j++) {
		cin >> b[j];
	}
	for (int k = 0; k < 9; k++) {
		bingo[k] = 0;
	}
	for (int l = 0; l < 9; l++) {
		for (int m = 0; m < N; m++) {
			if (b[m] == A[l]) {
				bingo[l] = 1;
				break;
			}
		}
	}
	if ((bingo[0] == bingo[1]) && (bingo[1] == bingo[2])&&(bingo[0]==1)) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((bingo[3] == bingo[4]) && (bingo[4] == bingo[5])&&(bingo[3]==1)) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((bingo[6] == bingo[7]) && (bingo[7] == bingo[8])&&(bingo[6]==1)) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((bingo[0] == bingo[3]) && (bingo[3] == bingo[6])&&(bingo[0]==1)) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((bingo[1] == bingo[4]) && (bingo[4] == bingo[7])&&(bingo[1]==1)) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((bingo[2] == bingo[5]) && (bingo[5] == bingo[8])&&(bingo[2]==1)) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((bingo[0] == bingo[4]) && (bingo[4] == bingo[8])&&(bingo[0]==1)) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((bingo[2] == bingo[4]) && (bingo[4] == bingo[6])&&(bingo[2]==1)) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(x) (x).begin(),(x).end()

int main () {
  int n,k,x;
  int acc = 0;
  cin >> n >> k;

  REP(i,n) {
    cin >> x;
    acc += min(x*2, (k-x)*2);
  }

  cout << acc << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
	int n,c=0,i;
	scanf("%d",&n);
	for(i=0;i<3;i++)
	{
		int d=n%10;
		if(d==1)
		c++;
		n=n/10;
		}
		printf("%d",c);
		}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807;
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }

long long f[100002] = {0};

int main() {
	long long N, K;
	long long A, B;
	scanf("%lld%lld", &N, &K);

	for (long long i = 0; i < N; i++) {
		scanf("%lld%lld", &A, &B);
		f[A - 1] += B;
	}

	long long ans = 0;
	long long tmp = 0;
	for (long long i = 0; i < 100002; i++) {
		tmp = tmp + f[i];
		if(tmp >= K) {
			ans = i+1;
			break;
		}
	}
	printf("%ld\n", ans);

#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	string s; cin >> s;
    int n = (int)s.size();
    for(int i = 0; i < n - 1; ++i) {
        if(s[i] == 'A' && s[i + 1] == 'C') {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;

int main()
{
	int32_t N, K;
	cin >> N >> K;

	int64_t res = K;
	for (int32_t i = 1; i < N; i++)
		res *= (K - 1);

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int[] c = new int[26];
        for (int i=0;i<s.length();i++)c[s.charAt(i)-'A']++;
        boolean b = true;
        for (int i=0;i<26;i++)if (c[i]!=0&&c[i]!=2)b=false;
        if (b)System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 35724
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a>b) cout << 2*a-1 << endl;
    else if(a<b) cout << 2*b-1 << endl;
    else cout << 2*a << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int tim[1001] = {0};
	int s, e, n, ans;
	cin >> s >> e;
	tim[s] = 1;
	tim[e] = -1;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s >> e;
		tim[s] = tim[s] + 1;
		tim[e] = tim[e] - 1;
	}
	for (int i = 0; i <= 1000; i++)
	{
		if (i != 0)
			tim[i] = tim[i - 1] + tim[i];
		ans = tim[i];
		if (ans > 1)
			break;
	}
	if (ans > 1)
		cout << "1" << endl;
	else
		cout << "0" << endl;
	return 0;
}


Measured memory_bytes: 3112
N = int(input())
S = str(input())

if (N % 2) == 1:
    print("No")
else:
    num = N/2
    i = 0
    T1 = ""
    T2 = ""
    for val in S:
        i += 1
        if i > num:
            T2 += val
        else:
            T1 += val
    if T1 == T2:
        print("Yes")
    else:
        print("No")

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

using namespace std;
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define fwr(x) { cout << x << '\n'; }

typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int inf = 1e9 + 7;
const ll linf = 1ll * inf * inf;
const int N = 100000 + 7;
const int M = 1600;
const int multipleTest = 0;
const double pi = acos(-1);

int n;
int a[N];

pair<ll, ll> nil = make_pair(-1, -1);

pair<ll, ll> get(ll cur, int modNow, int modPre) {
    ll low = cur, high = cur + modNow - 1;
    
    ll hh = (high / modPre) * modPre;
    if (hh < low) return nil;
    
    ll waoef = ((low + modPre - 1) / modPre) * modPre;
    
    return make_pair(waoef, hh);
}

ll check(ll k) {
    rep(i, 1, n + 1) {
        k -= k % a[i];
    }
    return k;
}

void solve() {
    cin >> n;
    rep(i, 1, n + 1) {
        scanf("%d", a + i);
    }
    
    if (a[n] != 2) {
        puts("-1");
        return;
    }
    
    
    ll low = 1, high = linf, mid = -1;
    
    while (low <= high) {
        ll g = (low + high) / 2;
//        cout << g << ' ' << check(g) << ' ' << check(g + 1) << '\n';
        if (check(g) >= 2) {
            mid = g;
            high = g - 1;
        } else low = g + 1;
    }
    
    if (mid == -1 || check(mid) != 2) {
        puts("-1");
        return;
    }
    cout << mid << ' ';
    low = mid; high = linf;
    while (low <= high) {
        ll g = (low + high) / 2;
        if (check(g) == 2) {
            mid = g;
            low = g + 1;
        } else high = g - 1;
    }
    cout << mid;
    
}

int main() {
#ifdef _LOCAL_
    freopen("inp.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
#endif
    
    int Test = 1;
    if (multipleTest)
        cin >> Test;
    
    for(int i = 0; i < Test; ++i) {
        //        printf("Case #%d: ", i + 1);
        solve();
    }
#ifdef _LOCAL_
    cout<< "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    n++;
    ll in, ans;
    vector<ll> fee(n);
    vector<ll> fee_total(n);

    // input
    fee[0] = 0;
    fee_total[0] = 0;
    for(int i=1; i<n; i++){
        cin >> in;
        fee[i] = in;
        fee_total[i] = fee_total[i-1] + abs(fee[i] - fee[i-1]);
    }
    fee.push_back(0);
    fee_total.push_back(fee_total[n-1] + abs(fee[n]-fee[n-1]));
    //for(int i=0;i<n;i++){
        //cout << fee_total[i] << endl;
    //}

    for(int i=1; i<n; i++){
        ans = (fee_total[i-1] - fee_total[0]) + abs(fee[i+1] - fee[i-1]) + (fee_total[n] - fee_total[i+1]); 
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

#define MAX_N 200005
ll inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i=2; i<MAX_N; i++) {
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    fac[i] = fac[i-1] * (ll)i % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
ll perm(ll n, ll r) {
  if(n < 0)       return 0;
  else if(n < r)  return 0;
  else            return (fac[n] * finv[n-r]) % mod;
}
ll comb(ll n, ll r) {
  ll ans = 1;
  ans = perm(n, r); // n * (n-1) * ... * (n-r+1)
  ans = (ans * finv[r]) % mod; // フェルマーの小定理
  return ans;
}

int main() {
  make();
  int N, M, K;
  cin >> N >> M >> K;
  ll ans = 0;
  REP(i, 1, N) {
    ans += (i * ((((N-i) * M % mod) * M % mod) * comb(N*M-2, K-2) % mod) % mod);
    ans %= mod;
  }
  REP(i, 1, M) {
    ans += (i * ((((M-i) * N % mod) * N % mod) * comb(N*M-2, K-2) % mod) % mod);
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}



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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; ++i) {
    cin >> h.at(i);
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (h.at(i) >= K) {
      ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>

int main () {
   int a[50];
   int n, i, j;

   scanf("%d", &n);

   a[0] = 1;
   a[1] = 1;

   for(i = 2; i <= n; i++){
      a[i] = a[i-1] + a[i-2];
   }

   printf("%d\n", a[n]);

   return 0;
}

Measured memory_bytes: 1852
/*
author: Hayato Kawakita
date: 2020/05/11 22:27
vertict: AC
URL:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2104
所要時間:10分
*/


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }

//Binary Indexed Tree: 1 indexed
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n = 0): n(n), d(n + 1) {}
  void add(int i, T x = 1) {
    for (i++; i <= n; i += i & -i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i & -i) {
      x += d[i];
    }
    return x;
  }
};

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

  //inputs
  ll n, p, q;
  cin >> n >> p >> q;
  vector<ll> c(n);
  rep(i, n) cin >> c[i];

  //void solve()
  vector<ll> a(n);
  rep(i, n) a[i] = p * (q - i) - c[i];
  sort(a.begin(), a.end(), greater<ll>());
  ll ans = 0;
  rep(i, n) ans += c[i];
  ll res = ans;
  rep(i, n) {
    res += a[i] + p * 2 * i;
    chmax(ans, res);
  }
  cout << ans << '\n';








  
  return 0;
}


Measured memory_bytes: 10752
#include<stdio.h>

int	i	=	0,	result;
int	train[100];
int outtrain[100];

void	push(int	k){
	train[i]	=	k;
	i++;
}

void	pop(int train[]){
	int	a,	check	=	0;
	for(a	=	i	-	1;	a	>=	0;	a--){
		if(train[a]	!=	0){
			result	=	train[a];
			train[a]	=	0;
			check	+=	1;
		}
		if(check	!=	0)break;
	}
}


int	main(){
	int	k,	cnt	=	0;
	outtrain[100]	=	0;
	while(scanf("%d",	&k) != EOF){
		push(k);
		if(k	==	0){
			pop(train);
			outtrain[cnt]	=	result;
			cnt++;
			i	-=	2;
		}
	}
	for(k	=	0;	k	<=	cnt;	k++){
		if(outtrain[k]	!=	0)printf("%d\n",	outtrain[k]);
	}
	return 0;
}


	

Measured memory_bytes: 1028
#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;

int n;
int h[100009],memo[100009];
 
int dp(int i){
  int rec;
  if(memo[i]!=-1)return memo[i];
  if(i==n-1)return 0;
  if(i+1<n)rec=dp(i+1)+abs(h[i]-h[i+1]);
  if(i+2<n)rec=min(rec,dp(i+2)+abs(h[i]-h[i+2]));
  return memo[i]=rec;
}

int main(){
  memset(memo,-1,sizeof(memo));
  cin>>n;
  for(int i=0;i<n;i++)cin>>h[i];
  cout<<dp(0)<<endl;
  return(0);
}


Measured memory_bytes: 5760
s = raw_input().split()

stack = []
for op in s:
	if op.isdigit():
		stack.append(op)
	else:
		b = int(stack.pop())
		a = int(stack.pop())
		ret = 0
		if op == "+":
			ret = a + b
		elif op == "-":
			ret = a - b
		elif op == "*":
			ret = a * b
		stack.append(str(ret))
print stack.pop()

Measured memory_bytes: 6240