akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int  N=100000 +10, M=(ll)1e9+1 ;
 const int mod =998244353 ,sz=5 ;

void work(){
   ll n;
   cin >> n;
   cout << 3*n*n;
}
int main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0);
    ll t;
    // cin >> t;
    t=1;
    while(t--){
            work();
    }
   return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int H, W; cin >> H >> W;
  vs C(H); rep(i,H) cin >> C.at(i);
  
  rep(i,H) {
    cout << C.at(i) << endl;
    cout << C.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
string s;
LL ans,len;
LL count(LL a,LL i)
{
    LL s=0;
    LL cnt=i;
    i=pow(2,i);
    s+=i;
    for(int j=1;j<=len-cnt-1;j++)
    {
        s=s*10+i;
        i*=2;
    }
    return a*s;
}
int main()
{
    cin>>s;
    len=s.length();
    for(LL i=0;i<s.length();i++)
    {
        ans+=count(s[i]-'0',i);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  const int INF = 1e9 + 5;
int main()
{
  int n;
  cin>>n;

  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  vector<int> dp(n,INF);
  dp[0]=0;
  for(int i=0;i<n;i++)
  {
    for(int j :{i+1,i+2})
    {
      if(j<n)
      {
        dp[j]= min(dp[j], dp[i]+abs(arr[j]-arr[i]));

      }
    }
  }
  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
}

	
int main(){
	init();
	ll N;
	cin>>N;
	ll a=1;
	ll last=a;
	while(1){
		ll data=a*108/100;
		if(data==N){
			cout<<a<<endl;
			return 0;
		}
		if(data>N){
			cout<<":("<<endl;
			return 0;
		}
		a++;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
    int N;  cin>>N;
    int num=N/111;
    if(N%111==0){
        cout<<N<<endl;
        return 0;
    }
    cout<<(num+1)*111<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;i++)

int w,h,m[100][100],ans;
int dx[2][6]={{1,1,0,-1,0,1},{1,0,-1,-1,-1,0}},dy[6]={0,-1,-1,0,1,1};

void A(int y,int x){
	if(m[y][x]!=0)return;
	m[y][x]=2;
	rep(i,6){
		int tx=x+dx[y%2][i],ty=y+dy[i];
		if(0<=ty&&ty<h&&0<=tx&&tx<w) A(ty,tx);
	}
}

int main(){
	scanf("%d%d",&w,&h);
	rep(i,h) rep(j,w) scanf("%d",&m[i][j]);
	rep(i,h){
		A(i,0);
		A(i,w-1);
	}
	rep(i,w){
		A(0,i);
		A(h-1,i);
	}
	rep(i,h) rep(j,w){
		if(m[i][j]==2)continue;
		rep(k,6){
			int ty=i+dy[k],tx=j+dx[i%2][k];
			if(0>ty||ty>=h||0>tx||tx>=w||m[ty][tx]==2)ans++;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1328
#include <iostream>
#include <algorithm>

#define SIZE 200001
#define MAXI 1200012

using namespace std;

int main() {
    long long int i,j,i2,j2,N,M,K,Q,X,B;
   long long int A[SIZE];
   long long int P[SIZE];
   long long int F[SIZE];
   cin >> N >> K;

   for (i=1;i<=N;i++)
    P[i] = -1;
   for (i=1;i<=N;i++) {
     cin >> A[i];
   }

   // F[i] = image de 1

   F[0] = 1;
   P[1] = 0; //
   j = A[1];
   i = 1;
   F[1] = j;
   while ((i<=K) && (P[j]<0)) {
     P[j]=i;
     j2 = A[j];
     F[i] = j;
     i++;
     j = j2;
   }
   F[i] = j;

   if (i>K) {
     cout << F[K] << endl;
   }
   else {
     long long int debut,fin,longueur;

     debut = P[j];
     fin = i;
     longueur = fin-debut;
     K -= fin;
     cout << F[debut+(K % longueur)] << endl;
   }



  return 0;

}


Measured memory_bytes: 7956
N, M = map(int, input().split())
from1 = set()
toN = set()
for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        from1.add(b)
    if b == N:
        toN.add(a)
msg = "IMPOSSIBLE" if from1.isdisjoint(toN) else "POSSIBLE"
print(msg)


Measured memory_bytes: 18892
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;

char a[100];
LL ans[10];

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%s", a);
		if(a[0] == 'M') {
			ans[1] = ans[1] + 1;
		}
		else if(a[0] == 'A') {
			ans[2] = ans[2] + 1;
		}
		else if(a[0] == 'R') {
			ans[3] = ans[3] + 1;
		}
		else if(a[0] == 'C') {
			ans[4] = ans[4] + 1;
		}
		else if(a[0] == 'H') {
			ans[5] = ans[5] + 1;
		}
	}
	int pp = 0;
	for(int i = 1; i <= 5; i++)
	{
		if(ans[i] != 0) pp += ans[i];
		//printf("%lld\n", ans[i]);
	}
	if(pp < 3) printf("0\n");
	else {
		LL aw = 1;
		for(LL i = pp - 2; i <= pp; i++)
		{
			aw *= i;
		}
		aw = aw / 6;
		for(int i = 1; i <= 5; i++)
		{
			if(ans[i] > 2) {
				aw = aw - (ans[i] * (ans[i] - 1) * (pp - ans[i])) / 2 - (ans[i] * (ans[i] - 1) * (ans[i] - 2)) / 6;
			}
			else if(ans[i] == 2) {
				aw = aw - (pp - ans[i]);
			}
		}
		printf("%lld\n", aw);
	}
}

Measured memory_bytes: 128
n = gets.to_i
as = gets.split.map(&:to_i)

ans = n.times.with_object([]) do |i, a|
  if i.odd?
    a.push(as[i])
  else
    a.unshift(as[i])
  end
end

ans.reverse! if n.even?
puts ans.join(" ")


Measured memory_bytes: 27492
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long ans = 1;
		for(int i = 0; i < n; ++i) {
			ans = lcm(ans, in.nextLong());
		}
		
		System.out.println(ans);
	}
	
	
	public static long gcd(long a, long b) {
		if( b == 0 ) return a;
		return gcd(b, a%b);
	}
	
	public static long lcm(long a, long b) {
		return a * (b / gcd(a, b));
	}
}

Measured memory_bytes: 21972
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let upper_t = read::<usize>();
    let mut ans = 1 << 30;
    for _ in 0..n {
        let c = read::<usize>();
        let t = read::<usize>();
        if t <= upper_t {
            ans = std::cmp::min(ans, c);
        }
    }
    if ans != (1 << 30) {
        println!("{}", ans);
    } else {
        println!("TLE");
    }
}


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

int main() {
	char s[100];
	scanf("%s", s + 1); int k = strlen(s + 1);
	int cnt = 15 - k;
	for (int i = 1; i <= k; ++i) cnt += s[i] == 'o';
	puts(cnt >= 8 ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int comb(int x, int y) {
	int i;
	int ret = 1;

	for (i = x; i > x - y; i--) {
		ret *= i;
	}

	for (i = 1; i <= y; i++) {
		ret /= i;
	}

	return ret;
}

int abs(int x) {
	if (x < 0) x = -x;

	return x;
}

int main() {

	int n;

	std::cin >> n;

	int *a;
	a = new int[n];

	int max = -1;
	int i;

	for (i = 0; i < n; i++) {
		std::cin >> a[i];
		if (max < 0 || max < a[i]) max = a[i];
	}

	int half = (max + 1) / 2;
	int dif, mid, tmp_dif;

	dif = abs(a[0] - half);
	mid = a[0];
	
	for (i = 1; i < n; i++) {
		tmp_dif = abs(a[i] - half);
		if (tmp_dif < dif) {
			dif = tmp_dif;
			mid = a[i];
		}
	}

	if (max == mid) mid = 0;

	std::cout << max << " " << mid << std::endl;

	delete[] a;

	return 0;

}


Measured memory_bytes: 640
const bool TEST=0;
#include<iostream>
#include<cctype>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<cctype>
#include<cstring>
#include<utility>
#include<cmath>
#include<sstream>
#include<stack>
const int inf=0x7fffffff;
#define IF if(TEST)
#define FI if(!TEST)
#define gts(s) fgets((s),sizeof(s),stdin)
#define ALL(s) (s).begin(),(s).end()
#define MK(a,b) make_pair((a),(b))
typedef long long int LL;
typedef unsigned int U;
typedef unsigned long long ULL;
using namespace std;
typedef pair<int,int> Point;
template <typename T>
void pA(T *begin,int n){ for(int i=0;i<n;i++){ cout<<*(begin++); } printf("\n"); }
const int N  = 1e5;
int n; 
struct NODE{
	int l;
	int r;
	bool same;
	Point p;
}t[4*N];
int a[N*4];
LL ans[N+10];
int curi;
int cur;
int _min;
int D;
int CNT=0;
const int ROOT=1;
namespace std{
bool operator< (const Point &a,const Point &b){
	if(a.first<b.first)return 1;
	else if(a.first==b.first){
		return a.second>b.second;
	}
	else return 0;
}
}
void pri(){
	for(int i = 1;i<=n;i++){
		printf("%lld\n",ans[i]);
	}
}
inline void log(){
	FI return ;
	if(CNT==3)exit(0);
	CNT++;
	IF if(1){
		for(int i = 1;i< 5;i++){
			printf("i:%d l:%d r:%d p:(%d,%d) same:%d\n",i,t[i].l,t[i].r,t[i].p.first,t[i].p.second, t[i].same);
		}
	}
}
NODE build(int ind,int l,int r){
	t[ind].l=l;
	t[ind].r=r;
	if(l==r){
		t[ind].same=1;
		t[ind].p=MK(a[l],l);
		return t[ind];
	}
	NODE c1,c2;
	c1=build(2*ind,l,(l+r)/2);
	c2=(build(2*ind+1,(l+r)/2+1,r));
	if(c1.same&&c2.same&&c1.p.first==c2.p.first){
		t[ind].same=1;
	}
	t[ind].p=max(c1.p,c2.p);
	return t[ind];
}
NODE upg(int nod ,int l,int r){
	NODE &x=t[nod];
	IF cout<<"upg "<<nod<<' '<<l<<' '<<r<<endl;
	if(x.p.first<=_min)return x;
	if(x.r<l)return x;
	else if (x.l>r)return x;
	else if(l<=x.l&&x.r<=r&&x.same){
		LL times=x.p.first-_min;
		LL cnt=x.r-x.l+1;
		ans[curi]+=cnt*times;
		x.p.first-=times;
		return x;
	}
	else {
		NODE c1,c2;
		c1=upg(nod*2,l,r);
		c2=upg(nod*2+1,l,r);
		x.p=max(c1.p,c2.p);
		if(c1.p.first==c2.p.first&&
				c1.same&&c2.same){
			x.same=1;
		}
		return x;
	}
}
Point que(int nod,int l,int r){
	if(l>r)return MK(0,inf);
	NODE x=t[nod];
	if(l<=x.l&&x.r<=r)return x.p;
	if(x.r<l||x.l>r){
		//		cout<<"returing (0,inf) "<<nod<<' ';
		//		printf("(%d,%d)",x.l,x.r);
		//		printf("l,r:(%d,%d)\n",l,r);
		return MK(0,inf);
	}
	return max(que(nod*2,l,r),que(nod*2+1,l,r));
}
void sol(){
	cin>>n;
	for(int i = 1 ;i<= n;i++){
		int x;
		scanf("%d" , & x);
		a[i]=x;
	}
	D=1;
	while(n>(1<<D)){
		D++;
	}
	build (1,1,1<<D);
	NODE &x=t[1];
	log();
	while(x.p.first!=0){
		IF cout<<"-------------"<<endl;
		IF pri();
		curi=x.p.second;
		cur=x.p.first;
		_min=que(ROOT,1,curi-1).first;
		upg(ROOT,curi,n);
		IF {
			printf("curi:%d, cur:%d, _min:%d\n",curi,cur,_min);
		}
		log();
//		exit(0);
		x=t[1];
	}
	pri();
}
int main()
{
	sol();
	return 0;
}
//E.cc
//generated automatically at Sun Feb 19 10:43:33 2017
//by xsthunder


Measured memory_bytes: 10368
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		long a = in.nextLong();
		long b = in.nextLong();
		long x = in.nextLong();
		long ans = b/x + 1;
		if (a != 0) ans -= (a-1)/x + 1;
		out.println(ans);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 9812
fun main(args: Array<String>) {
    val ns = readLine()!!
    val n = readLine()!!.toLong()
    var f = 0
    for (c in ns) {
        if (c == '1') {
            f++
        } else {
            break
        }
    }

    if (n == 1L) {
        println(ns[0])
    } else if (n <= f) {
        println(1)
    } else {
        println(ns[f])
    }
}


Measured memory_bytes: 33748
#!/usr/bin/env python3
import sys


def solve(N: int, T: int, A: "List[int]"):
    right_max = [0] * N # i番目よりあとで一番大きいA_i
    m_a = 0
    for i in range(1, N):
        m_a = max(m_a, A[-i])
        right_max[-i-1] = m_a

    m_p = 0
    count = 0
    for i, a in enumerate(A):
        profit = right_max[i] - a
        if profit > m_p:
            m_p = profit
            count = 1
        elif profit == m_p:
            count += 1
    print(count)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, T, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 60192
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
bool f[1300000];
int main(){
    fill(f,f+1300000,true);
    f[0]=f[1]=false;
    vector<int>prime(1,1);
    for(int i=2;i<=1300000;i++){
        if(!f[i])continue;
        prime.push_back(i);
        for(int j=i+i;j<=1300000;j+=i)f[j]=false;
    }

    int n;
    while(scanf("%d",&n),n){
        int pos=lower_bound(prime.begin(),prime.end(),n)-prime.begin();
        if(prime[pos]==n){
            puts("0");
        }
        else{
            printf("%d\n",prime[pos]-prime[pos-1]);
        }
    }

    return 0;
}

Measured memory_bytes: 2836
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int cnt = 0;
    int n;
    cin >> n;
    REP(i,n){
        int tmp;
        cin >> tmp;
        if(tmp != i+1){
            cnt ++;
        }
    }
    if(cnt <= 2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 256
#include<stdio.h>
long long MAX(long long a,long long b){return a<b?b:a;}
int main(){
  long long n,m,max=0,a[100010],b[100010],i,d[4][100010]={};
  scanf("%lld %lld",&n,&m);
  for(i=0;i<n;i++)scanf("%lld %lld",&a[i],&b[i]);
  for(i=0;i<n;i++)d[0][i+1]=d[0][i]+b[i];
  for(i=0;i<n;i++)d[1][i+1]=MAX(d[1][i],d[0][i+1]-a[i]*2);
  for(i=0;i<n;i++)d[0][i+1]=MAX(d[0][i],d[0][i+1]-a[i]  );
  //for(i=0;i<=n;i++)printf("%lld %lld\n",d[0][i],d[1][i]);//printf("\n");
  //for(i=0;i<=n;i++)printf("%lld\n",d[0][i]);printf("\n%lld %lld\n",max0,max1);
  for(i=n;i  ;i--)d[2][i-1]=d[2][i]+b[i-1];
  //for(i=0;i<=n;i++)printf("%lld\n",d[2][i]);printf("\n");
  for(i=n;i  ;i--)d[3][i-1]=MAX(d[3][i],d[2][i-1]-(m-a[i-1])*2);
  for(i=n;i  ;i--)d[2][i-1]=MAX(d[2][i],d[2][i-1]-(m-a[i-1])  );
  //for(i=0;i<=n;i++)printf("%lld %lld %lld %lld\n",d[0][i],d[1][i],d[2][i],d[3][i]);
  for(i=0;i<=n;i++)max=MAX(max,MAX(d[0][i]+d[3][i],d[1][i]+d[2][i]));
  printf("%lld\n",max);
  return 0;
}


Measured memory_bytes: 4864
N, K = map(int,input().split())
A = list(map(int,input().split()))
X = []
for l in range(N):
  r = l
  v = 0
  while r < N:
    v += A[r]
    X.append(v)
    r += 1
ans = 0
for i in range(60, -1, -1):
  Y = [ x for x in X if (x >> i & 1) == 1 ]
  if len(Y) >= K:
    ans += 1 << i
    X = Y
print(ans)


Measured memory_bytes: 28904
MOD = 10**9+7

n = int(input())

dp = [0 for i in range(n+1)]

if(n == 1):
    print("1")
    exit()
if(n==2):
    print("1")
    exit()

dic = {}

ind = [0 for i in range(n+1)]

for i in range(1,n+1):
    c = int(input())
    if c in dic:
        ind[i] = dic[c][-1]
        dic[c].append(i)
    else:
        dic[c] = [i]

dp[0] , dp[1],dp[2] = 1,1,1

for i in range(3,n+1):
    dp[i] = (dp[i] + dp[i-1]) % MOD
    if(ind[i] == 0):continue
    if(ind[i] == i-1):continue
    dp[i] = (dp[i] + dp[ind[i]]) % MOD

print(dp[n])

Measured memory_bytes: 84556
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};
 int main(){
  ll n ;cin>> n ;
  vector<P> X(n) ;
  vector<P> Y(n) ;
  rep(i,n){
    X[i].second=i ;
    Y[i].second=i ;
    cin>>X[i].first>>Y[i].first ;
  }
   sort(X.begin(),X.end()) ;
   sort(Y.begin(),Y.end()) ;
   vector<pair<ll,P>> all(2*n-2) ;//cost,vertex
   rep(i,n-1){
     all[2*i]=mpa(X[i+1].first-X[i].first,mpa(X[i].second,X[i+1].second)) ;
     all[2*i+1]=mpa(Y[i+1].first-Y[i].first,mpa(Y[i].second,Y[i+1].second)) ;
    }
   sort(all.begin(),all.end()) ;
   UnionFind uf(n) ;
   ll ans=0 ;
   for(auto g :all){
     if(uf.same(g.second.first,g.second.second)) continue ;
     ans+=g.first ;
     uf.unite(g.second.first,g.second.second) ;
   }
   cout<<ans<<endl ;
   return 0;
  }

Measured memory_bytes: 5376
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,a;
	cin>>n;
	int tab[n+1]={0,0};
	for(int i=2;i<=n;i++){
		tab[i]=0;
		cin>>a;
		tab[a]++;
	}
	for(int i=1;i<=n;i++){
		cout<<tab[i];
		if(i!=n)cout<<endl;
	}
	return 0;
}


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

typedef long long ll;
const int mod = 1e9+7;
ll l,r;
int ans = 0;

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<k;i++){
		l += i;
	}
	for(int i=n;i>n-k;i--){
		r += i;
	}
	for(int i=k;i<=n+1;i++){
		//printf("%d %lld %lld\n",i,l,r);
		int add = (r-l+1)%mod;
		ans = (ans+add)%mod;
		l += i;
		r += n-i;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
int N;int F[100][14];int P[100][15];int  main(){scanf ("%d",&N);for(int i=0;i<N;i++){for(int j=0;j<10;j++) scanf ("%d",&F[i][j]);}for(int i=0;i<N;i++) for(int j=0;j<11;j++) scanf ("%d",&P[i][j]);int  res=-(1<<30);for(int b=1;b<(1 <<10);b++){int cc=0;for(int i=0;i<N;i++){int c=0;for(int j=0;j<10;j++)if((b>>j&1)&&F[i][j])c++;cc+=P[i][c];}if(res <cc)res=cc;}printf ("%d\n",res);}

Measured memory_bytes: 384
main(h,m,s,t,i){for(;scanf("%d%d%d",&h,&m,&s)*-~h;){t=7200-h*3600-m*60-s;for(i=2;i--;t*=3)printf("%02d:%02d:%02d\n",t/3600,t/60%60,t%60);}}

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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int h, n, ans = 0;
  cin >> h >> n;
  int m[4][h];
  rep(i, 0, 4) rep(j, 0, h) m[i][j] = 0;
  rep(i, 0, n) {
    int x, y;
    cin >> x >> y;
    m[x][y] = 1;
  }

  rep(i, 0, h - 1) {
    if(!m[0][i] && !m[1][i] && !m[0][i + 1] && !m[1][i + 1]) {
      m[0][i] = 1, m[1][i] = 1, m[0][i + 1] = 1, m[1][i + 1] = 1;
      ans++;
    }
    if(!m[2][i] && !m[3][i] && !m[2][i + 1] && !m[3][i + 1]) {
      m[2][i] = 1, m[3][i] = 1, m[2][i + 1] = 1, m[3][i + 1] = 1;
      ans++;
    }
    if(!m[1][i] && !m[2][i] && !m[1][i + 1] && !m[2][i + 1]) {
      int k = 0;
      while(!m[0][i + 1 + k] && !m[1][i + 1 + k] && !m[2][i + 1 + k] && !m[3][i + 1 + k]) {
        k++;
      }
      if(!k || k % 2 == 1) {
        m[1][i] = 1, m[2][i] = 1, m[1][i + 1] = 1, m[2][i + 1] = 1;
        ans++;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3296
#include <cstdio>
using namespace std;
int N, Y, x, y, z, t;
int main() {
  scanf("%d %d", &N, &Y);
  for(z = 0; z <= N; z++) {
    for(y = 0; z+y <= N; y++) {
      x = N-z-y;
      t = 10000*x+5000*y+1000*z;
      if(t == Y) break;
    }
    if(t == Y) break;
  }
  if(t != Y) x = y = z = -1;
  printf("%d %d %d", x, y, z);
}

Measured memory_bytes: 128
<?php
while ($line = fgets(STDIN)) {
    $line = rtrim($line);
    $data = explode(" ", $line);

    if ($data[2] < 0 || $data[3] < 0) {
        // ????????¢?????§?¨?(W, H)???????????£??¨???????????§
        // ????????§?¨?(x, y) ???????????´??????No??¨?????????
        echo "No" . PHP_EOL;
    } else {
        if ($data[2] + $data[4] <= $data[0] && $data[3] + $data[4] <= $data[1]) {
            // x + r <= W  ?????? y + r <= H
            echo "Yes" . PHP_EOL;
        } else {
            echo "No" . PHP_EOL;
        }
    }
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N,K;
ll A[200010],sum[200010];

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

  cin>>N>>K;
  rep(i,N)cin>>A[i];

  rep(i,N)sum[i+1]=sum[i]+A[i];

  rep(i,N+1){
    sum[i]=(sum[i]-i+K)%K;
  }
  map<ll,ll> cnt;
  ll res=0;
  rep(i,N+1){
    if(i-K>=0)cnt[sum[i-K]]--;
    res+=cnt[sum[i]];
    cnt[sum[i]]++;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=1000005;
int n,l[N],id[N],cnt[26];
int nd=1,ch[N][26],sz[N];
string s[N];
ll ans;
bool cmp(int x,int y){
	return l[x]<l[y];
}
int main(){
	cin>>n;
	For(i,1,n) cin>>s[i];
	For(i,1,n) l[i]=s[i].length(),id[i]=i;
	sort(id+1,id+n+1,cmp);
	For(i,1,n){
		int x=id[i];
		reverse(s[x].begin(),s[x].end());
		for (auto j:s[x]) ++cnt[j-'a'];
		int p=1;
		for (auto j:s[x]){
			For(k,0,25)	if (cnt[k]) ans+=sz[ch[p][k]];
			if (!ch[p][j-'a']) ch[p][j-'a']=++nd;
			p=ch[p][j-'a']; --cnt[j-'a'];
		}
		++sz[p];
	}
	cout<<ans;
}

Measured memory_bytes: 140832
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
import math
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    r = int(input())
    print(2 * r * math.pi)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 65676
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    H, W = NMI()
    grid = [input() for _ in range(H)]
    L = make_grid(H, W, 0)
    R = make_grid(H, W, 0)
    U = make_grid(H, W, 0)
    D = make_grid(H, W, 0)

    # left
    for h in range(H):
        for w in range(W):
            if grid[h][w] == "#":
                continue
            elif w == 0:
                L[h][w] = 1
            else:
                L[h][w] = L[h][w-1] + 1

    # right
    for h in range(H):
        for w in range(W-1, -1, -1):
            if grid[h][w] == "#":
                continue
            elif w == W-1:
                R[h][w] = 1
            else:
                R[h][w] = R[h][w+1] + 1

    # up
    for w in range(W):
        for h in range(H):
            if grid[h][w] == "#":
                continue
            elif h == 0:
                U[h][w] = 1
            else:
                U[h][w] = U[h-1][w] + 1

    # down
    for w in range(W):
        for h in range(H-1, -1, -1):
            if grid[h][w] == "#":
                continue
            elif h == H-1:
                D[h][w] = 1
            else:
                D[h][w] = D[h+1][w] + 1

    ans = 0
    for h in range(H):
        for w in range(W):
            if grid[h][w] == "#":
                continue
            ans = max(ans, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 180956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> v(n,false);
  rep(i,k) {
    int d;
    cin >> d;
    vi a(d);
    rep(j,d) {
      cin >> a[j];
      a[j]--;
    }
    rep(j,d) v[a[j]] = true;
  }
  int ans = 0;
  rep(i,n) if(!v[i]) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>

const ll INF = pow(10, 9) + 7;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  rep(i,n/2){
    if(s[i] == s[n-i-1]) continue;
    ans++;
  }
  cout << ans << endl;
}

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

int main(){
	int n,k,sum=1;
  	cin>>n>>k;
  	if(n==1)cout<<k<<endl;
  	else {
    	for(int i=1;i<n;++i)sum*=(k-1);
      	cout<<k*sum<<endl;
    }
  	return 0;
}

Measured memory_bytes: 256
pts = [[input().split() for _ in range(8)] for _ in range(3)]
npts = [sorted(pts[i], key=lambda x: float(x[1]))[:4] for i in range(3)]
ts = [sorted((npts[i][j] for i in range(3) for j in range(2, 4)), key=lambda x: float(x[1]))[:2]]
gen = (print(*npts[i][j]) for i in range(3) for j in range(2))
ans = lambda *x: print(*ts[0][0])
ans(*gen)
print(*ts[0][1])

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

int main(void)
{
	const long int MOD = 1E9+7;
	int n, m;
	cin >> n >> m;
	long long int X = 0, Y = 0, a;

	for (int i = 0; i < n; i++) {
		cin >> a;
		X += a*(n-2*i-1);
		X %= MOD;
	}

	for (int i = 0; i < m; i++) {
		cin >> a;
		Y += a*(m-2*i-1);
		Y %= MOD;
	}

	cout << (X*Y)%MOD << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int n,d1,d2,s;
int f[620][620];
void work(int d){
	int p=0;
	while(d%4==0){
		d/=4;
		p++;
	}
	if(d&1){
		for(int i=0;i<2*n;i++)
			for (int j=0;j<2*n;j++)
				if(((i>>p)+(j>>p))&1)
					f[i][j]=1;
	}else{
		for(int i=0;i<2*n;i++)
			for(int j=0;j<2*n;j++)
				if((i>>p)&1)
					f[i][j]=1;
	}
}
int main(){
	scanf("%d%d%d",&n,&d1,&d2);
	work(d1);
	work(d2);
	for(int i=0;i<2*n;i++){
		for(int j=0;j<2*n;j++){
			if(s<n*n && !f[i][j]){
				printf("%d %d\n",i,j);
				s++;
			}
		}
	}
	return 0;
}

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

int main () {
    
    ll p, n; cin >> p >> n;
    ll a[n];
    for(int i = 0; i < n ; i++)
        cin >> a[i];
    
    ll big_dist = 0;

    for(int i = 1; i < n; i++) {
        ll dif = abs(a[i] - a[i-1]);
        if(dif > big_dist) big_dist = dif;
    }
    if((p - a[n-1]) + a[0] > big_dist) big_dist = (p - a[n-1]) + a[0];

    cout << p-big_dist << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
 
signed main(){
    int n;  cin >> n;
    vi a(n), b(n), c(n);
    rep(i, n)cin >> a[i];
    rep(i, n)cin >> b[i];
    rep(i, n)cin >> c[i];

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    
    vi b_sum(n + 1, 0);
    rep(i, n){
        auto c_st = upper_bound(all(c), b[i]);
        if(c_st == c.end())break;
        b_sum[i + 1] = distance(c_st ,c.end());
    }

    loop(i, 1, n + 1)
        b_sum[i] += b_sum[i - 1];


    vi a_sum(n + 1, 0);
    rep(i, n){
        auto b_st = upper_bound(all(b), a[i]);
        if(b_st == b.end())break;
        a_sum[i + 1] = b_sum[n] - b_sum[distance(b.begin(), b_st)];
    }

    loop(i, 1, n + 1)
        a_sum[i] += a_sum[i - 1];
    cout << a_sum[n] << endl;
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
vector<int> v;
vector<char> op;
ll dp[100000][3];
ll calc(int i, int o) {
	if (o == 3)
		return -1e18;
	if (i == n)
		return 0;
	ll &ret = dp[i][o];
	if (ret != -1)
		return ret;
	ret = calc(i + 1, o) + v[i] * (o & 1 ? -1 : 1);
	if (o)
		ret = max(ret, calc(i, o - 1));
	if (v[i] < 0)
		ret = max(ret, calc(i + 1, o + 1) + v[i] * (o & 1 ? -1 : 1));
	return ret;
}
int main()
{
	cin >> n;
	v.resize(n);
	op.resize(n - 1);
	cin >> v[0];
	for (int i = 1; i < n; ++i) {
		cin >> op[i - 1] >> v[i];
		v[i] *= op[i - 1] == '+' ? 1 : -1;
	}
	memset(dp, -1, sizeof(dp));
	cout << calc(1, 0) + v[0] << endl;
	return 0;
}

Measured memory_bytes: 9344
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Set<Integer> set = new HashSet<>();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int a,b;
		for(int i = 0; i < m; i++) {
			a = sc.nextInt();
			b = sc.nextInt();
			if((h[a-1]==h[b-1])) {
				set.add(a-1);
				set.add(b-1);
			}else {
				set.add(h[a-1]<h[b-1]?(a-1):(b-1));
			}
		}
		System.out.println(n-set.size());
	}
}


Measured memory_bytes: 63168
n,m = map(int,input().split())
d = dict()
p = [0]*m
y = [0]*m
c = [0]*m
a = []
for i in range(m):
  p[i], y[i] = map(int,input().split())
  a.append([y[i], i, p[i]])
a.sort()
for x in a:
  if x[2] in d:
    d[x[2]] =  d[x[2]] + 1
  else:
    d[x[2]] = 1
  c[x[1]] = d[x[2]]
for i in range(m):
  print("{0:06d}".format(p[i])+"{0:06d}".format(c[i]))


Measured memory_bytes: 34492
import math
import heapq

n, m =map(int,input().split()) 
a =list(map(int, input().split()))
h =[]
for i in a:
    heapq.heappush(h, i*(-1))


while m >0:
    heru = math.ceil((heapq.heappop(h))/2)
    heapq.heappush(h,heru)
    m = m-1
print((-1)*sum(h))

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

int main(){
    size_t H, W;
    cin >> H >> W;
    cout << string(W + 2, '#') << endl;
    for(size_t i = 0; i < H; ++i){
        string s;
        cin >> s;
        cout << '#' << s << '#' << endl;
    }
    cout << string(W + 2, '#') << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n,m,c,sum,ans;
    ans=0;
    scanf("%d %d %d",&n,&m,&c);
    
    int a[n][m],b[m];
    for(int j=0; j<m; j++)
        scanf("%d",&b[j]);

    for(int i=0; i<n; i++){
        sum=0;
        for(int j=0; j<m; j++){
            scanf("%d",&a[i][j]);
            sum+=b[j]*a[i][j];
        }
        if(sum+c>0)
            ans++;
    }
    printf("%d",ans);
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    public static class Dijkstra {
        Vertex[] g;
        PriorityQueue<Pair> que;
        long[] d;

        public Dijkstra(int n) {
            this.g = new Vertex[n];
            this.d = new long[n];
            this.que = new PriorityQueue<>();

            for (int i = 0; i < n; i++) {
                this.g[i] = new Vertex(i);
            }
            Arrays.fill(this.d, Long.MAX_VALUE / 4);
        }

        public void set(int i, int j, long cost) {
            Vertex u = this.g[i];
            Vertex v = this.g[j];
            u.adj.add(new Edge(cost, v));
            v.adj.add(new Edge(cost, u));
        }

        public void calc(int s) {
            this.d[s] = 0;
            this.que.add(new Pair(0, this.g[s]));

            while (this.que.size() > 0) {
                Pair t = this.que.poll();
                int from = t.now.name;
                List<Edge> toes = t.now.adj;
                if (this.d[from] < t.value) {
                    continue;
                }
                for (Edge e : toes) {
                    int to = e.to.name;
                    long cost = e.w;
                    if (this.d[to] > this.d[from] + cost) {
                        this.d[to] = this.d[from] + cost;
                        this.que.add(new Pair(this.d[to], e.to));
                    }
                }
            }
        }

        public long distance(int g) {
            return this.d[g];
        }
    }

    public static class Edge {
        long w;
        Vertex to;

        public Edge(long w, Vertex to) {
            this.w = w;
            this.to = to;
        }

    }

    public static class Vertex {
        int name;
        List<Edge> adj;

        public Vertex(int name) {
            this.name = name;
            this.adj = new ArrayList<>();
        }

    }

    public static class Pair implements Comparable<Pair> {
        long value;
        Vertex now;

        public Pair(long value, Vertex now) {
            this.value = value;
            this.now = now;
        }

        @Override
        public int compareTo(Pair o) {

            return Long.compare(this.value, o.value);
        }

    }

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        Dijkstra dijkstra = new Dijkstra(N);
        for (int i = 0; i < N - 1; i++) {
            int u = scanner.nextInt() - 1;
            int v = scanner.nextInt() - 1;
            long w = scanner.nextLong();
            dijkstra.set(u, v, w);
        }
        dijkstra.calc(0);

        for (int i = 0; i < N; i++) {
            System.out.println(dijkstra.distance(i) % 2);
        }
    }
}


Measured memory_bytes: 111512
// Marcin Knapik
#include<bits/stdc++.h>
// #pragma GCC optimize("O3")
using namespace std;

typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
typedef long double             ld;

#define boost                   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define szy                     first
#define gi                      second
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define REP(i, a, b)            for (int i = (a); i <= (b); i++)
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define TRAV(i, n)              for(auto&i:n)
#define beg(x)                  (*(x.begin()))
#define re(x)                   int x; cin >>x;   
#define f                       first
#define s                       second

template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const ll T = 1 << 18;
const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1e18 + 7;
const ll  N = (1<<21) + 7;
const int LOG = 21;

ll n, m, k;

signed main(){
    boost;

    cin >> n;
    vi B(n-1);
    cin >> B;
    ll ans = 0;

    int maxi = B[0] + B[n-2];
    for(int i = 1; i < n-1; i++)
    	maxi += min(B[i-1], B[i]);
    cout << maxi;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	ll L, R;
	cin >> L >> R;
	ll ans = 1e9;
	for (ll i = L; i < R; i++)
	{
		for (ll j = i+1; j <= R; j++)
		{
			ans = min(ans, i*j % 2019);
			if (ans == 0)
			{
				cout << ans << endl;
				return (0);
			}
		}
	}
	cout << ans << endl;
}


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

int main() {
  int a;
  cin>>a;
  vector<int> b(a);
  for(int i=0;i<a;i++)
    cin>>b[i];
  int a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0,a8=0,all=0;
  for(int i=0;i<a;i++){
    if(b[i]<400)
      a1=1;
    else if(b[i]<800)
      a2=1;
    else if(b[i]<1200)
      a3=1;
    else if(b[i]<1600)
      a4=1;
    else if(b[i]<2000)
      a5=1;
    else if(b[i]<2400)
      a6=1;
    else if(b[i]<2800)
      a7=1;
    else if(b[i]<3200)
      a8=1;
    else
      all+=1;
  }
  int d;
  d=a1+a2+a3+a4+a5+a6+a7+a8;
  cout<<max(d,1)<<" "<<d+all<<endl;
}

      


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
    int x=0,p=1;char c=getchar();
    while (c<=32)c=getchar();
    if(c==45)p=-p,c=getchar();
    while (c>32)x=x*10+c-48,c=getchar();
    return x*p;
}
using namespace std;
//ruogu
const int N=3500;
int n,mod,a[N],inv[N],inv2[N],res[N];
int dp[N][N];
//
inline int add(int x,int y){x+=y;if(x>=mod)x-=mod;return x;}
inline int sub(int x,int y){x-=y;return (x<0)?x+mod:x;}
inline int mul(int x,int y){int ans=x*y;return ans%mod;}
inline int modpow(int x,int y){
	int ans=1;
	while(y){
		if(y&1)ans=mul(ans,x);
		x=mul(x,x);
		y>>=1;
	}
	return ans;
}
inline int modinv(int x){
	return modpow(x,mod-2);
}
int main(){
	n=getint();mod=n;
	rep(i,n)a[i]=getint();
	rep(i,N)inv[i]=modinv(i);
	rep(i,N)inv2[i]=modinv(sub(0,i));
	dp[n][0]=1;
	for(int i=n-1;i>=0;i--)for(int j=0;j<=n-i;j++){
		dp[i][j]=mul(dp[i+1][j],sub(0,i));
		if(j)dp[i][j]=add(dp[i][j],dp[i+1][j-1]);
		//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
	}
	rep(i,n)if(a[i]){
		int ans=1;
		rep(j,i)ans=mul(ans,inv[i-j]);
		for(int j=i+1;j<n;j++)ans=mul(ans,inv2[j-i]);
		int tmp=0;
		if(!i)tmp=dp[1][0];
        else tmp = mul(dp[0][0], inv2[i]);
		res[0]=add(res[0],mul(tmp,ans));
		for(int j=1;j<n;j++){
			tmp=mul(sub(dp[0][j],tmp),inv2[i]);
			if(!i)tmp=dp[1][j];
			res[j]=add(res[j],mul(tmp,ans));
		}
	}
	rep(i,n)printf("%d ",res[i]);
	return 0;
}


Measured memory_bytes: 43392
#include <bits/stdc++.h>
#define REP(i, n) REPI(i, 0, n)
#define REPI(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)

#define SZ(x) ((int)(x).size())


using ull = unsigned long long;
using ll = long long;
using namespace std;

int main()
{
    ull X, money,n;
    cin >> X;
    money = 100;
    // n = log(X / money) / log(1.01) + 2;
    // cout << n << endl;
    n = 0;
    while (X > money)
    {
        money = money * 1.01;
        n++;
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3620
import collections

n,m=map(int,input().split())
g=[[] for _ in range(n+1)]
for _ in range(m):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
q=collections.deque()
q.append(1)
check=[0]*(n+1)
check[1]=1
ans=[0]*(n+1)
while len(q)!=0:
  v=q.popleft()
  for u in g[v]:
    if check[u]==0: #まだ探索していない頂点について、その頂点に親の頂点に移動する道しるべを置く
      check[u]=1
      ans[u]=v
      q.append(u)
print('Yes')
for i in range(2,n+1):
  print(ans[i])

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

using namespace std; 

int main(){ 
  int h,w;
  cin>>h>>w;
  char data[60][60];

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

for (int j = 0; j <w ; j++) { 

cin >> data[i][j]; 
  data[i+1][j]='.';
  data[i][j+1]='.';
  data[i+1][j+1]='.';

}} 
  
 for(int i=0;i<h;i++){
   for(int j=0;j<w;j++){
     if(data[i][j]=='#'){
       cout<<'#';
       if(j==w-1&&i!=h-1){
         cout<<endl;
       }
     }
     else{
     int ans=0;
     if(data[i-1][j-1]=='#'){
       ans+=1;
     }
       if(data[i-1][j]=='#'){
       ans+=1;
     }
       if(data[i-1][j+1]=='#'){
       ans+=1;
     }
        if(data[i][j+1]=='#'){
       ans+=1;
     }
        
        if(data[i][j-1]=='#'){
       ans+=1;
     }
        if(data[i+1][j+1]=='#'){
       ans+=1;
     }
        if(data[i+1][j]=='#'){
       ans+=1;
     }
        if(data[i+1][j-1]=='#'){
       ans+=1;
     }
     
       cout<<ans;
       if(j==w-1){
         cout<<endl;
       }
     }
     
   }
 }
}

Measured memory_bytes: 256
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (a, b) = listOfInt()
    println(Math.max(Math.max(a+b, a-b), a*b))
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt()= listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37908
import java.util.Scanner;

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

		int n = 0;
		int min = 0;
		int max = 0;
		long sum = 0;

		// n??\???
		n = sc.nextInt ();

		int[] a = new int[ n ];

		// a??\???
		for (int i = 0; i < n; i++ ) {
			a[ i ] = sc.nextInt ();
		}

		// ????¨??????????
		for (int j = 0; j < n; j++ ) {
			sum += a[ j ];
		}

		// ?????§?????\???
		for (int  x = 0; x < n; x++ ) {
			if ( x == 0 ) {
				max = a[ x ];
			} else {
				if ( max < a[ x ] ) {
					max = a[ x ];
				}
			}
		}

		// ????°??????????
		for (int  y = 0; y < n; y++ ) {
			if ( y == 0 ) {
				min = a[ y ];
			} else {
				if ( a[ y ] < min ) {
					min = a[ y ];
				}
			}
		}



		System.out.print ( min + " " + max + " " + sum + "\n" );
	}
}

Measured memory_bytes: 41468