akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

typedef long long i64;
const int inf = (int)1.05e9;


int main()
{
	int n;
	int m;
	vector<int> xs;
	vector<int> count;
	vector<int> same;

	scanf("%d%d", &n, &m);
	xs.resize(n);
	count.resize(m);
	same.resize(m);
	for(int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		xs[i] = x;
	}

	sort(xs.begin(), xs.end());

	for(int i = 0; i < n; ++i)
		count[xs[i] % m] += 1;
	int lit = 0;
	while(lit < n) {
		int rit = lit + 1;
		while(xs[rit] == xs[lit] && rit < n)
			rit += 1;
		int c = (rit - lit) / 2;
		same[xs[lit] % m] += c;
		lit = rit;
	}

	int ans = 0;

	for(int i = 0; i <= (m - i); ++i) {

		int l = i;
		int r = (m - i);

		if(l == 0) {
			ans += count[l] / 2;
			continue;
		} else if(l == r) {
			ans += count[l] / 2;
			continue;
		}

		int pa = min(count[l], count[r]);

		int sa_l = min((count[l] - pa) / 2, same[l]);
		int sa_r = min((count[r] - pa) / 2, same[r]);

		//printf("%d: %d %d %d\n", i, pa, sa_l, sa_r);

		ans += (pa + sa_l + sa_r);
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n;
  cin >> n;
  
  vector<int>num(n,0);
  for(int i=0;i<n;i++){
    cin >> num[i];
  }

  int max = 0;
  int p = 0;
  for(int i=0;i<n;i++){
    if(num[i] > max){
      max = num[i];
      p = i;
    }
  }
  
  num[p] = 0;
  int max2 = 0;
  int q = 0;
  for(int i=0;i<n;i++){
    if(num[i] > max2){
      max2 = num[i];
      q = i;
    }
  }
  
  for(int i=0;i<n;i++){
    if(i == p){
      cout << max2 << endl;
    }
    else
      cout << max << endl;
  }
  
  return 0;
}



      

Measured memory_bytes: 2432
#include <iostream>

using namespace std;

main(){
  int data[30];
  int n, in;
  while(1){
    cin >> in;
    if(in==0) break;

    for(int i=0;i<in;i++){
      cin >> data[i];
    }

    n=32;
    int turn=0;
    int p=0;
    while(1){
      if(turn==0){
	n-=(n-1)%5;
      }else{
	if(p==in) p=0;
	n-=data[p++];
      }
      if(n<=0){
	printf("0\n");
	break;
      }else{
	printf("%d\n", n);
      }
      turn=(turn+1)%2;
    }
  }
  return 0;
}

Measured memory_bytes: 0
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
#include <regex>
using namespace std;
using ll = int64_t;
using P = pair<int,int>;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
 double a,b,c,d,e,f;
 cin>>a>>b>>c>>d>>e>>f;
 double maxs=0;
 double maxsw=a*100;
 double sugar;
 double water;
 rep(i,3000){
   rep(j,3000){
     sugar=i*c+j*d;
     if((sugar*(100+e)/e)>f){continue;}
     rep(n,30){
       rep(m,30){
         water=n*a*100+m*b*100;
         if(water==0){continue;}
         if(sugar+water>f){
           continue;
         }
         if(sugar>(double)(e*water/(double)(100))){
           continue;
         }
         if((sugar/(sugar+water))>(maxs/maxsw)){
           //cout<<i<<j<<sugar<<" "<<sugar+water<<endl;
           maxs=sugar;
           maxsw=sugar+water;
         }
       }
     }
   }
 }
 cout<<maxsw<<" "<<maxs<<endl;
}




Measured memory_bytes: 3764
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rr(x,y) read(x);read(y)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define pb(x) push_back(x)
#define sss(str) scanf("%s",str+1)
#define ssf(x) scanf("%lf",&x)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long LL;
typedef double dd;
typedef pair<int,int> pt;
const int N=1e5+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const int sz=18;
const double eps=1e-10;
const double pi=acos(-1);
//***********************

//***********************
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    int n,m;
    rr(n,m);
    if(n>=10) cout<<m<<endl;
    else{
        m+=100*(10-n);
        cout<<m<<endl;
    }
    return 0;
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
#define guard(x) if( not ( x ) ) continue;
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename T>
struct Maybe {
   T x;
   bool valid;
   Maybe() : valid(false) {}
   Maybe(T x_) : x(x_), valid(true) {}
   operator T() const {
      assert( valid );
      return x;
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      Int x, y, z; scan(x, y, z);
      Int res = (x - z) / (y + z);
      printf("%ld\n", res);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




Measured memory_bytes: 256
S = input()
g = 0
p = 0

ans = 0

for i, s in enumerate(S):
    if i&1:
        m = "p"
    else:
        m = "g"
    
    if s=="g" and m=="p":
        ans += 1
    elif s=="p" and m=="g":
        ans -= 1

print(ans)

Measured memory_bytes: 9056
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: usize,
    }

    let mut ans = Vec::with_capacity(n);
    for _i in 0..n + 1 {
        ans.push(0);
    }

    for i in 1..(n as f64).sqrt() as usize {
        for j in i..(n as f64).sqrt() as usize {
            for k in j..(n as f64).sqrt() as usize {
                let value = i * i + j * j + k * k + i * j + j * k + k * i;
                // println!("{} {} {}", i, j, k);
                // println!("value: {}", value);
                if value > n {
                    continue;
                }

                if i == j && j == k {
                    ans[value as usize] += 1;
                } else if i != j && j != k && k != i {
                    ans[value as usize] += 6;
                } else {
                    ans[value as usize] += 3;
                }
            }
        }
    }

    for i in 1..n+1 {
        println!("{}", ans[i]);
    }
}


Measured memory_bytes: 2076
k = int(input())
range_num = input().split(" ")
a = int(range_num[0])
b = int(range_num[1])
con1 = 1 <= a and a <= b and b <= 1000
con2 = 1 <= k and k <= 1000
count = 0
if con1 == True and con2 == True:
    b = b + 1
    for i in range (a, b):
        if i % k == 0:
            count = count + 1
        else:
            count = count
    if count > 0:
        print("OK")
    else:
        print("NG")
else:
    print()


Measured memory_bytes: 9176
using System;

namespace ALDS1_3_C
{
    class Program
    {
        static int[] S = new int[2000000];

        static int top;
        static int last;

        static void Main(string[] args)
        {
            int n = getint("a");
            for (int i = 0; i < n; i++)
            {
                string[] d = getsplit();
                if (d[0] == "insert")
                {
                    insert(getint(d[1])); 
                }
                else if (d[0] == "delete")
                {
                    delete(getint(d[1]));
                }
                else if(d[0] == "deleteFirst" )
                {
                    deleteFirst();
                }
                else
                {
                    deleteLast();
                }
            }

            int a = 0;
            for (int i = top; i >= last; i--)
            {
                if (S[i] != 0 && a==1)
                {
                    Console.Write(" "+ (S[i] - 1));
                }
                else if (S[i] != 0)
                {
                    Console.Write(S[i] - 1);
                    a = 1;
                }               
            }
            Console.WriteLine();
        }

        public static string[] getsplit()
        {
            string[] x = Console.ReadLine().Split(' ');
            return x;
        }
        public static int getint(string a)
        {

            if (a == "a")
            {
                int x = int.Parse(Console.ReadLine());
                return x;
            }
            else
            {
                int x = int.Parse(a);
                return x;
            }
        }

        static void insert(int x)
        {
            S[top] = x+1;
            top++;
        }

        static void delete(int x)
        {
            for (int i = top - 1; i >= last; i--)
            {
                if (S[i] == x+1)
                {
                    S[i] = 0;
                    break;
                }
            }
        }

        static void deleteFirst()
        {
            while (S[top - 1] == 0) top--;
           
            S[top - 1] = 0;
            top--;
        }
        static void deleteLast()
        {
            while (S[last] == 0) last++;
            S[last] = 0;
            last++;
        }

    }
}

Measured memory_bytes: 23176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <math.h>
#include <cmath>
#include <ctime>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
typedef pair<int, int> P;

const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>void vecin(vector<TT>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
long long modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

bool chmax(int& xx, int yy) {
	if (xx < yy) {
		xx = yy;
		return true;
	}
	return false;
}
bool chmin(int& xx, int yy) {
	if (xx > yy) {
		xx = yy;
		return true;
	}
	return false;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx <= 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int n,mi=INF,ans=1;
	cin >> n;
	for (int i = 1; i*i <= n; i++) {
		if (n % i == 0) {
			chmin(mi,n / i);
		}
	}
	if (mi == INF)mi = n;
	while (mi >= 10) {
		mi /= 10;
		ans++;
	}
	cout << ans << endl;
}

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

const int maxn = 2e5 + 10;
typedef long long int ll;
void solved(){
	int k;cin>>k;
	string s;cin>>s;
	if(s.size() <= k){
		cout<<s<<endl;
	}else{
		for(int i = 0; i < k; i++)cout<<s[i];
		cout<<"..."<<endl;
	}
}
int main(){
	solved();
	return 0;
}

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

int main()
{
	long long n, m; cin >> n >> m;
	long long ans = 0;
	if (2*n <= m) {
		ans += n;
		m -= 2*n;
		ans += m / 4;
	}
	else {
		ans += m / 2;
	}
	cout << ans << endl;
	return 0;
}



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

using namespace std;
typedef long long ll;

struct info {
    ll val, to;
};

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

    vector<vector<info>> doubling(60, vector<info>(m));
    for (ll i = 0; i < m; i++)doubling[0][i] = {i, i * i % m};

    for (int t = 1; t < 60; t++) {
        for (ll i = 0; i < m; i++) {
            ll mid = doubling[t - 1][i].to;
            doubling[t][i].val = doubling[t - 1][i].val + doubling[t - 1][mid].val;
            doubling[t][i].to = doubling[t - 1][mid].to;
        }
    }

    ll ret = 0;
    for (int i = 0; i < 60; i++) {
        if (n & (1LL << i)) {
            ret += doubling[i][x].val, x = doubling[i][x].to;
        }
    }

    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 98496
#include <cstdio>                          
using namespace std;                       
                                           
int main()                                 
{                                          
  int N;                                   
  scanf("%d", &N);                         
  int h[N];                                
  for (int i = 0; i < N; i++ ){            
    scanf("%d", &h[i]);                    
  }                                        
  h[0]--;                                  
  bool flag = true;                        
  for (int i = 1; i < N && flag ; i++){    
    if (h[i] - h[i-1] < 0) flag = false;   
    else if (h[i] - h[i-1] == 0) h[i]++;   
    h[i]--;                                
  }                                        
  if (flag) printf("Yes\n");               
  else printf("No\n");                     
}                                          

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
int dp[10010];

vector<int> vi;

int sum[100100];
int cnt[1010];

int main() {
	REP(i, 5000)sum[i] = i;
	vi.push_back(0);
	REP(i, 5000) {
		sum[i + 1] += sum[i];
		vi.push_back(sum[i + 1]);
	}
	REP(i, vi.size()) {
		FOR(j, i + 2, vi.size()) {
			if (vi[j] - vi[i] > 1000)continue;
			//if (vi[j] - vi[i] == 9)cout << j << " " << i << endl;
			cnt[vi[j] - vi[i]]++;
		}
	}
	while (cin >> n&&n) {
		cout << cnt[n] << endl;
	}
}

Measured memory_bytes: 3072
bingo = [[0] * 3 for i in range(3)]
score = [[0] * 3 for i in range(3)]
for i in range(3):
    bingo[i][0], bingo[i][1], bingo[i][2] = map(int,input().split())

N=int(input())

A=[]

for i in range(N):
    A.append(int(input()))
ans = list(set(A))

for i in range(3):
    for j in range(3):
        if bingo[i][j] in ans: score[i][j]=1

flg=0

col=[0]*3
# 縦
for i in range(3):
    col[0]+=score[i][0]
    col[1]+=score[i][1]
    col[2]+=score[i][2]

for i in range(3):
    if col[i] == 3: flg=1
        
# 横
for i in score:
    if sum(i) == 3: flg=1

# 斜め
S1=score[0][0]+score[1][1]+score[2][2]
S2=score[2][0]+score[1][1]+score[0][2]

if S1 == 3: flg=1
if S2 == 3: flg=1
    
print("Yes" if flg==1 else "No")

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int n = s.size();
    vll d10(n,1), d2(n,1), dp(n);
    rep(i,n-1) d10[i+1]=d10[i]*10;
    rep(i,n-1) d2[i+1]=d2[i]*2;
    rep(i,n-1) dp[i+1]=dp[i]*2+d10[i];
    ll ans=0;
    rep(i,n){
        int c = s[i]-'0';
        ll sum = dp[n-i-1]+d10[n-i-1];
        sum *= c;
        sum *= d2[i];
        ans+=sum;
    }
    cout<<ans<<"\n";
    return 0;
}


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

int getNum(char c){
  if('A'<=c&&c<='Z')return 10+c-'A';
  if('a'<=c&&c<='z')return 36+c-'a';
  return c-'0';
}

int pto10(int p,string s){
  int res=0,x=1;
  for(int i=0;i<s.size();i++)res+=x*getNum(s[i]),x*=p;
  return res;
}

int Cnt(int num){
  int res=0;
  while(num)res++,num/=2;
  return res;
}

int main(){
  int n,p,cnt1=0,cnt2=0;
  vector<int> v;
  string s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>p>>s;
    reverse(s.begin(),s.end());
    int num=pto10(p,s),t=0;
    while(num){
      if(num%2)t=t*10+1;
      else v.push_back(t),t=0;
      num/=2;
    }
    v.push_back(t);
  }
  for(int i=0;i<v.size();i++){
    int cnt=Cnt(v[i]);
    if(!v[i])continue;
    if(cnt==1)cnt1++;
    else cnt2++;
  }
  if(cnt2||cnt1%2)cout<<"win"<<endl;
  else cout<<"lose"<<endl;
  return 0;
}

Measured memory_bytes: 7284
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

int N,D,A;
int X[200005],H[200005];
pair<int,int> XH[200005];
signed main(){
    scanf("%lld %lld %lld",&N,&D,&A);
    rep(i,N){
        scanf("%lld %lld",&X[i],&H[i]);
        XH[i]=mp(X[i],H[i]);
    }
    sort(XH,XH+N);
    int ans=0;
    int BOMBED[200100];
    rep(i,N)BOMBED[i]=0;
    rep(itr,N){
        if(itr>0){//累積和をまくる
            BOMBED[itr]+=BOMBED[itr-1];
            //すでに爆破された分の体力を引く
            XH[itr].second-=A*BOMBED[itr];
        }
        if(XH[itr].second>0){
            //自分を減らす
            int b=XH[itr].second/A+(XH[itr].second%A>0);
            //自分以降の減少累積和に一を足しておく
            BOMBED[itr+1]+=b;
            ans+=b;
            //printf("%lld\n",ans);
            int upperbomitr=upper_bound(XH,XH+N,mp(XH[itr].first+2*D+1,(int)-LLINF))-XH;
            if(upperbomitr<N)BOMBED[upperbomitr]-=b;
        }
    }
    
    printf("%lld\n",ans);
    return 0;
}


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


int main(){
    int maxn = 10010;
    long long N;cin >> N;
    for( long i = 1; i*i <= N; i++ ) {
        if (N % i != 0) {
            continue;
        }
        long long a = 0, b = 0;
        a = i;
        b = N / i;
        int lena = 0, lenb = 0;
        while (a) {
            a /= 10;
            lena++;
        }
        while (b) {
            b /= 10;
            lenb++;
        }
        maxn = min(maxn, max(lena, lenb));
      }
    cout << maxn << endl;
}

Measured memory_bytes: 256
s = input()
flag = True
for i in range(1,len(s)):
	if s[i]==s[i-1]:
		flag = False
		print(i,i+1)
		break
if flag:
	for i in range(2,len(s)):
		if s[i]==s[i-2]:
			flag = False
			print(i-1,i+1)
			break
if flag: print(-1,-1)

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

typedef pair<int, int> P;
#define INF 1e9
#define INF_LL 1LL<<60
#define ll long long

bool isPrime(ll t) {
    REPN(i, 2, sqrt(t)+1) {
        if(t % i == 0) {
            return false;
        }
    }
    return true;
}

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

    while(1) {
        if(isPrime(x)) {
            cout << x << endl;
            return 0;
        }
        x++;
    }

    return 0;
}

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

int main(){
    
    int n;
    cin >> n;
    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }

    long long int money=1000;
    long long int profit;
    long long int stock;

    for(int i=0; i<n-1; i++){
        profit=a.at(i+1)-a.at(i);
        if(profit>0){
            stock=money/a.at(i);
            money+=stock*profit;
        }
    }
    cout << money << endl;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<vector>
//#include<ctime>
#define rg register
typedef long long ll;
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline void mind(T&a,const T b){a=a<b?a:b;}
template <typename T> inline void maxd(T&a,const T b){a=a>b?a:b;}
template <typename T> inline T abs(const T a){return a>0?a:-a;}
template <typename T> inline void swap(T&a,T&b){T c=a;a=b;b=c;}
//template <typename T> inline void swap(T*a,T*b){T c=a;a=b;b=c;}
template <typename T> inline T gcd(const T a,const T b){if(!b)return a;return gcd(b,a%b);}
template <typename T> inline T lcm(const T a,const T b){return a/gcd(a,b)*b;}
template <typename T> inline T square(const T x){return x*x;};
template <typename T> inline void read(T&x)
{
	char cu=getchar();x=0;bool fla=0;
	while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}
	while(isdigit(cu))x=x*10+cu-'0',cu=getchar();
	if(fla)x=-x;
}
template <typename T> inline void printe(const T x)
{
	if(x>=10)printe(x/10);
	putchar(x%10+'0');
}
template <typename T> inline void print(const T x)
{
	if(x<0)putchar('-'),printe(-x);
	else printe(x);
}
int a,b; 
int main()
{
	read(a),read(b);
	puts(a==b?"Yes":"No");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
const long long LINF=1e18;
signed main(void)
{
  int N,over=0;
  long long x,y;
  x=scanf("%d",&N);
  while(~scanf("%lld",&y))
  {
    if(y==0)return printf("%d",0),0;
    else if(LINF/y<x)over=1;
    else x*=y;
  }
  if(over)x=-1;
  return printf("%lld",x),0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <iomanip>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n, m;
    cin >> n >> m;
    ll s[m];
    char c[m];
    for(ll i = 0; i < m; i++){
        cin >> s[i] >> c[i];
    }
    bool check = true;
    double MIN = pow(10, n-1);
    if(MIN==1) MIN = 0;
    double MAX = pow(10, n);
    for(ll i = MIN; i < (ll)MAX; i++){
        string a = to_string(i);
        check = true;
        for(ll j = 0; j < m; j++){
            ll d = s[j]-1;
            if(a[d]!=c[j])
                check = false;
        }
        if(check == true){
            cout << i << endl;
            break;
        }
        if(check == false && i==MAX-1)
            cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S.size() 配列名.Length()
using namespace std;
typedef unsigned long long ll;

ll memo[100];

/*ll func(ll n){
	if(memo[n] != -1)return memo[n];

	if(n == 0) return memo[n] = 1;
	else if(n == 1) return memo[n] = 1;
	else return memo[n] = func(n - 1) + func(n - 2);
}*/

ll func(ll n){
	memo[0] = 1;
	memo[1] = 1;
	for(int i = 2; i <= n; i++){
		memo[i] = memo[i - 1] + memo[i - 2];
	}
	return memo[n];
}

int main(void){
	//rep(i, 100) memo[i] = -1;
	ll n;
	cin >> n;
	cout << func(n) <<endl;

}



Measured memory_bytes: 3112
n = int(input())
a = list(map(float,input().split()))
dp = [[0 for i in range(n)] for i in range(n//2+1)]
for i in range((n//2)+1):
    l,j=1,i
    while j<n:
        if i==0:
            l=l*a[j]
            dp[i][j]=l
            j=j+1
        else:
            for k in range(i):
                l=l*(1-a[k])
                dp[i][k]=l
            while j<n:
                dp[i][j]=(dp[i-1][j-1]*(1-a[j]))+(dp[i][j-1]*a[j])
                j=j+1
l=0
for i in range(n//2+1):
    l+=dp[i][n-1]
print(l)


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

#define N (int)2e5+5
int a[N];

int main() {
  int n, k; cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  double m = 0.0;
  int i = 0;
  while (i < k) {
  	m += (a[i] + 1.0) / 2.0;
  	i++;
  }
  double t = m;
  while (i < n) {
  	t = t + (a[i] - a[i - k]) / 2.0;
  	// cout << i << " " << t << endl;
  	if (t > m) m = t;
  	i++;
  }
  cout << setprecision(9) << fixed << m;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
	int W, H;
	int i, j;

	while (1)
	{
		cin >> H >> W;

		if (W == 0 && H == 0)
			break;

		for (j = 0; j < H; j++)
		{

			for (i = 0; i < W; i++)
			{
				if ((i+j)%2==0)
					cout << '#';
				else
					cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std ;
int main () {
  int A , B ;
  string S ;
  cin >> A >> B >> S ;
  bool ans = true ;
  if(S[A]!='-') ans = false ;
  int pre = 0 ;
  for(int i = 0 ; i < S.size() ; i++ ){
    if(isdigit(S[i])) pre ++ ;
  }
  if((S.size()-pre)!=1) ans = false ;
  if(ans) cout << "Yes" << endl ;
  else cout << "No" << endl ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007

lli k,n;
lli arr[200005];
lli prefix[200005];

lli min(lli a,lli b)
{
    if(a<b)
    {
        return a;
    }
    return b;
}
int main()
{
    cin>>k>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    vector<int> v;
    for(int i=1;i<n;i++)
    {
        v.push_back(arr[i]-arr[i-1]);
    }

    v.push_back(arr[0]+(k-arr[n-1]));

    lli ans=INT_MAX;

    for(int i=0;i<v.size();i++)
    {
        ans=min(ans,k-v[i]);
    }
    cout<<ans<<"\n";

    return 0;
}


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

int main() {
	string ans;
	int x, y;
	cin >> x >> y;
	if (x == 2 || y == 2) {
		ans = "No";
	}
	else if (x == 4 || x == 6 || x == 9 || x == 11) {
		if (y == 4 || y == 6 || y == 9 || y == 11) {
			ans = "Yes";
		}
		else {
			ans = "No";
		}
	}
	else {
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import Foundation

let PI: Double = 3.14159265358979323846
if let inp = readLine() {
  let s = inp.components(separatedBy: " ")
  if let fa: Double = Double(s[0])
    ,let fb: Double = Double(s[1])
    ,let fh: Double = Double(s[2])
    ,let fm: Double = Double(s[3]) {
    let dir: Double = fh/12.0 + (fm/60.0)/12.0 - fm/60.0
    let ra: Double =  PI * 2.0 * dir
    let rq: Double = (fa * fa + fb * fb) - 2.0 * fa * fb * cos(ra)
    print(sqrt(rq))
  }
}


Measured memory_bytes: 14728
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    name_roop = []

    level = 1

    ans = ""
    while N > 0:
        N -= 1
        n = N % 26
        ans += ascii_lowercase[n]
        N //= 26
    print(ans[::-1])
    # for i in range(level, 1, -1):
    #     count = 0
    #     a = 26**(i-1)
    #     for j in range(26):
    #         if N-a > 26**(i-2):
    #             N -= a
    #             count += 1
    #     name_roop.append(count)

    # name_roop.append(N)
    # for i in name_roop:
    #     ans += ascii_lowercase[i-1]
    # print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9856
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FFrogJump solver = new FFrogJump();
        solver.solve(1, in, out);
        out.close();
    }

    static class FFrogJump {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] arr = new long[n];
            for (int i = 0; i < n; i++)
                arr[i] = in.nextLong();
            //long res = solveSimple(n, arr);
            long res = solveMe2(n, arr);
            out.println(res);
        }

        private long solveMe2(int n, long[] s) {
            long max = 0;
            long[] dp = new long[n + 1];
            for (int d = 1; d < n; d++) {
                int maxn = n - d;
                if ((n - 1) % d == 0) maxn = n / 2;
                for (int k = 1; k * d < maxn; k++) {
                    dp[k] = dp[k - 1] + s[k * d] + s[n - 1 - k * d];
                    max = Math.max(max, dp[k]);
                }
            }
            return max;
        }

    }
}



Measured memory_bytes: 60452
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1327
// 解答AC (beetさん)
// ICPC: アジア地区予選2012C
// One-Dimensional Cellular Automaton

/*
Problem.
配列Sが与えられて、以下の操作をt回(0 <= t <= 10^9)繰り返す。
操作: S(i, t+1) = (A*S(i-1,t) + B*S(i, t) + C*S(i+1, t)) % m;
S(0, t), S(1, t) , ... , S(N-1, t)
を答えよ。

Point.
tが大きいため、操作をt回繰り返すのはNG。
配列について同じ操作を繰り返すなら、変換行列のt乗をを自乗法により求める。
*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int n, m, a, b, c, t;

class t_mat{
public:
  vvi x;
  t_mat(){
    x = vvi(50, vi(50, 0));
  }
  t_mat(const t_mat &p){
    x = p.x;
  }
  void multi(t_mat sec){
    vvi nmp(50, vi(50, 0));
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        for(int k = 0; k < n; k++){
          nmp[i][j] += (x[i][k] * sec.x[k][j]) % m;
        }
        nmp[i][j] %= m;
      }
    }
    x = nmp;
  }
  void rec(int ti){
    t_mat nmp(*this);
    ti--;
    while(ti > 0){
      if(ti&1) nmp.multi(*this);
      this->multi(*this);
      ti >>= 1;
    }
    this->x = nmp.x;
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  while(cin >> n >> m >> a >> b >> c >> t && n){
    vi s(n, 0), ans(n, 0);
    for(int &i: s) cin >> i;

    //変換行列作成
    t_mat mp;
    mp.x[0][0] = b, mp.x[0][1] = c;
    for(int i = 1; i < n-1; i++){
      mp.x[i][i-1] = a;
      mp.x[i][i] = b;
      mp.x[i][i+1] = c;
    }
    mp.x[n-1][n-2] = a;
    mp.x[n-1][n-1] = b;
    mp.rec(t);

    //計算結果作成
    if(t == 0){
      for(int i = 0; i < n; i++) cout << s[i] << (i == n-1 ? '\n' : ' ');
    }
    else{
      for(int i = 0; i < n; i++){
        for(int k = 0; k < n; k++){
          ans[i] += (mp.x[i][k]*s[k])%m;
        }
        ans[i] %= m;
      }
      for(int i = 0; i < n; i++) cout << ans[i] << (i == n-1? '\n' : ' ');
    }
  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}



Measured memory_bytes: 3116
A, B = map(int, input().split())

def F(v):
    tmp = v // 2
    amari = v % 2
    ans = 0
    if tmp % 2 == 0:
        if amari != 0:
            ans = v - 1
    else:
        if amari != 0:
            ans = 1 ^ (v - 1)
        else:
            ans = 1
    return ans

ansA = F(A)
ansB = F(B + 1)
print(ansA ^ ansB)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	int a;
	cin>>a;long long sum=0;vector<int> te;
	for(int i=0;i<a;i++)
	{
		int t;
		cin>>t;
		te.push_back(t);
	}
	int top=te[0];
 	for(int i=1;i<a;i++)
 	{
 		if(te[i]<top)
		 sum+=(top-te[i]);
		 else
		 top=te[i];	
	 }
	 cout<<sum;
  return 0;
}

Measured memory_bytes: 3848
#include<iostream>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct lazysegtree{
	function<T(T,T)>calcfn,lazycalcfn;
	function<T(T,T,unsigned int)>updatefn;
	int n;
	T defvalue,lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	lazysegtree(int n_=0,T defvalue_=0,
		function<T(T,T)>calcfn_=[](T a,T b){return a+b;},
		function<T(T,T)>lazycalcfn_=[](T a,T b){return a+b;},
		function<T(T,T,unsigned int)>updatefn_=[](T a,T b,unsigned int width){return a+b*width;},
		T lazydefvalue_=0
	):defvalue(defvalue_),lazydefvalue(lazydefvalue_),
		calcfn(calcfn_),lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
		lazy.assign(2*n-1,lazydefvalue);
		lazyflag.assign(2*n-1,false);
	}
	void copy(vector<T>v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
	}
	void eval(int i,int l,int r)
	{
		if(lazyflag[i])
		{
			dat[i]=updatefn(dat[i],lazy[i],r-l);
			if(r-l>1)
			{
				lazy[2*i+1]=lazycalcfn(lazy[2*i+1],lazy[i]);
				lazy[2*i+2]=lazycalcfn(lazy[2*i+2],lazy[i]);
				lazyflag[2*i+1]=lazyflag[2*i+2]=true;
			}
			lazy[i]=lazydefvalue;
			lazyflag[i]=false;
		}
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			lazy[k]=lazycalcfn(lazy[k],x);
			lazyflag[k]=true;
			eval(k,l,r);
		}
		else
		{
			update(a,b,x,2*k+1,l,(l+r)/2);
			update(a,b,x,2*k+2,(l+r)/2,r);
			dat[k]=calcfn(dat[2*k+1],dat[2*k+2]);
		}
	}
	T query(int a,int b,int k=0,int l=0,int r=-1)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return defvalue;
		else if(a<=l&&r<=b)return dat[k];
		else return calcfn(
			query(a,b,2*k+1,l,(l+r)/2),
			query(a,b,2*k+2,(l+r)/2,r)
		);
	}
};
int n,q;
main()
{
	cin>>n>>q;
	lazysegtree<int>P(n,0,[](int a,int b){return a+b;},[](int a,int b){return b;},[](int a,int b,int width){return b*width;});
	for(int i=0;i<q;i++)
	{
		int c;cin>>c;
		if(c)
		{
			int s,t;cin>>s>>t;
			cout<<P.query(s,t+1)<<endl;
		}
		else
		{
			int s,t,x;cin>>s>>t>>x;
			P.update(s,t+1,x);
		}
	}
}


Measured memory_bytes: 4936
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int n=s.size();
	if(n%2) {
		cout<<"No\n";
		return 0;
	}
	string t;
	for (int i=0; i<n/2; i++)
		t+="hi";
	cout<<(s==t?"Yes":"No")<<"\n";
	return 0;
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))
S1_S2 = []

for i in range(N):
    S1 = sum(W[0:i])
    S2 = sum(W[i:N])
    if S1 >= S2 :
        S1_S2.append(S1-S2)
    else:
        S1_S2.append(-S1+S2)

print(min(S1_S2))

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }
        if (sum >= h) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}

Measured memory_bytes: 48584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1000000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)


int main() {
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    if (v-w>0 && abs(a-b) <= t*(v-w)){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define F first
#define S second
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define PICK(N,m,p) (N/(int)(pow(p,m-1))-(N/(int)(pow(p,m)))*p)
using lint = long long;
using ld = long double;
using namespace std;

//ユークリッド互除法
lint gcd(lint x,lint y){
    lint a=MAX(x,y);
    lint b=MIN(x,y);
    if(b==0) return a;
    else {
        lint q=a/b;
        lint g=gcd(b,a-q*b);
        return g;
    }
}

int main(){
    lint A, B, C;
    cin >> A >> B >> C;
    if(C%gcd(A,B)==0) cout << "YES" << endl;
    else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)
#define MAX_N (100000+10)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N;

vector<int> adj[2*MAX_N];
bool visited[2*MAX_N];
vector<Int> cnt;

void dfs(int v) {
    if (visited[v])
        return;
    visited[v] = true;
    cnt[v/MAX_N]++;
    for(auto u : adj[v])
        dfs(u);
}
int main(void) {
    cin>>N;

    for(int i = 0;i < N;i++) {
        int x,y;
        cin>>x>>y;
        y += MAX_N;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    Int ans = 0;
    for(int i = 0;i < 2*MAX_N;i++) {
        if(visited[i])
            continue;
        cnt = vector<Int>(2);
        dfs(i);
        ans += cnt[0]*cnt[1];
    }

    ans -= N;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 10240
#include <stdio.h>

int main(void)
{
	int i,j,a,b,c;

	j=0;

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

	for(i=a;i<=b;i++)
	{
		if(c%i==0)
		{
			j++;
		}
	}

	printf("%d\n",j);
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 1000000007

int main()
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a>=0&&c>=0){
        cout << b*d << endl;
    }else if(b<=0&&d<=0){
        cout << a*c << endl;
    }else if(a>=0&&d<=0){
        cout << a*d << endl;
    }else if(b<=0&&c>=0){
        cout << b*c << endl;
    }
    else{
        ll max_=max(a*c,b*d);
        cout << max_ << endl;
    }
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, lli> pi;


int main()
{
    lli n;
    cin >> n;
    cout << n*(n-1)/2 << "\n";

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;


namespace abc94_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = int.Parse(ReadLine());
            List<int> list = new List<int>();
            list = ReadLine().Split().Select(int.Parse).ToList();

            var tmp = new List<int>(list);

            list.Sort();

            for(int i=0; i<s; i++)
            {
                if(tmp[i] <= list[s/2-1])
                {
                    WriteLine(list[s/2]);
                }
                else
                {
                    WriteLine(list[s/2-1]);
                }
            }
        }
    }
}

Measured memory_bytes: 38108
#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 all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
#define INF 1000000000;
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int open[105][10],profit[105][10];

int main(){
    int n;
    cin >> n;
    rep(i,n) rep(j,10) cin >> open[i][j];
    rep(i,n) rep(j,11) cin >> profit[i][j];
    int ans = -INF;
    FOR(bit,1,(1<<10)){
        int get = 0;
        rep(i,n){
            int c = 0;
            rep(j,10){
                if ((bit>>j&1)&&open[i][j]) c++;
            }
            get += profit[i][c];
        }
        chmax(ans,get);
    }
    PRINT(ans);
}


Measured memory_bytes: 256
//xenowitz -- Jai Shree Ram
#include<bits/stdc++.h>
using namespace std;

#define fori(i,a,b) for (long int i = a; i <= b ; ++i)
#define ford(i,a,b) for(long int i = a;i >= b ; --i)
#define mk make_pair
#define mod 1000000007
#define pb push_back
#define eb emplace_back
#define vec vector<long long int>
#define ll long long
#define rnd mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count())
#define pi pair<long long int,long long int>
#define sc second
#define fs first
#define stf shrink_to_fit

void SieveOfEratosthenes(int n, bool prime[],
						bool primesquare[], int a[])
{
	// Create a boolean array "prime[0..n]" and
	// initialize all entries it as true. A value
	// in prime[i] will finally be false if i is
	// Not a prime, else true.
	for (int i = 2; i <= n; i++)
		prime[i] = true;

	// Create a boolean array "primesquare[0..n*n+1]"
	// and initialize all entries it as false. A value
	// in squareprime[i] will finally be true if i is
	// square of prime, else false.
	for (int i = 0; i <= (n * n + 1); i++)
		primesquare[i] = false;

	// 1 is not a prime number
	prime[1] = false;

	for (int p = 2; p * p <= n; p++) {
		// If prime[p] is not changed, then
		// it is a prime
		if (prime[p] == true) {
			// Update all multiples of p
			for (int i = p * 2; i <= n; i += p)
				prime[i] = false;
		}
	}

	int j = 0;
	for (int p = 2; p <= n; p++) {
		if (prime[p]) {
			// Storing primes in an array
			a[j] = p;

			// Update value in primesquare[p*p],
			// if p is prime.
			primesquare[p * p] = true;
			j++;
		}
	}
}

// Function to count divisors
int countDivisors(int n)
{
	// If number is 1, then it will have only 1
	// as a factor. So, total factors will be 1.
	if (n == 1)
		return 1;

	bool prime[n + 1], primesquare[n * n + 1];

	int a[n]; // for storing primes upto n

	// Calling SieveOfEratosthenes to store prime
	// factors of n and to store square of prime
	// factors of n
	SieveOfEratosthenes(n, prime, primesquare, a);

	// ans will contain total number of distinct
	// divisors
	int ans = 1;

	// Loop for counting factors of n
	for (int i = 0;; i++) {
		// a[i] is not less than cube root n
		if (a[i] * a[i] * a[i] > n)
			break;

		// Calculating power of a[i] in n.
		int cnt = 1; // cnt is power of prime a[i] in n.
		while (n % a[i] == 0) // if a[i] is a factor of n
		{
			n = n / a[i];
			cnt = cnt + 1; // incrementing power
		}

		// Calculating the number of divisors
		// If n = a^p * b^q then total divisors of n
		// are (p+1)*(q+1)
		ans = ans * cnt;
	}

	// if a[i] is greater than cube root of n

	// First case
	if (prime[n])
		ans = ans * 2;

	// Second case
	else if (primesquare[n])
		ans = ans * 3;

	// Third case
	else if (n != 1)
		ans = ans * 4;

	return ans; // Total divisors
}

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

  ll n, ans = 0;
  cin >> n;

  fori(a, 1, n) {
     for(ll b = 1; a*b < n; b += 1) {
         ans += 1;
     }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3648
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    if S[0] == 'A' and S[2:-1].count('C') == 1:
        for s in list(S):
            if s != 'A' and s != 'C' and str.isupper(s):
                print('WA')
                exit()
        else:
            print('AC')
    else:
        print('WA')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064