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

int a[303][303];

int cnt[303];
int ans=880301;

int n,m;

void solve(vector<int> v)
{
    if (v.empty()) return;
    memset(cnt,0,sizeof(cnt));
    for (int i=1;n>=i;i++)
    {
        int mx=-1;
        int mx_id = -1;
        for (int j:v)
        {
            if (a[i][j] > mx)
            {
                mx = a[i][j];
                mx_id = j;
            }
        }
        assert(mx_id != -1);
        cnt[mx_id]++;
    }
    int mx=-1;
    int sum=0;
    for (int j:v)
    {
        mx = max(mx,cnt[j]);
        sum += cnt[j];
    }
    assert(sum == n);
    ans = min(ans,mx);
    assert(mx != -1);
    vector<int> vv;
    bool found = false;
    for (int j:v)
    {
        if (found) vv.push_back(j);
        else if (cnt[j] == mx) found = true;
        else vv.push_back(j);
    }
    solve(vv);
    return;
}

int main ()
{
    scanf("%d %d",&n,&m);
    for (int i=1;n>=i;i++)
    {
        for (int j=1;m>=j;j++)
        {
            int x;
            scanf("%d",&x);
            a[i][x] = m-j+1;
            //scanf("%d",&a[i][j]);
        }
    }
    ans = 880301;
    vector<int> v;
    for (int i=1;m>=i;i++)
    {
        v.push_back(i);
    }
    solve(v);
    printf("%d\n",ans);
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N; cin>>N;
	int B[N+1]; int x;
	rep(i,0,N+1) B[i] = -1;
	rep(i,0,N){
		cin>>x;
		int a = -1,b = N-1;
		while(b - a > 1){
			int m = (a + b) / 2;
			if(B[m] >= x) a = m;
			else b = m;
		}B[b] = x;
	}
	rep(i,0,N+1){
		if(B[i] == -1){ cout<<i<<endl; break; }
	}
}

Measured memory_bytes: 640
import math
import copy
import sys

def zorome(num):
    return int(111*num)

inputa = input().split()
# inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputaList = [int(n) for n in inputa]

# inputb = input().split()
# inputbList = [int(n) for n in inputb]
#
# inputList = []
# inputNumList = []
# for i in range(a):
#     inputNum = input().split()
#     inputNumList = list(inputNum[0])
#     inputList.append(inputNumList)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

listNum = list(str(a))

if int(a) <= zorome(int(listNum[0])):
    print(zorome(int(listNum[0])))
else:
    print(zorome(int(listNum[0])+1))





Measured memory_bytes: 3444
S = input()
N = len(S)
ans = 0

#125の場合、1<ここ>2<ここ>5で2箇所に+が入るか否かの2**(N-1)通りのbit全探索
for i in range(2**(N-1)):
    #最終的に1<>2<>5の5の部分がtmp_Sに残る。これをあとで足す
    tmp_S = ""
    #1+2+5をans+=1,ans+=2としたいところでans+=12とならないようにcheck_jを残す
    check_j = 0
    for j in range(N-1):
        if i >> j & 1:
            ans += int(S[check_j:j+1])
            check_j = j+1
            tmp_S = S[j+1:]
    if tmp_S:
        ans += int(tmp_S)

# 最後に+が0個のパターンを足す
ans += int(S)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
signed main()
{
    int n;
    cin >> n;
    vi a(n);
    vi b(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if (n % 2)
    {
        int x = a[n / 2], y = b[n / 2];
        cout << (y - x + 1) << endl;
    }
    else
    {
        int x1 = a[n / 2], x2 = a[(n - 1) / 2], y1 = b[n / 2], y2 = b[(n - 1) / 2];
        cout << (y2 + y1 - x2 - x1 + 1) << endl;
    }
    return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(a,b,c,d);
  cout << max(a * b, c * d) << endl;

  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
      int X = scan.nextInt();
      int Y = scan.nextInt();
      Boolean ans = false;
      
      for(int i=0; i<=X; i++){
        if(Y == (2*i) + (4*(X-i)))
          ans = true;
      }
      if(ans == true)
        System.out.println("Yes");
      else
        System.out.println("No");
   }
}

Measured memory_bytes: 35676
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
int main (void)
{
	int n,q,t;
	queue< pair<int,int> > queue;
	cin >> n >> q;
	vector< string > name(n);
	vector< int > time(n);
	for(int i=0;i<n;i++){
		cin >> name[i] >> t;
		queue.push(pair<int,int>(i,t));
	}
	t=0;
	while(!queue.empty()){
		if(queue.front().second-q<=0){
			t+=queue.front().second;
			cout << name[queue.front().first] << " " << t << endl;
		}
		else{
			t+=q;
			queue.push(pair<int,int>(queue.front().first,queue.front().second-q));
		}
		queue.pop();
	}
	return 0;
}

Measured memory_bytes: 4440
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define REP(i,n) for(int i=0;i<signed(n);i++)
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
const ll MOD = 1000000007;
const ll INF = 9e9;
ll N,M,ans=INF;
ll A[300010],S[301000];
int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){
        cin>>A[i];
        S[i]+=A[i];
        S[i+1]=S[i];
    }
    //a:右半分の区切り i:真ん中 b:左半分
    //s:右の和 t:左の和
    ll a=0,b=2,s,t;
    REP(i,N-2){
        if(i==b)b++;
        s=(S[i]-S[a])-S[a];
        t=(S[N-1]-S[b])-(S[b]-S[i]);
        bool f=true;
        if(i==0)continue;
        while(f){
            f=false;
            if(a+1==i)continue;
            if(std::abs(s)>std::abs(s-A[a+1]*2)){
                s-=A[a+1]*2;
                a++;f=true;
            }
        }
        f=true;
        while(f){
            f=false;
            if(b+1==N-1)continue;
            if(std::abs(t)>std::abs(t-A[b+1]*2)){
                t-=A[b+1]*2;
                b++;f=true;
            }
        }
        ans=min( ans,( max({S[a],S[i]-S[a],S[b]-S[i],S[N-1]-S[b]})
        -min({S[a],S[i]-S[a],S[b]-S[i],S[N-1]-S[b]}) ) );
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3840
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;

LL n,c1 = 0,c0 = 0,cnt[5] = {0};
LL p[400005] = {0},usd[400005] = {0};
vector <LL> G[2];

LL ec = 0,to[400005],nxt[400005],hed[200005] = {0};
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

LL col[400005] = {0};
void dfs(LL u,LL f){
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		col[v] = 1 - col[u];
		dfs(v,u);
	}
}

int main(){
	ios::sync_with_stdio(false);
	LL u,v;
	cin >> n;
	for(LL i = 1;i < n;i ++){
		cin >> u >> v;
		add_edge(u,v);
		add_edge(v,u);
	}
	col[1] = 0; dfs(1,0);
	for(LL i = 1;i <= n;i ++) cnt[i % 3] ++;
	for(LL i = 1;i <= n;i ++){
		if(col[i] == 0){
			c0 ++;
			G[0].push_back(i);
		}
		if(col[i] == 1){
			c1 ++;
			G[1].push_back(i);
		}
	}
	if(c0 > c1){
		swap(c0,c1);
		swap(G[0],G[1]);
	}
	if(c0 <= cnt[0]){
		LL tot = 0;
		for(LL i = 0;i < G[0].size();i ++){
			v = G[0][i];
			p[v] = (i + 1) * 3; usd[(i + 1) * 3] = 1;
		}
		for(LL i = 1;i <= n;i ++){
			while(usd[tot + 1]) tot ++;
			if(!p[i]) p[i] = ++ tot;
		}
	}
	else{
		LL tot = 0;
		for(LL i = 0;i < G[0].size();i ++){
			v = G[0][i];
			if(i * 3 + 2 > n) break;
			p[v] = i * 3 + 2; usd[i * 3 + 2] = 1;
		}
		for(LL i = 0;i < G[1].size();i ++){
			v = G[1][i];
			if(i * 3 + 1 > n) break;
			p[v] = i * 3 + 1; usd[i * 3 + 1] = 1;
		}
		for(LL i = 1;i <= n;i ++){
			while(usd[tot + 1]) tot ++;
			if(!p[i]) p[i] = ++ tot;
		}
	}
	for(LL i = 1;i <= n;i ++) cout << p[i] << (i == n ? '\n' : ' ');
	return 0;
}
/*
8
1 2 2 3 2 4 4 8 3 5 3 6 5 7
*/

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct UnionFind {
private:
    vector<int> par,sizes;
public:
    UnionFind (int n) {
        par.resize(n);
        sizes = vector<int>(n,1);
        for (int i = 0;i < n;++i) par[i] = i;
    }

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

    void unite(int x,int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x,y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

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

    int size(int x) {
        return sizes[find(x)];
    }
};

int main() {
    int n,r;
    cin >> n >> r;
    int s = min(r,n-r);
    vector<int> a(n),b;
    bitset<300010> bs;
    bs.set(0); 
    UnionFind uf(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) uf.unite(i,a[i]-1);
    for (int i = 0;i < n;++i) if (uf.find(i) == i) b.push_back(uf.size(i));
    for (int& i : b) {
        bs |= (bs<<i);
        if (bs[s]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 8428
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

struct card{
	int r,c;
	ll a;
	bool operator<(const card &rhs){
		return (a>rhs.a);
	}
};

card v[100100];
int ufp[225816],ufv[225816],ufe[225816];

void ufinit(int n){
	int i;
	for(i=0; i<n; ++i){
		ufp[i] = i;
		ufv[i] = 1;
	}
}

int ufind(int x){
	if(ufp[x] == x){
		return x;
	}
	return ufp[x] = ufind(ufp[x]);
}

bool unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x==y){
		if(ufe[x]<ufv[x]){
			++ufe[x];
			return true;
		}else{
			return false;
		}
	}
	if(ufv[x]<ufv[y]){
		swap(x,y);
	}
	if(ufe[x]+ufe[y]<ufv[x]+ufv[y]){
		ufv[x] += ufv[y];
		ufe[x] += ufe[y]+1;
		ufp[y] = x;
		return true;
	}
	return false;
}

int main(void){
	int n,h,w,i;
	ll ans = 0ll;
	cin >> n >> h >> w;
	ufinit(h+w);
	for(i=0; i<n; ++i){
		cin >> v[i].r >> v[i].c >> v[i].a;
		--v[i].r; --v[i].c; v[i].c += h;
	}
	sort(v,v+n);
	for(i=0; i<n; ++i){
		if(unionf(v[i].r,v[i].c)){
			ans += v[i].a;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3840
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	string str[4] = {"Christmas Eve Eve Eve", "Christmas Eve Eve", "Christmas Eve", "Christmas"};
	cout << str[N - 22] << endl;
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    using tsii = tuple<string,int,int>;
    using vi = vector<tsii>;
    
    vi data(N);
    
    for(int i = 0;i<N;i++){
        string S;
        int P;
        cin >> S >> P;
        P *= -1;//昇順にしかやってくれないから－1をかけてくだーさい
        data.at(i) = make_tuple(S,P,i + 1);//-1かけよう
    }

//    reverse(data.begin(),data.end());
    sort(data.begin(),data.end());
//    reverse(data.begin(),data.end());
    for(int i = 0;i< N; i++){
        string S;
        int P;
        int num;
        tie(S,P,num) = data.at(i);
        P *= -1;//まいなすでプラスになおそう
        
//        cout << S << " " << P << ":" <<num << endl;
        cout << num << endl;
      }
}


Measured memory_bytes: 256
import random
import time

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(score - sum)


def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    start = time.time()
    
    last_d = [0 for i in range(26)]
    
    ans = []
    
    score1 = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
                max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2 and c[j] != 0:
                idx = j
            
        last_d[idx] = i+1
        score1 += s[i][idx]
        score1 = down_score(i+1,c,last_d,score1)
        
        ans.append(idx)

    while time.time() - start < 1.9:
        d1 = random.randint(0,D-19)
        d2 = random.randint(d1+1,d1+18)
        if d1 == d2:
            continue
        tmp_d1 = ans[d1]
        tmp_d2 = ans[d2]
        ans[d1] = tmp_d2
        ans[d2] = tmp_d1
        last_d = [0 for i in range(26)]
        score2 = 0    
        for i in range(D):
            score2 += s[i][ans[i]]
            last_d[ans[i]] = i+1
            score2 = down_score(i+1, c, last_d, score2)
        
        if score1 > score2:
            ans[d1] = tmp_d1
            ans[d2] = tmp_d2
        else:
            score1 = score2
    
    for i in range(D):
        print(ans[i]+1)  

if __name__ == "__main__":
    main()


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

int main() {
  int A;
  int B;
  int C;
  cin >> A >> B >> C;
  if (A == 5 && B == 5 && C == 7) {
    cout << "YES" << endl;
  }
  else if (A == 5 && B == 7 && C == 5) {
    cout << "YES" << endl;
  }
  else if (A == 7 && B == 5 && C == 5) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let t: Vec<i64> = (0..n).map(|_| input()).collect();
    let m: usize = input();
    let px: Vec<(usize, i64)> = (0..m)
        .map(|_| {
            let p = input();
            let x = input();
            (p, x)
        })
        .collect();

    let sum: i64 = t.iter().sum();
    for i in 0..m {
        let (p, x) = px[i];
        println!("{}", sum - t[p - 1] + x);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
#define INF (1<<29)
#define PII pair<lli,lli>
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
int dist[202][202];
lli ans;
int r;
bool vis[10];
int R[10];

void dfs(int node,int lst,int ds)
{
    if(node==r+1){
        if(ds<ans){
            ans=ds;
        }
        return;
    }

    for(int i=1;i<=r;i++){
        if(!vis[i]){
            vis[i]=true;
            if(lst==-1) dfs(node+1,i,0);
            else dfs(node+1,i,ds+dist[R[i]][R[lst]]);
            vis[i]=false;
        }
    }
}

int main()
{
    int n,m,x,y,d;
    si(n);si(m);si(r);

    for(int i=1;i<=r;i++) si(R[i]);

    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i!=j) dist[i][j]=INF;
        }
    }
    for(int i=0;i<m;i++){
        si(x);si(y);si(d);
        if(d<dist[x][y]) dist[x][y]=dist[y][x]=d;
    }

    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(dist[i][k]+dist[k][j]<dist[i][j]){
                    dist[i][j]=dist[i][k]+dist[k][j];
                }
            }
        }
    }

    ans=INF;

    dfs(1,-1,0);

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

Measured memory_bytes: 384
import java.util.Scanner;

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

	int N = scan.nextInt();
	int Y = scan.nextInt();

	int fukuzawa = -1;
	int higuchi = -1;
	int noguchi = -1;
	int flag = 0;
	loop: for(int i = 0; i <= N; i++){
	    for(int j = 0; j <= N-i; j++){
		int k = N-i-j;
		int money = 10000*i+5000*j+1000*k;
		if(money == Y){
		    fukuzawa = i;
		    higuchi = j;
		    noguchi = k;
		    break loop;
		}
	    }
	}
	
	
	System.out.println(fukuzawa+" "+higuchi+" "+noguchi);
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
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--)

int main() {
  int a, b, c, d, Yen;
  cin >> a >> b >> c >>d;
  Yen = 0;
  if ( a <= b ) {
    Yen += a;
  }
  else {
    Yen += b;
  }
  if ( c <= d ) {
    Yen += c;
  }
  else {
    Yen += d;
  }
  
  cout << Yen << endl;
  return 0;
}






Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int n,a[110];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	int ans=0;
	int i=2;
	while(i<=n)
	{
		if(a[i]==a[i-1]) ans++,i+=2;
		else i++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

while True:
    N, M = [int(x) for x in input().split()]
    if N==0 and M==0:
        break
    P = []
    for i in range(M):
        P.append([int(x) for x in input().split()])

    A = []
    for i in range(N):
        temp = 0
        for j in range(M):
            temp += P[j][i]    
        A.append(temp)

    print(max(A))


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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const double eps = 1e-9;
const int oo = 0x3f3f3f3f;
const int mod = 1000000007;

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

    int n, k; cin >> n >> k;

    vector<vi> children(n);
    int answer = 0;

    for (int i = 0; i < n; ++i){
        int u; cin >> u;
        u--;

        if (!i){
            answer += u != 0;
        } else {
            children[u].push_back(i);
        }
    }

    function<int(int,int)> dfs = [&](int s, int d){
        int dd = d;

        for (auto u : children[s]){
            int cd = dfs(u, d + 1);
            dd = max(dd, cd);
        }

        if (dd - d < k - 1){
            return dd;
        } else {
            assert(dd - d == k - 1);
            if (d > 1) answer++;
            return 0;
        }
    };

    dfs(0, 0);

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 13568
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define LB(v, x) distance((v).begin(), lower_bound(ALL(v), (x)))
#define UB(v, x) distance((v).begin(), upper_bound(ALL(v), (x)))

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#pragma endregion

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i, n) cin >> s[i];
    vector<string> cases{"AC", "WA", "TLE", "RE"};
    vector<int> ans(4,0);
    REP(i, n){
        REP(j, 4){
            if(s[i]==cases[j]) ans[j]++;
        }
    }

    cout << "AC x " << ans[0] << "\n";
    cout << "WA x " << ans[1] << "\n";
    cout << "TLE x " << ans[2] << "\n";
    cout << "RE x " << ans[3] << "\n" << endl;


    return 0;
}

Measured memory_bytes: 6368
N, M = map(int, input().split())

l = [[] for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    l[a].append(b)
    l[b].append(a)
ans = 'IMPOSSIBLE'
for i in l[0]:
    for j in l[i]:
        if j == N-1:
            ans = 'POSSIBLE'
            break
print(ans)


Measured memory_bytes: 38320
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <functional>

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    int a, b, h; cin >> a >> b >> h;
    cout << (a + b)*h / 2 << endl;
}

Measured memory_bytes: 256
import sys
#input = sys.stdin.readline

def io_generator():
	return input()
	
def ioByFile(fn='inputFile.txt'):
	with open(fn) as f:
		for line in f:
			yield line[:-1]

#+++++ +++++ +++++#
		
def main(a_io):
	c = a_io()
	tt='vowel'
	ff='consonant'
	boin=list('aiueo')
	ret=tt if c in boin else ff
	print(ret)
	
	
#+++++ +++++ +++++#

if __name__ == "__main__":
	io= lambda : io_generator()
	if sys.platform =='ios':
		testInput=ioByFile()
		io=lambda : next(testInput)
	main(io)

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


using namespace std;

// Returns the longest repeating non-overlapping
// substring in str
string longestRepeatedSubstring(string str)
{
    int n = str.length();
    int LCSRe[n+1][n+1];

    // Setting all to 0
    memset(LCSRe, 0, sizeof(LCSRe));

    string res; // To store result
    int res_length  = 0; // To store length of result

    // building table in bottom-up manner
    int i, index = 0;
    for (i=1; i<=n; i++)
    {
        for (int j=i+1; j<=n; j++)
        {
            // (j-i) > LCSRe[i-1][j-1] to remove
            // overlapping
            if (str[i-1] == str[j-1] &&
                LCSRe[i-1][j-1] < (j - i))
            {
                LCSRe[i][j] = LCSRe[i-1][j-1] + 1;

                // updating maximum length of the
                // substring and updating the finishing
                // index of the suffix
                if (LCSRe[i][j] > res_length)
                {
                    res_length = LCSRe[i][j];
                    index = max(i, index);
                }
            }
            else
                LCSRe[i][j] = 0;
        }
    }

    // If we have non-empty result, then insert all
    // characters from first character to last
    // character of string
    if (res_length > 0)
        for (i = index - res_length + 1; i <= index; i++)
            res.push_back(str[i-1]);

    return res;
}

int main() {
  int n; cin >> n;
  string s; cin >> s;
  string cur = longestRepeatedSubstring(s);
  cout << cur.length() << '\n';
}


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

int n, dp[200005], a[100005], k;

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i], dp[i] = INT_MAX;
    dp[n] = 0;
    for (int i = n - 1; i; i--)
        for (int j = i + 1, x = k; j <= n && x > 0; j++, x--)
            dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
    cout << dp[1];
    return 0;
}

Measured memory_bytes: 1024
n,k = map(int,input().split())
ls = list(map(int,input().split()))
flag = True
if 0 not in ls:
    ls.append(0)
    ls.sort()
    flag = False
ind = ls.index(0)
if flag == True:
    if ind >= k-1:
        l = ind - k + 1
    else:
        l = 0
    if ind + k - 1 <= n - 1:
        r = ind + k - 1
    else:
        r = n - 1 
    mn = float("inf")
    while True:
        if l+k-1 > r:
            break
        a = abs(ls[l]) + ls[l+k-1] + min(abs(ls[l]),ls[l+k-1])
        if a < mn:
            mn = a
        l += 1
else:
    if ind >= k:
        l = ind - k
    else:
        l = 0
    if ind + k <= n:
        r = ind + k
    else:
        r = n
    mn = float("inf")
    while True:
        if l+k > r:
            break
        a = abs(ls[l]) + ls[l+k] + min(abs(ls[l]),ls[l+k])
        if a < mn:
            mn = a
        l += 1
print(mn)


Measured memory_bytes: 20464
# include <iostream>
# include <algorithm>
# include <functional>
# define MAX 102

using namespace std;

int N;
int a[MAX];
int ans = 0;

int main () {
    cin >> N;
    for ( int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a, a+N, std::greater<int>() );
    
    for ( int i = 0; i < N; i++){
        if ( i % 2 == 0 ) { ans += a[i]; }
        else { ans -= a[i]; }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

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


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

int main() {
    int a, b, k;
    cin >> a >> b >> k;

    set<int> A;
    for (int i = 0; i < k && a + i <= b; i++) {
        A.insert(a + i);
    }
    for (int i = 0; i < k && b - i >= a; i++) {
        A.insert(b - i);
    }

    for (set<int>::iterator it = A.begin(); it != A.end(); it++) {
        cout << *it << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vi a(N); REP(i, N) cin >> a[i];

    int ans = 0;

    FOR(i, 1, N - 1) {
        vi tmp = {a[i-1], a[i], a[i+1]};
        sort(ALL(tmp));
        if (tmp[1] == a[i]) ans++;
    }

    print(ans);
}


Measured memory_bytes: 3596
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

signed main() {
	IOS;
	int h1, h2, m1, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int x = h2*60 + m2 - h1*60 - m1;
	cout << x - k;	
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define MOD 1000000007
template <typename Type>
istream &operator>>(istream &in, vector<Type> &vec) {
    ll n = vec.size();
    for (ll i = 0; i < n; i++)
        in >> vec[i];
    return in;
}
template <typename Type>
ostream &operator<<(ostream &out, vector<Type> &vec) {
    for (auto val : vec)
        out << val << " ";
    return out;
}
#define PI 3.14159265

int main()
{
   ll n,w;
   cin>>n>>w;
   vector<ll>val(n),wt(n);
   for(ll i=0;i<n;i++)
   {
       cin>>wt[i]>>val[i];
   }
   ll x=0;
   vector<ll> dp(1000000,INT_MAX);
   dp[0]=0;
   for(ll i=0;i<n;i++)
    {
        x+=val[i];
        for(ll j=x-val[i];j>=0;j--)
        {
            dp[j+val[i]] = min(dp[j+val[i]],dp[j]+wt[i]);
        }
    }
    ll ans=0;
    for(ll i=0;i<=x;i++)
    {
        if(dp[i]<=w)
        ans = max(ans,i);
    }
    cout<<ans<<endl;
   
   return 0;
}
    


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FOOR(i,a,b) for(int i=a;i<=b;i++)
#define FI first
#define SE second
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  string S;
  cin>>S;
  bool M[100000];
  FOR(i,0,(int)S.size()-1){
    M[i]=(S[i]!=S[i+1]);
  }
  int m=INF;
  FOR(i,0,(int)S.size()-1){
    if(M[i]){
      m=min(m,max(i+1,(int)S.size()-i-1));
    }
  }
  if(m==INF){
    cout<<(int)S.size()<<endl;
  }else{
    cout<<m<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 11100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[3100];
long long dp[3100][3100];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
	}
	dp[0][0]=1;
	for(int i=0;i<a;i++){
		for(int j=0;j<=b;j++){
			dp[i+1][j]=(dp[i+1][j]+dp[i][j]*2)%mod;
			if(j+p[i]<=b)dp[i+1][j+p[i]]=(dp[i+1][j+p[i]]+dp[i][j])%mod;
		}
	}
	printf("%lld\n",dp[a][b]);
}

Measured memory_bytes: 74400
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

const int INF = 100000000;
struct MinCostFlow{
    typedef pair<int, int> P; // (最短距離, 頂点の番号)

    struct Edge{
        int dst, cap, cost, rev;
        Edge() {}
        Edge(int d, int c, int cs, int r) : 
            dst(d), cap(c), cost(cs), rev(r) {}
    };

    typedef vector<Edge> Node;
    typedef vector<Node> Graph;

    Graph G;

    MinCostFlow(int N) : G(N) {}

    // from から to へ向かう容量cap, 費用costの辺を追加
    void add_edge(int src, int dst, int cap, int cost){
        G[src].push_back(Edge(dst, cap, cost, G[dst].size()));
        G[dst].push_back(Edge(src, 0, -cost, G[src].size() - 1));
    }

    // 頂点sから頂点tへの流量fの最小費用流を求める
    // 流せない場合は-1を返す
    int min_cost_flow(int s, int t, int f){
        int V = G.size();
        vector<int> h(V);
        vector<int> prevv(V), preve(V);
        int res = 0;
        while(f > 0){
            // dijkstraでhを更新する (負の辺がある場合は使えない!)
            priority_queue<P, vector<P>, greater<P>> que;
            vector<int> dist(V, INF);
            dist[s] = 0;
            que.push(P(0, s));

            while(!que.empty()){
                P p = que.top(); que.pop();
                int v = p.second;
                if(dist[v] < p.first) continue;
                for(int i = 0; i < G[v].size(); i++){
                    Edge& e = G[v][i];
                    int ndist = dist[v] + e.cost + h[v] - h[e.dst];
                    if(e.cap > 0 && dist[e.dst] > ndist){
                        dist[e.dst] = ndist;
                        prevv[e.dst] = v;
                        preve[e.dst] = i;
                        que.push(P(ndist, e.dst));
                    }
                }
            }

            if(dist[t] == INF){
                // これ以上流せない
                return -1;
            }

            for(int v = 0; v < V; v++) h[v] += dist[v];

            int d = f;
            for(int v = t; v != s; v = prevv[v]){
                d = min(d, G[prevv[v]][preve[v]].cap);
            }

            f -= d;
            res += d * h[t];
            for(int v = t; v != s; v = prevv[v]){
                Edge& e = G[prevv[v]][preve[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    const int src = 2 * n;
    const int dst = src + 1;
    MinCostFlow solver(dst + 1);
    for(int i = 0; i < n; i++){
        solver.add_edge(src, i, 1, 0);
        solver.add_edge(i + n, dst, 1, 0);
        for(int j = 0; j < n; j++){
            if(p[i] != j + 1){
                int cost = abs(i - j) * p[i];
                solver.add_edge(i, j + n, 1, cost);
            }
        }
    }
    cout << solver.min_cost_flow(src, dst, n) << endl;
    return 0;
}

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

int main() {
	string s,t="";
	cin>>s;
	int i;
	for(i=0;i<s.size();i++)
	{
	    if(s[i]=='?')
	    t+='D';
	    else
	    t+=s[i];
	}
	cout<<t<<endl;
	
	
	return 0;
}


Measured memory_bytes: 3924
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
int gcd(int n,int m){
	if(n==0) return m;
	else return gcd(m%n,n);
}

int main(){
  int A, B, C;
  cin >> A >>B >> C;
  if(C%gcd(A,B)==0) cout << "YES"<<endl;
  else cout << "NO" <<endl;
  

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 20
#define INF 2000000001
int d[MAX_V][MAX_V];
int V;
int edge[20];

void init(){
  for(int i=0;i<V;i++)
    for(int j=0;j<V;j++)
      if(i==j)d[i][j]=0;
      else d[i][j]=INF;
} 

void warshall_floyd(){
  for(int k=0;k<V;k++)
    for(int i=0;i<V;i++)
      for(int j=0;j<V;j++)
	if(d[i][k]!=INF&&d[k][j]!=INF)
	  d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}

int sum=INF;
int dp[1<<20];
vector<int> v;

int rec(int s=0){
  if(dp[s]>=0)return dp[s];
  if(s==(1<<v.size())-1)return 0;
  int res=INF;
  for(int i=0;i<v.size();i++){
    if(s>>i&1)continue;
    for(int j=0;j<v.size();j++){
      if(s>>j&1)continue;
      if(i==j)continue;
      res=min(res,rec((s|1<<i)|1<<j)+d[v[i]][v[j]]);
    }
  }
  return dp[s]=res;
}

int main(){
  int E,ans=0;
  cin>>V>>E;
  init();
  for(int i=0;i<E;i++){
    int s,t,k;
    cin>>s>>t>>k;
    edge[s]++,edge[t]++;
    d[s][t]=min(k,d[s][t]);
    d[t][s]=d[s][t];
    ans+=k;
  }
  warshall_floyd();
  memset(dp,-1,sizeof(dp));
  for(int i=0;i<V;i++)
    if(edge[i]%2)v.push_back(i);
  cout<<rec()+ans<<endl;
  return 0;
}


Measured memory_bytes: 7236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, int> PL;
constexpr int mod = 1e9 + 7;
constexpr int INF = 2e9;
constexpr int AMAX = 1e5 + 10;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<ll> cnt(AMAX, 0);
  ll res = 0;
  rep(i,n) {
    cin >> a[i];
    res += a[i];
    cnt[a[i]]++;
  }

  int q;
  cin >> q;
  while (q--) {
    int b, c, tmp;
    cin >> b >> c;
    res -= cnt[b] * b;
    res += cnt[b] * c;
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << res << endl;
  }
  return 0;
} 

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

using namespace std;

int n;

double a[10005], sum;

int main () {
	cin >> n;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
		a[i] = 1 / a[i];
		sum += a[i];
	}sum = 1 / sum;
	cout << fixed << setprecision (-1e5) << sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

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

int main() {
  ll a, b;
  while (true) {
    cin >> a >> b;
    if (cin.eof()) break;
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
  return 0;
}



Measured memory_bytes: 3092
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int b, r, g, c, s, t;
    int medal;

    void run(){
	while(sc.hasNext()){
	    b = sc.nextInt();
	    r = sc.nextInt();
	    g = sc.nextInt();
	    c = sc.nextInt();
	    s = sc.nextInt();
	    t = sc.nextInt();
	    if(!(b==0 && r==0 && g==0 && c==0 && s==0 && t==0)){
		    medal = 100;
		    solve();
	    }
	}
    }

    void solve(){
	int n;
	int turn=0;
	int Tturn = b+b*5+r+r*3+g+c+s*2;
	while(b>0){
	    b--; turn++;
	    medal += (15-3);
	    n=5;
	    while(n>0){
		n--; turn++;
		medal += (15-2);
	    }
	}
	while(r>0){
	    r--; turn++;
	    medal += (15-3);
	    n=3;
	    while(n>0){
		n--; turn++;
		medal += (15-2);
	    }
	}
	while(g>0){
	    g--; turn++;
	    medal += (7-3);
	}
	while(c>0){
	    c--; turn++;
	    medal += (2-3);
	}
	while(s>0){
	    s--; turn+=2;
	    medal -= 3;
	}
	medal -= (t-turn)*3;

	//System.out.println(t+" "+turn+"  *"+medal);
	System.out.println(medal);
    }
}

Measured memory_bytes: 22200
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	r = int(input())
	#S = list(input())
	#L,R = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	print(3*(r**2))


if __name__ == "__main__":
	main()


Measured memory_bytes: 3572
import qualified Data.Vector.Unboxed as VU

divisor :: Int -> Int -> VU.Vector (Int, Int)
divisor n i
    | n < i*i = VU.empty 
    | n `mod` i == 0 =
        if i*i /= n then
            VU.cons (i, n `quot` i) $ divisor n (i+1)
        else
            VU.cons (i,i) $ divisor n (i+1)
    | otherwise = divisor n (i+1)

main = do
    x <- readLn :: IO Int
    let res = VU.minimum $ VU.map (\(a,b) -> max (length $ show a) (length $ show b)) $ divisor x 1
    print res

Measured memory_bytes: 1916