akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
int b[N];
int n;
ll solve(int sign){
	int i;
	ll ans = 0;
	ll cur = 0;
	Fo(i, 0, n){
		cur += a[i];
		if(sign==1){
			//positive
			if(cur<=0) ans += -cur+1, cur = 1;
		}
		else{
			//negative
			if(cur>=0) ans += cur+1, cur = -1;
		}
		sign *= -1;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,k,j;
	cin >> n;
	fo(i, n) cin >> a[i], b[i] = a[i];
	cout << min(solve(-1), solve(1)) << endl;
	
	return 0;
} 

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
	if (exp & 1) result = ((ll)result * base) % mod;
	base = ((ll)base * base) % mod;
	exp >>= 1;
	}
	return result;
}

void ipgraph(int m){
	int i, u, v;
	fo(i, m){
		cin>>u>>v; 
		u++, v++;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=305,INF=1<<30;
bool dp[MAX][MAX][MAX];
ll dp2[MAX][MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;cin>>S;
    int N=si(S);
    dp[0][0][0]=1;
    
    for(int i=0;i<N;i++){
        for(int j=N;j>=0;j--){
            for(int k=N;k>=0;k--){
                if(dp[i][j][k]==0) continue;
                
                if(i+1<N){
                    if(S[i]=='0') dp[i+2][j+1][k]=1;
                    else dp[i+2][j][k+1]=1;
                    
                    if(S[i+1]=='0') dp[i+2][j+1][k]=1;
                    else dp[i+2][j][k+1]=1;
                    
                    dp[i+1][j][k]=1;
                }
                
                if(j&&S[i]=='1') dp[i+1][j-1][k+1]=1;
                
                if(k&&S[i]=='0') dp[i+1][j+1][k-1]=1;
                
                if(j||k) dp[i+1][j][k]=1;
                
                if(j) dp[i][j-1][k]=1;
                
                if(k) dp[i][j][k-1]=1;
            }
        }
    }
    
    reverse(all(S));
    
    dp2[0][0][0]=1;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<=N;j++){
            for(int k=0;k<=N;k++){
                if(S[i]=='0'){
                    dp2[i][j][k+1]+=dp2[i][j][k];
                    dp2[i][j][k+1]%=mod;
                }else{
                    dp2[i][j+1][k]+=dp2[i][j][k];
                    dp2[i][j+1][k]%=mod;
                }
                dp2[i+1][j][k]+=dp2[i][j][k];
                dp2[i+1][j][k]%=mod;
            }
        }
    }
    
    ll ans=0;
    
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            for(int k=0;k<=N;k++){
                if(dp[i][j][k]){
                    ans+=dp2[N-i][j][k];
                }
                ans%=mod;
            }
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 228936
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 100005;

class Edge {
public:
  int nxt, to;
} e[MAX_N << 1];

int head[MAX_N], cnt, Nx;

void addedge(int u, int v) {
  e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
  e[++cnt] = (Edge){head[v], u}, head[v] = cnt;
}

int dep[MAX_N], fa[MAX_N], id[MAX_N];
bool vis[MAX_N];

void dfs(int u, int v) {
  id[u] = u, fa[u] = v, dep[u] = dep[v] + 1;
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].to != v)
      dfs(e[i].to, u);
}

bool cmp(int x, int y) {
  return dep[x] > dep[y];
}

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1, u, v; i < N; ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
  }
  
  dfs(1, 0);

  sort(id + 1, id + N + 1, cmp);

  vis[0] = 1;
  bool flag = 1;
  for (int i = 1; i <= N; ++i) {
    if (vis[id[i]]) continue;
    if (vis[fa[id[i]]]) flag = 0;
    vis[fa[id[i]]] = 1;
  }

  if (flag) puts("Second");
  else puts("First");
  
  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main()
{
    long long ans = 0;
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n;i++)
        cin >> a[i];
    for (int i = 1; i < n;i++)
        if(a[i]>a[i-1])
            continue;
        else
            {
                ans += a[i-1] - a[i];
                a[i] = a[i - 1];
            }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3972
#include <stdio.h>

int main(void) {
	int i, idx = 0;
  	char str[12];
  	char buf[12];
  
  	scanf("%s", str);
  	for (i = 0; str[i]; i++) {
    		if (str[i] == 'B') { if (--idx < 0) idx = 0; }
      		else buf[idx++] = str[i];
    	}
  	buf[idx] = '\0';
  	printf("%s", buf);
  	
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  
  int count = 0;
  
  if(s.at(0) == '1') count++;
  if(s.at(1) == '1') count++;
  if(s.at(2) == '1') count++;
  
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
const int N = 99999;
int n, m, d, q;
int X[N], Y[N], f[N];
int Mabs(int x)
{
	return x<0?-x:x;
}
int main()
{
	scanf("%d%d%d", &n, &m, &d);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			int x;
			scanf("%d", &x);
			X[x] = i;
			Y[x] = j;
		}
	for(int i = d + 1; i <= n*m; i++)
		f[i] = f[i-d] + Mabs(X[i]-X[i-d]) + Mabs(Y[i]-Y[i-d]);
	scanf("%d", &q);
	for(int i = 1; i <= q; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		printf("%d\n", f[y] - f[x]);
	}
	return 0;
}

Measured memory_bytes: 2176
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()
	}
	return ints
}

func calcGcd(l, r int) int {
	if r > l {
		r, l = l, r
	}

	if r == 0 {
		return l
	}
	d := l % r
	for d != 0 {
		l = r
		r = d
		d = l % r
	}
	return r
}

func calcLeftSideGcds(ints []int) []int {
	n := len(ints)
	left := make([]int, n)
	for i := 1; i < n; i++ {
		left[i] = calcGcd(left[i-1], ints[i-1])
	}
	return left
}

func calcRightSideGcds(ints []int) []int {
	n := len(ints)
	right := make([]int, n)
	for j := n - 2; j >= 0; j-- {
		right[j] = calcGcd(right[j+1], ints[j+1])
	}
	return right
}

func calcMaxGcd(ints []int) int {
	left := calcLeftSideGcds(ints)
	right := calcRightSideGcds(ints)

	n := len(ints)
	gcds := make([]int, n)

	for i := 0; i < n; i++ {
		gcds[i] = calcGcd(left[i], right[i])
	}

	max := gcds[0]
	for i := 1; i < n; i++ {
		if max < gcds[i] {
			max = gcds[i]
		}
	}
	return max
}

func main() {
	n := nextInt()
	ints := nextInts(n)
	r := calcMaxGcd(ints)
	fmt.Println(r)
}


Measured memory_bytes: 5504
var lines = [];
var MOD = Math.pow(10, 9) + 7
var result = 1;

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var S = lines[1].split("");

    S.sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0));

    var counter = []; var cnt = 1;
    for (var i = 1; i < N; i++) {
        if (S[i - 1] !== S[i]) { counter.push(cnt); cnt = 0; }
        cnt++;
    }

    counter.push(cnt);

    for (var i = 0; i < counter.length; i++) {
        result *= counter[i] + 1;
        result %= MOD;
    }

    console.log(result - 1);
});

Measured memory_bytes: 9788
#include<stdio.h>

int ar[200005];

int main() {
  int n;
  scanf("%d", &n);
  int f = 0, s = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &ar[i]);
    if (ar[i] > f) s = f, f = ar[i];
    else if (ar[i] > s) s = ar[i];
  }
  for (int i = 0; i < n; i++) {
	if (ar[i] != f) printf("%d\n", f);
    else printf("%d\n", s);
  }
  return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,k;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	if(a==b)
		printf("0");
	else if(k==0)
		printf("%d",a-b);
	else if(k%2==0)
	{
		printf("%d",a-b);
	}
	else
	{
		printf("%d",b-a);
	}
	return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
L =[]
R =[]
for i in range(M):
    L1, R1 = map(int,input().split())
    L.append(L1-1)
    R.append(R1+1)
if min(R) - max(L) -1<0:
    print("0")
else:
    print(min(R)-max(L)-1)

Measured memory_bytes: 10996
'use strict';
(function(stdin) {
  //declare function
  var compare = function(a, b) {
    if (a < b) return 'a < b';
    if (a > b) return 'a > b';
    return 'a == b';
  };
  //declare variable
  var inputs = stdin.toString().trim().split('\n');
  var cols = inputs[0].split(' ').map(Number);
  var a = cols.shift();
  var b = cols.shift();
  //main
  //display
  console.log(compare(a, b));
})(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 15512
a,b = map(int, input().split())
l = range(a, b+1)

def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return array

ans = 0
for i in range(a, b+1):
	s = digitSum(i)
	if s[0]==s[-1] and s[1] == s[-2]:
		ans += 1
print(ans)




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

int main(void){
  int N;
  cin>>N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin>>P[i];
  }
  int mini=200005;
  int count=0;
  for(int i=0;i<N;i++){
    if(P[i]<=mini){
      mini=P[i];
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}


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

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, W;
    cin>>n>>W;
    vector<int> w(n+1), v(n+1);
    vector<vector<long long int>> dp(n+1, vector<long long int> (W+1, 0));
    for(int i = 1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(int i = 1;i<=n;i++)
    {
        for(int j = 1;j<=W;j++)
        {
            if(j - w[i] >= 0)
            {
                dp[i][j] = max(dp[i-1][j - w[i]] + v[i], dp[i-1][j]);
            }
            else
            {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W]<<"\n";
    return 0;
}

Measured memory_bytes: 83164
from collections import defaultdict
 
S = list(input())
T = list(input())
ds = defaultdict(int)
dt = defaultdict(int)
cnt_s = []
cnt_t = []
for s, t in zip(S, T):
    ds[s] += 1
    dt[t] += 1
    cnt_s.append(ds[s])
    cnt_t.append(dt[t])
print('Yes' if cnt_s == cnt_t else "No")

Measured memory_bytes: 28240
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
#include <array>
#include <string>
#include <map>
#include <cmath>
//#include <iomainp>
using namespace std;

#define DB(x)
#define rep(i, n) for(int i = 0;i < n;i++)


int getIntSp(){
    string str;
    getline(cin,str,' ');
    return stoi(str);
}

int getIntLF(){
    string str;
    getline(cin,str);
    return stoi(str);
}



int main()
{
    int N;
    cin >> N;
    string S,T;
    cin >> S >> T;
    
    rep(i,N){
        cout << S.c_str()[i] << T.c_str()[i];
    }
    cout << endl;
    
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a+b<24) {
			System.out.println(a+b);
		}else if(a + b > 24){
			System.out.println(a+b-24);
		}else {
			System.out.println(0);
		}
	}

}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define test() ll t;cin>>t;while(t--)
#define MOD 1000000007
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

int main() {
    SPEED;
    //CODE
	ll x;
	cin>>x;
	ll ans=0;
	ll y=x/500;
	ans+=(y*1000);
	x-=(500*y);
	y=x/5;
	ans+=(y*5);
	cout<<ans;
	return 0;
}

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

const int N = 1e5 + 100, inF = N;

int n, U, V, dis[2][N];
vector<int> nei[N];
queue<int> q;

void act(int v, int *dis) {
	for (int u: nei[v])
		if (dis[u] == inF) {
			dis[u] = dis[v] + 1;
			q.push(u);
		}
}

void BFS(int v, int *dis) {
	fill(dis, dis + N, inF);
	dis[v] = 0;
	q.push(v);
	while (q.size()) {
		act(q.front(), dis);
		q.pop();
	}
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> U >> V;
	U--, V--;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		nei[--u].push_back(--v);
		nei[v].push_back(u);
	}
	BFS(U, dis[0]);
	BFS(V, dis[1]);
	int ans = 0;
	for (int i = 0; i < n; i++)
		if (dis[0][i] < dis[1][i])
			ans = max(ans, dis[1][i]);
	cout << ans - 1;
}


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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;

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

  ll n;
  cin >> n;
  string s;
  cin >> s;
  vector < set < ll > > v(26);
  for(int i = 0; i < n; i++){
    v[s[i] - 'a'].insert(i + 1);
  }

  ll q;
  cin >> q;
  while(q--){
    int a;
    cin >> a;
    if(a == 1){
      ll pos;
      cin >> pos;
      char ch;
      cin >> ch;
      v[s[pos - 1] - 'a'].erase(pos);
      v[ch - 'a'].insert(pos);
      s[pos - 1] = ch;
    }else{
      ll l, r;
      cin >> l >> r;
      ll cnt = 0;
      for(int i = 0; i < 26; i++){
        auto it = v[i].lower_bound(l);
        if(it != v[i].end() && *it <= r) cnt++;
      }
      cout << cnt << '\n';
    }
  }
}


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

int main()
{
	int n;
	cin >> n;
	n %= 10;

	if (n == 3)
	{
		cout << "bon\n";
	}
	else if (!n || n == 1 || n == 6 || n==8)
	{
		cout << "pon\n";
	}
	else
	{
		cout << "hon\n";
	}
}

Measured memory_bytes: 3556
from collections import deque

n, m = map(int, input().split())
ab = [[] for i in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    ab[a].append(b)
    ab[b].append(a)

ans = [-1]*(n+1)
que = deque([1])

while que:
    q = que.popleft()
    for i in ab[q]:
        if ans[i] == -1:
            que.append(i)
            ans[i] = q

print("Yes")

for i in range(2,n+1):
    print(ans[i])

Measured memory_bytes: 34184
n = int(input())
l = list(map(int, input().split()))
nl = {}
cal = {}
kal = {}
cl = {}
all = 0
for num in l:
  if num in nl:
    nl[num] = nl[num] + 1
  else:
    nl[num] = 1
for n in nl:
  if nl[n] > 1:
    cal[n] = nl[n] * (nl[n]-1) / 2
  else:
    cal[n] = 0
  if nl[n]-1 > 1:
    kal[n] = (nl[n]-1) * (nl[n]-2) / 2
  else:
    kal[n] = 0
  all += cal[n]
for n in nl:
  cl[n] = int(all - cal[n] + kal[n])
for i in l:
  print(cl[i])

Measured memory_bytes: 49696
from fractions import gcd
A,B,C,D = map(int,input().split())

c = (B // C) - ((A-1) // C)
d = (B // D) - ((A-1) // D)
lcm = C * D // gcd(C,D)
cd = (B // lcm) - ((A-1) // lcm)
print((B-A+1)-(c + d - cd))

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

long long spf[1000009],vis[1000009];

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mn=LLONG_MAX;
        long long cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld %lld",&n,&h); v.push_back(h);

        for(i=2;i<=n;i++)
        {
            scanf("%lld",&a); h=__gcd(h,a); v.push_back(a);

        }

        if(h>1)
        {
            printf("not coprime\n");
        }
        else
        {

             long long x,y,z,mx=1000007,lp,lim,tp; lim=sqrt(mx)+4;

             for(lp=3; lp<=mx; lp+=2)
             {
                  if(spf[lp]==0)
                   {
                        spf[lp]=lp;

                        if(lp<=lim)
                        {
                               y=lp << 1;

                               for(tp=lp+y; tp<=mx; tp+=y)
                               {
                                      if(spf[tp]==0){  spf[tp]=lp;  }
                               }

                       }

                   }

            }

            for(i=0;i<n;i++)
            {
                a=v[i];

                if(a!=1)
                {
                    while(a!=1)
                    {
                        if(a%2==0)fr=2;
                        else{  fr=spf[a]; }


                        if(vis[fr]<i+1 && vis[fr]!=0)
                        {
                            flag=0; break;
                        }

                        vis[fr]=i+1; a=a/fr;


                    }
                }

                if(flag==0)break;

            }


            if(flag==1)printf("pairwise coprime\n");
            else
            {
                printf("setwise coprime\n");
            }


        }










    return 0;
}





Measured memory_bytes: 19648
mod = 10 ** 9 + 7
max_kai = 2*10**6
kai = [1]
for i in range(1, max_kai):
    kai.append(kai[-1] * i % mod)
kkai = [0] * max_kai
kkai[-1] = pow(kai[-1], mod - 2, mod)
for i in reversed(range(1, max_kai)):
    kkai[i - 1] = kkai[i] * i % mod


def comb(a, b):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai[a]
    c *= kkai[b]
    c *= kkai[a - b]
    return c % mod


k = int(input())
s = input()

ans = 0
for i in range(k + 1):
    ans += pow(25, i, mod) * pow(26, k - i, mod) * comb(i + len(s) - 1, len(s) - 1)
    ans %= mod
print(ans)


Measured memory_bytes: 163368
n,m=map(int,input().split())
A=[]
B=[]
for i in range(n):
  A.append(list(map(int,input().split())))
for i in range(m):
  B.append(list(map(int,input().split())))

for i in range(n):
  man=1000000000
  ans=0
  for j in range(m):
    if abs(A[i][0]-B[j][0])+abs(A[i][1]-B[j][1])<man:
      man=abs(A[i][0]-B[j][0])+abs(A[i][1]-B[j][1])
      ans=j+1
  print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)malloc(sizeof(int)*n);
  int *b=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) scanf("%d%d",a+i,b+i);
  for(i=0;i<n && a[i]==b[i];i++);
  if(i==n){
    printf("0\n");
    return;
  }
  int64 sum=0;
  for(i=0;i<n;i++) sum+=a[i];
  int min=1000000000;
  for(i=0;i<n;i++){
    if(a[i]-b[i]>0 && min>b[i]){
      min=b[i];
    }
  }
  printf("%lld\n",sum-min);
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
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; }
using namespace std;
//#define P pair<int, int>
typedef pair<int, int> P;

int main(){
    int N;
    cin >> N;
    int M = (N + 1) / 2;
    cout << fixed << setprecision(10) << double(M)/double(N) << endl;
}

Measured memory_bytes: 256
import math

tb = [0 for x in range(10**5 + 1)]
so = []
sof = [False for x in range(len(tb))]
for i in range(2, 10**5 + 1):
  flag = True
  for s in so:
    if i % s == 0:
      flag = False
      break
    if s > math.sqrt(i):
      break
  if flag:
    so += [i]
    sof[i] = True

count = 0
for i in range(3, 10**5 + 1):
  if sof[i]:
    n2 = (i + 1) // 2
    if sof[n2]:
      count += 1
  tb[i] = count

q = int(input())
L = []
r = []
for i in range(q):
  L += [0]
  r += [0]
  L[i], r[i] = [int(x) for x in input().split()]
for i in range(q):
  res = tb[r[i]] - tb[L[i] - 1]
  print(res)


Measured memory_bytes: 13704
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

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

	int num = n;
	int sum=0;
	while (n != 0) {
		sum = sum + n % 10;
		n = n / 10;
	}

	if (num % sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3604
package main
import . "fmt"
import "sort"
func main() {
  var n,a,b,i int
  var k int64
  var keys []int
  m := map[int]int64{}
  Scan(&n,&k)
  for i=0;i<n;i++ {
    Scan(&a,&b)
    if v,ok := m[a];ok {
      m[a] = v+int64(b)
    } else {
      m[a] = int64(b)
    }
  }
  n = len(m)
  keys = make([]int,n)
  i = 0
  for key,_ := range m {
    keys[i] = key
    i++
  }
  sort.Ints(keys)
  for i=0;i<n;i++ {
    v := m[keys[i]]
    if k <= v {
      Println(keys[i])
      break
    }
    k -= v
  }
}

Measured memory_bytes: 8064
#include<stdio.h>
const int N = 105;
int main()
{
	int n, a[N] = {0};
	scanf("%d", &n);
	for(int i = 0;i < n; i++)
	{
		scanf("%d",&a[i]);
	}
	for (int i = n-1;i >= 0; i--)
	{
		if(i)
		{
			printf("%d ",a[i]);
		}
		else
		{
			printf("%d\n",a[i]);
		}
	}
	return 0;
} 


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

int main(void) {
	int n[3];
	int fiveCnt = 0;
	int sevenCnt = 0;
	for (int i = 0; i < 3; i++) {
		scanf("%d", &n[i]);
		if (n[i] == 5) {
			fiveCnt++;
		} else if (n[i] == 7) {
			sevenCnt++;
		}
	}
	if (fiveCnt == 2 && sevenCnt == 1) {
		printf("YES");
	} else {
		printf("NO");
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    ll lcm = n / __gcd(n, m) * m;
    map<ll, char> mp;
    for(int i = 0; i < s.size(); i++){
        ll j = i * (lcm/n) + 1;
        mp[j] = s[i];
    }
    for(int i = 0; i < t.size(); i++){
        ll j = i * (lcm/m) + 1;
        if (mp.find(j) != mp.end()){
            if (mp[j] != t[i]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << lcm << endl;
    return 0;
}

Measured memory_bytes: 9260
from collections import Counter
from functools import lru_cache

N = int(input())

#約数を列挙
@lru_cache(maxsize=1000)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

A_list = [make_divisors(int(e)) for e in input().split()]

all_divisors_list=[]

for i in A_list:
  all_divisors_list += i

collected_adl = Counter(all_divisors_list)

ans = 1
for a in collected_adl.most_common():
  if a[1] <= N-2:
    break
  elif a[0]>ans:
    ans=a[0]
    
print(ans)

Measured memory_bytes: 86212
#include <iostream>
using namespace std;
int main(){
    string S;
    cin >> S;
    int N = S.size(), MOD = 1000000007;
 	long long dp[100010][4] = {};
    for(int i = N; i >= 0; --i){
        for(int j = 3; j >= 0; --j){
            if(i == N){
                dp[i][j] = (j == 3 ? 1 : 0);
            }else{
                dp[i][j] = dp[i+1][j] * (S[i] == '?' ? 3LL : 1LL);
                if(j < 3 && (S[i] == '?' || S[i] == "ABC"[j])){
                    dp[i][j] += dp[i+1][j+1];
                }
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<int,int>
#define ff first
#define ss second
#define MAX 1000005
const ll MOD = 1000000007;

struct query{
	int k;
	char ch;
};

int BIT[26][MAX];

void update(int r, int idx, int n, int val){
	while(idx <= n){
		BIT[r][idx] += val;
		idx += (idx&-idx);
	}	
}

int sum(int r, int idx){
	int sum = 0;
	while(idx > 0){
		sum += BIT[r][idx];
		idx -= (idx&-idx);
	}
	return sum;
}

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

	int n;
	cin>>n;
	string s[n];
	for(int i=0;i<n;i++){
		cin>>s[i];
		reverse(s[i].begin(),s[i].end());
	}

	sort(s,s+n);

	// for(int i=0;i<n;i++)
	// 	cout<<s[i]<<"\n";

	vector<int> v;
	for(int i=0;i+1<n;i++){
		int k=0;
		while(k<s[i].length() && k<s[i+1].length() && s[i][k]==s[i+1][k])
			++k;
		v.pb(k);
		// cout<<k<<" ";
	}
	// cout<<"\n";

	
	int f[n][20];
	for(int i=0;i+1<n;i++)
		f[i][0] = v[i];
	f[n-1][0] = -1;

	for(int k=1;k<20;k++){
		for(int i=0;i<n;i++){
			int j = i+(1<<(k-1));
			if(j >= n)
				f[i][k] = -1;
			else
				f[i][k] = min(f[i][k-1],f[j][k-1]);
		}
	}


	vector<query> q;
	query temp;  

	vector<int> rem[n+1],add[n+1];
	for(int i=0;i<n;i++){
		int k = s[i].length()-1;
		int l=i,r=i;
		for(int j=19;j>=0;j--){
			if(f[r][j] >= k)
				r = r+(1<<j);
			if(l-(1<<j) >= 0 && f[l-(1<<j)][j] >= k)
				l = l-(1<<j);
		}
		// cout<<"i="<<i<<" l="<<l<<" r="<<r<<"\n";
		
		temp.k = k;
		temp.ch = s[i][k];
		int sz = q.size();
		q.pb(temp);
		add[r].pb(sz);
		if(l>0)
			rem[l-1].pb(sz);
	}
	
	
	memset(BIT,0,sizeof(BIT));

	ll ans = 0;

	for(int i=0;i<n;i++){
		vector<int> last(26,-1);
		for(int j=0;j<s[i].length();j++){
			int idx = s[i][j]-'a';
			if(last[idx] != -1)
				update(idx,last[idx]+1,MAX-1,-1);
			update(idx,j+1,MAX-1,1);
			last[idx] = j;
		}

		for(int idx: rem[i]){
			int k = q[idx].k;
			int r = q[idx].ch-'a';

			ans -= (sum(r,MAX-1)-sum(r,k));
		}

		for(int idx: add[i]){
			int k = q[idx].k;
			int r = q[idx].ch-'a';

			ans += (sum(r,MAX-1)-sum(r,k));
		}
	}

	cout<< ans-n <<"\n";
	
}


Measured memory_bytes: 146564
#include <iostream>
using namespace std;
int main()
{
  int N,Y;
  cin>>N>>Y;
  if (Y>10000*N) {cout<<"-1 -1 -1\n";return 0;}
  if (Y<1000*N) {cout<<"-1 -1 -1\n";return 0;}
  for (int i=0;i<=Y/10000;i++)
  {
    bool b=true;
    int j0=Y/1000-N-9*i;
    if (j0<0) b=false;
    if (j0%4) b=false;
    int j=j0/4,k=N-i-j;
    if (k<0) b=false;
    if (b) {cout<<i<<" "<<j<<" "<<k<<endl;return 0;}
  }
  cout<<"-1 -1 -1\n";return 0; 
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h> 
int main(void){
    int num,sum=0,o=0,sign=0;
    char line[100001];
    while((num=getchar()) != EOF){
        if(num >= '0' && num <= '9'){
            sign=1;
            line[o]=num;
            o++;
        }
        else if(sign == 1){
            line[o]=0;
            o=0;
            sum+=atoi(line);
            sign=0;
        }
        else{
            sign=0;
        }
    }
    if(sign == 1){
        line[o]=0;
        o=0;
        sum+=atoi(line);
        sign=0;
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 524
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

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

int main(void) {
    string str;
    while (1) {
        str.clear();
        getline(cin, str);
        if (str == ".") break;
        stack<char> st;
        int i;
        for (i = 0; i < str.size(); i++) {
            if (str[i] == '(' || str[i] == '[') st.push(str[i]);
            else if (str[i] == ')') {
                if (st.empty() || st.top() != '(') break;
                st.pop();
            } else if (str[i] == ']') {
                if (st.empty() || st.top() != '[') break;
                st.pop();
            }
        }
        if (i == str.size() && st.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

Measured memory_bytes: 1176
S = input()
target = 'keyence'
if target in S:
    print('YES')
    exit()
l = 0
r = 0
while S[l] == target[l]:
    l += 1
while S[len(S)-r-1] == target[6-r]:
    r += 1
if l + r >= 7:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(kbrni,n)cout<<" "<<a[kbrni];cout<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define svecp(v) cout<<#v<<":";each(kbrni,v)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    int n;
    cin >> n;
    cout << 0 << "\n";
    string s;
    cin >> s;
    int nw;
    if(s == "Vacant"){
        return 0;
    }else if(s == "Male"){
        nw = 0;
    }else{
        nw = 1;
    }
    int l = 0;
    int r = n-1;
    while(r-l>1){
        int mid = (l+r)/2;
        int cri = 0;
        cout << mid << "\n";
        cin >> s;
        if(s == "Vacant"){
            return 0;
        }else if(s == "Male"){
            if((mid - l)%2){
                if(nw == cri){
                    r = mid-1;
                }else{
                    nw = 0;
                    l = mid;
                }
            }else{
                if(nw == cri){
                    nw = 0;
                    l = mid;
                }else{
                    r = mid-1;
                }
            }
        }else{
            cri = 1;
            if((mid - l)%2){
                if(nw == cri){
                    r = mid-1;
                }else{
                    nw = 1;
                    l = mid;
                }
            }else{
                if(nw == cri){
                    nw = 1;
                    l = mid;
                }else{
                    r = mid-1;
                }
            }
        }
    }
    cout << r << "\n";
    cin >> s;
    return 0;
}


Measured memory_bytes: 852
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

int p, q, a, n;

//return
//1 -> ans == x / y
//0 -> ans < x / y
//-1 -> ans > x / y
int isOK(int x, int y){
    int tmp_x = x * q;
    int tmp_p = p * y;
    if(tmp_x == tmp_p) return 1;
    else if(tmp_x > tmp_p) return 0;
    else return -1;
}

int dfs(int x, int y, int now, int step){
    int tmp = isOK(x, y);
    if(tmp == 1) return 1;
    if(tmp == 0) return 0;
    if(step >= n) return 0;
    int ret = 0;
    for(int i = now; y * i <= a; i++){
        int next_y = i * y;
        int next_x = (next_y / i) + (next_y / y * x);
        ret += dfs(next_x, next_y, i, step + 1);
    }
    return ret;
}

int main(){
    while(cin >>p >>q >>a >>n && n) cout <<dfs(0, 1, 1, 0) <<endl;
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(void) {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (c>b&&b>a) {
		printf("%d %d %d\n", a, b, c);
	}
	if (b>c&&c>a) {
		printf("%d %d %d\n", a, c, b);
	}
	if (a>c&&c>b) {
		printf("%d %d %d\n", b, c, a);
	}
	if (c>a&&a>b) {
		printf("%d %d %d\n", b, a, c);
	}
	if (b>a&&a>c) {
		printf("%d %d %d\n", c, a, b);
	}
	if (a>b&&b>c) {
		printf("%d %d %d\n", c, b, a);
	}
	if (a == b&&b == c) {
		printf("%d %d %d\n", a, a, a);
	}
	if (a == b&&b>c) {
		printf("%d %d %d\n", c, a, a);
	}
	if (a == b&&c>b) {
		printf("%d %d %d\n", a, a, c);
	}
	if (b>a&&a==c){
		printf("%d %d %d\n", a, a, b);
	}
	if (a>c&&b == c) {
		printf("%d %d %d\n", b, b, a);
	}
	if (c>a&&b == c) {
		printf("%d %d %d\n", a, b, b);
	}
	return 0;
}


Measured memory_bytes: 2120
// Author : Mohamed sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
const int N = 1e6+9;
int a[N], n;
int sieve[N];
int factors[N];
int main()
{
	sieve[0] = sieve[1] = 1;
	for (int i = 2; i < N; i++)
	{
		for (int j = i; j < N; j+=i)
		{
			if (sieve[j] == 0)sieve[j] = i; 
			sieve[j] = min(i, sieve[j]); 
		}
	}
	cin >> n;
	int g = 0;
	for (int i = 0; i < n; i++)cin >> a[i], g = __gcd(g, a[i]);
	for (int i = 0; i < n; i++)
	{
		while(a[i] != 1)
		{
			int cur = sieve[a[i]];
			factors[ cur ]++;
			while(a[i] % cur == 0)a[i]/=cur; 
		}
	}
	int mx = 0;
	int ones = 0;
	for (int i = 2; i < N; i++)mx = max(mx, factors[i]), ones += (factors[i] == 1);
	if (mx <= 1)
	{
		cout <<"pairwise coprime\n"; 
	}else 
	{
		if (g == 1)
		{
			cout <<"setwise coprime\n";
		}else 
		cout <<"not coprime\n";
	}
}


Measured memory_bytes: 15224
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vll dir(n,-1);
    REP(i,n){
        cin >> dir[i];
        dir[i]--;
    }
    vll visited(n,0);
    vll ith(n,0);
    vll dep(n,0);
    ll a,b;
    ll now = 0;
    ll cnt = 0;
    while(true){
        if(visited[now]==1){
            a = dep[now];
            b = cnt;
            break;
        }
        visited[now]=1;
        dep[now]=cnt;
        ith[cnt]=now;
        now = dir[now];
        cnt++;
    }
    if(k<=a){
        cout << ith[k]+1 << endl;
    }else{
        k-=a;
        k%=(b-a);
        cout << ith[a+k]+1 << endl;
    }


    return 0;
}

Measured memory_bytes: 9536
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int tmp1, tmp2, a;

int main(){

	rep(i, 4) {
		cin >> a;
		tmp1 += a;
	}

	while (tmp1 / 60 != 0) {
		tmp1 -= 60;
		tmp2++;
	}

	cout << tmp2 << endl << tmp1 << endl;

	return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<algorithm>
using namespace std;
int p[1001],s[1002001];
int main(){
	int n,m;
	while(true){
	cin>>n>>m;
	if(n==0&&m==0)break;
	int cnt=1;
	p[0]=0,s[0]=0;
	for(int i=1;i<=n;i++){
		cin>>p[i];
		for(int j=0;j<=i;j++)
			s[cnt]=p[i]+p[j],cnt++;
	}
	sort(s,s+cnt);
	int ans=0;
	for(int i=0;i<cnt;i++){
		int left=0,right=cnt,mid;
		while(true){
			if(left>=right-1){
				mid=(left+right)/2;
			    if(s[i]+s[mid]<=m)
				ans=max(ans,s[i]+s[mid]);
				break;
			}
			mid=(left+right)/2;
			if(s[i]+s[mid]<=m){
				ans=max(ans,s[i]+s[mid]);
				left=mid;
			}
			else right=mid;
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

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


int main()
{  
    
    int n,k;
    cin>>n>>k;
    vector<int> coins(n);
    for(int i = 0 ; i < n ; i++) cin>>coins[i];
    vector<int> dp(k+1,false);
    for(int i = 1 ; i <= k ; i++)
    {
       for(auto x : coins)
       {
           if(i - x >= 0)
           {
               dp[i] |= !dp[i-x];
           }
       }
    }
    if(dp[k]) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
        
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD (int)1e9+(int)7
#define INF 2147483647
typedef long long ll;
typedef unsigned long long ull;
//dark power
#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
//komennto C+udekaijo
//conbination n!/r!(n-r)!
class UnionFind{
	public:
	vector<int> parent;
	vector<int> rank;
	vector<int> size;
	UnionFind(signed n){
		parent.reserve(n);
		rank.reserve(n);
		size.reserve(n);
		rep(i,n){
			parent[i]=i;
			rank[i]=0;
			size[i]=1;
		}
	}
	signed find(signed x){
		//keiroassyuku
		if(parent[x]==x){
			return x;
		}else{
			return parent[x]=find(parent[x]);
		}
	}
	void unite(signed x,signed y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(rank[x]<rank[y]){
			size[y]+=size[x];
			size[x]=size[y];
			parent[x]=y;
		}else{
			size[x]+=size[y];
			size[y]=size[x];
			parent[y]=x;
			if(rank[x]==rank[y])rank[x]++;
		}
	}
	bool same(signed x,signed y){return (find(x)==find(y));}
	int sizeis(int x){return size[find(x)];}
};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin>>n>>m;
	int c=n*(n-1)/2;
	UnionFind u(n);
	vector<pair<int,int> > v(m);
	rep(i,m)cin>>v[m-i-1].first>>v[m-i-1].second;
	vector<int> ans(m+1,0);
	ans[0]=c;
	rep(i,1,m+1){
		if(u.same(v[i-1].first-1,v[i-1].second-1)){
			ans[i]=ans[i-1];
		}else{
			ans[i]=ans[i-1]-u.sizeis(v[i-1].first-1)*u.sizeis(v[i-1].second-1);
			u.unite(v[i-1].first-1,v[i-1].second-1);
		}
	}

	rep(i,1,m+1)cout<<ans[m-i]<<endl;

	return 0;
}


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

int main() {
	long long N;
	cin >> N;
	long long ans = 0;
	long long K = 10;
	if (N % 2 == 1) cout << 0 << endl;
	else {
		while (K <= N) {
			ans += N / K;
			K *= 5;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
import collections
import math
 
def combinations_count(n, r):
  if n == r:
    return 1
  elif n < r:
    return 0
  else:
    return n * (n-1) // 2 
    #math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input().strip())
A = list(map(int, input().strip().split()))

combi = collections.Counter(A)
combi_count = {}
calc_dict = {}
total = 0
for k, v in combi.items():
  if v in calc_dict:
    combi_count[k] = calc_dict[v]
  else:
    combi_count[k] = combinations_count(v, 2)
    calc_dict[v] = combi_count[k]
  total += combi_count[k]

for i in range(N):
  ans = total - combi_count[A[i]] + combinations_count(combi[A[i]]-1, 2)
  print(ans)

Measured memory_bytes: 32156
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

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

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    int cnt = 0;
    REP(i, N - 1) {
        if (S[i + 1] == 'L' && S[i] == 'L') cnt++;
        if (S[i + 1] == 'R' && S[i] == 'R') cnt++;
    }

    int ans = min(N - 1, cnt + 2 * K);
    cout << ans << endl;
    return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a*b==15){
        cout << "*" << endl;
    }
    else if(a+b==15){
        cout << "+" << endl; 
    }
    else{
        cout << "x" << endl;
    }
    return 0;
}

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(void){
    int v[3];
    rep(i,3)cin>>v[i];
    sort(v,v+3);
    int a = (v[2]-v[0])/2;
    int b = (v[2]-v[1])/2;
    int cnt = a+b;
    v[0] += a*2;
    v[1] += b*2;
    sort(v,v+3);
    if(v[1]!=v[2])cnt++;
    else if(v[0]!=v[1])cnt += 2;
    cout<<cnt<<endl;
    return 0;
}


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

int main(void){
 
    char X,Y;
    cin >> X >> Y;
    
    if((int)X > (int)Y){
        cout << ">" <<endl;
    }
    else if((int)X == (int)Y){
        cout << "=" <<endl;
    }
    else{
        cout << "<" <<endl;
    }
}

Measured memory_bytes: 3596
S = str(input())

count = 0
X =[]
for n in range(len(S)):
    if n != len(S) -1:
        if S[n] == 'A' or S[n] == 'T' or S[n] == 'C' or S[n] == 'G':
            count += 1
        else:
            X.append(count)
            count = 0
    else:
        if S[n] == 'A' or S[n] == 'T' or S[n] == 'C' or S[n] == 'G':
            count += 1
            X.append(count)
        else:
            X.append(count)
print(int(max(X)))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#define rep(i,l,n) for(int i=l;i<n;i++)
typedef long long ll;

ll N,K,count=0ll;

int main(void){

    cin>>N>>K;
    if(K){
        rep(b,K+1,N+1){
            count+=(N/b)*max(0ll,b-K)+max(0ll,N%b-K+1);
        }
        cout<<count<<endl;
    }
    else{
        cout<<N*N<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    N, M, X = list(map(int, input().split()))
    C = []
    A = []
    for _ in range(N):
        L = list(map(int, input().split()))
        C.append(L[0])
        A.append(L[1:])

    ans = 10**5*13
    for flag in range(1 << N):
        cost = 0
        skill = [0] * M
        for i in range(N):
            if flag >> i & 1:
                cost += C[i]
                for j in range(M):
                    skill[j] += A[i][j]
        if all(sk >= X for sk in skill):
            ans = min(ans, cost)
    if ans == 10**5*13:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9228
#include<iostream>
#include<string>

#define endl '\n'

using namespace std;

const int MAXN=3e3+3,MOD=1e9+7;
int dp[MAXN][MAXN],prefix[MAXN][MAXN];

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

    int n;
    string signs;
    cin>>n>>signs;

    dp[1][1]=1;
    for(int len=2;len<=n;++len){
        for(int i=1;i<len;++i){
            prefix[len-1][i]=(prefix[len-1][i-1]+dp[len-1][i])%MOD;
        }
        for(int curr=1;curr<=len;++curr){
            int l,r;
            if(signs[len-2]=='>'){
                l=curr;
                r=len-1;
            }else{
                l=1;
                r=curr-1;
            }
            dp[len][curr]=(dp[len][curr]+(prefix[len-1][r]-prefix[len-1][l-1]+MOD)%MOD)%MOD;
        }
    }

    int res=0;
    for(int i=1;i<=n;++i){
        res=(res+dp[n][i])%MOD;
    }
    cout<<res<<endl;
return 0;
}

Measured memory_bytes: 69376
use std::cmp::{max, min};
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<u64>();
    println!("{}", ((n - 1) * n) / 2)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define REP(i,x) for(ll i=0;i<(ll)(x);i++)

int main()
{
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    for(auto it=S.begin(); it!= S.end(); it++)
    {
        *it = 'x';
    }

    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256