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

int main() {
 
  int A, B, C;
  cin >> A >> B >> C;

  if (A == B) {
    cout << C << endl;
  } else if (B == C) {
    cout << A << endl;
  } else {
    cout << B << endl;
  }

}

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

int main() {
  int D, N;
  cin >> D >> N;
  
  int ans=1;
  while(D>0){
    ans *=100;
    D--;
  }
  if(N==100)N=101;
  cout << ans*N << endl;
}


Measured memory_bytes: 3588
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int[] coin = {500,100,50,10,5,1};
		while (sc.hasNext()) {
			int n = sc.nextInt();
			if (n == 0) break;
			int change = 1000 - n;
			int num = 0;
			for (int i=0; i<6; i++) {
				while (change >= coin[i]) {
					change -= coin[i];
					num++;
				}
			}
			out.println(num);
		}
	}
}


Measured memory_bytes: 26144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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 () {
  int a, b, c;
  cin >> a >> b >> c;
  string ans = "No";
  if (a == b && a != c) ans = "Yes";
  if (a == c && a != b) ans = "Yes";
  if (b == c && b != a) ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

#define rep(i,n) for(long long i=0;i<n;i++)
using namespace std;



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

	vector<int> A(N);
	rep(i, N) cin >> A[i];

	vector<int> g;

	rep(i, N)
	{
		if (A[i] % 2 == 0)
		{
			g.push_back(A[i]);
		}
	}

	bool temp = true;

	rep(i, g.size())
	{
		if (g[i] % 3 != 0 && g[i] % 5 != 0)
		{
			temp = false;
		}
	}

	cout << (temp ? "APPROVED":"DENIED")<<endl;
	
	return 0;
}




Measured memory_bytes: 256
n, a, b = map(int, input().split())
if abs(b - a) & 1:
    l = (a - 1) + (b - 1) + 1
    r = (n - a) + (n - b) + 1
    x = min(l, r)
else:
    x = abs(b - a)
print(x // 2)


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

int pivot(int *a,int i,int j){
  int k=i+1;
  while(k<=j && a[i]==a[k]) k++;
  if(k>j) return -1;
  if(a[i]>=a[k]) return i;
  return k;
}

int partition(int *a,int i,int j,int x){
  int l=i,r=j;

  while(l<=r){
    while(l<=j && a[l]<x)  l++;
    while(r>=i && a[r]>=x) r--;
    if (l>r) break;
    int t=a[l];
    a[l]=a[r];
    a[r]=t;
    l++; r--;
  }
  return l;
}

void quickSort(int *a,int i,int j){
  if(i==j) return;
  int p=pivot(a,i,j);
  if(p!=-1){
    int k=partition(a,i,j,a[p]);
    quickSort(a,i,k-1);
    quickSort(a,k,j);
  }
}

int main() {
  int i, n;
  int *d;
  scanf("%d", &n);
  d = malloc(sizeof(int)*n);
  for (i=0; i<n; i++) {
    scanf("%d", d+i);
  }
  quickSort(d, 0, n-1);
  printf("%d\n", d[n/2]-d[n/2-1]);
  return 0;
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	a := readInt()
	b := readInt()
	println((a - 1) * (b - 1))
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll N, K;
vector<ll> vec;

void solve() {
	cin >> N >> K;
	vec.resize(N);
	rep(i, N) cin >> vec[i];

	vector<ll> right_sum(N);
	vector<ll> left_sum(N);

	rep(i, N) {
		if (i == 0) {
			right_sum[i] = vec[i];
			left_sum[N - 1 - i] = vec[vec.size() - 1];
		}
		else {
			right_sum[i] = right_sum[i - 1] + vec[i];
			left_sum[N - 1 - i] = left_sum[N - i] + vec[N - 1 - i];
		}
	}

	ll ans = 0;

	for (int R = 0; R <= N; R++) {
		for (int L = 0; L <= N - R; L++) {
			if (R + L > K) continue;
			if (L + R == 0) continue;

			priority_queue<int, vector<int>, greater<int> > PQ;
			for (int i = 0; i < R; i++) PQ.push(vec[i]);
			for (int i = 0; i < L; i++) PQ.push(vec[N - 1 - i]);

			for (int i = 0; i < K - R - L; i++) {
				if (PQ.size() == 0) break;
				if (PQ.top() > 0) break;
				PQ.pop();
			}

			ll tmp = 0;
			while (PQ.size() != 0) {
				tmp += PQ.top();
				PQ.pop();
			}

			ans = max(ans, tmp);

		}
	}

	cout << ans;

}

int main() {
	solve();
	cout << 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++)
typedef long long int ll;
template<typename T> T changeMax(T& a, T b){if(a < b)a = b;return 0;}

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(a, max(b, c))-min(a, min(b, c)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N;cin>>N;
  int U[110]={0},D[110]={0};
  for(int t=1;t<=N;t++){
    int a;cin>>a;
    U[t]+=a+U[t-1];
  }
  for(int t=1;t<=N;t++){
    int b;cin>>b;
    D[t]+=b+D[t-1];
  }

  int ans=0;
  for(int t=1;t<=N;t++){
    int sum=0;
    sum=U[t]+D[N]-D[t-1];
    ans=max(ans,sum);
  }

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


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a[10];
	int i, j, max;
	
	for(i = 0; i < 10; i++)
	  scanf("%d", &a[i]);
	
	for(i = 0; i < 3; i++){
		max = 0;
	    for(j = 0; j < 10; j++){
	      if(a[max] < a[j])
	        max = j;
	    }
	    printf("%d\n", a[max]);
	    a[max] = 0;
	}
    
    return 0;
}

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

int main()
{
char s[101] ;
scanf("%s",s);
int l = strlen(s);
int w=l-1,c=0;
for(int i=0 ; i<l; i++)
{
    if(s[i] != s[w]) c++;
    w--;
}
printf("%d",c/2);
    return 0;
}


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

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(long long e){
        long long a = 1, p = x;
        while(e > 0) {
            if (e & 1) {a = (a * p) % mod; e--;}
            else {p = (p * p) % mod; e /= 2;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

template<int mod> struct Combination {
    vector<ModInt<mod>> fact, ifact;
    Combination(int n) : fact(n+1), ifact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i);
        ifact[n] = fact[n].inverse();
        for (int i = n; i > 0; i--) ifact[i - 1] = ifact[i] * i;
    }
    ModInt<mod> operator() (int n, int r) {
        if (r < 0 or r > n) return 0;
        return fact[n] * ifact[n-r] * ifact[r];
    }
    const ModInt<mod> &operator[] (int i) const {
        return fact[i];
    }
};

constexpr int MOD = 1000000007;
constexpr int MAX = 1000100;

int main() {
	Combination<MOD> binom(MAX);
	int n, k;
	cin >> n >> k;
	
	if (n < k) {
		cout << 0 << '\n';
		return 0;
	}
	
	ModInt<MOD> ans = 0;
	for (int i = 0; i <= k; i++) {
		ModInt<MOD> res = binom(k, i) * ModInt<MOD>(i).pow(n);
		if ((k - i) & 1) ans -= res;
		else ans += res;
	}
	
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 10580
#include<iostream>;
using namespace std;
int main() {
	int H, W, i, j;
	while (1) {
		cin >> H >> W;
		if (W == 0 && H == 0)break;
		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n = II()
    ans = 0
    for i in range(1, n+1):
        if i % 3 != 0 and i % 5 != 0 and i % 15 != 0:
            ans += i

    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9208
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();

        int nSubInt = Integer.parseInt(n.substring(n.length() - 1));

        String ans = new String();

        switch (nSubInt) {
            case 2:
            case 4:
            case 5:
            case 7:
            case 9:
                ans = "hon";
                break;
            case 0:
            case 1:
            case 6:
            case 8:
                ans = "pon";
                break;
            case 3:
                ans = "bon";
            default:
                break;
        }

        System.out.println(ans);
    }
}


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

N = int(input())
A = [int(x) for x in input().split()]

A.append(1)

B = [A[0]]
B_cnt = [1]
for i,(x,y) in enumerate(zip(A[:-1],A[1:])):
    if x < y and y < A[i+2]:
        continue
    if x == y:
        B_cnt[-1] += 1
    else:
        B.append(y)
        B_cnt.append(1)

def test(x):
    digit = [0]
    cnt = [0]
    for a,a_cnt in zip(B,B_cnt):
        if digit[-1] < a:
            digit.append(a)
            cnt.append(a_cnt)
            continue
        if digit[-1] == a:
            cnt[-1] += a_cnt
            continue
        while True:
            # 繰り上がり処理をしながら左に戻る
            if digit[-1] <= a:
                break
            n = digit.pop()
            k = cnt.pop()
            if k <= x:
                continue
            if digit[-1] == n-1:
                cnt[-1] += (k-1)//x
            else:
                digit.append(n-1)
                cnt.append((k-1)//x + 1)
        if digit[-1] == a:
            cnt[-1] += a_cnt
        else:
            digit.append(a)
            cnt.append(1+a_cnt)
    return cnt[1] <= x+1

if all(x<y for x,y in zip(A[:-2],A[1:-1])):
    print(1)
    exit()

left = 1 # 無理
right = 10 # 可能?
while not test(right):
    left *= 10
    right *= 10
right = min(right,N)
while right > left + 1:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

answer = right
print(answer)

Measured memory_bytes: 25168
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string o, e;
	cin >> o >> e;
	rep(i, o.size()){
		cout << o[i];
		if(i < e.size()){
			cout << e[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        w: i32,
        h: i32,
        x: i32,
        y: i32,
        r: i32,
    }

    if x < r || y < r || x > w - r || y > h - r {
        println!("No");
    } else {
        println!("Yes");
    }
}



Measured memory_bytes: 5024
import sys
sys.setrecursionlimit(1000000)
def main():
  _map = map
  _input = input
  _int = int
  def calc_results(values, links, i, p):
    for j in links[i]:
      if j == p:
        continue
      values[j] += values[i]
      calc_results(values, links, j, i)
  n, q = _map(_int, _input().split())
  values = [0] * (n + 1)
  links = [[] for _ in range(n + 1)]
  for _ in range(n - 1):
    a, b = _map(_int, _input().split())
    links[a].append(b)
    links[b].append(a)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p] += x
  calc_results(values, links, 1, 0)
  print(*values[1:])
main()


Measured memory_bytes: 268436
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

void canP(bool x){
    if(x){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
}
int main(){
    int a,b,t; cin >> a >> b >> t;
    cout << int((t + 0.5)/a) * b << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
void swap(long int *x,long int *y){
	long int tmp;
	tmp=*x;
	*x=*y;
	*y=tmp;
	}
long int gcd(long int x,long int y){
	if(x<y) swap(&x,&y);
	if(x%y!=0) return gcd(y,x%y);
	return y;
	}
int main(){
	long int a,b,c;
	scanf("%ld %ld",&a,&b);
	c=gcd(a,b);
	printf("%ld\n",c);
	return 0;
	}



Measured memory_bytes: 2080
package main

import (
	"fmt"
	"os"
	"strings"
)

var (
	s string
)

func main() {
	fmt.Scan(&s)

	for i := 0; i < len(s); i++ {
		if strings.Contains(s[i+1:], string(s[i])) {
			fmt.Println("no")
			os.Exit(0)
		}
	}

	fmt.Println("yes")
}

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

int main() {
	string s, t;
	cin >> s >> t;
	int ss[26] = {}, tt[26] = {};
	for (int i = 0;i < s.size();i++) {
		ss[s[i] - 'a']++;
		tt[t[i] - 'a']++;
	}
	sort(ss, ss + 26);
	sort(tt, tt + 26);
	for (int i = 0;i < 26;i++) {
		if (ss[i] != tt[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

using namespace std;

int main()
{
    long long A, B, K;
    cin >> A >> B;

    for (K = 0; K < 1000000000; K++)
    {
        if (abs(A-K) == abs(B-K)) {
            cout << K << endl;
            return 0;
        } 
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 256
/// <reference path="lib.ts" />
function main(input) {
    var n = +input.shift();
    var a = [];
    for (var i = 0; i < n; ++i)
        a.push(+input.shift());
    var ans = [];
    ans.push(_.min(a));
    ans.push(_.max(a));
    ans.push(_.sum(a));
    console.log(ans.join(' '));
}
/// <reference path="node.d.ts" />
/// <reference path="main.ts" />
(function () {
    process.stdin.resume();
    process.stdin.setEncoding('utf8');
    var input = '';
    process.stdin.on('data', function (chunk) {
        input += chunk;
    });
    process.stdin.on('end', function (chunk) {
        main(input.split(/\s+/));
    });
})();
// based on lodash
var _;
(function (_) {
    function min(a) {
        return Math.min.apply(Math, a);
    }
    _.min = min;
    function max(a) {
        return Math.max.apply(Math, a);
    }
    _.max = max;
    function reduce(a, func, init) {
        var result = init;
        for (var i = 0; i < a.length; ++i)
            result = func(result, a[i]);
        return result;
    }
    _.reduce = reduce;
    function sum(a) {
        return reduce(a, function (result, v) { return result + v; }, 0);
    }
    _.sum = sum;
})(_ || (_ = {}));

Measured memory_bytes: 17860
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int time = Integer.parseInt(sc.next());
        int h = time / 60 / 60;
        int m = time / 60 % 60;
        int s = time % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26320
#include<iostream>
#include<stdio.h>
using namespace std;
int n,v,son,snum,lft,dep[101000],root;
struct tree
{
	int p,l,r;
	tree():p(-1),l(-1),r(-1){}
};
tree t[101000];
void setd(int n,int d)
{
	dep[n]=d;
	if(t[n].l!=-1)setd(t[n].l,d+1);
	if(t[n].r!=-1)setd(t[n].r,d);
}
string typ(int x)
{
	if(t[x].p==-1)return "root";
	else if(t[x].l==-1)return "leaf";
	else return "internal node";
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>v>>snum;
		for(int j=1;j<=snum;j++)
		{
			cin>>son;
			t[son].p=v;
			if(j==1)t[v].l=son;
			else t[lft].r=son;
			lft=son;
		}
	}
	for(int i=0;i<n;i++)if(t[i].p==-1)root=i;
	setd(root,0);
	for(int i=0;i<n;i++)
	{
		printf("node %d: parent = %d, depth = %d, %s, [",i,t[i].p,dep[i],typ(i).c_str());
		if(t[i].l!=-1)
		{
		cout<<t[i].l;
		int temp=t[i].l;
		while(t[temp].r!=-1)
		{
			temp=t[temp].r;
			cout<<", "<<temp;
		}
		}
		cout<<"]"<<endl;
	}
}


Measured memory_bytes: 4860
from collections import defaultdict


M, D = list(map(int, input().rstrip().split()))

prod_set = defaultdict(lambda: 0)
for d in range(1, D + 1):
    if d >= 10:
        d1 = d % 10
        d10 = int((d - d1) / 10)
        if d1 >= 2 and d10 >= 2:
            m = d1 * d10
            prod_set[m] += 1

res = 0
for m in range(1, M + 1):
    if m in prod_set:
        res += prod_set[m]
print(res)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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() {
	int n,m,x;
	cin >> n >> m >> x;
	vector<int> c(n);
	vector<vector<int>> a(n,vector<int>(m));
	rep(i,n) {
		cin >> c[i];
		rep(j,m) {
			cin >> a[i][j];
		}
	}
	ll mini = 1e18;
	rep(i,1<<n) {
		ll sum = 0;
		vector<int> v(m,0);
		rep(j,n) {
			if((i>>j) & 1) {
				sum += c[j];
				rep(k,m) {
					v[k] += a[j][k];
				}
			}
		}
		rep(j,m) {
			if(v[j] < x) break;
			if(j == m-1) chmin(mini, sum);
		}
	}
	if(mini == 1e18) mini = -1;
	cout << mini << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for(int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  int ans = 1;
  
  for(int i = 0; i < N; i++) {
    if(i < N - 1) {
      if(vec.at(i + 1) - vec.at(i) != 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
//20190913 22:00
//PCK2016
//F_Naru
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
#define N 1000000007

int calc[1001][1001];

int main() {
  string str;
  string key;
  cin >> str >> key;
  //準備
  for(int i=0; i<=str.size(); i++) {
    calc[i][0] = 1;
  }
  //計算
  for(int i=1; i<=key.size(); i++) {
    for(int j=1; j<=str.size(); j++) {
      if(str[j-1] == key[i-1]) {
        calc[j][i] += (calc[j-1][i-1])%N;
      }
      calc[j][i] += (calc[j-1][i])%N;
    }
  }
  cout << (calc[str.size()][key.size()])%N << endl;
}



Measured memory_bytes: 7072
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	int N, L;
	cin >> N >> L;
	vector<string> vec;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		vec.push_back(s);
	}
	sort(vec.begin(), vec.end());
	for (int i = 0; i < vec.size(); i++) cout << vec[i];
	cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> //required
//#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define lb long double
#define pb push_back
#define loop(i,start,n) for(ll i=start;i<n;i++)
#define rloop(i,n,start)for(ll i=n;i>=start;i--)
#define mod 1000000007
#define endl "\n"
#define INF     1e15
#define NEG_INF -1e15
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//using namespace __gnu_pbds;
vector<vector<ll> > vect(200010 + 1);
ll visited[200010], found = 0, start = -1;
vector<ll> cycle, path;
void dfs(ll node){
	if(visited[node] == 2)
		return ;
	if(visited[node] == 1){
		found = 1, start = node;
		return ;
	}
	visited[node] = 1;
	for(auto &child : vect[node]){
		dfs(child);
		if(found){
			if(node == start){
				cycle.pb(node);
				start = -1;
				return ;
			}
			if(start != -1)
				cycle.pb(node);
			else
				path.pb(node);
			return ;
		}
	}
	visited[node] = 2;

}
int main(){
	IOS;
	ll n, k ;
	cin >> n >> k;
	ll a[n + 1];
	loop(i, 1, n + 1){
		cin >> a[i];
		vect[i].pb(a[i]);
	}

	dfs(1);
	reverse(all(cycle));
	reverse(all(path));
	if(k <path.size()){
		cout<< path[k] << endl;
		return 0;
	}
	debug(path, cycle);
	k -= path.size();
	debug(k);
	k %=cycle.size();
	cout << cycle[k] << endl;
}


Measured memory_bytes: 28544
import copy
n = int(input())
v = input().split()

x = []
y = []

for i in range(n):
    if i % 2 == 0:
        x.append(v[i])
    else:
        y.append(v[i])

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j])
        countx = 1
    elif x[j - 1] != x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k])
        county = 1
    elif y[k - 1] != y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county = 1
s2 = copy.deepcopy(s)
t2 = copy.deepcopy(t)
#a = [int(m) for m in a]
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

ssym = 0
for i in s2:
    if sc == -1:
        sk = i
    elif sc == 0:
        sk = i
        ssym = 1
        break
    sc += 1
if sc == 0 and ssym == 0:
    sk = 0

tsym = 0
for i in t2:
    if tc == -1:
        tk = i
    elif tc == 0:
        tk = i
        tsym = 1
        break
    tc += 1
if tc == 0 and tsym == 0:
    tk = 0

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)


Measured memory_bytes: 13556
#include<bits/stdc++.h>
using namespace std;
#define MAXN 16
#define LL long long int
#define INF (1LL << 62)

int N, a[MAXN + 3][MAXN + 3];
LL dp[(1 << MAXN) + 3], score[(1 << MAXN) + 3];

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

    //precompute match score
    for (int mask = 0; mask < (1 << N); mask++) {
        score[mask] = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if ((mask & (1 << i)) > 0 && (mask & (1 << j)) > 0)
                    score[mask] += a[i][j];
            }
        }
    }

    dp[0] = 0;
    for (int mask = 1; mask < (1 << N); mask++) {
        dp[mask] = -INF;
        for (int submask = mask; submask > 0; submask = (submask - 1)&mask)
            dp[mask] = max(dp[mask], score[submask] + dp[mask ^ submask]);
    }

    cout << dp[(1 << N) - 1] << endl;    
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define int long long
// friendship: consider connected. for each cc, find cc-adjacant-cc and blocked
const int MX = 1e5+2;
vector<int> adj[MX];
vector<int> block[MX];
vector<int> cc;
int ans[MX];
bool seen[MX];
void dfs(int i) {
	if(seen[i])
		return;
	cc.push_back(i);
	seen[i] = 1;
	for(int a: adj[i]) {
		dfs(a);
	}
}
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	for(int i=0; i<m; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for(int i=0; i<k; i++) {
		int c, d;
		cin >> c >> d;
		block[c].push_back(d);
		block[d].push_back(c);
	}
	for(int i=1; i<=n; i++) {
		if(!seen[i]) {
			cc.clear();
			dfs(i);
			sort(cc.begin(), cc.end());
			for(int p: cc) {
				int cnt = 0;
				for(int b: block[p]) {
					if(binary_search(cc.begin(), cc.end(), b))
						cnt++;
				}
				ans[p] = cc.size() - adj[p].size() - cnt;
			}
		}
	}
	for(int i=1; i<=n; i++)
		cout << ans[i]-1 << ' ';
}

Measured memory_bytes: 15224
#include <stdio.h>

long long int sigma(long long int n){
    return n * (n + 1) / 2;
}
int main(void){
    char S[600000];

    scanf("%s", S);

    int ns[600000], flgs[600000];
    long long int sums[600000];
    int i = 1;
    int prev_i = 0;
    int j = 0;

    while(1){
        if(S[i-1] == '>' && S[i] == '<'){
            ns[j] = (i - prev_i);
            sums[j] = sigma(i - prev_i);
            prev_i = i;
            flgs[j] = 0;
            j ++;
        }else if(S[i-1] == '<' && S[i] == '>'){
            ns[j] = (i - prev_i);
            sums[j] = sigma(i - prev_i);
            prev_i = i;
            flgs[j] = 1;
            j ++;
        }else if(S[i] == '\0'){
            ns[j] = (i - prev_i);
            sums[j] = sigma(i - prev_i);
            prev_i = i;
            j ++;

            break;
        }
        i ++;
    }
    long long int sum = 0;

    for(i = 0; i < j; i ++){
        sum += sums[i];
    }
    for(i = 0; i < j - 1; i ++){
        if(flgs[i] == 1){
            if(ns[i] < ns[i + 1]){
                sum -= ns[i];
            }else{
                sum -= ns[i + 1];
            }
        }
    }
    printf("%lld\n", sum);
}

Measured memory_bytes: 9088
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define int long long
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (ll i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((ll)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <ll, ll> pii ;
typedef vector <ll> vi ;
typedef vector <pii> vii ;
typedef queue <ll> qi ;
typedef queue <pii> qii ;
typedef set <ll> si ;
typedef map <ll, ll> mii ;
typedef map <string, ll> msi ;
const ll maxn = 5e3 + 100 ;
const ll inf = 0x3f3f3f3f ;
const ll iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 998244353 ;
const double eps = 1e-7 ;
template <class T = ll> T chmin(T &a, T b) { return a = min(a, b);}
template <class T = ll> T chmax(T &a, T b) { return a = max(a, b);}
template <class T = ll> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

ll n, vl, vr, ans = linf;

ll a[maxn];

ll f[maxn][maxn];

signed main()
{
	n = read(), vr = read(), vl = read();
	rep(i, 1, n) a[i] = read();
	ass(f, 0x3f);
	f[0][0] = 0;
	rep(i, 0, n - 1)
	{
		rep(j, 0, n)
		{
			chmin(f[i + 1][j], f[i][j] + (a[i + 1] > j ? vr : vl));
			if(a[i + 1] > j) chmin(f[i + 1][a[i + 1]], f[i][j]);
		}
	}
	rep(i, 0, n) chmin(ans, f[n][i]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 206984
N = int(input())
S = input()
K = int(input())

x = S[K-1]
T = [S[i] for i in range(N)]
for i in range(N):
    if T[i] != x:
        T[i] = '*'

y = ''
for i in range(N):
    y += T[i]

print(y)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
using namespace std;
using ll = long long;
using ld = long double;
const int mxn = 1e6+10;
string strings[mxn];
int child[mxn][26], nxt = 1;
bool is_end[mxn];
vector<int> paths[mxn];

void insert(string &A, int ind) {
	int len = A.length();
	int node = 0;
	for(int i=0; i<len; i++) {
		if(child[node][A[i]-'a']==0) child[node][A[i]-'a'] = nxt++;
		node = child[node][A[i]-'a'];
		paths[ind].push_back(node);
	}
	is_end[node] = 1;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int n; cin>>n;
	for(int i=0; i<n; i++) cin>>strings[i];

	for(int i=0; i<n; i++) reverse(strings[i].begin(), strings[i].end());

	for(int i=0; i<n; i++) {
		insert(strings[i], i);
	}

	ll ans = 0;
	for(int i=0; i<n; i++) {
		set<char> suffix; int len = strings[i].length();
		for(int j=len-1; j>=0; j--) {
			int node = paths[i][j];
			for(char c:suffix) {
				if(is_end[child[node][c-'a']]) ans++;
			}
			suffix.insert(strings[i][j]);
		}
		for(char c:suffix) if(is_end[child[0][c-'a']]) ans++;
	}

	cout << ans-n << '\n';
	return 0;
}

Measured memory_bytes: 159208
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int change = 1000-(n%1000);
        if(change == 1000) change = 0;
        System.out.println(change);
        
    }
}


Measured memory_bytes: 35764
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 111;
int N;
int a[MAX], b[MAX];

int main(void) {
    cin >> N;
    REP(i, N) cin >> a[i];
    REP(i, N) cin >> b[i];
    int ans = 0;
    REP(i, N) {
        int pre = 0;
        REP(j, N) {
            if (j < i) pre += a[j];
            else if (j == i) pre += a[j] + b[j];
            else pre += b[j];
        }
        chmax(ans, pre);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = int(input())
WW = inpl()
ans = INF
for T in range(1,N):
    S1 = sum(WW[:T+1])
    S2 = sum(WW[T+1:])
    ans = min(abs(S1-S2),ans)
print(ans)


Measured memory_bytes: 4328
#include <stdio.h>

int main(void) {
    int n, i, max = 0, second_max = 0;
    scanf("%d", &n);
    int a[n];
    for ( i = 0; i < n; i++ ) {
        scanf("%d", &a[i]);
        if ( a[i] > max ) {
            second_max = max;
            max = a[i];
        }
        else if ( a[i] > second_max ) {
            second_max = a[i];
        }
    }
    for ( i = 0; i < n; i++ ) {
        if ( a[i] == max ) {
            printf("%d\n", second_max);
        }
        else {
            printf("%d\n", max);
        }
    }
    return 0;
}

Measured memory_bytes: 2304
import queue

class Dinic():
    def __init__(self, v, inf = 1000000007):
        self.V = v
        self.inf = inf
        self.G = [[] for _ in range(v)]
        self.level = [0 for _ in range(v)]
        self.iter = [0 for _ in range(v)]

    def add_edge(self, from_, to, cap):
        # to: 行き先, cap: 容量, rev: 反対側の辺
        self.G[from_].append({'to':to, 'cap':cap, 'rev':len(self.G[to])})
        self.G[to].append({'to':from_, 'cap':0, 'rev':len(self.G[from_])-1})

    # sからの最短距離をbfsで計算
    def bfs(self, s):
        self.level = [-1 for _ in range(self.V)]
        self.level[s] = 0;
        que = queue.Queue()
        que.put(s)
        while not que.empty():
            v = que.get()
            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if e['cap'] > 0 and self.level[e['to']] < 0:
                    self.level[e['to']] = self.level[v] + 1
                    que.put(e['to'])
     
    # 増加バスをdfsで探す
    def dfs(self, v, t, f):
        if v == t: return f
        for i in range(self.iter[v], len(self.G[v])):
            self.iter[v] = i
            e = self.G[v][i]
            if e['cap'] > 0 and self.level[v] < self.level[e['to']]:
                d = self.dfs(e['to'], t, min(f, e['cap']))
                if d > 0:
                    e['cap'] -= d
                    self.G[e['to']][e['rev']]['cap'] += d
                    return d
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            # bfsで到達不可
            if self.level[t] < 0 : return flow
            self.iter = [0 for _ in range(self.V)]
            f = self.dfs(s, t, self.inf)
            while f > 0:
                flow += f
                f = self.dfs(s,t, self.inf)


N = int(input())
AB = [list(map(int,input().split())) for i in range(N)]
CD = [list(map(int,input().split())) for i in range(N)]

MF = Dinic(2*N+2) ## 二部グラフの2*N点と、始点と終点の2点

## 赤と青を結ぶ
for i in range(N):
  for j in range(N):
    if AB[i][0] < CD[j][0] and AB[i][1] < CD[j][1]:
      MF.add_edge(i, j+N, 1) ## 今回は重み1
      
## 始点と赤を結ぶ
for i in range(N):
  MF.add_edge(2*N, i, 1)
  
## 青と終点を結ぶ
for j in range(N):
  MF.add_edge(j+N, 2*N+1, 1) ## 順番に注意: 青がfrom、終点がto
  
max_flow = MF.max_flow(2*N, 2*N+1)
print(max_flow)



Measured memory_bytes: 5872
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <utility>
using namespace std;


int main(){
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> v(n);
  for(long long i = 0; i < n; i++){
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end());
  long long res = 0;
  bool f = true;
  for(long long i = 0; i < n; i++){
    res += v[i].second;
    if(k <= res){
      cout << v[i].first << endl;
      f = false;
      break;
    }
  }
  if(f){ cout << v[n - 1].first << endl;}
}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        int minScore = INT_MAX;
        int maxScore = INT_MIN;
        for(int i=0; i<n; ++i){
            int a = 0;
            for(int j=0; j<5; ++j){
                int b;
                cin >> b;
                a += b;
            }
            minScore = min(minScore, a);
            maxScore = max(maxScore, a);
        }

        cout << maxScore << ' ' << minScore << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
typedef long long ll;
const int maxn=1e6+9;
const int mod=1e9+7;
using namespace std;
ll kpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}
int main()
{
	ll n,i,j,a[maxn],la=1,ans=0,f[maxn]={0};
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		ll b=a[i];
		for(j=2;j*j<=b;j++)
		{
			if(b%j==0)
			{
				ll cnt=0;
				while(b%j==0)b/=j,cnt++;
				f[j]=max(f[j],cnt);
			}
		}
		if(b>1)f[b]=max(f[b],1ll);
	}
	for(i=2;i<=1e6;i++)la=(la*kpow(i,f[i]))%mod;
	for(i=1;i<=n;i++)ans=(ans+la*kpow(a[i],mod-2)%mod)%mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 11776
#include<iostream>
#include<string>
#include<vector>
using namespace std;
string index="IVXLCDM";
int trans[]={1,5,10,50,100,500,1000};
int t_num(char c){
for(int i=0;i<index.size();i++){
if(c==index[i]){
return trans[i];
}
}
}
int main(){
string input;
while(cin>>input){
int ans=0;
vector<int> in;
for(int i=0;i<input.size();i++){
in.push_back(t_num(input[i]));
}
int tmp=0;
tmp=in[0];
for(int i=1;i<in.size();i++){
if(in[i]>in[i-1]){
tmp=in[i]-tmp;
}else if(in[i]<in[i-1]){
ans+=tmp;
tmp=in[i];
}else{
tmp+=in[i];
}
}
ans+=tmp;
cout<<ans<<endl;
}
return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
using l1 = long long;
#define rep(i,n) for(int i=0,i<(n);++i)
int main(){
    string a,b;

    cin>>a>>b;

    if(a==b.substr(0,a.length())){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;

}

Measured memory_bytes: 3628
#include<stdio.h> 
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	int i;
	int m[9];
	if(a<=b){
	for(i=1;i<=b;++i)
	{
	m[i]=a;
	printf("%d",a);}
	}
	else if(a>b){
	for(i=1;i<=a;i++){
	m[i]=b;
	printf("%d",b);}	
}
//printf("%d",m[i]);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int A[1000000],n;

int binarySerch(int key){
  int left=0,right=n,mid;

  while(left<right){
    mid=(left+right)/2;
    if(key==A[mid])return 1;
    if(key>A[mid])left=mid+1;
    else if(key<A[mid])right=mid;
  }
  return 0;
}

int main(){
  int i,q,k,s=0;

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

  scanf("%d",&q);
   for(i=0;i<q;i++){
    scanf("%d",&k);
    if(binarySerch(k))s++;
  }
   printf("%d\n",s);

   return 0;
}



Measured memory_bytes: 2144
<?php

while($n = trim(fgets(STDIN))) {
	echo largest($n) . ' ' . smallest($n) . "\n";
}


function largest($n) {
	while ($n > 2) {
		$n--;
		if (isPrime($n)) {
			return $n;
		}
	}
	return $n;
}

function smallest($n) {
	while (true) {
		$n++;
		if (isPrime($n)) {
			return $n;
		}
	}
}

function isPrime($n) {
	if ($n == 2 || $n == 3) {
		return true;
	}
	if ($n < 2 || $n % 2 == 0) {
		return false;
	}
	if ($n < 9) {
		return true;
	}
	if ($n % 3 == 0) {
		return false;
	}

	$r = intval(sqrt($n));
	$f = 5;
	while ($f <= $r) {
		if ($n % $f == 0 || $n % ($f + 2) == 0) {
			return false;
		} else {
			$f += 6;
		}
	}
	return true;
}

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


int d[100][5]={0};//来店時刻/人数/食事時間/着席時間/待ち時間/
int wait=0;//待っている客の番号
int Min=0;//現在時間

int isu[17]={0};
int isu_chk(int num){
	int tmp=0;
	for(int i=0;i<17;i++){
		if(isu[i]==-1)tmp++;
		else tmp=0;
		if(tmp>=num)return i-num+1;
	}
	return -1;
}
void tyaku(int pos,int name){
	for(int i=0;i<d[name][1];i++){
		isu[pos+i]=name;
	}
}
void update(){
	for(int i=0;i<17;i++){
		if(isu[i]<0)continue;
		if(Min>=d[isu[i]][2]+d[isu[i]][3]){
			isu[i]=-1;
		}
	}
}


void init(){
	for(int i=0;i<17;i++)isu[i]=-1;
	for(int i=0;i<100;i++){
		d[i][0]=5*i;
		d[i][1]=(i%5==1?5:2);
		d[i][2]=17*(i%2)+3*(i%3)+19;
		d[i][3]=-1;
		d[i][4]=-1;
		//cout<<i<<"\t"<<d[i][0]<<"\t"<<d[i][1]<<"\t"<<d[i][2]<<"\n";
	}
	
	for(;wait<100;Min++){
		update();
		while(true){
			if(Min<d[wait][0])break;
			if(isu_chk(d[wait][1])==-1)break;
			d[wait][3]=Min;
			d[wait][4]=Min-d[wait][0];
			tyaku(isu_chk(d[wait][1]),wait);
			wait++;
			if(wait>=100)break;
		}
	}
}

int main(){
	init();
	
	for(int n;cin>>n;)cout<<d[n][4]<<endl;
	
	return 0;
}


Measured memory_bytes: 1160