akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include "Header.h"

#define pi 3.14159265358979323846264

#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)

#define sp(n) setprecision(n)
#define d7 1000000007
#define mkp make_pair
#define mkt make_tuple

using namespace std;

bool isPrime(long long k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    long long i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}

ll binomialCoeff(ll n, ll k){
    ll C[n + 1][k + 1];ll i, j;
    for (i = 0; i <= n; i++){
        for (j = 0; j <= min(i, k); j++){
            if (j == 0 || j == i){C[i][j] = 1;}
            else{C[i][j] = (C[i - 1][j - 1]%d7 + C[i - 1][j]%d7)%d7;}}}
    return C[n][k]%d7;
 }

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

ll srihrg(ll n,ll k,ll m){
    ll ans;
    ans=1;
    fori(k){
        ans=(ans*n)%m;
    }
    return ans;
}

ll kk=1;
void dfsi(vector<bool> &vis, vector<ll> adj1[], ll n, ll start, vector<ll> &pre, vector<ll> &pos){
    vis[start]=true;
    pre[start]=kk;kk++;
    for(ll i: adj1[start]){
        if(!vis[i]){
            vis[i]=true;
            dfsi(vis,adj1,n,i,pre,pos);
        }
    }
    pos[start]=kk;kk++;
}

void bfsi(vector<ll> &dis, vector<ll> adj[], ll s, vector<ll> &parent){
    dis[s]=-1;
    queue<ll> q;
    q.push(s);
    while(!q.empty()){
        ll z=q.front();
        q.pop();
        for(ll v:adj[z]){
            if(dis[v]==0){
            q.push(v);
            dis[v]=-dis[z];
                parent[v]=z;}
        }
    }
}

void make_set(ll v, vector<ll> &parent, vector<ll> &krank) {
    parent[v] = v;
    krank[v] = 0;
}

ll find_set(ll v,vector<ll> &parent, vector<ll> &krank) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v], parent, krank);
}

void union_sets(ll a, ll b,vector<ll> &parent, vector<ll> &krank) {
    a = find_set(a,parent,krank);
    b = find_set(b,parent,krank);
    if (a != b) {
        if (krank[a] < krank[b])
            swap(a, b);
        parent[b] = a;
        if (krank[a] == krank[b])
            krank[a]++;
    }
}

void dijkstra(ll s, vector<ll> &dist, vector<ll> &parent, ll n, vector<pair<ll,ll>> adj[]){
    dist[s]=0;
    vector<bool> u(n,false);
    fori(n){
        ll v=-1;
        forj(n){
            if(!u[j] &&(v==-1||(dist[j]<dist[v]))) v=j;
        }
        if(dist[v]==d7) break;
        u[v]=true;
        for(auto j:adj[v]){
            ll a,b;
            a=j.first;
            b=j.second;
            if(dist[v]+b<dist[a]){
                dist[a]=dist[v]+b;
                parent[a]=v;
            }
        }
    }
}


int main(int argc, const char * argv[]) {
 //cout<<"Om\n";
 //Praise to Lord
 //make cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);
// code now
   
    ll n;
    cin>>n;
    ll a,b;
    cin>>a>>b;
    ll k=n/(a+b);
    n-=k*(a+b);
    if(n<=a){cout<<k*a+n;}
    else{
        cout<<(k+1)*a;
    }
    
//code ends
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
	string s, str1, str2;
	int maxn = 0;
	map<string, int> mp;
	while(cin >> s){
		mp[s]++;
		if(mp[s] > maxn){maxn = mp[s];str1 = s;}
		if(s.size() > str2.size())str2 = s;
	}
	cout << str1 << " " << str2 << endl;
	return 0; 
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;
  vector< vector<int> > G(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  int q;
  cin>>q;
  vector<int> us(q),ds(q),cs(q);
  for(int i=0;i<q;i++) cin>>us[i]>>ds[i]>>cs[i],us[i]--;

  vector< vector<int> > dp(11,vector<int>(n,-1));
  using P = pair<int, int>;
  vector< queue<P> > qs(11);
  for(int i=0;i<q;i++){
    chmax(dp[ds[i]][us[i]],i);
    qs[ds[i]].emplace(us[i],i);
  }

  for(int d=10;d>0;d--){
    queue<P> que=qs[d];
    while(!que.empty()){
      int v,i;
      tie(v,i)=que.front();que.pop();
      if(dp[d][v]!=i) continue;
      for(int u:G[v]){
        if(dp[d-1][u]==i) continue;
        chmax(dp[d-1][u],i);
        qs[d-1].emplace(u,i);
      }
      if(dp[d-1][v]==i) continue;
      chmax(dp[d-1][v],i);
      qs[d-1].emplace(v,i);
    }
  }

  for(int i=0;i<n;i++)
    cout<<(~dp[0][i]?cs[dp[0][i]]:0)<<endl;
  return 0;
}


Measured memory_bytes: 27264
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if ((a * b) % 2 == 0) {
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }
    }
}


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

int main() {
    long long int c=0,l,r,d;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
        c++;
    }
    cout<<c<<endl;
    return 0;
}


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


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

  string s;
  cin>>s;
  

  vector<int> data(n);
  
  int eastcount=0;
  
  for (int i=0;i<n;i++){
    if (s.at(i)=='E'){
      eastcount++;
    }
    data.at(i)=eastcount;
  }
  
  int answer=data.at(n-1)-data.at(0);
  
  for (int i=1;i<n;i++){
    int tmp=i-data.at(i-1)+data.at(n-1)-data.at(i);
    answer=min(answer,tmp);
  }
  
  cout<<answer<<endl;
  
    
    

  
  

  
  
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll X[2000];
ll Y[2000];
ll Z[2000];
int main(){
    int N, M;
    cin >> N >> M;
    REP(i, N){
        ll x, y, z;
        cin >> x >> y >> z;
        X[i] = x;
        Y[i] = y;
        Z[i] = z;
    }

    ll ans = -1;
    for(int i = -1; i <= 1; i+=2){
        for(int j = -1; j <= 1; j+=2){
            for(int k = -1; k <= 1; k+=2){
                vector<ll> C(N);
                ll num = 0;
                for(int c = 0; c < N; c++){
                    C[c] = i*X[c] + j*Y[c] + k*Z[c];
                }
                sort(C.begin(), C.end(), greater<ll>());
                for(int c = 0; c < M; c++){
                    num += C[c];
                }
                ans = max(ans, num);
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
y = d-b
x = c-a

res = ""
res += 'U'*(y)
res += 'R'*(x)
res += 'D'*(y)
res += 'L'*(x)
res += 'L'
res += 'U'*(y+1)
res += 'R'*(x+1)
res += 'D'
res += 'R'
res += 'D'*(y+1)
res += 'L'*(x+1)
res += 'U'

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N, K;
    cin >> N >> K;
    vector <ll> A(N);
    loop(i,0,N) cin >> A[i];
    ll prod=1;
    loop(i,0,K) prod*=A[i];
    loop(i,K,N){
        if (A[i]>A[i-K]) {
            cout << "Yes\n";
        }
        else cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 4780
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vvi root(n);
  rep(i, n - 1){
    int a,b;
    cin >> a >> b;
    a--; b--;
    root[a].push_back(b);
    root[b].push_back(a);
  }
  queue<int> que, que2;
  que.push(0); que2.push(n - 1);
  vi checked(n, -1), checked2(n, -1);
  checked[0] = 0; checked2[n - 1] = 0;
  while(!que.empty()){
    int pos = que.front();
    que.pop();
    for(int x : root[pos]){
      if(checked[x] == -1){
        checked[x] = checked[pos] + 1;
        que.push(x);
      }
    }
  }
  while(!que2.empty()){
    int pos = que2.front();
    que2.pop();
    for(int x : root[pos]){
      if(checked2[x] == -1){
        checked2[x] = checked2[pos] + 1;
        que2.push(x);
      }
    }
  }
  int f = 0, s = 0;
  rep(i, n){
    if(checked[i] <= checked2[i]) f++;
    else s++;
  }
  if(f > s) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
}

Measured memory_bytes: 6528
N = int(input())
H = list(map(int, input().split()))

def water(H):
	if H == []:
		return 0
	
	minH = min(H)
	H_temp = [x - minH for x in H]
	index0 = H_temp.index(0)
	return water(H_temp[0:index0]) + water(H_temp[index0+1:]) + minH

print(water(H))

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

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

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


	ll N = 0, K = 0;
	char c;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';
	while ((c = getchar_unlocked()) >= '0') K = K * 10 + c - '0';

	int A[200001];
	int D2[200001];
	rep1(i, N) A[i] = getint();

	int d = 0;
	int p = 1;
	while (A[p] > 0) {
		D2[d] = p;
		int tugi = A[p];
		A[p] = -d++;
		p = tugi;
	}
	if (K > -A[p]) {
		ll k = K + A[p];
		k %= d + A[p];
		K = -A[p] + k;
	}
	printf("%d", D2[K]);

	Would you please return 0;
}

Measured memory_bytes: 3240
n = int(input())
AC,WA,TLE,RE=0,0,0,0
for i in range(n):
  s = input()
  if s =="AC":
    AC += 1
  elif s =="WA":
    WA += 1
  elif s=="TLE":
    TLE += 1
  else:
    RE += 1
print('AC x', AC)
print('WA x', WA)
print('TLE x', TLE)
print('RE x', RE)

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

int main()
{
  string s; cin >> s;
  int n = s.size();
  bool f = false;
  for (int i=1; i<n; i++) {
    if (s[i] !='9') f = true;
  }
  ll ans = (s[0]-'0') + (n-1)*9;
  //cout << n << " " << ans << " ";
  if (f) ans--;
  cout << ans << endl;

  return 0;
}


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

int n;
vector<lint> a;
int q;

int main() {
    cin >> n;
    a.resize(n);
    map<lint, lint> count;
    lint sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        count[a[i]]++;
        sum += a[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        lint b, c;
        cin >> b >> c;
        lint from_num = count[b];
        sum += (c - b) * from_num;
        count[b] = 0;
        count[c] += from_num;
        cout << sum << endl;
    }
}

Measured memory_bytes: 9972
import Data.Bool
import Data.List

main :: IO ()
main = do
  abc <- map read . words <$> getLine
  putStrLn . toAnswer $ couldBe575 abc

toAnswer :: Bool -> String
toAnswer = bool "NO" "YES"

couldBe575 :: [Int] -> Bool
couldBe575 = (==[5,5,7]) . sort

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll dp[1010][10010*2];

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

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

template<class T>
bool chmax(T &a, initializer_list<T> l)
{
	return chmax(a, *max_element(l.begin(), l.end()));
}

template<class T>
bool chmin(T &a, initializer_list<T> l)
{
	return chmin(a, *min_element(l.begin(), l.end));
}

int main(int argc, char **argv)
{
	ll H, N; cin >> H >> N;
	vector<ll> A(N), B(N);
	REP(i, N) cin >> A[i] >> B[i];

	REP(i, 1010)REP(j, 10010*2) dp[i][j] = INF;
	REP(i, 1010) dp[i][0] = 0;

	REP(n, N)
	{
		REP(h, 10100*2)
		{
			chmin(dp[n+1][h], dp[n][h]);
			if (h-A[n] >= 0)
				chmin(dp[n+1][h], dp[n+1][h-A[n]] + B[n]);
		}
	}

	ll mi{INF};

	FOR(h, H, 10010)
	{
		mi = min(dp[N][h], mi);
	}
	std::cout << mi << std::endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
        int N;
        int ans = 0, cnt = 0;
        char a[] = {'A', 'C', 'G', 'T'};
        string S;
        cin >> S;
        N = S.size();

        rep(i, N)
        {
                cnt = 0;
                while (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')
                {
                        i++;
                        cnt++;
                        ans = max(ans, cnt);
                }
        }

        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
s = input().split()

r = int(s[0])
c = int(s[1])

A = [[0 for i in range(c+1)] for j in range(r+1)]

row=[]
for i in range(r):
    row = list(map(int,input().split()))
    
    for j in range(c):
        A[i][j]=row[j]
        A[i][c]+=row[j] # sum of row
        A[r][j]+=row[j] # sum of column
    
    A[r][c]+=A[i][c]
        
for i in range(r+1):
    for j in range(c):
        print(A[i][j]," ",end="",sep="")
    print(A[i][c])


Measured memory_bytes: 6752
#include<bits/stdc++.h>
using namespace std;
int dp[100050],a[100050];
int main(){
    int n,k;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    
    cout<<dp[n-1];
    
    
    
    
    
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  int n;
  ll most = -INF, least = INF;
  fscanf(stdin, "%d", &n);
  ll sum = 0, val = -1;
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%lld", &val);
    most = max(most, val);
    least = min(least, val);
    sum += val;
  }
  fprintf(stdout, "%lld %lld %lld", least, most, sum);
  fprintf(stdout, "\n");
  return 0;
}

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

using namespace std;

#define pii pair<int,int>
#define pb push_back
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define MOD 1000000007

ll factorial(ll n) { if(n == 0 || n == 1) return 1; ll res = 1;for(ll i=2;i<=n;i++) res = (res*n)%MOD;return res;}
ll mpow(ll a, ll n) { ll ret=1; ll b=a; while(n) { if(n&1) {ret=(ret*b)%MOD;} b=(b*b)%MOD; n>>=1; } return (ll)ret; }
int toint(const string &s) { stringstream ss(s); int x; ss >> x; return x; }
ll xGCD(ll a, ll b, ll &x, ll &y) { if (b == 0) {x = 1;y = 0;return a;} ll x1, y1, gcd = xGCD(b, a % b, x1, y1); x = y1; y = x1 - (a / b) * y1; return gcd; }
ll inverse(ll a) {ll x, y;ll gcd = xGCD(a, MOD, x, y);return (x%MOD+MOD)%MOD;}
ll bc(ll n, ll k) { if(n == k || k == 0) return 1; if(k == 1 || k == n-1) return n;ll a = factorial(n);ll b = inverse(factorial(k));ll c = inverse(factorial(n - k));return ((a%MOD*b%MOD)*c%MOD)%MOD;}
void fastscan(ll &x) { bool neg=false; register int c; x =0;c=getchar();if(c=='-') {neg = true;c=getchar();}for(;(c>47 && c<58);c=getchar())x = (x<<1) + (x<<3) +c -48;if(neg) x *=-1;}


int main() {
//     fstream fin,fout;
//     fin.open("sample.txt");
//     fout.open("res.txt");
    ll n;
    cin>>n;
    vi v(n);
    for(ll i=0;i<n;i++) cin>>v[i];
    
    ll x=v[0];
    for(ll i=1;i<n;i++) x=x^v[i];
    
    for(ll i=0;i<n;i++)  {
        ll res = x^v[i];
        cout<<res<<" ";
    }
//     cout << duration.count() << endl;
//     fin.close();
//     fout.close();
    return 0;
}



Measured memory_bytes: 4776
#include<stdio.h>

int main()
{
    int a,b,c,chg;

    scanf("%d %d %d", &a, &b, &c);

    if(a > b) {
      chg = a;
      a = b;
      b = chg;
    }

    if(b > c) {
      chg = b;
      b = c;
      c = chg;
    }

    if(a > b) {
      chg = a;
      a = b;
      b = chg;
    }

    printf("%d %d %d\n", a, b, c);

    return 0;
}



Measured memory_bytes: 2104
# coding: utf-8
# N, hの入力
N = int(input())
h = list(map(int, input().split()))
# 足場ごとにそこまでのコストの最小を記録
memo =[0, abs(h[0] - h[1])] + [-1] * (N - 2)
for i in range(N - 2):
    """
    ある足場h_iに到達するコストの最小値k_iは
    k_(i - 1) + |h_i - h_(i - 1)|と
    k_(i - 2) + |h_i - h_(i - 2)|のうち小さい方である
    """
    memo[i + 2] = min(memo[i] + abs(h[i] - h[i + 2]),memo[i + 1] + abs(h[i + 1] - h[i + 2]))
# h_Nに到達するコストの最小値が求める答えである
print(memo[N - 1])

Measured memory_bytes: 52208
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    n = int(sys.stdin.readline())
    k = input()
    if len(k) > n:
        print(k[:n],end="")
        print("...")
    else: print(k)
    return 0

if __name__ == "__main__":
    main()

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(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 Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,k,sum=0;
	cin >> n >> k;
	for(ll i=k;i<=n+1;i++){
		sum=(sum+n*(n+1)/2-(n-i)*(n-i+1)/2-i*(i-1)/2+1)%mod;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	for(int i=0; i<s.size(); i++)
	{
		if(s[i]=='C')
		{
			for(int j=i+1; j<s.size(); j++)
			{
				if(s[j]=='F')
				{
					cout<<"Yes"<<endl;
					return 0;
				}
		    }
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


vector<int> v[100000];
vector<bool> u(100000,false);

void dfs(int root){
    for(int x : v[root]){
      if(!u[x]){
        u[x] = true;
        dfs(x);
      }
    }
}

int main(){


  int N, M, x, y, z, count = 0;
  cin >> N >> M;
  REP(i,M){
    cin >> x >> y >> z;
    v[x-1].push_back(y-1);
    v[y-1].push_back(x-1);
  }
  REP(i,N){
    if(!u[i]){
      count++;
      dfs(i);
    }
  }
  cout << count << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N;i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());

  int i = 0;
  int count;
  int res=0;
  while(i < N){
    int j = i+1;
    count = 1;
    if(j < N){
      while(A.at(i) == A.at(j)){
        count ++;
        j ++;
        if(j == N)
          break;
      }
    }
    if(count >= A.at(i))
      res += count - A.at(i);
    else
      res += count;
    i += count;
  }
  cout << res << endl;
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i <(n); i++)
#define rep2(i,l,r) for (int i=(l); i<(r); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//~ using P = pair<int, int>;

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 v[100100][3];
vector<vector<int>> dp(100100, vector<int>(3, 0));

int main(){
    int N;
    cin >> N;
    
    rep(i, N){
        rep(j, 3){
            cin >> v[i][j];
        }
    }

    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    
    rep(i, N){
        rep(j, 3){
            rep(k, 3){
                if(i==0 || j!=k) chmax(dp[i+1][j], dp[i][k] + v[i][k]);
            }
        }
    }
    
    int ans;
    ans = max({dp[N][0], dp[N][1], dp[N][2]});
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int n,i,j,ans = 0,mi,cnt,now,sum,tmp;
    int mini = 10000; /* 最大値は10の4乗 */

    
    scanf("%d",&n); /* n個(1<=n<=1000)で全て異なる値 */
    
    int *W = malloc(sizeof(int)*n);
    memset(W,0,n);
    
    int *done = malloc(sizeof(int)*n);
    memset(done,0,n);
//    int mp[1010];
    int mp[1000];
    
    for( i=0 ; i<n ; i++ )
    {
        scanf("%d",&W[i]);
        if(W[i] < mini)
        {
            mini = W[i]; /* 最小に設定 */
        }
//        mp[W[i]] = 0;
        mp[i] = W[i]; /* W[i]は全て異なる値 */
    }
    
    /* mp[]を昇順にバブルソート */
    for( i=0 ; i<n; i++ )
    {
        for( j=1; j<n-i; j++ )
        {
            if( mp[j] < mp[j-1] )
            {
                tmp = mp[j];
                mp[j] = mp[j-1];
                mp[j-1] = tmp;
            }
        }
    }
    
    for( i=0 ; i<n ; i++)
    {
        if (done[i]==1) continue; /* 処理済なら次 */
        
//        cnt = 0,now = i, mi = 100000, sum = 0;
        cnt = 0;
        now = i;
        mi = 10000;
        sum = 0;

        while(1)
        {
            if (done[now]==1) break; /* 処理済ならループを抜ける */
            cnt++;
            done[now] = 1; /* 処理済 */
            if(W[now] < mi)
            {
                mi = W[now]; /* 最小値に設定 */
            }
            sum += W[now];

            for( j=0 ; j<n ; j++ )
            {
                if( mp[j] == W[now] )
                {
                    /* 検索 */
                    now = j;
                    break;
                }
            }
//            now = mp[W[now]];
        }

        if( (sum+(cnt-2)*mi) < (sum+mi+mini*(cnt+1)) )
        {
            tmp = sum+(cnt-2)*mi;
        }
        else
        {
            tmp = sum+mi+mini*(cnt+1);
        }
        ans += tmp;
    }
    
    printf("%d\n",ans);

    free(done);
    free(W);
    
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define MAX 100010
#define aout(a) REP(i,sizeof(a)) cout << a[i] << " "; cout << endl;
#define vout(v) REP(i,v,size()) cout << v[i] << " "; cout << endl;
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(){
  int N; cin>>N;
  vector<int> L(N);
  REP(i,N) cin>>L[i];
  sort(L.begin(),L.end());
  int ans = 0;
  REP(i,N){
    FOR(j,i+1,N){
      FOR(k,j+1,N){
        if(L[i]==L[j] || L[i]==L[k] || L[k]==L[j]) continue;
        if(L[i]+L[j]>L[k] && L[j]+L[k]>L[i] && L[k]+L[i]>L[j]) ans++;
      }
    }
  }
  cout<<ans;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s;
  cin >> s;
  map<char, int> mp;
  mp['N'] = 0;
  mp['W'] = 0;
  mp['S'] = 0;
  mp['E'] = 0;
  rep(i, s.length()) mp[s[i]]++;

  cout << ((((mp['N'] > 0 && mp['S'] > 0) || (mp['N'] == 0 && mp['S'] == 0)) &&
            ((mp['W'] > 0 && mp['E'] > 0) || (mp['W'] == 0 && mp['E'] == 0)))
               ? "Yes"
               : "No")
       << endl;
  return 0;
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long K, long long A, long long B){
    for(int i = K; i <= B; i += K){
        if(A <= i && i <= B){
            cout << "OK" << endl;
            return;
        }
    }
    cout << "NG" << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(K, A, B);
    return 0;
}


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

N = int(readline())
A = [int(x) for x in readline().split()]

answer = [None] * N
for i,a in enumerate(A):
    answer[a-1] = i+1

print(*answer)

Measured memory_bytes: 13876
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] AlphaBowl = new int[26];
        for(int i = 0; i < 26; i++){
            AlphaBowl[i] = 0;
        }
        while(sc.hasNext()){
            String str = sc.next();
            str = str.toLowerCase();
            for(int i = 0; i < str.length(); i++){
                char alpha = 'a';
                for(int j = 0; j <= ('z' - 'a'); j++){
                    if(str.charAt(i) == alpha){
                        AlphaBowl[j]++;
                        break;
                    }
                    alpha++;
                }
            }
        }
        char alpha = 'a';
        for(int i = 0; i <= ('z' - 'a'); i++){
            System.out.println(alpha + " : " + AlphaBowl[i]);
            alpha++;
        }
        sc.close();
    }
}


Measured memory_bytes: 26104
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int m;
		string s;
		cin>>m>>s;
		if(m==0&&s=="0") break;
		int n=s.size(),mx=-1;
		vector<vs> res;
		for(int i=0;i<1<<(n-1);i++){
			string t="";
			int x=0;
			vs a;
			for(int j=0;j<n;j++){
				t+=s[j];
				if((i&1<<j)||(j==n-1)){
					x+=atoi(t.c_str());
					a.push_back(t);
					t="";
				}
			}
			if(x<=m&&mx<=x){
				if(x>mx) res.clear();
				res.push_back(a);
				mx=x;
			}
		}
		if(res.empty()) cout<<"error"<<endl;
		else if(res.size()>1) cout<<"rejected"<<endl;
		else{
			cout<<mx;
			for(auto i:res[0]) cout<<' '<<i;
			cout<<endl;
		}
	}
}


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

#define rep(i, n) for (int i=0; i<n; ++i)
typedef long long ll;

const int mod = 1e9 + 7;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint dp0[2005][2005];
mint dp1[2005][2005];

int main(void){
  int n, m;
  cin >> n >> m;
  vector<int> s(n+1), t(m+1);
  rep(i, n) scanf("%d", &s[i]);
  rep(j, m) scanf("%d", &t[j]);
  
  dp0[0][0] = 1;
  rep(i, n+1) rep(j, m+1) {
    dp0[i+1][j] += dp0[i][j];
    dp1[i][j] += dp0[i][j];
    dp1[i][j+1] += dp1[i][j];
    if (s[i] == t[j]) {
      dp0[i+1][j+1] += dp1[i][j];
    }
  }
  mint ans = dp1[n][m];
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 63104
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define UMap        std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    llong power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd   ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm   ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs   ( llong n )          { return ( n < 0 ) ? -n : n; }
    boolean chmax ( llong &a, llong b ) { return a<b ? a=b, true : false; }
    boolean chmin ( llong &a, llong b ) { return b<a ? a=b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    signed call_of_Cthulhu( signed datum ) {

        int n;
        String q[3];
        read n >> q[0] >> q[1] >> q[2];
        int ans = 0;
        for ( int i = 0; i < n; i++ ) {
            char tmp[3];
            for ( int j = 0; j < 3; j++ ) {
                tmp[j] = q[j][i];
            }
            bozo_sort(tmp, tmp+3);
            if ( tmp[0] == tmp[2] ) ans += 0;
            elif ( tmp[0] != tmp[1] ) {
                if ( tmp[1] != tmp[2] ) {
                    ans += 2;
                }
                else {
                    ans++;
                }
            }
            elif ( tmp[1] != tmp[2] ) ans++;
        }
        echo ans fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 256
while True:
    H, W = map(int,input().split())
    if H == 0 and W == 0 :
        break
    print("#" * W)
    for i in range(1, H - 1):
        print("#", end="")
        print("." * (W - 2), end="")
        print("#")
    print("#" * W)
    print()


Measured memory_bytes: 5636
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

const val mod = (1e9 + 7).toInt()

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val H = sc.nextLong()
    val W = sc.nextLong()
    val t = sc.nextLong()

    val w = gcd(W, t)
    val h = gcd(H, t)

    var res = 0L

    val x = H / h
    val y = W / w
    res = (res + pow(2, x)) % mod
    res = (res + pow(2, y)) % mod
    res = (res + pow(2, gcd(x, y))) % mod
    res = (res - 3 + mod) % mod

    res = pow(res, w * h)

    println(res)
    /*val n = sc.nextLong()
    val m = sc.nextLong()
    val T = sc.nextLong()
    val gn = gcd(T, n)
    val gm = gcd(T, m)
    val mod = 1000000007
    val q = gcd(n / gn, m / gm)
    var res = 0L
    res = (res + pow(2, q)) % mod
    res = (res + pow(2, n / gn)) % mod
    res = (res + pow(2, m / gm)) % mod
    res = (res - 3 +mod) % mod
    println(pow(res, gn * gm))*/
}

fun inv(h: Long): Long = pow(h, (mod - 2).toLong())

fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)
fun pow(a: Long, x: Long): Long {
    var res = 1L
    var x = x
    var a = a
    while (x > 0) {
        if (x % 2 == 1L) res = (res * a) % mod
        a = (a * a) % mod
        x /= 2
    }
    return res
}


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 31400
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    a = readInt()
    m = {}
    for x in a:
        if x in m.keys():
            m[x] += 1
        else:
            m[x] = 1
    for i in range(1,n+1):
        if i in m.keys():
            print(m[i])
        else:
            print(0)
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 33524
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

using namespace std;

#define REP(var, count) for(int var=0; var<count; var++)

struct unionf {
	
	vector<int> data;
	
	unionf(int n) {
		REP(i, n+1) { data.push_back(i); }
	}
	
	int root(int a) {
		if(data[a] == a) { return a; }
		return (data[a] = root(data[a]));
	}
	
	bool issame(int a, int b) {
		return root(a) == root(b);
	}
	
	void unite(int a, int b) {
		data[root(a)] = root(b);
	}

};


int main(void) {
	int N, Q;
	cin >> N >> Q;
	
	unionf un(N);
	
	REP(i, Q) {
		int a, x, y;
		cin >> a >> x >> y;
		
		if ( a == 0 ) {
			un.unite(x, y);
		} else {
			cout << (un.issame(x, y) ? 1 : 0) << endl;
		}
	}
	
}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  char b;
  cin >> b;
  if(b == 'A') cout << 'T' << endl;
  if(b == 'T') cout << 'A' << endl;
  if(b == 'G') cout << 'C' << endl;
  if(b == 'C') cout << 'G' << endl;
  return 0;
}

Measured memory_bytes: 3576
def getparent(parent, place):
    childrens = [place]
    while place != parent[place]:
        place = parent[place]
        childrens.append(place)
    for i in childrens:
        parent[i] = place
    return place


def main():
    ans = []
    n, m = list(map(int, input().split()))
    pairs = []
    parent = [i for i in range(n)]
    parent_sum = [1 for _ in range(n)]
    for i in range(m):
        a, b = list(map(int, input().split()))
        pairs.append((a - 1, b - 1))
    sum_count = n * (n - 1) // 2
    ans.append(sum_count)
    for p, q in reversed(pairs[1:]):
        np, nq = getparent(parent, p), getparent(parent, q)
        if np != nq:
            sum_count -= parent_sum[np] * parent_sum[nq]
            parent_sum[np] += parent_sum[nq]
            parent[nq] = np
        ans.append(sum_count)
    ans.reverse()
    for i in ans:
        print(i)


if __name__ == "__main__":
    main()



Measured memory_bytes: 25028
#include <stdio.h>
 
#define AMAX 20   //define no ato ni ; wo tuketeha ikenai
#define MMAX 2000
int n,q;
int isExist[MMAX +1] = {0};// 0 de syokika
int main(void)
{
  int i,j;
  int num;
 
  scanf("%d",&n);
  for (i = 0;i<n;i++)
    {
      scanf("%d",&num);
      for(j = MMAX-num; 0<j; j--)
        {
          if(isExist[j])   // A retsu no suuchi wo tashite sono kazu ga mae ni tukurete itara 1
              
            {
              isExist[j+num] = 1; // mae ni tukureta kazu ni ima haittekita kazu wo tasu.
            }
        }
      isExist[num]=1; // suuji ga attara 0 wo 1 ni suru
      // ima haittekita suuji no tokoro wo 1 ni suru
    }
 
  scanf("%d", &q);
  for (i = 0;i < q; i++)
    {
      scanf("%d",&num);
      if(isExist[num])
        {
          printf("yes\n");
        }
      else
        {
          printf("no\n");
        }
    }
  return 0;
}

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

int main(){
  long n,p,kekka = 1;
  cin >> n >> p;
  long m = p;
  for(long i = 2;i*i <= m;i++){
    long c = 0;
    for(long j = 0;j > -1;j++){
      if(p % i == 0){
        p /= i;
        c++;
      }
      else{
        break;
      }
    }
    if(c >= n){
      for(long k = 0;k < c/n;k++){
        kekka *= i;
      }
      //cout <<c << " " << i << endl;
    }
  }
  if(n == 1){
    cout << kekka*p << endl;
  }
  else{
    cout << kekka << endl;
  }
}

Measured memory_bytes: 256
from sys import stdin
readline = stdin.readline

def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())

def main():
    A, B, C, D = i_map()
    print(max([A * C, A * D, B * C, B * D]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 61884
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<int> s;
    for(int i=0;i<3;i++){
        int a;
        cin >> a;
        s.insert(a);
    }
    cout << (s.size()==2? "Yes":"No") << "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int num[];
		num = new int[w];
		for(int i = 0 ; i < w ; i++) {
			num[i] = i + 1;
		}
		int n = sc.nextInt();
		for(int i = 0 ; i < n ; i++) {
			String str = sc.next();
			String sp[] = str.split(",");
			int a = Integer.parseInt(sp[0]) - 1;
			int b = Integer.parseInt(sp[1]) - 1;
			int swap = num[a];
			num[a] = num[b];
			num[b] = swap;
		}
		for(int i = 0 ; i < w ; i++) System.out.println(num[i]);
		sc.close();
	}
}


Measured memory_bytes: 26268
s = int(input())

numset = {s}
for i in range(2, 1000001, 1):
  
  if s % 2 == 0:
    s = s / 2
  else:
    s = (s * 3) + 1
  
  if {s} <= numset:
    print(i)
    break
  else:
    numset.add(s)

Measured memory_bytes: 2940
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize, k: usize
    };

    let mut res = 0;
    let mut n = n;
    while n > 0 {
        res += 1;
        n /= k;
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>a(n);
	map<int,int>m;
	for(auto&i:a){
		cin>>i;
		++m[i];
	}
	int64_t ans=0,tmp,tmp2;
	for(auto&i:m)ans+=(int64_t)i.second*(i.second-1)/2;
	for(auto&i:a){
		tmp=m.at(i);
		tmp=tmp*(tmp-1)/2;
		tmp2=m.at(i)-1;
		tmp2=tmp2*(tmp2-1)/2;
		cout<<ans-tmp+tmp2<<"\n"s;
	}
}

Measured memory_bytes: 8320
import sys
input=sys.stdin.readline
n=int(input())

a=[list(map(int,input().split())) for i in range(n)]

a=sorted(a,key=lambda x:x[1])

time=0
for l in a:
    time+=l[0]
    if time>l[1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 84572
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k) ans += p[i];
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3632
//ALL GLORY TO JESUS CHRIST 
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define frpn(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout);
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define fornd(i, n) for(int i=(int)(n-1); i>=0; --i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )

const int MOD = (int)1e9+7;

template <class T>
inline void rem(T &n){
   n = (-MOD <= n && n <= MOD) ? n : n%MOD ;
  if(n < 0) n += MOD; 
}
//modular inverse
//inv(a,m) - inverse of a mod m
template <class T>
inline T inv(T a, T m){
 return 1<a ? m - inv(m%a, a)*m/a : 1;
}
//const int NAX = (int)3e5+5;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    int n, k; cin >> n >> k;
    int res = 0;
    forn(i, n)  {
      int x; cin >> x;
      if(x >= k) ++res;
    }
    cout << res << "\n";
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
 
//calc G.C.D(m >= n)
int calcGcd(int m, int n){
    return n == 0 ? m : calcGcd(n, m%n);
}
//calc L.C.M
inline int calcLcm(int m, int n, int gcd){
    return m / gcd * n;
}

int main(){
	
    int a, b;
    // input
    while(std::cin >> a >> b){
        int gcd, lcm;
         
        if(a > b) gcd = calcGcd(a, b);
        else gcd = calcGcd(b, a);
        lcm = calcLcm(a, b, gcd);
        // output
        std::cout << gcd << " " << lcm << std::endl;
    }
     
    return 0;
}

Measured memory_bytes: 1160