akhauriyash/Code-Regression huggingface dataset:
//
// Created by Hideaki Imamura on 2020-01-03.
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

class ModInt {
    static int MOD;
    long long x;

public:
    static void mod(int m) { MOD = m; }

    ModInt(long long v = 0) : x(v % MOD) {
        if (x < 0) x += MOD;
    }

    ModInt& operator+=(const ModInt& r) {
        x += r.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    ModInt& operator-=(const ModInt& r) {
        x -= r.x;
        if (x < 0) x += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& r) {
        x = (x * r.x) % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& r) {
        *this *= r.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt& r) const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt& r) const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt& r) const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt& r) const { return ModInt(*this) /= r; }
    bool operator==(const ModInt& r) const { return x == r.x; }
    bool operator!=(const ModInt& r) const { return x != r.x; }

    ModInt inverse() const {
        long long a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(long long n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.x; }

    friend istream& operator>>(istream& is, ModInt& x) { return is >> x.x; }

    int getMod() { return MOD; }

    long long val() { return x; }
};
int ModInt::MOD = 1000000007;

int n;
vector<vector<int>> G;
unordered_map<int, unordered_map<int, int>> memo;

int count(int p, int u) {
    if (memo[p][u] != 0) return memo[p][u];
    if (memo[u][p] != 0) return n - memo[u][p];

    int res = 1;
    for (int v : G[u]) {
        if (v == p) continue;
        res += count(u, v);
    }
    memo[p][u] = res;
    return res;
}

int main() {
    cin >> n;
    G.resize(n);
    for(int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    ModInt ans = (ModInt(2).pow(n-1) - 1) * n;
    for(int v = 0; v < n; ++v) {
        for(int u : G[v]) {
            ans -= ModInt(2).pow(count(v, u)) - 1;
        }
    }
    ans /= ModInt(2).pow(n);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 57032
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll MOD = 1000000007;
const int MAX = 100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }


int main(){
    int N,K,S; cin >> N >> K >> S;
    bool f=false;
    if(K==N) f=true;
    int cnt=0;
    for(int i=0;i<N;i++){
        if(i<K) cout << S << " ";
        else{
            if(S==1) cout << S+1 << " ";
            else cout << S-1 << " ";
        }
    }
    return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        System.out.println((N-1)*(K-1));
        sc.close();
    }
}

Measured memory_bytes: 19540
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <iterator>
#include <deque>
#include <assert.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}



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

    
    int n, sum = 0;
    cin>>n;
    vector<int> x(n);
    for (int i = 0; i < n; i++){
        cin>>x[i];
        sum += x[i];
    }

    int a = sum/n, b = (sum+n-1)/n;

    int p = 0, q = 0;
    for (int i = 0; i < n; i++){
        p += (x[i]-a)*(x[i]-a);
        q += (x[i]-b)*(x[i]-b);
    }
    cout<<min(p,q)<<"\n";

    return 0;
    
}





Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b = map(int, read().split())
h, w = 100, 100
print(h, w)
ans = [['#'] * w for _ in range(h // 2)] + [['.'] * w for _ in range(h // 2)]
if a > 1:
    cnt = 0
    flag = False
    for i in range(0, h, 2):
        for j in range(0, w, 2):
            ans[i][j] = '.'
            cnt += 1
            if a - 1 == cnt:
                flag = True
                break
        if flag:
            break
if b > 1:
    cnt = 0
    flag = False
    for i in range(h // 2 + 1, h, 2):
        for j in range(0, w, 2):
            ans[i][j] = '#'
            cnt += 1
            if b - 1 == cnt:
                flag = True
                break
        if flag:
            break
for aa in ans:
    print(''.join(aa))


Measured memory_bytes: 3188
from collections import deque
n = int(input())
q = deque()
a=[]
for i in range(n):
    a.append(int(input())-1)
q.append(a[0])
cnt=0

while q:
    cnt+=1
    i = q.pop()
    q.append(a[i])
    if i==1:
        print(cnt)
        exit()
    if cnt>10**5:
        print(-1)
        exit()
print(-1)


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	int u,v,w;
	Data()=default;
	Data(int U,int V,int W):u(U),v(V),w(W){}
};

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

	while(true){
		int N=in();
		if(!N) break;

		vector<vector<int>> M(N,vector<int>(N,0));
		queue<Data> Q;
		Q.emplace(N/2,(N/2)+1,1);
		while(!Q.empty()){
			auto p=Q.front();
			Q.pop();
			int u=p.u,v=p.v;
			if(u>=N){
				Q.emplace(0,v,p.w);
			}
			else if(u<0){
				Q.emplace(N-1,v,p.w);
			}
			else if(v>=N){
				Q.emplace(u,0,p.w);
			}
			else if(!M[v][u]){
				M[v][u] = p.w;
				if(p.w==N*N) break;
				Q.emplace(u+1,v+1,p.w+1);
			}
			else{
				Q.emplace(u-1,v+1,p.w);
			}
		}
		
		REP(i,N){
			REP(j,N){
				printf("%4d",M[i][j]);
			}
			out();
		}
	}
	return 0;
}


Measured memory_bytes: 3128
"""
Code of Ayush Tiwari
Codeforces: servermonk
Codechef: ayush572000

"""
import sys
input = sys.stdin.buffer.readline

def solution():
    n,k=map(int,input().split())
    l=list(map(int,input().split()))
    dp=[0]*n
    for i in range(1,n):
        m=2e12
        for j in range(1,k+1):
            m=min(m,dp[max(0,i-j)]+abs(l[i]-l[max(0,i-j)]))
        dp[i]=m
    print(dp[n-1])

solution()

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n; cin >> n;
    int a, b; cin >> a >> b;
    vector<int> p(n);
    REP(i, n) cin >> p[i];

    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    REP(i, n) {
        if (p[i] <= a) cnt1++;
        else if (p[i] <= b) cnt2++;
        else cnt3++;
    }

    int ans = min(cnt1, min(cnt2, cnt3));

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

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

typedef long long ll;

int main(){
    ll n, k, cnt, ans = 0;
    cin >> n >> k;
    cnt = n/k;
    ans += cnt*cnt*cnt;
    if(k%2 == 0){
        if(n%k >= k/2) cnt++;
        ans += cnt*cnt*cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)

void printVec(std::vector<int> &vec)
{
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it)
	{
		std::cout << *it << " ";
	}
	cout << '\n';
}
void printVec1(std::vector<string> &vec)
{
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it)
	{
		std::cout << *it << " ";
	}
	cout << '\n';
}
void printVec2(std::vector<Int> &vec)
{
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it)
	{
		std::cout << *it << " ";
	}
	cout << '\n';
}

Int gcd(Int a, Int b)
{
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b)
{
	return a / gcd(a, b) * b;
	//a*bは64bit integer overflow
}

bool integer(double num)
{
	return floor(num) == num;
}

Int fact(int num)
{
	if (num == 0)
		return 1;
	else
		return num * fact(num - 1);
}

int main(){
	//IOS;
	int n,x;cin>>n;
	// int a,b,c;cin>>a>>b>>c;
	// string str;cin>>str;
	

	 vector<int> l(n);
	// vector<string> s(n);
	
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	ssort(l);
	double ans=l[0];
	for(int i=1;i<n;i++){
		ans=1.0*(ans+l[i])/2;
	}
	
	cout<<std::fixed << std::setprecision(15)<<ans;

	





	cout << endl;
	return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

int N, P;
bool p[300000];
vector<int> prime;

int main(void) {
  REP(i, 0, 300000) p[i] = 1;
  p[0] = p[1] = 0;
  REP(i, 2, 300000) if(p[i]) for(int j = i * 2; j < 300000; j += i) p[j] = 0;
  REP(i, 0, 300000) if(p[i]) prime.push_back(i);

  while(cin >> N >> P, N != -1) {
    int m;
    REP(i, 0, prime.size()) if(prime[i] > N) {
      m = i;
      break;
    }

    vector<int> v;
    REP(i, m, m + P) REP(j, i, m + P) v.push_back(prime[i] + prime[j]);
    sort(v.begin(), v.end());
    cout << v[P - 1] << endl;
  }

  return 0;
}

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

int main(){
	int n, k;
	std::vector<int> pList;

	std::cin>>n>>k;
	pList.resize(n);

	for(int i=0; i< n; i++)
		std::cin>>pList[i];

	std::sort(pList.begin(), pList.end(), [](int x, int y){return x<y;});

	int sum=0;

	for(int i=0; i< k; i++)
		sum+= pList[i];

	std::cout<<sum<<std::endl;

	return 0;
}

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

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

int main() {
    int N, M;
    cin >> N >> M;

    vector<int> divisors = divisor(M);
    sort(divisors.begin(), divisors.end());

    int res = 1;
    for (int i = 0; i < divisors.size(); i++) {
        if (divisors[i] > M / N) break;
        res = max(res, divisors[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    sx, sy, tx, ty = MII()
    x1 = tx-sx
    y1 = ty-sy
    go1 = 'U'*y1 + 'R'*x1
    bk1 = 'D'*y1 + 'L'*x1
    go2 = 'L'+'U'+go1+'R'+'D'
    bk2 = 'R'+'D'+bk1+'L'+'U'
    print(go1+bk1+go2+bk2)

if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
	int n,i;
	string s;
	cin>>n;
	cin>>s;
	long long len=s.size();
	if(n==0||n==26)
	cout<<s;
	else
	{
		for(i=0;i<len;i++)
		{
			s[i]='A'+(s[i]-'A'+n)%26;
		}
		cout<<s;
	}
	
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define REP(i, a, b) for(int i = (a); i < int(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

constexpr int SIZE = 4;
enum { R, G, B, NUM_COLORS };

int bfs(const array<int, NUM_COLORS> &colors, const vector<int> &stamps) {
	constexpr int ARRAY_SIZE = 1 << (SIZE * SIZE);
	constexpr int goal = ARRAY_SIZE - 1;

	queue<int> que;
	array<int, ARRAY_SIZE> dist;

	que.push(0);
	dist.fill(INT_MAX);
	dist[0] = 0;

	while(!que.empty()) {
		const int v = que.front();
		que.pop();

		for(const auto &s : stamps) {
			for(const auto &c : colors) {
				const int to = (v & ~s) | (c & s);

				if(dist[to] == INT_MAX) {
					if(to == goal) return dist[v] + 1;
					que.push(to);
					dist[to] = dist[v] + 1;
				}
			}
		}
	}
	assert(false);
}

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

	int convert[128];
	convert[static_cast<int>('R')] = R;
	convert[static_cast<int>('G')] = G;
	convert[static_cast<int>('B')] = B;

	int n;
	cin >> n;

	vector<int> stamps;
	stamps.reserve(n * (2 * SIZE - 1) * (2 * SIZE - 1));

	rep(idx, n) {
		int h, w;
		cin >> h >> w;

		REP(dx, -SIZE + 1, SIZE) {
			REP(dy, -SIZE + 1, SIZE) {
				int bit = 0;

				rep(i, h) {
					const int y = i + dy;
					if(y < 0 || y >= SIZE) continue;

					rep(j, w) {
						const int x = j + dx;
						if(x < 0 || x >= SIZE) continue;

						bit |= (1 << (y * SIZE + x));
					}
				}

				stamps.emplace_back(bit);
			}
		}
	}

	sort(ALL(stamps));
	stamps.erase(unique(ALL(stamps)), end(stamps));

	array<int, NUM_COLORS> colors;
	colors.fill(0);

	rep(i, SIZE) {
		string row;
		cin >> row;

		rep(j, SIZE) {
			colors[convert[static_cast<int>(row[j])]] |= (1 << (i * SIZE + j));
		}
	}

	cout << bfs(colors, stamps) << endl;

	return EXIT_SUCCESS;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a;
  cin >> a;
  cout << 3*a*a << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define mp make_pair
int main(){
int n;
cin>>n;
string s;
cin>>s;
int r=0,si=0;
for(int i=0;i<n;i++){
    if(s[i]=='R')
        r++;
    else si++;
}
if(r>si)
    cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

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

  map<int, int> counts;
  for (int i = 0; i < N; ++i) {
    counts[A[i]] += 1;
  }

  ll sum = 0;
  for (auto x : counts) {
    ll c = x.second;
    sum += c * (c - 1) / 2;
  }

  for (int i = 0; i < N; ++i) {
    ll c = counts[A[i]];
    cout << sum - c * (c - 1) / 2 + (c - 1) * (c - 2) / 2 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int N;
vector<int> t[20];
int dp[16][1<<16];
int dp2[1<<16];

int dfs(int pos, int S) {
    if(S == (1<<N)-1) return 0;
    if(dp[pos][S] != -1) return dp[pos][S];
    int ret = 1000000000;

    //i番目をj番目の装備で攻略
    rep(i,N) {
        if(i == pos) continue;
        if((S>>i)&1) continue;
        rep(j,N) {
            if(i==j) continue;
            if(!((S>>j)&1)) continue;

            ret = min(ret, dfs(i,S|(1<<i)) + t[i][j+1]);
        }
        ret = min(ret, dfs(i, S|(1<<i)) + t[i][0]);
    }
    return dp[pos][S]=ret;

}

void solve() {
    rep(i,16) rep(j,1<<16) dp[i][j]=-1;
    rep(i,N) {
        t[i].resize(N+1);
        rep(j,N+1) {
            int a;
            cin>>a;
            t[i][j]=a;
        }
    }
    rep(i,1<<16) dp2[i]=100000000;
    dp2[0]=0;
    rep(i,1<<N) {
        rep(j,N) {
            //状態i でjを攻略
            if(!((i>>j)&1)) {
                rep(k,N) {
                    if((i>>k)&1) dp2[i|(1<<j)] = min(dp2[i|(1<<j)], dp2[i]+t[j][k+1]);
                }
                dp2[i|(1<<j)] = min(dp2[i|(1<<j)], dp2[i] + t[j][0]);
            }
        }
    } 
    cout<<dp2[(1<<N)-1]<<endl;

    /*

    int ans = 1000000000;
    rep(i,N) {
        ans = min(ans,dfs(i, 1<<i)+t[i][0]);
    }
    cout<<ans<<endl;
    */

    rep(i,N) t[i].clear();

}
int main() {

    while(cin>>N) {
        if(!N) return 0;
        solve();
    }

    return 0;
}

Measured memory_bytes: 5548
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    if(n==1)cout << 1;
    else if(n<4)cout << 2;
    else if(n<8)cout << 4;
    else if(n<16)cout << 8;
    else if(n<32)cout << 16;
    else if(n<64)cout << 32;
    else cout << 64;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define maxs 200202
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int t=n/100;
        int tt=n%10;
        if(t==tt)
            puts("Yes");
        else
            puts("No");
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                                  \
    ({                                                         \
        if (1) cerr << "TR: " << (#X) << " = " << (X) << endl; \
    })
#define LL(name) \
    ll name;           \
    cin >> name;
#define VL(name, num) \
    vl name(num);           \
    FOR(INPUT_VL_I, 0, num) { cin >> name[INPUT_VL_I]; }

int main() { cin.sync_with_stdio(0);
    LL(A) LL(B) LL(H) LL(M);

    long double alpha = 2 * M_PI * ((static_cast<long double>(H) + M / 60.0) / 12.0);
    long double beta = 2 * M_PI * (static_cast<long double>(M) / 60.0);

    double x_h = cos(alpha) * A;
    double y_h = sin(alpha) * A;

    double x_m = cos(beta) * B;
    double y_m = sin(beta) * B;

    TR(x_h);
    TR(y_h);
    TR(x_m);
    TR(y_m);

    cout << fixed << setprecision(20) << hypotl(x_h-x_m, y_h-y_m) << endl;
}  // cin.tie(0) bei schnellem Wechseln


Measured memory_bytes: 4172
#include <stdio.h>
int main(void){
    int a,h,d,s;
    scanf("%d", &a);
    
    h=a/3600;
    d=(a%3600)/60;
    s=(a%3600)%60;
    printf("%d:%d:%d\n", h,d,s);

    return 0;
}



Measured memory_bytes: 2104
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

// utils
func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

// func max(a, b int) int {
// 	return int(math.Max(float64(a), float64(b)))
// }

// func min(a, b int) int {
// 	return int(math.Min(float64(a), float64(b)))
// }

// func abs(a, b int) int {
// 	return int(math.Abs(float64(a) - float64(b)))
// }

// //data types

// type pair struct {
// 	first  int
// 	second int
// }

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := make(map[string]int)
	max := 0

	for i := 0; i < n; i++ {
		k := next()
		if _, ok := m[k]; ok {
			m[k]++
		} else {
			m[k] = 1
		}
		if max < m[k] {
			max = m[k]
		}
	}

	var keys []string
	for k, v := range m {
		if max == v {
			keys = append(keys, k)
		}
	}
	sort.Sort(sort.StringSlice(keys))
	for _, v := range keys {
		fmt.Println(v)
	}
}


Measured memory_bytes: 30720
def takaaki(edge,s)
  dist = []
  dist[s] = 0
  queue = [s]
  while pre_v = queue.shift
    pre_dist = dist[pre_v]
    edge[pre_v].each do |next_v,d|
      next_dist = pre_dist+d
      if dist[next_v] == nil || dist[next_v] > next_dist
        dist[next_v] = next_dist
        queue << next_v
      end
    end
  end
  return dist
end

n,m,s,t = gets.chomp.split(" ").map(&:to_i)
edge_a = Hash.new{|h,k|h[k] = Hash.new}
edge_b = Hash.new{|h,k|h[k] = Hash.new}

m.times do
  u,v,a,b = gets.chomp.split(" ").map{|i|i.to_i-1}
  edge_a[u][v] = edge_a[v][u] = a+1
  edge_b[u][v] = edge_b[v][u] = b+1
end

min_a = takaaki(edge_a,s-1)
min_b = takaaki(edge_b,t-1)

ans = Array.new(n)

for i in 0..n-1
  ans[i] = min_a[i]+min_b[i]
end

(n-1).downto(1) do |i|
  if ans[i] < ans[i-1]
    ans[i-1] = ans[i]
  end
end

for i in 0..n-1
  puts 10**15-ans[i]
end

Measured memory_bytes: 80496
<?php
  list($s) = explode(" ", trim(fgets(STDIN)));

  $n = strlen($s);
  $ans = PHP_INT_MAX;
  for ($i=0; $i<$n-2; $i++) {
    $value = $s[$i].$s[$i+1].$s[$i+2];
    $ans = min($ans, abs($value-753));
  }
  echo $ans;

Measured memory_bytes: 16132
#include <stdio.h>

typedef struct {
    int flip;
    long long rotate;
} Query;

long long n, k, q;

Query tree[(1 << 20) * 2];

void  build(long long _n);
Query merge(Query a, Query b);
void  update(Query data, long long i);
Query sum(void);

int main()
{
    long long _n;
    long long a;

    scanf("%lld %lld %lld", &k, &_n, &q);

    build(_n);

    for (long long i = 0; i < _n; i++) {
        scanf("%lld", &a);

        Query data = {0, 0};

        if (a == 0) data.flip = 1;
        else data.rotate = -a;

        update(data, i);
    }

    for (long long i = 0; i < q; i++) {
        long long left, right;
        Query l, r;
        scanf("%lld %lld", &left, &right);
        left--;
        right--;

        l = tree[left + n - 1];
        r = tree[right + n - 1];

        update(l, right);
        update(r, left);


        Query total = sum();

        long long num;
        if (total.rotate < 0) total.rotate = k + total.rotate;
        num = 1 + total.rotate;

        if (total.flip) {
            if (num == 1) num *= -1;
            else num = ((k + 2) - num) * -1;
        }

        printf("%lld\n", num);
    }
    
    return 0;
}

void  build(long long _n)
{
    n = 1;

    while (n < _n) {
        n *= 2;
    }

    for (long long i = 0; i < 2 * n; i++) {
        tree[i] = (Query){0, 0};
    }

    return;
}

Query merge(Query a, Query b)
{
    Query x;

    x.flip = (a.flip + b.flip) % 2;

    if (b.flip) {
        x.rotate = (b.rotate - a.rotate) % k;
    } else {
        x.rotate = (a.rotate + b.rotate) % k;
    }

    return x;
}

void update(Query data, long long i)
{
    i += n - 1;

    tree[i] = data;

    while (i != 0) {
        i = (i - 1) / 2;
        tree[i] = merge(tree[i * 2 + 1], tree[i * 2 + 2]);
    }

    return;
}

Query sum(void)
{
    return tree[0];
}


Measured memory_bytes: 5948
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <tuple>
using namespace std;
typedef long long ll;
typedef tuple<int, int, pair<int, int> > tup;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
int w, h;
int s[32][32];
int c[6];
//dist[t][y][x] :=????????¨?????§?¨????(x, y)??§??\????????????t????????????????????????
int dist[6][32][32];

void dijkstra(void){
    rep(i, 6)rep(j, 32)rep(k, 32){
    	dist[i][j][k] = INF;
    }

    priority_queue<tup, vector<tup>, greater<tup> >  q;//????????????????????????????????\?????? ?????¨?????§?¨?
    dist[1][0][0] = 0;
    q.push(make_tuple(0, 1, make_pair(0, 0)));

    while(!q.empty()){
        int cost, v;
        pair<int, int> p;
        tie(cost, v, p) = q.top(); q.pop();
        int y = p.first, x = p.second;
        if(dist[v][y][x] < cost) continue;

        for (int i = 0; i < 4; ++i){//??´??????????????¢?????????????????????
            int nextv = (v + i) % 4;
                //?????????????????????????????????
            int ny = y + dy[nextv], nx = x + dx[nextv];
            if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
            if(i == s[y][x]){//????????????
                if(cost < dist[nextv][ny][nx]){
                    dist[nextv][ny][nx] = cost;
                    q.push(make_tuple(dist[nextv][ny][nx], nextv, make_pair(ny, nx)));
                }
            }else{
                if(cost + c[i] < dist[nextv][ny][nx]){
                    dist[nextv][ny][nx] = cost + c[i];
                    q.push(make_tuple(dist[nextv][ny][nx], nextv, make_pair(ny, nx)));
                }
            }
        }
    }
}

int main(void){
	while(1){
		cin >> w >> h;
		if(w == 0 && h == 0) return 0;
        rep(i, h)rep(j, w) cin >> s[i][j];
        rep(i, 4){
            cin >> c[i];
        }

		dijkstra();

		int ans = INF;
		for (int i = 0; i < 4; ++i){
			ans = min(ans, dist[i][h - 1][w - 1]);
		}
        printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3208
N = int(input())

ans = 0
for i in range(1, N+1):
    if i % 3 == 0 and i % 5 == 0:
        pass
    elif i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    else:
        ans += i


print(ans)

Measured memory_bytes: 9108
/*ex4_3
ryo_1129*/
#include<stdio.h>
//プロトタイプ宣言、引数は2つの塔の見えている高さ
int snowhight(int heighta,int heightb);

int main(void){
    //変数宣言
    int heighta,heightb,ans;
    //入力
    scanf("%d %d",&heighta,&heightb);
    //積雪量を出す関数の呼び出し
    ans = snowhight(heighta,heightb);
    //出力
    printf("%d\n",ans);

    return 0;
}
//n番目の木の高さを出す関数、等差数列の和
int snowhight(int heighta,int heightb){
    int talla,n,snowhight;
    //n番目とn+1番目の木の高さの違い(b-a)はn+1である。
    n = heightb-heighta-1;
    //aの高さを出す。n番目の高さは
    talla = (n)*(n+1)/2;
    //積雪量は（aの高さ-埋まらずに見えている高さ）
    snowhight = talla-heighta;
    return snowhight;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>

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

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  int n;
  cin >> n;
  set<LL> st;
  map<LL, LL> mp;
  LL tmp;
  REP(i, n) {
    cin >> tmp;
    st.insert(tmp);
    mp[tmp] += 1;
  }

  if(mp.size() == 1) {
    if(mp.begin()->second == 1) {
      cout << 1 << endl;
      return 0;
    }
    else {
      cout << 0 << endl;
      return 0;
    }
  }

  LL count = 0;
  for(auto itr = st.begin(); itr != st.end(); itr++) {
    if(mp[*itr] == 1) {
      count += 1;
    }
    for(LL num = *itr; num <= *(st.rbegin()); num += *itr) {
        mp[num] = 0;
    }
  }
  cout << count << endl;
  return 0;
}


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

struct Node{
	int key;
	Node *prev, *next;
};

Node *nil;

void init(){
	//nil=(Node *)malloc(sizeof(Node));
	nil = new Node();
	nil->next=nil;
	nil->prev=nil;
}

void insert(int k){
	Node *x=(Node *)malloc(sizeof(Node));
	//x=new *Node();
	x->key = k;
	x->next=nil->next;
	nil->next->prev=x;
	x->prev=nil;
	//nil->next->prev=x;
	nil->next=x;
}

Node *search(int k){
	Node *cur=nil->next;
	while(cur!=nil && cur->key!=k)
		cur=cur->next;
	return cur;
}

void del(Node *cur){
	if(cur==nil)
		return ;
	cur->prev->next=cur->next;
	cur->next->prev=cur->prev;
	//free(cur);
	delete cur;
}

void deleteNode(int k){
	if(search(k)!=nil){
		del(search(k));
	}
}

void deleteFirst(){
	Node *cur=nil->next;
	del(cur);
	//del(nil->next);
}

void deleteLast(){
	Node *cur=nil->prev;
	del(cur);
	//del(nil->prev);
}

int main(){
	ios::sync_with_stdio(false);
	init();
	int n;
	cin>>n;
	while(n--){
		string str;
		cin>>str;
		if(str=="insert"){
			int x;
			cin>>x;
			insert(x);
		}
		else if(str=="delete"){
			int x;
			cin>>x;
			deleteNode(x);
		}
		else if(str=="deleteFirst")
			deleteFirst();
		else if(str=="deleteLast")
			deleteLast();
	}
	Node *cur=nil->next;
	cout<<cur->key;
	cur=cur->next;
	while(cur!=nil){
		cout<<" "<<cur->key;
		cur=cur->next;
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 34472
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test01
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');


            if(s[0]==s[1] && s[1]==s[2] && s[2] == s[0])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }



        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;

int n, m;
pi a[200005];

int main(){
	scanf("%d %d",&n,&m);
	for(int i=0; i<n; i++) scanf("%d",&a[i].first), a[i].second = 0;
	for(int i=n; i<n+m; i++) scanf("%d",&a[i].first), a[i].second = 1;
	sort(a, a+n+m);
	int c1 = n+1, c2 = m+1;
	lint ans = 0;
	for(int i=0; i<n+m; i++){
		if(a[i].second){
			ans += 1ll * c1 * a[i].first;
			c2--;
		}
		else{
			ans += 1ll * c2 * a[i].first;
			c1--;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int INF = 1e9;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

int main() {
    int N;
    cin >> N;
    vector<pair<string,int>> vec(N);
    for(int i = 0;i < N;i++) {
        string A;
        int B;
        cin >> A >> B;
        vec.at(i) = make_pair(A,B);
    }
    string X;
    cin >> X;
    bool cnt = false;
    int ret = 0;
    for(int i = 0;i < N;i++) {
        if(cnt == true) {
            ret += vec[i].second;
        }
        else if(X == vec[i].first) {
            cnt = true;
        }
    }
    cout << ret << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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 A,B;
int D[11][11];

vector<int>X,Y,Z;

signed main(){
    cin>>A>>B;
    for(int i=1;i<=A;i++)for(int j=1;j<=B;j++)cin>>D[i][j];

    rep(i,100){
        X.pb(i);Y.pb(i+1);Z.pb(-1);
        X.pb(i+100);Y.pb(i+1+100);Z.pb(-2);
    }
    int S=0,T=200;

    for(int i=1;i<=A;i++){
        for(int j=1;j<=B;j++){
            bool flag=false;
            for(int k=0;k<=100;k++)for(int l=0;l<=100;l++){
                if(flag)continue;
                if(k*i+l*j>D[i][j])continue;
                int m=D[i][j]-k*i-l*j;
                bool ok=true;
                for(int x=1;x<=A;x++)for(int y=1;y<=B;y++)if(k*x+l*y+m<D[x][y])ok=false;
                if(!ok)continue;
                flag=true;

                bool latte=false;
                rep(w,X.size())if(X[w]==k&&Y[w]==200-l)latte=true;
                if(!latte){X.pb(k);Y.pb(200-l);Z.pb(m);}

            }
            if(!flag){
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }
    cout<<"Possible"<<endl;



    cout<<201<<" "<<X.size()<<endl;
    rep(i,X.size()){
        cout<<X[i]+1<<" "<<Y[i]+1<<" ";
        if(Z[i]==-1)cout<<"X"<<endl;
        else if(Z[i]==-2)cout<<"Y"<<endl;
        else cout<<Z[i]<<endl;
    }
    cout<<S+1<<" "<<T+1<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {

	for {
		var H, W int
		fmt.Scan(&H)
		fmt.Scan(&W)

		if H == 0 && W == 0 {
			break
		}
		for h := 0; h < H; h++ {
			for w := 0; w < W; w++ {
				fmt.Print("#")
			}
			fmt.Println("")
		}
		fmt.Println("")
	}
}




Measured memory_bytes: 1120
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define watch(x) cout << (#x) << " is: " << (x) << endl
#define vw(v)                        \
    cout << endl                     \
         << endl                     \
         << (#v) << " is: " << endl; \
    for (ll B : (v))                 \
    {                                \
        cout << B << " ";            \
    }                                \
    cout << endl
#define check(x) cout << "here " << (x) << "?" << endl
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a) for (long long i = (a - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rv(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
ll const MAX = 2147483647, REALMAX = 9223372036854775806;
// ll const N = ;

int main()
{
    FAST_IO
    ll n, m, maxi = 0;
    cin >> n >> m;
    char A[n][m];
    rep(i, 0, n)
            rep(j, 0, m)
                cin >>
        A[i][j];
    rep(i, 0, n)
    {
        rep(j, 0, m)
        {
            vector<vector<bool>> vis(n, vector<bool>(m, 0));
            queue<pair<pair<ll, ll>, ll>> q;
            q.push({{i, j}, 0});
            while (!q.empty())
            {
                ll i1 = q.front().first.first;
                ll j1 = q.front().first.second;
                ll dep = q.front().second;
                q.pop();
                if (i1 >= n || j1 >= m || i1 < 0 || j1 < 0 || vis[i1][j1] || A[i1][j1] == '#')
                    continue;
                vis[i1][j1] = true;
                maxi = max(maxi, dep);
               // cout << i1 << " " << j1 << " " << dep << endl;
                q.push({{i1 + 1, j1}, dep + 1});
                q.push({{i1 - 1, j1}, dep + 1});
                q.push({{i1, j1 + 1}, dep + 1});
                q.push({{i1, j1 - 1}, dep + 1});
            }
        }
    }
    cout << maxi;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#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 PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(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 pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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

class UnionFind{
private:
  vector<ll> Parent; 
 public:
  UnionFind(ll N){
    Parent = vector<ll>(N, -1);
  }
  
  ll root(ll A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  ll size(ll A){
    return -Parent[root(A)]; 
  }
  
  bool connect(ll A, ll 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;
  }
  
  bool isSame(ll A, ll B){
    return root(A) == root(B);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,m; cin>>n>>m;
  vpll ab(m);
  rep(i,m){
    ll a,b; cin>>a>>b; a--,b--;
    ab[i]={a,b};
  }
  
  UnionFind uf(n);
  
  vll ans(m);
  ans[m-1]=n*(n-1)/2;
  for(ll i=m-1; i>0; i--){
    ll a=ab[i].first, b=ab[i].second;
    if(!uf.isSame(a,b)){
     ans[i-1]=ans[i]-uf.size(a)*uf.size(b);
     uf.connect(a,b); 
    }else{
      ans[i-1]=ans[i];
    }
  }
  
  rep(i,m){
    cout<<ans[i]<<endl;
  }
  
  
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#include <string>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
const int INF = 1001001001;


int main() {
  char C;
  cin >> C;
  cout << char(C + 1) << endl;
  return 0;
}


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

int main(){
  int X, Y;
  cin >> X >> Y;

  int t;
  int k;
  bool r = false;
  for (t = 0; t <= X; t++){
    k = X - t;
    if (Y == (2*t + 4*k)){
      r = true;
      break;
    }
  }
  cout << (r ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3636
n, m, l = map(int, input().split())

matrix_A = [list(map(int, input().split())) for _ in range(n)]
matrix_B = [list(map(int, input().split())) for _ in range(m)]

matrix_Bt = list(map(list, zip(*matrix_B)))

for a in matrix_A:
    r = []
    for bt in matrix_Bt:
        r.append(sum(x * y for (x, y) in zip(a, bt)))
    print(*r)

Measured memory_bytes: 8760
#include <bits/stdc++.h>
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  int n; cin >> n;
  vector<int> nums(n);
  rep_i(i, n){
    cin >> nums[i];
  }

  int q; cin >> q;
  int tmp;
  rep_i(i, q){
    cin >> tmp;
    vector<int>::iterator itr = lower_bound(nums.begin(), nums.end(), tmp);
    cout << itr - nums.begin() << endl;
    // if(binary_search(nums.begin(), nums.end(), tmp)){
    //   say(1);
    // }else{
    //   say(0);
    // }
  }
}


Measured memory_bytes: 3120
#include <string>
#include <stack>
#include <iostream>
#include <algorithm>

using namespace std;
int main(){
  string s;
  stack<char> st;
  bool flag;
  char c;
  int i;
  while(getline(cin, s)){
    if(s==".") break;
    flag=true;
    while(!st.empty()) st.pop();
    for(i=0;i<s.size();i++){
      if(!flag) break;
      if(s[i]=='('||s[i]=='['){
        st.push(s[i]);
      }
      if(s[i]==')'){
        if(st.empty()){flag=false;break;}
        c=st.top();
        st.pop();
        if(c!='('){
          flag=false;
        }
      }
      if(s[i]==']'){
        if(st.empty()){flag=false;break;}
        c=st.top();
        st.pop();
        if(c!='['){
          flag=false;
        }
      }
    }
    if(!st.empty()) flag=false;
    if(flag) cout<<"yes"<<endl;
    else cout <<"no"<<endl; 

  }

  return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod 1000000007
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main()
{
    chutiyaap;
      int a,b,c,k;cin>>a>>b>>c>>k;
      int res=0;
      res+=min(a,k);
      k-=a;
      k-=b;
      res-=max(0,min(k,c));
      cout<<res;
}


Measured memory_bytes: 3660
from operator import mul

n, m = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

MOD = 10 ** 9 + 7

fX = sum(map(mul, xs, range(-n + 1, n + 1, 2))) % MOD
fY = sum(map(mul, ys, range(-m + 1, m + 1, 2))) % MOD

print((fX * fY) % MOD)


Measured memory_bytes: 18752
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder02a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] bodan = Console.ReadLine().Split(' ');
            int a = int.Parse(bodan[0]);
            int b = int.Parse(bodan[1]);
            if (a > b && a>=3 && b>=3 && a<=30&&b<=30)
            {
                int z = a + (a - 1);
                Console.WriteLine(z);
            }
            else if (b > a && a >= 3 && b >= 3 && a <= 30 && b <= 30)
            {
                int z = b + (b - 1);
                Console.WriteLine(z);
            }
            else if(a==b && a >= 3 && b >= 3 && a <= 30 && b <= 30)
            {
                int y = a + b;
                Console.WriteLine(y);
            }
        }
    }
}

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

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar 
inline int read(){
	int x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(int x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(int x){
	write(x);puts("");
}

int a,b,c;

int main(){
	a=read();b=read();c=read();
	if(a>c){
		puts("NO");
		return 0;
	}
	if(a+b<c){
		puts("NO");
		return 0;
	}
	puts("YES");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 ll n;
  cin>>n;
ll cnt[1001];
  rep(i, 1001){
    cnt[i]=0;}
  
  for(ll j=2;j<=n;j++){
    ll a=j;
    while(a>=2){
       bool prime=true;
      for(ll k=2;k*k<=a;k++){
        if(a%k==0){
          cnt[k]++;
          a/=k;
          prime=false;
        break;}
      }
      if(prime){
        cnt[a]++;
        break;}
    }
  }
    
    ll ans=1;
    for(int i=2;i<=n;i++){
      ans*=cnt[i]+1;
      ans%=1000000007;
    }
      
  
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
 
 
public class Main{
     
    public static void main(String[] args) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	
    	final int N = sc.nextInt();
    	
    	List<String> id_list = new LinkedList<String>();
    	
    	for(int i = 0; i < N; i++){
    		id_list.add(sc.next());
    	}
    	
    	final int M = sc.nextInt();
    	
    	boolean is_open = false;
    	for(int i = 0; i < M; i++){
    		String id = sc.next();
    		
    		if(id_list.contains(id)){
    			is_open = !is_open;
    			System.out.println((is_open ? "Opened by " : "Closed by ") + id);
    		}else{
    			System.out.println("Unknown " + id);
    		}
    	}
    	
    }
     
}

Measured memory_bytes: 12000