akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n: usize,
        mut a: [u64; n],
    }
    let mut b = VecDeque::new();
    if n % 2 == 0 {
        for i in 0..n {
            if i % 2 == 0 {
                b.push_back(a[i]);
            } else {
                b.push_front(a[i]);
            }
        }
    } else {
        for i in 0..n {
            if i % 2 == 0 {
                b.push_front(a[i]);
            } else {
                b.push_back(a[i]);
            }
        }
    }

    for b_ in b.iter() {
        print!("{} ", b_);
    }
    println!("");
}


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

const int MAXN = 1e5 + 10;
int n, a[MAXN], ans;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int j = 0, f = 0;
	for (int k = 1; k < MAXN; k++) {
		while (j < n && a[j] < k)
			f++, j++;
		if (f == n / 2)
			ans++;
	}
	cout << ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using LL = long long;
const LL MOD = 1e9+9;
using namespace std;



int main(){
    int N,M;cin >> N >> M;
    vector<int> vec;
    for(int a = 0;a< M;a++){
        int b;cin >> b;
        vec.push_back(b);
    }
    sort(vec.begin(),vec.end());
    vector<int> diff;
    for(int a = 0;a< M-1;a++){
        diff.push_back(abs(vec.at(a)-vec.at(a+1)));
    }
    sort(diff.begin(),diff.end());
    reverse(diff.begin(),diff.end());
    LL sum = vec.back()-vec.front();
    for(int a = 0;a < min(N-1,(int)diff.size());a++){
        sum -= diff.at(a);
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string n;
    cin >> n;
    REP(i, n.size()) {
        if(n[i] == '1') cout << 9;
        else cout << 1;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy

n, m = input().split(" ")
n = int(n)
m = int(m)

h_list = input().split(" ")
h_list = numpy.array(list(map(int, h_list)))

edges = {} # key -> tower_id, value, connected_tower_id

for i in range(m):
  s, e = input().split(" ")
  s = int(s) - 1
  e = int(e) - 1

  if s not in edges:
    edges[s] = set()
  edges[s].add(e)
  
  if e not in edges:
    edges[e] = set()
  edges[e].add(s)

isolated_tower_num = n - len(edges.keys())

good_tower_num = 0
for t_idx in edges.keys():
  connected_towers = list(edges[t_idx])
  t_height = h_list[t_idx]
  connected_highest_height = max(h_list[connected_towers])
  if t_height > connected_highest_height:
    good_tower_num += 1

print(good_tower_num+isolated_tower_num)


Measured memory_bytes: 60924
#include<bits/stdc++.h>
using namespace std;
int cnt[65][65],cnt2,cnt5;
long long ans,tmp;
int main(){
	double x;int n;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>x;
		tmp=llround(x*1e9);
		//cout<<tmp<<endl;
		cnt2=cnt5=0;
		while(tmp%2==0) ++cnt2,tmp/=2;
		while(tmp%5==0) ++cnt5,tmp/=5;
		for(int j=0;j<=64;++j)
			for(int k=0;k<=64;++k)
				if(cnt2+j>=18 && cnt5+k>=18)ans+=cnt[j][k];
		cnt[cnt2][cnt5]++;
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 3784
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<int,int> P;
struct edge{ int to,cost; };
#define VMAX 100000
//bool cmp(P a,P b){ return a.second < b.second;}

ll N,M,ans=0;
ll A,B,S[52];


int main(){
	std::ios_base::sync_with_stdio(false);
	cin>>A>>B;
	if(A%2==0){
		ans=(((B-A+1)/2)%2);
		if((B-A+1)%2==1)ans^=B;
	}else{
		ans=((B-A)/2)%2;
		ans^=A;
		if((B-A)%2==1)ans^=B;
	}



	cout<<ans<<endl;
	return 0;
}
//ABC 121 D - XOR World

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;

namespace at_coder
{
#if TEST
    [TestClass]
#endif
    public class Test_164_a
    {

#if TEST
        public static void Test_Main()
#else
        public static void Main()
#endif
        {
            int s, w;
            ReadInt(out s, out w);
            if (w >= s)
            {
                Write("unsafe");
            }
            else
            {
                Write("safe");
            }
        }


        private static void Write(string s)
        {
            Console.WriteLine(s);
        }

        private static int[] ReadIntArray()
        {
            string[] ss = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int[] ar = new int[ss.Length];
            for (int i = 0; i < ss.Length; i++)
            {
                ar[i] = int.Parse(ss[i]);
            }
            return ar;
        }
        private static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static void ReadInt(out int a, out int b)
        {
            var ar = ReadIntArray();
            a = ar[0];
            b = ar[1];
        }
        private static void ReadInt(out int a, out int b, out int c)
        {
            var ar = ReadIntArray();
            a = ar[0];
            b = ar[1];
            c = ar[2];
        }
        private static string ReadString()
        {
            return Console.ReadLine();
        }
        private static string[] ReadStringArray()
        {
            string[] ss = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            return ss;
        }
#if !TEST
    }
}
#endif


Measured memory_bytes: 27532
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
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 drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#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
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;

int dist[100010][3];

int main(void){

    int n,m;
    cin>>n>>m;
    vvi v(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a].push_back(b);
    }
    int sv,tv;
    cin>>sv>>tv;
    sv--;tv--;
    rep(i,n)rep(h,3)dist[i][h]=INF;
    dist[sv][0]=0;
    queue<pair< int,int>> q;
    q.push(mp(sv,0));
    while(!q.empty()){
        int a=q.front().first;//場所
        int b=q.front().second;//状態
        q.pop();
        for(int i=0;i<v[a].size();i++){
            if(dist[v[a][i]][(b+1)%3]!=INF)continue;
            q.push(mp(v[a][i],(b+1)%3));
            dist[v[a][i]][(b+1)%3]=dist[a][b]+1;
        }
    }
    int ans=dist[tv][0];
    ans/=3;
    if(ans==INF/3)ans=-1;
    if(sv!=tv&&ans==0)ans=-1;
    fin(ans);

    // rep(i,n){rep(j,3){
    //     cout<<dist[i][j]<<" ";
    // }cout<<endl;
    // }

}

Measured memory_bytes: 6912
<?php
  
while ($line = fgets(STDIN)) {
   $stdin[] = trim($line);
}
#$v2 = str_split($stdin[0]);
$v2 = explode(" ", $stdin[0]);

#var_dump($v2);

$renzoku = $v2[0];
$kuro = $v2[1];

for($i = $kuro; $i < $kuro + $renzoku; $i++){
  #if($i > 100 || $i < 0){
  #  continue;
  #}
  
  
  $res[] = $i;
}

for($i = $kuro; $i > $kuro - $renzoku; $i--){
  #if($i > 100 || $i < 0){
  #  continue;
  #}
  $res[] = $i;
}

sort($res);
$res = array_unique($res);
#var_dump($res);

$ans = implode(" ", $res);





echo $ans . PHP_EOL;



Measured memory_bytes: 3828
// C++ program to count common subsequence in two strings
#include<iostream>
#include<string>
#define MOD 1000000007
using namespace std; 
  
/*// return the number of common subsequence in two strings
int Count_Commom_Subsequences(int s[n],int t[m],int n1,int n2)
{ 
    long long dp[n1+1][n2+1]; 
  
    for(int i=0;i<=n1;i++){
        for(int j=0;j<=n2;j++){
            dp[i][j] = 0;
        }
    }
  
    // for each character of S 
    for(int i=1;i<=n1;i++){
        // for each charcater in T
        for(int j=1;j<=n2;j++){
            // if character are same in both
            // the string
            if(s[i-1]==t[j-1])
                dp[i][j]=1+dp[i][j-1]+dp[i-1][j];
            else 
                dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1];
        }
    }
    return dp[n1][n2];
}*/
  
// Driver Program 
int main(){
  int n,m;
  cin>>n>>m;
  int s[n],t[m];
  for(int i=0;i<n;i++)cin>>s[i];
  for(int j=0;j<m;j++)cin>>t[j];
  int n1=n;
  int n2=m;
    long long dp[n1+1][n2+1]; 
  
    for(int i=0;i<=n1;i++){
        for(int j=0;j<=n2;j++){
            dp[i][j] = 0;
        }
    }
  
    // for each character of S 
    for(int i=1;i<=n1;i++){
        // for each charcater in T
        for(int j=1;j<=n2;j++){
            // if character are same in both
            // the string
            if(s[i-1]==t[j-1]){
              dp[i][j]=1+dp[i][j-1]+dp[i-1][j];
              dp[i][j]%=MOD;
            }
            else 
                dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1];
          dp[i][j]=(dp[i][j]%MOD+MOD)%MOD;
        }
    }
    cout<<(dp[n1][n2]+1)%MOD<<endl;
    return 0; 
} 



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

int main() {

  int N;
  std::cin >> N;

  int A[200'000];

  long long int sum = 0;
  long long int max = 0;

  for (int i=0; i<N; ++i) {
    int t = 0;
    std::cin >> t;
    max = std::max(max, (long long int) t);
    sum += max - t;
  }

  std::cout << sum << std::endl;

  return 0;

}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
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;
}
 
using namespace std;

void solve(){
  int n;
  cin>>n;
  vector<ll>r(n),c(n);
  rep(i,n)cin>>r[i]>>c[i];
  vector<vector<ll>>dp(n+1,vector<ll>(n+1,INF));
  rep(i,n)dp[i][i+1]=0;
  REP(w,2,n+1){
    rep(i,n){
      int j=i+w;
      if(j>n)continue;
      for(int k=i+1;k<j;++k){
        chmin(dp[i][j],dp[i][k]+dp[k][j]+r[i]*r[k]*c[j-1]);
      }
    }
  }
  cout<<dp[0][n]<<"\n";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}



Measured memory_bytes: 3212
#include <iostream>
using namespace std;
int main(){
  char c;
  cin >> c;
  if(c == 'A')cout << 'T' << endl;
  if(c == 'T')cout << 'A' << endl;
  if(c == 'G')cout << 'C' << endl;
  if(c == 'C')cout << 'G' << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <numeric> 
 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define int long long int
#define mod 1000000007
#define INT_BITS 16
#define test int t;cin>>t;while(t--)
#define INF 10000000
#define pi 3.141592
#define watch(x) cout<<(#x)<<"="<<(x)<<"\n" 
#define pb push_back
//#include "debug.cpp"
//__builtin_popcount


#define MAXN   2000001 
  
// stores smallest prime factor for every number 
int spf[MAXN]; 
int check[MAXN];
// Calculating SPF (Smallest Prime Factor) for every 
// number till MAXN. 
// Time Complexity : O(nloglogn) 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}

void getFactorization(int x) 
{ 
    set<int>st;
    while (x != 1) 
    { 
        st.insert(spf[x]);
        //check[spf[x]]++;
        x = x / spf[x]; 
    } 

    for(auto x:st)
        check[x]++;
     
} 

int32_t main()
{
    fast
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    sieve();
    int n;
    cin>>n;
    int a[n];
    memset(check,0,sizeof(check));
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        getFactorization(a[i]);
    }

    int sw=1;
    int pw=1;
    //watch(check[2]);
    for (int i = 2; i < MAXN; ++i)
    {
        if(check[i]>=n)
        {
            sw=0;
        }
        if(check[i]>1)
        {
            pw=0;
        }
    }

    if(pw==1)
        cout<<"pairwise coprime"<<endl;
    else
    {
        if(sw==1)
            cout<<"setwise coprime"<<endl;
        else
            cout<<"not coprime"<<endl;
    }


    

}


Measured memory_bytes: 42644
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.1415926535
 
int main() 
{
  FAST;
  string s;
  cin>>s;
  ll n=s.length();
  bool b=1;
  for(int i=0,j=n-1;i<j;i++,j--)
    if(s[i]!=s[j])
      	b=0;
  for(int i=0,j=((n-1)/2)-1;i<j;i++,j--)
    if(s[i]!=s[j])
      	b=0;
  for(int i=((n-1)/2)+1,j=n-1;i<j;i++,j--)
    if(s[i]!=s[j])
      	b=0;
  if(b)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  var A = intShift();
  var B = strShift();
  
  var s = 0;
  
  var o = [];
  
  for(var i = 0; i < A; i++){
  	if(B[i] == ".")s++;
  }
  o.push(s);
  for(var i = 0; i < A; i++){
  	if(B[i] == "."){
    	s--;
    }else{
    	s++;
    }
    o.push(s);
  }
  
  return ~~o.reduce((a,b)=>a<b?a:b);
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
5
#.##.
`);

Measured memory_bytes: 13496
class Dice:
    def __init__(self, top, dside):
        self.top = top
        self.dside = dside
        self.rside = None
        self.num = [self.top, self.dside, 7-self.top, 7-self.dside]
    def rside_num(self):
        if 2 in self.num and 3 in self.num:
            if(self.num.index(3)==self.num.index(2)+1 or 
                self.num==[3, 5, 4, 2]):
                self.rside = 1
            else:
                self.rside = 6
        elif 1 in self.num and 4 in self.num:
            if(self.num.index(4)==self.num.index(1)+1 or 
                self.num==[4, 6, 3, 1]):
                self.rside = 2
            else:
                self.rside = 5
        else:
            if(self.num.index(2)==self.num.index(1)+1 or
                self.num==[2, 6, 5, 1]):
                self.rside = 3
            else:
                self.rside = 4

num = list(map(int, input().split()))
n = int(input())
for i in range(n):
    value = list(map(int, input().split()))
    dice = Dice(num.index(value[0])+1, num.index(value[1])+1)
    dice.rside_num()
    print(num[dice.rside-1])



Measured memory_bytes: 5608
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int result = b / a;
		if(result > c) {
			result = c;
		}
		System.out.println(result);
		
	}
}

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



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

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
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; }

const long long INF = 1LL<<60;

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


int n;
map<int,ll> m;
map<int,ll>done;

int main()
{
    cin>>n;
    vec<int> a(n,-1);
    rep(i,n){
        cin>>a[i];
        m[a[i]]++;
    }

    ll res=0;
    ll val=0;
    for(auto v=m.begin() ; v!=m.end() ; ++v){
        val=v->second;
        res+=val*(val-1)/2;
    }
    for(auto v=m.begin() ; v!=m.end() ; ++v) done[v->first]=res-(v->second)+1;
    


    rep(i,n){
        // cout<<"already done it"<<endl;
        cout<<done[a[i]]<<endl;
    }
    return 0;

}




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

int main()
{
    long long l, r;
    cin >> l >> r;
    if (r - l > 2018)
    {
        cout << 0 << endl;
        return 0;
    }
    
    long long ans = 2019;


    for (long long i = l; i < r; i++)
    {
        for (long long j = i + 1; j <= r; j++)
        {
            ans = min(ans, (i * j) % 2019);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
vector <bool> used;
vector <vector <pair <int, int> > > g;
vector <vector <int> > usedver;
vector <int> dsu;
vector <int> sum;
vector <int> rang;
vector <bool> used1;
vector <int> last;
vector <bool> used2;
int pred(int a){
	if(a == dsu[a]) return a;
	else return dsu[a] = pred(dsu[a]);
}
void unite(int a, int b)
{
	a = pred(a);
	b = pred(b);
	if(a != b)
	{
		if(rang[a] < rang[b])
		{
			swap(a, b);
		}
		dsu[b] = a;
		for(int i = 0; i < usedver[b].size(); i++)
		{
			usedver[a].push_back(usedver[b][i]);
		}
		last[a] = max(last[a], last[b]);
		sum[a] += sum[b];
		if(rang[a] == rang[b])
		{
			rang[a]++;
		}
	}
}
void dfs(int v)
{
	used1[v] = true;
	for(int i = 0; i < g[v].size(); i++)
	{
		int to = g[v][i].first;
		int ind = g[v][i].second;
		used2[ind] = true;
		if(!used1[to])
		{
			dfs(to);
		}
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m;
	cin >> n >> m;
	dsu.resize(n);
	rang.resize(n);
	last.resize(n, -1);
	used2.resize(m);
	sum.resize(n);
	usedver.resize(n);
	for(int i = 0; i < n; i++)
	{
		cin >> sum[i];
		rang[i] = 1;
		dsu[i] = i;
	}
	g.resize(n);
	used1.resize(n);
	used.resize(m);
	vector <pair <int, pair <int, int> > > ver(m);
	for(int i = 0; i < m; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		ver[i] = {c, {a, b}};
	}
	sort(ver.begin(), ver.end());
	for(int i = 0; i < ver.size(); i++)
	{
		int a = ver[i].second.first;
		int b = ver[i].second.second;
		int c = ver[i].first;
		unite(a, b);
		if(c <= sum[pred(a)])
		{
			while(usedver[pred(a)].size() > 0)
			{
				usedver[pred(a)].pop_back();
			}
			usedver[pred(a)].push_back(i);
		}
	}
	for(int i = 0; i < usedver[pred(0)].size(); i++)
	{
		int w = usedver[pred(0)][i];
		used[w] = true;
	}
	for(int i = 0; i < ver.size(); i++)
	{
		int a = ver[i].second.first;
		int b = ver[i].second.second;
		g[a].push_back({b, i});
		g[b].push_back({a, i});
		if(used[i])
		{
			dfs(a);
		}
	}
	int ans = 0;
	for(int i = 0; i < m; i++)
	{
		if(!used2[i])
		{
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 18304
S=list(input())
T=list(input())
#print(S)
#print(T)
con=[0]*len(S)
for i in range(len(S)-len(T)+1):
    #print(i)
    for j in range(len(T)):
        if(S[i+j]==T[j]):
            con[i]=con[i]+1
print(len(T)-max(con))


Measured memory_bytes: 65464
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var a [3][3]int
	var bingo [3][3]int
	var n int
	fmt.Fscan(r, &a[0][0], &a[0][1], &a[0][2])
	fmt.Fscan(r, &a[1][0], &a[1][1], &a[1][2])
	fmt.Fscan(r, &a[2][0], &a[2][1], &a[2][2])
	fmt.Fscan(r, &n)
	var b [10]int
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &b[i])
	}
	for j := 0; j < 3; j++ {
		for i := 0; i < 3; i++ {
			for _, r := range b {
				if r == a[j][i] {
					bingo[j][i] = 1
				}
			}
		}
	}

	for i := 0; i < 3; i++ {
		if bingo[i][0] == 1 && bingo[i][1] == 1 && bingo[i][2] == 1 {
			fmt.Println("Yes")
			return
		}
	}

	for i := 0; i < 3; i++ {
		if bingo[0][i] == 1 && bingo[1][i] == 1 && bingo[2][i] == 1 {
			fmt.Println("Yes")
			return
		}
	}

	if bingo[0][0] == 1 && bingo[1][1] == 1 && bingo[2][2] == 1 {
		fmt.Println("Yes")
		return
	}

	if bingo[0][2] == 1 && bingo[1][1] == 1 && bingo[2][0] == 1 {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")
}


Measured memory_bytes: 640
import java.util.Scanner;
 

public class Main {
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String line = sc.nextLine();
        String[] md1 = line.split(" ");
        
        line = sc.nextLine();
        String[] md2 = line.split(" ");
        
        int ret = md2[1].equals("1") ? 1 : 0;
        System.out.println(ret);

        sc.close();
	}
	
}


Measured memory_bytes: 23636
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n;cin>>n;
  bool b[1000001];
  REP(i,1000001){
    b[i] = false;
  }
  b[0] = true;
  vector<int> v;
  REP(i,n){
    int t;cin>>t;
    v.pb(t);
  }
  VSORT(v);

  REP(i,v.size()){
    if(v[i+1] == v[i]){
      //int j = i+1;
      int tmp = v[i];
      int p = v[i];
      if(b[v[i]] == false){
        while(tmp<1000001){
          b[tmp] = true;
          tmp += p;
        }
      }
      
      /*while(j<v.size()){
        j++;
        if(v[j] != v[i]||j==v.size()-1){
          v.erase(v.begin()+i,v.begin()+j);
          break;
        }
      }
      i--;*/
    }
  }

  int ans = 0;

  REP(i,v.size()){
    if(b[v[i]]==false){
      ans++;
      int tmp = v[i];
      int p = v[i];
      while(tmp<1000001){
        b[tmp] = true;
        tmp += p;
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}

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

int main(void){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int q;
	cin>>q;
	int x,y;
	while(q--){
		cin>>x>>y;
		reverse(a+x,a+y);
	}
	for(int i=0;i<n;i++){
		if(i!=0)cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
}



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

int main() {
  string S;
  cin>>S;
  rep(i,S.size()){
    if((i+1)%2==0){
      if(S[i]=='R'){
        puts("No");
        return 0;
      }
    }
    else{
      if(S[i]=='L'){
        puts("No");
        return 0;
      }
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  bool flg = false;
  for(int i = 1; i < B; i++){
    if((A * i) % B == C){
      cout << "YES" << endl;
      flg = true;
      break;
    }
  }
  if(!flg){
    cout << "NO" << endl;
  }
  return 0;
}


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

int main(){
    int n;
    string s, t;
    cin >> n >> s >> t;
    int Ans = n*2;

    for(int i=0;i<n;i++){
        if(s.substr(i) == t.substr(0, n-i)){
            Ans = n+i;
            break;
        }
    }
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

char get_youngest(const map<char, ll>& m) {
  for (char c = 'a'; c <= 'z'; c++) {
    if (m.find(c) == m.end()) {
      return c;
    }
  }
}

int main() {
  init();

  string S;
  cin >> S;
  const char* s = S.c_str();
  map<char, ll> M;
  char youngest = 'z';
  REP(i, 0, S.size()) {
    M.emplace(s[i], 1);
    youngest = get_youngest(M);
  }

  if (M.size() == 26) {
    cout << "None" << endl;
    return 0;
  }

  cout << youngest << endl;

  return 0;
}


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

using ll = long long;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)
#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

char S[12];

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

  cin>>S;

  int L = strlen(S);

  int m = 1000;

  rep(i, L-2) {
    int X = 0;
    rep(j, 3)X = X*10 + (S[i+j]-'0');
    //cout<<X<<endl;
    m = min(m, abs(X-753));
  }

  cout<<m<<endl;

  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;


int main(){
    ll n,i=2,ans;
    cin>>n;
    while(1){
        if(n<i){
          	i/=2;
            break;
        }
        i*=2;
    }
    ans=i*2-1;
    cout<<ans;
}

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

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int l; cin >> l;
  int k = 20;
  while((1 << k) > l) k--;
  vector<vector<pair<int, int>>> g(20);
  int m = 0;
  for(int i = 0; i < k; i++) {
    g[i].emplace_back(i + 1, 0);
    g[i].emplace_back(i + 1, 1 << i);
    m+=2;
  }
  int i = k - 1;
  while(i >= 0) {
    if(l - 1 - ((1 << k) - 1) >= (1 << i)) {
      g[i].emplace_back(k, l - (1 << i));
      m++;
      l -= (1 << i);
    } else {
      i--;
    }
  }
  cout << k + 1 << " " << m << endl;
  for(int i = 0; i < k; i++) {
    for(auto p : g[i]) {
      cout << i + 1 << " " << p.first + 1 << " " << p.second << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean g, t, p;
		int a[] = new int[5];

		while (true) {
			g = t = p = false;
			a[0] = sc.nextInt();
			if (a[0] == 0) {
				break;
			}
			a[1] = sc.nextInt();
			a[2] = sc.nextInt();
			a[3] = sc.nextInt();
			a[4] = sc.nextInt();
			for (int i = 0; i < 5; i++) {
				if (a[i] == 1) {
					g = true;
				} else if (a[i] == 2) {
					t = true;
				} else {
					p = true;
				}
			}
			if ((g && t && p) || (g && !t && !p) || (!g && t && !p) || (!g && !t && p)) {
				for (int i = 0; i < 5; i++) {
					System.out.println("3");
				}
			} else {
				if (g && t && !p) {
					for (int i = 0; i < 5; i++) {
						if (a[i] == 1) {
							System.out.println("1");
						} else {
							System.out.println("2");
						}
					}
				} else if (g && !t && p) {
					for (int i = 0; i < 5; i++) {
						if (a[i] == 3) {
							System.out.println("1");
						} else {
							System.out.println("2");
						}
					}
				} else if (!g && t && p) {
					for (int i = 0; i < 5; i++) {
						if (a[i] == 2) {
							System.out.println("1");
						} else {
							System.out.println("2");
						}
					}
				}
			}
		}
	}
}

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

const int MAX_N = 1e5;
vector<vector<int> > points(MAX_N + 1, vector<int>(3));
vector<vector<int> > ans(MAX_N + 1, vector<int>(3, -1));

int dp(int n, int id) {
    if (ans[n][id] == -1) {
        if (id == 0) {
            ans[n][id] = max(dp(n-1, 1), dp(n-1, 2)) + points[n][id]; } else  
        if (id == 1) {
            ans[n][id] = max(dp(n-1, 0), dp(n-1, 2)) + points[n][id]; } else 
        if (id == 2) {
            ans[n][id] = max(dp(n-1, 0), dp(n-1, 1)) + points[n][id];
        }
    }
    return ans[n][id];
}

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            int k; cin >> k;
            points[i][j] = k;
        }
    }
    ans[0][0] = points[0][0]; 
    ans[0][1] = points[0][1];
    ans[0][2] = points[0][2];
    cout << max(max(dp(N-1, 0), dp(N-1, 1)), dp(N-1, 2)) << endl;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>   
#include<cstring>
typedef long long int ll;
using namespace std;
ll ans;
ll t[100000];
ll solve(ll a[],ll n){
	if(n<=0){
		return 0;
	}
	if(t[n]!=-1)
		return t[n];
	int l = solve(a,n-1);
	l = abs(a[n]-a[n-1]) + l;
	int r;
	if(n>1){
		r = solve(a,n-2);
		r = abs(a[n]-a[n-2]) + r;
	}
	else{
		r = INT_MAX;
	}
	t[n] = min(l,r);
	return  t[n];
}
int main(){
	ll n;
	cin>>n;
	ll a[n];
	ans = 0;
	memset(t,-1,sizeof(t));
	for(ll i = 0;i<n;i++)
		cin>>a[i];
	cout<<solve(a,n-1);
	// cout<<ans<<endl;
}







Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
	cin >> N;
	for(int i = 1; ; i++) {
		int z = i * (i + 1) / 2;
		if(N <= z) {
			int q = z - N;
			for(int j = 1; j <= i; j++) {
				if(j != q) cout << j << endl;
			}
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,A,B;

int sub(int val,int x){
    int res=0;
    for(int i=0;i<30;i++){
        if(i==x) continue;
        if(val&(1<<i)){
            if(i<x) res+=(1<<i);
            else res+=(1<<(i-1));
        }
    }
    return res;
}

int add(int val,int x){
    int res=0;
    for(int i=0;i<30;i++){
        if(i==x) continue;
        if(i>x){
            if(val&(1<<(i-1))) res+=(1<<i);
        }else{
            if(val&(1<<i)) res+=(1<<i);
        }
    }
    return res;
}

vector<int> solve(int n,int start,int end){
    vector<int> res;
    if(n==1){
        res.push_back(start);
        res.push_back(end);
        return res;
    }

    int dif=0;
    for(int i=n-1;i>=0;i--){
        if((start&(1<<i))!=(end&(1<<i))){
            dif=i;
            break;
        }
    }

    int nexst=sub(start,dif);
    int nexed=sub(end,dif);
    int mid=nexst^(1<<(n-2));
    vector<int> lef=solve(n-1,nexst,mid);
    for(int i=0;i<lef.size();i++){
        int val=add(lef[i],dif);
        if(start&(1<<dif)) val+=(1<<dif);
        res.push_back(val);
    }
    vector<int> rig=solve(n-1,mid,nexed);
    for(int i=0;i<rig.size();i++){
        int val=add(rig[i],dif);
        if(end&(1<<dif)) val+=(1<<dif);
        res.push_back(val);
    }
    return res;
}

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

  int C=A^B;
  if(__builtin_popcount(C)%2==0){
      cout<<"NO"<<endl;
      return 0;
  }

  vector<int> ans=solve(N,A,B);

  cout<<"YES"<<endl;
  for(auto v:ans) cout<<v<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 1716
#include<iostream>
#include<math.h>
using namespace std;
int main(){
	int dif[13];
	int n;
	int mini=12;
	cin>>n;
  if(n==1){int a;cin>>a;cout<<a<<endl;return 0;}
  for(int i=0;i<13;i++){dif[i]=0;}
	for(int i=0;i<n;i++){
		int a;cin>>a;
		dif[a]++;
		if(dif[a]==3 or a==0){
			cout<<'0'<<endl;
			return 0;
		}
      mini=min(mini,a);
	}
	int ans=99;
    dif[0]=1;
	dif[12]=dif[12]*2;
	for(int i=0;i<12;i++){
		int num=0;
		int k=i;
		while(num<3 and k<13){
			num+=dif[k];
			k++;
		}
		if(num>=3){
			ans=min(k-i-1,ans);
		}
		//cout<<i<<" "<<k<<" "<<ans<<endl;
	}
  	dif[12]=dif[12]/2;
	for(int i=0;i<12;i++){
		int num=0;
		int k=i;
		while(num<2 and k<13){
			num+=dif[k];
			k++;
		}
		if(num>=2){
			ans=min(24-i-k+1,ans);
		}
		//cout<<i<<" "<<k<<" "<<ans<<endl;
	}
  ans=min(ans,mini);
	cout<<ans<<endl;
	return 0;
}

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

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

    long long res = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        while (a % 2 == 0) {
            res++;
            a /= 2;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

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

int main() {
    int a,b;
    cin>>a>>b;
    if (a*b%2==0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100010
vector<pair<int,int> > p[N];
int vis[N];
void dfs(int x)
{
    int i,j,k;
    pair<int,int> d;
    k=p[x].size();
    for(i=0;i<k;i++)
    {
        d=p[x][i];
        if(vis[d.first]!=-1)
            continue;
        j=d.second%2;
        if(j)
            vis[d.first]=1-vis[x];
        else
            vis[d.first]=vis[x];
        dfs(d.first);
    }
}
int main()
{
    int i,j,k,n,u,v,w;
    scanf("%d",&n);
    for(i=1;i<n;i++)
    {
        scanf("%d%d%d",&u,&v,&w);
        p[u].push_back(pair<int,int>{v,w});
        p[v].push_back(pair<int,int>{u,w});
    }
    memset(vis,-1,sizeof(vis));
    vis[1]=0;
    dfs(1);
    for(i=1;i<=n;i++)
        printf("%d\n",vis[i]);
    return 0;
}


Measured memory_bytes: 8448
import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if (x == 1) {
            System.out.println(1);
        } else {
            ArrayList<Integer> list = new ArrayList<Integer>();
            for (int i = 2; i <= Math.sqrt(x); i++) {
                int max = 0;
                for (int j = 0; Math.pow(i, j) <= x; j++) {
                    max = (int)Math.pow(i, j);
                }
                list.add(max);
            }
            Collections.sort(list);
            Collections.reverse(list);
            System.out.println(list.get(0));
        }

    }
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define IN freopen("alchemy_input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)

#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define i64 long long int
#define ui64 unsigned long long int
#define xx first
#define yy second
#define ln 17
#define off 2

#define sq(x) ((x)*(x))

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace __gnu_pbds;
using namespace std ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int,int> pii;

//#define log 20
#define mod1 1000000007LL
#define mod2 1000000009LL
#define INF 2000000000
#define maxn 1000005

const long double eps = 1e-9 ;

vector <string> vs ;

bool comp( string s1 , string s2 )
{
    return s1.size() > s2.size() ;
}

map< pair<pair<int,int>,int> , int > Map ;

int cnt[maxn][28] ;
int yes[maxn][28] ;

int main()
{
    FASTIO ;

    int n ;
    cin>>n ;

    for(int i=1 ; i<=n ; i++)
    {
        string s ;
        cin>>s ;
        reverse(s.begin(),s.end()) ;
        vs.pb(s) ;
    }

    sort( vs.begin() , vs.end() , comp ) ;

 //   reverse(vs.begin(),vs.end()) ;

    int cur = 0 ;

    i64 ans = 0 ;

    for(int i=0 ;  i<n ; i++)
    {
        int sz = vs[i].size() ;
        for(int j=sz-1 ; j>=0 ; j--) for(int k=0 ; k<26 ; k++) yes[j][k] = 0 ;

        for(int j=sz-1 ; j>=0 ; j--)
        {
            for(int k=0 ; k<26 ; k++) yes[j][k] |= yes[j+1][k] ;
            yes[ j ][ vs[i][j]-'a' ] = 1 ;
        }

        int b1 = 29 , b2 = 43 ;
        int h1 = 0, h2 = 0 ;

        for(int j=0 ; j<sz-1 ; j++)
        {
            h1 = (1LL*h1*b1 + vs[i][j]-'a')%mod1 ; h2 = (1LL*h2*b2 + vs[i][j]-'a')%mod2 ;
        }
        if( Map.find( mp( mp(h1,h2) , sz-1 ) ) != Map.end() )
        {
            int idx = Map[ mp(mp(h1,h2),sz-1) ] ;
            ans += cnt[ idx ][ vs[i][sz-1]-'a' ] ;
        }

        h1 = 0 ; h2 = 0 ;

        for(int j=0 ; j<sz ; j++)
        {
            if( Map.find( mp(mp(h1,h2),j) ) == Map.end() )
            {
                Map[ mp(mp(h1,h2),j) ] = ++cur ;
            }
            int c = Map[ mp(mp(h1,h2),j) ] ;
            for(int k=0 ; k<26 ; k++) cnt[ c ][ k ] += yes[j][k] ;
            h1 = (1LL*h1*b1 + vs[i][j]-'a')%mod1 ; h2 = (1LL*h2*b2 + vs[i][j]-'a')%mod2 ;
        }

        for(int j=sz-1 ; j>=0 ; j--)
        {
            for(int k=0 ; k<26 ; k++) yes[j][k] = 0 ;
        }

      //  cout<<vs[i]<<" "<<ans<<endl ;
    }

    cout<<ans<<endl ;

    return 0 ;
}


Measured memory_bytes: 279408
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int calc(string s, bool start) {
	int res = 0;
	rep(i, s.size()) {
		res += abs(start - (s[i] - '0'));
		start ^= true;
	}
	return res;
}
int main() {
	string s;
	cin >> s;
	cout << min(calc(s, 0), calc(s, 1)) << endl;
	return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    int ans = INT_MAX;
    sort(a.begin(), a.end());
    do {
        int cst = 0;
        for (int i = 0; i < 2; i++) {
            cst += abs(a[i + 1] - a[i]);
        }
        ans = min(cst, ans);
    } while (next_permutation(a.begin(), a.end()));
    cout << ans << endl;

}



Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int32_t N;
std::pair<int32_t, int32_t> a[100000+1];
int64_t count[100001] = {};

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	for (int32_t i = 0; i < N; ++i)
	{
		in >> a[i].first; a[i].second = i;
	}
	a[N].first = 0; a[N].second = 0; ++N;
	std::sort(a, a + N, std::greater<>{});

	int32_t beg_index = a[0].second;
	int32_t max_v = a[0].first;
	for (int32_t i = 1; i < N; ++i)
	{
		if (a[i].first < max_v) {
			count[beg_index] += i * int64_t(max_v - a[i].first);
			max_v = a[i].first;
		}
		beg_index = std::min(beg_index, a[i].second);
	}
	for (int32_t i = 0; i < N-1; ++i)
	{
		out << count[i] << '\n';
	}

	return 0;
}
#endif


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define int long long
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int n,k;
    cin >> n >> k;
    vector<int>a(n);
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    vector<int>dp(n,INT_MAX);
    dp[0] = 0;
    dp[1] = abs(a[0] - a[1]);
    for(int i = 2;i < n; i++)
    {
        for(int j = 1; j <= k; j++)
        {
            if(i - j < 0)
            {
                break;
            }
            dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
        }
    }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 4760