akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    char s_[500]{};
    char *s = s_ + 150;

    var(int, N);
    read(s);
    dump(s);

    int head = 0;
    int p = 0;
    rep(i, 0, N) {
        if (s[i] == '(')
            ++p;
        else
            --p;

        if (p < 0) s[--head] = '(', ++p;
    }

    rep(i, N, N + p) { s[i] = ')'; }
    print(s + head);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define ll long long int
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
const double pi = 3.14159265358979323846;



void solve()
{
	int i=0,j=0,k=0,n=0,m=0;
    int x;
    cin>>x>>n;
    int arr[n];
    for(i;i<n;i++)
    cin>>arr[i];
    sort(arr,arr+n);
    
    while(1)
    {
        
        
        if(!binary_search(arr,arr+n,x-j))
        {
            cout<<x-j;
            break;
        }
        
        if(!binary_search(arr,arr+n,x+j))
        {
            cout<<x+j;
            break;
        }
        
        j++;
    }
    
}
int main() {
    fast
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 3648
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}
void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[200001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

//なんて工夫のない提出

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


	int N = getint();
	ll K = 0;
	while ((ct = *ci++) >= '0') K = K * 10 + ct - '0';

	int sei[200000], fu[200000];
	int seik = 0, fuk = 0;
	int zero = 0;
	rep(i, N) {
		int a = getint();
		if (a > 0) sei[seik++] = a;
		else if (a < 0) fu[fuk++] = -a;
		else zero++;
	}
	pakuri_sort(seik, sei);
	pakuri_sort(fuk, fu);
	ll k0 = ll(seik) * fuk + ll(zero) * (zero - 1) / 2 + ll(zero) * (N - zero);

	ll L = -1000000000000000001, R = 1000000000000000000;
	while (L + 1 < R) {
		ll M = (L + R) / 2;
		ll k = 0;
		if (M >= 0) {
			k += k0;
			int i = 0;
			int j = seik - 1;
			while (i < seik) {
				while (j > i && ll(sei[i]) * sei[j] > M) j--;
				if (i == j) break;
				k += j - i;
				i++;
			}
			i = 0;
			j = fuk - 1;
			while (i < fuk) {
				while (j > i && ll(fu[i]) * fu[j] > M) j--;
				if (i == j) break;
				k += j - i;
				i++;
			}
		}
		else {
			int j = 0;
			rep(i, seik) {
				while (j < fuk && ll(sei[i]) * fu[fuk - j - 1] >= -M) j++;
				k += j;
			}
		}
		if (k >= K) R = M;
		else L = M;
	}

	printf("%lld\n", R);

	Would you please return 0;
}

Measured memory_bytes: 1664
N=int(input())
A=[int(input()) for _ in range(N)]
d=dict()
for a in list(set(A)):
  d[a]=0
for a in A:
  d[a]+=1
ans=0
for a in list(d.keys()):
  if d[a]%2==1:
    ans+=1
print(ans)

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

int main(void)
{
  int h, w;
  std::cin >> h >> w;

  std::vector<std::string> c;
  for (int i = 0; i < h; i++) {
    std::string buf;
    std::cin >> buf;
    c.push_back(buf);
  }

  std::vector<std::string> px(2*h);
  for (int i = 0; i < 2*h; i++) {
    px[i] = c[i/2];
  }

  for (auto i : px) {
    std::cout << i << std::endl;
  }

  return 0;
}

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

int main(){
  int n;
  cin >> n;
  ll l[n];
  rep(i,n) cin >> l[i];
  ll ans = 0;
  rep(i,n) {
    for(int j = i+1; j < n; j++) {
      for(int k = j+1; k < n; k++) {
        if(l[i]+l[j] > l[k] and l[i]+l[k] > l[j] and l[j]+l[k] > l[i] and l[i] != l[j] and l[j] != l[k] and l[i] != l[k]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  set<int> st;
  rep(i,n){
    int a;
    cin >> a;
    st.insert(a);
  }
  int ans = st.size();
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  string S;
  cin >> S;

  int N = S.size();
 
  for(int i = 0; i < N; i++){
    // 末尾削除
    S.pop_back();
    string S1, S2;
    S1 = S.substr(0, S.size()/2);
    S2 = S.substr(S.size()/2);
    if(S1 == S2){
      cout << S.size() << endl;
      exit(0);
    }
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		for (int i = 0; i < n; i++) {
		    if (sc.nextInt() % 2 == 0) {
		        count++;
		    }
		}
	    System.out.println(count);
	}
}



Measured memory_bytes: 26408
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 345;
char s[MAXN];
int cake[MAXN][MAXN];
int ans[MAXN][MAXN];
bool OK_col[MAXN];

int main() {
    int H, W, K;
    scanf("%d %d %d", &H, &W, &K);
    int cake_idx = 1;
    for (int i = 0; i < H; i++) {
        scanf("%s", s);
        for (int j = 0; j < W; j++) {
            if (s[j] == '#') {
               cake[i][j] = 1;
               ans[i][j] = cake_idx++;
               OK_col[j] = true;
            }
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (cake[i][j]) {
               int cur = i - 1, idx = ans[i][j];
               while (cur >= 0 && !ans[cur][j]) {
                     ans[cur][j] = idx;
                     cur--;
               }
               cur = i + 1;
               while (cur < H && !ans[cur][j]) {
                     ans[cur][j] = idx;
                     cur++;
               }
            }
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (cake[i][j]) {
               int idx = ans[i][j];
               int tp = i, dw = i;
               while (tp > 0 && ans[tp - 1][j] == idx) tp--;
               while (dw < H - 1 && ans[dw + 1][j] == idx) dw++;
               for (int k = j - 1; k >= 0 && !OK_col[k]; k--) {
                   bool check = true;
                   for (int z = tp; z <= dw; z++) {
                       if (ans[z][k]) check = false;
                   }
                   if (!check) break;
                   for (int z = tp; z <= dw; z++) ans[z][k] = idx;
               }
               for (int k = j + 1; k < W && !OK_col[k]; k++) {
                   bool check = true;
                   for (int z = tp; z <= dw; z++) {
                       if (ans[z][k]) check = false;
                   }
                   if (!check) break;
                   for (int z = tp; z <= dw; z++) ans[z][k] = idx;
               }
            }
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            printf("%d ", ans[i][j]);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>

/* #define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0]))
sort(a, a + SIZE_OF_ARRAY(a)); 配列内を昇順ソート(aという配列) */

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int flag = 0;
    for(int i=1;i<=b;i++){
        if((a*i)%b == c){
            flag = 1;
            break;
        }
    }
    if(flag == 1){
        printf("YES");
    }
    else{
        printf("NO");
    }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sum = 0
before = n+1
for i in a:
  sum += b[i-1]
  if i == before+1:
    sum += c[before-1]
  before = i

print(sum)

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

int main(){
	ios::sync_with_stdio(false);
	int tmp1,tmp2,cnt=0;
	cin >> tmp1;
	int lis[tmp1];
	for(int i=0; i<tmp1; i++){
		cin >> lis[i];
	}
	cin >> tmp2;
	int key[tmp2];
	for(int i=0; i<tmp2; i++){
		cin >> key[i];
		if( *lower_bound(lis, lis+tmp1,key[i]) == key[i]){
			cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{	
	string s;
	cin >> s;
	bool b = true;
	REP(i, 3){
		if(s[i] == s[i+1]) b = false;
	}
    if(b) cout << "Good" << endl;
    else cout << "Bad" << endl;
}


Measured memory_bytes: 256
/*===============================================================
*  Filename：c.cpp
*  Author：zhuyutian
*  Date：2016年11月06日
================================================================*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N=100005;
char s[N];

int main()
{
	scanf("%s",s);
	int len=strlen(s);
	int cnt=0;
	for(int i=1;i<len;i++)
		if(s[i]!=s[i-1])
			cnt++;
	cnt++;
	printf("%d\n",cnt-1);
    return 0;
}


Measured memory_bytes: 384
k, n = map(int, input().split())
a = list(map(int, input().split()))
len = []

for i in range(n):
    if i == 0:
        len.append(min(k-(a[1]-a[0]), a[n-1]-a[0]))
    elif i == n-1:
        len.append(min(a[n-1]-a[0], k-(a[n-1]-a[n-2])))
    else:
        len.append(min(k-(a[i]-a[i-1]), k-(a[i+1]-a[i])))

print(min(len))


Measured memory_bytes: 26444
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
using namespace std;

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin,(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
  int a,b,c,ans;
  cin >> a >> b >> c;
  if(b/a>c)ans=c;
  else ans=b/a;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import itertools

N,A,B,C=map(int,input().split())
L=[int(input()) for i in range(N)]
M=[A,B,C]
M.sort()

ans=10**10
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      X=[L[i],L[j],L[k]]
      Y=[]
      for l in range(N):
        if l!=i and l!=j and l!=k:
          Y.append(L[l])
      #print(X,Y)
      
      for m in range(4**len(Y)):
        tmp=0
        mm=m
        XX=[L[i],L[j],L[k]]
        for n in range(len(Y)):
          mmm=mm%4
          if mmm!=0:
            XX[mmm-1]+=Y[n]
            tmp+=10
          mm=(mm-mmm)//4
        XX.sort()
        #print(XX)
        tmp+=abs(XX[0]-M[0])+abs(XX[1]-M[1])+abs(XX[2]-M[2])
        ans=min(tmp,ans)
print(ans)

Measured memory_bytes: 3064
import math
X= int(input())
#
# def make_divisors(n):
#     divisors = []
#     for i in range(1, int(n**0.5)+1):
#         if n % i == 0:
#             divisors.append(i)
#             if i != n // i:
#                 divisors.append(n//i)
#
#     # divisors.sort()
#     return divisors
# yakusu = make_divisors(X)
# for div in yakusu:
#     for a in range(0,div + 1):
#         b =   a - div
#         print(f"{a,b}:{a ** 5 - b ** 5}")
#
#         if (a - b)  * ((a ** 4) + (a**3 * b) + (a **2 *  b ** 2) + (a * b ** 3 )+ (b ** 4)) == X:
#             print(a,b)
#             exit(0)
#



for a in range(-500,500):
    for b in range(-500,500):
        if X ==a ** 5  - b** 5:
            print(a,b)
            exit(0)



# (a - b)  * ((a ** 4) + (a**3 * b) + (a **2 *  b ** 2) + (a * b ** 3 )+ (b ** 4))



# if A % B == 0:
#     print(  min ( (A//B - 1) *B,A//B * N )


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define LINF		((ll)1 << 63 -1)
#define INF 		(1<<29)
#define MINF		-2000000007
#define MAX 		100050

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//



//
int main(){
	int N,D;
	cin >> N >> D;

	cout << ceil((double)N/(2*D+1)) << endl;




	return 0;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int field[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8};
const int l = sizeof(field) / sizeof(int);

int main() {
	int n;
	cin >> n;
	while (n--) {
		int s, g;
		int res_size = 100, res_begin;
		cin >> s >> g;
		for (int i = 0; i < l; i++) {
			if (field[i] != s) continue;
			for (int j = i + 1; j < l; j++) {
				if (field[j] != g) continue;
				int size = j - i;
				if (size < res_size) {
					res_size = size;
					res_begin = i;
				}
			}
		}
		for (int i = res_begin;; i++) {
			if (i != res_begin) cout << ' ';
			cout << field[i];
			if (field[i] == g) break;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
long long up(long long x)
{
    long long d[15],cnt=0;
    while(x)
    {
        d[cnt++]=x%10;
        x/=10;
    }
    long long i=0;
    for(; i<cnt; i++)
    {
        if(d[i]==7)
            d[i]=3;
        else
        {
            if(d[i]==3)
                d[i]=5;
            else if(d[i]==5)
                d[i]=7;
            break;
        }
    }
    if(i>=cnt)  d[cnt++]=3;
    long long ans=0;
    for(i=cnt-1; i>=0; i--)
        ans=ans*10+d[i];
    return ans;
}
bool ok(long long x)
{
    long long f1=0,f2=0,f3=0;
    while(x)
    {
        long long k=x%10;
        if(k==3)
            f1++;
        if(k==5)
            f2++;
        if(k==7)
            f3++;
        if(f1&&f2&&f3)
            return true;
        x/=10;
    }
    return false;
}
int main()
{
    int n;
    scanf("%d",&n);
    long long k=333;
    long long ans=0;
    while(k<=n)
    {
        if(ok(k))
            ans++;
        k=up(k);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

typedef struct test
{
  int h;
  int w;
}test;

int main()
{
  test a[100];
  int count=0;
  scanf("%d%d", &a[count].h, &a[count].w);
  while(a[count].h != 0 || a[count].w != 0)
    {
      count++;
      scanf("%d%d", &a[count].h, &a[count].w);
    }
  for(int i = 0; i<count; i++)
    {
      for(int j = 0; j<a[i].h; j++)
	{
	  for(int k = 0; k<a[i].w; k++)
	    {
	      printf("#");
	    }
	  printf("\n");
	}
      printf("\n");
    }
}




Measured memory_bytes: 2060
#include <stdio.h>
main(){
int tate,yoko;

scanf("%d",&tate);
scanf("%d",&yoko);
tate+=1;
int i,j,suzi[tate],a,b,c=0;

for(i=0;i<tate;i++){
suzi[i]=i;
}
for(i=0;i<yoko;i++){
scanf("%d,%d",&a,&b);
c=suzi[a];
suzi[a]=suzi[b];
suzi[b]=c;
}
for(i=1;i<tate;i++){
printf("%d\n",suzi[i]);
}
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort(x.begin(),x.end())
#define mp make_pair
#define pb push_back
using namespace std;

int main(){
string s;
cin>>s;
int count=0;
rep(i,0,3) if(s[i]=='1')count++;
cout<<count<<endl;

return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    char a, b;
    cin >> a >> b;
    a -= '0';
    b -= '0';
    if(a == b)
        cout << "=" << endl;
    else if(a < b)
        cout << "<" << endl;
    else
        cout << ">" << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
n=int(input())
l=list(sorted(map(int,input().split())))
count=0
for i in range(1,n):
    for j in range(i+1,n):
        p=l[i]+l[j]
        count+=min(bisect.bisect_left(l,p),i)-min(bisect.bisect_left(l,l[j]-l[i]+1),i)
print(count)


Measured memory_bytes: 45660
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>

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

ll gcd(ll a, ll b){
    if (a < b) swap(a,b);

    if (a%b == 0) return b;
    
    return gcd(b, a%b);
}

ll lcm(ll a, ll b){
    return a/gcd(a, b)*b;
}

ll n, ans;
ll t[112];

int main() {
    cin >> n;
    rep(i,n) cin >> t[i];
    ans = 1;
    rep(i,n) ans = lcm(ans, t[i]);
    cout << ans << endl;
    return 0;
}

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)
#define rreps(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rreps(v, 0, n - 1)
#define rlep(v, n) rreps(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define debug(x) std::cerr << #x << " = " << (x) << "\n";

using namespace std;

typedef long long int lint;
typedef complex<double> P;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
  rep(i, in()){
    int res;
    double r1, r2;
    P p1, p2;
    cin >> p1.imag() >> p1.real() >> r1 >> p2.imag() >> p2.real() >> r2;
    if (abs(p1 - p2) > r1 + r2){
      res = 0;
    }
    else if (r2 + abs(p1 - p2) < r1){
      res = 2;
    }
    else if (r1 + abs(p1 - p2) < r2){
      res = -2;
    }
    else {
      res = 1;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	string s, t;
	cin >> s >> t;
	sort(all(s));
	sort(all(t));
	reverse(all(t));
	if (s < t) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double dp[301][301][301];

double solve(int x, int y, int z, int& n)
{
	if(x < 0 || y < 0 || z < 0)return 0;
	if(x == 0 && y == 0 && z == 0)
		return 0;
	if(dp[x][y][z] > -0.9)return dp[x][y][z];
	double exp = n + x*solve(x-1,y,z,n) + y*solve(x+1,y-1,z,n) + z*solve(x,y+1,z-1,n);
	return dp[x][y][z] = exp/(x+y+z);
}
int main()
{
	int n;
	cin >> n;
	vector<int> vec(n + 1);
	int one = 0, two = 0, three = 0;
	memset(dp, -1, sizeof dp);
	for(int i = 1; i <= n; i++)
	{
		cin >> vec[i];
		if(vec[i] == 1)one++;
		else if(vec[i] == 2)two++;
		else three++;
	}
	double ans = solve(one, two, three, n);
	cout << fixed << setprecision(14) << ans;
	return 0;
}

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

UL A[128]={};

int main(){
 string S; cin>>S;
 for(char c:S) A[c]++;
 priority_queue<UL,vector<UL>,greater<UL>> Q;
 rep(i,127) Q.push(A[i]);
 UL ans=0;
 while(Q.size()>=2){
  UL a=Q.top(); Q.pop();
  if(a==0) continue;
  UL b=Q.top(); Q.pop();
  ans+=a+b;
  Q.push(a+b);
 }
 if(ans==0) ans=Q.top();
 printf("%u\n",ans);
 return 0;
}



Measured memory_bytes: 3408
import java.util.*;

public class Main {

    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	int a = scan.nextInt();
	int b = scan.nextInt();
	if (a <= 8 && b <= 8) {
	    System.out.println("Yay!");
	} else {
	    System.out.println(":(");
	}
    }
}


Measured memory_bytes: 23636
/*
Mangal bhavan amangal haari
Drabahu su Dasharath achar Bihari
Raam Siya Raam Siya Raam jai jai Raam
Raam Siya Raam Siya Raam jai jai Raam
Ho hoi hai wohi jo Raam rachi raakha
Ko kari tarak badhave saakha
Raam Siya Raam Siya Raam jai jai Raam
Ho dheeraj dharam mitra aru naari
Aapad kaal parakhiye chaari
Ho jehike jehi par satya sanehu
So tehi milay na kachhu sandehu
Ho jaaki rahi bhawana jaisi
Prabhu murati dekhi tin taisi
Ho Raghukul reet sada chali aayi
Praan jaaye par vachan na jaayi
Raam Siya Raam Siya Raam jai jai Raam, Raam
Raam Siya Raam Siya Raam jai jai Raam
Ho hari anant hari katha ananta
Kahahi sunahi bahuvidhi sab santa
Raam Siya Raam Siya Raam jai jai Raam, Raam
Raam Siya Raam Siya Raam jai jai Raam
Raam Siya Raam Siya Raam jai jai Raam
*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
//auto->.
//map<int,int>::iterator i
vector<int> sieve(ll n) 
{ 
//cout<<":";
    vector<bool> prime(n+1,true); 
       
    prime[0] = false; 
    prime[1] = false; 
    int m = n; 

    for (int p=2; p<=m; p++) 
    { 
    
        if (prime[p]) 
        { 
         
            for (int i=p*2; i<=n; i += p) 
            prime[i] = false; 
        } 
    }  
    vector<int> ans; 
    for (int i=0;i<n;i++) 
        if (prime[i]) 
            ans.push_back(i);  
}

int gcd(int a,int b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
int mod = 1e9 + 7;
int power(int a , ll b)
{
	int res = 1;
	while(b)
	{
		if(b & 1)
			res = 1LL * res * a ;//% mod;
		a = 1LL * a * a ;//% mod;
		b >>= 1;
	}
	return res;
}
ll min(int a,ll b)
{
	if(a>b)
	return b;
	return a;
}
ll max(int a,ll b)
{
	if(a>b)
	return a;
	return b;
}
#define PI 3.141592653589793
ll lcm(ll a,ll b)
{
	return a*b/__gcd(a,b);
	//return t*c/__gcd(t,c);
}
bool isprime(ll n)
{
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		return false;
	}
	return true;
}
ll v(ll n)
{
	if(isprime(n))
	return 1;
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return max(i,n/i);
		}
	}
}
void solve()
{
int n;
cin>>n;
if(n>=400&&n<=599)
{
	cout<<8;
	return ;
}
if(n>=600&&n<=799)
{
	cout<<7;
	return ;
}
if(n>=800&&n<=999)
{
	cout<<6;
	return ;
}
if(n>=1000&&n<=1199)
{
	cout<<5;
	return ;
}
if(n>=1200&&n<=1399)
{
	cout<<4;
	return ;
}
if(n>=1400&&n<=1599)
{
	cout<<3;
	return ;
}
if(n>=1600&&n<=1799)
{
	cout<<2;
	return ;
}
if(n>=1800&&n<=1999)
{
	cout<<1;
	return ;
}
}

int main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
int mul=0;
if(mul==1)
{
 int t;
    cin>>t;
   while(t--)
    {
    //	cout<<"Case #"<<i<<": ";
		solve();
	cout<<"\n";
    }
}
else
{
	solve();
}
}

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

namespace ejq{

const int mod = 1000000007;

const int maxn = 40, maxnn = 2000;
int pr[maxn], pp[maxn], tp;
vector<long long> div;
long long ans[maxnn];

void dfs(int lay, long long cur)
{
//	cerr << lay << ' ' << cur << endl;
	if (lay == tp)
	{
//		cerr << cur << endl;
		div.push_back(cur);
		return;
	}
	long long ccur = 1;
	for (int i = 0; i <= pp[lay]; i++)
	{
		dfs(lay + 1, cur * ccur);
		ccur *= pr[lay];
	}
}

long long pow_m(long long a, int b)
{
	long long ret = 1;
	while (b)
	{
		if (b & 1)
			ret = ret * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ret;
}

int main()
{
	long long n, nn, k;
	cin >> n >> k;
	long long ub = sqrt(n) + 1;
	nn = n;
	for (long long i = 2; i <= ub && i * i <= n; i++)
	{
		if (nn % i == 0)
		{
			pr[tp] = i;
			while (nn % i == 0)
			{
				nn /= i;
				pp[tp]++;
			}
//			cerr << pr[tp] << ' ' << pp[tp] << endl;
			tp++;
		}
	}
	if (nn > 1)
	{
		pr[tp] = nn;
		pp[tp] = 1;
		tp++;
	}
//	for (int i = 0; i < tp; i++) cerr << pr[i] << ' ' << pp[i] << endl;
	dfs(0, 1);
	sort(div.begin(), div.end());
	long long inv2 = pow_m(2, mod - 2);
//	cerr << inv2 << endl;
	for (int i = 0; i < (int)div.size(); i++)
	{
		long long minus = 0;
		for (int j = 0; j < i; j++)
			if (div[i] % div[j] == 0) (minus += ans[j]) %= mod;
		ans[i] = pow_m(k, (div[i] + 1) / 2) % mod;
		ans[i] = ((ans[i] - minus) % mod + mod) % mod;
	}
	long long rans = 0;
	for (int i = 0; i < (int) div.size(); i++)
		if (div[i] % 2 == 0)
			ans[i] = ans[i] * inv2 % mod;
	for (int i = 0; i < (int) div.size(); i++)
//		cerr << div[i] << ' ' << ans[i] << endl;
		(rans += (div[i] * ans[i] % mod)) %= mod;
	cout << rans << endl;
	return 0;
}
}

int main()
{
	return ejq::main();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

ll c[100];

ll burger(int n, ll x) {
    if (n == 0) return 1;
    ll len = (1ll << (n + 1)) - 3;
    ll num = (1ll << n) - 1;
    if (x == 1) return 0;
    else if (x <= len + 1) return burger(n - 1, x - 1);
    else if (x == len + 2) return num + 1;
    else if (x <= (len + 1) * 2) return num + 1 + burger(n - 1, x - len - 2);
    else return num * 2 + 1;
}


int main() {
    int n;
    ll x;
    cin >> n >> x;
    cout << burger(n, x) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
#define M 1000000
using namespace std;

int isprime(ll n){
    if(n==1) return 0;
    if(n==2 || n==3) return 1;
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return 0;
    }
    return 1;
}

void answer(){
    ll n,ans=0,m,p=0,x;
    cin>>n>>m;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n-m;i++){
        ans+=a[i];
    }
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    //cin>>q; while(q--)
        answer();
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main () {
	int N , M ;
	cin >> N >> M ;
	int K;
	int cnt [M] = {0};
  	int A;
  	int ans = 0;
  	for(int i = 0; i < N; ++i){
      cin >> K;
      for(int j = 0; j < K; ++j){
        cin >> A;
        --A;
        ++cnt[A];
      }
    }
  	for(int i = 0; i < M; ++i){
      if(cnt[i] == N)
        ++ans;
    }
	
	cout << ans << endl ;
}

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


int main()
{
  ios::sync_with_stdio(false);
  int n, tmp;
  cin >> n;
  vector<int> a(n),b(n);
  rep(i, n) {
    cin >> tmp;
    a[i] = tmp;
    b[i] = tmp;
  }
  sort(a.begin(), a.end());
  int count = 0;
  rep(i, n) {
    if(a[i]!=b[i]) count++;
  }
  if(count > 2) cout << "NO" <<endl;
  else cout << "YES" << endl;
}	

Measured memory_bytes: 256
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')
MOD = 10 ** 9 + 7


n, k = LI()
a = LI()
c = list(Counter(sorted(a)).items())
# a 単体の中での転倒数
count_in_a = 0
for i in range(n):
    for j in range(i + 1, n):
        if a[i] > a[j]:
            count_in_a += 1
# b 全体での転倒数
count_in_b = 0
# ある a の各要素の もうひとつの a の各要素に対する転倒数の数を計算
for elem_1 in a:
    for elem_2 in a:
        if elem_1 > elem_2:
            count_in_b += 1
# b に含まれる k 個の a から 2 つ転倒数を考えるペアを選ぶ(k C 2)
ans = count_in_a * k + count_in_b * (k * (k - 1) // 2)
ans %= MOD
print(ans)


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

int main()
{
    int N;
    cin >> N;
    vector<long long> A(N);
    vector<long long> B(N);

    long long sumA = 0;
    long long sumB = 0;

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

    for (int i = 0; i < N; i++)
    {
        cin >> B[i];
        sumB += B[i];
    }

    if (sumA < sumB)
    {
        cout << -1 << endl;
        return 0;
    }

    long long shortage = 0;
    int change = 0;
    vector<long long> sub(N);
    for (int i = 0; i < N; i++)
    {
        sub[i] = B[i] - A[i];
        if (0 < sub[i])
        {
            shortage += sub[i];
            change++;
        }
    }
    sort(sub.begin(), sub.end());

    for (int i = 0; i < N; i++)
    {
        if (shortage <= 0)
        {
            break;
        }
        shortage += sub[i];
        change++;
    }

    cout << change << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.141592653289793;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define lld long double
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

int main()
{
	char a, b;
	cin >> a >> b;
	if (a > b) cout << ">" << endl;
	else if (a == b) cout << "=" << endl;
	else cout << "<" << endl;
}

Measured memory_bytes: 256
using System;

namespace ITP1_6_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string str1 = Console.ReadLine();
            int n = int.Parse(str1);
            int b, f, r, v;
            int[, ,] room = new int[4, 3, 10];
            for (int i = 0; i < n; i++)
            {
                string[] str2 = Console.ReadLine().Split(' ');
                b = int.Parse(str2[0]);
                f = int.Parse(str2[1]);
                r = int.Parse(str2[2]);
                v = int.Parse(str2[3]);

                room[b-1, f-1, r-1] += v; 
            }

            for(int i = 0; i < 4; i++)
            {
                for(int j = 0; j < 3; j++)
                {
                    for(int k = 0; k < 10; k++)
                    {
                        Console.Write(" {0}", room[i, j, k]);
                    }
                    Console.Write("\n");
                }
                if (i < 3)
                    Console.WriteLine("####################");
            }

//            string end = Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9760
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;


const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<std::vector<long long>> D){
    int cnt=0;
    rep(i,N){
        if(D[i][0]==D[i][1]){
            cnt++;
            if(cnt==3){
                cout<<YES<<endl;
                return;
            }
        }else{
            cnt=0;
        }
    }

    cout<<NO<<endl;
    return;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::vector<long long>> D(N, std::vector<long long>(2));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < 2 ; j++){
            scanf("%lld",&D[i][j]);
        }
    }
    solve(N, std::move(D));
    return 0;
}


Measured memory_bytes: 3696
N, _ = map(int, input().split())
A = list(map(int, input().split()))

mi = 10**18
mx = -10**18
ans = 0
for a in A:
    if mx < a - mi:
        ans = 0
        mx = a - mi
    if mx == a - mi:
        ans += 1
    mi = min(mi, a)

print(ans)


Measured memory_bytes: 14244
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
int main(){

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

	ll total=0;
	if(x==1)total+=300000;
	if(x==2)total+=200000;
	if(x==3)total+=100000;
	if(y==1)total+=300000;
	if(y==2)total+=200000;
	if(y==3)total+=100000;
	if(x==1&&y==1)total+=400000;
	cout<<total<<endl;
	return 0;

}


Measured memory_bytes: 764
class UnionFindWithSize
  def initialize(n)
    # 親の番号を格納
    # ただし、rootの位置には、-(その集合のサイズ)を格納
    @parent = Array.new(n, -1)
    @size = n
  end

  def root(x) # xのrootの番号を返す
    raise :"UnionFindWithSize::IndexError" if x < 0 || @size <= x
    return x if @parent[x] < 0
    @parent[x] = root(@parent[x])
    return @parent[x]
  end

  def size(x) # xの属するグループのサイズを返す
    return -@parent[root(x)]
  end

  def merge(x, y)
    x, y = root(x), root(y)
    return false if x == y
    # 大きい方(x)に小さい方(y)をくっつけたい
    x, y = y, x if size(x) < size(y)
    @parent[x] += @parent[y]
    @parent[y] = x
    return true
  end

  def same?(x, y)
    root(x) == root(y)
  end
end

n, m = gets.split.map(&:to_i)
uf = UnionFindWithSize.new(n)
ab = m.times.map { gets.split.map { |t| t.to_i - 1 } }

cnt = n * (n - 1) / 2
ans = [cnt]
ab.reverse_each do |a, b|
  s = uf.size(a)
  t = uf.size(b)
  if uf.same?(a, b)
    ans << ans[-1]
  else
    ans << ans[-1] - s * t
  end
  uf.merge(a, b)
end
ans.reverse!
puts ans[1..-1]


Measured memory_bytes: 12596
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

template<class T> T lower_search(T lb, T ub, bool (*C)(T)) {
  while(ub-lb>1) { // ツつアツつアツづ債適ツ督鳴づ可。
    T mid = (lb+ub)/2;
    if (C(mid)) ub = mid;
    else lb = mid;
  }
  return ub;
}
int m, n;
int a[100];

bool C(int x) {
  int hoge = 0;
  REP(i,m) {
    int tmp = 0;
    while(tmp + a[hoge] <= x) {
      tmp += a[hoge];
      hoge++;
      if (hoge >= n)
        return true;
    }
  }
  return false;
}
int main() {
  while(cin >> m >> n, m+n) {
    REP(i,n) {
      cin >> a[i];
    }
    cout << lower_search(0, INF, C) << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
  public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(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;
  }
};

class Factrial{
  public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  string s; cin >> s;
  int n = s.size();

  int ans = 0;
  rep(i,n) {
    if(i%2 == 0){
      if(s[i] == 'p') ans--;
    }
    else{
      if(s[i] == 'g') ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main( ){
  int x,y,z;
  scanf("%d %d %d",&x,&y,&z);
  if(x>=y&&y>=z){printf("%d %d %d\n",z,y,x);
  } else if(x>=z&&z>=y){printf("%d %d %d\n",y,z,x);
  } else if(y>=x&&x>=z){printf("%d %d %d\n",z,x,y);
  } else if(z>=x&&x>=y){printf("%d %d %d\n",y,x,z);
  } else if(y>=z&&z>=x){printf("%d %d %d\n",x,z,y);
  } else{printf("%d %d %d\n",x,y,z);  
  }
  return 0;
}   
 

Measured memory_bytes: 596
#include<stdio.h>
#include <stdlib.h>

typedef struct {
    int a;
    int num;
    char type;
} CARD;

void Qsort(CARD *,int,int);
int partition(CARD *,int,int);

int main(){
    int n,i,sta=0;
    CARD *A;
    scanf("%d",&n);

    A = (CARD *) malloc (sizeof(CARD)*n);

    for(i=0;i<n;i++) {
        scanf(" %c",&A[i].type);
        scanf("%d",&A[i].a);
        A[i].num=i;
    }

    Qsort(A,0,n-1);

    for(i=0;i<n-1;i++) if(A[i].a==A[i+1].a && A[i].num > A[i+1].num) sta=-1;
    if(sta==-1) printf("Not stable\n");
    else printf("Stable\n");

    for(i=0;i<n;i++) printf("%c %d\n",A[i].type,A[i].a);

    return 0;    
}

void Qsort(CARD *A,int p,int r){
    int q,i;

    if(p<r){
        //for(i=0;i<=r;i++) printf("%c%d ",A[i].type,A[i].a); printf("\n");
        q=partition(A,p,r);
        Qsort(A,p,q-1);
        Qsort(A,q+1,r);
        //for(i=0;i<=r;i++) printf("%c%d ",A[i].type,A[i].a); printf("\n");
    }

}
int partition(CARD *A,int p,int r){
    int i,j;
    CARD sw;
   i=p-1;

    for(j=p;j<r;j++){
        if(A[j].a <= A[r].a) {
            i++;
            sw=A[i];
            A[i]=A[j];
            A[j]=sw;
        }
    }

    sw=A[i+1];
    A[i+1]=A[r];
    A[r]=sw;

    return i+1;
}



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

// 1 way is to find compute all the sorted permutations and find the 
// positions of the current permutation.

int powerOfTwo(int n){
    int cnt=0;
    while(n%2==0 and n>0){
        cnt++;
        n/=2;
    }
    return cnt;
}

int _find(vi &arr,int n){
    if(n==0){return 0;}
    int ans=powerOfTwo(arr[0]);
    for(int i=1;i<n;i++){
        ans=min(ans,powerOfTwo(arr[i]));
    }
    return ans;
}
void solve(){
    int n;
    cin>>n;
    vi arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    cout<<_find(arr,n)<<endl;
}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3616
n = int(input())
a = [[-1for _ in range(n)]for _ in range(n)]

ans = 0

for i in range(n):
  m = int(input())
  for j in range(m):
    x,y = map(int,input().split())
    a[i][x-1] = y

for i in range(2**n):
  #bit全探索
  #d:正直者と仮定してる人
  d = []
  p = len(bin(i))
  q = bin(i)
  for j in range(p-2):
    q = bin(i>>j)
    if int(q[len(q)-1]) == 1:
      d.append(j)
  
  res = True
  for j in d:
    for k in range(n):
      #jさんがkさんの事を正直者だと思ってた時
      if a[j][k] == 1:
        if k not in d:
          res = False
      #jさんがkさんのことを不親切な人と思ってた時
      elif a[j][k] == 0:
        if k in d:
          res = False
  if res:
    ans = max(ans,len(d))

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int  long long
#define endl '\n'
int mod=1e9+7;
int p(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
            res*=a;
        res%=mod;
        a*=a;
        a%=mod;
        b/=2;
    }
    return res;
}
int modinv(int x)
{
    return p(x,mod-2);
}
int32_t main()
{
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    int fact[200000];
    fact[0]=1;
    for(int i=1;i<200000;i++)
        fact[i]=(fact[i-1]*i)%mod;
    int mx=0,mi=0;
    for(int i=0;i<n;i++)
    {
        int poss=n-i-1;
        if(poss<k-1)
            break;
        int num=fact[poss];
        int den=fact[k-1]*fact[poss-k+1];
        den%=mod;
        den=modinv(den);
        int curr=(num*den)%mod;
        curr=(curr*(v[i]+mod))%mod;
        mi+=curr;
        mi%=mod;
    }
    for(int i=n-1;i>=0;i--)
    {
        int poss=i;
        if(poss<k-1)
            break;
        int num=fact[poss];
        int den=fact[k-1]*fact[poss-k+1];
        den%=mod;
        den=modinv(den);
        int curr=(num*den)%mod;
        curr=(curr*(v[i]+mod))%mod;
        mx+=curr;
        mx%=mod;
    }
    cout<<(mx-mi+mod)%mod;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int a, b;
    char op;
    cin >> a >> op >> b;
    if(op == '+'){
        cout << a+b << endl;
    }else{
        cout << a-b << endl;
    }
    return 0;
}

Measured memory_bytes: 256