akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll h, w;
  cin >> h >> w;
  // While=0, Black=1
  VV field(h+2, V(w+2, 1));
  queue<ll> bfs_buf_x;
  queue<ll> bfs_buf_y;
  queue<ll> bfs_buf_step;
  ll cnt_step;

  for(ll y=1; y<=h; y++) {
    for(ll x=1; x<=w; x++) {
      char t;
      cin >> t;
      if(t == '.') {
        field[y][x] = 0;
      } else {
        field[y][x] = 1;
        bfs_buf_x.push(x);
        bfs_buf_y.push(y);
        bfs_buf_step.push(0);
      }
    }
  }

  while(!bfs_buf_x.empty()) {
    ll s_x, s_y;
    ll c_x = bfs_buf_x.front();
    ll c_y = bfs_buf_y.front();
    ll c_step = bfs_buf_step.front();
    bfs_buf_x.pop();
    bfs_buf_y.pop();
    bfs_buf_step.pop();

    cnt_step = c_step;

    // search adjacent
    s_x = c_x; s_y = c_y-1;
    if(field[s_y][s_x] == 0) {
      bfs_buf_x.push(s_x);
      bfs_buf_y.push(s_y);
      bfs_buf_step.push(c_step+1);
      field[s_y][s_x] = 1;
    }
    s_x = c_x-1; s_y = c_y;
    if(field[s_y][s_x] == 0) {
      bfs_buf_x.push(s_x);
      bfs_buf_y.push(s_y);
      bfs_buf_step.push(c_step+1);
      field[s_y][s_x] = 1;
    }
    s_x = c_x+1; s_y = c_y;
    if(field[s_y][s_x] == 0) {
      bfs_buf_x.push(s_x);
      bfs_buf_y.push(s_y);
      bfs_buf_step.push(c_step+1);
      field[s_y][s_x] = 1;
    }
    s_x = c_x; s_y = c_y+1;
    if(field[s_y][s_x] == 0) {
      bfs_buf_x.push(s_x);
      bfs_buf_y.push(s_y);
      bfs_buf_step.push(c_step+1);
      field[s_y][s_x] = 1;
    }
  }

  cout << cnt_step << endl;

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;i++){
  	cin >> d[i];
  }
  sort(d.begin(), d.end());
  if(d[n/2-1]==d[n/2])
    cout << 0;
  else if(d[n/2-1]<d[n/2])
    cout << d[n/2]-d[n/2-1];
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
 ll n;
  cin>>n;
  //!!;
  ll ans=0;
                if(n%2==1) {
                  cout<<0<<endl;
 					return 0;
                }
  else{
   //5の数
    n/=2;
    
    while(n>0){
     n/=5;
      ans+=n;
    }
    cout<<ans<<endl;
 }
}





Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();

		if(a > b){
			if(b == 1){
				System.out.println("Bob");
			}else{
				System.out.println("Alice");
			}
		}else if (a < b){
			if(a == 1){
				System.out.println("Alice");
			}else {
				System.out.println("Bob");
			}
		}else {
			System.out.println("Draw");
		}
	}
}


Measured memory_bytes: 21844
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
	string s;
    int k;
    cin >> k >> s;
    
    if(s.size() <= k){
        cout << s << endl;
    }else{
        REP(i,k) cout << s[i];
        cout << "...\n";
    }
	
	return 0;
}

Measured memory_bytes: 3604
package main

import (
	"fmt"
)

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

	ret := float64(0)
	for i := 1; i <= n; i++ {
		tmp := 1.0 / float64(n)
		now := i
		for now < k {
			now *= 2
			tmp /= 2
		}
		ret += tmp
	}
	fmt.Print(ret)

}


Measured memory_bytes: 512
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		if(n%2==0){
			long count=0;
			long k=5;
			while(n/(2*k)>0){
				count+=n/(2*k);
				k*=5;
			}
			System.out.println(count);
		}else{
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

const ll INF = 1e9+7;

// 各桁の和
template<typename T>T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

#define test(a) cout<<#a<<':'<<a<<endl

class tree{
public:
  tree* par;
  vector<tree*> chi;
  int cnt;
};


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<int> h(n);rep(i,n)cin>>h[i];
  int ans = 0;
  int tmp = 0;
  rep(i,n-1){
    if(h[i] >= h[i+1])++tmp;
    else {
      ans = max(tmp,ans);
      tmp = 0;
    }
  }
  ans = max(tmp,ans);
  print(ans);
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define _LIBCPP_DEBUG 0
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;
//g++ -std=c++1z main.cpp
//.\a.exe
int main(){
///////////////////////////////////////////////////////////
int r;
cin >> r;
cout << r*r << endl;
//////////////////////////////////////////////////////////
}

Measured memory_bytes: 256
#include<stdio.h>
char s[111111];
int main(){
	scanf("%s",s);
	int res=0;
	for(int i=0; s[i]; i++){
		char t = i%2?'p':'g';
		if(s[i] != t){
			if(t == 'p')res++;else
				res--;
		}
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

long long GCD(long long a, long long b){
    if(a<b){long long t=a; a=b; b=t;}
    if(b==0) return a;
    return(GCD(a%b, b));
}

int main(){
    long long  N,X; cin >> N >> X;
    long long ans;
    for(int i=0;i<N;i++){
        long long n; cin >> n;
        if(i==0) {ans = abs(n-X); continue;}
        ans = GCD(abs(n-X), ans);
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {

  int N, K; std::cin >> N >> K;
  std::vector<ll> x(N); for(int i=0; i<N; i++) std::cin >> x[i];

  // l ~ r : std::abs(x[l]) + std::abs(x[r]-x[l]) + std::abs(x[r]) minimum
  ll ans = 1e18;
  for(int i=0; K+i-1<N; i++) {
    ans = std::min( { ans, std::abs(x[i]) + std::abs(x[i+K-1]-x[i]), std::abs(x[i+K-1]) + std::abs(x[i+K-1]-x[i]) } );
  }
  if ( ans == 1e18 ) ans = 0;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 1024
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
n = n%10
if n == 3:
    print('bon')
elif n in [2,4,5,7,9]:
    print('hon')
else:
    print('pon')

Measured memory_bytes: 9176
#include<iostream>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	bool n=0;
	for(int i=0;i<=x;i++){
		if(2*i+4*(x-i)==y)n=1;
	}
	if(n==1)cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<math.h>

int main(void){

int N,K,i,j,c;
long double x=0;

scanf("%d %d",&N,&K);

for(j=1;j<=N;j++){
   i=j;
   c=0;
   while(i<=(K-1)){
     i+=i;
     c++;
   }
   x=x+(1/(N*pow(2,c)));
}
   printf("%1.12Lf\n",x);

return 0;
}


Measured memory_bytes: 128
open System

let N =stdin.ReadLine()|>int
let A =stdin.ReadLine().Split()|>Array.map double
[<EntryPoint>]
let main argv =
    A
    |>Seq.sumBy(fun c -> (1.0/c))
    |>fun c -> (1.0/c)
    |>printfn "%f"
    0

Measured memory_bytes: 14044
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a-b>0)cout<<a-b<<endl;
	else cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,sum;
	scanf("%d %d %d",&a,&b,&c);
	sum=a+b+c;
	if(sum<=21){
		printf("win");
	}
	else{
		printf("bust");
	}
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <iostream>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
#include <cmath>

using namespace std;

const int mod = 1000000007;

int ipow(int x, int y)
{
    if(y == 0)
        return 1;
    if(y % 2)
        return 1LL * ipow(x, y - 1) * x % mod;
    int t = ipow(x, y / 2);
    return 1LL * t * t % mod;
}

int inv(int x)
{
    return ipow(x, mod - 2);
}

int arr[100010];
int pos[100010];
int res[100010];

int fac[100010];
int caf[100010];

int ncr(int n, int r)
{
    return 1LL * fac[n] * caf[r] % mod * caf[n - r] % mod;
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, i;
    scanf("%d", &n);
    for(i = 1; i <= n + 1; i++)
        scanf("%d", &arr[i]);

    int x, y;
    for(i = 1; i <= n + 1; i++)
    {
        if(!pos[arr[i]])
            pos[arr[i]] = i;
        else
        {
            x = pos[arr[i]];
            y = i;
            break;
        }
    }

    fac[0] = 1;
    for(i = 1; i <= n + 1; i++)
        fac[i] = 1LL * fac[i - 1] * i % mod;
    for(i = 0; i <= n + 1; i++)
        caf[i] = inv(fac[i]);

    int t = n + 1 - (y - x + 1);
    for(i = 1; i <= n + 1; i++)
    {
        res[i] = ncr(n + 1, i);
        if(1 <= i && i - 1 <= t)
            res[i] = (res[i] - ncr(t, i - 1) + mod) % mod;
    }

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

Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
#define INF 100000000
#define MAX_C 100
using namespace std;
map<int, int> mp;
int main()
{
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> a(m);
	for (int i = 0; i < m; i++) cin >> a[i];
	int left = 0, right = 0;
	for (int i = 0; i < m; i++) {
		if (a[i] < x) left++;
		else right++;
	}
	cout << min(left, right) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
int a,b,sum=0,i;
  
  scanf("%d %d",&a,&b);
  
  for(i=0;i<=1;i++){
  if(a>=b){
  sum=sum+a;
    a=a-1;
  }
    else{
    sum=sum+b;
      b=b-1;
    }
  }
  
  printf("%d",sum);
  
  return 0;
}

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

int main() {
  int D; cin >> D;
  if ( D == 25 ) cout << "Christmas" << endl;
  else if ( D == 24 ) cout << "Christmas Eve" << endl;
  else if ( D == 23 ) cout << "Christmas Eve Eve" << endl;
  else if ( D == 22 ) cout << "Christmas Eve Eve Eve" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define SQ(x)	((x) * (x))

int main(void)
{
	int a, b, c, i, n;
	int sub1, sub2, max;
	
	scanf("%d", &n);
#if 0
	for (i = 0; i < n; i++){
		scanf("%d %d %d", &a, &b, &c);
		if (a >= b && a >= c){
			max = a * a;
			sub1 = b * b;
			sub2 = c * c;
		}
		else if (b > a && b > c){
			max = b * b;
			sub1 = a * a;
			sub2 = c * c;
		}
		else if (c > a && c > b){
			max = c * c;
			sub1 = b * b;
			sub2 = a * a;
		}
		
		if (sub1 + sub2 == max){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
#endif

	for (i = 0; i < n; i++){
		int ps[3];
		int j;
		for (j = 0; j < 3; j++){
			scanf("%d", &ps[j]);
		}
		for (j = 1; j < 3; j++){
			if (ps[0] < ps[j]){
				int t = ps[0];
				ps[0] = ps[j];
				ps[j] = t;
			}
		}
		if (SQ(ps[0]) == SQ(ps[1]) + SQ(ps[2])){
			puts("YES");
		}
		else {
			puts("NO");
		}
	}
	return (0);
}

Measured memory_bytes: 580
def make_divisors(n):
    divisors = []

    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return divisors


A, B, K = map(int, input().split())
divisors_all = make_divisors(A) + make_divisors(B)
divisors = sorted([i for i in set(divisors_all)
                   if divisors_all.count(i) == 2], reverse=True)
print(divisors[K - 1])


Measured memory_bytes: 3064
using System;
using System.Linq;

namespace ABC153_C
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            long[] NK = Console.ReadLine().Trim().Split(' ').Select(a => long.Parse(a)).ToArray();
            long[] H = Console.ReadLine().Trim().Split(' ').Select(a => long.Parse(a)).ToArray();
            long count=0;
            Array.Sort(H);
            Array.Reverse(H);
            for(long i = 0; i < NK[0]; i++)
            {
                if (NK[1] > 0)
                {
                    NK[1]--;
                }
                else
                {
                    count += H[i];
                }
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 35328
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
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,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors
#print(make_divisors(10))
n=I()
lis=sorted(LI())
u=make_divisors(lis[0])

for j in range(len(u)):
    br=u[j]
    count=0
    #print(br)
    for i in range(n):
        if lis[i]%br!=0:
            count+=1
    if count<=1:
        ans1=br
        break
#print(ans1)

v=make_divisors(lis[1])

for j in range(len(v)):
    bre=v[j]
    counti=0
    #print(bre)
    for i in range(n):
        if lis[i]%bre!=0:
            counti+=1
    if counti<=1:
        ans2=bre
        break
#print(ans2)
print(max(ans1,ans2))

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

int main() {
	 long long int a,b,n;
	cin>>a>>b>>n;
	long long int x;
	if(b>n){
	x=n;
	}
	else
	{
	x=b-1;
	}
	cout<<floor(a*x/b)-a*floor(x/b)<<endl;
}



Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define mod (1000*1000*1000+7)
using namespace std;
typedef long long i64;
int main() {
    int h,w;
    cin>>h>>w;
    string s[h];
    i64 dp[h+1][w+1] = {0};
    for(int i = 0; i < h; i++)
        cin>>s[i];
    dp[1][1] = 1;
    for(int i = 0; i <= h; i++) {
        for(int j = 0; j <= w; j++) {
            dp[1][1] = 1;
            if(i == 0 || j == 0)
                dp[i][j] = 0;
            else if(s[i-1][j-1] == '#')
                dp[i][j] = 0;
            else 
                dp[i][j] = (dp[i][j-1]+dp[i-1][j])%mod;
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    cout<<dp[h][w]<<endl;
}

Measured memory_bytes: 9088
s = input()
n,m = 0,0
for i in range(len(s)):
    if i%2==0 and s[i]=='0': n+=1
    if i%2==1 and s[i]=='1': n+=1
for i in range(len(s)):
    if i%2==0 and s[i]=='1': m+=1
    if i%2==1 and s[i]=='0': m+=1
print(min(n,m))

Measured memory_bytes: 3188
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    
    N,Q=MI()
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        a,b = MI_()
        edges[a].append(b)
        edges[b].append(a)
    counter = [0]*N
    for _ in range(Q):
        p,x = MI()
        counter[p-1]+=x

    serched = {0}
    def dfs(now_sum,node):
        now_sum += counter[node]

        ans[node] = now_sum
        for b in edges[node]:
            if b not in serched:
                serched.add(b)
                dfs(now_sum,b)
            

    ans = [0]*N
    dfs(0,0)
    print(*ans)


    
if __name__ == '__main__':
    main()

Measured memory_bytes: 283012
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(void) {
    int n, k, l[50], ans = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    REP(i, n) {
        cin >> l[i];
    }
    sort(l, l + n, greater<int>());
    REP(i, k) {
        ans += l[i];
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		long ans = 0;

		Scanner sc = new Scanner(System.in);
		int  n = sc.nextInt();
//		longd = sc.nextInt();
//
		boolean f = false;
		int[] array = new int [n+1];
		int[] array2 = new int[n];
		for (int i = 0; i < n+1; i++) {
			array[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			array2[i] = sc.nextInt();
		}

		long  tmp = 0;
		for (int i = 0; i < n+1; i++) {
			if(tmp > 0) {
				if(array[i]>=tmp) {
					ans = ans + tmp;
					array[i] = array[i] - (int)tmp;
				} else {
					ans = ans + array[i];
					array[i]=0;
				}
				tmp = 0;
			}
			if(i == n) {
				continue;
			}
			if(array[i] >= array2[i]) {
				ans = ans + array2[i];
				tmp = 0;
			} else {
				ans = ans + array[i];
				tmp  = (array2[i] - array[i]);
			}
//			System.out.println(ans);
		}

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 84036
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>

#define ok printf("ok\n");
#define MAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

int main()
{
	ll n,sec,go;
	int a,b,ans = 1;
	string s,t;
	bool flag;
	cin >> a;
	vi moti(a);
	rep(i,a)
	{
		cin >> moti[i];
	}
	sort(all(moti));

	rep(i,a-1)
	{
		//cout << moti[i] << " " << moti[i+1] << endl;
		if(moti[i]<moti[i+1])
		{
			//ok
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
//File Name: arc074_B.cpp
  //Created Time: 2017年06月13日 星期二 15时50分50秒
                                   
#include <bits/stdc++.h>
#define LL long long
#define pii pair<int,int>
#define fir first
#define sec second
using namespace std;
const int MAXN = 300000 + 5;
LL a[MAXN];
pii b[MAXN];
int is[MAXN]; //表示第i个数目前属于哪里：1大的，0候选，2小的
bool cmp(pii x,pii y){
	if(x.fir == y.fir) return x.sec < y.sec;
	return x.fir > y.fir;
}
LL solve(const int n){
	LL res(0),big(0),small(0);
	sort(b + 1,b + n + n + 1,cmp);
	for(int i(1);i<=n;++i){
		is[b[i].sec] = 1;
		big += b[i].fir;
	}
	priority_queue<pii> que; //用来保存目前的候选数
	for(int i(n+1);i<=2 * n;++i){
		is[b[i].sec] = 0;
		que.push(b[i]);
	}
	priority_queue<int> rem;  //用来保存目前的后面的前n小个数
	for(int i(n + n + 1);i<=3 * n;++i){
		is[i] = 2;
		small += a[i];
		rem.push(a[i]);
	}
	res = big - small;
	for(int i(n + n);i>n;--i){
		if(is[i] == 1){
			big -= a[i];
			pii tmp;
			while(!que.empty()){
				tmp = que.top();
				que.pop();
				if(is[tmp.sec]) continue;
				else break;
			}
			big += tmp.fir;
			is[tmp.sec] = 1;
		}
		is[i] = 2;
		LL cur = rem.top();
		if(cur > a[i]){
			rem.pop();
			small += a[i] - cur;
			rem.push(a[i]);
		}
		res = max(res,big - small);
	}
	return res;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i(1);i<=3*n;++i){
		scanf("%d",a + i);
		b[i] = pii(a[i],i);
	}
	printf("%lld\n",solve(n));
	return 0;
}



Measured memory_bytes: 7796
#include<iostream>
using namespace std;
int main(){
int a=0,b=0,tmp;
for(int i=0;i<4;i++){
cin >> tmp; a+=tmp;
}
for(int i=0;i<4;i++){
cin >> tmp; b+=tmp;
}
cout << std::max(a,b) << endl;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void){
	double sum;
	int n, m, p, i, x[100];
	while(1){
		scanf("%d%d%d",&n,&m,&p);
		if(n == 0 && m == 0 && p == 0)
			break;
		sum = 0;
		for(i = 0;i < n;i++){
			scanf("%d",&x[i]);
			sum += 100 * x[i];
		}
		if(x[m - 1] != 0){
			sum = sum * (100 - p) * 0.01;
			sum /= x[m - 1];
			printf("%d\n",(int)sum);
		}
		else
			printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 1036
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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

#define forn(i, a, n) for (int i = (a); i < (int)n; i++)
#define trav(x, arr) for (auto &x : arr)
#define sz(x) (int)x.size()
#define Matrix(m, h, w) std::vector<vector<int>> m(h, vector<int> (w)); 
using ll = long long;

#define vi vector<int>
#define vl vector<long>
#define vll vector<ll>

// benq
const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;


ll mysum(map<ll,ll> &m, ll &firstValue, ll v, ll r) {

    ll oldV = (v * m[v]), oldR = 0;
    if (m.find(r) != m.end())
        oldR = (m[r] * r);

    oldV += oldR;

    m[r] += m[v];

    m.erase(v);

    ll newValue = (r * m[r]);

    // cout << "Old " << oldV << " New " << newValue << endl;


    firstValue -= oldV;
    firstValue += newValue;

    if (m.size() == 1)
        return newValue;
    else
        return firstValue;

    return firstValue;
}

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

    int n; cin >> n;
    map<ll,ll> m {};

    forn(i,0,n) {
        ll x; cin >> x;
        m[x]++;
    }
    int q; cin >> q;

    ll firstSum = 0;

    map<ll,ll>::iterator it;

    for (it = m.begin(); it != m.end(); it++) {

        firstSum += (it->first * it->second);

    }

    forn(i, 0, q) {
        ll value, newValue;
        cin >> value >> newValue;

        cout << mysum(m, firstSum, value, newValue) << endl;
    }


    return 0;
}

Measured memory_bytes: 7604
import sys
A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
C = [2]

nums = [int(x) for x in input().split()]
a = nums[0]
b = nums[1]

for group in [A,B,C]:
	if a in group:
		if b in group:
			print("Yes")
			sys.exit()

print("No")

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  string ans;
  while (n) {
    n--;
    ans.push_back('a' + (n % 26));
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans;
}

Measured memory_bytes: 3124
#include <iostream>
#include <cmath>
#define EPS 1e-9
using namespace std;
 
int main() {
  int n, d;
  long long x, y;
  int res = 0;
  cin >> n >> d;
  for (int i = 0 ; i < n ; i++){
    cin >> x >> y;
    if ((sqrt(x*x+y*y) - d) < EPS) {
      res++;
    }
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,lli,N,0);
  rep(i,0,N)cin >> P[i];
  A=P[0];
  rep(i,1,N){
    if(A<P[i])sum++;
    A=min(A,P[i]);
  }
  Out(N-sum);
}

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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
//#define ld long double
#define mod 1000000007
#define inf 100000000000010
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;
typedef long double ld;
bool isprime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}




ll builtin_popcount(ll x)
{
    ll cnt = 0;
    for(ll i=60;i>=0;i--)
    {
        if((1LL<<i)&x)cnt++;
    }
    return cnt;
}

ll addmod(ll a,ll b,ll r)
{
    a%=r;
    b%=r;
    return (a+b)%r;
}
ll mulmod(ll a,ll b,ll r)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll submod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    a-=b;
    if(a<0)a+=mod;
    return a%mod;
}
struct CustomCompare
{
    bool operator()(ll a,ll b)
    {
        return a>b;
    }
};
/*
const int mxn = 5*(1e6) +10;
vi spf(mxn);
void sieve()
{
    for(ll i =0;i<mxn;i++)spf[i]  = i;
    for(ll i=2;i<mxn;i+=2)spf[i] = 2;
    for(ll i = 3;i*i<mxn;i++)
    {
        if(spf[i]==i)
        {
            for(ll j = i*i;j<mxn;j+=i)
            {
                if(spf[j]==j)spf[j] = i;
            }
        }
    }
}
*/

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll n; cin>>n;
ll ans = modexp(10LL,n,mod);
ans = addmod(ans,modexp(8LL,n,mod),mod);
ans = submod(ans,2LL*modexp(9LL,n,mod));
cout<<ans<<"\n";
return 0;
}
/*
1
3 1
023l
2 3
*/


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	int K, A, B; 
	cin >> K >> A >> B;

	bool ok = false;
	FOR(i, A, B+1){
		if(i%K == 0) ok = true;
	}

	if(ok) cout << "OK" << endl;
	else cout << "NG" << endl;

	return 0;

}


Measured memory_bytes: 3624
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

c = 0
for i in range(n):
    ai = a[i]
    bi = b[i]
    if ai < bi:
        c += (bi-ai)//2
    else:
        c -= (ai-bi)
print('Yes' if c >= 0 else 'No')


Measured memory_bytes: 4600
using System;

public class ABC150A {
  public static void Main(string[] args) {
    var str = Console.ReadLine();
    int n = int.Parse(str);
    string s = Console.ReadLine();
    int count = 0;
    int flag = 0;
    
    for (int i = 0; i < n-2; i++) {
      //string str2 = s[i] + s[i+1] + s[i+2];
      string str2 = String.Concat(s[i], s[i+1], s[i+2]);
      //Console.WriteLine(str2);
      if (str2.Equals("ABC")) {
        count++;
      }
       /*
      if ((s[i].Equals("A") && flag == 0) || (s[i].Equals("B") && flag == 1)) {
        flag++;
      }else if (s[i].Equals("C") && flag == 2) {
        count++;
        flag = 0;
      }else {
        flag = 0;
      }
      */
    }
    
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 13140
import java.util.Scanner;


public class Main {

    public static int getSum(int x) {
	int sumv = 0;
	while ( true ) {
	    sumv += x%10;
	    x /= 10;
	    if ( x == 0 ) break;
	}
	return sumv;
    }

    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	int a = sc.nextInt();
	int b = sc.nextInt();

	int sumv = 0;
	for ( int x=1; x<n+1; x++ ) {
	    int y = getSum(x);
	    if ( a <= y && y <= b ) {
		sumv += x;
	    }
	}
	System.out.println(sumv);
    }

}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	int res = 1;
	for (int i = 1; i*i <= M; i++) {
		if (M%i == 0) {
			if (i*N <= M) {
				res = max(res, i);
			}
			if ((M/i) * N <= M) {
				res = max(res, M/i);
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb1(x) cout << #x << ": " << x << endl
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define prec(n) fixed << setprecision(n)
#define all(a) a.begin(), a.end()
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define pii pair<int, int>
#define vii vector<int>
#define ld long double
#define int long long
#define MOD LLONG_MAX
#define mp make_pair
#define pb push_back
#define endl "\n";
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
/*----------------------------------TEMPLATE------------------------------------*/
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    /*----------------------------PEEPEEPOOPOO-------------------------------------*/
    int t;
    //cin >> t;
    t = 1;
    while (t--)
    {
        int n;
        cin >> n;
        vii x;
        vii y;
        rep(i,0,n)
        {
            int a,b;
            cin >> a >> b;
            x.pb(a);
            y.pb(b);
        }
        vii xplusy;
        vii xminusy;
        rep(i,0,n)
        {
            xplusy.pb(abs(x[i])+abs(y[i]));
            xminusy.pb(abs(x[i]) - abs(y[i]));
        }
        cout << max((*max_element(all(xplusy)) - *min_element(all(xplusy)))
        , (*max_element(all(xminusy)) - *min_element(all(xminusy)))) << endl;
    }
    return 0;
}
/*--------------------------------PEEPEEPOOPOO-------------------------------------*/

Measured memory_bytes: 11436
#include <stdio.h>
int main(void)
{

	int i, j, r[200000], d, rmin, dmax, k;
	scanf("%d",&i);

	for (j = 0; j < i; j++)
	{
		scanf("%d",&r[j]);
	}

	rmin = r[0];
	dmax = r[1] - r[0];
	for (j = 1; j < i; j++)
	{	
		
		if (dmax < r[j] - rmin)
		{
			dmax = r[j] - rmin;
		}
		if (rmin > r[j])
		{
			rmin = r[j];
		}
		

		//printf("dmax:%d, rmin:%d\n", dmax, rmin );
		
	}

	printf("%d\n", dmax);
	
	return 0;
}

Measured memory_bytes: 2608
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <fstream>	// require freopen

using namespace std;

typedef long long ll;

int main()
{
//	cut here before submit 
//	freopen ("testcase.lining_up_card", "r", stdin );
	int n, k;

	while (cin >> n >> k && n && k ) {
//		vector <string> card (n );
		vector <int> card (n, 0 );
		for (int i = 0; i < n; ++i ) {
			cin >> card[i];
		} // end for
		sort (card.begin(), card.end() );
		set <ll> res;

		do{
			ll sum = 0LL;
			for (int i = 0; i < k; ++i ){
				if (card[i] < 10 ){
					sum *= 10LL;
				}else{ 
					sum *= 100LL;
				} // end if
				sum += (ll)card[i];
//				cout << card[i] << ' ';
			} // end for

//			if (!res.count (sum ) ){
//				cout << "sum: " << sum << endl;
			res.insert (sum );
//			}else{
//				cout << endl;
//			} // end if
		}while ( next_permutation (card.begin(), card.end() ) );

		cout << res.size() << endl;
		
	} // end loop
		
	return 0;
}

Measured memory_bytes: 988
def main():
    x, y, z = (int(_) for _ in input().split(' '))
    if any(_ % 2 == 0 for _ in (x, y, z)):
        print(0)
        return
    t = max((x, y, z))
    if t == x:
        print(y * z)
    elif t == y:
        print(x * z)
    elif t == z:
        print(x * y)


if __name__ == '__main__':
    main()


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

int main() {
int N;
cin >>N;
string S;
cin >>S;
char A=S.at(0);
int counter=0;

for(int i=0;i<N;i++){
if(A!=S.at(i)){
counter++;}
A=S.at(i);
}
cout << counter+1<<endl;

}


Measured memory_bytes: 512
import bisect

n=int(input())
a = []
INF = float('inf')
for i in range(n):
    aa = int(input())
    a.append(aa)
#dp[i][j] =a_0～a_iにおける長さjの部分増加列の最後の数のmin
#dp[i][j] = dp[i-1][j-1] < a[i]ならmin(a[i],dp[i-1][j])
#            そうでないならdp[i-1][j]

dp = [INF for i in range(n)]
dp[0] = a[0]
for i in range(1,n):
        p = bisect.bisect_left(dp, a[i])
        dp[p] = min(a[i],dp[p])

print(bisect.bisect_left(dp, INF))


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

int main()
{
    map<string,int> str;
    map<string,int> :: iterator it;
    string s,t1,t2;
    int max1=0,max2=0;

    while(cin >> s)
    {
        str[s]++;
        if(s.size()>max1)
        {
            max1 = s.size();
            t1 = s;
        }
        if(str[s]>max2)
        {
            max2 = str[s];
            t2 = s;
        }
    }

    cout << t2 << " " << t1 << "\n";
    return 0;
}

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

#define WHITE 0
#define GRAY 1
#define BRACK 2

int **matrix;
int *color;
int *dist;

int n;
int time;

int *queue;
int head;
int tail;

void enqueue(int);
int dequeue(void);
void bfs(void);


int main(){
  int i,j,u,k,v;

  scanf("%d",&n);

  queue = malloc((n+1) * sizeof(int));
  color = malloc((n+1) * sizeof(int));
  dist = malloc((n+1) * sizeof(int));
 
  
  matrix = malloc((n+1) * sizeof(int *));
  for(i=0;i<n+1;i++) matrix[i] = malloc((n+1) * sizeof(int));


  for(i=1;i<n+1;i++){
 dist[i] = -1;
 color[i] =WHITE;
  }
  
  for(i=1;i<n+1;i++)
    for(j=1;j<n+1;j++)
      matrix[i][j] = 0;
  
  
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      matrix[u][v] = 1;
    }
  }


  bfs();
 

  for(i=1;i<n+1;i++) printf("%d %d\n",i,dist[i]);

  for(i=0;i<n+1;i++)
    free(matrix[i]);
  free(matrix);
  free(queue);
  free(dist);
  free(color);

  return 0;
}

void bfs(){
  int u,i;

  head = tail = 0;
  color[1] = GRAY;
  dist[1] = 0;
  enqueue(1);
  
  while(head != tail){
    u = dequeue();
    for(i=1;i<n+1;i++){
      if(matrix[u][i] == 1 && color[i] == WHITE){
	color[i] = GRAY;
	dist[i] = dist[u] + 1;
	enqueue(i);
      }
    }
    color[u] = BRACK;
  }
}

void enqueue(int q){
  
  queue[tail] = q;
  if(++tail == (n+1)) tail = 0;
  
}

int dequeue(){
  int v;
  
  v = queue[head];
  if(++head == (n+1)) head=0;
  return v;

}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
const int N = 10010;
int fa[N];
int findfa(int x){
    if(x == fa[x]) return x;
    return findfa(fa[x]);
}
int main(){
    int n, q;
    scanf("%d %d", &n, &q);
    for(int i = 0; i < n; i++) fa[i] = i;
    for(int time = 0; time < q; time++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        if(a == 1){
            printf("%d\n", findfa(b) == findfa(c) ? 1 : 0);
        }else{
            fa[findfa(b)] = findfa(c);
        }
    }
    return 0;
}



Measured memory_bytes: 3272
n,d = map(int, input().split())
arr = []
for _ in range(n):
  x = list(map(int,input().split()))
  arr.append(x)

ans = 0
for i in range(len(arr)-1):
  for j in range(i+1, len(arr)):
    dis = 0
    for k in range(d):
      dis += (arr[i][k] - arr[j][k])**2
    l = 0
    while l*l < dis:
      l+=1
      if l*l == dis:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <vector>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

ll dist[10][10];

int main() {
  int h, w;
  scanf("%d %d", &h, &w);

  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      dist[i][j] = INF;
    }
  }

  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      ll cost;
      scanf("%lld", &cost);
      dist[i][j] = cost;
    }
  }

  for (int k = 0; k < 10; ++k) {
    for (int i = 0; i < 10; ++i) {
      for (int j = 0; j < 10; ++j) {
	dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int n;
      scanf("%d", &n);
      if (n != -1 && n != 1)
	ans += dist[n][1];
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int32_t main(){
    FAST
    int n;cin>>n;
    vector<int> v(n);
    for(int &i : v) cin>>i;
    sort(v.begin(),v.end(),greater<int>());
    if(n==1){
        cout<<0<<"\n";
        return 0;
    }
    else if(n==2){
        cout<<v[0]<<"\n";
        return 0;
    }
    int ans=v[0];
    float idx=1;
    for(int i=2;i<n;i++){
        ans+=v[(int)idx];
        idx=idx+0.5;
        // cout<<idx<<" ";
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4780
s1 = input()

r1 = 0
n1 = 0
for i1 in range(len(s1)):
    if s1[i1] == "A" or s1[i1] == "T" or s1[i1] == "C" or s1[i1] == "G":
        n1 += 1
    else:
        r1 = max(n1,r1)
        n1 = 0
r1 = max(n1,r1)

print(r1)

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

using namespace std;
typedef long long ll;

int main(){
    vector<ll> ar;
    int n;
    cin >> n;
    ll tmp;
    ll hoge; cin >> hoge; ar.push_back(hoge);
    for(int i=1;i!=n;i++){
    ll hoge; cin >> hoge; ar.push_back(hoge);
  }
  int ans=0;
  sort(ar.begin(),ar.end());
  ll tmp2=0;
  for(int i=0;i!=n;i++){
    if(tmp2!=ar.at(i)){
      ans++;
      tmp2=ar.at(i);
    }
    else{
      ans--;
      tmp2=0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1400
import java.util.*;

public class Main {
	public static void main(String[] args) {
		// practice contest

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a == 1 && b == 2) {
			System.out.println(3);
		} else if (a == 1 && b == 3) {
			System.out.println(2);
		} else if (a == 2 && b == 3) {
			System.out.println(1);
		} else if (a == 2 && b == 1) {
			System.out.println(3);
		} else if (a == 3 && b == 1) {
			System.out.println(2);
		} else if (a == 3 && b == 2) {
			System.out.println(1);
		} else if (b == 1 && a == 2) {
			System.out.println(3);
		} else if (b == 1 && a == 3) {
			System.out.println(2);
		} else if (b == 2 && a == 3) {
			System.out.println(1);
		} else if (b == 2 && a == 1) {
			System.out.println(3);
		} else if (b == 3 && a == 1) {
			System.out.println(2);
		} else if (b == 3 && a == 2) {
			System.out.println(1);
		}

	}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  ll N;
  cin >> N;
  bool ans = true;
  ll a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    if (a % 2 != 0) continue;
    if (a % 3 != 0 && a % 5 != 0) ans = false;
  }

  if (ans)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.function.IntToDoubleFunction;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = getInt(sc);
		int y = getInt(sc);

		boolean ng = true;
		for (int i = 0; i <= x; i++) {
			// 全部カメから計算
			if (2 * i + 4 * (x - i) == y) {
				System.out.println("Yes");
				ng = false;
			}
		}
		if (ng) {
			System.out.println("No");
		}

	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if(B < C || D < A){
    cout << 0 << endl;
  }
  else{
    cout << min(B,D) - max(A,C) << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
// cout << fixed << setprecision(10);
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
int main(){
    int N; cin >> N;
    int mon[1000100]; fill(mon,mon+1000100,MM);
    mon[0] = 0;
    int a[14] = {1,6,36,216,1296,7776,46656,279936,9,81,729,6561,59049,531441};
    for (int i = 0; i < 13; i++){
        for (int num = 0; num <= 1000010; num++){
            if (num >= a[i]){
                mon[num] = min(mon[num], mon[num-a[i]] + 1);
            }
        }
    }
    cout << mon[N] << endl;
} 


Measured memory_bytes: 4096
#include<iostream>
using namespace std;
int main(){
  int n,pointA,pointB;
  int a[10000],b[10000];
  for(n = 1;n != 0;){  
 cin >> n;
 if(n != 0){
    pointA = 0; pointB = 0;
  for(int i = 0;i < n;i++){
    cin >> a[i] >> b[i];
  }
  for(int i = 0;i< n;i++){
    
    if(a[i] < b[i]){
      pointB = pointB + a[i] +b[i];
    } else if(a[i] > b[i]){
      pointA = pointA + a[i] +b[i];
    } else if(a[i] == b[i]){
      pointA = pointA + a[i];
      pointB = pointB + b[i];
    }
  }
 
  cout << pointA << " "<< pointB << endl;
 }
  }
  
  
}

Measured memory_bytes: 0