akhauriyash/Code-Regression huggingface dataset:
def main():
    N,K = map(int,input().split())
    l_s = list(map(int,input().split()))
    l_s.sort()
    l_s.reverse()
    length = 0
    for i in range(K):
        length += l_s[i]
    print(length)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int N;
	long long ans = 0;

	cin >> N;

	for (int ni = 1; ni < N; ni++){
		ans += ni;
	}

	printf("%lld\n", ans);


	return 0;
}



Measured memory_bytes: 256
import numpy as np
pi = np.pi

a, b , h, m = list(map(int, input().split()))

short = 2*pi*(h*60+m)/720
long = 2*pi*m/60

if short <= long:
    ans = np.sqrt(a**2 + b**2 - 2*a*b*np.cos(long - short))
else:
    ans = np.sqrt(a**2 + b**2 - 2*a*b*np.cos(short - long))
    
print(ans)

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

int main() {
  string str;
  cin >> str;

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

  if (str[0] == str[1] && str[2] == str[3] && str[1] != str[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

using i64 = int64_t;

int main() {
  int n;
  cin >> n;
  vector<i64> a(n), b(n);
  for (i64& x : a) cin >> x;
  for (i64& x : b) cin >> x;
  i64 sa = accumulate(a.begin(), a.end(), 0ll);
  i64 sb = accumulate(b.begin(), b.end(), 0ll);
  i64 ma = sb - sa;
  i64 m1 = 0, m2 = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > b[i])
      m1 += a[i] - b[i];
    else
      m2 += (b[i] - a[i] + 1) / 2;
  }
  cout << ((ma >= m1 && ma >= m2) ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 3764
from bisect import bisect_left
from itertools import accumulate

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

Acum = [0] + list(accumulate(A))

left = 0
right = 10 ** 10 + 1

while left + 1 < right:
  mid = (left + right) // 2
  tmp = 0
  for i in range(N):
    bi = bisect_left(A, mid - A[i])
    tmp += N - bi
  if tmp <= M:
    right = mid
  else:
    left = mid

cnt = 0
answer = 0
for i in range(N):
  bi = bisect_left(A, right - A[i])
  cnt += N - bi
  answer += Acum[N] - Acum[bi] + A[i] * (N - bi)

print(answer + (M - cnt) * left)

Measured memory_bytes: 59384
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  list($s) = explode(" ", trim(fgets(STDIN)));

  $ans = 1;
  $zen = $s[0];
  for ($i=1; $i<$n; $i++) {
    if($zen != $s[$i]){
      $ans++;
      $zen = $s[$i];
    }
  }

  echo $ans;

Measured memory_bytes: 4604
#include<iostream>
using namespace std;
int main()
{
    int i,n,k,c=0,l;
    cin>>n;
    int a[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>l;
        a[l]=i;
    }
    for(i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 3880
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

int n, m;
vector<int> eds[120000];
int was[120000];
int cl[120000];
int gl;

void dfs1(int v, int c) {
	cl[v] = c;
	was[v] = 1;
	for (int u: eds[v]) {
		if (!was[u]) {
			dfs1(u, c ^ 1);
		}
		else {
			if (cl[u] != (cl[v] ^ 1))
				gl = 1;
		}
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		--a, --b;
		eds[a].push_back(b);
		eds[b].push_back(a);
	}
	ll c0 = 0;
	ll c1 = 0;
	ll c2 = 0;
	for (int i = 0; i < n; ++i) {
		if (was[i])
			continue;
		if (eds[i].empty()) {
			++c2;
			continue;
		}
		gl = 0;
		dfs1(i, 0);
		if (gl)
			++c0;
		else
			++c1;
	}
	ll ans = 0;
	ans += c2 * n + (n - c2) * c2;
	ans += c1 * c1 * 2;
	ans += c0 * c0 + c0 * c1 + c1 * c0;
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 10880
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		Long K = Long.parseLong(tokens[1]);
		int[] A = new int[N];
		tokens = in.readLine().split(" ");
		for (int i = 0; i < N; ++i) {
			A[i] = Integer.parseInt(tokens[i]);
		}
		long[] upperNums = new long[N];
		long[] beforeUpperNums = new long[N];
		Arrays.fill(upperNums, 0L);
		Arrays.fill(beforeUpperNums, 0L);
		for (int i = 0; i < N; ++i) {
			int val = A[i];
			for (int j = 0; j <= i - 1; ++j) {
				if (val > A[j]) {
					++beforeUpperNums[j];
				}
			}
			for (int j = i + 1; j < N; ++j) {
				if (val > A[j]) {
					++upperNums[i];
				}
			}
		}
		long result = 0;
		long MOD = 1000000007L;
		long addVal = (K * (K + 1) / 2) % MOD;
		for (int i = 0; i < N; ++i) {
			result += upperNums[i] * addVal;
			result %= MOD;
		}
		addVal = (K * (K - 1) / 2) % MOD;
		for (int i = 0; i < N; ++i) {
			result += beforeUpperNums[i] * addVal;
			result %= MOD;
		}
		System.out.println(result);

	}
}

Measured memory_bytes: 22484
using System;
using System.Collections.Generic;

class ABC
{
    public static void Main()
    {
        string  str = Console.ReadLine();
        List<char> list = new List<char> { };
        foreach(char c in str)
        {
            list.Add(c);
        }

        switch (list.Count) {
            case 1:
                Console.WriteLine(Convert.ToString(list[0]));
                break;
            case 2:
                Console.WriteLine(9);
                break;
            case 3:
                Console.WriteLine(10 +
                    (int.Parse(Convert.ToString(list[0])) - 1) * 100  +
                    int.Parse(Convert.ToString(list[1])) * 10 +
                    int.Parse(Convert.ToString(list[2])));
                break;
            case 4:
                Console.WriteLine(909);
                break;
            case 5:
                Console.WriteLine(910 +
                    (int.Parse(Convert.ToString(list[0])) - 1) * 10000 +
                    int.Parse(Convert.ToString(list[1])) * 1000 +
                    int.Parse(Convert.ToString(list[2])) * 100 + 
                    int.Parse(Convert.ToString(list[3])) * 10 +
                    int.Parse(Convert.ToString(list[4])));
                break;
            case 6:
                Console.WriteLine(90909);
                break;
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
long long a[205],bas[65];
char s[205];
bool add(long long x)
{
	for (int i=60;i>=0;i--)
	{
		if (x&(1LL<<i))
		x^=bas[i];
	}
	if (!x)
	return 1;
	for (int i=60;i>=0;i--)
	{
		if (x&(1LL<<i))
		{
			bas[i]=x;
			return 0;
		}
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while (t--)
	{
		int n;
		scanf("%d",&n);
		for (int i=0;i<n;i++)
		scanf("%lld",&a[i]);
		scanf(" %s",s);
		bool z=1;
		memset(bas,0,sizeof(bas));
		for (int i=n-1;i>=0;i--)
		{
			if (s[i]=='1')
			z&=add(a[i]);
			else
			add(a[i]);
		}
		printf("%d\n",!z);
	}
}

Measured memory_bytes: 3636
#!/usr/bin/env python3
from heapq import heappop,heappush

def main():
    N = int(input())
    red = []
    blue = []
    for i in range(N):
        a, b = map(int, input().split())
        red.append([a,b])
    for i in range(N):
        c, d = map(int, input().split())
        blue.append([c,d])
    blue.sort()
    ans = 0

    for i in range(N):
        pairs = []
        for j in range(len(red)):
            x = blue[i][0] - red[j][0]
            y = blue[i][1] - red[j][1]
            if x > 0 and y > 0:
                heappush(pairs, (y,j))

        if len(pairs) > 0:
            ans += 1
            _, index = heappop(pairs)
            del red[index]
    
    print(ans)


    

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
using namespace std;
#define N 200005
char s[N], t[N];
int G[30][30];
int main()
{
	while(~scanf("%s", s))
	{
		scanf("%s", t);
		int len = strlen(s);
		memset(G, 0, sizeof(G));
		for(int i = 0; i < len; i++)
		{
			G[s[i]-'a'][t[i]-'a'] = 1;
		}
		int w[30], x[30];
		memset(w, 0, sizeof(w));
		memset(x, 0, sizeof(x));
		bool flag = true;
		for(int i = 0; i < 26; i++)
		{
			for(int j = 0; j < 26; j++)
			{
				w[i] += G[i][j];
				x[j] += G[i][j];
				if(w[i] >= 2 || x[j] >= 2)
				{
					flag = false;
					break;
				}
			}
		}
		if(flag) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i%2==0){
                    if(j%2==0){
                        cout<<"#";
                    }
                    else{
                        cout<<".";
                    }
                }
                else{
                    if(j%2==0){
                        cout<<".";
                    }
                    else{
                        cout<<"#";
                    }
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


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

int main() {
  int n, a, b, rank = 1, dare = 0;
  string s;

  cin >> n >> a >> b >> s;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'a' && i + 1 - dare <= a + b)
      cout << "Yes" << endl;
    else if (s[i] == 'b' && i + 1 - dare <= a + b && rank <= b) {
      cout << "Yes" << endl;
      rank++;
    } else {
      cout << "No" << endl;
      dare++;
    }
  }

  return 0;
}

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

#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double
#define int long long 

using namespace std;

const int MAXN = 1001 * 1001 , MOD = 1e9 + 7 ; 

vector<int> adj[MAXN] ; 

int ans = 0 ; 

bool mark[MAXN] ; 

int col[MAXN] ; 

int c[3] ; 

void dfs(int u , int p , int cc )
{
	col[u] = cc ;
	c[col[u]] ++ ; 
	for(auto v : adj[u])
	{
		if(col[v])
		{
			if(col[v]!=3-col[u]) c[0] = -1;  
			continue ; 
		}
		dfs(v,u,3-col[u]) ;
	}
}

int32_t main() 
{
	ios::sync_with_stdio(0) ; 
	cin.tie(0) ;
	int n , m ; 
	cin >> n >> m ; 
	for(int i = 0 ; i < m ; i ++ )
	{
		int x , y ; 
		cin >> x >> y ; 
		adj[x].pb(y) ; 
		adj[y].pb(x) ; 
	}
	for(int i = 1 ; i <= n ; i ++ ) 
	{
		if(!mark[i]) 
		{
			c[0] = c[1] = c[2] = 0 ; 
			dfs(i,-1,1) ; 
			if(c[0]==0) ans += c[1] * c[2] ; 
			else ans += (c[1]+c[2]) * (c[1]+c[2]-1) / 2 ; 
		}
	}
	cout << ans - m << endl ; 

}

Measured memory_bytes: 29696
import java.io.*;
 
public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String input = br.readLine();
    int zero = 0;
    for(int i = 0; i<input.length(); i++){
      if(input.indexOf('1',i) == i){
        zero++;
      }
    }
	System.out.println(zero);
  }
}


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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<pair<long long, int>>> c( N );
	for( int i = 0; i < M; i++ ) {
		int P;
		long long Y;
		cin >> P >> Y;
		P--;
		c[P].push_back( make_pair( Y, i ) );
	}

	vector<pair<int, string>> id;
	for( int i = 0; i < N; i++ ) {
		sort( c[i].begin(), c[i].end() );
		int y = 1;
		for( int j = 0; j < c[i].size(); j++ ) {
			int n;
			long long Y;
			tie( Y, n ) = c[i][j];
			char ch[16];
			sprintf( ch, "%06d%06d", i + 1, y );
			id.push_back( make_pair( n, string( ch ) ) );
			y++;
		}
	}
	sort( id.begin(), id.end() );
	for( int i = 0; i < id.size(); i++ ) {
		int n;
		string ans;
		tie( n, ans ) = id[i];
		cout << ans << endl;
	}
}


Measured memory_bytes: 14008
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string S;
int K, I, H, B, R;

int main()
{
	in >> S;
	if (S.length() > 9)
	{
		out << "NO" << std::endl;
		return 0;
	}
	else
	{
		rep(i, S.length())
		{
			if (S[i] == 'K')
			{
				if (K != 0)
				{
					out << "NO" << std::endl;
					return 0;
				}
				K = i + 1;
			}
			else if (S[i] == 'I')
			{
				if (I != 0)
				{
					out << "NO" << std::endl;
					return 0;
				}
				I = i + 1;
			}
			else if (S[i] == 'H')
			{
				if (H != 0)
				{
					out << "NO" << std::endl;
					return 0;
				}
				H = i + 1;
			}
			else if (S[i] == 'B')
			{
				if (B != 0)
				{
					out << "NO" << std::endl;
					return 0;
				}
				B = i + 1;
			}
			else if (S[i] == 'R')
			{
				if (R != 0)
				{
					out << "NO" << std::endl;
					return 0;
				}
				R = i + 1;
			}
			else if(S[i]!='A')
			{
				out << "NO" << std::endl;
				return 0;
			}
		}
		if (K == 0 || I == 0 || H == 0 || B == 0 || R == 0)
		{
			out << "NO" << std::endl; 
			return 0;
		}
		if (K <= 2 && K + 1 == I&&I + 1 == H&&B - H <= 2 && R - B <= 2 && S.length() - R <= 1)
		{
			out << "YES" << std::endl;
		}
		else
		{
			out << "NO" << std::endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import math

a, b, x = map(int, input().split())
c = (x * 2) / (a * b)
d = (2 * x) / (a * a) - b
if a * a * b / 2 >= x:
    print(math.degrees(math.atan2(b, c)))
else:
    print(math.degrees(math.atan2(b - d, a)))

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

int main() {

  int n;
  cin >>n ;
  string s, t;
  cin >> s >> t;
  string a;
  
  for(int i=0;i<n;i++){
    a+=s.at(i);
    a+=t.at(i);
    
  }
  
  cout << a << endl;
}

Measured memory_bytes: 256
#137_D
import heapq

n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[0])

l = []
heapq.heapify(l)

tmp = 0
ans = 0
for i in range(1, m+1):
    for j in range(tmp, n):
        a, b = ab[j]
        if i == a:
            heapq.heappush(l, -b)
        else:
            tmp = j
            break
    if len(l) > 0:
        ans += -1 * heapq.heappop(l)
print(ans)

Measured memory_bytes: 20432
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<utility>
#include<string>

using namespace std;

main(){
  double t,v,y,n;
  int i,j,l;
  while(cin >> v){
    t=v/9.8;
    y=4.9*t*t;
    n=ceil((y+5)/5);
    printf("%.0f\n",n);
  }
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  ll ans = 0;
  for(int i=0;i<=n;++i){
    if(i%3==0||i%5==0)continue;
    ans+=i;
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
bool comp(pair<pair<string,int>,int> &a,pair<pair<string,int>,int> &b){
  if(a.first.first==b.first.first) return a.first.second>b.first.second;
  else return a.first.first<b.first.first;
}
int main()
{
  int n;cin >> n;
  vector<pair<pair<string,int>,int>> p(n);
  rep(i,n){
    string s;int x;
    cin >> s >> x;
    p[i] = {{s,x},i+1};
  }
  sort(p.begin(), p.end(),comp);
  rep(i,n){
    cout << p[i].second << "\n";
  }    

  
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main() {
	bool b[3] = {};
	scanf("%d%d%d", &b[0], &b[1], &b[2]);
	if ((b[0] == true && b[1] == true) || b[2] == true) {
		printf("Open\n");
	}
	else {
		printf("Close\n");
	}
}


Measured memory_bytes: 1012
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n;
  cin >> n;
  vector<double> v(n);
  for(auto &x:v) cin >> x;
  sort(v.begin(),v.end());
  REP(i,n-1) {
    v[i+1] = (v[i]+v[i+1])/2;
  }
  cout << v.back() << endl;
  return 0;
}


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

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


    int sum=0;
    int max=0;
    for(int i=0; i<N; ++i) {
        int l;
        cin >> l;

        if(l>max) max=l;
        sum += l;
    }
    sum -= max;

    if(max<sum) cout << "Yes" << endl;
    else cout << "No" << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
using namespace std;
signed main(){
    string a,b;
    cin >> a >> b;
    if(a > b){
        cout << ">" << endl;
    }else if(a < b){
        cout << "<" << endl;
    }else cout << "=" << endl;
    return 0;
}

Measured memory_bytes: 256
class Num:
    def __init__(self, h, t, d):
        self.head = h
        self.tail = t
        self.digit = d
        self.min = self.get_min()
        self.max = self.get_max()

    def get_min(self):
        if self.digit == 1:
            if self.head == self.tail:
                return self.head
            else:
                return 0
        else:
            return self.head * (10 ** (self.digit-1)) + self.tail

    def get_max(self):
        if self.digit == 1:
            if self.head == self.tail:
                return self.head
            else:
                return 0
        if self.digit == 2:
            return self.get_min()
        else:
            return self.get_min() + (10 ** (self.digit-1) - 10)


def solve(a, b, n):
    if a.min * a.max * b.min * b.max == 0:
        return 0

    if a.min > n:
        return 0

    if b.min > n:
        return 0

    if a.max > n:
        if a.digit >= 3:
            if str(a.max)[-1] > str(n)[-1]:
                a.max = int(str(a.max)[0] + str(n-10)[1:-1] + str(a.max)[-1])
            else:
                a.max = int(str(a.max)[0] + str(n)[1:-1] + str(a.max)[-1])

    if b.max > n:
        if b.digit >= 3:
            if str(b.max)[-1] > str(n)[-1]:
                b.max = int(str(b.max)[0] + str(n-10)[1:-1] + str(b.max)[-1])
            else:
                b.max = int(str(b.max)[0] + str(n)[1:-1] + str(b.max)[-1])

    total_a = (a.max - a.min) // 10 + 1
    total_b = (b.max - b.min) // 10 + 1
    count = total_a * total_b

    # print('------')
    # print(a.min, a.max)
    # print(b.min, b.max)
    # print(count)

    return count


def main():
    n = int(input())
    digit_n = len(str(n))

    total = 0
    for a_head in range(1, 10):
        for a_tail in range(1, 10):

            b_head = a_tail
            b_tail = a_head

            for digit_a in range(1, digit_n+1):
                for digit_b in range(1, digit_n+1):
                    a = Num(a_head, a_tail, digit_a)
                    b = Num(b_head, b_tail, digit_b)
                    count = solve(a, b, n)
                    total += count

    print(total)


if __name__ == '__main__':
    main()


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long INF = 1LL << 60;
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

signed main()
{   
    gearup;
    ll n; cin >> n;
    vector<ll> l(n);
    rep(i,n)cin >> l[i];
    sort(all(l));
    ll res = 0;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            ll index = lower_bound(all(l),l[i]+l[j]) - l.begin();
            res += max(1LL*0,index-(j+1));
        }
    }
    cout << res << endl;
}


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

int main(){
	
	int date[20][20] = {0}, n, number, i, j;
	char mark;
	
	cin >> n;
	
	for(i = 0; i < n; i++){
		
		cin >> mark >> number;
		
		if(mark == 'S'){	date[0][number - 1] = 1;}
		if(mark == 'H'){	date[1][number - 1] = 1;}
		if(mark == 'C'){	date[2][number - 1] = 1;}
		if(mark == 'D'){	date[3][number - 1] = 1;}
	}
	
	for(i = 0; i < 4; i++){
		for(j = 0; j < 13; j++){
			
			if(date[i][j] == 0){
				
				if(i == 0){	cout << "S " << j+1 << endl;}
				if(i == 1){	cout << "H " << j+1 << endl;}
				if(i == 2){	cout << "C " << j+1 << endl;}
				if(i == 3){	cout << "D " << j+1 << endl;}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)

int main(){
    int n; cin >> n;
    string s; cin >> s;
    if(n%2==1){
        cout << "No" << endl;
        return 0;
    }
    else{
        rep(i,n/2){
            if(s[i]!=s[i+n/2]){
                cout << "No";
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}


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

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

  ll n;
  cin>>n;
  if(n%2==0)
  cout<<(n/2-1)<<"\n";
else
	cout<<(n/2)<<"\n";
  return 0;
}

Measured memory_bytes: 256
n, k = [int(i) for i in input().split()]
al = [int(i) for i in input().split()]
al.sort()
mod = 10 ** 9 + 7


kai = [1]
for i in range(1, n + 1):
    kai.append(kai[-1]*i%mod)




def comb(a, b, p=mod):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai[a]
    c *= pow(kai[b], p - 2, p)
    c *= pow(kai[a - b], p - 2, p)
    return c % p


ans = 0
for i in range(k - 1, n):
    ans += al[i] * comb(i,k-1)
    ans %= mod
al = list(reversed(al))
for i in range(k - 1, n):
    ans -= al[i] * comb(i, k-1)
    ans %= mod
print(ans)


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

void dfs(const vector<vector<pair<int,int>>> &G, vector<int> &C, int v){
  for(auto e : G[v]){
    int v_ = e.second, w = e.first;
    if(C[v_] >= 0) continue;
    if(w%2) C[v_] = 1 - C[v];
    else C[v_] = C[v];
    dfs(G,C,v_);
  }
}


int main(){
  int N;
  cin >> N;
  vector<vector<pair<int,int>>> G(N);
  for(int i = 0; i < N-1; ++i){
    int u, v, w;
    cin >> u >> v >> w;
    --u,--v;
    G[u].emplace_back(w,v);
    G[v].emplace_back(w,u);
  }
  vector<int> C(N,-1);
  C[0] = 0;
  dfs(G,C,0);
  for(int i = 0;  i < N; ++i){
    cout << C[i] << endl;
  }
}


Measured memory_bytes: 8960
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("avx,avx2,fma,sse,sse2")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll= long long;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0)cout<<(b-a)/2<<endl;
    else cout<<min((a-1)+((b-a)+1)/2,(n-b)+(n-(a+(n-b))+1)/2)<<endl;

}


Measured memory_bytes: 3564
def myAnswer(X:int) -> int:
   numbers = [i for i in range(2,X+1)]
   ans = 1
   for p in numbers:
      i = 2
      while True:
         if(p**i <= X):
            ans = max(p**i,ans)
            i += 1
         else:
            break
   return ans


def modelAnswer():
   tmp=1
def main():
   X = int(input())
   print(myAnswer(X))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, A;
    cin >> N >> A;
    int x[N];
    rep(i, N) {cin >> x[i]; x[i] -= A;}
    ll dp[N+1][5001];
    fill(dp[0], dp[N+1], 0);
    dp[0][2500] = 1;
    rep(i, N){
        rep(j, 5001){
            if(dp[i][j] == 0) continue;
            dp[i+1][j] += dp[i][j];
            dp[i+1][j+x[i]] += dp[i][j];
        }
    }
    cout << dp[N][2500]-1 << endl;
}

Measured memory_bytes: 5608
li = list(map(int,input().split()))
li.extend(list(map(int,input().split())))
li.extend(list(map(int,input().split())))

num = []
for i in range(1,5):
    num.append(li.count(i))

if num.count(1) == 2 and num.count(2) == 2:
    ans = 'YES'
else:
    ans = 'NO'
print(ans)

Measured memory_bytes: 3064
//ABC147 B

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = s; i < (int)(n); i++)
const lint mod = 1000000007;


lint ans = 0;
string s;
lint a[200000];


int main() {
  cin >> s;

  int n = s.length();
  rep(i,n/2){
    if(s[i] != s[n-1-i]) ans++;
  }

  
  printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
using namespace std;
using ll=long long;
//using R=double;

const int INF = 10000000;
typedef pair<int, int> p;


int main(){
	string S,T;
    cin >> S >> T;
    for(int i = 0; i < S.length(); i++){
        for(int j = 0; j < S.length(); j++){
            if(S[j]==T[j]){
                if(j==S.length()-1){
                    puts("Yes");
                    return 0;
                }
            }else{
                break;
            }
        }
        string new_S = S;
        for(int k = 0; k < S.length(); k++){
            if(k==0){
                new_S[k] = S.back();
            }else{
                new_S[k] = S[k-1];
            }
        }
        S = new_S;
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int N,K;
    cin >> N >> K;
    vector<int> V(N);
    rep(i,N){
        cin >> V[i];
    }
    int mx=0;
    rep(a,min(N,K)+1){
        rep(b,min(N,K)+1-a){
            vector<int> v;
            rep(i,a){
                v.push_back(V[i]);
            }
            for(int i=N-1;i>=N-b;i--){
                v.push_back(V[i]);
            }
          	sort(all(v));
        	int sum=0;
        	rep(i,v.size()){
            	if(i<=K-a-b-1){
                	sum+=max(0,v[i]);
            	}
            	else sum+=v[i];
        	}
        	if(chmax(mx,sum))cerr << a << ' ' << b << endl;
        }
    }
    cout << mx;

}

/*



 */



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed<<setprecision(a)<<
#define F first
#define S second
#define I insert
#define pii pair<int,int>
#define trav(a, x) for(auto& a : x)
#define fl(i,n) for(int i = 0;i<n;i++)
#define rfl(n) for(int i = n-1;i>=0;i--)
#define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" "; cout<<endl;
#define ingrid(data,n,commands) for(int i = 0; i<n; i++){cin>>data[i];commands}
#define section(a,b,w) set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w) set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define copy(a,w) copy(a.begin(), a.end(),back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'
#define last(a) a[sz(a)-1]
#define mp make_pair
 
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
 
// Graph DFS
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
 
//primes for hashing 937,991,1013,1409,1741
 
//Returns index of first element not less than key and more than key respectively
#define lb(data,key) lower_bound(all(data),key) - data.begin();
#define up(data,key) upper_bound(all(data),key) - data.begin();
#define fnd(data,key) find(all(data),key) - data.begin();
//Long Long Int
#define int long long int

void solve()
{
    int n,k;cin>>n>>k;
    std::vector<int> v;
    fl(i,n)
    {
        int j;cin>>j;
        v.pb(j);
    }
    int dp[n];
    dp[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        dp[i]=abs(v[i]-v[i+1])+dp[i+1];
        for(int j=2;i+j<n&&j<=k;j++)
            dp[i]=min(dp[i],abs(v[i]-v[i+j])+dp[j+i]);
    }
    cout<<dp[0]<<endl;
}
 
signed main()
{
    
    FAST
    
    int t = 1;
    //cin>>t;
    while(t--)
    solve();
    
 
return 0;
}
 
/*6
30 10 60 10 60 50*/

Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x)          __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;

int nCrevenoroddfinder(int n,int r)
{
    int a=r;
    int b=n-r;
    for(int i=0;i<30;i++)
    {
        int x=1<<i;
        if((x&a)&&(x&b))
        {
            return 0;//even
        }
    }
    return 1;//odd
}

ll gcd(ll a, ll b) {
  if (a == 0)return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)return true;
  return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == b.first) return a.second>b.second;
  return a.first < b.first;
}
 ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }

  }
}

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  ll n,x,t;
  cin>>n>>x>>t;
  ll d=(n/x)+(n%x!=0);

  d*=t;
  cout<<d;
}



  

Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f

using namespace std;

int g[2020][2020];
char g2[2020][2020];

int maxi[2020][2020];
int maxj[2020][2020];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n, m;
	cin>>n>>m;
	memset(maxi, -1, sizeof maxi);
	memset(maxj, -1, sizeof maxj);
	for(int i=0;i<n;i++){
		string s; cin>>s;
		for(int j=0;j<m;j++)
			g2[i][j] = s[j];
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(maxi[i][j]!=-1)continue;
			
			int cont = 0;
			for(int ii=i;ii<n;ii++){
				if(g2[ii][j] == '#')break;
				cont++;
			}
			for(int ii=i;ii<n;ii++){
				if(g2[ii][j] == '#')break;
				maxi[ii][j] = cont;
			}	
			
		}
	
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(maxj[i][j]!=-1)continue;
			int cont = 0;
			for(int jj=j;jj<m;jj++){
				if(g2[i][jj] == '#')break;
				cont++;
			}
			for(int jj=j;jj<m;jj++){
				if(g2[i][jj] == '#')break;
				maxj[i][jj]=cont;
			}
			
		}
	
	}
	
	int ans = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			ans = max(ans, maxi[i][j]+maxj[i][j]-1);
		
		}
		
		}
		cout<<ans<<"\n";
	
	return 0;	
}


Measured memory_bytes: 39532
#pragma warning(disable:4996)
#include "bits/stdc++.h"
using namespace std;

//macro
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,a,b) for(int i=(int)(b) - 1;i>=(int)(a);i--)
#define rrep(i,n) RREP(i,0,n)
#define each(i, ctn) for (auto &&i : (ctn))
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define INFL 1145148100000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define equals(a,b)(fabs((a)-(b))<EPS)

//alias
using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vs = vector<string>;
using P = pair<ll, ll>;
template<class T> using heap = priority_queue<T>;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;

//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H);	rep(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n)os << v[i] << (i == n - 1 ? "\n" : " "); return os; }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template<class T> inline void print(const T &x) { cout << x << '\n'; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;


int main()
{
	int N;
	cin >> N;
	vi I(4);
	rep(i, 4) {
		I[3-i] = N % 10;
		N /= 10;
	}

	vs op = { "+", "-" };

	rep(i, 2) {
		int ans1 = I[0];
		if (i)ans1 -= I[1];
		else ans1 += I[1];
		rep(j, 2) {
			int ans2 = ans1;
			if (j)ans2 -= I[2];
			else ans2 += I[2];
			rep(k, 2) {
				int ans3 = ans2;
				if (k)ans3 -= I[3];
				else ans3 += I[3];
				if (ans3 == 7) {
					cout << I[0] << op[i] << I[1] << op[j] << I[2] << op[k] << I[3];
					cout << "=7" << endl;
					return 0;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin>>a;
    if(a==111) cout<<"999"<<endl;
    else if(a==119) cout<<"991"<<endl;
    else if(a==199) cout<<"911"<<endl;
    else if(a==911) cout<<"199"<<endl;
    else if(a==991) cout<<"119"<<endl;
    else if(a==999) cout<<"111"<<endl;
    else if(a==919) cout<<"191"<<endl;
    else if(a==191) cout<<"919"<<endl;
}



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

int main(){
    int D, T, S;
    cin >> D >> T >> S;
    
    if (S * T >= D){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
from functools import reduce
import math

def lcm_base(x,y):
    return (x*y) // math.gcd(x,y)

def lcm(*numbers):
    return reduce(lcm_base, numbers ,1)

def lcm_list(listOfNumbers):
    return reduce(lcm_base ,listOfNumbers ,1)

N=int(input())
a=list(map(int,input().split()))

m=lcm_list(a)-1

ans = 0

for num in a:
    ans+=m%num

print(ans)

Measured memory_bytes: 9340
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793


   
int main(){
    int n,m;
    cin >> n >> m ;
    int ans=(n-1)*(m-1);
    cout <<  ans << endl;
    
  }


Measured memory_bytes: 256
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]
a=[0]*101
for i in range(N):
    a[i]=s.count(s[i])
    for j in range(M):
        if s[i]==t[j]:
            a[i]-=1

print(max(a))

Measured memory_bytes: 9196
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;

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

int main(){
    int a, b, c, x, y;
    cin>>a>>b>>c>>x>>y;
    int ans=INF;
    for(int i=0; i<=2*max(x, y); i+=2){
        int j=max(x-i/2, 0), k=max(y-i/2, 0);
        chmin(ans, a*j+b*k+c*i);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m;cin >> m;
    cout << (24-m)+24 << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

vector<vector<int> > G;

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  G.resize(n);
  for (int i = 1; i < n; ++i) {
    int a;
    cin >> a;
    a--;
    G[a].emplace_back(i);
  }
  rep(i,n) {
    cout << G[i].size() << endl;;
  }
  return 0;
}

Measured memory_bytes: 14200
from sys import stdin


def main() -> None:
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]

    ans = []
    for i in range(h):
        ans += [[0] * w]

    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                ans[i][j] = 9
                for x in (-1, 0, 1):
                    for y in (-1, 0, 1):
                        if 0 <= i + y < h and 0 <= j + x < w:
                            ans[i + y][j + x] += 1

    for i in range(h):
        for j in range(w):
            if ans[i][j] >= 9:
                print("#", end="")
            else:
                print(ans[i][j], end="")
        print()


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

int64_t mod = 1000000007;

int main(){
	int n;
	cin >> n;
	vector<int> as;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		as.push_back(a);
	}
	sort(as.begin(), as.end());
	if (n % 2 == 0) {
		int c = 1;
		bool flag = true;
		for (int i = 0; i < n / 2; ++i) {
			flag &= (as[i*2] == c);
			flag &= (as[i*2 + 1] == c);
			c += 2;
		}
		if (!flag) cout << 0 << endl;
		else{
			int64_t res = 1;
			for (int i = 0; i < n / 2; ++i) {
				res *= 2;
				res %= mod;
			}
			cout << res << endl;
		}
	}
	if (n % 2 == 1) {
		int c = 0;
		bool flag = true;
		flag &= (as[0] == 0);
		c += 2;
		for (int i = 0; i < n / 2; ++i) {
			flag &= (as[1+i*2] == c);
			flag &= (as[2+i*2] == c);
			c += 2;
		}
		if (!flag) cout << 0 << endl;
		else {
			int64_t res = 1;
			for (int i = 0; i < n / 2; ++i) {
				res *= 2;
				res %= mod;
			}
			cout << res << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for (int i = 0; (i * 4) <= N; i++) {
			for (int j = 0; (j * 7) + (i * 4) <= N; j++) {
				if ((j * 7) + (i * 4) == N) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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;
}

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n, m;
    cin >> n >> m;
    Graph g(n);
    REP(i, m) {
        ll a, b;
        cin >> a >> b;
        add_edge(g, --a, --b, 1, true, 1);
    }

    vec<P> es;
    Array used(n, false);
    int id = 1;
    auto dfs = [&](auto &&self, int v, int p) -> ll {
        used[v] = id++;
        bool flag = true;
        ll ret = 0;
        for(auto e : g[v]) {
            if(used[e.to]) {
                if(used[e.to] > used[v]) {
                    ret++;
                    es.push_back({v + 1, e.to + 1});
                }
                continue;
            }
            if(self(self, e.to, v)) {
                ret++;
                es.push_back({v + 1, e.to + 1});
            }
        }
        if(ret & 1) {
            es.push_back({v + 1, p + 1}); //奇数の時は親に向かう辺で調整
            return 0;
        } else {
            return 1;
        }
    };

    if(dfs(dfs, 0, -1)) {
        for(auto [a, b] : es) {
            cout << a << " " << b << en;
        }
    } else {
        cout << -1 << en;
    }
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 28704
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;
#define MAXN 2005

ll a[MAXN],dp[MAXN][MAXN];

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

    int n;
    cin >> n;
    vector<pii> v;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        v.push_back(pii(a[i],i));
    }

    sort(all(v));

    for(int i=n-1;i>=0;i--)
    {
        ll x=v[i].first;
        ll p=v[i].second+1;
        for(int j=1;j+i<=n;j++)
        {
            dp[j+1][j+i]=max(dp[j+1][j+i],dp[j][j+i]+x*abs(p-j));
            dp[j][j+i-1]=max(dp[j][j+i-1],dp[j][j+i]+x*abs(p-(j+i)));
        }
    }

    ll res=0;
    for(int i=1;i<=n;i++)
        res=max(res,dp[i][i-1]);
    db(res)

    return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

int n;
int a[3];

int main()
{
  cin >> n;
  while(n--){
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    puts((a[0]*a[0]+a[1]*a[1]==a[2]*a[2]) ? "YES" : "NO");
  }

  return 0;
}

Measured memory_bytes: 1128