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

using namespace std;

const int MAX = 1000001; 
  
// array to store prime factors 
int factor[MAX] = { 0 }; 
  
// function to generate all prime factors 
// of numbers from 1 to 10^6 
void generatePrimeFactors() 
{ 
    factor[1] = 1; 
  
    // Initializes all the positions with their value. 
    for (int i = 2; i < MAX; i++) 
        factor[i] = i; 
  
    // Initializes all multiples of 2 with 2 
    for (int i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
  
    // A modified version of Sieve of Eratosthenes to 
    // store the smallest prime factor that divides 
    // every number. 
    for (int i = 3; i * i < MAX; i++) { 
        // check if it has no prime factor. 
        if (factor[i] == i) { 
            // Initializes of j starting from i*i 
            for (int j = i * i; j < MAX; j += i) { 
                // if it has no prime factor before, then 
                // stores the smallest prime divisor 
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 
  
// function to calculate number of factors 
int calculateNoOFactors(int n) 
{ 
    if (n == 1) 
        return 1; 
  
    int ans = 1; 
  
    // stores the smallest prime number 
    // that divides n 
    int dup = factor[n]; 
  
    // stores the count of number of times 
    // a prime number divides n. 
    int c = 1; 
  
    // reduces to the next number after prime 
    // factorization of n 
    int j = n / factor[n]; 
  
    // false when prime factorization is done 
    while (j != 1) { 
        // if the same prime number is dividing n, 
        // then we increase the count 
        if (factor[j] == dup) 
            c += 1; 
  
        /* if its a new prime factor that is factorizing n,  
           then we again set c=1 and change dup to the new  
           prime factor, and apply the formula explained  
           above. */
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
  
        // prime factorizes a number 
        j = j / factor[j]; 
    } 
  
    // for the last prime factor 
    ans = ans * (c + 1); 
  
    return ans; 
} 

int main() {
    int n;
    cin>>n;
    generatePrimeFactors();
    long long ans=0;
    
    for(int i=1;i<n;i++){
        ans+= calculateNoOFactors(n-i);
    }
    
    cout<<ans;
}

Measured memory_bytes: 7532
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	while(cin>>n,n){
		vector<pii> v(n);
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			v[i]=pii(b+c,a);
		}
		sort(ALL(v));
		cout<<v.back().S<<" "<<v.back().F<<endl;
	}
}


signed main() {
	ios_base::sync_with_stdio(false);
    cin.tie(0);
  	cout<<fixed<<setprecision(20);
    mainmain();
}

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

using namespace std;
using ll = long long;

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

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

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const int mod = 1000000007;
// typedef long long ll;

struct mint {
	ll x;
	mint(ll x = 0): x( (x % mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	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 { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if(!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod-2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(istream& os, const mint& a) { return os << a.x; }


mint choose(int n, int a) {
	mint x = 1, y = 1;
	REP(i, a) {
		x *= (n-i);
		y *= i+1;
	}
	return x / y;
}


int main() {
	int a,b;
	cin >> a >> b;

	cout << (choose(a,2) + choose(b,2)).x << endl;


	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int ans = 0;
  int N;
  cin>>N;
  vector <int> a(N);
  int sum = 0;
  for(int k = 0;k<N;k++){
    cin>>a.at(k);
    sum += a.at(k);
  }
  sort(a.begin(),a.end());
  if(sum%10 != 0){
    ans = sum;
  }
  else{
    for(int i = 0;i<N;i++){
      if((sum-a.at(i))%10 != 0){
        ans = sum-a.at(i);
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
      

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int main(){
	long long a,b,c,max,t;
	cin>>a>>b>>c;
	max=a;
	if(a%2==0||b%2==0||c%2==0){
		printf("0\n");return 0;
		}
	if(b>a&&b>=c){
		max=b;
		printf("%lld\n",c*a);
		return 0;
		}
	if(b<c&&c>a){
		printf("%lld\n",a*b);
		return 0;
		}
		printf("%lld\n",b*c);
}

	


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1000][1000];
vector<ll> va,vb,vc;

int main(){
    cin>>n;
    cin>>a;
    b=a;
    for(int i=1;i<n;i++){
        cin>>aa[i];
        a=max(a,aa[i]);
        b=min(b,aa[i]);
    }
    C a-b E;
    
}

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

#define IOS std::cin.tie(0);std::ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>;

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())
#define END cout<<"\n"

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 55;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;
map<int,int>mp;

//----------------------Global-------------------------//

void findFactors(int num){
    while(num%2==0){
        num /= 2;
        mp[2]++;
    }
    for(int i=3;i<=num;i++){
        while(num%i==0){
            num /= i;
            mp[i]++;
        }
    }
}

signed main(){
    CIN(N);
    RepS(i,2,N)findFactors(i);
    ll ans=1;
    RepA(mp){
        ans=ans*(item.second+1)%MOD;
    }
    COUT(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define dbug(x) cout<<#x<<"="<<x<<endl
#define m0(x) memset(x,0,sizeof(x))
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pl;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}

int man(){

  int a,b,c;
  cin >> a>>b>>c;

  if(a==b){
    if(a==c)return 1;
    return 2;
  }
  if(a==c||b==c) return 2;
  return 3;
}
int main(){

  std::cout << man() << '\n';
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n, k;
	cin >> n >> k;

	int t = 1;
	for(int i = 1; i < k; i++){
		t += 2;
	}
	if(t > n){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}

}


Measured memory_bytes: 256
N,L=list(map(int, input().split()))

azi=[]
for i in range(N):
  azi.append(L+i)
  
if azi[0]*azi[N-1]<=0:
  eat = 0
elif abs(azi[0])<=abs(azi[N-1]):
  eat = azi[0]
else:
  eat = azi[N-1]

total=sum(azi)-eat

print(total)

Measured memory_bytes: 38384
#include<stdio.h>

int main() {

	int k;
	int i, j;
	int n;
	int c[500][500];

	//入力
	scanf("%d", &k);

	if (k == 1) {
		printf("1\n1\n");
		return 0;
	}

	n = (k + 3) / 4 * 2;

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			c[i][j] = (i + j) % n + 1;
		}
	}
	for (i = 1; i < n; i += 2) {
		for (j = 0; j < n; j++) {
			if (c[i][j] + n <= k)c[i][j] += n;
		}
	}

	//出力
	printf("%d\n", n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			printf("%d ", c[i][j]);
		}
		printf("\n");
	}

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int count = 0; 
  for (int i = 0; i < (int)s.size() - 1; i++) {
    if (s.at(i) != s.at(i + 1)) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3756
#include <stdio.h>
int main(){
    int H, W;
    scanf("%d %d", &H, &W);
    char a[H][W];
    for(int i = 0; i < H; i++){
        scanf("%s", a[i]);
    }
    int b[H][W];
    for(int i = 0; i < H; i++){
        int flag = 0;
        for(int j = 0; j < W; j++){
            if(a[i][j] == '#') flag = 1;
        }
        if(flag) for(int j = 0; j < W; j++) b[i][j] = 0;
        else for(int j = 0; j < W; j++) b[i][j] = 1;
    }
    for(int i = 0; i < W; i++){
        int flag = 0;
        for(int j = 0; j < H; j++){
            if(a[j][i] == '#') flag = 1;
        }
        if(!flag) for(int j = 0; j < H; j++) b[j][i] = 1;
    }
    for(int i = 0; i < H; i++){
        int u = 0;
        for(int j = 0; j < W; j++){
            if(!b[i][j]) {
                printf("%c", a[i][j]);
                u = 1;
            }
            if(u == 1 && j == W - 1) printf("\n");
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int n; cin >>n;
  vector<li> a(n);
  rep(i,n) cin >>a[i];
  sort(a.begin(),a.end(),greater<li>());
  int j=0,flag=1;
  li s=0;
  rep(i,n-1){
    s+=a[j];
    if(flag)j++;
    flag^=1;
  }
  print(s);
}


Measured memory_bytes: 4852
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

int main() {
	int N;
	int len;
	char W[105][16];
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> W[i];

	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			if (strcmp(W[i], W[j]) == 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	for (int i = 0; i < N - 1; i++) {
		len = strlen(W[i]) - 1;
		//printf("%c,%c\n", W[i][len], W[i + 1][0]);
		if (W[i][len] != W[i + 1][0]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	//cin >> N;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    vector<int> red(N),cnt(N, 1);
    red[0] = 1;
    rep(i,0,M){
        int a,b;
        cin >> a >> b;
        a--,b--;
        if(cnt[a] == 1){
            if(red[a]){
                red[a] = 0;
                red[b] = 1;
            }
        }else{
            if(red[a]){
                red[b] = 1;
            }
        }
        cnt[a]--;
        cnt[b]++;
    }
    int ans = 0;
    rep(i,0,N)ans += red[i];
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

/*
 T 0
 A 1
 G 2
 C 3
 */

char cul(ll a){
    return (a==0?'T':(a==1?'A':(a==2?'G':'C')));
}

bool judge(string s){
    if(s[0]=='A' && s[1]=='G' && s[2]=='C'){return false;}
    if(s[1]=='A' && s[2]=='G' && s[3]=='C'){return false;}
    return true;
}

int main(){
    ll n;
    cin>>n;
    const ll M=1LL<<(2*3);
    vector<vector<ll>> dp(n+1,vector<ll>(M,0));
    vector<vector<ll>> edge(M,vector<ll>(M,0));
    for(int t=0;t<M;t++){
        for(int h=0;h<4;h++){
            string s;
            for(int j=0;j<3;j++){
                s.push_back(cul(t>>(2*j)&3));
            }
            s.push_back(cul(h));
            bool j=judge(s);
            for(int i=0;i<3;i++){
                swap(s[i],s[i+1]);
                if(!judge(s)){j=false;}
                swap(s[i],s[i+1]);
            }
            ll k=t;
            k|=h<<(2*3);
            if(j){edge[t][k>>2]=1;}
        }
    }
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int t=0;t<M;t++){
            for(int h=0;h<4;h++){
                ll k=t;
                k|=h<<(2*3);
                k>>=2;
                dp[i+1][k]+=edge[t][k]*dp[i][t];
                dp[i+1][k]%=MOD;
            }
        }
    }
    ll ans=0;
    for(auto &I:dp.back()){ans+=I;}
    cout<<ans%MOD<<endl;
    
    
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	int d = x%10;
	int c = x/10%10;
	int b = x/10/10%10;
	int a = x/10/10/10%10;
	for(int i = 0; i<8; i++) {
	    int number = i;
	    int cnt = 0;
	    int[] abcd = {a,b,c,d};
	    char[] symbol = {0,0,0};
	    while(cnt < 3) {
		symbol[cnt] = (number%2==0) ? '+': '-';
		number = number/2;
		cnt++;
	    }
	    int result = abcd[0];
	    for(int j = 0; j<3; j++) {
		if(symbol[j]=='+') {
		    result += abcd[j+1];
		}else{
		    result -= abcd[j+1];
		}
	    }
	    if(result == 7) {
		System.out.println(a+""+symbol[0] +""+b+""+ symbol[1] +""+c+""+ symbol[2] +""+d+"=7");
		return;
	    }

	}
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
	int N;
	const int MOD = 1e9+7;
	cin >> N;
	vector<long long> A(N),T(N);
	vector<long long> AA(N),TT(N);
	for(int i=0;i<N;i++){
		cin >> T[i];
	}
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
 
	AA[N-1] = A[N-1];
	TT[0] = T[0];
	for(int i=0;i<N-1;i++){
		if(T[i] != T[i+1])TT[i+1] = T[i+1];
	}
	for(int i=N-1;i>0;i--){
		if(A[i] != A[i-1])AA[i-1] = A[i-1];
	}
 
	bool ok = true;
	for(int i=0;i<N;i++){
		if(AA[i] != 0){
			if( T[i] < AA[i] )ok =false;
		}
		if(TT[i] != 0){
			if( A[i] < TT[i])ok = false;
		}
		if(AA[i] != 0 && TT[i] != 0 && AA[i] != TT[i])ok = false;
		// cerr << AA[i] << " ";
	}
	// cerr << endl;
 
	if(!ok){
		cout << 0 << endl;
		return 0;
	}
 
	long long ret = 1;
	for(int i=0;i<N-2;i++){
		if( T[i] == T[i+1] && A[i+1] == A[i+2]){
			ret *= min(T[i+1],A[i+1]);
			ret %= MOD;
			// cerr << min(T[i],A[i]) << " ";
		}
	}
 
	if( T[N-1] != A[0] )cout << 0 << endl;
	else cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3328
n,q=map(int,input().split())
l=[0 for i in range(n)]
for i,v in enumerate(list(input().replace("AC","X!"))):
    l[i]=l[i-1]+(v=="!")
for c in range(q):
    h,m=map(int,input().split())
    print(l[m-1]-l[h-1])

Measured memory_bytes: 7856
import sys
readline = sys.stdin.readline

H,W,K = map(int,readline().split())
grid = [None] * (H+1)
grid[0] = [0] * (W+1)
for i in range(1,H+1):
  grid[i] = [0] + list(map(int,list(input())))
  
# 二次元累積和でチョコレートの数を管理
# 直前に選んだチョコのY座標をp,X座標をqとすると、
# チョコレートの数をO(1)で求められる
# 最初に空行を入れているので1-indexで。

for i in range(len(grid)-1):
  for j in range(len(grid[i])):
    grid[i+1][j] = grid[i][j] + grid[i+1][j]

for i in range(len(grid)):
  for j in range(len(grid[i])-1):
    grid[i][j+1] = grid[i][j] + grid[i][j+1]
  
def get_choco_cnt(i,j,p,q):
  return grid[i][j] - grid[i][q] - grid[p][j] + grid[p][q]
  
# Hが10と少ないので、切る場所9箇所をすべて試しても2^9 = 512通り
# すべてに対して、Wのどこを切るかを求める。
# 二分探索なら　O(2^(H-1) * (log W * H)) = 約51200
# 線形探索でも　O(2^(H-1) * WH) = 5,120,000

def isOk(x,lastq,cond,K,H,W):
  # xで切ったとき、iで分割されたすべての領域の数がK以下になればOK
  lastp = 0 # Hを最後に切った場所
  for j in range(H-1):
    if (cond >> j) & 1: # j+1で切る
      if get_choco_cnt(j+1,x,lastp,lastq) > K:
        return False
      lastp = j+1
  # 最後に切った場所から、最後まで
  if get_choco_cnt(H,x,lastp,lastq) > K:
    return False
  return True
  
def decide_cut(cond,lastq,K,H,W):
  ok = lastq
  ng = W+1
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if isOk(mid,lastq,cond,K,H,W):
      ok = mid
    else:
      ng = mid
  return ok

ans = 10000
for cond in range(2 ** (H-1)):
  cut_num = (bin(cond)[2:]).count("1") # カットした回数
  lastq = 0 # 最後にカットした場所
  while lastq < W+1:
    new_lastq = decide_cut(cond,lastq,K,H,W)
    if new_lastq == W:
      break
    if new_lastq == lastq:
      cut_num = 10000
      break
    cut_num += 1
    lastq = new_lastq
  if ans > cut_num:
    ans = cut_num
print(ans)

Measured memory_bytes: 3440
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
char T[200010];
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	scanf("%s",T+1);int n=strlen(T+1);
	for(int i=1;i<=n;++i)if(T[i]=='?')T[i]='D';
	printf("%s",T+1);
	return 0;
}


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

using namespace std;

int f[5];
long long c[444][5], p[444][5];
long long a[444];
long long an;
map<long long, int> mp;
int n;

long long pw(int a, int b){
	long long tmp = 1;
	for(int i = 1; i <= b; ++i) tmp *= a;
	return tmp;
}

long long get(int x, int y, int z, int h){
	long long cur = x;
	cur <<= 10;
	cur += y;
	cur <<= 10;
	cur += z;
	cur <<= 10;
	cur += h;
	return cur;
}

long long pack(int x, int y, int z, int h){
	return min(min(get(x, y, z, h), get(y, z, h, x)), 
			   min(get(z, h, x, y), get(h, x, y, z)));
}

int rot(long long h){
	int res = 1;
	long long ori = h;
	for(int i = 1; i < 4; ++i){
		long long tmp = h & ((1 << 10) - 1);
		h >>= 10;
		tmp <<= 30;
		h += tmp;
		res += h == ori;		
	}
	return res;
}

int main(){
//	freopen("input.inp", "r", stdin);
	f[0] = 1;
	for(int i = 1; i < 5; ++i) f[i] = f[i - 1] * i;
	for(int i = 0; i <= 400; ++i) c[i][0] = 1;
	for(int i = 1; i <= 400; ++i){
		for(int j = 1; j <= min(4, i); ++j){
			c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
		}
	}
	scanf("%d",&n);
	for(int i = 1; i <= n; ++i){
		scanf("%d%d%d%d",&p[i][0],&p[i][1],&p[i][2],&p[i][3]);
		a[i] = pack(p[i][0], p[i][1], p[i][2], p[i][3]);
	}
	for(int i = 1; i <= n; ++i){
		for(int ii = 1; ii < i; ++ii){
			for(int j = 0; j < 4; ++j){
				long long y[4];
				y[0] = pack(p[i][1], p[i][0], p[ii][(1 + j) % 4], p[ii][(0 + j) % 4]);
				y[1] = pack(p[i][2], p[i][1], p[ii][(0 + j) % 4], p[ii][(3 + j) % 4]);
				y[2] = pack(p[i][3], p[i][2], p[ii][(3 + j) % 4], p[ii][(2 + j) % 4]);	
				y[3] = pack(p[i][0], p[i][3], p[ii][(2 + j) % 4], p[ii][(1 + j) % 4]);
				sort(y, y + 4);
				long long tmp = 1;
				for(int l = 0; l < 4;){
					int cnt = 1, r = l;
					while (r < 4 && y[l] == y[r + 1]) ++cnt, ++r;
					int num = mp[y[l]];
					if (y[l] == a[ii]) --num;
					if (num < cnt){
						tmp = 0;
						break;
					}
					tmp *= c[num][cnt] * pw(rot(y[l]), cnt) * f[cnt];
					l += cnt;
				}
				an += tmp;
			}
		}
		++mp[a[i]];
	}
	printf("%lld",an);
	return 0;
}

Measured memory_bytes: 20224
c=0
import sys
def merge(x, y):
  i=j=0
  res = []
  while j<len(y) or i<len(x):    
    while i<len(x) and (j>=len(y) or x[i]<=y[j]):

      res.append(x[i])
      i+=1
    if j<len(y):
      global c
      res.append(y[j])
      c+=len(x)-i
    j+=1
  return res
  
def sort(x):
  if len(x)>1:
    l = sort(x[:len(x)//2])
    r = sort(x[len(x)//2:])
    merged=merge(l, r)
    return merged
  else:
    return x
input()
a=list(map(int, input().split()))
sort(a)

print(c)


Measured memory_bytes: 27692
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>

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

using namespace std;
const int V = 100005;
int INF = 1000000000;

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};



int main(){
  int n,m;
  cin >> n >> m;
  int x,y,z;

  bool havelist[n];
  rep(i,n) havelist[i] = false;

  UnionFind tree(n);

  rep(i,m){
    cin >> x >> y >> z;
    tree.merge(x,y);
  }
  int r[n];
  rep(i,n) {
    r[i] = tree.root(i);
  }
  rep(i,n) havelist[r[i]] = true;
  int ans = 0;
  rep(i,n) if(havelist[i]) ans++;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

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

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n; cin >> n;
    deque<int> q;
    rep(i, n) {
        int a; cin >> a;
        if (i % 2) q.push_front(a);
        else q.push_back(a);
    }

    if (n % 2) reverse(all(q));

    int j = 0;
    for (auto i : q) {
        cout << i;
        j++;
        if (j == n) cout << endl;
        else cout << ' ';
    }
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,p;cin>>n>>p;
  ll a[n];
  ll e=0,o=0;
  for(ll i=1;i<=n;i++){
    cin>>a[i];
    a[i]%=2;
    if(a[i]==1)o++;
    else e++;
  }
  ll dp[n+1][n+1];
  for(ll i=0;i<=n;i++){
    dp[i][0]=1;
    dp[i][i]=1;
  }
  for(ll i=2;i<=n;i++){
    for(ll j=1;j<i;j++){
      dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
    }
  }
  ll ans=0;
  if(p==1){
    for(ll i=1;i<=o;i+=2){
      for(ll j=0;j<=e;j++){
      ans+=dp[o][i]*dp[e][j];
      }
    }
  }
  else{
    for(ll i=0;i<=o;i+=2){
      for(ll j=0;j<=e;j++){
        ans+=dp[o][i]*dp[e][j];
      }
    }
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}
/*
 Atcoder 100~200点代
 アな問題が多いので,まとめる
*/
// https://abc042.contest.atcoder.jp/tasks/abc042_a
//void solve(){ ll A,B,C; cin >> A >> B >> C; if(A == 5 && B == 5 && C == 7){ cout << "YES" << endl; return;} if(A == 5 && B == 7 && C == 5){ cout << "YES" << endl; return;} if(A == 7 && B == 5 && C == 5){ cout << "YES" << endl; return;} cout << "NO" << endl; return ; }
// https://abc043.contest.atcoder.jp/tasks/abc043_a
//void solve(){ ll N; cin >> N; cout << N*(N+1)/2 << endl; }
// https://abc044.contest.atcoder.jp/tasks/abc044_a
//void solve(){ll N,K,X,Y;cin>>N>>K>>X>>Y; cout<<X*min(N,K)+Y*max(0LL,N-K)<<endl;}
// https://abc045.contest.atcoder.jp/tasks/abc045_a
//void solve(){ll a,b,h;cin>>a>>b>>h;cout<<(a+b)*h/2<<endl;}
// https://abc046.contest.atcoder.jp/tasks/abc046_a
//void solve(){ ll a,b,c; cin >> a >> b >> c; set<ll> s; s.insert(a); s.insert(b); s.insert(c); cout << s.size() << endl; }
// https://abc047.contest.atcoder.jp/tasks/abc047_a
//void solve(){ll a,b,c;cin>>a>>b>>c;if(a==b+c||b==a+c||c==a+b)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
// https://abc048.contest.atcoder.jp/tasks/abc048_a
//void solve(){string s1,s2,s3;cin>>s1>>s2>>s3;cout<<"A"<<s2[0]<<"C"<<endl;}
// https://abc049.contest.atcoder.jp/tasks/abc049_a
//void solve(){char c;cin>>c;string s="aiueo";if(s.find(c)!=string::npos)cout<<"vowel"<<endl;else cout<<"consonant"<<endl;}
// https://abc050.contest.atcoder.jp/tasks/abc050_a
void solve(){ll A,B;char op;cin>>A>>op>>B;if(op=='+')cout<<A+B<<endl;else cout<<A-B<<endl;}
// https://abc051.contest.atcoder.jp/tasks/abc051_a
//void solve(){}
// https://abc052.contest.atcoder.jp/tasks/abc052_a
//void solve(){}
// https://abc053.contest.atcoder.jp/tasks/abc053_a
//void solve(){}
// https://abc054.contest.atcoder.jp/tasks/abc054_a
//void solve(){}

// Main function
int main(void) {cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }


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

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}


int main() {

	int N;
	cin >> N;
	vector<int> inputs(N);
	for (int i = 0; i < N; i++) {
		cin >> inputs[i];
	}
	sort(inputs.begin(), inputs.end());

	int min_num = inputs[0];
	int max_num = inputs[N - 1];
	
	vector<bool> candidate(max_num+1, false);

	set<int> duplicates;
	int last_num = 0;
	for (int i = 0; i < N; i++) {
		int target = inputs[i];
		candidate[target] = true;

		if (last_num == target) duplicates.insert(target);

		last_num = target;
	}
	
	int ans = 0;
	for (int i = min_num; i <= max_num; i++) {
		if (candidate[i]) {
			if(duplicates.count(i)==0) ans++;
			for (int j = 2; i * j <= max_num; j++) {
				candidate[i * j] = false;
			}
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 4948
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    ls1 = [False] * 1000
    ls2 = [False] * 1000
    ls3 = [False] * 1000
    for i in range(n):
        t = [s[i]]
        if not ls1[int("".join(t))]:
            ls1[int("".join(t))] = True
            for j in range(i + 1, n):
                t = [s[i], s[j]]
                if not ls2[int("".join(t))]:
                    ls2[int("".join(t))] = True
                    for k in range(j + 1, n):
                        t = [s[i], s[j], s[k]]
                        ls3[int("".join(t))] = True
    print(ls3.count(True))


if __name__ == '__main__':
    solve()


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  ll n, a, max_a = 0;
  cin >> n >> max_a;
  ll ans = 0;
  for(int i = 1; i < n; ++i)
  {
    cin >> a;
    ans += max(0LL, max_a - a);
    max_a = max(a, max_a);
  }
  cout << ans;

}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int main(){
  int N,T,m[101];cin>>N>>T;
  int MIN=0;
  int M=110000;
  for (int i=0;i<N;++i){
    cin>>m[i];
    MIN+=m[i];
    if (M>m[i]) M=m[i];
  }
  int P=T-MIN;
  int ans=N+P/M;
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;

public class hello
{
    public static void Main()
    {
        string line2;
        for (; (line2 = Console.ReadLine()) != null;)
        {
            var a = new long[8];
            string[] line = line2.Trim().Split(' ');
            for (int i = 0; i < 8; i++)
                a[i] = (long)(decimal.Parse(line[i]) * 100000);
            var x1 = a[2] - a[0];
            var y1 = a[3] - a[1];
            var x2 = a[6] - a[4];
            var y2 = a[7] - a[5];
            var ip = x1 * x2 + y1 * y2;
            Console.WriteLine(ip == 0 ? "YES":"NO");
        }
    }
}



Measured memory_bytes: 13904
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, x, m = input_int_list()

    # 方針 循環するため、その循環を見つける。
    # 1.循環を探す
    A = []
    used = set([x])
    A.append(x)
    while True:
        a_next = ((A[-1])**2) % m
        if a_next in used:
            n_loop = a_next
            break
        A.append(a_next)
        used.add(a_next)
    # 2.ループの場所を探す
    start_ptr = A.index(n_loop)
    end_ptr = len(A) - 1
    loop_len = end_ptr - start_ptr + 1
    loop_sum = sum(A[start_ptr:])
    ans = 0
    rem = n - 1
    # 3.ループに入るまで分を足す
    if start_ptr < rem:
        ans += sum(A[:start_ptr])
        rem -= start_ptr
        if rem >= loop_len > 0:
            ans += loop_sum * (rem // loop_len)
        rem = rem % loop_len
        ans += sum(A[start_ptr:start_ptr + rem + 1])
        print(ans)
    else:
        ans = sum(A[:n])
        print(ans)
        return

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 76840
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	int count;
	if (K == 1)
		cout << 0;
	else {
		cout << N - K;
	}
	
	return 0;
}


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


int main() {

	int n, l;
	cin >> n >> l;

	vector<string> s(n);
	for(int i=0; i<n; i++){
		cin >> s.at(i);
	}

	sort(s.begin(), s.end());
	for(int i=0; i<n; i++){
		cout << s.at(i);
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int ans[555][555];
void doit(int l, int r, int level) {
  if (l + 1 == r) return;
  int mid = (l + r) / 2;
  for (int i = l; i < mid; i++) {
    for (int j = mid; j < r; j++) {
      ans[i][j] = level;
    }
  }
  doit(l, mid, level + 1);
  doit(mid, r, level + 1);
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  doit(0, n, 1);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (j > i + 1) cout << " ";
      cout << ans[i][j];
    }
    cout << '\n';
  }
  return 0;
}

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

namespace Volume0014
{
    class Program
    {
        static double _endPoint = 600;
        static void Main(string[] args)
        {
            string divisionNum = "";
            while ((divisionNum = Console.ReadLine()) != null)
            {
                double areaOfIntegration = Integration.Integral(0, _endPoint, double.Parse(divisionNum));
                Console.WriteLine(areaOfIntegration);
            }
        }
    }
    class Integration
    {
        internal static double Integral(double startPoint, double endPoint, double divisionNum)
        {
            double numOfSquare = endPoint / divisionNum;
            double areaOfIntegration = 0;
            for (int i = 1; i < numOfSquare; ++i)
            {
                areaOfIntegration += divisionNum * Function.Function1(i * divisionNum);
            }
            return areaOfIntegration;
        }
    }
    class Function
    {
        internal static double Function1(double x)
        {
            return x * x;
        }
    }
}



Measured memory_bytes: 15912
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;

int main(void) {
    vector<ll> vec;
    ll n, y;
    ll i, j, k;
    cin >> n >> y;
    
    for(i=0; i<=min(y/10000, n); i++) {
        for(j=0; j<=min(y/5000, n); j++) {
            if(y-10000*i-5000*j>=0 && (y-10000*i-5000*j)%1000==0 && i+j+(y-10000*i-5000*j)/1000==n) {
                printf("%lld %lld %lld", i, j, (y-10000*i-5000*j)/1000);
                return 0;
            }
        }
    }
    printf("-1 -1 -1\n");
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <tuple>
#include <map>
#include <cassert>

using namespace std;
typedef long long ll;

struct union_find {
    vector<ll> par;
    vector<ll> rank;

    union_find(ll n) : par(n, 0), rank(n, 0) {
        for(ll i = 0; i < n; ++i){ par.at(i) = i; }
    }

    ll find(ll x){
        if(par.at(x) == x){
            return x;
        }else{
            return par.at(x) = find(par.at(x));
        }
    }

    void unite(ll x, ll y){
        x = find(x);
        y = find(y);
        if(x == y){ return; }
        if(rank.at(x) < rank.at(y)){
            par.at(x) = y;
        }else{
            par.at(y) = x;
            if(rank.at(x) == rank.at(y)){
                rank.at(x)++;
            }
        }
    }

    bool same(ll x, ll y){
        return find(x) == find(y);
    }
};


int main(){
    ll n;
    cin >> n;
    map<pair<int, ll>, ll> c2i;
    vector<pair<ll, ll>> ps;
    for(ll i = 0; i < n; ++i){
        ll x, y;
        cin >> x >> y;
        ps.push_back(make_pair(x, y));

        auto tmpx = make_pair(0, x);
        if(c2i.count(tmpx) == 0){
            c2i.insert(make_pair(tmpx, c2i.size()));
        }
        auto tmpy = make_pair(1, y);
        if(c2i.count(tmpy) == 0){
            c2i.insert(make_pair(tmpy, c2i.size()));
        }
    }

    union_find uf(c2i.size());
    for(auto p : ps){
        uf.unite(
            c2i.at(make_pair(0, p.first)),
            c2i.at(make_pair(1, p.second)));
    }

    map<ll, ll> count_x, count_y;
    for(auto it = c2i.begin(); it != c2i.end(); ++it){
        if(it->first.first == 0){
            count_x[uf.find(it->second)]++;
        }else{
            count_y[uf.find(it->second)]++;
        }
    }

    ll ans = - n;
    for(auto it = count_x.begin(); it != count_x.end(); ++it){
        ans += it->second * count_y.at(it->first);
    }

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


Measured memory_bytes: 9584
import std.stdio;
import std.conv;
import std.string;
import std.array;

void main() {
  string[] input1 = split(readln());
  string[] input2 = split(readln());

  int S;
  int T;
  for(int i = 0; i < 4; ++i)
    S += to!int(input1[i]);

  for(int i = 0; i < 4; ++i)
    T += to!int(input2[i]);

  if (S > T)
    writeln(S);
  else
    writeln(T);
}



Measured memory_bytes: 2444
#include<iostream>
using namespace std;
using ll = long long int;
const int size=405;
const ll inf=1e18;
ll dp[size][size],psum[size];
ll sum(int l,int r)
{
    if(l==0)
        return psum[r];
    return psum[r]-psum[l-1];
}
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i],psum[i]=arr[i];
    for(int i=1;i<n;i++)
        psum[i] += psum[i-1];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            dp[i][j]=inf;
        dp[i][i]=0;
    }
    for(int i=n-1;i>=0;i--)
    {
        for(int j=i;j<n;j++)
        {
            for(int k=i;k<j;k++)
            {
                dp[i][j] = min(dp[i][j],(dp[i][k]+dp[k+1][j])+sum(i,j));
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    bool cnt[10] = {false};
    int n;
    rep(i, 4){
        cin >> n;
        cnt[n] = true;
    }

    if(cnt[1] && cnt[9] && cnt[7] && cnt[4]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n;
    cin >> n;
    vector<li> as(n);
    for (int i = 0; i < n; ++i) {
        cin >> as[i];
    }
    li ans = 0;
    map<li, li> counts;
    for (int i = 0; i < n; ++i) {
        counts[as[i]] += 1;
        ans += as[i];
    }
    li q;
    cin >> q;

    for (int _q = 0; _q < q; ++_q) {
        li b, c;
        cin >> b >> c;
        ans += c * counts[b] - b * counts[b];
        counts[c] += counts[b];
        counts[b] = 0;
        cout << ans << '\n';
    }


    return 0;
}

Measured memory_bytes: 10116
#include<iostream>
using namespace std;
int M[101][101];

int main(){
  int n,u,k,v;
  cin>>n;

  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(j) cout<<" ";
      cout<<M[i][j];
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3108
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let k: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();

    for i in 0..n {
        if i == k-1 {
            print!("{}", ((s[i] as u8) - ('A' as u8) + ('a' as u8)) as char);
        } else {
            print!("{}", s[i]);
        }
    }
    println!();
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define inf 9999999
using namespace std;

typedef int weight;
typedef vector<weight> array;
typedef vector<array> matrix;

void backward_traverse(int v, int s, int r, matrix &g,
		       vector<int> &no, vector< vector<int> > &comp,
		       vector<int> &prev, vector<weight> &mcost,
		       vector<int> &mark, weight &cost, bool &found) {
  const int n = g.size();
  if (mark[v]) {
    vector<int> temp = no;
    found = true;
    do {
      cost += mcost[v];
      v = prev[v];
      if (v != s) {
        while (comp[v].size() > 0) {
          no[comp[v].back()] = s;
          comp[s].push_back(comp[v].back());
          comp[v].pop_back();
        }
      }
    } while (v != s);
    for (int j = 0; j < n; ++j)
      if (j != r && no[j] == s)
        for (int i = 0; i < n; ++i)
          if (no[i] != s && g[i][j] < inf)
            g[i][j] -= mcost[ temp[j] ];
  }
  mark[v] = true;
  for (int i = 0; i < n; ++i)
    if (no[i] != no[v] && prev[ no[i] ] == v)
      if (!mark[ no[i] ] || i == s)
        backward_traverse(i, s, r, g,
			  no, comp, prev, mcost, mark, cost, found);
}

weight minimum_spanning_arborescence(int r, matrix &g) {
  const int n = g.size();
  
  vector<int> no(n);
  vector< vector<int> > comp(n);
  for (int i = 0; i < n; ++i) {
    no[i] = i;
    comp[i].push_back(i);
  }
  weight cost = 0;
  while (1) {
    vector<int> prev(n, -1);
    vector<weight> mcost(n, inf);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (j == r) continue;
        if (no[i] != no[j] && g[i][j] < inf) {
          if (g[i][j] < mcost[ no[j] ]) {
            mcost[ no[j] ] = g[i][j];
            prev[ no[j] ] = no[i];
          }
        }
      }
    }
    bool stop = true;
    vector<int> mark(n);
    for (int i = 0; i < n; ++i) {
      if (i == r || mark[i] || comp[i].size() == 0) continue;
      bool found = false;
      backward_traverse(i, i, r, g,
			no, comp, prev, mcost, mark, cost, found);
      if (found) stop = false;
    }
    if (stop) {
      for (int i = 0; i < n; ++i)
        if (prev[i] >= 0)
          cost += mcost[i];
      return cost;
    }
  }
}

int main(){
  int s,t,w,n;
  for(;;){
    cin>>n;
    if(n==0) break;
    matrix g(n+1);
    for(int i=0;i<=n;i++){
      g[i].resize(n+1);
      g[i][0]=inf;
    }
    for(int i=1;i<=n;i++)
      for(int j=0;j<=n;j++)
	cin>>g[j][i];
    printf("%d\n",minimum_spanning_arborescence(0,g));
  }
}


Measured memory_bytes: 1212
n,k=map(int,input().split())
p=list(map(int,input().split()))

ans=0
if n!=1:
    for i in range(k):
        min=p[i]
        for j in range(i+1,n):
            if min>p[j]:
                min=p[j]
                p[j]=p[i]
                p[i]=min
        ans+=min
else:
    ans=p[0]
print(ans)


Measured memory_bytes: 9192
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans=0;
    for(int i=0;i<n;i++){
        ll j=lower_bound(a.begin(),a.end(),b[i])-a.begin();
        ll k=upper_bound(c.begin(),c.end(),b[i])-c.begin();
        ans+=j*(n-k);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4560
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define pdd pair<double,double>
using namespace std;
int main(){
    long long x,y;
    scanf("%lld%lld",&x,&y);
    if(x%y==0)printf("-1\n");
    else printf("%lld\n",x);
    return 0;
}
/*
1 1 2 2
2
2 0 1
1 1 1
*/


Measured memory_bytes: 256