akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 60
#else
#define SIZE 60
#endif

int N,K;
int DP[SIZE][SIZE][SIZE*SIZE];
int MOD=1e9+7;

void solve() {
    cin>>N>>K;
    
    DP[0][0][0] = 1;
    DP[0][1][2] = 1;
    FOR(i,1,N)REP(j,N+1)REP(k,N*N+1) {
        if (k-2*j < 0) continue;
        (DP[i][j][k] += (2*j+1) * DP[i-1][j][k-2*j]) %= MOD;
        (DP[i][j][k] += (j+1)*(j+1) * DP[i-1][j+1][k-2*j]) %= MOD;
        if (j) {
            (DP[i][j][k] += DP[i-1][j-1][k-2*j]) %= MOD;
        }
    }
    
    cout << DP[N-1][0][K] << endl;
}

Measured memory_bytes: 84480
import sys

readline = sys.stdin.readline

def main():
    n = int(input())
    A = [int(i) for i in readline().split()]
    q = int(input())
    m = list(map(int, readline().split()))

    #print(A)

    sumarray = []
    for i in range(2 ** n):
        select = []
        for j in range(n):
            if (i >> j) & 1:
                select.append(A[j])
        #print(select)
        sumarray.append(sum(select))

    #print(sumarray)
    #print(m)

    for k in [x in sumarray for x in m]:
        #print(k)
        if k:
            print('yes')
        else:
            print('no')


if __name__ == "__main__":
    main()



Measured memory_bytes: 43088
from operator import itemgetter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)
        self.rank = [0] * (n + 1)

    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def size(self, x):
        return -self.root[self.find(x)]


N = int(input())
uf = UF_tree(N)
pos = []
for i in range(N):
    x, y = map(int, input().split())
    pos.append((x, y, i))

inf = N + 10  # 番兵

# x方向に走査
stack = [(inf, N)]
pos.sort()
for _, y, i in pos:
    while stack[-1][0] < y:
        _, j = stack.pop()
        uf.unite(j, i)
    stack.append((y, i))
stack = [(-inf, N)]
for _, y, i in pos[::-1]:
    while stack[-1][0] > y:
        _, j = stack.pop()
        uf.unite(i, j)
    stack.append((y, i))


# y方向に走査
stack = [(inf, N)]
pos.sort(key=itemgetter(1))
for x, _, i in pos:
    while stack[-1][0] < x:
        _, j = stack.pop()
        uf.unite(i, j)
    stack.append((x, i))
stack = [(-inf, N)]
for x, _, i in pos[::-1]:
    while stack[-1][0] > x:
        _, j = stack.pop()
        uf.unite(i, j)
    stack.append((x, i))

for i in range(N):
    print(uf.size(i))

Measured memory_bytes: 122200
#include <stdio.h>
#include <algorithm>
using namespace std;

main(){
	int a[300];
	int n;
	scanf("%d",&n);
	for(int i=0;i<2*n;i++)scanf("%d",&a[i]);
	sort(a,a+2*n);
	int ans=0;
	for(int i=0;i<2*n;i+=2)ans+=a[i];
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    long long int a[n+1];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    long long int sum=0;
    if(n>k)
    {
        for(int i=0;i<n-k;i++)
        {
            sum+=a[i];
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1792
N=int(input())
A=[0]*(10**5+1)
b=input().split()
numbers=[int(a) for a in b]
for a in numbers:
    A[a]+=1
list=[]
for z in range(10**5-1):
    y=A[z]+A[z+1]+A[z+2]
    list.append(y)
print(max(list))


Measured memory_bytes: 15500
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pf push_front
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("board.in");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main() {
    fast;
    ll a; cin>>a;
    vec<pll> m(a);
    for(int q=0;q <a; q++) cin>>m[q].F>>m[q].S;
    sort(m.begin(), m.end(), [](pll p1, pll p2){return p1.S<p2.S;});
    int fl =1;
    ll s=0;
    for(int q=0; q<a; q++){
        s+=m[q].F;
        fl&=s<=m[q].S;
    }
    if(fl) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3456
#include<iostream>
#include<cstdio>
#include<math.h>
#include<cstring>
using namespace std;
const int MAXN = 210000;
bool flag[MAXN];
int primes[MAXN / 3], pi;
void GetPrime_2()
{
    int i, j;
    pi = 0;
    memset(flag, false, sizeof(flag));
    for (i = 2; i < MAXN; i++)
    {
        if (!flag[i])
            primes[pi++] = i;
        for (j = 0; (j < pi)  && (i * primes[j] < MAXN); j++)
        {
            flag[i * primes[j]] = true;
            if (i % primes[j] == 0)
                break;
}
    }
}
int main()
{
    int q,n,m,i,s[100005],res;
    flag[0]=1;
    GetPrime_2();
    //for(i=1;i<=100;i++) cout<<i<<"     "<<flag[i]<<endl;
    for(i=3;i<=100000;i++)
        if(!flag[i]&&!flag[(i+1)/2]) s[i]=s[i-1]+1;
        else s[i]=s[i-1];
        scanf("%d",&q);
        while(q--)
        {
              scanf("%d%d",&n,&m);
              res=s[m]-s[n-1];

              //for(i=n;i<=m;i++)
       // if(flag[i]==0&&flag[(i+1)/2]==0) printf("%d  %d\n",i,(i+1)/2);



        printf("%d\n",res);
        }
}


Measured memory_bytes: 1280
#include<stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	if(a<b&&b<c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2680
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll a, b;
    char op;
    cin >> a >> op >> b;
    cout << (op == '+' ? a + b : a - b) << endl;
}


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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> Tree;

#define dbg(x) cout<<#x<<"="<<x<<'\n'
#define ll long long
#define pr pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define For(i,n,a) for(int i=a;i<(n);++i)
#define Forr(i,n) for(int i=n-1;i>=0;i--)
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#define fin ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define sz(a) (int)a.size()
#define Fill(a,b) memset(a,b,sizeof(a));
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
const int INF=1e9;

void solve(){
	int n;
	ll W;
	cin>>n>>W;
	ll w[n];
	int v[n];int tot=1000004;
	for(int i=0;i<n;i++) cin>>w[i]>>v[i];
	vector<vector<ll>> dp(n+1,vector<ll>(tot+1,100100100100100));
	//memset(dp,100100100100100LL,sizeof(dp));
	//cout<<tot<<endl;
	dp[0][0]=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=tot;j++){
			if(j-v[i-1]<0)dp[i][j]=dp[i-1][j];
			else dp[i][j]=min(dp[i-1][j-v[i-1]]+w[i-1],dp[i-1][j]);
		}
	}
	while(dp[n][tot]>W)tot--;
	cout<<tot<<endl;

    	
}



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

Measured memory_bytes: 800456
#include<stdio.h>
int main()
{
  int a,b;
  char op;
  while(1)
    {
  scanf("%d %c %d",&a, &op, &b);
  if(op=='+')
    {
      printf("%d\n",a+b);
    }
  else if(op=='-')
    {
      printf("%d\n",a-b);
    }
  else if(op=='*')
    {
      printf("%d\n",a*b);
    }
  else if(op=='/')
    {
      printf("%d\n",a/b);
    }
  else
    { break;}
    }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define int long long
#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 inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)
template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N;
map<string,int>mp;
signed main() {
	cin>>N;
	rep(i,N){
		string s;cin>>s;
		mp[s]++;
	}
	vector<string>ans;
	int mx=0;
	for(auto p:mp){
		if(p.second==mx){
			ans.push_back(p.first);
		}else if(p.second>mx){
			ans.clear();ans.push_back(p.first);
			mx=p.second;
		}
	}
	sort(all(ans));
	for(string s:ans)cout<<s<<endl;
}


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

int main() {
  long long h, w, n;
  cin>>h>>w>>n;
  pair<int, int> ab[n];
  for (int i=0; i<n; i++) cin>>ab[i].first>>ab[i].second;
  sort(ab, ab + n);
  set<pair<int, int>> s;
  for (auto p: ab) {
    int x = p.second;
    int y = p.first;
    for (int i=-2; i<3; i++) {
      for (int j=-2; j<3; j++) {
        int xk = x + i;
        int yk = y + j;
        if (xk > 1 && xk < w && yk > 1 && yk < h) {
          s.insert(make_pair(yk, xk));
        }
      }
    }
  }
  long long cnt[10];
  for (int i=0; i<10; i++) cnt[i] = 0;
  cnt[0] = (h - 2) * (w - 2);
  for (auto p: s) {
    int x = p.second;
    int y = p.first;
    int tmp = 0;
    for (int i=-1; i<2; i++) {
      for (int j=-1; j<2; j++) {
        if (binary_search(ab, ab + n, make_pair(y+i, x+j))) {
          ++tmp;
        }
      }
    }
    ++cnt[tmp];
    --cnt[0];
  }
  for (long long i: cnt) {
    cout<<i<<endl;
  }
}

Measured memory_bytes: 118272
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
// #define req(j, n) for (ll j = 1; j < (n+1); j++)
// #define rer(k, n) for (ll k = 1; k < (n+1); k++)


int main()
{
    ll N, K;
    cin >> N >> K;
    ll arr[N];
    vector<int> A(N, 0);
    ll d;
    ll n;
    rep(i, K) {
        cin >> d;
        rep(j, d) {
            cin >> n;
            A[n-1] += 1;
            // cout << A[1] << endl;
        }
    }
    // cout << "OK" << endl;
    ll people = 0;
    rep(k, N) {
        if (A[k] == 0) {
            // cout << arr[k] << endl;
            people += 1;
        }
    }
    cout << people << endl;
}



Measured memory_bytes: 3192
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

if sum(A) < sum(B):
    print(-1)
    exit()

s = 0
cnt = 0
delta = []
for i in range(N):
    if A[i] < B[i]:
        cnt += 1
        s += B[i] - A[i]
    else:
        delta.append(A[i] - B[i])
n = 0
for d in sorted(delta, reverse=True):
    if n < s:
      n += d
      cnt += 1
    else:
        break
print(cnt)


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

int main()
{
    int x, n;
    cin >> x >> n;
    
    vector<int> p(n);
    rep(i, n) cin >> p.at(i);

    if (n == 0) {
        cout << x << endl;
        return 0;
    }

    int i = 0;
    while(1){
        int flag1 = 0, flag2 = 0;
        rep(j, n) {
            if (x - i == p.at(j)) {
                flag1++;
            }
            if (x + i == p.at(j)) {
                flag2++;
            }
        }

        if (flag1 == 0) {
            cout << x - i << endl;   
            return 0;
        }

        if (flag2 == 0) {
            cout << x + i << endl;
            return 0;
        }
        i++;
    }
}

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

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    if (k <= a) {
        cout << a - k << " " << b << endl;
    } else if (k <= a + b) {
        cout << 0 << " " << b - (k - a) << endl;
    } else {
        cout << 0 << " " << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
import sys

def min_coins(N, M, ws):
    dp = [-(1 << 32)] * (N + 1)
    dp[0] = 0
    
    for i in range(M):
        for j in range(ws[i], N + 1):
            dp[j] = max(dp[j - ws[i]] - 1, dp[j])
    
    
    return abs(dp[-1])
    
    
if __name__ == '__main__':
    N = sys.stdin.readline()
    N, M = N.split()
    N, M = int(N), int(M)
    arr = sys.stdin.readline()
    arr = arr.split()
    arr = map(lambda x: int(x), arr)
    
    sys.stdout.write(str(min_coins(N, M, arr)))
    sys.stdout.write('\n')
    

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

int go[100000];

int main()
{
	int n;
	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++){
			scanf("%d", &go[i]);
			
			int p = i - 1;
			if (i % 2 == 1){
				while (p >= 0 && go[i] != go[p]){
					go[p] = go[i];
					p--;
				}
			}
		}
		
		int cnt = 0;
		for (int i = 0; i < n; i++){
			cnt += !go[i];
		}
		
		printf("%d\n", cnt);
	}
	
	return 0;
}

Measured memory_bytes: 1576
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
    ll n,k;
    cin>>n>>k;
    ll res=0;
    while(n>0)
    {
        n/=k;
        res++;
    }
    cout<<res<<"\n";
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 3584
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;
ll T,n,m;
int main() {
	cin>>n;
	if(n%2==0){
		printf("%.8f\n",0.5);
	}
	else {
		double t = n;
		printf("%.8f\n",((t+1)/2)/t);
	}
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

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

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a[15],x[15][15],y[15][15];

int main(void){
	int i,j,k,n,ans=0,tmp;
	bool flag;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
		for(j=0; j<a[i]; ++j){
			cin >> x[i][j] >> y[i][j];
			--x[i][j];
		}
	}
	for(i=0; i<(1<<n); ++i){
		tmp = 0; flag = true;
		for(j=0; j<n; ++j){
			if(!(i&(1<<j))){
				continue;
			}
			++tmp;
			for(k=0; k<a[j]; ++k){
				if(((i>>x[j][k])&1)==y[j][k]){
					continue;
				}
				flag = false;
				break;
			}
			if(!flag){
				break;
			}
		}
		if(flag){
			ans = max(ans,tmp);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
     

int main() {
  ll x,y,z=0,k,n,m,h,w,ans=0,sum=0,Max=-1,Min=1e9+1;
  bool ok = true;
  string s,t,r;
  cin >> n;
  rep(i,n+1){
    if(i%3 != 0 && i%5 != 0){
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
)

func max(a, b int) int {
	if a > b {
		return a

	}
	return b
}
func main() {
	var a, b int
	fmt.Scan(&a, &b)

	fmt.Println(max(max(a+b, a-b), a*b))
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}


void solve()
{
  ll a, b; cin >> a;
  string s; cin >> s;
  b = (s[0]-'0') * 100 + (s[2]-'0')*10 + (s[3]-'0');
  
  ll ans = 0;
  ans = a * b;
  cout <<( ans / 100) << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 3640
from collections import deque
N = int(input())
S = input()
W = deque([])
R = deque([])

for i in range(N):
    if S[i] == "W":
        W.append(i)
    else:
        R.appendleft(i)
#print(W)
#print(R)
ans = 0
while W and R:
    w = W.popleft()
    r = R.popleft()
    if w > r:
        break
    ans += 1
print(ans)

Measured memory_bytes: 68616
#include<stdio.h>
#include<string.h>
int main(){
  char s[33],d[1000][33];
  int r=0,i,ml,mi,l=0,max=0,b[1000]={0};
  while(~scanf("%s",s)){
    for(i=0;i<r;i++){
      if(strcmp(s,d[i])==0)break;
    }
    if(i-r){
      b[i]++;
      if(max<b[i])max=b[mi=i];
    }
    else{
      b[r]=1;
      strcpy(d[r++],s);
      if(strlen(s)>l)l=strlen(d[ml=r-1]);
    }
  }
  printf("%s %s\n",d[mi],d[ml]);
  return 0;
}

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

#define ll long long
#define F first
#define S second

const int mod = 1000000007;
const int M = 100005;

ll dp[105][M];

int main() {
	int T = 1;
	// cin>>T;
	while(T--)
	{
		int n,m;	cin>>n>>m;
		char mat[n][m];
		
		for(int i=0; i<n; i++)
		{
			for(int j=0; j<m; j++)
				cin>>mat[i][j];
		}
		
		int dp[n][m];
		
		if(mat[0][0]!='#')
			dp[0][0] = 1;
		
		for(int i=0; i<n; i++)
		{
			for(int j=0; j<m; j++)
			{
				if(i==0 && j==0)	continue;
				if(mat[i][j]!='#'){
				int u = 0;
				int l = 0;
				
				if(i-1>=0)	u = dp[i-1][j];
				if(j-1>=0)  l = dp[i][j-1];
				
				dp[i][j] = (u%mod + l%mod)%mod; }
				else	dp[i][j] = 0;
			}
		}
		
		cout<<dp[n-1][m-1];
	}
	return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>

int main(void)
{
  int num;
  scanf("%d",&num);

  int i,a[num];
  for(i=0;i<num;i++)
    scanf("%d",&a[i]);

  int tmp,j;
  for(i=0;i<num;i++){
    for(j=num-1;j>i;j--){
      if(a[j-1]>a[j]){
        tmp=a[j-1];
        a[j-1]=a[j];
        a[j]=tmp;
      }
    }
  }

  double ans=(double)a[0];
  for(i=1;i<num;i++){
    ans=(ans+a[i])/2;
  }

  printf("%f\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cctype>

using namespace std;

#define REP(i,n) for(int i = 0;i < n;i++)
	
int main()
{
	int n,r;
	while(cin >> n >> r,n)
	{
		vector<int> v;
		REP(i,n)
		{
			v.push_back(i+1);
		}
		REP(i,r)
		{
			int p,c;
			cin >> p >> c;
			vector<int> tmp;
			REP(j,c)
			{
				tmp.push_back(v[v.size()-p-j]);
			}
			v.erase(v.end()-p-c+1,v.end()-p+1);
			REP(j,c)
			{
				v.push_back(tmp[tmp.size()-j-1]);
			}
		}
		
		cout << v.back() << endl;
		
	}
	
	return 0;
}
			

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

int main(){
  string S;
  cin >> S;
  if(S.size()==2){
    cout << S << endl;
    return 0;
  }
  for(int i=S.size()-1; i>=0; i--){
    cout << S[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
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; }
using namespace std;

//竸プロは楽しい！！！！！！！！
//AtCoderさんいつもありがとうございます！！！！！！！！
signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    reverse(all(a));

    multiset<int> st;
    st.insert(-1);
    int ans=0;
    rep(i,n){
        auto it=st.upper_bound(a[i]);
        if(it==st.end()){
            ans++;
            st.insert(a[i]);
        }else{
            st.erase(it);
            st.insert(a[i]);
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 5760
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
for(var i=0;i<n;i++){
   var arr=Arr.shift().split(" ").map(Number);
   (function(x1, y1, x2, y2, x3, y3, x4, y4){
      var k1=(y2-y1)/(x2-x1);
      var k2=(y4-y3)/(x4-x3);
      k1=k1.toFixed(6);
      k2=k2.toFixed(6);
      console.log((k1==k2)?"YES":"NO");
   }).apply(null,arr);
}

Measured memory_bytes: 7644
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
  int x;
	cin >> x;
	if (x == 2) {
		cout << 2 << endl;
		return 0;
	}
	if (x % 2 == 0)	x++;
	bool f = true;
	while (f) {
		f = false;
		for (int i = 3; i <= sqrt(x); i += 2) {
			if (x % i == 0) {
				x += 2;
				f = true;
				break;
			}
		}
	}
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int n;
  string a;
  cin >> n >> a;
  int ans = 0;
  repm(i, 1, n){
    int cnt = 0;
    for (char c = 'a'; c <= 'z'; c++){
      bool l = false, r = false;
      rep(j, i) if (a.at(j) == c) l = true;
      repm(j, i, n) if (a.at(j) == c) r = true;
      if (l && r) cnt++;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var A, B int
	fmt.Scanln(&A, &B)

	var ans int
	if 6 <= A && A <= 12 {
		ans = B / 2
	} else if 12 < A {
		ans = B
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import Control.Applicative
import Control.Monad
import Data.List

comb :: Int -> Int -> Int
comb n r = iterate (scanl1 (+)) [1, 1 ..] !! (n - r) !! r

main :: IO ()
main = do
    [n, p] <- fmap read . words <$> getLine :: IO [Int]
    as <- fmap read . words <$> getLine :: IO [Int]
    let bs = fmap (`mod` 2) as
    let x = length $ filter (== 0) bs
    let y = length $ filter (== 1) bs
    let ax = [comb x i | i <- [0 .. x]]
    let ay = if even p
             then [comb y i | i <- [0, 2 .. y]]
             else [comb y i | i <- [1, 3 .. y]]
    print (sum ax * sum ay)

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

vector<int>v;
int main()
{
    int n,m,j,k,i,T,x;
    while (cin>>n)
    {
        for (i=0;i<n;i++)
        {
            cin>>x;
            v.push_back(x);
        }
        while (v.size()>=2)
        {
            vector<int>::iterator it;
            sort(v.begin(),v.end());
            for (i=1;i<v.size();i++)
            {
                v[i] = v[i] % v[0];
                if (v[i]<=0)
                v.erase(v.begin()+i);
            }

        }
            cout<<v[0]<<endl;
            v.clear();
    }


	return 0;
}


Measured memory_bytes: 892
def dfs(i,s):
    if i==n-1:
        return sum(map(int,s.split('+')))
    return dfs(i+1,s+S[i+1])+dfs(i+1,s+'+'+S[i+1])

S=input()
n=len(S)
ans=dfs(0,S[0])
print(ans)

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

int main()
{
	int N, H, max = 0, count = 0, a[100001], b[100001];

	cin >> N >> H;

	for (int i = 1; i <= N; i++)
	{
		cin >> a[i] >> b[i];
  
		if (a[i] > max)
		{
			max = a[i];
		}
	}
	
	sort(b + 1, b + N + 1);

	for (int i = N; i >= 1; i--)
	{
		if (b[i] > max)
		{
			H -= b[i];
			count++;
		}

		if (H <= 0)
		{
			cout << count << endl;
			return 0;
		}
	}

	int j = 1;
	while (H - j * max > 0)
	{
		j++;
	}

	cout << count + j << endl;
}

Measured memory_bytes: 1024
# ABC064C - Colorful Leaderboard
from collections import Counter


def main():
    n = int(input())
    C = Counter(map(lambda x: int(x) // 400, input().split()))
    colored = sum(i < 8 for i in C.keys())  # rate: <3200
    free = sum(j for i, j in C.items() if i >= 8)  # ≥3200
    x, y = max(1, colored), colored + free  # min, max
    print(x, y)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    ll a;
    long double b;
    cin >> a >> b;
    cout << (ll)floor(a * b) << endl;
    return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

constexpr auto M = 5000L;

void dijkstra(const vector<vector<pair<int64_t, pair<int64_t, int64_t>>>>& adjs,
              const vector<pair<int64_t, int64_t>>& cd,
              vector<vector<int64_t>>& costs, int64_t s) {
    using Entry = std::tuple<int64_t, int64_t, int64_t>;

    priority_queue<Entry, vector<Entry>, std::greater<>> q;

    costs[0][min(s, M)] = 0;
    q.emplace(0L, 0L, min(s, M));

    while (!q.empty()) {
        auto [cost, v, money] = q.top();
        q.pop();

        if (costs[v][money] < cost) {
            continue;
        }

        {
            auto next_money = min(money + cd[v].first, M);
            auto next_cost = cost + cd[v].second;

            if (next_cost < costs[v][next_money]) {
                costs[v][next_money] = next_cost;
                q.emplace(next_cost, v, next_money);
            }
        }

        for (const auto& link : adjs[v]) {
            auto u = link.first;

            auto next_money = min(money - link.second.first, M);
            if (next_money < 0) {
                continue;
            }

            auto next_cost = cost + link.second.second;

            if (next_cost < costs[u][next_money]) {
                costs[u][next_money] = next_cost;
                q.emplace(next_cost, u, next_money);
            }
        }
    }
}

int main() {
    int64_t n, m, s;
    cin >> n >> m >> s;

    vector adjs(n, vector<pair<int64_t, pair<int64_t, int64_t>>>());
    for (auto _ : irange(0L, m)) {
        int64_t u, v, a, b;
        cin >> u >> v >> a >> b;
        --u;
        --v;
        adjs[u].emplace_back(v, make_pair(a, b));
        adjs[v].emplace_back(u, make_pair(a, b));
    }

    vector cd(n, make_pair(0L, 0L));
    for (auto&& t : cd) {
        cin >> t.first >> t.second;
    }

    vector costs(n, vector(M + 1L, numeric_limits<int64_t>::max()));
    dijkstra(adjs, cd, costs, s);

    for (auto i : irange(1L, n)) {
        cout << *min_element(costs[i].begin(), costs[i].end()) << "\n";
    }
}

Measured memory_bytes: 11420
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>	
#include<limits>
#include<ctime>
#include<stack>	
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
	
typedef long long ll;
using namespace std;
const ll x=1000000007;
int mod(ll a){
	return a%x;
}

int main(){
	map<string,int> a;
	int n,m,maks=0;
	cin>>n;
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		a[s]++;
		cout<<endl;
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>s;
		a[s]--;
		cout<<endl;
	}
	for(map<string,int>:: iterator i=a.begin();i!=a.end();i++){
		maks=max(maks,i->second);
	}	
	cout<<maks;
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)

int main(){
    int n,c,k;
    cin>>n>>c>>k;
    vector<ll> t(n+1,INF);
    REP(i, n) cin >> t[i];
    sort(t.begin(),t.end());

    int ans = 0;
    int left = 0;
    int right = 1;
    int jouin = 1;

    while(left < n){
        if(t[left] + k >= t[right] && jouin < c){
            jouin++;
            right++;
        }
        else{
            ans += (jouin+c-1)/c;
            left = right;
            right++;
            jouin = 1;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1024
import numpy as np
import decimal

a, b, h, m = map(int, input().split())

### 短針について
h = (h /12) * 360 + 0.5 * m
### 長針について
m = (m / 60) * 360

x = 360 - abs(h-m)
y = abs(h-m)
x = min(x,y)

ans = float(np.sqrt(a**2 + b**2 - 2*a*b*np.cos(np.radians(x))))

print('{:.11f}'.format(ans))


Measured memory_bytes: 27200
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver() ? "Yes" : "No");
        }
        static bool solver()
        {
            var A = new int[3, 3];
            var isHit = new bool[3, 3];
            for (int i = 0; i < 3; i++)
            {
                var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                for (int j = 0; j < 3; j++)
                {
                    A[i, j] = read[j];
                    isHit[i, j] = false;
                }

            }
            var N = int.Parse(Console.ReadLine());
            for (int i = 0; i < N; i++)
            {
                var read = int.Parse(Console.ReadLine());
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (A[j, k] == read) isHit[j, k] = true;
                    }
                }
            }

            for (int h = 0; h < 3; h++)
            {
                var result = true;
                for (int v = 0; v < 3; v++)
                {
                    if (!isHit[h, v])
                    {
                        result = false;
                        break;
                    }
                }
                if (result) return true;
            }
            for (int v = 0; v < 3; v++)
            {
                var result = true;
                for (int h = 0; h < 3; h++)
                {
                    if (!isHit[h, v])
                    {
                        result = false;
                        break;
                    }
                }
                if (result) return true;
            }
            if (isHit[0, 0] && isHit[1, 1] && isHit[2, 2]) return true;
            if (isHit[2, 0] && isHit[1, 1] && isHit[0, 2]) return true;
            return false;
        }
    }
}


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

using namespace std;


typedef long long ll;

const int M = 1e9+7 ;


int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    vector<int> A = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

    int k ;
    cin >> k ;

    cout << A[k-1 ] << "\n";

    return 0;
}



Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
    int Q;

    cin >> Q;

    int l[Q], r[Q];
    for(int i=0;i<Q;i++){
        cin >> l[i] >> r[i];
    }

    int K[100000+1];
    int a[100000+1];
    
    for(int i=0;i<=100000;i++){
        K[i] = 1;
        a[i] = 0;
    }
    K[0] = K[1] = 0; 
    for(int i=2;i<=100000;i++){
        if(K[i]){
            for(int j=i+i;j<=100000;j=j+i){
                K[j] = 0;
            }
        }
    }
    for(int i=2;i<=100000;i++){
        if(K[i]==1 and K[(i+1) /2]==1){
            a[i] = 1;
        }
        else{
            a[i] = 0;
        }
    }
    for(int i=2;i<=100000;i++){
        a[i] = a[i] + a[i-1];
    }
    
    for(int q=0;q<Q;q++){
        int ans = 0;
        ans = a[r[q]] - a[l[q]-1];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
N = gets.to_i
s = gets.strip.each_char.collect{|c| c == "o"}

[
	[true, false],
	[true, true],
	[false, true],
	[false, false],
].each{|first, last|
	
	pre = last
	cur = first
	list = []
	s.each{|c|
		list << cur
		n = pre ^ c ^ cur
		pre = cur
		cur = n
	}
	if cur == first && pre == last
		puts list.collect{|c| c ? "S" : "W"}.join
		exit
	end
}

puts "-1"


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

const int max_n = 1e5 + 5;

lint dp[max_n];

int main () {
	dp[0] = 0;
	make2(n, W);
	FOR(i,0,n) {
		make2(w, v);
		FORD(j,W-w,0) {
			dp[j+w] = max(dp[j]+v, dp[j+w]);
		}
	}
	lint ans = 0;
	FOR(i,0,W+1) ans = max(ans, dp[i]);
	printf("%lld\n", ans);
}	





Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, w;
    cin >> n >> w;
    vector<int> v(n);
    vector<int> u(n);
    REP(i, n) cin >> v[i] >> u[i];

    vector<vector<int>> dp(n + 1, vector<int>(w + 1, 0));

    REP(i, n) {
        REP(j, w + 1) {
            chmax(dp[i + 1][j], dp[i][j]);
            if (j - u[i] >= 0) chmax(dp[i + 1][j], dp[i][j - u[i]] + v[i]);
        }
    }
    int ans = 0;
    REP(i, w + 1) chmax(ans, dp[n][i]);
    cout << ans << endl;
}



Measured memory_bytes: 6832
#include<stdio.h>
int main(){
long n,a,b,ans;
scanf("%ld%ld%ld",&n,&a,&b);
if(n==1){
if(a==b)
ans=1;
else
ans=0;
}
else{
if(a>b)
ans=0;
else
ans=(n-2)*(b-a)+1;
}
printf("%ld\n",ans);
return 0;
}


Measured memory_bytes: 128
class UnionFindTree:
    '''
    Union Find木の実装
    ランクは無視する
    '''
    
    def __init__(self, n):
        '''ノード数nで初期化'''
        # nodes[i] < 0 すなわち各ノードは自身が根
        # 根の値はその木の要素数の符号反転したもの
        self.nodes = [-1] * n

    def is_root(self, idx):
        '''根ならTrue、根以外ならFalse'''
        return self.nodes[idx] < 0
        
    def is_same_group(self, idxA, idxB):
        return self.root(idxA) == self.root(idxB)
    
    def size(self, idx):
        '''ノードを含むグループのノード数を返す'''
        return -self.nodes[self.root(idx)]

    def union(self, idxA, idxB):
        '''ノードAを含む木とノードBを含む木を結合'''
        a = self.root(idxA)
        b = self.root(idxB)

        size_a = self.size(idxA)
        size_b  =self.size(idxB)

        # b番目のノードの根をaにする
        if a != b:
            self.nodes[b] = a
        self.nodes[a] -= size_b
    
    def root(self, idx):
        '''ノードの根番号を返す。途中で経路圧縮を行う'''
        
        # 探索
        _idx = idx
        while not self.is_root(_idx):
            _idx = self.nodes[_idx]
        root_idx = _idx

        # 経路圧縮
        _idx = idx
        while root_idx != _idx:
            tmp = _idx
            _idx = self.nodes[_idx]
            self.nodes[tmp] = root_idx

        return root_idx
###========================

N, M = map(int, input().split())
A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


tree = UnionFindTree(N)

hubensa_list = [None] * M
hubensa_list[M-1] = N * (N-1) // 2

for i in range(M-2, -1, -1):
    if tree.is_same_group(A[i+1]-1, B[i+1]-1):
        hubensa_list[i] = hubensa_list[i+1]    
    else:
        sa = tree.size(A[i+1]-1)
        sb = tree.size(B[i+1]-1)
        hubensa_list[i] = hubensa_list[i+1] - sa * sb
        tree.union(A[i+1]-1, B[i+1]-1)

for x in hubensa_list:
    print(x)

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

using ll=long long;

int main() {
  int N,H,W; cin >>N >>H >>W;
  int ans=0;
  rep(i,0,N) {
    int A,B; cin >>A >>B;
    if (A>=H and B>=W) {
      ans++;
    }
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)

using namespace std;
typedef long long ll;

int main(){
    int N,M,C;
    int B[20];
    cin>>N>>M>>C;
    rep(i,M){
        cin>>B[i];
    }
    int ans = 0;
    rep(n,N){
        ll temp = C;
        rep(i,M){
            int A;
            cin>>A;
            temp += A*B[i];
        }
        if(temp>0){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
A = [[int(i) for i in input().split()] for j in range(3)]
N = int(input())
B = [int(input()) for j in range(N)]

for b in B:
    for row in range(3):
        for col in range(3):
            if A[row][col] == b:
                A[row][col] = 0

cond = [
    A[0][0] == A[0][1] and A[0][1] == A[0][2],
    A[1][0] == A[1][1] and A[1][1] == A[1][2],
    A[2][0] == A[2][1] and A[2][1] == A[2][2],
    A[0][0] == A[1][0] and A[1][0] == A[2][0],
    A[0][1] == A[1][1] and A[1][1] == A[2][1],
    A[0][2] == A[1][2] and A[1][2] == A[2][2],
    A[0][0] == A[1][1] and A[1][1] == A[2][2],
    A[0][2] == A[1][1] and A[1][1] == A[2][0]
]
print('Yes' if any(cond) else 'No')

Measured memory_bytes: 3064
// 未解決

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
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 in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

//***** basic func *****//
int power_mod(int a, int b) {
  // return (a**b)%MOD (O(log b))
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res *= a;
      res %= MOD;
    }
    a *= a;
    a %= MOD;
    b >>= 1;
  }
  return res;
}

// int fact[510000], fact_inv[510000];  // n!, (n!)^-1 mod MOD
// // calc fact (in main routine)
// fact[0] = 1;
// REP(i, n) { fact[i + 1] = fact[i] * (i + 1) % MOD; }
// fact_inv[n] = power_mod(fact[n], MOD - 2);
// RREP(i, n) { fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD; }
// int comb_mod(int n, int r) {
//   return ((fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD);
// }

//**********

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

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> req;
  int a, b;
  REP(i, m) {
    cin >> a >> b;
    req.pb(mp(b, a));
  }

  sort(ALL(req));

  int ans = 0;
  int last_pos = 0;
  REP(i, m) {
    if (req[i].S < last_pos) {
      continue;
    } else {
      ans += 1;
      last_pos = req[i].F;
    }
  }

  cout << ans << endl;

  return 0;
};


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

    int ans;
    if(d == 0){
        if(n == 100)
            ans = 101;
        else
            ans = 1 * n;
    }
    else{
        if(n == 100)
            ans = pow(100, d) * (n+1);
        else
            ans = pow(100, d) * n;
    }
    cout << ans; 

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
	int a[100],b,n,m,ma,cnt;
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0&&m==0)break;
		ma=cnt=0;
		for(int i=0;i<100;i++)a[i]=0;
		for(int i=0;i<n;i++)for(int j=0;j<m;j++){
			scanf("%d",&b);
			if(b==1)a[j]++;
			ma=ma>a[j]?ma:a[j];
		}
		do{
			for(int i=0;i<m;i++)
				if(ma==a[i]){
					cnt++;
					printf(cnt==m?"%d\n":"%d ",i+1);
				}
		}while(ma-->=0);
	}
	return 0;
}

Measured memory_bytes: 0
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if(a<b) swap(a,b);
  if(a<c) swap(a,c);
  cout << a*10+b+c<<endl;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int res;
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionset(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
      res--;
    }
    return x != y;
  }
  bool findset(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

/*
UnionFind tree(n):0~n-1を初期値としてUnionfindを定義
tree.unionset(x,y): x が入っている集合と y が入っている集合を併合する．
tree.findset(x,y): x と y が同じ集合に入っているかを判定する．
*/  


int main(){
  ll i,j;
  int n,m; cin>>n>>m;
  res=n;
  //ll a,b,c,d,e,f; cin>>a>>b;
  //ll a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  //string s; cin >> s;
  ll result = 0;
  ll buf = 0;
  bool judge = true;
  //cout<<<<endl;

  vector<ll> x(m),y(m),z(m);
  UnionFind tree(n+1);
  for(i=0;i<m;i++){
    cin >>x[i]>>y[i]>>z[i];
     tree.unionset(x[i],y[i]);
  }
  
  cout<<res<<endl;

  return 0;
}

Measured memory_bytes: 2944