akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f(i,p,n) for(ll i=p;i<n;i++)
#define debug(x) cout<<"["<<#x<<": "<<x<<"]"<<endl
typedef pair<ll,ll> pl;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
ll exp(ll a,ll b,ll m);
 
int main()
{
 ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 /*
 	#ifndef ONLINE_JUDGE
        freopen("/home/savish/Desktop/2019/io/input.txt", "r", stdin);
        freopen("/home/savish/Desktop/2019/io/output.txt", "w", stdout);
    #endif
 */
    ll n,k;
    cin>>n>>k;

    ll dp[k+1]={0};

    ll a[n];
    f(i,0,n) cin>>a[i];

    f(i,0,k)
    {
    	if(dp[i]==1) continue;
    	if(i+a[0]>k) break;

    	f(j,0,n)
    	{
    		if(i+a[j]>k) break;
    		dp[i+a[j]] = 1;
    	}
    }
    if(dp[k]==0)
    {
    	cout<<"Second"<<endl;
    }
    else cout<<"First"<<endl;

    
    
return 0;
}
 
ll exp(ll a,ll b,ll m)
{
	if(b==0)
	{
		return 1;
	}
	ll temp =exp(a,b/2,m);
	temp=(temp*temp)%m;
	if(b&1)
	{
		return (temp*(a%m))%m;
	}
	return temp;
}


Measured memory_bytes: 1024
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"3
4
" => r"5",

r"19
100
" => r"261",

r"10
0
" => r"100"
}

use std::cmp;
use std::collections::HashSet;
use std::f32::MAX;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: i32,
        a: i32,
    }

    (n * n - a).to_string()
}


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

int gcd(int x,int y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rp(i,n) cin >> a.at(i);
    int ans=gcd(a[0],a[1]);
    for(int i=2; i<n; i++){
        ans=gcd(ans,a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

const double pi = 3.14159265358;
int main()
{
	double x = 0.0, y = 0.0, angle = 0.0;

	while(1)
	{
		double walk, turn;
		char cn;
		cin >> walk >> cn >> turn;

		if(!walk && !turn) break;

		x += walk * sin( angle * pi * ((double)1/180) );
		y += walk * cos( angle * pi * ((double)1/180) );

		angle += turn;

	}
	printf("%d\n%d\n", (int)x, (int)y);
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }


int N; ll M; int A[101010];

ll getCount(int tot) {
	ll res = 0;
	rep(i, 0, N) {
		int Ay = tot - A[i];
		int idx = lower_bound(A, A + N, Ay) - A;
		res += N - idx;
	}
	return res;
}

ll As[101010];
ll getSum(int tot) {
	rep(i, 0, N) As[i] = A[i];
	rrep(i, N - 2, 0) As[i] += As[i + 1];

	ll res = 0;
	rep(i, 0, N) {
		int Ay = tot - A[i];
		int idx = lower_bound(A, A + N, Ay) - A;
		int cnt = N - idx;
		res += 1LL * A[i] * cnt;
		res += As[idx];
	}
	return res;
}

void _main() {
	cin >> N >> M;
	rep(i, 0, N) cin >> A[i];
	sort(A, A + N);

	int ok = 0, ng = inf;
	while (ok + 1 != ng) {
		int md = (ok + ng) / 2;
		if (M <= getCount(md)) ok = md;
		else ng = md;
	}

	ll ans = (M - getCount(ok + 1)) * ok + getSum(ok + 1);
	cout << ans << endl;
}







Measured memory_bytes: 1408
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace AtCoderBeginnerContest177
{
    class Program
    {
        static void Main(string[] args)
        {

            // 課題B：Substring(2020/8/29)

            string reStr = Console.ReadLine();
            string str = Console.ReadLine();

            if (reStr.Contains(str))
            {
                Console.Write(0);
                return;
            }

            int minCnt = str.Length;

            for (int i = 0; i < reStr.Length- str.Length+1; i++)
            {
                int cnt = 0;
                for(int j=0; j<str.Length; j++)
                {
                    if(!reStr[i+j].Equals(str[j])) cnt++;
                }

                if (minCnt > cnt) minCnt = cnt;
            }

            Console.Write(minCnt);

        }

    }
}


Measured memory_bytes: 25952
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
using namespace std;

const int INF = 1LL << 60;

static bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) {
    if (p1.second < p2.second) return true;
    if (p1.second == p2.second) return p1.first > p2.first;
    return false;
}

int main() {
    vector<pair<int, int>> vc;
    int n, m;
    cin >> n >> m;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        vc.push_back({y, x});
    }
    sort(vc.begin(), vc.end(), cmp);
    for (int i = 0; i < n && m > 0; i++) {
        if (m > vc[i].first) {
            m -= vc[i].first;
            ans += 1ll * vc[i].first * vc[i].second;
        } else if (m == vc[i].first) {
            m -= vc[i].first;
            ans += 1ll * vc[i].first * vc[i].second;
        } else {
            ans += 1ll * m* vc[i].second;
            m = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
import sys
sys.setrecursionlimit(10**6)

n,v,u = map(int, input().split()); u -= 1; v -= 1
g = [list() for _ in range(n)]
for _ in range(n-1):
  a,b = map(int, input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
dep = [0]*n; mdep = [0]*n; par = [-1]*n

if u == v: print(0); exit(0)

def dfs(v,p):
  for x in g[v]:
    if x == p:
      continue
    par[x] = v
    dep[x] = dep[v] + 1
    dfs(x,v)
    if mdep[v] < mdep[x] + 1:
      mdep[v] = mdep[x] + 1
  return
      
dfs(u,-1)
t = (dep[v]-1)//2
curv = v
for _ in range(t):
  curv = par[curv]
curu = par[curv]
if not dep[v]%2:
  curu = par[curu]
print(t + mdep[curv] + 1 - dep[v]%2)

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

int n;
int order[128][128];
vector<string> t;

//[from, to] not [from, to)
bool check(int x, int from, int to){
  for(int i = from; i <= to; i++){
    if(t[i].size() <= x) continue;

    for(int j = i + 1; j <= to; j++){
      if(t[j].size() <= x) return false;

      char a = t[i][x];
      char b = t[j][x];

      if(a != b && order[a][b] != 0 && order[a][b] == 1){
        return false;
      }
      order[a][b] = -1;
      order[b][a] = +1;
    }
  }

  int i = from;
  while(i <= to && t[i].size() <= x) i++;

  for( ; i <= to; i++){
    int j = i;
    for( ; j <= to && t[i][x] == t[j][x]; j++);
    if(!check(x + 1, i, j - 1)) return false;
    i = j - 1;
  }

  return true;
}

int main(){
  while(cin >> n, n){
    t.clear();

    for(int i = 0; i < n; i++){
      string s;
      cin >> s;
      t.push_back(s);
    }

    memset(order, 0, sizeof(order));

    cout << (check(0, 0, n - 1) ? "yes" : "no") << endl;
  }
}

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

using namespace std;
int main(){
	int H, W;
	int res=0;
	int fail=0;
	char S[55][55];
	cin >> H >> W;
	for(int n=1; n<=H; n++){
		for(int i=1; i<=W; i++)
		cin >> S[n][i];
	}
	for(int n=1; n<=H; n++){
		for(int i=1; i<=W; i++)
		if(S[n][i]=='#'){
			if(S[n+1][i]!='#' &&S[n-1][i]!='#'&& S[n][i+1]!='#'&&S[n][i-1]!='#'){
				fail=1;
			}
		}
	}

if(fail==1){
		cout << "No"<<endl;
	}else {
cout << "Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

string s[2000];
int cnt[2000][2000][4] = {};

int main(){
    int h, w, i, j, res = 0;
    cin >> h >> w;
    for(i=0; i<h; i++){
        cin >> s[i];
    }
    for(i=0; i<h; i++){
        for(j=0; j<w; j++){
            if(s[i][j] == '.'){
                if(i == 0){
                    cnt[i][j][0] = 1;
                }else{
                    cnt[i][j][0] = cnt[i-1][j][0]+1;
                }
                if(j == 0){
                    cnt[i][j][2] = 1;
                }else{
                    cnt[i][j][2] = cnt[i][j-1][2]+1;
                }
            }
        }
    }
    for(i=h-1; i>=0; i--){
        for(j=w-1; j>=0; j--){
            if(s[i][j] == '.'){
                if(i == h-1){
                    cnt[i][j][1] = 1;
                }else{
                    cnt[i][j][1] = cnt[i+1][j][1]+1;
                }
                if(j == w-1){
                    cnt[i][j][3] = 1;
                }else{
                    cnt[i][j][3] = cnt[i][j+1][3]+1;
                }
            }
        }
    }
    for(i=0; i<h; i++){
        for(j=0; j<w; j++){
            res = max(res, cnt[i][j][0] + cnt[i][j][1] + cnt[i][j][2] + cnt[i][j][3] - 3);
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 66816
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int mod=0;
ll gi() {
    ll x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int check(ll a,ll b,ll c,ll d) {
    if(b>a||b>d) return 0;
    ll k=(c-b+1-a)/(__gcd(b,d))+3;
    while(a+1ll*(k-1)*__gcd(b,d)>=c-b+1) --k;
    return a+1ll*k*__gcd(b,d)>=0;
}
void work() {
    ll a,b,c,d;
    a=gi(),b=gi(),c=gi(),d=gi();
    puts(check(a,b,c,d)?"Yes":"No");
}
int main() {
    int T=gi();
    while(T--) work();
    return 0;
}


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

#define ll long long int
#define pb push_back
#define pob pop_back
#define vl vector<ll>
#define mp make_pair
#define sz size()
#define fast ios::sync_with_stdio(0)
#define maxx 100005
#define edge pair<ll,ll>
using namespace std;
 
 
// ¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++¦¦¦++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦¦¦¦¦¦¦¦¦+++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦+++++++¦++¦¦
// ¦¦¦¦¦¦¦¦++¦¦¦¦¦¦++++++¦¦¦¦+++++++++++++¦
// ¦¦¦¦¦¦¦++++++¦¦¦++++++¦¦++++++++++++++¦¦
// ¦¦¦¦¦¦¦+++++++¦¦¦+++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++¦¦¦¦¦¦¦¦+++++++¦ 
// ¦¦¦¦¦¦¦¦¦¦++¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦++++¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦ 
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦+¦++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++¦¦+++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦¦+++¦¦¦¦++++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++¦¦+¦¦¦¦¦+++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦+++++++++++¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦¦¦¦
 
int main()
{
	ll n,t,a,b;
	cin>>n;
	ll ans=0;
	if(n>=500)
	{
		ll x;
		x=n/500;
		ans+=x*1000;
	}
	ll y;
	y=n%500;
	y=y/5;
	ans=ans+y*5;
	cout<<ans<<endl;
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;
	cin>>N;
	vector<int> rabbit(N);
	REP(i,N)cin>>rabbit[i];
	int ans = 0;
	REP(i,N){
		if(rabbit[rabbit[i]] == i)ans++;
	}
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
a_dict = dict()
for _ in range(M):
    a = int(input())
    a_dict[a] = 1

LARGE = 10**9 + 7

r_arr = [0]*(N+1)
r_arr[0] = 1
if a_dict.get(1, 0) == 1:
    r_arr[1] = 0
else:
    r_arr[1] = 1

for i in range(2, N+1):
    if a_dict.get(i, 0) == 1:
        pass
    else:
        r_arr[i] = (r_arr[i-1] + r_arr[i-2]) % LARGE

print(r_arr[-1])


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long double L;
    cin >> L;
    long double d = L / 3;
    long double v = d * d * d;
    cout << setprecision(30) << v << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import heapq
inf = 10**6
n, m = map(int, input().split())

if n >= m:
  print(0)
  sys.exit()

a = [int(x) for x in input().split()]
a.sort()

count = []
heapq.heapify(count)
for i in range(m-1):
  heapq.heappush(count, -a[i+1]+a[i])

ans = 0
for j in range(n-1):
  ans -= heapq.heappop(count)
ans = max(a)-min(a)-ans
print(ans)

Measured memory_bytes: 13960
#include <stdio.h>

int main(void){
	int month, day;
	int dday[12] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
	int answer;
	while(1){
		scanf("%d %d", &month, &day);
		if(month == 0) break;

		answer = (dday[month -1] + day-1) % 7;
		switch(answer){
		case 0:
			puts("Thursday");
			break;
		case 1:
			puts("Friday");
			break;
		case 2:
			puts("Saturday");
			break;
		case 3:
			puts("Sunday");
			break;
		case 4:
			puts("Monday");
			break;
		case 5:
			puts("Tuesday");
			break;
		case 6:
			puts("Wednesday");
		}
	}	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    double l;
    cin>>l;
    printf("%.6f\n",(l/3.0)*(l/3.0)*(l/3.0));
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
count = [0] * N
for i in range(N):
  count[A[i] - 1]  += 1
  
nanimo = 0 
for i in range(N):
  nanimo += count[i] * (count[i] - 1) // 2
for i in range(N):
  tekito = count[A[i] - 1]
  if tekito == 2:
    s = nanimo - 1
  elif tekito == 1:
    s = nanimo
  else:
    s = nanimo -  ((tekito * (tekito - 1) //2) - ((tekito - 1) * (tekito - 2) //2))
  print(s)


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

int is_square(int x){
  int i;
  for(i=0;i*i<=x;i++){
    if(i*i==x){
      return 1;
    }
  }
  return 0;
}

int dist(int *X, int *Y,int D){
  int x=0;
  for(int i=0;i<D;i++){
    x += (X[i]-Y[i])*(X[i]-Y[i]);
  }
  return x;
}

int main()
{
  int N,D,i,j;
  int **X;

  cin >> N >> D;

  X = (int**)malloc(sizeof(int*)*N);
  for(i=0;i<N;i++){
    X[i] = (int *)malloc(sizeof(int)*D);
    for(j=0;j<D;j++){
      cin >> X[i][j];
    }
  }
  int distance,count;
  count = 0;
  for(i=0;i<N;i++){
    for(j=i+1;j<N;j++){
      distance = dist(X[i],X[j],D);
      if(is_square(distance)==1){
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools


class Dice:
    def __init__(self, a, b, c, d, e, f):
        # サイコロの現在一番上にある面
        self.a = a
        self.b = b
        self.c = c
        self.d = d
        self.e = e
        self.f = f

        # 他のダイスと一致したかどうか
        self.result = 0

    def move(self, move_str):
        for i in move_str:
            if i == "N":
                self.move_N()
            elif i == "E":
                self.move_E()
            elif i == "W":
                self.move_W()
            elif i == "S":
                self.move_S()

    def move_N(self):
        tmp1 = self.a
        tmp2 = self.e
        self.a = self.b
        self.b = self.f
        self.e = tmp1
        self.f = tmp2

    def move_E(self):
        tmp1 = self.a
        tmp2 = self.c
        self.a = self.d
        self.c = tmp1
        self.d = self.f
        self.f = tmp2

    def move_W(self):
        tmp1 = self.a
        tmp2 = self.d
        self.a = self.c
        self.c = self.f
        self.d = tmp1
        self.f = tmp2

    def move_S(self):
        tmp1 = self.a
        tmp2 = self.b
        self.a = self.e
        self.b = tmp1
        self.e = self.f
        self.f = tmp2

    def check_one_around(self, dice):
        """チェックのために時計回りに一周させる"""
        for _ in range(4):
            """時計回りに回転"""
            tmp1 = self.b
            tmp2 = self.d
            self.b = self.c
            self.c = self.e
            self.d = tmp1
            self.e = tmp2

            # ダイスが一致しているかチェック
            self.check_dice_same(dice)

    def check_dice_same(self, dice):
        """引数指定したダイスと同一面かチェック"""
        if (
            self.a == dice.a and
            self.b == dice.b and
            self.c == dice.c and
            self.d == dice.d and
            self.e == dice.e and
            self.f == dice.f
        ):
            self.result += 1

    def all_check(self, dice):
        self.clear_result()

        self.check_one_around(dice)
        # b面をトップにする
        self.move("N")
        self.check_one_around(dice)

        # c面をトップにする
        self.move("W")
        self.check_one_around(dice)

        # e面をトップにする
        self.move("W")
        self.check_one_around(dice)

        # d面をトップにする
        self.move("W")
        self.check_one_around(dice)

        # f面をトップにする
        self.move("N")
        self.check_one_around(dice)

    def clear_result(self):
        self.result = 0

n = int(input())

li = []
for _ in range(n):
    a, b, c, d, e, f = map(int, input().split())
    dice = Dice(a, b, c, d, e, f)
    li.append(dice)

# 順列走査
flg = True
for v in itertools.combinations(li, 2):
    v[0].all_check(v[1])
    if v[0].result != 0:
        flg = False
        break

if flg:
    print("Yes")
else:
    print("No")




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

using namespace std;

#define ll long long
#define pb push_back
#define pf push_front
#define loop(i, n) for(int i = 0 ; i < n ; ++i)
#define LOOP(i, a, b) for(int i = a ; i < b ; ++i)
#define max3(a, b, c) max(a, max(b,c))
#define max4(a, b, c, d) max3(a, b, max(c, d))
#define ff first
#define ss second
#define mkp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vvii vector<vii>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define nmbr(c) (int)(c-'0')
#define ltr(c) (int)(c-'a')
#define INF 1e18
#define inf 1e9
#define MOD 1000000007 //check
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

ll n, st[1000000], h[200005], b[200005], ind[200005], dp[200005], res = 0;
ll left(ll x){return 2*x;}
ll right(ll x){return 2*x+1;}
pll P[200005];
ll compare(pll p1, pll p2) 
{ 
    if (p1.first == p2.first)  
        return p1.second < p2.second; 
    return p1.first < p2.first; 
} 

void update(ll p, ll l, ll r, ll t, ll v)
{
	if(l == r)
	{
		 st[p] = v;
		 return;
	}
	ll m = l + (r-l)/2;
	if(t < m) update(left(p), l, m, t, v);
	else update(right(p), m+1, r, t, v);
	st[p] = max(st[left(p)], st[right(p)]);
}

ll query(ll p, ll l, ll r, ll i, ll j)
{
	if(r < i || l > j) return -1;
	if(r <= j && l >= i) return st[p];
	ll m = l + (r-l)/2;
	return max(query(left(p), l, m, i, j), query(right(p), m+1, r, i, j));
}

void LIS(ll x)
{
	if(x == n) return;
	ll &ans = dp[x];
	if(ans != -1) return;
	ll mx = query(1, 0, n-1, 0, P[x].ss);
	ans = mx+b[P[x].ss];
	update(1, 0, n-1, P[x].ss, ans);
	res = max(res, ans);
	LIS(x+1);
}
int main() {
	_69e27;
	memset(st, 0, sizeof(st));
	memset(dp, -1, sizeof(dp));
	cin >> n;
	loop(i, n) cin >> h[i];
	loop(i, n) cin >> b[i];
	loop(i, n)
	{
		P[i].ff = h[i];
		P[i].ss = i;
	}
	sort(P, P+n, compare);
	loop(i, n) ind[P[i].ss] = i;
	LIS(0);
	cout << res;
	return 0;
}

Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define rep(i, a, b) for(re int i = (a); i <= (b); ++ i)
#define drep(i, a, b) for(re int i = (b); i >= (a); -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define int long long
#define D double
#define inf 1023456789
#define mod 1000000007
#define lb(x) (x)&(-(x))
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005
namespace Graph {
	int head[maxn], cnt;
	struct edge { int v, next; }e[maxn << 1];
	il void add(int u, int v) { e[++ cnt] = (edge){v, head[u]}, head[u] = cnt; }
}
//using namespace Graph;
int n, m, ans, a[maxn];
char c[maxn];
signed main() {
	n = ans = read(), m = read();
	rep(i, 1, m) {
		int x = read();
		rep(j, 1, x) {
			int y = read();
			if(!a[y]) a[y] = 1, -- ans;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3644
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int[][] map;
	int w, h;
	int sx, sy, gx, gy;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			w = sc.nextInt();
			h = sc.nextInt();
			if( (w|h) == 0 ) break;
			map = new int[h+2][w+2];
			sx = sc.nextInt();
			sy = sc.nextInt();
			gx = sc.nextInt();
			gy = sc.nextInt();
			int n = sc.nextInt();
			for(int i=0;i<n;i++) {
				int c = sc.nextInt();
				int d = sc.nextInt();
				int x = sc.nextInt();
				int y = sc.nextInt();
				for(int j=x;j<(d==0? x+4:x+2);j++) for(int k=y;k<(d==0? y+2:y+4);k++) 
					map[k][j] = c;
			}
//			for(int[] a: map) debug(a);
			if(bfs()) System.out.println("OK");
			else System.out.println("NG");
		}
	}
	int dx[] = {-1,0,1,0};
	int dy[] = {0,-1,0,1};
	
	boolean bfs() {
		LinkedList<P> que = new LinkedList<P>();
		boolean visited[][] = new boolean[h+2][w+2];
		if(map[sy][sx] == 0) return false;
		que.add(new P(sx, sy, 0));
		for(;!que.isEmpty();) {
			P now = que.removeFirst();
//			debug(now.x, now.y, now.c);
			if(now.x == gx && now.y == gy) return true;
			for(int i=0;i<4;i++) if(!visited[now.y+dy[i]][now.x+dx[i]] && map[now.y+dy[i]][now.x+dx[i]]==map[now.y][now.x]){
				visited[now.y+dy[i]][now.x+dx[i]] = true;
				que.add(new P(now.x+dx[i], now.y+dy[i],now.c+1));
			}
		}
		
		return false;
	}
	
	class P {
		int x, y, c;
		P(int x, int y) {
			this.x = x;
			this.y = y;
			c=0;
		}
		P(int x, int y, int c) {
			this.x = x;
			this.y = y;
			this.c = c;
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

// 入力
const int DEBUG = 0;
int N, C[409], S[409][409];

// 出力
int Last[409];
int Answer[409];

int solve(int pos) {
	pair<int, int> maxn = make_pair(-(1 << 30), -1);
	for (int i = 1; i <= 26; i++) {
		int score = S[pos][i];
		for (int j = 1; j <= 26; j++) {
			if (i != j) score -= C[j] * (pos - Last[j]);
		}
		maxn = max(maxn, make_pair(score, i));
	}
	return maxn.second;
}

int getscore(vector<int> vec) {
	for (int i = 1; i <= 26; i++) Last[i] = 0;
	int t = 0;
	for (int i = 0; i < vec.size(); i++) {
		Last[vec[i]] = i + 1; t += S[i + 1][vec[i]];
		for (int j = 1; j <= 26; j++) t -= C[j] * ((i + 1) - Last[j]);
	}
	return t;
}

int main() {
	if (DEBUG == 0) {
		cin >> N;
		for (int i = 1; i <= N; i++) cin >> C[i];
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= 26; j++) cin >> S[i][j];
		}
	}
	else {
		N = 365;
		for (int i = 1; i <= N; i++) C[i] = rand() % 101;
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= 26; j++) S[i][j] = ((rand() % 32768) * 32768 + (rand() % 32768)) % 20001;
		}
	}

	// Step #2. 貪欲法で初期解を求める
	for (int i = 1; i <= N; i++) {
		Answer[i] = solve(i);
		Last[Answer[i]] = i;
	}

	// Step #3. 山登り法を使ってより良い解を求める
	vector<int> R;
	for (int i = 1; i <= N; i++) R.push_back(Answer[i]);

	int CurrentMax = getscore(R);
	for (int t = 1; t <= 80000; t++) {
		if (rand() % 10 < 5) {
			int v1 = rand() % (N - 1);
			swap(R[v1], R[v1 + 1]);
			int CandMax = getscore(R);
			if (CurrentMax <= CandMax) { CurrentMax = CandMax; }
			else { swap(R[v1], R[v1 + 1]); }
		}
		else {
			int v1 = rand() % N, v2 = rand() % 26 + 1;
			int moto = R[v1];
			R[v1] = v2;
			int CandMax = getscore(R);
			if (CurrentMax <= CandMax) { CurrentMax = CandMax; }
			else { R[v1] = moto; }
		}
	}
	for (int i = 1; i <= N; i++) cout << R[i - 1] << endl;
	return 0;
}

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

inline int read(){
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
} 

int k, n, m;

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    //freopen(".in","r",stdin);
	//freopen(".out","w",stdout); 
	
	cin >> k >> n >> m;
	
	for(int i=n; i<=m; i++){
		if(i%k==0){
			cout << "OK";
			return 0;
		}
	}
	
	cout << "NG";
	 
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M;
    cin >> N >> M;

    vector<ll> A(N);
    map<ll, ll> B;

    int b = 0;
    B[0]++;

    for(int i = 0; i < N; i++) {
        cin >> A[i];
        b += A[i];
        b %= M;
        B[b]++;
    }

    ll count = 0;

    for(auto i = B.begin(); i != B.end(); i++) {
        //cerr << i -> first << " " << i -> second << endl;
        count += i -> second * (i -> second - 1) / 2;
    }

    cout << count << endl;
}

Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>

int main()
{
	double a, b, c, d, e, f;
	double x, y;
	while (std::cin >> a >> b >> c >> d >> e >> f)
	{
		y = (a*f - c*d) / (a*e - b*d);
		x = (c - b*y) / a;
		printf("%.3lf ", x);
		printf("%.3lf\n", y);
	}
	return 0;
}

Measured memory_bytes: 1236
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    d = list(map(int, readline().split()))
    d.sort()
    t = [d[0]]
    s = min(24 - d[0], d[0])

    for i in range(1, n):
        cur = d[i]
        am = cur
        pm = 24 - cur
        s_am = s
        s_pm = s
        for j in range(i):
            prev = t[j]
            s_am = min(s_am, min(24 - abs(am - prev), abs(am - prev)))
            s_pm = min(s_pm, min(24 - abs(pm - prev), abs(pm - prev)))

        if s_am > s_pm:
            t.append(am)
            s = s_am
        else:
            t.append(pm)
            s = s_pm

    print(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 64372
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;
        while(k!=0&&a!=0)
        {
            sum=sum+1;
            a--;
            k--;
        }
        while(k!=0&&b!=0)
        {
            sum=sum+0;
            b--;
            k--;
        }
        while(k!=0&&c!=0)
        {
            sum=sum-1;
            c--;
            k--;
        }
        cout<<sum<<endl;

}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
double a, b, x, pi = 3.141592653589793238;cin >> a >> b >> x;

if(x >= a*a*b/2){
double left = 0, right = 90;

    while(right - left > pow(10, -12)){

    double d = right - (right - left)/2,
    V = a*a*(2*b - a*tan(d*pi/180))/2;

    if(V > x)left = d;

    if(V <= x)right = d;

    }

cout << fixed << setprecision(10) << right - (right - left)/2;
exit(0);

}

else{

double left = 0, right = 90;

    while(right - left > pow(10, -10)){

    double d = right - (right - left)/2,
    V = a*b*b*tan(pi/2 - d*pi/180)/2;

    if(V > x)left = d;

    if(V <= x)right = d;

    }

cout << fixed << setprecision(10) << right - (right - left)/2;
exit(0);

}
}


Measured memory_bytes: 4056
#include <iostream>

using namespace std;

int main()
{
	string s;
	int n;

	cin >> n;
	cin >> s;
	
	int count = 0;
	int max_count = 0;

	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'D')
		{	
			count--;
		}
		else
		{
			count++;
		}

		if(count > max_count)
		{
			max_count = count;
		}
	}

	cout << max_count;		
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
 
 
int main()
{ int n,i,sum=0; scanf("%d",&n); int A[n];
for(i=0;i<n;i++){scanf("%d",&A[i] ); sum=sum^A[i];  }
if(sum!=0){printf("No"); return 0;}
 printf("Yes");
 
 
 
return 0;
}


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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    int n;
    cin >> n;
    cout << (n + 1) / 2 - 1 << '\n';
    return 0;
}

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

typedef long long ll;
int isPrime[55556];
vector<int> primes;

void sieve()
{
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;
    for(ll i = 2; i < 55556; i++)
        if(isPrime[i])
        {
            for(ll j = i*i; j < 55556; j += i)
                isPrime[j] = 0;
            primes.push_back(i);
        }
}

int main() 
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    sieve();
    int n;
    while(cin >> n)
    {
        for(int i = 0, k = 0; k < n && i < primes.size(); i++)
            if(primes[i] % 10 == 1)
            {
                cout << " " << primes[i];
                k++;
            }
        cout << '\n';
    }
    return 0;
}

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

const ll lim =1e+18;
int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    bool fl=false;
    rep(i,n) {
        cin>>a[i];
        if(a[i]==0) fl=true; 
    }
    if(fl){
        cout<<0<<endl;
        return 0;
    }

    ll ans=1;

    rep(i,n){
        ll tans = ans;
        bool fl=true;
        if(lim%ans==0&&a[i]==lim/ans){
            fl =false;
        }
        if(fl){
            if(a[i] > lim/ans){
                cout<<-1<<endl;
                return 0;
            }
        }
        ans = a[i]*ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	ll num, i, ans = 0;
	cin >> num;
	for (i = 1; i < num; i++) {
		ans += num / i;
		if (num % i == 0)
			ans--;
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

int main(void){
    long long X;
    cin >> X;
    long long ans = 0;
    ans += (X / 500) * 1000;
    X %= 500;
    ans += (X / 5) * 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    long A,B;
    long ans;
    cin >> A >> B;
    ans=A+B;
    if (ans%2==0) {
        ans=ans/2;
        cout << ans;
    }else{
        cout << "IMPOSSIBLE"<< endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from heapq import heappush, heappop
INF = float("inf")


def main():
    K = int(input())
    graph = defaultdict(list)
    for i in range(K):
        graph[i].append((1, (i + 1) % K))
        graph[i].append((0, (i * 10) % K))

    cost = [INF] * K
    cost[1] = 1
    que = deque()
    que.appendleft(1)
    while len(que) != 0:
        now = que.popleft()

        for c, node in graph[now]:
            new_cost = cost[now] + c
            if new_cost < cost[node]:
                cost[node] = new_cost
                if c == 0:
                    que.appendleft(node)
                else:
                    que.append(node)

    print(cost[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 43924
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif
#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;
const int MOD=1e9+7;
const int INF=1<<29;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
const int N=1e5+11;
using ii= pair<int,int>;
vector<ii> g[N];
int color[N],n;
void dfs(int curr,int c){
  color[curr]=c;
  for(auto it:g[curr]){
	    if(color[it.f]!=-1)continue;
	    if(it.s&1)dfs(it.f,c^1);
	    else dfs(it.f,c); 
	 }	
}
void init(){
  for(int i=0;i<N;i++)color[i]=-1;
}
void solve(){
	init();
	cin>>n;
	for(int i=0;i<n-1;i++){
		int u,v,w;
		cin>>u>>v>>w;
		--u,--v;
		g[u].push_back({v,w});
		g[v].push_back({u,w});
	}
	dfs(0,0);
	for(int i=0;i<n;i++)cout<<color[i]<<endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
    IOS;
    solve();
    #ifdef LOCAL_DEFINE
    cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
    #endif
}


Measured memory_bytes: 10240
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define con_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define con_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);

int main(){
    int n,d=0,x;
    cin>>n;
    vector<pair<string,int>> vec(n);
    string s,t;
    rep(i,n){
        cin>>t>>x;
        vec[i]=make_pair(t,x);
    }
    cin>>s;
    int ans=0;
    rep(i,n){
        if(d==1){
            ans+=vec[i].second;
        }
        if(vec[i].first==s){
            d=1;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    string s;cin >> s;
    ll bc=0,res=0;
    rep(i,s.size()){
        if(s[i]=='B')bc++;
        else res+=bc;
    }
    cout << res <<endl;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

void trace(int A[],int N){
    REP(i,N){
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}


int main(){
    string s,t;
    cin >> s >> t;
    if(s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0])cout<<"YES"<<endl;
    else cout << "NO" <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int a[3005];

int main(){

	int N;

	scanf("%d",&N);

	int i;

	for(i=0;i<N;i++){
	scanf(" %d",&a[i]);
	}

	int ans=0;

	for(i=0;i<N;i++){
	ans+=a[i]-1;
	}

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

	return 0;
}

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

int main(void){
  int y1, y2;
  int ind = 0;
  while(1){
    cin >> y1 >> y2;
    if(!(y1 | y2)){
      break;
    }
    if(ind == 0){
      ind++;
    }else{
      cout << endl;
    }

    int cnt = 0;

    for(int i=y1; i <= y2; i++){
      if(i%4 == 0){
	if(i%100 == 0){
	  if(i%400 == 0){
	    cout << i << endl;
	    cnt++;
	    continue;
	  }else{
	    continue;
	  }
	}else{
	  cout << i << endl;
	  cnt++;
	}
      }else{
	continue;
      }
    }
    if(cnt == 0)
      cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>

#define N 100

static const int white = 0;
static const int gray = 1;
static const int brack = 2;

void dfs(int);
void visit(int,int);

int A[N][N],color[N],time,d[N],f[N];


int main()
{
  int n,i,j,u,k,v;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j] = 0;
    }
  }
    for(i=0;i<n;i++){
      scanf("%d %d",&u,&k);
      u--;
      for(j=0;j<k;j++){
	scanf("%d",&v);
	v--;
	A[u][v] = 1;
      }
    }
    //printf("%d",n);
    dfs(n);

    return 0;

  }

void dfs(int n)
{
  int u;

  for(u=0;u<n;u++){
    color[u] = white;
  }
  time = 0;
  for(u=0;u<n;u++){
    if(color[u] == white) visit(u,n);
  }

  for(u=0;u<n;u++) printf("%d %d %d\n",u+1,d[u],f[u]);
 
}

void visit(int u,int n)
{
  int v;

  color[u] = gray;
  d[u] = ++time;

  for(v=0;v<n;v++){
    if(A[u][v] == 0) continue;
    if(color[v] == white) visit(v,n);
  }
  color[u] = brack;
  f[u] = ++time;
}


    



Measured memory_bytes: 2104
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;
 
int parent[N];
 
int gcd(int a, int b) { 
    if (a == 0) 
        return b;  
    return gcd(b%a, a);  
} 
   
int lcm(int a, int b) {  
    return (a*b)/gcd(a,b);  
} 
 
ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}
 
int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}
 
void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}
 
ll nCr(ll n, ll r) {
    ll res = 1;
    for(ll i=1;i<=r;i++) {
        res = res * (n - r + i) / i;
        // is different from
        // res *= (n -r + i) / i;
    }
    return res;
}
 
int ask(int i, int j) {
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    int v;
    cin >> v;
    return v;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    ll mx = a[0];
    ll res = 0;
    for(int i=1;i<n;i++) {
        if(a[i] < mx) {
            res += mx - a[i];
        }
        mx = max(mx, a[i]);
    }
    cout << res << endl;
    return;
} 
 
int main()
{
    IOS
    //int t;
    //cin >> t;
    //while(t--) 
    solve();
    return 0; 
}

Measured memory_bytes: 4756
import std.stdio, std.algorithm;

void main() {
    int A, B, C, D, P;
    scanf("%d\n", &A);
    scanf("%d\n", &B);
    scanf("%d\n", &C);
    scanf("%d\n", &D);
    scanf("%d\n", &P);
    writeln( min(A * P, B + D * max(0, P - C)) );
}

Measured memory_bytes: 1040
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int n = s.nextInt();
        int m = s.nextInt();
        long k = s.nextLong();
        long [] arr =new long[n];
        long [] brr = new long[m];
        long [] prearr =new long[n];
        long [] prebrr = new long[m];
        for(int i=0;i<n;i++)
            arr[i]=s.nextLong();
        prearr[0]=arr[0];
        for(int i=1;i<n;i++)
            prearr[i]+=(arr[i]+prearr[i-1]);
        for(int i=0;i<m;i++)
            brr[i]=s.nextLong();
        prebrr[0]=brr[0];
        for(int i=1;i<m;i++)
            prebrr[i]+=(brr[i]+prebrr[i-1]);
        long res =0;
        long max=0;
        long temp;
        int flag=0;
        for(int j=0;j<m;j++){
            if(k<prebrr[j]){
                max+=j;
                flag=1;
                break;
            }
        }
        if(flag==0)
            max=m;

        for(int i=0;i<n;i++){
            res=i+1;
            temp=k-prearr[i];
            if(temp<0)
                break;
            res+=(binary_search(prebrr,0,m-1,temp)+1);
            if(max<res)
                max=res;
        }
        System.out.println(max);
    }

    private static int binary_search(
            long arr[], int l,
            int h, long x)
    {
        while (l <= h) {
            int mid = (l + h) / 2;
            if (arr[mid] <= x)
                l = mid + 1;
            else
                h = mid - 1;
        }
        return h;
    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 70492