akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    T = list(map(int, input().split()))
    total = sum(T)
    M = int(input())
    for _ in range(M):
        P, X = map(int, input().split())
        P -= 1
        print(total - T[P] + X)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4200
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int n,m; cin >> n >> m;
  vi p(m),y(m);
  vvi G(n);
  rep(i, m){
    cin >> p[i] >> y[i];
    G[--p[i]].push_back(y[i]);
  }

  rep(i, n) sort(all(G[i]));

  rep(i, m){
    cout << setfill('0') << setw(6) << p[i]+1;

    int x = lower_bound(all(G[p[i]]),y[i]) - G[p[i]].begin();
    std::cout << setfill('0') << setw(6) << x + 1 << '\n';
  }
}


Measured memory_bytes: 7808
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <atcoder/dsu>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;
using namespace atcoder;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;

int main(void) {
    int n, m;
    cin >> n >> m;
    dsu d(n);
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        d.merge(a, b);
    }
    auto v = d.groups();

    ans = (ll) sz(v);



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





Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define in insert
#define pi 3.14159265358979323846
#define rep(i,a,b) for(int i = a ; i < b ; i++)
#define repr(i,a,b) for(int i = b ; i > a ; i--)
  
long long fact(long long a, long long b){
    int r= max(a, b);
    int v= min(a, b);
    int l=1;
    // if(v==0)
    for(int i=r+1; i<=a+b; i++){
        l*=i;
    }
    for(int i=v; i>=2; i--){
        l/=i;
    }
    return l;
}

int gcd(int a, int b) { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
}

int powr(int a) { 
    int var=1;
    for(int i=0; i<a; i++){
        var*=2;
    }
    return var;
}

void func(int a, bool i){
    cout << a;
    if(a==100){
        i=1;
    }
    else if(a==0){
        return;
    }
    if(!i)
        func(a+1, i);
    else
        func(a-1, i);
}

signed main(){   
    fast;
    int n;
    cin >> n;
    double d[n];
    rep(i,0,n)
        cin >> d[i];
    double a[n][n+1];
    a[0][0]=1-d[0];
    a[0][1]=d[0];
    for(int i=1; i<n; i++){
        for(int j=0; j<=i+1; j++){
            if(j==0){
                a[i][j]=a[i-1][j]*(1-d[i]);
            }
            if(i+1==j){
                a[i][j]=a[i-1][j-1]*d[i];
            }
            else
                a[i][j] = a[i-1][j]*(1-d[i])+a[i-1][j-1]*d[i]; 
        }
    }
    double ans = 0;
    for(int i = (n+1)/2 ; i<=n ; i++){
        // cout << a[n-1][i] << " ";
        ans+=a[n-1][i];
    }
    cout << setprecision(10) << ans;
}

Measured memory_bytes: 49912
#include<cstdio>

#define FOR(i, a, b) for(int i = a; i <= b; i++)

const int MAX = 1e2 + 10;
int s[MAX], n;

void Print(void)
{
	FOR(i, 0, n - 1)
	{
		printf("%d", s[i]);
		if(i != n - 1)
			printf(" ");
		else
			printf("\n");
	}
	return;
}

int main()
{
	while(~scanf("%d", &n))
	{
		FOR(i, 0, n - 1)
			scanf("%d", &s[i]);
		Print();
		FOR(i, 1, n - 1)
		{
			int v = s[i];
			int j = i - 1;
			while(j >= 0 && s[j] > v)
			{
				s[j + 1] = s[j];
				j--;
			}
			s[j + 1] = v;
			Print();
		}
	}
	return 0;
}



Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define yes cout << "YES" \
                 << "\n"
#define no cout << "NO" \
                << "\n"
#define MOD 1000000007
using namespace std;
const double pi = 3.14159265358979323846;
const int MAX_CHARS = 256;

template <typename T>
T Maxnun(T x, T y)
{
    return (x > y) ? x : y;
}
long long fast_power(long long base, long long power)
{
    long long result = 1;
    while (power > 0)
    {

        if (power % 2 == 1)
        { // Can also use (power & 1) to make code even faster
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
template <typename T, typename X>
void pairsort(T a[], T b[], T n)
{
    pair<T, X> a_p[n];
    for (T i = 0; i < n; i++)
    {
        a_p[i].first = a[i];
        a_p[i].second = b[i];
    }
    sort(a_p, a_p + n);
    for (T i = 0; i < n; i++)
    {
        b[i] = a_p[i].second;
    }
}
ll power(ll x, ll y)
{
    ll res = 1; // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = res * x;

        // y must be even now
        y = y >> 1; // y = y/2
        x = x * x;  // Change x to x^2
    }
    return res;
}
ll kthRoot(ll n, ll k)
{
    return pow(k,
               (1.0 / k) * (log(n) / log(k)));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << std::max(std::max(b * d, b * c), std::max(a * c, a * d));
}


Measured memory_bytes: 3664
program main
	implicit none
	integer :: N, i, ans
	integer, allocatable :: V(:), C(:)
	read(*, *) N
	allocate(V(1:N), C(1:N))
	read(*, *) V(1:N)
	read(*, *) C(1:N)
	ans = 0
	do i = 1, N
		ans = ans + max(0,V(i)-C(i))
	end do
	write(*, *) ans
end program main

Measured memory_bytes: 256
using System;

namespace AtCoderProblems
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string str = Console.ReadLine();

            if(str.EndsWith("s"))
            {
                Console.WriteLine(str + "es");
            }
            else
            {
                Console.WriteLine(str + "s");
            }

        }
    }

}

Measured memory_bytes: 26132
#include<iostream>
#include<climits>
using namespace std;
struct ticket{
  int x,y,c;
}M_arr[100005];
int A[100005],B[100005];
int main(){
  int N,M,Q;
  long long int mn;
  int mn1=INT_MAX/2,mn2=INT_MAX/2;
  cin>>N>>M>>Q;
  for(int i=0; i<N; i++){
    cin>>A[i];
    mn1=min(mn1,A[i]);
  }
  for(int i=0; i<M; i++){
    cin>>B[i];
    mn2=min(mn2,B[i]);
  }
  mn=mn1+mn2;
  for(int i=0; i<Q; i++){
    cin>>M_arr[i].x>>M_arr[i].y>>M_arr[i].c;
    mn=min(mn,(long long)(A[M_arr[i].x-1]+B[M_arr[i].y-1]-M_arr[i].c));
  }
  cout<<mn<<endl;
  return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>
int n,i;
int a[300000],b[300000],c[300000],d[300000];
int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	for (i=1;i<=n;i++)
	  scanf("%d",&b[i]);
	for (i=1;i<=n;i++)
	  c[i]=b[n-i+1];
	int flag=1;
	for (i=1;i<=n;i++)
	  if (c[i]==a[i])
	    flag=0;
	if (flag==1){
		printf("Yes\n");
		for (i=1;i<=n;i++)
		  printf("%d ",c[i]);
		return 0;
	}
	for (i=1;i<=n;i++)
	  d[(i-1+n/2)%n+1]=b[i];
	flag=1;
	for (i=1;i<=n;i++)
	  if (d[i]==a[i])
	    flag=0;
	if (flag==1){
		printf("Yes\n");
		for (i=1;i<=n;i++)
		  printf("%d ",d[i]);
		return 0;
	}
	printf("No");
}

Measured memory_bytes: 4880
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve(); int main() { solve(); return 0; }

void solve() {
  map<string, int> M {
    { "SUN", 7 },
    { "MON", 6 },
    { "TUE", 5 },
    { "WED", 4 },
    { "THU", 3 },
    { "FRI", 2 },
    { "SAT", 1 },
  };
  string s; cin >> s;
  cout << M[s] << endl;
}


Measured memory_bytes: 3604
s = input()
f = int(s[0]+s[1])
b = int(s[2]+s[3])
if (f <= 12) & (f >= 1):
    if (b <= 12) and (b >= 1):
        print("AMBIGUOUS")
    else:
        print('MMYY')
        
else:
    if (b <= 12) and (b >= 1):
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> p;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    p.resize(n);
    for(auto &i : p) cin >> i;
    vector <int> v(n);
    for(int i = 0 ; i < n ; i++){
        p[i]--;
        v[p[i]] = i;
    }
    vector <int> a(n), b(n);
    b[0] = v[0];
    for(int i = 1 ; i < n ; i++){
        a[i] = a[i - 1];
        b[i] = b[i - 1];
        if(v[i] > a[i] + b[i]) a[i] = v[i] - b[i];
        else b[i] = v[i] - a[i];
        while(a[i] == a[i - 1] || b[i] == b[i - 1]){
            a[i]++;
            b[i]--;
        }
    }
    int mn = 1e9;
    for(int i = 0 ; i < n ; i++){
        mn = min(mn, min(a[i], b[i]));
    }
    for(int i = 0 ; i < n ; i++){
        a[i] += -mn + 1;
        b[i] += -mn + 1;
    }
    for(auto &i : a) cout << i << " ";
    cout << endl;
    for(auto &i : b) cout << i << " ";
    cout << endl;
}


Measured memory_bytes: 896
#include<stdio.h>
int main(void){
    int r;
    int d;
    int x2000;
    int x[10];
    int i;

    scanf("%d %d %d",&r,&d,&x2000);

    x[0]=r*x2000-d;
    for(i=1;i<10;i++){
        x[i]=r*x[i-1]-d;
    }

    for(i=0;i<10;i++){
        printf("%d\n",x[i]);
    }
    return 0;
}

Measured memory_bytes: 128
import functools

import os
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def inpm(line):
    return [inp() for _ in range(line)]


def inpfm(line):
    return [inpf() for _ in range(line)]


def inpsm(line):
    return [inps() for _ in range(line)]


def inlm(line):
    return [inl() for _ in range(line)]


def inlfm(line):
    return [inlf() for _ in range(line)]


def inlsm(line):
    return [inls() for _ in range(line)]


def Yesif(cond):
    print('Yes' if cond else 'No')


def YESIF(cond):
    print('YES' if cond else 'NO')


def yesif(cond):
    print('yes' if cond else 'no')




print('ABC' if int(input()) < 1200 else 'ARC')

Measured memory_bytes: 3684
n=int(input())
s=[]
# アルファベット(a〜z)→数値(1〜26)小文字限定
a2n = lambda c: ord(c) - ord('a') + 1
# 数値(1〜26)→アルファベット(a〜z)
n2a = lambda c: chr(c+64).lower()

for _ in range(n):
  s_=input()
  si=[]
  for i in range(1,27):
    si.append(s_.count(n2a(i)))
  s.append(si)
ans=''
#print(s)
for i in range(26):
  a=min([s[j][i] for j in range(len(s))])
  #print(str(a)+' '+n2a(a))
  ans+=n2a(i+1)*a
  
print(ans)




Measured memory_bytes: 3064
import sys
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
print(n**3)

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;


long long N;

int main(){
    cin >> N;
    cout << 50 << endl;
    for(int i = 0; i < 50; i++){
        if(i) cout << " ";
        cout << 49-i + (N+49-i) / 50;
    }
    cout << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    ll arr[n+1];
    int i;
    for(i=0;i<=n;i++)
        cin >> arr[i];
    ll max_nodes[n+1];
    max_nodes[n] = arr[n];
    for(i=n-1;i>=0;i--)
        max_nodes[i] = max_nodes[i+1] + arr[i];
    ll v = 1;
    ll ans = 0;
    bool ok = 1;
    for(i=0;i<=n;i++)
    {
       // cout << v << " " << arr[i] << '\n';
        v = min(v, max_nodes[i]);
        if(arr[i] <= v)
            ans+=v, v = 2*(v - arr[i]);
        else
        {
            ok = 0;
            break;
        }
    }
    if(!ok)
        cout << -1 << '\n';
    else    
    {
        cout << ans << '\n';
    }
}

Measured memory_bytes: 5184
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int mx = 0, sum = 0;
	rep(i,n){
		int l;
		cin >> l;
		chmax(mx, l);
		sum += l;
	}
	sum -= mx;
	if(mx < sum) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI acos(-1.0)
#define test() int t; cin>>t; while(t--)
#define ll long long int

int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	string s, t;
	cin >> s >> t;
	int mn = INT_MAX;
	bool b = false;
	for (int i = 0; i < s.length(); i++) {
		int cnt = 0;
		for (int j = 0; j < t.length(); j++) {
			if (i + j >= s.length()) {
				b = true;
				break;
			}
			if (s[i + j] != t[j])	cnt++;
		}
		if (b)	break;
		mn = min(mn, cnt);
	}
	cout << mn << endl;
	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>

using namespace std;

long long n, k;
long long a[500];
long long b[500];
long long c[500];
long long s;
long long ans = 0;

bool ok(int x)
{
    long long summ1 = 0, summ2 = 0;
    for (int i = 0; i < n; i++) c[i] = x - b[i];
    for (int i = 0; i < n; i++) summ2 += c[i];
    for (int j = 0; j <= n; j++)
    {
        if (max(summ1, summ2) <= k) return 1;
        if (j != n)
        {
            summ1 += b[j];
            summ2 -= c[j];
        }
    }
    return 0;
}

void check(int x)
{
    for (int i = 0; i < n; i++) b[i] = a[i] % x;
    sort(b, b + n);
    if (ok(x))
        ans = max(ans, (long long)x);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) {cin >> a[i]; s += a[i];}
    for (int i = 1; i * i <= s; i++)
    {
        if (s % i == 0)
        {
            check(i);
            check(s / i);
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int MAX = 1000000000;

int main()
{
    ll x;
    cin >> x;
    for (ll i = -1000; i < 1000;i++){
        for (ll j = -1000; j < 1000;j++){
           if(pow(i,5)-pow(j,5) ==  x){
               cout << i << " " <<j;
               return 0;
           }   
        }
    }
} 


Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n,T;
  cin >> n >> T;
  vector<int> c(n);
  vector<int> t(n);
  rep(i,n){
    cin >> c[i] >> t[i];
  }
  int ans=1001;
  rep(i,n){
    if(t[i]<=T){
      if(ans>c[i]){
        ans = c[i];
      }
    }
  }
  if(ans==1001){
    cout << "TLE" << endl;
  }else{
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#補助関数
def convert(num,radix):
    res = 0
    while num > 0:
        res += num % radix
        num //= radix
    return res

#入力
INF = (1 << 31)
N   = int(input())
ans = INF

#計算
for i in range(N + 1):
    dec6 = i
    dec9 = N - i
    ans  = min(ans , convert(dec6,6) + convert(dec9,9))

#出力
print(ans)


Measured memory_bytes: 3060
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

a,b=get_i
puts yn_judge(((a*b)%2).zero?,"Even","Odd")

Measured memory_bytes: 1788
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    int N;
    cin >> N;
    string result;
    vector<int> ans(4);
    REP (i, N) {
        cin >> result;
        if (result == "AC") {
            ans[0]++;
        } else if (result == "WA") {
            ans[1]++;
        } else if (result == "TLE") {
            ans[2]++;
        } else {
            ans[3]++;
        }
    }

    cout << "AC x " << ans[0] << endl;
    cout << "WA x " << ans[1] << endl;
    cout << "TLE x " << ans[2] << endl;
    cout << "RE x " << ans[3] << endl;

    return 0;
}

Measured memory_bytes: 3224
#include <iostream>
using namespace std;
int main() {
  int n;
  string ans;
  std::cin >> n;
  switch (n % 10) {
    case 0:
    case 1:
    case 6:
    case 8:
      ans = "pon";
      break;
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      ans = "hon";
      break;
    case 3:
      ans = "bon";
      break;
  }
  std::cout << ans;
}


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

int main(){
    
    int N,s;
    cin >> N;
    s=N-1;
    s=s/2;
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

// care about lowest number mod 10 that is not 0
void solve(){
	multiset<pair<int,int>> s;
	FOR(5){
		int x; cin >> x;
		if(x%10 == 0) s.insert({11,x});
		else s.insert({x%10,x});
	}
	auto itr = s.begin();
	int ans = (*itr).second;
	++itr;
	while(itr != s.end()){
		int num = (*itr).second;
		while(num%10) ++num;
		ans += num;
		++itr;
	}
	cout << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


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

even_nums = [int(num) for num in input().split() if int(num) % 2 == 0]
approve_nums = [num for num in even_nums if any([num % 6 == 0, num % 10 == 0, num % 30 == 0])]
print('APPROVED') if len(approve_nums) == len(even_nums) else print('DENIED')

Measured memory_bytes: 3060
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
int val[200005];
vector<int> adj[200005];
bool vis[200005];
void dfs(int s){
	vis[s]=true;
	for(int i=0;i<(int)adj[s].size();++i){
		if(!vis[adj[s][i]]){
			val[adj[s][i]]+=val[s];
			dfs(adj[s][i]);
		}
	}
}
void q1(){
	int a;
	cin>>a;
	string s;
	cin>>s;
	if(a>=3200)
	cout<<s;
	else 
	cout<<"red";
}
void q2(){
	int n;cin>>n;
	long double tp=0;
	for(int i=0;i<n;++i){
		long double xp;
		cin>>xp;
		xp=1/xp;
		tp+=xp;
	}
	tp=1/tp;
	cout<<fixed<<setprecision(10)<<tp;
}
void q3(){
	int pp;
	cin >>pp;
	double arr[pp];
	for(int i=0;i<pp;++i)
	cin>>arr[i];
	sort(arr,arr+pp);
	for(int i=1;i<pp;++i){
		arr[i]+=arr[i-1];
		arr[i]/=2;
	}
	cout<<arr[pp-1];
}
void q4(){
	int n;	cin>>n; int q;	cin>>q;
	int cpy=n-1;
	while(cpy--){
		int n1,n2;
		cin>>n1>>n2;
		adj[n1].push_back(n2);		adj[n2].push_back(n1);
	}
	while(q--){
		int node,cost;
		cin>>node>>cost;
		val[node]+=cost;
	}
	dfs(1);
	for(int i=1;i<=n;++i)
	cout<<val[i]<<" ";
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;//cin>>t;
	t=1;
	while(t--)//
	q4();
	return 0;
}


Measured memory_bytes: 24448
#include <iostream>
using namespace std;
int main() {
  int h1,h2,k1,k2;
  cin >> h1 >> h2 >> k1 >> k2;
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int hiroshi = h1 * a + h2 * b + h1/10 * c + h2 /20 * d;
  int ken = k1 * a + k2 * b + k1/10 * c + k2 /20 * d;
  if(ken > hiroshi){
    cout << "kenjiro" << endl;
  } else if(ken < hiroshi) {
    cout << "hiroshi" << endl;
  } else {
    cout << "even" << endl;
  }
} 


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

using namespace std;

// A, B, S
// B = S - A
// X, X+D, X+2D, X+3D, ... X+(N-1)D
// X+iD = nX+sD ( s = \sigma ^ n)
// (m-n)X + (s-t)D = 0


int main(void) {
    long n, x, d;
    cin >> n >> x >> d;

    if(d==0) {
        if(x==0)
            cout << 1 << endl;
        else
            cout << n+1 << endl;
        return 0;
    }

    if(d < 0)
        x = -x, d = -d;

    map<long, vector<pair<long,long>>> slot;

    for(long c=0; c<=n; c++) {
        long a = c*(c-1)/2;
        long b = c*(n-1 + n-c)/2;

        slot[(d+((c*x)%d))%d].push_back({c*x/d + a, c*x/d + b +1});
    }

    long r = 0;
    for(auto &w: slot) {
        auto &l = w.second;

        // my きれい algorithm
        sort(l.begin(), l.end());
        long a = -1e18, b = -1e18;
        for(auto &x: l) {
            a = max(x.first, b);
            b = max(x.second, a);
            r += b - a;
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 22144
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=700,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>str>>str2>>str3;
	cout<<str[0]<<str2[1]<<str3[2];



	cout<<endl;
} 


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    int a[n+2];
    a[0] = 1; a[n+1] = -1;
    /*for(int i=1; i<=n; i++){
        char c;
        scanf("%c", &c);
        if(c == 'L'){
            a[i] = -1;
        }else{
            a[i] = 1;
        }
    }*/
    char str[n+1];
    scanf("%s", str);
    for(int i=0; i<n; i++){
        if(str[i] == 'L'){
            a[i+1] = -1;
        }else{
            a[i+1] = 1;
        }
    }
    int x = a[1];
    for(int i=2; i<=n; i++){
        if(a[i] != x){
            k--;
            for(i; i<=n; i++){
                if(a[i] == x){
                    i--;
                    break;
                }
                a[i] *= -1;
            }
        }
        if(k == 0){
            break;
        }
    }
    int ans = 0;
    for(int i=1; i<=n; i++){
        if(a[i] == a[i + a[i]]){
            ans++;
        }
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 640
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define PI 3.141592654
#define deb1(x) cout << #x <<"="<< x <<endl;
#define deb2(x,y) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<endl;
#define deb3(x,y,z) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<<endl;
#define deb4(x,y,z,a) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<< ", "<<#a <<"="<<a << endl;
#define debarr(x) cout << #x<<"::"<<endl;for(int i : x){cout << i <<" ";} cout <<endl;

inline void add(int& a, int b){a = (a+b); if(a>=mod)a-=mod;}
inline void sub(int& a, int b){a = a-b; if(a<0)a+=mod;}
inline void mul(int& a, int b){a = (a*b)%mod;}

const int N  = 1e5 + 5;
int n;
vector<int> edges[N];


pii dfs(int v, int par){
    int awhite=1 , sblack=0;
    for(int w : edges[v]){
        if(w!=par){
            pii a = dfs(w,v);
            int temp = awhite;
            awhite = (awhite*a.S)%mod;
            sblack = ((temp*a.F)%mod + (sblack*(a.F+a.S)%mod)%mod)%mod;
        }
    }
    pii ret = mp(awhite,(awhite+sblack)%mod);
    return ret;
}


void mymain(){
    cin >> n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        edges[a].pb(b);
        edges[b].pb(a);
    }

    pii ans = dfs(0,-1);
    cout << ( ans.F + ans.S ) % mod << endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
//cin>>t;

for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}
/*

*/


Measured memory_bytes: 12672
# -*- coding: utf-8 -*-
import numpy as np

N= int(input())

# スペース区切りの整数の入力
list = list(map(int, input().split()))


flag=True


for num in range(N):
    q, mod = divmod(list[num], 2)
    if mod==0:
        q, mod3 = divmod(list[num], 3)
        q, mod5 = divmod(list[num], 5)
        if mod3!=0 and mod5!=0:
           flag=False


if flag==False:
    print("DENIED")
else:
    print("APPROVED")


Measured memory_bytes: 12508
x,y=map(float,input().split(','))
bx,by=map(float,input().split(','))
s=0
while 1:
    try:xx,yy=map(float,input().split(','))
    except:break
    a=(pow(bx - xx, 2) + pow(by - yy, 2))**0.5;
    b=(pow(x - bx, 2) + pow(y - by, 2))**0.5;
    c=(pow(x - xx, 2) + pow(y - yy, 2))**0.5;
    z=(a+b+c)/2
    s+=(z*(z - a)*(z - b)*(z - c))**0.5
    bx,by=xx,yy
print(s)

Measured memory_bytes: 7508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

l_l cal(vector<ll>v){
    l_l res{inf,1};
    if(v[0]==v[2]&&v[1]==v[3]){
        if(v[0]==v[1])res.second=4;
        else res.second=2;
    }
    rep(i,0,2)v.pb(v[i]);
    rep(i,0,3){
        ll x=0;
        rep(j,0,3){
            x+=(ll)pow(1000,3-j)*v[i+j];
        }
        Min(res.first,x);
    }
    return res;
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    ll res=1;
    rep(i,0,k-1){
        res*=(n-i);
    }
    return res;
}
#define N 405
ll n;
l_l c[N];
ll anscal(vector<l_l>goal,ll x1,ll x2){
    ll res=1;
    rep(i,0,3)res*=goal[i].second;
    ll same[4];
    rep(i,0,3){
        same[i]=upper_bound(c,c+n,goal[i])-lower_bound(c,c+n,goal[i]);
        if(c[x1]==goal[i])same[i]--;
        if(c[x2]==goal[i])same[i]--;
    }
    ll pos=0;
    while(pos<=3){
        ll c=1;
        while(pos<=2&&goal[pos]==goal[pos+1]){
            c++;pos++;
        }
        res*=comb(same[pos],c);
        pos++;
    }
    return res;
}

int main(){
    cin>>n;
    rep(i,0,n-1){
        vector<ll>a;
        rep(j,0,3){ll k;cin>>k;a.pb(k);}
        c[i]=cal(a);
    }
    sort(c,c+n);
    ll prac[n][4];
    rep(i,0,n-1){
        ll res=c[i].first;
        for(ll j=3;j>=0;j--){
            prac[i][j]=res%1000;
            res/=1000;
        }
    }
   /* rep(i,0,n-1){
        cout<<c[i].first<<":";
        rep(j,0,3){
            cout<<prac[i][j]<<" ";
        }cout<<endl;
    }*/
    ll ans=0;
    rep(i,0,n-1){
        rep(j,0,n-1){
            if(j==i)continue;
            rep(k,0,3){
                vector<l_l>goal;
                rep(l,0,3){
                    vector<ll>res;
                    res.pb(prac[i][l]);
                    res.pb(prac[j][(7-l+k)%4]);
                    res.pb(prac[j][(6-l+k)%4]);
                    res.pb(prac[i][(l+1)%4]);
                    goal.pb(cal(res));
                }
                sort(goal.begin(),goal.end());
                ans+=anscal(goal,i,j);
            }
            //cout<<i<<" "<<j<<" "<<ans<<endl;
        }
    }
    cout<<ans/6<<endl;
    
    
    return 0;
}


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

using namespace std;

int a[100000];
int sum[100001];

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

	int n;
	cin >> n;
	for( int i = 0; i < n; i++ )cin >> a[i];
	sum[0] = abs(a[0]);
	for( int i = 1; i < n; i++ )sum[i] = sum[i - 1] + abs(a[i] - a[i - 1]);
	sum[n] = sum[n - 1] + abs(a[n - 1]);
	for( int i = 0; i < n; i++ )
	{
		int ret = sum[n] - sum[i + 1];
		if( i == 0 )ret += abs(a[i + 1]);
		else ret += sum[i - 1] + abs(a[i + 1] - a[i - 1]);
		cout << ret << endl;
	}

	return 0;
}


Measured memory_bytes: 2048
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int G = 301;
ld dp[G][G][G];
ll a;

ld rec(int x, int y, int z){
    if(min({x,y,z})<0) return 0;
    if(dp[x][y][z]!=-1) return dp[x][y][z];
    ld v0 = (ld)(1.0)*(a-x-y-z)/a;
    ld v1 = (ld)(1.0*x)/a;
    ld v2 = (ld)(1.0*y)/a;
    ld v3 = (ld)(1.0*z)/a;
    dp[x][y][z] = 1 + v1*rec(x-1, y, z) + v2*rec(x+1,y-1,z) + v3*(rec(x,y+1,z-1));
    dp[x][y][z] *= 1.0/(1.0-v0);
    return dp[x][y][z];
}

int main() {
    fast;
    cin>>a;
    for(int q=0; q<G; q++){
        for(int w=0; w<G; w++){
            for(int e=0; e<G; e++) dp[q][w][e] = -1;
        }
    }
    dp[0][0][0] = 0;
    vec<int> n(3);
    for(int q=0; q<a; q++){
        int x; cin>>x; x--;
        n[x]++;
    }
    cout.precision(12);
    cout<<fixed;
    cout<<rec(n[0], n[1], n[2]);
}

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

using namespace std;
using ll  = long long;
using ii  = pair < int , int >;
using i3  = pair < int , ii >;
using vi  = vector < int >;
using vii = vector < ii >;
using vi3 = vector < i3 >;

const int N = 1e5 + 5;
const ll INF = 1e12;
const double eps = 1e-9 , PI = acos(-1);

int n , m;
vi adj[N];
int dis[N][4];
bool vis[N][4];


queue < ii > q;

void bfs(int u){
    q.push({0 , u});
    dis[u][0] = 0;
    vis[u][0] = 1;

    while( !q.empty()){
        int u = q.front().second;
        int d = q.front().first;
        q.pop();

        for(int v : adj[u]){
            int w = (dis[u][d] + 1)%3;
            if(vis[v][w])continue;
            vis[v][w] = 1;
            dis[v][w] = 1 + dis[u][d];
            q.push({w , v});
        }
    }
}


void solve(){
    scanf("%d %d" , &n , &m);

    for(int i = 0 ; i < m ; i ++){
        int u , v;
        scanf("%d %d" , &u , &v);
        adj[u].push_back(v);
    }



    int s , t;
    scanf("%d %d" , &s , &t);


    bfs(s);

    if(vis[t][0]){
         printf("%d\n" , (dis[t][0]+2)/3 );
    }
    else printf("-1\n");
}

main(){
    int t = 1;
    //scanf("%d" , &t);

    while( t -- ){
            solve();
    }

    return 0;
}




Measured memory_bytes: 7680
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	m := make(map[rune]bool)
	for _, c := range s {
		m[c] = true
	}

	ans := "Yes"
	if m['N'] != m['S'] || m['W'] != m['E'] {
		ans = "No"
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int vaca[3][100005];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < 3; ++j)
			cin >> vaca[j][i];
	for (int i = 1; i < n; ++i)
		for (int j = 0; j < 3; ++j) {
			if (j == 0)
				vaca[j][i] = vaca[j][i] + max(vaca[1][i - 1], vaca[2][i - 1]);
			else if (j == 1)
				vaca[j][i] = vaca[j][i] + max(vaca[0][i - 1], vaca[2][i - 1]);
			else
				vaca[j][i] = vaca[j][i] + max(vaca[0][i - 1], vaca[1][i - 1]);
		}
	cout << max(vaca[0][n - 1], max(vaca[1][n - 1], vaca[2][n - 1])) << '\n';
	return 0;
}

Measured memory_bytes: 1408
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,d;
	cin >> n >> d;
	ll x[n][d];
	rep(i,0,n){
		rep(j,0,d){
			cin >> x[i][j];
		}
	}
	ll ans=0;
	rep(i,0,n){
		rep(j,i+1,n){
			ll sum=0;
			rep(k,0,d){
				sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			ll y=sqrt(sum);
			if(y*y==sum) ans++;
		}
	}
	cout << ans;
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int K;

    private class P implements Comparable<P> {
        int m;
        long c;

        public P(int m,long c) {
            this.m = m;
            this.c = c;
        }

        public int compareTo(P p) {
            return Long.compare(this.c,p.c);
        }
    }

    private void solve() {
        K = nextInt();

        int start = K;
        long startSum = 0;
        while(start > 0) {
            startSum += start % 10;
            start /= 10;
        }

        PriorityQueue<P> pq = new PriorityQueue<>();
        pq.add(new P(1,1));

        long[] min = new long[K];
        Arrays.fill(min,Long.MAX_VALUE / 2);

        long ans = Long.MAX_VALUE;
        while(pq.size() > 0) {

            P p = pq.poll();

            if (min[p.m] <= p.c) {
                continue;
            }

            min[p.m] = p.c;
            if (p.m == 0) {
                ans = Math.min(ans,p.c);
            }

            pq.add(new P((p.m + 1) % K,p.c + 1));
            pq.add(new P((p.m * 10) % K,p.c));
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 31476
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for( auto &k : a ) cin >> k;
	int ans = 0;
	int m = inf;
	for( auto k : a ){
		if ( k < m ){
			++ans;
			m = k;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  vll v(10, 0);
  v[a]++;
  v[b]++;
  v[c]++;
  v[d]++;
  if (v[1] == v[9] && v[9] == v[7] && v[7] == v[4] && v[4] == 1) YES();
  else NO();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    setprecision(18);
    int n,k;
    cin>>n>>k;
    double ans=0.0;
    for(int i=1;i<=min(n,k-1);i++)
    {
        int cur=i;
        int cnt=0;
        while(cur<k)
        {
            cur=cur*2;
            cnt++;
        }
        double curAns=(1.0/(1.0*n));
        for(int j=0;j<cnt;j++)
        {
            curAns=curAns*(0.5);
        }
        ans+=curAns;
    }
    for(int i=min(n,k-1)+1;i<=n;i++)
    {
        double curAns=(1.0/(1.0*n));
        ans+=curAns;
    }
    cout<<setprecision(18)<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3680
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
    char ch;

    while(1){
        scanf("%c",&ch);
        if(isalpha(ch)){
            if(islower(ch))printf("%c", toupper(ch));
            else printf("%c",tolower(ch));
          } else printf("%c",ch);

          if(ch=='\n')break;
    }

    return 0;
}


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
vector<int> e[105][105],g[105];
int match[105],dfn[105];
int dfs(int u,int d){
	if(dfn[u]==d) return 0;
	dfn[u]=d;
	for(int i=0;i<g[u].size();++i)
		if(!match[g[u][i]] || dfs(match[g[u][i]],d)){
			match[g[u][i]]=u;
			return 1;
		}
	return 0;
}
int a[105][105],b[105][105],ans[105][105];
int flcl[105][105];
signed main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			cin>>a[i][j];
			b[i][j]=(a[i][j]-1)/m+1;
			e[i][b[i][j]].push_back(j);
		}
	for(int j=1;j<=m;++j){
		for(int i=1;i<=n;++i)
			g[i].clear(),match[i]=dfn[i]=0;
		for(int i=1;i<=n;++i)
			for(int k=1;k<=n;++k)
				if(!e[i][k].empty()) g[i].push_back(k); 
		int Ans=0;
		for(int i=1;i<=n;++i)
			if(dfs(i,i)) ++Ans;
		for(int col=1;col<=n;++col){
			int i=match[col];
			ans[i][j]=a[i][e[i][col].back()];
			e[i][col].pop_back();
		}
	}
	for(int i=1;i<=n;++i,puts(""))
		for(int j=1;j<=m;++j)
			cout<<ans[i][j]<<" ";
	for(int j=1;j<=m;++j){
		for(int i=1;i<=n;++i)
			flcl[j][i]=ans[i][j];
		sort(flcl[j]+1,flcl[j]+n+1);
	}
	for(int i=1;i<=n;++i,puts(""))
		for(int j=1;j<=m;++j)
			cout<<flcl[j][i]<<" ";
	return 0;
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

// struct UnionFind {
//     vector<int> data;
//     UnionFind(int size) : data(size, -1) { }
//     bool unionSet(int x, int y) {
//         x = root(x); y = root(y);
//         if (x != y) {
//             if (data[y] < data[x]) swap(x, y);
//             data[x] += data[y]; data[y] = x;
//         }
//         return x != y;
//     }
//     bool findSet(int x, int y) {
//         return root(x) == root(y);
//     }
//     int root(int x) {
//         return data[x] < 0 ? x : data[x] = root(data[x]);
//     }
//     int size(int x) {
//         return -data[root(x)];
//     }
// };


class UnionFind{
    vector<int> parent, rank;

    int find_root(int x){
        if(parent[x] < 0) return x;
        else return parent[x] = find_root(parent[x]);
    }

public:
    UnionFind(int n) : parent(n, -1), rank(n, 0){}

    void unite(int x, int y){
        x = find_root(x);
        y = find_root(y);
        if(x == y) return;

        if(rank[x] < rank[y]) {
            parent[y] += parent[x];
            parent[x] = y;
        }
        else {
            parent[x] += parent[y];
            parent[y] = x;
            if(rank[x] == rank[y]) ++rank[x];
        }
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    int size(int x) {
        return -parent[find_root(x)];
    }
};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, m;
    cin >> n >> m;
    vector<pii> a(m);
    for(int i = 0; i < m; ++i){
        cin >> a[i].first >> a[i].second;
        --a[i].first;
        --a[i].second;
    }
    vector<ll> ans(m+1, (ll)n * (n-1) / 2);
    UnionFind uf(n);
    for(int i = m - 1; i >= 0; --i){
        if(i != m-1) ans[i] = ans[i+1];
        if(!uf.same(a[i].first, a[i].second)) ans[i] -= (ll)uf.size(a[i].first) * uf.size(a[i].second);
        uf.unite(a[i].first, a[i].second);
    }
    for(int i = 1; i <= m; ++i){
        cout << ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3712