akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int a[200002]={0};
int main()
{
	int n,i;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(i=1;i<n;i++)
		if(a[i]==a[i-1])
			{cout<<"NO";
			 return 0;
			}
	cout<<"YES";
//	for(i=0;i<n;i++)
//		cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll p, q, r;
    cin >> p >> q >> r;
    cout << min(p + q, min(p + r, q + r)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N,M;
	int a,b;
	int i,j,k;
	int r[50];

	cin>>N>>M;
	for(i=0;i<N;i++){
		r[i]=0;
	}
	for(i=0;i<M;i++){
		cin>>a>>b;
		r[a-1]++;
		r[b-1]++;
	}
	for(i=0;i<N;i++){
		cout<<r[i]<<endl;
	}
      
	return 0;
}

Measured memory_bytes: 256
n, y = gets.chomp.split(' ').map(&:to_i)


(n+1).times do |i|
  (n-i+1).times do |j|
    k = n - i - j
    price = 10000 * i + 5000 * j + 1000 * k
    if price == y
      puts "#{i} #{j} #{k}"
      exit
    end
  end
end

puts '-1 -1 -1'

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, k, x;
	cin>>n>>k;
	set<int> st;
	for(int i = 0; i < k; i++){
		cin>>x;
		st.insert(x);
	}
	for(int i = n; ; i++){
		int v = i; bool flg = true;
		while(v){
			if(st.find(v%10) != st.end()){
				flg = false;
				break;
			}
			v /= 10;
		}
		if(flg){
			cout<<i<<endl;
			exit(0);
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N;cin>>N;
  vector<int> B(N);
  REP(i,0,N){
    cin>>B[i];
  }
  vector<int> ans;
  bool flg=true;
  while(flg){
    flg=false;
    RREP(i,B.size()-1,-1){
      if(B[i]==i+1){
        ans.push_back(B[i]);
        B.erase(B.begin()+i);
        flg=true;
        break;
      }

    }
  }
  if(ans.size()!=N)print(-1);
  else{
    reverse(ALL(ans));
    each(v,ans){
      print(v);
    }
  }

}


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

typedef int32_t i32;
typedef int64_t i64;

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
    a[i]--;
  }
  i64 sum = 0;
  i64 *imos = (i64 *) calloc (2 * m, sizeof (i64));
  i64 *ans = (i64 *) calloc (2 * m, sizeof (i64));
  for (i32 i = 1; i < n; ++i) {
    if (a[i] > a[i - 1]) {
      sum += a[i] - a[i - 1];
      imos[a[i - 1] + 2]++;
      imos[a[i] + 1]--;
      ans[a[i] + 1] -= a[i] - a[i - 1] - 1;
    } else {
      sum += a[i] + m - a[i - 1];
      imos[a[i - 1] + 2]++;
      imos[a[i] + m + 1]--;
      ans[a[i] + m + 1] -= a[i] + m - a[i - 1] - 1;
    }
  }
  for (i32 i = 1; i < 2 * m; ++i) {
    imos[i] += imos[i - 1];
  }
  for (i32 i = 1; i < 2 * m; ++i) {
    ans[i] += ans[i - 1] + imos[i];
  }
  for (i32 i = m; i < 2 * m; ++i) {
    ans[i - m] += ans[i];
  }
  i64 min = sum;
  for (i32 i = 0; i < m; ++i) {
    i64 v = sum - ans[i];
    if (v < min) min = v;
  }
  printf ("%" PRIi64 "\n", min);
}

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


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

typedef long long ll;
typedef pair<int, int> P;
int dx[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
int dy[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
const ll MOD = 1000000007;
const ll INF = 1000000;
const int MAX = 10000000;

int p[100005];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }

    int ans = 0;
    for (int i = 0; i < n - 1; i++){
        if (p[i] != i) continue;
        swap(p[i], p[i + 1]);
        ans++;
    }
    if (p[n - 1] == n - 1) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
double x[10], y[10];


int main() {
    cin >> n;
    rep(i, n) cin >> x[i] >> y[i];

    double sum = 0.0;
    rep(i, n) {
        rep(j, n) {
            if (i == j) continue;
            else {
                sum += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
            }
        }
    }
    sum /= n;
    cout << fixed << setprecision(16) << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1


#ifndef ONLINE_JUDGE
#define watch(x)		cerr << #x << " = " << x << "\n"
#else
#define watch(x)		42
#endif

mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
#endif
}

int32_t main()
{
	c_p_c();

	int a,b; cin>>a>>b;

	cout << a*b;
	
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool comp(pair<ll,ll>&a,pair<ll,ll>&b)
{
    if(a.first==b.first)
      return a.second<b.second;
    return a.first<b.first;
}
bool comp1(pair<ll,ll>&a,pair<ll,ll>&b)
{
    return a.second<b.second;
}
int main()
{
    ll n;
  cin>>n;
  vector<pair<ll,ll>>v;
  multiset<ll>set1;
  multiset<ll>set2;
    multiset<ll>set3;
  multiset<ll>set4;
  ll p=0,q=INT_MAX;
  ll dis=0;
  for(int i=0;i<n;i++)
  {
     ll a,b;
      cin>>a>>b;
     set1.insert(a);
     set2.insert(b);
     v.push_back(make_pair(a,b));
    p=max(a,p);
    q=min(b,q);
    dis=max(dis,b-a+1);
  }
  sort(v.begin(),v.end(),comp);
  ll maxi=max(q-p+1,(ll)0);   
  for(int i=n-1;i>0;i--)
  {
     set3.insert(v[i].first);
     set4.insert(v[i].second);
     set1.erase(set1.find(v[i].first));
     set2.erase(set2.find(v[i].second));
     ll f1,f2,s1,s2;
     f1=*(--set3.end());
      s1=*(set4.begin());
      f2=*(--set1.end());
      s2=*(set2.begin());
      ll tempo1=max(s1-f1+1,(ll)0);
      ll tempo2=max(s2-f2+1,(ll)0);
      maxi=max(maxi,tempo1+tempo2);
  }
       cout<<max(maxi,dis+max(0LL,q-p+1));
    return 0;
}

Measured memory_bytes: 11120
use std::cmp::min;

fn input_one<T: std::str::FromStr> () -> Result<T, T::Err> {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    n.trim().parse()
}

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

fn main() {
    let n: usize = input_one().unwrap();
    let p: Vec<usize> = input_arr();
    let mut r = 0;
    let mut c = n + 1;
    for &v in p.iter() {
        if v < c {
            r += 1;
        }
        c = min(v, c);
    }
    println!("{}", r);
}


Measured memory_bytes: 5000
# is a prime
def ispr(n):
    if n==1:
        return False
    elif n==2:
        return True
    elif n%2==0:
        return False
    else:
        k=3
        while k**2<=n:
            if n%k==0:
                return False
            else:
                k+=2
        return True

X=int(input())
while True:
    if ispr(X):
        print(X)
        break
    else:
        X+=1

Measured memory_bytes: 38384
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int p = saori.saori_hayami();
		System.out.println((a*3 + p)/2);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  //input
  int N;
  cin >> N;
  vector <string> W(N);
  rep(i,N) cin >> W[i];

  //solve
  set<string> s;
  s.insert(W[0]);
  string ans = "Yes";

  for (int i = 1; i < N; i++){
    if (s.count(W[i]) == 1) ans = "No";
    int len = W[i - 1].size();
    if (W[i][0] != W[i - 1][len - 1]) ans = "No";
    s.insert(W[i]);
  }

  //output
  cout << ans << endl;
}


Measured memory_bytes: 3600
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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 run() {
    input! {
        n: u64,
    }
    let mut n = n;
    let mut k = 2;
    let mut cnt = 1;
    let mut factor = 0;
    while k * k <= n {
        if n % k == 0 {
            factor += 1;
            let mut c = 0;
            while n % k == 0 {
                c += 1;
                n /= k;
            }
            cnt *= c + 1;
        }
        k += 1;
    }
    if n > 1 {
        cnt *= 2;
        factor += 1;
    }
    println!("{} {}", factor, cnt - 1);
}

fn main() {
    run();
}



Measured memory_bytes: 5036
import itertools 
N = int(input())
march = list(itertools.combinations("MARCH", 3))
dict = {i:0 for i in "MARCH"}
for _ in range(N):
    S = input()
    if(S[0] in "MARCH"):
        dict[S[0]] += 1
ans = 0
for i in range(10):
    ans +=  dict[march[i][0]]*dict[march[i][1]]*dict[march[i][2]]

print(ans)

Measured memory_bytes: 3064
import math
from functools import reduce

K = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0

for i in range(1, K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      ans += gcd(i, j, k)

print(ans)


Measured memory_bytes: 74864
# 38
menu = []
jissai_menu = []
for i in range(5):
    menu.append(int(input()))
    if menu[i] % 10 == 0: 
        jissai_menu.append(menu[i])
    else:
        jissai_menu.append(menu[i] - menu[i] % 10 + 10)

ans = float('inf')
for i in range(5):
    tmp = 0
    for j in range(5):
        if j == i: continue
        tmp += jissai_menu[j]
    ans = min(ans, tmp + menu[i])

print(ans)

Measured memory_bytes: 9160
#include<iostream>
#define INF 9000000000000000000
using namespace std;
typedef long long ll;

ll num_seq[100005];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> num_seq[i];
    ll min_count = INF, sub_count = 0, count = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            if (num_seq[i] + sub_count <= 0) {
                if (num_seq[i] + sub_count == 0) count++;
                else count += 1 - (num_seq[i] + sub_count);
                sub_count = 1;
            }
            else sub_count += num_seq[i];
        }
        else {
            if (num_seq[i] + sub_count >= 0) {
                if (num_seq[i] + sub_count == 0) count++;
                else count += 1 + (num_seq[i] + sub_count);
                sub_count = -1;
            }
            else sub_count += num_seq[i];
        }
    }
    if (min_count > count) min_count = count;
    count = 0;
    sub_count = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            if (num_seq[i] + sub_count >= 0) {
                if (num_seq[i] + sub_count == 0) count++;
                else count += 1 + (num_seq[i] + sub_count);
                sub_count = -1;
            }
            else sub_count += num_seq[i];
        }
        else {
            if (num_seq[i] + sub_count <= 0) {
                if (num_seq[i] + sub_count == 0) count++;
                else count += 1 - (num_seq[i] + sub_count);
                sub_count = 1;
            }
            else sub_count += num_seq[i];
        }
    }
    if (min_count > count) min_count = count;
    cout << min_count << endl;
    return 0;
}

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

int main()
{


    int k,a,b;
    cin>>k>>a>>b;
    for(int i=a; i<=b; i++){
		if(i%k==0){
			cout << "OK";
			return 0;
		}
    }
    cout << "NG" << endl;



    return 0;
}






Measured memory_bytes: 3616
#include <stdio.h>

int main(void) {
    int N, M, S, x, A[105], i;
    scanf("%d%d", &N, &M);
    for (i=0; i<N; i++) scanf("%d", &A[i]);
    S=0; 
    for (i=0; i<N; i++) S+=A[i];
    S=(S+4*M-1)/(4*M);
    x=0;
    for (i=0; i<N; i++) {
        if (A[i]>=S) x++;
    }
    if (x>=M) printf("Yes");
    else printf("No");
    // printf(" (%d %d)", S, x);
    return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

struct edge{
    int from, to; lint cost;
    edge(int f, int t, lint c) : from(f), to(t), cost(c) {}
    edge(int t, lint c) : from(-1), to(t), cost(c) {}
};

struct dijkstra{
    vector<vector<edge> > G;
    vector<lint> d;
    int V, s;
    dijkstra(vector<vector<edge> > _G, int _s) : G(_G), s(_s){
        init();
    }
    void init(){
        V = G.size();
        d = vector<lint>(V, INF);
        priority_queue<P, vector<P>, greater<P> > que; que.push(P(0, s));
        d[s] = 0;
        while(!que.empty()){
            P p = que.top(); que.pop();
            int v = p.second;
            if(d[v] < p.first) continue;
            for(int i = 0; i < G[v].size(); i++){
                edge e = G[v][i];
                if(d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
    }
    int dist(int t){
        return d[t];
    }
};

int main(){
    int n,m,s,t; cin>>n>>m>>s>>t;
    s--; t--;
    vector<vector<edge> > ga(n), gb(n);
    rep(i,m){
        lint u,v,a,b; cin>>u>>v>>a>>b;
        u--; v--;
        ga[u].push_back(edge(v,a));
        ga[v].push_back(edge(u,a));
        gb[u].push_back(edge(v,b));
        gb[v].push_back(edge(u,b));
    }

    dijkstra da(ga, s), db(gb, t);
    
    vector<P> vp;
    const lint L = 1e15;
    rep(i,n){
        lint c = da.d[i] + db.d[i];
        vp.push_back(P(L-c, i));
    }
    sort(all(vp), greater<P>());

    int j = 0;
    rep(i, n){
        while(vp[j].se < i) j++;
        out(vp[j].fi);
    }
}

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

int main(){
    int N,K;
    int h[100000] = {};
    int r[100000] = {};
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    sort(h,h+N);
    for(int i = 0; i < N-K+1; i++){
        r[i] = h[i+K-1] - h[i];
        //cout << r[i];
    }
    sort(r,r+N-K+1);
    cout << r[0] << endl;

}


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

using namespace std;
using boost::multiprecision::cpp_int;

const int dx[8] = { 0,1,1,1,0,-1,-1,-1 };
const int dy[8] = { 1,1,0,-1,-1,-1,0,1 };

vector<std::string> StringSplit(const string &str, char sep) {
	vector<std::string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int count = 1;
	if (a != b)
		count++;
	if (b != c && c != a)
		count++;
	cout << count << endl;
}

Measured memory_bytes: 256
import sys
import numpy as np

read = sys.stdin.read

H, N, *AB = map(int, read().split())

A = np.array(AB[::2], np.int64)
B = np.array(AB[1::2], np.int64)

INF = 10 ** 10
dp = np.full(H + 1, INF, np.int64)
dp[0] = 0

for i in range(1, H + 1):
    dp[i] = (dp[np.maximum(i - A, 0)] + B).min()

print(dp[-1])

'''
pypyなら346ms

import sys

read = sys.stdin.read

H, N, *AB = map(int, read().split())

INF = 10 ** 10
dp = [INF] * (H + 1)
r = INF
dp[0] = 0

for a, b in zip(*[iter(AB)] * 2):
    for i in range(a, H + 1):
        dp[i] = min(dp[i], dp[i - a] + b)
    r = min(r, min(dp[-a:]) + b)

print(min(r, dp[-1]))
'''


Measured memory_bytes: 12520
#include <stdio.h>

int main(void)
{
	long H, N, A[100010], i, damage;
	damage = 0;

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

	if (damage >= H)
		printf("Yes");
	else
		printf("No");
	
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<N; i++){ ;
int main() {
int X;
cin>>X;
if(X<30){
    cout<<"No"<<endl;
}
else
{
    cout<<"Yes"<<endl;
}

 }


Measured memory_bytes: 3632
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int N;
    cin>>N;
    vector<string>W(N);
    bool flag=true;

    for(int i=0;i<N;i++)cin>>W[i];
    for(int i=1;i<N;i++){
        if(W[i].front()!=W[i-1].back())flag=false;
    }

    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            if(W[i]==W[j])flag=false;
        }
    }

    if(flag){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> g[200000];
int t[200000];
int ans[200000];
void dfs(int a,int b,int c){
    ans[a]=c+t[a];
    for(int i=0;i<g[a].size();i++){
        if(g[a][i]==b)
            continue;
        dfs(g[a][i],a,c+t[a]);
    }
}
int main(){
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        u--,v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i=0;i<q;i++){
        int p,c;
        cin>>p>>c;
        p--;
        t[p]+=c;
    }
    dfs(0,-1,0);
    for(int i=0;i<n;i++)
        cout<<ans[i]<<" ";
    cout<<endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 1123456;
int x[MAX_N];

int dp[MAX_N][2];

int main2() {
  string S; cin >> S;
  S = "0" + S;
  const int N = S.size();
  REP(i, N) x[i] = S[i]-'0';

  const int INF = 1001001001;
  REP(i, MAX_N) REP(j, 2) dp[i][j] = INF;
  dp[0][0] = 0;
  for (int i = 1; i <= N; i++) {
    int e = x[i-1];
    chmin(dp[i][0], dp[i-1][0] + e);
    chmin(dp[i][1], dp[i-1][0] + e + 1);

    chmin(dp[i][1], dp[i-1][1] + 9 - e); // 何もしない
    chmin(dp[i][0], dp[i-1][1] + e + 1); // 今の桁ぴったり出す。
    chmin(dp[i][1], dp[i-1][1] + e + 1 + 1); // 今の桁+1出す。どこの桁で超えたかがリセットされる
  }
  int ans = min(dp[N][0], dp[N][1] + 1);
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 14000
//author-micheal corleone
//the godfather
#include <bits/stdc++.h>
#include <set> 
#include<algorithm>
#define ll long long int
 
using namespace std;
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k,i,j;
    cin>>n>>k;
    ll A[n+1];
     for(i=1;i<=n;i++) cin>>A[i];
     ll start=1,l;
    ll vis[n+1]={0};
     while(1)
     {
        if(vis[start]==1)
        {
          l=start;
          break;
        }
        vis[start]=1;
        start=A[start];
        k--;
        if(k==0)
        {
          cout<<start<<endl;
          return 0;
        }
     }
     ll cnt=0;
      vector<ll> v;
     for(i=l;;)
     {
        if(i==l && cnt!=0) break;
        v.push_back(i);
        i=A[i];
        cnt++;
     }
     ll d=v.size();
      cout<<v[k%d]<<endl;
}
     

Measured memory_bytes: 7252
import Data.List (sortBy)

main:: IO ()
main = do
    [_,k] <- (map read . words) <$> getLine
    ls <- (map read . words) <$> getLine
    print $ solve k ls

-- |
--
-- >>> solve 3 [1,2,3,4,5]
-- 12
solve :: Int -> [Int] -> Int
solve k ls = sum $ take k $ rSort ls

rSort :: (Ord a) => [a] -> [a]
rSort = sortBy (flip compare)


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

int main(){
   int n; cin>>n;
   vector<int> p(n);
   for(int i=0;i<n;i++) cin>>p[i];
   int sum=0;
   int maxj=p[0];
   for(int i=0;i<n;i++){
      sum+=p[i];
      maxj=max(maxj,p[i]);
   }
   cout<<sum-maxj/2<<endl;
   return 0;
}

Measured memory_bytes: 256
//I am so vegetable
//#define err
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define PB push_back
#define IN insert
#define ER erase
#define CT count
#define EP empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-6;
const double pi = acos(-1.0);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, int MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2) % mod; }
ll m_m(ll a){ return (a%MOD+MOD)%MOD; }


int main() {
	//ofstream cout("E:\\acm dream\\out.txt",ios::out);
	FIO;
    #ifdef err
	double be = clock();
    #endif
    int n;cin>>n;
    map<int,ll>mp;
    ll sum = 0;
    _for(i,0,n){
        int x;cin>>x;
        ++mp[x];
        sum+=x;
    }
    int q;cin>>q;
    _for(i,0,q){
        int u,v;cin>>u>>v;
        sum-=u*mp[u];
        sum+=v*mp[u];
        mp[v]+=mp[u],mp[u]=0;
        cout<<sum<<'\n';
    }
    #ifdef err
	double en = clock();
    cout<<"time: "<<fixed<<setprecision(8)<<en-be;
    #endif
	return 0;
}

Measured memory_bytes: 9452
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>


using namespace std;

int main()
{
	int n;
	int t[100], v[100], ts[100];
	double x=0;
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d", &t[i]);
		if(i==0){
			ts[0]=t[0];
		}else{
			ts[i]=ts[i-1]+t[i];
		}
	}
	for(int i=0; i<n; i++){
		scanf("%d", &v[i]);
	}
	double vmin[40001];
	vmin[0]=0;
	for(int i=0; i<n; i++){
		if(i==0){
			for(int j=1; j<2*t[0];j++){
				vmin[j]=v[0];
			}
		}else{
			if(v[i-1]<v[i]){
				vmin[2*ts[i-1]]=v[i-1];
			}else{
				vmin[2*ts[i-1]]=v[i];
			}
			for(int j=2*ts[i-1]+1; j<2*ts[i]; j++){
				vmin[j]=v[i];
			}
		}
	}
	vmin[2*ts[n-1]]=0;

	for(int j=0; j<2*ts[n-1];j++){
		if((double)j/2<vmin[j]){
			vmin[j]=(double)j/2;
		}
		if((double)ts[n-1]-(double)j/2<vmin[j]){
			vmin[j]=(2*(double)ts[n-1]-(double)j)/2;
		}
		for(int i=0; i<n-1; i++){
			int w;
			if(v[i]<v[i+1]){
				w=v[i];
			}else{
				w=v[i+1];
			}
			if(j<=2*ts[i] && (2*(double)ts[i]-(double)j)/2+(double)w<vmin[j]){
				vmin[j]=(2*(double)ts[i]-(double)j)/2+(double)w;
			}
			if(j>=2*ts[i] && ((double)j-2*(double)ts[i])/2+(double)w<vmin[j]){
				vmin[j]=((double)j-2*(double)ts[i])/2+(double)w;
			}
		}
	}

	for(int j=0; j<2*ts[n-1]; j++){

		x=x+(vmin[j]+vmin[j+1])/2;
	}
	printf("%f\n", x/2);

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

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

	for(i = 0;i < n;i++){
		string train;
		cin >> train;
		set<string> ans;

		ans.insert(train);
		for(unsigned int j = 1;j < train.size();j++){
			string change1 = train.substr(0, j);
			string change2 = train.substr(j);
			string re1 = change1;
			string re2 = change2;

			reverse(re1.begin(), re1.end());
			reverse(re2.begin(), re2.end());
			//cout << change1 << " " << change2 << " " << re1 << " " << re2 << endl;
			ans.insert(change1 + re2);
			ans.insert(re1 + change2);
			ans.insert(re1 + re2);
			ans.insert(change2 + change1);
			ans.insert(change2 + re1);
			ans.insert(re2 + change1);
		}

		reverse(train.begin(),train.end());
		ans.insert(train);

		cout << ans.size() << endl;
	}

	
	return 0;
}

Measured memory_bytes: 1288
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

vector<int> ps;

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

    int diff_cnt = 0;

    ps.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> ps[i];
        if (ps[i] != (i + 1)) {
            diff_cnt++;
        }
    }

    // diff_cnt == 1 is impossible
    if (diff_cnt <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return 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)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    X = LI()

    Y = sorted(X)
    n = (N + 1) // 2
    l = Y[n-1]
    r = Y[n]

    for x in X:
        if x <= l:
            print(r)
        else:
            print(l)

if __name__ == '__main__':
    solve()



Measured memory_bytes: 30808
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
bool cmp(string c,string d)
{
	return strcmp(c.c_str(),d.c_str())<0;
}
int main()
{
	vector<string>a;
	string str;
	int i,n,s=1;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>str;
		a.push_back(str);
	}
	sort(a.begin(),a.end(),cmp);
	str=a[0];
	for(i=1;i<n;i++)
	{
		if(strcmp(str.c_str(),a[i].c_str()))str=a[i],s++;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 11600
package main
 
import (
	"fmt"
	"unicode/utf8"
)
 
func main() {
	var s string
	fmt.Scan(&s)
	l := utf8.RuneCountInString(s)
	s1 := s[0:(l - 1) / 2]
	s2 := s[(l + 2) / 2:l]
	if s == reverse(s) && s1 == reverse(s1) && s2 == reverse(s2) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func reverse(s string) string {
    rs := []rune(s)
    for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
        rs[i], rs[j] = rs[j], rs[i]
    }
    return string(rs)
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, n, m) for(int i = n; i >= m; i--)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main(){

  int N;
  cin >> N;

  int A[N+1];
  int B[N];
  rep(i,N+1){
    cin>>A[i];
  }
  rep(i,N){
    cin>>B[i];
  }

  ll ct=0;

  rep(i,N){
    int t=0;
    int r=0;
    if(A[i]>=B[i]){
      ct+=B[i];
    }
    else{
      t=B[i]-A[i];
      ct+=A[i];
      r=min(A[i+1],t);
      ct+=r;
      A[i+1]-=r;
    }
  }

  cout << ct <<endl;
  return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int h, w, n, s[114514], nows = 0, ans[110][110] = {};
	cin >> h >> w >> n;
	REP(i, n) cin >> s[i];
	REP(i, h) {
		if (i % 2 == 0) {
			REP(j, w) {
				if (s[nows] == 0) nows++;
				ans[i][j] = nows + 1;
				s[nows]--;
			}
		}
		else {
			REPR(j, w - 1) {
				if(s[nows] == 0) nows++;
				ans[i][j] = nows + 1;
				s[nows]--;
			}
		}
	}
	REP(i, h) {
		REP(j, w) {
			if (j != w - 1)cout << ans[i][j] << " ";
			else cout << ans[i][j];
		}
		cout << endl;
	}
}



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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if((a+b) > (c+d)){
    cout<<"Left"<<endl;
  }else if((a+b) == (c+d)){
    cout<<"Balanced"<<endl;
  }else{
    cout<<"Right"<<endl;
  }
}


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

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

    vector<int> cnt(4, 0);
    rep (i, n)
    {
        string s;
        cin >> s;
        switch (s[0])
        {
            case 'A':
                cnt[0]++;
                break;

            case 'W':
                cnt[1]++;
                break;

            case 'T':
                cnt[2]++;
                break;

            case 'R':
                cnt[3]++;
                break;
        }
    }

    printf("AC x %d\n", cnt[0]);
    printf("WA x %d\n", cnt[1]);
    printf("TLE x %d\n", cnt[2]);
    printf("RE x %d\n", cnt[3]);
    return 0;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,n,a,m,k,l,sum1=0,sum=0,flag,cnt=0,maxn,ans1,ans2,p=0,q=0,rans=INT_MAX,minn=INT_MAX,ans;
    string s;
    char ch;
    vector<long long int>ar;
    cin>>k>>n;
    for(i=0; i<n; i++)
    {
        cin>>a;
        ar.push_back(a);

    }
    ans=ar[n-1]-ar[0];
    for(i=1; i<n; i++)
    {
        ans=min(ans,k-abs(ar[i]-ar[i-1]));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2420
program exception_handling
    implicit none
    integer(4):: n, i,m1(2), m2(2), b

    m1(:)=0;m2(:)=0
    read*, n

    do i=1,n
        read*, b
        if (b > m1(1)) then
            m2(:) = m1(:)
            m1(1) = b
            m1(2) = i
        else if(b > m2(1)) then
            m2(1) = b
            m2(2) = i
        end if
    end do

    do i=1, n
        if (i == m1(2))then
            print*, m2(1)
        else
            print*, m1(1)
        end if
    end do

end program exception_handling

Measured memory_bytes: 2816
# 13
# 5 5 6 7 6 6 5 6 7 7 7 6 6 7

def main():
    n = int(input())
    al = list(map(int, input().split()))
    
    buy_is = []
    sell_is = []

    if n == 2:
        if al[0] < al[1]:
            money = 1000
            buy_kabu = 1000//al[0]
            money -= (buy_kabu*al[0])
            money += al[1]*buy_kabu
            print(money)
        else:
            print(1000)
        exit()


    if al[0] < al[1]:
        buy_is.append(0)

    
    for i, (a0,a1,a2) in enumerate( zip(al[0:-2], al[1:-1], al[2:]) ):
        if a0 >= a1 and a1 < a2:
            buy_is.append(i+1)
        elif a0 <= a1 and a1 > a2:
            sell_is.append(i+1)


    money = 1000
    kabu = 0
    for i in range(n):
        if i in buy_is:
            buy_kabu = money//al[i]
            kabu += buy_kabu
            money -= (buy_kabu*al[i])
        elif i in sell_is or i == n-1:
            money += al[i]*kabu
            kabu = 0
    
    print(money)
    # print(buy_is)
    # print(sell_is)

if __name__ == "__main__":
    main()

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

int main(void) {

	int cnt[4] = {0, 0, 0, 0};//AC, WA, TLE, REの個数をいれる。
	int n, i;
	char judge[4];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%s", judge);

		if(judge[0]=='A'){
			cnt[0] += 1;
		}

		else if (judge[0] == 'W') {
			cnt[1] += 1;
		}

		else if (judge[0] == 'T') {
			cnt[2] += 1;
		}

		else if (judge[0] == 'R') {
			cnt[3] += 1;
		}


	}

	printf("AC x %d\n", cnt[0]);
	printf("WA x %d\n", cnt[1]);
	printf("TLE x %d\n", cnt[2]); 
	printf("RE x %d\n", cnt[3]);

	return 0;
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

bool is_prime(int x){
    if (x<=1) return false;
    for (int i=2;i*i<x;i++){
        if (x%i==0) return false;
    }
    return true;
}


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

    int n;
    cin >> n;

    int p=n;
    while(!is_prime(p)) {
        p++;
    }

    cout << p << endl;
        
    

    


        
}

Measured memory_bytes: 256
X, Y = map(int, input().split())

crane = (4 * X - Y) / 2
turtle = (Y - 2 * X) / 2


def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False


if is_integer_num(crane) and crane >= 0 and is_integer_num(turtle) and turtle >= 0:
    print("Yes")

else:
    print("No")


Measured memory_bytes: 9184
#include <stdio.h>
int main()
{
  int x, y, r, m;
  scanf("%d%d", &x, &y);

  if( x < y ){
    m = x;
    x = y;
    y = m;
  }

  r = x % y;
  while(r!=0){
    x = y;
    y = r;
    r = x % y;
  }
  printf("%d\n", y);

  return 0;
}



Measured memory_bytes: 2120
n, w = map(int, input().split())
goods = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * (w + 1) for _ in range(n)]
for i in range(n):
    for j in range(w + 1):
        if 0 <= j - goods[i][0]:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - goods[i][0]] + goods[i][1])
        dp[i][j] = max(dp[i][j], dp[i - 1][j])
print(dp[n - 1][w])


Measured memory_bytes: 121324
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
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() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  int a[n], res = 0;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    REP(j, i + 1, n) {
      res += a[i] * a[j];
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

if n%2==0:
    print(a[0] + sum(a[1:n//2])*2)
else:
    print(a[0] + sum(a[1:(n+1)//2])*2 - a[n//2])


Measured memory_bytes: 31620
#include <stdio.h>
  
void mysort(int *x) {
   int i;
   int j;
   int tmp;
   for(i=0; i<3; ++i) {
      for(j=0; j<10-1; ++j) {
         if (x[j] > x[j+1]) {
            tmp = x[j+1];
            x[j+1] = x[j];
            x[j] = tmp;
         }
      }
   }
}
  
int main() {
   int x[10];
   int i;
   for (i=0; i<10; ++i) {
      scanf("%d", &x[i]);
   }
  
   mysort(x);
  
   printf("%d\n", x[9]);
   printf("%d\n", x[8]);
   printf("%d\n", x[7]);
  
   return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
using namespace std;
int main(void){
  int W,i,x;W=0;i=0;
  
    char Q[1000] = "A";
    
    while(1){
    scanf("%s",Q);
  if(Q[0]=='0')break;
  while(Q[i]!=0){
      W=W+Q[i]-48;
      i=i+1;
  }
  i=0;
    printf("%d\n",W);
  W=0;
        
    }
    
}



Measured memory_bytes: 2712
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
    A--; B--; C--; D--;
    string s; cin >> s; 
    REP(i, s.size() - 1) {
        if (s[i] == '#' && s[i + 1] == '#') {
            if ((A < i && i < C) || (B < i && i < D)) {
                puts("No");
                return 0;
            }
        }
    }
    if (C > D) {
        for (int i = B-1; i < D && i + 2 < s.size(); i++) {
            if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
                puts("Yes");
                return 0;
            }
        }
        puts("No");
    }
    else {
        puts("Yes");
    }
    getchar(); getchar();
}

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

int main()
{
    int K;
    string S;

    cin >> K >> S;

    if (S.size() <= K) {
        cout << S << endl;
    } else {
        S.erase(K);
        cout << S << "..." << endl;;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;

int main() {
  int N,K;
  cin>>N>>K;
  repr(i,0,N) {
    if(K+(K-1)*(i-1)>=N) {
      cout<<i<<endl;
      break;
    }
  }
    
}

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

#define BESTBMI 22
#define MAX 10000

class CDATA {
public:
  int stnum;
  double hei, wei;
  double bmi;
  
  void setBMI() {
    bmi = wei/(hei*hei);
  }
  
  bool operator< (const CDATA &t) const {
    if(abs(22-bmi)==abs(22-t.bmi)) return stnum<t.stnum;
    else return abs(22-bmi) < abs(22-t.bmi);
  }
};

int main() {
  int n;
  double h;
  CDATA person[MAX]; 
  
  while(cin>>n, n) {
    for(int i=0; i<n; i++) {
      cin>>person[i].stnum>>h>>person[i].wei;
      person[i].hei=h/100;
      person[i].setBMI();
    }
    
    stable_sort(person, person+n);
    
    cout<<person[0].stnum<<endl;
    
  }

  return 0;
}

Measured memory_bytes: 1320