akhauriyash/Code-Regression huggingface dataset:
def warshall_floyd(graph, edges):
    N = len(graph)
    inf = Infinity()  # !_!
    for i in xrange(N):
        for j in xrange(N):
            if i == j:
                graph[i][j] = 0
            else:
                graph[i][j] = inf
    for e in edges:
        graph[e.source][e.destination] = e.weight
    for k in xrange(N):
        for i in xrange(N):
            for j in xrange(N):
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
    for k in xrange(N):
        for i in xrange(N):
            for j in xrange(N):
                if inf in (graph[i][j], graph[i][k], graph[k][j]):  # !_!
                    continue
                if graph[i][j] > graph[i][k] + graph[k][j]:
                    raise NegativeCycleError

def main():
    V, E = map(int, raw_input().split())
    graph = [[None] * V for _ in xrange(V)]
    edges = []
    for _ in xrange(E):
        s, t, d = map(int, raw_input().split())
        edges.append(Edge(s, t, d))
    try:
        warshall_floyd(graph, edges)
        for g in graph:
            print " ".join(map(str, g))
    except NegativeCycleError:
        print "NEGATIVE CYCLE"

class Infinity(object):
    def __eq__(self, other):
        return other is self

    def __lt__(self, other):
        return False

    def __gt__(self, other):
        return True

    def __add__(self, other):
        return self

    def __radd__(self, other):
        return self

    def __str__(self):
        return "INF"
    __repr__ = __str__

class NegativeCycleError(Exception):
    pass

class Edge(object):
    def __init__(self, source, destination, weight):
        self.source = source
        self.destination = destination
        self.weight = weight

if __name__ == "__main__":
    main()

Measured memory_bytes: 8260
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

pair<double, double> solve(int a, int b, int c, int d, int e, int f){
  double pre = b * d - a * e;
  int pre_x = f * b - c * e;
  int pre_y = c * d - a * f;
  pair<double, double> ans;
  
  ans.first = pre_x == 0 ? 0.0 : pre_x / pre;
  ans.second =  pre_y == 0 ? 0.0 : pre_y / pre;

  return ans;
}

int main(){
  int a, b, c, d, e, f;
  vector< pair<double, double> > ans;

  while(cin >> a && cin >> b && cin >> c && cin >> d &&	cin >> e && cin >> f) ans.push_back(solve(a, b, c, d, e, f)); 

  for(int i = 0; i < (int)ans.size(); i++) printf("%.3f %.3f\n", ans[i].first, ans[i].second);
  
  return 0;
}

Measured memory_bytes: 3072
//                          VIVEK UPADHYAY
//                         MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                         TAB -TAK CHODEGA NHI :D
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<endl
#define ok cout<<"ok\n" ;
typedef long long ll;
const int MAXN = 45000 + 10 ;
const int MAX = 1e7 ;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e18 ;
ll gcd(ll a,ll b){
    
    if(a==0) return b;
    
    return gcd(b%a,a);
    
}
int main() {
    
    int N  ;
    cin >> N ;
    ll X ;
    cin >> X ;
    ll a[N] ;
    for(int i=0;i<N;i++){
        cin >> a[i] ;
        a[i]-=X ;
    }
    ll g = abs(a[0]) ;
    
    for(int i=1;i<N;i++)
        g = gcd(g,abs(a[i])) ;
    cout<<g<<endl;
    return 0 ;
}


Measured memory_bytes: 1024
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int extgcd(int a, int b, int &x, int &y){
  int d = a;
  if(b != 0){
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else{
    x = 1;
    y = 0;
  }
  return d;
}

int main() {
  int A, B, x, y; cin >>A >>B;
  extgcd(A, B, x, y);
  cout <<x <<" " <<y <<endl;
  return 0;
}

Measured memory_bytes: 1168
import sys
input = sys.stdin.readline

N = int(input())
edges = [[int(i) for i in input().split()] for _ in range(N-1)]
edge_col = [0]*(N-1)
gp = [[] for _ in range(N)]

for ind, (a, b) in enumerate(edges):
    gp[a-1].append((b-1, ind))
    gp[b-1].append((a-1, ind))

cols = [set(list([x+1 for x in range(len(gp[i]))])) for i in range(N)]

seen = set()
stk = [0]
max_col = 0
while stk:
    pt = stk.pop()
    #print(pt)
    if(pt in seen):
        continue
    seen.add(pt)
    for nxt, ind in gp[pt]:
        if(nxt in seen):
            continue
        col = cols[pt].pop()
        max_col = max(col, max_col)
        edge_col[ind] = col
        try:
            cols[nxt].remove(col)
        except:
            pass

        stk.append(nxt)

print(max_col)
for i in edge_col:
    print(i)


Measured memory_bytes: 117080
#include<bits/stdc++.h>
///...................................*****.................................................///
///        Author :  MD. Rakibul Islam ( mmdrakibul2912@gmail.com )                         ///
///                  Department of Computer Science                                         ///
///                  & Engineering,                                                         ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#define PI 2.0*acos(0.0)
#define ll              long long int
#define ull             unsigned long long int
#define sc              scanf
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define pf              printf
#define MOD             1000000007
#define mx              123456789
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
using namespace std;
int main()
{
    ll n, m, i, j, k, l;
    cin>>n>>m;
    if(n==1 && m==2)
        cout<<3<<endl;
    else if(n==2 && m==3)
        cout<<1<<endl;
    else if(n==1 && m==3)
        cout<<2<<endl;
    else if(n==2 && m==1)
        cout<<3<<endl;
    else if(n==3 && m==2)
        cout<<1<<endl;
    else if(n==3 && m==1)
        cout<<2<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>  //sort,二分探索,など
#include <array>
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <map>            //map(辞書)s
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())  // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2 << endl;
  return 0;
}

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

using namespace std;

int main()
{
	char s[4][110];
	cin>>s[1]>>s[2]>>s[3];
	s[1][strlen(s[1])]='x';
	s[2][strlen(s[2])]='x';
	s[3][strlen(s[3])]='x';
	int h[4]={0},now=1,ans;
	while(1)
	{
		if(s[now][h[now]]=='a')h[now]++,now=1;
		else if(s[now][h[now]]=='b')h[now]++,now=2;
		else if(s[now][h[now]]=='c')h[now]++,now=3;
		else if(s[now][h[now]]=='x'){ans=now;break;}
	}
	char k='A';
	k=k+ans-1;
	printf("%c",k);
	return 0;
}

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


using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  srand((unsigned)time(NULL));
  int d;
  int res = 0;
  cin >> d;
  vector<int> c(26);
  rep(i,26)cin >> c[i];
  vector<vector<int>> v(d,vector<int>(26));
  vector<int> contest(d,0);
  vector<int> last(26,0);
  vector<int> satisfy(26,0);
  rep(i,d)rep(j,26){
    int x;cin >> x;
    v[i][j] = x;
  }
  for(int i = 1;i <= d;i++){
    rep(j,26)if(v[i-1][contest[i-1]] < v[i-1][j])contest[i-1] = j;
    last[contest[i-1]] = i;
    res += v[i-1][contest[i-1]];
    rep(j,26)res -= c[j]*(i-last[j]),satisfy[j] += c[j]*(i-last[j]);
  }
  while(1.0*clock()/CLOCKS_PER_SEC <= 1.9){
    //int now_time = clock();
    //if(1.0*now_time/CLOCKS_PER_SEC > 1.7)break;
    int day = rand()%d,pos = rand()%26;
    vector<int> new_contest = contest;
    int res_ = res;
    int pre = new_contest[day];
    res_ += satisfy[pos];
    res_ += satisfy[pre];
    res_ -= v[day][pre];
    res_ += v[day][pos];
    int pos_satisfy = 0,pre_satisfy = 0;
    last[pos] = last[pre] = 0;
    new_contest[day] = pos;
    for(int i = 1;i <= d;i++)last[pos] = (new_contest[i-1] == pos ? last[pos] = i : last[pos]),pos_satisfy += c[pos]*(i-last[pos]);
    for(int i = 1;i <= d;i++)last[pre] = (new_contest[i-1] == pre ? last[pre] = i : last[pre]),pre_satisfy += c[pre]*(i-last[pre]);
    res_ -= (pos_satisfy+pre_satisfy);
    if(res < res_){
      res = res_;
      contest = new_contest;
      satisfy[pre] = pre_satisfy;
      satisfy[pos] = pos_satisfy;
    }
  }
  rep(i,d)cout << contest[i]+1 << endl;
  


  return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct mint{
	ll x;
	mint(ll x=0):x((x%mod+mod)%mod){}
	friend ostream &operator<<(ostream& os,const mint& a){
		return os<<a.x;
	}
	friend istream &operator>>(istream& is,mint& a){
		ll t;
		is>>t;
		a=mint(t);
		return (is);
	}
	mint& operator+=(const mint a){
		if((x+=a.x)>=mod) x-=mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x+=mod-a.x)>=mod)x-=mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x*=a.x)%=mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if (!t) return 1;
		mint a=pow(t>>1);
		a*=a;
		if(t&1) a*=*this;
		return a;
	}
	// for prime mod
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this)*=a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
};

struct combination{
  vector<mint> fact,ifact;
  combination(int n):fact(n+1),ifact(n+1){
	assert(n<mod);
	fact[0]=1;
	for(int i=1;i<=n;i++) fact[i]=fact[i-1]*i;
	ifact[n]=fact[n].inv();
	for(int i=n;i>=1;i--) ifact[i-1]=ifact[i]*i;
  }
  mint operator()(int n,int k){
	if (k<0 || k>n) return 0;
	return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n);
	map<int,int> mp;
	rep(i,n){
		cin>>a[i];
		mp[a[i]]++;
	}
	int now=n-1;
	bool flag=true;
	while(now>0){
		if(mp[now]!=2){
			flag=false;
			break;
		}
		now-=2;
	}
	if(flag){
		n/=2;
		cout<<mint(2).pow(n)<<endl;
	}else{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 1e5+5;

int main()
{
    string s;
    cin >> s;
    bool ok = 1;
    if(s[3] != s[2]) ok = 0;
    if(s[5] != s[4]) ok = 0;
    if(ok) puts("Yes");
    else puts("No");
}


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



def solve(n,queries):
    def calcTopHeight(h,x,y,cx,cy):
        return h + abs(x-cx) + abs(y-cy)
    def calcHeight(h,x,y,cx,cy):
        return max(h - abs(x-cx) - abs(y-cy), 0)
    cand = [query for query in queries if query[2] != 0][0]
    for cx in range(101):
        for cy in range(101):
            cnt = 0
            probHeight = calcTopHeight(cand[2],cand[0],cand[1],cx,cy)
            for query in queries:
                x,y,h = query
                if calcHeight(probHeight,x,y,cx,cy) == h:
                    cnt += 1
            if cnt == n:
                return cx,cy,probHeight
    return -1,-1,-1


def main():
    N = int(int(input()))
    queries = [list(map(int,input().split())) for _ in range(N)]
    print(*solve(N,queries))
    return
    # write c


if __name__ == '__main__':
    main()


Measured memory_bytes: 9240
#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
ll N;
int cnt;
bool query(ll x){
	cnt++;
	cout<<"? "<<x<<endl;
	char c;
	cin>>c;
	return c=='Y';

//	return (x<=N && to_string(x)<=to_string(N)) || (x>N && to_string(x)>to_string(N));
}

void ans(ll x){
	cout<<"! "<<x<<endl;
}
int main(){
//	cin>>N;


	ll x = 0;
	rep(d,9){
		x*=10;
		int ub = 9, lb = (d==0?0:-1);
		while(ub-lb>1){
			ll m = (ub+lb)/2;
			ll nx = x+m;
			ll tmp = nx;
			while(tmp<1e11) tmp=tmp*10+9;
			if(query(tmp)) ub = m;
			else lb = m;
		}
		x += ub;
	}

	rep1(d,9){
		ll t = 1;
		rep(i,d) t *= 10;
		if(!query(t)){
			rep(j,9-d) x/=10;
			ans(x);
			return 0;
		}
	}

	rep1(d,10){
		ll t = 1;
		rep(i,d) t *= 10;
		t--;
		if(query(t)){
			ans((t+1)/10);
			return 0;
		}
	}
}


Measured memory_bytes: 596
import numpy as np

def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            vars()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

    
def solve(N, M, Ok):
    def solve_half(Ok_half):
        # 半分の辺について全探索
        n = len(Ok_half)
        res = [0] * (1<<M)
        for set_black in range(1<<n):
            r = 0
            for i, Ok_i in enumerate(Ok_half):
                if set_black>>i&1:
                    r |= Ok_i
            res[r] += 1
        return res

    A = solve_half(Ok[:(N-1)//2])
    B = solve_half(Ok[(N-1)//2:])

    def fwt(A):
        n = len(A)
        #for i in range(n.bit_length()-1):
        for i in range(int(np.log2(n))):
            i = 1<<i
            for j in range(n):
                if i&j == 0:
                    A[j|i] += A[j]
        return A

    def ifwt(A):
        n = len(A)
        #for i in range(n.bit_length()-1):
        for i in range(int(np.log2(n))):
            i = 1<<i
            for j in range(n):
                if i&j == 0:
                    A[j|i] -= A[j]
        return A

    A = fwt(A)
    B = fwt(B)
    AB = [a*b for a, b in zip(A, B)]
    AB = ifwt(AB)
    return AB[-1]

numba_compile([
    [solve, "i8(i8,i8,i8[:])"],
])

def main():
    N = int(input())
    G = [[] for _ in range(N)]
    Edges = []
    for _ in range(N - 1):
        a, b = sorted(map(int, input().split()))
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
        Edges.append((a, b))

    def dfs(v, target, p, Path):
        if v == target:
            Path.append(v)
            return True
        for u in G[v]:
            if p != u:
                f = dfs(u, target, v, Path)
                if f:
                    Path.append(v)
                    return True
        return False

    M = int(input())
    UV = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(M)]
    Ok = [0] * (N - 1)
    for idx_UV, (a, b) in enumerate(UV):
        Path = []
        dfs(a, b, -1, Path)
        for v, u in zip(Path, Path[1:]):
            v, u = sorted([v, u])
            idx_Edge = Edges.index((v, u))
            Ok[idx_Edge] |= 1 << idx_UV
    print(solve(N, M, np.array(Ok, dtype=np.int64)))

main()


Measured memory_bytes: 53564
def translate(x,y):
    if x == y[0]:
      return y[1]
    if x == y[1]:
      return y[0]
    return x

s1 = list(input())
s2 = list(input())
list = s1

count = 0
for i in range(len(list)):
    if s1[i] != s2[i]:
      x = s1[i]
      y = s2[i]
      for j in range(len(s1)):
        if s1[j] == x:
          s1[j]=y
        elif s1[j] == y:
          s1[j]=x
      #s1 = s1.translate(str.maketrans( s1[i]+s2[i], s2[i]+s1[i]) )
      #s1.replace( s1[i], "X").replace( s2[i], x).replace( 'X' , y)
      #s1 = list(map(translate, s1))
      
      count = count+1
    if count > 27:
      break

if s1==s2:
  print ("Yes")
else:
  print ("No")


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

const int N_MAX=50;
int N;
vector<int64_t> x(N_MAX),y(N_MAX);

int main(){
  cin>>N;
  map<pair<int64_t,int64_t>,int> S;
  for(int i=0;i<N;++i){
    cin>>x[i]>>y[i];
    ++S[make_pair(x[i],y[i])];
  }

  int ans=100;
  if(N==1) ans=1;
  else{
  for(int i=0;i<N;++i){
    for(int j=0;j<N;++j){
      if(i==j) continue;
      int cnt=0;
      int64_t a=x[i]-x[j],b=y[i]-y[j];
      for(int k=0;k<N;++k){
        if(S[make_pair(x[k]-a,y[k]-b)]==0) ++cnt;
      }
      ans=min(cnt,ans);
    }
  }
  }
  cout<<ans<<endl;
}

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

int main() {
	int n;
	cin >> n;
	string s1, s2;
	cin >> s1 >> s2;
	vector<int>ty;
	while (s1.length() > 0) {
		if (s1.at(0) == s2.at(0)) {
			ty.push_back(0);
			if (s1.length() >= 2) {
				s1 = s1.substr(1);
				s2 = s2.substr(1);
			}
			else break;
		}
		else {
			ty.push_back(1);
			if (s1.length() >= 3) {
				s1 = s1.substr(2);
				s2 = s2.substr(2);
			}
			else break;
		}
	}
	ll ans = 3;
	if (ty.at(0) == 1)ans *= 2;
	for (int i = 1; i < ty.size(); i++) {
		if (ty.at(i - 1) == 0)ans *= 2;
		else {
			if (ty.at(i) == 0)ans *= 1;
			else ans *= 3;
		}
		ans %= 1000000007;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int pMax = 100;
      int n = Integer.parseInt(in.readLine());
      int[] x = new int[n];
      int[] y = new int[n];
      int[] h = new int[n];

      String[] lines;
      for(int i=0; i<n; i++) {
        lines = in.readLine().split(" ");
        x[i] = Integer.parseInt(lines[0]);
        y[i] = Integer.parseInt(lines[1]);
        h[i] = Integer.parseInt(lines[2]);
      }

      for(int py=0; py<=pMax; py++) {
        for(int px=0; px<=pMax; px++) {
          int needH = -1;

          for(int i=0; i<n; i++) {
            if(h[i] == 0) continue;

            int tmpH = h[i] + Math.abs(py - y[i]) + Math.abs(px - x[i]);

            if(needH == -1)
              needH = tmpH;
            else if(needH != tmpH) {
              needH = -2;
              break;
            }
          }

          if(needH == -2)
            continue;

          for(int i=0; i<n; i++) {
            if(h[i] !=0) continue;

            int dist = Math.abs(py - y[i]) + Math.abs(px -x[i]);

            if(needH > dist) {
              needH = -2;
              break;
            }
          }

          if(needH > 0) {
            System.out.println("\n" + px + " " + py + " " + needH);
            return;
          }

        }
      }
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 21204
#include <vector>
#include <map>
#include <math.h>
#include <iostream>
using namespace std;

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

	int dist = abs(a - b);
	int ret = 0;
	if (dist > w) {
		int diff = abs(dist - w);
		ret = diff;
	} 
	cout << ret << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

int ctoi(char c){
    return c-'0';
}

void solve(){
    int N;
    cin >> N;
    
    if (100 <= N && N <= 111) {
        cout << 111 << endl;
    }else if (111 < N && N <= 222){
        cout << 222 << endl;
    }else if (222 < N && N <= 333) {
        cout << 333 << endl;
    }else if (333 < N && N <= 444) {
        cout << 444 << endl;
    }else if (444 < N && N <= 555) {
        cout << 555 << endl;
    }else if (555 < N && N <= 666) {
        cout << 666 << endl;
    }else if (666 < N && N <= 777) {
        cout << 777 << endl;
    }else if (777 < N && N <= 888) {
        cout << 888 << endl;
    }else if (888 < N && N <= 999) {
        cout << 999 << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
ll longinf=(1ll<<60);

string maximum(string s,string t){
      if(s.size()>t.size()) return s;
      else if(t.size()>s.size()) return t;
      else{
            if(s>=t) return s;
            else return t;
      }
}

int main(){
      cin.tie(0);
      ios::sync_with_stdio(false);
      ll n,m;
      cin>>n>>m;
      int a[m];
      rep0(i,m){
            cin>>a[i];
      }
      int match[]={-1,2,5,5,4,5,6,3,7,6};
      string dp[20];
      fill(dp,dp+20,"");
      dp[0]="";
      rep0(j,m){
            dp[match[a[j]]]=maximum(dp[match[a[j]]],to_string(a[j]));
      }
      rep1(i,n){
            rep0(j,m){
                  if(match[a[j]]<i&&dp[(i-match[a[j]])%10]!=""){
                        dp[i%10]=maximum(dp[i%10],dp[(i-match[a[j]])%10]+to_string(a[j]));
                  }
            }
      }
      /*rep0(i,n){
            cout<<dp[i]<<" ";
      }*/
      cout<<dp[n%10]<<endl;



      return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second
#define Mat vector<vector<ll>>
#define Arr vector<ll>
#define Matd vector<vector<ld>>
#define Arrd vector<ld>

class Combination
{
public:
	vector<ll> fact;
	vector<ll> inv;
	ll mod;
	ll mod_inv(ll x)
	{
		ll n = mod - 2LL;
		ll res = 1LL;
		while (n > 0)
		{
			if (n & 1)
				res = res * x % mod;
			x = x * x % mod;
			n >>= 1;
		}
		return res;
	}
	ll nCr(ll n, ll r)
	{
        if(r > n) return 0;
		return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod;
	}
	ll nPr(ll n, ll r)
	{
        if(r > n) return 0;
		return (fact[n] * inv[n - r]) % mod;
	}
	Combination(ll n, ll _mod)
	{
		mod = _mod;
		fact.resize(n + 1);
		fact[0] = 1;
		forn(i, n)
		{
			fact[i + 1] = (fact[i] * (i + 1LL)) % mod;
		}
		inv.resize(n + 1);
		forn(i, n + 1)
		{
			inv[i] = mod_inv(fact[i]);
		}
	}
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    const ll mod = 1e9 + 7;
    const ll N = 2005;
    Combination comb(N, mod);
    ll b, r;
    cin >> r >> b;
    r = r - b;
    Mat M(N + 1, Arr(N + 1));
    forn(i, N) M[i][0] = 1;
    forn(j, N) M[0][j] = 0;
    fori(i, 1, N) fori(j, 1, N) M[i][j] = (M[i - 1][j] + M[i][j - 1]) % mod;

    fori(i, 1, b + 1)
    {
        cout << ((comb.nCr(r + 1, i) * M[i][b - i]) % mod) << endl;
    }
    return 0;
}

Measured memory_bytes: 31872
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  lvector A(n),B(1e6+1,1);rep(i,n) cin>>A[i];
  sort(ALL(A));
  rep(i,n) {
    if(B[A[i]]==0) continue;
    if(i+1<n&&A[i]!=A[i+1]) ans++;
    if(i==n-1) ans++;
    for(ll j=A[i];j<=1000000;j+=A[i]) B[j]=0;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 12636
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
	long long a, b, x;
	cin >> a >> b >> x;

	// 0~x
	long long bb = b / x + 1;
	long long aa = (a - 1) / x + 1;
	if (a == 0)
		aa = 0;
	cout << bb - aa << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,a,b,k=1,x1,x2,x3,x4,x5,x,ans=0;
    cin>>n>>a>>b;
    while(k<=n)
    {
        x1=k/10000;
        x2=(k/1000)%10;
        x3=(k/100)%10;
        x4=(k/10)%10;
        x5=k%10;
        x=x1+x2+x3+x4+x5;
        if (x>=a&&x<=b) ans=ans+k;
        k=k+1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector as V

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, k] <- getIntList
    print $ solve n k

solve n k = modN $ sum [mulMod (comb n r) (comb (n-1) r) | r <- [0..n-1], r <= k]

moduloN :: Int
moduloN = 10 ^ 9 + 7

modN = flip mod moduloN

mulMod x y = modN $ x * y

finv :: Int -> Int
finv k = finvs V.! k
    where finvs :: V.Vector Int
          finvs = V.generate (2 * 10 ^ 5 + 1) finv'
              where finv' 0 = 1
                    finv' n = modN $ finvs V.! (n - 1) * inv n

inv :: Int -> Int
inv k = invs V.! k
    where inv' 1 = 1
          inv' n = modN (-(invs V.! r) * q)
              where (q, r) = moduloN `divMod` n
          invs :: V.Vector Int
          invs = V.generate (2 * 10 ^ 5 + 1) inv'

fact :: Int -> Int
fact k = facts V.! k
    where fact' 0 = 1
          fact' n = modN $ n * (facts V.! (n - 1))
          facts :: V.Vector Int
          facts = V.generate (2 * 10 ^ 5 + 1) fact'

comb :: Int -> Int -> Int
comb n k | n < 0 || k < 0 || n < k = 0
         | otherwise = modN $ modN (fact n * finv k) * finv (n - k)

Measured memory_bytes: 39804
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-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 all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }

    return gcd(b, a % b);
}

int main() {
    ll A, B;
    cin >> A >> B;
    cout << A * B / gcd(A, B);
    return 0;
}

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

public static class Program {
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        long[]a=Console.ReadLine().Split().Select(long.Parse).ToArray();
        long[,]dp=new long[n+1,n+1];
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                dp[i,j]=long.MinValue;
            }
        }
        for(int i=0;i<=n;i++){
            dp[i,i]=0;
        }
        for(int len=1;len<=n;len++){
            for(int l=0;l<=n-len;l++){
                int r=l+len;
                dp[l,r]=Math.Max(dp[l,r],-dp[l+1,r]+a[l]);
                dp[l,r]=Math.Max(dp[l,r],-dp[l,r-1]+a[r-1]);
            }
        }

        // for(int i=0;i<=n;i++){
        //     Console.Write($"[dp[{i}]]");
        //     for(int j=0;j<=n;j++){
        //         Console.Write($" {dp[i,j]}");
        //     }
        //     Console.Write("\n");
        // }

        Console.WriteLine(dp[0,n]);
    }
}


Measured memory_bytes: 83552
#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
#define MAX 50010
using namespace std;
int main(){
	int sum,k=0;
	vector<int> pri(MAX);
	vector<int> pre(MAX);
	for(int i=0;i<MAX;i++)
	pri[i]=1;
	pri[0]=0;
	pri[1]=0;
	for(int i=0;i*i<MAX;i++){
		if(pri[i]){
			for(int j=i*2;j<MAX;j+=i){
				pri[j]=0;
			}
		}
	}
	for(int i=0;i<MAX;i++)
	if(pri[i]){
	pre[k++]=i;
	}
	int n;
	while(cin>>n,n){
		sum=0;
		for(int i=0;pre[i]<=n/2;i++){
			if(pri[n-pre[i]])
				sum++;
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

int n;
string s;
map<string,int> mp; 

int main(void){
	scanf("%d",&n);
	ll ans=0;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		sort(s.begin(),s.end());
		ans+=mp[s];
		mp[s]++;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 11136
#include<iostream>
#include<iomanip>
#include<string.h>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);//65 90  97 122
    cin.tie(0);  cout.tie(0);
    int n, m;
    cin >> n >> m;
    if (500 * n < m)cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

int main()
{
  int* W;
  int N;
  int S1 = 0, S2 = 0;
  cin >> N;
  W = new int[N];
  for(int i = 0; i < N; i++) {
    cin >> W[i]; 
    S2 += W[i];
  }
  int min = 200; // > 100
 
  for(int i = 0; i < N - 1; i++) {
    S1 += W[i];
    S2 -= W[i];
    if(min > abs(S1 - S2))
      min = abs(S1 - S2);
  }
  cout << min << endl;
  delete W;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int x, y, z;
    while (1) {
        scanf("%d %d", &x, &y);
        if (x == 0 && y == 0) break;
        if (x > y) {
            z = x;
            x = y;
            y = z;
        }
        printf("%d %d\n", x, y);
    }
    return 0;
}



Measured memory_bytes: 2056
#include <stdio.h>

int n;
int a[100000];
int b[100000];
int c[100000];

int x[100000];
int y[100000];
void sort(int l, int r) {
	if(r - l < 2) { return; }
	
	int m = (l + r) / 2;
	sort(l, m);
	sort(m, r);
	
	int ll = l, rr = m, zz = l;
	while(zz < r) {
		bool flag;
		     if(rr == r) { flag = true;  }
		else if(ll == m) { flag = false; }
		else { flag = (a[ll] <= a[rr]); }
		
		if(flag) { x[zz] = a[ll]; y[zz++] = b[ll++]; }
		else     { x[zz] = a[rr]; y[zz++] = b[rr++]; }
	}
	
	for(int i = l; i < r; i++) { a[i] = x[i]; b[i] = y[i]; }
	
	return;
}

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) { scanf("%d", &a[i]); b[i] = i; }
	
	sort(0, n);
	for(int i = 0; i < n; i++) { c[ b[i] ] = i; }
	
	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans += ( (i % 2) != (c[i] % 2) );
	}
	
	printf("%d\n", ans / 2 );
	
	return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void solve(long long N, std::vector<long long> a){
    ll S = 0;
    REP(i, N) S = S^a[i];
    REP(i, N) {
        ll tmp = S^a[i];
        cout << tmp <<" ";
    }
    cout<<endl;
}
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 4432
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int []h = new int[N];
			int hmax = 0;
			
			for(int i = 0;i<N;i++) {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			}
			int count = 0;
			while(true) {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			}
			
			System.out.println(count);
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 21844
'''
Created on 2020/08/20

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  X,Y=map(int,pin().split())
  if X%Y==0:
    print(-1)
    return 
  print(X)
  return 

main()

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007 //10e9+7
#define INF 0x7FFFFFFF //オーバーフローに注意
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N,M,L,Q;
  cin>>N>>M>>L;
  vector<vector<int>> G(N, vector<int>(N, INF));
  vector<vector<int>> d(N,vector<int>(N, MOD));
  REP(i,M){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    G[a][b]=c;
    G[b][a]=c;
    d[a][b]=c;
    d[b][a]=c;
  }
  
  //距離でワーシャルフロイド
  for (int i = 0; i < N; i++){      // 経由する頂点
    for (int j = 0; j < N; j++){    // 開始頂点
      for (int k = 0; k < N; k++){  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }

  //距離L以下の都市間に重み1の辺を張る
  vector<vector<int>> G2(N, vector<int>(N, INF));
  vector<vector<int>> d2(N,vector<int>(N, MOD));
  REP2(i,1,N)REP(j,i){
    if(d[i][j]<=L){
      G2[i][j]=1;
      G2[j][i]=1;
      d2[j][i]=1;
      d2[i][j]=1;
    }
  }
  for (int i = 0; i < N; i++){      // 経由する頂点
    for (int j = 0; j < N; j++){    // 開始頂点
      for (int k = 0; k < N; k++){  // 終端
        d2[j][k] = min(d2[j][k], d2[j][i] + d2[i][k]);
      }
    }
  }
  //クエリ読み込み
  cin>>Q;
  int s,t;
  REP(i,Q){
    cin>>s>>t;
    if(d2[s-1][t-1]==MOD){
      cout<<"-1"<<endl;
    }else{
      cout<<d2[s-1][t-1]-1<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  for(ll h=1; h<=3500; h++) {
    for(ll n=1; n<=3500; n++) {
      ll a = (4*h*n-N*n-N*h);
      ll b = N*h*n;
      if(a!=0 && b%a==0 && b/a<=3500 && b/a>=1) {
        cout << h << ' ' << n << ' ' << b/a << "\n";
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
int n, s, g;
V<int> v, e[N];
bool dfs1(int a, int p){
  if (a==g) return true;
  for(int b:e[a]) if(p!=b){
    v.pb(b);
    if(dfs1(b, a)) return true;
    v.pop_back();
  }
  return false;
}
int dfs2(int a, int p){
  int ma = 0;
  for(int b:e[a]) if(p!=b) maxs(ma, dfs2(b, a)+1);
  return ma;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> s >> g;
  s--; g--;
  FOR(_, 0, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    e[a].pb(b);
    e[b].pb(a);
  }
  v.pb(s);
  dfs1(s, -1);
  int l = sz(v);
  cout << dfs2(v[l/2-1], v[l/2]) + (l-1)/2 << endl;
}

Measured memory_bytes: 10492
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
total = 0

for i in range(N):
    total += B[A[i]-1]
    if 0<i and A[i-1] == A[i]-1:
        total +=C[A[i-1]-1]
print(total)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5 +1)
#define INFL LLONG_MAX
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

ll binpow(ll a, ll b) {
	ll x = 1;
	while (b) {
		if (b & 1) x = x * a;
		a = a * a;
		b >>= 1;
	}
	return x;
}

ll mult(ll a, ll b) {
	ll x = 0;
	while (b) {
		if (b & 1) x = (x + a);
		a = (a + a);
		b >>= 1;
	}
	return x;
}



int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;

	// Write your code here

	int t = 1;
	//cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		vl v(nax, 0);
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			ll a;
			cin >> a;
			v[a]++;
			sum += a;
		}

		ll q;
		cin >> q;
		while (q--) {
			ll l, r;
			cin >> l >> r;
			sum -= v[l] * l;
			sum += v[l] * r;
			v[r] += v[l];
			v[l] = 0;
			cout << sum << "\n";
		}
	}


	return 0;
}

Measured memory_bytes: 3992
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];

void push(int x) {
/* top ?????????????????????????????????????????\ */
  S[++top] = x;
}

int pop() {
  top--;
/* top ??????????????????????´?????????? */
  return S[top+1];
}

int main() {
  int a, b;
  char s[100];
  top = 0;
  
  while( scanf("%s", s) != EOF ) {
    if ( s[0] == '+' ) {
      a = pop();
      b = pop();
      push(a + b);
    } else if ( s[0] == '-' ) {
      b = pop();
      a = pop();
      push(a - b);
    } else if ( s[0] == '*' ) {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }

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

  return 0;
}

Measured memory_bytes: 548
# ABC 087: B – Coins
a, b, c, x = [int(input()) for _ in range(4)]
number_of_ways = 0

for i in range(a + 1):
    for j in range(b + 1):
        if 0 <= (x - (500 * i + 100 * j)) // 50 <= c:
            number_of_ways += 1

print(number_of_ways)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e5+5;
ll p[MAX], w[MAX];
vector<ii> num;
vector<ll> v;
ll N, M, ans;

int find(int a) {
	if(p[a] == a) return a;
	return p[a] = find(p[a]);
}

int main(int argc, char ** argv) {
	rep(i, 0, MAX) p[i] = i;
	rep(i, 0, MAX) w[i] = 1;
	scanf("%lld%lld", &N, &M);
	int a, b;
	rep(i, 0, M) {
		scanf("%d%d", &a, &b);
		num.pb(mk(a, b));
	}
	N--;
	reverse(all(num));
	ans = ((1+N)*N)/2;
	rep(i, 0, M) {
		a = find(num[i].F);
		b = find(num[i].S);
		v.pb(ans);
		if(a != b) {
			p[a] = b;
			ans -= (w[a] * w[b]);
			w[b] += w[a];
		}
	}
	reverse(all(v));
	rep(i, 0, M) printf("%lld\n", v[i]);
	return 0;
}



Measured memory_bytes: 4596
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <queue>
#include <typeinfo>
using namespace std;
typedef long long ll;

int a, b, c;
int main()
{
  cin >> a >> b >> c;
  for (int i = 1; i <= b; i++) {
    if ((a * i) % b == c){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC061_A_Between_Two_Integers
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			int a = int.Parse(input[0]);
			int b = int.Parse(input[1]);
			int c = int.Parse(input[2]);
			
			if(a <= c && b >= c) Console.WriteLine("Yes");
			else Console.WriteLine("No");
		}
	}
}

Measured memory_bytes: 13140
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
 
		long i = 2;
		long M = (long) Math.sqrt(N) +1 ;
 
		long movement = N-1;
		for (i = 2; i < M; i++) {
			if (N % i == 0) {
				long j = N / i;
				if ((i + j - 2) < movement)
					movement = i + j - 2;
			}
		}
 
		System.out.println(movement);
		sc.close();
	}
}

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

using ll = long long;
using ld = long double;

const ll llinf = (ll)1e18;
const int intinf = 1e9;
const int MOD =  (int)(1e9 + 7);
const ld EPS =  1e-7;


void solve() {
	ll n;
	cin >> n;
	string ans = "";

	// n--;
	while (n > 0) {
		ll num = n % 26 - 1;

		if (num == -1) {
			num = 25;
			n--;
		}
		
		n /= 26;
		ans += (char)(((int)'a') + num);
	}

	reverse(ans.begin(), ans.end());

	cout << ans << endl;

}

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

	int t = 1;
	// cin >> t;
	while (t--){
		solve();
	}

	return 0;
}

Measured memory_bytes: 3616