akhauriyash/Code-Regression huggingface dataset:
N = int(input())
lis = [0]*40
tmp = [2]+[2**(i*2) for i in range(1,23)]
rui = [0]
for t in tmp:
    rui.append(rui[-1]+t)
for i in range(40):
    if i==0:
        if N%2 == 1:
            lis[0]=1
    else:
        if (N-rui[(i+1)//2])%((2**i) *2) < 2**i:
            lis[i]=1


print(int("".join(map(str,reversed(lis)))))


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

#define ll long long
int n, x, ans=0;
multiset<int> s;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> x;
		s.insert(x);
	}	

	for(int i=0;i<n && s.size();i++) {
		int e = *(--s.end());
		s.erase(--s.end());
		for(int j=0;j<32;j++) {
			if(s.find((1<<j) - e) != s.end()) {
				ans++;
				s.erase(s.find((1<<j) - e));
				break;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 9600
#include <stdio.h>
int main(void){
  int n, d, x[10][10] = {0}, count = 0;
  scanf("%d %d", &n, &d);getchar();
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      scanf("%d", &x[i][j]);getchar();
    }
  }
  
  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){
      int sum = 0;
      for(int k = 0; k < d; k++){
        sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      //printf("%d\n", sum);
      for(int i = 1; i < 1000; i++){
        if(sum == i * i){
          count++;
          break;
        }
      }
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

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

	int n;
	cin >> n;
	bool ok=false;
	for(int i=1; i<=9; i++){
		for(int j=i; j<=9; j++){
			if(i*j == n) ok=true;
		}
	}
	if(ok) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3488
//2020年4月17日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

namespace {
    // printElems(&a[0], &a[n]);　みたいな感じで使う。
    void printElems(const int* begin, const int* end)
    {
        for (const int* p = begin; p != end; ++p) {
            std::cout << *p << ' ';
        }
        std::cout << std::endl;
    }
}

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)
#define souatari(i,j,n) rep1(i,n-1)rep(j,i)
#define souatari1(i,j,n) for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<int,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
const ll BIG = 10000000000000000;

int klist[15];
int slist[15][15];
int plist[15];

int main(){
	int n,m;
	cin >> n >> m;
	rep(i,m){
		cin >> klist[i];
		rep(j,klist[i]) {cin >> slist[i][j];slist[i][j]--;}
	}
	rep(i,m) cin >> plist[i];


	int cnt = 0;
	rep(itr,1<<n){
		bool flag = true;
		rep(i,m){
			int tmp = 0;
			rep(k,klist[i]){
				if((itr&1<<slist[i][k])) {tmp++;}
			}
			if(tmp%2 != plist[i]) flag = false;
		}
		if(flag)cnt++;
	}

	prints(cnt);

	return 0;
}



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

int main() {
  int a[4], b[4];
  while (~scanf("%d%d%d%d", &a[0], &a[1], &a[2], &a[3])) {
    scanf("%d%d%d%d", &b[0], &b[1], &b[2], &b[3]);
    int hit = 0, blow = 0; 
    for (int i = 0; i < 4; ++i) {
      for (int j = 0; j < 4; ++j) {
        if (a[i] == b[j]) {
          if (i == j) hit++;
          else blow++;
        }
      }
    }
    printf("%d %d\n", hit, blow);
  }
}


Measured memory_bytes: 2616
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n,w):
        a = sorted([I() for _ in range(n)], reverse=True)
        dp = [0] * (w+1)
        dp[0] = 1
        sm = sum(a)
        if sm <= w:
            return 1
        r = 0
        for c in a:
            sm -= c
            if w >= sm:
                r += sum(dp[max(0,w-sm-c+1):w-sm+1])
                r %= mod
            for j in range(w-c,-1,-1):
                dp[j+c] += dp[j]
                dp[j+c] %= mod
        return r % mod

    while 1:
        n,m = LI()
        if n == 0:
            break
        rr.append(f(n,m))
        break

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 9212
def can(a, b):
  a, b = min(b, a),max(a,b)
  if b - a <= 1:
    return 2*a-2
  c = int((a*b)**0.5)
  if c**2 == a*b:
    c -= 1
  if c*(c+1) >= a*b:
    return 2*c-2
  return 2*c-1
q = int(input())
for _ in range(q):
  a, b = map(int, input().split())
  print(can(a, b))


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int N;
vector<int> P;

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

    cin >> N;
    P.resize(N);
    REP(i, N) { cin >> P[i]; }

    int ans = 0;
    int cur = LLINF;
    REP(i, N) {
        if(cur > P[i]) {
            ans++;
        }
        cur = min(cur, P[i]);
    }
    printf("%lld\n", ans);

    return 0;
}

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

using namespace std;
const long mod = 1000000007;
typedef long long lint;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(N) for(int i = 0; i < (int)(N); i++)
#define all(x) (x).begin(),(x).end()
#define length(x) ((int)(x).size())
#define prln(s) cout<<s<<endl;

#define str(s) int s;cin>>s;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;

int main() {
  int2(a,b);
  prln((a-1)*(b-1));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
constexpr auto INF = INT_MAX/2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n, q;
	cin >> n >> q;

	vvi e(n, vi(0));

	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--;b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}

	vi plus(n, 0), sum(n, -1);

	rep(i, q) {
		int p, x;
		cin >> p >> x;
		p--;
		plus[p] += x;
	}

	stack<int> st;
	st.push(0);
	sum[0] = plus[0];

	while (!st.empty()) {

		int v = st.top();st.pop();

		rep(i, e[v].size()) {
			int vv = e[v][i];
			if (sum[vv] > -1)continue;
			sum[vv] = plus[vv] + sum[v];
			st.push(vv);
		}

	}

	rep(i, n) {
		cout << sum[i];
		if (i < n - 1)cout << " ";
		else cout << endl;
	}

}

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

using namespace std;
long long int n,x,y,ans;
int main()
{       
        ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
        cin >> n >> x;
        while(n>=2 && x>=1)
        {
                x=max(x,n-x);
                y=n-x;
                ans+=3*(x/y)*y;
                n-=(x/y)*y;
                x%=y;
        }
        cout << ans;
        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

using namespace std;
void rdfs(int id, long long val);
void cdfs(int id, long long val);

vector<bool> rc, cc;
int r, c, n;
vector<vector<pair<int, long long>>> rp, cp;
vector<long long> rw, cw;
bool b = false;
long long rmin = 1000000000000, cmin = 10000000000000;

void rdfs(int id, long long val) {
  rmin = min(rmin, val);
  if(rc[id]) {
    if(rw[id] != val) b = true;
    return;
  } else {
    rc[id] = true;
    rw[id] = val;
  }
  for(int i = 0; i < rp[id].size(); i++) {
    cdfs(rp[id][i].first, rp[id][i].second - val);
  }
}

void cdfs(int id, long long val) {
  cmin = min(cmin, val);
  if(cc[id]) {
    if(cw[id] != val) b = true;
    return;
  } else {
    cc[id] = true;
    cw[id] = val;
  }
  for(int i = 0; i < cp[id].size(); i++) {
    rdfs(cp[id][i].first, cp[id][i].second - val);
  }
}

int main() {
  cin >> r >> c >> n;
  rw.resize(r); cw.resize(c);
  rp.resize(r); cp.resize(c);
  for(int i = 0; i < n; i++) {
    long long r1, c1, a;
    cin >> r1 >> c1 >> a;
    r1--; c1--;
    rp[r1].push_back(make_pair(c1, a));
    cp[c1].push_back(make_pair(r1, a));
  }
  rc.resize(r); cc.resize(c);
  for(int i = 0; i < r; i++) if(!rc[i]) {
    rmin = 100000000000; cmin = 100000000000;
    rdfs(i, 0);
    if(rmin + cmin < 0) b = true;
  }
  for(int i = 0; i < c; i++) if(!cc[i]) {
    rmin = 100000000000; cmin = 100000000000;
    cdfs(i, 0);
    if(rmin + cmin < 0) b = true;
  }
  if(b) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

	return 0;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int R,C,N;
    Scd3(R,C,N);


    auto oned = [&]( int x, int y ){
        if( x == 0 ) return y;
        else if( y == C ) return C+x;
        else if( x == R ) return C+R+C-y;
        else if( y == 0 ) return C+R+C+R-x;
        else return -1;
    };

    map<int,int> ed;
    int x1,y1,x2,y2;
    int t1,t2;
    Rep(i,N){
        Scd2(x1,y1);
        Scd2(x2,y2);
        t1 = oned(x1,y1);
        t2 = oned(x2,y2);
        if( t1 >= 0 && t2 >= 0 ){
            ed.insert({t1,i});
            ed.insert({t2,i});
        }
    }

    stack<int> st;
    st.push(-1);
    for( pii t : ed ){
        int id = t.second;
        if( st.top() != id ) st.push(id);
        else st.pop();
    }

    YESNO(st.size()==1);

    return 0;
}



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

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


Measured memory_bytes: 52292
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll sum[5];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		string S;
		cin >> S;
		if (S[0] == 'M') sum[0]++;
		if (S[0] == 'A') sum[1]++;
		if (S[0] == 'R') sum[2]++;
		if (S[0] == 'C') sum[3]++;
		if (S[0] == 'H') sum[4]++;
	}
	ll ans = 0;
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += sum[i] * sum[j] * sum[k];
			}
		}
	}
	cout << ans << endl;
}

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


int main(void){
	int n;
	scanf("%d",&n);
	int a[n];
	int c[n];
	c[0] =0;
	int i;
	for(i=1;i<n;i++){
		scanf("%d",&a[i]);
		c[i] = 0;
	}
	for(i=1;i<n;i++){
		c[a[i] - 1]++;
	}
	for(i=0;i<n;i++){
		printf("%d\n",c[i]);
	}

    return 0; 
}


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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define deb 0

int A[1000001];

int T[2][1000001];

void make(int n, int start, int end)
{
	if (start == end) {
		T[start&1][n] = start; return;
	}

	int mid = (start + end) >> 1;
	make(n<<1, start, mid);
	make(n<<1|1, mid+1, end);
	if (A[T[0][n<<1]] < A[T[0][n<<1|1]] ? T[0][n] = T[0][n<<1] : T[0][n] = T[0][n<<1|1]);
	if (A[T[1][n<<1]] < A[T[1][n<<1|1]] ? T[1][n] = T[1][n<<1] : T[1][n] = T[1][n<<1|1]);
}

int query(int id, int n, int start, int end, int l, int r)
{
	if (start > end || start > r || end < l) return 0;
	if (start >= l && end <= r) return T[id][n];
	int mid = (start + end) >> 1;

	int a = query(id, n<<1, start, mid, l, r);
	int b = query(id, n<<1|1, mid+1, end, l, r);

	if (A[a] < A[b]) return a;
	return b;
}

multiset <pair<pii, pii> > pq;
pair<pii, pii> tmp;
int ans[1000001], mp[1000001];

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

	int n, i, j, k, x, y, z, a, b, c;

	cin >> n;
	A[0] = MOD;
	for (i = 1; i <= n; ++i) {
		cin >> A[i];
		mp[A[i]] = i;
	}
	make(1, 1, n);

	a = query(1, 1, 1, n, 1, n);
	b = query(0, 1, 1, n, a, n);
	pq.insert(mkp(mkp(A[a], A[b]), mkp(1, n)));


	int start, end;
	for (i = 1; i <= n; i += 2) {
		tmp = *pq.begin();
		pq.erase(pq.begin());
		ans[i] = tmp.fi.fi;
		ans[i+1] = tmp.fi.sc;

		x = mp[ans[i]];
		y = mp[ans[i+1]];
		start = tmp.sc.fi;
		end = tmp.sc.sc;

		if (start != x) {
			a = query(start&1, 1, 1, n, start, x-1);
			b = query((start&1)^1, 1, 1, n, a+1, x-1);
			pq.insert(mkp(mkp(A[a], A[b]), mkp(start, x-1)));
		}

		if (end != y) {
			a = query(start&1, 1, 1, n, y+1, end);
			b = query((start&1)^1, 1, 1, n, a+1, end);
			pq.insert(mkp(mkp(A[a], A[b]), mkp(y+1, end)));
		}

		if (x+1 != y) {
			a = query((x&1)^1, 1, 1, n, x+1, y-1);
			b = query((x&1), 1, 1, n, a+1, y-1);
			pq.insert(mkp(mkp(A[a], A[b]), mkp(x+1, y-1)));
		}
	}

	for (i = 1; i <= n; ++i) cout << ans[i] << " "; cout << endl;

	return 0;
}

Measured memory_bytes: 21248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7
#define eb emplace_back

int main() {
    int n; cin >> n;
    int w[n]; rep(i, n) cin >> w[i];
    int mmin = inf;
    rrep(t, 1, n) {
        int a = 0, b = 0;
        rep(i, n) {
            if (i <= t) a += w[i];
            else b += w[i];
        }
        //cout << a << " " << b << endl;
        chmin(mmin, abs(a - b));
    }
    cout << mmin << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second<b.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
}
int main()
{
    vok();
    int n,k;
      IN n>>k;
      ll ans=0;
      ll ans2=0,ans4=0;
      vll v(k);
    ll temp=0;
      loop(i,0,k)
    {
          IN v[i];
          if(i>0)
        {
              temp=max(temp,v[i]-v[i-1]);
        }
    }
    temp= max(temp,v[0]+n-v[k-1]);
    OUT n-temp;
//    rloop(i,k-1,1)
//    {
//        ans4+=(v[i]-v[i-1]);
//    }
//      loop(i,2,k)
//    {
//          ans2+=(v[i]-v[i-1]);
//    }
//      ans2+=(v[0]+n-v[k-1]);
//    ll ans3=0;
//    rloop(i,k-2,1)
//    {
//        ans3+=(v[i]-v[i-1]);
//    }
//    ans3+=(v[0]+n-v[k-1]);
////    OUT ans<<endl
////    OUT ans2<<endl
////    OUT ans3<<endl
//    OUT min({ans,ans2,ans3,ans4});
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

ll K;

long long gcd(long long a, long long b)
{
    if(a < b)
    {
        swap(a, b);
    }
    while(b != 0)
    {
        long long c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int main()
{
    cin >> K;
    long long sum = 0;
    for(long long a = 1;a <= K;a++)
        for(long long b = 1;b <= K;b++)
            for(long long c = 1;c <= K;c++)
            {
                sum += gcd(gcd(a,b),c);
            }
    
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3168
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1e5+10
#define mod 1e9 + 7
#define pii pair<int,int>
using namespace std;
const int N = 1e5 + 1;
int n,w,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
vector<int> wgt(200),val(200);
int dp[200][(int)1e5+1];
int brute(int indx,int curWt){
	if(indx >= n){
		return 0;
	}
	if(curWt <= 0 ){
		return 0;
	}
	if(dp[indx][curWt] != -1){
		return dp[indx][curWt];
	}
	int ans1 = -1;
	if(curWt >= wgt[indx])
		ans1 = brute(indx + 1,curWt - wgt[indx]) + val[indx];
	int ans2 = brute(indx + 1,curWt);
	dp[indx][curWt] = max(ans1,ans2);
	return dp[indx][curWt];
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>w;
	for(int i=0;i<n;i++){
		cin>>wgt[i]>>val[i];
	}
	memset(dp,-1,sizeof dp);
	cout<<brute(0,w);
    return 0;
}
//.........

Measured memory_bytes: 156544
#include<stdio.h>
#include<stdlib.h>

#define MAX_NUM 100001
#define INF 10000000

typedef struct{
  int prev;
  int next;
  int cost;
} Edge;

Edge G[500000];
int d[MAX_NUM];

void da(int n, int count){
  int i, min = 1;
  int d[MAX_NUM];

  d[0] = 0;
  for(i=1; i<n; i++){
    d[i] = INF;
  }

  while(min != 0){
    min = 0;

    for(i=0; i<count; i++){
      if(d[G[i].prev] + G[i].cost < d[G[i].next]){
        d[G[i].next] = d[G[i].prev] + G[i].cost;
        min = 1;
      }
    }
  }

  for(i=0; i<n; i++) printf("%d %d\n", i, d[i]);

  return;
}

int main(void){

  int i, j, NUM,n, v, u;
  int count=0;

  scanf("%d", &n);

  for(i=0; i<n; i++){

    scanf("%d%d", &u, &NUM);

    for(j=0; j<NUM; j++){

      G[count].prev = u;
      scanf("%d%d", &G[count].next, &G[count].cost);
      count++;

    }
  }

  da(n,count);


  return 0;
}



Measured memory_bytes: 7516
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if( z->key < x->key ){
      x = x->left;
    }else{
      x = x->right;
    }
  }

  z->parent = y;

  if( y == NIL ){
    root = z;
  }else if( z->key < y->key ){
    y->left = z;
  }else{
    y->right = z;
  }

}

void inorder(Node u){
  if( u == NIL ){
    return;
  }

  inorder(u->left);
  printf(" %d" ,u->key);
  inorder(u->right);  
}

void preorder(Node u){
  if( u == NIL ){
    return;
  }

  printf(" %d" ,u->key);
  preorder(u->left);
  preorder(u->right);  


}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

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

using namespace std;

#define pb push_back
#define eb emplace_back
#define ll long long
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define ok puts("ok");
#define whatis(x) cerr << #x << " = " << x << endl;
#define pause system("pause");

const int N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;

int a[3];

main() {
  for (int i = 0; i < 3; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + 3);
  int ans = 0;
  while (a[0] + 2 <= a[2]) {
    a[0] += 2;
    ans++;
  }
  while (a[1] + 2 <= a[2]) {
    a[1] += 2;
    ans++;
  }
  sort(a, a + 3);
  if (a[0] < a[2] && a[1] == a[2]) {
    ans += 2;
  } else if (a[0] == a[1] && a[1] < a[2]) {
    ans++;
  }
  cout << ans;
}


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

#define debug(x) cerr<<#x<<'='<<x<<'\n'

const int N=1e5+6;
int n;
char y[N], c[N];
int ly, lc;

int main(void) {
	scanf("%s", y+1);
	int i=1, j=strlen(y+1);
	int ans=0;
	while (i<=j) {
		if (y[i]==y[j]) {
			i++;
			j--;
			continue;
		}
		if (y[i]=='x') {
			ans++;
			i++;
			continue;
		}
		if (y[j]=='x') {
			ans++;
			j--;
			continue;
		}
		puts("-1");
		return 0;
	}
	cout<<ans;	
	return 0;
}
	

Measured memory_bytes: 384
s=io.read()

bigger={}
bigger[#s+1]=0
for i=#s,1,-1 do
    inequality=s:sub(i,i)
    if inequality==">" then
        bigger[i]=bigger[i+1]+1
    else
        bigger[i]=0
    end
end

smaller={}
smaller[1]=0
for i=1,#s do
    inequality=s:sub(i,i)
    if inequality=="<" then
        smaller[i+1]=smaller[i]+1
    else
        smaller[i+1]=0
    end
end

total=0
for i=1,#s+1 do
    total=total+math.max(bigger[i],smaller[i])
end
print(total)

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

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

class Permutation {
  ll *_array;
  ll _length;
  bool _finished;

 public:
  Permutation(ll *array, ll length) {
    _array = array;
    _length = length;
    _finished = false;
  }

  void next() {
    if (_finished) {
      return;
    }
    if (!next_permutation(_array, _array + _length)) {
      _finished = true;
    }
  }

  ll data(ll index) { return _array[index]; }

  vector<ll> vec() {
    vector<ll> r;

    for (ll i = 0; i < _length; i++) {
      r.emplace_back(_array[i]);
    }

    return r;
  }

  void print() {
    for (ll i = 0; i < _length; i++) {
      cout << _array[i];
    }
    cout << endl;
  }

  bool finished() { return _finished; }
};

int main() {
  ll N;
  scanf("%lld", &N);

  vector<ll> v;
  for (ll i = 1; i <= N; i++) {
    v.emplace_back(i);
  }

  vector<ll> p;
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    p.emplace_back(v);
  }

  vector<ll> q;
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    q.emplace_back(v);
  }

  ll p_index = -1;
  ll q_index = -1;

  ll count = 1;
  auto perm = Permutation(v.data(), v.size());
  while (!perm.finished()) {
    // perm.print();

    if (perm.vec() == p) {
      p_index = count;
    }
    if (perm.vec() == q) {
      q_index = count;
    }

    perm.next();

    count += 1;
  }

  // cout << "p_index:" << p_index << endl;
  // cout << "q_index:" << q_index << endl;

  cout << abs(p_index - q_index) << endl;
}


Measured memory_bytes: 3696
N = int(input())
S = [None]*N
P = [None]*N

for i in range(N):
    S[i], P[i] = input().split()

P = [int(p) for p in P]
I = [j+1 for j in range(N)]
x = [(s, p, i) for s, p, i in zip(S, P, I)]

x.sort(key=lambda x:x[1], reverse=True)
x.sort(key=lambda x:x[0], reverse=False)

for s, p, i in x:
    print(i)

Measured memory_bytes: 3064
//#include <string>
//#include <set>
//#include <map>
//#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int inf = 0x7fffffff;
typedef long long ll;
void Faster( ){ ios_base::sync_with_stdio( false ); cin.tie( nullptr ); }
void iv( vector<int>& p ){ for( int& x: p ) cin >> x; }
void sa( vector<int>& p ){ sort( p.begin(), p.end() ); }
void pv( const vector<int>& p ){ for( int x: p ) cout << x << ' '; cout << '\n'; }
const vector<string> pussy{ "Sunny", "Cloudy", "Rainy" };
int main( ){
	Faster( );
	string s;
	cin >> s;
	for( int i = 0; i < 3; i++ ){
		if( s == pussy[i] ){
			cout << pussy[  (i + 1)%3  ];
		}
		

	}
	return 0;
}

// 08-06-2020
// Master Template 14
// kafiulshabbir@phystech.edu



Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	ll n, x, m;
	cin >> n >> x >> m;
	vector<ll>c;
	c.push_back(x);
	set<ll>s;
	ll cnt(0);
	ll ans(0);
	ans += c[0];
	bool ok = false;
	int key;
	rep(i, n-1) {
		int k = (c[i] * c[i]) % m;
		//cout << k;
		//cout << s.count(k)<<endl;
		if (s.count(k)) {
			key = k;
			ok = true;
			break;
		}
		else {
			s.insert(k);
			c.push_back(k);
			ans += k;
			cnt++;
		}
	}

	if (ok) {
		//ans -= key;
		//cout << ans << endl;;
		int i = 0;
		ll part(0);
		while (1) {
			if (c[i] == key)break;
			i++;
		}
		cnt++;
		ll amari = (n - i) % (cnt - i);
		ll kazu= (n - i) / (cnt - i);
		ll kaisuu = 0;
		//cout << kazu << " " << amari << " ";
		for (int j = i; j < c.size(); ++j) {
			part += c[j];
			
			kaisuu++;
			if (kaisuu == amari) {
				ans += part;
				//cout << part;
			}
		}
		ans += part * (kazu-1);
	}
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 5992
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line;
        while ((line = br.readLine()) != null && !line.isEmpty() && !"0".equals(line)) {
            String oct = Integer.toOctalString(Integer.valueOf(line));
            oct = oct.replaceAll("7","9");
            oct = oct.replaceAll("6","8");
            oct = oct.replaceAll("5","7");
            oct = oct.replaceAll("4","5");
            System.out.println(oct);
        }
    }
}


Measured memory_bytes: 63700
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<string,int>P;

int dy[]={-1,-1,0,1,1,1,0,-1};
int dx[]={0,1,1,1,0,-1,-1,-1};
int n;
string s,t;
set<string>st;


bool CNT(string &S){
  r(i,n*n)if(S[i]=='#')return 0;
  return 1;
}

void solve(){
  st.insert(s);
  queue<P>q;
  q.push(P(s,0));
  while(!q.empty()){
    s=q.front().first;
    int cost=q.front().second;q.pop();
    if(CNT(s)){
      cout<<cost<<endl;
      return;
    }
    string a[n],b[n];
    r(i,n)a[i]=b[i]=s.substr(i*n,n);
    r(i,n)r(j,n)if(a[i][j]=='@'){
      r(k,8){
        a[i][j]='.';
        int y=i+dy[k];
        int x=j+dx[k];
        if(y<0||x<0||y>=n||x>=n)continue;
        if(a[y][x]=='#')continue;
        a[y][x]='@';
        r(i1,n)r(j1,n)if(!(i1==y&&j1==x)){
          int sum=0;
          r(k1,8){
            int ny=i1+dy[k1];
            int nx=j1+dx[k1];
            if(ny<0||nx<0||ny>=n||nx>=n)continue;
            if(b[ny][nx]=='#'||a[ny][nx]=='@')sum++;
          }
          if((b[i1][j1]!='#')&&sum==3)a[i1][j1]='#';
          if((b[i1][j1]=='#')&&!(sum==3||sum==2))a[i1][j1]='.';
        }
        t="";
        r(q,n)t+=a[q];
        if(!st.count(t)){
          st.insert(t);
          q.push(P(t,cost+1));
        }
        r(q,n)a[q]=b[q];
      }
      a[i][j]='@';
    }
  }
  cout<<-1<<endl;
}

signed main(){
  while(cin>>n,n){
    st.clear();
    s="";
    r(i,n){
      cin>>t;
      s+=t;
    }
    solve();
  }
}


Measured memory_bytes: 5600
#include <cstdio>
#include <utility>
#include <queue>

using namespace std;

typedef pair<int, int> pii;

#define fst first
#define scd second
#define rep(i,x) for(int i=0;i<(x);++i)

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

int st[1000][1002];

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

	rep(i, H) rep(j, W) {
		char c; scanf("\n%c", &c);
		st[i][j] = (c == '.') ? -1 : c - '0';
	}

	queue<pii> q;

	rep(i, H) rep(j, W) if (st[i][j] == -1) q.push(pii(i, j));

	int ans = 0;

	while (q.size()) {
		queue<pii> Q;

		while (q.size()) {
			pii p = q.front(); q.pop();
			rep(i, 8) {
				int ny = p.fst + dy[i], nx = p.scd + dx[i];
				if (0 <= ny && ny < H && 0 <= nx && nx < W && st[ny][nx] > 0) {
					st[ny][nx]--;
					if (st[ny][nx] == 0) Q.push(pii(ny, nx));
				}
			}
		}

		if (Q.empty()) break;

		while (Q.size()) {
			q.push(Q.front()); Q.pop();
		}

		ans++;
	}

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

Measured memory_bytes: 5088
#include <stdio.h>
#include <stdint.h>

uint64_t n;
uint64_t a[2 * 100005];
uint64_t sum[2 * 100005];
uint64_t xum[2 * 100005];
uint64_t ans;

int main()
{
	scanf("%llu", &n);
	for (uint64_t i = 1; i <= n; i++) {
		scanf("%llu", &a[i]);

		sum[i] = sum[i - 1] + a[i];
		xum[i] = xum[i - 1] ^ a[i];
	}

	uint64_t l, r;
	l = r = 1;
	while (r <= n && l <= n) {
		while (r + 1 <= n && (sum[r + 1] - sum[l - 1]) == (xum[r + 1] ^ xum[l - 1])) {
			r++;
		}

		ans += r - l + 1;
		l++;
	}
	
	printf("%llu\n", ans);

	return 0;
}


Measured memory_bytes: 4864
def partition(a, p, r):
    """パーティション分割"""
    x = int(a[r].split()[1])
    i = p - 1
    for j in range(p, r):
        if int(a[j].split()[1]) <= x:
            i = i + 1
            a[i], a[j] = a[j], a[i]
    a[i+1], a[r] = a[r], a[i+1]
    return i + 1


def quick_sort(a, p, r):
    if p < r:
        # パーティション分割し、基準値を取得
        q = partition(a, p, r)

        # 基準値を境目に更にパーティション分割を実施
        quick_sort(a, p, q-1)
        quick_sort(a, q+1, r)


n = int(input())
li = [input().splitlines()[0] for x in range(n)]
stable = sorted(li, key=lambda x: int(x.split()[1]))
# print(f"{li=}")
# print(f"{stable=}")

quick_sort(li, 0, n - 1)
# print(f"{li=}")
print("S" if stable == li else "Not s", end="")
print("table")
for i in li:
    print(i)



Measured memory_bytes: 17276
A, B, C = [int(x) for x in input().split()]

def main():
    list = [A, B, C]
    list.sort()

    d1 = list[2] - list[0]
    d2 = list[2] - list[1]

    d = d1 + d2
    
    if d % 2 == 0:
        ans = d // 2
    else:
        ans = d // 2 + 2

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(m)]

for i in ab:
    ans = []
    for j in cd:
        kyori = abs(i[0]-j[0]) + abs(i[1]-j[1])
        ans.append(kyori)
    print(ans.index(min(ans))+1)

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

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

int main(){

  int N,K;
    cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    bool flag=false;
    if(K>A[N-1]) cout<<"IMPOSSIBLE"<<endl;
    else{
        for(int i=0;i<N-1;i++){
            A[i+1]=gcd(A[i],A[i+1]);
            if(A[i+1]==1){
                flag=true;
                break;
            }
        }
        if(flag) cout<<"POSSIBLE"<<endl;
        else{
            if(K%A[N-1]==0) cout<<"POSSIBLE"<<endl;
            else cout<<"IMPOSSIBLE"<<endl;
        }
    }
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#define N_ 101000
using namespace std;
struct point1 {
	int b, e, num;
	bool operator <(const point1 &p)const {
		return e < p.e;
	}
}A[N_];

struct point2 {
	int b, e, num;
	bool operator <(const point2 &p)const {
		return b > p.b;
	}
}B[N_];
int n, v[N_];
int main() {
	int i, b, e;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &b, &e);
		A[i] = { b,e,i };
		B[i] = { b,e,i };
	}
	sort(A + 1, A + n + 1);
	sort(B + 1, B + n + 1);
	int cur = 0, pv = 1;
	long long s = 0;
	for (i = 1; i <= n; i++) {
		if (v[A[i].num])continue;
		if (cur < A[i].b) {
			s += A[i].b - cur;
			cur = A[i].b;
		}
		if (cur > A[i].e) {
			s += cur - A[i].e;
			cur = A[i].e;
		}
		v[A[i].num] = 1;
		while (pv <= n) {
			if (v[B[pv].num]) {
				pv++;
				continue;
			}
			if (cur < B[pv].b) {
				s += B[pv].b - cur;
				cur = B[pv].b;
			}
			if (cur > B[pv].e) {
				s += cur - B[pv].e;
				cur = B[pv].e;
			}
			v[B[pv].num] = 1;
			pv++;
			break;
		}
	}
	long long res = s + abs(cur);
	for (i = 1; i <= n; i++)v[i] = 0;
	pv = 1;
	s = 0; cur = 0;
	for (i = 1; i <= n; i++) {
		if (v[B[i].num])continue;
		if (cur < B[i].b) {
			s += B[i].b - cur;
			cur = B[i].b;
		}
		if (cur > B[i].e) {
			s += cur - B[i].e;
			cur = B[i].e;
		}
		v[B[i].num] = 1;
		while (pv <= n) {
			if (v[A[pv].num]) {
				pv++;
				continue;
			}
			if (cur < A[pv].b) {
				s += A[pv].b - cur;
				cur = A[pv].b;
			}
			if (cur > A[pv].e) {
				s += cur - A[pv].e;
				cur = A[pv].e;
			}
			v[A[pv].num] = 1;
			pv++;
			break;
		}
	}
	res = max(res, s + abs(cur));
	printf("%lld\n", res);
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,k,t,u,v,l,d[210]={};
  cin>>n>>k>>t>>u>>v>>l;
  for(int i=1;i<=n;i++)cin>>d[i];
  d[n+1]=l;
  long long a=0,p=0;
  for(int i=1;i<=n+1;i++){
    if(a>d[i]-d[i-1]){
      a-=d[i]-d[i-1];
      a=min(a+v*t,v*t*(k+1));
    }
    else p+=d[i]-d[i-1]-a,a=v*t;
  }
  printf("%.10f\n",1.0*p/u+1.0*(l-p)/v);
  return 0;
}

Measured memory_bytes: 1196
(let ((a (make-hash-table))
      (b (make-array '(3 3) :initial-element nil))
      (n 0)
      (ans 0))
  (loop :for i :from 0 :to 2
        :do (loop :for j :from 0 :to 2
                  :do (setf (gethash (read) a) (cons i j))))
  (setf n (read))
  (loop :for i :from 1 :to n
        :do (let ((x (gethash (read) a)))
              (when x
                (setf (aref b (car x) (cdr x)) t))))
  ;
  (loop :for i :from 0 :to 2
        :do (if (and (aref b i 0) (aref b i 1) (aref b i 2))
                (incf ans)))
  (loop :for i :from 0 :to 2
        :do (if (and (aref b 0 i) (aref b 1 i) (aref b 2 i))
                (incf ans)))
  (if (and (aref b 0 0) (aref b 1 1) (aref b 2 2))
      (incf ans))
  (if (and (aref b 2 0) (aref b 1 1) (aref b 0 2))
      (incf ans))
  ;
  (if (> ans 0)
      (format t "Yes~%")
      (format t "No~%")))


Measured memory_bytes: 23804
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

#define mmum 1e9
using vint = vector<int>;
using vvint = vector< vector<int> >;

int main(int argc, char* argv[]){
  int n; cin >> n;
  vint a;
  for(int i = 0; i < n ; i++){
    int t;
    cin >> t;
    t = mmum - t;
    auto it = upper_bound(a.begin(), a.end(), t);
    if(it != a.end()){
      *it = t;
    }
    else a.push_back(t);
  }
  cout << a.size() << endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
int main(){
  string s;
  cin>>s;
  int ans = 0;
  rep(i,3){
    if(s[i]=='1')
      ans++;
  }
  cout<<ans<<endl;
      



}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      if(b-a == c-b)System.out.println("YES");
      else System.out.println("NO");
    }
}

Measured memory_bytes: 23508
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

ll A[N];

int best_of(int l, int r) {
	int la = l, ra = r-1;
	while(la < ra) {
		int m = (la + ra + 1) >> 1;
		if(A[m] - A[l-1] < A[r] - A[m]) {
			la = m;
		}
		else ra = m - 1;
	}
	return la;
}

ll try_with(int a, int b, int c, int d) {
	ll P = A[a];
	ll Q = A[b] - A[a];
	ll R = A[c] - A[b];
	ll S = A[d] - A[c];

	return max(max(P, Q), max(R, S)) - min(min(P, Q), min(R, S));
}

int main() {

	boost;
	int n; cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>A[i];
		A[i] += A[i-1];
	}
	ll ans = 9e18;

	for(int i=2; i<=n-2; i++) {

		int a = best_of(1, i);
		int b = best_of(i+1, n);

		ans = min(ans, try_with(a, i, b, n));
		if(a+1 < i) ans = min(ans, try_with(a+1, i, b, n));
		if(b+1 < n) ans = min(ans, try_with(a, i, b+1, n));
		if(a+1 < i and b+1 < n) ans = min(ans, try_with(a+1, i, b+1, n));
	}

	cout<<ans<<"\n";
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define LL long long
#define R register int
#define G if(++ip==ie)if(fread(ip=buf,1,SZ,stdin))
using namespace std;
const int SZ=1<<19,N=2e5+9;
char buf[SZ],*ie=buf+SZ,*ip=ie-1;
inline int in(){
    G;while(*ip<'-')G;
    R x=*ip&15;G;
    while(*ip>'-'){x*=10;x+=*ip&15;G;}
    return x;
}
int a[N],f[N];
struct Edge{
    int u,v,w;
    inline bool operator<(const Edge&x)const{
        return w<x.w;
    }
}e[2*N];
inline void Cmn(R&x,R y){
    if(x>y)x=y;
}
int Getf(R x){
    return x==f[x]?x:f[x]=Getf(f[x]);
}
int main(){
    R n=in(),q=in();
    memset(a,63,4*n);
    for(R i=1;i<=q;++i){
        e[i].u=in(),e[i].v=in(),e[i].w=in();
        Cmn(a[e[i].u],e[i].w+1);
        Cmn(a[e[i].v],e[i].w+2);
    }
    R pos=min_element(a,a+n)-a;
    for(R i=pos+1;i!=pos;++i%=n)
        Cmn(a[i],a[i?i-1:n-1]+2);
    for(R i=0;i<n;++i)
        e[++q]=(Edge){i,(i+1)%n,a[i]},f[i]=i;
    sort(e+1,e+q+1);
    LL ans=0;
    for(R i=1;i<=q;++i){
        R x=Getf(e[i].u),y=Getf(e[i].v);
        if(x!=y)f[x]=y,ans+=e[i].w;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10112
#include <stdio.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
 
int main(void)
{
    int i, n, a[200001];
    
    scanf("%d", &n);
    
    for( i = 0; i < n; i++ ){
        scanf("%d", &a[i]);
    }
    
    qsort(a, n, sizeof(int), compare_int);
    
    for( i = 0; i < n-1; i++ ){
        if( a[i] == a[i+1] ){
            printf("NO\n");
            
            return 0;
        }
    }
    
    printf("YES\n");
    return 0;
}

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.rl", "r", stdin);
	string str = "";
	
	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if

		vector <double> Area(11, 0. );
		vector <double> Sum (11, 0.);
		int i;

		while (str.find(',') != string::npos ){
			str = str.replace(str.find(','), 1, " ");
		} // end while

		stringstream ss(str);

		Area[0] = 0.;

		for (i = 1; i <= 10; ++i){
			ss >> Area[i];
		} // end for

		for (i = 0; i <= 10; ++i){
			Sum[i] = accumulate (Area.begin(), Area.begin()+i+1, 0.);
//			cout << "Sum[" << i << "]: " << Sum[i] << endl;
		} // end for
		
		double v1 = 0., v2 = 0.;
		ss >> v1;
		ss >> v2;
		double L = v1*Sum[10]/(v1 + v2);

		for (i = 1; i <= 10; ++i){
			if (Sum[i-1] < L && L <= Sum[i]){
				cout << i << endl;
				break;
			} // end if
		} // end for
	} // end while

	return 0;
}

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

int main() {
    vector<int> v(5);
    for (int i=0; i<5; ++i) {
        cin >> v[i];
    }
    sort(v.begin(), v.end(), greater<int>());
    for (int i=0; i<5; ++i) {
        cout << (i == 0 ? "" : " ") << v[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1212
#include <vector>
#include <list>
#include <string>
#include <iostream>
#include <fstream>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

int solve(void);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

int solve(void)
{
	string S, T;
	cin >> S >> T;
	cout << T << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

vector<int> divisor(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i, n) cin >> vec[i];
    map<int, int> mp;
    sort(all(vec));
    int cnt = 0;
    set<int> same;
    vector<int> ignore(1000001, 0);
    rep(i, n){
        ignore[vec[i]]++;
    }
    rep(i, n){
        if(ignore[vec[i]] > 1){
            mp[vec[i]]++;
        }
    }
    rep(i, n){
        if(ignore[vec[i]] > 1) continue;
        vector<int> divs = divisor(vec[i]);
        bool found = false;
        rep(j, divs.size()){
            if(mp[divs[j]] != 0){
                found = true;
                break;
            }
        }
        if(!found) cnt++;
        mp[vec[i]]++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 36704
from fractions import gcd
import numpy as np

n = int(input())
a = list(map(int, input().split()))

left = np.zeros(n + 1, dtype=np.int)
right = np.zeros(n + 1, dtype=np.int)

for i in range(n):
    left[i + 1] = gcd(left[i], a[i])
    right[n - i - 1] = gcd(right[n - i], a[n - i - 1])

last = np.zeros(n, dtype=np.int)

for i in range(n):
    last[i] = gcd(left[i], right[i + 1])


print(max(last))


Measured memory_bytes: 24520
n = int(input())
ind = []
m = 0
k = 0
for i in range(n):
    a = int(input())
    if m == a:
        ind = -1
    elif m < a:
        k, m = m, a
        ind = i
    elif k < a:
        k = a
if ind == -1:
    print("\n".join(map(str, [m for i in range(n)])))
else:
    print("\n".join(map(str, [k if i == ind else m for i in range(n)])))


Measured memory_bytes: 17372