akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A,B = map(int,input().split())

P = tuple(map(int,input().split()))

n1 = sum(p <= A for p in P)
n2 = sum(A < p <= B for p in P)
n3 = sum(B < p for p in P)

print(min(n1,n2,n3))

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

int N, M;
int masu[1000];
int me[1000];

signed main()
{
	while (true) {
		cin >> N >> M;
		if (N == 0 && M == 0) break;
		rep(i,N) cin >> masu[i];
		rep(i,M) cin >> me[i];

		int place = 0;
		int cnt = 0;
		while (place < N - 1) {
			place += me[cnt];
			if (place < N - 1) {
				place += masu[place];
			}
			cnt++;
		}

		cout << cnt << endl;
	}
}

Measured memory_bytes: 1168
s = int(input())
a = []
a.append(s)
n = 0
while True:
	if a[n]%2 == 0:
		an = a[n]/2
	else:
		an = 3*a[n] + 1
	if an in a:
		print(n+2)
		exit()
	else:
		a.append(an)
	n += 1


Measured memory_bytes: 38768
import collections
import sys
n = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1:
  print(n//2)
  sys.exit()
a1 = [a[x] for x in range(0,n,2)]
l_a1 = len(a1)
a2 = [a[y] for y in range(1,n,2)]
l_a2 = len(a2)
c1 = collections.Counter(a1)
c2 = collections.Counter(a2)
K_a1 = c1.most_common()[0][0]
K_a2 = c2.most_common()[0][0]
F_a1 = c1.most_common()[0][1]
F_a2 = c2.most_common()[0][1]
if K_a1 == K_a2:
  if  F_a1 > F_a2:
    F_a2 = c2.most_common()[1][1]
  elif F_a1 == F_a2:
    if  c1.most_common()[1][1] >  c2.most_common()[1][1]:
      F_a1 =  c1.most_common()[1][1]
    else:
      F_a2 =  c2.most_common()[1][1]
  else:
    F_a1 = c1.most_common()[1][1]
print((l_a1 - F_a1)+(l_a2 - F_a2))

Measured memory_bytes: 24668
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N;
    ll ans = 111;
    while(N > ans) ans += 111;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
// review
#include <iostream>

using namespace std;
const int MAXN = 50;
const int MAXV = 500;
const int INF = 1e9;

int n, ma, mb;
int a[MAXN], b[MAXN], c[MAXN];
int dp[MAXN][MAXV][MAXV]; // ijk: min cost for 1-ith, a is j gram and b is k gram

void solve() {
  for (int i=0;i<=n;i++) {
    for (int j=0;j<MAXV;j++) {
      for (int k=0;k<MAXV;k++) {
        dp[i][j][k] = INF;
      }
    }
  }
  dp[0][0][0] = 0;
  for (int i=0;i<n;i++) {
    for (int j=0;j<MAXV;j++) {
      for (int k=0;k<MAXV;k++) {
        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]); // Do not use ith
        dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]); // Do use ith
      }
    }
  }

  int ans = INF;
  for (int i=1;i<MAXV;i++) {
    for (int j=1;j<MAXV;j++) {
      if (i * mb == j * ma) {
        ans = min(ans, dp[n][i][j]);
      }
    }
  }
  if (ans == INF) {
    ans = -1;
  }
  cout << ans << endl;
}

int main() {
  cin >> n >> ma >> mb;
  for (int i=0;i<n;i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  solve();
}


Measured memory_bytes: 41216
import heapq
def topologicalsort(N,E):
    V = [0]*N
    for i in range(N):
        for y in E[i]:
            V[y] += 1
    S = [ i for i in range(N) if V[i] == 0]
    SORTED = []
    while S:
        s = S.pop(0)
        SORTED.append(s)
        for t in E[s]:
            V[t] -= 1
            if V[t] == 0:
                S.append(t)
    return SORTED
    
N, M = map( int, input().split())
E = [ [] for _ in range(N)]
for _ in range(M):
    x, y = map( int, input().split())
    x, y = x-1, y-1
    E[x].append(y)
V = topologicalsort(N, E)
ANS = [0]*N
for i in range(N):
    v = V[i]
    t = ANS[v]+1
    for e in E[v]:
        if t > ANS[e]:
            ANS[e] = t
print( max(ANS))

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

int readInt(){
  int ret = 0;
  char c;
  while((c=getchar()) && '0' <= c && c <= '9'){
    ret = ret * 10 + (c-'0');
  }
  return ret;
}

main(){
  int n,s;
  while(true){
    n = readInt();
    if (n==0)break;
    s = readInt();

    int r[101]={0};
    for(int i=0;i<n;i++){
      int tmp;tmp=readInt();r[tmp]++;
    }
    int ans = 0;
    for(int i=1;i<101;i++){
      if (i+i > s && r[i])ans += (r[i]*(r[i]-1))/2;
      for(int j=i+1;j<101;j++){
	if (i+j > s)ans += r[i]*r[j];
      }
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**9)

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

root = [-1] * n

# 親を返す
def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]


def unite(x,y):
    x = r(x)
    y = r(y)
    if x==y:
        return
    root[x] += root[y]
    root[y] = x


def size(x):
    x = r(x)
    return -root[x]

for i in range(m):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    unite(x,y)

max_size = 0
for i in range(n):
    max_size = max(max_size, size(i))

print(max_size)

Measured memory_bytes: 35700
#include <stdio.h>

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	long long K, N;
	scanf("%lld %lld", &N, &K);
	
	long long i, j, ans[2001] = {};
	for (i = 1; i <= K && i <= N - K + 1; i++) {
		for (j = K - 1, ans[i] = 1; j >= K - i + 1; j--) ans[i] = ans[i] * j % 1000000007;
		for (j = i - 1; j >= 2; j--) ans[i] = div_mod(ans[i], j, 1000000007);
		for (j = N - K + 1; j >= N - K - i + 2; j--) ans[i] = ans[i] * j % 1000000007;
		for (j = i; j >= 2; j--) ans[i] = div_mod(ans[i], j, 1000000007);
	}
	
	for (i = 1; i <= K; i++) printf("%lld\n", ans[i]);
	fflush(stdout);
	return 0;
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define dbg(x) cout<<#x<<"="<<x<<endl

int main(){

  int N;
  string S;
  cin>>N>>S;

  int res=0;
  rep(i,N){
    if(S[i]!='.')continue;
    string T=S;
    T[i]='W';
    bool ok1=true,ok2=true;
    {
      int j=i;
      while(j<N&&T[j]=='W')j++;
      if(j<N&&T[j]=='B')ok1=false;
    }
    {
      int j=i;
      while(j>=0&&T[j]=='W')j--;
      if(j>=0&&T[j]=='B')ok2=false;
    }

    if(!ok1&&!ok2)continue;

    int sum=0;
    {
      int j=i+1;
      int cnt=0;
      while(j<N&&T[j]=='B'){
        cnt++;
        j++;
      }
      if(j<N&&T[j]=='W')sum+=cnt;
    }
    {
      int j=i-1;
      int cnt=0;
      while(j>=0&&T[j]=='B'){
        cnt++;
        j--;
      }
      if(j>=0&&T[j]=='W')sum+=cnt;
    }
    res=max(res,sum);
  }

  cout<<res<<endl;

  return 0;
}



Measured memory_bytes: 3200
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		
		List <Integer>[]  L = new ArrayList [m];
		
		for(int i = 0 ;i < m ;i++) {
			L[i] = new ArrayList <Integer>();
		}
		
		for(int i = 0; i < n ;i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			if(m - a >= 0) {
				L[m-a].add(b);
			}
		}
		int ans = 0;
		PriorityQueue <Integer> pq = new PriorityQueue<Integer>(Comparator.reverseOrder());
		
		for(int day = m-1 ; day >= 0 ; day--) {
			for(int num : L[day]) {
				pq.add(num);
			}
			if(!pq.isEmpty()) {
				ans += pq.poll();
			}
		}
		
		System.out.println(ans);
	}
}



Measured memory_bytes: 68816
N = int(input())

lst = [-1] * N

r = 0
print (r)
s = str(input())
if s == 'Vacant':
    exit()
elif s == 'Male':
    lst[r] = 1
else:
    lst[r] = 0

l = N - 1

print (l)
s = str(input())
if s == 'Vacant':
    exit()
elif s == 'Male':
    lst[l] = 1
else:
    lst[l] = 0


# print (r, l)
while True:
    mid = (l + r) // 2
    print (mid)
    s = str(input())
    if s == 'Vacant':
        exit()
    elif s == 'Male':
        lst[mid] = 1
    else:
        lst[mid] = 0

    if (mid - r) % 2 == 0: #間が奇数個
        if lst[r] == lst[mid]: #この間に空席がない可能性あり
            r = mid
        else:
            l = mid
    else: #間が偶数個
        if lst[r] == lst[mid]: #この間に空席がない可能性あり
            l = mid
        else:
            r = mid

    # print (r, l)

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

int main() {
	int n;
	int taroScore = 0, hanaScore = 0;
	string taro, hana;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> taro >> hana;
		if (taro == hana) {
			taroScore += 1;
			hanaScore += 1;
		}
		else if (taro > hana) taroScore += 3;
		else if (taro < hana) hanaScore += 3;
	}
	cout << taroScore << " " << hanaScore << endl;
	return 0;
}

Measured memory_bytes: 1208
s = input()
n = len(s)
a=[0] #aはiのフラグが立っている位置、sのスライスのために使う
sum = 0
if n == 1:
    print(s)
else:
    for i in range(2 ** (n-1)): # iは二進数表記にしたとき隙間に+を入れるかどうかのフラグ
        for j in range(n-1):
            if i >> j & 1: a.append(j+1) # 二進数表記iをj右にシフトしフラグが立っているかどうか判断しその位置をaに加える
        else:
            a.append(n)
            for k in range(len(a)-1):
                sum += int(s[a[k]:a[k+1]])
            else:
                a = [0]
    else:
        print(sum)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
  
signed main(){
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);
  
  int n,m,x;
  cin >> n >> m >> x;
  vector<pair<int, vector<int>>> p(n); 
  REP(i, n){
    int c;
    cin >> c;
    vec a(m);
    REP(j, m){
      cin >> a[j];
    }
    p[i] = make_pair(c, a);
  }

  int ans = INF;
  REP(i, 1 << n){
    int cost = 0;
    vec a(m, 0);
    REP(j, n){
      if(i >> j & 1){
        cost += p[j].first;
        REP(k, m) a[k] += p[j].second[k]; 
      }
    }
    bool f = true;
    REP(j, m) f &= a[j] >= x;
    if(f) ans = min(ans, cost);
  }

  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cout<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
  
#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;

#define MAX 1000000005

int t[200001];
int main(){
  fill_n(t,200001,1);
  int n,m; cin >> n >> m;
  rep(i,m){
    int a,b; cin >> a >> b;
    if(a==1 && t[b]%2){
      t[b] *= 2;
    }
    if(b==n && t[a]%3){
      t[a] *= 3;
    }
    if(t[a] %6 == 0 || t[b] % 6 == 0){
      cout << "POSSIBLE"<<endl;return 0;
    }
  }
  
  cout << "IMPOSSIBLE"<<endl;
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  int d[n],c[n];
  mem(d);
  fill(c,c+n,1);
  d[0]=1;
  rep(i,m) {
    int x,y;
    cin >> x >> y;
    x--,y--;
    d[y]|=d[x];
    c[y]++;
    c[x]--;
    if(!c[x]) d[x]=0;
  }
  int ans=0;
  rep(i,n) ans+=d[i];
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

void swap(int *a, int *b){
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

int partition(int *A, int p, int r){
  int x = A[r];
  int i = p-1;
  int j;
  for(j=p; j<r; j++){
    if(A[j] <= x){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}

int main(){
  int *A;
  int i,n,q;

  // input and allocation
  scanf("%d",&n);
  A = (int *)malloc(sizeof(int) * n);
  for(i=0; i<n; i++){
    if(i == n-1) scanf("%d",&A[i]);
    else scanf("%d ",&A[i]);
  }

  // partition
  q = partition(A,0,n-1);

  // output
  for(i=0; i<n; i++) printf((i == q) ? ((i == n-1) ? "[%d]\n" : "[%d] ")
			    : (i == n-1) ? "%d\n"
			    : "%d " ,A[i]);

  free(A);

  return 0;
}

Measured memory_bytes: 888
#include <stdio.h>

int main(void){
  long i;
  long count;//連続してる数を数える
  long max=0;//最大値を求める
  long N;


  scanf("%ld", &N);

  long long H[N];

  for(i=0; i<N; i++){
    scanf("%lld", &H[i]);
  }

  count=0;
  for(i=0; i<=N-2; i++){

    if(H[i]>=H[i+1]){
      count++;

      if(i==N-2 && count>max){
        max=count;
      }
      
    }else{
      if(count>max){
        max=count;
      }
      count=0;
    }
  }

  printf("%ld\n", max);

  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#define PRIME 1000000007
using namespace std;
long long pow(int b, int e){
	long long ret = 1;
	for(int i=0; i<e; i++)
		ret = ret * b % PRIME;
	return ret;
}
long long base = pow(10, 100);
long long o2 = 500000004;
int main(){
	long long N, K;
	cin >> N >> K;
	long long lb = 0, ub = 0, ans = 0;
	for(int k=1; k<=N+1; k++){
		lb = (lb + k-1);
		ub = (ub + N-k+1);
		if(k >= K)
		ans = (ans + (ub - lb + 1)) % PRIME;
	}
	cout << ans % PRIME << endl;
}




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

int main(){
  int a,b;
  cin >> a >> b;
  
  int total = 0;
  for (int i=1;i<=a;i++) {
    if (i==a) {
      if (a<=b) total++;
    }
    else total++;
  }
  
  cout << total << endl;
  
  return 0;
}

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

int n, x, y;
int p[200003];
bool used[200003];
	


int main (){
	
	cin >> n >> x;
	
	if (x==1 || x==2*n-1)
		cout << "No" << endl;
		
	else
	{
		y=1;
		p[n] = x;
  		p[n-1] = 1;
  		p[n+2] = 2;
  		p[n+1] = 2*n-1;

  		if (x == 2) 
		{
			p[n-1] = 2*n-1;
    		p[n+2] = 2*n-2; 
			p[n+1] = 1;
		}
		
		used[p[n]]= true;
		used[p[n-1]]=true;
		used[p[n+1]]=true;
		used[p[n+2]]=true;
		
		for (int i = 1; i <= 2*n-1; i++)
		{
			if (p[i]==0)
			{
				if (used[i]!=true)
				{
					used[i]=true;
					p[i]=i;
				}
			
			else
			{
				while (used[y]!=false)
					y++;
					
				p[i]=y;
				used[y]=true;
				y++;
			}
				
			}
			
		}
		
		cout << "Yes" << endl;
		for (int i = 1; i <= 2*n-1; i++)
		cout << p[i] << endl;	
		
	}
	
return 0;
	
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int m=10000;
  for(int i=0;i<s.size()-2;i++){
    int j=i+1,k=i+2;
          int a=s[i]-'0',b=s[j]-'0',c=s[k]-'0';
          m=min(m,abs(753-(a*100+b*10+c)));
        
  }
  cout<<m;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <typeinfo>

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define all(x) (x).begin(),(x).end()
*/

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans=0;
    for (int i = 1; i <= n; i += 2)
    {
        int yakusuu = 0;
        for (int j = 1; j <= i; j += 2)
        {
            if (i % j == 0)
                yakusuu++;
        }
        if (yakusuu == 8)
            ans++;
    }
    cout << ans << endl;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  string b;
  cin >> b;
  string ret;
  if(b == "A") ret = "T";
  if(b == "T") ret = "A";
  if(b == "C") ret = "G";
  if(b == "G") ret = "C";
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(void){
    vector<int> v; 
    long long N,tmp_max_height,tmp_num,ans=0;

    cin >> N;  

    for(int i =0;i<N;i++){
        cin >> tmp_num;
        v.push_back(tmp_num);
    }
    
    tmp_max_height=v[0];
    
    for(int i =0;i<v.size();i++){
//        cout << tmp_num << endl;
        if(tmp_max_height>v[i]){
            ans = ans + tmp_max_height-v[i];
        }else if(tmp_max_height<v[i]){
            tmp_max_height = v[i];
        }
    }

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

Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n;

bool judge(int x)
{
    int k = n;
    while(k%x==0) k/= x;
    k %= x;
    return k == 1;
}

int solve(int x)
{   
    if(x == 2) return 1;
    int ans = 0;
    for(int i = 2; i <= sqrt(x); i++) 
    {
        if(x%i == 0)
        {
            if(judge(i)) ans++;
        }
        else if((x-1)%i == 0)
        {   
            ans += 2;
            if(i*i == x-1) ans--;
            //cout<<i<<' '<<(x-1)/i<<endl;
        }
    }
    return ans+2;
}

signed main()
{
#ifdef ONLINE_JUDGE
#else
    //freopen("data.in", "r", stdin);
#endif
    cin>>n;
    cout<<solve(n)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define maxN 1000001
#define mod 1000000007
#define maxLL 1000000000000000000
typedef long long ll;

bool compared(int a,int b){
	return a < b;
}

int cmp(const void *a,const void *b){
	return(*(int*)b - *(int*)a);
}

int GCD(int a,int b){
	return b?GCD(b,a%b):a;
}

int main(){
	string a;
	cin>>a;
	if(a[a.size()-1] == '2' || a[a.size()-1] == '4' || a[a.size()-1] == '5' || a[a.size()-1] == '7' || a[a.size()-1] == '9'){
		puts("hon");
	}
	else if(a[a.size()-1] == '0' || a[a.size()-1] == '1' || a[a.size()-1] == '6' || a[a.size()-1] == '8'){
		puts("pon");
	}
	else{
		puts("bon");
	}
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int inf = 2e18;  
const int mod1 = 998244353;
const int mod = 1e9 + 7;
const int nax = 100005;
int x,y,A,B,C,a[nax],b[nax],c[nax];

void solve()
 {
  cin>>x>>y>>A>>B>>C;
  loop(i,1,A+1)
   cin>>a[i];
  loop(i,1,B+1)
   cin>>b[i];
  loop(i,1,C+1)
   cin>>c[i];
  sort(a+1,a+A+1,greater<int>());
  sort(b+1,b+B+1,greater<int>());
  sort(c+1,c+C+1,greater<int>());
  multiset<int> red,green;
  int r = 0,g = 0;
  loop(i,1,x+1)
  {
    r += a[i];
    red.insert(a[i]);
  }
  loop(i,1,y+1)
  {
    g += b[i];
    green.insert(b[i]);
  }
  int pos = 1;
  while(pos<=C)
     {
      int red_least = *(red.begin());
      int green_least = *(green.begin());
      if((c[pos]>red_least && c[pos]<green_least) || (c[pos]>red_least && c[pos]>green_least && red_least <= green_least))
         {
          red.erase(red.begin());
          r -= red_least;
          red.insert(c[pos]);
          r += c[pos];
          pos++;
         }
      else if((c[pos]<red_least && c[pos]>green_least) || (c[pos]>red_least && c[pos]>green_least && red_least > green_least))
         {
          green.erase(green.begin());
          g -= green_least;
          green.insert(c[pos]);
          g += c[pos];
          pos++;
         }
      else 
         break;
     }
  cout<<r+g;
 }
signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
  solve();
  // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
} 

Measured memory_bytes: 14388
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <cmath>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  double ans = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
  ans = pow(ans, 0.5);
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}



Measured memory_bytes: 3416
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#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 FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 1999999999
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

#ifdef INPUT
stringstream input(R"(
10 587586158 185430194
894597290 708587790
680395892 306946994
590262034 785368612
922328576 106880540
847058850 326169610
936315062 193149191
702035777 223363392
11672949 146832978
779291680 334178158
615808191 701464268
)");
#define cin input
#endif

int main()
{
    int n, h, w, a, b;
    cin >> n >> h >> w;

    int count = 0;
    for (int i=0; i<n; i++)
    {
        cin >> a >> b;
        if (a>=h && b>=w)
            count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
Plus = defaultdict(int)
for _ in range(N):
	s = input()
	Plus[s] += 1

M = INT()
Minus = defaultdict(int)
for _ in range(M):
	s = input()
	Minus[s] += 1

ans = 0
for x in Plus:
	ans = max(ans, Plus[x]-Minus[x])

print(ans)

Measured memory_bytes: 5200
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  double r;
  int i,j;
  while(cin>>r,r){
    for(i=1;i<1000000;i++){
      j=M_PI*i;
      if( fabs( (double)j/i-M_PI ) <= r )break;
      j++;
      if( fabs( (double)j/i-M_PI ) <= r )break;
    }
    printf("%d/%d\n",j,i);
  }
}

Measured memory_bytes: 0
import sys
N,K = map(int,input().split())
Data = list(map(int,input().split()))
Move = K
if 0 in Data:
    Move -= 1
Pos = []
Neg = []
for d in Data:
    if d > 0:
        Pos.append(d)
    if d < 0:
        Neg.append(-d)
Pos.sort()
Neg.sort()
posMaxRange = min(Move,len(Pos))
negMaxRange = min(Move,len(Neg))

if Move == 0:
    print(0)
    sys.exit()

minlen = -1
for t in range(1,posMaxRange+1):
    distance  = Pos[t-1]
    left = Move-t
    if left > 0:
        if len(Neg) < left:
            continue
        distance += Pos[t-1]
        distance += Neg[left-1]

    if minlen == -1:
        minlen = distance
    else:
        if minlen > distance:
            minlen = distance

for t in range(1,negMaxRange+1):
    distance = Neg[t-1]
    left = Move - t
    if left > 0:
        if len(Pos) < left:
            continue
        distance += Neg[t-1]
        distance += Pos[left-1]

    if minlen == -1:
        minlen = distance
    else:
        if minlen > distance:
            minlen = distance

print(minlen)

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

const int INF = 1e9;

int main() {
  string s;
  string t;
  cin>>s;
  cin>>t;
  vector<int> pos;
  for(int i=0;i<s.length()-t.length()+1;i++){
    bool flag=true;
    for(int j=0;j<t.length();j++){
      if(s[i+j]==t[j]||s[i+j]=='?'){
        continue;
      }
      flag=false;
      break;
    }
    if(flag){
      pos.push_back(i);
    }
  }
  if(pos.size()==0){
    cout<<"UNRESTORABLE"<<endl;
    return 0;
  }

  vector<string> ans;
  for(int p: pos){
    string tmp="";
    for(int i=0;i<s.length();i++){
      if(i>=p&&i<p+t.length()){
        tmp+=t[i-p];
      }else if(s[i]!='?'){
        tmp+=s[i];
      }else{
        tmp+='a';
      }
    }
    ans.push_back(tmp);
  }
  sort(ans.begin(), ans.end());
  cout<<ans[0]<<endl;

}

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

#define ll long long
using namespace std;

ll solve()
{
	int N;
    cin>>N;
	++N;
	vector<ll> A(N);
    for(ll &a : A)
        cin>>a;
	vector<ll> B(N);
	B[N-1] = A[N-1];
	for(int i=N-2; i>=0; --i)
	{
		B[i]=B[i+1]+A[i];
	}
	B[0]=1;
	if(B[0]<A[0])
		return -1;
	for(int i=1; i<N;++i)
	{
		ll prev = B[i-1]-A[i-1];
		B[i]=min(B[i],prev*2);
		if(B[i]<A[i])
			return -1;
	}
	ll ans = 0;
	for(auto &a: B)
		ans+=a;
	return ans;
}

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

    cout<<solve()<<endl;
	return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N;
    string S;
    cin >> N;

    vector<ll> p(N);
    REP(i,N){
        cin >> p.at(i);
    }

    ll ans = 0;

    REP(i,N-1){
        if(p.at(i)==(i+1)){
            swap(p.at(i), p.at(i + 1));
            ans++;
        }
    }

    if (p.at(N-1) == N){
        swap(p.at(N - 1), p.at(N - 2));
        ans++;
    }

        cout << ans << endl;
}


Measured memory_bytes: 3972
def main():
    N, M, X = map(int, input().split())
    A = [int(a) for a in input().split()]
    costL = 0
    for i in range(len(A)):
        if A[i] < X:
            costL += 1
    return min(costL, M-costL)
    
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
/*I wanna be the very best, like no one ever was...*/

#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);
 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif


int main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
  

    int n,r;
    cin>>n>>r;
    n = n>10? 10:n;
    cout<<r +(100*(10-n))<<endl;
 
 
    
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int N;
    cin >> N;
    vector<double> v;
    for (int i=0; i<N; i++) {
        double temp;
        cin >> temp;
        v.push_back(temp);
    }

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

    double result = v[0];
    for (int i=0; i<N; i++) {
        result = (result+v[i])/2;
    }
    cout << setprecision(10) << fixed << result;
    
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      string A,B;
      cin>>A>>B;
      int n=A.length(),m=B.length();
      vector<vector<int>>dp(n+1,vector<int>(m+1,0));
      for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                  dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                  if(A[i-1]==B[j-1])dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
            }
      }
      int x=n,y=m;
      string ans;
      while(x>0&&y>0){
            while(x>0&&dp[x-1][y]==dp[x][y])x--;
            while(y>0&&dp[x][y-1]==dp[x][y])y--;
        	if(x>0&&y>0)
            ans.pb(A[x-1]);
            x--,y--;
      }
      reverse(all(ans));
      cout<<ans;
}


Measured memory_bytes: 70784
a, v = input().split(" ")
a = int(a)
v = int(v)

b, w = input().split(" ")
b = int(b)
w = int(w)

t = int(input())

if w > v:
	print ("NO")
elif w == v:
	if a == b:
		print ("YES")
	else:
		print ("NO")
else:
	tt = abs(b - a) / abs(v - w)
	if tt <= t:
		print ("YES")
	else:
		print ("NO")

Measured memory_bytes: 9204
#include<iostream>

using namespace std;

int main () {

        int H,W;
        cin >> H >> W;
        while (H || W) {
                for (int i = 0; i < H; i++) {
                        for (int j = 0; j < W; j++) {
                                if (!i || i == H - 1 || !j || j == W - 1) {
                                        cout << "#";
                                } else {
                                        cout << ".";
                                }
                        }
                        if (W > 0) {
                                cout << endl;
                        }
                }
                cout << endl;
                cin >> H >> W;
        }

        return 0;

}

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}


inline int addmod(int x,int y)
{
    return (x%mod + y%mod)%mod;
}
inline int submod(int x,int y)
{
    return (x%mod - y%mod + mod)%mod;
}
inline int mulmod(int x,int y)
{
    return (x%mod *1LL* y%mod)%mod;
}

inline int nextSubMask(int i, int mask)
{
    return (i-1)&mask;   /// returns next  submask
}

template<typename T>
void we_r_done(T mssg)
{
    cout<<mssg;
    exit(0);
}


int main()
{
    ///freopen("output.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    lli ans = -1;
    for(lli i=1; (i*i)<=m; i++){
        if(m%i) continue;
        lli d = m/i;
        if(i>=n) ans = max(ans , d);
        if(d>=n) ans = max(ans , i);
    }
    assert(ans != -1);
    cout<<ans;



    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?
///sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b : x.a<y.a);});


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

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

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let b = read::<String>();
  let a = read::<String>();
  let mut x = 0;
  let mut max_x = 0;
  for c in a.chars() {
    if c == 'I' {
      x += 1;
      max_x = max(max_x, x)
    } else {
      x -= 1;
    }
  }

  println!("{}", max_x);
}



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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

ll mod = 1e9 + 7ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;

int main(){
    int n;
    scanf("%d", &n);
    vector<int> L(n);
    rp(i, 0, n) {
        int s;
        scanf("%d", &s);
        L.at(i) = s;
    }
    sort(L.begin(), L.end());
    int ans = 0;
    rp(i, 0, n) {
        int a = L.at(i);
        rp(j, i+1, n) {
            int b = L.at(j);
            ans += lower_bound(L.begin(), L.end(), a+b) - L.begin() - (j+1);
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3804
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int cmp(const void *a,const void *b){
  return *(char*)a - *(char*)b;
}

int scmp(const void *a,const void *b){
  return strcmp((char *)a,(char *)b);
}


int main(){
  long long n = 0;
  char str[100000][20] = {};
  long long cnt = 0;
  long long hoge[100000] = {};
  long long i = 0;
  long long total = 0;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf(" %s",str[i]);
    qsort(str[i],10,sizeof(char),cmp);
  }
  
  qsort((void*)str,n,sizeof(str[0]),scmp);
  
  cnt = 0;
  hoge[0] = 1;
  for(i=1;i<n;i++){

    if(!strcmp(str[i-1],str[i])){
      hoge[cnt]++;
      //printf("#");
      //printf("%d-%d/",cnt,hoge[cnt]);
    }else{
      cnt++;
      hoge[cnt] = 1;
      //printf("%d-%d/",cnt,hoge[cnt]);
    }
  }
  //printf("%d/",hoge[i]);
  for(i=0;i<=cnt;i++){
    total += hoge[i]*(hoge[i]-1)/2;
  }
    
  printf("%lld",total);
  /*for(i=0;i<n;i++){
    printf("%s\n",str[i]);
  }*/
  return 0;
}

Measured memory_bytes: 4860
#include<stdio.h>

int main()
{
  int A, B, C, chan, r;
  scanf("%d %d %d", &A, &B, &C);
  
  if (B > C)
  {
    chan = B;
      B = C;
      C = chan;
  }
  
   
   if (A > C)
  {
    chan = A;
      A = C;
      C = chan;
  }
  
  printf("%d", 10*C + A +B);
  
  return 0;
}
      
  
		

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int m, k;
    cin >> m >> k;
    vector<int> ans;

    if(1 << m <= k)
    {
        cout << "-1\n";
        return 0;
    }

    if(m == 1)
    {
        if(k == 1)
        {
            cout << "-1\n";
        }
        else
        {
            cout << "0 0 1 1\n";
        }
        return 0;
    }
    ans.push_back(k);
    for(int i = 0; i < (1 << m); i++)
    {
        if(i != k)
            ans.push_back(i);
    }
    ans.push_back(k);
    for(int j = ans.size() - 1; j >= 0; j--)
    {
        if(ans[j] != k)
            ans.push_back(ans[j]);
    }
    for(int i = 0; i < ans.size(); i++)
    {
        if(i) cout << " ";
        cout << ans[i];
    }
    return 0;
}


Measured memory_bytes: 2932
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	int d = Integer.parseInt(sc.next());
	int[][] a = new int[n][d];
	int c = 0;
	int e = 0;
	int count = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < d; j++){
			a[i][j]= Integer.parseInt(sc.next());
		}
	}
	for(int i = 0; i < n - 1; i++){
		for(int j = i + 1; j < n; j++){
			for(int k = 0; k < d; k++){
	c += (a[i][k] - a[j][k])*(a[i][k] - a[j][k]);
			}
			e = (int)Math.sqrt(c);
			if(c == e * e)count++;
			c=0;
		}
	}
	System.out.println(count);
}
}


Measured memory_bytes: 23764
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{

    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var N = int.Parse(inputs[0]);
        var A = int.Parse(inputs[1]);
        var B = int.Parse(inputs[2]);
        var C = int.Parse(inputs[3]);
        var l = new int[N];
        for (int i = 0; i < l.Length; i++)
        {
            l[i] = int.Parse(Console.ReadLine());
        }
        var param = new Parameter(N, A, B, C, l);

        var result = dfs(0, 0, 0, 0, param);
        Console.WriteLine(result);
    }

    static int dfs(int depth, int a, int b, int c, Parameter param)
    {
        if (depth == param.N)
        {
            // A,B,Cのいずれかが0以下の場合を除外する
            var ok = a > 0 && b > 0 && c > 0;
            if (!ok)
            {
                return 1000000000;
            }

            // 最初にA,B,Cに割り当てられた竹は合成ではないので、引いておく
            return Math.Abs(a - param.A) + Math.Abs(b - param.B) + Math.Abs(c - param.C) - 30;
        }

        // 何もしない
        var ret1 = dfs(depth + 1, a, b, c, param);
        // 合成にかかわらず10MPを使用することとし、最後に調整する
        // Aに使用する
        var ret2 = dfs(depth + 1, a + param.l[depth], b, c, param) + 10;
        // Bに使用する
        var ret3 = dfs(depth + 1, a, b + param.l[depth], c, param) + 10;
        // Cに使用する
        var ret4 = dfs(depth + 1, a, b, c + param.l[depth], param) + 10;

        // 最小コストを決定する
        var minArrays = new int[] { ret1, ret2, ret3, ret4 };
        int min = int.MaxValue;
        for (int i = 0; i < minArrays.Length; i++)
        {
            min = Math.Min(minArrays[i], min);
        }
        return min;
    }

    struct Parameter
    {
        internal int N;
        internal int A;
        internal int B;
        internal int C;
        internal int[] l;
        internal Parameter(int N, int A, int B, int C, int[] l)
        {
            this.N = N;
            this.A = A;
            this.B = B;
            this.C = C;
            this.l = l;
        }
    }
}



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

int main() {
    int n, b, a;
    cin >> n;
    multimap<int, int> work = {};
    for (int i = 0; i < n; ++i) {
        cin >> b >> a;
        work.emplace(a, b);
    }
    int now = 0;
    auto itr = work.begin();
    for (int j = 0; j < n; ++j) {
        for (; ;) {
            now += itr -> second;
            if (now > itr -> first) {
                cout << "No" << endl;
                return 0;
            }
            ++itr;
            break;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 9600
import heapq


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

edges = []
for i in range(m):
    s, t, w = map(int, input().split())
    heapq.heappush(edges, (w, s, t))

cost = 0
roots = [i for i in range(n)]
clusters = {i: {i} for i in range(n)}

while len(edges) > 0:
    w, s, t = heapq.heappop(edges)

    if roots[s] != roots[t]:
        cluster = clusters.pop(roots[t])
        for elem in cluster:
            roots[elem] = roots[s]
        clusters[roots[s]] |= cluster
        cost += w

print(cost)



Measured memory_bytes: 27100
pr = [True] * 1001
n = int(input())
ans = 1

for i in range(2, n + 1):
    if pr[i]:
        for j in range(i * 2, n + 1, i):
            pr[j] = False
        cnt = 0
        now = n
        while now:
            cnt += now // i
            now //= i
        ans *= (cnt + 1)

print(ans % 1000000007)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int A = Integer.parseInt(scanner.next());
        int B = Integer.parseInt(scanner.next());
        for (int i = 1; i < 4; i++) {
            if (i == A | i == B) {
                continue;
            } else {
                System.out.println(i);
            }
        }
    }

}


Measured memory_bytes: 22996
import scala.io.StdIn.{readInt,readLine}

object Main {
  def play(a:Int,b:Int,i:Int):(Int,Int) = {
    if(i==0) (a,b)
    else {
      val l = readLine.split(" ").map(_.toInt);val x = l(0);val y = l(1)
      if(x>y) play(a+x+y,b,i-1)
      else if(x<y) play(a,b+x+y,i-1)
      else play(a+x,b+y,i-1)
    }
  }

  def main(args:Array[String]) = {
    var n = 0
    while( { n = readInt; n } > 0 ) {
      val (a,b) = play(0,0,n)
      println(a + " " + b)
    }
  }
}

Measured memory_bytes: 55512
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

n = int(input())
edge = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a)

d1 = [-1] * n
d2 = [-1] * n
def dfs(v, d):
    for v_next in edge[v]:
        if d[v_next] == -1:
            d[v_next] = d[v] + 1
            dfs(v_next, d)

d1[0] = 0
dfs(0, d1)
d2[-1] = 0
dfs(n-1, d2)

n_f = 0
for i in range(n):
    if d1[i] <= d2[i]:
        n_f += 1

if n_f > n // 2:
    ans = "Fennec"
else:
    ans = "Snuke"
print(ans)


Measured memory_bytes: 117656
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    int r = x%y;
    if (r == 0) {
        return y;
    }
    return gcd(y, r);
}

ll mypow(ll x, ll n) {
    if (n == 0) return 1;
    if (n%2 == 0) return mypow(((x%mod)*(x%mod))%mod, n/2);
    else return ((x%mod) * mypow(((x%mod)*(x%mod))%mod, (n-1)/2))%mod;
}

int main(){
    int S, W;
    cin >> S >> W;
    if (S > W) cout << "safe" << endl;
    else cout << "unsafe" << endl;
}

Measured memory_bytes: 3632
cards = []
for i in range(4):
    if i == 0:
        a = "S "
    elif i == 1:
        a = "H "
    elif i == 2:
        a = "C "
    else:
        a = "D "
    for j in range(13):
        cards.append(a+str(j+1))
N = int(input())
for z in range(N):
    card = input()
    cards.remove(card)
for lose in cards:
    print(lose)
        
    


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
template<typename T> ostream& operator<<(ostream& os, vector<T> a){os<<"( ";for(T &x:a)os<<x<<" ";os<<")\n";return os;}
template<typename T> ostream& operator<<(ostream& os, set<T> a){os<<"( ";for(T x:a)os<<x<<" ";os<<")\n";return os;}
template<typename T> ostream& operator<<(ostream& os, pair<T,T> a){os<<"("<<a.first<<" "<<a.second<<") ";return os;}
template<typename T> ostream& operator<<(ostream& os, complex<T> a){os<<"(r="<<a.real()<<" i="<<a.imag()<<") ";return os;}
typedef long long ll;
typedef double dd;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;
#define all(a) a.begin(),a.end()
#define DEBUG 1
#define debug(a) if(DEBUG)cout<<#a<<" = "<<a<<endl
#define x first
#define y second
//===========================Head=========================//

bool solve(){
    string s;
    cin>>s;
    if (s[0]!='A') return 0;
    int flag=0;
    for (int i=2;i<s.size()-1;++i) flag += s[i]=='C';
    if (flag!=1) return 0;
    for (int i=1;i<s.size();++i) if (s[i]!='C'){
        if (s[i]>='A'&&s[i]<='Z') return 0;
    }
    return 1;
}

int main(int argc,char** argv){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (solve()) cout<<"AC";
    else cout<<"WA";
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
limit = 100000
mod = 10**9+7
lpow = [False] * (limit+1)
lpow[0] = 1
def pow(n,p):
    if p<0:return 0
    if lpow[p]:
        return lpow[p]
    else:
        if p % 2 == 0:
            ret = (pow(n,p//2)**2) % mod
        else:
            ret = ((pow(n,p//2)**2)*n) % mod
        lpow[p] = ret
        return ret

def main():
    s=input()
    res = 0
    ca = 0
    cc = s.count("C")
    cw = 0
    aw = s.count("?")
    for c in s:
        if c == "A":
            ca += 1
        elif c == "C":
            cc -= 1
        elif c == "B":
            res += ca*cc*pow(3,aw)+ca*(aw-cw)*pow(3,aw-1)+cw*cc*pow(3,aw-1)+cw*(aw-cw)*pow(3,aw-2)
            res %= mod
        elif c == "?":
            res += ca*cc*pow(3,aw-1)+ca*(aw-cw-1)*pow(3,aw-2)+cw*cc*pow(3,aw-2)+cw*(aw-cw-1)*pow(3,aw-3)
            res %= mod
            cw += 1

    print(res)

main()

Measured memory_bytes: 4084