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

#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

  int n; cin >> n;
  vec<int, 2> adjEdge(n);
  for (int i = 1; i < n; ++i) {
    int u, v; cin >> u >> v; --u; --v;
    adjEdge[u].emplace_back(v);
    adjEdge[v].emplace_back(u);
  }

  vec<int, 1> side(n, -1);
  function<void(int, int, bool)> dfs = [&](int u, int par, bool curSide) {
    side[u] = curSide;
    for (auto& v : adjEdge[u]) {
      if (v != par) {
        dfs(v, u, curSide ^ 1);
      }
    }
  };
  dfs(0, -1, false);

  array<vec<int, 1>, 3> group;
  for (int i = 1; i <= n; ++i) {
    group[i % 3].emplace_back(i);
  }
  if (static_cast<int>(count(all(side), false)) <= n / 3) {
    for (int i = 0; i < n; ++i) {
      if (!side[i]) {
        cout << group[0].back() << ' ';
        group[0].pop_back();
      } else {
        if (sz(group[1])) {
          cout << group[1].back() << ' ';
          group[1].pop_back();
        } else if (sz(group[2])) {
          cout << group[2].back() << ' ';
          group[2].pop_back();
        } else {
          cout << group[0].back() << ' ';
          group[0].pop_back();
        }
      }
    }
  } else if (static_cast<int>(count(all(side), true)) <= n / 3) {
    for (int i = 0; i < n; ++i) {
      if (side[i]) {
        cout << group[0].back() << ' ';
        group[0].pop_back();
      } else {
        if (sz(group[1])) {
          cout << group[1].back() << ' ';
          group[1].pop_back();
        } else if (sz(group[2])) {
          cout << group[2].back() << ' ';
          group[2].pop_back();
        } else {
          cout << group[0].back() << ' ';
          group[0].pop_back();
        }
      }
    }
  } else {
    for (int i = 0; i < n; ++i) {
      if (side[i]) {
        if (sz(group[1])) {
          cout << group[1].back() << ' ';
          group[1].pop_back();
        } else {
          cout << group[0].back() << ' ';
          group[0].pop_back();
        }
      } else {
        if (sz(group[2])) {
          cout << group[2].back() << ' ';
          group[2].pop_back();
        } else {
          cout << group[0].back() << ' ';
          group[0].pop_back();
        }
      }
    }
  }

  return 0;
}

Measured memory_bytes: 27268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_150
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            long[] array = ReadLongs();
            long lcm = array[0];
            for (int i = 1; i < n; i++)
            {
                long gcd = GCD(lcm, array[i]);
                lcm *= array[i] / gcd;
                if (lcm / 2 > m)
                {
                    WriteLine(0);
                    return;
                }
            }
            if (lcm % 2 == 1)
            {
                WriteLine(0);
                return;
            }
            for (int i = 0; i < n; i++)
            {
                long div = lcm / array[i];
                if (div % 2 == 0)
                {
                    WriteLine(0);
                    return;
                }
            }
            WriteLine((m - lcm / 2) / lcm + 1);
        }

        static long GCD(long a, long b)
        {
            if (b > a)
            {
                long temp = b;
                b = a;
                a = temp;
            }
            long c = b;
            do
            {
                c = a % b;
                a = b;
                b = c;
            } while (c > 0);
            return a;
        }

        static long LCM(long a, long b)
        {
            long c = GCD(a, b);
            return a * b / c;
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 29404
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
ans=1
c=a.count(0)
if c>0:
    print(0)
    exit()
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        print(-1)
        exit()
print(ans)
        

Measured memory_bytes: 23972
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

int N;
vector<int> neighbors[100000];
bool visited[100001][2];
ll dp[100001][2];

ll rec(int v, int pv, int c)
{
    if (visited[v][c]) return dp[v][c];
    visited[v][c] = true;

    ll ret = 1;
    if (c == 0) {
        for (int nv: neighbors[v]) {
            ll x = 0;
            if (nv == pv) continue;
            REP (i, 2) {
                x += rec(nv, v, i);
                x %= MOD;
            }
            ret *= x;
            ret %= MOD;
        }
    } else {
        for (int nv: neighbors[v]) {
            if (nv == pv) continue;
            ret *= rec(nv, v, 0);
            ret %= MOD;
        }
    }
    return dp[v][c] = ret;
}

void solve()
{
    ll ans = 0;
    ans += rec(0, -1, 0);
    ans %= MOD;
    ans += rec(0, -1, 1);
    ans %= MOD;
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP (i, N-1) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        neighbors[x].pb(y);
        neighbors[y].pb(x);
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 15872
lines = readlines
n = lines[0].chomp.to_i

arr = []
for i in 1..n do
  arr << lines[i].chomp.chars.sort.join
end

count_hash = Hash.new(0)

arr.each do |a|
  count_hash[a] += 1
end

result = 0
count_hash.each_value do |culc|
  result += culc*(culc-1) / 2
end

p result

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll nCrmod(ll n,ll r){ll x=1,y=1; rep(i,r){x=x*(n-i)%mod; y=y*(i+1)%mod;} return x*powmod(y,mod-2)%mod;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m;
	cin >> m >> n;
	cout << powmod(m,n) << endl;
	return 0;
}


Measured memory_bytes: 3116
N, K = map(int, input().split())
Ad_list = [list(map(int, input().split(' '))) for _ in range(K*2)]

result = {i: 0 for i in range(1, N+1)}
for i in range(1, K+1):
    index = i*2 - 1
    for k in Ad_list[index]:
        result[k] += 1

print(len({k for k, v in result.items() if v == 0}))


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

int main() {
  int N,K,l[60],i,sum=0;

  cin >> N >> K;
  for (i=0; i<N; i++) cin >> l[i];

  sort(l, l+N, greater<int>());

  for (i=0; i<K; i++) {
    sum += l[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, input().split())


class UnionFind(object):
    def __init__(self, n = 1):
        self.link = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.link[x] == x:
            return x

        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
        self.link[x] = self.find(self.link[x])
        return self.link[x]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.size[x] < self.size[y]:
            x, y = y, x
        self.link[y] = x
        self.size[x] += self.size[y]
    
    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

es = [0] * M
for i in range(M):
    a, b = map(int, input().split())
    es[i] = (a - 1, b - 1)

ans = 0
for i in range(M):
    u = UnionFind(N)
    for j in range(M):
        if i == j:
            continue
        a, b = es[j]
        u.unite(a, b)
    if u.get_size(0) != N:
        ans += 1
print(ans)

Measured memory_bytes: 9512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    VI p(n); REP(i,n) cin >> p[i];
    REP(i,n) REP(j,n){
        bool ok = 1;
        VI copy = p;
        swap(copy[i],copy[j]);
        int now = copy[0];
        FOR(q,1,n) if(now>copy[q]){ok = 0;} else{now=copy[q];}
        if(ok){YES; return 0;}
    }
    NO;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 1000005
#define MAX_H 1005
#define MAX_W 1005

int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int INF = 1e8;
struct state{
  int y,x,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};

int H,W,N;
int si,sj,ti,tj;
char a[MAX_N];
int b[4][MAX_N];

char t[MAX_H][MAX_W];
int d[MAX_H][MAX_W];


bool solve(){
  fill( (int*)d[0], (int*)d[MAX_H] , INF );
  priority_queue< state > Q;
  Q.push( (state){si,sj,0} );
  d[si][sj]=0;
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.cost > d[s.y][s.x])continue;
    if(t[s.y][s.x]=='G')return true;
    for(int ndir=0;ndir<4;ndir++){
      int ncost=b[ndir][s.cost];
      if(ncost==-1)continue;
      int ny=s.y+dy[ndir];
      int nx=s.x+dx[ndir];
      if(ny<0 || nx<0 || ny>=H || nx>=W )continue;
      if(t[ny][nx]=='#')continue;
      if(ncost < d[ny][nx]){
        d[ny][nx]=ncost; 
        Q.push( (state){ny,nx,ncost} );
      }
    }
  }
  return false;
}

int main(){
  while(1){
    scanf("%d %d %d",&H,&W,&N);
    if(H==0&&W==0&&N==0)break;
    
    scanf("%s",a);

    memset(b,-1,sizeof(b));
    int dir=0;
    for(int i=0;i<=N;i++){
      b[dir][i]=i;
      if(i<N)dir=dir+(a[i]=='L'?3:1);
      if(dir>=4)dir-=4;
    }
    for(int i=N-1;i>=0;i--){
      for(int j=0;j<4;j++){
        if(b[j][i]==-1)b[j][i]=b[j][i+1];
      }
    }
    
    for(int i=0;i<H;i++){
      scanf("%s",t[i]);
      for(int j=0;j<W;j++){
        if(t[i][j]=='S')si=i,sj=j;
      }
    }
    printf(solve() ? "Yes\n" : "No\n" );
  }
  return 0;
}

Measured memory_bytes: 22228
#include <stdio.h>

void margesort(int *, int, int);
void marge(int *, int, int, int);

int count = 0;
int S[5000000];
int L[2500001];
int R[2500001];

int main(){
  int n, i;

  scanf("%d", &n);
   for(i = 0; i < n; i++){
    scanf("%d", &S[i]);
  }

  margesort(S, 0, n);
 
   for(i = 0; i < n-1; i++){
    printf("%d ", S[i]);
  }
  printf("%d\n", S[i]);
  printf("%d\n", count); 

  return 0;
}
 
void margesort(int *S, int left, int right){
  int mid;

  if(left+1 < right){ 
    mid = (left + right)/2;
    margesort(S, left, mid);
    margesort(S, mid, right);
    marge(S, left, mid, right);
  }
}

 void marge(int *S, int left, int mid, int right){
  int b1, b2;
  int i, j=0, k;
 
  b1 = mid - left;
  b2 = right - mid;
 
  for(i = 0; i < b1; i++){
    L[i] = S[left+i];
  }
  L[b1] = 1000000001;

  for(i = 0; i <b2; i++){
    R[i] = S[mid+i];
  }
  R[b2] = 1000000001;
 
  i = 0;
  for(k = left; k < right; k++){
    if(L[i] <= R[j]){  
    S[k] = L[i];
    i++;
  }
  else{
    S[k] = R[j];
    j++;
  }
  count++;
  }
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  
  ll ans=n/11*2;
  if(n%11){
    if(n%11>6) ans+=2;
    else ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P  = pair<int, int>;
using PP = pair<bool, P>;
struct Graph
{
    Graph(const int v)
        : V{ v }, edge(v), rev_edge(v) {}
    void addEdge(const int from, const int to)
    {
        edge[from].push_back(to);
        rev_edge[to].push_back(from);
    }
    const int V;
    vector<vector<int>> edge;
    vector<vector<int>> rev_edge;
};

inline bool ng(const PP& p)
{
    return (not p.first) and (((((p.second.first + p.second.first) % 2) + 2) % 2 == 1) or p.second.first > p.second.second);
}
inline PP merge(const PP& p1, const PP& p2)
{
    if (p1.first) {
        return p2;
    } else if (p2.first) {
        return p1;
    } else {
        if ((((p1.second.first + p2.second.first) % 2) + 2) % 2 == 0) {
            return { false, { max(p1.second.first, p2.second.first), min(p1.second.second, p2.second.second) } };
        } else {
            return { false, { 0, -2 } };
        }
    }
}

inline PP next(const PP& p) { return (ng(p) ? PP{ false, { 0, -2 } } : PP{ p.first, { p.second.first - 1, p.second.second + 1 } }); }
void dfs(const Graph& g, const int s, vector<bool>& used, vector<PP>& cand, const vector<int>& node)
{
    used[s] = true;
    PP ans  = { true, { 0, 0 } };
    if (node[s] != -1) {
        ans = merge(ans, { false, { node[s], node[s] } });
    }
    for (const int to : g.edge[s]) {
        if (not used[to]) {
            dfs(g, to, used, cand, node);
            if (not cand[to].first) {
                ans = merge(ans, next(cand[to]));
                if (ng(ans)) {
                    ans = { false, { 0, -2 } };
                }
            }
        }
    }
    cand[s] = ans;
}

void dfs(const Graph& g, const int s, const int par, vector<bool>& used, const vector<PP>& cand, vector<int>& node)
{
    used[s]        = true;
    const auto tmp = merge(cand[s], { false, { par - 1, par + 1 } });
    node[s]        = tmp.second.first;
    for (const int to : g.edge[s]) {
        if (not used[to]) {
            dfs(g, to, node[s], used, cand, node);
        }
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    Graph g(N);
    vector<int> node(N, -1);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g.addEdge(u, v);
        g.addEdge(v, u);
    }
    int K;
    cin >> K;
    for (int i = 0; i < K; i++) {
        int v, p;
        cin >> v >> p;
        v--;
        node[v] = p;
    }
    vector<PP> cand(N);
    vector<bool> used(N, false);
    dfs(g, 0, used, cand, node);
    if (ng(cand[0])) {
        cout << "No" << endl;
        return 0;
    } else if (cand[0].first) {
        node[0] = 0;
        cand[0] = { false, { 0, 0 } };
    } else {
        node[0] = cand[0].second.first;
        cand[0] = { false, { cand[0].second.first, cand[0].second.first } };
    }
    fill(used.begin(), used.end(), false);
    dfs(g, 0, cand[0].second.first + 1, used, cand, node);
    cout << "Yes" << endl;
    for (int i = 0; i < N; i++) {
        cout << node[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 24448
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;
typedef map<LL, LL> MLL;

const double PI = 3.1415926535897932384626433832795;

int main() {
  int n;
  cin >> n;
  MLL probs;
  LL t;
  REP(i, n) {
    cin >> t;
    probs[t]++;
  }
  int m;
  cin >> m;
  REP(i, m) {
    cin >> t;
    probs[t]--;
    if(probs[t] < 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

  return 0;
}


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

int main() {
  int r;
  cin >> r;
  cout << 3*r*r << endl;
}


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

using namespace std;

#define allof(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define exists(s, e) (s.find(e)!=s.end())
#define INF 0x3f3f3f3f
#define endl '\n'
#define mp make_pair
#define watch(x) cout << (#x) << " is " << (x) << endl;

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

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

#define int long long

set<int> s;
int n;

bool good(string str) {
    bool has3=false, has5=false, has7=false;
    for(int i=0; i<sz(str); i++) {
        if(str[i]=='3') has3 = true;
        else if(str[i]=='5') has5 = true;
        else if(str[i]=='7') has7 = true;
        else return false;
    }
    if(has3 and has5 and has7) return true;
    else return false;
}

// generate all permutations until 999999999
void dfs(int cur) {
    if(cur>n) return;
    string num = to_string(cur);
    if(good(num)) s.insert(cur);
    if(not exists(s, stol(num+'3'))) dfs(stol(num+'3'));
    if(not exists(s, stol(num+'5'))) dfs(stol(num+'5'));
    if(not exists(s, stol(num+'7'))) dfs(stol(num+'7'));
    if(not exists(s, stol('3'+num))) dfs(stol('3'+num));
    if(not exists(s, stol('5'+num))) dfs(stol('5'+num));
    if(not exists(s, stol('7'+num))) dfs(stol('7'+num));
}

void solve() {
    cin >> n;
//  dfs all individual numbers
    dfs(357);
    dfs(375);
    dfs(537);
    dfs(573);
    dfs(735);
    dfs(753);

// dfs duplicates of 2
    dfs(335); dfs(353);
    dfs(337); dfs(373);
    dfs(553); dfs(535);
    dfs(557); dfs(575);
    dfs(773); dfs(737);
    dfs(775); dfs(757);

    dfs(533); dfs(733);
    dfs(755);

//    for(int x : s) {
//        cout << x << " ";
//    }
    cout << sz(s) << endl;

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    solve();
    return 0;
}




Measured memory_bytes: 1536
//ABC147 C

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = s; i < (int)(n); i++)
const lint mod = 1000000007;


lint ans = 0;
lint n;
lint a[16],x[16][16],y[16][16],s[16],t[16];


int main() {
  cin >> n;

  reps(i,1,n+1){
    scanf("%lld",&a[i]);
    rep(j,a[i]){
      scanf("%lld %lld",&x[i][j],&y[i][j]);
    }
  }

  lint tmp = 1<<n;
  reps(i,1,tmp+1){
    lint cnt = 0;
    rep(j,n){
      //cnt = i>>j;
      t[j+1] = (i>>j)%2;
    }
    rep(j,n){
      if((i>>j)%2 == 1){
        rep(k,a[j+1]){
          if(t[x[j+1][k]] != y[j+1][k]){
            goto next_loop;
          }
        }
      }
    }
    reps(j,1,n+1){
      if(t[j] == 1) cnt++;
    }
    next_loop:
    ans = max(ans,cnt);
  }
  
  printf("%lld\n",ans);
}


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

typedef long long Int;
#define MAX_L 16
Int table[MAX_L + 1][MAX_L + 1];
bool wall[MAX_L + 1][MAX_L + 1];
int a, b, n;

Int dp(int x, int y){
	if(x == a && y == b) return 1;
	if(x > a || y > b) return 0;
	if(table[x][y] >= 0) return table[x][y];
	if(wall[x][y]) return 0;
	
	return table[x][y] = dp(x + 1, y) + dp(x, y + 1);
}

int main(){
	while(1){
		scanf("%d%d", &a, &b);
		if(a == 0 && b == 0) return 0;
		scanf("%d", &n);
		
		int in_x, in_y;
		
		memset(wall, 0, sizeof(wall));
		for(int i = 0; i < n; i++){
			scanf("%d%d", &in_x, &in_y);
			wall[in_x][in_y] = true;
		}
		
		memset(table, -1, sizeof(table));
		
		printf("%lld\n", dp(1, 1));
	}
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  string s;
  R s;
  rep(i,s.size()) {
    if(i%2==0) {
      if(s[i]=='L') {
        pr("No");
        return;
      }
    } else {
      if(s[i]=='R') {
        pr("No");
        return;
      }
    }
  }
  pr("Yes");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();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)

int main() {
  int n; cin >> n;
  vector<string> s(n); REP(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  int m; cin >> m;
  vector<string> t(m); REP(i, m) cin >> t[i];
  
  int i = 0; int ans = 0;
  while(i < n) {
    string tmp = s[i];
    int cs = count(s.begin(), s.end(), tmp);
    int ct = count(t.begin(), t.end(), tmp);
    ans = max(ans, cs - ct);
    i += cs;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string>

#define _CRT_SECURE_NO_WARNINGS

int main() {
	int N;
	scanf("%d", &N);
	int a[100010] = {};
	for (int i = 0; i < N;i++) {
		scanf("%d",&a[i]);
	}
	std::sort(&a[0],&a[N]);
	int ans=0;
	for (int i = 0; i < N; i++) {
		if (a[i]==a[i+1]) {
			i++;
		}
		else {
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
import numpy as np
import queue
H,W=map(int,input().split())
S=list()
for i in range(H):
  S.append(input())
ans=0
  
for i in range(H):
  for j in range(W):
    if S[i][j]==".":
      L=[[-1]*W for i in range(H)]
      L[i][j]=0
      q=queue.Queue()
      q.put([i,j])
      while not q.empty():
        r=q.get()
        for k,l in [[1,0],[0,-1],[0,1],[-1,0]]:
          if r[0]+k>=0 and r[0]+k<H and r[1]+l>=0 and r[1]+l<W and S[r[0]+k][r[1]+l]=="." and L[r[0]+k][r[1]+l]==-1:
            L[r[0]+k][r[1]+l]=L[r[0]][r[1]]+1
            q.put([r[0]+k,r[1]+l])
      ans=max(ans,max(list(map(lambda x:max(x),L))))
print(ans)


Measured memory_bytes: 27304
using System;

public class Hello
{
    public static void Main()
    {
        var a = new int[] { 63, 6, 91, 79, 102, 109, 125, 39, 127, 111,0 };
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == -1) break;
            var pre = 10;
            for (int i = 0; i < n; i++)
            {
                var d = int.Parse(Console.ReadLine().Trim());
                var ret = Convert.ToString(a[pre] ^ a[d], 2);
                Console.WriteLine(ret.Length == 7 ? ret:new string('0',7-ret.Length) + ret);
                pre = d;
            }
        }
    }
}


Measured memory_bytes: 8988
#include<cstdio>
#include<string.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,a[100005],vis[100005],sum;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	scanf("%d",&a[i]);
    	if(a[i]<=n)vis[a[i]]++;
    	else sum++;
	}
	for(int i=1;i<=n;i++){
		if(vis[i]<i)sum+=vis[i];
		else sum+=(vis[i]-i);
	}
	cout<<sum;
}


Measured memory_bytes: 640
a=input().split(" ")
n=int(a[0])
m=int(a[1])
ans=[]
b=[]
c=[]
for i in range(m):
    x=input().split(" ")
    y=[x[0],x[1]]
    b.append(y)
if n==1:
    for i in range(10**(n)):
    
        num=list(str(i))
        num=num[::-1]
        num.append(0)
        num=num[::-1]
        count=0
        for j in range(m):
            if int(num[int(b[j][0])])!=int(b[j][1]):
                count+=1
                break
        if count==0:
            c.append(i)
            print(i)
            break

        
else:
    for i in range(10**(n-1),10**(n)):
        
        num=list(str(i))
        num=num[::-1]
        num.append(0)
        num=num[::-1]
        count=0
        for j in range(m):
            if int(num[int(b[j][0])])!=int(b[j][1]):
                count+=1
                break
        if count==0:
            c.append(i)
            print(i)
            break
if c==[]:
    print("-1")

Measured memory_bytes: 3064
A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

def bsr(a, v, lo=0, hi=None):
	if None == hi:
		hi = len(a) - 1
	while lo <= hi:
		mi = (lo + hi) // 2
		if a[mi] <= v:
			lo = mi + 1
		else:
			hi = mi - 1
	return lo

INF = 10 ** 18
s = [-INF] + S + [INF]
t = [-INF] + T + [INF]

for x in X:
	sp = bsr(s, x)
	tp = bsr(t, x)
	cost = []
	cost += [abs(s[sp - 0] - x) + abs(s[sp - 0] - t[tp - 0])]
	cost += [abs(s[sp - 1] - x) + abs(s[sp - 1] - t[tp - 0])]
	cost += [abs(s[sp - 0] - x) + abs(s[sp - 0] - t[tp - 1])]
	cost += [abs(s[sp - 1] - x) + abs(s[sp - 1] - t[tp - 1])]
	cost += [abs(t[tp - 0] - x) + abs(s[sp - 0] - t[tp - 0])]
	cost += [abs(t[tp - 1] - x) + abs(s[sp - 0] - t[tp - 1])]
	cost += [abs(t[tp - 0] - x) + abs(s[sp - 1] - t[tp - 0])]
	cost += [abs(t[tp - 1] - x) + abs(s[sp - 1] - t[tp - 1])]
	print(min(cost))


Measured memory_bytes: 105176
#include <stdio.h>
#include <string.h>
 
char HA[1<<21], T[256];
 
int main() {
    unsigned int n, s, t;
    char c;
    T['A'] = 4;
    T['C'] = 3;
    T['G'] = 2;
    T['T'] = 1;
    scanf("%d", &n);
    getchar();
    while (n--) {
        s = 0;
        t = 1;
        int flag = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = T[getchar()] ) != 0 ) {
            s += c * t;
            t *= 4;
        }
        if ( flag ) HA[s] = 1; else puts( HA[s] ? "yes" : "no" );
    }
    return 0;
}


Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, a[200005], out[1000005], ans;
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d", a+i);
		if(out[a[i]] == 0){
			for(int t = a[i]; t <= 1000000; t += a[i]) out[t]++;
		}else out[a[i]]++;
	}
	rep(i,n) if(out[a[i]] == 1) ans++;
	printf("%d\n", ans);
}

Measured memory_bytes: 8400
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.sort()
y.sort()

Z = list(range(max(X, x[-1])+1, min(Y, y[0])+1))

if X < Y and x[-1] < y[0] and len(Z) > 0:
    print('No War')
else:
    print('War')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1e18;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

string f(string s) {
  if (sz(s) == 0) return "-1";
  vi a(256);
  for (char c : s) a[c] = 1;
  for (int i = s.back()-'a'; i < 26; ++i) {
    char c = 'a'+i;
    if (a[c]) continue;
    s.back() = c;
    return s;
  }
  return f(s.substr(0,sz(s)-1));
}

int main() {
  string s;
  cin>>s;
  vi a(256);
  string ans;
  rep(i,sz(s)) {
    if (a[s[i]]) {
      cout<<f(ans)<<endl;
      return 0;
    }
    a[s[i]] = 1;
    ans += s[i];
  }
  rep(i,26) {
    char c = 'a'+i;
    if (a[c]) continue;
    ans += c;
    cout<<ans<<endl;
    return 0;
  }
  cout<<f(ans)<<endl;
  return 0;
}






















Measured memory_bytes: 256
//! (*'ω'*)

use std::str::Chars;
use std::io;

fn get_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_string()
}

fn game(turn: char, sa: &mut Chars, sb: &mut Chars, sc: &mut Chars) -> String {
    let card = match turn {
        'a' => sa.next(),
        'b' => sb.next(),
        'c' => sc.next(),
        _ => panic!(),
    };

    if let Some(c) = card {
        game(c, sa, sb, sc)
    } else {
        turn.to_uppercase().collect()
    }
}

fn main() {
    let sa = get_line();
    let sb = get_line();
    let sc = get_line();

    println!("{}",
             game('a', &mut sa.chars(), &mut sb.chars(), &mut sc.chars()));
}


Measured memory_bytes: 380
#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ld eps = 1e-9;
const int inf = mod;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a){if(a<0)return -1;if(a>0)return 1;return 0;}


template<typename T> inline void in(T &x){
    x = 0; T f = 1; char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
    while (isdigit(ch))  {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

PII range[100010];
int pre[100010];
int suf[100010];
void f(){
    cout<<0;exit(0);
}
void upd(int i,PII ran){
    if(ran.fi>range[i].se||ran.se<range[i].fi)f();
    range[i].fi = max(range[i].fi,ran.fi);
    range[i].se = min(range[i].se,ran.se);
}
int main(){
    int n;in(n);
    REP(i,1,n+1){
        in(pre[i]);
        if(pre[i]<pre[i-1])f();
        range[i] = MP(1,1000000000);
    }
    REP(i,1,n+1){
        in(suf[i]);
    }
    REP(i,1,n+1){
        if(suf[i]<suf[i+1])f();
    }
    REP(i,1,n+1){
        if(pre[i]!=pre[i-1]) upd(i,MP(pre[i],pre[i]));
        else upd(i,MP(1,pre[i]));
    }
    RREP(i,n,1){
        if(suf[i]!=suf[i+1]) upd(i,MP(suf[i],suf[i]));
        else upd(i,MP(1,suf[i]));
    }
    ll ans = 1;
    REP(i,1,n+1){
        ans = (ans*(range[i].se-range[i].fi+1))%mod;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define setp(x) setprecision(x)
#define nep(x) next_permutation(x);
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

int main() {
    ll M, N;
    cin >> N >> M;
    vector<pair<ll, ll>> Shop(N);
    for(int i = 0; i < N; i++) cin >> Shop[i].fi >> Shop[i].se;
    sort(all(Shop));
    ll sum = 0;
    for(int i = 0; i < N; i++){
        M -= Shop[i].se;
        sum += Shop[i].se * Shop[i].fi;
        if(M <= 0){
            M += Shop[i].se;
            sum -= Shop[i].se * Shop[i].fi;
            sum += M * Shop[i].fi;
            break;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 1792
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias XY = Tuple!(long, "x", long, "y");

XY[1000] XYS;

void main()
{
    auto N = readln.chomp.to!int;
    long c = -1;
    foreach (i; 0..N) {
        auto xy = readln.split.to!(long[]);
        auto x = xy[0];
        auto y = xy[1];
        XYS[i] = XY(x, y);
        if (c < 0) c = abs((x + y) % 2);
        if (c != abs((x + y) % 2)) {
            writeln("-1");
            return;
        }
    }

    long[] ds;
    ds.length = 39;
    foreach (i; 0..39) {
        ds[i] = 1L<<i;
    }
    if (!c) ds = [1L] ~ ds;
    writeln(ds.length);
    writeln(ds.map!(to!string).join(" "));

    foreach (xy; XYS[0..N]) {
        auto u = -xy.x - xy.y;
        auto v = -xy.x + xy.y;
        string r;
        foreach_reverse (d; ds) {
            auto a = u < 0 ? 1 : -1;
            auto b = v < 0 ? 1 : -1;
            u += a * d;
            v += b * d;
            if (a == 1 && b == 1) {
                r = "R" ~ r;
            } else if (a == 1 && b == -1) {
                r = "U" ~ r;
            } else if (a == -1 && b == 1) {
                r = "D" ~ r;
            } else {
                r = "L" ~ r;
            }
        }
        writeln(r);
    }
}

Measured memory_bytes: 1276
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>

using namespace std;

int comb(int n,int r);

int main(void){

  int n;
  cin >> n;

  vector<int> a(n);

  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  
  sort(a.begin(),a.end());

  for(int i=0;i<n;i++){
    //cout << a[i] << endl;
  }
  //cout << endl;
  
  if(n==2) cout << a[1] << " " << a[0] << endl;
  else{

    int before=a[0];
    for(int i=1;i<n;i++){
      if(a[i] < a[n-1]/2){
	before=a[i];
      }
      else{
	if( abs(a[n-1]/2 - before) < abs(a[n-1]/2 - a[i]) ){
	  cout << a[n-1] << " " << before << endl;
	}
	else{
	  cout << a[n-1] << " " << a[i] << endl;	  
	}
	break;
      }
    }
    
  }
  
  return 0;
}

int comb(int n,int r){

  int value=1;

  
}


Measured memory_bytes: 640
#include <iostream>                                                   
using namespace std;                                                  
                                                                      
int main() {                                                          
  int x, y;                                                           
  while (true) {                                                      
    cin >> x >> y;                                                    
    if (x==0 && y==0) {                                               
      break;                                                          
    }                                                                 
    if (x>y) {                                                        
      swap(x,y);                                                      
    }                                                                 
    cout << x << " " << y << endl;                                    
  }                                                                   
  return 0;                                                           
}       

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

int main()
{

    ll r, d;
    ll a[11];
    cin >> r >> d >> a[0];
    for(ll i =1; i <= 10; i++) a[i] = r*a[i-1]-d;
    for(ll i = 1; i <= 10; i++) cout << a[i] << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
	      Scanner sc = new Scanner(System.in);
	      int a = sc.nextInt();
	      int b = sc.nextInt();
	      String n = sc.next();
	      char c = n.charAt(a);
	      int l = n.length();
	      String ans = "No";
	      if((a+b+1) == l && c == ('-')){
	    	  ans = "Yes";
	    	  for(int i = 0; i < a; i++) {
	    		  if(n.charAt(i) == '-') {
	    			  ans = "No";
	    		  }
	    	  }
	      for(int i = 0; i < b; i++) {
    		  if(n.charAt(a+1+i) == '-') {
    			  ans = "No";
    		  }
    	  }
      }
	      System.out.println(ans);
	}
}

Measured memory_bytes: 22868
def gcd(x, y): 
   while(y): 
       x, y = y, x % y 
  
   return x

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

Prefix=[0 for i in range(n + 2)] 
Suffix=[0 for i in range(n + 2)] 

Prefix[1] = a[0] 
for i in range(2,n+1): 
    Prefix[i] = gcd(Prefix[i - 1], a[i - 1]) 

Suffix[n] = a[n - 1] 

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

ans = max(Suffix[2], Prefix[n - 1]) 

for i in range(2,n): 
    ans = max(ans, gcd(Prefix[i - 1], Suffix[i + 1])) 

print(ans)

Measured memory_bytes: 14440
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    double r;
    cin>>r;
    cout<<fixed<<setprecision(10)<<(double)2.0*r*3.141592<<endl;
}

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

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

    int ans = 2e9+1, ta = 0;
    for(int i=0; i<n; i++){
        int a, b;
        cin >> a >> b;
        if(ta < a){
            ans = min(ans, a+b);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3536
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
		String s = sc.next();
      	int count = 0;	
      
      	for(char c : s.toCharArray()) {
      		if(c == '1') count++;
        }
      	System.out.println(count);
    }
}

Measured memory_bytes: 21588