akhauriyash/Code-Regression huggingface dataset:
"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
    for (var line of lines) {
	let l = line.trim().split(' ');
	let a = parseInt(l[0]);
	let op= l[1];
	let b = parseInt(l[2]);

	//console.log('a: ', a,'op: ', op, 'b: ', b);
	if (op==='?') {
	    break;
	}
	console.log(aux(a, op, b));
    }
});

function aux(a,op,b)
{
    var s;

    if (op==='+') {
	s = a + b;
    } else if (op==='-') {
	s = a - b;
    } else if (op==='*') {
	s = a * b;
    } else if (op==='/') {
	s = Math.floor(a/b);
    }

    return(s);
}


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

class UnionFind{
    public:
        //親の番号を格納、親だった場合は-(その集合のサイズ)
        vector<int> Parent;

        //親初期化（N個の要素すべてに-1を代入）
        UnionFind(int N){
            Parent = vector<int>(N, -1);
        }

        //Aがどのグループに属しているか調べる
        int root(int A){
            if (Parent[A] < 0) return A;
            return Parent[A] = root(Parent[A]);
        }

        //自分のいるグループの頂点数を調べる
        int size(int A){
            return -Parent[root(A)];
        }

        //AとBをくっ付ける
        bool connect(int A, int B){
            A = root(A);
            B = root(B);
            //すでにくっついているからくっつけない
            if (A == B) return false;

            if (size(A) < size(B)) swap(A,B);
            
            Parent[A] += Parent[B];
            Parent[B] = A;

            return true;
        }
};

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	vector<long long> ans(M);
	ans[M - 1] = (long long)N * (N - 1) / 2;

	UnionFind Uni(N);

    for(int i = M-1; i >= 1; i--){

        ans[i-1] = ans[i];

        //繋がってないのがつながったとき
        if (Uni.root(A[i]) != Uni.root(B[i])){
            ans[i-1] -=(long long)Uni.size(A[i]) * Uni.size(B[i]);
            Uni.connect(A[i], B[i]);
        }
    }

    for (int i = 0; i < M; i++ ){
        cout << ans[i] << endl;
    }

}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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 const INF = 1001001001;


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

int N,K;
cin >> N >> K;

int R = N-K;
K--;
cout << (R+K-1)/K + 1 << endl;
return 0;
}

Measured memory_bytes: 256
m,k=map(int,input().split())
if 2**m<=k or m==1 and k!=0:
    print(-1)
elif m==1 and k==0:
    print(0,0,1,1)
else:
    ans=[k]
    for i in range(2**m):
        if i!=k:
            ans.append(i)
    ans.append(k)
    for i in range(2**m):
        i=2**m-1-i
        if i!=k:
            ans.append(i)
    print(*ans)

Measured memory_bytes: 20016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    ll N, W; cin >> N >> W;
    vector<ll> w, v;
    REP(i, N){
        ll w_i, v_i;
        cin >> w_i >> v_i;
        w.PB(w_i);
        v.PB(v_i);
    }
    ll maxv = 100003;
    vector<vector<ll>> dp(N, vector<ll>(maxv, INF));
    REP(i, maxv){
        if (i == 0){
            dp.at(0).at(i) = 0;
            continue;
        }
        if (i <= v.at(0)){
            dp.at(0).at(i) = w.at(0);
        }
        else{
            dp.at(0).at(i) = INF;
        }
    }
    REP(i, N){
        if (i == 0){continue;}
        REP(j, maxv){
            if (j <= v.at(i)){
                dp[i][j] = min(dp[i-1][j], w.at(i));
            }
            else{
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v.at(i)] + w.at(i));
            }
            // cout << dp[i][j] << endl;
        }
    }
    ll ans;
    REP(i, maxv){
        if (dp[N-1][i] <= W){
            ans = i;
        }
    }
    cout << ans << endl;
}


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

#define pb push_back
#define MAX 100005
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
int n, a[100005], b[100005], c[100005], dp[100005][3];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i = 0; i<n; ++i){
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[n-1][0] = a[n-1];
    dp[n-1][1] = b[n-1];
    dp[n-1][2] = c[n-1];
    for(int i = n-2; i>=0; i--){
        dp[i][0] = max(dp[i+1][1],dp[i+1][2])+a[i];
        dp[i][1] = max(dp[i+1][0],dp[i+1][2])+b[i];
        dp[i][2] = max(dp[i+1][0],dp[i+1][1])+c[i];
    }
    cout<<max(dp[0][0],max(dp[0][1],dp[0][2]))<<"\n";
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
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; }

bool isOK(string s){
    bool can = false;
    string srev = s;
    reverse(srev.begin(), srev.end());
    if(s == srev) can = true;
    return can;
}

signed main(){
    string s;
    cin >> s;
    int len = s.size();
    string s1, s2;
    rep(i, (len-2)/2+1){
        s1 += s[i];
    }
    for(int i = len/2 + 1; i < len; i++){
        s2 += s[i];
    }
    /* cout << s1 << " " << s << " " << s2 << endl; */
    if(isOK(s) && isOK(s1) && isOK(s2)) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

using namespace std;
using ll = long long;

int main() {
    ll x, k, d; cin >> x >> k >> d;
    ll need = 0;
    
    ll cnt = x / d;
    if (cnt < 0) cnt = -cnt;
    if (cnt > k) cnt = k;
    
    if (x < 0) {
        x += cnt * d;
    } else {
        x -= cnt * d;
    }
    
    
    if ((k - cnt) & 1) {
        if (x > 0) {
            x -= d;
        } else {
            x += d;
        }
    }
    
    cout << abs(x);
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define sgn(v) (abs((v))<eps?0:((v)<0?-1:1))
#define sqr(v) ((v)*(v))
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define debug 0
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<double,int> PDI;
typedef pair<double,double> PDD;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<LL,int> PLI;
typedef pair<LL,LL> PLL;
const double eps=1e-8;
const double pi=acos(-1);
const int maxn=1200;
const int maxe=2e6;
struct Edge
{
	int from,to,cap,next;
	Edge(){}
	Edge(int u,int v,int c,int n)
	{
		from=u;to=v;cap=c;next=n;
	}
}edge[maxe];
int ne,head[maxn];
int n,m,dis[maxn];
void add(int u,int v,int c)
{
	edge[ne]=Edge(u,v,c,head[u]);
	head[u]=ne++;
	edge[ne]=Edge(v,u,0,head[v]);
	head[v]=ne++;
}
bool bfs(int st,int tp)
{
	queue<int> q;
	int now,i,u,v;
	memset(dis,-1,sizeof(dis));
	dis[st]=0;
	q.push(st);
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		for(i=head[u];i!=-1;i=edge[i].next)
		{
			v=edge[i].to;
			if(dis[v]==-1&&edge[i].cap>0)
			{
				dis[v]=dis[u]+1;
				q.push(v);
			}
		}
	}
	return (dis[tp]!=-1);
}
int dfs(int a,int b,int tp)
{
	int res=0,v,i;
	if(a==tp)return b;
	for(i=head[a];i!=-1&&res<b;i=edge[i].next)
	{
		v=edge[i].to;
		if(edge[i].cap>0&&dis[v]==dis[a]+1)
		{
			int x=min(edge[i].cap,b-res);
			x=dfs(v,x,tp);
			res+=x;
			edge[i].cap-=x;
			edge[i^1].cap+=x;
		}
	}
	if(!res)dis[a]=-2;
	return res;
}
int MAX=1000;
int dinic(int st,int tp)
{
	int total=0,t;
	while(bfs(st,tp))
	{
		while(t=dfs(st,MAX,tp))
			total+=t;
	}
	return total;
}
int main()
{
	int n,m,k,b,i,j,flw;
	memset(head,-1,sizeof(head));
	ne=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
	{
		add(0,i,1);
		scanf("%d",&k);
		for(j=0;j<k;++j)
		{
			scanf("%d",&b);
			add(i,n+b,1);
		}
	}
	for(i=1;i<=m;++i)
		add(n+i,n+m+1,1);
	flw=dinic(0,n+m+1);
	//cout <<flw<<endl;
	if(flw==m)puts("Bob");
	else puts("Alice");
	return 0;
}

Measured memory_bytes: 9380
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

ll mpow(int base, int n) {
    ll b = base, ret = 1; 
    while(n) {
        if (n&1) ret *= b;
        n = n >> 1;
        b *= b; 
    }
    return ret;
}

int main() {
    int n; cin >> n;
    vector<int> as(n);
    rep(i, n) cin >> as[i]; 
    sort(all(as), greater<int>());
    vector<ll> buf;
    int idx = 0;
    while(buf.size() < 2 && idx < n-1) {
        if (as[idx] == as[idx+1]) {
            ++idx;
            buf.push_back(as[idx]);
        }
        ++idx;    
    }
    ll ret = buf.size() < 2 ? 0 : buf[0] * buf[1];
    cout << ret << endl; 
    return 0;
}

Measured memory_bytes: 640
N = int(input())
arr = list(map(int, input().split()))
arr2 = [0]*(max(arr)+1)
if max(arr) < 4:
    print(len(arr))
    exit()
for i in range(N):
    arr2[arr[i]] += 1
ans = arr2[1] + arr2[2] + arr2[3]
tmp = ans
for i in range(4,len(arr2)):
    tmp = tmp - arr2[i-3] + arr2[i]
    if ans < tmp:
        ans = tmp
print(ans)

Measured memory_bytes: 14092
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<double, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

int n;
ll a[333333],memo[2][333333];
bool done[2][333333];

int main(void){
	int m,i,j,k,t;
	ll ans=0ll;
	cin >> n;
	m = (1<<n);
	fill(done[0],done[2],false);
	for(i=0; i<m; ++i){
		cin >> a[i];
		memo[0][i] = a[i];
		memo[1][i] = 0ll;
	}
	for(i=0; i<n; ++i){
		for(j=0; j<m; ++j){
			if(j&(1<<i)){
				t = (j^(1<<i));
				for(k=0; k<2; ++k){
					if(memo[0][j] < memo[k][t]){
						memo[1][j] = memo[0][j];
						memo[0][j] = memo[k][t];
					}else if(memo[1][j] < memo[k][t]){
						memo[1][j] = memo[k][t];
					}
				}
			}
		}
	}
	for(i=1; i<m; ++i){
		ans = max(ans,memo[0][i]+memo[1][i]);
		cout << ans << endl;
	}
	return 0;
}

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


int main(){
	int a,b,c,d,e,f,g,h;
	int n;
	while(cin>>n,n){
		for(;n;n--){
			cin>>a>>b>>c>>d>>e>>f>>g>>h;
			
			
			cout<<a*e-b*f-c*g-d*h<<" ";
			cout<<a*f+b*e+c*h-d*g<<" ";
			cout<<a*g-b*h+c*e+d*f<<" ";
			cout<<a*h+b*g-c*f+d*e<<"\n";
			
			
		}
	}
	
	return 0;
}


Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main() {
	int n , l;
	cin >> n >> l;
	vector<int>v(n);
	rep(i, n){
		v[i] = (l + i);
	}
	int sum = 0;

	rep(i, n){
		sum += v[i];
	}
	int ans = 1e8;
	rep(i, n){
		int t = sum - v[i];
		if(abs(t-sum) < abs(ans - sum)){
			ans = t;
		}
	}
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
S = list(input())
T = list(input())
ans = {}
for c_s, c_t in zip(S, T):
    if c_s not in ans.keys() and c_t not in ans.values():
        ans[c_s] = c_t
    else:
        try:
            if ans[c_s] == c_t:
                continue
            else:
                print("No")
                break
        except KeyError:
            print("No")
            break
else:
    print("Yes")


Measured memory_bytes: 6704
use proconio::input;

fn gcd(a: usize, b: usize) -> usize {
    use std::cmp::{max, min};
    let mi = min(a,b);
    let ma = max(a,b);

    let r = ma % mi;
    if r == 0 {
        return mi;
    }

    gcd(mi, r)
}

fn reduce(mut a: isize, mut b: isize) -> (isize, isize) {
    if a == 0 {
        return (0, 1);
    }

    if b == 0 {
        return (1, 0);
    }

    if b < 0 {
        b = -b;
        a = -a;
    }

    let g = gcd(a.abs() as usize, b.abs() as usize) as isize;
    (a/g, b/g)
}

// (2,1) -> (-1, 2) , (-2, 1) -> (1, 2)
fn inv(ab: (isize, isize)) -> (isize, isize) {
    if ab == (1,0) {
        return (0,1);
    }

    if ab == (0,1) {
        return (1,0);
    }

    let (a,b) = ab;
    if a < 0 {
        (b, -a)
    } else {
        (-b, a)
    }
}

static MOD: isize = 1000000007;

fn main() {
    input! {
        n: usize,
        abs: [(isize, isize); n]
    };

    let mut abzero = 0;
    let mut hash = std::collections::HashMap::<(isize, isize), usize>::new();
    for (a,b) in abs {
        if a==0 && b==0 {
            abzero += 1;
            continue;
        }

        let rab = reduce(a,b);
        if let Some(v) = hash.get_mut(&rab) {
            *v = *v+1;
        } else {
            hash.insert(rab, 1);
        }
    }

    let mut m = 1;
    while let Some((&rab, &c)) = hash.iter().next() {
        hash.remove(&rab);

        let mut s = 1;
        for _ in 0..c {
            s *= 2;
            s %= MOD;
        }

        let rab_inv = inv(rab);

        if let Some(d) = hash.remove(&rab_inv) {
            s += (MOD - 1);
            s %= MOD;

            let mut t = 1;
            for _ in 0..d {
                t *= 2;
                t %= MOD;
            }

            t += (MOD-1);
            t %= MOD;

            m *= (s+t+1) % MOD;
            m %= MOD;
        } else {
            m *= s;
            m %= MOD;
        }
    }

    print!("{}", (abzero as isize + m + (MOD - 1)) % MOD);
/*
    A1 A2 A3 2^3
    B1 B2    2^2

    (2^3-1) + (2^2-1) + 1
*/

/*
    A1 A2 A3 2^3
*/
}


Measured memory_bytes: 22412
using System;
using static System.Console;

namespace dp
{
    class Program
    {
        static int[] ReadNumList()
        {
            var line = ReadLine().Split(' ');
            if (line.Length == 1 && string.IsNullOrEmpty(line[0]))
            {
                return new int[0];
            }
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
        static void Main()
        {
            var n = int.Parse(ReadLine());
            var aList = ReadNumList();

            var dp = new long[n + 1][];
            for (var i = 0; i < dp.Length; ++i)
            {
                dp[i] = new long[n + 1];
            }

            for (var rest = 1; rest <= n; ++rest)
            {
                var isSente = (n - rest) % 2 == 0;
                for (var shift = 0; shift <= n - rest; ++shift)
                {
                    if (isSente)
                    {
                        dp[shift][rest + shift] = Math.Max(
                            dp[shift + 1][rest + shift] + aList[shift],
                            dp[shift][rest + shift - 1] + aList[rest + shift - 1]
                        );
                    }
                    else
                    {
                        dp[shift][rest + shift] = Math.Min(
                            dp[shift + 1][rest + shift] - aList[shift],
                            dp[shift][rest + shift - 1] - aList[rest + shift - 1]
                        );
                    }
                }
            }
            WriteLine(dp[0][n]);
        }
    }
}


Measured memory_bytes: 99124
def f(arr, ma, mb)
  inf = 1.0/0
  a_max = arr.map{|v| v[:a]}.max
  b_max = arr.map{|v| v[:b]}.max

  dp = (arr.size+1).times.map{
    (arr.size*a_max+1).times.map{ [inf]*(arr.size*b_max+1) }
  }
  dp[0][0][0] = 0
  #p [dp.size, dp[0].size, dp[0][0].size]

  (dp.size-1).times{|i|
    dp[i].size.times{|a|
      dp[i][a].size.times{|b|
        next if dp[i][a][b] == inf
        dp[i+1][a][b] = [dp[i+1][a][b], dp[i][a][b]].min
        dp[i+1][a+arr[i][:a]][b+arr[i][:b]] = \
        [dp[i+1][a+arr[i][:a]][b+arr[i][:b]], dp[i][a][b] + arr[i][:price]].min

      }
    }
  }

  r = inf
  (1..dp[0].size-1).each{|a|
    (1..dp[0][a].size-1).each{|b|
      if a * mb == b * ma
        r = [r, dp[arr.size][a][b]].min
      end
    }
  }
  r == inf ? -1 : r
end

N, Ma, Mb = gets.split(" ").take(3).map(&:to_i)
Arr = N.times.map{ Hash[%i[a b price].zip(gets.split(" ").take(3).map(&:to_i))] }
p f(Arr, Ma, Mb)


Measured memory_bytes: 57472
#include <stdio.h>
#include <set>
#define MAX_USER (100000)

typedef std::set<long> Circle;

void merge_circle( Circle** circleinfo , long uid1 , long uid2 )
{
	Circle* src;
	Circle* dst;
	if( circleinfo[ uid1 ]->size() < circleinfo[ uid2 ]->size() )
	{
		src = circleinfo[ uid1 ];
		dst = circleinfo[ uid2 ];
	}
	else
	{
		src = circleinfo[ uid2 ];
		dst = circleinfo[ uid1 ];
	}

	Circle::const_iterator itr;
	for( itr = src->begin() ; itr != src->end() ; itr++ )
	{
		circleinfo[ *itr ] = dst;
		dst->insert( *itr );
	}
}

void add_member( Circle** circleinfo , long uid1 , long uid2 )
{
	if( circleinfo[ uid1 ] == 0 && circleinfo[ uid2 ] == 0 )
	{
		//create new circle
		Circle* entry = new Circle;
		entry->insert( uid1 );
		entry->insert( uid2 );

		circleinfo[ uid1 ] = entry;
		circleinfo[ uid2 ] = entry;
	}
	else if( circleinfo[ uid1 ] != 0 && circleinfo[ uid2 ] == 0 )
	{
		circleinfo[ uid1 ]->insert( uid2 );
		circleinfo[ uid2 ] = circleinfo[ uid1 ];
	}
	else if( circleinfo[ uid1 ] == 0 && circleinfo[ uid2 ] != 0 )
	{
		circleinfo[ uid2 ]->insert( uid1 );
		circleinfo[ uid1 ] = circleinfo[ uid2 ];
	}
	else
	{
		if( circleinfo[ uid1 ] != circleinfo[ uid2 ] )
		{
			merge_circle( circleinfo , uid1 , uid2 );
		}
	}
}

int main( int argc , char** argv )
{

	//read setting
	long user_count;
	long friendship_count;
	scanf( "%ld %ld" , &user_count , &friendship_count );

	//initialize
	Circle** user_info = new Circle*[ user_count ];
	for( long i = 0 ; i < user_count ; i++ )
	{
		user_info[ i ] = 0;
	}

	//read user friendship
	for( long i = 0 ; i < friendship_count ; i++ )
	{
		long uid1;
		long uid2;
		scanf( "%ld %ld" , &uid1 , &uid2 );

		add_member( user_info , uid1 , uid2 );
	}

	//read number of question
	long question_count;
	scanf( "%ld" , &question_count );

	//process question
	for( long i = 0 ; i < question_count ; i++ )
	{
		long uid1;
		long uid2;
		scanf( "%ld %ld" , &uid1 , &uid2 );

		if( user_info[ uid1 ] == user_info[ uid2 ] && user_info[ uid1 ] != 0 )
		{
			printf( "yes\n" );
		}
		else
		{
			printf( "no\n" );
		}
	}

	delete[] user_info;
	return 0;
}

Measured memory_bytes: 11416
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int A[200010];

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

	cin >> N;
	rep(i, 0, N)
	{
		cin >> A[i];
	}

	int ans = 0;
	int r = 0;
	int t = 0;
	rep(l, 0, N)
	{
		while (r < N&&t + A[r] == (t^A[r]))
		{
			t += A[r];
			r++;
			ans += r - l;
		}
		if (l < r)
		{
			t -= A[l];
		}
	}

	cout << ans << endl;

	return 0;
}

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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template<class T> lint gcd(T a, T b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T> lint lcm(T a, T b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
#define pi acos(-1)
#define mod 1000000007
#define MOD 998244353
#define inf ((1LL << 62) - 1 + (1LL << 62))

// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
        
    string N;
    cin >> N;
    if (N[2] == N[3] && N[4] == N[5]) {
        y();
    }
    else { n(); }
    


}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#define y1 yyy1
#define y2 yyy2
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef double db;
const int maxn=200000+10,mx=100000000;
const db pi=acos(-1);
struct dong{
    int x,y;
    friend bool operator<(dong a,dong b){
        return a.x<b.x||a.x==b.x&&a.y<b.y;
    }
} a[maxn];
int b[maxn],p[maxn];
int lis[maxn];
int i,j,k,l,t,n,m,x1,y1,x2,y2,z1,z2,top;
db ans;
int main(){
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    scanf("%d",&n);
    fo(i,1,n) scanf("%d%d",&a[i].x,&a[i].y);
    if (x1>x2){
        swap(x1,x2);
        swap(y1,y2);
    }
    if (y1>y2){
        y1=mx-y1;
        y2=mx-y2;
        fo(i,1,n) a[i].y=mx-a[i].y;
    }
    a[++n].x=x1;
    a[n].y=y1;
    a[++n].x=x2;
    a[n].y=y2;
    fo(i,1,n) b[i]=a[i].y;
    sort(b+1,b+n+1);
    top=unique(b+1,b+n+1)-b-1;
    fo(i,1,n) a[i].y=lower_bound(b+1,b+top+1,a[i].y)-b;
    z1=y1;z2=y2;
    y1=lower_bound(b+1,b+top+1,y1)-b;
    y2=lower_bound(b+1,b+top+1,y2)-b;
    p[0]=y1;
    fo(i,1,n) p[i]=n+1;
    sort(a+1,a+n+1);
    fo(i,1,n){
        if (a[i].x<x1||a[i].y<y1||a[i].y>y2) continue;
        if (a[i].x>x2) break;
        if (a[i].x==x1&&a[i].y==y1){
            lis[i]=0;
            continue;
        }
        lis[i]=upper_bound(p,p+n+1,a[i].y)-p;
        p[lis[i]]=a[i].y;
        if (a[i].x==x2&&a[i].y==y2) break;
    }
    k=lis[i]-1;
    ans=(x2-x1)+(z2-z1);
    ans*=100;
    ans+=(pi-4)*5*k;
    if (k==min(x2-x1+1,z2-z1+1)&&k) ans+=pi*5;
    printf("%.12lf\n",ans);
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	int k = 0;
	REP(i, h) {
		if (i >= h - b)
			k = 1;
		REP(j, w) {
			if (j >= w - a)
				cout << k;
			else
				cout << (!k);
		}
		cout << '\n';
	}
}

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

typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1001001001;

const double PI = 3.14159;

using namespace std;

vector<ll> memo(1000007, INF);

int main() {

    int x, y;
    cin >> x >> y;

    rep(i, x+1) {

        if (i*2 + (x-i)*4 == y) {
            AA("Yes");
            return 0;
        }
    }

    AA("No");
    return 0;
}

Measured memory_bytes: 11012
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(stdR.readLine());
        String[] s = stdR.readLine().split(" ");
        int[] A = new int[N];
        for(int i = 0 ; i < N; i++) {
            int num = Integer.parseInt(s[i]);
            int count = 0;
            while(true) {
                if(num % 2 == 0) {
                    count++;
                    num /= 2;
                }else {
                    break;
                }
            }
            A[i] = count;
        }
        Arrays.sort(A);
        System.out.println(A[0]);
    }
}

Measured memory_bytes: 20948
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
    int n,m;
    cin >> n >> m;
    vi v,diff;
    if(n >= m){
        P(0);
        return;
    }
    rep(i,m){
        int a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    REP(i,1,m){
        int d = abs(v[i] - v[i-1]);
        diff.push_back(d);
    }
    sort(diff.begin(),diff.end());
    int score = 0;
    rep(i,m-n){
        score += diff[i];
    }
    P(score);
}

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


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b)cout<<c;
	else if(a==c)cout<<b;
	else cout<<a;
	cout<<"\n"s;
}

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

using namespace std;
typedef long long ll;

#define INF (1e9)

int main(int argc, const char *argv[])
{
    ll N, K, a, b, i;
    cin >> N >> K;

    vector<ll> v(1e5+3, 0);
    for (ll i = 0; i < N; i++)
    {
        cin >> a >> b;
        v[a] += b;
    }

    for (i = 0; K > 0; i++)
    {
        K -= v[i];
    }
    cout << i-1 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
////////////////
void solve(){
  double a,b,x; in(a,b,x);
  double pi = acos(-1);
  if(a * a * b <= 2 * x) out( atan((b - x / a / a) * 2 / a) * 180 / pi);
  else out( atan(b * b * a / 2 / x) * 180 / pi);
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $S);
$a = str_split($S);
$len = count($a);
$ans = PHP_INT_MAX;
for ($i = 0; $i < $len - 2; $i++) {
	$X = $a[$i] * 100 + $a[$i + 1] * 10 + $a[$i + 2];
	$ans = min($ans, abs(753 - $X));
}
echo $ans;


Measured memory_bytes: 4728
N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')
sum_rgb = r*g*b

# rgbの組み合わせの総数から距離が等しいものを引く
for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j-i)
        if k > N-1:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            sum_rgb -= 1
print(sum_rgb)

Measured memory_bytes: 9064
my ($N) = split(/ /,<>);
my $T = sqrt($N);
my @ans;
for(my $i=1;$i<=$T;$i++){
  for(my $j=1;$j<=$T;$j++){
    for(my $k=1;$k<=$T;$k++){
      my $v = $i*$i+$j*$j+$k*$k+$i*$j+$j*$k+$i*$k;
      if($v >$N){next;}
      $ans[$v]++;
    }
  }
}
for(my $i=1;$i<=$N;$i++){
  my $v = $ans[$i]+0;
  print "$v\n";
}

Measured memory_bytes: 4940
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
#define fir first
#define sec second

const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n;
int a[100010];

void solve() {
	sort(a, a + n);
	int j = 0;
	for (int i = 0; i < n; i++) {
		if (j < min(a[i], a[n - 1] - a[i])) {
			j = min(a[i], a[n - 1] - a[i]); // j = max(j, min(a[i], a[n - 1] - a[i]));
			j = a[i];
		}
	}

	printf("%d %d\n", a[n - 1], j);	
}

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

	solve();
	
	return 0;
}

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

int gcd(int a, int b){
    int r, tmp;
    if(a < b){
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(){
    int a, b, k, g, d[1000], j;
    cin >> a >> b >> k;
    g = gcd(a, b);
    j = 0;
    for(int i = g; i >= 1; i--){
        if(g % i == 0) { 
          d[j] = i;
          j++;
        }
    }
    printf("%d\n", d[k-1]);
    return 0;
}

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

int main(){
  ll n,ans=0;
  cin>>n;
  for(ll i=1;i*i<=n;i++){
    if((n-i)%i!=0){
      continue;
    }
    ll x=(n-i)/i;
    if(x==0){
      continue;
    }
    if(n/x==n%x){
      ans+=x;
    }
  }
  cout<<ans<<endl;
}

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

#define mp       make_pair
#define mt	  make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF=1<<29;
const double EPS=1e-9;
const ll MOD = 1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int H,W;
char board[10][10];
bool check[10][10];
int main(){
  cin >> H >> W;

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> board[i][j];
    }
  }
  string ok = "Possible";
  string out = "Impossible";
  
  if (board[0][0] != '#' or board[H - 1][W - 1] != '#'){
    cout << out << endl;
    return 0;
  }
  int py,px;
  py = px = 0;
  while (true){
    check[py][px] = true;
    if (py == H - 1 and px == W - 1){
      break;
    }
    int ny,nx;
    
    //right
    ny = py + dy[0];
    nx = px + dx[0];
    if (ny >= 0 and ny < H and nx >= 0 and nx < W and board[ny][nx] == '#'){
      py = ny;
      px = nx;
      continue;
    }
    ny = py + dy[3];
    nx = px + dx[3];
    if (ny >= 0 and ny < H and nx >= 0 and nx < W and board[ny][nx] == '#'){
      py = ny;
      px = nx;
      continue;
    }
    cout << out << endl;
    return 0;
    //down
  }

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (board[i][j] == '#' and !check[i][j]){
	cout << out << endl;
	return 0;
      }
    }
  }

  
  cout << ok << endl;
  
  return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int dis = min(abs(c-a), max(abs(b-a), abs(b-c)));
	if(dis <= d)cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

//「オイラーのふるい」。pnには素数の数が、primesには順番に素数が、
//eulnumsにはその整数を割り切る最小の素数が入る。
//ある数からeulnumsを割っていくとその数の素因数分解が可能。
int pn = 0;
int primes[16000000];
int eulnums[16000000];

void eulerprime(int n) {
    fill(eulnums, eulnums + n + 1, 0);
    for (int i = 2; i <= n; i++) {
        if (eulnums[i] == 0) {
            eulnums[i] = i;
            primes[pn] = i;
            pn++;
        }

        for (int j = 0; i * primes[j] <= n; j++) {
            eulnums[i * primes[j]] = primes[j];
            if (i % primes[j] == 0) {
                break;
            }
        }
    }
}

ll tri[10000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    eulerprime(1000010);
    tri[0] = 0;
    REP(i, 1, 10000) {
        tri[i] = tri[i - 1] + i;
    }
    ll ans = 0;
    REP(i, 0, pn) {
        ll sum = 0;
        while (N % primes[i] == 0) {
            N /= primes[i];
            sum++;
        }
        ll tmp = upper_bound(tri, tri + 10000, sum) - tri - 1;
        // if (sum > 0) {
        //     cout << primes[i] << " " << sum << " " << tmp << endl;
        // }
        ans += tmp;
    }
    if (N != 1) {
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 7964
#include <stdio.h>

int main() {
    int t, v, ok = 0;
    scanf("%d %d", &t, &v);
    
    ok = (v*2)+1;
    
    if (t%ok != 0)
        printf("%d\n", (t/ok) + 1);
    else    
        printf("%d\n", t/ok);

    return 0;
}


Measured memory_bytes: 128
n, k = map(int, input().split())
l = list(map(int, input().split()))

l = [c-1 for c in l]
 
l = [0] + l
from itertools import accumulate
cum =list(accumulate(l))
cum = [c%k for c in cum]

from collections import deque
ans = 0
d = {}
q = deque()
for i in range(n+1):
  if cum[i] not in d:
    d[cum[i]] = 1
  else:
    ans += d[cum[i]]
    d[cum[i]] += 1
  q.append(cum[i])
  if len(q) == k:
    rem = q.popleft()
    d[rem] -= 1
print(ans)

Measured memory_bytes: 120168
#include<stdio.h>
#define M 51000
int main(){
  int i,j,p[M]={1,1};
  for(i=2;i*i<M;i++){
    if(p[i])continue;
    for(j=i*i;j<M;j+=i)p[j]=1;
  }
  while(~scanf("%d",&i)){
    for(j=i-1;p[j];j--);
    printf("%d ",j);
    for(j=i+1;p[j];j++);
    printf("%d\n",j);
  }
  return 0;
}

Measured memory_bytes: 800
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define MOD 1000000007
//#define ONLINE_JUDGE

vector< vector<char> > grid;
vector< vector<ll> > ans;
ll totalPaths(int H,int W){
	if(W<0 || H<0){
		return 0;
	}
	if(H==0 && W==0){
		return 1;
	}
	if(grid[H][W]=='#'){
		return 0;
	}
	
	if(ans[H][W]==-1){
		ans[H][W] = (totalPaths(H-1,W) + totalPaths(H,W-1))%MOD;
	}
	return ans[H][W];
}
int main()
{
	/*
		Jainam Shah's Code
	*/
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	int N,M;
	cin>>N>>M;
	grid.resize(N);
	ans.resize(N);
	for(int j=0;j<N;j++){
		for(int i=0;i<M;i++){
			char c;
			cin>>c;
			grid[j].push_back(c);
		}
	}
	for(int i=0;i<N;i++){
		ans[i].resize(M,-1);
	}
	
	cout<<(totalPaths(N-1,M-1))<<endl;
	
	//cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
}


Measured memory_bytes: 12124
# include <iostream>
# include <cstdio>
using namespace std;
typedef long long LL;
const int N = 3e3 + 12;
int n;
LL g[N][N],p,pw[N * N],t[N],f[N],ans,fac[N],inv[N];
LL qpow(LL x,LL y,LL mod)
{
	LL ret = 1;
	while(y){if(y & 1LL)ret = ret * x % mod;x = x * x % mod;y >>= 1LL;}
	return ret;
}
LL C(int x,int y){return fac[x] * inv[y] % p * inv[x - y] % p;}
int main()
{
  scanf("%d %lld",&n,&p);
  pw[0] = t[0] = fac[0] = 1;
  for(int i = 1;i <= n;i++)t[i] = t[i - 1] * (-1LL),fac[i] = 1LL * i * fac[i - 1] % p;
  inv[n] = qpow(fac[n],p - 2,p);
  for(int i = n - 1;~i;i--)inv[i] = 1LL * inv[i + 1] * (i + 1) % p;
  for(int i = 1;i <= n * n;i++)pw[i] = pw[i - 1] * 2LL % p;
  for(int i = 0;i <= n;i++)
  {
  	g[i][0] = 1;
  	for(int j = 1;j <= i;j++)
  	g[i][j] = (g[i - 1][j - 1] + g[i - 1][j] * (j + 1) % p) % p; 
  }
  for(int i = 0;i <= n;i++)
  {
  	for(int j = 0;j <= i;j++)
  	f[i] = (f[i] + g[i][j] * pw[(n - i) * j] % p) % p;
  	f[i] = f[i] * qpow(2,qpow(2,n - i,p - 1),p) % p;
  }
  for(int i = 0;i <= n;i++)
  ans = (ans + t[i] * C(n,i) % p * f[i] % p + p) % p;
  printf("%lld\n",ans);
}

Measured memory_bytes: 141824
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
int main()
{
    string s;
    cin >> s;
    REP(i,s.size()-1){
        if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
     x=-x;
  }
  while(x){
    f[s++]=x%10;
     x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int A[50], B[50], C[50], D[50], M, N;
int main(){
  int i, j, mn, res, tmp;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
      rd(B[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY;
    for(KL2GvlyY=0;KL2GvlyY<M;KL2GvlyY++){
      rd(C[KL2GvlyY]);
      rd(D[KL2GvlyY]);
    }
  }
  for(i=0;i<N;i++){
    mn = 1073709056;
    for(j=0;j<M;j++){
      tmp = abs(A[i]-C[j]) + abs(B[i]-D[j]);
      if(mn > tmp){
        mn = tmp;
         res = j;
      }
    }
    wt_L(res+1);
    putchar_unlocked('\n');
  }
  return 0;
}
// cLay varsion 20170330-1


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int min(int a,int b){return a>b?b:a;}

int main(void){
  long long int mod = 1e9+7;
  int N,M;
  int a,i,j;
  scanf("%d %d",&N,&M);
  
  int v[N+1];
  for(i=0;i<N+1;i++) v[i] = 1;
  for(i=0;i<M;i++){
    scanf("%d",&a);
    v[a] = 0;
  }
  
  long long int dp[N+1];
  for(i=0;i<N+1;i++) dp[i] = 0;
  dp[0] = 1;
  for(i=0;i<N;i++){
    for(j=i+1;j<=min(N,i+2);j++){
      if(v[j]) dp[j] = (dp[j]+dp[i]) % mod;
    }
  }
  
  printf("%lld\n",dp[N]);
  return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	string st;
	while (getline(cin,st)) {
		long long int p = stoi(st.substr(0, st.find(" ")));
		long long int q = stoi(st.substr(st.find(" ") + 1));
		vector<int>vs;
		for (int i = 0; i < 10000; ++i) {
			p *= 10;
			vs.push_back(p / q);
			p %= q;
			if (!p)break;
		}
		if (vs.size() != 10000) {
			for (auto v : vs) {
				cout << v;
			}
			cout << endl;
		}
		else {
			int roop = 1;
			for (; roop <=80; ++roop) {
				bool flag = true;
				for (int i = 2000; i < 8000; ++i) {
					if (vs[i] == vs[i + roop]) {

					}
					else {
						flag = false;
					}
				}
				if (flag)break;
			}
			int start = 100;
			for (; start >= 0; --start) {
				if (vs[start] == vs[start + roop]) {

				}
				else {
					start;
					break;
				}
			}
			for (int i = 0; i <= start+roop; ++i) {
				cout << vs[i];
			}
			cout << endl;
			for (int i = 0; i <= start + roop; ++i) {
				if (i <=start)cout << " ";
				else cout << "^";
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3300
s = int(input())
def f(n):
  if n % 2 == 0:
    return n // 2
  else:
    return 3 * n + 1

a = [s]
for i in range(1000000):
  _a = f(a[i])
  if _a in a:
    print(i + 2)
    break
  else:
    a.append(_a)
    

Measured memory_bytes: 2940
using System;
using System.Collections.Generic;

class B {
    static char Winner(Queue<char>[] cards) {
        var current = 0;
        while (true) {
            if (cards[current].Count == 0) return (char)('A' + current);
            current = cards[current].Dequeue() - 'a';
        }
    }

    public static void Main() {
        var cards = new Queue<char>[3];
        for (int i = 0; i < 3; ++i)
            cards[i] = new Queue<char>(Console.ReadLine());
        Console.WriteLine(Winner(cards));
    }
}


Measured memory_bytes: 11476