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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n, k;
  cin >> n >> k;
  if(n%k) cout << 1 << endl;
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {

	var SA, SB, SC string
	fmt.Scan(&SA)
	fmt.Scan(&SB)
	fmt.Scan(&SC)

	turn := SA[0]
	for {
		switch turn {
		case byte('a'):
			if len(SA) == 0 {
				fmt.Println("A")
				return
			}
			turn = SA[0]
			SA = SA[1:]
		case byte('b'):
			if len(SB) == 0 {
				fmt.Println("B")
				return
			}
			turn = SB[0]
			SB = SB[1:]

		case byte('c'):
			if len(SC) == 0 {
				fmt.Println("C")
				return
			}
			turn = SC[0]
			SC = SC[1:]
		}
	}
}


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

using int64 = long long;
using i64 = int64;

template<typename T>
using p_que = priority_queue<T>;
template<typename T>
using rp_que = priority_queue<T, vector<T>, greater<T>>;

constexpr int INF = (1 << 30) - 1;
constexpr int64 INF64 = (1ll << 60) - 1;

#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 fs first
#define sc second
#define e_b emplace_back
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	return os << "P(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& m) {
	os << "{" << endl;
	for (auto& e : m) os << "(" << e.first << ", " << e.second << ")" << endl;
	return os << "}";
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& s) {
	os << "{" << endl;
	for (auto& e : s) os << ", " << e << endl;
	return os << "}";
}

template<typename T>
vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int64 gcd(int64 x, int64 y) {
	if (x == 0 || y == 0) return 0;
	int64 r;
	while ((r = y % x) != 0) {
		y = x;
		x = r;
	}
	return x;
}
int64 lcm(int64 x, int64 y) {
	if (x == 0 || y == 0) return 0;
	return x / gcd(x, y) * y;
}

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

void Main();
signed main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	Main();
}

/*----------------------------Insert from here!----------------------------*/

map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

struct UnionFind {
	vector< int > data;

	UnionFind(int sz) {
		data.assign(sz, -1);
	}

	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return (false);
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return (true);
	}

	int find(int k) {
		if (data[k] < 0) return (k);
		return (data[k] = find(data[k]));
	}

	int size(int k) {
		return (-data[find(k)]);
	}
};

/*----------------------------Insert above here----------------------------*/

//const int MOD = 998244353;
//const int MOD = 1e9 + 7;

void Main() {
	int N; cin >> N;
	vector<int> a(N);
	rep(i, N) cin >> a[i];

	auto b = a;
	sort(all(b));

	map<int, int> mp;
	UnionFind uf(b[N - 1] + 1);
	for (int i = 0; i < N; ++i) {
		auto prime = prime_factor(a[i]);
		for (auto& e : prime) {
			if (mp.count(e.first) == 0) mp[e.first] = a[i];
			else uf.unite(mp[e.first], a[i]);
		}
	}
	for (int i = 0; i < N; ++i) {
		if (uf.find(a[i]) == uf.find(b[i])) {
		} else {
			cout << 0 << endl;
			return;
		}
	}

	cout << 1 << endl;
}


Measured memory_bytes: 4472
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
Ar = list(reversed(A))
for i in range(1,N):
    Ar[i] += Ar[i-1]
ans = 0
Ar = list(reversed(Ar))
for i in range(N-1):
    ans += A[i]*Ar[i+1]
    ans %= mod
print(ans)

Measured memory_bytes: 31724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }

    int now = 0, cnt = 0;
    while (now != 1 && cnt < n + 1) {
        now = a[now];
        cnt++;
    }
    if (now == 1) {
        cout << cnt << endl;
    } else cout << -1 << endl;
}


Measured memory_bytes: 640
c1=list(map(int,input().split()))
c2=list(map(int,input().split()))
c3=list(map(int,input().split()))
print('Yes' if c1[0]-c1[1]==c2[0]-c2[1]==c3[0]-c3[1] and c1[2]-c1[1]==c2[2]-c2[1]==c3[2]-c3[1] and c2[0]-c3[0]==c2[1]-c3[1]==c2[2]-c3[2] and c1[0]-c2[0]==c1[1]-c2[1]==c1[2]-c2[2] else 'No')

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

const int mod = 1000000007;

int main(){
    int n;
    cin >> n;
    int list[n];
    long long int sum = 0;
    for (int i = 0; i < n; ++i){
        cin >> list[i];
        sum += list[i];
        sum %= mod;
    }
    long long int result = 0;
    for (int i = 0; i < n; ++i){
        sum -= list[i];
        if (sum < 0) sum += mod;
        result += (sum * list[i]);
        result %= mod;
    }
    cout << result << "\n";
}


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

using namespace std;

int main()
{
    int num,num_1,Accepted=0,wrong=0,l;
    cin>>num>>num_1;
    vector<int> a[num+1];
    int visited_array[ num+1 ]={0};
    for(int i=1; i<=num_1 ;i++)
    {
        string word;
        cin>>l>>word;
        if( word =="AC" ){
            a[l].push_back(1);
            visited_array[l]=1;}
        else
            a[l].push_back(0);
    }
    int visit[num+1]={0};
    for( int i=1;i<=num;i++ )
    {
        for(int j=0 ; j<a[i].size() ; j++ )
        {
            if( a[i][j]==1 && visit[i]==0 )
            {
                Accepted++;
                visit[i]=1;
                break;
            }
            else if( a[i][j]==0 && visit[ i ]==0 && visited_array[i]==1 )
                wrong++;

        }
    }
    cout<<Accepted<<" "<<wrong<<endl;
    return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int a, b; cin >> a >> b;
  int x=2;
  cout<<(a+b+x-1)/x<<endl;

    return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,c;
  cin >> n >> c;
  vector<vector<int>> d(c,vector<int>(c)),field(n,vector<int>(n));
  for(int i=0;i<c;i++){
    for(int j=0;j<c;j++){
      cin >> d[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> field[i][j];
      field[i][j]--;
    }
  }
  vector<vector<LL>> total(c,vector<LL>(3,0));
  for(int k=0;k<c;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        total[k][(i+j)%3]+=d[field[i][j]][k];
      }
    }
  }
  LL ans=1000000000000000000;
  for(int i=0;i<c;i++){
    for(int j=0;j<c;j++){
      for(int k=0;k<c;k++){
        if(i!=j&&j!=k&&k!=i) ans=min(ans,total[i][0]+total[j][1]+total[k][2]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(1e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v){
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}


void solve(int &test) {
    int n;
    cin >> n;
    int ans =0;
    for(int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if(x%2 && i%2)ans++;
    }
    cout << ans << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   
    start = clock(); 

   
    int t = 1;
    

    cout << fixed << setprecision(2);
     
    for(int i = 1; i <= t; ++i){
        solve(i); 
    }

    cerr << time(start);
    return 0;
}

Measured memory_bytes: 3796
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

N = int(input())
if N%1000==0:
    print(0)
else:
    a = int(N/1000) + 1
    print(a*1000 - N)


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    int T=1;
    //cin >> T;
    while(T--){
     ll n,x;
     cin>>n;
     ll a[n]={0};
     rep(i,n-1){
        cin>>x;
        x--;
        a[x]++;
     }
     rep(i,n) cout<<a[i]<<el;

    }

    return 0;
}

Measured memory_bytes: 5216
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	mps := make([]int, 26)

	st := sc.NextLine()
	for _, v := range st {
		mps[v-'a']++
	}

	for i := 0; i < N-1; i++ {
		tmp := make([]int, 26)

		st := sc.NextLine()
		for _, v := range st {
			tmp[v-'a']++
		}
		for j := 0; j < 26; j++ {
			if mps[j] > tmp[j] {
				mps[j] = tmp[j]
			}
		}
	}
	for j := 0; j < 26; j++ {
		fmt.Print(strings.Repeat(string('a'+j), mps[j]))
	}
	fmt.Println()

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

using i64 = int64_t;

i64 rec(i64 h, map<i64, i64> &memo){
    if(memo.count(h))return memo[h];
    if(h == 1)return 1;
    return memo[h] = rec(h/2, memo) * 2 + 1;
}

int main(){
    i64 h;
    cin >> h;
    map<i64, i64> memo;
    cout << rec(h, memo) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  vector<int> num(2000);
  for(int i = 10*B; i < 10*B + 10; i++){
    num[i]++;
  }
  if(A%2 == 0){
    for(int i = 25*A/2; i <= 25*A/2 + 12; i++){
      num[i]++;
    }
  }
  if(A%2 == 1){
    for(int i = 25*A/2 + 1; i < 25*(A + 1)/2; i++){
      num[i]++;
    }
  }
  int ans = -1;
  for(int i = 0; i < 2000; i++){
    if(num[i] == 2){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST_IO   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin);freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define mfill(a,v) memset(a,v,sizeof(a))
#define INF 0x3f3f3f3f
#define MAX 5000005
#define v_n 5005
#define LL long long
#define e_n 5000005
#define MOD 1000000007
#define eps 0.000000001
#define Blen 32
using namespace std;
int N;
struct p {
	int par, sz;
};
p ufs[MAX];
vector<int> g[MAX];
int col[MAX];
void Init()
{
	for (int i = 1; i <= N; i++)
	{
		ufs[i].par = i;
		ufs[i].sz = 1;
	}
}
int Find(int i)
{
	if (ufs[i].par == i)
		return i;
	return ufs[i].par = Find(ufs[i].par);
}
bool Union(int i, int j)
{
	int si = Find(i), sj = Find(j);
	if (si == sj)
	{
		return 0;
	}
	else if (ufs[si].sz < ufs[sj].sz)
	{
		ufs[si].par = sj;
		ufs[sj].sz += ufs[si].sz;
	}
	else
	{
		ufs[sj].par = si;
		ufs[si].sz += ufs[sj].sz;
	}
	return 1;
}
struct e {
	int s, t;
	LL w;
};
vector<e> hh;
void dfs(int r)
{
	for (auto one : g[r])
	{
		if (col[one] == 0)
		{
			col[one] = 3 - col[r];
			dfs(one);
		}
	}
}
int main(void)
{
	int i, j, k;
	FAST_IO;
	//Relocate;
	LL w;
	cin >> N;
	Init();
	up(i, 2, N)
	{
		cin >> j >> k >> w;
		if (!(w & 1))
		{
			Union(j, k);
		}
		else
		{
			hh.push_back(e{ j,k,w });
		}
	}
	if (hh.empty())
	{
		up(i, 1, N)
		{
			cout << 0 << endl;
		}
		return 0;
 
	}
	int r;
	for (auto one : hh)
	{
		int rs = Find(one.s);
		int rt = Find(one.t);
		r = rs;
		g[rs].push_back(rt);
		g[rt].push_back(rs);
	}
	col[r] = 1;
	dfs(r);
	up(i, 1, N)
	{
		cout << col[Find(i)] - 1 << endl;
	}
	return 0;
}

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

#define ll int64_t
using namespace std;
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const ll MOD=998244353;


ll Power(ll base , ll e)
{
    if(e == 0) return 1;
    ll ans = base; e--;
    while(e)
  {
        if(e & 1) ans = (((ans%MOD) * (base%MOD)) %MOD+MOD)%MOD;
        base = (((base%MOD) * (base%MOD)) %MOD+MOD)%MOD;
        e >>= 1;
  }
  return (ans+MOD) %MOD;
}

ll modinv(ll k)
    {
        ll ans=(Power(k, MOD-2)+MOD)%MOD;
        return ans;
    }


int main(){
    IOS
    ll n,s;
    cin>>n>>s;
    vector<ll> v(n+1);
    FOR(i,1,n) cin>>v[i];
    ll dp[n+1][s+1];
    ll powerof2[4000];
    powerof2[0]=1;
    FOR(i,1,3500) {
        powerof2[i]=(powerof2[i-1]*2)%MOD;
    }
    fo(i,n+1){
        fo(j,s+1){
            
            dp[i][j]=0;
        }
    }
    dp[0][0]=(powerof2[n])%MOD;
    
    ll inv2=modinv(2);
  
    
    FOR(i,1,n){

        FOR(j,0,s){
           
            dp[i][j]=(dp[i-1][j]+dp[i][j]+MOD)%MOD;
            //if(i==2&&j==0) dbg2("Dfsd",dp[2][0]);

 
            if(j-v[i]>=0) {
                //if(i==2&&j==0) dbg("Dfsd");
                ll tmp=(dp[i-1][j-v[i]]*inv2)%MOD;

                dp[i][j]=(tmp+dp[i][j]+MOD)%MOD;
            }
            //dbg3(dp[i][j],i,j);
        }
    }
       
    cout<<(dp[n][s])%MOD<<endl;

}


Measured memory_bytes: 74008
#!/usr/local/bin/ruby
while line=gets
   rec=line.split(" ").map(&:to_i)
   x,y=rec[0].to_i,rec[1].to_i
   s=x*y
   while true
      k = x % y
      x = y
      y = k
      gcd = x
      break if k==0
   end
   lcm = s/gcd
   puts "#{gcd} #{lcm}"
end

Measured memory_bytes: 6096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args> void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int a,b;
  cin >> a >> b;
  vector<vector<char> > ans(100, vector<char>(100,'.'));
  rep(y,100) {
    for (int x = 50; x < 100; ++x) { //左半分を白、右半分を黒
      ans[y][x] = '#';
    }
  }
  int bcnt = 0;
  for (int x = 0; x < 50; x += 2) {
    for (int y = 0; y < 100; y += 2) {
      if (bcnt == b-1) break;
      ans[y][x] = '#';
      bcnt++;
    }
  }
  int wcnt = 0;
  for (int x = 100-1; x >= 50; x -= 2) {
    for (int y = 0; y < 100; y += 2) {
      if (wcnt == a-1) break;
      ans[y][x] = '.';
      wcnt++;
    }
  }
  print(100, 100);
  rep(y,100) {
    rep(x,100) {
      cout << ans[y][x];
    }
    cout << "\n";
  }
  return 0;
}

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

using namespace std;

#define MOD 998244353

int n, a[330], dp[300*303], d2[300*303], ans = 1, sum;

int expo(int b, int e) {
    if(e == 0) return 1;
    if(e & 1) return 1ll * b * expo(1LL * b * b % MOD, e >> 1) % MOD;
    return expo(1LL * b * b % MOD, e >> 1);
}

int inv_mod(int x) { return expo(x, MOD - 2); }

int main() {
    scanf("%d", &n);

    dp[0] = d2[0] = 1;
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);

        sum += a[i];
        ans = 3LL * ans % MOD;

        for(int v = n * 300; v >= 0; v--) {
            dp[v] = (2LL * dp[v] % MOD + (v >= a[i] ? dp[v - a[i]] : 0)) % MOD;
            d2[v] =       (d2[v] % MOD + (v >= a[i] ? d2[v - a[i]] : 0)) % MOD;
        }
    }

    for(int i = sum; 2*i >= sum; i--)
        ans = (ans - 3LL * dp[i] % MOD + MOD) % MOD;

    if(sum % 2 == 0) ans = (ans + 3LL * d2[sum/2] % MOD) % MOD;

    printf("%d\n", ans);
    return 0;
}


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

class d {
  int n, q;
  vector<vector<int>> g;
  vector<int> ans;

  void dfs(int from, int parent = -1) {
    for (auto &&to : g[from]) {
      if (to == parent) continue;
      ans[to] += ans[from];
      dfs(to, from);
    }
  }

 public:
  d() {
    cin >> n >> q;

    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      cin >> a >> b;

      a--;
      b--;

      g[a].push_back(b);
      g[b].push_back(a);
    }

    ans.resize(n, 0);
    for (int i = 0; i < q; i++) {
      int p, x;
      cin >> p >> x;

      p--;
      ans[p] += x;
    }

    dfs(0);

    for (int i = 0; i < n; i++) {
      cout << ans[i] << (i + 1 != n ? " " : "\n");
    }
  };
};

int main() {
  new d();
  return 0;
}

Measured memory_bytes: 20352
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    int a, b, k;
    cin >> k >> a >> b;
    
    for(int i = a; i <= b; i++){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3636
S = input()
odd = ('R', 'U', 'D')
even = ('L', 'U', 'D')
flg = True

for i in range(0, len(S), 2):
    if S[i] not in odd:
        flg = False

for i in range(1, len(S), 2):
    if S[i] not in even:
        flg = False

print('Yes') if flg == True else print('No')


Measured memory_bytes: 38352
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>

using namespace std;

typedef unsigned long long ull;

ull K;

int main(void) {
	cin >> K;
	int N = 50;
	ull a[50];

	printf("%d\n",N);
	ull add = K / N;
	for (int i = 0; i < N; ++i) {
		a[i] = add + i;
	}

	for (int i = 0, end = K%N; i < end; ++i) {
		a[i] += N;
		for (int j = 0; j < 50; ++j) {
			if (i == j)
				continue;
			a[j] -= 1;
		}
	}
	printf("%ld", a[0]);
	for (int i = 1; i < N; ++i)
		printf(" %ld", a[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [[] for _ in range(N)]
for i in range(N):
  A_i = int(input())
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))

max_person = 0
for i in range(2**N):
  judge = True
  bin_num = bin(i)
  times = 0
  for j in reversed(bin_num):
    if j == "b":
      break
    if j == "1":
      for k in a[times]:
        if ((i >> k[0]-1) & 1) != k[1]:
          judge = False
    times += 1
  true_person = bin_num.count("1")
  if judge == True:
    max_person = max(max_person, true_person)
print(max_person)

Measured memory_bytes: 8968
s = str(input())
ans = 0

for i in range(len(s)-1,0,-1):
    if i%2!=0:
        continue

    if s[0:i//2] == s[i//2:i] and i > ans :
        ans = i
    elif i <= ans:
        break

if len(s)==2:
    ans = 2
print(ans)

Measured memory_bytes: 8864
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {
        var r1r2 = Console.ReadLine().SplittedStringToInt32List();
        Console.WriteLine((double)(r1r2[0]*r1r2[1])/( r1r2[0] + r1r2[1]));

        Console.ReadLine();
    }

    public static long f(long n,long b)
    {
        if (n < b)
        {
            return n;
        }
        else
        {
            return f((long)Math.Floor((double)n/b),b) + n % b;
        }
    }

    public static string N(long n,long b)
    {
        var sb = new StringBuilder();
        while (true)
        {
            sb.Append((n % b).ToString());
            n /= b;
            if (n < b)
            {
                sb.Append(n.ToString());
                break;
            }
        }
        return new string( sb.ToString().Reverse().ToArray() );
    }

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<long> SplittedStringToInt64List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;
    public const int Mod1e9 = 1000000007;
    

    public static void PrintArray(int[,] array)
    {
        for (int i = 0; i < array.GetLength(0); i++)
        {
            var sb = new StringBuilder();
            for (int j = 0; j < array.GetLength(1); j++)
            {
                sb.Append(array[i, j]).Append(" ");
            }
            Console.WriteLine(sb.ToString());
        }
    }

    #endregion
}



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

int main() {
    int N; cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; ++i) cin >> L[i];
    
    sort(L.begin(), L.end());
    int res = 0;
    for(int i = 0; i < N - 2; ++i) {
        for(int j = i+1; j < N - 1; ++j) {
            auto it = lower_bound(L.begin(), L.end(), L[i] + L[j]);
            int ng = (int)distance(it, L.end());
            res += N - 1 - j - ng;
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
template<class T> inline bool chmin(T& a, T b){
  if (a > b){
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b){
  if (a < b){
    a = b;
    return true;
  }
  return false;
}

int main(){
  cout << fixed << setprecision(15);
  
  ll a; cin >> a;

  ll ans = 0;
  ll b = 1;
  ll d = 0;
  while (b * b <= a){
    if (a % b == 0) chmax(d, b);
    b++;
  }
  ll c = a / d;
  ans = d + c - 2;
  
  cout << ans << endl;
  return 0;
}

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

class BinaryTree
{
private:
  struct Node
  {
    int parent;
    int left;
    int right;

    Node():
      parent(NIL),
      left(NIL),
      right(NIL)
    {}
  };

  static const int NIL = -1;
  std::vector<Node> Tree;

public:
  explicit BinaryTree(int n):
    Tree(n)
  {}

  void set(int id, int l, int r)
  {
    Tree.at(id).left = l;
    Tree.at(id).right = r;

    if (l != NIL)
      Tree.at(l).parent = id;
    if (r != NIL)
      Tree.at(r).parent = id;
  }

  int root()
  {
    int root = 0;

    std::vector<Node>::const_iterator it = Tree.begin();
    for (; it != Tree.end(); ++it)
    {
      if (it->parent == NIL)
        break;
      ++root;
    }

    return root;
  }

  void print_preorder(int id)
  {
    if (id == NIL)
      return;

    std::cout << ' ' << id;
    print_preorder(Tree.at(id).left);
    print_preorder(Tree.at(id).right);

    if (Tree.at(id).parent == NIL)
      std::cout << std::endl;
  }

  void print_inorder(int id)
  {
    if (id == NIL)
      return;

    print_inorder(Tree.at(id).left);
    std::cout << ' ' << id;
    print_inorder(Tree.at(id).right);

    if (Tree.at(id).parent == NIL)
      std::cout << std::endl;
  }

  void print_postorder(int id)
  {
    if (id == NIL)
      return;

    print_postorder(Tree.at(id).left);
    print_postorder(Tree.at(id).right);
    std::cout << ' ' << id;

    if (Tree.at(id).parent == NIL)
      std::cout << std::endl;
  }
};

int main()
{
  int n;
  std::cin >> n;

  BinaryTree tree(n);

  for (int i = 0; i < n; ++i)
  {
    int id, left, right;
    std::cin >> id >> left >> right;
    tree.set(id, left, right);
  }

  int root = tree.root();

  std::cout << "Preorder" << std::endl;
  tree.print_preorder(root);
  std::cout << "Inorder" << std::endl;
  tree.print_inorder(root);
  std::cout << "Postorder" << std::endl;
  tree.print_postorder(root);

  return 0;
}


Measured memory_bytes: 3092
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 100005
using namespace std;
int n,s[MN][2],tt=1;char ch[MN];long long l;
long long dfs(int x,long long y){return (!y)?0:(!x?(y&(-y)):dfs(s[x][0],y-1)^dfs(s[x][1],y-1));}
int main(){
	scanf("%d%lld",&n,&l);
	for(int i=1;i<=n;i++){
		scanf("%s",ch);int len=strlen(ch),now=1;
		for(int j=0;j<len;j++){
			int tmp=ch[j]-'0';
			if(!s[now][tmp])s[now][tmp]=++tt;
			now=s[now][tmp];
		}
	}printf("%s\n",dfs(1,l+1)?"Alice":"Bob");
}


Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    cout << (a<b&&n>1?(n-2)*(b-a)+1:(a==b?1:0)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll X, Y;

//拡張拡張Euclidの互除法による(階乗)逆元の求め方
//O(N)
void stairs(long long N, vector<long long>& st, long long mod = 1e9 + 7) {
	st.resize(N + 1, 1);
	for (long long n = 2; n <= N; n++) {
		st[n] = (st[n - 1] * n) % mod;
	}
}

ll stair(ll N, ll mod = 1e9 + 7) {
	ll ans = 1;
	for (ll n = 2; n <= N; n++)ans = (ans * n) % mod;
	return ans;
}

void modinvs(long long N, vector<long long>& inv, vector<long long>& sinv, long long mod = 1e9 + 7) {
	inv.resize(N + 1);
	sinv.resize(N + 1);
	inv[1] = 1;
	sinv[0] = 1;
	sinv[1] = 1;
	for (int n = 2; n <= N; n++) {
		inv[n] = mod - (inv[mod % n] * (mod / n)) % mod;
		sinv[n] = (sinv[n - 1] * inv[n]) % mod;
	}
}

//(n^(-1),(n!)^(-1))
pll modinvs(ll N, ll mod = 1e9 + 7) {
	vector<ll> inv(N + 1);
	inv[1] = 1;
	ll sinv = 1;
	for (int n = 2; n <= N; n++) {
		inv[n] = mod - (inv[mod % n] * (mod / n)) % mod;
		sinv = (sinv * inv[n]) % mod;
	}
	return pll(inv[N], sinv);
}

long long Comb(long long n, long long k, vector<long long>& st, vector<long long>& sinv, long long mod = 1e9 + 7) {
	long long ans = st[n];
	ans = (ans * sinv[n - k]) % mod;
	ans = (ans * sinv[k]) % mod;
	return ans;
}

ll Comb(ll N, ll K, ll mod = 1e9 + 7) {
	if (K == 0 || K == N)return 1;
	ll ans = stair(N,mod);
	ans = (ans * modinvs(N - K).second) % mod;
	ans = (ans * modinvs(K).second) % mod;
	return ans;
}

int main() {
	cin >> X >> Y;
	ll x = X + Y;
	ll y = 2 * Y - X;
	if (y >= 0 && x % 3 == 0 && y % 3 == 0 && y <= x) {
		x /= 3;
		y /= 3;
		cout << Comb(x, y) << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 3552
#include<set>    
#include<iostream>    
using namespace std;
int main()
{
    set<string>s;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        string x;
        cin>>x;
        s.insert(x);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19256
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define inf 1e18
#define all(v) (v).begin(),(v).end()
using namespace std;

vector <int> dx = {-1,1,0,0};
vector <int> dy = {0,0,-1,1};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;cin>>s;
	if(s[s.length()-1] == 's'){
		cout << s + "es" <<"\n";
	}else{
		cout << s + "s"<<"\n";
	}
	return 0;
}

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

#define sfor(i,a,n) for(int i=a;i<n;i++)
#define efor(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define t int tc; cin>>tc; while(tc--)
#define ll long long
const ll mod=1000000007;

int solve(){
    return 0;
}
int32_t main(){
    static const int _ = []() {
        ios::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        return 0;
    }();
    int n;
    vector<int> vec;
    //idhar dekho idhar
    map<string, int> mp;
    string s1,s2;
    cin>>s1>>s2;
    int num1, num2;
    cin>>num1>>num2;
    mp[s1]=num1;
    mp[s2]=num2;
    string temp;
    cin>>temp;
    mp[temp]=mp[temp]-1;
    cout<<mp[s1]<<" "<<mp[s2]<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

ll int2int(ll src, int base) {
  string res;
  while(src != 0) {
    char c = src%base;
    if (c < 10) c += '0';
    else c += 'a'-10;
    res = string(1,c) + res;
    src /= base;
  }
  FOR(it, res) if (!isdigit(*it)) return -1;
  return atoi(res.c_str());
}

int main() {
  ll A,B,C;
  while(cin>>A>>B>>C,A!=-1) {
    bool f = 0;
    for (int i=2; i<=16; ++i) {
      if (B == int2int(A,i)) {
        f = 1;
        break;
      }
    }
    if (!f) {
      puts("-1");
      continue;
    }
    for (int i=A+1; i<=C; ++i) {
      ll next = -1;
      for (int j=2; j<=16; ++j) {
        ll k = int2int(i,j);
        if (k >= B) {
          if (next == -1 || next > k) {
            next = k;
          }
        }
      }
      B = next;
    }
    cout << B << endl;
  }
}

Measured memory_bytes: 1216
class Facts

  def initialize(mod=10**9+7, n_max=1)
    @mod = mod
    @n_max = n_max
    @fact = [1, 1]
    @inv = [0,1]
    @factinv = [1, 1]
    setup_table(n_max) if 1 < @n_max
  end

  def cmb(n,r)
    return 0 if r < 0 || n < r
    setup_table(n) if @n_max < n
    @fact[n] * (@factinv[r] * @factinv[n-r] % @mod) % @mod
  end

  def factorial(n)
    setup_table(n) if @n_max < n
    @fact[n]
  end

  def hom(n,k)
    cmb(n+k-1, k)
  end

  def prm(n,k)
    setup_table(n) if @n_max < n
    @fact[n] * @factinv[n-k] % @mod
  end

  private
    # O(t)
    def setup_table(t)
      (@n_max+1).upto(t) do |i|
        @fact.push( @fact[-1] * i % @mod )
        @inv.push( -@inv[@mod % i] * (@mod / i) % @mod )
        @factinv.push( @factinv[-1] * @inv[-1] % @mod )
      end
      @n_max = t
    end
end

mod = 10 ** 9 + 7

n, k = gets.to_s.split.map{|t|t.to_i}

B = k
R = n - k

f = Facts.new

1.upto(k) do |i|
  r = R - (i-1)
  b = B - i
  
  ans = f.hom(i, b) * f.hom(i + 1, r) % mod
  puts ans
end

# ABC145 2020/5/6
# ABC156 Roaming 2020/5/11 AC
# ABC167 E - Colorful Blocks 2020/5/11 AC

Measured memory_bytes: 1916
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 aa, bb, cc;
	cin >> aa >> bb >> cc;
	if(aa <= cc && cc <= aa + bb)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
  using namespace std;
   
  int main() {
    int N;
    cin >> N;
    vector<int> buttons(N, 0);
    for(int i=0;i<N;i++) {
      cin >> buttons[i];
    }
    int cur = 1, count = 0;
    while(true) {
      int next = buttons[cur-1];
      buttons[cur-1] *= -1;
      //cout << "cur="<<cur<<"  next="<<next<<endl;
      count++;
      if (next < 0) {
        count = -1;
        break;
      }
      if (next == 2) {
        break;
      }
      cur = next;
    }
    cout << count << endl;
  }


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

char c1[] = { ' ', '.', ',', '!', '?', };
char c2[] = { 'c', 'a', 'b', };
char c3[] = { 'f', 'd', 'e', };
char c4[] = { 'i', 'g', 'h', };
char c5[] = { 'l', 'j', 'k', };
char c6[] = { 'o', 'm', 'n', };
char c7[] = { 's', 'p', 'q', 'r', };
char c8[] = { 'v', 't', 'u', };
char c9[] = { 'z', 'w', 'x', 'y', };

char get_c(char a, int cnt) {
        if (a == '1') return c1[cnt % 5];
        if (a == '2') return c2[cnt % 3];
        if (a == '3') return c3[cnt % 3];
        if (a == '4') return c4[cnt % 3];
        if (a == '5') return c5[cnt % 3];
        if (a == '6') return c6[cnt % 3];
        if (a == '7') return c7[cnt % 4];
        if (a == '8') return c8[cnt % 3];
        if (a == '9') return c9[cnt % 4];
        return 0;
}

int main() {
        int n;
        cin >> n;
        while (n --) {
                string s;
                cin >> s;
                bool doing = false;
                int cnt = 0;
                char now;
                for (int i = 0; i < s.size(); i ++) {
                        if (s[i] != '0') {
                                doing = true;
                                cnt ++;
                                now = s[i];
                        } else {
                                if (!doing) continue;
                                else {
                                        cout << get_c(now, cnt);
                                }
                                doing = false;
                                cnt = 0;
                        }
                }
                cout << endl;
        }
        return 0;
}

Measured memory_bytes: 3204
#include<stdio.h>
#define N 50
int p[N];

int fib(int x){
  if(x==0 || x==1) return p[x]=1;
  if(p[x] != -1) return p[x];
  return p[x] = fib(x-1)+fib(x-2);
}

int main(){
  
  int n,i;

  for(i=0;i<N;i++){
    p[i]=-1;
  }
    scanf("%d\n",&n);
    printf("%d\n",fib(n));

    return 0;
  }



Measured memory_bytes: 2044
a, b, c = map(int, input().split())

ans = ''

if a % b == 0:
    if c == 0:
        ans = 'YES'
    else:
        ans = 'NO'
else:
    k = a % b
    for x in range(101):
        if (k * x) % b == c:
            ans = 'YES'
            break
    else:
        ans = 'NO'

print(ans)


Measured memory_bytes: 9064
# -*- coding: utf-8 -*-


class Dice:
    def __init__(self, n):
        self.upper    = n[0]
        self.backward = n[1]
        self.right    = n[2]
        self.left     = n[3]
        self.ahead    = n[4]
        self.bottom   = n[5]

    def __eq__(self, other):
        return self.upper == other.upper and self.backward == other.backward and self.right == other.right \
               and self.left == other.left and self.ahead == other.ahead and self.bottom == other.bottom

    def roll_north(self):
        self.upper, self.ahead, self.bottom, self.backward = self.backward, self.upper, self.ahead, self.bottom

    def roll_south(self):
        self.upper, self.ahead, self.bottom, self.backward = self.ahead, self.bottom, self.backward, self.upper

    def roll_east(self):
        self.upper, self.right, self.bottom, self.left = self.left, self.upper, self.right, self.bottom

    def roll_west(self):
        self.upper, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.upper

    def roll_side(self):
        self.ahead, self.right, self.backward, self.left = self.left, self.ahead, self.right, self.backward


def match_dice(dice1, dice2):
    for i in range(4):
        dice1.roll_north()

        for j in range(4):
            dice1.roll_east()

            for k in range(4):
                dice1.roll_side()

                if dice2 == dice1:
                    return 0
    return 1


n = int(input())
dice_list = []
result = []

for i in range(n):
    dice_list.append(Dice(list(map(int, input().split()))))

for i in range(n):
    for j in range(n):
        if i != j:
            result.append(match_dice(dice_list[i], dice_list[j]))

if 0 in result:
    print('No')
else:
    print('Yes')



Measured memory_bytes: 5684
/*

    author : s@if

*/

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

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			99999999
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)


bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

	cin>>p>>q>>r;
  
 	int ans = p+q;
  	ans = min(ans,q+r);
  	ans = min(ans,p+r);
  	
  	cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256