akhauriyash/Code-Regression huggingface dataset:
//#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
ll h[300001],w[300001];
ll gyo[300001]={},retu[300001]={};
bool maxgyo[300001],maxretu[300001];
int main(){
	ll H,W,M;
	scan(H>>W>>M);
	ll gmax=0,rmax=0;
	rep(i,M){
		scan(h[i]>>w[i]);
		h[i]--;
		w[i]--;
		gyo[h[i]]++;
		retu[w[i]]++;
		gmax=max(gmax,gyo[h[i]]);
		rmax=max(rmax,retu[w[i]]);
	}
	ll gnum=0,rnum=0;
	rep(i,H) if(gyo[i]==gmax) maxgyo[i]=1,gnum++;
	rep(i,W) if(retu[i]==rmax) maxretu[i]=1,rnum++;
	ll maxkosu=gnum*rnum;
	rep(i,M){
		if(maxgyo[h[i]]&&maxretu[w[i]]) maxkosu--;
	}
	debug(gmax,rmax,gnum,rnum,maxkosu);
	if(maxkosu<=0) prin(gmax+rmax-1);
	else prin(gmax+rmax);
	return 0;
}


Measured memory_bytes: 13468
#include <iostream>
using namespace std;
long long f(long long a, long long b, long long x){
    return (a*x)/b - a*(x/b);
}
int main(void){
    long long a, b, n;
    cin >> a >> b >> n;
    if(b <= n){
        cout << f(a, b, b-1) << endl;
    }else{
        cout << f(a, b, n) << endl;
    }

}


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

const int max_num = 1000010;
int main(){
  vector<int> tetra;
  int x = 1;
  int num = 1;
  while(num <= max_num){
    if (num != 1) tetra.push_back(num);
    x++;
    num = (x * (x+1) * (x+2)) / 6;
  }
  int m = tetra.size();
  vector<int> dp(max_num);
  vector<int> dp2(max_num);
  rep(i, max_num){
    dp[i] = i;
    dp2[i] = i;
    rep(j, m){
      if (i - tetra[j] < 0) break;
      dp[i] = min(dp[i], dp[i - tetra[j]] + 1);
      if (tetra[j] % 2 == 1)
        dp2[i] = min(dp2[i], dp2[i - tetra[j]] + 1);
    }
  }
  while(1){
    int n;
    cin >> n;
    if (n == 0) break;
    cout << dp[n] << ' ' << dp2[n] << endl;
  }
  return 0;
}


Measured memory_bytes: 10552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int mod=1e9+7;
void add(int& x,int y){
	x+=y;
	if(x>=mod) x-=mod;
}
int dp[101][101][256];
int main(){
	int N,X;
	cin>>N>>X;
	dp[0][0][0]=1;
	rep(i,N){
		int x;
		cin>>x;
		rep(l,i+1){
			rep(j,256){
				add(dp[i+1][l][j],dp[i][l][j]);
				add(dp[i+1][l+1][j^x],dp[i][l][j]);
			}
		}
	}
	int ans=0;
	long long f=1;
	rep(l,N+1){
		ans=(ans+f*dp[N][l][X])%mod;
		f=f*(l+1)%mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j;
	long int n, k;
	long int a[100][100];
	long int count[100] = {0};
	long int work;
	long int flg = 0;
	long int ans = 0;
	
	scanf("%ld %ld", &n, &k);
	
	for(i = 0; i < k; i++) {
		scanf("%ld", &work);
		for(j = 0; j < work; j++) {
			scanf("%ld", &a[i][j]);
			count[a[i][j] - 1]++;
		}
	}
	
	for(i = 0; i < n; i++) {
		if(count[i] == 0) {
			ans++;
		}
	}
	
	printf("%ld\n", ans);
	
	return 0;
}


Measured memory_bytes: 2224
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n, v) rep(i, n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1, 0, -1, 0}, y_pos[4] = {0, 1, 0, -1};
int ctoi(char c)
{
	if (c >= '0' && c <= '9')
	{
		return c - '0';
	}
	return 0;
}

char upper(char c)
{
	return c - 0x20;
}

char lower(char c)
{
	return c + 0x20;
}

void unique_vector(vector<int> &v)
{
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
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 gcd(ll x, ll y)
{
	if (y == 0)
		return x;
	return gcd(y, x % y);
}

//最小公倍数
ll lcm(ll x, ll y)
{
	ll g = gcd(x, y);
	return x / g * y;
}

ll myPow(ll x, ll n, ll m)
{
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

//素因数分解
map<ll, ll> prime_factor(ll n)
{
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++)
	{
		while (n % i == 0)
		{
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1)
		ret[n] = 1;
	return ret;
}

int main()
{
	ll n, k;
	cin >> n >> k;
	rep(i,10){
		ll before = n;
		n = min(min(n, n % k ),abs(n-k));
		if(before==n){
			cout << n << endl;
			return 0;
		}
	}
	cout << min(n % k, k - n % k) << endl;
}


Measured memory_bytes: 256
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int k, x; cin >> k >> x;
	if(500*k >= x) println("Yes");
	else println("No");
}


Measured memory_bytes: 256
n = int(input())
x,y,t=0,0,0

for i in range(n):
  mt,mx,my= map(int,input().split())
  ft = mt - t
  fx = abs(x-mx)
  fy = abs(y-my)
  if fx + fy > ft:
    print("No")
    exit()
  elif (ft - (fx + fy)) % 2 == 0:
    pass
  else:
    print("No")
    exit()
  x,y,t=mx,my,mt
print("Yes")

Measured memory_bytes: 9140
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

template<class T>
inline istream& operator >>( istream& s, vector<T>& v ) {
	for( size_t i = 0; i < v.size(); ++i ) { s >> v[i]; }
	return s;
}

template<class T>
inline ostream& operator <<( ostream& s, vector<T>& v ) {
	for( size_t i = 0; i < v.size(); ++i ) {
		s << v[i];
		if( i < v.size()-1 ) { s << ' '; }
	}
	return s;
}


int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;
	vector<int> a( n );
	cin >> a;
	int q;
	cin >> q;
	while( q-- > 0 ) {
		int b, m, e;
		cin >> b >> m >> e;
		auto it = a.begin();
		rotate( it+b, it+m, it+e );
	}
	cout << a << endl;

	return 0;
}



Measured memory_bytes: 3228
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// your code goes here
		int n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		var b = Console.ReadLine().Split().Select(y => int.Parse(y)).ToArray();
		var c = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
		int nanitaberun = 0;
		int nanitabetan = 0;
		int counter = 0;
		
		nanitaberun = a[0];
		counter += b[nanitaberun-1];
		nanitabetan = nanitaberun;
		
		for(int i=1; i!=n; i++){
			nanitaberun = a[i];
			counter += b[nanitaberun-1];
			
			if(nanitabetan == a[i]-1){
				counter += c[nanitaberun-2];
			}
			
			nanitabetan = nanitaberun;
			
		}
		
		Console.WriteLine(counter);
		
	}
}

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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

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

int main() {
    int card[3][3];
    REP(i, 3) {
        REP(j, 3) {
            cin >> card[i][j];
        }
    }

    int N;
    cin >> N;
    REP(k, N) {
        int b;
        cin >> b;
        
        REP(i, 3) {
            REP(j, 3) {
                if (card[i][j] == b) {
                    card[i][j] = -1;
                }
            }
        }
    }

    REP(i, 3) {
        if (card[i][0] == -1 && card[i][1] == -1 && card[i][2] == -1) {
            cout << "Yes" << endl;
            return 0;
        }
        if (card[0][i] == -1 && card[1][i] == -1 && card[2][i] == -1) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (card[0][0] == -1 && card[1][1] == -1 && card[2][2] == -1) {
        cout << "Yes" << endl;
        return 0;
    }
    if (card[0][2] == -1 && card[1][1] == -1 && card[2][0] == -1) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
using namespace std;
typedef long long ll;
int main(){
  int n,i;
  cin >> n >> i;
  cout << n-i+1 << endl;
}
    

Measured memory_bytes: 256
use std::io::*;
use std::str::*;
use std::collections::HashMap;

fn read <T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

pub fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let a: u32 = read(&mut stdin).unwrap();
    let b: u32 = read(&mut stdin).unwrap();
    let c: u32 = read(&mut stdin).unwrap();
    let x: u32 = read(&mut stdin).unwrap();

    let mut coins = HashMap::with_capacity(3);
    coins.insert(500, a);
    coins.insert(100, b);
    coins.insert(50, c);

    let mut adj_coins = HashMap::with_capacity(3);

    for (coin, &num) in coins.iter() {
        let max_coin = (x - x % coin) / coin;

        if num < max_coin {
            adj_coins.insert(coin, num);
        } else {
            adj_coins.insert(coin, max_coin);
        }
    }

    let mut count = 0;

    let a = adj_coins.get(&500).unwrap() + 1;
    for i in 0..a {
        if 500 * i > x {
            break;
        }

        let b = adj_coins.get(&100).unwrap() + 1;
        for j in 0..b {
            if 500 * i + 100 * j > x {
                break;
            }

            let c = adj_coins.get(&50).unwrap() + 1;
            for k in 0..c {
                if 500 * i + 100 * j + 50 * k > x {
                    break;
                }

                if 500 * i + 100 * j + 50 * k == x {
                    count += 1;
                    break;
                }
            }
        }
    }

    println!("{:?}", count);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    int n;
    cin >> n;
    vector<int>h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        while(h[i]>0){
            for(int j=i;j<n;j++){
                if(h[j]>0) h[j]--;
                else break;
            }
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    h, w = nm()
    s = [['.'] * (w+1)]
    for _ in range(h):
        temp = ['.']
        temp.extend(list(ns()))
        temp.extend(['.'])
        s.append(temp)
    s.append(['.'] * (w+1))

    flag = True
    for i in range(1, h+1):
        for j in range(1, w+1):
            if (
                s[i][j] == '#' and
                s[i-1][j] == '.' and
                s[i][j-1] == '.' and
                s[i+1][j] == '.' and
                s[i][j+1] == '.' 
            ):
                flag = False

    print('Yes' if flag else 'No')
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 38896
#include <iostream>
#include <vector>
#include <cmath>

int main(){
	int n, s, k;
	std::cin >> n >> k >> s;
	int r = (s==1e+09)? 1 : s+1;
	for(int i=0; i<k; i++){
		std::cout << s;
		if(i!=n-1) std::cout << " ";
	}
	for(int i=0; i<n-k; i++){
		std::cout << r;
		if(i!=n-k-1) std::cout << " ";
	}
	std::cout << std::endl;
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int dp[25][51000];
int c[25];
const int INF=99999999;
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)cin>>c[i];
	for(int i=0;i<=m;i++)for(int j=1;j<=n;j++)dp[i][j]=INF;

	for(int i=1;i<=m;i++){
		for(int j=0;j<=n;j++){
			if(j<c[i])dp[i][j]=dp[i-1][j];
			else dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1);
		}
	}
	cout<<dp[m][n]<<endl;
	//for(int i=0;i<=m;i++){for(int j=0;j<=n;j++){cout<<dp[i][j]<<" ";}cout<<endl;}
	return 0;
}

Measured memory_bytes: 5348
#include<iostream>
#include<iomanip>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef pair < int , int > Pi;
typedef pair < double , Pi > Pii;
#define fr first
#define sc second


struct edge{
  int to,cost;
  edge(int to, int cost): to(to), cost(cost){};
};

int n, m, p, a, b;
int t[8];
vector< edge > info[31];
typedef vector<edge>::iterator itr;
bool used[31][1 << 8];

double Dijkstra(){
  priority_queue< Pii , vector < Pii > , greater< Pii > > que;
  //Pii( こすと, Pi( いまのまち, ばしゃけん))
  que.push( Pii( 0, Pi( a, ( 1 << n ) - 1)));
  fill_n( *used, 31 * (1 << 8), false);
  while(!que.empty()){
    Pii p = que.top();
    que.pop();
    if(used[p.sc.fr][p.sc.sc]++) continue;
    if(p.sc.fr == b) return p.fr;
    for(itr it = info[p.sc.fr].begin() ; it != info[p.sc.fr].end() ; it++ ){
      for(int ticket = 0 ; ticket < n ; ticket++ ){
        if((p.sc.sc >> ticket) & 1){
          que.push(Pii( p.fr + (double)it->cost / t[ticket], Pi( it->to, p.sc.sc&~(1<<ticket))));
        }
      }
    }
  }
  return -1;
}

int main(){
  while(cin >> n >> m >> p >> a >> b , n){
    for(int i = 0 ; i < n ; i++ ){
      cin >> t[i];
    }
    for(int i = 0 ; i < p ; i++ ){
      int x, y, z;
      cin >> x >> y >> z;
      info[x].push_back( edge( y, z));
      info[y].push_back( edge( x, z));
    }
    double ret = Dijkstra();
    if(ret == -1) cout << "Impossible" << endl;
    else cout << fixed << setprecision(7) << ret << endl;

    for(int i = 0 ; i < 31 ; i++ ) info[i].clear();
  }
}

Measured memory_bytes: 16188
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////

//verify by https://atcoder.jp/contests/nikkei2019-final/tasks/nikkei2019_final_d
//RSQ and RUQ
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int N;
    cin >> N;
    static ll A[100002] = {};
    static ll B[100002] = {};

    FORq(i,1,N){
        cin >> A[i] >> B[i];
    }

    ll ans = 0;
    FORqr(i,1,N){
        ll a = A[i] + ans;
        ll b = B[i];
        if (a == 0) continue;
        if (a<b){
            ans += b-a;
        }else if (a%b != 0){
            ans += b - (a%b);
        }
    }

    cout << ans << "\n";

}


Measured memory_bytes: 1792
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

void dfs(int i, std::vector<std::vector<int> >& from, std::vector<int>& went, int to, std::vector<int>& parent) {
	went[i] = 1;
	for(int r:from[i]) {
		if(went[r]==0) {
			parent[r]=i;
			dfs(r,from,went,to,parent);
		}
	}
}

signed main() {
	int n;
	std::cin >> n;
	std::vector<std::vector<int> > from(n);
	rep(i,n-1) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		from[a].emplace_back(b);
		from[b].emplace_back(a);
	}
	int p1count; // first, start at 0
	int p2count; // second, start at n-1
	std::vector<int> went(n,0);
	std::vector<int> path;
	std::vector<int> parent(n);
	dfs(n-1,from,went,0,parent);
	int inde = 0;
	while(inde!=n-1) {
		path.emplace_back(inde);
		inde = parent[inde];
	}
	path.emplace_back(n-1);

	int cut1,cut2;
	int temp = path.size();
	if(temp&1)temp++;
	cut1 = path[temp/2-1];
	cut2 = path[temp/2];


	p1count = 0;
	p2count = 0;

	std::queue<int> que;
	que.emplace(0);
	std::vector<int> went1(n,0);
	while(!que.empty()) {
		int i = que.front();que.pop();
		went1[i] = 1;
		p1count++;
		for(int j:from[i]) {
			if(went1[j]==0&&j!=cut2)que.emplace(j);
		}
	}
	que.emplace(n-1);
	std::vector<int> went2(n,0);
	while(!que.empty()) {
		int i = que.front();que.pop();
		went2[i] = 1;
		p2count++;
		for(int j:from[i]) {
			if(went2[j]==0&&j!=cut1)que.emplace(j);
		}
	}

	if(p1count>p2count) {
		print("Fennec");
		return 0;
	}
	if(p1count<=p2count) {
		print("Snuke");
		return 0;
	}
	return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	int a,b,m,ma=1e9,mb=1e9;
	cin>>a>>b>>m;
	vector<int>aa(a+1),bb(b+1);
	for(int i=1;i<=a;++i){
		cin>>aa.at(i);
		ma=min(aa.at(i),ma);
	}
	for(int i=1;i<=b;++i){
		cin>>bb.at(i);
		mb=min(bb.at(i),mb);
	}
	int ans=ma+mb;
	for(int i=0,pa,pb,minus;i<m;++i){
		cin>>pa>>pb>>minus;
		ans=min(ans,aa.at(pa)+bb.at(pb)-minus);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:

  int mH, mW;

  vector<vector<char>> table;
  vector<vector<int>> memo;
  int res;

  Tmp(int H, int W);
  void query(int h, int w);
  void reset();
  void rec(int h, int w, int x);
};

Tmp::Tmp(int H, int W)
  : mH(H)
  , mW(W)
  , table(H, vector<char>(W))
  , memo(H, vector<int>(W, -1))
  , res(-1)
{}

void Tmp::query(int h, int w)
{
  rec(h, w, 0);
  int ret{};
  for (auto& r : memo) {
    for (auto& c : r) {
      chmax(ret, c);
    }
  }
  chmax(res, ret);
  reset();
}

void Tmp::rec(int h, int w, int x)
{
  if (h < 0 || w < 0 || h >= mH || w >= mW) {
    return;
  }
  if (table[h][w] == '#') {
    return;
  }
  if (memo[h][w] == -1) {
    memo[h][w] = x;
  }
  else {
    if (!chmin(memo[h][w], x)) {
      return;
    }
  }
  auto r = memo[h][w];

  rec(h-1, w, r+1);
  rec(h+1, w, r+1);
  rec(h, w-1, r+1);
  rec(h, w+1, r+1);
}

void Tmp::reset()
{
  for (auto& row : memo) {
    std::fill(row.begin(), row.end(), -1);
  }
}


void solve(void)
{
  int H, W; cin >> H >> W;
  Tmp t(H, W);
  for (auto& row : t.table) {
    for (auto& cell : row) {
      cin >> cell;
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      t.query(i, j);
    }
  }
  auto res = t.res;
  auto ans = res;
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
# 解き直し
import collections

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)

total = 0
for v in c.values():
    total += v * (v - 1) // 2

for k_ball in A:
    cnt = c[k_ball]
    print(total - (cnt * (cnt - 1) // 2) + ((cnt - 1) * (cnt - 2) // 2))

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

const int MOD = 1e9 + 7;
ll dp[70][2][2][2];

ll solve(ll l, ll r, int pos, bool limit1, bool limit2, bool lead) {
	if (pos < 0) return 1;
	ll &ans = dp[pos][limit1][limit2][lead];
	if (ans != -1) return ans;
	ans = 0;
	int up2 = limit2 ? (r >> pos & 1) : 1;
	int up1 = limit1 ? (l >> pos & 1) : 0;
	for (int i = up1; i <= 1; i++)
		for (int j = 0; j <= up2; j++) {
			if (i > j) continue;
			if (lead && i != j) continue;
			(ans += solve(l, r, pos - 1, limit1 && i == up1, limit2 && j == up2, lead && j == 0)) %= MOD;
		}
	return ans;	
}

int main() {
	memset(dp, -1, sizeof(dp));
	ll l, r;
	scanf("%lld%lld", &l, &r);
	printf("%lld", solve(l, r, 60, 1, 1, 1));
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a[n];

    int ans = 0;
    rep(i, n) {
        int b;
        cin >> b;
        b--;
        for (auto e : a[i]) {
            if (e == b) {
                ans++;
                break;
            }
        }
        a[b].push_back(i);
    }

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


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            sum = sum + a;
            if (max < a) {
                max = a;
            }
            if (min > a) {
                min = a;
            }
            
        }
        System.out.println(min + " " + max + " " + sum);
    }
}

Measured memory_bytes: 42000
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef map<ll, ll> M;

const ll INF = 1e9 + 100;
const ll MOD = 1e9 + 7;

ll n, m, m_;
V ya, pr;
vector<P> ps;

vector<ll> prime(ll n)
{
    vector<bool> num;
    vector<ll> p;

    for (ll i = 0; i <= n + 10; i++)
        num.push_back(true);

    FOR(i, 2, n)
    {
        if (!num[i])
            continue;

        p.push_back(i);

        for (ll j = i * 2; j <= n; j += i)
        {
            num[j] = false;
        }
    }

    return p;
}

ll solve(ll pos, ll val)
{
    ll hoge = m_;

    if (pos == ps.size() - 1)
    {
        REP(i, ps[pos].first + 1)
        {
            ll hoge_ = val * pow(ps[pos].second, i);

            if (hoge_ >= n)
            {
                hoge = min(hoge_, hoge);
            }
        }
        return hoge;
    }

    REP(i, ps[pos].first + 1)
    {
        ll hoge_ = solve(pos + 1, val * pow(ps[pos].second, i));

        if (hoge_ >= n)
            hoge = min(hoge_, hoge);
    }

    return hoge;
}

int main()
{
    pr = prime(1000000);
    cin >> n >> m;
    m_ = m;

    if (m == 1)
    {
        cout << 1 << endl;
        return 0;
    }

    ll ind = 0;
    while (m > 1)
    {
        if (m % pr[ind] != 0)
        {
            ind++;
            if (ind >= pr.size())
            {
                ya.push_back(m);
                ps.push_back(P(1, m));
                m = 1;
            }
        }
        else
        {
            m /= pr[ind];
            ya.push_back(pr[ind]);

            if (ps.size() == 0 || ps[ps.size() - 1].second != pr[ind])
            {
                ps.push_back(P(0, pr[ind]));
            }

            ps[ps.size() - 1].first++;
        }
    }

    cout << m_ / solve(0, 1) << endl;

    return 0;
}

Measured memory_bytes: 1528
x, n = map(int, input().split())

x1 = x
x2 = x

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    if x not in p:
        print(x)
    else:
        while True:
            x1 -= 1
            x2 += 1
        
            if x1 not in p:
                print(x1)
                exit()
            
            if x2 not in p:
                print(x2)
                exit()

Measured memory_bytes: 61716
local n, m = io.read("*n", "*n")
local a = {}
for i = 1, n do
  a[i] = {io.read("*n", "*n")}
end
local b = {}
for i = 1, m do
  b[i] = {io.read("*n", "*n")}
end
local mab = math.abs
local function solve(i, j)
  return mab(a[i][1] - b[j][1]) + mab(a[i][2] - b[j][2])
end
for i = 1, n do
  local p, v = 1, solve(i, 1)
  for j = 2, m do
    local tv = solve(i, j)
    if tv < v then
      p, v = j, tv
    end
  end
  print(p)
end


Measured memory_bytes: 760
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n;cin>>n;
    ll a=0,b=0,c=0,d=0;
    rep(i,n){
        string s;cin>>s;
        if(s=="AC")a++;
        if(s=="WA")b++;
        if(s=="TLE")c++;
        if(s=="RE")d++;
    }
    cout<<"AC"<<" x "<<a<<endl;
    cout<<"WA"<<" x "<<b<<endl;
    cout<<"TLE"<<" x "<<c<<endl;
    cout<<"RE"<<" x "<<d<<endl;
}

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

int main(void) {
    int N,M;
    int a[50], b[50], co[50] = {};
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < M; i++) {
        co[a[i]] ++;
        co[b[i]] ++;
    }
    for (int i = 1; i <= N; i++) {
        cout << co[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
 

//result = Math.pow(num1, num3)
//StringBuffer str = new StringBuffer(hoge1);
//String hoge2 = str.reverse().toString();
//map.containsKey(A)
//Map<String, Integer> map = new HashMap<String, Integer>(n);
//ArrayList<String> cc = new ArrayList<>(n);
//Collections.sort(list);
//Array.sort(list);
//Arrays.asList(c).contains("a")

public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	//static String eikomoji[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
	
	
	public static void main(String[] args) {
	int a=sc.nextInt();
	int b=sc.nextInt();
	if(a==b) {
		p("Yes");
	}else {
		p("No");
	}
	
 }
}


Measured memory_bytes: 22868
#include<iostream>
#include<cstring>
#include<algorithm>
#define INF 1<<28
using namespace std;
 
int p[222];
int memo[1111111];
int memo2[1111111];
 
int solve(int n){
   
  if(!n) return 0;
  if(~memo[n]) return memo[n];
 
  int ans = INF;
  for(int i=180;i>0;i--) if(n >= p[i]) ans = min(ans, solve(n-p[i])+1);
   
  return memo[n] = ans;
}
 
int solve2(int n){
   
  if(!n) return 0;
  if(~memo2[n]) return memo2[n];
 
  int ans = INF;
  for(int i=180;i>0;i--) if(p[i]&1 && n >= p[i]) ans = min(ans, solve2(n-p[i])+1);
 
  return memo2[n] = ans;
}
 
int main(){
   
  int n;
   
  memset(memo, -1, sizeof(memo));
  memset(memo2, -1, sizeof(memo2));
 
  for(int i=0;i<181;i++) p[i] = i*(i+1)*(i+2)/6;
  while(cin >> n, n) cout << solve(n) << " " << solve2(n) << endl;
 
}

Measured memory_bytes: 9848
/*input
20 3
5 10 15
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	ll k, ans = 0; cin >> k;
   	int n; cin >> n;
   	vector<int> a(n);
   	for(int i = 0; i < n; i++) cin >> a[i];
   	vector<int> d(n, k - a[n - 1] + a[0]);
   	for(int i = 1; i < n; i++) d[i] = a[i] - a[i - 1];
   	sort(d.begin(), d.end());
   	for(int i = 0; i < n - 1; i++) ans += d[i];
   	cout << ans;

    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

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

    int H = sc.nextInt();
    int W = sc.nextInt();

    boolean[][] grid = new boolean[H+2][W+2];
    boolean[][] plot = new boolean[H+2][W+2];

    for (int i=1; i <= H; i++) {
      String str = sc.next();

      for (int j=1; j <= W; j++) {
        char c = str.charAt(j-1);
        String strAt = String.valueOf(c);

        if (strAt.equals("#")) {
          grid[i-1][j] = true;
          grid[i+1][j] = true;
          grid[i][j-1] = true;
          grid[i][j+1] = true;

          plot[i][j] = true;
        }
      }
    }

    String ans = "Yes";

    for (int i=1; i <= H; i++) {
      for (int j=1; j <= W; j++) {
        if (plot[i][j] == true && grid[i][j] == false) {
          ans = "No";
        }
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define deb(x) cout<<#x<<" " <<x<<"\n";
#define pi 3.1415926535897932384626433832795
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define cr7 ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))
/*
1
0
2
*/
int main()
{
    cr7
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    ll n, k;
    cin >> n >> k;
    map<ll, ll> mp;
    while (k--) {
        ll d;
        cin >> d;
        for (ll i = 0; i < d; ++i) {
            ll y;
            cin >> y;
            mp[y]++;
        }
    }
    ll i, c = 0;
    for (i = 1; i <= n; ++i) {
        if (mp[i] == 0) {
            c++;
        }
    }
    cout << c << "\n";
    return 0;
}

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

int main() {
    int marble_number = 0;
    cin >> marble_number;

    // 条件分岐を利用しない前提
    // 各、位の値がある場合のみ、marble_numberから数字が減算される
    int hundred = marble_number / 100;
    marble_number -= (100*hundred);
    int ten = marble_number / 10;
    marble_number -= (10*ten);
    int one = marble_number;
    int answer = hundred + ten + one;
    cout << answer;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define t1(a) cout << #a << ":" << a << endl;
#define t2(a, b) cout << #a << ":" << a << " | " << #b << ":" << b << endl;
#define t3(a, b, c) cout << #a << ":" << a << " | " << #b << ":" << b << " | " << #c << ":" << c << endl;

using namespace std;

int main()
{
  char A[12];
  char B[12];
  cin>> A;
  cin >> B;

  if(strlen(A)!=strlen(B)-1)
  {
    cout<<"No"<<endl;
    
    return 0;
  }
  for(int i=0;i<strlen(A);i++)
       {
        if(A[i]!=B[i])
        {
            cout<<"No"<<endl;
            return 0;
        }   
       }  
  
    cout<<"Yes"<<endl;
 
  return 0;
}

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

inline bool isp(const int &x){
    for(int i=2;i*i<=x;i++){
        if(x%i==0)return false;
    }
    return true;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int x;
    cin>>x;
    while(!isp(x))x++;
    cout<<x<<endl;

    return 0;
}

Measured memory_bytes: 256
# ABC073D - joisino's travel (218ms)
from heapq import heapify, heappop, heappush
from itertools import permutations


def dijkstra(G: "Array[Array[int]]", size: int, start: int) -> list:
    dist = [float("inf")] * size
    unchecked = size - 1  # vertex_0 won't appear in 1-idx graph
    queue = [(0, start)]
    heapify(queue)
    while queue:
        cost, v = heappop(queue)
        if cost > dist[v]:
            continue
        dist[v] = cost
        for next_cost, u in G[v]:
            if cost + next_cost < dist[u]:
                heappush(queue, (cost + next_cost, u))
        unchecked -= 1
        if not unchecked:
            return dist


def main():
    global G, N
    N, M, R, *RABC = map(int, open(0).read().split())
    visit, ABC = RABC[:R], RABC[R:]
    G = [[] for _ in range(N + 1)]
    for v, u, cost in zip(*[iter(ABC)] * 3):
        G[v].append((cost, u)), G[u].append((cost, v))
    dist = {v: dijkstra(G, N + 1, v) for v in visit}
    ans = float("inf")
    for perm in permutations(visit):
        cur = sum(dist[v][u] for v, u in zip(perm, perm[1:]))
        ans = min(ans, cur)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9836
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int H,W,i,j;
  
    while(true){
          cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        else{
            for(i=0;i<H;i++){
                for(j=0;j<W;j++){
                cout<<"#";
                }
                cout<<endl;
            }
            cout<<endl;
        }
    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)


int main() {

  int N,M; cin >> N >> M ;

  vector<int> A(M);

  rep(i,M) cin >> A[i];

  ll sum=0;

  rep(i,M) sum+=A[i];

  ll ans=N-sum;

  if(ans<0) cout << -1 << endl;

  else cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
#include<iostream> 
using namespace std; 
int main() 
{ 
	int a, b, c, max, med, min;
	cin >> a >> b >> c;
	if (a > b) {
		max = a; med = b;
	}
	else { max = b; med = a; }
	if (c > max) { min = med; med = max; max = c; }
	else if (c > med) { min = med; med = c; }
	else min = c;
	for (a = 0; a < 7; a++)
	{
		cin >> c;
		if (c > max) { min = med; med = max; max = c; }
		else if (c > med) { min = med; med = c; }
		else if (c>min) min = c;
	}
	cout << max << '\n' << med << '\n' << min << endl;
	return 0; 
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stack>
#include <climits>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

struct Point
{
	double x,y;
};

void koch(int n,Point a,Point b)
{
	if(n==0) return ;
	Point s, t, u;
	double th = M_PI * 60.0 / 180.0;

	s.x = (2.0 * a.x + 1.0 *  b.x)/3.0;
	s.y = (2.0 * a.y + 1.0 *  b.y)/3.0;
	t.x = (1.0 * a.x + 2.0 *  b.x)/3.0;
	t.y = (1.0 * a.y + 2.0 *  b.y)/3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

	koch(n - 1, a, s);
	printf("%.8f %.8f\n", s.x,s.y);
	koch(n - 1, s, u);
	printf("%.8f %.8f\n", u.x,u.y);
	koch(n - 1, u, t);
	printf("%.8f %.8f\n", t.x , t.y);
	koch(n - 1 , t,b);

}

int main()
{
	Point a, b;
	int n;cin >> n;
	 a.x = 0;
	 a.y = 0;
	 b.x = 100;
	 b.y = 0;

	 printf("%.8f %.8f\n", a.x, a.y);
	 koch(n,a,b);
	 printf("%.8f %.8f\n", b.x, b.y);

	return 0;
}


Measured memory_bytes: 3196
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <utility>

using namespace std;

template <class T>
using gp_queue=priority_queue<T, deque<T>, less<T>>;

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

struct Puzzle {
    vector<size_t> board;
    size_t cost, mdistance, gap;
    Puzzle(): board(16), cost(0), mdistance(0) {}
    Puzzle(vector<size_t> &b): board(b), cost(0), mdistance(0) {}
    bool operator<(const Puzzle &rhs) const {
        for (size_t i=0; i<16; ++i)
            if (board[i] != rhs.board[i]) 
                return board[i] < rhs.board[i];

        return false;
    }
};

size_t calc_mdistance(Puzzle p, const vector<vector<size_t>> &dtable) {
    size_t mdistance=0;
    for (size_t i=0; i<16; ++i)
        if (p.board[i] < 16)
            mdistance += dtable[i][p.board[i]-1];

    return mdistance;
}

size_t encode(vector<size_t> d) {
    size_t cur=0, enc=0;
    for (size_t i=0; i<15; ++i)
        if (d[i] == 16) {
            d[i] = 0;
            break;
        }

    for (size_t i=0; i<15; ++i) {
        cur = d[i];
        for (size_t j=i+1; j<16; ++j)
            if (cur < d[j])
                --d[j];

        (enc += d[i]) *= 15-i;
    }

    return enc;
}

struct State {
    Puzzle puzzle;
    size_t hcost;
    State() {}
    State(Puzzle &p): puzzle(p) {}
    bool operator<(const State &rhs) const {
        return hcost > rhs.hcost;
    }
};

size_t astar(Puzzle p, const vector<vector<size_t>> &dtable) {
    p.mdistance = calc_mdistance(p, dtable);
    p.cost = 0;
    State init(p);
    init.hcost = p.mdistance;

    set<size_t> visited;
    gp_queue<State> q; q.push(init);
    while (!q.empty()) {
        State s=q.top(); q.pop();
        Puzzle u=s.puzzle;

        if (!u.mdistance) return u.cost;

        visited.insert(encode(u.board));
        size_t sx=u.gap/4, sy=u.gap%4;
        for (size_t r=0; r<4; ++r) {
            size_t tx=sx+dx[r], ty=sy+dy[r];
            if (!(0<=tx && tx<4 && 0<=ty && ty<4)) continue;

            Puzzle v=u;
            v.gap = tx*4+ty;
            v.mdistance -= dtable[tx*4+ty][v.board[tx*4+ty]-1];
            v.mdistance += dtable[sx*4+sy][v.board[tx*4+ty]-1];
            swap(v.board[sx*4+sy], v.board[tx*4+ty]);

            if (!visited.count(encode(v.board))) {
                ++v.cost;
                State nstate(v);
                nstate.hcost = v.cost + v.mdistance;
                q.push(nstate);
            }
        }
    }
    return -1;
}

int main() {
    vector<vector<size_t>> dtable(16, vector<size_t>(16));
    for (size_t i=0; i<16; ++i)
        for (size_t j=0; j<16; ++j)
            dtable[i][j] = abs(int(i/4-j/4)) + abs(int(i%4-j%4));

    Puzzle in;
    for (size_t i=0; i<16; ++i) {
        scanf("%zu", &in.board[i]);
        if (!in.board[i]) {
            in.board[i] = 16;
            in.gap = i;
        }
    }

    printf("%zd\n", astar(in, dtable));
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  long long n;
  cin >> n;
  long long min = n;
  for (int64_t i = 1; i <= (int64_t)pow(n, 0.5); i++) {
    if (n%i == 0) {
      if (min > (i-1)+((n/i)-1)) {
        min = (i-1)+((n/i)-1);
      }
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 384
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        var h = int.Parse(Console.ReadLine().Trim());
        var w = int.Parse(Console.ReadLine().Trim());
        var n = int.Parse(Console.ReadLine().Trim());
        var a = Max(h, w);
        Console.WriteLine((n + a - 1) / a);
    }
}


Measured memory_bytes: 11092
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		mut a: [usize; n],
	}

	a.push(0);

	let mut kabu = 0usize;
	let mut money = 1000usize;
	for i in 0..n {
		if 0 < kabu {
			// 株あり
			if a[i] > a[i+1] {
				// 明日安くなる → すべて売る
				money  += kabu * a[i];
				kabu = 0;
			}
			else {
				// 何もしない
			}
		}
		else {
			// 株なし
			if a[i] < a[i+1] {
				// 明日高くなる → 買えるだけ買う
				let buy = money / a[i];
				money -= buy * a[i];
				kabu += buy;
			}
			else {
				// 何もしない
			}
		}
	}
	println!("{}", money);
}



Measured memory_bytes: 2128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class140
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var first = new long[N];
            var last = new long[N];
            for(int i = 0; i <N;i++)
            {
                var xl = Console.ReadLine().Split().Select(int.Parse).ToArray();
                first[i] = xl[0] - xl[1];
                last[i] = xl[0] + xl[1];
            }
            Array.Sort(last, first);
            long s = long.MinValue;
            int count = 0;
            for(int i = 0; i < N; i++)
            {
                if (s <= first[i])
                {
                    s = last[i];
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 19004
s = str(input())
n = len(s)
f = 1
for i in range(0,int((n-1)/2)):
    if s[i] != s[n-1-i]:
        f = 0
        break
for i in range(0,int((n-1)/2)):
    if s[i] != s[int((n-1)/2)-1-i]:
        f = 0
        break

if f == 1:
    print("Yes")
else:
    print("No")

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

class Point{
	int count;
	bool cross; //true:pass false:not pass
public:
	Point() : count(),cross(true){ } //constructor
	void not_cross(){ cross = false; }
	bool getCross(){ return cross; }
	void setCount(int num){ count=num; }
	int getCount(){ return count;}
	~Point() = default;
};

int main(){
	int a,b; //a:east-west b:north-south
	int n; //number of crossing
	int x,y; //not pass crossing
	
	while(std::cin >> a >> b){
		//input end
		if(a == 0 && b == 0){
			break;
		}
		
		std::vector< std::vector<Point> > road (a+1, std::vector<Point>(b+1) );
		//initialization
		for(int i=0; i<=a; ++i){
			for(int j=0; j<=b; ++j){
				Point p;
				road[i][j] = p;
			}
		}
		//construction
		std::cin >> n;
		for(int i=0; i<n; ++i){
			std::cin >> x >> y;
			road[x][y].not_cross(); //not pass
		}
		
		//search road
		for(int i=1; i<=a; ++i){
			for(int j=1; j<=b; ++j){
				if(i==1 && j==1){
					road[i][j].setCount(1); //start
				}
				//cross = true
				else if(road[i][j].getCross()){
					int num = road[i-1][j].getCount()+road[i][j-1].getCount();
					road[i][j].setCount(num);
				}
				//cross = false
				else{
					road[i][j].setCount(0);
				}
			}
		}
		//output
		std::cout << road[a][b].getCount() << std::endl;
	}
}

Measured memory_bytes: 1208