akhauriyash/Code-Regression huggingface dataset:
# 064 B

N = int(input())
A=[int(j) for j in input().split()]
A =list(set(A))
A.sort(reverse=True)
ans = 0
for i,j in enumerate(A):
    if i !=len(A)-1:
        ans += A[i] - A[i+1]
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>

#define int long long
#define rr register

#define MAXN 1010
#define MAXM 10010
#define inf 1e18

using namespace std;

inline int read() {
	int s = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) {f |= ch == '-'; ch = getchar();}
	while (isdigit(ch)) {s = s * 10 + (ch ^ 48); ch = getchar();}
	return f ? -s : s;
}

signed main() {
    string s;
    cin >> s;
    if (s == "ABC")
    cout << "ARC\n";   
    if (s == "ARC")
    cout << "ABC\n";   
}

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

int main()
{
    ll N,A,B;
    cin >> N >> A >> B;

    ll count = N / (A + B);
    ll remain = N % (A + B);

    if(remain >= A)remain = A;
    
    cout << A * count + remain << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i, h) cin >> g[i];

    mat dist(h, vec(w, INF));
    queue<P> que;
    
    rep(i, h) rep(j, w) {
        if (g[i][j] == '#') {
            dist[i][j] = 0;
            que.push({i, j});
        }
    }

    while (!que.empty()) {
        auto fr = que.front();
        que.pop();

        rep(i, 4) {
            int ty = fr.first + dy[i];
            int tx = fr.second + dx[i];

            if (ty >= 0 && ty < h && tx >= 0 && tx < w) {
                if (g[ty][tx] == '.' && dist[ty][tx] > dist[fr.first][fr.second] + 1) {
                    dist[ty][tx] = dist[fr.first][fr.second] + 1;
                    que.push({ty, tx});
                }
            }
        }
    }

    int mx = 0;

    rep(i, h) rep(j, w) mx = max(mx, dist[i][j]);
    cout << mx << endl;
    return 0;
}

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

// Description: ????????????
// Verifyed: various problem 
using namespace placeholders;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P c;R r;};

#define at(a,i) (a[(i + a.size()) % a.size()])

auto& operator >> (istream& is,P& p){ R x,y; is >> x >> y,p=P(x,y); return is;}
auto& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline P vec(L l){return l.t-l.s;}
auto sdot = bind(sgn,bind(dot,_1,_2,_3));
auto sdet = bind(sgn,bind(det,_1,_2,_3));

//projection verify AOJ CGL_1_A
P proj(L l,P p){ R u=real((p-l.s)/vec(l)); return (1-u)*l.s+u*l.t;}

/*
// closest point pair Verify AOJ CGL_5_A
R cpp(VP a,int flag = 1){
	
	
	VP e;

	rep(i,n){
        if(abs(real(a[i])-x)>=d) continue;   
        rep(_j,e.size()){
            const
            if(imag(a[i]-e[j])>=d) break;
            chmin(d,abs(a[i]-e[j]));
        }
        e.emplace_back(a[i]);
    }
	for(auto &p:a){
		if(abs(real(p)-x)>=d) continue;	
		rep(j,e.size())){
			P q = at(pol,-j);
			if(imag(p-q)>=d) break;
			d = min(d,abs(p-q));
		}
		e.push_back(p);
	return d;
}
*/

// closest point pair Verify AOJ CGL_5_A
R cpp(VP a,int flag=1){
	const int n=a.size(),m=n/2;
	if(n<=1) return INF;
	
	auto cmp_x=[](P a,P b)->bool{
		int sr = sgn(real(a-b)), si = sgn(imag(a-b));
		return sr ? sr < 0 :si < 0;
	};

	if(flag) sort(begin(a),end(a),cmp_x);
	
	VP b(begin(a),begin(a)+m),c(begin(a)+m,end(a));
	R x=real(a[m]),d=min(cpp(b,0),cpp(c,0));
	

	auto cmp_y=[](P a,P b)->bool{
		int sr = sgn(real(a-b)), si = sgn(imag(a-b));
		return si ? si < 0 :sr < 0;
	};

	sort(begin(a),end(a),cmp_y);
	deque<P> e;

	for(auto &p:a){
		if(abs(real(p)-x)>=d) continue;	
		
		for(auto &q:e){
			if(imag(p-q)>=d) break;
			d=min(d,abs(p-q));
		}
		e.push_front(p);
	}
	return d;
}

int main(void){
	int n;
	cin >> n;
	VP pol;
	rep(i,n){
		P p;
		cin >> p;
		pol.push_back(p);
	}
	cout.precision(20);
	cout << fixed << cpp(pol) << endl;
	return 0;
}

Measured memory_bytes: 21876
#include<bits/stdc++.h>
#define N 505
using namespace std;
int n,m; char A[N][N],B[N][N],C[N][N];
int main()
{
	int i,j;
	scanf("%d %d\n",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%s",A[i]+1);
		for(j=1;j<=m;j++)
			B[i][j]=C[i][j]='.';
	  }
	for(i=1;i<=n;i++){
		B[i][1]=C[i][m]='#';
		if(i&1){
			for(j=2;j<m;j++)
				B[i][j]='#';
		  }
		else{
			for(j=2;j<m;j++)
				C[i][j]='#';
		  }
	  }
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			if(A[i][j]=='#')
				B[i][j]=C[i][j]='#';
	for(i=1;i<=n;i++)
		printf("%s\n",B[i]+1);
	printf("\n");
	for(i=1;i<=n;i++)
		printf("%s\n",C[i]+1);
	return 0;
}


Measured memory_bytes: 1536
n, m = map(int, input().split())
gr = {}
edge = []
wt = {}
for v in range(1, n + 1):
    gr[v] = []
for _ in range(m):
    a, b, c = map(int, input().split())
    gr[a].append(b)
    edge.append((a, b))
    wt[(a, b)] = c
costs = [-1e15 for _ in range(n + 1)]
costs[1] = 0

for i in range(m):
    for u, v in edge:
        if costs[v] < costs[u] + wt[(u, v)]:
            costs[v] = costs[u] + wt[(u, v)]
tmp = costs[n]
for i in range(m):
    for u, v in edge:
        if costs[v] < costs[u] + wt[(u, v)]:
            costs[v] = costs[u] + wt[(u, v)]
if tmp < costs[n]:
    print('inf')
else:
    print(costs[n])

Measured memory_bytes: 48856
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstring>
#include <cctype>
#include <ctime>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <tuple>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <complex>
#include <random>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <functional>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#ifndef M_PI
#define M_PI 3.141592653589793238462643383279
#endif

#define int long long

#define mp make_pair
#define mt make_tuple
#define fr first
#define sc second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
#define get0 get<0>
#define get1 get<1>
#define get2 get<2>
#define get3 get<3>

#define debug(x) cerr << #x << " = " << x << ", line = " << __LINE__ << endl

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef tuple<long long, long long, long long> tlll;
typedef tuple<int, int, int> tiii;
typedef tuple<int, int, int, int> tiiii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MOD = 1e9 + 7;

int pw(int v, int n) {
    int cur = 1;
    for (int i = 0; i < n; ++i) {
        cur = cur * v % MOD;
    }
    return cur;
}


int32_t main()
{
#ifdef chikibambony
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif

    int n;
    cin >> n;

    cout << (pw(10, n) + MOD + MOD + MOD - 2 * pw(9, n) + pw(8, n)) % MOD;



    return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;

const int INF = 1e9 + 5;

int main() {

	int n; cin >> n;
	vector < int > h(n);
	for(int i = 0; i < n; ++i) cin >> h[i];
	vector < int > dp(n, INF);
	dp[0] = 0;
	for(int i = 0; i < n; ++i) {
		for(int j : {i + 1, i + 2}) {
			if(j < n) 
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
		}
	}

	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define se second
#define fi first
ll a,b,h,w,ans,to,r,c,jarak;
char cc;
bool bb[1010][1010];
using namespace std;

int main(){
    cin>>h>>w;
    queue<pair<ll, pair <ll, ll> > > q;
    
    for (int i=1; i<=h; i++){
        for (int j=1; j<=w; j++){
            cin>>cc;
            if (cc=='#'){
                bb[i][j]=1;
                q.push(mp(0,mp(i,j)));
            }
            else bb[i][j]=0;
        }
    }
    
    while (!q.empty()){
        r=q.front().se.fi;
        c=q.front().se.se;
        jarak=q.front().fi;
        q.pop();
        
		if (jarak!=0 && (r<1 || r>h || c<1 || c>w || bb[r][c])) continue;
        
		ans=jarak;
        bb[r][c]=1;
        q.push(mp(jarak+1,mp(r+1,c)));
        q.push(mp(jarak+1,mp(r-1,c)));
        q.push(mp(jarak+1,mp(r,c+1)));
        q.push(mp(jarak+1,mp(r,c-1)));
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 98488
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i;
  i=0;
  int a;
  cin >> a;
  
  if(a>99)
    i++;
  
  if(a/10%10==1)
    i++;
  
  if(a%10==1)
    i++;
  
  cout << i;
  
}

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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	// freopen("in.txt", "r", stdin);
	string s;
	cin >> s;
	if(s[0] != 'A'){
		cout << "WA" << endl;
		return 0;
	}
	if((s[1] >= 'A' && s[1] <= 'Z') || (s[s.length()-1] >= 'A' && s[s.length()-1] <= 'Z')){
		cout << "WA" << endl;
		return 0;
	}
	int cnt = 0;
	for(int i=2; i<s.length()-1; i++){
		if(s[i] == 'C') cnt++;
		if(cnt == 2 || (s[i] != 'C' && s[i] >= 'A' && s[i] <= 'Z')){
			cout << "WA" << endl;
			return 0;
		}
	}
	if(cnt)
		cout << "AC" << endl;
	else
		cout << "WA" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define endl "\n"
// const int N=2e5+10;


void solve()
{
    int ans;
    f(i,0,5)
    {
        int x;
        cin>>x;
        if(x==0)
        ans=i;
    }
    cout<<ans+1<<endl;


}


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--) 
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3604
def main():
    S = input()
    
    mod = 10**9 + 7
    Ans = [[0,0,0,0,0]]
    import copy
    q = 1
    
    S = S[::-1]
    for i in range(len(S)):
        tmp = copy.deepcopy(Ans[i])
        if S[i] == "C":
            tmp[2] += q
            Ans.append(tmp)
        elif S[i] == "B":
            tmp[1] += q
            tmp[3] += tmp[2]
            tmp[3] %= mod
            Ans.append(tmp)
        elif S[i] == "A":
            tmp[0] += q
            tmp[4] += tmp[3]
            tmp[4] %= mod
            Ans.append(tmp)
        elif S[i] == "?":
            a,b,c,bc,abc = tmp
            Ans.append([(3*a+q)%mod, (3*b+q)%mod, (3*c+q)%mod, (3*bc+c)%mod, (3*abc+bc)%mod])
            q *= 3
            q %= mod
            
    print(Ans[-1][-1])
    
    
main()

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

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

    int ans = 0;
    if (k % 2 == 0)
        ans = k / 2 * k / 2;
    else
        ans = k / 2 * (k - k / 2);

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


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


int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n, k, temp;
    cin >> n >> k;
    lli sum = 0;
    for(int i = 0 ; i < k ; i++) {
        cin >> temp;
        sum += temp;
    }
    if(sum > n) cout << -1 << endl;
    else cout << n - sum << endl;
    return 0;
}

Measured memory_bytes: 3656
import java.util.HashMap;
import java.util.Scanner;
public class Main {
    Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
        new Main();
    }
    public Main() {
        new AOJ0029();
    }

    class AOJ0029{
        public AOJ0029() {
            String input[] = in.nextLine().split(" ");
            HashMap<String,Integer> map = new HashMap<String, Integer>();
            int max = Integer.MIN_VALUE;
            int result_index = 0;
            for(int i=0;i<input.length;i++){
                if(max<input[i].length()){
                    max = input[i].length();
                    result_index = i;
                }
                if(!map.containsKey(input[i]))map.put(input[i], 0);
                map.put(input[i], map.remove(input[i])+1);
            }
            max = Integer.MIN_VALUE;
            String result2 = "";
            for(String key:map.keySet()){
                if(max<map.get(key)){
                    result2 = key;
                    max = map.get(key);
                }
            }
            System.out.println(result2+" "+input[result_index]);
        }
    }
}

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

int main()
{
  int n,m,i,j;
  int mat[100][100],vec[100];
  int ans[100]={0};

  cin>>n>>m;
  for(i=0;i<n;i++)
    for(j=0;j<m;j++)
      cin>>mat[i][j];
  for(i=0;i<m;i++)
    cin>>vec[i];
  for(i=0;i<n;i++)
    for(j=0;j<m;j++)
      ans[i]+=mat[i][j]*vec[j];
  for(i=0;i<n;i++)
    cout<<ans[i]<<endl;
}


Measured memory_bytes: 1200
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int c,p;
int main()
{
	int h=0,n=0;
	scanf("%d%d",&h,&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&c);
		p+=c;
	}
	if(p>=h) printf("Yes");
	else printf("No");
	return 0;
 } 

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e7
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int N){
    vector<int>S;
    rep(i,N)if(bit & (1<<i))S.push_back(i);
    return S;
}

int main(){
    ll a,b,c;cin>>a>>b>>c;
    ll res;
    if(b>c)res = b+c;
    else {
        res = 2*b;
        c-=b;
        if(a>=c)res += c;
        else res += a+1;
    }
    cout<<res;
}



Measured memory_bytes: 256
import Data.Char (toLower)

initCharSet :: [(Char, Int)]
initCharSet = [(x, 0) | x <- ['a'..'z']]

incCharCount :: [(Char, Int)] -> Char -> [(Char, Int)]
incCharCount [] ch = []
incCharCount (x@(ch', n):xs) ch
  | toLower ch == ch' = (ch', n+1):xs
  | otherwise         = x:(incCharCount xs ch)

countChars :: String -> [(Char, Int)]
countChars = foldl incCharCount initCharSet

main :: IO ()
main = getContents >>= mapM_ (\(ch, n) -> putStrLn $ ch:" : " ++ show n) . countChars


Measured memory_bytes: 4128
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,q;
string s;
vector<pair<char,bool> >a;
main()
{
	cin>>n>>q>>s;
	for(int i=0;i<q;i++)
	{
		char t,d;cin>>t>>d;
		a.push_back(make_pair(t,d=='R'));
	}
	int L=0;
	for(int i=q;L<n&&i--;)
	{
		if(a[i].second)
		{
			if(L>0&&a[i].first==s[L-1])
			{
				L--;
			}
		}
		else
		{
			if(a[i].first==s[L])L++;
		}
	}
	L--;
	int R=n-1;
	for(int i=q;R>=0&&i--;)
	{
		if(a[i].second)
		{
			if(a[i].first==s[R])R--;
		}
		else
		{
			if(R<n-1&&a[i].first==s[R+1])
			{
				R++;
			}
		}
	}
	R++;
	cout<<max(0,n-L-1-(n-R))<<endl;
}

Measured memory_bytes: 1024
n, m, x = map(int, input().split())
dat = []
gold = []
for i in range(n):
    l = list(map(int, input().split()))
    gold.append(l[0])
    dat.append(l[1:])
inf = 99999999999999999999
minval = inf
for pat in range(2 ** n):
    tmp = [0] * m
    cost = 0
    for i in range(n):
        if (pat >> i & 1) == 1:
            cost += gold[i]
            for j in range(m):
                tmp[j] += dat[i][j]
    can = True
    for i in range(m):
        if tmp[i] < x:
            can = False
            break
    if can is False:
        continue
    minval = min(minval, cost)

if minval == inf:
    print(-1)
else:
    print(minval)




Measured memory_bytes: 9240
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,m,v,p;
  cin >> n >> m >> v >> p;
  vector<ll> a(n);
  ll l = -1,r=n,h;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end(),greater<ll>());
  while(r-l>1){
    h = (r+l)/2;
    ll sum = 0,val=a[h]+m;
    for(int i=0;i<n;i++){
      if(i<p-1||i>=h){
        sum += m;
      }else{
        sum += max(0ll,val-a[i]);
      }
    }
    if((h<p-1)||((a[h]+m>=a[p-1])&&(sum>=m*v))){
      l = h;
    }else{
      r = h;
    }
  }
  cout << l+1<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main()
{int s ,a[10],i,j,q;
while(~scanf("%d",&s))
  {q=0;
  for(i=0;i<3;i++)
    if(s>=10)
	{
     a[i]=s%10;
     s/=10;
    }
    a[i]=s;
    for(i=0;i<3;i++)
      
      if(a[i]==a[i+1])
      {printf("Bad\n");
      q=1;
      break;
      }
      if(q==0)printf("Good\n");
  }
} 

Measured memory_bytes: 760
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<cmath>
#include<cstdlib>
#include<utility>
#include<queue>
#include<ctime>
#include<string>
#include<string.h>
#include<cstring>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<functional>
#include<cassert>
#include<complex>
#include<deque>
#include<stdio.h>
using namespace std;
int main()
{
	long long a[100]={0},n;
	a[0]=2;
	a[1]=1;
	cin>>n;
	for (int i=2;i<=n;i++) a[i]=a[i-1]+a[i-2];
	cout<<a[n];
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
const int K = 1050;
int A[2][K][K];
char s[5];
inline int Sum(int c, int x1, int y1, int x2, int y2) {
  if (x1 > x2 || y1 > y2) return 0;
  return A[c][x2][y2] - A[c][x1 - 1][y2] - A[c][x2][y1 - 1] + A[c][x1 - 1][y1 - 1];
}
int main() {
  int n, k, x, y;
  scanf("%d%d", &n, &k);
  while (n--) {
    scanf("%d%d%s", &x, &y, s);
    ++A[((*s == 'W') ^ (x / k) ^ (y / k)) & 1][x % k + 1][y % k + 1];
  }
  for (int c = 0; c < 2; ++c)
    for (int i = 1; i <= k; ++i)
      for (int j = 1; j <= k; ++j)
        A[c][i][j] += A[c][i - 1][j] + A[c][i][j - 1] - A[c][i - 1][j - 1];
  int ans = 0;
  for (int i = 1; i <= k; ++i)
    for (int j = 1; j <= k; ++j)
      ans = std::max(ans, Sum(0, i, j, k, k) + Sum(0, 1, 1, i - 1, j - 1) + 
                          Sum(1, i, 1, k, j - 1) + Sum(1, 1, j, i - 1, k));
  for (int i = 1; i <= k; ++i)
    for (int j = 1; j <= k; ++j)
      ans = std::max(ans, Sum(1, i, j, k, k) + Sum(1, 1, 1, i - 1, j - 1) + 
                          Sum(0, i, 1, k, j - 1) + Sum(0, 1, j, i - 1, k));
  return printf("%d\n", ans) & 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N;
    cin >> N;
    int ans = 0;
    int M = N;
    for(int i=2;i*i<=N;i++){
        int num = 1;
        int cnt = 0;
        while(M % i == 0){
            M /= i;
            cnt++;
            if(cnt == num){
                ++ans;
                num++;
                cnt = 0;
            }
        }
    }
    if(M != 1) ++ans;
    cout << ans << endl;
}

Measured memory_bytes: 3640
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
    def find(self, x):
        """
        x が属するグループを探索して親を出す。
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]

from heapq import heapify, heappop, heappush
N = int(input())
X = [];Y = []
for i in range(N):
  a,b = map(int,input().split())
  X.append((a,b,i))
  Y.append((a,b,i))
X.sort(key=lambda x:x[0])
Y.sort(key=lambda x:x[1])
#print(X,Y)
PQ = []
for i in range(N-1):
  difx = (X[i+1][0]-X[i][0],X[i][2],X[i+1][2])
  dify = (Y[i+1][1]-Y[i][1],Y[i][2],Y[i+1][2])
  #print(difx,dify)
  heappush(PQ,difx);heappush(PQ,dify)
uf = UnionFind(N)
ans = 0
while PQ:
  dis,a,b = heappop(PQ)
  if uf.is_same(a, b):
    continue
  ans += dis
  uf.union(a,b)
print(ans)


Measured memory_bytes: 150620
#include <stdio.h>

int main() {
    int a, b;
    int i, j;
    while (1) {
        scanf("%d %d", &a, &b);
        if (a==0 && b==0) {
            break;
        }
        for ( i = 0; i < a; i++ ){
            for ( j = 0; j < b; j++ ){
                if (i%2==0) {
                    if (j%2==0) {
                        printf("#");
                    }else{
                        printf(".");
                    }
                 }else{
                     if (j%2==0) {
                         printf(".");
                     }else{
                         printf("#");
                     }
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

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


int main(){
    
    int h, w;
    cin >> h >> w;
    int start_x, start_y, end_x, end_y;
    cin >> start_x >> start_y >> end_x >> end_y;
    
    start_x--;
    start_y--;
    end_x--;
    end_y--;
    
    vector<string>a(h);
    for(int i = 0; i < h; i++){
        cin >> a[i];
    }
    
    auto f = [&](int i, int j){
        if (i >= 0 && i < h && j >= 0 && j < w && a[i][j] == '.'){
            return true;
        }else{
            return false;
        }
    };
    
    vector<vector<int>>dist(h, vector<int>(w, 1e+9));
    set<pair<int, pair<int, int>>>s;
    dist[start_x][start_y] = 0;
    
    vector<int>dx = {-1, 1, 0, 0};
    vector<int>dy = {0, 0, -1, 1}; 
    
    s.insert({0, {start_x, start_y}});
    while(!s.empty()){
        int cur_x = (s.begin()->second).first;
        int cur_y = (s.begin()->second).second;
        s.erase(s.begin());
        int cur_value = dist[cur_x][cur_y];  
        for(int i = 0; i < 4; i++){ 
            
            int n_x = cur_x + dx[i];
            int n_y = cur_y + dy[i];
            
            if(!f(n_x, n_y))continue;
            if(dist[n_x][n_y] > cur_value){
                s.erase(make_pair(dist[n_x][n_y], make_pair(n_x, n_y)));
                dist[n_x][n_y] = cur_value;
                s.insert({cur_value, {n_x, n_y}});
            }
        }
        
        for(auto i : {-2, -1, 0, 1, 2}){
            for(auto j : {-2, -1, 0, 1, 2}){
                int n_x = cur_x + i;
                int n_y = cur_y + j;
                
                if(!f(n_x, n_y))continue;
                if(dist[n_x][n_y] > cur_value + 1){
                    s.erase({dist[n_x][n_y], {n_x, n_y}});
                    dist[n_x][n_y] = cur_value + 1;
                    s.insert({cur_value +1, {n_x, n_y}});
                }
                
            }
        }
          
    }
    
    if(dist[end_x][end_y] > 1e+7){
        cout << -1 << endl;
    }else{
        cout << dist[end_x][end_y] << endl;
    }
}


Measured memory_bytes: 9632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void readi(ll &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(ll x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
struct matrix{
	int h,w;
	ll a[51][51];
};
matrix mymul(matrix A,matrix B){
	matrix C;
	C.h=A.h,C.w=B.w;
	for(int i=0;i<C.h;i++)for(int j=0;j<C.w;j++){
		C.a[i][j]=0;
		for(int k=0;k<A.w;k++)
			C.a[i][j]=(C.a[i][j]+A.a[i][k]*B.a[k][j])%MOD;
	}
	return C;
}
int g[53][53];
int n;
ll k;
matrix mypow(ll x){
	matrix res,ans;
	ans.h=n,ans.w=n;
	res.h=n,res.w=n;
	for (int i=0;i<ans.h;i++)for (int j=0;j<ans.w;j++) ans.a[i][j]=g[i][j],res.a[i][j]=0;
	for (int i=0;i<res.h;i++) res.a[i][i]=1;
	while (x){
		if(x%2==1){
			x--;
			res=mymul(res,ans);
			continue;
		}
		x/=2;
		ans=mymul(ans,ans);
	} 
	return res;
}
int main(){
	read(n),readi(k);
	matrix f_;f_.h=n,f_.w=1;
	for (int i=0;i<n;f_.a[i][0]=1,i++) for (int j=0;j<n;j++) read(g[i][j]);
	matrix ans_=mymul(mypow(k),f_);
	ll ans=0;
	for (int i=0;i<n;i++) ans+=ans_.a[i][0];
	write(ans%MOD);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int n,k,f[100010],a[101];
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	f[0]=1; 
	for(int i=1;i<=k;i++)
	{
		int cnt=0;
		for(int j=0;j<n;j++)
			if(i-a[j]>=0 && f[i-a[j]])
				cnt=1;
		if(!cnt)
			f[i]=1;
		else
			f[i]=0;
	}
	if(!f[k])
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
	return 0;
}


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

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a); i >= (b); i--)
#define ALL(container) (container).begin(), (container).end()

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

const int INF = 1e9;

vector<string> split(const string &str, char sep) {
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while(getline(ss, buffer, sep)) {
    v.push_back(buffer);
  }
  return v;
}

int main() {
  string S;
  cin >> S;

  vector<string> v = split(S, '/');
  int y = stoi(v[0]);
  int m = stoi(v[1]);
  int d = stoi(v[2]);
  if (y < 2019 || (y == 2019 && m <= 4)) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
  return 0;
}


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

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define INF 1000000000000000000
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define x first 
#define y second
const int maxx = 1000006;
const int maxlog = 20;
const ll mod = 1000000007;
int arr[maxx];

int main() {
    IOS
    int N, M;
    cin >> N >> M;
    int arr[M];
    int brr[M];
    for (int i = 0; i < M; i++) brr[i] = 0;
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        arr[i] = a;
        for (int j = 0; j < b; j++) {
            int e; cin >> e;
            e--;
            brr[i] |= (1 << e);
        }
    }
    int dp[(1 << N) + 2];
    for (int i = 0; i < (1 << N); i++) dp[i] = mod;
    dp[0] = 0;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < (1 << N); j++) {
            dp[j | brr[i]] = min(dp[j | brr[i]], dp[j] + arr[i]);
        }
    }
    cout << (dp[(1 << N) - 1] == mod ? -1 : dp[(1 << N) - 1]);
}


Measured memory_bytes: 256
from collections import deque
import sys
input=sys.stdin.readline
s=deque([input().rstrip()])
q=int(input())
rev=0
for _ in range(q):
	qw=input().split()
	if qw[0]=="1":
		rev+=1
	else:
		f=qw[1]
		c=qw[2]
		if f=="1":
			if rev%2==0:
				s.appendleft(c)
			else:
				s.append(c)
		else:
			if rev%2==0:
				s.append(c)
			else:
				s.appendleft(c)
ans=""
for x in s:
	ans+=x
if rev%2==0:
	print(ans)
else:
	print(ans[::-1])



Measured memory_bytes: 6184
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
 ll N;
 cin>>N;
 ll A=0;
 ll W=0;
 ll T=0;
 ll R=0;
 
 for(ll i=0;i<N;i++){
   string s;
   cin>>s;
   if(s[0]=='A')A++;
   if(s[0]=='W')W++;
   if(s[0]=='T')T++;
   if(s[0]=='R')R++;
   
 }
cout<<"AC x "<<A<<endl;
cout<<"WA x "<<W<<endl;
cout<<"TLE x "<<T<<endl;
cout<<"RE x "<<R<<endl;

 
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n, m;
    cin >> n >> m;

    vector<lint> a(n);
    rep(i, n){
        cin >> a[i];
    }

    vector< LLP > v;
    rep(i, m){
        lint b, c;
        cin >> b >> c;
        v.emplace_back(c, b);
    }

    SORT(a);
    SORT(v);

    int j = m - 1, k = 0;
    while(k < n && j >= 0){
        int cnt = 0;
        while(cnt < v[j].second && k < n && a[k] < v[j].first){
            a[k] = v[j].first;
            ++cnt;
            ++k;
        }
        --j;
    }

    lint ans = 0;
    rep(i, n){
        ans += a[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  std::string s;
  Solver() {
    S002 r;
    r >= s;
  }
  void solve() {
    s[5] = ' ';
    s[5 + 1 + 7] = ' ';
    printf("%s\n", s.c_str());
  }
};
 
int main() {
  for(;;) std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long countMax = sc.nextLong();
		long array[] = new long[num];
		long sorted[][] = new long[num][2];
		for(int i = 0; i < num; i ++) {
			array[i] = sc.nextLong();
			sorted[i][0] = array[i];
			sorted[i][1] = i;
		}
		Arrays.sort(sorted, (a, b) -> Long.compare(a[0], b[0]));
		int next[] = new int[num];
		int prv = (int)sorted[0][1];
		for(int i = 1; i < num; i ++) {
			if(sorted[i][0] == sorted[i - 1][0]) {
				next[(int)sorted[i - 1][1]] = (int)sorted[i][1];
			}else {
				next[(int)sorted[i - 1][1]] = prv;
				prv = (int)sorted[i][1];
			}
		}
		next[(int)sorted[num - 1][1]] = prv;

		int count = 1;
		int tmpIndex = 0;
		int lastIndex[] = new int[num];
		while(tmpIndex != num) {
			if(next[tmpIndex] <= tmpIndex) {
				lastIndex[count - 1] = tmpIndex;
				count ++;
			}
			tmpIndex = next[tmpIndex] + 1;
		}
		countMax = (countMax - 1) % count;
		if(countMax == count - 1) {
			System.out.println(); return;
		}

		StringBuilder ans = new StringBuilder();
		tmpIndex = lastIndex[(int)countMax];
		while(tmpIndex < num) {
			if(next[tmpIndex] <= tmpIndex) {
				ans.append(array[tmpIndex]+" ");
				tmpIndex ++;
			}else {
				tmpIndex = next[tmpIndex] + 1;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 101016
import copy

array_to_str = lambda A: ' '.join([str(a) for a in A])
input_number = lambda: int(input())
input_num_array = lambda: [int(a) for a in input().split()]
input_array = lambda: input().split()

def bubble_sort(C, A, N):
  flag = 1
  while flag:
    flag = 0
    for j in range(N)[:0:-1]:
      if A[j] < A[j-1]:
        A[j],A[j-1] = A[j-1], A[j]
        C[j],C[j-1] = C[j-1], C[j]
        flag = 1
  print(' '.join(C))
  print('Stable')

def selection_sort(C, A, N):
  stability = True
  for i in range(N):
    minj = i
    for j in range(i,N):
      if A[j] < A[minj]:
        minj = j

    # if i > minj and A[minj] == A[i]:
    #   stability = not stability

    C[i], C[minj] = C[minj], C[i]
    A[i], A[minj] = A[minj], A[i]
        
  print(' '.join(C))
  # print('Stable' if stability else 'Not stable')

N = input_number()
C = input_array()
A = [int(c[1]) for c in C]
A_copy = copy.copy(A)
C_copy = copy.copy(C)
bubble_sort(C_copy, A_copy, N)
selection_sort(C, A, N)
print('Stable' if C == C_copy else 'Not stable')


Measured memory_bytes: 6348
#include<iostream>
#include<string>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>

//#include"gap.h"

using namespace std;

const int int_max = 2147483647;


int N, Q, MaxN = 1;
vector<int> seg, lazy;
vector<bool> flag;

void solve(int k, int l, int r){
	if(flag[k]){

		seg[k] = lazy[k];

		if(r - l > 1){
			lazy[2*k+1] = lazy[k];
			flag[2*k+1] = true;
			lazy[2*k+2] = lazy[k];
			flag[2*k+2] = true;
		}

		flag[k] = false;
	}
}

void update(int s, int t, int x, int k, int l, int r){
	solve(k, l , r);

	if(r <= s || t <= l) return;
	if(s <= l && r <= t){
		lazy[k] = x;
		flag[k] = true;
		solve(k, l, r);
	}
	else{
		update(s, t, x, 2*k+1, l, (l+r)/2);
		update(s, t, x, 2*k+2, (l+r)/2, r);

		seg[k] = min(seg[2*k+1], seg[2*k+2]);
	}
}

int find(int s, int t, int k, int l, int r){
	solve(k, l, r);

	if(r <= s || t <= l) return int_max;

	solve(k, l, r);
	if(s <= l && r <= t){
		return seg[k];
	}
	else{
		int vl = find(s, t, 2*k+1, l, (l+r)/2);
		int vr = find(s, t, 2*k+2, (l+r)/2, r);

		return min(vl, vr);
	}
}

int main(){
	cin >> N >> Q;

	while (N > MaxN)
	{
		MaxN *= 2;
	}

	seg.resize(MaxN*2-1, int_max);
	lazy.resize(MaxN*2-1, int_max);
	flag.resize(MaxN*2-1, false);

	for(int i=0; i<Q; i++){
		int com, s, t, x;
		cin >> com;

		if(com == 0){
			cin >> s >> t >> x;
			update(s, t+1, x, 0, 0, MaxN);
		}
		if(com == 1){
			cin >> s >> t;
			cout << find(s, t+1, 0, 0, MaxN) << endl;
		}

	}


	return 0;
}



Measured memory_bytes: 4872
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
int main(){
	double n,d;
	cin>>n>>d;
	int nax=0;
	while(n--){
		double x,y;
		cin>>x>>y;
		double ans=sqrt(x*x+y*y);
		if(ans<=d)
		 nax++;}
		 cout<<nax<<endl;}

Measured memory_bytes: 3840
let () = Scanf.scanf "%d\n" @@ fun n ->
  let abs = Array.init n @@ fun _ -> Scanf.scanf "%d %d\n" @@ fun a b -> a, b in
  Array.sort (fun (a, b) (a', b') -> compare (a' + b') (a + b)) abs;
  Printf.printf "%d\n" @@ Array.fold_left ( + ) 0 @@ Array.init n @@ fun i ->
    if i mod 2 = 0 then fst abs.(i) else ~- (snd abs.(i))
    



Measured memory_bytes: 7040
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
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;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

class union_find {
private:
	int par[114514], rank[114514], size[114514];
public:
	void init(int n) {
		rep(i, n) {
			par[i] = i;
			rank[i] = 0;
			size[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	int siz(int x) {
		return size[find(x)];
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y]) {
			par[x] = y;
			size[y] = size[x] + size[y];
		}
		else {
			if (rank[x] == rank[y])rank[x]++;
			par[y] = x;
			size[x] = size[x] + size[y];
		}
	}
	bool same(int x, int y) {
		x = find(x);
		y = find(y);
		return x == y;
	}
};

int n, m, a[114514], b[114514];
int ans[114514];

signed main() {
	cin >> n >> m;
	union_find ta;
	ta.init(n + 1);
	rep(i, m)cin >> a[i] >> b[i];
	reverse(a, a + m);
	reverse(b, b + m);
	for (int i = 1; i <= m; i++) {
		if (ta.same(a[i-1], b[i-1]))ans[i] = ans[i - 1];
		else ans[i] = ans[i - 1] + ta.siz(a[i-1])*ta.siz(b[i-1]);
		ta.unite(a[i-1], b[i-1]);
	}
	for (int i = m; i >= 1; i--)cout << n * (n - 1) / 2 - ans[i-1] << endl;
}

Measured memory_bytes: 6272
import sys
H, W = list(map(int, input().split()))

if H == 1 or W == 1:
    print(1)
    sys.exit()

a = (W+1)//2
b = W//2
if H % 2 == 0:
    print((a+b)*H//2)
else:
    print(((a+b)*(H//2))+a)

Measured memory_bytes: 3068
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int a,b,c;
    while(cin >> a >> b >> c){
        if(a+b==c){
            cout << "Yes" << endl;
            continue;
        }
        if(a+c==b){
            cout << "Yes" << endl;
            continue;
        }
        if(b+c==a){
            cout << "Yes" << endl;
            continue;
        }
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
ll a, b;
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int Q;
	cin >> Q;
	while(Q--){
		cin >> a >> b;
		if(a==b){
			cout << (a-1)*2 << '\n';
			continue;
		}
		if(a > b)swap(a, b);
		ll v = sqrt(a * b);
		assert(v * v <= a * b and (v+1) * (v+1) > a * b);
		ll res = (a-1) << 1;
		if(v * (v+1) < a * b){
			res += (v-a) * 2;
		}
		else{
			res += max((v-a-1) * 2 + 1, 0ll);
			if(v*v == a*b)--res;
		}
		if(b-a > 1)++res;
		cout << res << '\n';
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    vector<int> a(5);
    rep(i, 5) cin >> a[i];
    int ans = 100000;
    do {
        int m = 0;
        rep(i, 5) {
            m += a[i];
            if (i==4) continue;
            if (m%10!=0) m += (10-m%10);
        }
        ans = min(ans, m);
    } while (next_permutation(a.begin(), a.end()));
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
ll dx[4]={0,-1,0,1};
ll dy[4]={1,0,-1,0};
/****************************/
ll h[300010],w[300010];
ll H,W,m;
map<pii,bool> m_p;
vector<int> vheight,vwidth;
bool cmp(int a,int b)
{
	return a>b;
}
ll maxh,maxw;
int main()
{
	cin>>H>>W>>m;
	rep(i,m)
	{
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		h[a]++;
		maxh=max(maxh,h[a]);
		w[b]++;
		maxw=max(maxw,w[b]);
		m_p[mp(a,b)]=1;
	}
	ll ans=maxh+maxw;
	rep(i,H)
	{
		if(h[i]==maxh)
		vheight.pb(i);
	}
	rep(i,W)
	{
		if(w[i]==maxw)
		vwidth.pb(i);
	}
	if(vheight.size()*vwidth.size()>m)
	{
		cout<<ans;
		return 0;
	}
	rep(i,vheight.size())
	{
		rep(j,vwidth.size())
		{
			if(!m_p[mp(vheight[i],vwidth[j])])
			{
				cout<<ans;
				return 0;
			}
		}
	}
	cout<<ans-1;
	return 0;
}

Measured memory_bytes: 30808
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
int main(){
    string s;
    cin>>s;
    int ans=1000;
    rep(i,0,s.size()-2){
        int a=stoi(s.substr(i,3));
        if(ans>abs(a-753))ans=abs(a-753);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int maxn=100000;

ll n,x;
ll p[51],sum[51];

ll cal(ll n,ll x){
    if(x==1){
        return (n>0)? 0:1;
    }else if(1<x&&x<2+sum[n-1]){
        return cal(n-1,x-1);
    }else if(x==2+sum[n-1]){
        return 1+p[n-1];
    }else if(2+sum[n-1]<x&&x<2*sum[n-1]+3){
        return p[n-1]+1+cal(n-1,x-2-sum[n-1]);
    }else if(x==2*sum[n-1]+3){
        return 2*p[n-1]+1;
    }
    
    return 0;
}

int main(){
    
    
    cin >> n>>x;
    p[0]=1;
    sum[0]=1;
    for(int i=1;i<=n;i++){
        p[i]=2*p[i-1]+1;
        sum[i]=sum[i-1]*2+3;
    }
    
    cout << cal(n,x)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
    int n,i;
    cin>>n;
    string s[n];
    ll ans=0;
    map<string ,int> mp;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
        mp[s[i]]++;
    }
    for(i=0;i<n;i++)
    {   if(mp[s[i]]>0)
        {ans+=(mp[s[i]]-1);
        mp[s[i]]--;}

        }
        cout<<ans<<e;
}


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

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

  if (a%500 == 0) {
    cout << "Yes" << endl;
  }
  else if (a%500 <= b) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}


Measured memory_bytes: 256