akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

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

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    set<pair<int,int>> se;
    CIN(N);
    I vec;
    REP(a,N){
        CIN(b);
        vec.push_back(b-1);
    }
    for(int a = 0;a < N;a++){
        if(a== vec.at(vec.at(a))){
            int ma = max(vec.at(a),vec.at(vec.at(a)));
            int mi = min(vec.at(a),vec.at(vec.at(a)));
            se.insert(make_pair(mi,ma));
        }
    }
    COUT(se.size());
    rt 0;
}


Measured memory_bytes: 2936
from itertools import accumulate

def f(k, A):
    n = len(A)

    mod = int(1e9 + 7)
    dp = [0] * (k + 1)

    # init for last column
    for j in range(min(A[n - 1], k) + 1):
        dp[j] = 1

    for i in range(n - 2, -1, -1):
        dp = list(accumulate(dp))
        a = A[i]
        dp[a+1:] = [x - y for x, y in zip(dp[a + 1:], dp)]
        dp = [x % mod for x in dp]

    return dp[-1] % mod

assert f(4, [2, 3]) == 2
assert f(4, [1, 2, 3]) == 5
assert f(10, [9]) == 0
assert f(0, [0, 0]) == 1
assert f(100000, [100000, 100000, 100000, 100000]) == 665683269

n, k = map(int, input().split())
A = list(map(int, input().split()))
ans = f(k, A)
print(ans)


Measured memory_bytes: 120232
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

bool d=false;

int main(){
    int n;cin>>n;
    if(n>=1000){
        d=true;
        n-=999;
    }
    if(d)cout<<"ABD";
    else cout<<"ABC";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a,b,k;
	cin>>a>>b>>k;
	if(b-a>=k*2){
		for(int i=0;i<k;i++){
			cout<<a+i<<endl;
		}
		for(int i=0;i<k;i++){
			cout<<b-k+1+i<<endl;
		}
	}else{
		for(int i=0;i<b-a+1;i++){
			cout<<a+i<<endl;
		}
	}


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nl endl
#define dbg(a) cout << #a << "=" << a << endl
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define md 1000000007
#define gu getchar_unlocked

using namespace std;


int solve()
{
    ll x, k, d;
    cin >> x >> k >> d;
    x=abs(x);
    ll a=x/d;
    ll baki=k-a;
    if(baki<0)
    {
        cout<<abs(x-k*d)<<endl;
        return 0;
    }
    a+=baki%2;
    cout<<abs(x-a*d)<<endl;

    return 0;
}

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

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

long long gcd(long long a, long long b){
  return b?gcd(b,a%b):a;
}

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

int main(){
  long long a,b,c,d,LcmCd;cin>>a>>b>>c>>d;
  LcmCd=lcm(c,d);
  cout<<b-a+1-(b/c-(a-1)/c+b/d-(a-1)/d-b/LcmCd+(a-1)/LcmCd)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
const ll MOD=1e9+7;
const int N=500000;

main(){
    int n=in(),t=in();
    int mi=INF,ans=1,ma=0,las=0;
    rep(i,n){
        int now=in();
        if(ma==now-mi&&las!=mi){
            ans++;
            las=mi;
        }
        if(now-mi>ma)las=mi;
        ma=max(ma,now-mi);
        mi=min(mi,now);
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue> 
using namespace std;
const int N=100001;
long long n,ans=0,tmp=0;
long long a[N],b[N];
int main()
{
    long long i;
    cin>>n;
    for(i=1;i<=n;i++)
        scanf("%d %d",&a[i],&b[i]);
    for(i=n;i>=1;i--)
    {
        if((a[i]+tmp)%b[i]!=0)
        {
            ans+=(((a[i]+tmp)/b[i]+1)*b[i]-(a[i]+tmp));
            tmp+=(((a[i]+tmp)/b[i]+1)*b[i]-(a[i]+tmp));
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
map<pii,int> fir;
vector<int> g[100005]; 
int vis[100005];
int n,m,k;
int ans[100005];
int sum;
int siz[100005];
vector<int> ha;
void dfs(int now,int col){
    if(vis[now]) return;
    sum++;
    vis[now]=col;
    for(int i=0;i<g[now].size();i++)
        dfs(g[now][i],col);
    ha.pb(now);
}
int main(){
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<m;i++){
        int a,b;
        scanf("%d %d",&a,&b);
        g[a].pb(b);
        g[b].pb(a);
        fir[mp(a,b)]=fir[mp(b,a)]=1;
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
        if(!vis[i]){
            sum=0;
            ++cnt;
            ha.clear();
            dfs(i,cnt);
            for(int i=0;i<ha.size();i++) siz[ha[i]]=sum;
        }
    for(int i=1;i<=n;i++)
        ans[i]=siz[i]-g[i].size()-1;
    for(int i=0;i<k;i++){
        int c,d;
        scanf("%d %d",&c,&d);
        if(vis[c]==vis[d]) ans[c]--,ans[d]--;
    }
    for(int i=1;i<=n;i++)
        printf("%d ",ans[i]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 21884
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (5000010)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
int n,c1,c2,c3,p1,p2,q1,q2,now,tar;
char s[N],str[N],w1,w2,w3;
vector<int> pos2; bool ban[N];
int gs(int x){
	if(s[x]==w1)return 1;else if(s[x]==w2)return 2;else return 3;
}
void getstr(int L,int R){
	if(L>R)return;
	int ch[4]={0,0,0,0};
	for(int i=L;i<=R;i++)ch[gs(i)]++;
	if(!ch[2]&&L>1&&R<n)q2++,pos2.push_back(L-1);
	if(!ch[3]&&L>1&&R<n)p2++;
	if(ch[2])p1++; if(ch[3])q1++;
}
void del(){
	int tmp=0,lst=-1;
	for(int i=1;i<=n;i++)
	if(!ban[i]&&s[i]!=lst)lst=s[i],s[++tmp]=s[i];
	n=tmp;
}
void cal(){
	c1=c2=c3=0;
	for(int i=1;i<=n;i++)
	if(s[i]==w1)c1++;else if(s[i]==w2)c2++;else c3++;
	memset(ban,0,sizeof(ban));
}
void solve(int L,int R){
	if(L>R)return;
	if(L==R){
		if(L==1||L==n){if(s[L]==w3&&c3>c2)c3--,ban[L]=1;}
		return;
	}
	if(s[L]==w3&&c3>c2)c3--,ban[L]=1;
	if(s[R]==w3&&c3>c2)c3--,ban[R]=1;
}
void solve2(int L,int R){
	if(L>R)return;
	while(L<R&&now>tar){
		if(L+1>=R&&L!=1&&R!=n)break;
		now--,ban[L]=ban[L+1]=1,L+=2;
	}
}
void Print(){
	for(int i=1;i<=n;i++)putchar(s[i]); puts("");
}
int main(){
	scanf("%s",str+1),w1='A',w2='B',w3='C';
	for(int i=1;i<=strlen(str+1);i++)
	if(str[i]!=str[i-1]){
		s[++n]=str[i];
		if(s[n]==w1)c1++;else if(s[n]==w2)c2++;else c3++;
	}
	if(c1>c2)swap(c1,c2),swap(w1,w2);
	if(c1>c3)swap(c1,c3),swap(w1,w3);
	if(c2>c3)swap(c2,c3),swap(w2,w3);
//	cout<<w1<<" "<<w2<<" "<<w3<<endl;
	int j=0;
	for(int i=1;i<=n;i++)
	if(s[i]==w1)getstr(j+1,i-1),j=i; getstr(j+1,n);
	if(p1<q2)for(int i=0;i<q2-p1;i++)ban[pos2[i]]=1,c1--;
//	Print();
	del(),cal(),j=0;
	for(int i=1;i<=n;i++)
	if(s[i]==w1)solve(j+1,i-1),j=i; solve(j+1,n);
	del(),cal(),j=0,now=c2,tar=c1;
//	Print();
	for(int i=1;i<=n;i++)
	if(s[i]==w1)solve2(j+1,i-1),j=i; solve2(j+1,n);
	for(int i=1;i<=n;i++)
	if(!ban[i])printf("%c",s[i]);
}

Measured memory_bytes: 11896
#include<cstdio>

#define	SEA	0
#define	GND	1

using namespace std;

struct P{int x,y;};

P color[13][13];

P UF_root(P p)
{
	if(color[p.y][p.x].x==-1)	return p;
	return p=UF_root(color[p.y][p.x]);
}

bool UF_find(P p,P q)
{
	p=UF_root(p);
	q=UF_root(q);
	return p.x==q.x && p.y==q.y;
}

void UF_union(P p,P q)
{
	p=UF_root(p);
	q=UF_root(q);
	if(p.x!=q.x || p.y!=q.y)	color[q.y][q.x]=p;
}

int main()
{
	int world[13][13];
	for(int i=0;i<13;i++)	world[i][0]=world[0][i]=SEA;

	do{
		for(int i=1;i<13;i++){
			char s[256];
			if(scanf("%s",s)==EOF)	return 0;
			for(int j=1;j<13;j++)	world[i][j]=s[j-1]-'0';
		}

		for(int i=0;i<13;i++)
			for(int j=0;j<13;j++)
				color[i][j].x=-1;

		int dx[]={-1,0},dy[]={0,-1};
		for(int y=1;y<13;y++){
			for(int x=1;x<13;x++){
				for(int k=0;k<2;k++){
					P p={x,y},q={x+dx[k],y+dy[k]};
					if(world[p.y][p.x]==world[q.y][q.x] && !UF_find(p,q))
						UF_union(p,q);
				}
			}
		}

		int cnt=0;
		for(int y=1;y<13;y++)
			for(int x=1;x<13;x++)
				if(world[y][x]==GND && color[y][x].x==-1)	cnt++;
		printf("%d\n",cnt);
	}while(1);

	return 0;
}

Measured memory_bytes: 0
object Main {
  def main(args: Array[String]): Unit = {
    import java.util.Scanner
    val in = new Scanner(System.in)
    val n, k = in.nextInt
    val heights = List.fill(n)(in.nextInt)
    val riders = heights.filter(_ >= k)
    val answer = riders.length
    println(answer)
  }
}

Measured memory_bytes: 54460
n = int(input())
a = list(map(int, input().split()))

index = [-1] * (n + 1)
for i, v in enumerate(a):
    index[v] = i

area = [[i, i] for i in range(n + 1)]
result = 0
for i in range(n, 0, -1):
    position = index[i]
    l, r = area[position]
    area[r + 1][0] = l # right
    area[l - 1][1] = r # left
    result += (position - l + 1) * (r - position + 1) * i
print(result)




Measured memory_bytes: 45784
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ull N; cin >> N;
  cout << (N-1)*N/2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;

int main(){
    int n, k;
    cin >>n >>k;
    REP(i, k){
        int x, y;
        cin >>x >>y;
        x = min(x, n - x + 1);
        y = min(y, n - y + 1);
        int num = min(x, y);
        if(num % 3 == 1) cout <<1 <<endl;
        else if(num % 3 == 2) cout <<2 <<endl;
        else cout <<3 <<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
const int mod = 1000000007;
ll dp[101][4][4][4];
int main(){
    int n;cin >> n;
    dp[0][3][3][3]=1;
    for(int len=0;len<n;len++){
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    if(dp[len][i][j][k]==0) continue;
                    for(int a=0;a<4;a++){
                        if(a==2&&i==1&&j==0) continue;
                        if(a==1&&i==2&&j==0) continue;
                        if(a==2&&i==0&&j==1) continue;
                        if(a==2&&j==1&&k==0) continue;
                        if(a==2&&i==1&&k==0) continue;
                        (dp[len+1][a][i][j]+=dp[len][i][j][k])%=mod;
                    }
                }
            }
        }
    }
    ll ans=0;
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                (ans+=dp[n][i][j][k])%=mod;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;


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

	string s;
	cin >> s;
	if (s == "AAA" || s == "BBB")cout << "No\n";
	else cout << "Yes\n";
}

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

using namespace std;

int main(void)
{
    int n, m;
    while(1) {
        scanf("%d %d", &n, &m);
        if(n==0 && m==0) break;
        int mas[n], me[m];
        for(int i=0; i<n; i++) scanf("%d", &mas[i]);
        for(int i=0; i<m; i++) scanf("%d", &me[i]);
        int pos = 1, step = 0;
        while(pos < n) {
            pos = max(1, pos + me[step] + mas[pos + me[step] - 1]);
            step++;
        }
        printf("%d\n", step);
    }

    return 0;
}

Measured memory_bytes: 1192
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] T = new int[N];
        int[] A = new int[N];
        int max_T = 0;
        for (int i=0;i<N;i++) {
            T[i] = sc.nextInt();
            max_T = Math.max(max_T, T[i]);
        }
        int max_A = 0;
        for (int i=0;i<N;i++) {
            A[i] = sc.nextInt();
            max_A = Math.max(max_A, A[i]);
        }

        if (max_T!=max_A) {
            System.out.println(0);
            return;
        }
        int max_left = 0;
        int max_right = N-1;
        for (int i=0;i<N;i++) {
            if (T[i]==max_T) {
                max_left = i;
                break;
            }
        }
        for (int i=N-1;i>=0;i--) {
            if (A[i]==max_A) {
                max_right = i;
                break;
            }
        }
        if (max_right<max_left) {
            System.out.println(0);
            return;
        }

        long ans = 1;
        int mod = 1_000_000_007;
        for (int i=0;i<max_left;i++) {
            if (i!=0 && T[i]==T[i-1]) {
                ans = ans*T[i]%mod;
            }
        }
        for (int i=N-1;i>=max_right+1;i--) {
            if (i!=N-1 && A[i]==A[i+1]) {
                ans = ans*A[i]%mod;
            }
        }
        for (int i=max_left+1;i<max_right;i++) {
            ans = ans*T[i]%mod;
        }
        // System.out.println("max_left, max_right: "+max_left+" "+max_right);
        System.out.println(ans);
    }
}


Measured memory_bytes: 82688
#include<stdio.h>    

int main(void){ 

int a[10000]; 

int n; 

int i; 

long s=0; 

int h,l;    

scanf("%d",&n);    

for(i =0; i<n; i++){ 

scanf("%d",&a[i]); 

s += a[i]; 

}    

l =1000001; 

h=-1000001;    

for(i=0;i<n;i++){ 

if(l>a[i])

l = a[i]; 

if(h<a[i])

h = a[i]; 

}    

printf("%d %d %ld\n",l, h,s);    

return 0; 

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr int mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int k, n, a[20];
    ll ans = 1e18;

    cin >> n >> k;
    rep(i, n) cin >> a[i];

    rep(i, 1 << n) {
        int cnt = 0;
        int mx = 0;
        ll cost = 0;
        rep(j, n) {
            if((i >> j) & 1) {
                if(!chmax(mx, a[j])) cost += (++mx) - a[j];
                cnt++;
            } else if(chmax(mx, a[j]))
                cnt++;
        }
        if(cnt >= k) chmin(ans, cost);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools
H, W, K = map(int, input().split())
table = [0 for i in range(H)]
ans = 0
S = 0

for i in range(H):
    table[i] = input()

for i in range(H+1):
    list_H = list(itertools.combinations(range(H), i))
    for X in list_H:
        for j in range(W+1):
            list_W = list(itertools.combinations(range(W), j))
            for Y in list_W:
                H_check = [0 for i in range(H)]
                W_check = [0 for i in range(W)]
                black = 0
                if i != 0:
                    for A in range(i):
                        H_check[X[A]] = 1
                if j != 0:
                    for B in range(j):
                        W_check[Y[B]] = 1
                for k in range(H):
                    for l in range(W):
                        if H_check[k] == 0 and W_check[l] == 0:
                            if table[k][l] == "#":
                                black += 1
                if black == K:
                    ans += 1
                # print(black)
                # S += 1
print(ans)
# print(S)


Measured memory_bytes: 69968
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define VEC(n)  int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

int main()
{
    FAST();
    ll int n,a,b,res=0,num,x;
    cin>>n;
   vector<ll int>v;
   map<ll int,ll int>mp;
   for(int i=0;i<n;i++)
   {
    cin>>x;
    v.pb(x);
    mp[x]++;
    res+=x;
   }
    cin>>num;
    while(num--)
    {
        cin>>a>>b;
        if(mp[a]!=0)
        {
            //mp[b]+=mp[a];
            res-=a*mp[a];

             mp[b]+=mp[a];
            res+=b*mp[a];




            mp[a]=0;
        }
        cout<<res<<endl;
    }


}




Measured memory_bytes: 9808
#include<bits/stdc++.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 rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k;
    cin >> n >> k;
    ll ans = k;
    rep(i,n-1) ans *= k-1;
    cout << ans << endl;
}


Measured memory_bytes: 256
// AOJ 1163: Cards
// 2017.9.15 bal4u@uu
// 2018.3.12
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAX 1004
short hi[MAX], to[MAX][MAX];
char  seen[MAX];
short match[MAX];
 
int bipartiteMatching(int m, int n)
{
    int u, max;
    int bpm(int u);
 
    memset(match, -1, (m+n) << 1);
    max = 0;
    for (u = 0; u < m; u++) {
        memset(seen, 0, m+n);
        if (bpm(u)) max++;
    }
    return max;
}
 
int bpm(int u)
{
    int i, v;
 
    for (i = 0; i < hi[u]; i++) {
        v = to[u][i];
        if (seen[v]) continue;
        seen[v] = 1;
        if (match[v] < 0 || bpm(match[v])) {
            match[u] = v, match[v] = u;
            return 1;
        }
    }
    return 0;
}
//#define getchar_unlocked()  getchar()
int in()
{
    int n = 0, c = getchar_unlocked();
    do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
    return n;
}
 
int gcd(int a, int b)
{
    int r;
if (!((a | b) & 1)) return 2;
    while (b != 0) r = a % b, a = b, b = r;
    return a;
}
 
int b[501], r[502];
 
int cmp(int *a, int *b) { return (*a & 1) - (*b & 1); }

int main()
{
    int i, j, m, n, bb, rr, sb, sr;
 
    while (m = in()) {
        n = in(); 
		sb = sr = 0;
        for (i = 0; i < m; i++) b[i] = bb = in(), sb += (bb & 1);
        for (j = 0; j < n; j++) r[j] = rr = in(), sr += (rr & 1);
		sb = m - sb, sr = n - sr;

		qsort(b, m, sizeof(int), cmp);
		qsort(r, n, sizeof(int), cmp);

        memset(hi, 0, (m+n) << 1);
		for (i = 0; i < sb; i++) {
			for (j = 0; j < sr; j++) to[i][hi[i]++] = m+j;
			for (; j < n; j++) if (gcd(b[i], r[j]) > 1) to[i][hi[i]++] = m + j;
		}
        for ( ; i < m; i++) for (j = 0; j < n; j++) {
            if (gcd(b[i], r[j]) > 1) to[i][hi[i]++] = m + j;
        }           
 
        printf("%d\n", bipartiteMatching(m, n));
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll x; cin >> x;

    ll sum = 100;
    ll ans = 0;
    while(true) {
        ++ans;
        sum = sum + sum / 100;

        if (sum >= x) {
            cout << ans << endl;
            return 0;
        }
    }
}

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

int main(){
  int n;
  long ryuka[90] = {2, 1};
  cin >> n;
  for( int i = 2; i <= n; i++){
    ryuka[i] = ryuka[i - 1] + ryuka[i - 2];
  }
  cout << ryuka[n] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            double sum1=0, sum2=0, ave=0, bun=0, hen=0;
            int n = sc.nextInt();
            if(n==0) break;
            int[] data = new int[n];
            for(int i=0;i<n;i++){
                data[i] = sc.nextInt();
                sum1 += (double)data[i];
            }
            ave = sum1/n;
            for(int i=0;i<n;i++){
                sum2 += (data[i]-ave)*(data[i]-ave);
            }
            bun = sum2/n;
            hen = Math.sqrt(bun);
            System.out.println(hen);
        }
    }
}


Measured memory_bytes: 31572
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        
        for (int i=0; i<S.length(); i++) {
            char c = S.charAt(i);
            if (i%2==0) {
                if (c != 'R' && c != 'U' && c != 'D') {
                    System.out.println("No");
                    return;
                }
            } else {
                if (c != 'L' && c != 'U' && c != 'D') {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 21972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main  implements Runnable {

    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();

    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
		//long n = Long.parseLong(sc.next());
    	//int[] ar = new int[3];
    	//ar[0]=Integer.parseInt(sc.next());
    	//ar[1]=Integer.parseInt(sc.next());
    	//ar[2]=Integer.parseInt(sc.next());
    	//Arrays.parallelSort(ar);
		int n = Integer.parseInt(sc.next());
		//int k = Integer.parseInt(sc.next());
		//int l = Integer.parseInt(sc.next());
		//long a = Long.parseLong(sc.next());
		//String s = sc.next();
		//int k = Integer.parseInt(sc.next());
		//int m = Integer.parseInt(sc.next());
		//int x2000 = Integer.parseInt(sc.next());
		//int t = Integer.parseInt(sc.next());
		//int k = 0;
		//int k = Integer.parseInt(sc.next());
		//String str = sc.next();
		//char c[] = str.toCharArray();
		//char a[][] = new char[n];
		//int atmp[] = new int[h];
		//int max= 0;
		//int blackar[][] = new int[h*w][2];
		//int p=0;
		//ArrayList<Integer> lists = new ArrayList<Integer>();
		//lists = new ArrayList;
		PrintWriter out = new PrintWriter(System.out);
		int[] a = new int[n];
		int ans = 0;
		for(int i = 0; i< n; i++)
		{
			a[i] = Integer.parseInt(sc.next());
			if(i>=2)
			{
				if(a[i-2] < a[i-1] && a[i-1] < a[i-0])
				{
					ans++;
				}
				else if (a[i-2] > a[i-1] && a[i-1] > a[i-0])
				{
					ans++;
				}
			}
		}

			out.println(ans);


		out.flush();
	}

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public long nextInt() {
            return Integer.parseInt(next());
        }

    }


}


Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#define INF 99999999
using namespace std;

int N;
int F[10001];


int cost(int s, int e, int j) {
  int tmp[3];
  if(s == 0) {
    switch(F[j]) {
    case 0:
      tmp[0] = 0; tmp[1] = 1; tmp[2] = 2;
      break;
    case 1:
      tmp[0] = 1; tmp[1] = 1; tmp[2] = 2;
      break;
    case 2:
      tmp[0] = 3; tmp[1] = 2; tmp[2] = 2;
      break;
    case 3:
      tmp[0] = 3; tmp[1] = 2; tmp[2] = 2;
      break;
    }
  } else if(s == 1) {
    switch(F[j]) {
    case 0:
      tmp[0] = 1; tmp[1] = 0; tmp[2] = 1;
      break;
    case 1:
      tmp[0] = 1; tmp[1] = 1; tmp[2] = 2;
      break;
    case 2:
      tmp[0] = 2; tmp[1] = 1; tmp[2] = 1;
      break;
    case 3:
      tmp[0] = 2; tmp[1] = 2; tmp[2] = 2;
      break;
    }
  } else {
    switch(F[j]) {
    case 0:
      tmp[0] = 2; tmp[1] = 1; tmp[2] = 0;
      break;
    case 1:
      tmp[0] = 2; tmp[1] = 2; tmp[2] = 3;
      break;
    case 2:
      tmp[0] = 2; tmp[1] = 1; tmp[2] = 1;
      break;
    case 3:
      tmp[0] = 2; tmp[1] = 2; tmp[2] = 3;
      break;
    }
  }
  return tmp[e];
}

int solve() {
  int dp[3][10001];
  fill(dp[0], dp[3], INF);
  for(int i = 0; i < 3; ++i) dp[i][0] = cost(0, i, 0);

  for(int j = 1; j <= N; ++j) {
    for(int i = 0; i < 3; ++i) {
      for(int s = 0; s < 3; ++s) {
	dp[i][j] = min(dp[i][j], dp[s][j-1] + 1 + cost(s, i, j));
      }
    }
  }

  return dp[0][N];
}

main() {
  int T;
  cin >> T;
  for(int t = 0; t < T; ++t) {
    fill(F, F+10001, 0);
    cin >> N;
    for(int i = 0; i < 2; ++i) {
      for(int j = 0; j < N*2; ++j) {
	char c;
	cin >> c;
	if(c == 'Y') F[(j+1)/2] |= (1 << i);
      }
    }
    cout << solve() << endl;
  }
}

Measured memory_bytes: 1016
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0,nn=(intl)(n);i<nn;++i)
#define Rep1(i,n) for(intl i=1,nn=(intl)(n)+1;i<nn;++i)
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);}
#define Input2(a,b) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);cin>>(b).at(ii);}
#define mp make_pair
#define mt make_tuple
using intl = int64_t;
using vi = vec<intl>;
using vb = vec<bool>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
using si = set<intl>;
using vsi = vec<si>;
using mii = map<intl,intl>;
using vmii = vec<mii>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;



int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  
  intl N;
  cin >>N;
  string S;
  intl A=0,W=0,T=0,R=0;
  Rep(i,N){
    cin >>S;
    if(S=="AC"){A++;}
    if(S=="WA"){W++;}
    if(S=="TLE"){T++;}
    if(S=="RE"){R++;}
  }
  
  cout<<"AC x "<<A<<endl<<"WA x "<<W<<endl<<"TLE x "<<T<<endl<<"RE x "<<R;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <memory.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <queue>
#include <stack>
#include <cstdio>
#include <bitset>

using namespace std;

#define nfs ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f first
#define s second
#define m_p make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define ll long long
#define ull unsigned long long
#define ld long double
#define ef else if
#define loc(x) (x).begin(),(x).end() 
#define locR(x) (x).rbegin(),(x).rend()
#define no puts("NO")
#define yes puts("YES")
#define ex puts("-1")
#define en puts("")
#define _ cout  
#define __ <<
#define outV(v) for(int i = 0 ; i < v.size() ; i++)cout << v[i] << ' ';
#define outA(x,l,r) for(int i = l ; i < r ; i++)cout << x[i] << ' ';

const ld EPS = 1e-18;
const double DEPS = 1e-9;
const ld PI = 3.141592653589793238;
const ull MOD = 1e9 + 7;
const int N = (int)(5e5) + 1;

ll gcd(ll fx, ll fy)
{
	if (!fy) return fx;
	return gcd(fy, fx % fy);
}

inline void fill(int* ar, int sz, int val)
{
	for (int i = 0; i < sz; i++)
	{
		ar[i] = val;
	}
}

int n, m, w[101], v[101], ans;
ll dp[N][101];

int main()
{

	cin >> n >> m;

	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", w + i, v + i);
	}

	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= 1e5; j++)
		{
			dp[j][i] = 2e9;
		}
	}

	dp[0][0] = 0;

	for (int i = 1; i <= n; i++)
	{
		dp[v[i]][i] = w[i];
		for (int j = 1e5; j >= 0; j--)
		{
			if (j - v[i] >= 0 && dp[j - v[i]][i - 1] + w[i] <= m)
			{
				dp[j][i] = min(dp[j][i], dp[j - v[i]][i - 1] + w[i]);
				ans = max(j, ans);
			}
			
			dp[j][i] = min(dp[j][i], dp[j][i - 1]);
			
		}
	}
	
	cout << ans;

}

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

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

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

  A[0] = B[0];
  for (int i = 1; i < N - 1; i++) {
    A[i] = min(B[i-1], B[i]);
  }
  A[N-1] = B[N-2];

  int ans;
  for (auto i : A) ans += i;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
S={}
for i in range(N):
  a,b=map(int,input().split())
  if a in S:
    S[a]+=b
  else:
    S[a]=b
T=sorted(S.items())
count=0
for i in range(len(T)):
  count+=T[i][1]
  if count>=K:
    print(T[i][0])
    break
    
  

Measured memory_bytes: 14560
#include<bits/stdc++.h>
using namespace std;
#define deb(x) cerr << #x << " = " << x << "\n";
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}



int main(){
	FIO
	
	int n, m;cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int L,A,B,C,D;
	int a,b,c;
	scanf("%d",&L);
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	scanf("%d",&D);
	a=A/C;
	if(A%C!=0){
		a=A/C;
		a=a+1;
	}
	b=B/D;
	if(B%D!=0){
		b=B/D;
		b=b+1;
	}
	if(a>=b){
		c=L-a;
	}
	else if(a<b){
		c=L-b;
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,m;
	cin >> n >> m;
	vector<int> a(n);
	rep(i,0,n)cin >> a[i];
	int N = accumulate(all(a), 0);
	int cnt = 0;
	rep(i,0,n)cnt+=(N+4*m-1)/(4*m) <= a[i];
	cout << (cnt >= m?"Yes":"No") << '\n';
}


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

int main() {
  int x, y; cin >> x >> y;
  cout << (group(x) == group(y) ? "Yes" : "No") << endl;
}

int group(int x) {
  if (x <= 7) {
    if (x % 2 == 1) {
      return 1;
    } else {
      if (x == 2) {
        return 3;
      } else {
        return 2;
      }
    }
  } else {
    if (x % 2 == 0) {
      return 1;
    } else {
      return 2;
    }
  }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A_all = A[0]
for i in range(1,N):
    A_all ^= A[i]
B = [0] * N
for j in range(N):
    B[j] = A[j] ^ A_all
print(' '.join(map(str, B)))


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int a_sum = 0, b_sum = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for(int i=0; i<n; i++){
        if(i%2==0){
            a_sum+=a[i];
        }else{
            b_sum+=a[i];
        }
    }

    cout << a_sum-b_sum << endl;
    return 0;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#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 pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

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

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

class union_find_tree
{
    private:
        const int number_of_nodes;
        int number_of_groups;
        int *par;
        int *rank;
    public:
        //int *size_of_group;
        union_find_tree(int n);
        int get_number_of_nodes();
        int get_number_of_groups();
        int root(int x);
        void unite(int x, int y);
        bool same(int x, int y);
};

union_find_tree::union_find_tree(int n) : number_of_nodes(n)
{
    number_of_groups = n;
    par = new int[n];
    rank = new int[n];
    //size_of_group = new int[n];
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rank[i] = 0;
        //size_of_group[i] = 1;
    }
}

int union_find_tree::get_number_of_nodes()
{
    return number_of_nodes;
}

int union_find_tree::get_number_of_groups() {
    return number_of_groups;
}

int union_find_tree::root(int x)
{
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = root(par[x]);
    }
}

void union_find_tree::unite(int x, int y)
{
    x = root(x);
    y = root(y);
    if (x == y) {
        return;
    }
    if (rank[x] < rank[y]) {
        par[x] = y;
        //size_of_group[y] += size_of_group[x];
    } else {
        par[y] = x;
        //size_of_group[x] += size_of_group[y];
        if (rank[x] == rank[y]) {
            rank[x]++;
        }
    }
    number_of_groups--;
}

bool union_find_tree::same(int x, int y) {
    return root(x) == root(y);
}


int N, M;

int main() {
    cin >> N >> M;
    union_find_tree uft(N);
    REP(i, M) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        X--;
        Y--;
        uft.unite(X, Y);
    }
    cout << uft.get_number_of_groups() << endl;
    return 0;
}



Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int ans = 0;
		if(n >= 2){
			ans += n * (n - 1) / 2;
		}
		if(m >= 2){
			ans += m * (m - 1) / 2;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35636
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  st A, B;
  ci(A, B);
  if(sz(A) > sz(B)){
    co("GREATER");
  }
  else if(sz(A) < sz(B)){
    co("LESS");
  }
  else{
    rep(i, sz(A)){
      if(A.at(i) > B.at(i)){
        co("GREATER");
        rt;
      }
      else if(A.at(i) < B.at(i)){
        co("LESS");
        rt;
      }
    }
    co("EQUAL");
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

const int N = 1e5 + 9;

int res = 0;

int ans[N];
vector<pair<int, int>> g[N];

void dfs(int cur, int pr, int edc) {
	int pnt = 0;
	for (auto t : g[cur]) {
		if (t.first == pr) continue;
		if (pnt == edc) pnt++;
		ans[t.second] = pnt;
		res = max(res, pnt);
		dfs(t.first, cur, pnt);
		pnt++;
	}
}

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

	int n;
	cin >> n;
	for (int i = 0; i + 1 < n; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back({v, i});
		g[v].push_back({u, i});
	}
	dfs(0, -1, -1);
	cout << res + 1 << '\n';
	for (int i = 0; i + 1 < n; i++) {
		cout << ans[i] + 1 << ' ';
	}
	cout << endl;
}


Measured memory_bytes: 9344
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  bool f = true;
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%3!=0&&a[i]%5!=0){
	f = false;
	break;
      }
    }
  }
  if(f) cout << "APPROVED" << "\n";
  else cout << "DENIED" << "\n";
  return 0;
}


Measured memory_bytes: 256
import math

def is_prime(n):
    if n==1:
        return False
    nmax = int(math.sqrt(n)) + 1
    for i in range(2, nmax):
        if(n%i)==0:
            return False
    return True

def pf(n):
    sn = int(math.sqrt(n)) + 1
    ps = []
    for i in range(1, sn):
        if (n%i)==0:
            ps.append(i)
            ps.append(int(n/i))
    del ps[0]
    return ps        

n = int(input())
ps = []
num = pf(n)
for i in num:
    if is_prime(i):
        ps.append(i)
        
zs = []        
for p in ps:
    z = p
    while(z<=n):
        zs.append(z)
        z *= p
zs.sort()

cnt = 0
for z in zs:
    if(n>1):
        if(n%z==0):
            n /= z
            cnt += 1
print(cnt)

Measured memory_bytes: 70388
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
ans = 0
for i in range(N):
    A = list(map(int, input().split()))
    temp = 0
    for j in range(M):
        temp += A[j] * B[j]
    temp = temp + C
    if temp > 0:
        ans += 1
        
print(ans)

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> cnt(n + 1, 0);
    for (int i = 0; i < n - 1; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            cnt[i + 2] = 1;
        }
    }

    for (int i = 1; i <= n; i++) {
        cnt[i] += cnt[i - 1];
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << cnt[r] - cnt[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1488
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int a, b; cin >> a >> b;
	if (b == 100) {
		a *= 1000;
	}
	else if (1 <= b && b <= 9) {
		a *= 10;
	}
	else {
		a *= 100;
	}

	int C = a + b;

	bool isSquare = false;

	rep(i, 0, 10000) {
		if (i*i == C) {
			isSquare = true;
			break;
		}
	}

	cout << ((isSquare) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx,avx2")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

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

    int h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << max(0ll, h2 * 60 + m2 - h1 * 60 - m1 - k) << "\n";

    return 0;
}


Measured memory_bytes: 3672
nk = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = [0] * (nk[0] + nk[1])
 
zeros = [0] * nk[1]
 
seq4search = zeros + p
 
for i in range(nk[1], nk[0] + nk[1]):
    seq4search[i] = (seq4search[i] + 1) / 2
    ans[i] = ans[i-1] + seq4search[i] - seq4search[i - nk[1]] 
 
print(max(ans))

Measured memory_bytes: 89352
object MainKt {
  @JvmStatic fun main(args:Array<String>) {
    val (x,y) = readLine()!!.split(" ").map(String::toInt)

    val a=arrayOf(1,3,5,7,8,10,12)
    val b=arrayOf(4,6,9,11)

    println(if(x==y) {
      "Yes"
    } else {
      when {
        x in a && y in a -> "Yes"
        x in b && y in b -> "Yes"
        else -> "No"
      }
    })
  }
}


Measured memory_bytes: 35940
#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 Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll, ll>

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const int sz=1e3+100;
bool cmp(PII a,PII b)
{
    if(a.s==b.s) return a.f<b.f;
    return a.s<b.s;
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n)
    { 
        PII ara[n];
        for(i=0;i<n;i++) cin>>ara[i].f>>ara[i].s;

    sort(ara,ara+n,cmp);
    ll time=0;
    bl=true;
    for(i=0;i<n;i++)
    {
        if(time+ara[i].f<=ara[i].s){
            time+=ara[i].f;
        }
        else{
            bl=false;
            break;
        }
    }

    if(bl) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    }



}


Measured memory_bytes: 3328