akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;

const int INF = 1 << 30;
struct edge {int to, cost; };
typedef pair<int, int> P;

vector<vector<edge>> graph;
vector<vector<int>> dist2d;

void dijkstra(int N, int s) {
	vector<int>& dist = dist2d[s];
	for (int i = 0; i < N; i++) dist[i] = INF;
	dist[s] = 0;

	priority_queue<P, vector<P>, greater<P>> queue;
	queue.push(P(0, s));
	while (!queue.empty()) {
		P p = queue.top(); // first=distance, second=node
		queue.pop();
		int node = p.second;
		if (dist[node] < p.first) continue; // Distance is fixed. No need to see.
		for (int i = 0; i < graph[node].size(); i++) {
			edge e = graph[node][i];
			if (dist[e.to] > dist[node] + e.cost) {
				dist[e.to] = dist[node] + e.cost;
				queue.push(P(dist[e.to], e.to)); // Next, see updated node
			}
		}
	}
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M), C(M);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i] >> C[i];
		A[i]--; // zero indexed
		B[i]--; // zero indexed
	}

	graph = vector<vector<edge>>(N);
	for (int i = 0; i < M; i++) {
		graph[A[i]].push_back((edge){B[i], C[i]});
		graph[B[i]].push_back((edge){A[i], C[i]});
	}

	dist2d = vector<vector<int>>(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		dijkstra(N ,i);
	}
	
	int ans = 0;
	for (int i = 0; i < M; i++) {
		if (C[i] > dist2d[A[i]][B[i]]) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, dd;
	cin >> nn;
	set<int64> memo;
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> dd;
		memo.insert(dd);
	}
	cout << memo.size() << endl;
	return 0;
}

Measured memory_bytes: 3584
#A
#入力
N=input()


#デバッグ用
def pront(*n):
    if debug==1:
        print(n)
        
debug=1#0:本番,1:デバッグ

#処理

t=0
for i in range(3):
    if N[i]=="7":
        t=1
        break
if t==0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9028
n = int(input())
a = list(map(int,input().split()))
cnt_1=0
cnt_2=0
cnt_4=0
for i in range(n):
  if a[i]%2 !=0:
    cnt_1 +=1 
  elif a[i]%4 !=0 :
    cnt_2 +=1
  else:
    cnt_4 +=1
    
if cnt_2==0:
  if cnt_4>=cnt_1-1:
    print("Yes")
  else:
    print("No")
else:
  if cnt_4>=cnt_1:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 14252
#include <stdio.h>

int main(void){
    int N,a;

    scanf("%d",&N);

    if(10000<=N && N<=99999)
    {
        a=N-10000+1;
        N=9+900+a;
    }
    else if(100<=N && N<=999)
    {
        a=N-100+1;
        N=9+a;
    }
    else if(1<=N && N<=9)
    {
        N=N;
    }
    else if(10<=N && N<=99)
    {
        N=9;
    }
    else if(1000<=N && N<=9999){
        N=909;
    }
    else if(N==100000)
        N=90909;

    printf("%d\n",N);

}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   string S;
   cin >> S;
   string T[2]={"",""};
   int Q;
   cin >> Q;
   int rev=0;
   for(int i=0;i<Q; i++){
      int q;
      cin >> q;
      if(q==1) rev=1-rev;
      else{
         int f; char c;
         cin >> f >> c;
         if(f==1){
            T[rev]+=c;
         }else{
            T[1-rev]+=c;
         }
      }
   }
   if(rev==0){
         reverse(T[0].begin(),T[0].end());
      cout << T[0]<<S<<T[1]<<endl;
   }
   else{
      reverse(S.begin(),S.end());
      reverse(T[1].begin(),T[1].end());
      cout << T[1] << S << T[0]<<endl;

   }


   return 0;
}


Measured memory_bytes: 1088
//---------- begin union_find ----------
#[allow(dead_code)]
mod union_find {
    pub struct UF {
        p: Vec<i32>,
    }
    impl UF {
        pub fn new(n: usize) -> UF {
            UF {p: vec![-1; n] }
        }
        pub fn init(&mut self) {
            for p in self.p.iter_mut() {
                *p = -1;
            }
        }
        pub fn root(&mut self, mut x: usize) -> usize {
            while self.p[x] >= 0 {
                x = self.p[x] as usize;
            }
            x
        }
        pub fn same(&mut self, x: usize, y: usize) -> bool {
            self.root(x) == self.root(y)
        }
        pub fn unite(&mut self, mut x: usize, mut y: usize) -> Option<(usize, usize)>{
            x = self.root(x);
            y = self.root(y);
            if x == y {
                return None;
            }
            if self.p[x] > self.p[y] {
                let s = x;
                x = y;
                y = s;
            }
            self.p[x] += self.p[y];
            self.p[y] = x as i32;
            Some((x, y))
        }
        pub fn get_size(&mut self, x: usize) -> usize {
            let r = self.root(x);
            (-self.p[r]) as usize
        }
    }
}
//---------- end union_find ----------
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let m = 100_000;
    let mut u = union_find::UF::new(2 * m);
    let mut cnt = vec![(1, 0); 2 * m];
    for p in &mut cnt[m..] {
        *p = (0, 1);
    }
    for _ in 0..n {
        let x = it.next().unwrap().parse::<usize>().unwrap() - 1;
        let y = it.next().unwrap().parse::<usize>().unwrap() - 1 + m;
        if let Some((a, b)) = u.unite(x, y) {
            cnt[a].0 += cnt[b].0;
            cnt[a].1 += cnt[b].1;
            cnt[b] = (0, 0);
        }
    }
    let ans = cnt.iter().fold(0, |s, p| s + p.0 * p.1) - n;
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 10492
#include<iostream>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;
static const int MAX_A = 2 * MAX_N - 1;

int N, a[2 * MAX_N - 1];

bool def(bool b[]){
	int s = 0, t = 0;
	while(N - s - 1 > 0 && b[N - s - 1] != b[N - s - 2]) s++;
	while(t + N - 1 < 2 * N - 1 && b[N + t - 1] != b[N + t]) t++;
	if(min(s, t) >= N - 1) return ((N % 2) ? b[N - 1] : !b[N - 1]);
	else if(t < s) return b[t + N - 1];
	else return b[N - s - 1];
}

int main(){
	cin >> N;
	for(int i = 0; i < 2 * N - 1; i++) cin >> a[i];
	
	int lb = -1, ub = MAX_A + 1;
	while(ub - lb > 1){
		int mid = lb + (ub - lb) / 2;
		bool b[2 * MAX_N - 1];
		for(int i = 0; i < 2 * N - 1; i++){
			if(a[i] >= mid) b[i] = true;
			else b[i] = false;
		}
		if(def(b)) lb = mid;
		else ub = mid;
	}
	cout << lb << endl;
	return 0;
}


Measured memory_bytes: 1280
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n = str.length();
        
        int count = 0;
        int left = 0;
        int right = n - 1;
        while (true) {
            char ca = str.charAt(left);
            char cb = str.charAt(right);
            
            if (ca == cb) {
                left++;
                right--;
            } else if (ca == 'x') {
                count++;
                left++;
            } else if (cb == 'x') {
                count++;
                right--;
            } else {
                System.out.println(-1);
                return;
            }
            
            if (left > right) {
                break;
            }
        }
        System.out.println(count);
    }
}


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

int main(){
    int n, m; cin >> n >> m;
    vector<int> v[m], p(m);
    for (int i = 0; i < m; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int c; cin >> c; c--;
            v[i].emplace_back(c);
        }
    }
    for (int i = 0; i < m; i++) cin >> p[i];
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        bool ok = true;
        for (int u = 0; u < m; u++) {
            int cnt = 0;
            for (int w = 0; w < v[u].size(); w++) {
                if (i & (1 << v[u][w])) cnt++;
            }
            if (p[u] % 2 != cnt % 2) ok = false;
        }
        if (ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <stack>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

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

void solve() {
	ll n, m; cin >> n >> m;
	vector<ll> v(n);
	for (auto &i : v)cin >> i, i /= 2;
	ll cur = 1;
	for (auto i : v)cur = lcm(cur, i);
	for (auto i : v) {
		if ((cur / i) % 2 == 0) {
			cout << 0; return ;
		}
	}

	cout << (m / cur / 2) + (m / cur) % 2 << endl;



}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 3996
import java.util.Scanner;

public class Main {

	public static String[] bubbleSort(String[] a, int num) {
		String[] b = new String[num];
		String temp;

		for(int i = 0; i < num; i++) {
			b[i] = a[i];
		}

		for(int i = 0; i < num - 1; i++) {
			for(int j = num - 1; j >= i + 1; j--) {
				if(b[j-1].charAt(1) > b[j].charAt(1)) {
					temp = b[j-1];
					b[j-1] = b[j];
					b[j] = temp;
				}
			}
		}

		return b;
	}

	public static String[] selectionSort(String[] a, int num) {
		String[]	c = new String[num];
		int minIndex = 0;
		String temp;

		for(int i = 0; i < num; i++) {
			c[i] = a[i];
		}

		for(int i = 0; i < num; i++) {
			minIndex = i;
			for(int j = i; j < num; j++){
				if(c[j].charAt(1) < c[minIndex].charAt(1)) {
					minIndex = j;
				}
			}
			temp = c[i];
			c[i] = c[minIndex];
			c[minIndex] = temp;
		}


		return c;
	}

	public static boolean isStable(String[] b, String[] c, int num) {

		for(int i = 0; i < num; i++) {
			if(!b[i].equals(c[i])){
				return false;
			}
		}

		return true;
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String[] a = new String[36];
		int num = scan.nextInt();
		for (int i = 0; i < num; i++) {
			a[i] = scan.next();
		}

		String[] b = bubbleSort(a, num);
		String[] c = selectionSort(a, num);

		for(int i = 0; i < num; i++) {
			if (i != 0) {
				System.out.print(" ");
			}
			System.out.print(b[i]);
		}
		System.out.println("");
		System.out.println("Stable");

		for(int i = 0; i < num; i++) {
			if (i != 0) {
				System.out.print(" ");
			}
			System.out.print(c[i]);
		}
		System.out.println("");
		if(isStable(b, c, num)) {
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}






	}
}


Measured memory_bytes: 26336
N = int(input())
a = list(map(int,input().split()))
ans = 0
while True:
  if sum(a) == 0:
    print(ans)
    exit()
  for i in range(N):
    if a[i]%2 == 0:
      a[i] //= 2
    else:
      print(ans)
      exit()
  ans += 1

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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (i == (N - 1)) {
      cout << "Three" << endl;
    }
  }
  
}


Measured memory_bytes: 3552
#include <iostream>
#include <math.h>
#define llong long long 

using namespace std;

int main(void){
    
    
    llong N = 0;
 //   static llong Power_Old = 1;
    static llong Power_now = 1;
    static llong ans = 0;
 //   llong Temp_a = 0;
 //   llong Temp_b = 0;
    cin >> N;
    
    for ( int i = 1; i <= N; i++){
        
        Power_now = (Power_now % 1000000007)* i;
        
  //      Temp_a = Power_now / 1000000007;
  //      Temp_b = Power_now % 1000000007;
   //     Power_Old = Power_now;
        
     //   cout<<Power_now<<endl;
    }
    
    
    ans = Power_now % 1000000007;
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = 1LL << 60;//numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g;
vector<edge>ed;
vector<Pll>pv;
set<LL>st;
map<Pll, LL>ma;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
string str, ss;
bool f;
LL n, m, s, t, h, w, a[6010],sub[6010];
LL dp1[6010][6010], dp2[6010][6010], to1[6010], to2[6010];
void dfs(int cur, int par) {
	sub[cur] = 1;
	rep(i, 6000)dp1[cur][i] = INF, dp2[cur][i] = INF;
	if (a[cur] > 0)
		dp1[cur][0] = a[cur];
	else
		dp2[cur][0] = a[cur];
	rep(i, g[cur].size()) {
		LL v = g[cur][i];
		if (v == par)continue;
		dfs(v, cur);
		
		rep(i, 6000)to1[i] = INF, to2[i] = INF;
		for (int i = 0; i < sub[cur]; i++) {
			for (int j = 0; j < sub[v]; j++) {
				if (dp2[v][j] < 0 || dp1[v][j] < INF) {
					to1[i + j + 1] = min(to1[i + j + 1], dp1[cur][i]);
					to2[i + j + 1] = min(to2[i + j + 1], dp2[cur][i]);
				}
				to1[i + j] = min(to1[i + j], dp1[cur][i] + dp1[v][j]);
				to2[i + j] = min({ to2[i + j], dp1[cur][i] + dp1[v][j] ,
					dp2[cur][i] + dp1[v][j] ,dp1[cur][i] + dp2[v][j],dp2[cur][i] + dp2[v][j] });
			}
		}
		rep(i, 6000)dp1[cur][i] = to1[i], dp2[cur][i] = to2[i];
		sub[cur] += sub[v];
	}
}
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	g.resize(n);
	rep(i, n - 1) {
		LL x, y;
		cin >> x >> y;
		x--, y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(0, -1);
	rep(i, n+1) {
		if (dp1[0][i] < INF) {
			cout << i << endl;
			return 0;
		}
		if (dp2[0][i] < 0) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 474496
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
signed main()
{
    fast;
    ll n,m,i;
    cin>>n>>m;
    vvpi arr(n+1);
    for(ll i=2;i<=n;i++)
        arr[i].pb(mp(i-1,0));
    for(i=0;i<m;i++)
    {
        ll l,r,c;
        cin>>l>>r>>c;
        arr[l].pb(mp(r,c));
    }
    multiset < pii > lol;
    lol.insert(mp(0,1));
    ll dist[n+1];
    for(i=1;i<=n;i++)
        dist[i] = 1e18;
    while(!lol.empty())
    {
        pii temp = *lol.begin();
        lol.erase(lol.begin());
        if(dist[temp.sec]<=temp.fi)
            continue;
        dist[temp.sec] = temp.fi;
        for(auto v:arr[temp.sec])
        {
            ll x = temp.fi+v.sec;
            if(dist[v.fi]>x)
                lol.insert(mp(x,v.fi));
        }
    }
    if(dist[n]==1e18)
        dist[n] = -1;
    cout<<dist[n];
    
}


Measured memory_bytes: 12800
import math
N,D = map(int,input().split())
X = []
for i in range(N):
  X.append(list(map(int,input().split())))
ans = 0
for i in range(N):
  for j in range(i+1,N):
    now = 0
    dis = 0
    for k in range(D):
      now += (X[i][k]-X[j][k])**2
    dis = math.sqrt(now)
    if dis%1 == 0:
      ans += 1
print(ans)

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


int main()
{
	long x, y;

	cin >> x >> y;
	if (x < y) swap(x, y);

	int r = x % y;
	while (r != 0)
	{
		x = y;
		y = r;
		r = x % y;
	}

	cout << y << endl;

    return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>
#define N 100

int main(void){
  
  int i,j,n,tmp,cntr=0;
  int A[N];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(A[j]<A[j-1]){
	tmp = A[j];
	A[j] = A[j-1];
	A[j-1] = tmp;
	cntr++;
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1) printf(" ");
    
  }
  printf("\n");
  printf("%d\n",cntr);
  
  return 0;
  
}
  

Measured memory_bytes: 604
from collections import deque

def main():
	q = int(input())
	a = deque()
	for _ in range(q):
		query = list(map(int,input().split()))
		if query[0] == 0:
			if query[1] == 0:
				a.appendleft(query[2])
			else:
				a.append(query[2])
		elif query[0] == 1:
			print(a[query[1]])
		elif query[1] == 0:
			a.popleft()
		else:
			a.pop()

main()


Measured memory_bytes: 21980
using System;
public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var sfrom = "Hoshino";
        var sto = "Hoshina";
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine();
            var ans = s.Replace(sfrom, sto);
            Console.WriteLine(ans);
        }
    }
}

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

void chmin(int& a, int b) {
  if (a > b) a = b;
}

int main() {
  string S, T;
  cin >> S >> T;
  
  int ans = 1000;
  for (int i = 0; i < S.size()-T.size()+1; i++) {
    int sum = 0;
    for (int j = 0; j < T.size(); j++) {
      if (S[i+j] != T[j]) sum++;
    }
    
    chmin(ans, sum);
  }
  
  cout << ans << endl;
}

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

#define turn(x1,y1,x2,y2,x3,y3) x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)
int hantei(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy);
int main()
{
	int i;
	double xy[8];
	int ans;
	char a;
	
	for(;cin >> xy[0];)
	{
		for(i=1;i<8;i++)
			cin >> xy[i] ;
		
		ans=1;
		
		if(hantei(xy[0],xy[1],xy[2],xy[3],xy[4],xy[5],xy[6],xy[7])==0)
			ans=0;
		
		if(ans==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
}

int hantei(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy)
{
	if((
		turn(ax,ay,bx,by,cx,cy)>0.0 &&
		turn(dx,dy,ax,ay,bx,by)>0.0 &&
		turn(dx,dy,bx,by,cx,cy)>0.0 &&
		turn(dx,dy,cx,cy,ax,ay)>0.0)
		||(
		turn(ax,ay,bx,by,cx,cy)<0.0 &&
		turn(dx,dy,ax,ay,bx,by)<0.0 &&
		turn(dx,dy,bx,by,cx,cy)<0.0 &&
		turn(dx,dy,cx,cy,ax,ay)<0.0)
	)
		return 1;
	else
		return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int int_vector_find(std::vector<int> vec, int num) {
	auto itr = std::find(vec.begin(), vec.end(), num);
	int index = std::distance(vec.begin(), itr);

	if (index != vec.size()) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {
	std::vector<int> vec;
	int n;
	std::cin >> n;
	int ans = 1;

	for (int i = 0; i < n; ++i) {
		int a;
		std::cin >> a;
		vec.push_back(a);
	}

	for (int i = 1; i < n; ++i) {
		bool hoge = true;
		for (int j = 0; j < i; ++j) {
			if (vec[j] > vec[i]) {
				hoge = false;
			}
		}
		if (hoge) {
			ans++;
		}
	}

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
int dp[10000001];

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  dp[1] = 1;
  for(int i = 2; i <= n; i++){
    if(dp[i - 1] * (dp[i - 1] + 1) == 2 * (i - 1))dp[i] = dp[i - 1] + 1;
    else dp[i] = dp[i - 1];
  }
  int curr = n;
  while(curr){
    cout << dp[curr] << endl;
    curr = curr - dp[curr];
  }
	return 0;
}


Measured memory_bytes: 39296
import java.util.*;

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 X = sc.nextInt();

        int res = 0;
        for (int a=0; a<=A; a++) {
            for (int b=0; b<=B; b++) {
                int c = (X - a * 500 - b * 100) / 50;
                if (c >= 0 && c <= C) {
                    res++;
                }
            }
        }

        System.out.println(res);
    }
}

Measured memory_bytes: 23380
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double[] p = new double[n];
		for(int i=0; i<n; i++){
			p[i] = sc.nextDouble();
		}
		double[][] dp = new double[n+1][n+1];
		dp[0][0] = 1;
		for(int i=1; i<n+1; i++){
			for(int j=0; j<i+1; j++){
				if(j == 0){
					dp[i][j] = dp[i-1][j] * (1 - p[i-1]);
				}
				else{
					dp[i][j] = dp[i-1][j-1] * p[i-1] + dp[i-1][j] * (1 - p[i-1]);
				}
			}
		}
		double ans = 0;
		for(int i=n/2+1; i<n+1; i++){
			ans += dp[n][i];
		}
		System.out.println(ans);
	}
}

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

int main () {
  int N, X;
  int w = 0;
  int min = 1<<30;
  cin >> N >> X;
  for (int i=0; i < N; ++i) {
    int m;
    cin >> m;
    w += m;
    if (m < min) {
      min = m;
    }
  }
  cout << N + (X - w) / min << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[] checkAry = { 0, 0, 0 }; // a,b,c
		Scanner sc = new Scanner(System.in);
		String abc = sc.next();
		for (int i = 0; i < abc.length(); i++) {
			char c = abc.charAt(i);
			switch (c) {
			case 'a':
				checkAry[0] += 1;
				break;
			case 'b':
				checkAry[1] += 1;
				break;
			case 'c':
				checkAry[2] += 1;
				break;
			}
		}
		int tmp = 0;
		for (int i = 0; i < abc.length(); i++) {
			if(checkAry[i]==0) {
				break;
			}
			tmp++;
		}
		String answer = tmp == 3 ? "Yes" : "No";
		System.out.print(answer);
	}
}


Measured memory_bytes: 23764
n = int(input())
a = list(map(int, input().split()))
mx = max(a)
a[a.index(mx)] = abs(mx)
evn = sum(max(0, i) for i in a[::2])
odd = sum(max(0, i) for i in a[1::2])
if mx < 0:
    print(mx)
else:
    print(max(evn, odd))
oe = int(evn < odd)
res = []
beg = 0
while beg%2!=oe or a[beg]<0:
    res.append(1)
    beg += 1
end = n-1
while end%2!=oe or a[end]<0:
    res.append(end-beg+1)
    end -= 1
while beg < end:
    if a[end-2] < 0:
        res.append(end-beg-1)
    else:
        res.append(end-beg)
    end -= 2
print(len(res))
for i in res:
    print(i)

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

    int re, di;
    String s;
    int[] len;
    int i, j, k;

    void run(){
	re = 0;
	di = 0;
	while(sc.hasNext()){
	    s = sc.next();
	    len = new int[3];
	    j = 0;
	    k = 0;
	    for(i=0; i<3 && k<s.length(); i++){
		while(j<s.length() && !s.substring(j, j+1).equals(",")) j++;
		//System.out.println("*"+j+" "+k);
		len[i] = Integer.parseInt(s.substring(k, j));
		k = j+1;
		j++;
		//System.out.print(len[i]+" ");
	    }
	    //System.out.println();
	
	    check();
	}
	System.out.println(re);
	System.out.println(di);
    }

    void check(){
	// 辺1, 辺2, 対角線
	if(len[0]==len[1]) di++;
	if(len[0]*len[0]+len[1]*len[1] == len[2]*len[2]) re++;
    }
}

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

int main(){
  int n; cin>>n;
  vector<ll> num(n),sum(n,0);
  cin>>num[0];
  for(int i=1;i<n;i++){
    cin>>num[i];
  }
  sort(num.begin(),num.end());
  for(int i=0;i<n;i++){
    if(i==0) sum[i]=num[i];
    else sum[i]=sum[i-1]+num[i];
  }
  int ans=1;
  for(int i=n-2;i>=0;i--){
    if(sum[i]*2>=num[i+1]) ans++;
    else break;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 10000000
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func powMod(a, n int) int {
	if n < 0 {
		log.Fatal("pow error")
	}
	if n == 0 {
		return 1
	}
	if n%2 == 0 {
		d := powMod(a, n/2) % mod
		return d * d % mod
	}
	return a * powMod(a, n-1) % mod
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

type key struct {
	Positive bool
	First    int
	Second   int
}

func toPositive(a, b int) (int, int, bool) {
	if a == 0 && b == 0 {
		return a, b, true
	}
	if a == 0 {
		if b > 0 {
			return a, b, true
		}
		return a, -b, false
	}

	if b == 0 {
		if a > 0 {
			return a, b, true
		}
		return -a, b, false
	}

	if a > 0 && b > 0 {
		return a, b, true
	}
	if a > 0 && b < 0 {
		return a, -b, false
	}
	if a < 0 && b > 0 {
		return -a, b, false
	}
	if a < 0 && b < 0 {
		return -a, -b, true
	}
	log.Fatal("positive error")
	return 0, 0, true
}

const mod = 1000000007

func main() {
	n := nextInt()
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		b[i] = nextInt()
	}
	count := make(map[key]int)
	twoZeroes, zeroOne, oneZero := 0, 0, 0
	for i := 0; i < n; i++ {
		var val key
		if a[i] == 0 && b[i] == 0 {
			twoZeroes++
		} else if a[i] == 0 {
			zeroOne++
		} else if b[i] == 0 {
			oneZero++
		} else {
			pa, pb, pos := toPositive(a[i], b[i])
			g := gcd(pa, pb)
			val = key{pos, pa / g, pb / g}
			count[val]++
		}
	}

	ans := (powMod(2, zeroOne) + powMod(2, oneZero) - 1 + mod) % mod
	used := make(map[key]bool)
	for k, cnt := range count {
		if used[k] {
			continue
		}

		pair := key{!k.Positive, k.Second, k.First}
		ans *= (powMod(2, cnt) + powMod(2, count[pair]) - 1 + mod) % mod
		ans %= mod
		used[pair] = true
	}
	ans += twoZeroes % mod
	ans--
	ans = (ans + mod) % mod
	fmt.Println(ans)
}


Measured memory_bytes: 39188
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y;
	cin >> x >> y;
	cout << x + y / 2 << endl;
	return 0;
}



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

int main(){
	int n[4]={0,0,0,0},i;
	std::string s;

	while (std::cin>>s){
		s = s.substr(s.find(",")+1);
		n[(s=="A")?0:(s=="B")?1:(s=="O")?3:2]++;
	}
	for (i=0; i<4; i++) std::cout<<n[i]<<std::endl;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<ll> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  sort(all(A));
  reverse(all(A));
  ll ans=0;
  priority_queue<int> pq;
  pq.push(A.at(0));
  for(int i=1;i<N;i++){
    ans+=pq.top();
    pq.pop();
    pq.push(A.at(i));
    pq.push(A.at(i));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5820
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <string.h>
#include <cmath>
using namespace std;
typedef pair<int,int> P;

struct fence{
  int u,v;
  double cost;
};

#define N 10000

int par[N];
int urank[N];

void init(int n){
  for(int i=0;i<n;i++){
    par[i] = i;
    urank[i] = 0;
  }
}
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}
void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x==y)return;

  if(urank[x]<urank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(urank[x]==urank[y])urank[x]++;
  }
}
bool same(int x,int y){
  return find(x)==find(y);
}

double distance(int x1,int y1,int x2,int y2){
  return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

bool cmp(const fence &a,const fence &b){
  return a.cost > b.cost;
}

int main(){
  int n,m;
  P piles[N];
  vector<fence> fences;

  scanf("%d%d",&n,&m);
  for(int i=0;i<n;i++){
    int x,y;
    scanf("%d%d",&x,&y);
    piles[i] = P(x,y);
  }
  for(int i=0;i<m;i++){
    int p,q;
    scanf("%d%d",&p,&q);
    p--;q--;
    double c = distance(piles[p].first,piles[p].second,piles[q].first,piles[q].second);
    fences.push_back((fence){p,q,c});
  }

  double sum = 0;
  init(n);
  sort(fences.begin(),fences.end(),cmp);
  for(int i=0;i<m;i++){
    int u = fences[i].u;
    int v = fences[i].v;
    if(same(u,v)){
      sum += fences[i].cost;
    }else{
      unite(u,v);
    }
  }

  printf("%.3f\n",sum);


  return 0;
}

Measured memory_bytes: 1876
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    vector<ll> recon(n+1);
    ll ma = -1e10;
    ll pos = 0;

    vector<ll> dp(n+1);
    for(int i = 1; i <= n; i++)
    {
        dp[i] = a[i];
        for(int x = 1; x < i; x++)
        {
            if((i-x)%2 == 0)
            {
                if(dp[x] + a[i] > dp[i])
                {
                    dp[i] = dp[x] + a[i];
                    recon[i] = x;
                }
            }
        }
        if(ma < dp[i])
        {
            ma = dp[i];
            pos = i;
        }
    }

    vector<int> ans;
    int i;
    for(i = n; i > pos; i--)
    {
        ans.push_back(i);
    }
    while(recon[i] > 0)
    {
        int j = i;
        while(recon[i] < j)
        {
            ans.push_back((j + recon[i]) / 2);
            j -= 2;
        }
        i = j;
    }
    for(int j = 1; j < i; j++)
    {
        ans.push_back(1);
    }

    cout << ma << endl;
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 256
X, K, D = map(int, input().split())

p = abs(X) // D
if (p >= K):
    print(abs(abs(X) - (K * D)))
else:
    re = K - p
    if (re % 2 == 0):
        print(abs(abs(X) - (D * p)))
    else:
        print(abs(abs(X) - (D * (p + 1))))


Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

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

    int a = N/1000;
    int b = N/100 % 10;
    int c = N/10 % 10;;
    int d = N%10;

    if(a+b+c+d == 7){
        cout << a <<  '+' << b << '+' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }

    if(a+b+c-d == 7){
        cout << a <<  '+' << b << '+' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }

    if(a+b-c+d == 7){
        cout << a <<  '+' << b << '-' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }

    if(a-b+c+d == 7){
        cout << a <<  '-' << b << '+' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }

    if(a+b-c-d == 7){
        cout << a <<  '+' << b << '-' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }

    if(a-b-c+d == 7){
        cout << a <<  '-' << b << '-' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }

    if(a-b+c-d == 7){
        cout << a <<  '-' << b << '+' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }

    if(a-b-c-d == 7){
        cout << a <<  '-' << b << '-' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    use itertools_num::ItertoolsNum as _;
    input! {
       N: usize,
    }

    let mut ans = vec![0; N + 1];
    for x in 1..100 {
        for y in 1..100 {
            for z in 1..100 {
                let n = x * x + y * y + z * z + x * y + y * z + z * x;
                if n <= N {
                    ans[n] += 1;
                }
            }
        }
    }
    echo!(ans.iter().skip(1).toVec().joinToString("\n"));
}


Measured memory_bytes: 2864
using System;
using System.IO;
using System.Linq;

namespace ABC107
{
    class C
    {
        static void Main(string[] args)
        {

            //StreamReader sr = new StreamReader(@"./testcase/in/testcase");

            //long[] input = sr.ReadLine().Split().Select(long.Parse).ToArray();
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = input[0];
            long K = input[1];

            //long[] x = sr.ReadLine().Split().Select(long.Parse).ToArray();
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();

            long[] Res = new long[N - K + 1];
            for (long i = 0; i < N - K + 1; i++)
            {
                Res[i] = Math.Min(Math.Abs(x[i]) + Math.Abs(x[i + K - 1] - x[i]), Math.Abs(x[i + K - 1]) + Math.Abs(x[i + K - 1] - x[i]));
            }

            Console.WriteLine(Res.Min());
        }
    }
}


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

#define INF (INT_MAX/2)
#define PI (2*acos(0.0))
#define EPS (1e-8)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cst;
  Edge(int s, int d, Cost c) : src(s), dst(d), cst(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

vector<Cost> dijkstra(const Graph &g, int s) {
  const Cost inf = numeric_limits<Cost>::max() / 2;
  typedef tuple<Cost, int> State;
  priority_queue<State> q;
  vector<Cost> dist(g.size(), inf);
  dist[s] = 0; q.emplace(0, s);
  while (q.size()) {
    Cost c; int v;
    tie(c, v) = q.top(); q.pop(); c *= -1;
    if (dist[v] < c) continue;
    for (auto & e : g[v]) {
      if (dist[e.dst] > dist[v] + e.cst) {
        dist[e.dst] = dist[v] + e.cst;
        q.emplace(-dist[e.dst], e.dst);
      }
    }
  }
  return dist;
}

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int v, e, r;
  int s, t, d;
  
  cin >> v >> e >> r;
  
  Graph g(v);
  for (int i = 0; i < e; i++) {
    cin >> s >> t >> d;
    g[s].push_back(Edge(s, t, d));
  }

  vector<Cost> c = dijkstra(g, r);
  for (int i = 0; i < (int)c.size(); i++) {
    if (c[i] == numeric_limits<Cost>::max() / 2) cout << "INF" << endl;
    else cout << c[i] << endl;
  }
  return 0; 
}

Measured memory_bytes: 15368
package main

import (
	"fmt"
)

func main() {
	var n int
	var k int
	fmt.Scan(&n,&k)
	ans := 1
	for i:= 0; i<n; i++ {
		if ans*2 <= ans+k {
			ans = ans*2
		} else {
			ans += k
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int k,s;
    cin>>k>>s;
    int cnt=0;
    rep(i,k+1){
        rep(j,k+1){
            if(range(s-i-j,0,k+1)) cnt++;
        }
    }
    cout<<cnt<<endl;
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
 
int main(){
  while(true){
    int n,k;
    scanf("%d %d",&n,&k);
    if(n==0&&k==0) return 0;
    int a[n];
    for(int i=0;i<n;i++) scanf("%d",a+i);
    int sum = 0,ans = 0;
    for(int i=0;i+k<=n;i++){
      if(i==0){
        for(int j=0;j<k;j++) sum += a[i+j];
        ans = sum;
      }else{
        sum = sum - a[i-1] + a[i+k-1];
        ans = max(ans,sum);
      }
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

vector<vi> G;
list<int> out;
vector<bool> visited;
vi indeg;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

void bfs(int s) {
  queue<int> q;
  q.push(s);
  visited[s] = true;
  while (!q.empty()) {
    auto u = q.front();
    q.pop();
    out.push_back(u);
    for (auto &&v : G[u]) {
      indeg[v]--;
      if (indeg[v] == 0 && !visited[v]) {
        visited[v] = true;
        q.push(v);
      }
    }
  }
}

void tsort() {
  auto n = G.size();
  for (auto &&uv : G) {
    for (auto &&v : uv) indeg[v]++;
  }
  REP(u, n) if (indeg[u] == 0 && !visited[u]) bfs(u);
  for (auto it = out.begin(); it != out.end(); it++) {
    cout << *it << endl;
  }
}

int main() {
  int n, m, s, t;
  cin >> n >> m;
  G.resize(n);
  visited.resize(n, false);
  indeg.resize(n);
  REP(i, m) {
    cin >> s >> t;
    G[s].push_back(t);
  }
  tsort();
}


Measured memory_bytes: 3816
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 
 using namespace std;

 int main()
 {
   int n;
   while(cin>>n)
   {
     if((n/10)==9||(n%10)==9) cout<<"Yes"<<endl;
     else cout<<"No"<<endl;             
   }
   return 0;    
 }
 
 

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

int main() {
  long M;
  long cD, cR, rD, rR, D, R;
  cin >> M >> rD >> rR >> cD >> cR;

  D = cD * 100 / rD;
  if(((cD * 100) % rD) != 0)
    D += 1;
  R = cR * 100 / rR;
  if(((cR * 100) % rR) != 0)
    R += 1;

  M = M - D - R;
  if(M < 0)
    cout << -1 << endl;
  else
    cout << M << endl;
  return 0;
}



Measured memory_bytes: 3100
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N-x+1):
        z = N-x-y
        if 0 <= z <= 2000 and 10000*x+5000*y+1000*z == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


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

    ll A;
    ll x;
    ll y;
    ll m[N + 1][N + 1];
    REP(i, N){
        REP(j, N){
            m[i][j] = -1;
        }
    }
    REP(i, N){
        cin >> A;
        rep(j, A){
            cin >> x >> y;
            m[i][x] = y;
        }
    }

    ll ans = 0;
    for(ll bit = 0; bit < (1<<N); bit++){
        ll skip = 0;
        REP(speaker, N){
            if((bit & (1<<(speaker - 1))) > 0){
                REP(target, N){
                    if(m[speaker][target] != -1 && ((bit>>(target - 1)) & 1) != m[speaker][target]){
                        skip = 1;
                        break;
                    }
                }
            }
            if(skip > 0){
                break;
            }
        }
        if(skip > 0){
            continue;
        }
        ll count = 0;
        rep(i, N){
            if((bit & (1<<i)) > 0){
                count++;
            }
        }
        if(ans < count){
            ans = count;
        }
    }

    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
	int x,y,a,b,c;
	cin >>x>>y>>a>>b>>c;
	int p[a+1],q[b+1],r[c+1];
	p[0]=0;
	q[0]=0;
	r[0]=0;
	rep(i,a)cin>>p[i+1];
	rep(i,b)cin>>q[i+1];
	rep(i,c)cin>>r[i+1];
	sort(p,p+a+1);
	sort(q,q+b+1);
	sort(r,r+c+1);
	int red=0,g=0,m=0;
	int color;//0赤1緑2無色
	int good;//良さ
	long long int sum=0;
	while(red+g+m<x+y)
	{	
		color=2;
		good=r[c-m];
		if(red<x&& p[a-red]>good){
			color=0;
			good=p[a-red];
		}
		if(g<y&& q[b-g]>good){
			color=1;
			good=q[b-g];
		}
		sum+=good;
		if(color==0)red++;
		if(color==1)g++;
		if(color==2)m++;
	}
	cout <<sum;
}

Measured memory_bytes: 4692