akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,0,n) cin >> a[i];
  ll ans = 1000;
  vector<ll> d(n-1);
  rep(i,0,n-1) {
    d[i] = a[i+1] - a[i];
  }
  int i = 0;
  while(i < n-1) {
    int j = i;
    while(j < n-1) {
      if (d[j] <= 0) {
        break;
      } else {
        j++;
      }
    }
    if (a[i] < a[j]) {
        ans += (ans/a[i]) * (a[j] - a[i]);
    } else {
      j++;
    }
    i = j;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  if(N/10==9){
    cout << "Yes" << endl;
  }else if(N%10==9){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long int
int main(){
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    priority_queue<ll, vector<ll>, less<ll> >q_a, q_b, q_c, q_d;
    for(ll i = 0; i < a; ++i){
        ll num;
        cin >> num;
        q_a.push(num);
    }
    for(ll i = 0; i < b; ++i){
        ll num;
        cin >> num;
        q_b.push(num);
    }
    for(ll i = 0; i < c; ++i){
        ll num;
        cin >> num;
        q_c.push(num);
    }
    for(ll i = 0; i < x; ++i){
        q_d.push(q_a.top());
        q_a.pop();
    }
    for(ll i = 0; i < y; ++i){
        q_d.push(q_b.top());
        q_b.pop();
    }
    while(q_c.size()){
        q_d.push(q_c.top());
        q_c.pop();
    }
    ll ans = 0;
    for(ll i = 0; i < x + y; ++i){
        ans += q_d.top();
        q_d.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8176
from collections import Counter
from functools import reduce
# import statistics
import bisect
import copy
import fractions
import math
import pprint
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n = II()
a = LI()
length = len(a)
odd = [a[i] for i in range(length) if i % 2 == 0]
even = [a[i] for i in range(length) if i % 2 == 1]
if length % 2 == 0:
    print(' '.join(map(str, even[::-1])) + ' ' + ' '.join(map(str, odd)))
else:
    print(' '.join(map(str, odd[::-1])) + ' ' + ' '.join(map(str, even)))


Measured memory_bytes: 28600
#include <vector>
#include <cstdio>
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	std::vector<int>v(n+1),w(k);
	for(int i=0;i<k;i++)scanf("%d",&w[i]);
	for(int i=k-1;i>=0;i--)if(!v[w[i]])v[w[i]]=1,printf("%d\n",w[i]);
	for(int i=1;i<=n;i++)if(!v[i])printf("%d\n",i);
}

Measured memory_bytes: 3452
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int N;
    cin >> N;
    int R;
    cin >> R;
    int ret = 0;
    if (N < 10) {
       ret = R + (10 - N) * 100;
    }
    else {
       ret = R;
    }
    // 出力
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int n,m,x;
const int maxn = 1e5+10;
ll a[maxn],b[maxn];
int main(){
    ll i,j,k;
    ll ans;
    ll now;
    ll comm;
    scanf("%d",&n);
        ans = 0;
        now = 0;
        for(i=1;i<=n;i++){
            scanf("%lld%lld",&a[i],&b[i]);
        }
        
        for(i=n;i>=1;i--){
            a[i] += ans;
            for(j=a[i]/b[i];;j++){
                if(j*b[i]>=a[i]){
                    break;
                }
            }
            comm = j*b[i] - a[i];
            ans += comm;
        }
        printf("%lld\n",ans);
    
    
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

int main() {
    string s,a;
    int n,k;
    cin>>n>>s>>k;
    a=s;
    string x;
    x=s[k-1];
    for(int i=0;i<n;i++){
        string ss;
        ss=s[i];
        if(ss!=x){
            a[i]='*';
        }
        cout<<a[i];
    }
    cout<<endl;
    
    return 0;
}



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

int main(){
	int m, f, r;
	while(1){
	cin >> m >> f >> r;
	if(m==-1 && f==-1 && r==-1){break;}
	else if(m==-1 || f==-1){cout << "F" << "\n";}
	else if(m+f>=80){cout << "A" << "\n";}
	else if(m+f>=65 && m+f<80){cout << "B" << "\n";}
	else if(m+f>=50 && m+f<65){cout << "C" << "\n";}
	else if(m+f>=30 && m+f<50 && r>=50){cout << "C" << "\n";}
	else if(m+f>=30 && m+f<50){cout << "D" << "\n";}
	else if(m+f<30){cout << "F" << "\n";}
	}
	return 0;
	}

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

int main(){
	long long a,b,c,d;
	cin >> a >> b >> c >> d;
	long long ans=max(a*c,a*d);
	ans=max(ans,b*c);
	ans=max(ans,b*d);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
typedef pair<int, int> P;

int dist[100005][3];

signed main(){
    string s, t;
    cin >> s >> t;
    if(s.length()+1== t.length() && t.substr(0,t.length()-1) == s) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for(int i = 0; i < N; i++){
    cin >> P.at(i);
  }
  int ans = 1, num = P.at(0);
  for(int i = 1;i < N; i++){
    if(P.at(i) < num){
      num = P.at(i);
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int ln;
  int a[10]={0,4,6,6,6,6,6,8,6,8};
  char s[10][9]={{""},{"',.!?"},{"abcABC"},{"defDEF"},{"ghiGHI"},{"jklJKL"},{"mnoMNO"},{"pqrsPQRS"},{"tuvTUV"},{"wxyzWXYZ"}};
  char t[10001];
  while(cin>>t){
    ln=strlen(t);
    for(i=0;i<ln;i=j){
      for(j=i;j<ln&&t[i]==t[j];j++);
      if(t[i]=='0'){
	for(k=0;k<j-i-1;k++)
	  cout<<" ";
      }else
	cout<<s[t[i]-'0'][(j-i-1)%a[t[i]-'0']];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef long long int ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}
ll combination(ll n) {
	ll nck[100][100];
	nck[0][0] = 1;
	for (int i = 1; i < 1 + n; i++) {
		nck[i][0] = nck[i][i] = 1;
		for (int j = 1; j < i; j++) {
			nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
	return 0;
}
//------------------変数-----------------------//
ll n, m, a, b, k, d, c;;
typedef pair<ll, ll> P;
vector<vector<ll>> way(2001), money(2001);
ll maxa = 0, moto = 0;
ll retu[11451] = {};
queue <ll>q;
ll bitmax = 0;
//-------------------関数----------------------//

int main() {
	ll n; cin >> n;
	ll four = 0, two = 0, zero = 0;
	REP(i, n) {
		ll hoge; cin >> hoge;
		if (hoge % 4 == 0) {
			four++; continue;
		}
		if (hoge % 2 == 0) {
			two++; continue;
		}
		else { zero++; }
	}
	if (two == 1) {
		zero++;
		if (four + 1 >= zero) { cout << "Yes" << endl; }
		else { cout << "No" << endl; }
	}
	else {
		if (two == 0) {
			if (four + 1 >= zero) { cout << "Yes" << endl; }
			else { cout << "No" << endl; }return 0;
		}
		if (four >= zero) { cout << "Yes" << endl; }
		else { cout << "No" << endl; }
	}
	return 0;
}

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

int main() {

	int n; cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
int hantei (int target){
  int i;
  if(target<2) return 0;
  else if(target == 2) return 1;
  else if(target % 2 ==0) return 0;

  for(i=3; i*i <= target; i+=2){
    if(target % i ==0) return 0;
  }
  return 1;
}

int main(){
  int i,j, yaku=0,n,target;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&target);
    if(hantei(target) == 1) yaku++;
  }

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

  
}



Measured memory_bytes: 2072
N = int(input())
c = [0]*9
for i in range(9):
    c[i] = [0]*9
#先頭がiで末尾がjの数を数えていく
for i in range(1,N+1):
    s = str(i)
    p = s[0]
    l = s[-1]
    p = int(p)
    l = int(l)
    if p != 0 and l != 0:
        c[p-1][l-1] += 1
ans = 0
#A=c[i][j],B=c[j][i]として(A,B)の組み合わせの数を数えていく
for i in range(9):
    for j in range(9):
        ans += c[i][j]*c[j][i]
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int M;
ll dsum, csum;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> M;
    for(int i = 0; i < M; i++){
        ll d, c;
        cin >> d >> c;
        dsum += d * c;
        csum += c;
    }
    dsum--, csum--;
    cout << (dsum / 9) + csum << endl;
    return 0;
}

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

int main(){
  char c1,c2;
  int y,m,d;
  cin>>y>>c1>>m>>c2>>d;
  cout<<(m<=4 ? "Heisei":"TBD")<<endl;
  return 0;
}

Measured memory_bytes: 3632
import sys
import math
#from queue import *
#import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
 
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input()))
def inara():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############

a,b,c,d=invr()

p=a*c
q=a*d
r=b*c
s=b*d

print(max(p,q,r,s))


Measured memory_bytes: 9216
// attr {{{
#![allow(
    dead_code,
    non_snake_case,
    unused_imports,
)]
// }}}

// use {{{
use std::fmt;
use std::io::{self,BufRead,Read,Write};
use std::str;
// }}}

const INF: i64 = 1_010_000_000_000_000_000;
const MOD: i64 = 1_000_000_007;
const EPS: f64 = 1e-9;

// util {{{
fn abs_diff(a: i64, b: i64) -> i64 {
    if a < b { b-a } else { a-b }
}

fn is_even(n: i64) -> bool { n % 2 == 0 }
fn is_odd (n: i64) -> bool { n % 2 != 0 }

fn div_ceil(a: i64, b: i64) -> i64 {
    let up = ((a<0) ^ (b>0)) && (a%b != 0);
    a/b + if up { 1 } else { 0 }
}

fn div_floor(a: i64, b: i64) -> i64 {
    let down = ((a>0) ^ (b>0)) && (a%b != 0);
    a/b - if down { 1 } else { 0 }
}

fn modulo(a: i64, b: i64) -> i64 {
    assert!(b > 0);
    let r = a % b;
    if r >= 0 { r } else { r+b }
}

fn chmax(xmax: &mut i64, x: i64) -> bool {
    if x > *xmax {
        *xmax = x;
        true
    }
    else {
        false
    }
}

fn chmin(xmin: &mut i64, x: i64) -> bool {
    if x < *xmin {
        *xmin = x;
        true
    }
    else {
        false
    }
}

fn _gcd(a: i64, b: i64) -> i64 {
    if b == 0 { a } else { _gcd(b, a%b) }
}

fn gcd(v: &[i64]) -> i64 {
    debug_assert!(v.len() >= 1);
    v.iter().fold(0, |a,&b| _gcd(a,b))
}

fn lcm(v: &[i64]) -> i64 {
    debug_assert!(v.len() >= 1);
    v.iter().fold(1, |a,&b| a / _gcd(a,b) * b)
}

fn _INPUT() -> String {
    let mut res = String::new();
    io::stdin().read_to_string(&mut res).expect("read_to_string()");
    res
}

struct Reader<'a> {
    input: &'a String,
    tokens: str::SplitWhitespace<'a>,
}

impl<'a> Reader<'a> {
    pub fn new(input: &'a String) -> Reader {
        Reader {
            input: input,
            tokens: input.split_whitespace(),
        }
    }

    pub fn RD<T>(&mut self) -> T
        where T: str::FromStr,
              <T as str::FromStr>::Err: fmt::Debug
    {
        self.tokens.next().unwrap().parse().unwrap()
    }

    pub fn RD_VEC<T>(&mut self, n: i64) -> Vec<T>
        where T: str::FromStr,
              <T as str::FromStr>::Err: fmt::Debug
    {
        let mut res: Vec<T> = Vec::with_capacity(n as usize);
        for _ in 0..n {
            res.push(self.RD());
        }
        res
    }
}
// }}}

fn main() {
    let input = _INPUT();
    let mut reader = Reader::new(&input);

    let N: i64 = reader.RD();
    let mut H: i64 = reader.RD();
    let mut A: Vec<i64> = Vec::with_capacity(N as usize);
    let mut B: Vec<i64> = Vec::with_capacity(N as usize);
    for _ in 0..N {
        A.push(reader.RD());
        B.push(reader.RD());
    }

    let amax = *A.iter().max().unwrap();
    B.sort_by(|a,b| b.cmp(a));

    let mut ans = 0;

    for b in B {
        if b <= amax { break }
        ans += 1;
        H -= b;
        if H <= 0 { break }
    }

    if H > 0 {
        ans += div_ceil(H, amax);
    }

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


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

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

  int n;
  cin >> n;
  map<string, vector<pair<int, int>>> mp;
  rep(i, 0, n) {
    string s;
    int a;
    cin >> s >> a;
    mp[s].emplace_back(a, i + 1);
  }

  for (auto p : mp) {
    sort(p.second.rbegin(), p.second.rend());
    for (auto v : p.second) cout << v.second << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int i,j,k,n,m;
struct stu{
    ll a,b,c,d;
}a[100010];
int cmp1(stu a,stu b){
    return a.a<b.a||(a.a==b.a&&a.b<b.b);
}
int cmp2(stu a,stu b){
    return a.c<b.c;
}
int main(){
    cin>>n>>m;
    for(i=1;i<=m;i++){
        scanf("%lld%lld",&a[i].a,&a[i].b);
        a[i].c=i;
    }
    sort(a+1,a+1+m,cmp1);
    for(i=1;i<=m;i++){
        if(a[i].a!=a[i-1].a)k=1;
        a[i].d=k++;
    }
    sort(a+1,a+1+m,cmp2);
    for(i=1;i<=m;i++){
        printf("%012lld",a[i].a*1000000+a[i].d);
        if(i!=m)printf("\n");
    }
    return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#include <cstring>
#include <map>
#include <set>
#define int long long int
#define cons 1000000007 
using namespace std;
 
 
signed main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
 
    int a, b;
    cin>>a>>b;
    cout<<max(max(a+b, a-b), a*b)<<endl;
}
 

Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn nCr(mut k: i64, n: i64) -> i64 {
    if k > n {
        return 0;
    }
    if k * 2 > n {
        k = n - k
    }
    let mut res = 1;
    for i in 1..k + 1 {
        res *= n - k + i;
        res /= i;
    }
    res
}
fn main() {
    let n = read();
    let a: Vec<usize> = read_n(n);
    let mut map: Vec<usize> = vec![0; n];
    let mut anss: Vec<i64> = vec![0; n];

    for i in &a {
        map[*i - 1] += 1;
    }
    //
    let mut ans = 0;
    for (idx, v) in map.iter().enumerate() {
        let mut vc: i64 = *v as i64;
        ans += nCr(2, vc as i64);
    }

    for i in 0..n {
        anss[i] = ans - nCr(2, map[i] as i64) + nCr(2, map[i] as i64 - 1);
    }

    for i in &a {
        println!("{}", anss[*i -1 as usize]);
    }
}


Measured memory_bytes: 31484
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair< int64, int > Pi;
const int64 INF = 1LL << 58;
int N, M, X, node[100000];
struct edge{
  int to, height;
};
vector< edge > info[100000];
bool used[100000];
int64 Dijkstra(){
  priority_queue< Pi > que;
  que.push( Pi( X, 0));
  while(!que.empty()){
    Pi p = que.top(); que.pop();
    if(p.second == N - 1) return X + node[N - 1] - p.first * 2;
    if(used[p.second]++) continue;
    for(int i = 0; i < info[p.second].size(); i++){
      edge e = info[p.second][i];
      if(e.height > node[p.second]) continue; //0以下になりそう(たぶん
      que.push( Pi( min( p.first - e.height, (int64)node[e.to]), e.to));
    }
  }
  return -1;
}
 
int main()
{
  scanf("%d %d %d", &N, &M, &X);
  for(int i = 0; i < N; i++){
    scanf("%d", node + i);
  }
  for(int i = 0; i < M; i++){
    int A, B, T;
    scanf("%d %d %d", &A, &B, &T);
    A--, B--;
    info[A].push_back((edge){ B, T});
    info[B].push_back((edge){ A, T});
  }
  printf("%lld\n", Dijkstra());
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if((a == b && a!= c) || (a==c&& a!= b) || (b==c && b!=a)){
	cout << "Yes" <<endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
	string s;
	vector < char > st;
	cin>>s;
	int res = 0;
	for (int i=0; i<s.size(); i++) {
		if (st.size()==0) {
			st.push_back(s[i]);
		} else {
			if (st[st.size()-1]!=s[i]) {
				st.pop_back();
				res++;
			} else st.push_back(s[i]);
		}
	}
	cout<<2*res<<endl;
}

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

typedef long long ll;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];

  int q;  cin >> q;
  for(int i=0; i<q; i++){
    int k; cin >> k;
    auto itrl = lower_bound(a.begin(),a.end(),k);
    auto itru = upper_bound(a.begin(),a.end(),k);
    
    cout << itrl-a.begin() <<" "<< itru-a.begin() << endl;
  }

}


Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<ll> L(N),R(N);
  rep(i,N) cin>>L[i]>>R[i];

  ll ans=0;
  rep(i,N) ans=max(ans,R[i]-L[i]+1);

  vector<tuple<ll,ll,int>> v;
  rep(i,N) v.push_back(mkt(L[i],R[i],i));
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());

  ll mal=get<0>(v[0]),mir=get<1>(v[0]);
  set<tuple<ll,ll,int>> se;
  for(int i=1;i<N;i++) se.insert(mkt(R[i],L[i],i));
  for(int i=1;i<N;i++){
    ll l=get<0>(v[i]);
    ll r=get<1>(v[i]);
    int now=get<2>(v[i]);
    
    auto itr=se.begin();
    auto f=*itr;
    ll val=get<0>(f);
    ll p=0;
    if(r<mir){
      if(l<=val) p=min(r,val)-l+mir-mal+2;
    } else{
      if(mal<=val) p=min(mir,val)-mal+r-l+2;
    }
    ans=max(ans,p);
    se.erase(mkt(r,l,now));
    mal=max(mal,l);
    mir=min(mir,r);
    if(mal>mir) break;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 10992
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
	int n;
	cin >> n;
	vector<vector<int> > graph(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	int c[100000];
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	sort(c, c + n);
	long long int m = accumulate(c, c + n - 1, 0);
	vector<int> d(n, -1);
	queue<int> qu;
	qu.push(0);
	for (int i = n - 1; i >= 0; i--) {
		int now = qu.front();
		// cout << now << endl;
		d[now] = c[i];
		qu.pop();
		for (int i = 0; i < graph[now].size(); i++) {
			int next = graph[now][i];
			if (d[next] >= 0) continue;
			qu.push(next);
		}
	}
	cout << m << endl;
	for (int i = 0; i < n; i++) {
		cout << d[i] << " ";
		if (i == n - 1)
			cout << endl;
		else
			cout << " ";
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc148_b() {
	ll N;
	string S, T;

	cin >> N >> S >> T;

	vector<char> ans;

	rep(i, N) {
		ans.push_back(S[i]);
		ans.push_back(T[i]);
	}

	rep(i, ans.size()) {
		cout << ans[i];
	}
	cout << "\n";
}

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

	solve_abc148_b();

	return 0;
}

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

using namespace std;

int main(){

	string pass;
	string odata("QWERTYUIOPASDFGHJKLZXCVBNM");
	string kdata("qwertyuiopasdfghjklzxcvbnm");
	string sdata("1234567890");

	bool o,k,s;

	cin>>pass;

	o=false,k=false,s=false;
	for(int i=0;i<pass.size();i++){
		if(odata.find(pass[i])!=-1) o=true;
		if(kdata.find(pass[i])!=-1) k=true;
		if(sdata.find(pass[i])!=-1) s=true;
	}

	if(o&&k&&s&&pass.size()>=6) cout<<"VALID"<<endl;
	else cout<<"INVALID"<<endl;
	
	return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>

int main(void)
{
    int N,i,f=0;
    int A[10002];

    scanf("%d",&N);

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

    for(i=0; i<N; i++){
        if(A[i]%2 == 0){//偶数の時
            if((A[i]%3!=0)&&(A[i]%5!=0)){
                f=1;
            }
        }
    }

    if(f==1){
        printf("DENIED\n");
    } else {
        printf("APPROVED\n");
    }

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int[] l = new int[Q];
		int[] r = new int[Q];
		for(int i = 0; i < Q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		sc.close();
		int[] a = new int[N + 1];
		for(int i = 1; i < N; i++) {
			if(S.charAt(i) == 'C' && S.charAt(i - 1) == 'A') {
				a[i + 1] += a[i] + 1;
			}else {
				a[i + 1] = a[i];
			}
		}
		//a[N] = a[N - 1];
		for(int i = 0; i < Q; i++) {
			System.out.println(a[r[i]] - a[l[i]]);
		}
//		for(int i = 0; i <= N; i++) {
//			System.out.println(i +" " + a[i]);
//		}
	}
}

Measured memory_bytes: 82408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a;
  cin >> b;
  if(a%2 == 0 && b%2 == 0){
  cout << (a+b)/2 <<endl;}
  else if (a%2 !=0 && b%2 !=0){
  cout << (a+b)/2 <<endl; 
  }
  else{
  cout << (a+b+2)/2 <<endl;
  }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x 
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/10/11  Problem: N18_e  / Link:   ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N, L, Q;
LL ans = 0LL;
LL dist[100005][31];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N;
	VL x(N, 0);
	FOR(i, 0, N) {
		cin >> x[i];
	}
	FOR(i, 0, 100005)FOR(j, 0, 31)dist[i][j] = -1;
	cin >> L >> Q;
	FOR(i, 0, N) {
		int id = upper_bound(ALL(x), x[i] + L) - x.begin();
		id--;

		dist[i][0] = i;
		dist[i][1] = id;
	}
	// ->だけつくる 2^(i-1)回の移動
	FOR(i, 1, 30) {
		FOR(j, 0, N) {
			dist[j][i + 1] = dist[dist[j][i]][i];
		}
	}

	//FOR(j, 0, N) {
	//	FOR(i, 1, 30) {
	//		debug(j); debug(i); debug(dist[j][i]); cout << endl;
	//	}
	//}

	FOR(i, 0, Q) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (a > b)swap(a, b);
		ans = 0;
		int pos = a;
		FORR(k, 29, -1) {
			int nx = dist[pos][k];
			if (nx < b&&pos < nx) {
				pos = nx;
				ans += 1 << (k - 1);
				if (pos == b)break;
			}
		}
		ans++;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 25856
sikis = input().split()
cue = []

for ope in sikis:
    if ope == '+':
        cue[-2] = cue[-1] + cue[-2]
        cue.pop(-1)
    elif ope == '-':
        cue[-2] = cue[-2] - cue[-1]
        cue.pop(-1)
    elif ope == '*':
        cue[-2] = cue[-1] * cue[-2]
        cue.pop(-1)
    else:
        cue.append(int(ope))
        
print(cue[-1])


Measured memory_bytes: 5596
#include <iostream>

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

   int N = S.size();
   bool flag = true;
   for(int i=0; i<N/2; ++i){
      if(S[i]!=S[N-1-i]) flag = false;
   }
   N = (N-1)/2;
   for(int i=0; i<N; ++i){
      if(S[i]!=S[N-1-i]) flag = false;
   }
   N = S.size();
   for(int i=0; i<N; ++i){
      int j = i + (N+3)/2 - 1;
      if(j>=N) break;
      if(S[j]!=S[N-1-i]) flag = false;
   }

   if(flag) std::cout << "Yes" << std::endl;
   else std::cout << "No" << std::endl;

   return 0;
}


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;

int n;
int sz[maxn];
ll a[maxn], dis[maxn];
vector<pair<ll, int> > ord;
map<ll, int> mp;
vector<int> g[maxn];

inline void dfs(int u, int p){
	dis[u] = 0;
	//printf("u = %d sz = %d\n", u, sz[u]);
	FOR(i, 0, g[u].size()){
		int v = g[u][i];
		if(v == p) continue;
		dfs(v, u);
		dis[u] += dis[v] + sz[v];
	}
	return;
}

int main(){
	scanf("%d", &n);
	FOR(i, 0, n){
		scanf("%lld", a + i);
		ord.PB(MP(a[i], i));
		mp[a[i]] = i;
	}
	sort(ord.begin(), ord.end());
	FOR(i, 0, n) sz[i] = 1;
	for(int i = ord.size() - 1; i >= 0; --i){
		int u = ord[i].snd;
		ll d = ord[i].fst;
		//printf("i = %d\n", i);
		if(!i){
			dfs(u, -1);
			if(dis[u] != d){
				//FOR(i, 0, n) printf("%lld ", dis[u]); puts("");
				//printf("::%lld %lld\n", dis[u], d);
				puts("-1");
				return 0;
			}
			break;
		}
		//printf("%lld %lld\n", d, d - n + sz[u] * 2);
		if(mp.find(d - n + sz[u] * 2) != mp.end()){
			int p = mp[d - n + sz[u] * 2];
			//printf("p = %d u = %d\n", p, u);
			sz[p] += sz[u];
			g[p].PB(u);
			g[u].PB(p);
		}
		else{
			puts("-1");
			return 0;
		}
	}
	FOR(u, 0, n) FOR(i, 0, g[u].size()){
		int v = g[u][i];
		if(u < v) printf("%d %d\n", u + 1, v + 1);
	}
	return 0;
}

Measured memory_bytes: 18672
/*
      author : nishi5451
      created: 11.08.2020 01:04:38
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int x,t;
    cin >> x >> t;
    if(x < t) cout << 0 << endl;
    else cout << x-t << endl;
    return 0;
}

Measured memory_bytes: 3564
N = gets.to_i
S = gets.chomp
ans = 0
for i in 1..N do
  a = 0
  s1 = S.slice(0,i)
  s2 = S.slice(i,N-i)
  while s1.size > 0
    char = s1[0]
    a += s2.include?(char) ? 1 : 0
    s1.delete!(char)
  end
  ans = [a, ans].max
end
puts ans

Measured memory_bytes: 1788
import math

N = int(input())
M = int(N**0.5//1)
S = list()
for i in range(M+1):
    if i > 0 :
       if N%i == 0:
           S.append(i)
a =  S[-1]
b = N//a
print(max(len(str(a)),len(str(b))))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long eor(int n,long X){
    if(X==-1){
        return 0;
    }
	long sum=0;
    long s=(1LL<<n),t=(1LL<<n+1);
	sum+=(X/t)*s;
	long a=X%t;
	if(a>=s){
		sum+=a-s+1;
	}return sum;
}
int main(){
	long A,B;cin>>A>>B;
	const int S=40;
	long result=0;
	for(int i=0;i<S;i++){
		result+=((eor(i,B)-eor(i,A-1))%2)*(1LL<<i);
	}cout<<result<<endl;
}

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

int main(int argc, char const *argv[])
{
    double X;
    cin>>X;
    double p = 100;
    double counter = 0;
    long long amount = 100;
    while(X>amount){
        amount = (amount * 1.01);
        counter++;
    }
    cout<<counter<<"\n";
    return 0;
}


Measured memory_bytes: 3788
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    string s,t;
    cin >> s >> t;
    rep(i,s.size()){
        if(s[i]!=t[i]){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 3064
#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 A, B, C, X, Y;

int main() {
  // A,B,C円
  // AピザをX枚，BピザをY枚

  cin >> A >> B >> C >> X >> Y;

  int res[3];
  //res = A * X + B * Y;

  res [0] = A * X + B * Y;
  res [1] = A * max(0,X-Y) + C * 2*Y;
  res [2] = B * max(0,Y-X) + C * 2*X;
  

  cout << min({res[0],res[1],res[2]}) << endl;
}


Measured memory_bytes: 256
n, k = input().split()
sunuke = {}

for i in range(1, int(n)+1):
  sunuke[i] = sunuke.get(i, 0)

for i in range(0, int(k)):
  okashi = input()
  mochi = list(map(int, input().split()))
  for j in range(0, len(mochi)):
    sunuke[mochi[j]] += 1

count = 0
for key, value in sunuke.items():
    if value == 0:
        count += 1
print(count)

Measured memory_bytes: 9192
n, m = map(int, input().split())
l1 = [0]*n
l2 = [0]*n

for i in range(m):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  if a == 0:
    l1[b] = 1
  elif b == n-1:
    l2[a] = 1
  else:
    continue

for j in range(n):
  if l1[j] == 1 and l2[j] == 1:
    print('POSSIBLE')
    exit()
else:
  print('IMPOSSIBLE')
  


Measured memory_bytes: 49112
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
flag = True
Sum = 0 
for i in range(N-1):
    for j in range(i+1, N):
        f = True
        for k in range(N):
            if k == i or k == j:
                continue
            if A[i][k] + A[k][j] < A[i][j]:
                flag = False
            elif A[i][k] + A[k][j] == A[i][j]:
                f = False
        if f:
            Sum += A[i][j]
if flag:
    print(Sum)
else:
    print(-1)

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

string num;

int ctoi(char c){
    return c - '0';
}


int calc(string S){
    int sum = 0;
    stack<int> stk;
    for(int i = S.length()-1;i>=0;i--){
        if(S[i] == '+'){
            sum += stk.top();
            stk.pop();
        }else if(S[i] == '-'){
            sum -= stk.top();
            stk.pop();
        }else{
            stk.push(ctoi(S[i]));
        }
    }
    sum += stk.top();
    stk.pop();
    return sum;
}

bool dfs(int i,string S){
    if(i == 4){
        if(calc(S) == 7){
            cout << S + "=7" << endl;
            return true;
        }
        return false;
    }else{
        if(dfs(i+1,S + "+" + num[i])) return true;
        if(dfs(i+1,S + "-" + num[i])) return true;
    }
    return false;
}

int main(){
    cin >> num;
    string S = {num[0]};
    dfs(1,S);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;

int main(){
    int n;cin>>n;
    vector<int> v(100003);
    while(n--){
        int a;cin>>a;
        v[a]++;
        v[a+1]++;
        v[a+2]++;
    }
    cout<<MAX(v)<<endl;
    return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define Set(x, i) memset(x, i, sizeof x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define R register
#define For(i, j, k) for(R int i = (j), ED = (k); i <= ED; ++i)
#define Rep(i, j, k) for(R int i = (j), ED = (k); i >= ED; --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 200011;
const ll INF = 5e16;

namespace IO {
	
	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) + 
			fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}
	
	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; int f = 0; char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd
	
	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}
	
	inline void wrn ( ll x ) { write(x), putchar(' '); }
	
	inline void wln ( ll x ) { write(x), putchar('\n'); }
	
	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }
	
}

using IO::wln;
using IO::read;

namespace Cesare {
	
	/*
		ÌâÒâ×ª»¯£º¸ø³öÒ»¶Ñ ai, bi £¬ 
		¶ÔÆä½øÐÐ·ÖÅäÊ¹×ÜºÍ×îÐ¡¡£ 
	*/
	
	ll cc;
	ll n, Ans, a[N], b[N], Vis[N];
	
	struct Node {
		ll x, sx, id;
	} K[N];
	
	inline bool cmp (Node a, Node b) {
		return a.x < b.x;
	}
	
	int F1 = 1;
	
namespace Subtask1 {
	
	inline void Solve() {
		ll S = 0;
		For ( i, 1, n ) 
			S += min(a[i], b[i]);
		wln(S), exit(0);
	}
	
}
	
namespace Subtask2 {
	
	/*
		Éè f[i][S] ±íÊ¾µ±Ç°ÔÚ i µã¼¯×´Ì¬Îª S µÄ×îÐ¡»·¡£ 
	*/
	
	const ll N = 17;
	
	ll f[N][(1 << 15) + 3];
	
	inline void Cmin ( ll &a, ll b ) { (a > b) && (a = b); }
	
	inline void Solve() {
		ll Ans = INF;
		ll Max = (1 << n) - 1;
		For ( i, 1, n ) {
			Set (f, 0x3f);
			f[i][1 << i - 1] = 0;
			For ( S, 0, Max ) For ( j, 1, n ) 
				if (S & (1 << j - 1)) For ( k, 1, n ) 
					if (!(S & (1 << k - 1))) 
						Cmin(f[k][S | (1 << k - 1)], f[j][S] + min(a[j], b[k]));
			For ( j, 1, n ) if (j != i) 
				Cmin(Ans, f[j][Max] + min(a[j], b[i]));
		} wln(Ans), exit(0);
	}
	
}

namespace Subtask {

	int F = 0;
	ll cc, Ansa, Ansb, Ans;

	struct Node {
		ll x, id, sx;
	} K[N];

	inline bool cmp (Node a, Node b) {
		return a.x < b.x;
	}

	inline void Solve() {
		For ( i, 1, n ) 
			Ansa += a[i], Ansb += b[i], 
			K[++cc] = (Node) {a[i], i, 0},
			K[++cc] = (Node) {b[i], i, 1}; 
		sort(K + 1, K + 2 * n + 1, cmp);
		For ( i, 1, n ) {
			Ans += K[i].x;
			if (Vis[K[i].id]) F = 1;
			Vis[K[i].id] = 1;
		} 
		if (!F) {
			ll res = INF;
			For ( i, n + 1, n << 1 ) {
				if (K[n].sx != K[i].sx && K[i].id == K[n].id) 
					res = min(res, K[i].x - K[n - 1].x);
				else res = min(res, K[i].x - K[n].x);
			} Ans += res;
		} wln(min(Ans, min(Ansa, Ansb))), exit(0);
	}

}

	int main() {
		n = read();
		For ( i, 1, n ) 
			a[i] = read(), b[i] = read();
		For ( i, 1, n ) F1 &= a[1] == a[i];
		
		if (F1) Subtask1 :: Solve();
		if (n <= 15) Subtask2 :: Solve();
		else Subtask :: Solve(); return 0;
	}
	
}

int main()
{
	return Cesare :: main();
}

/*
4
1 5
2 6
3 7
4 8

6
19 92
64 64
78 48
57 33
73 6
95 73
*/





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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}
template<class T>
void print_array(T a[],size_t n){
  cerr<<"array:";
  REP(n-1)cerr<<a[i]<<",";
  cerr<<a[n-1]<<endl;
}

int N;
int V[100000];
map<int,int> even,odd;
vector<pair<int,int>> e,o;


int main(){
  cin>>N;
  REP(N)cin>>V[i];
  for (int i = 0; i < N; i+=2) {
    if(odd.find(V[i])==odd.end()){
      odd[V[i]]=1;
    }else{
      odd[V[i]]++;
    }
  }
  for (int i = 1; i < N; i+=2) {
    if(even.find(V[i])==even.end()){
      even[V[i]]=1;
    }else{
      even[V[i]]++;
    }
  }
  for(auto tmp:odd){
    pair<int,int> t;
    t.first=tmp.second;
    t.second=tmp.first;
    o.push_back(t);
  }
  for(auto tmp:even){
    pair<int,int> t;
    t.first=tmp.second;
    t.second=tmp.first;
    e.push_back(t);
  }
  sort(o.begin(),o.end());
  sort(e.begin(),e.end());
  int ans=N;
  if(o.back().second==e.back().second){
    if(o.size()==1){
      ans-=o.back().first;
    }else{
      int tmp=max(o[o.size()-2].first+e[e.size()-1].first,o[o.size()-1].first+e[e.size()-2].first);
      ans-=tmp;
    }
  }else{
    ans-=(o.back().first+e.back().first);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 6520
#include <iostream>
#include <iomanip>
#include <cmath>
#include <map>

using namespace std;

int main()
{
    int N;
    cin >> N;
    map<int, pair<int, int>> city;
    for (int i = 0; i < N; i++)
    {
        int x, y;
        cin >> x >> y;
        city[i] = make_pair(x, y);
    }
    double sum{};
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            sum += sqrt(pow(city[i].first - city[j].first, 2.0) + pow(city[i].second - city[j].second, 2.0));
        }
    }
    double ans{sum * 2 / N};
    cout << fixed << setprecision(10) << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author EDGE
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BEasyLinearProgramming solver = new BEasyLinearProgramming();
        solver.solve(1, in, out);
        out.close();
    }

    static class BEasyLinearProgramming {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int a, b, c, d;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            if (d <= a) {
                out.println(d);
                return;
            }

            d = d - a;
            if (d - b <= 0) {
                out.println(a);
                return;
            }
            d = d - b;
            out.println(a - d);

        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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


int main() {
	int s,tmp,count=1;
	cin >> s;
	
	map<int, int> score;
	score[s] = 1;
	tmp = s;
	while (true)
	{
		if (tmp%2==0)
		{
			tmp /= 2;
		}
		else {
			tmp = 3 * tmp + 1;
		}
		count++;
		if (score[tmp])
		{
			break;
		}else{
			score[tmp] = 1;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 3500
A, B, C, X, Y = map(int, input().split())

cost1 = A * X + B * Y
cost2 = C * max([X, Y]) * 2

if X > Y:
    cost3 = C * Y * 2 + A * (X - Y)
else:
    cost3 = C * X * 2 + B * (Y - X)

print(min([cost1, cost2, cost3]))


Measured memory_bytes: 2940
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}


const int MAX = 10000000 ;
// UFTクラスを宣言するときはグローバル変数か、staticをつけて静的変数にすること
class UFT{
public :
	int par[MAX] ;
	int rank[MAX] ;
	int size[MAX] ;
	bool root[MAX] ;
	int tree ;

	void init(int n){
		for(int i=0;i<n;i++){
			par[i] = i ;
			rank[i] = 0 ;
			size[i] = 1 ;
			root[i] = true ;
		}
		tree = n ;
	}

	int find(int x){
		if(par[x]==x) return x ;
		return par[x] = find(par[x]) ;
	}

	void unite(int x,int y){
		x = find(x) ;
		y = find(y) ;
		if(x==y){
			if(root[x]){
				root[x] = false ;
				tree-- ;
			}
			return ;
		}
		if(rank[x]<rank[y]){
			par[x] = y ;
			size[y] += size[x] ;
			if(root[x]){
				root[x] = false ;
				tree-- ;
			}
		}else{
			par[y] = x ;
			size[x] += size[y] ;
			if(rank[x]==rank[y]) rank[x]++ ;
			if(root[y]){
				root[y] = false ;
				tree-- ;
			}
		}
	}

	bool same(int x,int y){
		return find(x)==find(y) ;
	}
};

int main(){
	ll n,m ;
	cin >> n >> m ;
	vector<pll> e(m) ;
	for(int i=0;i<m;i++){
		ll a,b ;
		cin >> a >> b ;
		a-- ;
		b-- ;
		e.at(i).first = a ;
		e.at(i).second = b ;
	}
	reverse(all(e)) ;
	vll ans(m+1,0) ;
	ans.at(0) = n*(n-1)/2 ;
	static UFT uft ;
	uft.init(n) ;
	for(int i=0;i<m;i++){
		ll sub = 0 ;
		if(!uft.same(e.at(i).first,e.at(i).second)){
			sub = uft.size[uft.par[e.at(i).first]]*uft.size[uft.par[e.at(i).second]] ;
//			cout << i << " " << uft.size[e.at(i).first] << " " << uft.size[e.at(i).second] << endl ;
			uft.unite(e.at(i).first,e.at(i).second) ;
		}
		ans.at(i+1) = ans.at(i)-sub ;
	}
	reverse(all(ans)) ;
	for(int i=1;i<=m;i++) cout << ans.at(i) << endl ;
}


Measured memory_bytes: 6880
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (b%a ? b-a : a+b) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN 10

int maxx, maxy, k;
int a[MAXN][MAXN];
int b[MAXN][MAXN];

int main() {
	cin >> maxx >> maxy >> k;
	for (int i = 0; i < maxx; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < maxy; j++) {
			if (s[j] == '#') {
				a[i][j] = 1;
			}
		}
	}
	int ret = 0;
	for (int maskx = 0; maskx < (1 << maxx); maskx++) {
		for (int masky = 0; masky < (1 << maxy); masky++) {
			memset(b, 0, sizeof(b));
			for (int i = 0; i < maxx; i++) {
				if (maskx & (1 << i)) {
					for (int j = 0; j < maxy; j++) {
						b[i][j] = 1;	
					}
				}
			}
			for (int j = 0; j < maxy; j++) {
				if (masky & (1 << j)) {
					for (int i = 0; i < maxx; i++) {
						b[i][j] = 1;
					}
				}
			}
			int cnt = 0;
			for (int i = 0; i < maxx; i++) {
				for (int j = 0; j < maxy; j++) {
					if (a[i][j] && !b[i][j]) {
						cnt++;
					}
				}
			}
			if (cnt == k) {
				ret++;
			}
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3632
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
        Set<Integer> list = new HashSet<>();
        Collections.addAll(list, a, b, c);
    
		// 出力
		System.out.println(list.size());
	}
}

Measured memory_bytes: 21716