akhauriyash/Code-Regression huggingface dataset:
using System.Collections.Generic;
using System;
using System.Linq;

class Pg
{
    static void Main()
    {
        for (string line; !string.IsNullOrEmpty(line = Console.ReadLine()); Console.WriteLine(GetAns(line.Split().ToList()))) ;
    }
    static double GetAns(List<string> a)
    {
        var st = new Stack<double>();
        a.ForEach(delegate (string v)
        {
            double b;
            if (double.TryParse(v, out b))
                st.Push(b);
            else
                st.Push(Calq(v, st));
        });
        return st.Pop();
    }
    static double Calq(string x, Stack<double> st)
    {
        var a1 = st.Pop();
        var a2 = st.Pop();
        return (x == "+") ? a1 + a2 : (x == "*") ? a1 * a2 : (x == "-") ? a2 - a1 : a2 / a1;
    }
}


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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

//プロトタイプ宣言
void faster(void);
ll gcd(auto , auto);
ll get_digent(auto);
ll POW(auto , auto);
ll vec_max(auto & , string);
ll vec_min(auto & , string);

int main(){
  faster();
  int n;
  cin >> n;
  string s , t;
  cin >> s >> t;
  string u;
  rep(i,n){
    u += s[i];
    u += t[i];
  }
  cout << u << endl;
}


























//以下、ライブラリ

//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
ll gcd(auto a, auto b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
ll get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
ll POW(auto x, auto y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 

//配列内の最大要素の添え字取得or要素取得
ll vec_max(auto &v, string s){
  auto itr = max_element(v.begin(),v.end());
  ll element = *itr;
  ll place = itr - v.begin();
  if(s == "element") return element;
  else if(s == "place") return place;
  else return -1;
}

//配列内の最小要素の添え字取得or要素取得
ll vec_min(auto &v, string s){
  auto itr = min_element(v.begin(),v.end());
  ll element = *itr;
  ll place = itr - v.begin();
  if(s == "element") return element;
  else if(s == "place") return place;
  else return -1;
}

Measured memory_bytes: 256
cnt = 1
def dep(G,s_cnt,f_cnt,np):
    global cnt
    s_cnt[np] = cnt
    cnt += 1
    for i in range(n):
        if G[np][i] == 1 and s_cnt[i] == 0:
            dep(G,s_cnt,f_cnt,i)
    f_cnt[np] = cnt
    cnt += 1
    

n = int(input())
G = [[0 for i in range(n)] for j in range(n)]
s_cnt = [0 for i in range(n)]
f_cnt = [0 for i in range(n)]

for i in range(n):
    S = list(map(int, input().split()))
    tmp_n = S[1]
    for j in range(tmp_n):
        G[i][S[j+2]-1] = 1
        
for i in range(n):
    if s_cnt[i]==0:
        dep(G,s_cnt,f_cnt,i)

for i in range(n):
    print(i+1,s_cnt[i],f_cnt[i])


Measured memory_bytes: 5800
"use strict"
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    var tmp = input[1].split(" ");
    //文字列から10進数に変換するときはparseIntを使います
    var a = parseInt(input[0], 10);
    var b = parseInt(tmp[0], 10);
    var c = parseInt(tmp[1], 10);
    var s = input[2];
    for (var i = 0; i < input.length; i++){
        input[i] = input[i].match(/[0-9]*/g);
        input[i] = input[i].filter(v => v);
    }
    //中身
    var leng = 0;
    var n = input[0];
    var k = input[1]/2;

    for(var count = 0; count < n; count++){
        if(input[2][count] < k){
            leng += Number(input[2][count])*2;
        } else {
            leng += Number(input[1]-input[2][count])*2;
        }
    }
    console.log(leng);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22596
#include <cstdio>

typedef long long llint;

llint solve(llint, llint);
llint abs(llint);

int main() {
	llint x, y;
	scanf("%lld %lld", &x, &y);
	if(abs(x)==abs(y)) {
		printf("1\n");
	}
	else if(x==0) {
		if(y>0) printf("%lld\n", solve(x, y));
		else printf("%lld\n", solve(x, y)+1);
	}
	else if(y==0) {
		if(x>0) printf("%lld\n", solve(x, y)+1);
		else printf("%lld\n", solve(x, y));
	}
	else if(x>0 && y>0) {
		if(abs(x)>abs(y)) printf("%lld\n", solve(x,y)+2);
		else printf("%lld\n", solve(x,y));
	}
	else if(x<0 && y<0) {
		if(abs(x)<abs(y)) printf("%lld\n", solve(x,y)+2);
		else printf("%lld\n", solve(x,y));
	}
	else {
		printf("%lld\n", solve(x,y)+1);
	}
	return 0;
}

llint solve(llint x, llint y) {
	return abs(abs(x)-abs(y));
}

llint abs(llint x) {
	if(x<0) return -x;
	else return x;
}


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

using namespace std;

const int size = 2e5 + 7;
int arr[size], height[size];

int main(){
	int n, k;
	for(int x=0;x<size;x++) arr[x] = INT_MAX;
	cin>>n>>k;
	for(int x=0;x<n;x++) cin>>height[x];
	arr[0] = 0;
	if(n > 1) arr[1] = abs(height[0]-height[1]);
	for(int x=2;x<n;x++){
		for(int i=max(x-k,0);i<x;i++)
			arr[x] = min(arr[x], arr[i] + abs(height[i] - height[x]));
	}
	cout<<arr[n-1];
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e8;
using namespace std;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl



int main(void)
{

	string s;
	string tmp;
	int z = 0;
	int o = 0;
	ll tobasu[100010] = {};
	ll count = 0;
	cin >> s;
	ll n = s.size();
	
	for (int i = 0;i < n;i++)
	{
		if (s[i] == '0')
			o++;
		else
			z++;
	}

	cout << min(o,z)*2 << endl;


}

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

int main() {
  int A, B, C;

  cin >> A >> B >> C;

  if (C - (A - B) < 0) {
    cout << 0;
  }
  else {
    cout << C - (A - B);
  }

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#define MAXN 100010
int n,q;
typedef struct p{
    char name[10];
    int time;
}P;
P que[MAXN];
int head,tail,tot;



void get_input() {
    scanf("%d %d",&n,&q);
    for(int i=0;i<n;i++) {
        scanf("%s %d",que[i].name,&que[i].time);
    }
    tail=n;
}

void solve() {
    P item;
    while(head!=tail) {
        item=que[head];
        head=(head+1)%(n+1);
        if(item.time>q) {
            item.time-=q;
            tot+=q;
            que[tail]=item;
            tail=(tail+1)%(n+1);
        } else {
            tot+=item.time;
            printf("%s %d\n",item.name,tot);
        }
    }
}

void display_output() {
    
}

int main() {
#ifdef debug
    freopen("in.txt","r",stdin);
#endif
    get_input();
    solve();
    display_output();
}

Measured memory_bytes: 3460
n = int(input())

def get_sieve_of_atkin(n):  # O(n)
    is_prime = {i: False for i in range(5, n + 1)}
    limit = int(n**0.5) + 1
    for x in range(1, limit):
        for y in range(1, limit):
            k = 4 * x**2 + y**2
            if k <= n and (k % 12 == 1 or k % 12 == 5):
                is_prime[k] = not is_prime[k]
            k = 3 * x**2 + y**2
            if k <= n and k % 12 == 7:
                is_prime[k] = not is_prime[k]
            k = 3 * x**2 - y**2
            if x > y and k <= n and k % 12 == 11:
                is_prime[k] = not is_prime[k]
    for k in range(5, limit):
        if is_prime[k]:
            i = 1
            while i * k**2 <= n:
                is_prime[i * k**2] = False
                i += 1
    return [2, 3] + [i for i in range(5, n + 1, 2) if is_prime[i]]

sieve = get_sieve_of_atkin(55555)
ANS = []

for prime in sieve:
    if prime % 5 == 1:
        ANS.append(prime)

print(*ANS[:n])

Measured memory_bytes: 81548
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int l, r, d;
    cin >> l >> r >>d;
    int ans = 0;
    for(int i = l; i <=r; i++){
       if(i%d==0){
           ans++;
       } 
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll dp[3005][3005], pref[3005][3005];

int main(){
    ll n; cin >> n;
    string s; cin >> s;
    
    dp[0][1] = pref[0][1] = 1;
for(ll j = 2; j <= n; j++)
        pref[0][j] += pref[0][j-1];
    
    for(ll i = 1; i <= n; i++){
        for(ll j = 1; j <= i+1; j++){
            if(s[i-1] == '>')
                dp[i][j] = (dp[i][j] + pref[i-1][i+1]-pref[i-1][j-1] + mod)%mod;
            else
                dp[i][j] = (dp[i][j] + pref[i-1][j-1]-pref[i-1][0] + mod)%mod;
        }
        for(ll j = 1; j <= n; j++)
            pref[i][j] = pref[i][j-1] + dp[i][j];
    }
    ll sum = 0;
    for(ll i = 1; i <= n; i++)
        sum = (sum+dp[n-1][i])%mod;
    cout << sum << endl;
	return 0;
}


Measured memory_bytes: 141312
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int Q;
multiset<ll> l, r;
ll ls, rs, bs;
ll x;

int main(){
    cin >> Q;
    int q;
    cin >> q >> x >> bs;
    l.insert(x);
    ls += x;

    for(int i = 1; i < Q; i++){
        cin >> q;
        auto it = l.end();
        x = *--it;
        if(q == 1){
            ll a, b;
            cin >> a >> b;
            bs += b;
            if(l.size() == r.size()){
                if(x < a){
                    rs += a;
                    r.insert(a);
                    it = r.begin();
                    rs -= *it;
                    ls += *it;
                    l.insert(*it);
                    r.erase(it);
                }else{
                    ls += a;
                    l.insert(a);
                }
            }else{
                if(x < a){
                    rs += a;
                    r.insert(a);
                }else{
                    ls += a;
                    l.insert(a);
                    it = l.end();
                    it--;
                    ls -= *it;
                    rs += *it;
                    r.insert(*it);
                    l.erase(it);
                }
            }
        }else{
            ll res = rs - ls + (l.size() == r.size() ? 0 : x);
            cout << x << " " << res + bs << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include<algorithm>
#include<vector> //動的配列
#include<string> 
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>


typedef long long ll;


using namespace std;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}


int x;
int y;
int z;
int k;

vector<ll> vec;
ll sub[3100];
vector<ll> ans;

int main(){
    cin>>x>>y>>z>>k;
    ll a[x];
    ll b[y];
    ll c[z];
    for (int i=0;i<x;i++){
        cin>>a[i];
    }
    for (int i=0;i<y;i++){
        cin>>b[i];
    }
    for (int i=0;i<z;i++){
        cin>>c[i];
    }
    for (int i=0;i<x;i++){
        for (int j=0;j<y;j++){
            vec.push_back (a[i]+b[j]);
        }
    }
    sort(vec.begin(),vec.end(),std::greater<ll>());
    int minsize=min(x*y,k);
    for (int i=0;i<minsize;i++){
        sub[i]=vec.at(i);
        //cout<<sub[i]<<endl;
    }
    for (int i=0;i<minsize;i++){
        for (int j=0;j<z;j++) {
            ans.push_back (sub[i]+c[j]);
        }
    }
    sort(ans.begin(),ans.end(),greater<ll>());
    int minm=min(k,x*y*z);
    for (int i=0;i<minm;i++){
        cout<<ans.at(i)<<endl;
    }
}


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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, a , n) for(int i=(a); i<(n); i++)

string weekdays[] = {
    "SUN",
    "MON",
    "TUE",
    "WED",
    "THU",
    "FRI",
    "SAT"
};

int main() {
    string s;
    cin >> s;
    rep(i, 7) {
        if(weekdays[i] == s) {
            cout << 7 - i << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#define ll long long
#define rg register
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=1e5+5;
ll n,X;
ll sf[maxn],ans;
struct pt{
	ll l,r,b,f;
	friend bool operator <(pt a,pt b){
		return a.f > b.f;
	}
}p[maxn];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc == '-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline bool check(ll x){
	ll a=x/X,b=x%X;
	if(a == n) return ans+sf[a] >= 0;
	go(i,n+1,1){
		ll ss=ans;
		if(i <= a){
			if(b <= p[i].b) ss=ss+sf[a+1]-p[i].f+b*p[i].l;
			else ss=ss+sf[a+1]-p[i].f+p[i].b*p[i].l+(b-p[i].b)*p[i].r;
		}
		else{
			if(b <= p[i].b) ss=ss+sf[a]+b*p[i].l;
			else ss=ss+sf[a]+p[i].b*p[i].l+(b-p[i].b)*p[i].r;
		}
		if(ss >= 0) return 1;
	}
	return 0;
}

void pre(){
	go(i,n+1,1) p[i].f=(ll)(X-p[i].b)*p[i].r+p[i].b*p[i].l,ans=ans-p[i].b*p[i].l;
	sort(p+1,p+n+1);
	go(i,n+1,1) sf[i]=sf[i-1]+p[i].f;
}

int main(){
//	freopen("1.in","r",stdin);
	n=rd(); X=rd(); ll l=0,r=0,res=-1;
	go(i,n+1,1)
		p[i].b=rd(),p[i].l=rd(),p[i].r=rd(),r=r+p[i].b;
	pre();
	while(l <= r){
		ll mid=l+r>>1;
		if(check(mid)) res=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 4096
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
struct S{
  int b,c,d;
  S(){}
  S(int b,int c,int d):b(b),c(c),d(d){}
};
int a[300],n,m;
S b[300],e[301][301];
S fi(int p,int q){
  int i;
  if(e[p][q].b!=-1)
    return e[p][q];
  S mx=S(0,0,0);
  for(i=0;a[p]*i<=q;++i){
    S tm=fi(p+1,q-a[p]*i);
    if(mx.b<tm.b+b[p].b*i)
      mx.b=tm.b+b[p].b*i;
    if(mx.c<tm.c+b[p].c*i)
      mx.c=tm.c+b[p].c*i;
    if(mx.d<tm.d+b[p].d*i)
      mx.d=tm.d+b[p].d*i;
  }
  return e[p][q]=mx;
}
int main(){
  int i;
  //int n,m;
  while(cin>>n>>m){
    //int a[300];
    //S b[300];
    string s;
    for(i=0;i<n;++i){
      getline(cin,s);
      getline(cin,s);
      cin>>a[i]>>b[i].b>>b[i].c>>b[i].d;
    }
    fill(e[0],e[0]+301*301,S(-1,-1,-1));
    fill(e[n],e[n]+301,S(0,0,0));
    S mx=fi(0,m);
    cout<<max(max(mx.b,mx.c),mx.d)<<endl;
  }
  return 0;
}

Measured memory_bytes: 2008
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
import heapq

def main():
    N = int(input())
    V = input_nums()
    heapq.heapify(V)
    while len(V) > 1:
        a = heapq.heappop(V)
        b = heapq.heappop(V)
        total = (a+b)/2
        heapq.heappush(V, total)
    print(heapq.heappop(V))

if __name__ == '__main__':
    main()

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

using namespace std;

int main(){
    int tmp = 1; 
    int count = 0;
    bool flg = false;
    int N; cin >> N;

    vector<int> a(N+1);

    //入力
    for(int i = 1; i <= N;i++){
        cin >> a.at(i);
    }

    for(int i = 1; i <= N; i++){
        count++;
        if(a.at(tmp) == 2){
            cout << count;
            flg = true;
            break;
        }
        tmp = a.at(tmp);
    }

    if(!flg)
        cout << -1;

  

    return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if ( (a+b) > (c+d) ) {
    cout << "Left" << endl;
  }
  else if ( (a+b) == (c+d) ) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

using ll = long long;
const int INF = 1e9+7;

void solve()
{
	int x,y;cin >> x >> y;
	string ans = "No";
	for(int i=0;i<x+1;++i)
	{
		int b=x-i;
		if((2*i)+(4*b)==y){
			ans = "Yes";
			break;
		}		
	}
	cout << ans << '\n';
}

int main()
{
	int t=1;
	//int t;cin >> t;
	while(t--) solve();
}	

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x;
    int i=0;
    while(1){
        cin >> x;
        if ( x == 0 ) {
            break;
        }else{
            i++;
            cout << "Case " << i <<": "<< x << endl;
        }

    
    }

    return 0;
}



Measured memory_bytes: 2988
#include<iostream>
#include<string>

using namespace std;

struct Dice{
	int P[6];
	void Roll(char a){
		
	int top;
	
	switch(a) {
		
		case 'E':
		top = P[0];
		P[0] = P[3];
		P[3] = P[5];
		P[5] = P[2];
		P[2] = top;
		break;
		
		case 'W':
		top = P[0];
		P[0] = P[2];
		P[2] = P[5];
		P[5] = P[3];
		P[3] = top;
		break;
		
		case 'S':
		top = P[0];
		P[0] = P[4];
		P[4] = P[5];
		P[5] = P[1];
		P[1] = top;
		break;
		
		default :
		top = P[0];
		P[0] = P[1];
		P[1] = P[5];
		P[5] = P[4];
		P[4] = top;
		break;	
	}
	
}
};

void Roll(char a, Dice S);

int main() {
	
	int n = 6;
	Dice S;
	
	while( cin >> S.P[0] ) {
		
		for(int i=1;i<n;i++)
		cin >> S.P[i];
		
		string Action;
		cin >> Action;
		
		for(int i=0;i<Action.length();i++)
		S.Roll(Action[i]);
		
		cout << S.P[0] << "\n";
		
	}
	
	return 0;
}



Measured memory_bytes: 3140
import math
def main():
    N, D = map(int, input().split())

    ans = 0

    for i in range(N):
        X, Y = map(int , input().split())

        d = math.sqrt(X**2 + Y**2)

        if d <= D:
            ans += 1
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9188
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		int n=sc.nextInt();
		for(int i=0; i<n; i++){
			double x1=sc.nextDouble();
			double y1=sc.nextDouble();
			double x2=sc.nextDouble();
			double y2=sc.nextDouble();
			double x3=sc.nextDouble();
			double y3=sc.nextDouble();

			double a1=2*(x2-x1);
			double b1=2*(y2-y1);
			double c1=x1*x1-x2*x2+y1*y1-y2*y2;
			double a2=2*(x3-x1);
			double b2=2*(y3-y1);
			double c2=x1*x1-x3*x3+y1*y1-y3*y3;

			double x=(b1*c2-b2*c1)/(a1*b2-a2*b1);
			double y=(c1*a2-c2*a1)/(a1*b2-a2*b1);

			double r=Math.sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
			println(String.format("%.3f %.3f %.3f", x, y, r));

			/*
			 * P a=new P(x1, y1);
			 * P b=new P(x2, y2);
			 * P c=new P(x3, y3);
			 * 
			 * P bc=c.sub(b);
			 * P ca=a.sub(c);
			 * P ab=b.sub(a);
			 * 
			 * P p=a.add(b).sub(ab.mul(bc.dot(ca)/ab.det(bc))).div(2);
			 * 
			 * double r=a.sub(p).abs();
			 * 
			 * println(String.format("%.3f %.3f %.3f", p.x, p.y, r));
			 */
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

class P{
	double x, y;

	P(){
		this(0, 0);
	}

	P(double x, double y){
		this.x=x;
		this.y=y;
	}

	P add(P p){
		return new P(x+p.x, y+p.y);
	}

	P sub(P p){
		return new P(x-p.x, y-p.y);
	}

	P mul(double m){
		return new P(x*m, y*m);
	}

	P div(double d){
		return new P(x/d, y/d);
	}

	double abs(){
		return Math.sqrt(abs2());
	}

	double abs2(){
		return x*x+y*y;
	}

	double arg(){
		return Math.atan2(y, x);
	}

	// inner product
	double dot(P p){
		return x*p.x+y*p.y;
	}

	// outer product
	double det(P p){
		return x*p.y-y*p.x;
	}

	P rot90(){
		return new P(-y, x);
	}

	// conjugation
	P conj(){
		return new P(x, -y);
	}
}

Measured memory_bytes: 12000
import math
X = int(input())


def fif_root(arg):
    def root(x):
        return math.floor(math.pow(x,1/5)*pow(10,10))/pow(10,10)
    return list(map(lambda x: root(x), arg))

def check_integer(arg):
    return list(map(lambda x: x.is_integer(), arg))

a = 0
while (A:= math.pow(a, 5))-math.pow(a-1, 5) <= X:
    #a,-aの時それぞれの5乗根を計算する。
    root = fif_root([abs(X-A), X+A])
    if True in (c := check_integer(root)):
        idx = c.index(True)
        b = int(root[idx])
        if idx == 1:
            a, b = -a, -b
        else:
            if X - A >= 0:
                b = -b
        print(a, b)
        break
    a += 1


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

int main(){
    int time;
    int h;
    int m;
    int s;

    cin >> time;
    h = time%60;
    m = (time/60)%60;
    s = time/60/60;
    cout << s << ":" << m << ":" << h << endl;

    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
string a;
long long ans;
int main()
{
    cin>>a;
    if(a[0] != 'C') ans++;
    if(a[1] != 'O') ans++;
    if(a[2] != 'D') ans++;
    if(a[3] != 'E') ans++;
    if(a[4] != 'F') ans++;
    if(a[5] != 'E') ans++;
    if(a[6] != 'S') ans++;
    if(a[7] != 'T') ans++;
    if(a[8] != 'I') ans++;
    if(a[9] != 'V') ans++;
    if(a[10] != 'A') ans++;
    if(a[11] != 'L') ans++;
    if(a[12] != '2') ans++;
    if(a[13] != '0') ans++;
    if(a[14] != '1') ans++;
    if(a[15] != '6') ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define ff first
#define ss second
#define inf 1000000000000LL
using namespace std;

int n,m;
string s;

deque<pii>dq;
ll dp[100007];
int st[100007];

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

	for( int i=1;i<=n;i++ )
		dp[i]= inf;

	dq.push_back({0,0});
	for( int i=1;i<=n;i++ )
	{
		if(s[i]=='1')
			continue;

		while( dq.size() and dq.front().ff<i-m ) dq.pop_front();
		while( dq.size() and dq.back().ss>=dp[i] ) dq.pop_back();
		
		if(dq.size())
			dp[i]= dq.front().ss+1, st[i]= i-dq.front().ff;

		dq.push_back({i,dp[i]});
	}

	if(dp[n]>n)
		cout<<"-1\n";
	else
	{
		std::vector<int> v;
		while(n>0)
			v.push_back(st[n]), n-= st[n];

		reverse(v.begin(), v.end());

		for( auto x: v )
			cout<<x<<" ";
	}
}

Measured memory_bytes: 5676
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	vector<int>A(5);
	rep(i, 0, 5) {
		cin >> A[i];
	}
	rep(i, 0, A.size()) {
		if (A[i] == 0) {
			cout << i + 1 << "\n";
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 3644
import sys
from collections import Counter
input = sys.stdin.readline
N, P = map(int, input().split())
c = Counter()
x = 2
while x * x <= P:
  while P % x == 0:
    P //= x
    c[x] += 1
  x += 1
if P > 1: c[P] += 1
#print(c)
res = 1
for k in c.keys():
  v = c[k]
  res *= pow(k, v // N)
print(res)

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

int main(){
  int N, L;
  cin >> N >> L;
  vector<int> azi(N);
  for(int i=0; i<N; i++){
    azi[i] = abs(L+i);
  }
  sort(azi.begin(), azi.end());
  int min = azi[0];
  int ans=0;
  bool f = true;
  for(int i=0; i<N; i++){
    if(f && abs(L+i)==min){f=false;continue;}
    ans += L+i;
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define MAX(a,b)((a)>=(b)?(a):(b))
int main() {
	int S,T;
	int i,m,s,e;
	scanf("%d %d %d %d",&i,&m,&s,&e);
	S=i+m+s+e;
	scanf("%d %d %d %d",&i,&m,&s,&e);
	T=i+m+s+e;
	printf("%d\n",MAX(S,T));
}

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

long long A, B, C, D;
map<long long, long long> mp;
long long cost_calc(long long);


int main(void) {

    int T;
    long long N;

    cin >> T;
    for (int i = 0; i < T; i++) {

        cin >> N >> A >> B >> C >> D;
        mp.clear();
        long long cost = cost_calc(N);
        cout << cost << "\n";
    }

    return 0;

}

long long cost_calc(long long N) {

    if (N == 0) { return 0; }
    if (N == 1) { return D; }
    if (mp.find(N) != mp.end()) { return mp[N]; }
    
    long long A1 = (N / 2) * 2;
    long long A2 = ((N + 1) / 2) * 2;
    long long B1 = (N / 3) * 3;
    long long B2 = ((N + 2) / 3) * 3;
    long long C1 = (N / 5) * 5;
    long long C2 = ((N + 4) / 5) * 5;

    //select A
    long long costA1 = llabs(A1 - N) * D + A + cost_calc(A1 / 2);
    long long costA2 = llabs(A2 - N) * D + A + cost_calc(A2 / 2);
    
    //select B
    long long costB1 = llabs(B1 - N) * D + B + cost_calc(B1 / 3);
    long long costB2 = llabs(B2 - N) * D + B + cost_calc(B2 / 3);
    

    //select C
    long long costC1 = llabs(C1 - N) * D + C + cost_calc(C1 / 5);
    long long costC2 = llabs(C2 - N) * D + C + cost_calc(C2 / 5);

    //select D + 1
    //long long costD1 = cost_calc(N + 1, cost + D);

    //select D - 1
    //long long costD2 = cost_calc(N - 1, cost + D);

    vector<long long> costs;
    costs.push_back(costA1);
    costs.push_back(costA2);
    costs.push_back(costB1);
    costs.push_back(costB2);
    costs.push_back(costC1);
    costs.push_back(costC2);

    if (N < 1e18 / D) costs.push_back(N * D);
    //costs.push_back(costD1);
    //costs.push_back(costD2);

    sort(costs.begin(), costs.end());
    //cout << "N : " << N << " return : " << costs[0] << endl;
    mp[N] = costs[0];

    return costs[0];
}

Measured memory_bytes: 4292
n,m = gets.split.map {|x| x.to_i}

arr = []
n.times {
  a,b = gets.split.map {|x| x.to_i}
  arr << [a,b]
}
arr.sort! {|x,y| x[0] <=> y[0]}

c = 0
arr.each { |v|
  flag = false
  if (m > v[1])
    buy = v[1]
  else
    buy = m
    flag = true
  end
  c += buy * v[0]
  if flag
    puts c
    exit
  end
  m -= buy
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
#define fi first
#define se second

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

int main() {
    ll a,b,n;
    cin>>a>>b>>n;
    //求めるべきはr=1~min(b-1,n)の中でa*r/bの最大
    ll num=min(b-1,n);
    cout<<(a*num)/b<<endl;

    return 0;
}

Measured memory_bytes: 3592
sx,sy,tx,ty=map(int,input().split())
dx=tx-sx
dy=ty-sy

a="U"*dy+"R"*dx
b="D"*dy+"L"*dx
c="L"+"U"*(dy+1)+"R"*(dx+1)+"D"
d="R"+"D"*(dy+1)+"L"*(dx+1)+"U"
print(a+b+c+d)

Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.InputMismatchException;

public class Main {
    
    public static void main(String[] args) {
        try {
            Scanner scanner = new Scanner(System.in);
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            int result = x - y + 1;
       
            System.out.println(result);
            scanner.close();
          } catch (InputMismatchException e) { 
            System.out.println("整数を入力してください。");
          }
    }
}


Measured memory_bytes: 22612
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
int MOD=1000000000+7;
int INF=1e6;
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

int rrank[110000],par[110000];
void init(int n){
    rep(i,n){
        rrank[i]=0;
        par[i]=i;
    }
}

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

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

void uni(int x,int y){
    x=root(x);
    y=root(y);
    if(rrank[x]>rrank[y]){
        par[y]=x;
    }else{
        par[x]=y;
        if(rrank[x]==rrank[y]) rrank[y]++;
    }
}

main(){
    int n,m;
    int pos[110000]={};
    cin>>n>>m;
    rep(i,n){
        int k;
        cin>>k;
        pos[k]=i+1;
    }
    init(n);
    rep(i,m){
        int x,y;
        cin>>x>>y;
        uni(x,y);
    }
    int ans=0;
    rep2(i,1,n){
        ans+=same(i,pos[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 1408
import java.util.*;

class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      
      double n = sc.nextInt();
	  double cnt = 0;
      
      for(int i=1;i<=n;i++){
      	if(i%2 == 1){
        	cnt++;
        }
      }
      double ans = 0;
      ans = cnt / n;
      System.out.println(ans);
      
    }
}

Measured memory_bytes: 35932
#include<iostream>
#include<string>
using namespace std;
int main() {
	int num, a;
	char word[50];

	cin >> num >> a;

	for (int i = 0; i < num; i++) {
		cin >> word[i];
	}
	
	word[a-1] -= 'A' - 'a';


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

		cout << word[i];
	}
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
int n, m, q, x, y; int group[111111]; vector<int> f[111111];
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++) group[i] = i, f[i].push_back(i);
	for(int i = 0; i < m; i++) {
		scanf("%d%d", &x, &y);
		if(group[x] == group[y]) continue;
		x = group[x], y = group[y];
		if(f[y].size() > f[x].size()) swap(x, y);
		for(int j = f[y].size() - 1; j >= 0; j--) {
			group[f[y][j]] = group[x];
			f[x].push_back(f[y][j]);
			f[y].pop_back();
		}
	}
	scanf("%d", &q);
	for(int i = 0; i < q; i++) {
		scanf("%d%d", &x, &y);
		printf("%s\n", group[x] == group[y] ? "yes" : "no");
	}
	return 0;
}

Measured memory_bytes: 9876
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }


int main() {

	int a, b, c, k;
	cin >> a >> b >> c >> k;

	if (k <= a) {
		cout << k << endl;
	}
	else if (k <= a + b) {
		cout << a << endl;
	}
	else {

		cout << a - (k-a-b) << endl;
	}
}




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


int main(void) {
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0;i < n;i++){
        cin >> p.at(i);
    }

    int count = 0;
    for(int i = 1;i < n-1;i++) {
        if(p.at(i) > p.at(i-1) && p.at(i) < p.at(i+1))count ++;
        if(p.at(i) < p.at(i-1) && p.at(i) > p.at(i+1))count ++;
    }
    cout << count << endl;

}


Measured memory_bytes: 256
n = int(input())
cards = [input().split() for i in range(n)]

p_taro = 0
p_hanako = 0

#Pythonでは辞書で後ろの方にある方が大きい扱い
# "a" < "b" = True

for i in range(n):
    if cards[i][0] > cards[i][1]:   #太郎が花子に勝った時
        p_taro += 3
    elif cards[i][0] < cards[i][1]:
        p_hanako += 3
    else:
        p_taro += 1
        p_hanako += 1
print(p_taro, p_hanako)



Measured memory_bytes: 5720
#include<cstdio>
#include <algorithm>
using namespace std;
 
int main(){
  int N,d,a,mini=200;
  scanf("%d",&N); 
  for (int i=0;i<N;i++){
   scanf("%d",&a);
    d=0;
    for(;a%2!=1;a/=2){
      d++;
    }
    mini=min(mini,d);
  }
  printf("%d\n",mini);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,m;
    cin>>n>>m;
    vector<int> a(n),cnt(n);
    int s,c;
    bool flag=true;
    rep(i,m){
        cin>>s>>c;
        if(cnt[s-1]!=0&&c!=a[s-1]) flag=false;
        a[s-1]=c;
        cnt[s-1]++;
    }
    if(cnt[0]!=0&&a[0]==0&&n!=1) flag=false;
    if(flag){
        if(a[0]==0&&n!=1) a[0]=1;
        rep(i,n) cout<<a[i];
    }
    else cout<<-1;
}

Measured memory_bytes: 3608
# 2020/02/11
# AtCoder Beginner Contest 103 - C

import math
import fractions

# Greatest Common Divisor(GCD)  
def gcd_fgf(a, b):
    return fractions.gcd(a, b)

# Least Common Multiple(LCM)
def lcm_fgf(a, b):
    return int(a * b // fractions.gcd(a, b))

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

# Calc Co-LCM
work_lcm = a[0]
for i in range(1, n):
    work_lcm = lcm_fgf(work_lcm, a[i])

m = work_lcm - 1

# Sum remains
fm = 0
for i in range(n):
    fm = fm + (m % a[i])

ans = fm    
# Output
print(ans)


Measured memory_bytes: 5344
# -*- coding: utf-8 -*-

import sys
from decimal import *

for line in sys.stdin:
    L = map(int, line.split(','))
    v1 = L.pop(10)
    v2 = L.pop(10)
    sum_L = sum(L)
    t = float(sum_L)*float(v1)/float(v1+v2)
    i = 0
    while t > 0:
        t -= L[i]
        i += 1
    print i

Measured memory_bytes: 7716
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;

    vector<long long> A(N+1);
    long long total=0;
    A[0]=0LL;
    for(int i=1; i<=N; ++i) {
        cin >> A[i];
        total+=A[i];
        A[i]+=A[i-1];
    }

    long long P,Q,R;
    long long ans=0;
    int i=1,j=i+1,k=j+1;
    while(true) {
        P=A[j-1]-A[i-1];
        Q=A[k-1]-A[j-1];
        R=total-P-Q;
        ans=max(ans,min({P,Q,R}));
        if(i==N-2) break;
        else if(R==min({P,Q,R})) {
            ++i;
            if(i==j) ++j;
            if(j==k) ++k;
        } else if(P<Q && k-j>1) {
            ++j;
        } else {
            ++k;
            if(k>N) break;
        }
    }    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int flag = 1;
		int count = 0;
		while (flag != 0) {
			for (int j = 0; j < n; j++) {
				if (a[j] % 2 == 0) {
					a[j] = a[j] / 2;
				} else {
					flag = 0;
				}
			}
			count ++;
		}

		System.out.println(count - 1);
	}
}


Measured memory_bytes: 21844
import math

n = int(input())

answer = (n - math.floor(n / 2)) / n

print(answer)

# nums = list(range(1, n + 1))
# 
# odds = [x for x in nums if x % 2 == 1]
# 
# if len(nums) % 2 == 0:
#     print(0.5)
# else:
#     print(len(odds) / len(nums))


Measured memory_bytes: 2940
#include<iostream>
#include<queue>

int main(){
    
    size_t n, m;
    std::cin >> n >> m;

    std::priority_queue<size_t> a;

    for(size_t i = 0; i < n; i++){
        size_t in;
        std::cin >> in;
        a.emplace(in);
    }

    for(size_t i = 0; i < m; i++){
        auto val = a.top(); a.pop();
        a.emplace(val / 2);
    }

    size_t ans = 0;

    for(size_t i = 0; i < n; i++){
        ans += a.top(); a.pop();
    }

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


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    string n; cin>>n;
    bool answer=false;
    rep(i,2) {
        if(n.at(i)==n.at(i+1)&&n.at(i+1)==n.at(i+2)) {
            answer=true;
        }
    }
    if(answer) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

template<const int L>
struct GaussJordan_Binary {
    vector<bitset<L + 1>> B;

    template<typename Int, class = typename std::enable_if<std::is_integral<Int>::value>>
    void buildMatrix(const vector<Int>& a) {
        B.resize(a.size());
        //for (int i = 0; i < (int)a.size()) {
        //    for (int b = 0; b < L; ++b) B[i][b] = a[i] >> b & 1;
        //}
        for (int i = 0; i < (int)a.size(); ++i) {
            B[i] = bitset<L + 1>(a[i]);
        }
    }

    void gauss_jordan() {
        int n = B.size();
        for (int i = 0, j = 0; i < n; ++i, ++j) {
            for (int k = 0; j < L; ++j) {
                for (k = i; k < n; ++k) if (B[k][j]) break;
                if (k == n) continue;
                else if (k != i) swap(B[i], B[k]);
                break;
            }
            if (j == L) break;

            for (int k = 0; k < n; ++k) if (k != i && B[k][j]) B[k] ^= B[i];
        }
    }
};

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll total = 0;
    rep(i, N) total ^= A[i];
    rep(i, N) A[i] &= ~total;

    GaussJordan_Binary<60> gj;
    gj.B.resize(N);
    rep(i, N) {
        rep(b, 60) {
            gj.B[i][60 - 1 - b] = A[i] >> b & 1;
        }
    }
    gj.gauss_jordan();

    ll ans = 0;
    rep(i, N) {
        if (gj.B[i].any()) {
            ll a = 0;
            rep(b, 60) a |= (ll)gj.B[i][60 - 1 - b] << b;
            ans ^= a;
        }
    }

    write(ans + (total ^ ans));
}

Measured memory_bytes: 1792
import heapq
import collections


class Graph:

    def __init__(self, size):
        self.size = size
        self.graph = [[] for i in range(size)]

    def add_edge(self, source, target, cost):
        self.graph[source].append((target, cost))

    def add_bidirectional_edge(self, source, target, cost):
        self.add_edge(source, target, cost)
        self.add_edge(target, source, cost)

    def min_dist_dijkstra(self, s):
        dist = [float('inf')] * self.size
        dist[s] = 0
        q = [(0, s)]
        while q:
            d, v = heapq.heappop(q)
            if dist[v] < d:
                continue
            for t, c in self.graph[v]:
                if dist[t] > dist[v] + c:
                    dist[t] = dist[v] + c
                    heapq.heappush(q, (dist[t], t))
        return dist

    def __str__(self):
        res = ''
        for i in range(self.size):
            res += str(i)
            for t, d in self.graph[i]:
                res += ' ' + str(t) + '(' + str(d) + ')'
            res += '\n'
        return res


def main():
    n, m, s, t = map(int, input().split())
    graph_a = Graph(n + 1)
    graph_b = Graph(n + 1)

    for i in range(m):
        u, v, a, b = map(int, input().split())
        graph_a.add_bidirectional_edge(u, v, a)
        graph_b.add_bidirectional_edge(u, v, b)
    cost_a = graph_a.min_dist_dijkstra(s)
    cost_b = graph_b.min_dist_dijkstra(t)

    min_costs = [(n + 1, float('inf'))]
    for i in range(n, 0, -1):
        cost = cost_a[i] + cost_b[i]
        if cost < min_costs[-1][1]:
            min_costs.append((i, cost))
    year = 0
    for i in range(n):
        while min_costs[-1][0] <= i:
            min_costs.pop()
        print(10**15 - min_costs[-1][1])


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef pair <ll, ll> pii;

const ll MAX_N = 1e5 + 5;
ll n, tmp, val;
ll Arr[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> Arr[i];

	sort(Arr, Arr + n);
	tmp = 0, val = -1;
	for (int i = 0; i + 1 < n; i++)
		if (val < min(Arr[i], Arr[n - 1] - Arr[i])) {
			val = min(Arr[i], Arr[n - 1] - Arr[i]);
			tmp = Arr[i];
		}

	cout << Arr[n - 1] << " " << tmp << "\n";
	return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    int n;
    cin>>n;
    VLL a(n);
    LL cnt=0;

    string ans;
    rep(i,n){
        cin>>a[i];
        if(a[i]%2!=0)
            cnt++;
    }
    if(cnt%2!=0)
        ans = "NO";
    else
        ans = "YES";
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&d[i])
	}

	s := make(map[int]struct{})
	for i := 0; i < n; i++ {
		s[d[i]] = struct{}{}
	}

	fmt.Println(len(s))
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 222222


ll mod_pow(ll x, ll y) {
  ll ret = 1;
  while (y > 0) {
	if (y & 1) ret = (x*ret) % mod;
	x = (x*x) % mod;
	y >>= 1;
  }
  return ret;
}

ll inv[MAX], sum[MAX];

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


  cin >> n;
  vll a(n + 1);
  rep(i, n) cin >> a[i + 1];
  ll fac = 1;
  FOR(i, 1, n + 1) (fac *= i) %= mod;
  FOR(i, 1, n + 1) inv[i] = mod_pow(i, mod - 2);
  sum[1] = 1;
  FOR(i, 2, n + 1) (sum[i] = sum[i - 1] + inv[i]) %= mod;
  FOR(i, 1, n + 1) {
	(tmp = sum[i] + sum[n - i + 1] - sum[1]) %= mod;
	(tmp *= fac) %= mod;
	(tmp *= a[i]) %= mod;
	(ans += tmp) %= mod;
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cctype>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cassert>
#include<cctype>
#include<cstring>
#include<utility>
#include<cmath>
const int inf=0x7fffffff;
typedef long long int ll;
using namespace std;
const bool test=0;
int n,w,h;
int const N=1000+10;
char A[N][N];
char V[N][N];
char s[N];
int _h,_w;
int mov[2][4]={
	0,0,-1,1,
	-1,1,0,0
};
void show(){
	if(test){
		for(int i=1;i<=_h;i++){
			for(int j=1;j<=_w;j++){
				printf("%2d",A[i][j]);
			}
			printf("\n");
		}

	}
}
const int H=0,W=1;
struct point{
	int h;
	int w;
	int cnt;
	point(int h=1,int w=1,int cnt=inf):h(h),w(w),cnt(cnt){}
};
int cor(char x,int i,int j){
	switch(x){
		case 'S':
			h=i;
			w=j;
			return 0;
			break;
		case 'X':
			return -1;
		case '.':
			return 0;
		default:
			return x-'0';
	}
}
int search(int goal){
	memset(V,0,sizeof(V));
	int cnt=0;
	queue<point> q;
	q.push(point(h,w,cnt));
	point p;
	if(test){cout<<"root"<<cnt<<' '<<h<<' '<<w<<endl;
		show();
	}
	while(q.size()){
		p=q.front();
		q.pop();
		h=p.h;
		w=p.w;
		cnt=p.cnt;
		if(V[h][w]!=0)continue;
		if(A[h][w]==goal){
			return cnt;
		}
		if(test)cout<<"q.size "<<q.size()<<" cnt "<<cnt<<' '<<h<<' '<<w<<' '<<(int)V[h][w]<<" goal "<<goal<<endl;
		for(int c=0;c<4;c++){
			int tmph=h+mov[H][c];
			int tmpw=w+mov[W][c];
			if(!V[tmph][tmpw]&&A[h][w]!=-1)q.push(point(tmph,tmpw,cnt+1));
		}
		V[h][w]=1;
	}
	assert(q.size());
}
void solve(){
	int sum=0;
	for(int i=1;i<=n;i++){
		sum+=search(i);
	}
	cout<<sum<<endl;
}
int main()
{
	scanf("%d%d%d", &h,&w,&n);
	_h=h;
	_w=w;
	memset(A,-1,sizeof(A));
	for(int i=1;i<=_h;i++){
		scanf("%s",s);
		for(int j=1;j<=_w;j++){
			A[i][j]=cor(s[j-1],i,j);
		}
	}
	show();
	solve();
	return 0;
}
////aoj0558.cc
////generated automatically at Fri Sep  9 18:27:24 2016
////by xsthunder

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

lint dsum(lint n, lint b = 10) {
  return n ? n % b + dsum(n / b) : 0;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  cout << (n % dsum(n) ? "No" : "Yes") << '\n';
  return 0;
}

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

main(){
  string s;
  while( cin >> s ){
    for ( int i = 0; i < s.size(); i++ ){
      if ( s[i] == '@' ){
	int v = s[i+1]-'0';
	char c = s[i+2];
	i += 2;
	for ( int j = 0; j < v; j++ ) cout << c;
      } else { cout << s[i]; }
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int X, Y, Z;
    cin >> X >> Y >> Z;
    swap(X, Y);
    swap(X, Z);
    cout << X << " " << Y << " " << Z;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
 
const int MAXN=2005;
 
int n,m,q;
int fV[MAXN][MAXN],fR[MAXN][MAXN],fC[MAXN][MAXN];
 
inline int calc(int f[MAXN][MAXN],int x1,int y1,int x2,int y2)
{return f[x2][y2]-f[x1-1][y2]-f[x2][y1-1]+f[x1-1][y1-1];}
 
int main()
{
	int i,j;scanf("%d%d%d",&n,&m,&q);
	for(i=1;i<=n;i++) for(j=1;j<=m;j++)
	{
		char c;do c=getchar();while(c!='0'&&c!='1');
		fV[i][j]= c=='1';
	}
	for(i=1;i<=n;i++) for(j=1;j<=m;j++)
		if(fV[i][j]) fR[i][j]+=fV[i+1][j],fC[i][j]+=fV[i][j+1];
	for(i=1;i<=n;i++) for(j=1;j<=m;j++)
		fV[i][j]+=fV[i][j-1],fR[i][j]+=fR[i][j-1],fC[i][j]+=fC[i][j-1];
	for(j=1;j<=m;j++) for(i=1;i<=n;i++)
		fV[i][j]+=fV[i-1][j],fR[i][j]+=fR[i-1][j],fC[i][j]+=fC[i-1][j];
	while(q--)
	{
		int x1,y1,x2,y2;scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int ans=calc(fV,x1,y1,x2,y2)-calc(fR,x1,y1,x2-1,y2)-calc(fC,x1,y1,x2,y2-1);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 48896