akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	
	public static void Main(string[] args)
	{
 		var p = Input().ToInt();
 		
 		var n = p[0];
 		var m = p[1];
 		Console.WriteLine(n * Math.Max(1, n-1)/2 + m * Math.Max(1, m-1)/2);
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 13140
use proconio::input;

fn main() {
    input! {
        n: usize,
        s: [String; n],
    }

    let mut c0 = 0;
    let mut c1 = 0;
    let mut c2 = 0;
    let mut c3 = 0;

    for req in s {
        match &*req {
            "AC" => c0 += 1,
            "WA" => c1 += 1,
            "TLE" => c2 += 1,
            "RE" => c3 += 1,
            _ => {},
        }
    }
    println!("AC x {}", c0);
    println!("WA x {}", c1);
    println!("TLE x {}", c2);
    println!("RE x {}", c3);
}

Measured memory_bytes: 7808
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define fd(i,j,k) for(int i=j;i>=k;i--)
#define fr(i,j) for(int i=beg[j];i;i=nex[i])
using namespace std;
int const mn=1e5+3,mh=203;
int n,h,gra,beg[mh*2],to[mn],nex[mn],vis[mh*2],ind[mh*2],outd[mh*2];
void ins(int u,int v){
	to[++gra]=v;
	nex[gra]=beg[u];
	beg[u]=gra;
}
void dfs(int p){
	vis[p]=1;
	fr(i,p)if(!vis[to[i]])dfs(to[i]);
}
int main(){
	scanf("%d%d",&n,&h);
	fo(i,1,n){
		int a,b,c,d,x,y;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		if(c)x=-c;else x=a;
		if(d)y=d;else y=-b;
		x+=h;y+=h;
		ins(x,y);
		ind[y]++;
		outd[x]++;
	}
	fo(i,0,h)if(outd[i]>ind[i]){printf("NO");return 0;}
	fo(i,h,h*2)if(outd[i]<ind[i]){printf("NO");return 0;}
	fo(i,0,h*2)if((ind[i]!=outd[i])&&(!vis[i]))dfs(i);
	fo(i,0,h*2)if((ind[i]||outd[i])&&(!vis[i])){printf("NO");return 0;}
	printf("YES");
	return 0;
}


Measured memory_bytes: 896
n, t = list(map(int, input().split()))
ct = []
for _ in range(n):
    cti = list(map(int, input().split()))
    ct.append(cti)

ok = [ct[i] for i in range(n) if ct[i][1] <= t]
ok.sort()
if len(ok) == 0:
    print('TLE')
else:
    print(ok[0][0])

Measured memory_bytes: 3064
n,m=map(int,input().split())
import collections
d=collections.defaultdict(int)
class unionfind:
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    def find(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def count(self, x):
        return -self.root[self.find(x)]
uf=unionfind(n)
for i in range(1,n+1):
    l=list(map(int,input().split()))
    for j in l[1:]:
        if d[j]==0:
            d[j]=i
        else:
            uf.unite(d[j],i)
if uf.count(1)==n:
    print("YES")
else:
    print("NO")

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e6+3)

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}


ll Q;
ll Fa[2020304];
ll i, j, k;

ll Pow(ll a,ll b){
    if(b==0)
        return 1;
    ll c=Pow(a*a%MOD,b / 2);
    if(b&1){
        return c * a % MOD;
    }
    return c;
}

int main(){
    scanf("%lld", &Q);
    Fa[0] = 1;
    fornum(i,0,MOD){
        Fa[i + 1] = Fa[i] * (i + 1) % MOD;
        /*
        if(j==0&&Fa[i+1]==0){
            j = 1;
            printf("%lld\n", i + 1);
        }*/
    }
    fornum(i,0,Q){
        ll x,d,n;
        scanf("%lld%lld%lld", &x, &d,&n);
        if(d==0){
            printf("%lld\n", Pow(x, n));
            continue;
        }
        ll xd = moddiv(x, d);
        
        if(xd==0||n>=MOD||xd>(xd+n-1)%MOD){
            printf("0\n");
        }else{
            //printf("%lld %lld:", xd+n-1,xd-1);
            printf("%lld\n", moddiv(Fa[xd + n - 1], Fa[xd - 1]) * Pow(d, n) % MOD);
        }
    }
    return 0;
}

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

int GCD( int x , int y )
{
	if( x < y ){ swap( x,y ); }

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

int main()
{
	unsigned int a,b ;

	while( cin >> a >> b )
	{
		cout << GCD(a,b) << " " << a/GCD(a,b) * b << endl ;
	}

	return 0 ;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

int n;
bool s[500], t[500], u[500], v[500];
int a[500][500];
ull ans[500][500];
void end(){
    cout << -1 << endl;
    exit(0);
}
void solve(){
    memset(a, 0xff, sizeof(a));
    vector<int> x(n), y(n);
    auto px = x.begin(), py = y.begin();
    for(int i = 0; i < n; i++) x[i] = y[i] = i;
    for(int i = 0; i < n; i++){
        if(s[i] ^ u[i]){
            for(int j = 0; j < n; j++) a[i][j] = u[i];
            px = x.erase(px);
        }
        else px++;
    }
    for(int j = 0; j < n; j++){
        if(t[j] ^ v[j]){
            for(int i = 0; i < n; i++){
                if(a[i][j] == (v[j] ^ 1)) end();
                a[i][j] = v[j];
            }
            py = y.erase(py);
        }
        else py++;
    }
    if(x.size() > 1 && y.size() > 1){
        bool b = 0;
        for(int i : x){
            bool c = b;
            for(int j : y){
                a[i][j] = c;
                c = !c;
            }
            b = !b;
        }
        return;
    }
    if(x.size() == 1){
        const int i = x[0];
        for(int j : y){
            a[i][j] = u[i];
            bool flag = 1;
            for(int i = 0; i < n; i++) if(a[i][j] == v[j]){
                flag = 0;
                break;
            }
            if(flag) a[i][j] = v[j];
        }
    }
    if(y.size() == 1){
        const int j = y[0];
        for(int i : x){
            a[i][j] = v[j];
            bool flag = 1;
            for(int j = 0; j < n; j++) if(a[i][j] == u[i]){
                flag = 0;
                break;
            }
            if(flag) a[i][j] = u[i];
        }
    }
    for(int i : x){
        bool flag = 1;
        for(int j = 0; j < n; j++) if(a[i][j] == u[i]){
            flag = 0;
            break;
        }
        if(flag) end();
    }
    for(int j : y){
        bool flag = 1;
        for(int i = 0; i < n; i++) if(a[i][j] == v[j]){
            flag = 0;
            break;
        }
        if(flag) end();
    }
}
int main(){
    cin >> n;
    vector<ull> u_(n), v_(n);
    for(int i = 0; i < n; i++) cin >> s[i];
    for(int i = 0; i < n; i++) cin >> t[i];
    for(auto& i : u_) cin >> i;
    for(auto& i : v_) cin >> i;
    for(int bit = 64; bit--; ){
        for(int i = 0; i < n; i++) u[i] = u_[i] >> bit & 1;
        for(int i = 0; i < n; i++) v[i] = v_[i] >> bit & 1;
        solve();
        for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){
            ans[i][j] <<= 1;
            ans[i][j] |= a[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++) cout << ans[i][j] << ' ';
        cout << '\n';
    }
}

Measured memory_bytes: 8444
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Arrays;

class Main{
	public static void main(String[] args)throws Exception{
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] numbers = new int[n];
		for(int i = 0; i < n; i++){
		    numbers[i] = scanner.nextInt();
		}
		int count = 0;
		int temp = 0;

		for(int i = 0; i < n; i++){
			int minj = i;
			for(int j = i; j < n; j++){
				if(numbers[j] < numbers[minj]){
					minj = j;
				}
			}
			if(i != minj){
			    temp = numbers[i];
    			numbers[i] = numbers[minj];
    			numbers[minj] = temp;
    			count++;
			}
		}

		for(int i = 0; i < n; i++){
			if(i == n-1){
				System.out.print(numbers[i]);
				System.out.print("\n");
			}else{
				System.out.print(numbers[i] + " ");
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 26316
import sys
#input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():
	h,w,k=MI()
	G=[]
	for _ in range(h):
		G.append(list(input()))
	#print(G)
	ans=0

	for i in range(1<<h):
		for j in range(1<<w):
			cnt=0
			for ii in range(h):
				for jj in range(w):
					#print(i,j,ii,jj,)
					if i&1<<ii and j&1<<jj and G[ii-1][jj-1]=="#":
						#print(1<<i)
						cnt+=1
			if cnt==k:
				ans+=1
	print(ans)







if __name__ == "__main__":
	main()


Measured memory_bytes: 68516
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var ND = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            double N = ND[0];
            double D = ND[1];

            double ans = N / (2 * D + 1);

            Console.WriteLine(Math.Ceiling(ans));
        }
    }
}


Measured memory_bytes: 11220
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=1e5+5;
const int mod=1e9+7;

ll n,W,V,w[N],v[N],dp[N][105];
ll rec(int val,int i){
    if(val==0) return 0;
    if(i>n or val<0) return 1e9;
    ll &cache=dp[val][i];
    if(cache!=-1) return cache;
    rec(val-1,i);
    cache=rec(val,i+1);
    cache=min(cache,w[i]+rec(val-v[i],i+1));
    return cache;
}
signed main(){
    FastIO;
    cin>>n>>W;
    rep(i,1,n) cin>>w[i]>>v[i],V+=v[i];
    memset(dp,-1,sizeof dp);
    rec(V,1);
    int ans=0;
    rep(i,1,V){
        rep(j,1,n) if(dp[i][j]!=-1 and dp[i][j]<=W) ans=i;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 87040
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest._300Problems_remain_
{
    class CF2017_A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string s = Read();
            int allPat = 1 << 4;
            string baseS = "KIHBR";
            for(int i = 0; i < allPat; i++)
            {
                string checkS = baseS;
                for(int j = 0; j < 4; j++)
                {
                    if ((i >> j) % 2 == 1)
                    {
                        switch (j)
                        {
                            case 0:
                                checkS = "A" + checkS;
                                break;
                            case 1:
                                checkS = checkS.Replace("H", "HA");
                                break;
                            case 2:
                                checkS = checkS.Replace("B", "BA");
                                break;
                            case 3:
                                checkS = checkS.Replace("R", "RA");
                                break;
                        }
                    }
                }
                //Console.WriteLine(checkS);
                if (s.Equals(checkS))
                {
                    Console.WriteLine("YES");
                    return;
                }
            }
            Console.WriteLine("NO");
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

void solve(){
    string s;
    cin>>s;
    int n=s.size();
    int cnt=0;
    rep(i,n/2){
      if(s[i]!=s[n-1-i])++cnt;
    }
    cout<<cnt<<"\n";
}
 
int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}

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

int n,a[5001],A,B,p[5001];
long long f[5001][5001],ans;

int main()
{
	scanf("%d%d%d",&n,&A,&B);
	for (int i=1; i<=n; i++) scanf("%d",&a[i]),p[a[i]]=i;
	for (int i=0; i<=n; i++)
		for (int j=0; j<=n; j++) f[i][j]=1000000000000000000ll;
	f[0][0]=0;
	for (int i=1; i<=n; i++)
		for (int j=0; j<=n; j++)
			if (j<p[i]) f[i][j]=min(f[i][j],f[i-1][j]+B),f[i][p[i]]=min(f[i][p[i]],f[i-1][j]);
			else f[i][j]=min(f[i][j],f[i-1][j]+A);
	ans=1000000000000000000ll;
	for (int i=0; i<=n; i++) ans=min(ans,f[n][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 195712
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;
  int t=0, x=0, y=0;
  string ans = "Yes";
  for(int i=0; i<N; ++i){
    int t1, x1, y1;
    cin >> t1 >> x1 >> y1;
    int d = abs(x1-x) + abs(y1-y);
    if(t1-t < d || (t1-t-d) % 2 == 1){
      ans = "No";
      break;
    }
    t = t1;
    x = x1;
    y = y1;
  }

  cout << ans << endl;

}

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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 1e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;


signed main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);
   int Q, H, S, D, n;
   cin >> Q >> H >> S >> D >> n;
   if (Q * 2 < H) H = Q * 2;
   if (H * 2 < S) S = H * 2;
   if (S * 2 < D) D = S * 2;
   int sum = 0;
   sum+= (n / 2) * D;
   n%= 2;
   cout << sum + n * S;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,x) for(int i=0,i##_len=(x);i<i##_len;++i)
#define rep(i,a,b) for(int i=(a),i##_len(b);i<i##_len;++i)
#define All(x) begin(x),end(x)
#define rAll(x) rbegin(x),rend(x)
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<ll> A(N);
    REP(i,N) cin>>A[i];
    const ll inf = 1e18;
    vector<vector<ll>> dp(N/2+2,vector<ll>(2,-inf));
    dp[0][0]=0;
    REP(i,N) for(int j=i/2+1;j>=max(i/2-3,0);--j){
        dp[j][0]=max(dp[j][0],dp[j][1]);
        if(j>0) dp[j][1]=max(dp[j][1],dp[j-1][0]+A[i]);
        //cerr<<i<<" "<<j<<" "<<dp[j][0]<<" "<<dp[j][1]<<endl;
    }
    cout<<max(dp[N/2][0],dp[N/2][1])<<endl;
}

Measured memory_bytes: 10384
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int2(n, t);

    int ans = 0, nxt = 0;
    rep(i, n) {
        Int(tmp);
        if (nxt > tmp) {
            ans += (tmp + t) - nxt;
        } else {
            ans += t;
        }
        nxt = tmp + t;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var t int
	min := 1000
	max := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&t)
		if t < min {
			min = t
		}
		if t > max {
			max = t
		}
	}
	fmt.Println(max - min)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k;std::cin >> n >> k;
  vll a(n);re(i, n) scanf("%lld", &a[i]);
  for(int i=k;i<n;i++){
    if(a[i]>a[i-k]) std::cout << "Yes" << '\n';
    else std::cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 4464
/**
  *  Author: dhruv_gheewala
  *  Problem: D - Replacing
  *  Date:   05.09.2020
  *  Time:   16:38:38
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;
    
    #define fundri 108
    #define debug(...) 1729
#endif

#define int int64_t
typedef pair<int, int> pii;
typedef vector<int> vi;

const bool testcases = false;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(), s.end()

// if vector isn't soted then it will remove consecutive same elements
#define make_unique(vec) vec.erase(unique(all(vec)), vec.end())
#define test int TC = 1;if(testcases)cin >> TC;for(int tc = 1 ; tc <= TC ; tc++)solve(), fundri
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})
// clears stdin
#define flush(ch) cin.ignore(std::numeric_limits<std::streamsize>::max(), ch) // default, EOF

int seed; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = INT_MAX) {return uniform_int_distribution<int>(l, r)(rng);}

inline bool in_range(int a, int l, int r) {return (a >= l && a <= r);}
template<typename H, typename ...T>void inp(H &head) {cin >> head;}
template<typename H, typename ...T>void inp(H &head, T &...tail) {cin >> head;inp(tail...);}
template<typename T>bool isPrime(T n) {for(T i = 2; i * i <= n; i++)if(n % i == 0)return false; return n >= 2;}
template<typename T>inline istream &operator >>(istream &in, vector<T> &a) {for(T &x : a)in >> x; return in;}
template<typename T, typename U>inline istream &operator >>(istream &in, pair<T, U> &a) {in >> a.ff >> a.ss; return in;}

void solve();
void fast_io();

int32_t main(int32_t argc, char **argv)
{
    fast_io();
    test;
    return 0;
}

void solve()
{
    int n;
    cin >> n;
    vi a(n);
    int q;
    cin >> a >> q;

    vi freq(100005, 0);
    for(int i = 0 ; i < n ; i++)
        freq[a[i]]++;

    int u, v;
    int sum = accumulate(all(a), 0LL);
    for(int i = 0 ; i < q ; i++) {
        cin >> u >> v;
        sum += (v - u) * freq[u];
        freq[v] += freq[u];
        freq[u] = 0;

        cout << sum << endl;
    }
}

void fast_io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef DHRUV_GHEEWALA
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif
}

Measured memory_bytes: 4800
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

const int kMaxN = 2000;
const int kMaxY = 20000;

int n, y;
int a = 0;
int b = 0;
int c = 0;

void f() {
  REP(i, a+1) {
    if ((a-i) + (b+2*i) > n) { break; }
    REP(j, b+2*i+1) {
      int cnt = (a-i) + (b+2*i-j) + c+5*j;
      if (cnt > n) {
        break;
      } else if (cnt == n) {
        a = a-i;
        b = b+2*i-j;
        c = c+5*j;
        return;
      } else {
        ;
      }
    }
  }
  a = -1; b = -1; c = -1;
  return;
}

int main() {
  cin >> n >> y;

  while (y >= 10000) { y -= 10000; ++a; }
  while (y >= 5000) { y -= 5000; ++b; }
  while (y >= 1000) { y -= 1000; ++c;}
  if (a+b+c > n) {
    a = -1; b = -1; c = -1;
  } else if (a+b+c == n) {
    ;
  } else {
    f();
  }

  cout << a << " " << b << " " << c << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        double a = double.Parse(str[0]);
        double b = double.Parse(str[1]);
        double C = double.Parse(str[2]) * Math.PI / 180;
        double S = a * b * Math.Sin(C) / 2;
        double L = a + b + Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(C));
        double h = 2 * S / a;
        Console.WriteLine(S);
        Console.WriteLine(L);
        Console.WriteLine(h);
    }
}


Measured memory_bytes: 15964
#include<stdio.h>
#include<stdlib.h>
#define N 100
#define INF 1<<21

int A[N],p[N],n,G[N][N];


int min(int c,int r){
  if(c<r) return c;
  else return r;
  
}

int main(){

  int i,j,k,x,y,GX;

  scanf("%d",&n);


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

  for(i=2;i<=n;i++){
    for(j=1;j<=n-i+1;j++){
      x = j+i-1;
      G[j][x] = INF;
      for(y = j;y<=x-1;y++){
	k = G[j][y] + G[y+1][x] + p[j-1]*p[y]*p[x];
	G[j][x] = min(G[j][x],k);
      }
    }
  }

  printf("%d\n",G[1][n]);

  return 0;
}




Measured memory_bytes: 2044
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v[200001];

ll mypow(ll a, ll b) {
	ll ret = 1;

	while (b) {
		if (b % 2) ret = ret * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}

	return ret;
}

struct node {
	ll z, o, t;
};

vector<node> dq[200001];
int tr;

int go(int o) {
	if (v[o].empty()){
		dq[o].push_back({ tr, tr, 0 });
		return o;
	}

	int pre = go(v[o][0]), kk = 0;
	for (int i = 1; i < sz(v[o]); i++) {
		int t = go(v[o][i]);

		if (sz(dq[pre]) < sz(dq[t]))
			swap(pre, t);
		int pp = sz(dq[pre]), tt = sz(dq[t]);
		kk = max(kk, tt);

		for (int j = 1; j <= tt; j++) {
			node tv;
			tv.z = dq[pre][pp - j].z * dq[t][tt - j].z % MOD;

			tv.o = dq[pre][pp - j].o * dq[t][tt - j].z % MOD;
			tv.o += dq[pre][pp - j].z * dq[t][tt - j].o % MOD;

			tv.t = dq[pre][pp - j].z * dq[t][tt - j].t % MOD;
			tv.t += dq[pre][pp - j].o * dq[t][tt - j].o % MOD;
			tv.t += dq[pre][pp - j].o * dq[t][tt - j].t % MOD;
			tv.t += dq[pre][pp - j].t * dq[t][tt - j].z % MOD;
			tv.t += dq[pre][pp - j].t * dq[t][tt - j].o % MOD;
			tv.t += dq[pre][pp - j].t * dq[t][tt - j].t % MOD;

			tv.o %= MOD;
			tv.t %= MOD;

			dq[pre][pp - j] = tv;
		}
	}
	
	int pp = sz(dq[pre]);
	for (int i = 1; i <= kk; i++) {
		dq[pre][pp - i].z = (dq[pre][pp - i].z + dq[pre][pp - i].t) % MOD;
		dq[pre][pp - i].t = 0;
	}

	dq[pre].push_back({ tr, tr, 0 });
	return pre;
}

int main() {
	tr = mypow(2, MOD - 2);
	int n;
	scanf("%d", &n);

	int t;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &t);
		v[t].push_back(i);
	}

	int k = go(0);
	int ttr = mypow(2, n + 1);
	
	ll ans = 0;
	for (int i = 0; i < sz(dq[k]); i++)
		ans = (ans + dq[k][i].o * ttr % MOD) % MOD;

	printf("%lld", ans);
}

Measured memory_bytes: 52208
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

LL B, W;
LL r2[214514];
LL rev[214514];
LL fact[214514];
LL t_w[214514];
LL t_b[214514];
LL p_w[214514];
LL p_b[214514];


LL mypow(LL base, LL exp) {
  if (!exp) return 1;
  LL res = mypow(base*base%MOD, exp/2);
  if (exp%2) res = res*base%MOD;
  return res;
}

LL Comb(LL n, LL k) {
  if (n < 0) return 0;
  if (k < 0 || n < k) return 0;
  return fact[n]*rev[n-k]%MOD*rev[k]%MOD;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> B >> W;
  r2[0] = 1;
  fact[0] = 1;
  rev[0] = 1;
  reps(i, 1, B+W+10) {
    r2[i] = r2[i-1]*500000004 % MOD;
    fact[i] = fact[i-1]*i % MOD;
    rev[i] = rev[i-1]*mypow(i, MOD-2) % MOD;
    t_w[i] = Comb(i-1, W-1) * r2[i] % MOD;
    t_b[i] = Comb(i-1, B-1) * r2[i] % MOD;
    p_w[i] = (p_w[i-1] + t_w[i]) % MOD;
    p_b[i] = (p_b[i-1] + t_b[i]) % MOD;
  }

  //rep(i, min(B, W)) {
  //  cout << "500000004" << endl;
  //}

  reps(i, 1, W+B+1) {
    LL ans = (p_w[i-1] + (MOD+MOD+1-p_b[i-1]-p_w[i-1]) * r2[1]) % MOD;
    cout << ans << endl;
  }
}


Measured memory_bytes: 13696
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    p,q,r = map(int, input().split())
    print(min(p+q, q+r, r+p))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <thread>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>



int main() {
	string s;
	cin >> s;
	if (s == "SUN")cout << 7 << endl;
	if (s == "MON")cout << 6 << endl;
	if (s == "TUE")cout << 5 << endl;
	if (s == "WED")cout << 4 << endl;
	if (s == "THU")cout << 3 << endl;
	if (s == "FRI")cout << 2 << endl;
	if (s == "SAT")cout << 1 << endl;
}


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

typedef long value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}

void quicksort(value_type a[], int left, int right)
/* クイックソート
 * a     : ソートする配列
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 */
{
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            i++; j--;
        }
        quicksort(a, left, i - 1);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right); /* 分割した右を再帰的にソート */
    }
}


int main()
{
	long N,H;
	cin >> N >> H;

	long a[N], b[N];
	long a_max = 0, a_max_index;
	for(long i = 0; i < N; i++){
		cin >> a[i] >> b[i];
		if(a_max < a[i] || (a_max == a[i] && b[a_max_index] > b[i])){
			a_max = a[i];
			a_max_index = i;
		}
	}

	quicksort(b, 0, N-1);

	int ans = 0;
	for(int i = N-1; i >= 0; i--){
		if(b[i] < a_max)
			break;
		if(i == a_max_index)
			continue;

		H -= b[i];
		ans++;
		if( H <= 0)
			break;
	}

	while(H > b[a_max_index]){
		H -= a_max;
		ans++;
	}

	if(H > 0)
		ans++;
	
	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#define ll long long int
using namespace std;

int main(int argc, char const* argv[])
{
	int x;
	cin >> x;
	if(x == 1){
			cout << 1 << endl;
			return 0;
	}
	int max = 1;
	int y = 4;
	while(y <= x){
			if(max < y)max = y;
			y = y * 2;
	}
	for(int i = 3; i < sqrt(x); i++){
			int z = i*i;
			while(z <= x){
					if(max < z)max = z;
					z = z * i;
			}
	}
	cout << max << endl;
	return 0;
}



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

int atc112_1(int nums[])
{
	if (nums[0] >= nums[1] && nums[0] >= nums[2])
	{
			return nums[0] * 10 + nums[1] + nums[2];
	}
	else if (nums[1] >= nums[0] && nums[1] >= nums[2])
		return nums[1] * 10 + nums[0] + nums[2];
	else
		return nums[2] * 10 + nums[0] + nums[1];
}
int main()
{
	int test[3];
	cin >> test[0] >> test[1] >> test[2];
	cout<< atc112_1(test);
	system("pause");
}

Measured memory_bytes: 888
#include <iostream>
#include <map>

using namespace std;

int main(void) {
  std::string s;
  cin >> s;

  int res = 0;
  int num = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') num++;
    else {
      if (res < num) res = num;
      num = 0;
    }
  }
  if (res < num) res = num;
  cout << res << endl;
  return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<tuple<string, int, int>> a;
	rep(i, n){
		string s;
		int p;
		cin >> s >> p;
		p *= -1;
		a.push_back(tie(s, p, i));
	}

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

	rep(i, n){
		string s;
		int p,id;
		tie(s, p, id) = a.at(i);
		cout << id+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    char c[4]={'A','C','G','T'};
    constexpr ll mod=1e9+7;
    vector<map<string,ll>> dp(N);
    function<ll(int,string)> dfs=[&](int now,string p3)->ll{
        if(now==N) return 1LL;
        if(dp[now][p3]) return dp[now][p3];
        ll res=0;
        REP(i,4){
            string t=p3+c[i];
            string tmp=t;
            if(tmp.size()==4) tmp.erase(tmp.begin());
            if(t.find("AGC")==string::npos){
                bool flag=true;
                REP(j,(int)t.size()-1){
                    swap(t[j],t[j+1]);
                    if(t.find("AGC")!=string::npos) flag=false;
                    swap(t[j],t[j+1]);
                }
                if(flag){
                    res+=dfs(now+1,tmp);
                    res%=mod;
                }
            }
        }
        return dp[now][p3]=res;
    };
    cout<<dfs(0,"")<<endl;
}

Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	a, p := nextInt(), nextInt()
	fmt.Println((a*3 + p) / 2)
}


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

using namespace std;
int main()
{
	int n, ans = 0;
	char a[100], b[100], c[100];
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++) {
		if (a[i] != b[i]) {
			ans++;
		}
		if (b[i] != c[i]) {
			if (a[i] != c[i]) {
				ans++;
			}
		}
	}
	cout << ans << endl;
    return 0;
}

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

int main(){
    //入力
    char c;
    cin >> c;
    
    //出力
    if((c=='a')||(c=='i')||(c=='u')||(c=='e')||(c=='o')){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NKQ (int64 *n, int64 *k, int64 *q)
{
  int cnt;
  
  cnt = scanf("%lld %lld %lld", n, k, q);

  return;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

#define SIZE (10*10*10*10*10)

int64 N,K,Q;
int64 A[SIZE];
int64 U[SIZE];
int main()
{
  int cnt, len;
  int i;

  get_NKQ (&N,&K,&Q);

  for (i=0; i<N; i++) {
    U[i] = K;
  }

  for (i=0; i<Q; i++) {
    get_N(&A[i]);
    U[(A[i]-1)]++;
  }

  for (i=0; i<N; i++) {
    U[i] -= Q;
    if (U[i] > 0) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
  
  return 0;
}



Measured memory_bytes: 2048
#168 - F
import sys
import numpy as np
#from numba import njit


def main():
    N, M = map(int, sys.stdin.buffer.readline().split())
    LineData = np.int64(sys.stdin.buffer.read().split())

    INF = 10**9 + 1

    LineData = LineData.reshape(-1, 3)
    A, B, C = LineData[:N].T
    D, E, F = LineData[N:].T
    X = np.unique(np.concatenate([D, [-INF, INF]]))
    Y = np.unique(np.concatenate([C, [-INF, INF]]))
    A = np.searchsorted(X, A)
    B = np.searchsorted(X, B, 'right') - 1
    C = np.searchsorted(Y, C)
    D = np.searchsorted(X, D)
    E = np.searchsorted(Y, E)
    F = np.searchsorted(Y, F, 'right') - 1

    area = cal_area(A, B, C, D, E, F, X, Y)

    if area == 0:
        print("INF")
    else:
        print(area)


#@njit
def cal_area(A, B, C, D, E, F, X, Y):
    x = np.searchsorted(X, 0, 'right') - 1
    y = np.searchsorted(Y, 0, 'right') - 1

    DX = X[1:] - X[:-1]
    DY = Y[1:] - Y[:-1]

    A = A.tolist()
    B = B.tolist()
    C = C.tolist()
    D = D.tolist()
    E = E.tolist()
    F = F.tolist()
    X = X.tolist()
    Y = Y.tolist()
    DX = DX.tolist()
    DY = DY.tolist()

    LenX = len(X)
    LenY = len(Y)

    visit = [[False] * LenY for _ in range(LenX)]
    visit[x][y] = True
    area = 0
    queue = [(x, y)]

    LineX = [[False] * LenY for _ in range(LenX)]
    LineY = [[False] * LenY for _ in range(LenX)]

    for x1, x2, y in zip(A, B, C):
        for x in range(x1, x2):
            LineY[x][y] = True
    #for i in range(len(A)):
    #    y = C[i]
    #    for x in range(A[i], B[i]):
    #        LineY[x][y] = True

    for x, y1, y2 in zip(D, E, F):
        for y in range(y1, y2):
            LineX[x][y] = True
    #for i in range(len(D)):
    #    x = D[i]
    #    for y in range(E[i], F[i]):
    #        LineX[x][y] = True

    LenX -= 1
    LenY -= 1
    
    while queue:
        x, y = queue.pop()
        
        if x == 0 or x == LenX or y == 0 or y == LenY:
            area = 0
            break
        
        area += DX[x] * DY[y]
        
        x1 = x - 1
        if not LineX[x][y] and not visit[x1][y]:
            visit[x1][y] = True
            queue.append((x1, y))
        y1 = y - 1
        if not LineY[x][y] and not visit[x][y1]:
            visit[x][y1] = True
            queue.append((x, y1))
        x1 = x + 1
        if not LineX[x1][y] and not visit[x1][y]:
            visit[x1][y] = True
            queue.append((x1, y))
        y1 = y + 1
        if not LineY[x][y1] and not visit[x][y1]:
            visit[x][y1] = True
            queue.append((x, y1))

    return area


if __name__ == '__main__':
	main()

sys.exit()


Measured memory_bytes: 66064
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long long x, y; cin >> x >> y;
    cout << (abs(x - y) > 1 ? "Alice" : "Brown") << endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
def zill(a,b):
  sum = 0
  for i in range(k):
    sum += (a[i] - b[i])**2
  sq = int(sum**0.5)
  if sq**2 == sum: return 1
  return 0


a=[[] for i in range(n)]

for i in range(n):
  a[i] = list(map(int, input().split()))

res = 0
for i in range(n-1):
  for j in range(i+1,n):
    if zill(a[i],a[j]) : res+=1
print(res)

Measured memory_bytes: 3064
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>

using namespace std;

class length {
	double x;
	double y;
	double leng;
public:
	void set_length(double a, double b, double c) { x = a; y = b; leng = c; }
	void get_length(double& s, double& t) { s = x; t = y; }
	
};

class Longa : public  length {
public:
	void get_xy(double A,double H, double M);
};

class Shorta : public  length {
public:
	void get_xy(double B,double H, double M);
};

void  Longa::get_xy(double A,double H, double M) {
	double theta;
	double a, b;
	theta = (H * 30 + 0.5 * M) * M_PI / 180;
	a =A* cos(theta);
	b = A * sin(theta);
	set_length(a, b, A);
}

void  Shorta::get_xy(double B,double H, double M) {
	double theta;
	double a, b;
	theta = (6*M) * M_PI / 180;
	a = B * cos(theta);
	b = B * sin(theta);
	set_length(a, b, B);
}

int main()
{
	double A, B, H, M;
	double long_x, long_y, short_x, short_y;
	double answer;

	cin >> A >> B >> H >> M;

	Shorta a;
	Longa b;

	a.get_xy(A, H, M);
	b.get_xy(B, H, M);
	a.get_length(long_x, long_y);
	b.get_length(short_x, short_y);

	answer = sqrt((long_x - short_x) * (long_x - short_x) + (long_y - short_y) * (long_y - short_y));

	cout.precision(15);
	cout << answer << endl;

	return 0;

}

Measured memory_bytes: 4100
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# なんこか入力
a,b = map(int, input().split())
# なんこか入力
c,d = map(int, input().split())

if a==c:
    print("0")
else:
    print("1")
    

Measured memory_bytes: 22168
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n;
  cin>>n;
  int a[n];
  REP(i, n) cin>>a[i];
  if(n==1){
    cout<<1<<endl;
    return 0;
  }
  int ans=1, mode=0;
  REP(i, n-1){
    if(mode==0){
      if(a[i]==a[i+1])continue;
      else if(a[i]<a[i+1]) mode=1;
      else mode=2;
      continue;
    }
    if(mode==1){
      if(a[i]<=a[i+1]) continue;
      else{
        ++ans;
        mode=0;
      }
    }
    else{
      if(a[i]>=a[i+1]) continue;
      else{
        ++ans;
        mode=0;
      }
    }
  }
  ECHO(ans);
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
using ll = long long;

ll bairitu(ll x,ll y){
	ll ret = x/y;
	if(x % y != 0){
		ret ++;
	}
	return ret;
//	return x/y;
}
long long seisuka(double x){
	long long ret = int(x);
	if(x - double(ret) > 0.0){
		ret ++;
	}
	return ret;
}

ll max(ll x,ll y){
	if (x > y){
		return x;
	}else{
		return y;
	}
}

int main(){
	int N;
	ll T[1001],A[1001];
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> T[i] >> A[i];
	}
//	double Max = 0;
	
	for(int i=0;i<N-1;i++){
		ll t = bairitu(T[i],T[i+1]);
		ll a = bairitu(A[i],A[i+1]);
		
		ll Max = max(t,a);
		
		if(Max <= 1)continue;
		
//		double nannbai = double(seisuka(Max));
//		Max = 0;
		T[i+1] = Max * T[i+1];
		A[i+1] = Max * A[i+1];
		Max = 0;
	}
	
	cout << T[N-1] + A[N-1] << endl;
//	printf("%f",T[N-1] + A[N-1]);

	return 0;
}

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

void solve(long long N, vector<long long> a){
	bool fail = true;
	for(int i = 0; i < N; ++i) {
		fail = fail && (a[i] % 2 == 0);
	}
	if(fail) {
		cout << "second" << endl;
	} else {
		cout << "first" << endl;
	}
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> a(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	solve(N, a);
	return 0;
}



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

using namespace std;

int fr[MAXN + 1];
int v[MAXN + 1];
int val[MAXN + 1];

int main() {
    //fstream cin("A.in");
    //ofstream cout("A.out");
    int n, x, y, m, i;
    ios::sync_with_stdio(false);
    cin >> n >> m;
    int ans = n;
    for(i = 1; i <= n; i++) {
        cin >> val[i];
        fr[val[i]]++;
        if(val[i] - fr[val[i]] >= 0) {
            if(v[val[i] - fr[val[i]]] == 0)
                ans--;
            v[val[i] - fr[val[i]]]++;
        }
    }
    while(m > 0) {
        m--;
        cin >> x >> y;
        if(val[x] - fr[val[x]] >= 0 && v[val[x] - fr[val[x]]] == 1)
            ans++;
        if(val[x] - fr[val[x]] >= 0)
            v[val[x] - fr[val[x]]]--;
        fr[val[x]]--;
        fr[y]++;
        if(y - fr[y] >= 0 && v[y - fr[y]] == 0)
            ans--;
        if(y - fr[y] >= 0)
            v[y - fr[y]]++;
        val[x] = y;
        cout << ans << endl;
    }
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 3840
import sys
from itertools import combinations


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    l = list(map(int, input().split()))
    ans = 0
    for i, j, k in combinations(range(n), 3):
        if (
            abs(l[j] - l[i]) < l[k] != l[i]
            and l[k] < l[i] + l[j]
            and l[i] != l[j]
            and l[k] != l[j]
        ):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9248
import bisect
n = int(input())
l = sorted(list(map(int,input().split())))
 
count = 0
for i in range(n):
  for j in range(i+1,n):
    index = bisect.bisect_left(l,l[i]+l[j])
    count += index - j - 1
    
print(count)

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

template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=2e5+5;
int a[N];s64 s[N];

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);
#endif
	int n,X;
	cin>>n>>X;
	s64 base=s64(n)*X;
	rep(i,1,n){scanf("%d",a+i);base+=5LL*a[i];}
	rep(i,1,n)s[i]=s[i-1]+a[i];
	s64 mn=s64(n)*X;
	rep(l,1,n)
	{
		s64 now=s64(l)*X;
		for(int i=n-l,k=1;i>0&&now<mn;i-=l,++k)now+=(s[i]-s[max(0,i-l)])*(2*k-2);
		chmin(mn,now);
	}
	cout<<mn+base;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
int main(void)
{
    char x[1000][1001];
    long long int i = 0,j = 0,sum = 0,a,b = 0;
    while(1){
        scanf("%s",x[i]);
        if(x[i][0] == '0')break;
        i++;
        b++;
    }
    while(1){
        a = strlen(x[j]);
        for(i = 0;i < a;i++){
            //printf("%d\n",x[i] - '0');
            sum += x[j][i] - '0';
        }
        printf("%lld\n",sum);
        sum = 0;
        j++;
        if(j == b)break;
    }


    return 0;
}

Measured memory_bytes: 1824
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    String S = sc.next();

    sc.close();

    String result = "None";

    int[] count = new int[26];

    for (int i = 0; i < S.length(); i++) {
      count[(int) S.charAt(i) - 97]++;
    }

    for (int i = 0; i < 26; i++) {
      if (count[i] == 0) {
        result = String.valueOf((char) (i+97));
        break;
      }
    }

    System.out.println(result);
  }

}

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

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

  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i) ;
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());

  int Alice,Bob;
  Alice=0;Bob=0;
  for(int i=0; i<N; i++){
    if(i%2==0){
      Alice+=vec.at(i);
    }
    if(i%2==1){
      Bob+=vec.at(i);
    }

  
  }

  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
s=int(input())
a=s
alp=list("abcdefghijklmnopqrstuvwxyz")
ans=""
i=1
#try:
while s!=0:
    jo=(26**i)
    x=s%jo
    if x==0:
      x=jo
    s-=x
    x//=26**(i-1)
    #print("{}%{} {} {}".format(s+x,jo,i,x))
    ans=alp[x-1]+ans
    i+=1
#except:
#  pass
  
print(ans)

Measured memory_bytes: 9192