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

const int Max = 1e5+10;
vector<int> adj[Max];
int memo[Max], indegree[Max] = {0};

void dfs(int node) {
    if(memo[node] != -1) return;
    memo[node] = 0;
    for(int to : adj[node]) {
        dfs(to);
        memo[node] = max(memo[node], 1 + memo[to]);
    }
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int u,v;
    for(int i = 1; i <= n; ++i) {
        memo[i] = -1;
    }
    for(int i = 0; i < m; ++i) {
        cin >> u >> v;
        adj[u].push_back(v);
        indegree[v]++;
    }
    int res = 0;
    for(int i = 1; i <= n; ++i) {
        if(indegree[i] == 0) {
            dfs(i);
            res = max(res, memo[i]);
        }
    }
    cout << res << '\n';
    return 0;
}


























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

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


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    // Your code here!
    int a,b,h,m,min;cin>>a>>b>>h>>m;
    long double ca,cb,pi,k;
    pi = 3.14159265359;
    min=h*60+m;
    ca = 2*pi*min/(12*60);
    cb=2*pi*min/60;
    k=sqrtl(a*a+b*b-2*a*b*cos(abs(ca-cb)));
    cout<<fixed<<setprecision(10)<<k<<endl;
}


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

int main() {
  int L, R, A, B, C, D;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (L < R) {
    cout << "Right" << endl;
  }
  else if (L == R) {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){

    long long int a,b;

    while(scanf("%lld%lld", &a, &b)!=EOF){
        printf("%lld %lld\n",__gcd(a,b),a*b/__gcd(a,b));
    }

    return 0;
}

Measured memory_bytes: 1188
#include <cstdio>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;

int g(int a, int b) {
	// cout << a << " " << b << " ";
	while (a % b != 0 && b % a != 0) {
		if (b > a)
			b = b % a;
		else
			a = a % b;
	}
	// cout << min(a, b) << endl;
	return min(a, b);
}

int main() {
	
	int n;
	cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		v.push_back(t);
	}

	vector<int> l, r;
	int gcd = v[0];
	l.push_back(gcd);
	for (int i = 1; i < n; i++) {
		gcd = g(gcd, v[i]);
		l.push_back(gcd);
	}

	gcd = v[v.size() - 1];
	r.push_back(gcd);
	for (int i = v.size() - 2; i >= 0; i--) {
		gcd = g(gcd, v[i]);
		r.push_back(gcd);
	}
	reverse(r.begin(), r.end());
	int res = 0;
	res = max(res, l[l.size() - 1]);
	for (int i = 0; i < n - 2; i++) {
		res = max(res, g(l[i], r[i+2]));
	}

	res = max(res, l[l.size() - 2]);
	res = max(res, r[1]);
	cout << res << endl;

}


Measured memory_bytes: 1784
-- Simultaneous Equation
import Text.Printf -- printf

main = getContents >>= putStr . solve

solve :: String -> String
solve = unlines . map (unwords . map (floatFormat . roundZero) . simul . map read) . map words . lines

roundZero :: Float -> Float
roundZero x | x == 0.0 = 0
            | otherwise = x

floatFormat :: Float -> String
floatFormat = printf "%.3f"

simul :: Fractional a => [a] -> [a]
simul [a,b,c,d,e,f] = [x,y]
  where
    det = a * e - d * b
    x = (c * e - b * f) / det
    y = (a * f - c * d) / det

-- printf :: PrintfType r => String -> r
-- printf "format"

Measured memory_bytes: 4400
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n%10==2)
  {
    cout<<"hon";
  } else if(n%10==3){
      cout<<"bon";
  } else if(n%10==0){
    cout<<"pon";
  } else if(n%10==1){
    cout<<"pon";
  } else if(n%10==6){
    cout<<"pon";
  } else if(n%10==8){
    cout<<"pon";
  } else{
    cout<<"hon"<<endl;
  }
}
		

Measured memory_bytes: 3560
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
long long int a,b,c,x,y;
cin>>a;
cin>>b;
cin>>c;
cin>>x;
cin>>y; 
long long int sum1,sum2,sum3;
if(x>y)
sum1=min(x,y)*c*2+abs(x-y)*a;
else
sum1=min(x,y)*c*2+abs(x-y)*b;
sum2=max(x,y)*c*2;
sum3=a*x+b*y;
cout<<min(min(sum1,sum2),sum3)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char c[105],s[5]="CF";
int now=0;
int main()
{
    scanf("%s",c);
    for(int i=0;i<strlen(c);i++)
    {
        if(c[i]==s[now])
        {
            now++;
            if(now==2)
            {
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 256
class Point:
    def __init__(self, x, y):
        super().__init__()
        self.x = x
        self.y = y


def solve(p1, p2):
    s_x = p1.x + (p2.x - p1.x) * (1/3)
    s_y = p1.y + (p2.y - p1.y) * (1/3)
    t_x = p1.x + (p2.x - p1.x) * (2/3)
    t_y = p1.y + (p2.y - p1.y) * (2/3)
    u_x = (p2.x + p1.x) * (1/2) + (p1.y - p2.y) * (1/6) * pow(3, 1/2)
    u_y = (p2.y + p1.y) * (1/2) + (p2.x - p1.x) * (1/6) * pow(3, 1/2)
    s = Point(s_x, s_y)
    t = Point(t_x, t_y)
    u = Point(u_x, u_y)
    return [s, u, t]


if __name__ == "__main__":
    n = int(input())
    P = [Point(0, 0), Point(100, 0)]
    for i in range(n):
        TMP = []
        for j in range(len(P) - 1):
            TMP.append(P[j])
            TMP += solve(P[j], P[j+1])
        TMP.append(P[-1])
        P = TMP

    for p in P:
        print('{} {}'.format(p.x, p.y))



Measured memory_bytes: 6412
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    ans = 0
    for i in range(1, N+1):
        if len(str(i)) % 2 == 1:
            ans += 1
    return ans


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


signed main(){
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;

    cout << (m1!=m2?1:0) << endl;
    
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
ll n, w;
const ll N = 100000+10;
ll weight[N], value[N];
ll dp[100+10][N]; // dp[i][j] = i個目の荷物まで使った時、重さj以下の価値の最大値

ll q(ll x, ll y){
    if(dp[x][y]!=-1) return dp[x][y];

    if(weight[x]>y) dp[x][y] = q(x-1,y);
    else dp[x][y] = max(q(x-1,y),q(x-1,y-weight[x])+value[x]);

    return dp[x][y];
}

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

    cin >> n >> w;
    REP(i,n){
        cin >> weight[i+1] >> value[i+1];
    }
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=w;j++){
            dp[i][j] = -1;
        }
    }
    for(ll j=0;j<=w;j++){
        dp[0][j] = 0;
    }

    cout << q(n,w) <<endl;

    





    
    return 0;
}



Measured memory_bytes: 82588
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0
    for i in reversed(range(N)):
        reduce2 = min(A[i+1],B[i])
        reduce1 = min(A[i], B[i]-reduce2)
        A[i] -= reduce1
        ans += reduce1 + reduce2
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 19156
import java.util.Scanner;
import java.math.BigDecimal;
class Main{
	public static void main(String[] a){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			double g = scan.nextDouble();
			double b = scan.nextDouble();
			double c = scan.nextDouble();
			double d = scan.nextDouble();
			double e = scan.nextDouble();
			double f = scan.nextDouble();
			double x = (c*e-b*f)/(g*e-b*d);
			double y = (c*d-g*f)/(b*d-g*e);
			BigDecimal bx = new BigDecimal(String.valueOf(x));
			BigDecimal by = new BigDecimal(String.valueOf(y));
			double outx = bx.setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue();
			if(outx*10 == (int)(outx*10)) System.out.print(outx + "00 ");
			else if(outx*100 == (int)(outx*100)) System.out.print(outx + "0 ");
			else System.out.print(outx + " ");
			double outy = by.setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue();
			if(outy*10 == (int)(outy*10)) System.out.print(outy + "00\n");
			else if(outy*100 == (int)(outy*100)) System.out.print(outy + "0\n");
			else System.out.print(outy + "\n");
		}
	}
}

Measured memory_bytes: 20516
// Main maut ko takiya, aur kafan ko chadaar banakar audhta hoon!

#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define len(a) ll(a.size())
#define endl "\n"
#define rep(i,n) for(int i = 0; i < n; i++)

#define vll vector< ll >
#define pll pair< ll, ll >
#define vvll vector< vll >
#define vpll vector< pll >

#define umsll unordered_map<string,ll>
#define umll unordered_map<ll,ll>
#define sll set<ll>
#define minpqll priority_queue<ll,vector<ll>,greater<ll>>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " : " << arg1 << endl;
    }

    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args)
    {
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1 << "  ";
        __f(comma + 1, args...);
    }

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

const double pi=3.141592653589793238462643383279502884197169399375105820974944;
const double e=2.71828182845904523536028747135266249775724709369995;
const ll mod=1e9+7;
const ll inf=2e18;
const ll ninf=-2e18;
const ll nax=1e6;

ll power(ll x, ll y, ll mod)
{
    ll ans=1;
    x=x%mod;
    while(y)
    {
        if(y&1)
            ans=(x*ans)%mod;

        x=(x*x)%mod;
        y>>=1;
    }
    return ans;
}

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

    time_t t1, t2;
    t1 = clock();

    umsll a;

    int n, m;
    cin>>n;

    while(n--)
    {
        string s;
        cin>>s;
        a[s]++;
    }

    cin>>m;
    while(m--)
    {
        string s;
        cin>>s;
        a[s]--;
    }

    ll ans = 0;

    for(auto it: a)
    {
        ans = max(ans,it.ss);
    }
    cout<<ans;




    t2 = clock();
    cerr << endl << "time taken: " << t2 - t1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    long long int h[100010];
    long long int max = -1, min;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    for (int i = 0; i < n; i++) {
        if (max <= h[i]) {
            max = h[i];
            min = 0;
        }
        if (max > h[i]) {
            min = max - h[i];
        }
        if (min >= 2) {
            cout << "No" << endl;
            return (0);
        }
    }

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


Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int A = sc.nextInt();
		int P = sc.nextInt();
		
		out.println((A*3+P)/2);
		
		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 24404
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>
#include<cmath>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
pair<int,int> first[51];
pair<int,int> second[51];

int dis(int i , int j)
{
    return abs(first[i].first-second[j].first) + abs(first[i].second-second[j].second);
}

int main()
{
	FAST;
	int n,m;
	cin >> n >> m;

	
	for(int i=0 ; i<n ; i++)
		cin >> first[i].first >> first[i].second;

	for(int j=0 ; j<m ; j++)
		cin >> second[j].first >> second[j].second;
	
	for(int i=0 ; i<n ; i++)
	{
		int minIndex = -1;
		for(int j=0 ; j<m ; j++)
		{
		    if(minIndex < 0 || dis(i ,j) < dis(i , minIndex))
		        minIndex = j;
		}

		cout << minIndex+1 << "\n";
	}


	return 0;
}

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

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef vector<vector<int> > vvi;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORED(i, s, n) for (int i = (s); i >= (int)(n); i--)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

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

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
// gcd : O(logN)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return
#define srting string

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

#define uniq(v) (v).erase(unique(ALL((v))), (v).end());

// area of (0, 0)(a, b)(c, d)
double area(double a, double b, double c, double d){
    return abs(a * d - b * c) / 2.0;
}

const int PREC = 10;
#define coutf(val) cout << fixed << setprecision(PREC) << (val) << endl;

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

const int N = 26;

signed main() {

    make(int, D);

    vi Cs(N);
    REP(n, N) {
        make(int, C);
        Cs.at(n) = C;
    }

    vvi Ss(D, vi(N, 0));
    REP(d, D) {
        REP(n, N) {
            make(int, s);
            Ss.at(d).at(n) = s;
        }
    }

    // とりあえず全ツッパ
    REP(d, D) {
        cout << 1 << endl;
    }

}


Measured memory_bytes: 3680
#include<stdio.h>

int main(){
  long int x,a,b;

  scanf("%ld %ld %ld",&x,&a,&b);

  if(a >= b){
    puts("delicious");
  }else{
    if(b - a <= x){
      puts("safe");
    }else{
      puts("dangerous");
    }
  }

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

#define sqr(x)  ((x) * (x))
#define sqr2(x)  ((x) * (x) * (x))

int main(void)
{
  int n;
  int x[1001] = {0};
  int y[1001] = {0};
  int i;
  int sum1 = 0;
  int sum2 = 0;
  long sum3 = 0;
  int summ = 0;
  double D1 = 0;
  double D2 = 0;
  double D3 = 0;
  double Dm = 0;

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

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

  for(i = 0; i < n; i++){
    if(x[i] > y[i]){
    sum1 += x[i] - y[i];
    sum2 += sqr(x[i] - y[i]);
    sum3 += sqr2(x[i] - y[i]);
    if(summ < x[i] - y[i])
	summ = x[i] - y[i];
    }
    else{
      sum1 += y[i] - x[i];
      sum2 += sqr(y[i] - x[i]);
      sum3 += sqr2(y[i] - x[i]);
      if(summ < y[i] - x[i])
	summ = y[i] - x[i];
    }
  }
    
  D1 = (double)(sum1);
  D2 = sqrt((double)(sum2));
  D3 = (double)(cbrt(sum3));
  Dm = (double)(summ);

  printf("%f\n%f\n%f\n%f\n", D1, D2, D3, Dm);

  return 0;
}

Measured memory_bytes: 660
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


bool isunnatural(int a, int b, bool par) {
    a %= 3; b %= 3;
    if (a == 0) a = 3;
    if (b == 0) b = 3;
    if (par) return (a < b);
    else return (a > b);
}
string str;

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    
    while (cin >> str) {
        if (str == "#") break;
        
        int ls = 0, rs = 0;
        int n = str.size();
        bool par = true;
        for (int i = 1; i < n; ++i) {
            if (isunnatural(str[i]-'0', str[i-1]-'0', par)) ++ls, par = 1-par; 
            par = 1-par;
        }
        par = false;
        for (int i = 1; i < n; ++i) {
            if (isunnatural(str[i]-'0', str[i-1]-'0', par)) ++rs, par = 1-par; 
            par = 1-par;
        }
                     
        cout << min(ls,rs) << endl;
    }
    return 0;
}


Measured memory_bytes: 1316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  string S;
  ll K;
  cin >> S >> K;
  char tmp = '1';
  int flag = 0;
  for(string::iterator ptr = S.begin(); ptr != S.end(); ptr++){
    if(*ptr != '1'){
      tmp = *ptr;
      break;
    }
    flag++;
  }
  
  if(K < flag + 1) cout << '1' << endl;
  else cout << tmp << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int i,j,k,l,m,n,o,p,q;
	int input,sum,kumiawase;
	
	while(1){
		scanf("%d %d",&input,&sum);
		if(input == 0 && sum == 0) break;
		kumiawase=0;
		
		if(input == 1){
			for(i=0;i <= 9;i++){
				if(i == sum) kumiawase++;
			}
		}else if(input == 2){
			for(i=0;i <= 9;i++){
				for(j=i+1;j <= 9;j++){
					if(i+j == sum) kumiawase++;
				}
			}
		}else if(input == 3){
			for(i=0;i <= 9;i++){
				for(j=i+1;j <= 9;j++){
					for(k=j+1;k <= 9;k++){
						if(i+j+k == sum) kumiawase++;
					}
				}
			}
		}else if(input == 4){
			for(i=0;i <= 9;i++){
				for(j=i+1;j <= 9;j++){
					for(k=j+1;k <= 9;k++){
						for(l=k+1;l <= 9;l++){
							if(i+j+k+l == sum) kumiawase++;
						}
					}
				}
			}
		}else if(input == 5){
			for(i=0;i <= 9;i++){
				for(j=i+1;j <= 9;j++){
					for(k=j+1;k <= 9;k++){
						for(l=k+1;l <= 9;l++){
							for(m=l+1;m <= 9;m++){
								if(i+j+k+l+m == sum) kumiawase++;
							}
						}
					}
				}
			}
		}else if(input == 6){
			for(i=0;i <= 9;i++){
				for(j=i+1;j <= 9;j++){
					for(k=j+1;k <= 9;k++){
						for(l=k+1;l <= 9;l++){
							for(m=l+1;m <= 9;m++){
								for(n=m+1;n <= 9;n++){
									if(i+j+k+l+m+n == sum) kumiawase++;
								}
							}
						}
					}
				}
			}
		}else if(input == 7){
			for(i=0;i <= 9;i++){
				for(j=i+1;j <= 9;j++){
					for(k=j+1;k <= 9;k++){
						for(l=k+1;l <= 9;l++){
							for(m=l+1;m <= 9;m++){
								for(n=m+1;n <= 9;n++){
									for(o=n+1;o <= 9;o++){
										if(i+j+k+l+m+n+o == sum) kumiawase++;
									}
								}
							}
						}
					}
				}
			}
		}else if(input == 8){
			for(i=0;i <= 9;i++){
				for(j=i+1;j <= 9;j++){
					for(k=j+1;k <= 9;k++){
						for(l=k+1;l <= 9;l++){
							for(m=l+1;m <= 9;m++){
								for(n=m+1;n <= 9;n++){
									for(o=n+1;o <= 9;o++){
										for(p=o+1;p <= 9;p++){
											if(i+j+k+l+m+n+o+p == sum) kumiawase++;
										}
									}
								}
							}
						}
					}
				}
			}
		}else if(input == 9){
			for(i=0;i <= 9;i++){
				for(j=i+1;j <= 9;j++){
					for(k=j+1;k <= 9;k++){
						for(l=k+1;l <= 9;l++){
							for(m=l+1;m <= 9;m++){
								for(n=m+1;n <= 9;n++){
									for(o=n+1;o <= 9;o++){
										for(p=o+1;p <= 9;p++){
											for(q=p+1;q <= 9;q++){
												if(i+j+k+l+m+n+o+p+q == sum) kumiawase++;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		printf("%d\n",kumiawase);
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.*;

public class Main {

    static final int MOD=1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long fact[] = new long[100001];
        fact[0]=1;
        for(int i=1;i<fact.length;i++)fact[i]=(i*fact[i-1])%MOD;
        long ans = 1;
        
        ans = fact[n]*fact[m];

        if(n==m){
            ans *= 2;
        }else if(Math.abs(n-m)==1){

        }else{
            ans = 0;
        }
        System.out.println(ans%MOD);

    }
}


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

int main ()
{
	int n, x = 0;
	string s;
	cin >> n >> s;
	int mx = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I')x++;
		if (s[i] == 'D')x--;
		mx = max(x, mx);
	}
	cout << mx << endl;
	return 0;
}


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

using namespace std;
const int N = 100010;
int _w;

int n, a[N];

int main() {
	cin >> n;
	int cnt = 0;
	for( int i = 1; i <= n; ++i ) {
		cin >> a[i];
		cnt += a[i] & 1;
	}
	cout << (cnt % 2 ? "NO" : "YES") << endl;
	return 0;
}


Measured memory_bytes: 640
fn main() {
    let s = {
        let mut s = String::new(); 
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_string()
    };

    let tokens = s.split(" ")
        .map(|num| num.parse().unwrap())
        .collect::<Vec<i32>>();

    if tokens[0] < tokens[1] {
        println!("a < b");
    } else if tokens[0] > tokens[1] {
        println!("a > b");
    } else {
        println!("a == b");
    }

}


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

int main(){
  int N,D;
  cin >> N >> D;
  int X[N][D];
  for (int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin >> X[i][j];
    }
  }
  int ans =0;
  int kyori2[D];
  for (int i=1;i<N;i++){
    for(int j=0;j<i;j++){
      for(int k=0;k<D;k++){
        kyori2[k]=X[i][k]-X[j][k];
      }
      int sum =0;
      for(int k=0;k<D;k++){
        sum+=kyori2[k]*kyori2[k];
      }
      for(int i=0;i<=sum;i++){
        if(i*i==sum){
          ans++;
          break;
        }
      }
    }
  }
  cout << ans<<endl;
}


Measured memory_bytes: 256
x, y = map(int,input().split())

for i in range(1, x+1):
    f = 2 * i + 4 * (x - i)
    f1 = 4 * i + 2 * (x-i)
    if f == y or f1 == y:
        print("Yes")
        break
else:
        print("No")


Measured memory_bytes: 9176
#include "bits/stdc++.h"

using namespace std;

//int maxHappinessFrom(int curr, int prevAction, const vector<int>& a, const vector<int>& b, const vector<int>& c
//        , vector<vector<int> >& memo) {
//    if (curr == a.size()) {
//        return 0;
//    }
//    if (prevAction == -1) {
//        int ha = maxHappinessFrom(curr + 1, 0, a, b, c, memo) + a[curr];
//        int hb = maxHappinessFrom(curr + 1, 1, a, b, c, memo) + b[curr];
//        int hc = maxHappinessFrom(curr + 1, 2, a, b, c, memo) + c[curr];
//        return max(max(ha, hb), hc);
//    }
//    if (memo[curr][prevAction] >= 0) {
//        return memo[curr][prevAction];
//    }
//
//    int ret = 0;
//    if (prevAction == 0) {
//        int hb = maxHappinessFrom(curr + 1, 1, a, b, c, memo) + b[curr];
//        int hc = maxHappinessFrom(curr + 1, 2, a, b, c, memo) + c[curr];
//        ret = max(hb, hc);
//    }
//    else if (prevAction == 1) {
//        int ha = maxHappinessFrom(curr + 1, 0, a, b, c, memo) + a[curr];
//        int hc = maxHappinessFrom(curr + 1, 2, a, b, c, memo) + c[curr];
//        ret = max(ha, hc);
//    }
//    else { // if (prevAction == 2) {
//        int ha = maxHappinessFrom(curr + 1, 0, a, b, c, memo) + a[curr];
//        int hb = maxHappinessFrom(curr + 1, 1, a, b, c, memo) + b[curr];
//        ret = max(ha, hb);
//    }
//    memo[curr][prevAction] = ret;
//    return ret;
//}

void Main() {
    int N;
    cin >> N;
    vector<int> a(N, 0), b(N, 0), c(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }

    //vector<vector<int> > memo(N, vector<int>(3, -1));
    //int ans = maxHappinessFrom(0, -1, a, b, c, memo);
    //cout << ans << endl;

    vector<vector<int> > maxHappiness(N, vector<int>(3, -1));
    maxHappiness[N - 1][0] = a[N - 1];
    maxHappiness[N - 1][1] = b[N - 1];
    maxHappiness[N - 1][2] = c[N - 1];
    for (int i = N - 2; i >= 0; --i) {
        maxHappiness[i][0] = max(maxHappiness[i + 1][1], maxHappiness[i + 1][2]) + a[i];
        maxHappiness[i][1] = max(maxHappiness[i + 1][0], maxHappiness[i + 1][2]) + b[i];
        maxHappiness[i][2] = max(maxHappiness[i + 1][0], maxHappiness[i + 1][1]) + c[i];
    }
    const vector<int>& firstDate = maxHappiness[0];
    int ans = max(firstDate[0], max(firstDate[1], firstDate[2]));
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 6912
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll r) {
  cout << 3*r*r << endl;
}

int main() {
  ll r;
  cin >> r;
  solve(r);
  return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  vector<ll> v(n,0);
  rep(i,n) cin>>v[i];

  sort(all(v));//昇順
  ll ans = 0 ;

  rep(i,n) ans+=v[i];

  if(ans % 10 != 0){ 
    cout<<ans<<endl;
    return ;
  } else {
    rep(i,n){
      // cout<<v[i]<<endl;
      if(v[i] %10 != 0){
        cout<<ans-v[i]<<endl;
        return ;
      }
    }
  }
  cout<<0<<endl;
}

int main(){
  solve();
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin>>t;
    while(t--){
        int N; cin>>N;
        vll a(N);
        rep(i,N) cin>>a[i];
        string S; cin>>S;
        vll Base;

        auto update = [&](ll x){
            int rank = Base.size();
            rep(i,rank)
                if (x & (Base[i]&-Base[i]))
                    x^=Base[i];
            if (x==0) return true;
            rep(i,rank)
                if (Base[i] & (x&-x))
                    Base[i]^=x;
            Base.pb(x);
            return false;
        };

        int ans=0;
        RFOR(i,N-1,0){
            if (!update(a[i]) && S[i]=='1'){
                ans=1;
                break;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3544
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
c_value = list(c.values())
c_key = list(c.keys())
cnt = 0

for i in range(len(c_key)):
    if c_key[i] > c_value[i]:
        cnt += c_value[i]
    elif c_value[i] > c_key[i]:
        cnt += c_value[i]- c_key[i]
print(cnt)

Measured memory_bytes: 22372
n,t = map(int, input().split())
tl = list(map(int,input().split()))
c = 0
for i  in range(n-1):
    if tl[i] + t <= tl[i+1]:
        c += t
    else:
        c += tl[i+1]-tl[i]
print(c+t)

Measured memory_bytes: 26708
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

s = input()

ans = ''
for i in range(len(s)):
    if s[i] == 'B':
        if len(ans) == 0: continue
        ans = ans[0:-1]
    else:
        ans += s[i]
print(ans)

Measured memory_bytes: 9328
#include <iostream>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
	int h = 0, w = 0;

	while (1){
		cin >> h >> w;
		if (h == 0 && w == 0){ break; }
		for (int i = 0; i < h;i++){
			for (int s = 0; s < w; s++){
				if (i == 0 || i == h-1  || s == 0 || s == w-1){printf("#");}
				else{ printf("."); }
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1112
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, c) for(long long i=0; i<(long long)c; i++)
const ll INF=1000000000000001;
int main() {
	int n;
	string ans="No";
	cin >>n;
	if (n>=30) ans="Yes";
	cout <<ans<<endl;
	return 0;
}


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

int main() {
  int N_input,a,b,c;
  cin >> N_input;
  a = N_input / 100;
  b = (N_input - a*100) / 10;
  c = (N_input - a* 100 - b* 10);
  cout << a+b+c << endl;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))

if n == 1:
    l = list(map(str,l))
    print(" ".join(l))
    exit()

ans = []

if n%2 == 0:
    tmp = n
    for j in range(n//2-1):
        ans.append(tmp)
        tmp -= 2
    ans.append(tmp)
    ans.append(1)
    tmp = 1
    for j in range(n//2-1):
        tmp += 2
        ans.append(tmp)
else:
    tmp = n
    for j in range(n//2):
        ans.append(tmp)
        tmp -= 2
    ans.append(tmp)
    tmp = 2
    for j in range(n//2):
        ans.append(tmp)
        tmp += 2

ans2 = [0]*n
cnt = 0
for i in ans:
    ans2[cnt] = str(l[i-1])
    cnt += 1


print(" ".join(ans2))


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

int main(){
int i;
int H;
int *A;

scanf("%d",&H);
H++;
A=(int *)malloc(H*sizeof(int));

for(i=1;i<H;i++){
scanf("%d",&A[i]);
}
for(i=1;i<H;i++){
printf("node %d: key = %d, ",i,A[i]);
if(i!=1) printf("parent key = %d, ",A[i/2]);
if(i*2<H) printf("left key = %d, ",A[i*2]);
if(i*2+1<H) printf("right key = %d, ",A[i*2+1]);
printf("\n");
}
return 0;
}



Measured memory_bytes: 2112
#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--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    while(1){
        int N,M;
        cin >> N >> M;

        if (N==0 && M==0)break;

        vector<int>C(M);
        REP(i,M){
            cin >> C[i];
        }
        vector<int>x(N);
        REP(i,N){
            cin >> x[i];
        }

        vector<vector<ll>> dp(256, vector<ll>(N+1,INF));
        dp[128][0] = 0;

        REP(i,N){
            REP(j,256){
                REP(k,M){
                    if (j+C[k]>=255){
                        dp[255][i+1] = min(dp[255][i+1], dp[j][i] + (int)pow(x[i]-255, 2));
                    }else if (j+C[k]<=0){
                        dp[0][i+1] = min(dp[0][i+1], dp[j][i] + (int)pow(x[i], 2));
                    }else{
                        dp[j+C[k]][i+1] = min(dp[j+C[k]][i+1], dp[j][i] + (int)pow(x[i]-j-C[k], 2));
                    }
                    
                    
                }
            }
        }


        ll ans = INF;

        REP(i,256){
            ans = min(ans, dp[i][N]);
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 43944
def ii():
    return int(input())

def lii():
    return list(map(int, input().split(' ')))
# a, b = lii()
# if b < a:
#     print(a-1)
# else:
#     print(a)


a, b, c = lii()
k = ii()

for _ in range(k):
    if a == max(a, b, c):
        a *= 2
    elif b == max(a, b, c):
        b *= 2
    elif c == max(a, b, c):
        c *= 2

print(sum([a, b, c]))

Measured memory_bytes: 3064
n,m,p=map(int,input().split())
g=[[] for _ in range(n)]
e=[]
for _ in range(m):
  a,b,c=map(int,input().split())
  a,b=a-1,b-1
  c-=p
  g[a].append([b,c])
  e.append([a,b,-c])



# ベルマンフォード法
# edges:エッジ、有向エッジ[a,b,c]a->bのエッジでコストc
# num_v:頂点の数
# source:始点
def BellmanFord(edges,num_v,source):
  #グラフの初期化
  inf=float("inf")
  dist=[inf for i in range(num_v)]
  dist[source]=0  
  #辺の緩和をnum_v-1回繰り返す。num_v回目に辺の緩和があればそれは閉路。-1を返す。
  for i in range(num_v-1):
    for edge in edges:
      if dist[edge[0]] != inf and dist[edge[1]] > dist[edge[0]] + edge[2]:
        dist[edge[1]] = dist[edge[0]] + edge[2]
        if i==num_v-1: return -1
  #閉路に含まれる頂点を探す。
  negative=[False]*n
  for i in range(num_v):
    for edge in edges:
      if negative[edge[0]]:negative[edge[1]]=True
      if dist[edge[0]] != inf and dist[edge[1]] > dist[edge[0]] + edge[2]:
        negative[edge[1]] = True
  return dist[n-1],negative[n-1]
d,n=BellmanFord(e,n,0)
if n:
  print(-1)
else:
  print(max(0,-d))

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  rep(i, n){
    double in;
    cin >> in;
    p.at(i) = (double)(in+1)/2;
  }
  vector<double> sums(n+1, 0);
  rep(i, n) sums.at(i+1) = sums.at(i) + p.at(i);
  double ans = 0;
  rep2(i, k, n+1){
    double add = sums.at(i) - sums.at(i-k);
    ans = max(ans, add);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 6480
n = int(input())
a = list(map(int, input().split()))

count = 0

while True:
    exist_odd = False

    for i in range(n):
        if a[i] % 2 != 0:
            exist_odd = True
    if exist_odd:
        break

    for i in range(n):
        a[i] //= 2
    count += 1

print(count)

Measured memory_bytes: 3060
#include<iostream>]
#include<algorithm>
#include<vector>
using namespace std;
int main(){vector<int> a(10);int i=0;for(;i++<10;)cin>>a[i];sort(a.begin(),a.end());cout<<a[9]<<"\n"<<a[8]<<"\n"<<a[7]<<endl;}

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

int main() {
  char S[2000];
  int i, N, D1, D2, ans = 0;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d %d", &D1, &D2);
    if (D1 == D2) ans++;
    else          ans = 0;
    if (ans >= 3) {
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;
ll INF = 1000000009;

/*

*/

void solve(){
    int n,h;
    cin >> n >> h;
    int a[n+10];
    int b[n+10];
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    sort(a,a+n,greater<int>());
    sort(b,b+n,greater<int>());
    int ans=0;
    int pointer=0;
    while(h>0){
        if(b[pointer]>a[0]&&pointer<n){
            h = h - b[pointer];
            pointer++;
            ans++;
        }
        else{
            if(h%a[0]==0){
                ans += h/a[0];
                h=0;
            }
            else{
                ans += h/a[0]+1;
                h=0;
            }
        }
    }
    cout << ans << endl;
}

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



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main() {
	int N; cin >> N;
	vector<int> dp(100001);

	for(int i = 1; i <= N; ++i){
		dp[i] = INT_MAX;
		int powN = 1; //power number
		while(powN <= i){
			dp[i] = min(dp[i], dp[i - powN]+1);
			powN *= 6;
		}
		powN = 1; 
		while(powN <= i){
			dp[i] = min(dp[i], dp[i - powN]+1);
			powN *= 9;
		}
	}

	cout << dp[N] << endl;
}


Measured memory_bytes: 640
class MyNode
  attr_accessor :flag
  attr_reader :connections


  def initialize
    @connections = []
  end


  def connect(my_node)
    @connections << my_node
    @connections.uniq!
  end


  def disconnect(my_node)
    @connections.delete(my_node)
  end


  def propagate_flag
    @flag = true

    @connections.each do |my_node|
      if my_node.flag
        next
      else
        my_node.flag = true
        my_node.propagate_flag
      end
    end

    @connections
  end
end




class MyGraph
  def initialize
    @nodes = {}
    @edges = []
  end


  def add_edge(from, to)
    @nodes[from] ||= MyNode.new
    @nodes[to] ||= MyNode.new

    a = @nodes[from]
    b = @nodes[to]

    a.connect(b)
    b.connect(a)


    @edges << [a, b]
  end


  def bridges
    @edges.select{|a, b|
      # Remove edge information from nodes
      a.disconnect(b)
      b.disconnect(a)

      a.propagate_flag
      result = b.flag

      a.connect(b)
      b.connect(a)

      @nodes.each{|id, my_node| my_node.flag = false }

      ! result
    }
  end
end


N, M = gets.chomp.split(" ").map(&:to_i)

graph = MyGraph.new

M.times do
  a, b = gets.chomp.split(" ").map(&:to_i)

  graph.add_edge(a, b)
end

puts graph.bridges.size


Measured memory_bytes: 1916
/*
ABHIJEET BISWAS
CSE 4th SEM 
MNNIT ALLAHBAD
https://atcoder.jp/contests/dp/tasks/dp_k
*/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define MAX 1000009
#define pb push_back
#define mp map<int,int>
#define f first
#define s second
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ld pi=2.0*acos(0.0);
int n,k;
int arr[102];
int dp[100007][2];
int solve(int num,int p)
{
	if(num==0)
	return (p+1)%2;
	if(num<0)
	return p;
	if(dp[num][p]!=-1)
	return dp[num][p];
	for(int i=1;i<=n;i++)
	if(arr[i]<=num)
	{
		if(p==solve(num-arr[i],(p+1)%2))
		return dp[num][p]=p;
	}
	return dp[num][p]=(p+1)%2;
}
int main() {
	fastIO
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	cin>>arr[i];
	for(int i=0;i<=k;i++)
	for(int j=0;j<2;j++)
	dp[i][j]=-1;
	int ans=solve(k,0);
	if(ans==0)
	cout<<"First"<<endl;
	else
	cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
const int maxn = 234567, mod = 1000000007;
int mul(long long a, long long b){
	return a * b % mod;
}
int xp(int a, long long b){
	int r = 1;
	for(; b ; b >>= 1, a = mul(a, a)) if(b&1) r = mul(r, a);
	return r;
}
int fat[maxn], ifat[maxn];
void init(){
	fat[0] = 1;
	for(int i = 1; i < maxn; i++) fat[i] = mul(fat[i - 1], i);
	ifat[maxn - 1] = xp(fat[maxn - 1], mod - 2);
	for(int i = maxn - 2; i >= 0; i--) ifat[i] = mul(ifat[i + 1], i + 1);
}
int ncr(int n, int r){
	if(n < r) return 0;
	return mul(fat[n], mul(ifat[r], ifat[n - r]));
}
int u[maxn], c[maxn], w[maxn];
vector<int> wh[maxn], pp[maxn];
int find(int x){
	if(x == u[x]) return x;
	return u[x] = find(u[x]);
}
int main(){
	init();
	iota(u, u + maxn, 0);
	int n, X, Y; cin >> n >> X >> Y;
	for(int i = 0; i < n; i++){
		cin >> c[i] >> w[i];
		wh[c[i]].push_back(i);
	}
	vector<int> od(n);
	iota(od.begin(), od.end(), 0);
	sort(od.begin(), od.end(), [&](int a, int b){
		return w[a] < w[b];
	});
	int d2 = 0;
	while(d2 < n && c[od[d2]] == c[od[0]]) d2++;
	for(int i = 0; i < n; i++){
		if(c[od[0]] != c[i] && w[od[0]] + w[i] <= Y) u[find(od[0])] = find(i);
		if(d2 < n && c[od[d2]] != c[i] && w[od[d2]] + w[i] <= Y) u[find(od[d2])] = find(i);
	}
	for(int i = 1; i <= n; i++){
		if(wh[i].empty()) continue;
		sort(wh[i].begin(), wh[i].end(), [&](int a, int b){
			return w[a] < w[b];
		});
		int len = wh[i].size();
		for(int j = 1; j < len; j++){
			if(w[wh[i][0]] + w[wh[i][j]] <= X){
				u[find(wh[i][0])] = find(wh[i][j]);
			}
		}
	}
	for(int i = 0; i < n; i++) pp[find(i)].push_back(c[i]);
	int ans = 1;
	for(int i = 0; i < n; i++){
		if(pp[i].empty()) continue;
		sort(pp[i].begin(), pp[i].end());
		int len = pp[i].size();
		for(int j = 0; j < len; ){
			int k = j;
			while(k < len && pp[i][k] == pp[i][j]) k++;
			ans = mul(ans, ncr(len - j, k - j));
			j = k;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 26880