akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
#define NIL -1

struct node{
    int p, l, r;
};

node t[MAX];
int n;

void preParse(int u) {
    if(u == NIL)return;
    cout << " " << u;
    preParse(t[u].l);
    preParse(t[u].r);
}

void inParse(int u) {
    if(u == NIL)return;
    inParse(t[u].l);
    cout << " " << u;
    inParse(t[u].r);
}

void postParse(int u) {
    if(u == NIL)return;
    postParse(t[u].l);
    postParse(t[u].r);
    cout << " " << u;
}

int main() {
    int id, l, r, root;
    cin >> n;
    for(int i = 0; i < n; i++) t[i].p = NIL;
    for(int i = 0; i < n; i++) {
        cin >> id >> l >> r;
        t[id].l = l;
        t[id].r = r;
        if(l != NIL) t[l].p = id;
        if(r != NIL) t[r].p = id;
    }
    for(int i = 0; i < n; i++) if(t[i].p == NIL) root = i;
    cout << "Preorder" << endl;
    preParse(root);
    cout << endl << "Inorder" << endl;
    inParse(root);
    cout << endl << "Postorder" << endl;
    postParse(root);
    cout << endl;
}


Measured memory_bytes: 3088
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n=int(input())
    fib=[1,1]
    for i in range(n-1):
        fib.append(fib[-1]+fib[-2])
    print(fib[-1])

main()



Measured memory_bytes: 5604
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

    int a;cin>>a;
    bool h=false;
    rep(i,10)rep(j,10)if(i*j==a)h=true;
    if(h)yes;else no;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	int n; cin >> n;
	ll ans = 0;
	for(int i=1; i<=n; i++){
		for(int j=i; j<=n; j+=i){
			ans += j;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3620
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 998244353LL
#define EPS 1e-8

LL solve(){
	int n;
	scanf("%d", &n);
	vector<int> ds(n);
	for(int i = 0; i < n; ++i){
		scanf("%d", &ds[i]);
	}
	if(ds[0] != 0){ return 0; }
	for(int i = 1; i < n; ++i){
		if(ds[i] == 0){ return 0; }
	}
	vector<int> cs(n);
	for(int d : ds){ ++cs[d]; }
	LL ans = 1;
	for(int i = 1; i < n; ++i){
		for(int j = cs[i]; j > 0; --j){
			ans = ans * cs[i - 1] % MOD;
		}
	}
	return ans;
}

void mainmain(){
	cout << solve() << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


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

int main() {
	int k, s, cnt = 0;
	cin >> k >> s;
	rep(x, k + 1) {
		rep(y, k + 1) {
			if (0 <= s - x - y && s - x - y <= k) cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a,s,d,i,w,t;
	while(1){
	  scanf("%d",&n);
	   if(n==0)	break;
		for(i=0;i<n;i++){
			scanf("%d %d %d",&a,&s,&d);
			t=(a+s)/2;
			w=(a+s+d)/3;
		if(a==100||s==100||d==100){
			printf("A\n");
		}
		else if(t>=90||w>=80){
			printf("A\n");
		}	
		else if(w>=70){
			printf("B\n");
		}
		else if(w>=50&&a>=80||s>=80){
			printf("B\n");
		}
		else{
			printf("C\n");
		}
	   }
	 }
   return 0;
}   

Measured memory_bytes: 1012
#include <stdio.h>

int main(){
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  int x = a + b - c - d;
  if(x > 0) {
    puts("Left");
  }else if(x==0) {
    puts("Balanced");
  }else{
    puts("Right");
  }
}

Measured memory_bytes: 128
inputs = raw_input().replace("\n", "").split(" ")
N, X = map(int, inputs)
inputs = raw_input().replace("\n", "").split(" ")
#xs = map(int, inputs)
xs = [abs(int(input_) - X) for input_ in inputs]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

if N >= 2:
    for i in xrange(1, N):
        if i >= 2:
            y = gcd(y, xs[i])
        else: 
            y = gcd(xs[0], xs[1])
else:
    y = xs[0]

print y

Measured memory_bytes: 11808
S=list(input())
if (S[0]==S[1] and S[2]==S[3] and S[0]!=S[2]) or (S[0]==S[2] and S[1]==S[3] and S[0]!=S[1]) or (S[0]==S[3] and S[2]==S[1] and S[0]!=S[1]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int N;
  int h;
  cin >> N;
  int x[N], y[N];
  int z[N];
  REP(i, N) {
    cin >> x[i] >> y[i] >> z[i];
  }
  int hw;
  int ax, ay, ah=0;
  REP(ix, 101){
    REP(iy, 101){
      h=0;
      REP(i, N){
        if(z[i]) {
          hw = abs(ix-x[i])+abs(iy-y[i])+z[i];
          if(h == 0) h = hw;
          else if(h != hw) goto hoge;
        }
      }
      REP(i, N){
        if(!z[i]) {
          hw = abs(ix-x[i])+abs(iy-y[i])+z[i];
          if(hw<h)goto hoge;
        }
      }
      if(h>ah){
        ax=ix;
        ay=iy;
        ah=h;
      }
      hoge:
      continue;
    }
  }
  cout << ax << " " << ay << " " << ah << endl;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N[5];
  int counter=1;
  cin >> N[0] >> N[1] >> N[2] >> N[3] >> N[4];
  for(int i=0; i<5; i++){
    if(N[i] == 0)cout << counter << endl;
    counter++;
  }
  return 0;
}


Measured memory_bytes: 3620
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		
		//n??¨m???????????\?????????int????????°???????´???????
		String s = scan.nextLine();
		String[] ary = s.split(" ");
		int n = Integer.parseInt(ary[0]);
		int m = Integer.parseInt(ary[1]);
		
		//n???????????±???????´???????
		ArrayList<String> array = new ArrayList<String>();
		for(int i = 0; i < n; i++) {
			array.add(scan.nextLine());
		}
		
		ArrayList<Integer> data = new ArrayList<Integer>();
		for(int i = 0; i < m; i++) {
			data.add(scan.nextInt());
		}
		
		//int??????????????????2?¬?????????????????´???????
		int [][] intArray = new int[n][m];
		for(int i = 0; i < n; i++) {
			String str = array.get(i);
			String [] strAry = str.split(" ");
			for(int j = 0; j < strAry.length; j++) {
				intArray[i][j] = Integer.parseInt(strAry[j]);
			}
		}
		
		int[] sum = new int[n];
		for(int i = 0; i < intArray.length; i++) {
			for(int j = 0; j < intArray[i].length; j++) {
				sum[i] = sum[i] + (intArray[i][j] * data.get(j));
			}
		}
				
		for(int i = 0; i < n; i++) {
			System.out.println(sum[i]);
		}
	}

}

Measured memory_bytes: 29888
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

long gcd(long a, long b){
    if(b > a){
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
    }
    while(b != 0){
        long t = b;
        b = a%b;
        a = t;
    }
    return a;
}

int main(){
    long a, b, c, d;
    cin >> a >> b >> c >> d;
    long abc = b/c - (a-1)/c, abd = b/d - (a-1)/d;
    long g = c/(double)gcd(c, d)*d, abg = b/g - (a-1)/g;
    cout << b - a + 1 - abc - abd + abg << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	ll h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) cout << 1 << endl;
	else {
		ll a = (w + 1) / 2;
		ll b = w / 2;
		ll c = (h + 1) / 2;
		ll d = h / 2;
		cout << a * c + b * d << endl;
	}
}

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

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

	int n;
	cin >> n;
	int p[n];
	for(int i=0; i<n; i++) cin >> p[i];
	sort(p, p+n);
	int res=0;
	for(int i=0; i<n-1; i++){
		res += p[i];
	}
	res += p[n-1]/2;
	cout << res;
	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //ifstream cin("input.in");
    //ofstream cout("output.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long n,m,k,a[10009],d[109][109];
    cin>>n>>m>>k;
    for(long i=1;i<=k;i++)
        cin>>a[i];
    long c=1;
    for(long i=0;i<n;i++){
        if(i%2==0)
            for(long j=0;j<m;j++)
            {
                if(a[c]==0)
                    c++;
                d[i][j]=c;
                a[c]--;
            }
        else
            for(long j=m-1;j>=0;--j)
            {
                if(a[c]==0)
                    c++;
                d[i][j]=c;
                a[c]--;
            }
    }  
    for(long i=0;i<n;i++){
        for(long j=0;j<m;j++)
            cout<<d[i][j]<<" ";
        cout<<"\n";
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

int main() {
  int N;
  cin >> N;
  int h, mx = 0, ret = 0;
  for (int i = 0; i < N; i++) {
    cin >> h;
    if (mx <= h) ret++;
    mx = max(h, mx);
  }
  cout << ret << endl;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,X;

ll hoge(ll a,ll b) {
	return (a-1)*3;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>X;
	ll g=__gcd(N,X);
	cout<<hoge(N/g,X/g)*g<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

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

  ll ans = 0, last = 0;
  rep(i,0,S.size()-1) {
    ll cnt = 0;
    if (S[i] == '<') {
      while(S[i] == S[i+cnt]) {
        cnt++;
        ans += cnt;
      }
      i += cnt - 1;
      last = cnt;
    } else {
      while(S[i] == S[i+cnt]) {
        cnt++;
        ans += cnt;
      }
      ans -= min(cnt, last);
      i += cnt - 1;
      last = cnt;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 900
#include<iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
int p,ans=0;
	int main(){
		while(cin>>p){
			for(int a=0;a<10;a++){
						for(int b=0;b<10;b++){
						for(int c=0;c<10;c++){
						for(int d=0;d<10;d++){
							if(a+b+c+d==p){ans++;}}}}}
		cout<<ans<<endl;
		ans=0;}
		return 0;}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
vector<long long> fact, invfact;
long long modpow(long long n, int k) {
	long long r = 1;
	while (k > 0) {
		if (k % 2) (r *= n) %= mod;
		n = n*n % mod;
		k /= 2;
	}
	return r;
}
long long comb(int n, int k) {
	return fact[n] * invfact[k] % mod * invfact[n-k] % mod;
}
int main() {
	long long N, A, B, K;
	cin >> N >> A >> B >> K;
	fact = vector<long long>(N+1);
	invfact = vector<long long>(N+1);
	fact[0] = 1;
	for (int i = 1; i <= N; ++ i) fact[i] = fact[i-1] * i % mod;
	for (int i = 0; i <= N; ++ i) invfact[i] = modpow(fact[i], mod-2);
	long long res = 0;
	for (int n = 0; n <= N; ++ n) {
		auto mm = K - A*n;
		if (mm % B != 0) continue;
		auto m = mm / B;
		if (!(0 <= m && m <= N)) continue;
		//cerr << n << " " << m << endl;
		(res += comb(N, n) * comb(N, m)) %= mod;
	}
	cout << res << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i - - )
#define eps 1e - 9
#define all(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == ' - ') f =  - 1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int n, m, s[26], q[26];
char c[100];
int main()
{
    scanf("%d", &n);
    rep(i, 0, 25) s[i] = 51;
    while (n --)
    {
        scanf("%s", c);
        rep(i, 0, 25) q[i] = 0;
        for (int i = 0; c[i]; i ++) q[c[i] - 'a'] ++;
        rep(i, 0, 25) s[i] = min(s[i], q[i]);
    }
    rep(i, 0, 25) while (s[i] --) putchar('a' + i);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<iomanip>

using namespace std;

int main() {
	int a;
	cin >> a;
	int x[50];

	for (int i = 0; i < a; i++) {
		int tmp;
		cin >> tmp;
		x[i] = tmp;
	}

	for (int i = 0; i < a; i++) {
		for (int j = i; j < a; j++) {
			int tmp;
			if (x[i] > x[j]) {
				tmp = x[i];
				x[i] = x[j];
				x[j] = tmp;
			}
		}
	}

	double ans = x[0];

	for (int i = 1; i < a ; i++) {
		ans = (ans + static_cast<double>(x[i])) / 2.0;
	}
	
	cout << setprecision(15) << ans;

	return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        int[] a = new int[N];
        for(int i = 0;i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        for (int k = 0; k < a.Length; k++)
        {
            if (k == a.Length - 1)
                Console.WriteLine("{0}", a[k]);
            else
                Console.Write("{0} ", a[k]);
        }

        for (int i = 1;i < a.Length; i++)
        {
            int v = a[i];
            int j = i - 1;
            while(j >= 0 && a[j] > v)
            {
                a[j + 1] = a[j];
                j--;
            }
            a[j + 1] = v;
            for(int k = 0;k < a.Length; k++)
            {
                if (k == a.Length - 1)
                    Console.WriteLine("{0}", a[k]);
                else
                    Console.Write("{0} ", a[k]);
            }
        }
        
    }
}

Measured memory_bytes: 9288
#include<cstdio>
#include<algorithm>
using namespace std;

const int MAX=101;
const int INF=(1<<21);

int main(){
  int n,m;
  int s,g1,g2;
  int pipe[MAX][MAX];

  while(1){
    scanf("%d%d%d%d%d", &n, &m, &s, &g1, &g2);

  if(n==0 && m==0 && s==0 && g1==0 && g2==0) break;

  for( int i=0;i<=n;i++ ) {
    for( int j=0;j<=n;j++ ) {
      pipe[i][j]=INF;
    }
    pipe[i][i]=0;
  }

  for( int i=0;i<m;i++ ) {
    int b1,b2,c; 
    scanf("%d%d%d", &b1, &b2, &c);
    pipe[b1][b2]=c;
  }

  for( int i=1;i<=n;i++ ) {
    for( int j=1;j<=n;j++ ) {
      for( int k=1;k<=n;k++ ) {
	pipe[j][k]=min(pipe[j][k],pipe[j][i]+pipe[i][k]);
      }
    }
  }
  int ans=INF;
  for( int i=1;i<=n;i++ ){
    ans=min(ans,pipe[s][i]+pipe[i][g1]+pipe[i][g2]);
  }
  printf("%d\n",ans);
  }
}

Measured memory_bytes: 1064
#include<stdio.h>
int main(){
int n[1006]={0},m[1006]={0},k=0,i,N,M;
for(;;k=0){
scanf("%d%d",&N,&M);
if(M==0)break;
for(i=0;i<N;i++)scanf("%d",&n[i]);
for(i=0;i<M;i++)scanf("%d",&m[i]);
for(i=0;;i++){
k+=m[i];
k+=n[k];
if(k>=N-1)break;
}	
printf("%d\n",i+1);
}
return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define mk make_pair
#define endl '\n'

const ll M=998244353;

ll f[200001];
 
ll pow(ll val, ll exp, ll MOD)
{
    ll x=1,y=val; 
    while(exp > 0)
        {
            if(exp%2 == 1)
        {
            x=(x*y);
            if(x>MOD) x%=MOD;
        }
        y = (y*y);
        if(y>MOD) y%=MOD; 
        exp /= 2;
        }
    return x;
}
ll InverseEuler(ll n, ll MOD)
{
    return pow(n,MOD-2,MOD);
}
 
ll C(ll n, ll r, ll MOD)
{
    return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}

void compute(int mod)
{
    f[0] = 1;
	for(int i = 1 ; i <= 200000 ; i++)
		f[i] = (f[i-1]*i)%mod;
}

int main()
{
    IOS;
    compute(M);
    int n,m,k;
    cin>>n>>m>>k;
    int ans=0;
    for (int i = 0; i <=k; i++)
    {
        ll temp=pow(m-1,n-1-i,M)*m;
        temp%=M;
        temp*=C(n-1,i,M);
        temp%=M;
        ans+=temp;
        ans%=M;
    }
    cout<<ans;
}

Measured memory_bytes: 5232
//BISMILLAH
#include<bits/stdc++.h>
#define ll long long

using namespace std;



int main()
{
    ll x,countt=0,temp=0,flag,num;
    cin>>x;
    num=100;
    while(num<x)
    {
        num+=num/100;
        countt++;
    }
    cout<<countt<<endl;
}


Measured memory_bytes: 3620
#include <stdio.h>
int GCD(int,int);
int main(){
  int x, y;
  int gcd, c;
  scanf("%d%d",&x,&y);
  if(x>=y){
    c=x%y;
    gcd=GCD(y,c);
  }
  else 
    gcd=GCD(x,y);
  printf("%d\n",gcd);
  return 0;
}
int GCD(int p,int q){
  int s,tmp;
  if(p<q){
    tmp=p;
    p=q;
    q=tmp;
  }
  if(q==0)return p;
  s=p%q;
  while(s!=0){
    p=q;
    q=s;
    s=p%q;
  }
  return q;
}



Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll count(ll n) {
    ll ans = 0;
    while(n > 0 && n % 2 == 0) {
        ans++;
        n /= 2;
    }
    return ans;
}


int main() {
    ll N, M;
    cin >> N >> M;
    ll lcm = 1, cnt;
    bool ok = true;
    rep(i, N) {
        ll a;
        cin >> a;

        if(i == 0) cnt = count(a);
        else if(cnt != count(a)) ok = false;

        a /= 2;
        lcm = lcm * a / __gcd(lcm, a);

        if(lcm > M) ok = false;
    }

    if(!ok) cout << 0 << endl;
    else cout << (M / lcm + 1) / 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Mx 1000000000005 
#define ll long long  
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll,ll>
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define vii vector<pair<ll,ll> > 
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a,x) memset(a,x,sizeof(a))
using namespace std;
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
  return a.second<b.second;
}
/*vi b=v;
   sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  ll t; cin>>t; fr(f,0,t){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 */

int main()
{
  ll n,W; cin>>n>>W;
  ll wt[n],v[n],ans,maxVal= 1e5;
  fr(i,0,n)
    cin>>wt[i]>>v[i];

  vector<vector<ll>> dp(n+1, vector<ll>(maxVal + 1, 0));

  fr(i,1,n+1)
    dp[i][0]=0;
  fr(j,1,maxVal + 1)
    dp[0][j]=Mx;

  dp[0][0]=0;

  fr(i,1,n+1)
  {
    fr(j,1,maxVal+1)
    {
      dp[i][j]=dp[i-1][j];
      if(j>=v[i-1])
        dp[i][j]=min(dp[i][j], wt[i-1]+dp[i-1][j-v[i-1]]);
    }
  }

  for(ll i=maxVal;i>=0;i--)
    if(dp[n][i]<=W)
    {
      ans=i;
      break;
    }

  cout<<ans;

}

Measured memory_bytes: 83264
#include <iostream>
#include <cstdio>
#include <stack>
#include <queue>

#define MAX 2048

using namespace std;

int main(void) {
	int n, num = 0, count = 0;
	char nums[MAX];
	scanf("%d", &n);
	while(n--) {
		scanf("%s", nums);
		for(int i = 0; nums[i] != '\0'; i++) {
			if(nums[i] == '0') {
				if(num >= 2 && num <= 6) {
					printf("%c", (num - 2) * 3 + ((count + 2) % 3) + 'a');
				} else if(num == 7) {
					printf("%c", (count + 3) % 4 + 'p');
				} else if(num == 8) {
					printf("%c", (count + 2) % 3 + 't');
				} else if(num == 9) {
					printf("%c", (count + 3) % 4 + 'w');
				} else if(num == 1) {
					switch((count + 4) % 5) {
					case 0: printf("."); break;
					case 1: printf(","); break;
					case 2: printf("!"); break;
					case 3: printf("?"); break;
					case 4: printf(" "); break;
					}
				} else {
					printf("");
				}
				num = 0;
				count = 0;
			}
			else if(nums[i] == num + '0') {
				count++;
			} else {
				num = nums[i] - '0';
				count = 1;
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1164
import math
def cal_cos(n): 
  
    degree = math.radians(n)
    cosx = math.cos(degree)
  
    return cosx 
  
# Function to find third side 
def third_side(a, b, c): 
    angle = cal_cos(c) 
    return math.sqrt((a * a) + 
                   (b * b) - 2 * a * b * angle) 
                   

def calcAngle(h,m): 
          
        # validate the input 
        if (h < 0 or m < 0 or h > 12 or m > 60): 
            print('Wrong input') 
          
        if (h == 12): 
            h = 0
        if (m == 60): 
            m = 0
          
        # Calculate the angles moved by  
        # hour and minute hands with  
        # reference to 12:00 
        hour_angle = 0.5 * (h * 60 + m) 
        minute_angle = 6 * m 
          
        # Find the difference between two angles 
        angle = abs(hour_angle - minute_angle) 
          
        # Return the smaller angle of two  
        # possible angles 
        angle = min(360 - angle, angle) 
          
        return angle 
    
l = list(map(int,input().split()))

angle = calcAngle(l[2],l[3])
distance = third_side(l[0],l[1],angle)

print ('%.10f'%distance)
  

Measured memory_bytes: 9488
function main()
	s=chomp(readline())
	L=1
	R=length(s)
	Lc=Rc=0
	ans=0
	while L<R
		while L<R&&s[L]=='x'
			Lc+=1
			L+=1
		end
		while L<R&&s[R]=='x'
			Rc+=1
			R-=1
		end
		if s[L]!=s[R]
			println(-1)
			exit()
		end
		if s[L]!='x'
			ans+=abs(Lc-Rc)
		end
		Lc=Rc=0
		L+=1
		R-=1
	end
	println(ans)
end
main()


Measured memory_bytes: 114064
function Main(input) {
    input = input.trim();
    var a = parseInt(input[input.length-1])
    if(a == 2 || a == 4 || a == 5|| a == 7 || a == 9) console.log('hon');
    if(a == 0 || a == 1 || a == 6|| a == 8 ) console.log('pon');
    if(a == 3 ) console.log('bon');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 


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

int main(){
  ll k,i,n,ans;
  cin >> k;
  n=0;
  ans=0;
  for(i=0;i<1500000;i++){
    n=n*10+7;
    n=n%k;
    if(n==0){
      cout << i+1;
      ans=1;
      break;
    }
  }
  if(ans==0){
    cout << -1;
  }
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define None cout<<"None"<<endl
typedef long long ll;
using namespace std;

int main() {
	int N,X; cin >> N >> X;
	int m[1000];
	int sum = X;
	for (int i = 0; i < N; ++i) {
		cin >> m[i];
		sum -= m[i];
	}
	sort(m, m + N);
	int cnt = N;
	cnt += sum / m[0];
	cout << cnt << endl;
}	


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int s;
	cin >> s;
	int array[10000];
	int min, max;
	long sum;
	cin >> array[0];
	sum = max = min = array[0];
	for(int i = 1;i < s;i++)
	{
		cin >> array[i];
		min = min < array[i] ? min : array[i];
		max = max > array[i] ? max : array[i];
		sum += array[i];
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    cout<<(1000-n%1000)%1000<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    int hand[6]={0};
    while(cin>>hand[0],hand[0]){
            int flg[5]={0};
        for(int i=1;i<5;i++)cin>>hand[i];
        for(int i=0;i<5;i++){
            if(hand[i]==1)flg[1]=1;
            if(hand[i]==2)flg[2]=1;
            if(hand[i]==3)flg[3]=1;
        }
        if(flg[1]==1&&flg[2]==1&&flg[3]==1)for(int i=0;i<5;i++)cout<<"3"<<endl;
        else if(flg[1]==1&&flg[2]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==1)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[2]==1&&flg[3]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==2)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[1]==1&&flg[3]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==3)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[1]==1)for(int i=0;i<5;i++)cout<<"3"<<endl;
        else if(flg[2]==1)for(int i=0;i<5;i++)cout<<"3"<<endl;
        else if(flg[3]==1)for(int i=0;i<5;i++)cout<<"3"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;


void solve(std::string S_A, std::string S_B, std::string S_C){
  vec(p,3);
  p[1]=-1;
  p[2]=-1;
  ll now=0; 
  while(1){
   if(now==0){
     if(p[0]==S_A.size()){op('A')return;}
     now = S_A[p[0]]-'a';
    p[now]++;
   }
    
   else if(now==1){
     if(p[1]==S_B.size()){op('B')return;}
     now = S_B[p[1]]-'a';
    p[now]++;
   }

   else if(now==2){
     if(p[2]==S_C.size()){op('C')return;}
     now = S_C[p[2]]-'a';
    p[now]++;
   }
    
  }
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S_A;
    std::cin >> S_A;
    std::string S_B;
    std::cin >> S_B;
    std::string S_C;
    std::cin >> S_C;
    solve(S_A, S_B, S_C);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int gcd(int y, int x){
	if(x==0)return y;
	return gcd(x,y%x);
}

int main(){
	int tmp,x,y;
	scanf("%d%d",&x,&y);
	if(x>y){
		tmp=y;
		y=x;
		x=tmp;
	}

	printf("%d\n",gcd(y,x));

	return 0;
}



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

        dist = []

        for i in range(N-1):
                dist.append(A[i+1]-A[i])
        dist.append(K-A[N-1]+A[0])

        ans = sum(dist) - max(dist)

        print("{}".format(ans))

if __name__=="__main__":
        main()

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

using UnWeightedGraph = vector<vector<int>>;
int is_bipartite(UnWeightedGraph &g) {
    int n = g.size();
    vector<int> color(n, -1);
    int cntW = 0;
    function<bool(int, int)> dfs = [&](int u, int c) {
        if ((color[u] = c) > 0) cntW++;
        for (int &v: g[u]) {
            if (color[v] == c) return false;
            if (color[v] < 0 && !dfs(v, 1 - c)) return false;
        }
        return true;
    };
    if (!dfs(0, 0)) return -1;
    return cntW;
}

int main() {
    int V, E; cin >> V >> E;
    UnWeightedGraph g(V);
    for (int i = 0; i < E; i++) {
        int a, b; cin >> a >> b; a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    int cntW = is_bipartite(g);
    if (cntW < 0) {
        cout << (1LL * V * (V - 1) / 2 - E) << endl;
    } else {
        int cntB = V - cntW;
        cout << (1LL * cntB * cntW - E) << endl;
    }
    return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N,T;
  cin>>N>>T;
  vector<int>C(N);
  vector<int>t(N);
  for (int i=0;i<N;++i){
    cin>>C[i]>>t[i];
  }
  int res=1<<30;
  for (int i=0;i<N;++i){
    if (t[i]<=T){
      if (res>C[i]){
        res=C[i];
      }
    }
  }
  if (res==1<<30) cout<<"TLE"<<endl;
  else cout<<res<<endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

LLi mod=1000000007;

void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}
 
LLi modinv(LLi a) {
    LLi b = mod, u = 1, v = 0;
    while (b) {
        LLi t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}
 
LLi modpow(LLi a, LLi n) {
    LLi res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//xCyを計算
LLi conb(LLi x, LLi y){
	if(x<y) cout<< "conb x<y" << x SP << y <<endl;
	LLi tmp=1;
	//y=min(y, x-y); 8C2==8C6なので
	
	for(int i=1;i<=y;i++){
		tmp*=x+1-i;
		tmp=tmp%mod;
		tmp*=modinv(i);
		tmp=tmp%mod;
	}

	return tmp;
}

//xPyを計算
LLi perm(LLi x, LLi y){
	if(x<y) cout<< "conb x<y" << x SP << y <<endl;
	LLi tmp=1;
	
	for(int i=1;i<=y;i++){
		tmp*=x+1-i;
		tmp=tmp%mod;
	}

	return tmp;
}

int main(){

	long long int n, a, b;
	LLi tmp, ans=0;
	cin>> n >> a >> b;

	ans+=modpow(2, n)-1;
	ans=ans%mod;
	ans+=mod-conb(n, a);
	ans=ans%mod;
	ans+=mod-conb(n, b);
	ans=ans%mod;
  
  cout<< ans <<endl;

	return 0;
}

Measured memory_bytes: 256
import Data.Bits
import Data.Foldable (foldlM,foldrM)
import Data.Maybe (fromJust)
import Data.List
import qualified Data.Vector.Unboxed.Mutable as V
import Control.Monad
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

solve :: String -> Int
solve s = sub s 0
  where
    sub [] n = 0
    sub [x] n = 0
    sub (b:c:s) n = if b == 'B' && c == 'C' then n+(sub s n)
      else if b == 'A' then sub (c:s) (n+1)
        else sub (c:s) 0

main :: IO ()
main = do
  s <- getLine
  print $ solve s


Measured memory_bytes: 9596
fun main(args : Array<String>) { 
  val b = (0 until readLine()!!.toInt()).map { readLine() }
  val r = (0 until readLine()!!.toInt()).map { readLine() }
  b.map { s -> (b.count { s == it } - r.count { s == it }) }.plus(0).let { print(it.max()) }
}

Measured memory_bytes: 33528
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    long long ans = 0;
    for (int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        if (u > v) swap(u, v);
        ans -= (long long)u * (n - v + 1);
    }
    for (int i = 1; i <= n; i++) ans += (long long)i * (n - i + 1);
    cout << ans << endl;
}


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

typedef long long ll;
struct P{
	ll x, y;
	P(ll x_, ll y_){ x = x_; y = y_; }
	P(){}
};
bool operator==(const P& a, const P& b){
	return (a.x == b.x && a.y == b.y);
}

bool is_8dir(P p1, P p2){
	return ( p1.x == p2.x || p1.y == p2.y || p1.x + p1.y == p2.x + p2.y || p1.x - p1.y == p2.x - p2.y);
}

P f(ll a, ll b){
	return P((a+b)/2, (a-b)/2);
}

ll llabs(ll x){
	return (x < 0)? -x : x;
}

bool is_check(P p1_, P p2_, P g){
	ll x1 = p1_.x, y1 = p1_.y, x2 = p2_.x, y2 = p2_.y;
	vector<P> vp;
	vp.push_back( P(x1, y2) );
	vp.push_back( P(x2, y1) );
	ll x_ = abs(x1 - x2);
	vp.push_back( P(x1, y2 + x_) );
	vp.push_back( P(x1, y2 - x_) );
	vp.push_back( P(x2, y1 + x_) );
	vp.push_back( P(x2, y1 - x_) );

	ll y_ = abs(y1 - y2);
	vp.push_back( P(x1 + y_, y2));
	vp.push_back( P(x1 - y_, y2));
	vp.push_back( P(x2 + y_, y1));
	vp.push_back( P(x2 - y_, y1));
	
	ll a = x1 + y1;
	ll b = x2 - y2;
	
	if( llabs(a+b) % 2 == 0 && llabs(a-b) % 2 == 0 ){
		vp.push_back( f(a, b) );
	}
	a = x2 + y2;
	b = x1 - y1;
	if( llabs(a+b) % 2 == 0 && llabs(a-b) % 2 == 0 ){
		vp.push_back( f(a, b) );
	}	
	for(int i=0 ; i < vp.size() ; i++ ){
		if( is_8dir( vp[i] , g ) ){
			return true;
		}
	}
	return false;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0 ; i < n ; i++ ){
		ll x1, y1, x2, y2, gx, gy, ans=4;
		cin >> x1 >> y1 >> x2 >> y2 >> gx >> gy;
		P p1(x1,y1), p2(x2,y2), g(gx,gy);
		
		if( p1 == g || p2 == g ){
			ans = 0;
		}else if( is_8dir(p1,g) && is_8dir(p2,g) ){
			ans = 1;
		}else if( is_8dir(p1,g) || is_8dir(p2,g) ){
			ans = 2;
		}else if( is_8dir(p1,p2) || is_check(p1,p2,g) ){
			ans = 3;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1204
# -*- coding: utf-8 -*-
K,N = map(int,input().split())
A   = list(map(int,input().split()))
Dist=[None]*len(A)
for i in range(len(A)-1):
    Dist[i] = A[i+1]-A[i]
Dist[i+1]=K-A[len(A)-1]+A[0]
MD=K-max(Dist)
print(MD)


Measured memory_bytes: 26420
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

vector<ll> divtable;

void Sieve(ll maxnum){
  if(maxnum+1 > ll(divtable.size())){
    divtable.resize(maxnum+1,0);
  }

  rep(i, maxnum+1) {
    divtable[i] = i;
  }

  for (ll i = 2; i * i <= maxnum; i++) {
    if (divtable[i] == i) {
      for (ll j = 2; i * j <= maxnum; j++) {
        divtable[i*j] = i;
      }
    }
  }
}

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

  ll allgcd = a[0];
  reps1(i, n) allgcd = __gcd(allgcd, a[i]);
  if (allgcd != 1) {
    cout << "not coprime" << endl;
    return 0;
  }

  Sieve(1e6);
  map<ll, bool> isused;

  rep(i, n) {
    set<ll> divset;
    divset.insert(divtable[a[i]]);
    while(a[i] != divtable[a[i]]) {
      a[i] /= divtable[a[i]];
      divset.insert(divtable[a[i]]);
    }
    for(auto i = divset.begin(); i != divset.end(); i++){
      if (isused[*i] && *i != 1) {
        cout << "setwise coprime" << endl;
        return 0;
      }
      isused[*i] = true;
    }
  }

  cout << "pairwise coprime" << endl;

  return 0;
}


Measured memory_bytes: 18744
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
#define rep(N) for(int i=0;i<N;i++)
#define rep2(N1,N2) for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)for(int k=0;k<N3;k++)
#define For(i,N) for(int i=0;i<N;i++)
void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int main() {
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	int a = C / B;
	int b = A / D;
	if (C%B != 0)
		a++;
	if (A%D != 0)
		b++;
	int flag = 0;
	if (a <= b)
		flag = 1;
	Yn(flag);
}

Measured memory_bytes: 3632
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, C) = Slice2<long>();
            var dsts = new long[N];
            var cals = new long[N];
            for (var i = 0; i < N; ++i)
                (dsts[i], cals[i]) = Slice2<long>();

            var ruiDstCW = new long[N + 1];
            var ruiCalCW = new long[N + 1];
            var maxCW = new long[N + 1];
            for (var i = 1; i <= N; ++i)
            {
                ruiDstCW[i] = dsts[i - 1];
                ruiCalCW[i] = ruiCalCW[i - 1] + cals[i - 1];
                maxCW[i] = Max(maxCW[i - 1], ruiCalCW[i] - ruiDstCW[i]);
            }
            var ruiDstCCW = new long[N + 1];
            var ruiCalCCW = new long[N + 1];
            var maxCCW = new long[N + 1];
            for (var i = 1; i <= N; ++i)
            {
                var n = N - 1 - i + 1;
                ruiDstCCW[i] = C - dsts[n];
                ruiCalCCW[i] = ruiCalCCW[i - 1] + cals[n];
                maxCCW[i] = Max(maxCCW[i - 1], ruiCalCCW[i] - ruiDstCCW[i]);
            }
            var maxCal = 0L;
            for (var i = 0; i <= N; ++i)//[0,i)で回る方向を変える
            {
                maxCal = Max(maxCal, maxCW[i] - ruiDstCW[i] + maxCCW[N - i]);
                maxCal = Max(maxCal, maxCCW[i] - ruiDstCCW[i] + maxCW[N - i]);
            }
            WriteLine(maxCal);
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 52116
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
int x[50][50],xy[50][50],a,b,c,n;
int mutu(int y,int z){
	int ans;
	if(a&&b) ans=xy[y][z]-xy[a-1][z]-xy[y][b-1]+xy[a-1][b-1];
	else if(b) ans=x[y][z]-xy[y][b-1];
	else if(a) ans=x[y][z]-x[a-1][z];
	else ans=x[y][z];
	if(y==a&&z<n-1&&z-b+2<=c)ans=max(ans,mutu(y,z+1));
	if(y<n-1&&(y-a+2)*(z-b+1)<=c)ans=max(mutu(y+1,z)+x[y][z],ans);
	return ans;
}
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a*b/2<<endl;
	return 0;
}


Measured memory_bytes: 256
s = input()
len_s = len(s)
n = 2**(len_s-1)
total = 0
for i in range(n):
    buf = s[0]
    for j in range(len_s-1):
        if i & (2**j):
            total += int(buf)
            buf = s[j+1]
        else:
            buf += s[j+1]
    total += int(buf)
print(total)

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

int main() {
    string S, T, t;
    cin >> S >> T;
    t = T.erase(T.size() - 1);
    if( S == t ) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3124
while True:
    n = int(input())
    if n == 0:
        break
    data = {}
    for i in range(n):
        a,b = input().strip().split()
        data[a] = b
    ans_data = ''

    for i in range(int(input())):
        c = input().strip()
        ans_data += data[c] if c in data else c
    print(ans_data)


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

int N;
vector<int> p;
vector<vector<int>> c;
vector<int> a, a_inv;
vector<int> a_sub;
vector<int> is_confirm, is_leaf, is_progeny, progeny_count, candidate_v;

int do_confirm(){
	for(int i = N - 1; i >= 0; i--){
		int count = 0;
		for(int j = 0; j < c[i].size(); j++){
			count += is_confirm[c[i][j]];
		}
		if(count == c[i].size()){
			is_leaf[i] = 1;
			if(a[i] == i){
				is_confirm[i] = 1;
			}
		}
	}
	return is_confirm[0];
}

void dfs(int a_v){
	if(is_confirm[a_v] == 0){
		is_progeny[a_inv[a_v]] = 1;
		if(is_leaf[a_v] == 0){
			for(int i = 0; i < c[a_v].size(); i++){
				dfs(c[a_v][i]);
			}
		}
	}
}

int decide(){
	if(is_leaf[a[0]] == 1){
		return a[0];
	}
	for(int i = 0; i < N; i++){
		is_progeny[i] = 0;
		progeny_count[i] = 0;
	}
	dfs(a[0]);
	for(int i = N - 1; i > 0; i--){
		progeny_count[i] += is_progeny[i];
		progeny_count[p[i]] += progeny_count[i];
	}
/*	printf("is_progeny:");
	for(int i = 0; i < N; i++){
		printf("%d ", is_progeny[i]);
	}
	printf("\n");
	printf("progeny_count:");
	for(int i = 0; i < N; i++){
		printf("%d ", progeny_count[i]);
	}
	printf("\n");
*/	candidate_v.assign(0, -1);
	for(int i = 1; i < N; i++){
		if(is_progeny[i] == 1 && progeny_count[i] == 1){
			candidate_v.push_back(i);
		}
	}
//	return candidate_v[0];
	return candidate_v[rand() % candidate_v.size()];
}

void insersion(int v){
	int V = v;
	for(; v >= 0; v = p[v]){
		a_sub[v] = a[v];
	}
	for(v = V; v > 0; v = p[v]){
		a[p[v]] = a_sub[v];
	}
	a[V] = a_sub[0];
	for(v = V; v >= 0; v = p[v]){
		a_inv[a[v]] = v;
	}
}

int main(){
//	srand((unsigned)time(NULL));
	int i;
	scanf("%d", &N);
	p.assign(N, -1);
	c.assign(N, vector<int>(0));
	for(i = 1; i < N; i++){
		scanf("%d", &p[i]);
//		p[i] = rand() % i;
//		printf("p[%d] = %d\n", i, p[i]);
		c[p[i]].push_back(i);
	}
	a.assign(N, 0);
	a_inv.assign(N, 0);
	a_sub.assign(N, 0);
/*	for(i = 0; i < N; i++){
		a[i] = i;
		swap(a[i], a[rand() % (i + 1)]);
	}
*/	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
		a_inv[a[i]] = i;
	}
	is_confirm.assign(N, 0);
	is_leaf.assign(N, 0);
	is_progeny.assign(N, 0);
	progeny_count.assign(N, 0);
	vector<int> ans(0);
	while(do_confirm() == 0){
/*		printf("a:");
		for(i = 0; i < N; i++){
			printf("%d ", a[i]);
		}
		printf("\n");
		printf("a_inv:");
		for(i = 0; i < N; i++){
			printf("%d ", a_inv[i]);
		}
		printf("\n");
		printf("is_confirm:");
		for(i = 0; i < N; i++){
			printf("%d ", is_confirm[i]);
		}
		printf("\n");
		printf("is_leaf:");
		for(i = 0; i < N; i++){
			printf("%d ", is_leaf[i]);
		}
		printf("\n");
*/		int v = decide();
//		printf("v = %d\n", v);
		ans.push_back(v);
		insersion(v);
//		printf("\n");
	}
	printf("%d\n", ans.size());
	for(i = 0; i < ans.size(); i++){
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 512