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

int main() {
  int n; cin >> n;
  long long l0=2, l1=1;
  long long li;
  if( n ==1) cout << l1 << endl;
  else {
  for(int i = 2;i<=n;i++){
    li = l1 + l0;
    l0 = l1;
    l1 = li;
  }
  cout << li << endl;
  }
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],k,n,min_;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){cin>>a[i];}
	n--,k--;
	int ans=n/k;if(n%k) ans++;
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
	int n, m, d;
	cin >> n >> m >> d;
	vector< vector<int> > mp(n, vector<int>(m));
	string s;
	for (int i = 0; i < n; i++) {
		cin >> s;
		for (int j = 0; j < m; j++) {
			if (s[j] == '.') {
				mp[i][j] = 0;
			}
			else {
				mp[i][j] = 1;
			}
		}
	}
	int ans = 0;
	int kk = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (mp[i][j] == 0) {
				kk++;
			}
			else {
				if (kk >= d) {
					ans += (kk - d) + 1;
				}
				kk = 0;
			}
		}
		if (kk >= d) {
			ans += (kk - d) + 1;
		}
		kk = 0;
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			if (mp[j][i] == 0) {
				kk++;
			}
			else {
				if (kk >= d) {
					ans += (kk - d) + 1;
				}
				kk = 0;
			}
		}
		if (kk >= d) {
			ans += (kk - d) + 1;
		}
		kk = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3232
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll a(n+2,0) ;
	for(int i=1;i<=n;i++) cin >> a.at(i) ;
	ll def = 0 ;
	for(int i=0;i<n+1;i++){
		def += sa(a.at(i),a.at(i+1)) ;
	}
	for(int i=1;i<=n;i++){
		if((a.at(i-1)<=a.at(i)&&a.at(i)<=a.at(i+1))||(a.at(i-1)>=a.at(i)&&a.at(i)>=a.at(i+1))) cout << def << endl ;
		else{
			ll d = sa(a.at(i-1),a.at(i))+sa(a.at(i),a.at(i+1))-sa(a.at(i-1),a.at(i+1)) ;
			cout << def-d << endl ;
		}
	}
}


Measured memory_bytes: 2048
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N,T=LI()
INL = [LI() for i in range(N)]

res = INTMAX
for c, t in INL:
    if t <= T:
        res = min(res, c)

if res == INTMAX:
    print('TLE')
else:
    print(res)

Measured memory_bytes: 3064
function frequency(s) {
    var freq = new Array(26).fill(0);
    for (var i = 0; i < s.length; i++) {
        var index = s[i].charCodeAt() - "a".charCodeAt();
        freq[index]++;
    }
    return freq;
}

function freqMatch(freq1, freq2) {
    for (var i = 0; i < 26; i++) {
        freq1[i] = Math.min(freq1[i], freq2[i]);
    }
    return freq1;
}

function Main(input) {
    input = input.split("\n");
    var n = parseInt(input[0], 10);
    var strings = input.slice(1, n+1);
    var freq1 = frequency(strings[0]);
    for (var i = 1; i < strings.length; i++) {
        var freq2 = frequency(strings[i]);
        freq1 = freqMatch(freq1, freq2);
    }
    res = "";
    for (var i = 0; i < 26; i++) {
        for (var j = 0; j < freq1[i]; j++) {
            res += String.fromCharCode(i+"a".charCodeAt());
        }
    }
    console.log(res);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
# -*- coding: utf-8 -*-
"""
https://abc060.contest.atcoder.jp/tasks/arc073_b

"""
import sys
from sys import stdin
input = stdin.readline


def normal_dp(items, N, W):
    dp = [[0] * (W+1) for _ in range(N+1)]

    for y in range(1, N+1):
        w = items[y-1][0]
        v = items[y-1][1]
        for x in range(1, W+1):
            if x >= w:
                dp[y][x] = max(dp[y-1][x-w] + v, dp[y-1][x])
            else:
                dp[y][x] = dp[y-1][x]
    return dp[-1][-1]


def solve(items, N, W):
    items.sort(reverse=True)

    c_items = [[] for _ in range(4)] #  同じ重さのアイテムをまとめたもの、vで降順ソート済。[0]が一番軽いアイテムで[3]が+3だけ重い。
    min_w = items[-1][0]
    for w, v in items:
        c_items[w - min_w].append(v)
    for l in c_items:
        l.append(0)

    # ある重さのアイテムをn個選択したときのベストなvの値を計算しておく
    accumulated_v = [[0] for _ in range(4)]
    for i in range(4):
        for j, v in enumerate(c_items[i], start=1):
            accumulated_v[i].append(accumulated_v[i][-1] + v)

    total_values = []
    for iw0 in range(len(c_items[0])):
        for iw1 in range(len(c_items[1])):
            for iw2 in range(len(c_items[2])):
                for iw3 in range(len(c_items[3])):
                    total_w = (iw0 * min_w) + (iw1 * (min_w+1)) + (iw2 * (min_w+2)) + (iw3 * (min_w+3))
                    if total_w <= W:
                        total_v = accumulated_v[0][iw0] + accumulated_v[1][iw1] + accumulated_v[2][iw2] + accumulated_v[3][iw3]
                        total_values.append(total_v)
    return max(total_values)



def main(args):
    items = []
    N, W = map(int, input().split())
    for _ in range(N):
        w, v = map(int, input().split())
        items.append([w, v])
    items.sort()
    ans = solve(items, N, W)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 9804
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll =long long;
using namespace std;
using graph=vector<vector<int>>;
using field=vector<string>;
using p =pair<int,int>;
const ll mod=1000000007;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

int main(){
    ll n,k;
    cin>>n>>k;
    ll tmp1=pow(n/k,3);//tmp*tmp*tmp;
    if(k%2!=0){
        cout<<tmp1<<endl;
    }else{
        ll tmp3=pow((n+k/2)/k,3);//tmp2*tmp2*tmp2;
        cout<<tmp1+tmp3<<endl;
    }
}

Measured memory_bytes: 4112
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	int N;
	scanf("%d",&N);

	if(N%2 == 0){

		printf("%d\n",N);
	}else{

		printf("%d\n",2*N);
	}

	return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int N;
int ans = 0;

void dfs(vector<vector<int>>& A, string flag) {
	if (sz(flag) == N) {
		rep(i, N) {
			if (flag[i] == '0') continue;
			rep(j, N) {
				if (A[i][j] == -1) continue;
				if (A[i][j] == 1 && flag[j] == '0') return;
				if (A[i][j] == 0 && flag[j] == '1') return;
			}
		}
		int memo = 0;
		rep(i, N) {
			if (flag[i] == '1') memo++;
		}
		chmax(ans, memo);

		return;
	}

	dfs(A, flag + "0");
	dfs(A, flag + "1");
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	cin >> N;

	vector<vector<int>> A(N, vector<int>(N, -1));
	rep(i, N) {
		int a;
		cin >> a;
		rep(j, a) {
			int x, y;
			cin >> x >> y;
			x--;
			A[i][x] = y;
		}
	}

	dfs(A, "");

	out(ans);

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int n,k;
    int d;
    int buf;
    int ans[n];
    scanf("%d %d",&n,&k);
    //printf("%d %d\n",n,k);
    for(int i=0;i<n;i++){
        ans[i]=0;
    }
    for(int i=0;i<k;i++){
        //printf("i=%d\n",i);
        scanf("%d",&d);
        //printf("d=%d\n",d);
        for(int j=0;j<d;j++){
            scanf("%d",&buf);
            //printf("buf=%d\n",buf);
            ans[buf-1]++;
        }
    }
    int f=0;
    for(int i=0;i<n;i++){
        if(ans[i]==0) f++;
    }
    printf("%d\n",f);
    return 0;
}

Measured memory_bytes: 1744
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        
        int ans=Math.max(0,a-2*b);
        
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
while 1:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    s=""
    for _ in range(w):
        s+="#"
    print(s)
    last=s
    for H in range(h-2):
        s="#"
        for W in range(w-2):
            s+="."
        s+="#"
        print(s)
    print(last)
    print()
        


Measured memory_bytes: 5608
N,K=map(int,input().split())
v=list(map(int,input().split()))
R=min(N,K)
ans=0
for A in range(R+1):
    for B in range(R-A+1):
        C=K-(A+B)
        have=[]
        have.extend(v[:A])
        have.extend(v[N-B:])
        have.sort()
        for c in range(C):
            if len(have)>0:
                if have[0]<0:
                    have.pop(0)
                else:
                    break
        ans=max(ans,sum(have))

print(ans)

Measured memory_bytes: 3064
import Control.Monad
import Control.Applicative
import Data.List
import Debug.Trace

parse :: String -> (Int, String)
parse xs =
    let (prev,t:rst) = break (== ']') xs
        x = read prev
    in ((x + 1) `div` 2, rst)

calc :: [Int] -> Int
calc xs =
    let m = ((length xs) + 1) `div` 2
    in sum $ take m $ sort xs

solve :: [Int] -> String -> (Int, String)
solve stk "" = (calc stk, "")
solve stk (c:cs)
    | c == '['  =
        let (x, rst) = solve [] cs
        in solve (x:stk) rst
    | c == ']'  =
        let x = calc stk
        in (x, cs)
    | otherwise = parse (c:cs)

main :: IO ()
main = do
    n <- readLn
    ls <- replicateM n getLine :: IO [String]
    mapM_ print $ map (fst . solve []) ls

Measured memory_bytes: 14312
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main(){
int A[3];
 
cin >> A[0] >> A[1] >> A[2];
 
sort(A,A+3);
 
cout << A[0]  << " "<< A[1] << " " <<A[2] << endl;
 
}


Measured memory_bytes: 3120
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int N; cin >> N;
  string str = "";
  while (N != 0) {
    /* N を 2 で割ったあまりを求める */
    int r = N % 2;
    if (r < 0) r += 2; // N がマイナスだと r がマイナスになったりするので 2 を足す

    /* N から余りを取り除いて -2 で割る */
    N = (N - r) / (-2);

    /* 答えに追加 */
    str += (char)('0' + r);
  }
  /* 向きが逆なので反転 */
  reverse(str.begin(), str.end());
  if (str == "") str = "0"; // N = 0 のときは空文字列になってしまうので例外処理
  cout << str << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//オーバーフローに注意 long long　にする
//'1'+=16;      で大文字Aに
//'大文字'+=32;  で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);


 
int main() {

  int n,m,q;
  cin >> n >> m >> q;
  
  vector<int> a(q);
  vector<int> b(q);
  vector<int> c(q);
  vector<int> d(q);

  rep(i,q) {
  cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  
  int ans = 0;
  
  vector<int> p(0);
  rep(i,n) {
  p.pb(0);
  }
  rep(i,m-1) {
  p.pb(1);
  }
     
  do {
      vector<int> A = {1};
    int num = 1;
    rep(i,m+n) {
      if(p[i]==0) A.pb(num);
      else num++;
    }
      A.pb(m);
      
      int ten = 0;
      rep(i,q) {
      if(A[b[i]]-A[a[i]]==c[i]) ten+=d[i];
      }
      ans=max(ans,ten);

  } while (next_permutation(p.begin(), p.end()));  
  
  cout << ans << endl;
}



Measured memory_bytes: 3632
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int N=101;

int cost[N][N];
int tim[N][N];

int bfs(int n,int p,int q,int graph[N][N]){
  vector<int> v(n);
  queue<int> que;
  rep(i,n)v[i]=INF;
  v[p]=0;
  que.push(p);
  int u;
  while(!que.empty()){
    u=que.front(),que.pop();
   
    rep(i,n){
      if(v[i]>v[u]+graph[u][i]){
        v[i]=v[u]+graph[u][i];
        que.push(i);
      }
    }
  }
  return v[q];
}


signed main(){
  int n,m;
  while(cin>>n>>m,n!=0){ 
    rep(i,m)rep(j,m){
      cost[i][j]=(i==j?0:INF);
      tim[i][j]=(i==j?0:INF);
    }
    rep(i,n){
      int a,b,c,t;
      cin>>a>>b>>c>>t;
      a--;b--;
      cost[a][b]=cost[b][a]=c;
      tim[a][b]=tim[b][a]=t;
    }
    int k;
    cin>>k;
    rep(i,k){
      int p,q,r;
      cin>>p>>q>>r;
      p--;q--;
      int ans;
      if(r==0){
        ans=bfs(m,p,q,cost);
      }else{
        ans=bfs(m,p,q,tim);
      }
      cout<<ans<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

struct UnionFind {
    vector<int> par, siz;

    UnionFind(int n) : par(n), siz(n, 1) {
        iota(par.begin(), par.end(), 0);
    }

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

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

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

    int size(int x) {
        return siz[root(x)];
    }
};

signed main() {
    int n;
    cin >> n;
    vector<tuple<int, int, int>> vxy;
    int x, y;
    rep(i, n) {
        cin >> x >> y;
        x--;
        y--;
        vxy.emplace_back(x, y, i);
    }
    sort(ALL(vxy));
    UnionFind uf(n);
    vector<pair<int, int>> v;
    v.emplace_back(get<1>(vxy[0]), get<2>(vxy[0]));
    rep(i, n) {
        auto itr = v.rbegin();
        while (itr != v.rend() && itr->first < get<1>(vxy[i])) {
            uf.unite(get<2>(vxy[i]), itr->second);
            itr++;
        }
        if (v.back().first > get<1>(vxy[i]))
            v.emplace_back(get<1>(vxy[i]), get<2>(vxy[i]));
    }
    rep(i, n) {
        cout << uf.size(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 7660
import math
N,K=map(int, input().split())
A = input().split()
l = A.index("1")
r = len(A) - l - 1

ama=l%(K-1)
l = max(l-ama, 0)
r = max(r-(K-1-ama), 0)

print(1+math.ceil(l/(K-1))+math.ceil(r/(K-1)))


Measured memory_bytes: 10420
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a + W < b){
			System.out.println(b - (a + W));
		}else if((a <= b && b <= a + W) || (b <= a && a <= b + W)){
			System.out.println(0);
		}else
			System.out.println(a - (b + W));

	}

}

Measured memory_bytes: 22996
# D
N, W = map(int, input().split())
 
import numpy as np
dp = np.zeros(W+1, dtype="int64")
 
for i in range(1, N+1):
    w, v = map(int, input().split())
    dp[w:] = np.maximum(dp[w:], dp[0:W-w+1] + v)
 
print(dp[-1])

Measured memory_bytes: 15488
#include <cstdio>

int main()
{
    int N;
    scanf("%d", &N);
    for (int i = 1; i <= 50000; i++)
    {
        if (i * 108 / 100 == N)
        {
            printf("%d\n", i);
            return 0;
        }
    }
    printf(":(\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int read(){
	int x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,m,k;
int maxx,maxy;
unordered_map<int,int> x,y;
#define P pair<int,int>
map<pair<int,int>,bool> vis;
bool pd(int xx,int yy){
	return vis[P(xx,yy)];
}
vector<int> Ax,Ay;
int main()
{
	n = read();m = read();k =read();
	for(int i = 1;i <= k;i++)
	{
		int a = read(), b = read();
		x[a] ++;
		y[b] ++;
		vis[P(a,b)] = 1;
		if(x[a] > maxx)
		{
			Ax.clear();maxx = x[a];Ax.push_back(a);
		} 
		else if(x[a] == maxx) Ax.push_back(a);
		if(y[b] > maxy) 
		{
			Ay.clear();maxy = y[b];Ay.push_back(b);
		}
		else if(y[b] == maxy) Ay.push_back(b);
//		cout << x[a] << " "<<y[b]<<endl;
	}
	int ans = 0;
	for(int i = 0;i < Ax.size();i++)
	{
		for(int j = 0;j < Ay.size();j++){
			ans = maxx+maxy-pd(Ax[i],Ay[j]);
			if(ans == maxy + maxx) {
				cout << ans << endl;
				return 0;
			}
		}
	}
	cout << maxx+maxy - 1 << endl;
	return 0;
//	cout << maxx <<" "<< maxy <<endl;
//	cout << x[maxx]+y[maxy]-pd(maxx,maxy) << endl;
	return 0;
}

Measured memory_bytes: 51328
#! python3
# standard_deviation.py

import math

while True:
    n = int(input())
    if n == 0: break
    s = [int(x) for x in input().split(' ')]

    sum = 0
    for num in s:
        sum += num
    m = sum/n

    tmp_sum = 0
    for num in s:
        tmp_sum += pow(num - m, 2)

    print("%.5f"%(math.sqrt(tmp_sum/n)))


Measured memory_bytes: 5708
#include<stdio.h>
#include<new>

class HeapTree {
private:
	int heap_size_, *A_;
	void maxHeapify(int i);
public:
	HeapTree();
	~HeapTree();
	void buildMaxHeap();
	void display_A_();
};

HeapTree::HeapTree()
{
	scanf("%d", &heap_size_);
	A_ = new int[heap_size_ + 1];
	for (int i = 1; i <= heap_size_; i++)
		scanf("%d", A_ + i);
}

HeapTree::~HeapTree()
{
	delete[] A_;
}

void HeapTree::maxHeapify(int i)
{
	int left{ i * 2 }, right{ i * 2 + 1 }, max;
	if (left <= heap_size_ && A_[left] > A_[i])
		max = left;
	else
		max = i;
	if (right <= heap_size_ && A_[right] > A_[max])
		max = right;

	if (max != i)
	{
		int tmp = A_[i];
		A_[i] = A_[max];
		A_[max] = tmp;
		this->maxHeapify(max);
	}
}

void HeapTree::buildMaxHeap()
{
	for (int i = heap_size_ / 2; i > 0; i--)
		maxHeapify(i);
}

void HeapTree::display_A_()
{
	for (int i = 1; i <= heap_size_; i++)
		printf(" %d", A_[i]);
	printf("\n");
}

int main()
{
	HeapTree heapTree;

	heapTree.buildMaxHeap();
	heapTree.display_A_();
	return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main(){
	int a, b, c;
	cin >> a >> b >> c;

	int ans = a + b;
	chmin(ans, a+c);
	chmin(ans, b+c);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
  int n, num;
  int MIN, MAX;
  long long SUM=0;

  std::cin >> n;

  for(int i=0; i<n; i++){
    std::cin >> num;
     SUM = SUM + num;
    if( i==0 ){
      MIN = num;
      MAX = num;
    }
    if(MIN > num){ MIN = num; }
    if(MAX < num){ MAX = num; }
  }

    std::cout << MIN << " " << MAX << " " << SUM <<std::endl;

  return 0;
}



Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            //var watch = new Stopwatch();
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);


            string s = Console.ReadLine();


            //watch.Start();

            int ans = 0;
            for(var i = 0; i < s.Length; i++)
            {
                if (s[i] == '+')
                {
                    ans++;
                }
                else { ans--; }
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();
            /*watch.Stop();

            Console.WriteLine($"time:{watch.ElapsedMilliseconds} ms"); //Debug Only.
            Console.Out.Flush();*/
        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}



Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<map>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
#include<functional>
using namespace std;
int main() {
	int N;
	cin >> N;
	string s = to_string(N);
	if (s[0] == '9' || s[1] == '9')
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	//cin >> A;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
MOD = 10 ** 9 + 7
n, m = map(int, input().split())
fact = [0] * (n + 100)
fact[0] = 1
for i in range(len(fact) - 1):
  fact[i + 1] = fact[i] * (i + 1) % MOD
factor = defaultdict(int)
for num in range(2, int(m ** (1 / 2)) + 1):
  while m % num == 0:
    m //= num
    factor[num] += 1
if m != 1:
  factor[m] += 1
ans = 1
for v in factor.values():
  ans *= (fact[v + n - 1] * pow(fact[n - 1], MOD - 2, MOD) * pow(fact[v], MOD - 2, MOD)) % MOD
print(ans % MOD)

Measured memory_bytes: 7284
def bfs(s, n_path, start)
  return -1 if s[start[0]][start[1]] == "#"

  path_all = {start => true}
  path = [{start => true}]
  n_reached = 1
  step = 0
  while n_reached < n_path do
    path[step + 1] = {}
    path[step].each_key do |p|
      y, x = p
      [[y - 1, x], [y, x + 1], [y + 1, x], [y, x - 1]].each do |q|
        if s[q[0]][q[1]] == "." && !path_all.include?(q)
          path_all[q] = true
          path[step + 1][q] = true
          n_reached += 1
        end
      end
    end
    step += 1
  end
  return step
end

h, w = gets.split.map(&:to_i)
s = h.times.map { "#" + gets.chomp + "#" }
s.unshift("#" * (w + 2))
s.push("#" * (w + 2))
n_path = 0
for i in 1..h do
  n_path += s[i].count(".")
end
max_count = 0
for i in 1..h do
  for j in 1..w do
    count = bfs(s, n_path, [i, j])
    max_count = count if max_count < count
  end
end
puts max_count


Measured memory_bytes: 1916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;

	void solve() {
		int[] ia = readNums();
		int h = ia[0];
		int w = ia[1];
		for (int i = 0; i < w + 2; i++) {
			p("#");
		}
		pln("");
		for (int i = 0; i < h; i++) {
			String line = readLine();
			p("#");
			p(line);
			p("#");
			pln("");
		}
		for (int i = 0; i < w + 2; i++) {
			p("#");
		}
		pln("");
	}

	// -----------------------------------------------------
	// 2018/04/26 r2
	// -----------------------------------------------------
	int abs(int a) {
		return (a >= 0) ? a : -a;
	}

	long abs(long a) {
		return (a >= 0) ? a : -a;
	}

	int max(int a, int b) {
		return (a > b) ? a : b;
	}

	long max(long a, long b) {
		return (a > b) ? a : b;
	}

	int min(int a, int b) {
		return (a < b) ? a : b;
	}

	long min(long a, long b) {
		return (a < b) ? a : b;
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	long readLong() {
		String line = readLine();
		return plong(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++)
			nums[i] = pint(flds[i]);
		return nums;
	}

	long[] readLongs() {
		String[] flds = readFlds();
		long[] nums = new long[flds.length];
		for (int i = 0; i < flds.length; i++)
			nums[i] = plong(flds[i]);
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	void pln(int[] ia) {
		for (int i = 0; i < ia.length; i++)
			pln(ia[i]);
	}

	void pln(long[] la) {
		for (int i = 0; i < la.length; i++)
			pln(la[i]);
	}

	static BufferedReader _in;
	static PrintWriter _out;
	static boolean _bElapsed = false;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (_bElapsed)
			System.err.println((end - start) + "ms");
	}
}


Measured memory_bytes: 19540
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
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; }
const long long MOD = 1000000007;
const long long INF = (1LL << 60);
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n; vector<int>h(n);
	rep(i, n)cin >> h[i];
	int dp[100010];
	for (int i = 0; i < 100010; i++) dp[i] = INF;
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1)chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>

using namespace std;
const int N=2e5+10,inf=1e9;
int dp[N][2];
char s[N];

int main(){
    int first,second;
    string s,ans;
	cin >> s;
    first = 10*(s[0]-'0')+(s[1]-'0');
    second = 10*(s[2]-'0')+(s[3]-'0');

    if((first>=1 && first<=12) && (second>=1 && second<=12)){
        ans = "AMBIGUOUS";
    }else if((first>=1 && first<=12) && (second<1 || second>12)){
        ans = "MMYY";
    }else if((first<1 || first>12) && (second>=1 && second<=12)){
        ans = "YYMM";
    }else{
        ans = "NA";
    }

	cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli a, n, b;
    cin>>n>>a>>b;
    out(min(a*n, b));
}

Measured memory_bytes: 3612
import java.util.*;

class Dice{
    int top,front,right,left,back,bottom;   //1,2,3,4,5,6

    //コンストラクタ
    Dice(int d1,int d2,int d3,int d4,int d5,int d6){
        top = d1;
        front = d2;
        right = d3;
        left = d4;
        back = d5;
        bottom = d6;
    }

    //前面を返すクラス
    int TurnFront(int d1,int d3){
        int result;
        //上面1or6の時
        if(d1 == top || d1 == bottom){
            if(d3 == front) result = 3;
            else if(d3 == right) result = 5;
            else if(d3 == left) result = 2;
            else    result = 4;
        }
        //上面2or5の時
        else if(d1 == front || d1 == back){
            if(d3 == top)   result = 4;
            else if(d3 == right)    result = 1;
            else if(d3 == left) result = 6;
            else    result = 3;
        }
        //上面3or4の時
        else{
            if(d3 == top)   result = 2;
            else if(d3 == front)    result = 6;
            else if(d3 == back) result = 1;
            else    result = 5;
        }
        //上面4or5or6の時
        if(d1 == left || d1 == back || d1 == bottom)    result = 7 - result;

        return result;
    }
}

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int d1 = sc.nextInt();
        int d2 = sc.nextInt();
        int d3 = sc.nextInt();
        int d4 = sc.nextInt();
        int d5 = sc.nextInt();
        int d6 = sc.nextInt();

        Dice d = new Dice(d1,d2,d3,d4,d5,d6);

        int num = sc.nextInt();

        for(int i = 0;i < num;i++){
            int t = sc.nextInt();
            int f = sc.nextInt();

            int result = d.TurnFront(t,f);
            if(result == 1) System.out.println(d.top);
            if(result == 2) System.out.println(d.front);
            if(result == 3) System.out.println(d.right);
            if(result == 4) System.out.println(d.left);
            if(result == 5) System.out.println(d.back);
            if(result == 6) System.out.println(d.bottom);
        }
    }
}


Measured memory_bytes: 26176
from math import gcd

n = int(input())
a = list(map(int, input().split()))

checker = [0 for _i in range(10**6+1)]
for i in a:
    checker[i] += 1

if all(sum(checker[i::i])<2 for i in range(2,10**6+1)):
    print('pairwise coprime')
else:
    r = a[0]
    for i in a:
        r = gcd(r, i)
    if r == 1:
        print('setwise coprime')
    else:
        print('not coprime')

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

using namespace std;

int w, h;
vector< vector<int> > c, island;

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

void dfs(int x, int y, int id) {

    island[y][x] = id;

    for(int i = 0; i < 8; i++) {

        int nx = x + dx[i];
        int ny = y + dy[i];

        if(nx < 0 || nx >= w || ny < 0 || ny >= h)
            continue;

        if(c[ny][nx] == 1 && island[ny][nx] != id)
            dfs(nx, ny, id);

    }

}

int main(){

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

    int ans;

    while(cin >> w >> h, w) {

        c.assign(h, vector<int>(w));
        island.assign(h, vector<int>(w, -1));
        ans = 0;

        for(int y = 0; y < h; y++)
            for(int x = 0; x < w; x++)
                cin >> c[y][x];

        for(int x = 0; x < w; x++)
            for(int y = 0; y < h; y++)
                if(c[y][x] == 1 && island[y][x] == -1)
                    dfs(x, y, ans++);

        cout << ans << endl;

    }

    return 0;

}

Measured memory_bytes: 3220
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;

int main(){

  int n; cin >>n;
  long long a[100010];

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

  sort(a,a+n);

  int ans=0;
  for(int i=0;i<n;i++){
    int cnt=0;
    while(a[i]==a[i+1]){
      cnt++; i++;
    }
    if(cnt %2==0) ans++;
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    int n; cin >> n;
    set<ll> s;
    map<ll, ll> mp;
    rep(i,n) {
        ll tmp;
        cin >> tmp;
        s.insert(tmp);
        mp[tmp]++;
    }

    ll ans = 0;
    for (auto x : s) {
        if (mp[x] % 2 == 1)
            ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 14376
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 10000

struct node{
  struct node *r,*l,*p;
  int key;
};

typedef struct node * Node;

#define NIL NULL

int t[MAX];
Node root;

void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->l=NIL;
  z->r=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->l;
    }else{
      x=x->r;
    }
  }
  z->p=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key < y->key){
      y->l=z;
    }else{
      y->r=z;
    }
  }
}

Node treeSearch(int x,Node u){
  while(u!=NIL && x!=u->key){
    if(x<u->key){
      u=u->l;
    }else{
      u=u->r;
    }
  }
  return u;
}
  

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}

void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}
  
int main(){
  int n,i,x;
  char s[10];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s);
    if(strcmp(s,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }else if(strcmp(s,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else{
      scanf("%d",&x);
      if(treeSearch(x,root)==NIL){
	printf("no\n");
      }else{
	printf("yes\n");
      }
    }	
  }
  return 0;
}
  
  



Measured memory_bytes: 20484
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n, t;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    ll ans = 0;
    cin >> n >> t;
    ll a = 0;
    ll b = t;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (i == 1) continue;
        if (b < x) {
            ans += b - a;
            a = x;
            b = x + t;
            continue;
        }
        else {
            b = x + t;
        }
    }
    ans += b - a;
    cout << ans;
    return 0;
}

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

int main() {
    
    int n;
    double m;
    cin>>n>>m;
    double sum = 0;
    double a[n];
    for (int i=0; i<n; i++){
        cin>>a[i];
        sum += a[i];
    }
    sort(a, a+n, greater<double>());
    int count = 0;
    double limit = sum/(4*m);
    for (int i=0; i<n; i++){
        if (a[i]<limit){break;}
        else count++;
    }
    if (count>=m) cout<<"Yes";
    else cout<<"No";
}




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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long a, b, c;
	cin >> a >> b >> c;
	b = min(2*c, b);
	a = min(2*c, a);
	long long x,y;
	cin >> x >> y;
	if(2*c >= a+b) {
		return cout << x*a + y*b << endl, 0;
	}
	else {
		int mn = min(x,y);
		return cout << 2*c*mn + (x-mn)*a + (y-mn)*b << endl, 0;
	}
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int[] nums = sc.IntArray();

        int before = nums[0];

        int answer = 0;

        for (int i = 1; i < n; i++)
        {
            if (before == nums[i])
            {
                answer++;
                before = -1;
            }
            else
            {
                before = nums[i];
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int N, M;
int dist[112345];
vector<pii> g[112345];

int main() {
	cin >> N >> M;
	REP(i, M) {
		int a, b, d;
		scanf("%d %d %d", &a, &b, &d);
		a--; b--;
		g[a].push_back(pii(b, d));
		g[b].push_back(pii(a, -d));
	}
	
	fill(dist, dist + N, INF);
	REP(st, N) {
		if (dist[st] != INF) continue;
		
		queue<int> que;
		que.push(st);
		dist[st] = 0;
		
		while (!que.empty()) {
			int u = que.front(); que.pop();
			
			REP(i, g[u].size()) {
				int v = g[u][i].fi;
				int ncost = dist[u] + g[u][i].se;
				
				if (dist[v] == INF) {
					dist[v] = ncost;
					que.push(v);
				}
				else if (dist[v] != ncost) {
					puts("No");
					return 0;
				}
				
			}
		}
	}
	
	puts("Yes");
	
	return 0;
}


Measured memory_bytes: 9600
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func main() {
	a := next()
	b := next()
	c := next()
	turn := "a"
	for {
		if turn == "a" {
			if len(a) == 0 {
				fmt.Println("A")
				break
			}
			turn = string(a[0])
			a = a[1:]
		} else if turn == "b" {
			if len(b) == 0 {
				fmt.Println("B")
				break
			}
			turn = string(b[0])
			b = b[1:]
		} else {
			if len(c) == 0 {
				fmt.Println("C")
				break
			}
			turn = string(c[0])
			c = c[1:]
		}
	}
}


Measured memory_bytes: 640
#include<stdio.h>
int main( ){
  int n,m,a[100][100]={},b[100]={},c[100]={};
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(int x=0;x<m;x++){
    scanf("%d",&b[x]);
  }
  for(int y=0;y<n;y++){
    for(int s=0;s<m;s++){
      c[y]+=a[y][s]*b[s];
    }
    printf("%d\n",c[y]);
  }
  return 0;
}

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

int main() {
    string s;
    cin >> s;

    bool ok = false;
    rep(i, s.size() - 1) {
        if (s.substr(i, 2) == "AC") ok = true;
    }

    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 152 C - Low Elements
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/07/18
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <climits>
using namespace std;

int n;
int p[200000];

int main() {

    scanf("%d", &n);
    int min_p = INT_MAX;
    int cnt = 0;
    for (int i=0;i<n;i++) {
        scanf("%d", &p[i]);
        if (p[i] < min_p) {
            min_p = p[i];
            cnt++;
        }
    }
    printf("%d\n", cnt);

}

Measured memory_bytes: 3992
#include <iostream>
using namespace std;
int gcd(int x,int y){
    int r=x%y;
    while(r){
        x=y, y=r;
        r=x%y;
    }
    return y;
}
int gcd3(int a, int b, int c){
    return gcd(gcd(a,c),b);
}
int main(void){
    int k;
    cin >> k;
    int a,b,c,sum=0,g;
    //do loop for a>=b>=c only
    for(c=1;c<=k;c++){
        for(b=c;b<=k;b++){
            for(a=b;a<=k;a++){
                g=gcd3(a,b,c);
                if(c==b && b==a) sum+=g;
                else if((c==b && b!=a)||(c!=b && b==a)) sum+=3*g;
                else if(c!=b && b!=a) sum+=6*g;
            }
        }
    }
    sum=sum;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
import sys

A = []
for i in range(3):
    A.append([[int(i), False] for i in input().split()])

N = int(input())

B = []
for n in range(N):
    B.append(int(input()))

for b in B:
    for i in range(len(A)):
        for j in range(len(A[i])):
            if A[i][j][0] == b:
                A[i][j][1] = True
                break

# 縦3つ
for i in range(3):
    if A[0][i][1] and A[1][i][1] and A[2][i][1]:
        print('Yes')
        sys.exit()

# 横3つ
for i in range(3):
    if A[i][0][1] and A[i][1][1] and A[i][2][1]:
        print('Yes')
        sys.exit()

# ななめ
if A[0][0][1] and A[1][1][1] and A[2][2][1]:
        print('Yes')
        sys.exit()
if A[0][2][1] and A[1][1][1] and A[2][0][1]:
        print('Yes')
        sys.exit()

print('No')

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(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; }


int main(){ 
    int n; cin >> n;
    int res = INF;
    rept(i, 1, n){
      int A = i, B = n-A, a = 0, b = 0;
      rep(j, 6){
        int p = pow(10, j);
        a += A / p % 10, b += B / p % 10;       
      }
      chmin(res, a+b);
    }
    cout << res << ln;
}


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

#define swap(type,a,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(int i=0;i<n;i++)
#define forS(i,start,n) for(int i=start;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}
#define DOUBLE fixed << setprecision(10)

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int main(){
    int n,m,i,j,cnt;
    
    const long long int MOD = 1e9+7;
    cin>>n>>m;
    vi a(n+1,true);
    bool res=true;
    forN(i,m){
        int tmp;cin >> tmp;
        a[tmp] = false;
        if(!a[tmp-1]) res=false;
    }
    
    vector<ll> fib(n+1);
    fib[0] = 1;
    forN(i,n){
        for(j=i+1;j<=min(n,i+2);j++){
            if(a[j]){
                fib[j]+=fib[i];
                fib[j]%=MOD;
            }
        }
    }
    cout << (res?fib[n]:0) << endl;
}

Measured memory_bytes: 4560
N = int(input())
arr = []
for x in list(map(int,input().split())):
    arr.append(x)
sort_arr = sorted(arr)
mid1 = sort_arr[N//2-1]
mid2 = sort_arr[N//2]

for x in arr:
    if x <= mid1:
        print(mid2)
    else:
        print(mid1)


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

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> cnt(100001);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        cnt[a] += b;
    }

    long long c = 0;
    for (int i = 0; i < 100001; i++) {
        c += cnt[i];
        if (c >= K) {
            cout << i << endl;
            return 0;
        }
    }
}

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

int main() {
    
    int a, i;
    string s1, s2;
    cin >> a >> s1 >> s2;
    for(i=0; i<a; i++){
        cout << s1[i] << s2[i];
    }
    
    cout << endl;
    
    
    
    
    
	return 0;
}

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

int main(){
  string s;
  ll k;
  cin >> s >> k;
  for (int i=0; i<s.size(); i++) {
    if (s.at(i) == '1' && k == i+1) {
      cout << s.at(i) << endl;
      break;
    }
    else if (s.at(i) != '1') {
      cout << s.at(i) << endl;
      break;
    }
  }
}

Measured memory_bytes: 256