akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
#define int long long
signed main() {
    int N, K; cin >> N >> K;
    vector<int>A(N);
    rep(i, N)cin >> A[i];
    long long count = 0;
    rep(i, N)for (int j = i + 1; j < N;j++)if (A[j] < A[i])count++;
    count %= INF;
    count *= K;
    count %= INF;
    sort(A.begin(), A.end());
    vector<int>B(N);
    long long ans = 0;
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)if(A[i]<A[j])ans++;
    ans%=INF;
    long long a=(K* (K - 1)/2) % INF;
    ans *= a;
    ans%=INF;
    ans += count;
    ans %= INF;
    cout << ans << endl;
}

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

int main() {
  int H,W;
  cin >> H >> W;
  for(int i=0;i<W+2;i++) {
    cout << "#" ;
  }
  cout << endl;
  
  for(int i=0;i<H;i++) {
    cout << "#";
    string pix;
    cin >> pix;
    for(int j=0;j<W;j++) {
      cout << pix.at(j);
    }
    cout << "#" << endl;
  }
  
  for(int i=0;i<W+2;i++) {
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

bool check[111];

int main(void)
{
	int n, k, i;

	scanf("%d %d", &n, &k);

	for (i = 1; i <= k; i++)
	{
		int d;
		scanf("%d", &d);
		while (d--)
		{
			int t;
			scanf("%d", &t);
			check[t] = true;
		}
	}

	int ans = 0;
	for (i = 1; i <= n; i++)
		if (!check[i])
			ans++;

	printf("%d", ans);
	return 0;
}

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



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

    int uresisa=0;
    int gohyakuen,goen;

    uresisa+=(x/500)*1000;

    x=x%500;

    uresisa+=(x/5)*5;

    cout<<uresisa<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int64_t gcd(int64_t x, int64_t y)
{
	if (x % y == 0)
		return y;
	else
		return gcd(y, x % y);
}

int main()
{
	int64_t N, X;
	cin >> N >> X;

	int64_t line = (N - 1) * 3;
	cout << line - (gcd(N, X) - 1) * 3 << endl;

	return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

counter = 0
for i in range(0, A+1):
    for n in range(0, B+1):
        for t in range(0, C+1):
            total = 500 * i + 100 * n + 50 * t
            if total == X:
                counter += 1
print(counter)     

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

const int N=301010;
int a[N],s[N],n,ss;
/*int solve(int l,int r) {
	if (vis[l][r]) return dp[l][r];
	else {
		vis[l][r]=1;
		int ans=2*(s[r*2-1]-s[2*l]);
		for (int i=l+1;i<r;i++) {
			ans=max(ans,min(solve(i,r),solve(l,i)));
		}
		printf("%d %d %d\n",l,r,ans);
		return dp[l][r]=ans;
	}
}
*/
int vis[N];
bool check(int md) {
	vis[0]=1;
	int z=0;
	rep(i,1,n/2+2) {
		vis[i]=0;
//		rep(j,0,i) if (vis[j]&&2*s[i*2-1]-2*s[2*j]>=md)
//			vis[i]=1;
//		printf("%d %d %d\n",md,i,vis[i]);
		if (2*s[i*2-1]-z>=md) vis[i]=1; else vis[i]=0;
		if (vis[i]) z=min(z,2*s[2*i]);
	}
	return vis[n/2+1];
}
int main() {
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d",a+i),ss+=a[i];
	if (n%2==0) {
		int s1=0,s2=0;
		rep(i,1,n+1) if (i%2==0) s1+=a[i]; else s2+=a[i];
		printf("%d %d\n",max(s1,s2),min(s1,s2));
		return 0;
	}
	rep(i,1,n+1) {
		if (i%2==1) s[i]=s[i-1]+a[i]; else s[i]=s[i-1]-a[i];
	}

//	memset(vis,0,sizeof(vis));
//	printf("%d\n",solve(0,n/2+1)-s[n]);

	int l=-1e9,r=1e9;
	while (l+1<r) {
		int md=l+(r-l)/2;
		if (check(md)) l=md; else r=md;
	}
	l-=s[n];
	printf("%d %d\n",(ss+l)/2,(ss-l)/2);
//	printf("%d\n",l-s[n]);
}


Measured memory_bytes: 3328
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

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

	double L=N;

	if (N % 2 == 0) { cout << fixed << setprecision(15) << 0.5 << endl; }
	if (N % 2 == 1) { cout << fixed << setprecision(15) << (L+1)/(2*L) << endl; }
}

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

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

int h,w;
vector<string> s;

void dfs(int y, int x, vector<vector<int>> &seen, int &p, int &q){
  if(seen[y][x] == 1)
    return;
  seen[y][x] = 1;
  if (s[y][x] == '#') p++;
  if (s[y][x] == '.') q++;

  rep(i,4){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx >= w || nx < 0 || ny >= h || ny < 0) continue;
    if (s[ny][nx] == s[y][x]) continue;
    dfs(ny,nx,seen,p,q);
  }
  return;
}

int main(){
  cin>>h>>w;
  s.resize(h);
  rep(i,h) cin>>s[i];

  vector<vector<int>> seen(h,vector<int>(w,0));
  ll ans = 0;
  int p,q;
  rep(i,h)rep(j,w){
      p = 0;
      q = 0;
      dfs(i,j,seen,p,q);
      ans += (ll)p*q;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 19276
import numpy as np
from itertools import product

n, m = (int(i) for i in input().split())  

i = 0
nums_list = []
while i < n:
  nums_list.append([int(i) for i in input().split()])
  i += 1
ans = 0

for x, y, z in product([1, -1], repeat = 3):
  tmp = []
  i = 0
  
  while i < n:
    a, b, c = nums_list[i]
    tmp.append(a * x + b * y + c * z)
    i += 1
  
  tmp.sort(reverse = True)
  ans = max(ans, sum(tmp[:m]))
  
print(ans)
  
  
  


  
  

Measured memory_bytes: 12260
H,W = map(int,(input().split()))
p = []

if H*W%3 == 0:
    p1 = 0
else:
    p1 = min(H,W)
p.append(p1)

for i in range(1,W+1):
    a = i*H
    if H%2 == 0:
        b = (W-i)*(H//2)
        p2 = abs(a-b)
    else:
        b = (W-i)*(H//2)
        c = (W-i)*(H//2 +1)
        p2 = max(a,b,c)-min(a,b,c)
    p.append(p2)

for i in range(1,H+1):
    a = i*W
    if W%2 == 0:
        b = (H-i)*(W//2)
        p3 = abs(a-b)
    else:
        b = (H-i)*(W//2)
        c = (H-i)*(W//2 +1)
        p3 = max(a,b,c)-min(a,b,c)
    p.append(p3)

print(min(p))

Measured memory_bytes: 47704
N, X = list(map(int, input().split()))

a = [1]
p = [1]
for i in range(N):
    a.append(3 + 2 * a[i])
    p.append(1 + 2 * p[i])

def f(N, X):
    # レベルNバーガーの下からX層までに含まれるパティPの枚数
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N - 1]:
        return f(N - 1, X - 1)
    else:
        return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1])

print(f(N, X))

Measured memory_bytes: 38384
#include <stdio.h>
#include <stdlib.h>
 
int
main(int argc, char *argv[])
{
        int n, m;
        int *A;
        int *b;
        int *itrA, *itrb;
        int i, j;
        int tmp;
 
        scanf("%d %d", &n, &m);
        A = (int *)malloc(n * m * sizeof(int));
        b = (int *)malloc(m * sizeof(int));
         
        /* Read A */
        itrA = A;
        for (i = 0; i < n; i++)
                for (j = 0; j < m; j++)
                        scanf("%d", itrA++);
        /* Read b */
        itrb = b;
        for (i = 0; i < m; i++)
                scanf("%d", itrb++);
 
        for (i = 0; i < n; i++) {
                tmp = 0;
                itrA = A + i * m;
                itrb = b;
                for (j = 0; j < m; j++)
                        tmp += *itrA++ * *itrb++;
                printf("%d\n", tmp);
        }
         
        return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
typedef pair<int,int> P;

int main(){
  int n;cin >> n;
  int a[n]; rep(i,n) cin >> a[i];
  sort(a,a+n);
  int same = 0;
  int j = 1;
  while(j < n){
    while(a[j-1] == a[j]) {
      same++;
      j++;
    }
    j++;
  }
  if( same % 2 == 0){
    cout << n - same << "\n";
  }else{
    cout << n - same - 1  << "\n";
  }
}

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(){
  ll n;
  cin >> n;
  vector<ll> p(n);
  rep(i,n)
    cin >> p[i];
  ll ans = 0;
  ll Max = p[0];
  rep(i,n){
    if(Max >= p[i]){
      Max = p[i];
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int r, g, b, s;
  cin >> r >> g >> b;
  s = g * 10 + b;
  if(s % 4 == 0){
  	cout<< "YES" << endl;
  }else{
  	cout << "NO" << endl;
  }
}

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

int main(){
  string a,b;
  cin >> a >> b;
  if(a == "H" && b == "H") puts("H");
  if(a == "D" && b == "D") puts("H");
  if(a == "H" && b == "D") puts("D");
  if(a == "D" && b == "H") puts("D");
  return 0;
}


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

typedef long long ll;
using namespace std;

int main()
{
    int n; cin >> n;
    ll min_natural;
    ll A = 1, B = 1;
    vector<int> t(n), a(n);

    for (int i = 0; i < n; i++) cin >> t[i] >> a[i];

    for(int i = 0; i < n; i++)
    {
        min_natural = max(ceil((long double)A / t[i]), ceil((long double)B / a[i]));
        A = t[i] * min_natural; B = a[i] * min_natural;
    }
    
    cout << A + B << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <list>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "


const int N = 1e5+1;
vector<int> g[N];
int n;
int dfs(int cur, int p)
{
  vector<int> sgs;
  for (auto nxt : g[cur])
    if (nxt != p)
      sgs.pb(dfs(nxt, cur));
  int ret = 0;
  for (auto e : sgs) ret ^= (e+1);
  return ret;
 }
int main()
{
  scanf("%d", &n);
  for (int i = 1; i <= n-1; ++i)
    {
      int u, v; scanf("%d %d", &u, &v);
      g[u].pb(v);
      g[v].pb(u);
    }
  puts(dfs(1, 1)?"Alice":"Bob");
}


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

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

int main()
{
    ll n,m; cin >> n >> m;
    vector<ll> h(n);
    for( int i = 0; i < n; ++i )
    {
        cin >> h[i];
    }

    vector< vector<ll> > g(n);
    for( int i = 0; i < m; ++i )
    {
        int a,b; cin >> a >> b; a--; b--;
        g[a].push_back(b);; g[b].push_back(a);
    }
    
    ll ans = 0;
    for( int i = 0; i < g.size(); ++i )
    {
        bool check = true;
        for( int j = 0; j < g[i].size(); ++j )
        {
            if( h[i] <= h[g[i][j]])
            {
                check = false;
            }
        }
        if( check )
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 9860
import java.util.Scanner;

public class Main {

    public static int aa = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int D = sc.nextInt();
        int x2000 = sc.nextInt();

        int xplus1 = x2000;

        for (int i = 0; i < 10; i++) {
            xplus1 = r * xplus1 - D;
            System.out.println(xplus1);
        }

    }
}

Measured memory_bytes: 21844
#include <stdio.h>
int main(void){
    int a,b;
    
    scanf("%d %d",&a,&b);
    
    int add = a + b;
    int sub = a - b;
    int mul = a * b;
    
    int max = add;
    if(sub > max) max = sub;
    if(mul > max) max = mul;
    
    printf("%d\n",max);
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>
   
using namespace std;

#define mod 1000000007

int n, m, s, g;

double solve(pair<double, double> r[31][31])
{
    double result[31][31][31];
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= 31; k++){
                result[i][j][k] = mod;
            }
        }
    }
    priority_queue<pair<double, pair<pair<int, int>, int> > > qu;
    qu.push(make_pair(0.0, make_pair(make_pair(s, -1), 0.0)));
    while(!qu.empty()){
        double nowcost = (qu.top()).first;
        pair<int, int> nowandbefore = ((qu.top()).second).first;
        int nowv = ((qu.top()).second).second;
        int nowp = nowandbefore.first;
        int beforep = nowandbefore.second;
        // cout << nowp << " " << beforep << " " << -nowcost << " " << nowv << endl;
        qu.pop();
        if(nowp == g && nowv == 1) {
            return -nowcost;
        }
        if(beforep != -1 && result[nowp][beforep][nowv] < -nowcost) continue;
        result[nowp][beforep][nowv] = -nowcost;
        for(int i = 1; i <= n; i++){
            if(r[nowp][i].first == 0 || i == beforep) continue;
            double kyori = r[nowp][i].first;
            double limit = r[nowp][i].second;
            double nextcost;
            for(int j = -1; j <= 1; j++){
                if(nowv + j <= 0) continue;
                nextcost = nowcost - (double)kyori / (nowv + j);
                if(nowv + j <= limit && -nextcost < result[i][nowp][nowv + j]){
                    result[i][nowp][nowv + j] = -nextcost;
                    qu.push(make_pair(nextcost, make_pair(make_pair(i, nowp), nowv + j)));
                }
            }
        }
    }
    return -1;
}

int main()
{
    while(1){
        cin >> n >> m;
        if(n == 0) break;
        cin >> s >> g;
        pair<double, double> road[31][31];
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                road[i][j] = make_pair(0, 0);
            }
        }
        for(int i = 0; i < m; i++){
            int x, y;
            double d, c;
            cin >> x >> y >> d >> c;
            road[x][y] = road[y][x] = make_pair(d, c);
        }
        double ans =  solve(road);
        if(ans == -1) cout << "unreachable" << endl;
        else cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3892
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

constexpr int vdx[13] = {1, 1, 0, -1, 1, 1, 0, -1, 1, 1, 0, -1, 0};
constexpr int vdy[13] = {0, 1, 1,  1, 0, 1, 1, 1, 0, 1, 1, 1, 0};
constexpr int vdz[13] = {0, 0, 0,  0, 1, 1, 1, 1, -1, -1, -1, -1, 1};

bool check(int field[10][10][10], int n, int m, int turn) {
    for (int d = 0; d < 13; ++d) {
        int dx = vdx[d]; int dy = vdy[d]; int dz = vdz[d]; 

        for (int x = 0; x < n; ++x) {
            for (int y = 0; y < n; ++y) {
                for (int z = 0; z < n; ++z) {
                    int c = 0;
                    for (; c < m; ++c) {
                        int nx = x + c * dx;
                        int ny = y + c * dy;
                        int nz = z + c * dz;

                        if(nx < 0 || n <= nx ||
                           ny < 0 || n <= ny ||
                           nz < 0 || n <= nz) {
                            break;
                        }

                        if(field[nx][ny][nz] != turn) {
                            break;
                        }
                    }
                    if (c == m) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}


void solve(int& n,
        int& m,
        int& p,
        vector<pair<int, int> >& vp) {
    int field[10][10][10];
    int height[10][10];

    for (int j = 0; j < n; ++j) {
        for(int k = 0; k < n; ++k) {
            fill(field[j][k], field[j][k] + n, 0);
        }
        fill(height[j], height[j] + n, 0);
    }

    int turn = 1;

    for (int j = 0; j < p; ++j) {
        int x = vp[j].first;
        int y = vp[j].second;
        field[x][y][height[x][y]++] = turn;

        if(check(field, n, m, turn)) {
            cout << (turn == 1 ? "Black" : "White") 
                 << ' ' << (j + 1) << endl;
            return;
        }

        turn = 3 - turn;
    }

    cout << "Draw" << endl;
}

int main(int argc, char** argv) {
    int n, m, p;
    vector<pair<int, int> > pos;
    while (true) {
        cin >> n >> m >> p;
        if(n == 0 && m == 0 && p == 0) {
            break;
        }
        pos.resize(p);
        for (int j = 0; j < p; ++j) {
            cin >> pos[j].first >> pos[j].second;
            --pos[j].first; --pos[j].second;
        }
        solve(n, m, p, pos);
    }

    return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
int n,A[N];

int dfs(int idx,int seki){
  if(idx == n) return seki%2 == 0;
  int res = 0;
  res+=dfs(idx+1,seki*(A[idx]+1));
  res+=dfs(idx+1,seki*A[idx]);
  res+=dfs(idx+1,seki*(A[idx]-1));
  return res;
}

signed main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];

  cout<<dfs(0,1)<<endl;


  return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll a, b;
    cin >> a >> b;
    string res = (a * b) % 2 == 0 ? "Even" : "Odd";
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,d,i,s=0;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  for(i=0;i<101;i++){
    if(a<=i&&i<=b&&c<=i&&i<=d) s++;
  }
  printf("%d",s-1*(s>0));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

int n,d,a;P x[210000];int y[210000];
int change[210000];
signed main(){
  cin>>n>>d>>a;
  rep(i,n)cin>>x[i].first>>x[i].second;
  sort(x, x+n);
  rep(i,n)y[i] = x[i].first;
  rep(i,n){
    double t = x[i].second, s = ceil(t/(double)a);
    x[i].second = (int)s;
  }
  int ans = 0;
  rep(i,n){
    if(i > 0)change[i] += change[i-1];
    x[i].second += change[i];
    chmax(x[i].second, 0LL);
    int right = x[i].first+2*d;
    auto itr = upper_bound(y+i, y+n, right)-1;
    ans += x[i].second;
    change[i+1] -= x[i].second;
    change[(itr-y)+1] += x[i].second;
  }
  cout << ans << endl;
}



Measured memory_bytes: 6528
/*****************************
 Filename: kljlddf.cpp
 Author: hbb
 Create: 2020-04-06 14:54:41
*****************************/
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = INT_MAX >> 1;
typedef long long int LL;

int n, x, y;
int ans[maxn];

int main(){
	scanf("%d %d %d", &n, &x, &y);
	memset(ans, 0, sizeof(ans));
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			int temp = min(abs(i - j), abs(i - x) + 1 + abs(j - y));
			temp = min(temp, abs(i - y) + 1 + abs(j - x));
			ans[temp]++;
		}
	}
	for(int i = 1; i <= n - 1; i++) printf("%d\n", ans[i]);
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << endl;
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int64_t, int >prime_factor(int64_t n){map< int64_t, int > ret;for(int64_t i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vector<double> x(n) , y(n); REP(i,n) cin >> x[i] >> y[i];
    double sum = 0;
    REP(i,n){
        REP(j,n){
            double a = (x[i]-x[j])*(x[i]-x[j]);
            double b = (y[i]-y[j])*(y[i]-y[j]);
            double c = pow(a+b,0.5);
            sum += c;
        }
    }
    cout << sum/n  << endl;

    return 0;
}

Measured memory_bytes: 512
data = list(map(lambda x: int(x),input().split(" ")))

cardNum = []

for n in range(data[1]):
	cardNum.append(list(map(lambda x: int(x),input().split(" "))))


card = [0]*(data[0])

check = [0,1000000]

for n in range(data[1]):
	if check[0] < cardNum[n][0]:
		check[0] = cardNum[n][0]
	if check[1] > cardNum[n][1]:
		check[1] = cardNum[n][1]

if check[1]-check[0] < 0:
	print(0)
else:
	print(check[1]-check[0]+1)

Measured memory_bytes: 28096
#include<iostream>
using namespace std;
int main(){
    int k;
    cin>>k;
    int ans=0;
    for(int i=1;i<=k;i+=2){
        for(int i=2;i<=k;i+=2){
           ans++; 
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int n;
	while(cin>>n){
		if(n==-1)break;
		//int a,b,c,d;
		int sum =4280-1150;
		if(n<=10){
			cout <<sum<<endl;
			continue;
		}else if(n>10&&n<=20){
			//sum -=10*125;
			sum -=(n-10)*125;
			cout <<sum<<endl;
			continue;
		}else if(n>20&&n <=30){
			sum -=10*125;
			//sum -=10*140;
			sum -=(n-20)*140;
			cout <<sum<<endl;
			continue;
		}else if(n>30){
			sum -=10*125;
			sum -=10*140;
			sum -=(n-30)*160;
			cout <<sum<<endl;
			continue;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#define rep(i,n) for(int i=0;i<(int)n;i++)

using namespace std;

string ten[3]={"A","B","C"};

int main()
{
	int n;
	cin>>n;
	for(;n!=0;cin>>n)
	{
		rep(i,n)
		{
			int ma,en,ja;
			int ans=2;
			cin>>ma>>en>>ja;
			
			if(((ma+en+ja)/3>=50&&(ma>=80||en>=80))||(ma+en+ja)/3>=70)ans=1;
			if((ma+en+ja)/3>=80||(ma+en)/2>=90||en==100||ja==100||ma==100)ans=0;
			
			cout<<ten[ans]<<endl;
		}
		
		
	}
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int MXN = 3100;
int n, m;
string s, t;
int dp[MXN][MXN];

int Dp(int i, int j) {
    if(i == n || j == m) return 0;
    if(dp[i][j] != -1) return dp[i][j];
    int ans = 0;
    if(s[i] == t[j]) ans = Dp(i + 1, j + 1) + 1;
    else ans = max(ans, max(Dp(i + 1, j), Dp(i, j + 1)));
    return dp[i][j] = ans;
}

void rec(int i, int j, string & ans) {
    if(i == n || j == m) return;
    if(s[i] == t[j] && Dp(i, j) == Dp(i + 1, j + 1) + 1) {
        ans += s[i];
        rec(i + 1, j + 1, ans);
        return;
    } 
    else if(Dp(i, j) == Dp(i + 1, j)) {
        rec(i + 1, j, ans);
        return;
    } else {
        rec(i, j + 1, ans);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> s >> t;
    n = s.size(), m = t.size();
    memset(dp, -1, sizeof dp);
    string ans;
    rec(0, 0, ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 41532
n,k=map(int,input().split())
A=list(map(int,input().split()))
r=max(A)
l=0
while l+1<r:
    mid=(l+r)//2
    if sum([(a-1)//mid for a in A])>k:
        l=mid
    else:
        r=mid

print(r)

Measured memory_bytes: 30772
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    map<int, int>::iterator itr = mp.find(a);
    if (itr != mp.end()) {
      itr->second++;
    } else {
      mp[a] = 1;
    }
  }

  vector<int> vec;
  for (map<int, int>::iterator itr = mp.begin(); itr != mp.end(); itr++) {
    vec.push_back(itr->second);
  }
  sort(vec.begin(), vec.end());

  int ans = 0;

  if (vec.size() > K) {
    for (int i = 0; i < vec.size() - K; i++) {
      ans += vec[i];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 10748
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>> N;
    if (N==3||N==5||N==7){
        cout << "YES"<<"\n";
    }
    else{
    cout << "NO"<<"\n";
    }
}



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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int K;
  queue<ll> que;
  cin >> K;
  for (ll i = 1; i < 10; i++) {
    que.push(i);
  }
  if (K <= 9)
    cout << K << endl;
  int cnt = 9;
  while (cnt < K) {
    ll p = que.front();
    que.pop();
    int t = p%10;
    for (int i = max(t-1, 0); i <= min(t+1, 9); i++) {
      que.push(p*10+i);
      cnt++;
      if (cnt == K)
        cout << p*10+i << endl;
     }
  }
}


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

int p;
string exp;
int index;
bool error;

int inverse(int a, int p);

int equation();
int factor();
int term();

int inverse(int x, int p) {
    int t = p-2;
    int r = 1;
    while(t) {
        if(t&1) r= r*x%p;
        x = x*x%p;
        t >>= 1;
    }
    return r;
}

int equation() {
    int res = factor();
    while(exp[index]=='+' || exp[index]=='-') {
        char op = exp[index++];
        int right = factor();
        if(op=='+') res = (res+right) % p;
        if(op=='-') res = (res-right+p) % p;
    }
    return res;
}
int factor() {
    int res = term();
    while(exp[index]=='*' || exp[index]=='/') {
        char op = exp[index++];
        int right = term();
        if(op=='*') res = res*right % p;
        if(op=='/') {
            if(right==0) error = true;
            else res = res*inverse(right,p) % p;
        }
    }
    return res;
}
int term() {
    int res = 0;
    if(exp[index]=='(') {
        index++;
        res = equation();
        index++;
    } else {
        while(isdigit(exp[index])) res = res*10 + exp[index++]-'0';
        res %= p;
    }
    return res;
}

int main()
{
    string s;
    while(cin >> p, p != 0){
        cin.ignore();
        getline(cin, s);
        s.erase(remove(s.begin(), s.end(), ' '), s.end());
        exp = s.c_str();
// int main()
// {
//     while(cin>>p, p) {
//         getline(cin, exp);
//         while(exp.find(" ",0)!=string::npos) exp.erase(exp.find(" ",0), 1);
//         exp.erase(0, 1);

        index = 0;
        error = false;
        int ans = equation();
        if(error) cout<<"NG"<<endl;
        else cout<<exp<<" = "<<ans<<" (mod "<<p<<")"<<endl;
    }
}

Measured memory_bytes: 1420
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

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

  if (N == 0) {
    cout << X << endl;
    return 0;
  }

  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    P[i] = p;
  }

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

  if (find(P.begin(), P.end(), X) == P.end()) {
    cout << X << endl;
    return 0;
  }

  int diff = 1;
  for (;;) {
    if (find(P.begin(), P.end(), X - diff) == P.end()) {
      cout << to_string(X - diff) << endl;
      return 0;
    }

    if (find(P.begin(), P.end(), X + diff) == P.end()) {
      cout << to_string(X + diff) << endl;
      return 0;
    }

    diff++;
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>

int main(){
  ll H,W; cin>>H>>W;
  ll ans = MOD;
  
  if(W%3==0 || H%3==0){ 
    ans = 0;
  }else{ 
    for(int x=0;x<W;++x){
      ll a = x*H;
      ll b = (W-x)*(H/2);
      ll c = (W-x)*((H+1)/2);
      ll t = max( {a,b,c} );
      ll s = min( {a,b,c} );
      chmin(ans, t-s);
      b = (W-x)/2*H;
      c = (W-x+1)/2*H;
      t = max( {a,b,c} );
      s = min( {a,b,c} );
      chmin(ans, t-s);
      if(ans==1){break;}
    }
    for(int y=0;y<H;++y){
      ll a = y*W;
      ll b = (H-y)*(W/2);
      ll c = (H-y)*((W+1)/2);
      ll t = max( {a,b,c} );
      ll s = min( {a,b,c} );
      chmin(ans, t-s);
      b = (H-y)/2*W;
      c = (H-y+1)/2*W;
      t = max( {a,b,c} );
      s = min( {a,b,c} );
      chmin(ans, t-s);
      if(ans==1){break;}
    }
  } 
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int m;
    cin >> m;
    vector<ll> ds(m), cs(m);
    ll ans = 0, ans2 = 0;
    for (int i = 0; i < m; ++i) {
        scanf("%lld %lld", &ds[i], &cs[i]);
        ans += cs[i]*ds[i];
        ans2 += cs[i];
    }
    cout << ans2-1+(ans-1)/9 << "\n";
    return 0;
}

Measured memory_bytes: 3328
//正直者の証言が正しいかどうかを確認する。不正直者の発言は検証する必要なし。
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int g[15][15];
 
int main() {
  int n;
  cin >> n;

  //i番目の人がj番目の人を証言していない「-1」として設定
  rep(i,n)rep(j,n) g[i][j] = -1;
  rep(i,n) {
    int m;
    cin>>m;
    rep(j,m) {
      int a, x;
      cin >> a >> x;
      --a;
      g[i][a] = x;
    }
  }
  
  int ans = 0;
  //シフト演算子(2進数で2のべき乗を求める。dの配列に正直者と不正直者の割り当て結果を代入している)
  rep(i,1<<n) {
    vector<int> d(n);
    rep(j,n) if (i>>j&1) {
      d[j] = 1;
    }
    bool ok = true; //割り当て結果が正しければTrueとする
    rep(j,n) {
      if (d[j]) {
        rep(k,n) {
          if (g[j][k] == -1) continue; //証言がなかったらSkip
          if (g[j][k] != d[k]) ok = false; //証言が正しければTrueのまま
        }
      }
    }
    if (ok) ans = max(ans, __builtin_popcount(i)); //popcountは1が立っている数を数える
  }
  cout << ans << endl;
}

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

using namespace std;

using int64 = long long;
const int mod = (int) (1e9 + 7);

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

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

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

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};

int main() {
  int N, H, W;
  cin >> N;
  cin >> H >> W;
  vector< int > A(N), B(N), C(N);

  vector< int > ord(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> B[i] >> C[i];
    --A[i], --B[i];
    ord[i] = i;
  }
  sort(begin(ord), end(ord), [&](int a, int b) {
    return C[a] > C[b];
  });
  UnionFind uf(H + W);
  int64 ret = 0;
  vector< int > sz(H + W, 1);

  for(int i : ord) {
    int x = sz[uf.find(A[i])];
    int y = sz[uf.find(B[i] + H)];
    if(uf.unite(B[i] + H, A[i])) {
      sz[uf.find(A[i])] = x + y;
    }
    if(sz[uf.find(A[i])]) {
      --sz[uf.find(A[i])];
      ret += C[i];
    }
  }
  cout << ret << endl;
}




Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<(n); i++)
#define int long long
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
signed main(void){
    int n,m,k;cin>>n>>m>>k;
    vector<vector<int>>dp(n,vector<int>(n,INF));
    vector<int>R(k);rep(i,k){cin>>R[i];R[i]--;}
    int t,f,c;
    rep(i,m){
        cin>>f>>t>>c;f--;t--;
        dp[f][t]=c;dp[t][f]=c;
    }
    rep(k,n)rep(i,n)rep(j,n){
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
    }
    
    vector<int>v(k);rep(i,k)v[i]=i;
    int ans=INF;int com;
    do{
        com=0;
        rep(i,k-1){
            f=R[v[i]];t=R[v[i+1]];
            com+=dp[f][t];
        }
        ans=min(ans,com);
    }while(next_permutation(all(v)));
    cout<<ans<<endl;
}

Measured memory_bytes: 512
from functools import reduce

n, m = map(int, input().split())
a = list(map(int, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
    
def lcm(a, b):
    return a * b // gcd(a, b)

def count(n):
    cnt = 0
    while n % 2 == 0:
        n //= 2
        cnt += 1
    return cnt

A = [count(i) for i in a]

if len(set(A)) != 1:
    print(0)
    exit()

aa = [i // 2 for i in a]
LCM = reduce(lcm, aa)

res = m // LCM
if res % 2 == 0:
    print(res // 2)
else:
    print(res // 2 + 1)


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

int main() {
  int n;
  cin >> n;
  string t, h;
  int st = 0;
  int sh = 0;
  rep(i,n) {
    cin >> t >> h;
    if(t == h) {
      ++st;
      ++sh;
    } else if (t > h) {
      st += 3;
    } else {
      sh += 3;
    }
  }

  cout << st << " " << sh << endl;

  return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';
int mod = 1e9 + 7;
ll inf = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int lose = 0;
    for (int i = 0; i < s.size();i++){
        if(s[i]=='x')
            lose++;
    }
    if(lose>7)
        cout<<"NO" <<endl;
        else
            cout << "YES" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		public static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush =
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}

		public void Solve(ConsoleInput cin) {
			var datum = cin.ReadIntArray(2);
			int N = datum[0], K = datum[1];
			var C = new long[N];
			var D = new long[K, N];
			const int M = 998_244_353;
			var invs = new (int l, int r)[K];
			for(int k = 0; k < K; k++) {
				datum = cin.ReadIntArray(2);
				invs[k] = (datum[0], datum[1]);
			}
			C[0] = 1;
			for(int k = 0; k < K; k++) {
				D[k, 0] = 0;
			}
			var RNG = Enumerable.Range(0, K);
			for(int i = 1; i < N; i++) {
				for(int k = 0; k < K; k++) {
					var newbie = (i - invs[k].l);
					var leaver = (i - 1 - invs[k].r);
					D[k, i] = D[k, i - 1] + (newbie >= 0 ? C[newbie] : 0) - (leaver >= 0 ? C[leaver] : 0);
				}
				C[i] = RNG.Sum(k => D[k, i]) % M;
			}
			Console.WriteLine((C[N - 1] + M) % M);
		}
	}

static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ")
			=> string.Join(separator, X);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i < N; ++i)
				ret[i] = Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek() == -1; }
		}
	}

}


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

using namespace std;

set<int> G[100];
bool visit[200];
pair<int ,int> temp[1000];

int bfs(int x){
    queue<int>Que;
    Que.push(x);
    int num = 1;
    visit[x] = true;
    while(!Que.empty()){
        int now = Que.front();
        Que.pop();
        for(set<int>::iterator beg = G[now].begin();beg !=G[now].end();++beg){
            if(visit[*beg]==false){
                visit[*beg] = true;
                ++num;
                Que.push(*beg);
            }
        }
    }
   // cout<<num<<endl;
    return num;
}

int main()
{
    int a,b;
    cin>>a>>b;
    int x,y;
    for(int i=0;i!=b;++i){
        cin>>x>>y;
        temp[i] = make_pair(x,y);
        G[x].insert(y);
        G[y].insert(x);
    }
    int cnt=0;

   for(int i=0;i!=b;++i){
        memset(visit,false,sizeof(visit));
        G[temp[i].first].erase(temp[i].second);
        G[temp[i].second].erase(temp[i].first);
        if(bfs(1)!=a)
            ++cnt;
        G[temp[i].first].insert(temp[i].second);
        G[temp[i].second].insert(temp[i].first);
   }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
K = int(input())
X = 7
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
sum = 1
while(True):
    if X % K == 0:
        print(sum)
        exit()
    else:
        X = X % K * 10 + 7
        sum += 1

Measured memory_bytes: 9092
n = gets.to_i
a = gets.split.map(&:to_i)

sub_arr = []
a.each_with_index do |aa, i|
  sub_arr << aa - (i+1)
end

sub_arr.sort!
if n%2==1
  b = sub_arr[n/2]
  res = sub_arr.map{|nn|(nn-b).abs}.inject(:+)
else
  b1 = sub_arr[n/2]
  b2 = sub_arr[n/2-1]
  res = [sub_arr.map{|nn|(nn-b1).abs}.inject(:+),sub_arr.map{|nn|(nn-b2).abs}.inject(:+)].min
end

puts res


Measured memory_bytes: 21368