akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int cc[33][200005];
int ans[200005];
int main() {
  int n,c;
  cin >> n >> c;
  for(int i = 0; i < n; i++) {
    int s,t,C;
    cin >> s >> t >> C;
    cc[C][s * 2 - 1]++;
    cc[C][t * 2 + 1]--;
  }
  
  for(int i = 0; i <= c; i++) {
    for(int j = 1; j < 200004; j++) cc[i][j] += cc[i][j-1];
    for(int j = 0; j < 200004; j++) if(cc[i][j]) ans[j]++;
    }
  
  int A = 0;
  for(int i = 0; i < 200005; i++) {
    A = max(A,ans[i]);
  }

  cout << A << endl;
}


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

using namespace std;

int main()
{
    #ifdef HOME
    freopen("input.txt", "rt", stdin);
    #endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a(n + 1), tmp;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        if (a[i] == i)
            tmp.push_back(i);
    }
    int ans = 0;
    if (tmp.size() == 0){
        cout << 0;
        return 0;
    }
    int l = tmp[0], r = tmp[0];
    for (int i = 1; i < tmp.size(); i++){
        if (r == tmp[i] - 1)
            r = tmp[i];
        else{
            ans += (r - l + 2) / 2;
            l = tmp[i];
            r = tmp[i];
        }
    }
    ans += (r - l + 2) / 2;
    cout << ans;
    return 0;
}


Measured memory_bytes: 1276
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

L = int(input())
a = L/3
print(a**3)

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

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

    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3] || s[3] == s[4]) {
        cout << "Bad" << endl;
    } else cout << "Good" << endl;
}

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

int main(){
    int A,B;
    cin >> A >> B;
    vector<int> prcA,prcB;
    rep(i,10000){
        int taxA = i*0.08;
        if(taxA==A){
            prcA.emplace_back(i);
        }
        int taxB = i*0.1;
        if(taxB==B){
            prcB.emplace_back(i);
        }
    }
    bool flg = false;
    int flg_prc;
    rep(i,prcA.size()){
        rep(j,prcB.size()){
            if(prcA.at(i)==prcB.at(j)){
                flg = true;
                flg_prc = min(flg_prc,prcA.at(i));
            }
        }
    }
    if(flg) cout << flg_prc << endl;
    else cout << "-1" << endl;
}

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

using namespace std;

#define int long long
#define ff first
#define ss second
#define pb emplace_back

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    n *= 2;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < n; i += 2)
        ans += a[i];
    cout << ans;
}


Measured memory_bytes: 256
C = 10 ** 9 + 7

def modinv(a, m)
  b, u, v = m, 1, 0
  until b.zero?
    t = a / b
    a -= t * b
    a, b = b, a
    u -= t * v
    u, v = v, u
  end
  u %= m
  u += m if u < 0
  u
end

n, k = gets.split.map(&:to_i)
seq = gets.split.map(&:to_i).sort_by {-_1.abs}

tmp = seq[0, k]
f0 = seq.all? {_1 < 0}
f1 = tmp.map {_1 <=> 0}.inject(:*)
ans = tmp.inject(1) {|acc, i| acc * i % C}

ans = if k == n || f1 >= 0
  ans
elsif f0 && k.odd?
  seq[n - k, k].inject(1) {|acc, i| acc * i % C}
else
  x1 = x2 = y1 = y2 = nil
  tmp.reverse_each do |i|
    if i < 0
      x1 = i
      break
    end
  end
  tmp.reverse_each do |i|
    if i > 0
      x2 = i
      break
    end
  end
  seq[k..].each do |i|
    if i >= 0
      y1 = i
      break
    end
  end
  seq[k..].each do |i|
    if i < 0
      y2 = i
      break
    end
  end
  
  if !x2 || !y2
    ans * y1 * modinv(x1, C) % C
  elsif !x1 || !y1
    ans * y2 * modinv(x2, C) % C
  elsif (x2 * y1).abs > (x1 * y2).abs
    ans * y1 * modinv(x1, C) % C
  else
    ans * y2 * modinv(x2, C) % C
  end 
end

puts ans

Measured memory_bytes: 34360
N = int(input())
Ali = [0]*(N+1)
 
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      i = x**2+y**2+z**2+x*y+y*z+z*x
      if i<=N:
        Ali[i] += 1
        
for i in range(N):
  print(Ali[i+1])

Measured memory_bytes: 9228
import sys
from scipy.sparse.csgraph import floyd_warshall as f
def main():
  n,m,l,*t=map(int,sys.stdin.buffer.read().split())
  d=[[0]*(n+1)for _ in range(n+1)]
  for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=c
  d=f(f(d,0)<=l)-1
  d[d>n]=-1
  d=d.astype('i2')
  print('\n'.join(map(str,[d[i]for i in zip(*[iter(t[m*3+1:])]*2)])))
main()

Measured memory_bytes: 36252
#include <stdio.h>

int main()
{
	long long x, y, t;


	(void)fscanf(stdin, "%lld %lld", &x, &y);

	int q = 0;
	t = x;
	for(int i = 1;;i++)
	{
		if (t > y)
			break;
		t += t;
		q++;
	}

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

	return 0;
}


Measured memory_bytes: 128
//これはDP4次元の場合である。これだと、どうしても空間のメモリが膨大な数になってしまう・原理的にはいけるはず
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> data(h, vector<char>(w));
    rep(i, h) rep(j, w) cin >> data[i][j];
    priority_queue<ll> py;
    rep(i, h)
    {
        rep(j, w)
        {
            queue<ll> que;
            vector<vector<int>> dist(h, vector<int>(w, -1)); //訪れたかどうかを判断
            //スタート地点を全部試して行く・
            que.push(i);
            que.push(j); //最初の場所を追加する。
            if (data[i][j] != '#')
            {
                dist[i][j] = 0; //初期条件
            }
            else
            {
                continue;
            }
            while (que.empty() != 1)
            {
                int a = que.front();
                que.pop();
                int b = que.front();
                //この最初を考えて行く。
                if (a + 1 < h && dist[a + 1][b] == -1 && data[a + 1][b] != '#')
                {
                    que.push(a + 1);
                    que.push(b);
                    dist[a + 1][b] = 1 + dist[a][b];
                }
                if (a - 1 > -1 && dist[a - 1][b] == -1 && data[a - 1][b] != '#')
                {
                    que.push(a - 1);
                    que.push(b);
                    dist[a - 1][b] = 1 + dist[a][b];
                }
                if (b + 1 < w && dist[a][b + 1] == -1 && data[a][b + 1] != '#')
                {
                    que.push(a);
                    que.push(b + 1);
                    dist[a][b + 1] = 1 + dist[a][b];
                }
                if (b - 1 > -1 && dist[a][b - 1] == -1 && data[a][b - 1] != '#')
                {
                    que.push(a);
                    que.push(b - 1);
                    dist[a][b - 1] = 1 + dist[a][b];
                }
                que.pop();
            }
            //distance(20*20の配列の中からもっとも大きいものを手に入れたい。)
            rep(p, h)
            {
                rep(q, w)
                {
                    py.push(dist[p][q]);
                }
            }
        }
    }
    cout << py.top();
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize
#define ini ll_MAX
#define inl LLONG_MAX
#define MOD 1000000007
#define sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define F0R(i, a) for (ll i = 0; i < (a); i++)
#define FORR(i, a, b) for (ll i = a; i >= (b); i--)
#define F0RR(i, a) for (ll i = a; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define pbds tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
 
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
 
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
 
ll mod(ll a,ll b)
{
    return (b+a%b)%b;
}
 
ll gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ll po(ll a,ll b)
{
    ll ans = 1;
    while(b--)
        ans*=a;
    return ans;
}
ll pom(ll a,ll b,ll mod)
{
    if(b==0)return 1;
    ll k = pom(a,b/2,mod);
    if(b%2==0)return (k*k)%mod;
    else return ((k*k)*mod*a)%mod;
}
 
ll sqdist(ll a,ll b,ll c,ll d)
{
    return (a-c)*(a-c)+(b-d)*(b-d);
}
ll fact(ll n)
{
    if(n==0)return 1;
    ll ans = 1;
    FOR(i,1,n+1)ans*=i;
    return ans;
}

 
void solve()
{
    ll n;
    cin>>n;ll ans = 0,mi=LLONG_MAX;
    while(n--)
    {
        ll p;
        cin>>p;
        if(p<mi)
        {
            ans++;
        }
        mi = min(mi,p);
    }
    cout<<ans;
}
 
 
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    // ll t;
    //cout<<"Y"<<endl;
    //cin>>t;
    //while(t--)
        solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define MOD 1000000007
//#define eps 1e-10
#define R freopen("555input.txt","r",stdin);
#define W freopen("555output.txt","w",stdout);
#define N 100005
#define M 16000
int i,j,n,t,l;
LL a[N],w,h;
int main()
{
    
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%lld",&a[i]);
    sort(a,a+n);
    for(i=n-1;i;i--)
    {
        if(a[i]==a[i-1]){w=a[i];i-=2;break;}
    }
    for(;i;i--)
    {
        if(a[i]==a[i-1]){h=a[i];break;}
    }
    printf("%lld",w*h);
    return 0;
}




Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val a = scanner.nextLong()
    val b = scanner.nextLong()
    val c = scanner.nextLong()
    val d = scanner.nextLong()
    var firstC = 0L
    var firstD = 0L
    var firstCD = 0L
    val numC:Long
    val numD:Long
    val numCD:Long
    val gcd = c*d / cal(c, d)
    var divC = a%c
    var divD = a%d
    var divCD = a%gcd
    if(divC === 0L) firstC = a
    else firstC = a+(c-divC)
    if(divD === 0L) firstD = a
    else firstD = a+(d-divD)
    if(a <= gcd) firstCD = gcd
    else if(divCD === 0L) firstCD = a
    else firstCD = a+(gcd-divCD)
    if(b < firstC) numC = 0L
    else numC = (b-firstC)/c+1L
    if(b < firstD) numD = 0L 
    else numD = (b-firstD)/d+1L
    if(b < firstCD) numCD = 0L
    else numCD = (b-firstCD)/gcd+1L
    /*println(gcd)
    println(numC)
    println(numD)
    println(numCD)*/
    val res = (b-a+1L)-(numC+numD-numCD)
    println(res)
}

fun cal(x:Long, y:Long): Long{
    var x2 = x;
    var y2 = y;
    if(x2 < y2) return cal(y2, x2);
    if(y2 === 0L) return x2;
    return cal(y2, x2 % y2);
}

Measured memory_bytes: 31252
#include<iostream>
#include<iomanip>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define EQ(a,b) (abs((a)-(b))<EPS)
using namespace std;
typedef long double D;
const D EPS = 1e-9;

struct event{
  D time;
  int type; // 0:lost, 1:collide
  int obj1, obj2;

  event(D a,int b,int c,int d):time(a),type(b),obj1(c),obj2(d){}
  bool operator<(const event &x)const {return time>x.time;}
};

struct meteor{
  D px, py, pz, vx, vy, vz, pr, vr;
  meteor(D a=0,D b=0,D c=0,D d=0,D e=0,D f=0,D g=0,D h=0):
    px(a),py(b),pz(c),vx(d),vy(e),vz(f),pr(g),vr(h){}
  
};

D collideTime(meteor m1, meteor m2){
  const D a1 = m1.vx - m2.vx, a2 = m1.vy - m2.vy, a3 = m1.vz - m2.vz;
  const D b1 = m1.px - m2.px, b2 = m1.py - m2.py, b3 = m1.pz - m2.pz;
  const D a4 = m1.vr + m2.vr, b4 = m1.pr + m2.pr;

  const D a = a1*a1+a2*a2+a3*a3 - a4*a4;
  const D b_p = a1*b1+a2*b2+a3*b3 + a4*b4;
  const D c = b1*b1+b2*b2+b3*b3 - b4*b4;
  
  if(EQ(a,0)){
    if(EQ(b_p,0)){
      if(EQ(c,0))return 0;
      else return -1.0;
    }else return -c/b_p;
  }

  D azu = b_p*b_p-a*c;
  if(azu < -EPS)return -1.0;
  if(EQ(azu,0))return b_p/a;
  D res1 = (-b_p-sqrt(azu)) /a, res2 = (-b_p+sqrt(azu)) /a;
  if(res1 < -EPS)return res2;
  return res1;
}

int main(){
  int n;

  while(cin >> n){
    if(n==0)break;
    vector<meteor> vm(n);
    priority_queue<event> next;

    rep(i,n){
      D a,b,c,d,e,f,g,h;
      cin >> a >> b >> c >> d >> e >> f >> g >> h;
      vm[i] = meteor(a,b,c,d,e,f,g,h);

      next.push(event(g/h,0,i,-1));
    }

    rep(i,n)rep(j,i){
      D t = collideTime(vm[i],vm[j]);
      if(t>=0.0)next.push(event(t,1,i,j));
    }

    vector<D> res(n,-1.0);
    while(next.size()){
      event cur = next.top(); next.pop();
      if(cur.type == 0){
	int m = cur.obj1;
	if(res[m] < 0)res[m] = cur.time;
      }else{
	int m1 = cur.obj1, m2 = cur.obj2;
	if(res[m1] < 0 && res[m2] <0)res[m1] = res[m2] = cur.time;
      }
    }

    rep(i,n)cout << fixed << setprecision(10) << res[i] << endl;
  }
}

Measured memory_bytes: 2764
/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
const int MAX_N = 100025;
ll dp[MAX_N],arr[MAX_N];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;scanf("%d",&n);
    for(int i = 1;i<=n;++i) scanf("%lld",&arr[i]);
    for(int i = 2;i<=n;++i)
    {
        if(i==2) dp[i] = dp[i-1]+abs(arr[i]-arr[i-1]);
        else dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    printf("%lld\n",dp[n]);
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    ll n, k;
    cin >> n >> k;

    map<ll, ll> cnt;
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        if(cnt.find(a) == cnt.end()) cnt[a] = 0;
        cnt[a] += b;
    }

    for(auto itr = cnt.begin(); itr != cnt.end(); ++ itr){
        if(itr->second < k) k -= itr->second;
        else{
            cout << itr->first << endl;
            break;
        }
    }
}

Measured memory_bytes: 4224
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=2e5+10;
int n,m,a[N],ans,b[N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
inline bool chck(int x)
{
	for(RG int i=1;i<=m;i++) b[i]= a[i]>=x;
	for(RG int i=0;i<n;i++)
	 if(b[n-i]==b[n-i-1]) return b[n-i];
	 else if(b[n+i]==b[n+i+1]) return b[n+i];
	return b[1];
}
int main()
{
//	freopen("Median Pyramid Hard.in","r",stdin);
	read(n); m=n*2-1;
	for(RG int i=1;i<=m;i++) read(a[i]);
	int l=1, r=m;
	while(l<=r)
	{
		int mid=l+(r-l)/2;
		if(chck(mid)) ans=mid, l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int mo=998244353;
const int N=300000;
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
int n,S,a[N],b[N],c[N];
void divide(int *a,int *b,int *c,int n){
	if (n==1){
		c[0]=b[0]*1ll*power(a[0],mo-2)%mo;
		return;
	}
	n>>=1;
	For(i,0,n-1){
		int x,y;
		x=a[i],y=a[i+n];
		a[i]=(x+y)%mo; a[i+n]=(x+mo-y)%mo;
		x=b[i],y=b[i+n];
		b[i]=(x+y)%mo; b[i+n]=(x+mo-y)%mo;
	}
	divide(a,b,c,n);
	divide(a+n,b+n,c+n,n);
	For(i,0,n-1){
		int x,y;
		x=c[i],y=c[i+n];
		c[i]=(x+y)%mo; c[i+n]=(x+mo-y)%mo;
		c[i]=1ll*c[i]*(mo+1)/2%mo;
		c[i+n]=1ll*c[i+n]*(mo+1)/2%mo;
	}
}
int main(){
	scanf("%d",&n);
	For(i,0,(1<<n)-1){
		scanf("%d",&a[i]);
		S=(S+a[i])%mo;
	}
	S=power(S,mo-2);
	For(i,0,(1<<n)-1) a[i]=1ll*a[i]*S%mo;
	For(i,0,(1<<n)-1) b[i]=(i?mo-1:(1<<n)-1);
	a[0]=(a[0]+mo-1)%mo;
	divide(a,b,c,1<<n);
	For(i,0,(1<<n)-1)
		printf("%d\n",(c[i]+mo-c[0])%mo);
}

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

const int MAX_N = 100010;
const int INF = 1001001001;

int dp[MAX_N];

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < MAX_N; i++)
        dp[i] = INF;

    dp[0] = 0;

    for (int i = 0; i <= N; i++)
    {
        for (int j = 1; i + j <= N; j *= 6)
            dp[i + j] = min(dp[i + j], dp[i] + 1);
        for (int j = 1; i + j <= N; j *= 9)
            dp[i + j] = min(dp[i + j], dp[i] + 1);
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<int MOD>
class ModInt {
public:
    ModInt() :value(0) {}
    ModInt(long long val) :value((int)(val<0 ? MOD + val%MOD : val%MOD)) { }

    ModInt& operator+=(ModInt that) {
        value = value + that.value;
        if (value >= MOD)value -= MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that) {
        value -= that.value;
        if (value<0)value += MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that) {
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that) {
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const {
        return ModInt(*this) += that;
    }
    ModInt operator-(ModInt that) const {
        return ModInt(*this) -= that;
    }
    ModInt operator*(ModInt that) const {
        return ModInt(*this) *= that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const {
        if (value == 0)return 0;
        ModInt n = *this, res = 1;
        while (k) {
            if (k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const { return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x) {
    os << x.toi();
    return os;
}

namespace comb {
    const int N = 1000006;
    mint fact[N];
    mint rev[N];

    void init() {
        fact[0] = 1;
        for (int i = 1; i < N; ++i)fact[i] = fact[i - 1] * i;
        for (int i = 0; i < N; ++i)rev[i] = fact[i].inverse();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    using namespace comb;
    init();

    int M;
    while (cin >> M) {
        mint re, p;
        for (int k = 1; k <= M - 1; ++k) {
            int a = 2 * k - M;
            int b = M - k - 1;
            if (a < 0 || b < 0)continue;
            mint q = fact[a + b] * rev[a] * rev[b] * fact[k] * fact[M - 1 - k];
            re += (q - p)*k;
            p = q;
        }
        cout << re << endl;
    }
}

Measured memory_bytes: 8064
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.HashMap;

public class Main
{
    int n, m;
    int nx[] = new int[51];
    int ny[] = new int[51];
    int mx[] = new int[51];
    int my[] = new int[51];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

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

	    int l = 1 << 30;
	    int cp = 0;

	    for(int j = 0; j < m; j++) {
		int tmp = Math.abs(nx[i] - mx[j]) + Math.abs(ny[i] - my[j]);
		if(l > tmp) {
		    l = tmp;
		    cp = j + 1;
		}
	    }

	    out(cp);
	    
	}
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);

	n = sc.nextInt();
	m = sc.nextInt();
	for(int i = 0; i < n; i++) {
	    nx[i] = sc.nextInt();
	    ny[i] = sc.nextInt();
	}
	for(int i = 0; i < m; i++) {
	    mx[i] = sc.nextInt();
	    my[i] = sc.nextInt();
	}
    }

    void out()
    {
	
    }
    
    void out(int n)
    {
	System.out.println(n);
    }

    void out(char c)
    {
	System.out.print(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
}


Measured memory_bytes: 21844
#
C = []
for i in range(3):
    C.append(list(map(int, input().split())))
#print(C)

# y0-1
if C[0][0]-C[1][0]!=C[0][1]-C[1][1] or C[0][1]-C[1][1]!=C[0][2]-C[1][2]:
    print('No')
    exit()
# y1-2
if C[1][0]-C[2][0]!=C[1][1]-C[2][1] or C[1][1]-C[2][1]!=C[1][2]-C[2][2]:
    print('No')
    exit()
if C[0][0]-C[0][1]!=C[1][0]-C[1][1] or C[1][0]-C[1][1]!=C[2][0]-C[2][1]:
    print('No')
    exit()
if C[0][1]-C[0][2]!=C[1][1]-C[1][2] or C[1][1]-C[1][2]!=C[2][1]-C[2][2]:
    print('No')
    exit()
print('Yes')


Measured memory_bytes: 3064
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include<math.h>
using namespace std;
 int main(){
   int n; cin >> n;
   string w[n]; int res=0;
   for(int i=0;i<n;i++) cin >> w[i];
   
   for(int i=1;i<n;i++){
     if(w[i].substr(0,1) != w[i-1].substr(w[i-1].size()-1,1)) res++;
     for(int j=0;j<i;j++){
       if(w[i]==w[j]) res++;
     }
   }
   if(res==0) cout << "Yes" <<endl;
   else cout << "No" <<endl;
 }
     

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,n) for(ll i=0;i<n;i++)
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ll a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <queue>
#include <map>
using namespace std;
int main(){
  int x,y;
  bool f;
  while(cin >>x>>y, x|y){
    int field[30][30][2] = {0};
    for(int i=0; i<y-1; i++){
      for(int k=0; k<x-1; k++){
	cin >>f;
	if(f){
	  field[k][i][1]|=1<<2;
	  field[k+1][i][1]|=1<<4;
	}
      }
      for(int k=0; k<x; k++){
	cin >>f;
	if(f){
	  field[k][i][1]|=1<<3;
	  field[k][i+1][1]|=1<<1;
	}
      }
    }
    for(int i=0; i<x-1; i++){
      cin >>f;
      if(f){
	field[i][y-1][1]|=1<<2;
	field[i+1][y-1][1]|=1<<4;
      }
    }
    field[0][0][0] = 1;
    queue<pair<int ,int> > q;
    q.push(make_pair(0,0));
    while(!q.empty()){
      int px = q.front().first, py = q.front().second, now = field[px][py][0];
      if(!(field[px][py][1] & 1<<1) && py>0){if(!field[px][py-1][0]){field[px][py-1][0] = now+1;q.push(make_pair(px,py-1));}}
      if(!(field[px][py][1] & 1<<2) && px<x-1){if(!field[px+1][py][0]){field[px+1][py][0] = now+1;q.push(make_pair(px+1,py));}}
      if(!(field[px][py][1] & 1<<3) && py<y-1){if(!field[px][py+1][0]){field[px][py+1][0] = now+1;q.push(make_pair(px,py+1));}}
      if(!(field[px][py][1] & 1<<4) && px>0){if(!field[px-1][py][0]){field[px-1][py][0] = now+1;q.push(make_pair(px-1,py));}}
      q.pop();
    }
    cout <<field[x-1][y-1][0]<<endl;
  }
  return 0;
}

Measured memory_bytes: 916
import java.io.*;
import java.util.*;

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] h = new int[N];
		int maxH = 0;
		for (int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
			maxH = Math.max(maxH, h[i]);
		}
		SegTree st = new SegTree(maxH + 1);
		long answer = 0;
		for (int i = 0; i < N; i++) {
			long a = sc.nextLong();

			long v = st.query(1, h[i]) + a;
			answer = Math.max(answer, v);
			st.update(h[i], h[i] + 1, v);
		}

		System.out.println(answer);
	}

	static class SegTree {

		private static final long MIN = 0;
		private final int n;
		private long[] data;
		private long[] x;

		SegTree(int n) {
			int t = 1;
			while (t < n) t <<= 1;
			this.n = t;
			this.data = new long[t * 2 - 1];
			this.x = new long[t * 2 - 1];
		}

		// [a, b) max
		public long query(int a, int b) {
			return query(a, b, 0, 0, n);
		}

		private long query(int a, int b, int k, int l, int r) {
			if (l >= b || a >= r) return MIN;
			if (a <= l && r <= b) return data[k];
			long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return Math.max(vl, vr) + x[k];
		}

		public void update(int l, int r, long v) {
			update(l, r, v, 0, 0, n);
		}

		private void update(int a, int b, long v, int k, int l, int r) {
			if (b <= l || r <= a) return;
			if (a <= l && r <= b) {
				data[k] += v;
				x[k] += v;
				return;
			}

			update(a, b, v, k * 2 + 1, l, (l + r) / 2);
			update(a, b, v, k * 2 + 2, (l + r) / 2, r);
			data[k] = Math.max(data[k * 2 + 1], data[k * 2 + 2]) + x[k];
		}
	}
}


Measured memory_bytes: 122632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
 
#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
 
using namespace std;

bool inserted[200010];

signed main() {
	int N, x;
	cin >> N >> x;

	if (x == 1 || x == 2 * N - 1) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;

	deque<int> deq;

	deq.push_back(x);
	deq.push_back(x - 1);
	deq.push_front(x + 1);

	inserted[x] = true;
	inserted[x - 1] = true;
	inserted[x + 1] = true;

	if (N > 2) {
		if (x == 2) {
			deq.push_back(4);
			inserted[4] = true;
		} else {
			deq.push_front(x - 2);
			inserted[x - 2] = true;
		}

		bool front = true;
		REP(i, 1, 2 * N - 1) {
			if (inserted[i]) continue;
			if (front)  deq.push_front(i);
			else		deq.push_back(i);
			front = !front;
		}
	}

	for (int num : deq) cout << num << endl;

	return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    for(int i = 0; i < N; i ++){
        cin >> A[i];
    }
    ll sum = 0;
    for(int i = 0; i < N; i ++){
        cin >> B[i];
        A[i] -= B[i];
        sum += A[i];
    }
    if(sum < 0){
        cout << "-1" << endl;
        return 0;
    }

    sort(A.begin(), A.end());
    vector<ll> Acp(A);
    
    /*cout << "after sort" << endl;
    for(int i = 0; i < N; i ++){
        cout << A[i] << " ";
    }
    cout << endl << endl;*/

    int l = 0, r = A.size() - 1, cnt = 0;
    while(0 <= l && l < A.size() && 0 <= r && r < A.size() && A[l] < 0){
        if(-A[l] < A[r]){
            A[r] += A[l];
            A[l] = 0;
            l ++;
        }
        else if(-A[l] == A[r]){
            A[l] = 0;
            A[r] = 0;
            l ++;
            r --;
        }
        else{
            A[l] += A[r];
            A[r] = 0;
            r --;
        }
    }
    for(int i = 0; i < A.size(); i ++){
        if(A[i] != Acp[i])cnt ++;
    }

    /*cout << "before ans" << endl;
    for(int i = 0; i < N; i ++){
        cout << A[i] << " ";
    }
    cout << endl << endl;

    cout << "ans" << endl;*/
    cout << cnt << endl;
	
	return 0;
}

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

int main(){
  int64_t a,b;
  int c,d;
  cin>> a >> b >> c >> d;
  
  //cとdの最大公約数をユークリッドの互除法で求める
  int x=max(c,d),y=min(c,d),z=x%y;
  while (z!=0){
    x=y;
    y=z;
    z=x%y;
  }
  //cとdの最小公倍数を求める
  int64_t lcm=(int64_t)c*d/y;
  
  int64_t ans=(b-a+1) - (b-a+a%c)/c - (b-a+a%d)/d + (b-a+a%lcm)/lcm;
  //全数 - cで割り切れる個数 - dで割り切れる個数 + cd両方で割り切れる個数
  if (a%c==0) ans--; //aの処理を補う、もっといい方法あるかも？
  if (a%d==0) ans--;
  if (a%lcm==0) ans++;
  cout<< ans <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(int i = 0;i < n;++i)
#define rep1(i, n) for(int i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define chmin

    
string s;
string d[]={"dream","dreamer","erase","eraser"};

int re (int stl, int ust){
    int ans = 0;
    if( s.substr(stl, s.length()) == d[ust]) {
        // 答えなら1を返す
        return 1;
    } 
    //if(s.length() < stl + d[ust].length()){
    //    //周転きまできたら返す
    //    return 0;
    //}
    if(s.substr(stl, d[ust].length()) != d[ust]) {
        return 0;
    }
    
    ans += re(stl+d[ust].length(),0);
    ans += re(stl+d[ust].length(),1);
    ans += re(stl+d[ust].length(),2);
    ans += re(stl+d[ust].length(),3);

    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    cin >> s;

    int ans =0;
    ans += re(0,0);
    ans += re(0,1);
    ans += re(0,2);
    ans += re(0,3);

    if(ans>0){
        pri("YES");
    }else{
        pri("NO");
    }

    return 0;
}



Measured memory_bytes: 2128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;

int main(){
    int h,w;
     set<int> rmvi,rmvj;
    char a[100][100];
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<h;i++){
        bool flag=true;
        for(int j=0;j<w;j++){
            if(a[i][j]=='#'){
                flag=false;
                break;
            }
        }
        if(flag)rmvi.insert(i);
    }
    for(int j=0;j<w;j++){
        bool flag=true;
        for(int i=0;i<h;i++){
            if(a[i][j]=='#'){
                flag=false;
                break;
            }
        }
        if(flag)rmvj.insert(j);
    }
    for(int i=0;i<h;i++){
        if(rmvi.find(i)!=rmvi.end())continue;
        for(int j=0;j<w;j++){
            if(rmvj.find(j)!=rmvj.end())continue;
            cout<<a[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <iomanip>
#include <queue>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int id;
  double cost;
  Node() {}
  Node(int i, double c) : id(i), cost(c) {}
  friend bool operator < (const Node& lhs, const Node& rhs) { return lhs.cost > rhs.cost; };
  friend bool operator > (const Node& lhs, const Node& rhs) { return rhs < lhs; };
  friend bool operator <= (const Node& lhs, const Node& rhs) { return !(lhs > rhs); };
  friend bool operator >= (const Node& lhs, const Node& rhs) { return !(lhs < rhs); };
};

struct Point {
  ll x, y, r;
};

double dist[1002][1002];
double cost[1002];
bool visit[1002];

double INF = 1e60;
double distance(const Point& from, const Point& to) {
  return max(0.0, sqrt((from.x-to.x)*(from.x-to.x)+(from.y-to.y)*(from.y-to.y))-from.r-to.r);
}

void dijkstra(int n) {
  int s = 0;
  for (int i = 0; i < n+2; ++i) {
    cost[i] = INF;
  }
  cost[0] = 0;
  priority_queue<Node> pq;
  pq.push(Node(s, 0));
  while (!pq.empty()) {
    Node from = pq.top(); pq.pop();
    // cerr << from.id << " " << from.cost << endl;
    if (visit[from.id]) continue;
    visit[from.id] = true;
    for (int to = 0; to < n+2; ++to) {
      if (from.id == to || visit[to]) continue;
      double c = cost[from.id]+dist[from.id][to];
      if (c > cost[to]) continue;
      cost[to] = c;
      pq.push(Node(to, c));
    }
  }
}

int main() {
  int xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;
  int n;
  cin >> n;
  vector<Point> lp;
  lp.push_back((Point){xs, ys, 0});
  for (int i = 0; i < n; ++i) {
    int x, y, r;
    cin >> x >> y >> r;
    lp.push_back((Point){x, y, r});
  }
  lp.push_back((Point){xt, yt, 0});
  for (int i = 0; i < n+2; ++i) {
    for (int j = 0; j < n+2; ++j) {
      dist[i][j] = distance(lp[i], lp[j]);
      // cerr << i <<  " " << j << " " << dist[i][j] << endl;
    }
  }
  dijkstra(n);
  cout << setprecision(12) << cost[n+1] << endl;
}


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


bool solve(vector<int>A)
{
    for(int x:A)
    {
        if(x%2==0)
        {
            if(x%3!=0&&x%5!=0)
                return false;
        }
    }
    return true;
}
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int n;
    cin>>n;
    vector<int> A(n);
    for(int i=0;i<n;++i)cin>>A[i];
    if(solve(A))cout<<"APPROVED\n";else cout<<"DENIED\n";
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	s[k - 1] = s[k - 1] + 0x20;
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3 20", "2 80", "9 120", "16 1" ].parse.expand.solve == 191 );
	assert( [ "3 20", "2 80", "9 1", "16 120" ].parse.expand.solve == 192 );
	assert( [ "1 100000000000000", "50000000000000 1" ].parse.expand.solve == 0 );
	assert( [ "15 10000000000", "400000000 1000000000", "800000000 1000000000", "1900000000 1000000000", "2400000000 1000000000", "2900000000 1000000000", "3300000000 1000000000", "3700000000 1000000000", "3800000000 1000000000", "4000000000 1000000000", "4100000000 1000000000", "5200000000 1000000000", "6600000000 1000000000", "8000000000 1000000000", "9300000000 1000000000", "9700000000 1000000000" ].parse.expand.solve == 6500000000 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nc = input.front.split.to!( long[] );
	auto xvs = new long[ 2 ][ nc[ 0 ] ];
	foreach( ref xv; xvs )
	{
		input.popFront;
		xv = input.front.split.to!( long[] );
	}
	return tuple( nc[ 1 ], xvs );
}

auto solve( long c, long[ 2 ][] xvs )
{
	// 時計回りに食べたときのカロリーの最大値を計算
	auto rfs = new long[ 1 + xvs.length ];		// 片道
	auto rbs = new long[ 1 + xvs.length ];		// 往復
	for( auto i = 0L, t = 0L; i < xvs.length; i++ )
	{
		t += xvs[ i ][ 1 ];
		rfs[ i + 1 ] = max( rfs[ i ], t - xvs[ i ][ 0 ] );
		rbs[ i + 1 ] = max( rbs[ i ], t - xvs[ i ][ 0 ] * 2 );
	}
	
	// 反時計回りに食べたときのカロリーの最大値を計算
	auto lfs = new long[ 1 + xvs.length ];		// 片道
	auto lbs = new long[ 1 + xvs.length ];		// 往復
	for( auto i = 0L, t = 0L; i < xvs.length; i++ )
	{
		t += xvs[ $ - 1 - i ][ 1 ];
		lfs[ i + 1 ] = max( lfs[ i ], t - ( c - xvs[ $ - 1 - i ][ 0 ] ) );
		lbs[ i + 1 ] = max( lbs[ i ], t - ( c - xvs[ $ - 1 - i ][ 0 ] ) * 2 );
	}
	
	// 途中まで食べた後に引き返して反対側を食べたときのカロリーの最大値を計算
	auto ans = 0L;
	foreach( rb, lf, lb, rf; lockstep( rbs, lfs.retro, lbs, rfs.retro ) )
	{
		ans = max( ans, rb + lf, lb + rf );
	}
	return ans;
}


Measured memory_bytes: 7932
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n,m,p;
    scanf("%d%d%d", &n, &m, &p);

    vector<vector<pair<int,int> > > g(n);   //to, coin-cost
    int i;
    for(i=0; i<m; i++) {
        int a,b,c;
        scanf("%d%d%d", &a, &b, &c);
        a--; b--;
        g[a].push_back(make_pair(b,c-p));
    }

    vector<ll> val(n,-LINF);

    queue<pair<int,pair<ll,int> > > que;    // vertexid, score, time

    que.push(make_pair(0, make_pair(0,0)));

    ll save=LINF;
    while(!que.empty()) {
        auto tmp=que.front();
        que.pop();

        int curr=tmp.first;
        ll  currval=tmp.second.first;
        int currtime=tmp.second.second;
        if(currval<=val[curr]) continue;

        if(currtime==n*2) {
           // printf("-1\n");
           // return 0;
            //printf("n*2   %lld\n", val[n-1]);
            save=val[n-1];
        }
        if(currtime==n*3) {
            //printf("n*4   %lld\n", val[n-1]);
            if(val[n-1]>save) {
                printf("-1\n");
                return 0;
            }
            else if(val[n-1]==save) {
                printf("%lld\n", MAX(0,val[n-1]));
                return 0;
            }
            assert(false);
            break;
        }

        val[curr]=currval;
        int siz=g[curr].size();
        int i;
        for(i=0; i<siz; i++) {
            int next=g[curr][i].first;
            ll nextval=currval+g[curr][i].second;
            if(nextval<=val[next]) continue;

            que.push( make_pair(next, make_pair(nextval,currtime+1)));
        }
    }
    printf("%lld\n", MAX(0,val[n-1]));

    return 0;
}

Measured memory_bytes: 512
n = int(input())
lis = list(map(int, input().split()))
odd = lis[::2]

odd_dic = {'a':(n+1)//2}
for i in odd:
    odd_dic[i] = odd_dic.get(i,(n+1)//2) - 1

even_dic = {'a':n//2}    
even = lis[1::2]
for i in even:
    even_dic[i] = even_dic.get(i,n//2) - 1

odd_count = sorted(list(odd_dic.keys()), key =lambda x: odd_dic[x])
even_count = sorted(list(even_dic.keys()), key =lambda x: even_dic[x])
if odd_count[0] == even_count[0]:
    if odd_dic.get(odd_count[1]) <= even_dic.get(even_count[1]):
        ko = odd_count[1]
        ke = even_count[0]
    else:
        ko = odd_count[0]
        ke = even_count[1]
else:
    ko = odd_count[0]
    ke = even_count[0]
print(odd_dic[ko] + even_dic[ke])

Measured memory_bytes: 20064
V, E = map(int, input().split())
a = [0 for i in range(E)]
b = [0 for i in range(E)]
m = [[0 for i in range(V)] for i in range(V)]
for i in range(E):
    a[i], b[i]=map(int, input().split())
    m[a[i]-1][b[i]-1]+=1
    m[b[i]-1][a[i]-1]+=1
S=0
for n in range(E):
    m[a[n]-1][b[n]-1]-=1
    m[b[n]-1][a[n]-1]-=1
    U=[[] for i in range(V)]
    for i in range(V):
        for j in range(V):
            if m[i][j]!=0:
                U[i].append(j)
    P=[set() for i in range(E+1)]
    P[0].add(0)
    Q=set()
    R=[False for i in range(V)]
    for i in range(1,E+1):
        for u in P[i-1]:
            for v in U[u]:
                if not(R[v]):
                    R[v]=True
                    P[i].add(v)
                    Q.add(v)
        if len(P[i])==0:
            break
    if len(Q)!=V:
        S+=1
    m[a[n]-1][b[n]-1]+=1
    m[b[n]-1][a[n]-1]+=1
print(S)


Measured memory_bytes: 3192
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	vector<vector<char>> grid(h+2, vector<char>(w+2, '.'));
	for(int i = 1; i <= h; ++i){
		for(int j = 1; j <= w; ++j){
			cin >> grid[i][j];
		}
	}
	for(int i = 1; i <= h; ++i){
		for(int j = 1; j <= w; ++j){
			if(grid[i][j] == '#'){
				cout << "#";
				continue;
			}
			int cnt = 0;
			rep(k,8){
				int ny = i + dy[k];
				int nx = j + dx[k];
				if(grid[ny][nx] == '#') ++cnt;
			}
			cout << cnt;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX_N 50
#define MAX_M 20

vector<pair<int, int>> G[MAX_N];

ll covered[MAX_M];

vector<int> es;
bool visited[MAX_N];

void dfs(int v, int to, int q){
    if(v == to){
        for(auto e : es){
            covered[q] |= 1LL << e;
        }
        return;
    }
    visited[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        int u = G[v][i].first;
        if(!visited[u]){
            es.emplace_back(G[v][i].second);
            dfs(u, to, q);
            es.pop_back();
        }
    }
}

signed main(){
    int n;
    cin >> n;
    REP(i,n - 1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }
    int m;
    cin >> m;
    REP(i,m){
        int u,v;
        cin >> u >> v;
        u--;
        v--;
        dfs(u, v, i);
        memset(visited, false, sizeof(visited));
    }
    ll ans = 0;
    for(int bit = 0; bit < 1 << m; bit++) {
        int cnt = 0;
        ll covereds = 0;
        for(int i = 0; i < m; i++) {
            if (bit & 1 << i){
                cnt++;
                covereds |= covered[i];
            }
        }
        ans += (cnt % 2 == 0 ? 1 : -1) * 1LL << (n - 1 - __builtin_popcountll(covereds));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
from sys import stdin
import sys
N=int(stdin.readline().rstrip())
data=[]
for i in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])
for X in range(0,101):
    for Y in range(0,101):
        for data_ in data:
            H = data_[2] + abs(X-data_[0]) + abs(Y-data_[1])
            flag = True
            for data__ in data:
                if max(H-abs(X-data__[0])-abs(Y-data__[1]),0) != data__[2]:
                    flag = False
            if flag:
                break
        else:
            continue
        break
    else:
        continue
    break
    
print(X,Y,H)

Measured memory_bytes: 51308
import scala.io.StdIn.readLine

object Main {
  val paper = Array.ofDim[Int](10,10)
  def dropTo(x:Int,y:Int) = if(x>=0 && x<10 && y>=0 && y<10) paper(x)(y) += 1

  def drop(x:Int,y:Int,size:Int) = {
    dropTo(x,y)
    dropTo(x+1,y)
    dropTo(x-1,y)
    dropTo(x,y+1)
    dropTo(x,y-1)
    if(size == 2 || size == 3) {
      dropTo(x-1,y-1)
      dropTo(x-1,y+1)
      dropTo(x+1,y-1)
      dropTo(x+1,y+1)
      if(size == 3) {
        dropTo(x+2,y)
        dropTo(x-2,y)
        dropTo(x,y+2)
        dropTo(x,y-2)
      }
    }
  }

  def dropInk():Unit = {
    val r = readLine

    if(r==null)  {
      val x = paper.flatten
      println(x.count(_==0))
      println(x.max)
    }
    else {
      val d = r.split(",").map(_.toInt)
      drop(d(0),d(1),d(2))
      dropInk()
    }
  }

  def main(args:Array[String]) = dropInk()
}

Measured memory_bytes: 43948