akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
struct point {
	ld x, y;
	point(ld X = 0, ld Y = 0) {
		x = X, y = Y;
	}
	point operator-(point a) {
		return point(x - a.x, y - a.y);
	}
	point operator+(point a) {
		return point(x + a.x, y + a.y);
	}
	ld len() {
		return sqrt(x * x + y * y);
	}
	ld operator^(point a) {
		return x * a.x + y * a.y;
	}
	ld operator*(point a) {
		return x * a.y - y * a.x;
	}
};

point nm(point a) {
	ld l = a.len();
	a.x /= l;
	a.y /= l;
	return a;
}

ld get(point a, point b, point c, ld r) {
	a = a - b;
	c = c - b;
	a = nm(a);
	c = nm(c);
	c = a + c;
	return abs(r * (a ^ c) / (a * c));
}

point pp[100];
ld c[100];


int main() {
	for (int i = 0; i < 3; ++i)
		cin >> pp[i].x >> pp[i].y;
	pp[3] = pp[0];
	pp[4] = pp[1];
	pp[5] = pp[2];
	for (int i = 1; i <= 4; ++i)
		c[i] = get(pp[i - 1], pp[i], pp[i + 1], 1);
	ld ans = 0;
	for (int i = 1; i <= 3; ++i)
		ans = max(ans, (pp[i + 1] - pp[i]).len() / (2 + c[i] + c[i + 1]));
	cout.setf(ios::fixed);
	cout.precision(20);
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n,c,cal=0;
  cin>>n>>c;
  vector<long> x(n+1),v(n+1),vtcw(n+1,0);
  vector<pair<long,long>> calcwmax(n+1,make_pair(0,0)),calccwmax(n+1,make_pair(0,0));
  x[0]=v[0]=0;
  for(long i=1;i<=n;++i)cin>>x[i]>>v[i];
  vtcw[0]=0;
  for(long i=1;i<=n;++i)vtcw[i]=v[i]+vtcw[i-1];
  auto vtccw = [&](long k){return k==0?0:vtcw[n]-vtcw[k-1];};
  calcwmax[0].second=vtcw[0]-x[0];
  for(long i=1;i<=n;++i){
    if(calcwmax[i-1].second<vtcw[i]-x[i])calcwmax[i]=make_pair(i,vtcw[i]-x[i]);
    else calcwmax[i]=calcwmax[i-1];
  }
  calccwmax[n]=make_pair(n,vtccw(n)-c+x[n]);
  for(long i=n-1;i>=0;--i){
    if(calccwmax[i+1].second<vtccw(i)-c+x[i])calccwmax[i]=make_pair(i,vtccw(i)-c+x[i]);
    else calccwmax[i]=calccwmax[i+1];
  }
  cal=calcwmax[n].second;
  for(long xbi=n;xbi>0;--xbi){
    long calt=calccwmax[xbi].second+calcwmax[xbi-1].second;
    cal=max(cal,calt-min(c-x[xbi],x[calcwmax[xbi-1].first]));
  }
  cout<<cal<<"\n";
  for(int i=0;i<=n;++i)cerr<<vtcw[i]<<endl;
  cerr<<endl;
  for(int i=n;i>=0;--i)cerr<<vtccw(i)<<endl;
  cerr<<endl;
  for(int i=0;i<=n;++i)cerr<<calcwmax[i].first<<" "<<calcwmax[i].second<<endl;
  cerr<<endl;
  for(int i=n;i>=0;--i)cerr<<calccwmax[i].first<<" "<<calccwmax[i].second<<endl;
  cerr<<endl;
  return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
char poi[1000000];
int main()
{
    //freopen("t5.in","r",stdin);
   //freopen("t5.out","w",stdout);
    int i,j,n,m;
    string x;
    cin>>x;
    int q;
    cin>>q;
    int cnt=0;
    int tou=499999,wei;
    memset(poi,0,sizeof(poi));
    for(i=500000;1;i++)
    {
        poi[i]=x[cnt];
        cnt++;
        if(cnt==x.size())break;
    }
    wei=i+1;
    int flag=0;
    while(q--)
    {
        int op;
        scanf("%d",&op);
        if(op==1)flag^=1;
        else{
            char ch;
            scanf("%d %c",&op,&ch);
            if((op+flag)%2)
            {
                poi[tou]=ch;
                tou--;
            }
            else
            {
                poi[wei]=ch;
                wei++;
            }
        }
    }
    if(!flag)
    {
        for(i=1;i<888888;i++)
        {
            if(poi[i])printf("%c",poi[i]);
        }
    }
    else
    {
        for(i=888888;i>=1;i--)
        {
            if(poi[i])printf("%c",poi[i]);
        }
    }
    puts("");
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;

    int h[N*10];
    for (int i=0; i<N; ++i) cin >> h[i];
    sort(h, h+N);
    
    int extract = h[N-1];
    for (int i=0; i<=N-K; ++i) {
        int tmp = h[K-1+i] - h[i];
        if (extract > tmp) extract = tmp;
    }

    cout << extract << endl;


    /*
    int extract1;
    int extract2;
    extract1 = h[K-1] - h[0];
    extract2 = h[N-1] -h[K];

    cout << min(extract1, extract2) << endl;
    */

    /*
    for (int i=0; i<K; ++i) {
        h[i]
    */

    return 0;
}




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

int main() {
    int n, m;
    cin >> n >> m;
    
    int res[n];
    bool check[n];
    
    rep(i, n){
        res[i] = 1e9;
        check[i] = false;
    }
    
    vector<vector<int> > v(n);
    
    rep(i, m){
        int a, b;
        cin >> a >> b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }
    
    queue<int> que;
    que.push(0);
    
    res[0] = 0;
    check[0] = true;
    
    while(!que.empty()){
        int room = que.front();
        que.pop();
        
        rep(i, (int)v[room].size()){
            if(!check[v[room][i]]){
                que.push(v[room][i]);
                check[v[room][i]] = true;
                res[v[room][i]] = room;
            }
        }
    }
    
    cout << "Yes" << endl;
    
    rep(i, n){
        if(i != 0) cout << res[i] + 1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int N,M;
vector<int> p[100000];
vector<pair<int, int> > vp;

int main(){
    int x,y;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        cin >> x >> y;
        vp.push_back(make_pair(x-1,y));
        p[x-1].push_back(y);
    }
    for(int i=0;i<N;i++) sort(p[i].begin(),p[i].end());
    for(int i=0;i<M;i++){
        cout << setfill('0') << right << setw(6) << (vp[i].first + 1);
        int q = lower_bound(p[vp[i].first].begin(),p[vp[i].first].end(),vp[i].second) - p[vp[i].first].begin();
        cout << setfill('0') << right << setw(6) << q+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 7796
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

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

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 998244353;

ll N;
int vis[1<<20], X, M;
vector<ll> A;

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 cin>>N>>X>>M;
 int j = 0;
 A.pb(X);
 vis[X]=1;
 j++;

 int aj = -1;
 while (1) {
   aj = (A[j-1]*A[j-1])%M;
   if(vis[aj]) {
     break;
   }
   A.pb(aj);
   j++;
   vis[aj]=1;
 }
 int i = 0;
 for(;i < j;i++) {
   if(A[i]==aj) break;
 }

 ll ans = 0;
 if(N <= i) {
   rep(k,N)ans+=A[k];
   cout<<ans;
   return 0;
 }

 rep(k,i)ans+=A[k];
 N -= i;
 ll tsum=0;
 for(int k = i;k<j;k++) tsum+=A[k];
 ans += (N/(j-i))*tsum;

 rep(k,N%(j-i)) ans+=A[i+k];
 cout<<ans;

 return 0;
}


Measured memory_bytes: 4268
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>

using namespace std;

int main(){
  int ans;
  int d[101] = {};
  int l[101] = {};
  int n,x;
  cin >> n >> x;
  cin >> l[0];
  int f = 0;
  for(int i = 1; i < n+1 ; i++){
    if(i != n)cin >> l[i];
    d[i] = d[i-1] + l[i-1];
    if(d[i] > x){
      ans = i;
      f = 1;
      break;
    }
  }
  if(!f) ans = n+1;
  cout << ans << endl;
}


Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N = int(input())
print(N**3)


Measured memory_bytes: 77484
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define orep(i, n) for (int i = 1; i < (int)(n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
  int n;
  string s;
  cin >> n >> s;
  bool flag = true;
  if (n % 2) {
    flag = false;
  } else {
    for (int i = 0; i < n / 2; i++) {
      if (s[i] != s[n / 2 + i]) {
        flag = false;
        break;
      }
    }
  }

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N;
    cin >> N;
    vector<long long> A(N);
    long long po = 1;
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
        if (po == 0 || A.at(i) == 0)
        {
            po = 0;
        }else if (po != -1 && 1000000000000000000/po >= A.at(i))
        {
            po = po*A.at(i);
        }else{
            po = -1;
        }
    }
    cout << po ;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int &x : A) {
        cin >> x;
        x--;
    }
    int ans = 0, j = 0;
    for(int i = 0; i < N; i++) {
        if(A[i] != j) ans++;
        else j++;
    }
    cout << (ans >= N ? -1 : ans) << endl;
    return 0;
}



Measured memory_bytes: 1024
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
/**************************************************************************/
const int N = 1e5+2;
bool dp[N];
signed main()
{
    fast;
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int stones = 0 ;stones<=k;stones++)
    {
        for(int j=1;j<=n;j++)
        {
            if(stones-a[j]>=0 && !dp[stones-a[j]])
                dp[stones] = true;
        }
    }
    if(dp[k])
        cout<<"First";
    else cout<<"Second";
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int debt=100000;
    for(int i=0; i<n; i++){
        debt=debt/20*21+999;
        debt-=debt%1000;
    }
    cout<<debt<<'\n';
    return 0;
}

Measured memory_bytes: 3108
import java.util.Scanner;
import java.util.HashSet;

public class Main {

	public static void main(String[] args) {
		int N, cnt = 0;
		String hin;
		Scanner scan = new Scanner(System.in);
		N= scan.nextInt();
		
		HashSet name = new HashSet();
		
		for(int i = 1; i <= N; i++) {
			hin = scan.next();
			name.add(hin);
		}
		System.out.println(name.size());
	}

}


Measured memory_bytes: 77172
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int x,ans=0;
    cin>>x;
    for(int i=1; i<=x; i++)
    {
        int cur=i;
        for(int j=1;j<=100;j++){
            cur*=i;
            if(cur<=x)
                ans=max(ans,cur);
            else
                break;
        }

    }
  cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3560
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#define inf 0x3f3f3f3f
#define LL long long

using namespace std;

int main()
{
    int n,a,b;
    while(scanf("%d%d%d",&n,&a,&b)==3)
    {
        if((b-a)%2==0)
        {
            printf("Alice\n");
        }
        else
        {
            printf("Borys\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#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 repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	priority_queue<ll, vector<ll>, greater<ll>> p, q;
	V r(c);
	ll cnt;
	ll ans = 0LL;
	rep(i, a) {
		cin >> cnt;
		p.push(cnt);
	};
	rep(i, b) {
		cin >> cnt;
		q.push(cnt);
	}
	cin >> r;
	sort(all(r));
	while (p.size() > x) {
		p.pop();
	}
	while (q.size() > y) {
		q.pop();
	}
	clog << "A" << endl;
	rep(i, c) {
		if (q.top() > p.top()) {
			p.push(r[i]);
			p.pop();
		} else {
			q.push(r[i]);
			q.pop();
		}
	}
	clog << "A" << endl;
	while (!q.empty()) {
		ans += q.top();
		q.pop();
	}
	while (!p.empty()) {
		ans += p.top();
		p.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 6416
N, K = map(int, input().split())
E = [[] for i in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  E[a-1].append(b-1)
  E[b-1].append(a-1)
counts = [False]*N
q = [0]
counts[0] = True
r = K
while q:
  i = q.pop(0)
  # get_nexts
  js = E[i]
  c = K-1 if i == 0 else K-2
  for j in js:
    if not(counts[j]):
      counts[j] = True
      r = (r*c)%1000000007
      c -= 1
      q.append(j)
print(r)


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

int main(void){
    int d,n; cin >> d >> n;
    int s=1;
    for(int i=0; i<d; i++) s*=100;
    if(n<=99) cout << s*n << endl;
    else cout << s*101 << endl;

    return 0;
}

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

struct activity{
    int a;
    int b;
    int c;
};
int dp[100001][3];

int points(int i,int j,vector<activity> &v)
{
    if(i==1)
    {
        if(j==0)
        {
            return v[1].a;
        }
        else if(j==1)
        {
            return v[1].b;
        }
        else if(j==2)
        {
            return v[1].c;
        }
    }
    else
    {
        if(dp[i][j]!=-1)
        {
            return dp[i][j];
        }
        
        if(j==0)
        {
            return dp[i][0]=v[i].a+max(points(i-1,1,v),points(i-1,2,v));
        }
        else if(j==1)
        {
            return dp[i][1]=v[i].b+max(points(i-1,0,v),points(i-1,2,v));
        }
        else if(j==2)
        {
            return dp[i][2]=v[i].c+max(points(i-1,0,v),points(i-1,1,v));
        }
    }
}

int solve(int n,vector<activity> &v)
{
     memset(dp,-1,sizeof(dp));
     return max(max(points(n,0,v),points(n,1,v)),points(n,2,v));
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin>>n;
    
    vector<activity> v(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].a>>v[i].b>>v[i].c;
    }
    cout<<solve(n,v);
    return 0;
}

Measured memory_bytes: 7296
x = int(input())
ar = list(map(int, input().split()))
sum_val = sum(ar)

unique_val = dict()

for i in ar:
    if i in unique_val:
        unique_val[i] += 1
    else:
        unique_val[i] = 1

q = int(input())
while(q):
    a, b = map(int, input().split())
    if a in unique_val:
        value = (b-a)*unique_val[a]
        sum_val += value
        if b in unique_val:
            unique_val[b] = unique_val[b] + unique_val.pop(a)
        else:
            unique_val[b] = unique_val.pop(a)
        #print(unique_val)
        
    print(sum_val)
    q -= 1






Measured memory_bytes: 20920
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;

ll N,K;
vll d;

void dfs(vector<string>& enm,string cur)
{
    if(cur!=""){
        if(N<=stoi(cur))enm.push_back(cur);
        if(5<cur.size())return;
    }
    for(ll i=0;i<10;i++)
    {
        if(find(d.begin(),d.end(),i)!=d.end())continue;
        cur.push_back('0'+i);
        dfs(enm,cur);
        cur.pop_back();
    }
}

int main()
{
    cin>>N>>K;
    d=vll(K);
    for(ll i=0;i<K;i++)cin>>d[i];
    
    vector<string> enm;
    vector<ll> res;

    dfs(enm,"");
    for(ll i=0;i<enm.size();i++)
    {
       res.emplace_back(stoi(enm[i]));
    }
    sort(res.begin(),res.end());
    cout<<res[0]<<endl;
}

Measured memory_bytes: 36136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt(), a = scanner.nextInt(), b = scanner.nextInt();
		int sum = 0;
		for(int i=1;i<=n;i++){
			String s = String.valueOf(i);
			int total = 0;
			int num = i;
			while(num != 0){
				total += num % 10;
				num /= 10;
			}
			if(a <= total && total <= b){
				sum += i;
			}
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 21972
#include <stdio.h>

int odd(int x[200], int n){
    for(int i = 0; i < n; i++){
        if(x[i] % 2 == 1){
            return 1;
            break;
        }
    }
    return 0;
}
int main(void){
    int N = 0;
    int A[200] = {0};
    scanf("%ld", &N);
    for(int i = 0; i < N; i++){
        scanf("%ld", &A[i]);
    }
    int counter = 0;
    int judge = 0;
    while(1){
        judge = odd(A, N);
        if(judge == 0){
            counter++;
            for(int j = 0; j < N; j++){
                A[j] /= 2;
            }
        }else {
            break;
        }
    }
    printf("%d\n", counter);
    return 0;
}

Measured memory_bytes: 128
h,w = list(map(int, input().split()))
L = [input() for _ in range(h)]

ans=[]
for row in range(len(L)):
    LINE=[]
    for col in range(len(L[row])):
        if L[row][col]=='.':
            cnt=0
            for shiftX, shiftY in [(i,j) for i in [-1,0,1] for j in [-1,0,1] if i!=0 or j!=0]:
                if 0<=row+shiftY<h and 0<=col+shiftX<w:
                    if L[row+shiftY][col+shiftX]=='#':
                        cnt+=1
            LINE.append(str(cnt))
        else:
            LINE.append('#')
    ans.append(LINE)

for a in ans:
    print(''.join(a))

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const ll M = 1000000;
ll f[M] = {};
map<ll, ll> mp;
ll MOD = 1e9 + 7;

void fact() {
	f[0] = 1;
	rep(i, 1, M) f[i] = f[i - 1] * i % MOD;
}

void factorization(ll m) {
	ll t = m;
	for (int i = 2; t != 1; i++) {
		while (!(t % i)) {
			mp[i]++;
			t /= i;
		}
	}
}

ll pow(ll e, ll x) {
	if (x == 0)return 1;
	if (x == 1)return e;

	ll t = pow(e, x / 2);
	if (x & 1) {
		return (((t *t) % MOD)* e) % MOD;
	}
	else {
		return (t * t) % MOD;
	}
}

ll nCr(ll n, ll r) {
	return ((f[n] * pow(f[r], MOD - 2) % MOD) * pow(f[n - r], MOD - 2) % MOD);
}

int main() {
	fact();

	ll n, m; cin >> n >> m;

	factorization(m);

	ll ans = 1;
	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		ans = (ans * nCr(n + it->second - 1, it->second)) % MOD;
	}
	cout << ans << endl;

	return 0;
}

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

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

using namespace std;
using ll = long long;

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

void solve()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<ll>());

  ll ans = a[0];
  int add_cnt = 1;
  int index = 1;
  while(add_cnt < n - 1)
  {
    ans += a[index];
    add_cnt++;
    if (add_cnt < n - 1)
    {
      ans += a[index];
      add_cnt++;
    }
    index++;
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4792
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	int x, y, z;

	while (scanf("%d", &n) != EOF){
		for (i = 0; i < n; i++){
			scanf("%d %d %d", &x, &y, &z);

			if ((x * x == y * y + z * z) || (y * y == x * x + z * z) || (z * z == x * x + y * y)){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
	}
	return (0);
}

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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
void Yes(){
  cout << "Yes" << endl;
}
void YES(){
  cout << "YES" << endl;
}
void No(){
  cout << "No" << endl;
}
void NO(){
  cout << "NO" << endl;
}
int main(){
  char a,b;
  cin >> a >> b;
  
  if(a=='H'){
  	if(b=='H') cout << 'H' << endl;
    else cout << 'D' << endl;
  }else{
  	if(b=='H') cout << 'D' << endl;
    else cout << 'H' << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split();
        int n = int.Parse(input[0]);
        int k = int.Parse(input[1]);
        int q = int.Parse(input[2]);

        var array = System.Linq.Enumerable.Repeat(0, n).ToArray();


        int cnt = 0;
        for (int i = 0; i < q; i++)
        {
            cnt++;
            array[int.Parse(Console.ReadLine())-1]++;
        }

        for (int i = 0; i < n; i++)
        {
            if(array[i] + k - cnt > 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

int main(){
    
    int W, H;
    while(cin >> W >> H, W||H){
        int n, dp[17][17] = {0};
        bool xx[17][17];
        
        memset(xx, false, sizeof(xx));
        cin >> n;
        for(int i = 0; i < n; i++){
            int x, y; cin >> x >> y;
            xx[--y][--x] = true;
        }
        
        dp[0][0]  = 1;
        for(int i = 1; i < W; i++)
            if(!xx[0][i]) dp[0][i] = dp[0][i - 1];
        for(int i = 1; i < H; i++)
            if(!xx[i][0]) dp[i][0] = dp[i - 1][0];
        for(int i = 1; i < H; i++){
            for(int j = 1; j < W; j++){
                if(!xx[i][j])
                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
        }
        cout << dp[H - 1][W - 1] << endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int N, Q, tp, a, b, c, d[109][109];
int main() {
	while (cin >> N >> Q, N) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (i == j) d[i][j] = 0;
				else d[i][j] = 999999999;
			}
		}
		while (Q--) {
			cin >> tp;
			if (tp == 1) {
				cin >> a >> b >> c; a--, b--;
				for (int i = 0; i < N; i++) {
					for (int j = 0; j < N; j++) {
						int dist2 = d[i][a] + c + d[b][j];
						if (d[i][j] > dist2) d[i][j] = dist2;
					}
				}
				swap(a, b);
				for (int i = 0; i < N; i++) {
					for (int j = 0; j < N; j++) {
						int dist2 = d[i][a] + c + d[b][j];
						if (d[i][j] > dist2) d[i][j] = dist2;
					}
				}
			}
			else {
				cin >> a >> b; a--, b--;
				cout << (d[a][b] != 999999999 ? d[a][b] : -1) << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3120
import sys
from collections import deque
sys.setrecursionlimit(10**6)
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def BFS(n,m,table,dist):
    next = deque([0])
    while next:
        tmp = next.popleft()
        for rep in table[tmp]:
            if dist[rep]==-1:
                dist[rep] = tmp+1
                next.append(rep)
    return not -1 in dist

def main():
    n,m = IL()
    table = [[] for _ in range(n)]
    for _ in range(m):
        a,b = IL()
        table[a-1].append(b-1)
        table[b-1].append(a-1)
    dist = [-1]*n
    dist[0] = 0
    if BFS(n,m,table,dist):
        print('Yes')
        for i in range(1,len(dist)):
            print(dist[i])
    else:  print('No')
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 36920
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rf = lambda: map(float, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = rr()
lens = len(s)
if lens == 3:
    print(s[::-1])
else:
    print(s)

Measured memory_bytes: 27148
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    S=[ST() for _ in range(N)]
    d = defaultdict(int)
    ma = 0
    for s in S:
        d[s]+=1
        ma = max(ma, d[s])
    ans = []
    for s,v in d.items():
        if v==ma:
            ans.append(s)
    ans.sort()
    print(*ans,sep="\n")

if __name__ == '__main__':
    main()

Measured memory_bytes: 38020
import itertools
n,m,q = list(map(int,input().split()))
abcd = [list(map(int,input().split())) for i in range(q)]

ans = 0
for iter in itertools.combinations_with_replacement(range(1,m+1),n):
    result = 0
    for i in range(q):
        a,b,c,d = abcd[i][0],abcd[i][1],abcd[i][2],abcd[i][3]
        if iter[b-1] - iter[a-1] == c:
            result += d
    ans = max(ans, result)

print(ans)


Measured memory_bytes: 9024
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>

int main() {
    std::cin.tie(0);
     std::ios_base::sync_with_stdio(false);
    
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    
    for (int i{}, tmp; i < N; ++i) {
        std::cin >> tmp;
        v[i] = tmp;
    };
    if ( N == 2 ) {
        std::cout << std::max(v[0], v[1]) << " " << std::min(v[0], v[1]) << "\n";
        return 0;
    }
    int a = *std::max_element( begin(v), end(v) );

    int b = *std::min_element( begin(v), end(v), [&](int _1, int _2){
        return std::abs( _1-a/2. ) < std::abs( _2-a/2. );
    });
    std::cout << a << " " << b << "\n";

}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> A(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    for (int j = 0; j < m; ++j) {
      cin >> A[i][j];
    }
  }
  int res = 1145141919;
  for (long long i = 0; i < (1LL << n); ++i) {
    int cost = 0;
    vector<int> r(m, 0);
    for (int j = 0; j < n; ++j) {
      if (i & (1 << j)) {
        cost += c[j];
        for (int k = 0; k < m; ++k) {
          r[k] += A[j][k];
        }
      }
    }
    bool flag = true;
    for (int j = 0; j < m; ++j) {
      if (r[j] < x) flag = false;
    }
    if (flag) { res = min(res, cost); }
  }
  cout << (res == 1145141919 ? -1 : res) << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef long long ull;
typedef long double ld;
#define inp_arr(name,size) for(int i = 0;i<size;i++)\
cin >> name[i];
#define cepat cin.tie(0);


int main(){
    cepat

   int a;
   cin >> a;
   int b = 1000;
   if(a%b==0)
    cout << 0;
   else
    cout << b-(a%b);


    return 0;
}








Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ll long long
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}

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

int a[3][3];
int d[3][3];

int main(){
  rep(i,3)rep(j,3) cin >> a[i][j];
  int n;
  cin >> n;
  rep(ni,n){
    int x;
    cin >> x;
    rep(i,3)rep(j,3) if (a[i][j] == x) d[i][j] = 1;
  }
  bool ans = false;
  rep(i,3){
    int cnt = 0;
    rep(j,3) cnt += d[i][j];
    if (cnt == 3) ans = true;
  }
  rep(i,3){
    int cnt = 0;
    rep(j,3) cnt += d[j][i];
    if (cnt == 3) ans = true;
  }
  {
    int cnt = 0;
    rep(j,3) cnt += d[j][j];
    if (cnt == 3) ans = true;
  }
  {
    int cnt = 0;
    rep(j,3) cnt += d[j][2-j];
    if (cnt == 3) ans = true;
  }
  puts(ans?"Yes":"No");
  return 0;
}

Measured memory_bytes: 256
n,t =[int(x) for x in input().split()]
Ts=[int(x)for x in input().split()]

total=t
for i in range(1,len(Ts)):
    if(Ts[i] - Ts[i-1]>t):
        total += t
    else:
        total += Ts[i] - Ts[i-1]

print(total)


Measured memory_bytes: 25172
local TernaryCounter = {}

function TernaryCounter.new()
    local self = setmetatable({}, {__index = TernaryCounter})
    self.count = {0}
    return self
end

function TernaryCounter:inc()
    local t = self.count
    local digits = #t
    t[1] = t[1] + 1
    for i=1,digits do
        if t[i] == 3 then
            t[i] = 0
            if t[i+1] == nil then
                t[i+1] = 0
            else
                t[i+1] = t[i+1] + 1
            end
        end
    end
    return self
end

function TernaryCounter:tonumber()
    local dic = {[0]=3, [1]=5, [2]=7}
    local t = self.count
    local ans = 0
    for i=#t,1,-1 do
        ans = ans * 10 + dic[t[i]]
    end
    return ans
end

function TernaryCounter:is753()
    local oc = {[0]=0, [1]=0, [2]=0}
    for _,v in ipairs(self.count) do
        oc[v] = oc[v] + 1
        if oc[0] > 0 and oc[1] > 0 and oc[2] > 0 then
            return true
        end
    end
    return false
end

local N = io.read("n")

local cntr = TernaryCounter.new()
local ans = 0
while true do
    local n = cntr:tonumber()
    if n > N then
        break
    end
    if cntr:is753() then
        ans = ans + 1
    end
    cntr:inc()
end
print(ans)


Measured memory_bytes: 760
N = int(input())
X = list(map(int, input().split()))
X_ = sorted(X)
median_max = X_[N//2]
median_min = X_[N//2 -1]
if median_max==median_min:
    for i in range(N):
        print(median_max)
else:
    for i in X:
        if median_max > i:
            print(median_max)
        else:
            print(median_min)

Measured memory_bytes: 30636
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    int s_former = Integer.parseInt(s.substring(0,2));
    int s_latter = Integer.parseInt(s.substring(2,4));
    if((s_former>=1 && s_former<=12) && (s_latter>=1 && s_latter<=12))
      System.out.println("AMBIGUOUS");
    else if(s_former>=1 && s_former<=12)
      System.out.println("MMYY");
    else if(s_latter>=1 && s_latter<=12)
      System.out.println("YYMM");
    else
      System.out.println("NA");
  }
}

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

using namespace std;


int main(){
  long long ika,bai;
  cin>>ika>>bai;
  
  long long total;
  if(bai%2==0){
    long long total1,total2;
    total1=(ika/bai)*(ika/bai)*(ika/bai);
    total2=((ika+bai/2)/bai)*((ika+bai/2)/bai)*((ika+bai/2)/bai);
    cout<<total1+total2<<endl;}
  else{total=(ika/bai)*(ika/bai)*(ika/bai);
       cout<<total<<endl;}
    
 
 
}


Measured memory_bytes: 256
def main():
  n = int(input())
  a = list(map(int, input().split()))
  ans = 1
  if 0 in a:
    print(0)
    return
  else:
    flag = True
    for i in a:
      ans *= i
      if ans > (10 ** 18):
        print(-1)
        return
    print(ans)
  
main()


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

using namespace std;

#define ALL(x) begin(x), end(x)

typedef long long ll;
typedef pair<int, int> ipair;

//const int INF = (int)1.1e9;

int main() {
    #ifndef MY
    // freopen("cards.in", "r", stdin);
    // freopen("cards.out", "w", stdout);
    cin.tie(0);
    #endif
    ios_base::sync_with_stdio(0);

    string s;
    int k;

    cin >> s >> k;

    int n = s.length();

    for (int i = 0; i < n; ++i) {
        if (s[i] != 'a') {
            int o = 'z' - s[i] + 1;
            // cout << s[i] << " -> z+1 = a -> req o = " << o << " (k = " << k << ")\n";
            if (o <= k) {
                s[i] = 'a';
                k -= o;
            }
        }
    }

    s.back() += k % 26;

    cout << s << "\n";
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#define ll long long
#define lu long unsigned
#define ull unsigned long long

using namespace std;
bool sortbysec(const pair<string,int> &a,
              const pair<string,int> &b)
{
    return (a.second < b.second);
}
bool sortpair(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(a.first==b.first)
        return (a.second<b.second);
    else
        return(a.first>b.first);
}
bool s(const string &a, const string &b){
    bool ans;
    return (a.size()<b.size());
}
bool isPrime(int val){
    for(int i=2;i*i<=val;i++){
        if(val%i==0)
            return false;
    }
    return true;
}
ll int conc(ll int a,ll int b){
   stringstream ss;
   ss<<a<<b;
   ll int ans;
   ss>>ans;
   ss.clear();
   return ans;
}
ll int binexp(int a,int b){
    ll int res=1;
    while(b!=0){
        if(b&1){
            res*=a;
            b--;
        }else{
            a*=a;
            b/=2;
        }
    }
    return res;
}
int gcd(int a,int b){
    if(a%b==0){
        return b;
    }else{
        return gcd(a%b,b);
    }
}
vector<int> ar[60];
int vis[60]={0};

void dfs(int v){
    vis[v]=1;
    cout<<v<<"->";
    for(int c:ar[v]){
        if(vis[c]==0){
            dfs(c);
        }
    }
}

void solve(){
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    cout<<v[n-1]-v[0];
}


int main(){
    /*int t;
    cin>>t;
    while(t--)*/
        solve();


    return 0;
}



































































//1-(3+5-2+(3+19-(3-1-4+(9-4-(4-(1+(3)-2)-5)+8-(3-5)-1)-4)-5)-4+3-9)-4-(3+2-5)-10




















Measured memory_bytes: 3580
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    set<string> x;
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        x.insert(s);
    }
    cout<<x.size()<<endl;
    return 0;
}



Measured memory_bytes: 19200
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 要素xが属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 要素xが属するグループのサイズ（要素数）を返す
    def size(self, x):
        return -self.parents[self.find(x)]

    # 要素x, yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    # すべての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を返す
    def group_count(self):
        return len(self.roots())

    # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    # print()での表示用 ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = map(int, input().split())
l = []
for i in range(M):
    array = list(map(int, input().split()))
    l.append(array)

l.reverse()
ans = [0]*M
ans[0] = N*(N-1)//2
uf = UnionFind(N)
for i in range(0,M-1):
    if not uf.same(l[i][0]-1,l[i][1]-1):
        ans[i+1] = ans[i]-uf.size(l[i][0]-1)*uf.size(l[i][1]-1)
    else:
        ans[i+1] = ans[i]
    uf.union(l[i][0]-1,l[i][1]-1)
ans.reverse()
for i in range(M):
    print(ans[i])

Measured memory_bytes: 107992
#if __cplusplus > 199711L      /* C++11 */
#include <unordered_map>
#include <unordered_set>
#include <forward_list>
#include <array>
#endif                         /* C++11 */
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 qvya13579
#define y1 qvyb24680
#define j0 qvja13579
#define j1 qvjb24680
#define next qvne13579xt
#define prev qvpr13579ev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS cin.tie(0);ios::sync_with_stdio(false)
#define M_P make_pair
#define P_B push_back
#define U_B upper_bound
#define L_B lower_bound
#define P_Q priority_queue
#define FIR first
#define SEC second
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZ(x) ((int)(x).size())
#define COUT(x) cout<<(x)<<endl
#define CIN(x) cin>>(x)
#define CIN2(x,y) cin>>(x)>>(y)
#define CIN3(x,y,z) cin>>(x)>>(y)>>(z)
#define CIN4(x,y,z,w) cin>>(x)>>(y)>>(z)>>(w)
#define SCAND(x) scanf("%d",&(x))
#define SCAND2(x,y) scanf("%d%d",&(x),&(y))
#define SCAND3(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define SCAND4(x,y,z,w) scanf("%d%d%d%d",&(x),&(y),&(z),&(w))
#define SCANLLD(x) scanf("%lld",&(x))
#define SCANLLD2(x,y) scanf("%lld%lld",&(x),&(y))
#define SCANLLD3(x,y,z) scanf("%lld%lld%lld",&(x),&(y),&(z))
#define SCANLLD4(x,y,z,w) scanf("%lld%lld%lld%lld",&(x),&(y),&(z),&(w))
#define PRINTD(x) printf("%d\n",(x))
#define PRINTLLD(x) printf("%lld\n",(x))
typedef long long int lli;
using namespace std;

int ctoi(char c)
{
  if( c >= '0' and c <= '9' )
    {
      return (int)(c-'0');
    }

  return -1;
}

int alphabet_pos(char c) 
{
  if( c >= 'a' and c <= 'z' )
    {
      return (int)(c-'a');
    }

  return -1;
}


int alphabet_pos_capital(char c)
{
  if( c >= 'A' and c <= 'Z' )
    {
      return (int)(c-'A');
    }

  return -1;
}


vector<string> split(string str, char ch)
{
  int first = 0;
  int last = str.find_first_of(ch);
  
  if(last == string::npos)
    {
      last = SIZ(str);
    }

  vector<string> result;

  while( first < SIZ(str) )
    {
      string Ssubstr(str, first, last - first);
      result.push_back(Ssubstr);
      first = last + 1;
      last = str.find_first_of(ch, first);

      if(last == string::npos)
	{
	  last = SIZ(str);
	}
    }
  
  return result;
}

/*--------------- the end of the template --------------------*/









int main()
{
  //IOS; /* making cin faster */
  int N;
  SCAND(N);
  vector<int> A(N);
  REP(i,N)
    {
      SCAND(A[i]);
      
    }

  int mx = 0;
  

  REP(i,N)
    {
      REP(j,N)
	{
	  if( i != j and mx < abs(A[i]-A[j]) )
	    {
	      mx = abs(A[i]-A[j]);
	      
	    }
	}
    }

  PRINTD(mx);
  

}


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


int main() {
    long long n,p=0,ans = 0;;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
    }
    
    for(int i = 0;i < n;i ++){
        if(a.at(i) < 0){
            p ++;
        }
    }
    if(p%2 == 0){
        for(int i = 0; i < n;i ++){
            ans += abs(a.at(i));
        }
    }else{
        for(int i = 0;i < n;i ++){
        a.at(i) = abs(a.at(i));
        }
        sort(a.begin(),a.end());
        for(int i = 1;i < n;i ++){
            ans += a.at(i);
        }
        ans -= a.at(0);
    }

    cout << ans << endl;


}


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

int main()
{
    string s,t;
    cin>>s>>t;
    long long int k = 0;
    for(long long int i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
        {
            k++;
        }
    }
    cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 3912
#  combination tst 
import itertools
sentinel = [0, 0]

flag = True
while flag == True:

    basic_info = [int(i) for i in input().split()]
    if basic_info == sentinel:
        flag == False
        break
    n = basic_info[0]
    x = basic_info[1]

    numbers = [i+1 for i in range(n)]
    # print(numbers)
    cnt = 0
    combi_nums = itertools.combinations(numbers, 3)
    for c in combi_nums:
        if sum(c) == x:
            cnt +=1
    print(cnt)


Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll div_ceil(int, int);

int main() {
  ll N, K;
  std::cin >> N >> K;
  std::cout << div_ceil(N - 1, K - 1) << '\n';
}

ll div_ceil(int a, int b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 256
#全国統一プログラミング王決定戦予選-C Different Strokes
"""
問題を言い換えた時に、
高橋くんがa+bの幸福度を得られる時に、
青木さんが-a-bの妨害をできる
と言い換えても、最適な行動が取れる。
よって、a+bの降順にソートして、
高橋くんの番なら+a
青木さんの番なら-b
することで答えが得られる
"""
import sys
from operator import itemgetter
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
AB = []
for i in range(n):
    a,b = map(int,readline().split())
    AB.append([a+b,a,b])

AB.sort(reverse=True)

ans = 0
for i in range(n):
    if even(i):
        ans += AB[i][1]
    else:
        ans -= AB[i][2]

print(ans)

Measured memory_bytes: 52828
object Main extends App {

	val N = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	if(N(0) == N(1)){
		println(N(2))
	}else if(N(0) == N(2)){
		println(N(1))
	}else{
		println(N(0))
	}

}

Measured memory_bytes: 27068
#include<stdio.h>
main(){
  int i,m,d,s;
  while(1){
  scanf("%d %d",&m,&d);
    if(m==0 && d==0){
      break;
    }
    s=0;
    for(i=1;i<m;i++){
      if(i==4 || i==6 || i==9 || i==11){
	s+=30;
      }
      else if(i==2){
	s+=29;
      }
      else{
	s+=31;
      }
    }
    s+=d;

    switch(s%7){
    case 0:
      printf("Wednesday\n");
      break;
    case 1:
      printf("Thursday\n");
      break;
    case 2:
      printf("Friday\n");
      break;
    case 3:
      printf("Saturday\n");
      break;
    case 4:
      printf("Sunday\n");
      break;
    case 5:
      printf("Monday\n");
      break;
    case 6:
      printf("Tuesday\n");
      break;
    default:
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 584
#include<stdio.h>

int main() {
	int i = 0, tf = 0;
	char a[100], b[100];
	scanf("%s", a);
	scanf("%s", b);

	for (i = 0; a[i] != '\0';i++) {
		if (a[i] != b[i]) {
			tf = 1;
		}
	}


	if (tf == 0) {
		printf("Yes\n");
	}
	else if(tf==1) {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1664