akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)

using namespace std;
int a[100][100];
int main(){
  int n, r, k, t;
  scanf("%d", &n);
  rep(i, n) rep(j, n) a[i][j] = 1<<16;
  rep(i, n){
    scanf("%d%d", &r, &k);r--;
    rep(j, k){
      scanf("%d", &t);t--;
      a[r][t] = 1;
    }
  }

  // solve
  rep(i, n) rep(j, n) rep(k, n)
    a[j][k] = min(a[j][k], a[j][i] + a[i][k]);

  int p, s, d, v;
  scanf("%d", &p);
  rep(i, p){
    scanf("%d%d%d", &s, &d, &v);s--;d--;
    if(v - a[s][d] > 0) printf("%d\n", a[s][d] + 1);
    else puts("NA");
  }

  return 0;
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
 #include <math.h>
 #include <iostream>
 #include <iomanip>
 using namespace std;
 
 int main(){
    long long N, K;
    long long H[240000];
    long long ans;
    int i;
   

    cin >> N >> K;

    for (i=0; i<N; i++){
        cin >> H[i];
    }
    
    sort(H, H + N, greater<long long>());

    for (i=K; i<N; i++){
        ans = ans + H[i];
    }   

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


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pii pair<int,int>
#define pill pair<int,long long>
#define ff first
#define ss second
#define ll long long
#define pb push_back
using namespace std;

const int lim=200005;

int n,base=1;

ll t[lim<<2];


ll wyn;
 
ll ask(int a, int b){

	a+=base; b+=base;
	wyn=max(t[a],t[b]);
	
	while((a>>1)!=(b>>1)){
		if(!(a&1)) wyn=max(wyn,t[a+1]);
		if(b&1) wyn=max(wyn,t[b-1]);
		a>>=1; b>>=1;
	}
	return wyn;	 
}

void update(int a, ll val){
	a+=base;
	t[a]=val;
	a>>=1;
	while(a){
		t[a]=max(t[a],val); a>>=1;
	}
}

vector<pill>lis;

int t1[lim];
ll t2[lim];

int x;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	
	for(int i=0;i<n;i++) cin>>t1[i];
	for(int i=0;i<n;i++) cin>>t2[i];
	while(base<lim) base<<=1;

	ll help;
	
	for(int i=0;i<n;i++){
		
		help=ask(0,t1[i]);
		update(t1[i],help+t2[i]);
	}
	
	cout<<ask(0,lim-1);
	return 0;
}

Measured memory_bytes: 6400
// Last Update:2017-11-29 22:27:04
// author:sjy
#include<bits/stdc++.h>
using namespace std;
typedef unsigned  long long LL;
LL w[100005],d[100005];
bool check(LL x,LL n,LL K);
int main(void)
{
    LL N,K;
    while(scanf("%llu %llu",&N,&K)!=EOF)
    {
        for(int i = 0;i < N;i++)
            scanf("%llu %llu",&w[i],&d[i]);
        LL l = 1,r = 1e19;
        LL ask = -1;
        while(l<=r)
        {
            LL mid = (l+r)/2LL;
            if(check(mid,N,K))
                ask = mid,r = mid-1;
            else l = mid + 1;
        }
        printf("%llu\n",ask);
    }
    return 0;
}
bool check(LL x,LL n,LL K)
{  LL sum = 0;
   for(int i = 0;i < n;i++)
   {
     if(x < w[i])
         continue;
     else
     {
         LL c = x-w[i];
         sum += c/d[i] + 1;
     }
     if(sum >= K)
         return true;
   }
   return false;
}


Measured memory_bytes: 1792
from operator import mul
from functools import reduce

mod = 7+10**9
def ncr(n,c,mod):
  x = 1
  y = 1
  for i in range(n-c+1,n+1):
    x = x*i%mod
  for j in range(1,c+1):
    y = y*j%mod
  return (x * pow(y, mod-2, mod)) % mod


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

for i in range(1, K + 1):
	print(ncr(K - 1, i - 1, mod) * ncr(N - K + 1, i, mod) % mod)

Measured memory_bytes: 3944
#include<iostream>
#include<cstdio>
using namespace std;
const int N=505;
int n;
int e[N][N];
void solve(int l,int r,int dep)
{
	if(l==r) return;
	int mid=(l+r)/2;
	for(int i=l;i<=mid;i++)
		for(int j=mid+1;j<=r;j++)
			e[i][j]=e[j][i]=dep;
	solve(l,mid,dep+1);
	solve(mid+1,r,dep+1);
	return;
}
int main()
{
	scanf("%d",&n);
	solve(1,n,1);
	for(int i=1;i<=n-1;i++)
	{
		for(int j=i+1;j<=n;j++)
			printf("%d ",e[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 4712
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
//#include<bits/extc++.h> inavilable in dev-cpp
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define me(i,k) memset(i,k,sizeof(i))
#define fr1(a,n) for(int a=1;a<=(n);a++)
#define frab(i,a,b) for(int i=(a);i<(b);i++)
#define fr0(i,n) for(int i=0;i<(n);i++)
#define trav(a,n) for(auto& a : n)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
const ll modn=1000000007;

int main(){
	ll a,b,ans;
	cin>>a>>b;
	if(a>b)swap(a,b);
	if(a==1){
		if(b==1)ans=1;
		else{
			ans=b-2;
		}
	}
	else ans=(a-2)*(b-2);
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
/*
 * @Author: clorf 
 * @Date: 2020-08-29 17:07:51 
 * @Last Modified by: clorf
 * @Last Modified time: 2020-08-29 17:31:41
 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define INF 1e9
using namespace std;
const int maxn=100010;
const double Pi=acos(-1.0);
template<class T>void read(T &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9') {f|=(ch=='-');ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return;
}
int n,ans,fa[maxn],cnt;
struct city
{
    int x;
    int y;
    int id;
}e[maxn];
struct edge
{
    int x;
    int y;
    int z;
}s[maxn];
bool cmp(edge a,edge b)
{
    return a.z<b.z;
}
inline int dis(int a,int b,int c,int d)
{
    return min(abs(a-c),abs(b-d));
} 
inline bool cmp1(city a,city b)
{
    return a.x<b.x;
}
inline bool cmp2(city a,city b)
{
    return a.y<b.y;
}
int getfa(int x)
{
    if(fa[x]==x)
        return x;
    return fa[x]=getfa(fa[x]);

}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&e[i].x,&e[i].y);
        e[i].id=i;
    }
    for(int i=1;i<=n;i++)
        fa[i]=i;
    sort(e+1,e+n+1,cmp1);
    for(int i=2;i<=n;i++)
        s[++cnt]=(edge){e[i].id,e[i-1].id,dis(e[i].x,e[i].y,e[i-1].x,e[i-1].y)};
    sort(e+1,e+n+1,cmp2);
    for(int i=2;i<=n;i++)
        s[++cnt]=(edge){e[i].id,e[i-1].id,dis(e[i].x,e[i].y,e[i-1].x,e[i-1].y)};
    sort(s+1,s+cnt+1,cmp);
    for(int i=1;i<=cnt;i++)
    {
        int x=getfa(s[i].x);
        int y=getfa(s[i].y);
        if(x!=y)
        {
            fa[x]=y;
            ans+=s[i].z;
        }
    }
    printf("%d",ans);
    return 0;
}

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

int main(){
    int n, w, temp1, temp2;
    cin>>n>>w;
    vector<int> weight, value;
    for(int i=0;i<n;i++){
        cin>>temp1>>temp2;
        weight.push_back(temp1);
        value.push_back(temp2);
    }
    long long dp[n+1][w+1];
    dp[0][0]=0;
    for(int i=0;i<=w;i++){
        dp[0][i]=0;
    }
    for(int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(weight[i-1]>j){
                dp[i][j]=dp[i-1][j];
            }
            else{
                dp[i][j]=max(dp[i-1][j-weight[i-1]]+value[i-1], dp[i-1][j]);
            }
        }
    }
    cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 82352
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
using ll = long long;

template <class T>
void print (T x) {
    cout << x << endl;
}

void solve()
{
    ll a, b, k;
    cin >> a >> b >> k;
    set<ll> ans;

    for (ll i = a; i <= min(b, a+k-1); ++i) {
        ans.insert(i);
    }
    for (ll i = max(a,b-k+1); i <= b; ++i) {
        ans.insert(i);
    }
    for (ll i: ans) {
        print(i);
    }
}

int main()
{
    solve();
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        // 整数の入力
        int N = int.Parse(Console.ReadLine());
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');

        int count = 0;

        var inputInt = new int[N];

        for (int i = 0; i < N; i++)
        {
            inputInt[i] = int.Parse(input[i]);
        }

        bool flg = true;

        while (flg)
        {
            for (int i = 0; i < N; i++)
            {
                if (inputInt[i] % 2 == 1)
                {
                    flg = false;
                    break;
                }
                else
                {
                    inputInt[i] = inputInt[i] / 2;
                }
            }

            if (flg)
            {
                count++;
            }
        }

        //// 文字列の入力
        //string s = Console.ReadLine();
        //出力
        Console.WriteLine(count.ToString());
    }
}


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

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n){        
        h -= a[i];
        if(h <= 0){
            cout << "Yes" << endl; 
            return 0;
        }
    }
    cout << "No" << endl;    
    return 0;
}

Measured memory_bytes: 3788
N=int(input())
A=[int(i) for i in input().split()]
A=sorted(A,reverse=True)
l=0
r=0
t=10**9+7
for i in range(N):
    s=A[i]
    if s==t:
        if l==0:
            l=s
            t=10**9+7
        elif r==0:
            r=s
            t=10**9+7
        continue
    t=A[i]
print(l*r)

Measured memory_bytes: 62704
#include <stdio.h>
#include <math.h>

struct Point {
	double x;         // スタックポインタ(一番上の位置)
	double y;
} ;



void kock(int n, struct Point p1, struct Point p2){

	if (n == 0) return;

	struct Point s,t,u;
    
	// p1, p2 から s, t, u を計算
	s.x = (2*p1.x+p2.x)/3;
	s.y = (2*p1.y+p2.y)/3;
	t.x = (p1.x+2*p2.x)/3;
	t.y = (p1.y+2*p2.y)/3;
	
	u.x = (t.x-s.x)*cos(M_PI/3) - (t.y-s.y)*sin(M_PI/3)+s.x;
	u.y = (t.x-s.x)*sin(M_PI/3) + (t.y-s.y)*cos(M_PI/3)+s.y;


    kock(n-1, p1, s);
	printf("%.8f %.8f\n",s.x,s.y);
    kock(n-1, s, u);
    printf("%.8f %.8f\n",u.x,u.y);
    kock(n-1, u, t);
    printf("%.8f %.8f\n",t.x,t.y);
    kock(n-1, t, p2);

}

int main(void){

	int n;
	struct Point p1,p2;
	
	p1.x=0;
	p1.y=0;
	p2.x=100;
	p2.y=0;
	
	scanf("%d",&n);
	
	printf("%.8f %.8f\n",p1.x,p1.y);
	kock(n,p1,p2);
	printf("%.8f %.8f\n",p2.x,p2.y);

	
	return 0;

}




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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

ll gcd(ll x, ll y) {

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

}

int main()
{
	int N, M;
	cin >> N >> M;
	ll lcm = 1;
	int cnt = 0;
	fx(N) {
		int m;
		cin >> m;
		lcm = m / 2 / gcd(lcm, m / 2) * lcm;
		if (lcm>M) {
			ce(0);
			return 0;
		}
		int i = 0;
		while (m%2==0) {
			i++;
			m /= 2;
		}
		if (x==0) {
			cnt = i;
		}
		else {
			if (cnt!=i) {
				ce(0);
				return 0;
			}
		}
	}

	ce((M/lcm+1)/2)


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;
ll mod = 1e9+7;
ll MOD = 998244353;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int f, b;
    f = b = 0;
    for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] == '(') {
            f++;
        }
        else if (s[i] == ')') {
            if (f > 0) f--;
        }
    }
    for (int i = (int)s.size()-1; i >= 0; i--) {
        if (s[i] == ')') {
            b++;
        }
        else if (s[i] == '(') {
            if (b > 0) b--;
        }
    }
    for (int i = 0; i < b; i++) cout << '(';
    cout << s;
    for (int i = 0; i < f; i++) cout << ')';
    cout << endl;
    return 0;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}
void primeFactors(int n)  
{  
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        cout << 2 << " ";  
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            cout << i << " ";  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        cout << n << " ";  
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
   long long int i,j;
 //long long int b[1000000];
 //set<long long int >s;
       long long int f=0,p=0,z,o=0;
       double pie=3.141592653589793238;
    long long int n,m,l=0,k,c,min1=10000000000000,max2=-100;
   cin>>n;
   p=n;
      
   while(n!=0)
   {
     if(o==0)
       n=0;
       n=n+p;
      o++; 
     if(n>=360)
       n=n%360;
      
   }
   cout<<o;
  
}
 return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[][] a = new int[h][w];
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                a[i][j] = sc.nextInt();
            }
        }
         
        int ans = Integer.MAX_VALUE;
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                int now = 0;
                for(int k = 0; k < h; k++) {
                    for(int l = 0; l < w; l++) {
                        now += Math.min(Math.abs(i - k), Math.abs(j - l)) * a[k][l];
                    }
                }
                ans = Math.min(ans, now);
            }
        }
         
        System.out.println(ans);
    }
}


Measured memory_bytes: 29700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    string s;
    cin >> s;
    if(s == "SUN"){
        cout << 7 << endl;
    }else if(s == "SAT"){
        cout << 1 << endl;
    }else if(s == "FRI"){
        cout << 2 << endl;
    }else if(s == "THU"){
        cout << 3 << endl;
    }else if(s == "WED"){
        cout << 4 << endl;
    }else if(s == "TUE"){
        cout << 5 << endl;
    }else if(s == "MON"){
        cout << 6 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def solve():
    s = read()
    result = think(s)
    write(result)


def read():
    return read_line()


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(s):
    local_s = 'L' + s
    n = len(local_s)
    symbol_right = 'R'
    symbol_left = 'L'
    steps = 10 ** 100

    steps_to_turning_point = [0 for x in range(n)]
    turning_point_from = [[0, 0] for x in range(n)]
    count = [0 for x in range(n)]

    index = 0
    from_x = 1
    to_x = 2
    while True:
        while to_x < n and local_s[from_x] == local_s[to_x]:
            to_x += 1
        # print('debug', from_x, to_x)
        if s[from_x] == symbol_right:
            for i in range(from_x, to_x):
                if ((steps - abs(to_x - i)) % 2 == 0):
                    # print('case 1,', i, to_x, abs(to_x - i))
                    count[to_x] += 1
                else:
                    # print('case 2,', i, to_x - 1, abs(to_x - i))
                    count[to_x - 1] += 1
        else:
            for i in range(from_x, to_x):
                if ((steps - abs(i - index)) % 2 == 0):
                    # print('case 3,', i, index)
                    count[index] += 1
                else:
                    # print('case 4,', i, index + 1)
                    count[index + 1] += 1
        index = to_x - 1
        from_x = to_x
        to_x += 1

        if to_x >= n:
            break

    # print('last,', from_x, to_x, index)
    # should be left symbol
    if from_x < n:
        for i in range(from_x, to_x):
            if ((steps - abs(i - index)) % 2 == 0):
                # print('case 5,', i, index)
                count[index] += 1
            else:
                # print('case 6,', i, index + 1)
                count[index + 1] += 1
    return count[1:]


def find_turning_point(s, what, symbol_left, symbol_right, from_x):
    if what == symbol_left:
        turning_point_from = s.find(symbol_left, from_x)
        return turning_point_from, turning_point_from - 1
    else:
        turning_point_from = s[:from_x].rfind(symbol_right)
        return turning_point_from, turning_point_from + 1


def write(result):
    print(' '.join(list(map(str, result))))


if __name__ == '__main__':
    solve()

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

typedef long long LL;
class RunningMedian {
public:
    priority_queue<int> left;
    priority_queue<int, vector<int>, std::greater<int>> right;
    LL leftSum = 0, rightSum = 0;

    void insert(int x) {
        if(left.empty()) {
            left.push(x);
            leftSum += x;
            return;
        }

        if(left.top() > x) {
            left.push(x);
            leftSum += x;
        } else {
            right.push(x);
            rightSum += x;
        }
        if (left.size()-2 == right.size()) {
            int t = left.top();
            left.pop();
            right.push(t);
            leftSum -= t;
            rightSum += t;
        } else if (left.size() == right.size() - 1) {
            int t = right.top();
            right.pop();
            left.push(t);
            rightSum -= t;
            leftSum += t;
        }
    }
    int median() {
        return left.top();
    }
    LL sum() {
        int m = left.top();
        LL leftAns = m * left.size() - leftSum;
        LL rightAns = m * right.size() - rightSum;
        return leftAns - rightAns;
    }
};

int main() {
    int N;
    LL C = 0;
    RunningMedian rm;
    cin >> N;
    for(int i = 0; i < N; i++) {
        int op, a, b;
        cin >> op;
        if (op == 1) {
            cin >> a >> b;
            C += b;
            rm.insert(a);
        } else {
            int m = rm.median();
            cout << m << " ";
            cout << rm.sum() + C << "\n";
        }
    }
}



Measured memory_bytes: 3452
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}

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

  return gcd(b, a%b);
}

/*
a b k

a b 100
 */
int a,b,k;

int main(){
  cin>>a>>b>>k;

  int d;
  int cnt=0;
  for(d = min(a,b); d>0; d--){
    if(a%d==0 && b%d==0){
      cnt++;
    }

    if(cnt==k) break;
  }

  cout<<d<<endl;
  return 0;
}


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

int main() {
  long n,k;
  cin >> n >> k;
  vector<long> a(n);
  for(long i=0;i<n;i++) cin >> a[i];
  for(long i=k;i<n;i++) {
    if(a[i]>a[i-k]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if  (a + b == c + d) {
    cout << "Balanced" <<endl;
  }
  else if (a + b < c + d) {
    cout << "Right" << endl;
  }
  else {
    cout << "Left" << endl;
  }
}

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

#define pb push_back
#define MAX 1010

using namespace std;

const int mod = 1e9 + 7;

string mat[MAX];
int dp[MAX][MAX];

int add(int a, int b) {

    a += b;
    if(a >= mod)
        a -= mod;
    return a;
}

int main() {

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

    int h, w;
    cin >> h >> w;

    for(int i = 0; i < h; i++)
        cin >> mat[i];
    
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(!i && !j) {
                dp[i][j] = 1;
                continue;
            }
            if(mat[i][j] == '#') {
                dp[i][j] = 0;
                continue;
            }

            dp[i][j] = add(i ? dp[i - 1][j] : 0, j ? dp[i][j - 1] : 0);
        }
    }

    cout << dp[h - 1][w - 1] << endl;
    return 0;
}


Measured memory_bytes: 8656
#include <stdio.h>
int main(void)
{
    int m,f,r;
    
    while(1)
    {
        scanf("%d %d %d",&m,&f,&r);
        if(m==-1 && f==-1 && r==-1) break;
        else
        {
            if(m==-1 || f==-1) printf("F\n");
            else if(m+f>=80) printf("A\n");
            else if(m+f>=65 && m+f<80) printf("B\n");
            else if(m+f>=50 && m+f<65) printf("C\n");
            else if(m+f>=30 && m+f<50)
            {
                if(r>=50) printf("C\n");
                else printf("D\n");
            }
            else if(m+f<30) printf("F\n");
        }
    }
    
    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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; }

int N;
long long a[100010][3];
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

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

int main(){
    
    string s; cin >> s;
    int ans = 0;
    set<char> S;
    for(int i = 0; i < (int)s.size(); i++){
        if(S.find(s[i]) == S.end()){
            if(s[i] == 'S') ans += 2;
            else if(s[i] == 'E') ans += 1;
            else if(s[i] == 'N') ans -= 2;
            else ans -= 1;

            S.insert(s[i]);
        }
    }

    if(ans) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int ans = 0;
  rep(i, 4){
    char s;
    cin >> s;
    if(s == '+'){
      ans++;
    }else ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;
    vint x(N);
    REP(i,N) cin>>x[i];

    int ans=1e18;
    REP(l,N-K+1){
        int r=l+K-1;
        int dist;
        if(x[r]<=0) dist=-x[l];
        else if(x[l]>=0) dist=x[r];
        else{
            dist=(x[r]-x[l])+min(-x[l],x[r]);
        }
        ans=min(ans,dist);
    }
    cout<<ans<<endl;
 
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/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;}
/*約数列挙*/vector<int> getDivisor(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(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b,c,d; cin >> a >> b >> c >> d;
    cout << c-(d-b) <<  " " << d+(c-a) << " " << a-(d-b) << " " << b+(c-a) << endl;

    return 0;
}



Measured memory_bytes: 256
from collections import deque

h,w=map(int,input().split(' '))
maze=[0]*h
kuro=0
for y in range(h):
    line=input()
    kuro+=line.count('#')
    maze[y]=line
count=[[-1]*w for _ in range(h)]
count[0][0]=1

q=deque([[0,0]])
def BFS():
    while q:
        y,x=q.popleft()
        if (y,x)==(h-1,w-1):
            return h*w-kuro-count[h-1][w-1]
        for dy,dx in [[0,1],[1,0],[-1,0],[0,-1]]:
            ny,nx=y+dy,x+dx
            if not (0<=ny<h and 0<=nx<w):
                continue
            if maze[ny][nx]=='.' and count[ny][nx]==-1:
                q.append([ny,nx])
                count[ny][nx]=count[y][x]+1
    return -1

print(BFS())

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

using namespace std;

int main(void){

    int n;
    cin >> n;
    
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    
    int index = 0;
    for(int i=0; i<100000; i++) {
        if(index == 1) {
            cout << i << endl;
            return 0;
        }
        index = a[index]-1;
    }

    cout << -1 << endl;

    return 0;
    
}


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

int main() {
	int l, r, d;
	cin >> l >> r >>d;
	int ans = 0;
	for (int i = l; i <= r;i++){
		if (i%d==0) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
/*
 *Author : zsenshi
 DP 
 */
#include <bits/stdc++.h> //Only for gcc compilers
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define dg(x) cout << #x << ":"<<x<<endl
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl
#define rep(i,begin,end) for(__typeof(end) i = (begin)-((begin) > (end)); i != (end) - ((begin) > (end)); i += 1-2*((begin) > (end)))
using namespace std;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vector<pii>> vvpi;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }
  for(int i = 0; i < n-1; i++){
    cin >> c[i];
  }
  int sum = 0;
  for(int i = 0; i < n; i++){
    sum += b[a[i]-1];
    if(i >0){
      if(a[i] == a[i-1]+1){
        sum += c[a[i-1]-1];
      }
    } 
  }
  cout << sum << "\n";
}


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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll n,k,s; cin>>n>>k>>s;
  ll b = s+1;
  if (s >= 1000000000) b = 1;

  vector<ll> ans(n);
  for (int i=0; i<n; i++) {
    if (i > 0) cout << " ";
    if (i < k) cout << s;
    else cout << b;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 4040
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;


public class Main {
	
	public static void main(String[] args) throws IOException {
		Main m = new Main();
		m.input();
		m.solve();
		m.output();
	}
	/*
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	/*/
	InputUtil in = new InputUtil();
	PrintWriter out = new PrintWriter(System.out);
	//*/
	int ABCD = 0;
	String ans = "";
	
	public void input() throws IOException {
		/*
		S = br.readLine();
		/*/
		ABCD = in.nextInt();
		//*/
	}

	public void solve() throws IOException {
		int A = ABCD/1000;
		int B = (ABCD/100)%10;
		int C = (ABCD/10)%10;
		int D = ABCD%10;
		
		for(int i=0; i<2; i++){
			for(int j=0; j<2; j++){
				for(int k=0; k<2; k++){
					if(solveSub(A,i==0,B,j==0,C,k==0,D)==7){
						ans = A 
								+ ((i==0)?"+":"-") + B
								+ ((j==0)?"+":"-") + C
								+ ((k==0)?"+":"-") + D
								+ "=7";
						break;
					}
				}
			}
		}
		
		
	}
	public int solveSub(int a, boolean opIsPlus1, int b, boolean opIsPlus2, int c, boolean opIsPlus3, int d) {
		int ret = a;
		ret = (opIsPlus1) ? (ret+b) : (ret-b);
		ret = (opIsPlus2) ? (ret+c) : (ret-c);
		ret = (opIsPlus3) ? (ret+d) : (ret-d);
		return ret;
	}
	
	public void output() {
		out.println(ans);
		out.flush();
	}
}

//*
class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 100000;
	
	//Fields
	protected InputStream in;
	private byte[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private DataInputStream dis = null;
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {dis = new DataInputStream(this.in = in);}
	protected void initBuf(int bufsiz) {buf = new byte[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && dis.available()>0) {
			if(max>0) Arrays.fill(buf,0,max,(byte)0);
			max = dis.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(byte b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(byte b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		byte c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}
}
//*/


Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  string a, b;
  int ad, bd;
  cin >> a >> b;
  if (a.length() > b.length()) {
    cout << "GREATER" << endl;
    return 0;
  } else if (a.length() < b.length()) {
    cout << "LESS" << endl;
    return 0;
  }
  REP(i, a.length()) {
    ad = a[i] - '0';
    bd = b[i] - '0';
    if (ad == bd) continue;
    if (ad > bd) {
      cout << "GREATER" << endl;
      return 0;
    } else {
      cout << "LESS" << endl;
      return 0;
    }
  }
  cout << "EQUAL" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e5 + 5;
const int BITS = 61;
const int MOD = 1e9 + 7;


int suffix[N][BITS], a[N];

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

  int n;
  cin >> n;
   
  for(int i = 1; i <= n; i++)
     cin >> a[i];

  for(int i = n; i > 0; i--){
     for(int j = 0; j < BITS; j++){
         suffix[i][j] += suffix[i + 1][j];
         suffix[i][j] += (a[i] >> j) & 1;
     }
  }
  
  int ans = 0;
  for(int i = 1; i <= n; i++){
     for(int j = 0; j < BITS; j++){
         if((a[i] >> j) & 1){
              int temp = (1LL << j) % MOD * (n - i - suffix[i + 1][j]) % MOD;
              temp %= MOD;
              ans += temp;
              ans %= MOD;
         } else{
              int temp = (1LL << j) % MOD * suffix[i + 1][j] % MOD;
              temp %= MOD;
              ans += temp;
              ans %= MOD;
         }
     }
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 148916
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < n; i++) {
        if (a[i]%2 == 0) {
            if (a[i]%3 == 0 || a[i]%5 == 0) {
            } else {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
/* ex6_2
    fmuacshai */
#include <stdio.h>
#include <string.h>

#define SIZE 100

int main(void){
    //英単語を入力する配列wordを定義
    char word[SIZE];
    //間の文字数lengthを定義
    int length;
    //英単語を入力
    scanf("%s",word);
    //lengthの計算
    length=strlen(word)-2;
    //1文字目を出力
    putchar(word[0]);
    //間の文字数を出力
    printf("%d",length);
    //最後の文字を出力
    putchar(word[length+1]);
    //改行して終わる
    putchar('\n');
    return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

def chmax(a, b):
    if a < b:
        a = b
        return b
    return a

N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
dp = [list([0] * 3) for _ in range(N + 1)]
for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = chmax(dp[i + 1][k], dp[i][j] + a[i][k])

ans = 0
for i in range(3):
    ans = max(ans, dp[N][i])

print(ans)

Measured memory_bytes: 53444
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main() {
  int N, D;
  cin >> D >> N;
  
  if(N == 100){
    N += 1;
  }

  if(D == 2 && N == 101){
    cout << 1010000 << endl;
  }else{
  	cout << pow(100, D) * N << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> sunuke(n, 0);
    int d;
    for(int turn=0;turn<k;turn++){
        cin >> d;
        int a;
        for(int i=0;i<d;i++){
            cin >> a;
            sunuke.at(a-1)++;
        }
    }
    int count = 0;
    for(int i=0;i<n;i++){
        if(sunuke.at(i) == 0){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n; string s;

void solve()
{
    cin >> n >> s;
    int ans=0, cnt=1;
    for (int i=1; i<n; i++) {
        if (s[i]==s[i-1]) cnt++;
        else {
            ans++;
            cnt=1;
        }
    }
    ans++; nout(ans);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3744
import sys
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
a, b, c, d = map(int, read().split())
 
def main(a, b, c, d):
    while True:
        if c <= b:
            return 'Yes'
        c -= b
        if a <= d:
            return 'No'
        a -= d
 
print(main(a, b, c, d))


Measured memory_bytes: 9076
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a==1)
    a=14;
  if(b==1)
    b=14;
  if(a>b)
    cout<<"Alice";
  if(a==b)
    cout<<"Draw";
  if(a<b)
    cout<<"Bob";
  system ("pause"); 
  return 0;
} 

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  vector<ll> ans(n, 0);
  FOR(i, 1, n + 1) FOR(j, i + 1, n + 1) {
    ll d = j - i;
    if (i >= y || j <= x) {
      ans[d]++;
      continue;
    }
    d = min(d, abs(x - i) + 1 + abs(y - j));
    ans[d]++;
  }
  FOR(i, 1, n) { cout << ans[i] << endl; }
}

Measured memory_bytes: 256
import numpy as np
from math import factorial
MOD = 10 ** 9 + 7

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv



U = 10**6
fact, fact_inv = make_fact(U,MOD)

X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
    print(0)
    exit()
time = (X+Y) // 3
diff = X - Y
if abs(diff) > time:
    print(0)
    exit()
x_time = (time+diff) // 2

answer = fact[time] * fact_inv[x_time] % MOD * fact_inv[time-x_time] % MOD
print(answer)




Measured memory_bytes: 53548
#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 );
  int n,m; cin>>n>>m;
  vi K(m); vector<map<int,int>> S(m); vi P(m);
  rep(i,m){
    cin>>K[i];
    rep(j, K[i]){
      int s; cin>>s; s--;
      S[i][s]=1;
    }
  }
  rep(i,m) cin>>P[i];
  
  int ans=0;
  for(int bit=0; bit<(1<<n); bit++){
    vi cnt(m);
    rep(i,n){
      if(bit&(1<<i)) rep(j,m){
        if(S[j][i]) cnt[j]++;
      }
    }
    bool ok=true;
    rep(i,m){
      if(cnt[i]%2!=P[i]) ok=false;
    }
    if(ok) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
 * 0300.cc: Floppy Cube
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

//    21 20 19
// 16  1  2  3 15 28 29 30
// 17  4  5  6 14 25 26 27
// 18  7  8  9 13 22 23 24
//    10 11 12

/* constant */

const int N = 30;
const int MAX_K = 8;
const int INF = 1 << 30;

const int rots[4][2][5] = {
  {{ 1,  2,  3, 15, 19}, {28, 29, 30, 16, 21}},
  {{ 3,  6,  9, 12, 13}, {22, 25, 28, 19, 15}},
  {{ 7,  8,  9, 18, 10}, {22, 23, 24, 13, 12}},
  {{ 1,  4,  7, 21, 16}, {24, 27, 30, 10, 18}}
};

/* typedef */

/* global variables */

int cs[N];

/* subroutines */

inline bool won(int cs[]) {
  return
    (cs[0] == cs[4] && cs[1] == cs[4] && cs[2] == cs[4] &&
     cs[3] == cs[4] && cs[5] == cs[4] &&
     cs[6] == cs[4] && cs[7] == cs[4] && cs[8] == cs[4] &&
     cs[9] == cs[10] && cs[11] == cs[10] &&
     cs[12] == cs[13] && cs[14] == cs[13] &&
     cs[15] == cs[16] && cs[17] == cs[16] &&
     cs[18] == cs[19] && cs[20] == cs[19] &&
     cs[21] == cs[25] && cs[22] == cs[25] && cs[23] == cs[25] && 
     cs[24] == cs[25] && cs[26] == cs[25] &&
     cs[27] == cs[25] && cs[28] == cs[25] && cs[29] == cs[25]);
}

inline void rot(int i, int cs[]) {
  for (int j = 0; j < 5; j++)
    swap(cs[rots[i][0][j] - 1], cs[rots[i][1][j] - 1]);
}

int rec(int k, int cs[]) {
  if (won(cs)) return k;
  if (k >= MAX_K) return INF;

  int minr = INF;
  for (int i = 0; i < 4; i++) {
    rot(i, cs);
    int r = rec(k + 1, cs);
    if (minr > r) minr = r;
    rot(i, cs);
  }

  return minr;
}

/* main */

int main() {
  int n;
  cin >> n;
  while (n--) {
    for (int i = 0; i < N; i++) cin >> cs[i];
    int ans = rec(0, cs);
    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 1144
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,y;
	cin>>n>>y;
	REP(i,n+1) {
		REP(j,n+1) {
			if(i+j>n) continue;
			if(y-(i*10000+j*5000)>=0&&(y-(i*10000+j*5000))/1000==n-i-j) {
				cout<<i<<" "<<j<<" "<<n-i-j<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)


int main()
{
	cin.tie( 0 ); ios::sync_with_stdio( false );
	ll n;cin>>n;
	vector<ll> v( n, 0 );
	REP(i,n)cin>>v[i];

	ll a0 = 0;
	REP(i,n) a0 += v[i] * (i%2==0?1:-1);
	REP(i,n)
	{
		if(i==0)cout<<a0;
		else
		{
			a0 = v[i-1]*2-a0;
			cout<<" "<<a0;
		}
	}

	return 0;
}

Measured memory_bytes: 2176