akhauriyash/Code-Regression huggingface dataset:
def bubblesort(A, N):
    for i in range(N):
        for j in range(N-1,i,-1):
            if A[j-1][1] > A[j][1]:
                A[j-1], A[j] = A[j], A[j-1]
    print(*A)
    return A
    
def selectionsort(A, N):
    for i in range(N):
        minj = i
        for j in range(i+1,N):
            if A[minj][1] > A[j][1]:
                minj = j
        A[minj], A[i] = A[i], A[minj]
    print(*A)
    return A
def judge(A,B,N):
    stable = True
    for m in range(N):
        for n in range(m+1, N):
            for x in range(N):
                for y in range(x+1,N):
                    if A[m][1]==A[n][1] and A[m]==B[y] and A[n]==B[x]:
                        stable = False
    if stable:
        return "Stable"
    else:
        return "Not stable"

N = int(input())
A = list(map(str, input().split(" ")))
B = A.copy()
Bubble = bubblesort(B,N)
print(judge(A,Bubble, N))
B = A.copy()
Selection = selectionsort(B,N)
print(judge(A,Selection, N))



Measured memory_bytes: 5608
from itertools import groupby
n,p=map(int,input().split())
s=[int(i) for i in input()]
if p==2 or p==5:
    ans=0
    for i in range(n-1,-1,-1):
        #Rとなるもの
        if s[i]%p==0:
            ans+=(i+1)
    exit(print(ans))
S=[0]*(n+1)
po=[1]*(n+1)
for i in range(n):
    po[i+1]=po[i]*10
    po[i+1]%=p
for i in range(n-1,-1,-1):
    S[i]=S[i+1]+s[i]*po[n-1-i]
    S[i]%=p
t=[[S[i],i] for i in range(n+1)]
t.sort()
#[L,R)となるのの候補
u=[[i[1] for i in sorted(list(group))] for key,group in groupby(t,key=lambda x: x[0])]
ans=0
for v in u:
    ans+=(len(v))*(len(v)-1)//2
print(ans)

Measured memory_bytes: 120036
def fLIP(N,M,K):
  for l in range(N+1):
    for k in range(M+1):
      P=l*(M-k)+k*(N-l)
      if P==K:
        return "Yes"
  return "No"

n,m,k=map(int,input().split())
print(fLIP(n,m,k))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    vector<int> D(N);
    D = A;
    sort(A.begin(), A.end());

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

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int a[21],b[21],c[21];
	int i;
	int sum;
	cin>>n;
	for(i=0;i<n;i++)	cin>>a[i];
	for(i=1;i<=n;i++)	cin>>b[i];
	for(i=1;i<n;i++)	cin>>c[i];
	sum=0;
	for(i=0;i<n;i++){
		sum+=b[a[i]];
		if(i+1<n){
			if(a[i]+1==a[i+1]){
				sum+=c[a[i]];
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let r: usize = sc.read();
    let d: usize = sc.read();
    let mut x: usize = sc.read();
    for _ in 0..10 {
        x = r * x - d;
        println!("{}", x);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define MAX 500500
char ch[MAX];
int a[MAX<<1],n,s;
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);
	for(int i=n;i;--i)a[i]=(ch[n-i+1]-48)*9;
	for(int i=1;i<=n;++i)a[i+1]+=a[i]/10,a[i]%=10;
	if(a[n+1])++n;
	for(int i=1;i<=n;++i)s+=a[i];
	for(int i=1;i<=n*9;++i)
	{
		a[1]+=9;int p=1;s+=9;
		while(a[p]>=10)
		{
			s-=a[p+1];a[p+1]+=a[p]/10;s+=a[p+1];
			s-=a[p];a[p]%=10;s+=a[p];
			++p;if(p>n)n=p;
		}
		if(s<=i*9){printf("%d\n",i);return 0;}
	}
	return 0;
}


Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int main(){
  int a, b, c, d, ans = 0;

  cin>>a>>b>>c>>d;

  ans += (a < b) ? a : b;
  ans += (c < d) ? c : d;

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

typedef struct quick_find {
  i32 *id;
  i32 **elem;
  i32 *size;
  i32 *max_size;
  i32 num;
} quick_find;

quick_find* new_quick_find (const i32 n) {
  quick_find *q = (quick_find *) calloc (1, sizeof (quick_find));
  q->id = (i32 *) calloc (n, sizeof (i32));
  q->elem = (i32 **) calloc (n, sizeof (i32 *));
  q->size = (i32 *) calloc (n, sizeof (i32));
  q->max_size = (i32 *) calloc (n, sizeof (i32));
  q->num = n;
  for (i32 i = 0; i < n; ++i) {
    q->id[i] = i;
    q->elem[i] = (i32 *) calloc (1, sizeof (i32));
    q->elem[i][0] = i;
    q->size[i] = 1;
    q->max_size[i] = 1;
  }
  return q;
}

i32 get_id (quick_find *q, i32 x) {
  return q->id[x];
}

i32 get_size (quick_find *q, i32 x) {
  return q->size[get_id (q, x)];
}

int same (quick_find *q, i32 x, i32 y) {
  return get_id (q, x) == get_id (q, y);
}

void unite (quick_find *q, i32 x, i32 y) {
  x = get_id (q, x);
  y = get_id (q, y);
  if (x == y) {
    return;
  }
  if (q->size[x] < q->size[y]) {
    i32 s = x;
    x = y;
    y = s;
  }
  if (q->max_size[x] < q->size[x] + q->size[y]) {
    q->max_size[x] *= 2;
    q->elem[x] = realloc (q->elem[x], sizeof (i32) * q->max_size[x]);
  }
  for (i32 i = 0; i < q->size[y]; ++i) {
    i32 v = q->elem[y][i];
    q->id[v] = x;
    q->elem[x][q->size[x]++] = v;
  }
  free (q->elem[y]);
  q->elem[y] = NULL;
  q->size[y] = 0;
}

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

int cmp (const void *a, const void *b) {
  i64 d = *(const i64 *)a - *(const i64 *)b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n = read_int();
  i32 m = read_int();
  i64 *e = (i64 *) calloc (m, sizeof (i64));
  for (i32 i = 0; i < m; ++i) {
    i32 a = read_int() - 1;
    i32 b = read_int() - 1;
    i32 c = read_int();
    e[i] = ((i64)c << 30) + a * n + b;
  }
  qsort (e, m, sizeof (i64), cmp);
  i32 *ans = (i32 *) calloc (n * n, sizeof (i32));
  i64 sum = 0;
  quick_find *q = new_quick_find (n);
  for (i32 i = 0; i < m; ++i) {
    i32 a = (e[i] & ((1 << 30) - 1)) / n;
    i32 b = (e[i] & ((1 << 30) - 1)) % n;
    if (same (q, a, b)) continue;
    a = get_id (q, a);
    b = get_id (q, b);
    i32 c = e[i] >> 30;
    sum += c;
    for (i32 j = 0; j < q->size[a]; ++j) {
      i32 s = q->elem[a][j];
      for (i32 k = 0; k < q->size[b]; ++k) {
        i32 t = q->elem[b][k];
        ans[s * n + t] = ans[t * n + s] = c;
      }
    }
    unite (q, a, b);
  }
  i32 iter = read_int();
  while (iter--) {
    i32 s = read_int() - 1;
    i32 t = read_int() - 1;
    print_int (sum - ans[s * n + t]);
    putchar ('\n');
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 67268
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
int n,t1,t2;
struct node
{
    int x,id;
}a[N],b[N];
bool cmp1(node a,node b)
{
    return a.x>b.x;
}
bool cmp2(node a,node b)
{
    return a.x<b.x;
}
bool vis[N];
int disa(int x,int y)
{
    return max(y-x,0);
}
int disb(int x,int y)
{
    return max(x-y,0);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&a[i].x,&b[i].x);
        a[i].id=b[i].id=i;
    }
    sort(a+1,a+1+n,cmp1);
    sort(b+1,b+1+n,cmp2);
    int now=0;
    ll ans=0;
    t1=t2=1;
    for(int i=1;i<=n;i++)
    {
        while(t1<=n&&vis[a[t1].id]) t1++;
        while(t2<=n&&vis[b[t2].id]) t2++;
        if(i&1)
        {
            ans+=disa(now,a[t1].x);
            if(disa(now,a[t1].x)) now=a[t1].x;
            vis[a[t1].id]=true;
        }
        else
        {
            ans+=disb(now,b[t2].x);
            if(disb(now,b[t2].x)) now=b[t2].x;
            vis[b[t2].id]=true;
        }
    }
    ans+=abs(now);
    ll res=0;
    memset(vis,false,sizeof(vis));
    t1=t2=1;
    now=0;
    for(int i=1;i<=n;i++)
    {
        while(t1<=n&&vis[a[t1].id]) t1++;
        while(t2<=n&&vis[b[t2].id]) t2++;
        if((i&1)^1)
        {
            res+=disa(now,a[t1].x);
            if(disa(now,a[t1].x)) now=a[t1].x;
            vis[a[t1].id]=true;
        }
        else
        {
            res+=disb(now,b[t2].x);
            if(disb(now,b[t2].x)) now=b[t2].x;
            vis[b[t2].id]=true;
        }
    }
    res+=abs(now);
    printf("%lld\n",max(ans,res));
}


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

using namespace std;
#define ll long long

int w, h, k;
ll calc(int w, int h, int o){
	ll ans=0;
	for(int x=1; x<w; ++x) for(int z=o; x*z<=k*2-2+w && z<=h-2; ++z){
		int R=k*2-2+__gcd(w, z)-x*z;
		if(R<0) continue;
		ans+=min(R/w, h-z-1);
		int y=R/w+1;
		if(y+z<h) ans+=(w*y-__gcd(x, y)-__gcd(w-x, y+z)<=R);
	}
	return ans;
}
int main() {
	scanf("%d%d%d", &w, &h, &k);
	printf("%lld\n", (calc(w, h, 0)+calc(w, h, 1)+calc(h, w, 0)+calc(h, w, 1))*2);
	return 0;
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int a, b, c;
 cin>>a>>b>>c;
 
 if(a > b) swap(a, b);
 if(b > c) swap(b, c);
 if(a > b) swap(a, b);
 
cout<<a<<" "<<b<<" "<<c<<endl;
 return 0;
}
 


Measured memory_bytes: 3092
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N, A, B, C = map(int, raw_input().split())
l = [int(input()) for i in range(N)]

ans = 10 ** 12

for i in range(4 ** N):
  S = [0, 0, 0, 0]
  hoge = i
  cost = -30
  for j in range(N):
    S[hoge % 4] += l[j]
    if hoge % 4 < 3:
      cost += 10
    hoge /= 4
  if S[0] * S[1] * S[2] == 0:
    continue
  ans = min(ans, cost + abs(S[0] - A) + abs(S[1] - B) + abs(S[2] - C))

print ans

Measured memory_bytes: 4856
import java.util.*;

public class Main{
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int t=sc.nextInt();
		int a=sc.nextInt();
		int h[]=new int[n];
		for(int i=0;i<n;i++){
			h[i]=sc.nextInt();
		}
		double min=10000;
		int ans=0;

		for(int i=0;i<n;i++){
			if(min>=Math.abs(a-t+h[i]*0.006)){
				min=Math.abs(a-t+h[i]*0.006);
				ans=i+1;
			}
		}

		System.out.println(ans);


	}
}


Measured memory_bytes: 23376
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC110(void);
void ABC111(void);
void ABC112(void);
void ABC113(void);
void ABC114(void);
void ABC115(void);
void ABC116(void);
void ABC117(void);
void ABC118(void);
void ABC119(void);

int main(void){
    ABC113();
}

void ABC113(){
    int n,t,a,i,ans,h;
    double x,min;
    cin>>n>>t>>a;
    for(i=0;i<n;i++){
        cin>>h;
        x=abs(t-(double)h*0.006-a);
        if(i==0){
            min=x;
            ans=1;
        }
        if(x<min){
            min=x;
            ans=i+1;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
m, k = map(int, input().split())

if m == 0:
    if k == 0:
        print('0 0')
    else:
        print('-1')
elif m == 1:
    if k == 0:
        print('0 0 1 1')
    elif k >= 1:
        print('-1')
else:
    if k < 2 ** m:
        l = list(range(2 ** m))
        l.pop(k)
        ans = l + [k] + l[::-1] + [k]
        print(' '.join(map(str, ans)))
    else:
        print(-1)



Measured memory_bytes: 28392
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back

bool compare(string a,string b){
    return ((a+b)<(b+a));
}
 
int main(){
	fast;
	int n, l;
	cin>>n>>l;
	vector<string> s(n);
	for(int i=0; i<n; i++){
	    cin>>s[i];
	}
	sort(s.begin(), s.end(), compare);
	string ans;
	for(int i=0; i<n; i++){
	    ans+=s[i];
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  vector<int> data(3), dual(3, 0);
  int count = 0;
  for(int i = 0; i < 3; i++) {
    cin >> data.at(i);
    if(data.at(i) % 2 == 1) count++;
  }
  sort(data.begin(), data.end());
  for(int i = 0; i < 3; i++) {
    if(data.at(i) % 2 == 1) dual.at(i)++;
  }
  if(count == 3 || count == 0) {
    cout << data.at(2) - (data.at(1) + data.at(0)) / 2 << endl;
  } else if (count == 1) {
    for(int i = 0; i < 3; i++) {
      if(dual.at(i) == 0) data.at(i)++;
    }
    cout << data.at(2) - (data.at(1) + data.at(0)) / 2 + 1<< endl;
  } else if (count == 2) {
    for(int i = 0; i < 3; i++) {
      if(dual.at(i) == 1) data.at(i)++;
    }
    cout << data.at(2) - (data.at(1) + data.at(0)) / 2 + 1<< endl;
  }
  return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    foreach(int i; 0..7) {
        int[] input = readln.split.to!(int[]);
        writeln(input[0]-input[1]);
    }
}

Measured memory_bytes: 2484
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,a,b,c,d,ans=0;
	cin>>a>>b>>c;
	for(i=0;i<a;i++)
	{
	 cin>>d;
	 if(d<b || d>=c)
	  ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
// 解説前
#include <iostream>
#include <iomanip>

int solve_B() {
  int N;
  std::cin >> N;

  double denom = 0.0;
  for (int i = 0; i < N; ++i) {
    int A;
    std::cin >> A;
    denom += 1.0 / A;
  }

  std::cout << std::setprecision(20) << (1.0 / denom);

  return 0;
}

int main() {
  return solve_B();
}


Measured memory_bytes: 256
# ABC131 C
from fractions import gcd
a,b,c,d=map(int,input().split())
lcm=c*d//gcd(c,d)
c_n=b//c-(a-1)//c
d_n=b//d-(a-1)//d
lcm_n=b//lcm-(a-1)//lcm
print(int(b-a+1-c_n-d_n+lcm_n))

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

int main() {
    long long N;
    long long trans[5];
    long long min_trans;
    long long time;
    cin >> N;
    for (int i = 0; i < 5; ++i) {
        cin >> trans[i];
    }

    min_trans = N;
    for (int i = 0 ; i < 5; ++i) {
        min_trans = min(min_trans, trans[i]);
    }

    time = 4 + N / min_trans;
    if (N % min_trans != 0) time++;
    cout << time << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#include <cmath>

#define int long long

using namespace std;

vector<int> tree;
vector<int> G[200001];

void dfs(int node, int cum) {
  tree[node] += cum;

  for (auto v : G[node]) {
    dfs(v, tree[node]);
  }
}

signed main() {
  int n, q;
  cin >> n >> q;

  tree.resize(n + 1);

  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
  }

  vector<int> p(q);
  vector<int> x(q);

  for (int i = 0; i < q; i++) {
    cin >> p[i] >> x[i];
    tree[p[i]] += x[i];
  }

  dfs(1, 0);

  for (int i = 1; i <= n; i++) {
    cout << tree[i] << " \n"[i==n];
  }

  return 0;
}


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

int gcd(int x, int y)
{
    if(x < y)   swap(x, y);
    if(y == 0)  return x;

    return gcd(x % y, y);
}

int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> h(N);
    rep(i, N){
        int a;
        cin >> a;
        h[i] = abs(X-a);
    }
    for(int i = 1; i < N; i++){
        h[i] = gcd(h[i-1], h[i]);
    }
    cout << h[N-1] << endl;
    return 0;
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int n;

intt sum (int n) {
	return 1LL * n * (n + 1) / 2;
}

int main() {

	FAST;

	cin >> n;
	intt ans = 0;
	for (int i = 1; i <= n; i ++) {
		int m = n / i;
		ans += 1LL * i * sum(m);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
 
int main() {
  int a, b, c, five_counter = 0, seven_counter = 0;
  cin >> a >> b >> c;
  int list[3] = {a,b,c};
  for(int i:list) {
    switch(i){
      case 5:
        five_counter++;
        break;
      case 7:
        seven_counter++;
        break;
    }
  }
  if(2 == five_counter && 1 == seven_counter) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

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

int main()
{
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int k, p;

		cin >> k >> p;

		if (k % p == 0)
			cout << p << endl;
		else
			cout << k % p << endl;
	}

	return 0;
}


Measured memory_bytes: 3100
import std.stdio,std.conv,std.string;

void main(){

	int D,N;
	auto DN = readArray!int();
	D = DN[0];
	N = DN[1];
	
	if( N == 100 ){
		(100^^D*101).writeln();
	}else{
		(100^^D*N).writeln();
	}
}

T[] readArray(T)(){
	T[] ret;
	foreach( elm ; readln().split() ){
		ret ~= elm.to!T();
	}
	return ret;
}

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

int main() {
    int n, m, s, t, length = 0;
    cin >> n >> m;
    vector<int> graph[3 * n + 1];
    for (int i = 0, u, v; i < m; i++) {
        cin >> u >> v;
        graph[u].emplace_back(v + n);
        graph[u + n].emplace_back(v + 2 * n);
        graph[u + 2 * n].emplace_back(v);
    }
    cin >> s >> t;
    queue<int> queue;
    queue.emplace(s);
    vector<bool> visited(3 * n + 1);
    visited[s] = true;
    do {
        for (auto size = queue.size(); size > 0; size--) {
            auto front = queue.front();
            if (front == t) {
                cout << length / 3;
                return 0;
            }
            queue.pop();
            for (auto i : graph[front]) {
                if (!visited[i]) {
                    visited[i] = true;
                    queue.emplace(i);
                }
            }
        }
        length++;
    } while (!queue.empty());
    cout << -1;
    return 0;
}


Measured memory_bytes: 16640
import sys
input = sys.stdin.readline

#input
N = int(input())

#output
import math
M = int(math.sqrt(N))

ans = N
for i in reversed(range(1, M+1)):
    if float.is_integer(N/i):
        a = i
        b = int(N/i)
        c = a + b -2
        ans = min(ans, c)
        
print(ans)

Measured memory_bytes: 40940
#include <iostream>

using namespace std;

int main()
{

    char c; cin >> c;

    switch(c)
    {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
        cout << "vowel" << endl;
        break;
    default:
        cout << "consonant" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;


int main() {
    ll S,W;
    cin>>S>>W;
    if(S<=W){cout<<"unsafe"<<endl;}
    else{cout<<"safe"<<endl;}
}


Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define sz(s) (int) s.size()
#define pb push_back
#define rc(x) return cout<<x<<"\n",0

using namespace std;
    int solve()
    {
      string s;
      cin >> s;
      if (s == "ABC")
        cout << "ARC";
      else
        cout << "ABC";
      return 0;
               
}
    int main()
    {
        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        int t=1;
       //cin>>t;
        while(t--)
        {
            solve();
        }
    }

Measured memory_bytes: 3580
#include <stdio.h>
#define MAX 250

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

int main(){
  int H,i,A[MAX+1],flag;

  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  for(i=1;i<=H;i++){
    flag=0;
    printf("node %d: key = %d, ",i,A[i]);

    if((flag=parent(i))>=1){
      printf("parent key = %d, ",A[flag]);
      flag=0;
    }
    if((flag=left(i))<=H){
      printf("left key = %d, ",A[flag]);
      flag=0;
    }
    if((flag=right(i))<=H){
      printf("right key = %d, ",A[flag]);
      flag=0;
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        String s = scn.nextLine();
        String ans = "ARC";

        if (s.equals(ans)) {
            System.out.println("ABC");
        } else {
            System.out.println(ans);
        }
        scn.close();
    }
}

Measured memory_bytes: 27004
n,k=map(int,input().split())
h=[int(i) for i in input().split()]

dp=[float('inf')]*n
dp[0]=0

for i in range(1,n):
    for j in range(k):
        if i-1-j<0:
            break
        dp[i]=min(dp[i],dp[i-1-j]+abs(h[i]-h[i-1-j]))
print(dp[-1])

Measured memory_bytes: 55008
#include<stdio.h>
#define n_max 100000

typedef struct{
  char name[10];
  int time;
}input;

int main(){
  int i=0,j=0,x,n,de,sum=0;
  input in[n_max];

  scanf("%d%d",&n,&de);
  for(i=0;i<n;i++){
    scanf("%s%d",&in[i].name,&in[i].time);
  }

  while(n>0){
    if(i==n_max-1)i=0;
    else if(j==n_max-1)j=0;
    if((x=in[j].time-de)>0){
      in[j].time=x;
      in[i]=in[j];
      sum+=de;
      i++;
      j++;
    }
    
    else if(in[j].time-de<=0){
      sum+=in[j].time;
      printf("%s %d\n",in[j].name,sum);
      j++;
      n--;
    }
  }
  
  return 0;
}



Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 4000 + 10;
int n;
ll ans;
char s[maxn];
ll cnt[maxn][3];
int main()
{
	scanf("%d%s", &n, s + 1);
	for(int i = 1; i <= n; ++i) 
	{
		for(int j = 0; j <= 2; ++j) cnt[i][j] = cnt[i - 1][j];
		if(s[i] == 'R') ++cnt[i][0];
		else if(s[i] == 'G') ++cnt[i][1];
		else ++cnt[i][2];
	}
	for(int i = 2; i < n; ++i)
	{
		if(s[i] == 'R') ans += cnt[i - 1][1] * (cnt[n][2] - cnt[i][2]) + cnt[i - 1][2] * (cnt[n][1] - cnt[i][1]);
		else if(s[i] == 'G') ans += cnt[i - 1][0] * (cnt[n][2] - cnt[i][2]) + cnt[i - 1][2] * (cnt[n][0] - cnt[i][0]);
		else ans += cnt[i - 1][1] * (cnt[n][0] - cnt[i][0]) + cnt[i - 1][0] * (cnt[n][1] - cnt[i][1]);
	}
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; 2 * j - i <= n; ++j)
		{
			int k = 2 * j - i;
			if(s[i] != s[j] && s[i] != s[k] && s[j] != s[k])
				--ans;
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int N;
  int a[200000];

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

  sort(a, a+N);

  ll x[2];
  int y = 0;
  for(int i = N-1; i > 0; i--){
    if(y == 2)  break;
    if(a[i] == a[i-1]){
      x[y] = a[i];
      i--;
      y++;
    }
  }

  if(y == 2){
    cout << x[0] * x[1] << endl;
  }
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    string s;
    cin>>n>>s;
    lli i,j,ans=0,a[n]={0},b[n]={0},c[n]={0};
    
    for(i=n-1;i>=0;i--)
    {
        if(s[i]=='R') a[i]++;
        if(s[i]=='G') b[i]++;
        if(s[i]=='B') c[i]++;
        
        if(i!=n-1)
        {
            a[i]+=a[i+1];
            b[i]+=b[i+1];
            c[i]+=c[i+1];
        }
    }
    
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n-1;j++)
        {
            if((s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R'))
            {
                ans+=(c[j+1]);
                if((2*j-i)<n)
                {
                    if(s[(2*j-i)]=='B')
                    ans--;
                }
            }
            else if((s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R'))
            {
                ans+=(b[j+1]);
                if((2*j-i)<n)
                {
                    if(s[(2*j-i)]=='G')
                    ans--;
                }
            }
            else if((s[i]=='B' && s[j]=='G') || (s[i]=='G' && s[j]=='B'))
            {
                ans+=(a[j+1]);
                if((2*j-i)<n)
                {
                    if(s[(2*j-i)]=='R')
                    ans--;
                }
            }
        }
    }
    cout<<ans;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    int max_sa =max(A.at(1) - A.at(0), A.at(0) - A.at(1));
    for (int i = 2; i < N; i++){
        for (int j = 0; j < i; j++){
            max_sa = max(max_sa,max(A.at(i) - A.at(j), A.at(j) - A.at(i)));
        }
    }
    cout << max_sa << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
#define N 1000000
  
int n, l,s,t;
int A[N];
int S[N];
int deq[N];
  
void sme(int i){
  int ith;
  
  while(A[deq[t-1]] >= A[i] && s < t ) t--;
  deq[t++] = i;
  ith = i-l+1;
  
  if (ith >= 0){
    S[ith]= A[deq[s]];
    if (deq[s] == ith) s++;
  }
}

int main(){
  int i;
  cin >> n >> l;
  for (i=0;i<n;i++)cin >> A[i];
  for (i=0;i<n;i++)sme(i);
  for (i=0;i<=n-l;i++){
    if (i != 0) cout << " ";
    cout << to_string(S[i]);
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 14904
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto route = new Pair[](n);
    foreach (ref e; route)
    {
        long x, y;
        scan(x, y);
        e = Pair(x, y);
    }

    real s = 0;
    auto iter = iota(n).array();
    do
    {
        foreach (i; iota(n - 1))
        {
            s += sqrt((abs(route[iter[i]].x - route[iter[i + 1]].x) ^^ 2 + abs(
                    route[iter[i]].y - route[iter[i + 1]].y) ^^ 2).to!real);
        }
    }
    while (iter.nextPermutation());
    // n.product.writeln();
    writefln("%.15s", cast(real) s / n.product());
}

long product(long t)
{
    if (t == 1)
        return 1;
    else
        return t * product(t - 1);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int ask(LL p)
{
    cout << "? " << p << endl;
    cout.flush();
    string s;
    cin >> s;
    if (s[0] == 'Y') return 1; else return 0;
}
void put(LL p)
{
    cout << "! " << p << endl;
    cout.flush();
    exit(0);
}
int main()
{
    if (ask(1000000000))
    {
        for (LL i = 1; ; i *= 10)
            if (ask(i * 2)) put(i);
    }
    else
    {
        for (LL i = 100000000; i >= 1; i /= 10)
            if (ask(i))
            {
                LL l = i + 1, r = i * 10 - 1;
                while (l < r)
                {
                    LL md = (l + r) / 2;
                    if (ask(md * 10 + 9)) r = md;
                    else l = md + 1;
                }
                put(l);
            }
    }
}


Measured memory_bytes: 724
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define s(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;
int main() {
	int a, b, ans = 1000, abc = 0;
	cin >> a >> b;
	vector<int> str(a);
	rep(i, a) {
		cin >> str[i];
		abc += str[i];
		ans = min(ans, str[i]);
	}
	cout << a + (b-abc) / ans << endl;
	return 0;
}



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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -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 (b < a) { a = b; return 1;} return 0;}

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong n, k;
    cin >> n >> k;
    vector<llong> A(n), Cum(n + 1);
    Cum[0] = 0;
    rep(i, n) {
        cin >> A[i];
        Cum[i + 1] = Cum[i] + A[i];
    }

    vector<llong> P;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n + 1; ++j) {
            P.push_back(Cum[j] - Cum[i]);
        }
    }
    sort(allr(P));

    vector<llong> cur = P;
    for (llong bit = 58; bit >= 0; --bit) {
        vector<llong> tmp;
        for (int e = 0; e < cur.size(); ++e) {
            if (cur[e] & (1LL << bit)) tmp.push_back(cur[e]);
        }
        if (tmp.size() >= k) cur = tmp;
    }

    llong res = -1;
    
    rep(i, k) {
        res &= cur[i];
    }

    cout << res << endl;

    return 0;
}



Measured memory_bytes: 10092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
#define FRO freopen("in.txt","r",stdin);


int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        int n,i,j,t,tcs=0,k,m,u,v;

        string str;
        cin>>n>>str>>k; k--;
        for(i=0;i<n;i++)
        {
                if(str[i]!=str[k]) str[i]='*';
        }
        cout<<str;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#define INF -3

using namespace std;
typedef long long ll;

queue<pair<int, int>> que;
pair<int, int> s, e;

int Search(pair<int, int> n, map<pair<int, int>, vector<pair<int, int>>> &nx, map<pair<int, int>, int> &d) {
	if (n == e)
		return d[n];
	for (int i = 0; i < nx[n].size(); i++) {
		if (d[nx[n][i]] == INF) {
			d[nx[n][i]] = d[n] + 1;
			que.push(nx[n][i]);
		}
	}
	if (que.empty())
		return INF;
	n = que.front();
	que.pop();
	return Search(n, nx, d);
}

int main(void) {
	int num, edg, i, a, b;
	cin >> num >> edg;
	map<pair<int, int>, vector<pair<int, int>>> mp;
	map<pair<int, int>, int> d;
	for (i = 1; i <= num; i++) {
		d[make_pair(i, 0)] = INF;
		d[make_pair(i, 1)] = INF;
		d[make_pair(i, 2)] = INF;
	}
	for (i = 0; i < edg; i++) {
		scanf("%d%d", &a, &b);
		mp[make_pair(a, 0)].push_back(make_pair(b, 1));
		mp[make_pair(a, 1)].push_back(make_pair(b, 2));
		mp[make_pair(a, 2)].push_back(make_pair(b, 0));
	}
	cin >> s.first >> e.first;
	s.second = 0;
	e.second = 0;
	d[s] = 0;
	a = Search(s, mp, d);
	printf("%d\n", a / 3);
	return 0;
}

Measured memory_bytes: 51840
#include "stdio.h"
  
int main(){
  int n,d[51],a=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){scanf("%d",&d[i]);}
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      a+=d[i]*d[j];
    }
  }
  printf("%d",a);
  return 0;
}

Measured memory_bytes: 128
def main():
    s = input()
    t = input()

    ans = 0
    for a, b in zip(s, t):
        if a != b:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9348
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))

isAffectedSwitch=[[False for _ in range(n)] for _ in range(m)]
for i in range(m):
    for j in range(1,s[i][0]+1):
        isAffectedSwitch[i][s[i][j]-1]=True
# print(isAffectedSwitch)
onoff=[[(i%(2**(n-j)))>>(n-j-1) for j in range(n)]for i in range(2**n)]
# print(onoff)
ans=0
for i in range(2**n):
    cnt=[0 for _ in range(m)]
    for j in range(n):
        for k in range(m):
            if onoff[i][j]==1:
                if isAffectedSwitch[k][j]==True:
                    cnt[k]+=1
    isOK=True
    for k in range(m):
        if cnt[k]%2!=p[k]:
            isOK=False
    if isOK:
        ans+=1
print(ans)


Measured memory_bytes: 3188
from collections import Counter


N = int(input())
D = list(map(int, input().split()))
p = 998244353
count = Counter(D)

if D[0] != 0 or len(set(D)) != max(D) + 1 or count[0] > 1:
    ans = 0
else:
    count = sorted(count.items(), key=lambda x: x[0])
    ans = 1
    for i in range(len(count) - 1):
        x = count[i][1]
        y = count[i + 1][1]
        ans *= x ** y
        ans %= p

print(ans)

Measured memory_bytes: 27924
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	int tmp,cnt=0;
	rep(i, n) {
		cin >> tmp;
		if (tmp >= k) {
			cnt++;
		}
	}

	cout << cnt;

}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        for (int i = 0; i < hw[0]; i++)
        {
            string s = Console.ReadLine();
            Console.WriteLine($"{s}\n{s}");
        }
    }
}

Measured memory_bytes: 13396
def solve():
    N = int(input())
    a = [int(x) for x in input().split()]

    N4 = sum(map(lambda x: x%4==0, a))
    N2 = sum(map(lambda x: x%2==0 and x%4!=0, a))
    N1 = sum(map(lambda x: x%2!=0, a))
    assert N1+N2+N4==N

    return N1 <= N4 or (N4==N1-1 and N2==0)


def main():
    ans = solve()
    if ans:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 14252
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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 (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

int main() {
  ll n,x,sum=0,mi=1e9,cnt=0;
  cin>>n;
  
  rep(i,n){
    cin>>x;
    if(x<0) cnt++;
    chmin(mi,abs(x));
    sum+=abs(x);
  }
  
  if(cnt%2==0) cout << sum <<endl;
  else cout<< sum-2*mi <<endl;
  
  return 0;
}

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

void trace(int A[],int N){
  for(int i=0;i<N;i++){
    if(i>0)
      printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int A[],int N){
  int i,j,v;

  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    trace(A,N);
  }
}


  int main(void){
    int A[1000];
    int N;

    scanf("%d",&N);
    for(int i=0;i<N;i++)scanf("%d",&A[i]);

    trace(A,N);
    insertionSort(A,N);

    return 0;
  }
  
  
    

Measured memory_bytes: 3216
#include<iostream>
#include<fstream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr)
int main()
{
        fast;
        int t=1;
        //cin>>t;
        while(t--)
        {
                int n,k;
                cin>>n>>k;
                int c1=0,c2=0;
                ll ans=0;
                for(int i=1;i<=n;i++)
                {
                        if(k%2==0)//even
                        {
                             if(i%k==0)
                                        c1++;
                             else if(i%k==k/2)
                                        c2++;
                        }
                        else
                        {
                                if(i%k==0)
                                c1++;
                        }
                }

                if(k%2==0)
                        ans=(pow(c1,2)*c1)+(pow(c2,2)*c2);


                else
                        ans=(pow(c1,2))*c1;

                      cout<<ans<<endl;

        }
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int N,m;
	cin >> N >> m;
	int all[N];
	for (int i =0; i < N; i++){
		all[i] = 0;
	}
	for (int i = 0; i < m*2; i++){
		int t;
		cin >> t;
		all[t-1]++;
	}
	for (int i = 0; i < N ; i++){
		cout << all[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())

astr = ''
bstr = ''

for i in range(b):
    astr += str(a)

for i in range(a):
    bstr += str(b)

if astr > bstr:
    print(bstr)
elif astr < bstr:
    print(astr)
else:
    print(astr)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  
  for (int i = 0; i < n; i++) {
	cin >> a[i];
    sum += ((-2)*(i%2)+1)*a[i];
  }
  
  long long y = sum; //y1 = a1 - a2 + a3 ... + an

  cout << y;
  for (int i = 0; i < n - 1; i++) {
    y = a[i] * 2 - y; //2*ai - yi = y(i+1) + yi - yi = y(i+1)
    cout << " " << y;
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 2048
package main

import (
	"bufio"
	"fmt"
	"os"
)

var h, w, n int
var blocks map[int]int

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d %d", &h, &w, &n)

	blocks = make(map[int]int)

	for ; n > 0; n-- {
		var x, y int
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &x, &y)
		if yy, e := blocks[x]; e {
			if y < yy {
				blocks[x] = y
			}
		} else {
			blocks[x] = y
		}
	}

	right := 1
	for i := 1; i <= h; i++ {
		if v, e := blocks[i+1]; e {
			if v <= right {
				fmt.Println(i)
				return
			}
			if right+1 < v {
				right++
			}
		} else {
			right++
		}
	}
	fmt.Println(h)
}


Measured memory_bytes: 13312
//
// Created by yamunaku on 2019/11/23.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int n;
    cin >> n;
    ll sum = 0;
    vl a(n);
    rep(i, n) cin >> a[i], sum += a[i];
    ll tmp =0;
    ll ans=LINF;
    rep(i,n){
        ans = min(ans,abs(sum-2*tmp));
        tmp+=a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int n, q, p[20009], a[20009], b[20009];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> q, p[q - 1] = i + 1;
	a[0] = 0, b[0] = p[0];
	for (int i = 1; i < n; i++) {
		if (p[i - 1] > p[i]) {
			a[i] = a[i - 1] + 1;
			b[i] = p[i] - a[i];
		}
		else {
			b[i] = b[i - 1] - 1;
			a[i] = p[i] - b[i];
		}
	}
	int ar = *min_element(a, a + n) * -1 + 1;
	int br = *min_element(b, b + n) * -1 + 1;
	if (ar > 0) {
		for (int i = 0; i < n; i++) a[i] += ar;
	}
	if (br > 0) {
		for (int i = 0; i < n; i++) b[i] += br;
	}
	for (int i = 0; i < n; i++) {
		if (i) cout << ' ';
		cout << a[i];
	}
	cout << endl;
	for (int i = 0; i < n; i++) {
		if (i) cout << ' ';
		cout << b[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,L=1,R=INF+1,ans=0;
	cin>>n;
	vector<Pi> g(n);
	rep(i,n){
		cin>>g[i].fi>>g[i].se;
		g[i].se++;
		chmax(L,g[i].fi);
		chmin(R,g[i].se);
		chmax(ans,g[i].se-g[i].fi);
	}
	ans+=max(R-L,0);
	vector<Pi> a(n);
	rep(i,n){
		a[i].fi=max(R-g[i].fi,0);
		a[i].se=max(g[i].se-L,0);
	}
	sort(begin(a),end(a),[](const Pi &a,const Pi &b){
		if(a.fi!=b.fi) return a.fi<b.fi;
		else return a.se>b.se;
	});
	int ma=INF;
	rep(i,n){
		if(i==0){
			chmin(ma,a[i].se);
			continue;
		}
		chmax(ans,a[i].fi+ma);
		chmin(ma,a[i].se);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    var lines = chunk.toString().split(' ');
    var place = parseInt(lines[0]);
    var color = parseInt(lines[1]);
    
    var ans = color * Math.pow((color - 1),place - 1)
        console.log(ans);
});

Measured memory_bytes: 7500
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
py = [list(map(int,input().split()))for i in range(m)]
pypy = py[::]
from operator import itemgetter
import bisect
py.sort(key = itemgetter(1))
dic = {}
for i in range(m):
    if py[i][0] not in dic:
        dic[py[i][0]] = []
    dic[py[i][0]].append(py[i][1])


anslist = [0]*m

for i in range(m):
    anslist[i] = str(pypy[i][0]).zfill(6) + str(bisect.bisect_left(dic[pypy[i][0]],pypy[i][1]) + 1).zfill(6)

for ans in anslist:
    print(ans)



Measured memory_bytes: 49200
#include <stdio.h>

int main(){
  char str[4];
  scanf("%s", str);
  
  int cont = 0;
  
  if (str[0] == 'R' && str[1] == 'R' && str[2] == 'R')
    printf("3\n");
  else if (str[0] == 'R' && str[1] == 'R')
    printf("2\n");
  
  else if (str[1] == 'R' && str[2] == 'R')
    printf("2\n");
  
  else if (str[1] == 'R' || str[2] == 'R' ||str[0] == 'R')
    printf("1\n");
  else if(str[0] != 'R' && str[1] != 'R' && str[2] != 'R')
    printf("0\n");

  return 0;
}

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

using namespace std;

int makecombi(int i, int n, vector<int> &s, vector<vector<int>> &ss, int &counter) {

	if (i == n) {
		for (int j = 0; j < n; j++) {
//			cout << s[j];
			ss[counter][j] = s[j];
		}
//		cout << endl;
		counter++;
		return 0;
	}

	makecombi(i + 1, n, s, ss, counter);
	s[i] = 1;
	makecombi(i + 1, n, s, ss, counter);
	s[i] = 0;
	return 0;
}

int main() {
	
	int n, m, x;
	cin >> n >> m >> x;

	//組み合わせ作り
	vector<int> s(n, 0);
	vector<vector<int>> ss(pow(2, n), vector<int>(n, 0)); //組み合わせは2^n個ある
	int counter = 0;;

	makecombi(0, n, s, ss, counter);

	for (int i = 0; i < counter; i++) {
		for (int j = 0; j < n; j++) {
//			cout << ss[i][j];
		}
//		cout << endl;
	}

	vector<int> c(n + 1);
	vector<vector<int>> a(n + 1, vector<int>(m + 1));
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}

	int minn = 10000000;
	for (int i = 0; i < counter; i++) {
		int sum = 0;
		vector<int> xx(m + 1,0);
		for (int j = 0; j < n; j++) {
			if (ss[i][j] == 1) {
				sum += c[j + 1];
				for (int k = 1; k <= m; k++) {
					xx[k] += a[j+1][k];
				}
			}
		}
		for (int k = 1; k <= m; k++) {
			if (xx[k] < x) {
				break;
			}
			if (k == m) {
				minn = min(minn, sum);
			}
		}
	}

	cout << (minn==10000000? -1 : minn) << endl;

	return 0;
}

Measured memory_bytes: 4464
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
t=list(reversed(t))
r_p, p_p, s_p = 0, 0, 0
r_c, p_c, s_c = None, None, None
for i in range(len(t)):
    if t[i] == 'r':
        if r_c is None:
            r_c = i
        if i+k < len(t) and t[i+k] == 'r':
            t[i+k] = 'x' 
        r_p += p
        r_c = i
    if t[i] == 'p':
        if p_c is None:
            p_c = i
        if i+k < len(t) and  t[i+k] == 'p':
            t[i+k] = 'x' 
        p_p += s
        p_c = i
    if t[i] == 's':
        if s_c is None:
            s_c = i
        if i+k < len(t) and t[i+k] == 's':
            t[i+k] = 'x' 
        s_p += r
        s_c = i
    #print(i, r_p, p_p, s_p,  t[i])
#print(r_p, p_p, s_p)
print(r_p + p_p + s_p)
#print(list(reversed(t)))

Measured memory_bytes: 4084