akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main() {
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    if (x1 == x2 && y2 - y1 > 0) cout << x1 - y2 + y1 << " " << y2 << " " << x1 - y2 + y1 << " " << y1;
    else if (x1 == x2 && y2 - y1 < 0) cout <<  x1 + y1 - y2 << " " << y2 << " " << x1 + y1 - y2 << " " << y1;
    else if (y1 == y2 && x1 - x2 > 0) cout << x2 << " " << y2 - x1 + x2 << " " << x1 << " " << y2 - x1 + x2;
    else if (y1 == y2 && x2 - x1 > 0) cout << x2 << " " << y1 + x2 - x1 << " " << x1 << " " << y1 + x2 - x1;
    else if ((x2 > x1 && y2 > y1) || (x2 < x1 && y2 > y1)) cout << x2 - y2 + y1 << " " << y2 + x2 - x1 << " " << x1 - y2 + y1 << " " << y1 + x2 - x1;
    else cout << x2 + y1 - y2 << " " << y2 + x2 - x1 << " " << x1 + y1 - y2 << " " << y1 + x2 - x1;
    return 0;
}


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

namespace Lsk {
#define _auto_ template <typename T>

// fast io
#define writesp(x) (write(x), putchar(' '))
#define writeln(x) (write(x), putchar('\n'))
_auto_ inline void read(T &x) {
	x = 0; bool sgn = false; char ch = getchar();
	while(!isdigit(ch)) (ch == '-') && (sgn = true), ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	if(sgn) x = -x;
}
_auto_ inline void write(T x) {
	if(x < 0) putchar('-'), x = -x;
	static char buf[40]; int o = 0;
	for(x; x > 9; x /= 10, ++o) buf[o] = x % 10 + '0'; buf[o] = x + '0';
	for(o; ~o; --o) putchar(buf[o]);
	return;
}

// cmin / cmax / swap
_auto_ inline void cmin(T &u, const T v) { if(u > v) u = v; }
_auto_ inline void cmax(T &u, const T v) { if(u < v) u = v; }
_auto_ inline T min(const T u, const T v) { return u < v ? u : v; }
_auto_ inline T max(const T u, const T v) { return u > v ? u : v; }
_auto_ inline void swap(T &u, T &v) { T tmp(u); u = v, v = tmp; }

// math
const int mod = 998244353, mod_2 = 1996488706;
//const int mod = 1000000007, mod_2 = 2000000014;
//const int mod = 1000000009, mod_2 = 2000000018;
_auto_ inline T abs(T x) { return x > 0 ? x : -x; }
_auto_ inline T gcd(T u, T v) {	return v ? gcd(v, u % v) : u; }
_auto_ inline T Mod(T u) { return u >= mod_2 ? u % mod : (u > mod ? u - mod : u); }
_auto_ inline T inmod(T u) { return u >= mod ? u - mod : (u < 0 ? u + mod : u); }
inline long long fpm(long long base, long long mi) {
	long long res = 1;
	while(mi) {
		if(mi & 1) res = Mod(res * base);
		base = Mod(base * base), mi >>= 1;
	}
	return res;
}

} using namespace Lsk;
#define N 200005
using std :: sort;

int n;
int a[N], f[N];
long long K;

inline bool check(long long mid) {
	long long res = 0;
	for(int i = 1; i <= n; ++i) {
		long long to = mid / f[i];
		if(to < a[i]) res += a[i] - to;
	}
	return res <= K;
}

int main() {
	read(n), read(K);
	for(int i = 1; i <= n; ++i) read(a[i]);
	for(int i = 1; i <= n; ++i) read(f[i]);

	sort(a + 1, a + 1 + n);
	sort(f + 1, f + 1 + n, std :: greater<long long>());

	long long l = 0, r = 1e12, mid, minp = 1e18;
	while(l <= r) {
		mid = l + r >> 1;
		//writesp(l), writeln(r);
		if(check(mid)) {
			cmin(minp, mid);
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}

	writeln(minp);
	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string ans = "";
  while(n != 0){
    int t = n%(-2);
    if(t == -1) t = 1;
    ans.push_back('0'+t);
    n = (n-t)/(-2);
  }
  if(ans.size() == 0) ans = "0";
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
}

Measured memory_bytes: 3628
H, W = map(int, input().split())

ans = min(H, W)


if H % 3 == 0 or W % 3 == 0:
    ans = 0
    
for ha in range(H//3, H//3+3):
    Sa = ha * W
    
    ## 横に分割
    hb = (H - ha)//2
    hc = H - ha - hb
    Sb = hb * W
    Sc = hc * W
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))
    
    ## 縦に分割
    wb = W//2
    wc = W - wb
    Sb = (H - ha) * wb
    Sc = (H - ha) * wc
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))

for wa in range(W//3, W//3+3):
    Sa = H * wa
    
    ## 横に分割
    hb = H//2
    hc = H - hb
    Sb = hb * (W - wa)
    Sc = hc * (W - wa)
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))
    
    ## 縦に分割
    wb = (W - wa)//2
    wc = W - wa - wb
    Sb = H * wb
    Sc = H * wc
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))

print(ans)


Measured memory_bytes: 3064
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-06-17 10:57:53

---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e3 + 7;

ll dp[MAXN][MAXN];
int a[MAXN], b[MAXN];
int main(int argc, char const *argv[])
{	
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; ++i)	cin >> a[i];
	for(int i = 1; i <= m; ++i)	cin >> b[i];
	for(int i = 0; i <= n; ++i){
		for(int j = 0; j <= m; ++j){
			dp[i][j] = 1;
		}
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= m; ++j){
			dp[i][j] = dp[ i-1 ][j] + dp[i][ j-1 ] - dp[ i-1 ][ j-1 ];
			if ( a[i] == b[j] ) dp[i][j] += dp[ i-1 ][ j-1 ];
			dp[i][j] = ( dp[i][j] + 10ll*mod ) % mod;

		}
	}
	cout << dp[n][m] << endl;
	return 0;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

// Rabin-Karp string search algorithm
class RollingHash{
    private:
      using ULL = unsigned long long;
      int n;
      const ULL mod = 1ULL << 63;
      const ULL base = 1000000007ULL;
      vector<ULL> hash, power;
    public:
      RollingHash(string s){
          n = s.size();
          hash.assign(n+1, 0ULL);
          power.assign(n+1, 0ULL);
          power[0] = 1ULL; 
          for(int i = 0; i < n; i++){
              power[i+1] = power[i] * base % mod;
              hash[i+1] = (s[i] + hash[i] * base) % mod;
          }
      }
      ULL GetHash(int l, int r){
          return ((hash[r] - hash[l] * power[r-l]) % mod + mod) % mod;
      }
};

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;

    vector<char> t(q), d(q);
    REP(i, q) cin >> t[i] >> d[i];

    auto f = [&](int m, int num){
        REP(i, q)
        {
            if(t[i] == s[m])
            {
                m += (d[i] == 'L' ? -1 : 1);
            }
            if(m == num) return true;
            else if(m >= n) return false;
            else if(m < 0) return false;
        }
        return false;
    };

    int r, l;
    int ok = 0, ng = n+1;
    while(abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;
        if(f(mid-1, -1)) ok = mid;
        else ng = mid;
    }
    l = ok;

    ok = 0, ng = n+1;
    while(abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;
        if(f(n - mid, n)) ok = mid;
        else ng = mid;
    }
    r = ok;
    cout << max(0, n - l - r) << endl;
}

Measured memory_bytes: 976
import java.util.*;

class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		for(int i = 0; i < 7; i++){
			int n = in.nextInt(), m = in.nextInt();
			System.out.println(n - m);
		}
	}

}

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

using namespace std;

template <class T> bool minimize(T &x, const T &y) {
    if (x > y) x = y; else return false; return true;
}

typedef long long ll;

const int N = 2e5 + 10;

int n, m, A, B;
int a[N];
ll s[N], bit1[N], bit2[N], f[N];

void upbit1(int x, ll para) {
    for (; x <= n; x += x & -x)
        minimize(bit1[x], para);
}

ll getbit1(int x) {
    ll ret = (ll)(1e16);
    for (; x; x -= x & -x)
        minimize(ret, bit1[x]);
    return ret;
}

void upbit2(int x, ll para) {
    for (; x; x -= x & -x)
        minimize(bit2[x], para);
}

ll getbit2(int x) {
    ll ret = (ll)(1e16);
    for (; x <= n; x += x & -x)
        minimize(ret, bit2[x]);
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> A >> B;
    for (int i = 1; i <= m; i++)
        cin >> a[i];
    /// init
    for (int i = 2; i <= m; i++) {
        s[i] = s[i - 1] + (ll)(abs(a[i] - a[i - 1]));
        /// A B
        f[i] = 1ll * abs(B - a[i]) + 1ll * abs(A - a[1]) + s[i - 1];
        /// B A
        f[i] = min(f[i], 1ll * abs(A - a[i]) + 1ll * abs(B - a[1]) + s[i - 1]);
    }
    memset(bit1, 60, sizeof(bit1));
    memset(bit2, 60, sizeof(bit2));
    /// dp
    for (int i = 2; i <= m; i++) {
        /// ai >= aj
        minimize(f[i], getbit1(a[i]) + (ll)(a[i]) + s[i - 1]);
        /// ai < aj
        minimize(f[i], getbit2(a[i] + 1) - (ll)(a[i]) + s[i - 1]);
        /// update
        upbit1(a[i - 1], f[i] - s[i] - (ll)(a[i - 1]));
        upbit2(a[i - 1], f[i] - s[i] + (ll)(a[i - 1]));
    }
    ll res = min(abs(a[1] - A), abs(a[1] - B)) + s[m];
    for (int i = 2; i <= m; i++)
        minimize(res, f[i] + s[m] - s[i]);
    cout << res;
}


Measured memory_bytes: 7296
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include <unordered_map>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n; ++i)
#define ALL(a) (a).begin(),(a).end()
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

#define MOD 1000000007
ll used[100010] = {};
int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i, n)cin >> a[i];

    ll ans = 1;

    if(n%2 == 1){
        int median = n/2+1;
        rep(i, n){
            int pos1 = max((ll)1, median-a[i]/2);
            int pos2 = min(n, median+a[i]/2);
            if(pos1 == pos2){
                if(used[pos1]++ > 0)ans = 0;
                continue;
            }
            if(used[pos1]++ > 2 || used[pos2]++ > 2)ans = 0;

            ans = (ans*max((ll)1, 3-used[pos1]))%MOD;
        }
    }
    else {
        int median = n/2;
        rep(i, n){
            int pos1 = max((ll)1, median - a[i]/2);
            int pos2 = min(n, median+1+a[i]/2);
            if(used[pos1]++ > 2 || used[pos2]++ > 2)ans = 0;
            ans = (ans*max((ll)1, 3-used[pos1]))%MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;

ll T, n, a, b, c, d;
map<ll, ll> mp;

ll f(ll p) {
	if(mp.count(p)) return mp[p];
	ll re = 1e18;
	if(p*d>0) re = min(re, p*d);
	re = min(re, f(p/2) + a + (p%2)*d);
	re = min(re, f(p/3) + b + (p%3)*d);
	re = min(re, f(p/5) + c + (p%5)*d);
	if(p>2)	re = min(re, f(p/2+1) + a + (2-p%2)*d);
	re = min(re, f(p/3+1) + b + (3-p%3)*d);
	re = min(re, f(p/5+1) + c + (5-p%5)*d);
	return mp[p] = re;
}

int main() {
	cin >> T;
	while(T--) {
		cin >> n >> a >> b >> c >> d;
		mp.clear();
		mp[0] = 0;
		mp[1] = d;
		cout << f(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 4804
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      String s = sc.next();
      String t = sc.next();
      int a = sc.nextInt();
      int b = sc.nextInt();
      String u = sc.next();
      if(u.equals(s)){
        System.out.println(a-1+" "+b);
      }else{
        System.out.println(a+" "+(b-1));
      }
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int n;
  std::cin >> n;
  std::vector<int> t(n + 1), x(n + 1), y(n + 1);
  t[0] = 0, x[0] = 0, y[0] = 0;
  for (int i = 1; i < n + 1; ++i) {
    std::cin >> t[i] >> x[i] >> y[i];
  }

  bool ok = true;
  rep(i, n) {
    int t_diff = t[i + 1] - t[i];
    int x_diff = abs(x[i + 1] - x[i]);
    int y_diff = abs(y[i + 1] - y[i]);
    if (t_diff < x_diff + y_diff) {
      ok = false;
    }
    if ((t_diff - x_diff - y_diff) % 2 != 0) {
      ok = false;
    }
  }

  std::cout << (ok ? "Yes" : "No") << std::endl;
  return 0;
}


Measured memory_bytes: 4560
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)            
    return divisors
a=int(input())
divisors=make_divisors(a)
divisors.sort()
b=len(divisors)
if b%2==0:
  c = (divisors[int(b/2-0.5)]-1)+(divisors[int(b/2+0.5)]-1)
else:
  c = 2*(divisors[int(b/2)]-1)
print(c)

Measured memory_bytes: 3296
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    int addition = a + b;
    int subtraction = a - b;
    int multiplication = a * b;
    
    int max = addition;
    if (addition < subtraction) {
      max = subtraction;
    }
    if (max < multiplication) {
      max = multiplication;
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 21716
using System;
using System.Linq;
public class P{
  public static void Main(){
    var s=Console.ReadLine().Split().Select(int.Parse).ToArray();
    var a=Enumerable.Repeat(0,s[0]).ToArray();
    for(int i=0;i<s[1];i++){
      var b=Console.ReadLine().Split().Select(int.Parse).ToArray();
      a[b[0]-1]++;
      a[b[1]-1]++;
    }
    Console.WriteLine(string.Join("\n",a));
  }
}

Measured memory_bytes: 13396
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	int A[200000];
	long ans = 0;
	int N;
	cin >> N;
	int i;
	for (i = 0;i < N;i++) {
		cin >> A[i];
		A[i] = A[i] - i - 1;
	}

	sort(A, A + N);

	long b;
	if (N % 2 != 0) {
		b = A[N / 2];
	}
	else {
		b = (A[N / 2 - 1] + A[N / 2]) / 2;
	}

	for (i = 0;i < N;i++) {
		ans += abs(A[i]-b);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
N = 100010

p = [True for i in range(N)]
p[0]=p[1]=False
for i in range(2,N):
    if p[i]:
        for j in range(2*i,N,i):
            p[j] = False

s = [0 for i in range(N)]
for i in range(1,N,2):
    if p[i] and p[(i+1)//2]:
        s[i] = 1

for i in range(N-1):
    s[i+1] += s[i]

Q = int(input())
for _ in range(Q):
    l,r = map(int,input().split())
    print(s[r]-s[l-1])


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int N, K;
    cin >> N >> K;

    ll ans = K;
    for (int i = 0; i < N - 1; i++) {
        ans *= K - 1;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    std::string S;
    std::cin >> S;

    for (int i = 0; i < 3; i++)
        if (S[i] == S[i + 1]) {
            std::cout << "Bad\n";
            return 0;
        }
    
    std::cout << "Good\n";
}

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

int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {1, -1, 0, 0, 1, -1, -1, 1}, W, H;
bool mem[50][50];

int dfs(int x, int y)
{
  if(!mem[y][x])
    return 0;
  mem[y][x] = 0;
  for(int i = 0; i < 8; i++)
  {
    int tx = x + dx[i];
    int ty = y + dy[i];
    if(tx >= 0 && tx < W && ty >= 0 && ty < H && mem[ty][tx])
      dfs(tx, ty);
  }
  return 1;
}

int main()
{
loop:
  int ans = 0;
  for(int y = 0; y < 50; y++)
    for(int x = 0; x < 50; x++)
      mem[y][x] = 0;
  cin >> W >> H;
  if(!W)
    return 0;
  for(int y = 0; y < H; y++)
    for(int x = 0; x < W; x++)
      cin >> mem[y][x];
  for(int y = 0; y < H; y++)
    for(int x = 0; x < W; x++)
      ans += dfs(x, y);
  cout << ans << endl;
  goto loop;
}

Measured memory_bytes: 1232
import itertools
n, m = map(int, input().split())
path = [[False] * n for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    path[b][a] = True
ans = 0

for i in itertools.permutations(range(n), n):
    if i[0] == 0:
        for j in range(n):
            if j == n - 1:
                ans += 1
                break
            if not path[i[j]][i[j + 1]]:
                break
print(ans)

Measured memory_bytes: 3064
# coding: utf-8
# Your code here!
xs = []
judge = ["AC","WA","TLE","RE"]
jd = {"AC":0,"WA":1,"TLE":2,"RE":3}
n = int(input())
for i in range(n):
    xs.append(input().rstrip())
xcount = [0 for i in range(4)]
for x in xs:
    xcount[jd[x]] += 1
for i in range(4):
    print(judge[i] + " x " + str(xcount[i]) )

Measured memory_bytes: 16256
TEST = true
def pt(obj)
  p obj if TEST
end

n = gets.chomp.to_i

if n==0
  puts 0
  exit
end

ans = ''
while n!=0
  if (n % -2).odd?
    ans += '1'
  else
    ans += '0'
  end
  n = n / -2 - n % -2
end

puts ans.reverse

Measured memory_bytes: 1788
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <array>
#include <bitset>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator >> (istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

LL K;
int S;
int main() {
	cin >> K;
	S = K >= 49 * 49 ? 50 : sqrt(K) + 1;

	if (K == 0) {
		cout << 2 << endl << "1 1" << endl;
	} else {
		cout << S << endl;
		int offset = S - 1;
		int r = K % S;
		REP(i, 0, S) {
			cout << K / S + offset + (i < r ? S + 1 - r : -r) << (i == S - 1 ? '\n' : ' ');
		}
	}

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]

ans = 1

ok = True
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ok = False
        break

for i in range(n):
    if a[i] == 0:
        ok = True
        ans = 0

if ok == True:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 21528
#include <stdio.h>
long long int yaku(long long int a,long long int b){
  if(a < b){
    long long int tmp = a;
    a = b;
    b = tmp;
  }
  long long int r = a % b;
  while(r > 0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
int main(){
  int n;
  scanf("%d",&n);
  long long int a[n];
  for(int i = 0;i < n;i++){
    scanf("%lld",&a[i]);
    if(i > 0){
      a[i] = a[i] / yaku(a[i],a[i - 1]) * a[i - 1];
    }
  }
  printf("%lld\n",a[n - 1]);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

		int W=sc.nextInt();
		int H=sc.nextInt();
		int N=sc.nextInt();
		int[][] max=new int[W][H];

		for(int i=0; i<=W-1; i++) {
			for(int j=0; j<=H-1; j++) {
				max[i][j]=0;
			}
		}

		for(int i=1; i<=N; i++) {
			int a=sc.nextInt();
			int b=sc.nextInt();
			int c=sc.nextInt();
			if(c%4==1) {
				for(int j=0; j<a; j++) {
					for(int k=0; k<=H-1; k++) {
						max[j][k]=1;
					}
				}
			}
			else if(c%4==2) {
				for(int j=W-1; j>=a; j--) {
					for(int k=0; k<=H-1; k++) {
						max[j][k]=1;
					}
				}
			}
			else if(c%4==3) {
				for(int j=0; j<=W-1; j++) {
					for(int k=0; k<b; k++) {
						max[j][k]=1;
					}
				}
			}

			else if(c%4==0) {
				for(int j=0; j<=W-1; j++) {
					for(int k=b; k<=H-1; k++) {
						max[j][k]=1;
					}
				}
			}
		}
		int sou=0;
		for(int i=0; i<=W-1; i++) {
			for(int j=0; j<=H-1; j++) {
				if(max[i][j]==0) {
					sou++;
				}
			}
		}
		System.out.println(sou);
	}
}

Measured memory_bytes: 23124
n,m,l=map(int,input().split())
R=list()
L=list()
M=list()
K=list()
N=list()
O=list()
P=list()
sum=0
for a in range(n):
    R=list(map(int,input().split()))
    L.append(R)
for h in range(m):
    K=list(map(int,input().split()))
    N.append(K)
for i in range(l):
    for b in range(n):
        for c in range(m):
            sum+=L[b][c]*N[c][i]
        O.append(sum)
        sum=0
    P.append(O)
    O=list()
for y in range(n):
    for j in range(l-1):
        print(P[j][y],end=" ")
    print(P[l-1][y])



Measured memory_bytes: 7064
n = int(input())
a = list(map(int, input().split()))
count = 0
flg = True
while(flg):
    for i in range(n):
        if a[i]%2 != 0:
            flg = False
            break
        else:
            a[i] = a[i]/2
    else:
        count += 1
print(count)

Measured memory_bytes: 3060
import sys

x = int(input())
for a in range(0,1000):
    a_5 = a**5
    if a_5 > x:
        b = 0
        s = x+1
        while s > x:
            s = a_5 - b**5
            if s == x:
                print(a, b)
                sys.exit()
            b += 1
            
    elif a_5 < x:
        b = 0
        s = x-1
        while s < x:
            s = a_5 - b**5
            if s == x:
                print(a, b)
                sys.exit()
            b -= 1
    else:
        print(a,0)
        sys.exit()

Measured memory_bytes: 8880
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, k: usize, q: usize, d: [usize; k]);
    for _ in 0..q {
        parse!(it, n: usize, x: usize, m: usize);
        let d = d.iter().map(|x| *x % m).collect::<Vec<_>>();
        let a = (n - 1) / k;
        let b = (n - 1) % k;
        let mut zeros = d.iter().filter(|x| **x == 0).count();
        let mut bzeros = d[..b].iter().filter(|x| **x == 0).count();
        zeros = zeros * a + bzeros;
        let s: usize = d.iter().sum();
        let bs: usize = d[..b].iter().sum();
        let s = s * a + bs;
        let s = s + (x % m);
        let r = s / m;
        println!("{}", n - zeros - r - 1);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

int main() {
    ll N, M;
    cin >> N >> M;
    priority_queue<ll> que;
    rep(i, N) {
        ll A;
        cin >> A;
        que.push(A);
    }

    rep(i, M) {
        ll tmp = que.top();
        que.pop();
        tmp /= 2;
        que.push(tmp);
    }

    ll ans = 0;
    while (que.size()) {
        ans += que.top(); que.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 1400
from fractions import gcd
from math import factorial, ceil, sqrt, atan2, log
from itertools import *
import string
import copy
import random
import bisect
from decimal import *
def id_generator(size=20, chars=string.digits):
    return ''.join(random.choice(chars) for _ in range(size))
 
def mp():
    return map(int,str(raw_input()).split())

a,b=mp()
if (a*b)%2==1:
	print 'Odd'
else:
	print 'Even'

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

using ll = long long;
const ll INF = 1LL<<60;
const ll MOD = 1000000007LL;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP2(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}


void solve() {
	string S, T;
    cin >> S >> T;
	
    cout << T+S <<endl;

}

signed main() {
    

    solve();

    return 0;
}



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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define INF 1020304050

int main()
{
  int n;cin>>n;
  vector<int> r(n);
  vector<int> c(n);
  int i,j,k;
  rep(i,n)cin>>r[i]>>c[i];
  vector<vector<int>> dp(n,vector<int>(n,INF));
  rep(i,n)dp[i][i]=0;
  rep(i,n-1)dp[i][i+1]=r[i]*c[i]*c[i+1];
  for(i=2;i<n;i++)
  {
    rep(j,n-i)
    {
      for(k=1;k<=i;k++)
      {
        dp[j][j+i]=min(dp[j][j+i],dp[j][j+k-1]+dp[j+k][j+i]+r[j]*r[j+k]*c[j+i]);
      }
    }
  }
  cout<<dp[0][n-1]<<endl;
}



Measured memory_bytes: 3172
import sys

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


def main():
    a, b, x = map(int, readline().split())

    print(b // x - (a - 1) // x)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61900
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

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


long long getDigit(long long n){
	if(n==1)return 1;
	else return log10(n)+1;
}

class Point{
public:
	long long x;
	long long y;
};
long long N,M;
vector<long long>X(100006,0);
bool isOK(long long N){
	string s=to_string(N);
	set<char>set;
	for(int i=0;i<s.length();i++){
		set.insert(s[i]);
	}
	return set.size()==1;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long N;
	cin>>N;
	while(1){
		if(isOK(N)){
			cout<<N<<endl;
			return 0;
		}
		N++;
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


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

long long A[N];

rep(i,N)cin>>A[i];
long long ans=0;
long long sum=0;
rep(i,N){
    sum+=A[i];
    if(A[i]==0){
        ans+=sum/2;
        sum=0;
    }
}
ans+=sum/2;

cout<<ans<<endl;
return 0;

}
/*
4
4
0
3
2

4

8
2
0
1
6
0
8
2
1

9
*/


Measured memory_bytes: 1024
x, y, a, b, c = map(int, input().split())

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

data = []

for i in p:
    data.append((i, 'r'))
for i in q:
    data.append((i, 'g'))
for i in r:
    data.append((i, 'n'))

data.sort(reverse=True)
total = x + y
result = 0

for i in data:
    if i[1] == 'r' and x != 0:
        x -= 1
        total -= 1
        result += i[0]
    elif i[1] == 'g' and y != 0:
        y -= 1
        total -= 1
        result += i[0]
    elif i[1] == 'n':
        total -= 1
        result += i[0]
    if total == 0:
        break

print(result)

Measured memory_bytes: 126700
n = int(input())
l = []
for i in range(n):
    x,y =[i for i in input().split()]
    l.append([x, y])

total_JPY = 0
for j in range(n):
    if l[j][1] == 'JPY':
        total_JPY += int(l[j][0])
    else:
        total_JPY += float(l[j][0])*380000
print(total_JPY)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;

int main() {
	long long int n;
	long long int k;
	cin >> n;
	cin >> k;
	if (n == 1 || k == 1) {
		cout << '1';
		return 0;
	}
	cout << n * k / 2 + (k % 2)*(n % 2);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

int N, A;
int x[111];
ll coudp[111][111][5555];

int main() 
{
	
	
	int  a, b, h;
	cin >> a>> b>> h;

	cout << (a + b) * h / 2 << endl;




	return 0;
	
}

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

int main() {
int sum = 0;
cin >> sum;
int a, b, c, d;
a = sum / 1000;
b = sum / 100 % 10;
c = sum / 10 % 10;
d = sum % 10;
if(b == c){
	if(a == b || b == d){
		cout << "Yes" << endl;
		return 0;
	}
}
cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())

if N >= 64:
  print("64")
elif N >= 32:
  print("32")
elif N >= 16:
  print("16")
elif N >= 8:
  print("8")
elif N >= 4:
  print("4")
elif N >= 2:
  print("2")
else:
  print("1")

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N;
	cin >> N;
	vector<int>A(N);
	double sum = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		sum += 1 / (double)A[i];
	}
	double ans = 1 / sum;
	cout << ans;
}

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

int main(){
    int n,m; cin>>n>>m;
    vector<int> vote(n);
    int sum = 0;
    for(int i=0; i<n; i++){
        cin>>vote[i];
        sum += vote[i];
    }
    int ans = 0;
    for(int i:vote){
        if(i*4*m>=sum) ans++;
    }
    cout<<(ans>=m?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe

main :: IO ()
main = do
  n <- readLn :: IO Int
  getLine >>= putStrLn . solve . map read . words

solve :: [Int] -> String
solve hs = if isNothing $ foldM f 0 hs
           then "No"
           else "Yes"
  where
    f prev x = if prev == x
               then Just x
               else if prev <= x - 1
                    then Just (x - 1)
                    else Nothing

Measured memory_bytes: 33148
#include <bits/stdc++.h>
using namespace std;
 
struct team_b{
    char c;
    int w, l, d;
    team_b(){ c = w = l = d = 0; }
};
bool operator<( const team_b &l, const team_b &r ){
    if( l.w == r.w )
        return l.l < r.l;
    else
        return l.w > r.w;
}
 
int main(){
    int n;
    while( cin >> n, n ){
        team_b t[10];
        for(int i=0; i<n; i++){
            cin >> t[i].c;
            for(int j=0; j+1<n; j++ ){
                int k;
                cin >> k;
                if(k==0)      t[i].w++;
                else if(k==1) t[i].l++;
                else          t[i].d++;
            }
        }
        stable_sort( t, t+n );
        for(int i=0; i<n; i++){
            cout << t[i].c << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int a, b;
  cin>>a>>b;
  string s;
  cin>>s;
  bool valid = 1;
  if(s.length()==a+b+1 && s[a]=='-'){
    s[a]='1';
    REP(i,0,s.length()){
      if(s[i]<'0' || s[i]>'9') valid = false;
    }
  }else valid = 0;
  Yes(valid);

  return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
aa, bb = [], []
for _ in range(n):
    aa.append(input())
for _ in range(m):
    bb.append(input())

ans = 'No'
from itertools import product
for i, j in product(range(n - m + 1), repeat=2):
    ok = True
    for x, y in product(range(m), repeat=2):
        if aa[x+i][y+j] != bb[x][y]:
            ok = False
            break
    if ok:
        ans = 'Yes'
        break

print(ans)


Measured memory_bytes: 3064
int_s, int_c = map(int, input().split())


if int_s * 2 == int_c:
    print(int_s)
elif int_s * 2 > int_c:
    print(int_c // 2)
else: # int_s * 2 < int_c
    zan_c = int_c - int_s * 2
    print(int_s + zan_c // 4)



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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    ll x2 = 0;
    rep(i, N) {
        if (i % 2) x2 -= a[i];
        else x2 += a[i];
    }
    vector<int> ans(N);
    ans[0] = x2 / 2;
    rep(i, N - 1) {
        ans[i + 1] = a[i] - ans[i];
    }
    rep(i, N) ans[i] *= 2;
    rep(i, N) printf("%d%c", ans[i], i == N - 1 ? '\n' : ' ');
    return 0;
}


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

int main() {
    long long min = 1000000, max = -1000000, sum = 0;
    int n;
    int i;
    int num;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> num;
        if (max < num) {
            max = num;
        }
        if (min > num) {
            min = num;
        }
        sum += num;
    }
    cout << min << " " << max << " " << sum << endl;
}

Measured memory_bytes: 3096
n = int(input())
s = input()

flag = True
if n % 2 != 0:
    flag = False
else:
    for i in range(n // 2):
        if s[i] != s[(n // 2) + i]:
            flag = False
            break

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
N, K = map(int, input().split())
A = list(map(int, input().split()))

# first : 数列Aのi番目以降の要素で操作をしたときに残っている最初の数字
#   first[idx] > 0  => idxからスタート
#   first[idx] == 0 => 空の数列が残る
#   first[idx] < 0  => follow_idx[idx]からスタート(後々スタートの数だけ取り出したいため区別して負の数で保持)
# follow_idx : 数列Aのi番目以降の要素で操作をしたときに残っている次の数のindex
first = [0] * (N+1)
follow_idx = [-1] * (N+1)
# d : ある数字が出現したindexを記憶
d = {}
for i, a in enumerate(A[::-1]):
  j = N - 1 - i
  # 自分よりも後に自分と同じ数字が出現する場合、その位置まで消えて、その次からスタートしたときと同じものが残る
  if a in d:
    idx = d[a][-1] + 1 # j以降にaと同じ数字が出現するindexの中で最も近いもの次のindex
    d[a].append(j)
    if first[idx] < 0: # 負の数 => idx番目の数からスタートしない
      first[j] = first[idx] # 自身から始まらないため、ここも負の数のまま保持
      follow_idx[j] = follow_idx[idx] # 本当に始まるindexを記録
    else: # 正の数 => idx番目からスタートする
      first[j] = -first[idx] # 自身から始まらないため、負の数で保持
      follow_idx[j] = idx # 本当はidxから始まる
  
  # 自分よりも後に自分と同じ数字が出現しない場合、先頭に自身を追加して、一つ後ろからスタートしたときと同じものが残る
  else:
    first[j] = a # 自身からスタート
    d[a] = [j]
    follow_idx[j] = j + 1 # 自身の次は一つ後ろにつながる


# indices : 先頭の数字が元の数列でどのindexだったかを記録
indices = [-1] # ダミー
s0 = first[0] # 数列を1つだけ並べて操作を行ったときに残る先頭の数字
if s0 >= 0: 
  indices.append(0) # 0以上の場合、自身から始まる
else:
  s0 = -s0 # 負の場合、正の値に戻す
  indices.append(follow_idx[0]) # 自身から始まるわけではないので、本当に始まるindexを追加

if s0 == 0: # 数列を1つ並べて操作を行った後の数列が空 => 何個並べても最終的に空になる
  print('')
  quit()

# first_a : 先頭の数字として出現したものを記録
#   key : 先頭の数字
#   value : 数列Aを何個並べて操作を行った場合か
first_a = {0:0, s0:1}
for k in range(2, K+1):
  idx = d[s0][-1] + 1 # 先頭の数字が最初に現れるとそこまで消えて、その次からスタートする
  s0 = first[idx] # 上で求めたスタート位置から始めたときに残る数列の先頭の数字
  if s0 >= 0: # 0以上ならその数字自身から始まる
    indices.append(idx) # ので、idxをそのまま記録
  else: # 負の数なら、本当はその位置から始まるわけではない
    s0 = -s0 # 一旦、正の値に戻しておく
    indices.append(follow_idx[idx]) # 本当のスタート位置を記録
  if s0 in first_a: # 既にその数からスタートしたことがある => ここから先は周期的に振る舞う
    break
  first_a[s0] = k # s0が先頭となるkを記録しておく

if len(indices) < K: # 周期を発見してシミュレーションが終了した場合、Kを更新
  # 1, 2, ..., first_a[s0], ..., k
  # ?, ?, ..., s0,          ..., s0
  #              <------------->
  #                 ここが周期
  K = first_a[s0] + (K - first_a[s0]) % (k - first_a[s0])

if K == 0: # 丁度からの数列になったときに終了している
  print('')
  quit()

ans = []
idx = indices[K] # ここからスタートしたときに残る数列と同じものが残る
while idx < N: # 最後尾になるまで後ろ側に辿っていく
  s = first[idx]
  if s > 0: # 正で保持されているなら、その数字を使うということなのでansに追加
    ans.append(s)
  idx = follow_idx[idx]

print(*ans)

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

using Edge = pair<int, int>; // (隣接ノード番号, 隣接ノードまでの長さ)
using Node = pair<int, vector<Edge>>; // ノード=(色, 隣接のリスト)
using NodeList = vector<Node>;

void dfs(int index, int prevIndex, int color, NodeList &nodes) {
    auto &node = nodes[index];
    node.first = color;
    for (auto edge : node.second) {
        auto nextIndex = edge.first;
        if (nextIndex == prevIndex) continue;
        auto len = edge.second;
        auto newColor = color;
        if (len % 2 == 1) newColor = !newColor;
        dfs(nextIndex, index, newColor, nodes);
    }
}

int main() {
    int n;
    cin >> n;
    NodeList nodes(n, Node(0, vector<Edge>(0)));
    rep(i, n - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        nodes[u].second.push_back(make_pair(v, w));
        nodes[v].second.push_back(make_pair(u, w));
    }
    dfs(0, -1, 0, nodes);
    rep(i, n) {
        auto node = nodes[i];
        cout << node.first << endl;
    }
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int inv(int a);
long long  C(long long n,long long m);
int main(){
	long long x,y;
	cin>>x>>y;
	long long a,b;
	a=2*x-y;
	b=2*y-x;
	if(a%3!=0||b%3!=0)
		cout<<0<<endl;
	else {
		a=a/3;b=b/3;
		cout<<C(a+b,a)%mod<<endl;
	}
	return 0;
} 



int inv(int a)
{
	return a==1?1:(long long)(mod-mod/a)*inv(mod%a)%mod;
}
long long C(long long n,long long m)
{
	if(m<0)return 0;
	if(n<m)return 0;
	if(m>n-m)m=n-m;
	long long up=1,down=1;
	for(long long i=0;i<m;i++)
	{
		up=up*(n-i)%mod;
		down=down*(i+1)%mod;
	}
	return up*inv(down)%mod;
}

Measured memory_bytes: 256
from collections import defaultdict

H,W,N = map(int, input().split())
sy, sx = map(int, input().split())
T = input()
A = input()

td = defaultdict(int)
ad = defaultdict(int)

for i in range(N):
    td[T[i]] += 1

    # 落とせるか判定
    if sx + max(0, td["R"] - ad["L"]) > W \
    or sx - max(0, td["L"] - ad["R"]) < 1 \
    or sy + max(0, td["D"] - ad["U"]) > H \
    or sy - max(0, td["U"] - ad["D"]) < 1:
        print("NO")
        exit()

    if A[i] == "L":
        ad[A[i]] = min(ad[A[i]] + 1, sx - 1 + td["R"])
    elif A[i] == "R":
        ad[A[i]] = min(ad[A[i]] + 1, W - sx  + td["L"])
    elif A[i] == "U":
        ad[A[i]] = min(ad[A[i]] + 1, sy - 1 + td["D"])
    if A[i] == "D":
        ad[A[i]] = min(ad[A[i]] + 1, H - sy + td["U"])

print("YES") 

Measured memory_bytes: 4040
#include <stdio.h>

int main(void)
{
    int b, r, g, c, s, t;

    while (scanf("%d %d %d %d %d %d", &b, &r, &g, &c, &s, &t), t){
        printf("%d\n", 100 + b * 95 + r * 63 + g * 7 + c * 2 - (t - s) * 3);
    }

    return 0;
}

Measured memory_bytes: 600
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) printf("%d\n",(x));
#define ENDL printf("\n");
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

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

struct Init_On{
    Init_On(){
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(16);
    }
};

signed main(){
    Init_On start;
    int n; cin >> n;
    cout << n << ": ";
    VI v;
    for( register int i = 2 ; i*i <= n ; ++i ){
        while( n % i == 0) {
            n /= i ;
            v.emplace_back(i);
        }
    }
    if(n != 1) v.emplace_back(n);
    /*-------------------------------------------------------------*/
    rep(i , v.size()-1){
        cout << v[i] << " ";
    }
    cout << v[v.size()-1] << endl;
}



Measured memory_bytes: 3208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC061A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            if (a <= c && b >= c)
            {
                     Console.WriteLine("Yes");
            } 
           
             else
            {
                     Console.WriteLine("No");
            }

            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
from copy import deepcopy

def show(o):
    for i in range(10):
        print ' '.join(map(str, o[i]))

def e(o, i, j):
    px = [-1, 0, 0, 1, 0]
    py = [0, -1, 0, 0, 1]
    for k in range(5):
        if i + py[k] >= 0 and j + px[k] >= 0 and i + py[k] < 10 and j + px[k] < 10:
            o[i + py[k]][j + px[k]] = 1 - o[i + py[k]][j + px[k]]

def f(o, n):
    r = [[0] * 10 for i in range(10)]
    for i in range(10):
        if n >> i & 1 == 1:
            e(o, 0, i)
            r[0][i] = 1
    for i in range(1, 10):
        for j in range(10):
            if o[i - 1][j] == 1:
                e(o, i, j)
                r[i][j] = 1
    if 1 not in o[9]:
        show(r)
        return True
    return False

n = int(raw_input())
for _ in range(n):
    o = [map(int, raw_input().split()) for i in range(10)]
    for i in range(2 ** 10):
        if f(deepcopy(o), i):
            break

Measured memory_bytes: 4332
#!/usr/bin/env python3

#from collections import defaultdict
#from heapq import heappush, heappop
#import numpy as np
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7

debug_indent = 0


def debug(*x):
    global debug_indent
    x = list(x)
    indent = 0
    if x[0].startswith("enter") or x[0][0] == ">":
        indent = 1
    if x[0].startswith("leave") or x[0][0] == "<":
        debug_indent -= 1
    x[0] = "  " * debug_indent + x[0]
    print(*x, file=sys.stderr)
    debug_indent += indent


def solve(N):
    # blute
    from math import sqrt, floor
    ret = [0] * (N + 1)
    n = N
    for x in range(1, floor(sqrt(n))):
        v0 = x * x
        for y in range(1, floor(sqrt(n))):
            v1 = v0 + y * y + y * x
            if v1 >= n:
                break
            for z in range(1, floor(sqrt(n))):
                v = v1 + z * z + y * z + z * x
                if v > n:
                    break
                ret[v] += 1
    return ret[1:]


def main():
    # parse input
    N = int(input())
    print(*solve(N), sep="\n")


# tests
T1 = """
20
"""


def test_T1():
    """
    >>> as_input(T1)
    >>> main()
    0
    0
    0
    0
    0
    1
    0
    0
    0
    0
    3
    0
    0
    0
    0
    0
    3
    3
    0
    0
    """
# add tests above


def _test():
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())

    def input():
        return bytes(f.readline(), "ascii")

    def read():
        return bytes(f.read(), "ascii")


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        print("testing")
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 68680
a = gets.chomp.split('')
rem = 15 - a.length
l, w = 0, 0
a.each do |m|
  if m == 'o'
    w += 1
  else
    l += 1
  end
end
if w >= 8 || rem >= 8
  puts 'YES'
elsif rem <= 8 && 8 - w <= rem
  puts 'YES'
else
  puts 'NO'
end

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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    
    vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(3,vector<ll>(2,-1e15)));
    
    dp[0][1][0] = 0;
    
    for (int i = 0; i < n; i++) {
        if(i%2==1){
            dp[i+1][1][1] = dp[i][1][0]+a[i];
            dp[i+1][1][0] = dp[i][2][1];
            dp[i+1][0][0] = max(dp[i][1][1],dp[i][1][0]);
        }else{
            dp[i+1][2][1] = dp[i][1][0]+a[i];
            dp[i+1][1][1] = dp[i][0][0]+a[i];
            dp[i+1][1][0] = max(dp[i][1][0],dp[i][1][1]);
        }
    }
    std::cout << max(dp[n][1][1],dp[n][1][0]) << std::endl;
}


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

int main(void){
	string n;
	cin >> n;
	
	for(int i=0; i<n.size(); i++){
		if(n[i]=='9'){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256