akhauriyash/Code-Regression huggingface dataset:
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

struct City{
    ll x, y, p;
};

int popcount(int x) {
    // x = (0x55555555&x)+((0xAAAAAAAA&x) >> 1);
    // x = (0x33333333&x)+((0xCCCCCCCC&x) >> 2);
    // x = (0x0F0F0F0F&x)+((0xF0F0F0F0&x) >> 4);
    // x = (0x00FF00FF&x)+((0x00FF00FF&x) >> 8);
    // x = (0x0000FFFF&x)+((0xFFFF0000&x) >> 16);
    int ret = 0;
    while(x) {
        ret += (x&1);
        x /= 2;
    }
    return ret;
}

int main() {
    int n; cin >> n;
    vector<City> da(n);
    rip(i,n,0) {
        cin >> da[i].x >> da[i].y >> da[i].p;
    }
    vector<vector<ll>> xx(1 << n, vector<ll>(n));
    vector<vector<ll>> yy(1 << n, vector<ll>(n));
    rip(i,1 << n, 0) {
        rip(j,n,0) {
            xx[i][j] = abs(da[j].x);
            yy[i][j] = abs(da[j].y);
            rip(k, n, 0) {
                if((i >> k)&1) {
                    chmin(xx[i][j], abs(da[j].x-da[k].x));
                    chmin(yy[i][j], abs(da[j].y-da[k].y));
                }
            }
        }
    }
    vector<ll> ans(n+1, LLONG_MAX/12);
    rip(i,1 << n, 0) {
        for(int j = i;j>0;j = (j-1)&i) {
            ll tmp = 0;
            int l = i-j;
            rip(k,n,0) {
                tmp += min(xx[j][k], yy[l][k]) * da[k].p;
            }
            chmin(ans[popcount(i)], tmp);
        }
        ll tmp = 0;
        rip(k,n,0) {
            tmp += min(xx[0][k], yy[i][k]) * da[k].p;
        }
        chmin(ans[popcount(i)],tmp);
    }
    rip(i,n+1,0) printf("%lld\n", ans[i]);
}

Measured memory_bytes: 12924
#include <iostream>
#include <algorithm>
#include <string>
#include <memory>
#include <cmath>
#include <vector>
int main() {
	std::string str; std::cin >> str;
	auto toBlack = 0;
	for (auto i = 0; i < str.size(); ++i) {
		if (i % 2 == 0 && str[i] != '0') {
			++toBlack;
		}
		else if (i % 2 == 1 && str[i] != '1') {
			++toBlack;
		}
	}
	auto toWhite = 0;
	for (auto i = 0; i < str.size(); ++i) {
		if (i % 2 == 0 && str[i] != '1') {
			++toWhite;
		}
		else if (i % 2 == 1 && str[i] != '0') {
			++toWhite;
		}
	}
	std::cout << std::min(toBlack, toWhite) << std::endl;
}

Measured memory_bytes: 512
while n=gets.chomp
  break if n=="0000"
  na=nil
  [*?1..?9].each{|e|na=true if n==e*4}
  (puts"NA";next) if na
  i=0
  while n!="6174"
    i+=1
    s=n.chars.sort*""
    n=(s.reverse.to_i-s.to_i).to_s
    n+=?0 while n.size<4
  end
  p i
end

Measured memory_bytes: 6112
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int NS = 1e5 + 100;
ll N, m, a[NS];
typedef pair <ll, ll> cn;

int main() {
	ll sum = 0;
	cin >> N >> m;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	sort(a, a + N);
	cn z[m];
	for (int i = 0; i < m; ++i) {
		cin >> z[i].first >> z[i].second;
	}
	sort(z, z + m, [](const cn &p1, const cn &p2) {
			return p1.second < p2.second;
			});
	int i = 0;
	--m;
	for (; i < N; ++i) {
		if (a[i] >= z[m].second) { break; }
		sum += z[m].second;
		if (z[m].first == 1) {
			if (m-- == 0) {
				++i;
				break;
			}
			continue;
		}
		z[m].first -= 1;
	}
	for (;i < N; ++i) {
		sum += a[i];
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 2560
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n,k = na()
s = input()
f = s[:k-1]
b = s[k-1:]
b = b.title().swapcase()
print(f + b)

Measured memory_bytes: 3060
import java.util.*;
  
public class Main {
    private static final Scanner scn = new Scanner(System.in);
      
    public static void main(String[] args) {
        int n = scn.nextInt();
        StringBuilder sb = new StringBuilder(scn.next());
        for(int i = 1; i < n; i++) {
            sb.insert(0, scn.next() + " ");
        }
        System.out.println(sb);
    }
}

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

int main() {
  int64_t H;
  cin>>H;
  
  int64_t sum=2;
  while(H!=1){
    H=H/2;
    sum*=2;
  }
  
  cout<<sum-1<<endl;
   
  
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll sum[200009];
map<ll,ll>mp;

int main(){
  ll n,k;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    sum[i+1]=sum[i]+a;
  }
  ll ans=0;
  for(int i=0;i<=n;i++){
    sum[i]=sum[i]-i;
    sum[i]%=k;
    if(i-k>=0){
      mp[sum[i-k]]--;
    }
    ans+=mp[sum[i]];
    mp[sum[i]]++;
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    int a,b,c; cin>>a>>b>>c;
    if(a==b){
        cout<<c<<endl;
    }else{
        if(a==c){
            cout<<b<<endl;
        }else{
            cout<<a<<endl;
        }
    }

}


Measured memory_bytes: 3628
N, D=map(int, input().split())

from math import sqrt

def dis(a, b):
    return sqrt(a**2+b**2)
count=0
for i in range(N):
    x,y=map(int, input().split())
    d=dis(x,y)
    if d<=D:
        count+=1

print(count)

Measured memory_bytes: 70028
H, W, K = map(int, input().split())

c = [input() for _ in range(H)]

row_num = 2 ** H
col_num = 2 ** W

result = 0

for row in range(row_num):
    for col in range(col_num):

        row_bin = format(row, 'b')
        row_bin = row_bin.zfill(H)
        col_bin = format(col, 'b')
        col_bin = col_bin.zfill(W)

        count = 0
        for i in range(H):
            for j in range(W):
                if c[i][j] == "#" and row_bin[i] == "0" and col_bin[j] == "0":
                    count += 1

        if count == K:
            result += 1

print(result)

Measured memory_bytes: 9168
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;


int main(int argc, char **argv) {
    int n;
    cin >> n;
    set<string> ss;

    for (int i=0; i<n; ++i) {
        string s;
        cin >> s;
        ss.insert(s);
    }

    cout << ss.size() << endl;

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int main()
{
	fastio;

	string s;
	cin >> s;

	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << 3 << '\n';
	else if  (s[0] == 'R' && s[1] == 'R' || s[1] == 'R' && s[2] == 'R') cout << 2 << '\n';
	else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << 1 << '\n';
	else cout << 0 << '\n';

	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(){
  int n;cin >>n;
  pair<pair<string,int>,int> p[n];
  rep{
      string s;cin >>s;
      int k;cin >>k;
      p[i] = make_pair(make_pair(s,-1*k),i+1);
  }
  sort(p,p+n);
  rep{
      cout << p[i].second << endl;
  }
} 

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    if(a<b){
        printf("a < b\n");
    }
    else if(a>b){
        printf("a > b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
 
bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
ll n;
ll l[110];

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

    sort(l,l+n);

       ll sum = 0;
       for(int i = 0; i < n-1; i++)       sum += l[i];
       if(sum > l[n-1])    cout << "Yes\n";
       else   cout << "No\n";
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
// headers {{{
using namespace std;
// using namespace rel_ops;
 
typedef long long int64;
typedef unsigned long long uint64;
const double pi=acos(-1.0);
const double eps=1e-11;
const int inf=0x7FFFFFFF;
template<class T> inline bool checkmin(T &a,T b){return b<a?a=b,1:0;}
template<class T> inline bool checkmax(T &a,T b){return b>a?a=b,1:0;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define mem(a,b) memset(a, b, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define rep(i,n) for(int i=0; i<n; i++)
#define repit(i,v) for(typeof(v.begin()) i=v.begin(); i!=v.end(); i++)
#define iter(v) typeof(v.begin())
#define ff first
#define ss second
#ifdef LOCAL
#define dbg(args...) printf(args); //##__VA_ARGS__
#define dout cout
#define out(x) (cout<<#x<<": "<<x<<endl)
template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}
#else
#define dbg(...)
#define dout if(true);else cout
#define out(...)
#define show(...)
#endif
// }}}

int h[505][505];
int obs[505][505];
int N;
int dir[] = {0,1,1,0,0,-1,-1,0};
inline bool valid(int x, int y) {
    return x>=0 && x <N && y>=0 && y < N;
}
void dfs(int x, int y) {
    for (int d = 0; d < 8 ; d+=2) {
        int xx = x+dir[d], yy = y+dir[d+1];
        out(xx<< yy);
        out(valid(xx,yy));
        if (valid(xx, yy) && checkmin(h[xx][yy], h[x][y]+obs[x][y])) {
            dfs(xx,yy);
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    while (cin >> N) {
        vector<int> v;
        rep(i, N*N) {
            int a;
            cin >> a;
            a--;
            v.PB(a);
        }
        rep(i, N) rep(j, N) {
            h[i][j] = min(min(i, j), min(N-1-i, N-1-j));
            obs[i][j] = 1;
        }
        int ans = 0;
        rep(i, int(v.size())) {
            int x = v[i]/N, y = v[i]%N;
            ans += h[x][y];
            obs[x][y] = 0;
            dfs(x,y);
            show(h, N, N);
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 21536
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[N];
			int[]C = new int[N];


			int count = 0;
			long goA = 0;
			long goB = 0;

			long hu = 0;
			int huco =0;
			for(int i = 0;i<N;i++)A[i] = scan.nextInt();
			for(int i = 0;i<N;i++)B[i] = scan.nextInt();

			for(int i = 0;i<N;i++) {

				C[i] = A[i]-B[i];
				if(C[i]<0) {
					hu+=(long)C[i];
					huco++;
				}
				goA+=(long)A[i];
				goB+=(long)B[i];
				if(A[i]<B[i])count++;
			}

			if(goA<goB) {
				System.out.println(-1);
				return;
			}


			if(count ==0) {
				System.out.println(0);
				return;
			}

			int co = 0;
			//System.out.println(huco);
			Arrays.sort(C);
			for(int i = N-1;i>=0;i--) {
				if(C[i]>0) {
					hu+=C[i];
					huco++;
					if(hu>=0) {
						break;
					}
				}
			}

			System.out.println(huco);











		}


	}


}


Measured memory_bytes: 60920
def floyd(dismat, v):
    for k in range(v):
        for i in range(v):
            if dismat[i][k] != float("inf"):
                for j in range(v):
                    if dismat[k][j] != float("inf"):
                        dismat[i][j] = min(dismat[i][j], dismat[i][k] + dismat[k][j])
    return dismat


def main():
    ve = input().split()
    v, e = tuple(map(int, ve))
    dismat = [[float("inf") for _ in range(v)] for _ in range(v)]
    for _ in range(e):
        std = input().split()
        s, t, d = tuple(map(int, std))
        dismat[s][t] = d
    for i in range(v):
        dismat[i][i] = 0
    dismat = floyd(dismat, v)
    for i in range(v):
        if dismat[i][i] < 0:
            print("NEGATIVE CYCLE")
            return
    for i in range(v):
        for j in range(v):
            if dismat[i][j] == float("inf"):
                dismat[i][j] = "INF"
        print(" ".join(map(str, dismat[i])))


if __name__ == "__main__":
    main()



Measured memory_bytes: 6404
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, t;
long long ans, sum;
long long cnt1[maxn], cnt2[maxn], a[maxn];
int main() {
	scanf("%d", &n);
	int p = 1;
	for(int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
		while((sum ^ a[i]) != sum + a[i]) sum ^= a[p++];
		ans += i - p + 1;
		sum ^= a[i];
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)

const int MAXN = 800 + 10, 
      dx[4] = {0, 0, +1, -1}, 
      dy[4] = {+1, -1, 0, 0};
int n, m, k, ans = INT_MAX;
pii st;
bool a[MAXN][MAXN];

bool is_val(int x, int y)
{
	return (x >= 0 && y >= 0 && x < n && y < m && !a[x][y]);
}

int mind(int x, int y)
{
	return min(min(x, y), min(n - x - 1, m - y - 1));
}

int dis[MAXN][MAXN];
queue <pii> q;
void bfs()
{
	memset(dis, 63, sizeof dis);
	dis[st.F][st.S] = 0;
	q.push(st);

	while (sz(q))
	{
		int x = q.front().F, y = q.front().S;
		q.pop();
		if (dis[x][y] <= k)
			smin(ans, (mind(x, y) + k - 1) / k + 1);

		for (int i = 0; i < 4; i ++)
		{
			int xp = x + dx[i], 
			    yp = y + dy[i];
			if (is_val(xp, yp) && dis[xp][yp] > 1e8)
			{
				dis[xp][yp] = dis[x][y] + 1;
				q.push(pii(xp, yp));
			}
		}
	}
}

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

	cin >> n >> m >> k;
	for (int i = 0; i < n; i ++)
		for (int j = 0; j < m; j ++)
		{
			char c;
			cin >> c;
			a[i][j] = (c == '#');
			if (c == 'S')
				st = pii(i, j);
		}

	bfs();
	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main(){

    int n;
    cin >> n;
    vector<int> arr(n+1, 0), ball(n+1, 0);
    for(int i = 1; i <= n; i++)
        cin >> arr[i];
    for(int i = n; i >= 1; i--){
        int sm = 0;
        for(int j = 2*i; j <= n; j += i)
            sm += ball[j];
        sm = sm%2;
        if( sm != arr[i] )
            ball[i]++;
    }
    vector<int> ans;
    for(int i = 1; i <= n; i++)
        if( ball[i] )
            ans.push_back(i);
    cout << ans.size() << endl;
    for(int i : ans)
        cout << i << " ";
    return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0; i<(int)(n); ++i)
#define REP(i,m,n) for(ll i=(ll)(m); i<(ll)(n); ++i)
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

int main(){
  int n,m;
  cin>>n>>m;
  int la=0,ra=n;
  vector<int> l(m),r(m);
  rep(i,m){
    cin>>l[i]>>r[i];
    la=max(la,l[i]);
    ra=min(ra,r[i]);
  }
  int ans=ra-la+1;
  if (ans<=0)ans=0;
  cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3980
// AOJ 1144 "カーリング 2.0" (ICPC国内予選 2006 Problem D)
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX_H = 20;
const int MAX_W = 20;
const int LIMITS = 10;

// 入力
int w, h;
int field[MAX_H+2][MAX_W+2];

int sx, sy;
int gx, gy;
int turn;

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

void debug() {
    printf("s(%d, %d), g(%d, %d)\n", sx, sy, gx, gy);
    for (int i = 0; i <= h + 1; i++) {
        for (int j = 0; j <= w + 1; j++) {
            printf("%2d ", field[i][j]);
        }
        cout << endl;
    }
    cout << endl;
    
    return;
}

void dfs(int c, int x, int y) {
    if (c > LIMITS) {
        return;
    }
    //printf("%d\n", c);
    for (int i = 0; i < 4; i++) {
        if (field[y+dy[i]][x+dx[i]] == 1) {
            continue;
        }
        int tmpx = x;
        int tmpy = y;
        while (field[tmpy+dy[i]][tmpx+dx[i]] != 1 && field[tmpy][tmpx] != -1) {
            tmpx += dx[i];
            tmpy += dy[i];
            if (tmpx == gx && tmpy == gy) {
                turn = min(turn, c);
                return;
            }
            if (field[tmpy][tmpx] == -1) {
                break;
            }
        }
        if (field[tmpy][tmpx] != -1) {
            field[tmpy+dy[i]][tmpx+dx[i]] = 0;
            dfs(c + 1, tmpx, tmpy);
            field[tmpy+dy[i]][tmpx+dx[i]] = 1;
        }
    }
}

void solve() {
    dfs(1, sx, sy);
    if (turn != 99) {
        printf("%d\n", turn);
    } else {
        printf("-1\n");
    }
}

int main() {
    while (true) {
        cin >> w >> h;
        if (w == 0) {
            break;
        }
        for (int i = 0; i < MAX_H + 2; i++) {
            memset(field[i], -1, sizeof(field[i]));
        }
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                cin >> field[i][j];
                if (field[i][j] == 2) {
                    sx = j;
                    sy = i;
                } else if (field[i][j] == 3) {
                    gx = j;
                    gy = i;
                }
            }
        }
        //debug();
        turn = 99;
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 1148
import java.util.Scanner;

public class Main {
	static final int MAX_L = 100;
	void run() {
		Scanner scan = new Scanner(System.in);
		int l = scan.nextInt();
		int k = scan.nextInt();
		long[] dp = new long[MAX_L + 1];
		dp[0] = dp[1] = 1;
		for (int i = 2; i < l; i++) {
			long num = i - k - 1 < 0 ? 0 : dp[i-k-1];
			dp[i] = dp[i - 2] + num + 1;
		}
		dp[l] = dp[l - 1] + (l >= k ? dp[l - k]:0);
		System.out.println(dp[l]);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}



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

int main() {
  string s;
  cin >> s;
  char a = s.at(0);
  char b;
  int i;
  int counta = 1;
  int countb = 0;
  for (i = 1; i < 4; i = i + 1) {
    if (s.at(i) == a) {
      counta = counta + 1;
    } else {
      b = s.at(i);
      countb = countb + 1;
      break;
    }
  }
  bool d = true;
  for (int j = i + 1; j < 4; j = j + 1) {
    if (s.at(j) == a) {
      counta = counta + 1;
    } else if (s.at(j) == b) {
      countb = countb + 1;
    } else {
      cout << "No" << endl;
      d = false;
      break;
    }
  }
  if (counta == 2 && countb == 2 && d) {
    cout << "Yes" << endl;
  } else if (d == true) {
    cout << "No" << endl;
  }
}

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

vector<int> tsort_Kahn(const vector<vector<int>>& g) {
    const int V = g.size();

    vector<int> indeg(V,0);
    stack<int>  S;

    // ??¨???????????????????????????????????\?¬???°????¨????
    for(auto& u_out_edges : g)
	for(auto& v : u_out_edges)
	    indeg[v]++;

    // ??\?¬???° == 0 ?????????????¨????
    for(int i=0; i<V; ++i) 
	if( indeg[i] == 0 )
	    S.push(i);

    vector<int> ans;
    while( S.size() > 0 ) {
	int u = S.top(); S.pop();
	ans.emplace_back(u);
	for(auto& v : g[u]) {
	    indeg[v]--;
	    if( indeg[v] == 0 ) S.push(v);
	}
    }
    return ans;
}

void visit(const vector<vector<int>>& g, int u, vector<bool>&used, vector<int>& ans) {

    if( used[u] == false ) {
	used[u] = true;
	for(auto& v : g[u]) {
	    visit(g, v, used, ans);
	}
	ans.emplace_back(u);
    }
}

vector<int> tsort_Tarjan(const vector<vector<int>>& g) {
    const int V = g.size();

    vector<bool> used(V,false);
    vector<int> ans;
    for (int u=0; u<V; ++u) {
	visit(g, u, used, ans);
    }
    reverse(ans.begin(), ans.end());
    return ans;
}



int main () {

    int V,E;
    cin >> V >> E;

    vector<vector<int>> g(V);
    for (int i=0; i<E; ++i) {
	int s,t;
	cin >> s >> t;
	g[s].emplace_back(t);
    }

    vector<int> ans = tsort_Tarjan(g);
    for(auto& e : ans) {
	cout << e << endl;
    }

    
    
    return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <queue>
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> pii;
const ll maxn = 1e6+10;
const ll inf = 1e14;
ll N,M;
ll h[maxn],e[maxn],ne[maxn],w[maxn],idx;
ll dis[maxn];

priority_queue<pii,vector<pii>,greater<pii> > heap;

void add(ll a,ll b,ll c){
    e[idx] = b,w[idx] = c,ne[idx] = h[a],h[a] = idx++;
}

ll Dijkstra(){
    heap.push({0,1});
    dis[1] = 0;
    
    while (heap.size()) {
        auto cur = heap.top();heap.pop();
        ll d = cur.first,s = cur.second;
        for(ll i = h[s];i!=-1;i = ne[i]){
            ll j = e[i];
            if(d+w[i] < dis[j]){
                dis[j] = d+w[i];
                heap.push({dis[j],j});
            }
        }
    }
    if(dis[N] == inf ) return -1;
    return dis[N];
}

void init(){
    for(ll i = 1;i<=N;i++) dis[i] = inf;
    memset(h,-1,sizeof(h));
    for(ll i = 1;i<=N;i++){
        add(i,i-1,0);
    }
}

int main(){
    cin>>N>>M;
    init();
    ll a,b,c;
    for(ll i = 0;i<M;i++){
        scanf("%lld%lld%lld",&a,&b,&c);
        add(a,b,c);
    }
    cout<<Dijkstra()<<endl;
    return 0;
}


Measured memory_bytes: 21880
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	string s;
	cin >> s;
	lli ans = 700;
	rep(i,s.size()) if(s[i] == 'o') ans+=100;
	cout << ans << endl;
	return 0;
}

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

ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            total = (500 * a) + (100 * b) + (50 * c)
            if total == X:
                ans += 1
print(ans)

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

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

	int ans;
	if (a == b) {
		ans = c;
	} else if (a == c) {
		ans = b;
	} else {
		ans = a;
	}

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


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

IN = 'sample-1.in'  # sample case for local test
def local_test():
    try:
        from pcm.utils import set_stdin
        import sys
        import os
        if len(sys.argv) == 1:
            set_stdin(os.path.dirname(__file__) + '/test/' + IN)
    except:
        pass


import sys
import os
import time
import re
from pydoc import help
import string
import math
import numpy as np
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    CS = [0]*(N+1)

    for n in range(N):
        if n >= 1:
            CS[n+1] = CS[n] + A[n]
        else:
            CS[n+1] = A[n]

    res = 0
    for v in Counter(CS).values():
        if v >= 2:
            res += v*(v-1)//2

    print(res)

if __name__ == "__main__":
    local_test()
    solve()

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

int main(){
	string s;
	char c;
	int ans = 0;
	cin >> s;
	c = s[0];
	ans++;
	for(int i=1; i<s.length(); i++){
		//cout << "i " << i << "  ans " << ans <<  endl;
		ans++;
		if(c == s[i]){
			if(i == s.length()-1){
				ans--;
				break;
			}else{
				i++;
				c = -1;
				continue;
			}
		}
		c = s[i];
	}
	cout << ans << endl;
	return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

signed main(){
    int N, M;
    cin >> N >> M;
    
    vector<int> X(M);
    collect(X, M);
    sort(all(X));
    
    priority_queue<int, vector<int>, greater<int>> q;
    rep(i,M-1) q.push(X[i+1]-X[i]);
    
    int ans = 0;
    rep(i, M-N){
        ans += q.top();
        q.pop();
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 2168
from itertools import permutations

n=int(input())
l=list(map(str,input().split()))
t=list(map(str,input().split()))
s="".join(l)
h="".join(t)

l1=list()

for i in permutations(s):
    k="".join(i)
    l1.append(k)
 
l1.sort()

print(abs(l1.index(s)-l1.index(h)))


Measured memory_bytes: 11964
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
  
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
  
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
  
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
  
using mint = ModInt<1000000007>;
mint dp[2001][2001];

signed main(){
    int n, m; cin >> n >> m;
    int s[n], t[m];
    REP(i,n) cin >> s[i];
    REP(i,m) cin >> t[i];
    dp[0][0] = 1;
    REP(i,n+1)REP(j,m+1){
        if(i > 0) dp[i][j] += dp[i-1][j];
        if(j > 0) dp[i][j] += dp[i][j-1];
        if(i > 0 and j > 0 and s[i-1] != t[j-1]) dp[i][j] -= dp[i-1][j-1];
    }
    cout << dp[n][m] << endl;
}

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

using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<vector<int>> dp(k+1, vector<int>(2));
    for(int i=0;i<=k;i++){
        int m=0;
        dp[i][0]=2;
        dp[i][1]=-2;    
        for(int j=0;j<n;j++){
            if(a[j]<=i){
                dp[i][0] = min(dp[i][0] , dp[i-a[j]][1]);
                dp[i][1] = max(dp[i][1] , dp[i-a[j]][0]);
                m++;
            }
        }
        //if has no possible moves, not sure with k=0 though
        if(m==0){
            dp[i][0]=1;
            dp[i][1]=0;
        }
        //cout<<dp[i][0] << " " << dp[i][1]<<"\n";
    }
    cout<<(dp[k][0]?"Second":"First")<<"\n";
    return 0;
}

Measured memory_bytes: 8780
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		if (k <= 1) {
			System.out.println(0);
		} else {
			System.out.println(n - k);
		}
	}
}


Measured memory_bytes: 23124
n = input()
a = map(int,raw_input().split())
s = 0
m = a[0]
M = a[0]
for i in range(0,n):
    s = s + a[i]
    if m > a[i]:
        m = a[i]
    if M < a[i]:
        M = a[i]
print m,M,s

Measured memory_bytes: 7092
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#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 K; cin >> K;
  int even = 0; int odd = 0;
  for (int i = 1; i <= K; ++i) {
    if (i%2==0) ++even;
    else ++odd;
  }
  cout << even * odd << endl;
  return 0;
}

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

const int MAX_N=51;

int N; string name; double score;
vector<double> dat(9);
vector<pair<double,string>> eff;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(cin >> N,N){
		eff.clear();
		for (int i=0;i<N;++i){
			cin >> name;
			for (int j=0;j<9;++j) cin >> dat[j];
			score=(-dat[0]+dat[6]*dat[7]*dat[8])/(dat[1]+dat[2]+dat[3]+(dat[4]+dat[5])*dat[8]);
			eff.emplace_back(-score,name);
		}
		sort(eff.begin(),eff.end());
		for (int i=0;i<N;++i) cout << eff[i].second << '\n';
		cout << '#' << '\n';
	}
}


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

int main(){
  int n;
  cin >> n;
  int now = 1, ans = 0;
  for (int i=0; i<n; i++){
    int a;
    cin >> a;
    if (a == now){
      now++;
    }
    else{
      ans++;
    }
  }
  if (ans == n) ans = -1;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
let checkNum num lst = 
	if List.mem num lst then lst
	else num :: lst 

let get_data () = 
	let index = int_of_string(read_line())
	in 
	let rec sub i result =
		if i < index then  	
			let num = int_of_string(read_line())  
			in sub (i + 1) (checkNum num result)
		else result
	in sub 0 []		
		

let solve () = 
	print_int (List.length (get_data()));;

solve()

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n; cin>>n;
  long long y; cin>>y;
  
  bool can1=false;
  for(int i=0;i<=y/1000;i++){
  bool can2=false;
    for(int j=0;j<=(y-i*1000)/5000;j++){
      int k=n-i-j;
      if(k>=0 && 1000*i+5000*j+10000*k==y){
        cout<<k<<" "<<j<<" "<<i;
        can1=true;
        can2=true;
        break;
      }
    }
    if(can2) break;
  }
  if(can1) cout<<endl;
  else cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		ArrayList<Integer> l = new ArrayList<Integer>();
		while(sc.hasNext()){
			l.add(sc.nextInt());
		}
		Collections.sort(l);
		for(int i=0; i<l.size(); i+=2){
			ans += l.get(i);
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 9680
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
int X, Y, Z, K;
ll A[1001], B[1001], C[1001], D[3001];
priority_queue<ll> que;

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

  cin >> X >> Y >> Z >> K;
  rep(i, X) cin >> A[i];
  rep(i, Y) cin >> B[i];
  rep(i, Z) cin >> C[i];
  rep(i, X) rep(j, Y) que.push(A[i]+B[j]);
  rep(i,min(K, X*Y)) {
    ll p = que.top(); que.pop();
    D[i] = p;
  }
  while(!que.empty()) que.pop();
  rep(i, K) rep(j, Z) que.push(D[i]+C[j]);
  rep(i,K) {
    ll p = que.top(); que.pop();
    cout << p << "\n";
  }
  return 0;
}

Measured memory_bytes: 35172
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

vector<vector<ll> > A;

ll dfs(ll a){
    if(A[a].size()==0){
        return 0;
    }

    vector<ll> D;
    for(ll child : A[a]){
        ll d = dfs(child);
        D.push_back(d);
    }
    sort(ALL(D), greater<ll>());

    ll max_depth = 0;
    FOR(i, 0, D.size()){
        ll d = D[i] + (i+1);
        max_depth = max(max_depth, d);
    }

    return max_depth;
}

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

    // input
    ll N;
    cin >> N;

    A.resize(N+1);

    FOR(i, 2, N+1){
        ll winner;
        cin >> winner;

        A[winner].push_back(i);
    }

    ll answer = dfs(1);
    p(answer);
    
    return 0;
}

Measured memory_bytes: 13568
if __name__ == '__main__':
    a = input()
    a_len = len(a)
    # check1
    top_s = a[:int((a_len-1)/2)]
    tail_s = a[int((a_len+3)/2)-1:]
    if a ==  ''.join(list(reversed(a))) and top_s == ''.join(list(reversed(top_s))) and tail_s == ''.join(list(reversed(tail_s))):
        print('Yes')
    else:
        print('No')

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


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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 998244353;
const int inf = INT_MAX;
const int N = 2e5 + 5;

ll power[N], prefix[N];

void comp() {
    power[0] = 1;
    for (int i = 1; i < N; i++) power[i] = 10 * power[i - 1] % mod;
    for (int i = 1; i < N; i++) prefix[i] = (10 * prefix[i - 1] + 1) % mod;
}


template <typename T>
class SegmentTree {
public:
    using F = function<T(const T&, const T&)>;

    int n;
    vector<T> t;
    vector<int> lazy;
    T e;
    F f;
    SegmentTree() : n(), t(), lazy(), e(), f() {}

    template <typename U>
    SegmentTree(const U& arr, int n, T e, F f): n(n), t(4 * n), lazy(4 * n), e(e), f(f) {
        build(arr, 1, 0, n - 1);
    }

    template <typename U>
    void build(const U& arr, int i, int l, int r) {
        if (l == r) {
            t[i] = T(arr[l]);
            return;
        }

        int mid = (l + r) >> 1;
        build(arr, i << 1, l, mid);
        build(arr, i << 1 | 1, mid + 1, r);

        t[i] = f(t[i << 1], t[i << 1 | 1]);
    }

    void push (int x, int l, int r) {
        if (lazy[x]) {
            int mid = (l + r) >> 1;
            t[x << 1].val = prefix[mid - l + 1] * lazy[x] % mod;
            t[x << 1 | 1].val = prefix[r - mid] * lazy[x] % mod;
            lazy[x << 1] = lazy[x];
            lazy[x << 1 | 1] = lazy[x];
            lazy[x] = 0;
        }
    }

    template <typename U>
    void update(int ql, int qr, U val) {
        updateHelper(ql, qr, val, 1, 0, n - 1);
    }

    template <typename U>
    void updateHelper(int ql, int qr, U val, int i, int l, int r) {
        if (ql > r or qr < l)
            return;
        if (ql <= l and r <= qr) {
            t[i].val = prefix[r - l + 1] * val % mod;
            lazy[i] = val;
            return;
        }
        push(i, l, r);
        int mid = (l + r) >> 1;
        updateHelper(ql, qr, val, i << 1, l, mid);
        updateHelper(ql, qr, val, i << 1 | 1, mid + 1, r);

        t[i] = f(t[i << 1], t[i << 1 | 1]);
    }
};

struct node {
    int length;
    ll val;
    node(): length(), val() {}
    node(int x): length(1), val(x) {}
};

node combine(const node& a, const node& b) {
    node res;
    res.length = a.length + b.length;
    res.val = (a.val * power[b.length] + b.val) % mod;
    return res;
}

int n, q;

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

    comp();

    cin >> n >> q;
    SegmentTree<node> st(vector<int>(n, 1), n, node(), combine);

    while (q--) {
        int l, r, d;
        cin >> l >> r >> d;
        st.update(--l, --r, d);
        cout << st.t[1].val << '\n';
    }
    return 0;
}

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

int main(){
	int n, d;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	rep(i, n){
		rep(j, d){
			cin >> x.at(i).at(j);
		}
	}

	int cnt = 0;
	for(int i = 0; i < n-1; i++){
		for(int j = i+1; j < n;j++){
			int dist = 0;
			for(int k = 0; k < d; k++){
				int tmp = x.at(j).at(k) - x.at(i).at(k); 
				dist += tmp*tmp;
			}

			bool res = false;
			for(int n = 1; n <= dist; n++){
				if(n*n == dist) res = true;
			}

			if(res) cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;

struct ss{
	ll a;
	ll b;
}s[100020];

bool cmp(ss aa,ss bb){
	return aa.b>bb.b;
}

int main()
{
	ios::sync_with_stdio(false);
	ll n,h;
	cin>>n>>h;
	int max=0;  //平a 最大
	int t=0;    //好刀的投掷
	for(int i=0;i<n;i++){
		cin>>s[i].a>>s[i].b;
	}
	sort(s,s+n,cmp);
	for(int i=0;i<n;i++){
		if(s[i].a>max){
			max=s[i].a;
			t=i;
		}
	}
	
	int yy=0;
	for(int i=0;i<n;i++){
		if(s[i].b>max){
			h=h-s[i].b;
			yy++;
			if(h<=0){
				cout<<yy<<endl;
				return 0;
			}
		}
	}
	yy+=ceil(h*1.0/max);
	cout<<yy<<endl;
return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int W,H,x,y,r;
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	int m,n;
	m = (x-W);
	n = (y-H);
	if(x*x+y*y>=r&&m*m+y*y>=r&&m*m+n*n>=r&&x*x+n*n>=r&&x>=r&&y>=r&&x<=W-r&&y<=H-r){
		printf("Yes\n");
	} 
	else printf("No\n");
}


Measured memory_bytes: 3164
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;

int dp[101][10010];
int main() {
	int N, W; cin >> N >> W;
	int v[1001], w[1001];
	memset(dp, 0, sizeof(dp));
	for (int i = 0; i < N; i++) cin >> v[i] >> w[i];

	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= W; j++) {
			if (j < w[i]) {
				dp[i + 1][j] = dp[i][j];
			}
			else {
				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			}
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}


Measured memory_bytes: 7068
#include<stdio.h>
#define NIL -1
#define MAX 10000

typedef struct {
    int p, l, r;
}Node;
Node T[MAX];
int n;

void preParse(int u){
    if(u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u){
    if(u == NIL) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

void postParse(int u){
    if(u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main(){
    int i, v, l, r, root;

    scanf("%d", &n);
    for(i=0; i<n; i++){
        T[i].p = NIL;
    }

    for(i=0; i<n; i++){
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if(l != NIL) T[l].p = v;
        if(r != NIL) T[r].p = v;
    }

    for(i=0; i<n; i++){
        //printf("%d %d\n", i, T[i].p);
        if(T[i].p == NIL){
            root=i;
        }
    }

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");

    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

int main() {
    int n, x;
    cin >> n >> x;
    if (x == 1 || x == 2*n-1) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    if (n == 2) {
        cout << 1 << endl;
        cout << 2 << endl;
        cout << 3 << endl;
        return 0;
    }
    int d[2*n-1];
    fill_n(d, 2*n-1, 0);
    set<int> s;
    for (int i = 1; i <= 2*n-1; i++) {
        s.insert(i);
    }
    d[n-2] = x-1;
    d[n-1] = x;
    d[n] = x+1;
    s.erase(x);
    s.erase(x-1);
    s.erase(x+1);
    if (1 <= x-2) {
        d[n+1] = x-2;
        s.erase(x-2);
    } else {
        d[n-3] = x+2;
        s.erase(x+2);
    }

    for (int i = 0; i < 2*n-1; i++) {
        if (!d[i]) {
            d[i] = *s.begin();
            s.erase(s.begin());
        }
        cout << d[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 11648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
  int N, f = true;
  cin >> N;
  REP(i, N) {
    int A;
    cin >> A;
    f &= (A % 2 == 1) || (A % 3 == 0) || (A % 5 == 0);
  }
  cout << (f ? "APPROVED" : "DENIED") << endl;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0180

#include <stdio.h>
#include <algorithm>

int A[10010], B[10010];
std::pair<int, int> bridge[10010];

int parent[110]; //代表元

int root(int a) {
	if(parent[a] == a) { return a; }
	parent[a] = root(parent[a]);
	return parent[a];
}

int main(void) {
	int n, m;
	
	while(true) {
		scanf("%d %d", &n, &m);
		if ( n == 0 ) { break; }
		
		for(int i=0; i<n; i++) {
			parent[i] = i;
		}
		
		for(int i=0; i<m; i++) {
			bridge[i].second = i;
			scanf("%d %d %d", &A[i], &B[i], &(bridge[i].first));
		}
		
		sort(bridge, bridge+m);
		
		int sum = 0;
		for(int i=0; i<m; i++) {
			int bid = bridge[i].second;
			if ( root(A[bid]) == root(B[bid]) ) { continue; } //既に連結
			
			sum += bridge[i].first;
			parent[root(A[bid])] = root(B[bid]);
		}
		
		printf("%d\n", sum);
	}
}

Measured memory_bytes: 1108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int n, a; cin >> n >> a;
    out(n * n - a);
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  vector<int> d(n);
  for(int &a:d) cin>>a;
  auto solve=[&](){
    int p=0;
    for(int i=0;i<n;i++){
      if(i>p) break;
      while((p+1)*10<=i*10+d[i]) p++;
    }
    return p>=n-1;
  };
  bool f=solve();
  reverse(d.begin(),d.end());
  f&=solve();
  cout<<(f?"yes":"no")<<endl;
  return 0;
}

Measured memory_bytes: 5180