akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
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; }
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;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int N;
cin >> N;

bool ok = false;

rep(a,100) rep(b,100) {
    if(7*a+4*b == N ) ok = true;
}

if(ok) cout << 'Y' << 'e' << 's' << endl;
else cout << 'N' << 'o' << endl;

return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::{min, max};

#[fastout]
fn main() {
    input! {
    n: usize,
    k: usize,
    x: [i64; n]
    }
    let mut ans = 1_000_000_000_000_000;
    for i in 0..=n - k {
        let t = if x[i] * x[i + k - 1] >= 0 {
            max(x[i].abs(), x[i + k - 1].abs())
        } else {
            min(2 * x[i].abs() + x[i + k - 1].abs(), x[i].abs() + 2 * x[i + k - 1].abs())
        };
        ans = min(ans, t);
    }
    println!("{}", ans);
}


Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 

 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

double convert(int d){
	return PI*d/180;
}


int main(){
	int n, m, sum, t;
	double s1, s2;
	while(cin>>n && n){
		sum = 0;
		s1 = s2 = 0.0;
		rep(i, n-1){
			cin>>t;
			sum+=t;
			s1+=sin(convert(t));
		}
		s1+=sin(convert(360-sum));
		cin>>m;
		sum = 0;
		rep(i, m-1){
			cin>>t;
			sum += t;
			s2 += sin(convert(t));
		}
		s2 += sin(convert(360-sum));
		int ans;
		if(abs(s1-s2)<EPS){
			ans = 0;
		}
		else if(s1>s2){
			ans = 1;
		}
		else {
			ans = 2;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1196
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }

vector<int> sw[12];
int p[12];

int main(){
    int N,M,k,s;
    cin >> N >> M;
    rep(i,M){
        cin >> k;
        rep(j,k){
            cin >> s;
            sw[i].push_back(s-1);//onかどうかチェックするスイッチ
        }
    }
    rep(i,M){
        cin >> p[i];
    }

    int cnt=0;
    for (int bit = 0; bit < (1<<N); ++bit){
        vector<int> S;//on,offの組み合わせ
        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                S.push_back(i);
            }
        }

        int on_light=0;
        rep(i,M){
            int on=0;
            rep(j,sw[i].size()){
                if ( vector_finder(S, sw[i][j]) ) on++;
            }
            if (on%2==p[i]){
                on_light ++;
            }
        }

        if(on_light==M) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> PP;


int main(){
	int n,m,a;
		while(cin>>n>>m>>a && n!=0){
		vector<PP> data;
		for(int i=0;i<m;i++){
			int h,p,q;
			cin>>h>>p>>q;
			data.push_back(PP(h,P(p,q)));
		}
		sort(data.begin(),data.end());
		int ans[105];
		for(int i=0;i<105;i++)ans[i]=i;
		for(int i=0;i<data.size();i++){
			P p=data[i].second;
			swap(ans[p.first],ans[p.second]);
		}
		cout<<ans[a]<<endl;
	}
	
}

Measured memory_bytes: 1224
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; 

const int Maxn = 2e5;

int len;
char s[Maxn + 5];

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%s", s + 1);
	len = strlen(s + 1);
	int ans = 1;
	string last, now;
	last += s[1];
	for(int i = 2; i <= len;) {
		now += s[i];
		if(i == len && now == last) break;
		while(now == last) {
			now += s[++i];
			if(i > len) break;
		}
		ans++, last = now, now = "", i++;
	}
	printf("%d\n", ans);
	return 0;
} 

Measured memory_bytes: 384
fn func(input_str: &str) -> u64 {
    let mut iter = input_str.split("\n");
    let n: u64 = iter.next().unwrap().parse().unwrap();
    let cap_min: u64 = iter.take(5).map(|x| x.parse().unwrap()).min().unwrap();
    if n % cap_min == 0 {
        n / cap_min + 4
    }
    else {
        n / cap_min + 5
    }
}

use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    println!("{}", func(&buf[..]));
}

Measured memory_bytes: 4352
lis=sorted(list(map(int,input().split())))
lis.sort(reverse=True)
if (lis[1]-lis[2])%2==0:#偶数
    print(((lis[0]-lis[1])+(lis[0]-lis[2]))//2)
else:#奇数
    print(((lis[0]-lis[1])+(lis[0]-lis[2])+3)//2)

Measured memory_bytes: 38384
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#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 SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(n,x);
  Vi HV(n);
  VIN(HV)
  RSORT(HV);
  REP(i,x){
    if(i >= n) break;
    HV[i] = 0;
  }
  REP(i,n){
    z += HV[i];
  }
  OUT(z);
}

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

int main(void){
    int K, res = 0;
    cin >> K;
    
    for (int i = 0; i < K; ++i)
    {
        for (int j = 0; j < K; ++j)
        {
            if (i % 2 == 0 && j % 2 == 1)
            {
                res++;
            }
        }
    }
    
    cout << res;
}


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

typedef long long ll;
const int MAX_N = 100030;    // Change as necessary
const ll  MODD = 1000000009; //

ll A[MAX_N];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin >> A[0] >> A[1] >> A[2];
  if(A[0] % 2 && A[1] % 2 && A[2] % 2){
    sort(A,A+3);
    cout << A[0]*A[1] << endl;
  } else {
    cout << 0 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int x, y;

int main() {
	cin >> x >> y;
	cout<<x + y / 2 << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String args[]){
		Scanner s = new Scanner(System.in);
		String indata = s.next();
		int a = Integer.parseInt(indata);
		indata=s.next();
		int b = Integer.parseInt(indata);
		if(a==b)System.out.println("a == b");
		else if(a>b)System.out.println("a > b");
		else System.out.println("a < b");
	}
}

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

class ITP1
{
    static void Main()
    {
        var str = Console.ReadLine();
        int a = int.Parse(str.Split(' ')[0]);
        int b = int.Parse(str.Split(' ')[1]);
        int[,] x = new int[a, b];
        int[] y = new int[b];
        int c ,d= 0;
        for (int i = 0; i < a; i++)
        {
            str = Console.ReadLine();
            for (int j = 0; j < b; j++)
            {
                x[i, j] = int.Parse(str.Split(' ')[j]);
            }
        }
        for (int i = 0; i < a; i++)
        {
            c = 0;
            for (int j = 0; j < b; j++)
            {
                Console.Write(x[i,j]+" ");
                c+=x[i,j];
                y[j]+=x[i,j];
            }
            Console.WriteLine(c);
        }
        for (int j = 0; j < b; j++)
        {
            Console.Write(y[j] + " ");
            d += y[j];
        }
        Console.WriteLine(d);
    }
}

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

void main_()
{
    int64_t N;
    cin >> N;

    int64_t i = 1;
    int64_t j = N;

    int64_t ans_i = i;
    int64_t ans_j = j;

    while (i < j) {
        j *= i;
        ++i;
        j /= i;
        while (i <= j) {
            auto n = i * j;
            if (n <= N) {
                if (n == N) {
                    ans_i = i;
                    ans_j = j;
                }
                ++j;
                break;
            }
            --j;
        }
    }

    cout << ans_i + ans_j - 2 << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
/**
 *      purpose : Dwango Programming Contest V / 第5回 ドワンゴからの挑戦状 予選 A
 *      author  : kyomukyomupurin
 *      created : 2018-11-24 20:01:05
**/

#include <bits/stdc++.h>
typedef int64_t int64;
#define print(x) cout << (x) << '\n'
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n; cin >> n;
    double a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];

    double mean = (accumulate(a, a + n, double())) / (double) n;
    for (int i = 0; i < n; ++i){
        a[i] -= mean;
        if (a[i] < 0) a[i] *= -1.0;
    }
    double ans = 1e9; int temp = 0;

    for (int i = 0; i < n; ++i){
        if (a[i] < ans){
            ans = a[i]; temp = i;
        }
    }
    print(temp);
    
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
#define smaller_queue_p  priority_queue <pll, vector<pll>, greater<pll> >
//------------------------------------------------------

struct edge {
    pii to;
    int cost;
};

int MAX_V = limit * 3;
map< pii, vector<edge> > E;
map<pii, int> d;

typedef pair<int, pii> P;

void dijkstra(pii s) {
    priority_queue <P, vector<P>, greater<P> > que;
    que.push(MP(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        pii v = p.second;
        if (d[v] == 0 && v != s) d[v] = INF;
        if (d[v] < p.first) continue;
        for (auto e : E[v]) {
            if (d[e.to] == 0 && e.to != s) d[e.to] = INF;

            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(MP(d[e.to], e.to));
            }
        }
    }
}

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

    rep(i, m) {
        int p, q, c;
        cin >> p >> q >> c;
        E[MP(p, c)].push_back({MP(q, c), 0});
        E[MP(q, c)].push_back({MP(p, c), 0});
        E[MP(p, c)].push_back({MP(p, -1), 0});
        E[MP(q, c)].push_back({MP(q, -1), 0});
        E[MP(p, -1)].push_back({MP(p, c), 1});
        E[MP(q, -1)].push_back({MP(q, c), 1});
    }

    dijkstra(MP(1, -1));
    cout << (d[MP(n, -1)] == 0 ? -1 : d[MP(n, -1)]) << endl;
    return 0;
}


Measured memory_bytes: 91700
#include<stdio.h>
int main(void)
{
    int a, b, c;
	scanf("%d",&a); 
	scanf("%d",&b);
	scanf("%d",&c);
	if(a<b && b<c){
	     printf("Yes\n");
	}
	else{
	     printf("No\n");
	}
    return 0;
}

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

int main(){
 int h, w, x, y, r;
 cin >> h >> w >> x >> y >> r;
 if((x-r)>=0 && (x+r) <= h && (y-r) >= 0 && (y+r)<=w) cout << "Yes" << endl;
 else cout << "No" << endl;
 return 0;
}


Measured memory_bytes: 3104
n = int(input())
a = [int(input()) for _ in range(n)]

i = 1
f = a[0]
while i< 10**6:
    
    if f == 2:
        print(i)
        break
    elif i>n+1:
        print(-1)
        break
    else:
        f = a[f-1]
        i+=1
        



Measured memory_bytes: 51288
import sys

def main():
    sys.setrecursionlimit(1000000) # recursion limit hack
    buf = input()
    N = int(buf)
    a = []
    b = []
    for i in range(N-1):
        buf = input()
        buflist = buf.split()
        a.append(int(buflist[0]) - 1)
        b.append(int(buflist[1]) - 1)
    graph = []
    for i in range(N):
        graph.append([])
    for i in range(N-1):
        graph[a[i]].append(b[i])
        graph[b[i]].append(a[i])
    path = find_path(graph, 0, N-1, [])
    split_point = (len(path) + 1) // 2
    fennec_base = path[0:split_point]
    snuke_base = path[split_point:len(path)]
    fennec_vertex_count = len(fennec_base)
    snuke_vertex_count = len(snuke_base)
    for i, v in enumerate(fennec_base):
        for j in graph[v]:
            if i != 0:
                if j == fennec_base[i-1]:
                    continue
            if i != len(fennec_base) - 1:
                if j == fennec_base[i+1]:
                    continue
            else:
                if j == snuke_base[0]:
                    continue
            fennec_vertex_count += get_vertex_count(graph, v, j)
    for i, v in enumerate(snuke_base):
        for j in graph[v]:
            if i != 0:
                if j == snuke_base[i-1]:
                    continue
            else:
                if j == fennec_base[-1]:
                    continue
            if i != len(snuke_base) - 1:
                if j == snuke_base[i+1]:
                    continue
            snuke_vertex_count += get_vertex_count(graph, v, j)
    if fennec_vertex_count > snuke_vertex_count:
        print("Fennec")
    else:
        print("Snuke")

def find_path(graph, current, target, path):
    path.append(current)
    if current == target:
        return path
    for i in graph[current]:
        if len(path) >= 2:
            if i == path[-2]:
                continue
        result = find_path(graph, i, target, path)
        if result:
            return path
    path.pop()
    return None

def get_vertex_count(graph, base, next):
    count = 1
    for i in graph[next]:
        if i == base:
            continue
        count += get_vertex_count(graph, next, i)
    return count

if __name__ == '__main__':
    main()


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

int main()
{
	int n;
	while (cin >> n) {
		bool flag = false;
		for (int i = 0; i < 10; i++) {
			if (n & (1 << i)) {
				if (flag) {
					cout << ' ';
				}
				cout << (1 << i);
				flag = true;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 5001
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

ll lcm(ll n, ll m){
	if(!n || !m)return 0;
	return n/__gcd(n, m)*m;
}
ll a[101][4];

ll solve(ll k){
	ll l = -1, r = -1, ans = 0, t1 = 0;
	ll x = a[k][0], y = a[k][1];
	if(a[k][2] != 0)l = solve(a[k][2]);
	if(a[k][3] != 0)r = solve(a[k][3]);
	if(l == -1 && r == -1)ans = (lcm(x, y)*(x+y))/(x*y);
	else if(l != -1 && r != -1){
		t1 = lcm(x*l, y*r);
		ans = t1/x+t1/y;
	}else{
		if(l == -1){
			r *= x/__gcd(x, r*y);
			l = (r*y)/x;
		}
		if(r == -1){
			l *= y/__gcd(y, l*x);
			r = (l*x)/y;
		}
		ans = l+r;
	}
	//cout << k << " " << ans << endl;
	return ans;
}

int used[101];
int main(){
	int n;
	ll st;
	while(cin >> n, n){
		fill(used, used+101, 0);
		for(int i = 1;i <= n;i++){
			for(int j = 0;j < 4;j++){
				scanf("%d", &a[i][j]);
				if(2<=j)used[a[i][j]] = 1;
			}
		}
		for(int i = 1;i <= n;i++)if(!used[i])st = i;
		int ans = solve(st);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3180
n = int(input())
x = [int(i) for i in input().split()]
y = [int(j) for j in input().split()]
answer = 0
for k in range(n):
	if answer < sum(x[:k+1]) + sum(y[k:]): answer = sum(x[:k+1]) + sum(y[k:])
print(answer)

Measured memory_bytes: 3060
// Problem: Megalomania
// Contest: Virtual Judge - AtCoder
// URL: https://vjudge.net/problem/AtCoder-abc131_d#author=0
// Memory Limit: 1048 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//
//#include <immintrin.h>
//#include <emmintrin.h>

#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
#define vi vector<int>
#define pii pair<int, int >
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define LL long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define all2(x,n) (x+1), (x+1+n)
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define mt make_tuple
#define eb emplace_back
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define contain(S,X) (((S)&o(X))!=0)
#define containL(S,X) (((S)&oL(X))!=0)
#define ppt(x) __builtin_popcount(x)
using namespace std;
const int INF=0x3f3f3f3f,N=5e6+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;
inline int getplc(int x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}
LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}
// Smax
//int Smax() { return -INF; }
template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) { return max(a, Smax(args...)); }
// Smin
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) { return min(a, Smin(args...)); }
template <typename T>
// erro
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); errl(_it, args); }

void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl;}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}
void Solve();
int main() {
#ifndef ONLINE_JUDGE
//	freopen("in.txt","r",stdin);
//    freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}

//////////////////////////////////////////////////////////////////

pii a[N];
void Solve(){
  int n;
  cin>>n;
  rep(i,1,n){
    cin>>a[i].fi>>a[i].se;
  }
  sort(a+1,a+1+n,[&](pii a,pii b){return a.se<b.se;});
  int sum=0,suc=1;
  rep(i,1,n){
    sum+=a[i].fi;
    if(sum>a[i].se)suc=0;
  }
  if(suc)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
} 


Measured memory_bytes: 5220
#include <stdio.h>

int solve(){
	
	int masu[32][32] = { 0 };
	int stop[32][32] = { 0 };
	int x,y,N,a,b;
	
	scanf("%d%d",&y,&x);
	if(x == 0)return 0;
	scanf("%d",&N);
	for(int i = 0; i < N; i++){
		scanf("%d%d",&b,&a);
		stop[a][b] = 1;
	}
	/*
	for(int i = 1; i <= x; i++){
		masu[i][0] = 1;
	}
	for(int j = 1; j <= y; j++){
		masu[0][j] = 1;
	}
	*/
	masu[0][1]=1;
	
	for(int i = 1; i <= x; i++){
		for(int j = 1; j <= y; j++){
			if(!(stop[i][j])){
				masu[i][j] = masu[i-1][j] + masu[i][j-1];
			}
			else{
				masu[i][j] = 0;
			}
			/*
			for(int k = 0; k <= x+1; k++){
				for(int l = 0; l <= y+1; l++){
					printf("%2d ",masu[k][l]);
				}
				puts("");
			}
			puts("");
			*/
		}
	}
	
	printf("%d\n",masu[x][y]);
	return 1;
}

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

Measured memory_bytes: 0
'use strict';

const receive = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\s/);

const main = input => {
  const c = input[0];

  const temp = ['a', 'i', 'u', 'e', 'o'].indexOf(c);
  const ans = !(temp === -1) ? 'vowel' : 'consonant';

  console.log(ans);
};

main(receive);


Measured memory_bytes: 7372
import java.util.Scanner;

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

        int X = sc.nextInt();

        System.out.println(solve(X));

        sc.close();
    }

    static int solve(int X) {
        int sum = 0;
        for (int i = 1;; ++i) {
            sum += i;
            if (sum >= X) {
                return i;
            }
        }
    }
}


Measured memory_bytes: 23636
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);


int main() {
  bool prime[1000005];
  int primenum[1000005];
  for(int i=0;i<1000005;++i) prime[i] = true;
  prime[0] = false;
  prime[1] = false;
  for(int i=2;i<1000005;++i){
    if(prime[i]==false) continue;
    for(int j=2;i*j<1000005;++j){
      prime[i*j] = false;
    }
  }
  primenum[0] = 0;
  primenum[1] = 0;
  for(int i=2;i<1000005;++i){
    if(prime[i]){
      primenum[i] = primenum[i-1] + 1;
    }
    else{
      primenum[i] = primenum[i-1];
    }
  }
  int N;
  while(cin>>N){
    cout<<primenum[N]<<endl;
  }
}



Measured memory_bytes: 7960
#写経

import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n, m = na()
ab = []
for i in range(n):
    ab.append(na())
ab.sort(key=lambda x: x[0])
 
rem = m
ans = 0
for v in ab:
    buy = min(rem, v[1])
    ans += buy * v[0]
    rem -= buy
print(ans)

Measured memory_bytes: 28956
// A. 

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, char *argv[])
{
	int N;
	string s, t, ans;
	cin >> N >> s >> t;
	for (int i = 0; i <= N; ++i) {
		ans = s.substr(0, i) + t;
		if (ans.substr(0, N) == s) {
			break;
		}
	}
	cout << ans.length() << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define FOR(i,a,b) for(int i=(a); i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;

int main(){
  int n;//入力するデータ
  int check;
  while(cin >> n){
    if(n==0) break;
    check=0;
    ll num[4001]={0};//社員の売り上げ金額
    bool bl[4001]={false};
    ll t[4001]={0};//社員番号
    ll emp,cost,count;
    int k=0;
    REP(i,n){
      cin >> emp >> cost >> count;
      if(bl[emp]==false){
        bl[emp]=true;
        t[k++]=emp;
        num[emp] = cost*count;
      }
      else{
      num[emp] += cost * count;
      }
    }
    REP(i,n){
      if(num[t[i]] >= 1000000){
        cout << t[i] << endl;
        check++;
  }
    }
    if(check==0)
      cout << "NA" << endl;
  }
}

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

int main() {
  string s,t;
  long ans=0;
  cin >> s >> t;
  map<char,set<long>> aaa;
  for(long i=0;i<s.size();i++) aaa[s[i]].insert(i);
  
  for(long i=0;i<t.size();i++) {
    if(!aaa.count(t[i])){
      ans=-1;
      break;
    }
    auto a=aaa[t[i]].end();
    a--;
    if(i==0) ans=*aaa[t[i]].begin();
    else if(ans%s.size()<*a) ans=ans/s.size()*s.size()+*aaa[t[i]].upper_bound(ans%s.size());
    else ans=(ans/s.size()+1)*s.size()+*aaa[t[i]].begin();
  }
  if(ans!=-1) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 5120
/* When Talent doesn't work, Hard work beats Talent*/
#include"bits/stdc++.h"
using namespace std;

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define llu long long unsigned int
#define fix fixed << setprecision(9)
#define nl "\n"

int main()
{
	FastIO;
	ll a;
	ld b;
	cin>>a>>b;
	ll x=round(b*100);
	cout<<x*a/100;
    return 0 ;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
int tree[3000000];
string s;
void build(int node , int start , int end)
{
    if(start==end)
    {
        int r;
        r = s[start-1] - 'a';
        tree[node] = 1<<r;
    }
    else
    {
        int mid;
        mid = (start+end)/2;
        build(2*node,start,mid);
        build(2*node+1,mid+1,end);
        tree[node] = tree[2*node]|tree[2*node+1];
    }
}
void update(int node, int start , int end , int idx , char val)
{
    if(start==end and start==idx)
    {
        s[idx-1] = val;
        int r;
        r = val - 'a';
        tree[node] = 1<<r;
    }
    else
    {
        int mid=(start+end)/2;
        if(idx>mid)
        {
            update(2*node+1,mid+1,end,idx,val);
        }
        else
        {
            update(2*node,start,mid,idx,val);
        }
        tree[node] = tree[2*node]|tree[2*node +1];
    }
}
int query(int node , int start , int end , int l , int r)
{
    if(l>end or r<start)
    {
        return 0;
    }
    else if(l<=start and r>=end)
    {
        return tree[node];
    }
    else
    {
        int mid;
        mid = (start+end)/2;
        int p1 = query(2*node,start,mid,l,r);
        int p2 = query(2*node+1,mid+1,end,l,r);
        return p1|p2;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    cin>>s;
    int q;
    cin>>q;
    build(1,1,n);
    for(int i=0;i<q;i++)
    {
        int r;
        cin>>r;
        if(r==1)
        {
            int w;
            char c;
            cin>>w>>c;
            update(1,1,n,w,c);
        }
        else
        {
            int l,r;
            cin>>l>>r;
            int ans = query(1,1,n,l,r);
            int cc=0;
            while(ans>0)
            {
                int er;
                er = ans&1;
                cc+=er;
                ans = ans>>1;
            }
            cout<<cc<<"\n";
        }
    }
    return 0;
}


Measured memory_bytes: 7068
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll H,A[10001],B[10001];
	int N;
	scan(H>>N);
	rep(i,N){
		scan(A[i]>>B[i]);
	}
	ll dp[10001];
	rep(h,H+1) dp[h]=INFl;
	dp[0]=0;
	rep1(h,H){
		rep(i,N){
			if(h<A[i]){
				dp[h]=min(dp[h],B[i]);
			}
			else{
				dp[h]=min(dp[h],B[i]+dp[h-A[i]]);
			}
		}
	}
	prin(dp[H]);
	return 0;
}


Measured memory_bytes: 384
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    int ab = a + b;
    int bc = b + c;
    int ca = c + a;
    
    if(a == bc || b == ca || c == ab) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21588
from sys import stdin
import numpy as np
from numba import njit

@njit("i8(i8[:,:],i8,i8)")
def search(grid,h,w):
    q=np.zeros(2*10**6+4,dtype=np.int64)
    now=0
    for i in range(h):
        for j in range(w):
            if grid[i][j]==1:
                q[now]=i
                q[now+1]=j
                now+=2

    now,nex=0,now
    cnt=0
    while now!=nex:
        tmp=nex
        for i in range(now,nex,2):
            y=q[i]
            x=q[i+1]
            for dy,dx in (-1,0),(1,0),(0,-1),(0,1):
                ny=y+dy
                nx=x+dx
                if 0<=ny<h and 0<=nx<w:
                    if grid[ny][nx]==0:
                        grid[ny][nx]=1
                        q[tmp]=ny
                        q[tmp+1]=nx
                        tmp+=2

        now,nex=nex,tmp
        cnt+=1

    return cnt-1

def main():
    #入力
    readline=stdin.readline
    h,w=map(int,readline().split())
    grid=[readline().strip() for _ in range(h)]
    grid=np.array([[1 if grid[i][j]=="#" else 0 for j in range(w)] for i in range(h)],dtype=np.int64)
    print(search(grid,h,w))

if __name__=="__main__":
    main()

Measured memory_bytes: 136676
# -*- coding: cp932 -*-

import sys
import os
import re
import datetime
import bisect

### main ###

X = input()

restS = []
for c in X:
    #print("c = {}".format(c))
    restS.append(c)
    if c == 'T':
        while(len(restS) >= 2):
            #print("restS = {}, last 2 string = {} ".format(restS, restS[-2:]))
            if("".join(restS[-2:]) == 'ST'):
                #print("hit")
                #restS = restS[:-2] # TLE
                del restS[-2:]
                #print("new restS = {}".format(restS))
            else:
                #print("no hit")
                break # out of while

print(len(restS))

Measured memory_bytes: 5648
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
ll w,h,a,b;
ll fak[200005];

ll modPow(ll x, ll p){
    if(p == 0) return 1;
    if(p == 1) return x;
    ll tmp = modPow(x,p/2);
    if(p %2 == 0) return tmp*tmp%MOD;
    else return (tmp*tmp%MOD)*x%MOD;
}

void seed(){
    ll mx = max(h-a+b,w+a);
    mx = max(mx,w+h);
    fak[0] = 1;
    rep(i,1,mx+1) {
        fak[i] = (fak[i-1]*(i))%MOD;
    }
}

ll getComb(ll n, ll k){
    if(k == 0) return 1;
    if(n == k) return 1;
    if(n < k) return 0;
    ll den = fak[k]*fak[n-k]%MOD;
    return fak[n]*modPow(den,MOD-2)%MOD;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;

    cin >> h >> w>> a>>b;
    seed();
    ll ans = 0;
    rep(i,1,b+1){
        ans = (ans + getComb(h-a+i-2,i-1)*getComb(w+a-1-i,a-1)%MOD)%MOD;
    }
    // cout <<ans << endl;
    cout << (getComb(h-1+w-1,h-1) + MOD - ans)%MOD;
    cout << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

typedef long long ll;

struct mobile
{
	int p, q, r, b;
	int par;
	
	void init(){
		p = q = r = b = 0;
		par = -1;
	}
};

ll gcd(ll a, ll b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

/*
2 3 
2 3

4 9

36 36

18 12
*/

mobile M[100];

ll weight(int now)
{
	ll R, B;
	
	if (M[now].r == -1) R = 1;
	else R = weight(M[now].r);
	if (M[now].b == -1) B = 1;
	else B = weight(M[now].b);
	
	ll P, Q;
	P = R * M[now].p;
	Q = B * M[now].q;
	
	ll l = lcm(P, Q);
	
	return (l / M[now].p) + (l / M[now].q);
}

int main()
{
	int n;
	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++){
			M[i].init();
		}
		
		for (int i = 0; i < n; i++){
			scanf("%d %d %d %d", &M[i].p, &M[i].q, &M[i].r, &M[i].b);
			int g = gcd(M[i].p, M[i].q);
			M[i].p /= g;
			M[i].q /= g;
			M[i].r--; M[i].b--;
			
			if (M[i].r != -1) M[M[i].r].par = i;
			if (M[i].b != -1) M[M[i].b].par = i;
		}
		
		int top = 0;
		for (int i = 0; i < n; i++){
			if (M[i].par == -1){
				top = i;
				break;
			}
		}
		
		printf("%lld\n", weight(top));
	}
	
	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void solve()
{
  int k;
  string s;
  cin>>k>>s;
  int length=s.size();
  if(length<=k)
  {
  	cout<<s<<"\n";
  }
  else
  {
    for(int i=0;i<length;i++)
    {
      if(i<k)
      {
        cout<<s[i];
      }
      else
      {
      	i=length;
      }
    }
    cout<<"...\n";
  }
  
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
}

Measured memory_bytes: 3612
import heapq


def main():
    Q = int(input())
    query_list = [list(map(int, input().split(' '))) for _ in range(Q)]
    # fの最小を与えるxの計算用
    que_left, que_right = [], []  # 最大ヒープと最小ヒープ
    # fの最小値の計算用
    sum_a_cost = 0
    sum_b = 0
    for query in query_list:
        if query[0] == 1:
            a, b = query[1], query[2]
            # fの更新
            if len(que_right) - len(que_left) == 1:
                sum_a_cost += abs(a - que_right[0])
            elif 0 < len(que_left) == len(que_right):
                if a > que_right[0]:
                    sum_a_cost += a - que_right[0]
                elif a < - que_left[0]:
                    sum_a_cost += - que_left[0] - a
            sum_b += b
            # xの更新
            if len(que_right) == 0 or a >= que_right[0]:
                heapq.heappush(que_right, a)
            else:
                # 最大ヒープにするため符号反転
                heapq.heappush(que_left, - a)
            # ヒープのサイズ差が0 or 1になるよう調整
            if len(que_right) - len(que_left) == - 1:
                heapq.heappush(que_right, - heapq.heappop(que_left))
            elif len(que_right) - len(que_left) == 2:
                heapq.heappush(que_left, - heapq.heappop(que_right))
        else:
            x = que_right[0] if len(que_right) - len(que_left) == 1 else (- que_left[0])
            f = sum_a_cost + sum_b
            print('{} {}'.format(x, f))


if __name__ == '__main__':
    main()

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

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0)break;
    vector<int> a;
    for(int i=0;i<n;i++){
      int input;
      cin >> input;
      a.push_back(input);
    }
    sort(a.begin(),a.end());
    int sum=0;
    for(int i=1;i<a.size()-1;i++){
      sum+=a[i];
    }
    cout << sum/(n-2) << endl;
  }
}


Measured memory_bytes: 3168
import scala.io.StdIn.{readInt,readLine}

object Main {
  def main(args:Array[String]) = {
    val n = readInt
    val s = for(i<-1 to n) yield {
      val l = readLine.split(" ").map(_.toInt)
      val x = l(0)*l(2)+l(1)*l(3)
      val y = (l(0)*(if(l(2)<5) 5 else l(2)) + l(1) * (if(l(3)<2) 2 else l(3)))*0.8
      if(x<y) x.toInt else y.toInt
    }
    println(s.mkString("\n"))
  }
}

Measured memory_bytes: 44364
#include <iostream>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  int adddd = stoi(a+b);
  int way = 1;
  string ggg = "No";
  while(adddd > way*way){
    way++;
    if(adddd == way*way)ggg="Yes";
    
  }
  cout << ggg << endl;
}

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

constexpr int inf = 1e9;

struct edge {
    int to, cost;
};

using edges = vector<edge>;
using graph = vector<edges>;

int main() {
    int n, m;
    while(cin >> n >> m, n) {
        vector<int> height(n), fee(n), bit(n);
        height[n - 1] = 1000;
        vector<int> h_cnt(1000);
        for(int i = 1; i < n - 1; ++i) {
            cin >> fee[i] >> height[i];
            bit[i] = h_cnt[height[i]]++;
        }
        graph g(n), rg(n);
        for(int i = 0; i < m; ++i) {
            int a, b, c;
            cin >> a >> b >> c;
            g[a - 1].push_back(edge{b - 1, c});
            rg[b - 1].push_back(edge{a - 1, c});
        }

        vector<vector<vector<int>>> d(n, vector<vector<int>>(n, vector<int>(1 << 10, inf)));
        d[0][0][1] = 0;
        using state = tuple<int, int, int, int>;
        priority_queue<state, vector<state>, greater<state>> que;
        que.emplace(0, 0, 0, 1);
        while(!que.empty()) {
            int cur_d, u, v, S;
            tie(cur_d, u, v, S) = que.top();
            que.pop();
            const int cur_h = max(height[u], height[v]);
            for(auto& e : g[u]) {
                if(height[e.to] < cur_h) continue;
                const int nS = (1 << bit[e.to]) | (height[e.to] > cur_h ? 0 : S);
                const int nxt_d = cur_d + (height[e.to] == cur_h && (S & (1 << bit[e.to])) ? 0 : fee[e.to]) + e.cost;
                if(nxt_d < d[e.to][v][nS]) {
                    d[e.to][v][nS] = nxt_d;
                    que.emplace(nxt_d, e.to, v, nS);
                }
            }
            for(auto& e : rg[v]) {
                if(height[e.to] < cur_h) continue;
                const int nS = (1 << bit[e.to]) | (height[e.to] > cur_h ? 0 : S);
                const int nxt_d = cur_d + (height[e.to] == cur_h && (S & (1 << bit[e.to])) ? 0 : fee[e.to]) + e.cost;
                if(d[u][e.to][nS] > nxt_d) {
                    d[u][e.to][nS] = nxt_d;
                    que.emplace(nxt_d, u, e.to, nS);
                }
            }
        }

        cout << (d[n - 1][n - 1][1] == inf ? -1 : d[n - 1][n - 1][1]) << endl;
    }
}



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

# define ll long long

int main(){
 
  int n;
  cin >> n;
  
  vector<int> numbers(n);
  for(int i=0; i<n; i++){
    cin >> numbers[i];
    numbers[i]--;
  }
  
  vector<int> ans;
  while(!numbers.empty()){
    bool flag = false;
    for(int i=numbers.size()-1; i>=0; i--){
      if(numbers[i] == i){
        numbers.erase(numbers.begin()+i);
        ans.push_back(i+1);
        flag = true;
        break;
      }
    }
    
    if(!flag){
      ans.clear();
      ans.push_back(-1);
      break;
    }
  }
  
  reverse(ans.begin(), ans.end());
  for(int num : ans) cout << num << endl;
  
  return 0;
} 



Measured memory_bytes: 3580
dic={}
while True:
    try:
        n = int(raw_input())
        if n not in dic:
            dic[n] = 1
        else:
            dic[n] += 1
    except:
        break
        
mode = []
m = 0 
for k,v in sorted(dic.items(),key = lambda x:x[1],reverse=True): 
    if m==0:
        mode.append(k)
        m +=1
    if v == dic[mode[-1]] and k!=mode[-1]:
        mode.append(k)
        
for i in range(len(mode)):
    print mode[i]

Measured memory_bytes: 4228
#include <bits/stdc++.h>
#define ll long long
const int N = 500050;
const long double eps = 1e-7;
using namespace std;
int gi(){
  char ch=getchar(); int x=0,q=0;
  while(ch<'0' || ch>'9') (ch=='-'?q=1:0),ch=getchar();
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
struct date{
  ll v; long double t;
}st[N];
int L,n,l=1,r;
ll v,w,p;
long double t,s;
int main(){
  cin>>n>>L;
  for (int i=1; i<=n; ++i){
    t=gi(),p=v=gi(),s+=t*v,L-=v;
    while(w>L){
      if (w-st[l].v>=L)
	w-=st[l].v,s-=st[l].v*st[l].t,++l;
      else
	st[l].v-=w-L,s-=st[l].t*(w-L),w=L;
    }
    while(l<=r&&st[r].t+eps>t){
      t=(t*v+st[r].t*st[r].v)/(st[r].v+v);
      v+=st[r].v,--r;
    }
    L+=p,w=L;
    st[++r]=(date){v,t};
    printf("%.7Lf\n",s/L);
  }
  return 0;
}


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

using namespace std;

int main() {
	string s;
	cin >> s;
	
	int start = 0, end = 0;
	for (int i=0; i<s.length(); ++i)
	{
		if (s[i] == 'A') {
			start = i;
			break;
		}
	}
	
	for (int i=0; i<s.length(); ++i) {
		if (s[i] == 'Z') end = i;
	}
	
	cout << end - start + 1;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <memory.h>

using namespace std;

const int maxn = 100000 + 10;

int par[maxn];

int find_par(int k) {
	if (par[k] == k) {
		return k;
	}
	else {
		return par[k] = find_par(par[k]);
	}
}

void join(int p, int q) {
	int x = find_par(p);
	int y = find_par(q);
	par[x] = y;
}

int N, M;
int nums[maxn], a, b;
vector<set<int> > vse;
vector<int> idx[maxn];
vector<int> nu[maxn];


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> N >> M;

	for (int i = 1; i <= N; i++) {
		cin >> nums[i];
		par[i] = i;
	}
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		join(a, b);
	}

	for (int i = 1; i <= N; i++) {
		idx[find_par(i)].push_back(i);
		nu[find_par(i)].push_back(nums[i]);
	}

	int res = 0;
	for (int i = 1; i <= N; i++) {
		if (idx[i].size() != 0) {
			sort(idx[i].begin(), idx[i].end());
			sort(nu[i].begin(), nu[i].end());
			int x = 0, y = 0;
			while (x < idx[i].size() && y < nu[i].size()) {
				if (idx[i][x] == nu[i][y]) {
					x++;
					y++;
					res++;
				}
				else if (idx[i][x] > nu[i][y]) {
					y++;
				}
				else {
					x++;
				}
			}//while
		}
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 12032
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a,b;
	char c;
	scanf("%lld %c %lld",&a,&c,&b);
	printf("%lld",c=='+'?a+b:a-b);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int H, W;
	cin>> H >> W;
	while (W>0 && H>0){
		for (int i=1; i<=H; i++ ) {
			for (int j=1; j<=W; j++ ) {
				cout<< "#";
			}
			cout<<endl;
		}cout<<endl;
		cin>> H >> W;
	}
	
	return 0;
}


Measured memory_bytes: 3128
import java.util.*;
 
class Main {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int a = stdIn.nextInt();
int b = stdIn.nextInt();
    if((a*b)%2==0) {
    System.out.println("Even");
    } else {
    System.out.println("Odd");
    }
}
}

Measured memory_bytes: 23764