akhauriyash/Code-Regression huggingface dataset:
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    a,b,c,d = map(int,input().split())
    print(max(a*b,c*d))
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38636
'''
????????£????????????1??????????????????
??\???C++??§????????????????§£?±???????????????????????????????????????§???
??????python??§??????????????????Accept??§??????????????????
????????£??¨optimization??????????????§??????
??§????????????Wrong Answer??§?????????
???????????????????????????????????????????????????
Online Judge???????????????Public Solutions??§
????????????nanae?????????python3????????????????????????
????????£??¨?????????????????????
???????????????????????????0.06?§????????????§??????
'''

import queue
v,e,s=map(int,input().split())
edge=[]
inf =1000000100
for i in range(v):
    edge.append([])

for i in range(e):
    vs,vt,d=map(int,input().split())
    edge[vs].append((vt,d))
    
dis=[]
for i in range(v):
    dis.append(inf)

dis[s]=0

q = queue.PriorityQueue()
q.put((0,s))


while(not q.empty()):
    now=q.get()
    nowv=now[1]
    for (vt,d) in edge[nowv]:
        if dis[vt]>dis[nowv]+d:
            dis[vt]=dis[nowv]+d
            q.put((dis[vt],vt))
'''

finished=0
while(finished<v and not q.empty()):
    now=q.get()
    nowv=now[1]
    if now[0]>dis[nowv]: continue
    for (vt,d) in edge[nowv]:
        if dis[vt]>dis[nowv]+d:
            dis[vt]=dis[nowv]+d
            q.put((dis[vt],vt))
    finished+=1       '''

for i in range(v):
    if dis[i]>=inf:
        print("INF")
    else:
        print(dis[i])

Measured memory_bytes: 90452
package main

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

var sc = bufio.NewScanner(os.Stdin)
var foothold []string

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

func updateCost(loc int) {
	if loc == 0 {
		return
	}
	if loc == 1 {
		cost[loc] = cost[loc-1] + Abs(h[loc]-h[loc-1])
		return
	}
	cost[loc] = Min(cost[loc-1]+Abs(h[loc]-h[loc-1]), cost[loc-2]+Abs(h[loc]-h[loc-2]))
	return
}

var N int
var h []int
var cost []int

func main() {
	N = nextInt()
	h = nextInts(N)
	cost = make([]int, N)
	for i := 0; i < len(cost); i++ {
		cost[i] = 1<<31 - 1
	}
	cost[0] = 0
	for i := 0; i < N; i++ {
		updateCost(i)
	}
	fmt.Println(cost[N-1])
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 2688
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;

int gcd(int a,int b){
    if(a < b){
        int c = a;
        a = b;
        b = c;
    }
    if(a%b == 0) return b;
    else return gcd(b,a%b);
}

signed main(){
    
    int n,m;
    cin >> n >> m;
    string s,t;
    cin >> s >> t;

    int p = gcd(n,m);
    if(p == 1){
        if(s[0] == t[0]) cout << n*m << endl;
        else cout << -1;
        return 0;
    }

    int nn = n/p;
    int mm = m/p;
    for(int i = 0;i < p;i++){
        if(s[i*nn] != t[i*mm]){
            cout << -1;
            return 0;
        }
    }
    cout << n*m/p;

    

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 512
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math;

void main()
{
  auto n = readln.chomp.to!int;

  auto s = point(0, 0);
  auto t = point(100, 0);

  auto ri = s ~ koch(s, t, n) ~ t;
  foreach (r; ri)
    writefln("%.5f %.5f", r.x, r.y);
}

point[] koch(point s, point t, int r)
{
  if (r == 0) return [];
  --r;

  auto u = s + (t - s) * (1.0 / 3);
  auto v = s + (t - s) * (2.0 / 3);
  auto w = u + (v - u).rot60;

  auto su = koch(s, u, r);
  auto uw = koch(u, w, r);
  auto wv = koch(w, v, r);
  auto vt = koch(v, t, r);

  return su ~ u ~ uw ~ w ~ wv ~ v ~ vt;
}

point rot60(point s)
{
  auto cos60 = 1.0 / 2;
  auto sin60 = 3.0.sqrt / 2;
  return point(s.x * cos60 - s.y * sin60, s.x * sin60 + s.y * cos60);
}

struct Point(T) {
  T x, y;

  point opBinary(string op)(point rhs) {
    static if (op == "+") return point(x + rhs.x, y + rhs.y);
    else static if (op == "-") return point(x - rhs.x, y - rhs.y);
  }

  point opBinary(string op)(T a) {
    static if (op == "*") return point(x * a, y * a);
  }
}

alias Point!real point;

Measured memory_bytes: 3168
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = (a); i <= (b); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const int MX = 6005;
int n, mod;
ll fac[MX], inv[MX], res, mem2[MX], mem3[MX];

ll pot (ll b, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= b) %= mod;
		(b *= b) %= mod;
		p /= 2;
	}
	return res;
}

ll comb (ll n, ll k) {
	if (n < k || k < 0) return 0;
	return fac[n] * inv[k] % mod * inv[n - k] % mod;
}

ll dp2 (int n) {
	if (!n) return 1;
	ll &res = mem2[n];
	if (res != -1) return res;
	return res = (n - 1) * dp2(n - 2) % mod;
}

ll dp3 (int n) {
	if (!n) return 1;
	ll &res = mem3[n];
	if (res != -1) return res;
	return res = (n - 1) * (n - 2) % mod * dp3(n - 3) % mod;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	memset(mem2, -1, sizeof(mem2));
	memset(mem3, -1, sizeof(mem3));

	cin >> n >> mod;

	fac[0] = inv[0] = 1;
	for (int i = 1; i < MX; i++) {
		fac[i] = i * fac[i - 1] % mod;
		inv[i] = pot(fac[i], mod - 2);
	}

	for (int i = 0; i <= 3 * n; i++)
		for (int j = 0; i + 2 * j <= 3 * n; j++)
			if ((3 * n - i - 2 * j) % 3 == 0) {
				int k = (3 * n - i - 2 * j) / 3;
				if (j + k <= n) {
					ll p = comb(3 * n, i) * comb(3 * n - i, 2 * j) % mod;
					(res += p * dp2(2 * j) % mod * dp3(3 * k)) %= mod;
				}
			}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
int main(){
	string a,b;
	int x,y;
	string s;
	cin>>a>>b>>x>>y>>s;
	if(a==s)cout<<x-1<<' '<<y;
	else cout<<x<<' '<<y-1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<long long,long long>lp;
typedef pair<lp,long long>P;
main(){
  long long n,m,l;
  queue<P> que;
  long long size_q=0;
  cin>>n>>m;
  while(1){
    long long s,t,e;
    cin>>s>>t>>e;
    if(s==0&&t==0&&e==0) break;
    que.push(P(lp(s,t),e));
  }
  size_q=que.size();
  cin>>l;
  for(int i=0;i<l;i++){
    long long b[10005]={0};
    long long c[10005]={0};
    for(int j=1;j<=m;j++){
      cin>>b[j];
    }
    for(int j=0;j<size_q;j++){
      P now=que.front();
      que.pop();
      que.push(now);
      c[now.F.F]+=b[now.F.S]*now.S;
    }
    for(int j=1;j<=n;j++){
      if(j!=1) cout<<" ";
      cout<<c[j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 4328
#include <stdio.h>
#define MAXN 60
int main(void) {
	int n, p, s = 0;
	scanf("%d%d", &n, &p);
	long long ans = 1LL << n;
	for(int i = 0; i < n; i++) {
		int v;
		scanf("%d", &v);
		s += v & 1;
	}
	printf("%lld\n", s ? ans >> 1 : p ? 0 : ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
using namespace std;
string s1;
int fzx_max(int x,int y) {
        return x<y ? y : x;
}
signed main()
{
        cin>>s1;
        int ans=0,sum=0,len=s1.size();
        for (int i=0; i<len; i++)
                if (s1[i]=='R') {ans++; sum=fzx_max(sum,ans);}
                else ans=0;
        cout<<sum<<"\n";
        return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define lf else if
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define abs(x)      ((x)>0?(x):-(x))
#define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
#define Add(x,y)    ((x)=((x)+(y))%mod)
#define Max(x,y)    ((x)=((x)<(y)?(y):(x)))
#define Min(x,y)    ((x)=((x)>(y)?(y):(x)))
#define E(x)        return writeln(x),0
#define p(x)        printf("~%lld~\n",(long long)x)
#define pp(x,y)     printf("~~%lld %lld~~\n",(long long)x,(long long)y)
#define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",(long long)x,(long long)y,(long long)z)
#define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",(long long)a,(long long)b,(long long)c,(long long)d)
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define GuYue		puts("\nGuYueNa________________________________________________________________________________")
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
#if NEG
    inline ll read(){    ll x=0,fa=1; char ch=getchar();   for (;!isdigit(ch);ch=getchar()) if (ch=='-') fa=-1;  for (;isdigit(ch);ch=getchar())  x=x*10-48+ch;   return x*fa; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=getchar();   for (;!isdigit(ch);ch=getchar());    for (;isdigit(ch);ch=getchar())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
	void writeln(ll x){write(x);puts("");}
	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);}
	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);}
	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);}
}using namespace SHENZHEBEI;
ll a,b,c,ans,x,y,z,a1,b1,c1,d1,a2,b2,c2,d2;
int main(){
	a=read(),b=read(),c=read();ans=2e9;
	For(i,-150,150){
		x=max((i-a+1)/2,0ll);y=max((i-b+1)/2,0ll);z=max((i-c+1)/2,0ll);
		c1=c+z*2;c2=c1-i;a1=a+x*2;a2=a1-i;b1=b+y*2;b2=b1-i;
		Min(ans,x+a2+y+b2+z+c2);
	}writeln(ans);
}

Measured memory_bytes: 256
/*
 * Author : Sadi
 * Wed 08/07/2020
 * 17:03:54.55
 */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



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

    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) {
    	cin >> v[i];
    }
    int maxtillhere = -1;
    for(int i = 1; i < n; ++i) {
    	if(v[i] < v[i - 1]) {
    		maxtillhere = max(maxtillhere, v[i - 1]);
    		if(maxtillhere - v[i] > 1) {
    			cout << "No" << endl;
    			return 0;
    		}
    	}
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3732
#include <iostream>
using namespace std;
 
int main() {
	// your code goes here
	long long int k,now_max,now_min;
cin>>k;
long long int a[k];
for(int i=0;i<k;i++){
cin>>a[i];
}
bool flag=true;
now_max=2;
now_min=2;
for(int i=k-1;i>-1;i--){
if(now_max/a[i]-(now_min-1)/a[i]>0){
now_min=((now_min-1)/a[i]+1)*a[i];
now_max=((now_max/a[i])+1)*a[i]-1;
}
else{
flag=false;
}
}
 
if(flag){
cout<<now_min<<" "<<now_max;
}
else{
cout<<-1;
}
}

Measured memory_bytes: 1024
// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    string s;
    cin >> s;

    if ('a' <= s[0] && s[0] <= 'z') {
        cout << "a" << endl;
    } else {
        cout << "A" << endl;
    }
}


Measured memory_bytes: 3644
s=input()
a=int(s[:2])
b=int(s[2:])

if a==0:
  if b>0 and b<13:
    print("YYMM")
  else:
    print("NA")
elif a>0 and a<13:
  if b ==0 :
    print("MMYY")
  elif b>0 and b<13:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if b==0:
    print("NA")
  elif b>0 and b<13:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 3064
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  vector<int> times;
  rep(i, 5) {
    int time;
    cin >> time;
    times.push_back(time);
  }

  int lastIndex;
  int lastTimeDev = 10;
  rep(i, 5) {
    if (times[i] % 10 != 0) {
      if (times[i] % 10 < lastTimeDev) {
        lastIndex = i;
        lastTimeDev = times[i] % 10;
      }
    }
  }

  int result = 0;
  rep(i, 5) {
    if (i != lastIndex) {
      result += ceil(1.0 * times[i] / 10) * 10;
      // cout << result << endl;
    }
  }
  result += times[lastIndex];
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

typedef pair<int,pair<int,int> > pp;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
int level[2][100001];
int room[500][500];
bool visited[500][500];

int main(){
    int r;
    while(cin>>r,r){
        int w,h,ex,ey;
        int e[2];
        for(int i=0;i<2;++i){
            cin>>w>>h>>ex>>ey;
            for(int j=0;j<h;++j){
                for(int k=0;k<w;++k){
                    cin>>room[j][k];
                }
            }
            memset(visited,0,sizeof(visited));
            visited[--ey][--ex]=1;
            level[i][0]=0;
            int mlevel=0,index=1;
            priority_queue<pp,vector<pp>,greater<pp> > pq;
            pq.push(make_pair(room[ey][ex],make_pair(ex,ey)));
            while(!pq.empty()){
                pp cur=pq.top();pq.pop();
                mlevel=max(mlevel,cur.first);
                level[i][index++]=mlevel;
                if(index>r) break;
                for(int j=0;j<4;++j){
                    int cx=cur.second.first+dx[j];
                    int cy=cur.second.second+dy[j];
                    if(cx>=0&&cx<w&&cy>=0&&cy<h&&visited[cy][cx]==0){
                        visited[cy][cx]=1;
                        pq.push(make_pair(room[cy][cx],make_pair(cx,cy)));
                    }
                }
            }
            e[i]=index-1;
        }
        int ans = 1000000000;
        for(int i=0;i<=r;++i){
            if(e[0]<r-i||e[1]<i) continue;
            ans=min(ans,level[1][i]+level[0][r-i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
// __uint128_t




int main(){
    ll M; cin >> M;
    ll ans = 0, S = 0; 
    vector<ll> D(M), C(M);
    for(int i = 0; i < M; i++){
        cin >> D[i] >> C[i]; 
        ans += C[i]; S += D[i]*C[i]; 
    }
    cout << ans-1+(S-1)/9 <<endl;

}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
    int h,w;
    cin >> h >> w;
    cout << (h-1)*(w-1) << endl;
}

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


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

int main() {
  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++) {
    int max_i = max(p.at(i - 1), max(p.at(i), p.at(i + 1)));
    int min_i = min(p.at(i - 1), min(p.at(i), p.at(i + 1)));
    if(p.at(i) != max_i && p.at(i) != min_i) {
      count++;
    }
  }
  cout << count << endl;
}

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

int main(int argc, char *argv[]) {
  
  int k;
  cin >> k;
  string s;
  cin >> s;
  if(s.size() > k){
    cout << s.substr(0,k)+"..." << endl;
  }else{
    cout << s << endl;
  }

  return 0;
}


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

#pragma GCC optimize("Ofast")

#define ll long long
#define pb push_back
#define fr first
#define sc second
#define in freopen("input.txt", "r" , stdin)
#define out freopen("snakes.out", "w", stdout)
using namespace std;

ll n;
ll a[100005];
int main(){
    //in;
    //out;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    ll p = 0;

    for (int i = 1; i <= n; i++) {
        ans += abs(p - a[i]);
        p = a[i];
    }
    ans += abs (a[n] - 0);
    cout << ans - abs (0 - a[1]) - abs (a[2] - a[1]) + abs (0 - a[2]) << " ";

    for (int i = 2; i < n; i++) {
        cout << ans - abs (a[i] - a[i-1])  - abs (a[i] - a[i+1])  + abs (a[i+1] - a[i-1])<< " ";
    }

    cout << ans - abs(a[n-1] - a[n]) - abs (0 - a[n]) + abs (a[n-1] - 0) ;
 }


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007

using namespace std;


int main(void){
	string s;
	int k;
	cin >> s >> k;
	string work[k];
	rep(i,k) work[i] = "";
	work[0] = s[0];
	for(int i=0;i<s.length();i++){
		for(int j=1;j<=k;j++){
			if(work[k-1] != "" && work[k-1] < s.substr(i, j))break;
			string tmp = s.substr(i, j);
			rep(l,k){
				if(tmp == work[l]) break;
				if(tmp < work[l] || work[l] == ""){
					string w = tmp;
					tmp = work[l];
					work[l] = w;
				}
			}
		}
	}

	//rep(i,k)cout << work[i] << endl;
	cout << work[k-1] << endl;
	return 0;

}


Measured memory_bytes: 256
n = gets.to_i
count = 0
1.upto(9) do |i1|
  1.upto(9) do |i2|
    left, right = i1 == i2 && n >= i1 ? [1, 1] : [0, 0]
    5.times do |id|
      bitw9 = "" + "9" * id
      bitw0 = "" + "0" * id
      bitwn = id != 0 ? n.to_s[1..-2] : ""
      if n > (i1.to_s + bitw9 + i2.to_s).to_i then
        left += 10 ** id
      elsif n >= (i1.to_s + bitw0 + i2.to_s).to_i then
        left += bitwn.to_i + (n >= (i1.to_s + bitwn + i2.to_s).to_i ? 1 : 0)
      end

      if n > (i2.to_s + bitw9 + i1.to_s).to_i then
        right += 10 ** id
      elsif n >= (i2.to_s + bitw0 + i1.to_s).to_i then
        right += bitwn.to_i + (n >= (i2.to_s + bitwn + i1.to_s).to_i ? 1 : 0)
      end
    end
    count += left * right
  end
end

puts count

Measured memory_bytes: 1788
l = []
for i in range(5):
    l.append(int(input()))
k = int(input())
ok = True
for i in range(5):
    for j in range(5):
        if i == j: continue
        diff = abs(l[i] - l[j])
        if diff > k:
            ok = False
if ok: print('Yay!')
else: print(':(')

Measured memory_bytes: 61888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int a,b;
	cin >> a >> b;
	cout<<a*b<<' '<<2*a+2*b<<endl;
	return 0;
}


Measured memory_bytes: 3032
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author houghstc
 */

#include <iostream>
#include <fstream>

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

using namespace std;
using pii = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;

const int MOD = 1e9+7;

class BMakingTriangle {
public:
    void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vector<ll> arr(n);
        for(int i = 0; i < n; ++i)
            in >> arr[i];

        int cnt = 0;
        for(int i = 0; i < n; ++i)
            for(int j = i+1; j < n; ++j)
                for(int k = j+1; k < n; ++k)
                {
                    if(arr[i] != arr[j] && arr[j] != arr[k] && arr[i] != arr[k]
                       && (arr[i] + arr[j] > arr[k]) && (arr[i] + arr[k] > arr[j]) && arr[j] + arr[k] > arr[i])
                    {
                        //cout << arr[i] << " " << arr[j] << " " << arr[k] << endl;
                        cnt++;
                    }
                }
        out << cnt << endl;
    }
};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    BMakingTriangle solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <utility>
#include <vector>
#include <cstring>
using namespace std;

const int MAXN = 60;
static vector<pair<int, int>> graph[MAXN];
static bool used[MAXN];

void dfs(int v, int ng) {
    used[v] = true;
    for (auto& e : graph[v]) {
        if (used[e.first] or e.second == ng) continue;
        dfs(e.first, ng);
    }
}

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

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back({b, i});
        graph[b].push_back({a, i});
    }

    int ans = 0;
    for (int i = 0; i < M; i++) {
        memset(used, false, sizeof(used));
        dfs(0, i);
        for (int v = 0; v < N; v++) {
            if (!used[v]) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii>
using vec = vector<T>;

const ll INF = 1e18, MOD = 1e9 + 7;

const int MAX = 1e6;

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);

    int n;
    cin >> n;
    vii v(n);
    for (auto &e : v) {
        cin >> e;
    }
    multiset<int> s;
    int res = 0;
    for (auto e : v) {
        auto it = s.lower_bound(e);
        if (it == s.begin() or s.empty()) {
            res++;
        }
        else {
            s.erase(--it);
        }
        s.insert(e);
    }
    cout << res << '\n';
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		 int F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
	long long G()
	{
		 long long F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
}
int R(int l,int r)
{
	return (rand()<<15|rand())%(r-l+1)+l;
}
long long a[8][200002];
long long s[129][200001];
long long tmp[200001];
int main()
{
	int n=io::F(),m=3,k=io::F();
	for(register int i=1;i<=n;++i)
		for(register int j=0;j<m;++j)
			s[0][i]+=a[j][i]=io::G();
	long long max=0;
	
	for(register int i=0;i<1<<m-1;++i)
	{
		long long* S=s[i];
		if(i)
		{
			int d=__builtin_ctz(i);
			long long *T=s[i&i-1];
			for(register int j=1;j<=n;++j)
				tmp[j]=S[j]=T[j]-2*a[d][j];
		}
		else for(register int j=1;j<=n;++j)tmp[j]=S[j];
		long long now=0;
		std::nth_element(tmp+1,tmp+k,tmp+n+1);
		for(register int j=1;j<=k;++j)now+=tmp[j];
		cmax(max,-now);
		std::nth_element(tmp+1,tmp+n-k+1,tmp+n+1);
		now=0;
		for(register int j=n-k+1;j<=n;++j)now+=tmp[j];
		cmax(max,now);
	}
	printf("%lld\n",max);
	return 0;
}


Measured memory_bytes: 10496
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N;
string s;
int main(){
    cin >> s;
    int cntg = 0;
    int cntp = 0;
    int cnt = 0;
    REP(i, s.size()){
        if(s[i] == 'g'){
            if(cntg <= cntp)
                cntg++;//グーに対してグーを出した
            else{
                cntp++;//グーに対してパーを出した
                cnt++;//win
            }
        }
        else{
            if(cntg < cntp){
                cntg++;//パーに対してグーを出した
                cnt -= 1; //loss
            }else{
                cntp++;//パーに対してパーを出した
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
def resolve():
    '''
    code here
    '''

    N = int(input())

    FB = []
    for i in range(1,N+1):
        if i%3 == 0 or i%5==0:
            pass
        else:
            FB.append(i)
    
    res = sum(FB)
    print(res)
        

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 30128
#include<iostream>
#include<vector>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

vector<int> ms;
vector<bool> msp;
vector<int> mp;
int find(int num){
	rep(i,ms.size())if(ms[i]==num)return i;
	return -1;
}

int main(){
	rep(i,300001)if(i%7==1 || i%7==6)ms.push_back(i);
	msp=vector<bool>(ms.size(),true);
	msp[0]=false;
	for(int i=1;ms[i]<sqrt(ms[ms.size()-1]);i++){
		if(!msp[i])continue;
		loop(j,i+1,ms.size())if(ms[j]%ms[i]==0)msp[j]=false;
	}
	rep(i,ms.size())if(msp[i])mp.push_back(ms[i]);
	int num;
	while(cin>>num,num!=1){
		bool alt=true;
		cout<<num<<": ";
		rep(i,mp.size()){
			if(num%mp[i]==0){
				if(alt){
					cout<<mp[i];
					alt=false;
				}else{
					cout<<" "<<mp[i];
				}
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3504
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        long[] allSize;
        long[] pSize;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long x = in.nextLong();

            allSize = new long[n + 1];
            pSize = new long[n + 1];
            allSize[0] = 1;
            pSize[0] = 1;
            for (int i = 0; i < n; i++) {
                allSize[i + 1] = 3 + 2 * allSize[i];
                pSize[i + 1] = 1 + 2 * pSize[i];
            }

            out.println(calc(n, x));
        }

        long calc(int n, long length) {
            if (length == 0) return 0;

            if (n == 0) return 1;

            if (length <= allSize[n - 1] + 1) {
                return calc(n - 1, length - 1);
            }

            if (length < allSize[n]) {
                return calc(n - 1, length - 2 - allSize[n - 1]) + 1 + pSize[n - 1];
            }

            return pSize[n];
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

    }
}



Measured memory_bytes: 22868
n = int(input())
s = list(input())

dp = [[0] * n for _ in range(n)]
for i in range(n-1, -1, -1):
    for j in range(n-1, -1, -1):
        if s[i] == s[j]:
            if j+1 <= n-1 and i+1 <= n-1:
                dp[i][j] = dp[i+1][j+1] + 1
            else:
                dp[i][j] = 1
                
for i in range(n):
    for j in range(n):
        dp[i][j] = min(abs(i-j), dp[i][j])

ans = 0
for i in range(n):
    ans = max(ans, max(dp[i]))
print(ans)

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


llint n;

llint calc(llint x){
    return (x*(x-1))/2;
}

void solve(){
  cin >> n;
  vector<llint>a(n);
  for(int i=0;i<n;i++)cin >> a[i];
  llint sum1=0;
  llint dp[n+1];
  for(int i=1;i<=n;i++)dp[i]=0;
  for(int i=0;i<n;i++){
    dp[a[i]]++;
  }
  for(int i=1;i<=n;i++){
      sum1+=calc(dp[i]);
  }
  for(int k=0;k<n;k++){
      llint ans=sum1;
      ans-=calc(dp[a[k]]);
      dp[a[k]]--;
      ans+=calc(dp[a[k]]);
      dp[a[k]]++;
      cout << ans << endl;
  }
}

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


Measured memory_bytes: 5760
import math


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def build(l, A):
    # minimum cost for mask to A
    N = len(l)
    mask_to_cost = [math.inf]*(1<<N)
    for m in range(1, 1<<N):
        i = 0
        cost = 0
        length = 0
        while i < N:
            if m&(1<<i):
                cost += 10
                length += l[N-i-1]
            i += 1
        if cost > 0:
            cost -= 10
        cost += abs(length-A)
        mask_to_cost[m] = cost
    for m in range(1<<N):
        s = m
        while s > 0:
            s = (s-1)&m
            mask_to_cost[m] = min(mask_to_cost[m], mask_to_cost[s])
    return mask_to_cost


def solve():
    N, A, B, C = read_ints()
    l = [read_int() for _ in range(N)]
    A_cost = build(l, A)
    B_cost = build(l, B)
    C_cost = build(l, C)
    min_cost = math.inf
    for a_mask in range(1, 1<<N):
        bc_mask = ((1<<N)-1)-a_mask
        b_mask = bc_mask
        while b_mask > 0:
            b_mask = (b_mask-1)&bc_mask
            c_mask = bc_mask-b_mask
            if b_mask and c_mask:
                min_cost = min(min_cost, A_cost[a_mask]+B_cost[b_mask]+C_cost[c_mask])
    return min_cost


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 73716
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
//////////////////////////////////////////////////////////

int main(void){
  int a,b;cin >> a >> b;
  if(b >= a)cout << "unsafe" << '\n';
  else cout << "safe" << '\n';
}


Measured memory_bytes: 3632
#pragma warning (disable:4996)
#include"bits/stdc++.h"
#include<cassert>
#define int long long
#define MRE assert(0);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<int, P > PP;
int a[100006], b[100006];
int ua[100006], ub[100006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i] >> b[i];
	int sa = 0, sb = 0;
	rep(i, n)sa += a[i];
	rep(i, n)sb += b[i];
	vector<PP>V;
	rep(i, n) {
		V.push_back(PP(a[i], P(i, 0)));
		V.push_back(PP(b[i], P(i, 1)));
	}
	sort(V.begin(), V.end());
	int sum = 0;
	rep(i, n) {
		if (V[i].second.second == 0)ua[V[i].second.first]++;
		else ub[V[i].second.first]++;
		sum += V[i].first;
	}

	int ans = inf;
	rep(i, n) {//a[i],b[i]を必ず使う
		int cnt = 0;
		if (ua[i])cnt++;
		if (ub[i])cnt++;

		if (cnt == 0) {//下から2個除去
			ans = min(ans, sum - V[n - 1].first - V[n - 2].first + a[i] + b[i]);
		}
		else if (cnt == 1) {//1個
			int M = -V[n - 1].first;
			if (V[n - 1].second.first == i)M = -V[n - 2].first;
			if (ua[i])M += b[i];
			else M += a[i];
			ans = min(ans, sum + M);
		}
		else {
			ans = min(ans, sum);
		}
	}
	cout << min({ ans,sa,sb }) << endl;
}

Measured memory_bytes: 10096
package main

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

func dummy() {
	math.Abs(1.0)
}

/************I/O***********/

var (
	// ReadString returns a WORD string.
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

// ReadFloat64 returns an float64.
func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func readRuneSlice() []rune {
	return []rune(readString())
}

/*********math********/
func mod(val int, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func minInt(val ...int) int {
	res := val[0]
	for i := 1; i < len(val); i++ {
		if res > val[i] {
			res = val[i]
		}
	}
	return res
}
func maxInt(val ...int) int {
	res := val[0]
	for i := 1; i < len(val); i++ {
		if res > val[i] {
			res = val[i]
		}
	}
	return res
}

const MOD = 1000000007

func main() {
	n := readInt()
	k := readInt()
	h := readIntSlice(n)
	dp := make([]int, n)
	dp[0] = 0
	for i := 1; i < n; i++ {
		mincost := dp[i-1] + absInt(h[i]-h[i-1])
		for j := 1; j <= minInt(k, i); j++ {
			cost := dp[i-j] + absInt(h[i]-h[i-j])
			if mincost > cost {
				mincost = cost
			}
		}
		dp[i] = mincost
	}
	fmt.Println(dp[n-1])
}


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

typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < n; i++)

int N;
double p[105];

struct SCC {
    vector<vector<int> > g, gr, ls;
    vector<int> visited, num, d;
    vector<P> es;
    stack<int> st;

    SCC(int n) : g(n), gr(n), visited(n, 0), num(n, -1), ls(n) {}

    void add_edge(int u, int v) {
        g[u].push_back(v);
        gr[v].push_back(u);
        es.push_back(P(u, v));
    }

    void dfs(int x) {
        if (visited[x]) return;
        visited[x] = 1;
        for (int i : g[x]) dfs(i);
        st.push(x);
    }

    void rdfs(int x, int k) {
        if (num[x] != -1) return;
        num[x] = k;
        ls[k].push_back(x);
        for (int i : gr[x]) rdfs(i, k);
    }
    void build() {
        for (int i = 0; i < g.size(); i++) dfs(i);
        int p = 0;
        while (!st.empty()) {
            int v = st.top();
            st.pop();
            if (num[v] == -1) {
                rdfs(v, p);
                p++;
            }
        }
        d.resize(p);
        for (auto &e : es) {
            int x = num[e.first], y = num[e.second];
            if (x == y) continue;
            d[y]++;
        }
    }
    double solve() {
        double res = 1;
        for (int i = 0; i < d.size(); i++) {
            if (d[i] == 0) {
                double q = 1;
                for (int j = 0; j < ls[i].size(); j++) {
                    q *= p[ls[i][j]];
                }
                res *= (1 - q);
            }
        }
        return res;
    }
};

int main() {
    while (1) {
        cin >> N;
        if (N == 0) break;
        SCC G(N);
        REP(i, N) {
            cin >> p[i];
            int m;
            cin >> m;
            REP(j, m) {
                int a;
                cin >> a;
                a--;
                G.add_edge(i, a);
            }
        }
        G.build();
        printf("%.8lf\n", G.solve());
    }
    return 0;
}



Measured memory_bytes: 3384
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    tree = [[] for _ in range(N)]
    for i in range(N-1):
        u, v, w = map(int, readline().split())
        u, v = u-1, v-1
        tree[u].append((v,w))
        tree[v].append((u,w))
    color = [-1]*N
    color[0]=0

    que = deque([0])
    while que:
        index = que.popleft()
        for next_, weight in tree[index]:
            if color[next_]==-1:
                if weight%2==0:
                    color[next_] = color[index]
                else:
                    color[next_] = color[index]^1
                que.append(next_)
    for c in color:
        print(c)


if __name__ == '__main__':
    main()

Measured memory_bytes: 39144
#include <stdio.h>

int main()
{
  int n /*荷物の数*/
    ,k /*トラックの数*/
    ,sum=0 /*荷物重量の合計*/
    ,M /*真ん中（初期値sum/k）*/
    ,L=0 /*左（初期値Nimotu[]のMAX）*/
    ,R /*右 （初期値sum）*/
    ,NIZUKURI /*トラックにつめる荷物の重さ合計*/
    ,hantei /*トラックが余ったかの判定*/
    ,x=0 /*MIN候補の個数*/
    ,MIN=9999999999 /*最小値の値*/
    ,i,j;/*変数*/
  
  scanf("%d%d",&n,&k);
  
  int Nimotu[n] /*荷物のそれぞれのおもさ*/
    ,Kouho[n]; /*MIN候補*/
  
  for(i=0;i<n;i++)/*荷物の重さそれぞれ入力*/
    {
      scanf("%d",&Nimotu[i]);
      sum+=Nimotu[i];
      if(L<Nimotu[i])L=Nimotu[i];
    }

  R=sum;
  M=sum/k;
  
  while(L<R)
    {
      j=0;
      hantei=1;//初期化
      
      for(i=0;i<k;i++)//トラックを交換
	{
	  NIZUKURI=0;//荷物量を初期化

	  if(j==n)//
	    {
	      hantei=0;
	      break;
	    }
	  
	  while(1)
	    {
	      NIZUKURI+=Nimotu[j];
	      
	      if(NIZUKURI>M || j==n)
		{
		  break;
		}
	      else
		{
		  j++;
		}
	    }
	}
      
      if(j==n&&i==k)
	{
	  Kouho[x++]=M;
	  hantei=0;
	}

      if(hantei==0)
	{
	  R=M; 
	}
      else
	{
	  L=M+1; 
	}
      M=(L+R)/2;
    }

  for(i=0;i<x;i++)
    {
      if(MIN>Kouho[i])
	{
	  MIN=Kouho[i];
	}
    }

    if(x!=0)
    {
      printf("%d\n",MIN);
    }
  else
    {
      printf("%d\n",M);
    }
  
	  
  return 0;

}



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

ll pow(ll x,ll y){
  if(y==0){
    return 1;
  }else if(y==1){
    return x%MOD;
  }else if(y%2==0){
    return pow(x,y/2)*pow(x,y/2)%MOD;
  }else{
    return x*pow(x,y-1)%MOD;
  }
}

int d(int x){
  if(x==0){
    return 1;
  }
  int ans=0;
  while(x>0){
    ans ++;
    x /= 10;
  }
  return ans;
}

int main(){
  int N,M;cin >> N >> M;
  vector<int> S(M);
  vector<int> C(M);
  vector<int> P(N,1);
  for(int i=1;i<N;i++){
    P[i] = 10 * P[i-1];
  }
  for(int i=0;i<M;i++){
    cin >> S[i] >> C[i];
  }
  for(int x=0;d(x)<=N;x++){
    bool ok= true;
    if(d(x)==N){
      for(int i=0;i<M;i++){
        if((x/P[N-S[i]])%10!=C[i]){
          ok = false;
          break;
        }
      }
      if(ok){
        cout << x << endl;
        return 0;
      }
    }
  }
  cout <<-1 << endl;
}

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

typedef unsigned long long int ull;

int main(){
    int n;
    scanf("%d",&n);
    ull ans=0;
    for(int i=0;i<n;i++){
        ull num;
        scanf("%llu",&num);
        ans+=(num-1);
    }
    printf("%llu\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

using ll =  long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}


}

#define MAX_V 200000

std::vector<std::pair<ll, ll>> G[MAX_V];

int main() {

	int n;
	std::cin >> n;

	rep(i, n - 1) {
		int a, b;
		std::cin >> a >> b;
		--a; --b;
		G[a].emplace_back(std::make_pair(b, i));
		G[b].emplace_back(std::make_pair(a, i));
	}

	// 最も次数が高い頂点を探す

	size_t max_degree = 0;
	int start_vertex = 0;

	rep(i, n) {
		if (G[i].size() > max_degree) {
			max_degree = G[i].size();
			start_vertex = i;
		}
	}

	int k = max_degree;

	std::vector<int> colors(n - 1, inf);
	std::vector<bool> used(n, false);
	std::queue<int> que;
	std::vector<int> parent_color(n, inf);

	que.push(start_vertex);

	while (!que.empty()) {
		int v = que.front();
		que.pop();
		used[v] = true;

		int color = 1;
		// 色をわりあてる 
		for (auto& vertex : G[v]) {
			int u = vertex.first;
			if (used[u]) continue;
			int edge = vertex.second;
			// 木構造なのでこれで十分
			if (color == parent_color[v]) ++color;
			colors[edge] = parent_color[u] = color;
			++color;
			que.emplace(u);
		}
	}

	std::cout << k << std::endl;
	rep(i, n - 1) {
		std::cout << colors[i] << std::endl;
	}

	return 0;
}

Measured memory_bytes: 11136
#include<cstdio>
using namespace std;
int n,k,d;
bool f[10];
int main()
{
	scanf("%d%d",&n,&k);for(int i=1;i<=k;++i) {scanf("%d",&d);f[d]=true;}
	for(int i=n;;++i) {
		int now=i;
		while(now) {if(f[now%10]) goto loop;now/=10;}
		printf("%d\n",i);break;
		loop:;
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
void fast(){
cin.tie(0);
cin.sync_with_stdio(0);
}
int main()
{
    fast();
    int n;
    cin>>n;
    long long co=0;
   for(int i=1;i<=n;i++)
   {
      if (i%3!=0 && i%5!=0)
        co+=i;
   }
   cout<<co;
return 0;
}

Measured memory_bytes: 3640
#include<iostream>

using namespace std;


int main() {
	int r, c;
	int**Graph;

	cin >> r >> c;

	Graph = new int*[r+1];
	for (int i = 0; i < r + 1; i++) {
		Graph[i] = new int[c + 1];
	}


	for (int i = 0; i < r; i++) {
		Graph[i][c] = 0;
		for (int j = 0; j < c; j++) {
			cin >> Graph[i][j];
			Graph[i][c] += Graph[i][j];
		}
	}

	for (int j = 0; j < c + 1; j++) {
		Graph[r][j] = 0;
		for (int i = 0; i < r; i++) {
			Graph[r][j] += Graph[i][j];
		}
	}

	for (int i = 0; i < r + 1; i++) {
		for (int j = 0; j < c + 1; j++) {
			if (j != 0)cout << " ";
			cout << Graph[i][j];
		}
		cout << endl;
	}


	for (int i = 0; i < r + 1; i++) {
		delete[]Graph[i];
		Graph[i] = 0;
	}
	delete[]Graph;
	Graph = 0;

	return 0;
}

Measured memory_bytes: 1236
H,W = map(int,input().split())
A = [list(str(input())) for _ in range(H)]
for i in range(H):
  A[i] += '.'
A += [list('.'*(W+1))]
y,x = 0,0
ans = 'Impossible'
while y < H and x < W:
  if A[y+1][x] == '#' and A[y][x+1] == '#':
    break
  elif A[y+1][x] == '#':
    if '#' in A[y][x+1:] or '#' in A[y+1][:x]:
      break
    y += 1
  elif A[y][x+1] == '#':
    x += 1
  else:
    break
  if y == H-1 and x == W-1:
    ans = 'Possible'
    break
print(ans)

Measured memory_bytes: 3064