akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func main() {
	var N, a int
	fmt.Scan(&N)
	A := make(map[int]int)
	for i := 0; i < N; i++ {
		fmt.Scan(&a)
		A[a]++
	}
	var l int
	for _, n := range A {
		l += n - 1
	}
	if l%2 == 1 {
		l++
	}
	fmt.Println(N - l)
}


Measured memory_bytes: 7936
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
int main() {
	int k;
	cin >> k;
	if (k == 1 || k == 2 || k == 3 || k == 5 || k == 7 || k == 11 || k == 13 || k == 15 || k == 17 || k == 19 || k == 23 || k == 30 || k == 31)
		cout << 1;
	else if (k == 4 || k == 6 || k == 9 || k == 10 || k == 14 || k == 21 || k == 22 || k == 25 || k == 26)
		cout << 2;
	else if (k == 8 || k == 12 || k == 18 || k == 20 || k == 27)
		cout << 5;
	else if (k == 16)
		cout << 14;
	else if (k == 24)
		cout << 15;
	else if (k == 28 || k == 30)
		cout << 4;
	else if (k == 32)
		cout << 51;
}

Measured memory_bytes: 256
from collections import deque

n = int(input())

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

for i in range(n-1):
    u, v, w = map(int, input().split())
    neighbors[u].append((v, w))
    neighbors[v].append((u, w))

checked = [False] * (n+1)
colors = [0] * (n+1)

d = deque([1])
while len(d) > 0:
    u = d.pop()
    checked[u] = True

    for v, w in neighbors[u]:
        if checked[v]:
            continue

        if (colors[u] == 0 and w % 2 == 1) or (colors[u] == 1 and w % 2 == 0):
            colors[v] = 1

        d.append(v)

for i in range(1, n+1):
    print(colors[i])


Measured memory_bytes: 73632
import sys
import math

input = sys.stdin.readline

def main():
    ans = 0
    A, B, H, M = map(int, input().split())
    h = 0.5*(H*60+M)
    m = 6*M
    d = abs(h-m)
    r = math.radians(d)
    ans = A**2 + B**2 - 2*A*B*math.cos(r)

    print('{:.20}'.format(ans**0.5))

if __name__ == '__main__':
    main()

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

int main(){
  int n;
  int cnt=0;
  cin >> n;
  for (int i=1; i<=n; i+=2) {
    int num=i;
    int div=0;
    for (int j=1; j<=n; j++) {
      if (num%j==0) div++;
      if (div>8) break;
    }
    if (div==8) cnt++;
  }
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<string.h>
#include<math.h>
  
  
      
int main(){
 
char str[48],c[48];
int i,j=0;

scanf("%s",str);

for(i=strlen(str)-1;i>=0;i--){
	c[j]=str[i];
	j++;
}

printf("%s\n",c);

    return 0;
}

Measured memory_bytes: 524
m,k=map(int,input().split())
a=['']*(2**(m+1))
if k==0:
    for i in range(2**m):
        for j in range(2):
            a[2*i+j]=str(i)
else:
    xor=0
    for i in range(2**m):
        if i<k:
            a[i]=str(i)
            xor^=i
        elif i>k:
            a[i-1]=str(i)
            xor^=i
    
    if xor!=k:
        print(-1)
        exit(0)
    
    a[2**m-1]=str(k)
    for i in range(2**m-1,-1,-1):
        if i>k:
            a[2**(m+1)-i-1]=str(i)
        elif i<k:
            a[2**(m+1)-i-2]=str(i)
    
    a[2**(m+1)-1]=str(k)


print(' '.join(a))

Measured memory_bytes: 85016
#include<iostream>

#include<string>

using namespace std;

int main(){
  int A,B;

  cin>>A>>B;

  if(A<B){

    cout<<"a"<<" < "<<"b"<<endl;

  }

  else if(A>B){

      cout<<"a"<<" > "<<"b"<<endl;

    }

  else if(A==B){

      cout<<"a"<<" == "<<"b"<<endl;

    }

    return 0;
}


Measured memory_bytes: 3092
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
cnt1=0
cnt2=0
for i in range(n):
  if arr[i]>=0:
    cnt1+=1
  if arr[i]<=0:
    cnt2+=1
if cnt1==n:
  ans=-arr[0]+sum(arr[1:])
  print(ans)
  tmp=arr[0]
  for i in range(2,n):
    print(tmp,arr[i])
    tmp=tmp-arr[i]
  print(arr[1],tmp)
elif cnt2==n:
  ans=arr[-1]
  for i in range(n-1):
    ans+=abs(arr[i])
  print(ans)
  tmp=arr[-1]
  for i in range(n-1):
    print(tmp,arr[i])
    tmp=tmp-arr[i]
else:
  pos=0
  for i in range(n-1):
    if arr[i]*arr[i+1]<=0:
      pos=i
      break
  pos=pos+1
  ans=0
  for i in range(n):
    ans+=abs(arr[i])
  print(ans)
  for i in range(pos+1,n):
    print(arr[0],arr[i])
    arr[0]=arr[0]-arr[i]
  for i in range(pos):
    print(arr[pos],arr[i])
    arr[pos]=arr[pos]-arr[i]

Measured memory_bytes: 13964
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

constexpr long long MOD = 1000000007;

int N, X, Y, Z;

int main()
{
    cin >> N >> X >> Y >> Z;

    vector<vector<long long int> > dp(N+1, vector<long long int>(1 << (X+Y+Z+1)));
    dp[0][1] = 1;

    long long int ans = 0;
    for (int i=0; i<N; i++)
    {
        ans = (ans * 10) % MOD;
        for (int s=0; s<(1<<(X+Y+Z)); s++)
        {
            if (!dp[i][s]) continue;
            for (int n=1; n<=10; n++)
            {
                int snew = 1;
                snew |= (s << n) & ((1<<(X+1))-2);
                snew |= ((s >> X)  << (X+n)) & ((1<<(X+Y+1)) - (1 << (X+1)));
                snew |= ((s >> (X+Y)) << (X+Y+n)) & ((1<<(X+Y+Z+1)) - (1 << (X+Y+1)));
                if ((snew >> (X+Y+Z)) & 1)
                {
                    ans = (ans + dp[i][s] ) % MOD;;
                    // cout << snew << endl;
                }
                else dp[i+1][snew] = (dp[i+1][snew] + dp[i][s]) % MOD;

            }
        }
    }
    cout << ans << endl;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forn(i,o,n) for(int i=o;i<n;i++)
#define int long long
#define endl "\n"
#define mod 1000000007
#define double long double
#define pb push_back
#define mk make_pair
#define swap(x,y) (x^=y^=x^=y)
#define TT int ttt;cin>>ttt;while(ttt--)

using namespace std;

int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b); 
}
bool isPrime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
int modexpo(int x,int p){
    int res = 1;
    x = x%mod;
    while(p){
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

int max(int a,int b){
    if(a>b){
        return a;
    }
    return b;
}

int min(int a,int b){
    if(a<b){
        return a;
    }
    return b;
}
const int N = 2005;
int n,k;
int32_t main(){
    IOS
    cin>>n>>k;
    int arr[10];
    memset(arr,0,sizeof(arr));
    for(int i=0;i<k;i++){
        int a;
        cin>>a;
        arr[a]++;
    }
    vector<int>v;
    int temp = n;
    while(temp>0){
        v.pb(temp%10);
        temp/=10;
    }
    reverse(v.begin(),v.end());
    int flag=0;
    int mn=25;
    for(int j=0;j<10;j++){
        if(arr[j]==0){
            mn = j;
            break;
        }
    }
    string ans = "";
    for(int i=0;i<v.size();i++){
        if(flag == 1){
            ans += (char)('0'+mn);
            continue;
        }
        for(int j=v[i];j<10;j++){
            if(arr[j]==0){
                ans+=(char)('0'+j);
                if(j>v[i]){
                    flag=1;
                }
                break;
            }
        }
    }
    if(ans.length()>0){
        //cout<<ans<<endl;
        int x = stoi(ans);
        if(x>=n){
            cout<<ans<<endl;
            return 0;
        }
    }
    if(arr[0]==0){
        for(int i=1;i<10;i++){
            if(arr[i]==0){
                cout<<i;
                break;
            }
        }
        for(int i=0;i<v.size();i++){
            cout<<0;
        }
        cout<<endl;
    }
    else{
        for(int i=1;i<10;i++){
            if(arr[i]==0){
                for(int j=0;j<v.size()+1;j++){
                    cout<<i;
                }
                break;
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 FI first
#define SE second
#define PB(a) push_back(a)
#define DEBUG(x) cerr << __LINE__ << ":" << #x << ": " << x << "\n";
#define SZ(x) ((int)(x).size())
#define SO(x) sizeof((x)) / sizeof((x)[0])
//#define int long long
using namespace std;
using lint = long long;
struct Fast{Fast(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};} fast;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline void co(int a[], int n) {REP(i, n) cout << a[i] << " "; cout << "\n";}
//if (IO > 1e5){lint a;	scanf(%lld, &a);	printf("%lld\n", a);}

signed main(){
	int n;	cin >> n;
	if (n == 1){
		cout << "Hello World" << endl;
	}else{
		int a,b;	cin >> a >> b;
		cout << a+b << endl;
	}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> par_num;

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
        par_num.assign(N,1);
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        par_num[root(rx)]++;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    int n, m; cin >> n >> m;
    UnionFind tree(n+1);
    vector<int> p(n+1,0);
    rep(i,n) cin >> p.at(i+1);
    rep(i, m){
        int x, y;
        cin >> x >> y;
        tree.unite(x,y);
    } 

    int cnt = 0;
    for(int i=1; i<=n; i++){
        if(tree.same(p.at(i), i)) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 1408
n = int(input())
a = list(int(x) for x in input().split())
a_s = sorted(a, reverse = True)

al = 0
bo = 0
for i in range(n):
    if i % 2 == 0:
        al += a_s[i]
    else:
        bo += a_s[i]

print(al-bo)

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  int m = max({a, b, c});
  int sum = a + b + c;
  if ((sum % 2) == ((3 * m) % 2)) {
    cout << (3 * m - sum) / 2 << endl;
  } else {
    cout << (3 * (m + 1) - sum) / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

void y(bool c) {
	if (c)print("Yes");
	else print("No");
}
void solve() {

	int N, M; cin >> N >> M;
	int sum = 0;
	vector<int>A(N);
	REP(i, N) {
		cin >> A[i];
		sum += A[i];
	}
	int cnt = 0;
	REP(i, N) {
		if (A[i] * 4 * M >= sum)cnt++;
	}
	y(cnt >= M);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}




Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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! 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")
    };
}

fn main() {
    input! {
        n: u32,
        a: u32,
        b: u32,
    }

    let mut available_num: Vec<u32> = Vec::new();

    for i in 0..(n + 1) {
        let num: Vec<_> = i
            .to_string()
            .chars()
            .map(|a| a.to_digit(10).unwrap())
            .collect();

        let sum = num.iter().fold(0, |a, b| a + b);
        if a <= sum && sum <= b {
            available_num.push(i);
        }
    }

    let answer = available_num.iter().fold(0, |a, b| a + b);

    println!("{}", answer);
}


Measured memory_bytes: 4352
#!/usr/bin/python

import sys
from pprint import pprint
import math

INF = float("inf")
  
def solve(N: str, K: int):
    M = len(N)
    DP = [[[0]*2 for __ in range(K+1)] for _ in range(M+1)]
    Nstr = N
 
    DP[0][0][False] = 1
 
    for i in range(M):
        DP[i+1][0][True] = 1
        DP[i+1][0][False] = 0
        for k in range(K):
            DP[i+1][k+1][True] = DP[i][k][True]*9 + DP[i][k+1][True]*1
            if int(Nstr[i]) != 0:
                DP[i+1][k+1][True] += DP[i][k+1][False]
                DP[i+1][k+1][True] += DP[i][k][False]*(int(Nstr[i])-1)
            if int(Nstr[i]) == 0:
                DP[i+1][k+1][False] = DP[i][k+1][False]
            else:
                DP[i+1][k+1][False] = DP[i][k][False]
    print(DP[M][K][True]+DP[M][K][False])
    # print(*DP, sep="\n")
 
    return
 
 
if __name__ == '__main__':
 
    n = sys.stdin.readline().strip()
    k = int(sys.stdin.readline().strip())
     
    solve(n, k)

Measured memory_bytes: 38256
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int N, K, arr [200010];

int main(){
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    cin >> N >> K; for(int i = 0; i < N; i++) cin >> arr[i];
    for(int i = K; i < N; i++){
        cout << (arr[i] > arr[i-K] ? "Yes" : "No") << '\n';
    }
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

Measured memory_bytes: 4428
/**
 * @author yuichirw
 *
 */
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	static int[][] puzzle = new int[9][9];
	
	static boolean read() {
		for(int i = 0; i < 9; i++) {
			for(int j = 0; j < 9; j++) {
				puzzle[i][j] = sc.nextInt();
			}
		}
		return true;
	}
	
	static void solve() {
		boolean[][] ng = new boolean[9][9];
		int[] hist; int sum = 0;
		for(int i = 0; i < 9; i++) {
			hist = new int[9];
			for(int j = 0; j < 9; j++) {
				hist[puzzle[i][j]-1]++;
			}
			for(int j = 0; j < 9; j++) {
				if(hist[puzzle[i][j] - 1] >= 2) {
					ng[i][j] = true;
				}
			}
		}

		for(int j = 0; j < 9; j++) {
			hist = new int[9];
			for(int i = 0; i < 9; i++) {
				hist[puzzle[i][j]-1]++;
			}
			for(int i = 0; i < 9; i++) {
				if(hist[puzzle[i][j] - 1] >= 2) {
					ng[i][j] = true;
				}
			}
		}
		
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				hist = new int[9];
				for(int k = 0; k < 9; k++) {
					int x,y;
					x = i * 3 + k % 3;
					y = j * 3 + k / 3;
					hist[puzzle[y][x]-1]++;
				}
				for(int k = 0; k < 9; k++) {
					int x,y;
					x = i * 3 + k % 3;
					y = j * 3 + k / 3;
					if(hist[puzzle[y][x] - 1] >= 2) {
						ng[y][x] = true;
					}
				}				
			}
		}
		
		for(int i = 0; i < 9; i++) {
			for(int j = 0; j < 9; j++) {
				if(ng[i][j]) {
					System.out.print("*" + puzzle[i][j]);
				} else {
					System.out.print(" " + puzzle[i][j]);
				}
			}
			System.out.println();
		}

	}
	
	public static void main(String[] args) {
		n = sc.nextInt();
		while(n-- > 0 && read()) {
			
			solve();
			if(n != 0) System.out.println();
		}
	}

}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

template <class M, class N>
common_type_t<M, N> gcd(M a, N b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int main(int argc, const char *argv[]) {
  //
  int a, b, c;
  cin >> a >> b >> c;
  bool ans = c % gcd(a, b) == 0;
  cout << (ans ? "YES" : "NO") << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	vector<int>B(N);
	vector<int>C(N);
	rep(i, N) {
		cin >> A[i] >> B[i] >> C[i];
	}
	vector<vector<int>>dp(N + 1, vector<int>(3));
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;
	for (int i = 1; i <= N; i++) {
		dp[i][0] = max(dp[i - 1][1] + A[i - 1], dp[i - 1][2] + A[i - 1]);
		dp[i][1] = max(dp[i - 1][0] + B[i - 1], dp[i - 1][2] + B[i - 1]);
		dp[i][2] = max(dp[i - 1][0] + C[i - 1], dp[i - 1][1] + C[i - 1]);
	}
	int ans = 0;
	rep(i, 3) {
		ans = max(ans, dp[N][i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 6912
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    
    if(N < 1000){
      System.out.println("ABC");
    }else{
      System.out.println("ABD");
    }
    

  }
}

Measured memory_bytes: 21588
L, R = map(int, input().split())
mod = 2019
ans = 2019
for i in range(L,R+1) :
    for j in range(i+1,R+1) :
        temp = (i*j)%mod
        ans = min(ans, temp)
        if ans == 0 :
            print(0)
            exit()

print(ans)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#include <algorithm>
int main(){
int n;
cin >> n;
int d[n];
for(int i=0;i<n;i++){
cin >> d[i];
}
int count=1;
sort(d,d+n);
for(int i=0;i<n-1;i++){
if(d[i]!=d[i+1]){
count++;
}
}
cout << count;
return 0;
}

Measured memory_bytes: 256
n=int(input())
vec=[0 for _ in range(10050)]
for x in range(1,105):
	for y in range (1,105):
		for z in range (1 , 105):
			sum= x*x + y*y + z*z + x*y +y*z + z*x
			if sum<10050:
				vec[sum]+=1
				
for i in range(1,n+1):
	print(vec[i])

Measured memory_bytes: 9268
//順列全探索
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;


int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>>connected(N, vector<int>(N));
	int a, b;
	for (size_t i = 0; i < M; i++)
	{
		cin >> a >> b;
		a--;
		b--;
		connected.at(a).at(b) = 1;
		connected.at(b).at(a) = 1;
	}
	vector<int>perm(N);
	for (size_t i = 0; i < N; i++)
	{
		perm.at(i) = i;
	}
	int ans = 0;
	bool chk = true;
	do
	{
		chk = true;
		if (perm.at(0) != 0)break;
		for (size_t i = 0; i < N-1; i++)
		{
			if (connected.at(perm.at(i)).at(perm.at(i+1)) == 0)chk = false;
		}
		if (chk)ans++;
	} while (next_permutation(perm.begin(),perm.end()));
	cout << ans;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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; }

int main(){
    ll N;
    vector<ll> a;
    cin >> N;
    rep(i, 0, N){
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }
    
    ll ans = 0;
    ll cnt = 1;
    rep(i, 0, N){
        if (a[i] == cnt){
            cnt++;
            continue;
        }
        ans++;
    }
    if (cnt == 1){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;



double W, H, x, y;

string S;


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	cin >> W >> H >> x >> y;
	cout << W * H / 2<<endl;
	if (W/2.0 == x&&H/2.0==y)cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string a,b,c;
	cin >>a>>b>>c;
	a[a.length()-1]==b[0] && b[b.length()-1]==c[0] ? cout << "YES\n" : cout << "NO\n";
	return 0;
	}

Measured memory_bytes: 256
#include <stdio.h>

int n;
int s;
int a[32];
int mini;

void rec(int teamA, int idx)
{
	if (idx == n){ //終了条件
		int dx = 2 * teamA - s;
		if (dx < 0){
			dx *= -1;
		}
		if (dx < mini){
			mini = dx;
		}
		return;
	}
	//状態の遷移
	rec(teamA + a[idx], idx + 1);
	rec(teamA         , idx + 1);
	return;
}

int main(void)
{
	int i;
	
	while (scanf("%d", &n) && n){
		
		s = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
			s += a[i];
		}
		
		mini = 1000000000;
		rec(0, 0);
		
		printf("%d\n", mini);
	}
	
	return (0);
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main(){
	cin>>n;
	cin>>s;
	for(int i=0;i<s.size();i++)
        s[i]=char((s[i]-65+n)%26+65);
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int 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))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;

#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

  u64 a;

public:
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 val() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr bool operator==(const modint rhs) const noexcept {
    return modint(*this).val() == rhs.val();
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
using mint = modint<MOD>;

typedef vector<mint> vec;
typedef vector<vector<mint>> mat;

const int N = 1e5+10;
vector<int> edge[N],used(N,0);
vec fact(N,1);
int n,k;

mint ans;
void dfs(int no){
  used[no]++;
  int col = k-1-(no!=0), cnt = edge[no].size()-(no!=0);
  if(col >= cnt) ans *= fact[col]/fact[col-cnt];
  else ans = 0;
  for(int to: edge[no]){
    if(used[to]) continue;
    dfs(to);
  }
}

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

  cin >> n >> k;

  REP(i,N-1) fact[i+1] = fact[i]*(i+1);

  REP(_,n-1){
    int x,y;
    cin >> x >> y;
    x--; y--;
    edge[x].emplace_back(y);
    edge[y].emplace_back(x);
  }

  ans = k;
  dfs(0);

  cout << ans.val() << endl;

  return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  int k;
  cin>>k;
  int ans=(k/2)*((k+1)/2);
  cout(ans);
  return 0;
}

Measured memory_bytes: 125568
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) { 
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
const int MOD = 1e9 + 7, INF = 1e9 + 5;
const ll LONG_INF = 1e18 + 10;
inline ll powmod(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)res=res*a%MOD;return res;}
inline ll power(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a)if(b&1)res=res*a;return res;}

const int MAXN = 2e5 + 10;

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	long double x, k, d;
        cin >> x >> k >> d;
        ll ans = LONG_INF;
        if((k + 1) * d > abs(x)){
                ll a = x, b = k, c = d;
#define x a
#define k b
#define d c
                ll one = x % d, two = one >= 0 ? one - d : one + d;
                ans = abs((one - x)) / d % 2 == k % 2 ? one : two;
#undef x
#undef k
#undef d
        }
        else{
                x = abs(x);
                ans = x - k * d;
        }
        cout << abs(ans) << '\n';
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

ll func(ll x) {
    ll p = ((x+1) / 2) % 2 == 0 ? 0:1;
    ll ret = (x % 2) == 0 ? x+p:p;
    return ret;
}

int main(void)
{
    IOS
    ll A, B;
    cin >> A >> B;
    //cerr << func(A-1) << endl;

    cout << (func(A-1) ^ func(B)) << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,U,D,ans;
string s;
int main(void){
    while(1){
        U=0,D=0,ans=0;
        cin>>n;
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            cin>>s;
            if(s=="lu"||s=="ru"){
                if(U==1){
                    U=0;
                    ans++;
                }
                else U=1;
                D=0;
            }
            else{
                if(D==1){
                    D=0;
                    ans++;
                }
                else D=1;
                U=0;
            }
            
        }
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 3168
import itertools
nums = input()
index = range(1, len(nums))
def resolve(i):
    t = list(nums)
    for j in reversed(i): t.insert(j, "+")
    return eval("".join(t))

print(sum([resolve(i) for i in itertools.chain(*[itertools.combinations(index, x) for x in range(len(index) + 1)])]))


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(void) {
	int n = 0;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int A[1000];
		for (int i = 0; i < 1000; i++) {
			A[i] = 0;
		}
		for (int i = 0; i < n; i++) {
			cin >> A[i];
		}
		for (int i = 0; i < n - 1; i++){
			for (int j = i + 1; j < n; j++) {
				if (A[i] > A[j]) {
					int tmp = A[i];
					A[i] = A[j];
					A[j] = tmp;
				}
			}
		}
		int min = 1000000;
		for (int i = 0; i < n - 1; i++) {
			if (A[i + 1] - A[i] < min) {
				min = A[i + 1] - A[i];
			}
		}
		cout << min << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp1 {
    public class Class {
        static void Main(string[] args) {
            var x = RL<int>();
            for (var i = 0; i < x.Length; i++) {
                if (x[i] == 0) {
                    Console.Write(i + 1);
                    return;
                }
            }
        }

        static T[] RL<T>() where T : IComparable {
            if (typeof(T) == typeof(int)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
            }
            if (typeof(T) == typeof(long)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
            }
            if (typeof(T) == typeof(double)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(double.Parse).ToArray();
            }
            if (typeof(T) == typeof(decimal)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(decimal.Parse).ToArray();
            }
            return (T[])(object)Console.ReadLine().Trim().Split().ToArray();
        }
    }
}

Measured memory_bytes: 28152
/*
 * atcoder ABC 132 : B. Ordinary Number
 * Solution : editorial
 * 22 august 2019
 *
 */

#include <bits/stdc++.h>
using namespace std;

int n;
int arr[22];

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

	cin >> n;

	for(int i = 1 ; i <= n ; i++){
		cin >> arr[i];
	}

	int ans = 0;
	for(int i = 2 ; i <= (n-1) ; i++){
		int curr = arr[i];
		if(((arr[i] > arr[i-1]) && (arr[i] < arr[i+1])) || ((arr[i] < arr[i-1]) && (arr[i] > arr[i+1]))){
			++ans;
		}
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <stdio.h>
//#include <cmath>
//#include <algorithm>
//#include <iostream>
//#include <vector>
//#include <cstring>
#define pb push_back
#define ll long long
#define pi 3.1415926
using namespace std;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<long long,int> pli;
typedef pair<int,long long> pil;
const int INF=1000000007;
const int MOD=1000000007;
const int nmax=201234;

int n,k,a[2012];
ll cnt[2],res;

ll ksm(ll a,int b){
    ll ans=1;
    while(b){
        if(b&1) ans=ans*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return ans;
}

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i)
        scanf("%d",&a[i]);
    for(int i=0;i<n;++i){
        for(int j=0;j<i;++j)
            if(a[j]<a[i])
                ++cnt[1];
       for(int j=i+1;j<n;++j)
            if(a[j]<a[i]){
                ++cnt[0];
                ++cnt[1];
            }
    }
    res=(cnt[0]*k%MOD+cnt[1]*k%MOD*(k-1)%MOD*ksm(2,MOD-2))%MOD;
    printf("%lld\n",res);
    return 0;
}
//    ios::sync_with_stdio(false);
//    cin.tie(0);
//    cout.tie(0);


Measured memory_bytes: 256
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

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

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

#define MAX_V 100010
struct edge {ll to, cost;};
int V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(int s){
    priority_queue<p,vector<p>, greater<p> > que;
    fill(d,d+V, INF*INF);
    d[s]=0;
    que.push(p(0,s));
    while(!que.empty()){
        p pi = que.top(); que.pop();
        int v = pi.second;
        if(d[v] < pi.first) continue;
        REP(i,G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(p(d[e.to],e.to));
            }
        }
    }
}

int N, Q, K;
int main(){
    ios::sync_with_stdio(false);
    cin >> N;
    V = N;
    REP(i, N-1) {
        int a, b, c;
        cin >> a >> b >> c;
        G[--a].pb(edge{--b, c});
        G[b].pb(edge{a, c});
    }
    cin >> Q >> K;
    dijkstra(--K);
    REP(i, Q) {
        int x, y;
        cin >> x >> y;
        cout << d[--x]+d[--y] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 9984
#include<iostream>
#include<cstring>
using namespace std;
#define ll long long
char x[200];
char y[200];
ll k;

int main(){
	cin >> x >> k;
	int len = strlen(x);
	if (x[len - 1] == x[0]){
		//判断是不是相同字母
		bool flag = 0;
		for (int i = 0; x[i];++i)
		if (x[0] != x[i]){ flag = 1; break; }
		if (!flag){
			cout << len*k / 2 << endl;
		}
		else{
			ll ans = 0;
			//前
			int p = 0;
			while (x[0] == x[p])p++;
			//后
			int q = 0;
			while (x[len - 1] == x[len - 1 - q])q++;
			ans = (p + q)/2;
			for (int i = p,j=0; i <= len - 1 - q; ++i, j++)y[j] = x[i];
			int n, m;
			n = m = 0;
			while (y[n]){
				while (y[n] == y[m])++n;
				ans += (n - m) / 2;
				m = n;
			}
			ans += (n - m) / 2;
			ans = ans*(k - 1);
			n = m = 0;
			while (x[n]){
				while (x[n] == x[m])++n;
				ans += (n - m) / 2;
				m = n;
			}
			ans += (n - m) / 2;
			cout << ans << endl;
		}
	}
	else{
		int n, m;
		n = m = 0;
		ll ans = 0;
		while (x[n]){
			while (x[n] == x[m])++n;
			ans += (n - m) / 2;
			m = n;
		}
		ans += (n - m) / 2;
		cout << ans*k << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=1e5+10;



int main(){
	int N,C;
	cin>>N>>C;
	int ts[MAX][31];
	rep(i,MAX)rep(j,C)ts[i][j]=0;
	rep(_,N){
		int s,t,c;
		cin>>s>>t>>c;
		c--;
		ts[s][c]++;
		ts[t][c]--;
	}
	int df[MAX];
  	rep(i,MAX)df[i]=0;
	rep(i,MAX)rep(j,C){
		if(ts[i][j]==1)df[i-1]++;
		if(ts[i][j]==-1)df[i]--;
	}
	int ans=0;
	int ct=0;
	rep(i,MAX){
		ct+=df[i];
		ans=max(ans, ct);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 12800
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<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 int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
const int mod = 1000000007;
struct mint {
int64_t x;
mint(int64_t x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod;return *this;}
mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod;return *this;}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(int64_t t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) {return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    vec<vll> a(3,vll(3));
    rep(i,3){
        rep(j,3){
            cin>>a[i][j];
        }
    }

    bool ok=true;
    rep2(i,1,2){
        rep2(j,0,2){
            if(a[0][j]==a[i][j])continue;
        }
        int x = a[0][0]-a[i][0];
        rep2(j,0,2){
            if(a[0][j]!=(a[i][j]+x))ok=false;
        }
    }

    if(ok){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}

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

#define maxn 200010

ll a[maxn];
ll n;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  ll sum; sum = accumulate(a + 1, a + n + 1, 0ll);
  if (sum % (n * (n+1) / 2)) {
    cout << "NO";
    return 0;
  }
  ll cnt = sum / (n * (n+1) / 2);
  a[n+1] = a[1];
  for (int i = 1; i <= n; ++i) {
    ll dif = a[i] - a[i+1];
    if (dif + cnt < 0 || (dif + cnt) % n) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
/// :D


Measured memory_bytes: 4404
if __name__ == "__main__":
    n, m = map(int, input().split())
    lmax = 0
    rmin = n + 1
    for i in range(m):
        ltmp, rtmp = map(int, input().split())
        if ltmp > lmax:
            lmax = ltmp
        if rtmp < rmin:
            rmin = rtmp

    if lmax > rmin:
        print(0)
    else:
        print(rmin - lmax + 1)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    double cnt=0;
    for (int i = 1; i <= n; i++) {
        if(i%2==1){
            cnt++;
        }
    }
    std::cout << cnt/n << std::endl;
}


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

int main() {
	string str; 
	while (getline(cin, str)) {
		for (int i = 0; i < 26; i++) {
			for (auto &itr : str) if (isalpha(itr)) itr = (itr - 'a' + 1) % 26 + 'a';
			if (str.find("the") != -1) { cout << str << endl; break; }
			if (str.find("this") != -1) { cout << str << endl; break; }
			if (str.find("that") != -1) { cout << str << endl; break; }
		}
	}
	return 0;
}


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

int main() {
    long double a, b;
    cin >> a >> b;
    ll ans = a*b;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3732
#include <iostream>
using namespace std;
#define MOD 1000000007

long powMod(long x, long n, long mod){
	if (n == 0) return 1;
	else if (n == 1) return (x % mod);
	else if (n % 2 == 0){
		long t = powMod(x, n/2, mod);
		return (t*t) % mod;
	}
	else{
		return (x*powMod(x, n-1, mod)) % mod;
	}
}

long divMod(long a, long b, long mod){
	long t = powMod(b, mod-2, mod);
	return (a*t) % mod;
}

long n, a, b, c, p, q, t;
long pn[100010], qn[100010], cn[100010];

int main(){
	cin >> n >> a >> b >> c;
	long out = 0;
	p = divMod(a, a+b, MOD);
	q = divMod(b, a+b, MOD);
	pn[0] = 1;  // p^i
	qn[0] = 1;  // q^i
	cn[0] = 1;  // comb(n+i,n)
	for (int i = 1; i <= n+1; ++i){
		pn[i] = (pn[i-1]*p) % MOD;
		qn[i] = (qn[i-1]*q) % MOD;
		cn[i] = (cn[i-1]*divMod(n+i, i, MOD)) % MOD;
	}
	for (long m = n; m < 2*n; ++m){
		t = (pn[n] * qn[m-n]) % MOD;
		t = (t + (pn[m-n] * qn[n]) % MOD) % MOD;
		t = (cn[m-n]*t) % MOD;
		out = (out + t) % MOD;
	}
	out = (out * divMod(100, 100-c, MOD)) % MOD;
	out = (out * n) % MOD;
	printf("%ld", out);
}

Measured memory_bytes: 2560
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) {
            System.out.println("Hello World");
        }else{
            System.out.println(sc.nextInt() + sc.nextInt());
        }
    }
}


Measured memory_bytes: 21072