akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <vector>
#include <iostream>
#include <math.h>
#include <string.h> //memset
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
using namespace std;
#define INF 1e9
#define MAX_V 1000
//辺の構造体
struct edge { int to, cap, rev; };
struct point{ int x, y; };

vector<edge> G[MAX_V];
bool used[MAX_V];

//from-to 容量capの辺を追加
void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, (int)G[to].size()});   //場所が被るごとに0,1,...がrevに入る
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

//増加パスをDFS
int dfs(int v, int t, int f) {
    if(v == t) return f;
    used[v] = true;
    for(int i = 0; i < (int)G[v].size(); i++) {
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f,e.cap));
            if(d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

//s-tの最大流
int max_flow(int s, int t) {
    int flow = 0;
    while(1) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f == 0) return flow;
        flow += f;
    }
}

signed main() {
    int n;
    cin >> n;
    rep(i,n) {
        //red
        add_edge(210, i, 1);
        //blue
        add_edge(i+100, 220, 1);
    }
    point red[n];
    point blue[n];
    rep(i,n) cin >> red[i].x >> red[i].y;
    rep(i,n) cin >> blue[i].x >> blue[i].y;
    rep(i,n) {
        rep(j,n) {
            if(red[i].x < blue[j].x && red[i].y < blue[j].y) {
                add_edge(i,j+100,1);
            }
        }
    }
    cout << max_flow(210,220) << endl;
    return 0;
}

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

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

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int nax = 2e5 + 100;

vector<int> g[nax];
ll holder[nax],cnt[nax];

void dfs(int u,int p,ll cur = 0){
	cur += holder[u];
	cnt[u] = cur;
	for(int v : g[u]){
		if(v == p)continue;
		dfs(v,u,cur);
	}	
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	int n,q;
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i=0;i<q;i++){
		int u,x;
		cin>>u>>x;
		holder[u] += x;
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
		cout << cnt[i] << ' ';
	cout << endl;
}

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
	return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

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

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

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

int l, r;
int ans = inf;
signed main() {
	cin >> l >> r;
	rep(i, 2019) {
		if (r <= i) break;
		for (int j = r; j > l + i; j--) {
			if (2019 < r - j) break;
			ans = min(ans, (l + i) * j % 2019);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def do_binary_search(target_value, target_list, target_list_length=None):
    left = 0
    right = target_list_length

    while right - left > 0:
        mid = (right + left) / 2
        key = target_list[mid]
        if key == target_value:
            return True
        elif target_value < key:
            right = mid
        else:
            left = mid + 1
    return False



def main():
    s_length = int(raw_input())
    s = [int(x) for x in raw_input().strip().split(' ')]
    t_length = raw_input()
    t = [int(x) for x in raw_input().strip().split(' ')]

    counter = 0
    for value in t:
        counter += int(do_binary_search(value, s, s_length))

    print counter 

if __name__ == '__main__':
    main()

Measured memory_bytes: 15040
#include<iostream>
using namespace std;
int main() {
	int n; cin >> n;
	int l = 0, r = 0;
	for (int i = 0; i < n; i++) {
		int q; char c;
		cin >> q >> c >> q;
		if (c == '(')l += q;
		else if (c == ')')r += q;
		if (l == r)puts("Yes");
		else puts("No");
	}
}

Measured memory_bytes: 3100
#include<iostream>
#include<set>

using namespace std;

int main(){

    while(1){
        int n;
        cin>> n;
        if(n==0) break;
        string f[n];
        for(int i=0; i<n; i++) cin>> f[i];

        int left, right;
        int up=1, down=0;
        left=right=down;
        int next=up;
        int cnt=0;
        for(int i=0; i<n; i++){
            if(f[i]=="lu"){
                if(right==up&&next==up) {cnt++; next=down;}
                left=up;
            }else if(f[i]=="ru"){
                if(left==up&&next==up) {cnt++; next=down;}
                right=up;
            }else if(f[i]=="ld"){
                if(right==down&&next==down) {cnt++; next=up;}
                left=down;
            }else if(f[i]=="rd"){
                if(left==down&&next==down) {cnt++; next=up;}
                right=down;
            }
        }
        cout<< cnt<< endl;
    }



    return 0;
}

Measured memory_bytes: 3020
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000009;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#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 long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

int par[100000];
int rank1[100000];
ll d[1 << 17];
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		rank1[i] = 0;
		d[i] = 0;
	}
}
pair<int,ll> find(int x) {
	if (par[x] == x) {
		return { x,0 };
	}
	else {
		d[x] += find(par[x]).second;
		par[x] = find(par[x]).first;
		return { par[x],d[x] };
	}
}
void unite(int x, int y,ll c) {
	ll mx = x, my = y;
	x = find(x).first;
	y = find(y).first;
	ll m1 = d[mx], m2 = d[my];
	if (x == y) {
		/*if (m2 - m1 != c) {
			cout << "?????!" << endl;
		}*/
		return;
	}
	if (rank1[x] < rank1[y]) {
		par[x] = y;
		d[x] = m2-m1- c;
	}
	else {
		par[y] = x;
		if (rank1[x] == rank1[y])rank1[x]++;
		d[y] = m1-m2 +c;
	}
}
bool same(int x, int y) {
	return find(x).first == find(y).first;
}
int main() {
	int n, m;
	while (cin >> n >> m, n) {
		init(n);
		rep(i, m) {
			char ord; cin >> ord;
			if (ord == '!') {
				int le, ri; ll z; cin >> le >> ri >> z; le--; ri--;
				unite(le, ri, z);
			}
			else {
				int le, ri; cin >> le >> ri; le--; ri--;
				if (!same(le, ri)) {
					cout << "UNKNOWN" << endl;
				}
				else {
					cout << d[ri] - d[le] << endl;
				}
			}
		}/*
		rep(i, n) {
			cout << d[i] << endl;
		}*/
	}
	
	return 0;
}


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

int main(){
    string S;
    cin >> S;
    int ans = INT_MAX;
    
    for(int i = 0; i <= S.length() - 3; i++){
        int a, b, c;
        a = S[i] - '0';
        b = S[i + 1] - '0';
        c = S[i + 2] - '0';
        int num = 100 * a + 10 * b + c;
        
        ans = min(ans, abs(num - 753));
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
($N,$X)=glob<>;
push@_,$x+=$_ for 0,glob<>;
$z=inf;
for$t(1..$N){
	$y=($N+$t)*$X;
	for(0..$N/$t){
		$y+=(2*($_||1)+3)*($_[$N-$t*$_]-$_[$-=$N-$t*++$_])
	}
	$y>$z or$z=$y
}
print$z


Measured memory_bytes: 48812
import datetime
import string
import re
import math

def isort(list, _beg, _end):
    if _beg < _end:
        beg = _beg
        end = _end
        pivot = abs(list[int((beg + end)/2)])
        while(True):
            while abs(list[beg]) < pivot: beg += 1
            while abs(list[end]) > pivot: end -= 1
            if beg <= end:
                tmp = list[beg]
                list[beg] = list[end]
                list[end] = tmp
                beg += 1
                end -= 1
            else:
                break
        isort(list, _beg, end)
        isort(list, beg, _end)

def searchByBool(list):
    for i in range(len(list)):
        if check(list[i]): return i
    return -1

def check(num):
    if num >= 0: return True
    else: return False

sp = list(map(int, input().split()))
N = sp[0]
K = sp[1]
alist = list(map(int, input().split()))
klist = []
isK = True

isort(alist, 0, len(alist) - 1)
alist.reverse()

numMinus = 0
for i in range(K):
    if check(alist[i]) == False: numMinus += 1

# select biggest K numbers in terms of absolute value

# for all chosen numbers
# if the number of negative number is even
if numMinus % 2 == 0:
    isK = False

# if odd
# -> choose the smallest number, and search opposite number
if isK and K < N:
    _right = -1
    _left = -1
    for right in range(K,N):
        if check(alist[K-1]) != check(alist[right]):
            _right = right
            break
    for left in range(K):
        if check(alist[K-1-left]) != check(alist[K]):
            _left = left
            break
    isK = False
    if _right != -1 and _left != -1:
        if abs(alist[K-1-left]*alist[_right]) < abs(alist[K-1]*alist[K]):
            alist[K-1-_left] = alist[K]
        else:
            alist[K-1] = alist[_right]
    elif _right == -1 and _left != -1:
        alist[K-1-_left] = alist[K]
    elif _right != -1 and _left == -1:
        alist[K-1] = alist[_right]
    else:
        isK = True

if isK:
    alist.reverse()
klist = alist[0:K]

multi = klist[0]
for i in range(1, K):
    multi *= klist[i]
    multi = multi % 1000000007

print(multi)


Measured memory_bytes: 32872
n,m=map(int,input().split())
if n%2==1:
    #x=["{} {}".format(i+1,n-i) for i in range(m)]
    x=[f"{i+1} {n-i}" for i in range(m)]
    print("\n".join(x))
else:
    #x=["{} {}".format(i+1,n-i) if i<m/2 else "{} {}".format(i+1,n-i-1) for i in range(m)]
    x=[f"{i+1} {n-i}" if i<m/2 else f"{i+1} {n-i-1}" for i in range(m)]
    print("\n".join(x))

Measured memory_bytes: 17484
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


table = [[] for row in range(3)]

def check(mark):
    global table

    for row in range(3):
        count = 0;
        for col in range(3):
            if table[row][col] == mark:
                count += 1
        if count == 3:
            return True

    for col in range(3):
        count = 0
        for row in range(3):
            if table[row][col] == mark:
                count += 1
        if count == 3:
            return True

    if table[1][1] == mark and ((table[0][0] == mark and table[2][2] == mark) or
            (table[0][2] == mark and table[2][0] == mark)):
        return True
    else:
        return False


while True:
    input_str = input()
    if input_str[0] == "0":
        break
    table[0] = input_str
    for row in range(1,3):
        table[row] = input()

    black = check("b")
    white = check("w")
    if black == True:
        print("b")
    elif white == True:
        print("w")
    else:
        print("NA")



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

using namespace std;

int n;
long long m;

long long a[100005];

map<int,int> mi;

int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i];
    a[i] %= m;
    if(i!=0){
      a[i] += a[i-1];
      a[i] %= m;
    }
  }

  mi[0] = 1;
  map<int,int>::iterator itr;

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

    itr = mi.find(a[i]);
    if(itr != mi.end()){
      mi[a[i]]++;
    } else {
      mi[a[i]] = 1;
    }
  }

  long long ans=0;
  for(itr = mi.begin();itr!=mi.end();itr++){
    long long tmp = (long long)(itr -> second);
    tmp = tmp*(tmp-1)/2LL;
    ans += tmp;
    //cout<<(itr -> first)<<" "<<(itr -> second)<<endl;
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e6+10;
ll prime[N],k;//RE就开小一点
bool isprime[N];
void Prime(){
    fill(isprime,isprime+N,1);
    k=0;
    prime[1]=0;
    for(ll i=2;i<N;i++){
        if(isprime[i]){
            prime[k++]=i;
            for(ll j=2;i*j<N;j++)
                isprime[i*j]=0;
        }
    }
}

//质因子分解找因子数
ll solve(ll n){
    ll cnt=0,sum=1;
    for(ll i=0;i<k&&prime[i]*prime[i]<=n;i++){
        if(n%prime[i]==0){
            cnt=0;
            while(n%prime[i]==0){
                cnt++;
                n/=prime[i];
            }
            sum*=(1+cnt);
        }
    }
    if(n>1) sum*=2;
    return sum;
}
ll x[10000005],n;
int main()
{
   for (int i=1; i<10000001; i++)
	for (int j=i; j<10000001; j+=i)
		x[j]++;//存因子个数
cin>>n;ll sum=0;
   for(ll i=1;i<=n;i++)
    sum+=x[i]*i;
    cout<<sum;
}


Measured memory_bytes: 81752
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}
 
int main()
{
    int n, m;
    int a[1001], b[1001];
    cin >> n;
    REP(i, n){
        scanf("%d", &a[i]);
    }
    cin >> m;
    REP(i, m){
        scanf("%d", &b[i]);
    }

    int max_a=0, max_b=0; //最高位
    REP(i, n){
        if(a[n-i-1]!=0) max_a = i+1;
    }
    REP(i, m){
        if(b[m-i-1]!=0) max_b = i+1;
    }

    int is_1 = -1;
    REP(i, min(n, m)){
        if(a[i] < b[i]){
            is_1 = 1;
            break;
        }else if(a[i] > b[i]){
            is_1 = 0;
            break;
        }
    }

    if(is_1==-1){
        if(n<m){
            is_1 = true;
        }else{
            is_1 = false;
        }
    }
    printf("%d\n", is_1);
    return 0;
}


Measured memory_bytes: 3232
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n, r;
  cin >> n >> r;
  if(n >= 10) {
  	cout << r << endl;
  } else {
  	cout << r + ((100) * (10 - n)) << endl;
  }
  return 0;
} //good night.

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const MOD: u64 = 1_000_000_000 +7;
fn main() {
    input! {
        n: usize,
        t: [u64; n],
        a: [u64; n],
    }
    let mut idx = vec![true; n];
    let mut ans = 1;
    
    let mut t_max = 0;
    for i in 0..n {
        if t[i] > t_max {
            if t[i] > a[i] {
                ans *= 0;
            }
            idx[i] = false;
            t_max = max(t_max, t[i]);
        }
    }
    let mut a_max = 0;
    for i in (0..n).rev() {
        if a[i] >a_max {
            if a[i] > t[i] {
                ans *= 0;
            }
            idx[i] = false;
            a_max = max(a_max,a[i]);
        }
    }
    for i in 0..n {
        if idx[i] {
            ans *= min(a[i], t[i]);
            ans %= MOD;
        }
    }
    println!("{}",ans% MOD);
}

Measured memory_bytes: 6396
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 1; i <= 100; i++) {
            int t = 0;
            for (int j = 0; j < n; j++) {
                t += (x[j] - i)*(x[j] - i);
            }
            if(t < ans) ans = t;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n;
    cin >> n;
    int sq = sqrt(n);
    n = sq*sq;
    cout << n << endl;
}


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

int main()
{
    int a,b; // 整数の変数の宣言
    cin >> a >> b; // 変数に入力を与える
    //a+bの値で条件分岐
    if(a+b >= 10)
    {
        cout << "error" << endl; // 文字列は必ず " " で囲む
    }
    else
    {
        cout << a+b << endl; // 数値はそのまま出力できる
    }
}

Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

long long N, M, H,K,W,re;
long long A[200001];
long long C[200001];
bool B[200001] = {};
string S[100];
bool OK = true;
bool f;
vector <long long>vl;

int main() {
	cin >>N;
	
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[A[i]] = true;
		if (B[A[i] - 1] == true) {
			C[A[i]] = C[A[i] - 1] + 1;
		}
		else {
			C[A[i]] = 0;
		}
		vl.push_back(C[A[i]]);

	}
	
	sort(vl.begin(), vl.end());


	cout << N - (vl[vl.size()-1] + 1) << endl;
	
	
	return 0;
}


Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    ll n, a[MAX_N], sum = 0;
    vector<ll> x, y;
    cin >> n;
    REP(i,n){
        cin >> a[i];
        if(a[i] >= 0) x.push_back(a[i]);
        else y.push_back(a[i]);
    }
    SORT(x);
    SORTR(y);
    vector<P> ans;
    if(y.size()==0){
        y.push_back(x[0]);
        x.erase(x.begin());
    }
    if(x.size()==0){
        x.push_back(y[0]);
        y.erase(y.begin());
    }
    for(int i=1;i<x.size();i++){
        ans.push_back({y[0],x[i]});
        y[0] -= x[i];
    }
    for(int i=1;i<y.size();i++){
        ans.push_back({x[0],y[i]});
        x[0] -= y[i];
    }
    ans.push_back({x[0],y[0]});
    cout << x[0] - y[0] << endl;
    for(auto p : ans){
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}


Measured memory_bytes: 5872
n = int(input())
ab = []

for i in range(n):
    a,b = map(int,input().split())
    ab.append([b,a])
ab.sort()

due = 0
time = 0
for i in range(n):
    due = ab[i][0]
    time += ab[i][1]
    
    if time > due:
        print("No")
        exit()
print("Yes")
    

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

int main(){
    int n;
    cin >> n;
    int a,dw=1,rel=1;
    for(int i=0;i<n;i++){
        cin >> a;
        if(a%2){
            dw*=1;
        }else{
            dw*=2;
        }
        rel*=3;
    }
    cout << rel-dw << endl;
}


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL(x) memset(x,0,sizeof(x))


using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

int main()
{
  string S;
  cin >> S;

  if(S[2]==S[3] && S[4]==S[5])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;


  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

int main(){
	int w, n;
	cin >> w;
	vector<int> num(31);
	for (int i = 1; i <= w; ++i) {
		num[i] = i;
	}
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a, b;
		char split;
		cin >> a >> split >> b;
		int temp;
		temp = num[a];
		num[a] = num[b];
		num[b] = temp;
	}
	for (int i = 1; i <= w; ++i) {
		cout << num[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
use std::vec::Vec;
use std::cmp::min;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let n: usize = read();
    let k: usize  = n / 2;
    let mut ans = 0;
    if n % 2 == 0 {
        let c5: usize = count(k, 5);
        let c2: usize = count(k, 2);
        ans = min(k+c2, c5);
    } else {
        let c5_2k: usize = count(2*k, 5);
        let c2_2k: usize = count(2*k, 2);
        let c5_k: usize = count(k, 5);
        let c2_k: usize = count(k, 2);
        ans = min(c2_2k - c2_k - k, c5_2k-c5_k);
    }

    println!("{}", ans);
}


fn count(n: usize, k: usize) -> usize {
  let mut n = n;
  let mut res_k = 0;
  while n > 0 {
    res_k += n / k;
    n /= k;
  }

  res_k
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> w(n),psum(n+1);
  for(int i = 0; i < n; ++i) cin >> w[i];
  for(int i = 0; i < n; ++i) psum[i+1] = psum[i]+w[i];
  int tot = psum[n], ans = tot;
  for(int i = 0; i < n; ++i) ans = min(ans,abs(tot-2*psum[i]));
  cout << ans;
  return 0;
}


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

int solve(long long h, long long w) {
  vector<long long> res = {w * ((h + 2) / 3 - h / 3)};
  for (auto &d : {(h + 2) / 3, h / 3}) {
    vector<long long> cand;
    cand.push_back(d * w);
    cand.push_back((h - d) * (w / 2));
    cand.push_back((h - d) * ((w + 1) / 2));
    sort(cand.begin(), cand.end());
    res.push_back(cand[2] - cand[0]);
  }
  return *min_element(res.begin(), res.end());
}

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

  int h, w;
  cin >> h >> w;
  int ans = min(solve(h, w), solve(w, h));
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   long long n,k,z,x,c=0,i;
  cin>>n>>k;long long a[n]={0};
  while(k--){
  cin>>z;
    while(z--){
    cin>>x;
      a[x-1]+=1;
    }
  }
  for(i=0;i<n;i++){
  if(a[i]==0) c++;
  }
  cout<<c;
 return 0; 
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  ll N,A[200000],cnt[200001] = {0};
  cin>>N;
  rep(i,N){
    cin>>A[i];
    cnt[A[i]]++;
  }
  ll sum(0);
  for(int i(0);i<=200000;i++){
    sum += cnt[i]*(cnt[i]-1)/2;
  }
  rep(i,N){
    int a = cnt[A[i]];
    cout << sum - (a-1) << endl;
  }
  return 0;
}



Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
 
int main(){
    int H, W, D;
    cin >> H >> W >> D;
    pair<int, int> number_position[100000];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int num;
            cin >> num;
            number_position[num - 1] = {i, j};
        }
    }
    int need_magic_cost[H * W];
    for(int i = H * W - D; i < H * W; i++){
        need_magic_cost[i] = 0;
    }
    for(int i = H * W - D - 1; i >= 0; i--){
        need_magic_cost[i] = need_magic_cost[i + D] + abs(number_position[i].first - number_position[i + D].first) + abs(number_position[i].second - number_position[i + D].second);
    }
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int left, right;
        cin >> left >> right;
        cout << need_magic_cost[left - 1] - need_magic_cost[right - 1] << endl;
    }
}

Measured memory_bytes: 2304
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef long long int lli;
int int_compare(const void* a, const void* b) { return *(int*)a - *(int*)b; }
int lli_compare(const void* a, const void* b) { return *(lli*)a - *(lli*)b; }
//qsort(dat,NUM,sizeof(int),int_compare);
int main(void)
{
	int n, t;
	static int a[100000], b[100000];
	int cnt, flg;

	do {
		scanf("%d", &t);
		if (t == 0)break;
		scanf("%d", &n);
		flg = cnt = 0;
		for (int i = 0; i < n; i++) {
			scanf("%d %d", &a[i], &b[i]);
			cnt += b[i] - a[i];
		}
		if (cnt<t) {
			printf("%d\n", t-cnt);
		}
		else {
			printf("OK\n");
		}
	} while (t != 0);
	
	return 0;
}


Measured memory_bytes: 2772
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	while(1)
	{
		int d,n,m;
		vector<int> vec;
		vec.pb(0);
		cin >> d;
		vec.pb(d);
		if(d==0)break;
		cin >> n;
		cin >> m;
		for(int i=0;i<n-1;i++)
		{
			int k;
			cin >> k;
			vec.pb(k);
		}
		SORT(vec);
		int ans=0;
		for(int i=0;i<m;i++)
		{
			int k;
			cin >> k;
			vector<int>::iterator it;
			it=lower_bound(all(vec),k);
			int p1=(*it);
			it--;
			int p2=(*it);
			ans+=min(abs(p1-k),abs(p2-k));
		}
		cout << ans << endl;
	}
	return 0;
}

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

ans = 0
for ta in range(a + 1):
    for tb in range(b + 1):
        for tc in range(c + 1):
            if 500 * ta + 100 * tb + 50 * tc == x:
                ans += 1

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int n,k;cin>>n>>k;
    vector<long double> a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=(a[i]+1)/2.0;
    }
    long double an=0,ans;
    for(int i=0;i<k;i++)an+=b[i];
    an/=k;
    ans=an;
    for(int i=0;i<n-k;i++){
        an=(1.0*k*an-b[i]+b[i+k])/k;
        ans=max(an,ans);
    }
    cout.precision(7);
    cout<<ans*k;
    
}

Measured memory_bytes: 6528
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#define fi(p) for(int i=0;i<(p);i++)
using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int n;
	int a[100];
	cin >> n;
	vector<int> p(n);

	fi(n) {
		cin >> p[i];
	}

	int ans = 0;
	
	fi(n -2) {
		if ((p[i] < p[i + 1]) && (p[i+1] < p[i + 2])) {
			ans++;
		}
		else if ((p[i] > p[i + 1]) && (p[i+1] > p[i + 2])) {
			ans++;
		}
	}

	cout << ans << endl;


}


int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include <string>
#include <iostream>
#include <algorithm>

#define H_MAX 100
#define W_MAX 100

using namespace std;

char board[H_MAX * W_MAX];
int num[H_MAX * W_MAX];

int H, W;

void setNum(int i, int j, int val){
  num[(i-1)*W + j-1] = val;
}

char getBoard(int i, int j){
  return board[(i-1) * W + j-1];
}

int getNum(int i, int j){
  // (1,1)から(i,j)を「いい状態」にするための操作の回数

  int result = num[(i-1)*W + j-1];

  if (result >= 0){
    // 1度求めている
    return result;
  }

  if (i == 1 && j == 1){
    if (getBoard(1,1) == '.'){
      result = 0;
    }else{
      result = 1;
    }
  }else{
    int result1 = -1, result2 = -1;
    if (i > 1){
      // (i-1, j)との比較
      // (i,j)が'.'ならば，(i-1, j)までをいい状態にする操作と同じ回数
      // (i, j), (i-1, j)が両方'#'のとき，同時に変更すればいいので同じ回数
      // (i, j)が'#'，(i-1, j)が'.'のとき，(i,j)に対して操作する必要があるので+1
      result1 = getNum(i-1, j);
      if (getBoard(i, j) == '#' && getBoard(i-1, j) == '.'){
        result1 ++;
      }
    }
    if (j > 1){
      // (i, j-1)との比較
      // (i,j)が'.'ならば，(i, j-1)までをいい状態にする操作と同じ回数
      // (i, j), (i, j-1)が両方'#'のとき，同時に変更すればいいので同じ回数
      // (i, j)が'#'，(i, j-1)が'.'のとき，(i,j)に対して操作する必要があるので+1
      result2 = getNum(i, j-1);
      if (getBoard(i, j) == '#' && getBoard(i, j-1) == '.'){
        result2 ++;
      }
    }

    // result1, result2のうち，0以上で小さい方を採用
    if (result1 < 0 || (0 <= result2 && result2 < result1)){
      result = result2;
    }else {
      result = result1;
    }
  }

  setNum(i, j, result);
  return result;
}

int main(){
  scanf("%d %d", &H, &W);

  for(int i = 0, end= H * W; i < end; i ++){
    cin >> board[i];
    num[i] = -1;
  }
  // num[i,j]：(1,1)から(i+1, j+1)を「いい状態」にするための操作の回数
  int result = getNum(H, W);

  cout << result;
  return 0;
}

Measured memory_bytes: 256
def divisor(n):
    divisors = []
    i = 1
    while i * i <= n:
        if n % i == 0:
            divisors.append(i)
            if i * i < n:
                divisors.append(n // i)
        i += 1
    divisors.sort()
    return divisors


N, K = map(int, input().split())
A = list(map(int, input().split()))
divisors = divisor(sum(A))
for d in divisors[::-1]:
    rem = [a % d for a in A]
    rem.sort(reverse=True)
    i = sum(rem) // d
    if sum(rem[i:]) <= K:
        print(d)
        exit()


Measured memory_bytes: 41820
#include <stdio.h>

long int battle(long int hp){
  if(hp <= 1){
    return 1;
  }else{
    return 2 * battle(hp / 2) + 1;
  }
}

int main(){
  long int result=0, h;
  
  scanf("%ld", &h);
  
  result = battle(h);
  printf("%ld", result);
  
  return 0;
}

Measured memory_bytes: 128
#include <climits>
#include <cstring>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <fstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define f first
#define s second

#define MM INT_MAX/5
#define MIM INT_MIN/2

int di[] = { 1,-1,0,0 };
int dj[] = { 0,0,1,-1 };

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define v vector
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

int dp[(int)1e5 + 10];
int stone[(int)1e5 + 10];

int main()
{
	memset(dp, 63, sizeof(dp));
	int N;
	cin >> N;
	F0R (i, N) {
		cin >> stone[i];
	}
	dp[0] = 0;
	FOR(i, 0, N) {
		dp[i + 1] = min(dp[i + 1], abs(stone[i] - stone[i + 1]) + dp[i]);
		dp[i + 2] = min(dp[i + 2], abs(stone[i] - stone[i + 2]) + dp[i]);
	}
	cout << dp[N - 1];
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int n;
  double sum=0;
  int a,b;
  int v[1001];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v[i]);
  }
  //ソーと
  for(int j=0;j<n-1;j++){
    for(int i=0;i<n-1;i++){
      if(v[i]>=v[i+1]){
	a= v[i];
	b=v[i+1];
	v[i]=b;
	v[i+1]=a;
      }
    }
  }
  
  sum=(double)(v[0]+v[1])/2;
  if(n!=2){
    for(int k=1;k<n-1;k++){
      sum =(double) (sum +v[k+1])/2;    
    }
  }
  printf("%lf\n",sum);      
  return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n string
	fmt.Scan(&n)

	ss := strings.Split(n,"")

	if ss[0] == "9" || ss[1] == "9" {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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


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

    int n;
    cin >> n;
    vector<int> one,two,thr;
    one = two = thr = vector<int>(10);

    int tmp = 0;
    for(int i = 0; i <= 2; ++i) {
        for(int j = i+1; j <= 3; ++j) {
            for(int k = j+1; k <= 4; ++k) {
                one[tmp] = i;
                two[tmp] = j;
                thr[tmp] = k;
                ++tmp;
            }
        }
    }
    /*
    rep(i, 10) {
        cout << one[i] << " " << two[i] << " " << thr[i] << endl;
    }
    */

    int m, a, r, c, h;
    m = a = r = c = h = 0;
    vector<int> d(5);
    rep(i,n) {
        string s;
        cin >> s;
        if(s[0] == 'M') ++m;
        if(s[0] == 'A') ++a;
        if(s[0] == 'R') ++r;
        if(s[0] == 'C') ++c;
        if(s[0] == 'H') ++h;
    }
    d[0] = m;
    d[1] = a;
    d[2] = r;
    d[3] = c;
    d[4] = h;

    ll ans = 0;
    rep(i, 10) {
        ans += ll(d[one[i]])*d[two[i]]*d[thr[i]];
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    s[k-1] = tolower(s[k-1]);
    cout << s <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 2000000
#define INF (1<<30)

int H, A[MAX+1];

void maxHeapify (int i) {
	int l, r, largest, tmp;
	l = 2 * i;
	r = 2 * i + 1;

	// select the node which has the maximum value
	if (l <= H && A[l] > A[i]) largest = l;
	else largest = i;
	if (r <= H && A[r] > A[largest]) largest = r;

	if (largest != i) {
		tmp = A[i];
		A[i] = A[largest];
		A[largest] = tmp;
		maxHeapify(largest);
	}
}

int extract() {
	int maxv;
	if ( H < 1 ) return -INF;
	maxv = A[1];
	A[1] = A[H--];
	maxHeapify(1);
	return maxv;
}

void increaseKey(int i, int key) {
	int tmp;
	if (key < A[i]) return;
	A[i] = key;
	while ( i > 1 && A[i / 2] < A[i]) {
		tmp = A[i];
		A[i] = A[i / 2];
		A[i / 2] = tmp;
		i = i / 2;
	}
}

void insert(int key) {
	H++;
	A[H] = -INF;
	increaseKey(H,key);
}

int main() {
	int key;
	char com[10];

	while ( 1 ) {
		scanf("%s", com);
		if ( com[0] == 'e' && com[1] == 'n') break;
		if ( com[0] =='i' ) {
			scanf("%d", &key);
			insert(key);
		} else {
			printf("%d\n",extract());
		}
	}

	return 0;
}


Measured memory_bytes: 5632
#include<stdio.h>
int main(void)
{
  char s[3],t[3];
  int count=0;
   scanf("%s",s);
   scanf("%s",t);
    for(int j=0;j<=2;j++)
    {
        if(s[j]==t[j])
        count++;
    }
   printf("%d",count);
 return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int read(){
	int w=0,f=1;
	char c=' ';
	while(c<'0'||c>'9')c=getchar(),f=c=='-'?-1:f;
	while(c>='0'&&c<='9')w=w*10+c-48,c=getchar();
	return w*f;
}
int n;
int a[N], b[N];
int ca[N], cb[N];
signed main(){
	n = read();
	for(int i = 1; i <= n; i++) a[i] = read(), ca[a[i]]++;
	for(int i = 1; i <= n; i++) b[i] = read(), cb[b[i]]++;
	for(int i = 1; i <= n; i++) if(ca[i] + cb[i] > n) return printf("No\n"), 0;
	reverse(b + 1, b + n + 1);
	vector<int> t;
	int cnt = 0, val = 0, len = 0;
	for(int i = 1; i <= n; i++)
	{
		if(b[i] == a[i])
		{
			cnt++;
			val = b[i];
			t.push_back(i);
		}
	}
  	// t has at most one unique element
	len = cnt;
	vector<int> s;
	for(int i = 1; i <= n; i++)
	{
	 if(a[i] == b[i]) continue;
	 if(cnt == 0) break;
	 if(a[i] != val && b[i] != val)
	 {
	 	s.push_back(i);
	 	cnt--;
       	if(cnt)
			val = b[t[cnt - 1]];
	 }		
	}
	for(int i = 0; i < len; i++)
	{
		swap(b[s[i]], b[t[i]]);
	}
	printf("Yes\n");
	for(int i = 1; i <= n; i++) printf("%d ", b[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 7316
//======================================================================
// Contents    : AOJ ITP1_8_B
//               与えられた数の各桁の和を計算
// Input       : 複数の整数x
// Output      : x の各桁の和
// Constraints : x は 1000 桁以下の整数
// Author      : 廣部智也
// LastUpdate  : 2020/07/24
// Since       : 2020/07/24
//======================================================================

#include <stdio.h>

int digit_sum( char str, int sum, int *n );

int main(){

    char str = 'A';

    int sum = 0;

    int m = 0;
    
    int *n = &m;

    while( 1 ){
        
        scanf("%c", &str );

        if( str == '\n' && sum == 0 && *n == 1 ){
            break;
        }
        else{
            sum = digit_sum( str, sum, n );
        }
        
//        printf("%d\n", *n ); //確認用
    }
    
    return 0;
}



int digit_sum( char str, int sum, int *n ){
    
    if( str >= '0' && str <= '9' ){
        sum = sum + (str - '0');
        *n = 1;
    }
    else if ( str == '\n' ){
        printf("%d\n", sum);
        sum = 0;
        n = 0;
    }

    return sum;
}



Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b;
	while(true)
	{
		cin >> a >> b;
		if(a == 0 && b == 0)
			break;
		for(int i = 0;i < a;i++)
		{
			for(int j = 0;j < b;j++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;



int main() {
  int x;
  cin >> x;
  if(400 <=x && x <=599){
    cout <<8<<endl;
  }
  else if(600<=x && x<=799){
    cout <<7 <<endl;

  }
  else if(800 <=x && x<=999){
    cout << 6<<endl;

  }
  else if(1000 <=x && x<=1199){
    cout << 5<<endl;

  }
  else if(1200 <=x && x<=1399){
    cout << 4<<endl;

  }
  else if(1400 <=x && x<=1599){
    cout << 3<<endl;

  }
  else if(1600 <=x && x<=1799){
    cout << 2<<endl;

  }
  else{
    cout <<1 <<endl;
  }
  
  

  
}

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

using namespace std;

int main() {
	long k, a, b;

	cin >> k >> a >> b;

	long biscuits = 1;

	long count_pocket = 0;
	long count = 0;

	if (a >= (b - 2)) {
		count_pocket = k;
	}
	else {
		biscuits += (a - 1);
		int remain_k = (k - (a - 1));
		
		if (remain_k < (remain_k / 2) * (b - a)) {
			if (remain_k % 2 != 0) {
				count_pocket = 1;
			}
			count = remain_k / 2;
		}
		else {
			count_pocket = remain_k;
		}
	}

	cout << (biscuits + count_pocket + ((b - a) * count)) << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

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

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	char x; cin >> x;
	if (x - 'a' < 0)cout << 'A' << endl;
	else cout << 'a' << endl;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int W, H, N;
	cin >> W >> H >> N;

	bool board[101][101] = {};
	for (int i = 0; i < N; i++) {
		int xi, yi, a;
		cin >> xi >> yi >> a;
		if (a == 1) {
			for (int x = 0; x < xi; x++)
				for (int y = 0; y < H; y++)
					board[x][y] = true;
		} else if (a == 2) {
			for (int x = xi; x < W; x++)
				for (int y = 0; y < H; y++)
					board[x][y] = true;
		} else if (a == 3) {
			for (int y = 0; y < yi; y++)
				for (int x = 0; x < W; x++)
					board[x][y] = true;
		} else if (a == 4) {
			for (int y = yi; y < H; y++)
				for (int x = 0; x < W; x++)
					board[x][y] = true;
		}
	}

	int ans = 0;
	for (int x = 0; x < W; x++)
		for (int y = 0; y < H; y++)
			ans += !board[x][y];

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,a[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int sum=0;
    ll ans=0;
    for(int i=n;i>=1;i--)
    {
        sum--;
        if(sum>a[i]){printf("-1\n");return 0;}
        if(a[i]!=sum)
        {
            ans+=a[i];
            sum=a[i];
        }
    }
    if(sum!=0){printf("-1\n");return 0;}
    printf("%lld\n",ans);
}


Measured memory_bytes: 1152
#include <iostream>
#include <map>
#include <string>
#include <list>
using namespace std;

int main(){
	list<string> res_list;
	while(1){
		int n;
		map<char,char> convert_map;
		cin>>n;
		if(n == 0){
			break;
		}
		for(int i = 0;i < n;i++){
			char rc ,lc;
			cin>>lc>>rc;
			convert_map.insert( map<char,char>::value_type(lc,rc) );
		}
		cin>>n;
		string res = "";
		for(int i= 0;i < n;i++){
			char c;
			cin>>c;
			auto it = convert_map.find(c);
			if(it != convert_map.end()){
				res+=it->second;
			}else{
				res+=c;
			}
		}
		res_list.push_back( res );
	}
	for(auto it = res_list.begin();it != res_list.end();it++){
		cout<<(*it)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3276
"use strict"
function main(arg) {
    let [N,K] = arg.trim().split("\n")[0].split(" ").map(Number)
    let p = arg.trim().split("\n")[1].split(" ").map(Number).sort((a,b)=>a-b)
    let sum = 0
    for (let i = 0; i < K; i++) {
        sum += p[i]
    }
    console.log(sum)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29720