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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

int N, W;
int value[110], weight[110];
int dp[110][10010];

void print(int cnt, bool ok) {
   printf("---------- (%d, %c) ----------\n", cnt, (ok?'T':'F'));
   rep (i, 0, N+1) {
      rep (j, 0, W+1) {
         printf("%3d", dp[i][j]);
      }
      puts("");
   }
}

int main() {
   cin >> N >> W;
   rep (i, 0, N) {
      cin >> value[i] >> weight[i];
   }

   rep (i, 0, W+1) {
      dp[0][i] = 0;
   }

   // rep (cnt, 1, N+1) {
   //    rep (limit, 0, W+1) { // 重さwまでの最大を求める感じ？
   //       if (limit >= weight[cnt-1]) {
   //          dp[cnt][limit] = 
   //             max(dp[cnt-1][limit-weight[cnt-1]] + value[cnt-1], dp[cnt-1][limit]);
   //       } else {
   //          dp[cnt][limit] = dp[cnt-1][limit];
   //       }
   //    }
   // }

   for (int cnt = 1; cnt <= N; cnt++) {
      for (int limit = 0; limit <= W; limit++) {
         if (limit >= weight[cnt-1]) {
            dp[cnt][limit] = 
               max(dp[cnt-1][limit-weight[cnt-1]]+value[cnt-1], dp[cnt-1][limit]);
         } else {
            dp[cnt][limit] = dp[cnt-1][limit];
         }
      }
   }

   cout << dp[N][W] << endl;

   return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;




int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
	
	ll a,b;
	cin>>a>>b;
	if(a==1 || b==1) cout<<1<<"\n";
	else cout<<(a*b+1)/2<<"\n";


}


Measured memory_bytes: 3604
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    print('YES' if sum(list(map(lambda x: int(x)%2, input().split())))%2 == 0 else 'NO')

if __name__ == '__main__':
  main()


Measured memory_bytes: 13756
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb   push_back
#define pt(x)  cout<<x<<endl;
#define T int time;        scanf("%d", &time); while(time--)
    struct aray{
        ll a,b;
    };
//aray a[10000],b[100000];
int main(){
     //T{
      ll a , b , c , d ;
      cin >> a >> b >> c >> d;
      ll ans = max((a*c), max( a*d , max( b*c, b*d)));

      cout << ans <<endl;

        
} 

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

string s;
int next_[200005][26];
int dp[200005],fuku[200005],ans[200005];
signed main() {
	cin>>s;
	rep(i,s.size()){
		dp[i]=inf;
	}
	rep(i,26)next_[s.size()][i]=s.size();
	for(int i=s.size()-1;i>=0;i--){
		rep(j,26)next_[i][j]=next_[i+1][j];
		next_[i][s[i]-'a']=i;
	}
	dp[s.size()]=1;
	/*rep(i,s.size()){
		rep(j,26)cout<<next_[i][j]<<" ";
		cout<<endl;
	}*/
	for(int i=s.size()-1;i>=0;i--){
		rep(j,26){
			if(next_[i][j]==s.size()){
				if(dp[i]>1){
					dp[i]=1;
					fuku[i]=s.size();
					ans[i]=j;
				}
			}
			else if(dp[i]>dp[next_[i][j]+1]+1){
				dp[i]=dp[next_[i][j]+1]+1;
				fuku[i]=next_[i][j]+1;
				ans[i]=j;
			}
		}
	}
	//rep(i,s.size())cout<<(char)(ans[i]+'a');
	string res;
	int now=0;
	while(now<s.size()){
		res.push_back((char)('a'+ans[now]));
		now=fuku[now];
		//cout<<now<<endl;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 45828
s = input()
n = int(input())
for i in range(n):
  q = input().split()
  a, b = int(q[1]), int(q[2])
  if q[0]=="print":
    print(s[a:b+1])
  elif q[0]=="reverse":
    if a==0:
      s = s[b::-1]+s[b+1:]
    else:
      s = s[:a]+s[b:a-1:-1]+s[b+1:]
  elif q[0]=="replace":
    s = s[:a]+q[3]+s[b+1:]


Measured memory_bytes: 5608
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int whiteNum[10][1000] = {};

// x1 <= x < x2 かつ y1 <= y < y2 となるような (x,
// y)の範囲のホワイトチョコレートの数を返す
int getWhiteNum(int x1, int x2, int y1, int y2) {
	int ans = whiteNum[x2 - 1][y2 - 1];
	if (x1 > 0) ans -= whiteNum[x1 - 1][y2 - 1];
	if (y1 > 0) ans -= whiteNum[x2 - 1][y1 - 1];
	if (x1 > 0 && y1 > 0) ans += whiteNum[x1 - 1][y1 - 1];
	return ans;
}

int main() {
	int h, w, k;
	cin >> h >> w >> k;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char s;
			cin >> s;
			if (i > 0) whiteNum[i][j] += whiteNum[i - 1][j];
			if (j > 0) whiteNum[i][j] += whiteNum[i][j - 1];
			if (i > 0 && j > 0) whiteNum[i][j] -= whiteNum[i - 1][j - 1];
			if (s == '1') whiteNum[i][j]++;
		}
	}
	// for (int i = 0; i < h; i++) {
	// 	for (int j = 0; j < w; j++) {
	// 		cout << whiteNum[i][j];
	// 	}
	// 	cout << endl;
	// }
	int ans = mod;
	for (int i = 0; i < (1 << (h - 1)); i++) {
		int res = 0;
		vector<int> start;
		start.push_back(0);
		for (int j = 0; j < h - 1; j++) {
			if (((1 << j) & i) > 0) {
				start.push_back(j + 1);
				res++;
			}
		}
		start.push_back(h);
		// for (int i = 0; i < start.size(); i++) {
		// 	cout << start[i];
		// }
		// cout << endl;
		int beforew = 0;
		for (int j = 1; j <= w; j++) {
			for (int l = 0; l < start.size() - 1; l++) {
				// cout << "\t" << start[l] << " " << start[l + 1] << " "
				//      << beforew << " " << j << " "
				//      << getWhiteNum(start[l], start[l + 1], beforew, j) <<
				//      endl;
				if (getWhiteNum(start[l], start[l + 1], beforew, j) > k) {
					if (j == beforew + 1) {
						j = w + 1;
						res = mod;
						// cout << "break!" << endl;
						break;
					} else {
						res++;
						// cout << "res:" << res << endl;
						beforew = j - 1;
					}
				}
			}
		}
		// cout << i << " " << res << endl;
		ans = min(ans, res);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
L = len(S)

def isKaibun(s):
    i = 0
    l = len(s)
    flag = 1
    while 1:
        if s[i]==s[l-1-i]:
            i+=1
        else:
            flag=0
            break
        if l-1-i<i:
            break
    return flag

if isKaibun(S)==1 and isKaibun(S[0:(L-1)//2])==1 and isKaibun(S[(L+1)//2:])==1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
from collections import deque
N,Q=map(int,input().split())
nondirtree=[[] for _ in range(N)]
dirtree=[[] for _ in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    nondirtree[a-1].append(b-1)
    nondirtree[b - 1].append(a - 1)
#points=[tuple(map(int,input().split())) for _ in range(Q)]
score=[0]*N
for i in range(Q):
    point,sc=map(int,input().split())
    score[point-1]=score[point-1]+sc
#print(points)
v=0
d=deque()
d.append(v)
seen=[0]*N
seen[0]=1
ans=[0]*N
while len(d)!=0:
    v=d.popleft()
    for j in nondirtree[v]:
        if seen[j]==0:
            dirtree[v].append(j)
            seen[j]=1
            d.append(j)
    #print(d,seen,dirtree)
    #input(
v=0
d=deque()
d.append(v)
#print(dirtree)
ans[0]=score[0]
while len(d)!=0:
    v=d.popleft()
    for j in dirtree[v]:
        ans[j]=ans[v]+score[j]
        d.append(j)
    #input()
    #print(ans)
print(*ans,sep=" ")


Measured memory_bytes: 140476
/*putchar(((i+j)&1)?'(':')');

    表示交替的符号很有用

*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b)
{
    ll res=1;
    a%=mod;
    assert(b>=0);
    for(; b; b>>=1)
    {
        if(b&1)
            res=res*a%mod;
        a=a*a%mod;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
// head

int n,m,a[10][10],ans;
int ok(string st)
{
    if(st[0] != 'A')
        return 0;
    int cnt = 0;
    for(int i=1; i<st.size(); i++)
    {
        if(!(st[i] >='a' && st[i] <= 'z'))
        {
            if(i == 1 || i == st.size()-1 || st[i] != 'C')
                return 0;
            cnt++;
        }
    }

    if(cnt != 1)
        return 0;
    return 1;

}
int main()
{
    string st;
    cin>>st;
    if(ok(st))
        puts("AC");
    else
        puts("WA");
}


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

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> c(N), t(N);
    rep(i, N) cin >> c[i] >> t[i];

    int mi = 0;
    rep(i, N) if(t[i] <= T) if(c[i] < c[mi]) mi = i;

    if(t[mi] <= T) cout << c[mi] << endl;
    else cout << "TLE" << endl;

    return 0;
    
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){
  int N,i,j,k,A[1000],v;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=N;i++){
    v = A[i];
    j = i-1;
    for(k=0;k<N-1;k++)printf("%d ",A[k]);
    printf("%d",A[N-1]);
    printf("\n");
    while(j>=0&&A[j]>v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  }
  return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <algorithm>
using namespace std;
int a[1000006], b[1000006], c[1000006];
long long s[1000006];
int main(){
	int n;
	cin >> n;
	long long s1 = 0, s2 = 0;
	for (int i = 1; i <= n; ++ i){
		cin >> a[i] >> b[i];
		s1 += a[i];
		s2 += b[i];
		c[i] = a[i];
		c[i + n] = b[i];
	}
	long long ans = min(s1, s2);
	sort(c + 1, c + 1 + 2 * n);
	for (int i = 1; i <= n; ++ i)
		s[i] = s[i - 1] + c[i];
	for (int i = 1; i <= n; ++ i){
		int x = a[i], y = b[i];
		if (x > y)
			swap(x, y);
		int px = lower_bound(c + 1, c + 1 + 2 * n, x) - c;
		int py = lower_bound(c + 1, c + 1 + 2 * n, y) - c;
		if (px <= n - 2){
			if (py <= n - 1)
				ans = min(ans, s[n]);
			else
				ans = min(ans, y + s[n - 1]);
		}
		else
			ans = min(ans, x + y + s[n - 2]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 9216
def LI(): return list(map(int, input().split()))
def LS(): return input().split()
def I(): return int(input())
def S(): return input()

n = I()
a1 = LI()
a2 = LI()
s1 = []
s2 = []
ans = 0

now = 0
now2 = 0
for i in range(n):
    now += a1[i]
    s1.append(now)
    now2 += a2[-i-1]
    s2.append(now2)
s2 = s2[::-1]
for i in range(n):
    ans = max(ans, s1[i] + s2[i])
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int n;string s;
	cin>>n>>s;
	int ans=0;
	fori(s.length()-1){
		int score=0;
		map<char,bool> m;
		forj(i+1){
			auto itr=m.find(s[j]);
			if(itr==m.end()){
				m[s[j]]=true;
			}
		}
		for(int j=i+1;j<s.length();++j){
			auto itr=m.find(s[j]);
			if(itr!=m.end()&&m[s[j]]){
				m[s[j]]=false;
				++score;
			}
		}
		ans=max(ans,score);
	}
	cout<<ans;
}

Measured memory_bytes: 384
def codefes17qc_c():
    s = str(input())

    # x除去して回文であることが成立条件
    nox = s.replace('x', '')  # x除去
    noxrev = nox[::-1]  # x除去の反転
    if nox != noxrev:
        print(-1)
        return

    # 順sと逆sを見ていき、合わないところはxが入るところ
    srev = s[::-1]  # s反転
    ins = 0  # x挿入した回数の管理
    i, j = 0, 0
    while i < len(s) and j < len(s):
        if s[i] == srev[j]:
            i += 1
            j += 1
        else:
            if s[i] != 'x' and srev[j] == 'x':
                ins += 1
                j += 1
            if s[i] == 'x' and srev[j] != 'x':
                ins += 1
                i += 1

    ins += len(s) - min(i, j)  # 端っこのxのぶんを足す
    ans = ins // 2  # ぜんぶなめたので答えはその半分
    print(ans)

codefes17qc_c()

Measured memory_bytes: 3316
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    BigDecimal l = BigDecimal.valueOf(Long.parseLong(sc.next()));
    pw.println(l.divide(BigDecimal.valueOf(3), 8, RoundingMode.HALF_UP).pow(3)
      .setScale(12, RoundingMode.HALF_UP));
  }
}


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

template<long long MOD = 1000000007>
struct Mint {
private:
  long long val;

public:
  constexpr Mint(const long long x = 0) noexcept : val(x < 0 ? x % MOD + MOD : x >= MOD ? x % MOD : x) {}
  constexpr Mint &operator+=(const Mint rhs) noexcept {
    if ((val += rhs.val) >= MOD) val -= MOD;
    return *this;
  }
  constexpr Mint &operator-=(const Mint rhs) noexcept {
    if ((val -= rhs.val) < 0) val += MOD;
    return *this;
  }
  constexpr Mint &operator*=(const Mint rhs) noexcept {
    val = val * rhs.val % MOD;
    return *this;
  }
  constexpr Mint &operator/=(Mint rhs) noexcept {
    val = val * rhs.inv().val % MOD;
    return *this;
  }
  constexpr Mint operator+(const Mint& rhs) const noexcept { return Mint(*this) += rhs; }
  constexpr Mint operator-(const Mint& rhs) const noexcept { return Mint(*this) -= rhs; }
  constexpr Mint operator*(const Mint& rhs) const noexcept { return Mint(*this) *= rhs; }
  constexpr Mint operator/(const Mint& rhs) const noexcept { return Mint(*this) /= rhs; }
  constexpr Mint inv() const noexcept { return pow(MOD-2); }
  constexpr Mint pow(long long n) const noexcept {
    Mint ret(1), mul(val);
    while (n) {
      if (n % 2) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  constexpr bool operator==(const Mint& rhs) const noexcept { return val == rhs.val; }
  constexpr bool operator!=(const Mint& rhs) const noexcept { return val != rhs.val; }
  friend ostream &operator<<(ostream &os, const Mint<MOD> &x) { return os << x.val; }
  friend istream &operator>>(istream &is, Mint<MOD> &x) {
    long long t;
    is >> t;
    x.val = t % MOD;
    return is;
  }
};

int main() {
  int n; cin>>n;
  vector<int> last(200010, -1);
  vector<Mint<>> dp(n+1, 0);
  dp[0] = 1;

  int prev = -1;
  for (int i = 0; i < n; i++) {
    dp[i+1] = dp[i];
    int c; cin>>c; --c;
    if (prev == c) continue;
    if (last[c] != -1) {
      dp[i+1] += dp[last[c] + 1];
    }
    last[c] = i;
    prev = c;
  }

  cout << dp[n] << endl;

  return 0;
}

Measured memory_bytes: 2688
using System;
using System.Linq;

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int a = arr[0];
    int b = arr[1];
    if (a + b == 15)  Console.WriteLine("+");
    else if (a * b == 15) Console.WriteLine("*");
    else Console.WriteLine("x");
  }
}

Measured memory_bytes: 13268
// Problem : D - People on a Line
// Contest : AtCoder Regular Contest 090
// URL : https://atcoder.jp/contests/arc090/tasks/arc090_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define size(x) (int)x.size()

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

struct adj_list {
	int v, w;
};

bool vis[N];
int n, m, cnt = 0, par[N], pos[N];
vector<adj_list> adj[N];

void dfs(int v) {
	vis[v] = 1;
	for (auto c : adj[v]) {
		int u = c.v, w = c.w;
		if (pos[u] == inf) {
			pos[u] = pos[v] + w;
		} else if (pos[u] != pos[v] + w) {
			cout << "No";
			exit(0);
		}
		if (vis[u]) {
			continue;
		}
		dfs(u);
	}
}

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	for (int i = 1, u, v, w; i <= m; i++) {
		cin >> u >> v >> w;
		adj[u].push_back({v, w});
		adj[v].push_back({u, -w});
	}
	fill(pos + 1, pos + n + 1, inf);
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			pos[i] = 0;
			dfs(i);
		}
	}
	cout << "Yes";
}


Measured memory_bytes: 36592
#include <stdio.h>
#include <iostream>
#include <map>
#include <string>

using namespace std;

map<string,int> mp;

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        string tmp;
        cin>>tmp;
        mp[tmp]++;
    }
    printf("%d\n",mp.size());
}

Measured memory_bytes: 19420
#include <bits/stdc++.h>
#define ll long long
using namespace std;
/*int max(int arr[]){
	for(int i=0;i<k;i++){
		
	}
}*/
int main() {
	ll n,k;
	cin>>n>>k;
	ll a[n][2];
	for(ll i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1];
		
	}
	ll dp[n+1][k+1];
	for(ll i=0;i<=n;i++){
		for(ll j=0;j<=k;++j)
		dp[i][j]=0;
	}
	for(ll i=1;i<=n;i++){
		for(ll j=0;j<=k;j++){
			if(j>=a[i-1][0])
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i-1][0]]+a[i-1][1]);
			else 
			dp[i][j]=dp[i-1][j];
		}
	}
	ll m=-1;
	for(ll i=0;i<=k;i++){
		m=max(m,dp[n][i]);
	}
	//for(int i=0;i<=n;++i){for(int j=0;j<=k;++j)cout<<dp[i][j]<<" ";cout<<"\n";}
	cout<<m;
	return 0;
}

Measured memory_bytes: 79104
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define VAR(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}
// }}} End Header

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

    VAR(int, H, W);
    int cnt = 0;
    rep(i, 0, H) {
        VAR(string, s);
        cnt += count(all(s), '#');
    }

    if (cnt == H + W - 1) {
        print("Possible");
    } else {
        print("Impossible");
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cctype>
#include <cstdio>
#include <math.h>
using f32 = float;
using f64 = double;
using f80 = __float80;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vs = vector<string>;
using vl = vector<LL>;
using vvl = vector<vl>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
int main()
{
    int n,a,b,c;
    string A,B,C;
    cin >> a>>b;
    REP(i,1000000000){
      if(abs(a-i)==abs(b-i)){
          cout <<i;
          return 0;
      }
    }
    cout << "IMPOSSIBLE";
   return 0;    
    }


Measured memory_bytes: 384
S = list(input())
a, b = [], []
cnt_a, cnt_b = 0, 0

for i in range(len(S)):
    if i % 2 == 0:
        a.append('0')
        b.append('1')
    else:
        a.append('1')
        b.append('0')

for j in range(len(S)):
    if a[j] != S[j]:
        cnt_a += 1
    if b[j] != S[j]:
        cnt_b += 1

print(min(cnt_a, cnt_b))

Measured memory_bytes: 5512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll a, b; cin>>a>>b;
  ll cnt=1;ll num=0;
  while (cnt<b) {
    cnt+=a-1;
    num++;
  }
  cout << num;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<double> a(n + 1);
    vector<vector<double>> dp(n + 1, vector<double>(n + 1));
    for (int i = 1; i <= n; i++) cin >> a[i];

    dp[0][0]=1;
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= n; j++){
            dp[i][j] = dp[i-1][j]*(1 - a[i]) + dp[i-1][j-1]*a[i];
        }
    }

    int mid = (n + 1) / 2;
    if (n % 2 == 0) mid ++;
    double res = 0;
    for (int i = mid; i <= n; i++) res += dp[n][i];
    cout << setprecision(10) << res;
}


Measured memory_bytes: 70656
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,x[510],rk[510],a[300010],cur;
bool cmp(int l,int r){
	return x[l]<x[r];
}
int main(){
	n=read();int i,j,tmp;
	for(i=1;i<=n;i++) x[i]=read(),rk[i]=i;
	sort(rk+1,rk+n+1,cmp);
	int used=0;cur=1;
	for(i=1;i<=n;i++){
//		cout<<"do "<<i<<' '<<cur<<'\n';
		if(x[rk[i]]-used<rk[i]){
			puts("No");return 0;
		}
		used+=rk[i];
		a[x[rk[i]]]=rk[i];
		for(j=1;j<=rk[i]-1;j++){
			while(a[cur]) cur++;
//			cout<<"	mark "<<cur<<'\n';
			a[cur]=rk[i];
		}
	}
	for(i=1;i<=n;i++){
		tmp=rk[i];if(tmp==n) continue;
		for(j=x[rk[i]]+1;j<=n*n;j++){
			if(a[j]) continue;
//			cout<<"mark "<<rk[i]<<' '<<j<<' '<<tmp<<' '<<n<<'\n';
			a[j]=rk[i];tmp++;
			if(tmp==n) break;
		}
		if(tmp<n){
			puts("No");return 0;
		}
	}
	puts("Yes");
	for(i=1;i<=n*n;i++) printf("%d ",a[i]);
} 

Measured memory_bytes: 2176
ans1 = []
ans2 = []
ans3 = []
for i in range(4):
    ans1 = []
    ans2 = []
    for j in range(3):
        ans1 = []
        for k in range(10):
            ans1.append(0)
        ans2.append(ans1)
    ans3.append(ans2)

ans4 = []
n = int(input())
for i in range(n):
    ans4 = list(map(int, input().split()))
    ans3[ans4[0]-1][ans4[1]-1][ans4[2]-1] += ans4[3]

for i in range(4):
    for j in range(3):
        print(" ", end="")
        for k in range(9):
            print(ans3[i][j][k], end=" ")
        print(ans3[i][j][9])
    if i < 3:
        print("####################")


Measured memory_bytes: 5616
from collections import deque
N, M = map(int, input().split())
path = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    path[a-1] += [b-1]
    path[b-1] += [a-1]

next_vec = [0]
visited = [1] + [0] * (N-1)
parent = [-1] + [0] * (N-1)
flag = 1


while next_vec:
    current_vec = next_vec[:]
    next_vec = []
    while current_vec:
        u = current_vec.pop()
        visited[u] = 1
        for v in path[u]:
            if visited[v] == 0:
                visited[v] = 1
                parent[v] = u
                next_vec.append(v)

ans_flag = 1
for i in visited:
    if i == 0:
        ans_flag = 0
if ans_flag:
    print('Yes')
    for i in range(1,N):
        print(parent[i]+1)
else:
    print('No')


Measured memory_bytes: 35476
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

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

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	int n, m;
	cin >> n >> m;
	if(n & 1)
	{
		rep(i,0,m)
			cout << i+1 << ' ' << n - i << '\n';
	}
	else
	{
		rep(i,0,min(m, n/4))
			cout << i+1 << ' ' << 2*(n/4) - i << '\n';
		m = max(m - n / 4, 0);
		rep(i,0,m)
			cout << 2*(n/4)+i+1 << ' ' << n - i - 1 << '\n';
	}
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
template<class T>
using PAIR = pair<T,T>;
template<class T>
using vec = vector<T>;
template<class T>
using maps = map<string, T>;
template<class T>
using mapi = map<int, T>;
using ll = long long;
int main(){
    int A, B;
    cin >> A >> B;
    if((A+B)%2 == 0){
        cout << (A+B)/2 << "\n";
    }
    else{
        cout << "IMPOSSIBLE" << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 200010;
 
// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i * fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll n, k;
    cin >> n >> k;
 
    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(all(a));
 
    init();
 
    ll ans = 0;
    exrep(i, 0, n-k) {
        ll p = (2*mod + a[n-1-i] - a[i])%mod;
        ll q = Comb(n-1-i, k-1);
        ans += (p*q)%mod;
        ans %= mod;
    }
 
    out(ans);
    re0;
}

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

int main(void)
{
    int n, w, h;
    int koto_w[100005] = {};
    int koto_h[100005] = {};
    int i, j, k, l;
    int a, b, c;
    int flag1 = 1;
    int flag2 = 1;
    l = 1;
    cin >> n >> w >> h;
    for(i = 0; i < n; i++){
        cin >> a >> b >> c;
        if(koto_w[a] < c){ koto_w[a] = c;}
        if(koto_h[b] < c){ koto_h[b] = c;}
    }
    /*for(i = 0; i <= w; i++){
        cout << koto_w[i] << " ";
    }
    cout << endl;
    for(i = 0; i <= h; i++){
        cout << koto_h[i] << " ";
    }
    cout << endl;
    */
    i = 0;
    j = -1;
    while(1){
        if(koto_w[i] != 0){
            //????????§??????
            if(j >= koto_w[i]){
                i++;
                j++;
                if(i == w){
                    flag1 = 0;
                    break;
                }
                continue;
                } //????????£????????¨???
            if(j > -1-koto_w[i]){
                j = -1-koto_w[i];
            }
        }
        i++;
        j++;
        //cout << i << endl;
        //???????????§??????
        if(i == w){
            j = j - koto_w[i];
            if(j >= 0){
                flag1 = 0;
                break;
            }else{
                break;
            }
        }
    }

    i = 0;
    j = -1;
    while(1){
        if(koto_h[i] != 0){
            //????????§??????
            if(j >= koto_h[i]){
                i++;
                j++;
                if(i == h){
                    flag2 = 0;
                    break;
                }
                continue;
                } //????????£????????¨???
            if(j > -1-koto_h[i]){
                j = -1-koto_h[i];
            }
        }
        i++;
        j++;
        //???????????§??????
        if(i == h){
            j = j - koto_h[i];
            if(j >= 0){
                flag2 = 0;
                break;
            }else{
                break;
            }
        }
    }
    if(flag1 || flag2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;

}

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

namespace Simple_Calculator
{
    class Program
    {
        static void Main(string[] args)
        {

            List<string> all = new List<string>();

            while (true) 
            {
                string temp = Console.ReadLine();
                string[] temp2 = temp.Split(' ');

                if (temp2[1].Equals("?"))
                {
                    break;
                }

                
                foreach (string item in temp2)
                {
                    all.Add(item);
                }
            }

            for (int i = 0; i < all.Count; i += 3)
            {
                switch (all[i + 1])
                { 
                    case "+":
                        Console.WriteLine(int.Parse(all[i]) + int.Parse(all[i + 2]));
                        break;
                    case "-":
                        Console.WriteLine(int.Parse(all[i]) - int.Parse(all[i + 2]));
                        break;
                    case "*":
                        Console.WriteLine(int.Parse(all[i]) * int.Parse(all[i + 2]));
                        break;
                    case "/":
                        Console.WriteLine(int.Parse(all[i]) / int.Parse(all[i + 2]));
                        break;
                }
            }
            
        }
    }
}



Measured memory_bytes: 15984
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 998244353;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A*B)%MOD;
}

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

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

//long long A,B;
bool ok(long long key,long long index){
    if(index > key) return true;
    else if(index <= key) return false;
}
long long binary_search(long long key,long long size){
    //left,right,midはいずれもindex
    long long left = -1,right = size;
    while(right - left > 1){
        long long mid = left + (right-left)/2;
        long long hantei = ok(key,mid);
        if(hantei) right = mid;
        else left = mid;
    }
    if(left == -1)return 0;
    return left;
}

int main() {
    int N,A,B;cin >> N >> A >> B;
    int mini = A+B-N;
    if(A+B - N < 0) mini = 0;
    cout << min(A,B) << " " << mini << endl;
}


Measured memory_bytes: 256
main2(n){
  int i,s,x,M=0,m=500;
  for(;n;n--){
    for(i=s=0;i<5;i++)
      scanf("%d",&x),s+=x;
    if(m>s)m=s;
    if(M<s)M=s;
  }
  printf("%d %d\n",M,m);
}
main(n){for(;scanf("%d",&n),n;)main2(n);exit(0);}

Measured memory_bytes: 0
import java.util.*;


public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		char c1=s.charAt(0);char c2=s.charAt(1);char c3=s.charAt(2);
		
		int ans=0;
		
		if(c1=='R') {
			if(c2!='R')ans=1;
			else {
				if(c3!='R')ans=2;
				else ans=3;
			}
		}else if(c2=='R') {
			if(c3=='R')ans=2;
			else ans=1;
		}else {
			if(c3=='R')ans=1;
		}
		
		
		System.out.println(ans);

	}

	
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

class UnionFind { public: std::vector<size_t> P; std::vector<size_t> S; size_t find(size_t x) { return P[x] == x ? x : P[x] = find(P[x]); } public: UnionFind(size_t n) { P.resize(n); iota(P.begin(), P.end(), 0); S.resize(n); fill(S.begin(), S.end(), 1); } void unite(size_t x, size_t y) { x = find(x); y = find(y); if (x == y) return; if (S[x] < S[y]) { P[x] = y; S[y] += S[x]; } else { P[y] = x; S[x] += S[y]; } } bool same(size_t x, size_t y) { return find(x) == find(y); } size_t size(size_t x) { return S[find(x)]; } };

using P = pair<i64, i64>;
signed main() {
  i64 n;
  cin >> n;
  vector<P> ps(n);
  vector<vector<i64>> cx(100010);
  vector<vector<i64>> cy(100010);
  UnionFind uf(n);
  vector<i64> Y;
  REP(i, n){
    i64 x, y;
    cin >> x >> y;
    ps[i] = {x, y};
    cx[x].push_back(i);
    cy[y].push_back(i);
    if (cx[x].size() > 1) {
      uf.unite(cx[x][0], i);
    }
    if (cy[y].size() > 1) {
      uf.unite(cy[y][0], i);
    }
  }
  vector<set<i64>> kx(100010);
  vector<set<i64>> ky(100010);
  REP(i, n) {
    kx[uf.find(i)].insert(ps[i].first);
    ky[uf.find(i)].insert(ps[i].second);
  }
  i64 ans = 0;
  REP(i, 100010) {
    ans += kx[i].size() * ky[i].size();
  }
  ans -= n;
  cout << ans << endl;
}


Measured memory_bytes: 25856
n=int(input())
l=[int(i) for i in input().split()]
l=sorted(l)
n=len(l)
ans=0 
for i in range(n-1,0,-1):
    le=0 
    r=i-1 
    while le<r:
        if l[le]+l[r]>l[i]:
            ans=ans+(r-le)
            r-=1 
        else:
            le+=1 
print(ans)

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

int max2(int length, int *num){
  int _max2 = num[0];
  for(int i = 1; i < length; i++){
    _max2 = max(_max2, num[i]);
  }
  return _max2;
}

int sigma(int length, int *num){
  int _sigma = 0;
  for(int i = 0; i < length; i++){
    _sigma += num[i];
  }
  return _sigma;
}

int main(){
  int a[3], max_, sigma_;
  for(int i = 0; i < 3; i++)cin >> a[i];

  int ans = 0;
  if(a[0]%2 == a[1]%2 && a[1]%2 == a[2]%2){

  }else if(a[0]%2 == a[1]%2 && a[1]%2 != a[2]%2){
    a[0] += 1;
    a[1] += 1;
    ans += 1;
  }else if(a[0]%2 != a[1]%2 && a[1]%2 == a[2]%2){
    a[1] += 1;
    a[2] += 1;
    ans += 1;
  }else if(a[0]%2 == a[2]%2 && a[0]%2 != a[1]%2){
    a[0] += 1;
    a[2] += 1;
    ans += 1;
  }
  max_ = max2(3, a);
  sigma_ = sigma(3, a);
  ans += ( max_*3 - sigma_)/2;

  cout << ans <<endl;

}


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

int main() {
  int n;cin>>n;
  int color[8];rep(i,8)color[i]=0;
  int rate;
  int over=0;
  rep(i,n) {
    cin>>rate;
    if (rate>=3200) over++;
    else color[rate/400]++;
  }
  int cnt = 0; rep(i,8) if(color[i]>0) cnt++;
  cout << max(cnt, 1) << " " << cnt+over;
}


Measured memory_bytes: 256
n,k = gets.chomp.split().map(&:to_i)

ans = 0.0
1.upto(n).each do |i|
  num = i
  c = 0
  while num <= k - 1
    num *= 2
    c += 1
  end
  ans += 0.5 ** c
end

puts ans / n

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
  int n, p; cin >> n >> p;
  string s; cin >> s;
  
  if (p == 2 || p == 5) {
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      int d = s[i] - '0';
      if (d % p == 0) {
        ans += i + 1;
      }
    }
    cout << ans << endl;
    return 0;
  }
  
  auto power = [&](ll a, ll b) -> ll {
    ll x = 1, y = a;
    while (b > 0) {
      if (b % 2) x = (x * y) % p;
      y = (y * y) % p;
      b /= 2;
    }
    return x % p;
  };
  
  vector<ll> count(p, 0);
  count[0] = 1;
  int res = 0;
  for (int i = 0; i < n; i++) {
    res = (10 * res + s[i] - '0') % p;
    int idx = (res * power(10, n - 1 - i)) % p;
    count[idx]++;
  }
  
  ll ans = 0;
  for (int i = 0; i < p; i++) {
    ans += (count[i] * (count[i] - 1)) / 2;
  }
  cout << ans << endl;
  return 0;
}
    
    

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<iostream>
#define in inline
#define re register
#define int long long
#define M 1000000007
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();	
	while(v<'0'||v>'9'){
	v=getchar();
	}	
	while(v>='0'&&v<='9'){		
	t=(t<<3)+(t<<1)+(v^48);		
	v=getchar();	}
	return t;
}
int t1,t2,a1,a2,b1,b2,a,b,lst,nxt,ans;
inline int gcd(re int x,re int y){
	return x%y?gcd(y,x%y):y;
}
signed main(){
t1=read();
t2=read();
a1=read();b1=read();
a2=read();

b2=read();

if((a1>a2&&b1>b2)||(a1<a2&&b1<b2)){
	puts("0");
	return 0;
}

if(a1<a2)swap(a1,a2),swap(b1,b2);
a=(a1-a2)*t1;
b=(b2-b1)*t2;
if(a>b){
	puts("0");
	return 0;
}
if(a==b){
	puts("infinity");
	return 0;
}
int tmp=b-a;
ans=(a/tmp)*2;
if(a%tmp)++ans;
printf("%lld",ans);
}

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

using namespace std;

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

int alpha[26];

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

    REP(i , 26) alpha[i] = 0;
    bool flag = false;

    string s;
    cin >> s;
    int length = s.length();
    REP(i, length){
        ++alpha[int(s[i]) - 'a'];
    }
    
    REP(i, 26){
        if(alpha[i] > 1) flag = true;
    }

    flag ? cout << "no" << endl : cout << "yes" << endl;


}



Measured memory_bytes: 256