akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//a??¨b?????§?????????

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//a??¨b????°??????????

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//a??¨b???????????¶??????

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//p????´???°,a???b??????p??§?????£?????????

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//p????´???°,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//?????§??¬?´???°

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//????°???¬?????°

int main() {
	
	int m, f, r;
	string ans;

	while (1) {

		cin >> m >> f >> r;

		if (m == -1 && f == -1 && r == -1)break;
		else {

			if (m == -1 || f == -1)ans = "F";
			else if (m + f >= 80)ans = "A";
			else if (m + f >= 65)ans = "B";
			else if (m + f >= 50)ans = "C";
			else if (m + f >= 30 && r >= 50)ans = "C";
			else if (m + f >= 30)ans = "D";
			else ans = "F";

			cout << ans << endl;

		}

	}

	return 0;
}

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

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

int main() {
	int a, b;
	cin >> a >> b;

	int ans = a*b;
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 3632
mod = 10 ** 9 + 7
N, K = map(int, input().split())
A = list(map(int, input().split()))

cnt_list = [[0, 0] for _ in range(N)]
for i in range(N):
    right = 0
    left = 0
    for j in range(N):
        if i < j:       # right
            if A[i] > A[j]:
                right += 1
        else:           # left
            if A[i] > A[j]:
                left += 1
    cnt_list[i][0] = left
    cnt_list[i][1] = right
ans = 0
for i in range(N):
    left = cnt_list[i][0]
    right = cnt_list[i][1]
    ans += left * (K - 1) * K // 2
    ans += right *  K * (K + 1) // 2
    ans %= mod
print(ans)

Measured memory_bytes: 3380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second

int main() {

   int a,b,x;
   cin>>a>>b>>x;
   
   if(x-a-b<=0&&x>=a)
      cout<<"YES";
      else
      cout<<"NO";
    

	return 0;
}

Measured memory_bytes: 256
n = int(input())
move = []
first = []
second = []
third = []
forth = []

for p in range(3):
    first.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

for q in range(3):
    second.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
    
for r in range(3):
    third.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
    
for s in range(3):
    forth.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

for i in range(n):
    move.append(list(map(int, input().split())))

for j in move:
    f = j[1] - 1
    r = j[2] - 1
    if j[0] == 1:
        first[f][r] += j[3]
    elif j[0] == 2:
        second[f][r] += j[3]
    elif j[0] == 3:
        third[f][r] += j[3]
    else:
        forth[f][r] += j[3]

for i in range(3):
    print(' ' + ' '.join(map(str, first[i])))

print("#" * 20)

for i in range(3):
    print(' ' + ' '.join(map(str, second[i])))
    
print("#" * 20)

for i in range(3):
    print(' ' + ' '.join(map(str, third[i])))
    
print("#" * 20)

for i in range(3):
    print(' ' + ' '.join(map(str, forth[i])))
  




Measured memory_bytes: 5624
package main

import "fmt"

func main(){
	var n, num int
	var s string
	fmt.Scan(&n)
	inputCards := make([][]bool, 4)
	for i := 0; i < 4; i++ {
		inputCards[i] = make([]bool, 13)
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&s, &num)
		// fmt.Println(s, num)
		switch s{
		case "S": inputCards[0][num-1] = true
		case "H": inputCards[1][num-1] = true
		case "C": inputCards[2][num-1] = true
		case "D": inputCards[3][num-1] = true
		default: fmt.Println("input is invalid.")
		}
	}
	// fmt.Println(inputCards)

	for i := 0; i < 4; i++ {
		for j := 0; j < 13; j++ {
			switch i {
			case 0:
				if inputCards[i][j] == false {
					fmt.Printf("S %d\n", j+1)
				}
			case 1:
				if inputCards[i][j] == false {
					fmt.Printf("H %d\n", j+1)
				}
			case 2:
				if inputCards[i][j] == false {
					fmt.Printf("C %d\n", j+1)
				}
			case 3:
				if inputCards[i][j] == false {
					fmt.Printf("D %d\n", j+1)
				}
			}
		}
	}
}


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

namespace ABC_Training
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ');
            var a = int.Parse(ab[0]);
            var b = int.Parse(ab[1]);
            Console.WriteLine(Ans(a, b));
            
        }

        static int Ans(int x,int y)
        {
            if(y == 1)
            {
                return 0;
            }
            if (x >= y)
            {
                return 1;
            }

            var amari = y - x;
            var count = 1;
            while(amari > 0)
            {
                amari -= x - 1;
                count++;
            }

            return count;
        }
    }
}


Measured memory_bytes: 13140
/* Coached by rainboy */
#include <stdio.h>

int min(int a, int b) {
	return a < b ? a : b;
}

int max(int a, int b) {
	return a > b ? a : b;
}

int main() {
	int n, m, k;
	double prob;

	scanf("%d%d", &n, &m);
	prob = max(n - m + 1, 0);
	for (k = 1; 1 << k - 1 < m; k++) {
		int p = 1 << k, q = 1 << k - 1;
		int lower = max((m + p - 1) / p, 1);
		int upper = min((m + q - 1) / q - 1, n);

		prob += (double) max(upper - lower + 1, 0) / p;
	}
	printf("%.12f\n", prob / n);
	return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

string f(string s,int n){
    rrep(i,n-1,-1)s+=s[i];
    string t,res="";
    rep(i,1,n+1){
        t=s.substr(i,n); reverse(ALL(t));
        if(res=="")res=t;
        else chmin(res,t);
    }
    reverse(ALL(res));
    return res;
}
string g(string s,int n){
    string res=s;
    rrep(i,n-1,-1)s+=s[i];
    rep(i,1,n+1)chmin(res,s.substr(i,n));
    return res;
}

int main(){
    int n,k; scanf("%d%d",&n,&k);
    string s; cin>>s;
    rep(rot,0,min(16,k-1))s=f(s,n);
    cout<<g(s,n)<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll D, T, S; cin >> D >> T >> S;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  // vector<ll> a(N); rep(i, N) cin >> a[i];
  
  bool ok = (D <= T * S);

  // cout << ans << endl;
  cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3680
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_6-A: Counting Sort

#include <cstdio>

static void print_ints(const int as[], const unsigned int n)
{
  auto out_sep = "";
  for (auto i = 0u; i < n; ++i) {
    std::printf("%s%d", out_sep, as[i]);
    out_sep = " ";
  }
  std::printf("\n");
}

static const unsigned int MAX_VALUE= 10000;
static void counting_sort(int as[], int bs[], const unsigned int n)
{
  int cs[MAX_VALUE+1] ={0};
  for (auto i = 0u; i < n; ++i) {
    auto a = as[i];
    ++cs[a];
  }
  --cs[0]; // 0-based
  for (auto i = 1u; i < MAX_VALUE+1; ++i) {
    cs[i] += cs[i-1];
  }
  for (int j = n-1; j >= 0; --j) {
    auto a = as[j];
    bs[cs[a]--] = a;
  }
}

int main()
{
  unsigned int n;
  std::scanf("%u", &n);
  int as[n], bs[n];
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%d", &as[i]);
  }

  counting_sort(as, bs, n);
  print_ints(bs, n);
}

// eof

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

int main() {
    int n;
    cin >> n;
    unsigned long long x;
    unsigned long long h = 0;
    unsigned long long ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x < h) {
            ans += h - x;
        } else {
            h = x;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
from collections import Counter

H, W = map(int, input().split())
a = ''
for i in range(H):
    a += input()

c = Counter(a)
n = c.values()
T = [0,
     sum(ni // 4 for ni in n),
     sum((ni % 4) // 2 for ni in n),
     sum(ni % 2 for ni in n)]
E = [(H // 2) * (W // 2),
     (H // 2) * (W % 2) + (H % 2) * (W // 2),
     (H % 2) * (W % 2)]

ans = True
for i in range(3):
    T[i + 1] += T[i] * 2
    T[i + 1] -= E[i]
    if T[i + 1] < 0:
        ans = False
        break
print('Yes' if ans else 'No')


Measured memory_bytes: 3436
def insertion_sort(A, N):
    for i in range(1, N):
        v = A[i]
        j = i - 1
        print(' '.join(list(map(str, A))))
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
    print(' '.join(list(map(str, A))))

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


Measured memory_bytes: 5604
#include <cstdio>

int main()
{
  int h,w,k;
  scanf("%d%d%d",&h,&w,&k);
  static char s[400][400];
  static int c[400];
  for(int i=0;i<h;i++){
    scanf("%s",s[i]);
    c[i]=0;
    for(int j=0;j<w;j++){
      c[i]+=(s[i][j]=='#'?1:0);
    }
  }
  static int a[400][400];
  int b=1;
  for(int i=0;i<h;){
    int k=i;
    while(k<h&&c[k]==0){
      k++;
    }
    if(k==h){
      for(int x=i;x<k;x++){
	for(int j=0;j<w;j++){
	  a[x][j]=a[x-1][j];
	}
      }
      i=k;
    }
    else{
      for(int j=0;j<w;){
	int l=j;
	while(l<w&&s[k][l]!='#'){
	  l++;
	}
	if(l==w){
	  for(int x=i;x<=k;x++){
	    for(int y=j;y<w;y++){
	      a[x][y]=a[x][y-1];
	    }
	  }
	  j=l;
	}
	else{
	  for(int x=i;x<=k;x++){
	    for(int y=j;y<=l;y++){
	      a[x][y]=b;
	    }
	  }
	  b++;
	  j=l+1;
	}
      }
      i=k+1;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      printf("%d%c",a[i][j],j==w-1?'\n':' ');
    }
  }
  return 0;
}


Measured memory_bytes: 1280
use std::cmp::min;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();

    let mut a_s = String::new();
    let mut b_s = String::new();

    for _ in 0..b {
        a_s += &a.to_string();
    }

    for _ in 0..a {
        b_s += &b.to_string();
    }

    println!("{}", min(a_s, b_s));
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, x, a[30]; bool dp[1000001], prime[1000001];
int main() {
	prime[0] = true, prime[2] = true;
	for(int i = 3; i <= 1000000; i += 2) prime[i] = true;
	for(int i = 3; i <= 1000; i++) {
		if(!prime[i]) continue;
		for(int j = i; i * j <= 1000000; j += 2) prime[i * j] = false;
	}
	while(scanf("%d%d", &n, &x), n) {
		for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n);
		for(int i = 0; i < x; i++) dp[i + 1] = false; dp[0] = true;
		for(int i = 1; i <= x; i++) {
			for(int j = 0; j < n && i >= a[j]; j++) {
				if(dp[i - a[j]]) {
					dp[i] = true; break;
				}
			}
		}
		for(int i = x; i >= 0; i--) {
			if(dp[i] && prime[i]) {
				printf(i ? "%d\n" : "NA\n", i); break;
			}
		}
	}
}

Measured memory_bytes: 4720
import sys
from collections import deque
def main():
  S = input()
  Q = int(input())
  r = False
  ans = deque(S)
  for l in sys.stdin:
    TFC = l.split()
    if TFC[0]=="1": r = not r
    elif TFC[1]=="1":
      if r: ans.append(TFC[2])
      else: ans.appendleft(TFC[2])
    elif TFC[1]=="2":
      if r: ans.appendleft(TFC[2])
      else: ans.append(TFC[2])
  print("".join(reversed(ans) if r else ans))

if __name__ == "__main__":
  main()

Measured memory_bytes: 8820
#include<bits/stdc++.h>
#define S 2010
using namespace std;
using ll = int64_t;
ll imos[510][510];
int main(){
    ios_base::sync_with_stdio(false);
    ll N, M, Q;
    cin >> N >> M >> Q;
    for(ll i = 0; i < M; i++){
        ll l, r;
        cin >> l >> r;
        imos[0][r]++;
        imos[l + 1][r]--;
    }
    for(ll i = 1; i < 510; i++) for(ll j = 0; j < 510; j++) imos[i][j] += imos[i - 1][j];
    for(ll i = 0; i < 510; i++) for(ll j = 1; j < 510; j++) imos[i][j] += imos[i][j - 1];
    for(ll i = 0; i < Q; i++){
        ll p, q;
        cin >> p >> q;
        cout << imos[p][q] << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            ulong a = ulong.Parse(str[0]);
            ulong b = ulong.Parse(str[1]);
            ulong n = ulong.Parse(str[2]);

            if (n > b - 1)
            {
                n = b - 1;
            }
            Console.WriteLine((a * n) / b);
        }
    }
}


Measured memory_bytes: 27456
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

ll gcd(ll A,ll B){
  if(B==0) return A;
  return gcd(B,A%B);
}

int main(){
  ll N,M;
  cin>>N>>M;
  VL A(N);
  rep(i,N) cin>>A[i];
  int F=0;
  rep(i,N) F|=A[i]%2;
  if(F){
    cout<<0<<endl;
    return 0;
  }
  ll lcm=1;
  rep(i,N){
    lcm=lcm/gcd(lcm,A[i])*A[i];
    if(lcm>M*2){
      cout<<0<<endl;
      return 0;
    }
  }
  rep(i,N){
    if(lcm/A[i]%2==0){
      cout<<0<<endl;
      return 0;
    }
  }
  lcm/=2;
  cout<<(M/lcm+1)/2<<endl;
}

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

using namespace std;
using LL = long long;
const int N = 1024 + 1e5;
const int INF = INT32_MAX - 1;
const double EPS = 1E-9;

int a[N];
int n, m;

int d[N];
set<int> b[N];
int p[N];
int cnt[N];

int find_set(int v) {
    if (p[v] != v) {
        p[v] = find_set(p[v]);
    }
    return p[v];
}

void union_sets(int u, int v) {
    int a=find_set(u);
    int b=find_set(v);
    if(a!=b){
        if(cnt[a]<cnt[b]){
            swap(a,b);
        }
        p[b]=a;
        cnt[a]+=cnt[b];
    }
}

int main() {
    ios_base::sync_with_stdio(false);

#ifdef CF_DEBUG
    freopen("../cf/input.txt", "r", stdin);
#endif



    int k;
    cin >> n >> m >> k;
        for(int i=1;i<=n;++i){
        p[i]=i;
        cnt[i]=1;
    }
    for (int i = 1; i <= m; ++i) {
        int u, v;
        cin >> u >> v;
        d[u]++,d[v]++;
        if(find_set(u)!=find_set(v)){
            union_sets(u,v);
        }
    }
    for(int i=1;i<=k;++i){
        int u,v;
        cin>>u>>v;
        b[u].insert(v);
        b[v].insert(u);
    }
    for(int i=1;i<=n;++i){
        int res=cnt[find_set(i)];
        res-=d[i];
        for(auto u:b[i]){
            if(find_set(u) == find_set(i)){
                res-=1;
            }
        }
        cout<<res-1<<" ";
    }
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<vector<bool>> is_card_exists(4, vector<bool>(13, false));
    for (int i = 0; i < n; i++)
    {
        string s;
        int x;
        cin >> s >> x;
        if (s == "S")
        {
            is_card_exists.at(0).at(x - 1) = true;
        }
        else if (s == "H")
        {
            is_card_exists.at(1).at(x - 1) = true;
        }
        else if (s == "C")
        {
            is_card_exists.at(2).at(x - 1) = true;
        }
        else if (s == "D")
        {
            is_card_exists.at(3).at(x - 1) = true;
        }
    }

    for (int i = 0; i < 13;i++){
        if(is_card_exists.at(0).at(i)==false){
            cout << "S " << i + 1 << endl;
        }
    }
    for (int i = 0; i < 13;i++){
        if(is_card_exists.at(1).at(i)==false){
            cout << "H " << i + 1 << endl;
        }
    }
    for (int i = 0; i < 13;i++){
        if(is_card_exists.at(2).at(i)==false){
            cout << "C " << i + 1 << endl;
        }
    }
    for (int i = 0; i < 13;i++){
        if(is_card_exists.at(3).at(i)==false){
            cout << "D " << i + 1 << endl;
        }
    }
}


Measured memory_bytes: 3156
def main():
    import numpy as np
    n=int(input())
    a=list(enumerate(map(int,input().split())))
    a.sort(key=lambda x: -x[1])
    dp=[np.zeros(i+1,dtype=np.int64) for i in range(n+1)]
    dp[0]=np.zeros(1,dtype=np.int64)
    r=np.arange(n+1,dtype=np.int64)
    for time,ix in enumerate(a):
        i,x=ix
        dp[time+1][1:]=dp[time][:time+1]+(i-r[:time+1])*x
        dp[time+1][:-1]=np.maximum(dp[time+1][:-1],dp[time]+((n-1-(time-r[:time+1]))-i)*x)
    print(np.max(dp[n]))
main()

Measured memory_bytes: 43392
N = int(input())
X = list(map(int, input().split()))
s = sorted(X)
midu = s[int(N/2)]
midd = s[int(N/2 - 1)]

for i in range(N):
    if X[i] <= midd:
        print(midu)
    else:
        print(midd)

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) 
    x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key)
    return u;
  if(k < u->key)
    return treeSearch(u->left,k);
  else
    return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL)
    return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL)
    y = z;
  else
    y = treeSuccessor(z);

  if(y->left != NIL)
    x = y->left;
  else
    x = y->right;

  if(x != NIL)
    x->parent = y->parent;

  if(y->parent == NIL)
    root = x;
  else if(y == y->parent->left)
    y->parent->left = x;
  else y->parent->right = x;

  if(y != z)
    z->key = y->key;

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  y = NIL;
  x = root;
  while(x != NIL) {
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->parent = y;

  if(y == NIL)
      root = z;
    else if(z->key < y->key)
      y->left = z;
    else
      y->right = z;
}

void inorder(Node u){
  if(u == NIL)
    return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL)
    return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20448
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = LI()
    a.sort()
    if a == [5, 5, 7]:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    n, l = LI()
    s = SR(n)
    s.sort()
    for i in s:
        print("".join(i), end="")
    print()
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 38512
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> x(N);
int i;
for(i=0;i<N;i++)cin >> x[i];
sort(x.begin(),x.end());
cout << (x[N-1]-x[0]+1)/2 << endl;
}


Measured memory_bytes: 3156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[]C = new int[N - 1];
		int[]S = new int[N - 1];
		int[]F = new int[N - 1];
		for(int i = 0; i < N - 1; i++) {
			C[i] = sc.nextInt();
			S[i] = sc.nextInt();
			F[i] = sc.nextInt();
		}
		sc.close();
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < N - 1; i++) {
			int t = S[i] + C[i];
			for(int j = i + 1; j < N - 1; j++) {
				if(t <= S[j]) {
					t = S[j] + C[j];
				}else {
					int k = (t - S[j] + F[j] - 1) / F[j];
					t = S[j] + k * F[j] + C[j];
				}
			}
			sb.append(t).append("\n");
		}
		sb.append(0);
		System.out.println(sb.toString());
	}
}


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

int main(){
  string a="abcdefghijklmnopqrstuvwxyz";
  char x;
  priority_queue<int> que;
  int H,W,n[26]={};
  cin>>H>>W;
  for(int i=0;i<H*W;i++){
    cin>>x;
    for(int j=0;j<26;j++){
      if(a[j]==x){
        n[j]+=1;
        break;
      }
    }
  }
  for(int i=0;i<26;i++){
    int y = n[i];
    que.push(y);
  }
  int m[4]={};
  while(!que.empty()){
    int z = que.top();
    que.pop();
    m[3]+=z/4;
    z = z - z/4 * 4;
    m[2] += z/2;
    z = z - z/2 * 2;
    if(z==1) m[1] += z;
  }

  //cout<<"before: m[1]="<<m[1]<<" m[2]="<<m[2]<<" m[3]="<<m[3]<<endl;
  m[3]= m[3]-(H/2)*(W/2);
  if(W%2==1) m[2]-= H/2;
  if(H%2==1) m[2]-= W/2;
  if(W%2==1&&H%2==1) m[1]-=1;
  if(m[2]<0){
    if(m[2]*(-1)*2==m[3]*4){
      m[2]=0;
      m[3]=0;
    }
  }
  //cout<<"after: m[1]="<<m[1]<<" m[2]="<<m[2]<<" m[3]="<<m[3]<<endl;
  if(m[1]==0&&m[2]==0&&m[3]==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, a[200000], s[200001];
map<LL, LL> mp;

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	inc1(i, n) { s[i] = s[i - 1] + a[i - 1]; }
	
	incII(i, 0, n) { mp[s[i]]++; }
	
	LL ans = 0;
	for(auto && e: mp) { ans += e.SE * (e.SE - 1) / 2; }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int H,W;
bool wall[33][33][4];

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

int bfs(){
  for(int i=0;i<H;i++) for(int j=0;j<W;j++) dist[i][j]=MOD;
  dist[0][0]=0;
  queue<pair<int,int>> Q;
  Q.push(mkp(0,0));
  while(!Q.empty()){
    int x,y;
    tie(x,y)=Q.front();
    Q.pop();

    if(x==H-1&&y==W-1) return dist[H-1][W-1];

    for(int i=0;i<4;i++){
      int nx=x+dx[i];
      int ny=y+dy[i];
      if(nx<0||ny<0||nx>=H||ny>=W) continue;
      if(dist[nx][ny]<MOD) continue;
      if(wall[x][y][i]) continue;
      dist[nx][ny]=dist[x][y]+1;
      Q.push(mkp(nx,ny));
    }
    
  }
  return -1;
}

void solve(){
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      for(int k=0;k<4;k++){
        wall[i][j][k]=false;
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W-1;j++){
      int x;
      cin>>x;
      if(x==1){
        wall[i][j][0]=true;
        wall[i][j+1][3]=true;
      }
    }
    if(i==H-1) break;

    for(int j=0;j<W;j++){
      int x;
      cin>>x;
      if(x==1){
        wall[i][j][1]=true;
        wall[i+1][j][2]=true;
      }
    }
  }
  int ans=bfs();
  if(ans==-1) cout<<0<<endl;
  else cout<<ans+1<<endl;
}

int main(){
  while(1){
    cin>>W>>H;
    if(W==0) break;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
int main() {
     int a,b,c,d;
     cin >> a >> b >> c >> d;
     int A = abs(a - b);
     int B = abs(b - c);
     int C = abs(c - a);
     if(A <= d && B <= d || C <= d) cout << "Yes" << endl;
     else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) 
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  ll h;
  cin >> h;

  ll n = 0;
  ll ans = 0;
  while (h > 1) {
    ans += pow(2, n);
    n++;
    h /= 2;
  }
  ans += pow(2, n);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define m 1000000007 
#define MAXN 100000
using namespace std;
int main(){
    string s;
    cin>>s;
    for(long long int i=0;i<s.length();i++){
        if(s[i]=='7'){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    long long sum = 0;
    for(int i=0; i<N; ++i) {
        cin >> A[i];
        sum += abs(A[i]);
    }
    sort(begin(A), end(A));

    if(N == 2) {
        cout << A[1] - A[0] << endl;
        cout << A[1] << ' ' << A[0] << endl;
        return 0;
    }

    if(A[0] >= 0) {
        cout << sum - 2 * A[0] << endl;
        long long x = A[0];
        for(int i=1; i+1<N; ++i) {
            cout << x << ' ' << A[i] << endl;
            x -= A[i];
        }
        cout << A[N - 1] << ' ' << x << endl;
    } else if(A[N - 1] <= 0) {
        cout << sum + 2 * A[N - 1] << endl;
        long long x = A[N - 1];
        for(int i=N-2; i>=0; --i) {
            cout << x << ' ' << A[i] << endl;
            x -= A[i];
        }
    } else {
        cout << sum << endl;
        int p = lower_bound(begin(A), end(A), 0) - begin(A);
        long long x1 = A[0];
        for(int i=p; i+1<N; ++i) {
            cout << x1 << ' ' << A[i] << endl;
            x1 -= A[i];
        }
        long long x2 = A[N- 1];
        for(int i=p-1; i>0; --i) {
            cout << x2 << ' ' << A[i] << endl;
            x2 -= A[i];
        }
        cout << x2 << ' ' << x1 << endl;
    }
}

Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if ((Math.abs(a-b) <= d && Math.abs(b-c) <= d) || Math.abs(a-c) <= d) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

#define MAX 200000

int N;
long long a[MAX];

long long X;

int main()
{
	cin >> N;
	for( int i = 0; i < N; i++ ) {
		cin >> a[i];
		X += a[i];
	}

	long long ans = INT64_MAX;
	long long x = 0;
	for( int i = 0; i < N - 1; i++ ) {
		x += a[i];
		ans = min( ans, abs( x - ( X - x ) ) );
	}

	cout << ans << endl;

	return 0;
}


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

int N, K;
int dis[10];

bool fnc(int num)
{
    while (num) {
        int rem = num % 10;
        if (dis[rem]) return false;
        num /= 10;
    }
    return true;
}

int dfs(int num)
{
    if (fnc(num)) return num;
    return dfs(num+1);
}

int main()
{
    cin >> N >> K;
    for (int i = 1; i <= K; i++) {
        int tmp;
        cin >> tmp;
        dis[tmp] = 1;
    }

    cout << dfs(N);
}


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

#define endl '\n'

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m; cin >> n >> m;
    int ans[n+1];
    memset(ans, -1, sizeof ans);
    bool ok = true;
    for (int i=0; i<m; i++){
        int s,c; cin >> s >> c;
        if (ans[s] != -1 && ans[s] != c){
            ok = false;
            break;
        }
        ans[s] = c;
    }
    if ((ans[1] == 0 && n != 1) || !ok) cout << -1 << endl;
    else{
        if (ans[1] == -1 && n > 1) ans[1] = 1;
        for (int i=1; i<=n; i++) cout << (ans[i] == -1 ? 0 : ans[i]);
        cout << endl;
    }
}

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

int main() {
    string str;
    cin >> str;
    int num[10],dif[10];
    int s;
  
    s = str.size();
      
    for(int i = 0; i < s - 2; i ++){
      num[i] = stoi(str.substr(i,3));
    }
  
   sort(num,num + s - 2);
     
   for(int i = 0; i < s - 2; i ++){
       dif[i] = abs(753 - num[i]);
    }
  
   sort(dif,dif + s - 2);
  
   cout << dif[0] << endl;
  
}

Measured memory_bytes: 764
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.25 20:43:57
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    int n, m;
    int l[100010], r[100010];
    scanf("%d%d", &n, &m);
    rep(i, m) scanf("%d%d", &l[i], &r[i]);
    int hidari, migi;
    hidari = 1;
    migi = n;
    rep(i, m) {
        hidari = max(hidari, l[i]);
        migi = min(migi, r[i]);
    }
    int ret = migi - hidari + 1;
    ret = max(0, ret);
    printf("%d\n", ret);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 1024
H, W = map(int, input().split())
S = [[0]*W for _ in range(H)]

for i in range(H):
    Si = list(input())
    for j in range(W):
        if Si[j] == '#':
            S[i][j] = 1

# row
S_row = [[0]*W for _ in range(H)]
for i in range(H):
    c = 0
    for j in range(W):
        if S[i][j] == 1:
            c = 0
        else:
            c += 1
        S_row[i][j] = c
    # reverse
    for j in range(W-2, -1, -1):
        if S_row[i][j+1] > 0 and S_row[i][j] > 0:
            S_row[i][j] = S_row[i][j+1]

# col
S_col = [[0]*W for _ in range(H)]
for j in range(W):
    c = 0
    for i in range(H):
        if S[i][j] == 1:
            c = 0
        else:
            c += 1
        S_col[i][j] = c
    # reverse
    for i in range(H-2, -1, -1):
        if S_col[i+1][j] > 0 and S_col[i][j] > 0:
            S_col[i][j] = S_col[i+1][j]

# res
res = max([max([S_row[i][j] + S_col[i][j] - 1 for j in range(W)]) for i in range(H)])
print(res)

Measured memory_bytes: 136712
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import re

def main():
  s = input().strip()
  s = s.replace('BC', 'X')
  ans = 0
  for ax in re.split(r'[BC]+', s):
    inds = []
    for i in range(len(ax)):
      if ax[i] == 'A':
        inds.append(i)
    ans += sum([len(ax) - 1 - ind for ind in inds]) - sum(range(len(inds)))
  print(ans)

if __name__=='__main__':
  main()



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

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

  vector<int> vec1(N);
  vector<int> vec2(N);

  for(int i=0;i<N;i++) {
    int k;
    cin >> k;
    vec1[i] = k;
    vec2[i] = k;
  }

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

  int max = vec1[N-1];
  int secondMax = vec1[N-2];

  int maxIndex = 0;

  for(int i=0;i<N;i++) {
    if(vec2[i] == max) {
      maxIndex = i;
      break;
    }
  }

  for(int i=0;i<N;i++) {
    if(i == maxIndex) {
      cout << secondMax << endl;
    } else {
      cout << max << endl;
    }
  }

  return 0;
}

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

int main (){
  
  int A;
  int B;
  int C;
  
  cin >> A >> B >> C;
  
  if(A == B && B == C){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  
}


Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

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

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	nums := make([]int, 5)
	for i := 0; i < 5; i++ {
		nums[i] = nextInt()
	}
	if nums[4] <= nums[2] && nums[2] <= nums[0]-nums[4] && nums[4] <= nums[3] && nums[3] <= nums[1]-nums[4] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}



Measured memory_bytes: 1088
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <deque>
using namespace std;

int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> pos(N);
    for(int i = 0; i < N; ++i)
    {
        vector<int> p(D);
        for(int j = 0; j < D; ++j)
        {
            cin >> p[j];
        }
        pos[i] = p;
    }

    int count = 0;
    for(int i = 0; i < N; ++i)
    {
        for(int j = i + 1; j < N; ++j)
        {
            auto pi = pos[i];
            auto pj = pos[j];
            int sum = 0;
            for(int d = 0; d < D; ++d)
            {
                sum += (pi[d] - pj[d]) * (pi[d] - pj[d]);
            }
            double r = sqrt(sum);
            if(r - (double)(int)r < __DBL_EPSILON__)
            {
                ++count;
            }
        }
    }
    cout << count;
}


Measured memory_bytes: 888
#include<iostream>
#define MAX 1400
using namespace std;
int H, W, s[MAX+1][MAX+1], t[MAX+1][MAX+1];

int main(){
  cin >> H >> W;

  for ( int i = 1; i <= H; i++){
    for ( int j = 1; j <= W; j++){
      cin >> t[i][j];
    }
  }

  int longest = 0;
  for ( int i = 1; i <= H; i++){
    for ( int j = 1; j <= W; j++){
      if ( i == 1 || j == 1){
        s[i][j] = (t[i][j] == 1) ? 0 : 1;
      } else {
        s[i][j] = (t[i][j] == 1) ? 0 : min(s[i-1][j-1], min(s[i-1][j], s[i][j-1])) + 1;
      }
      longest = max(longest, s[i][j]);
    }
  }

  cout << longest * longest << endl;

  return 0;
}


Measured memory_bytes: 18436
#include <stdio.h>

int main(void){
  
  int N;
  
  scanf("%d", &N);
  
  int i;
  long long a = 1000000007;
  long long num = 1;
  
  for( i = 1; i <= N; i++ ){
    num = (num*i)%a;
  }
  
  
  printf("%lld", num);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
const long long mod=1e9+7;
vector<int>v[N];
long long br[N],k;
long long dfs(int x,int p)
{
	long long ans=k-br[p];
	br[x]++;
	if(x!=p)br[x]++;
	for(auto y:v[x])
	{
		if(y!=p)
		{
			ans=(ans*dfs(y,x))%mod;
			br[x]++;
		}
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,a,b,i;
	cin>>n>>k;
	for(i=1;i<n;i++)
	{
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	cout<<dfs(1,1)<<'\n';
}


Measured memory_bytes: 12416
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    string str;
    cin >> str;
    // int right = (str[2] - '0') * 10 + (str[3] - '0');
    // int left =  (str[0] - '0') * 10 + (str[1] - '0');
    string right = str.substr(2, 2);
    string left = str.substr(0, 2);
    if (left >= "01" and left <= "12"
        and right >= "01" and right <= "12" ){
        cout << "AMBIGUOUS" << endl;
        return 0;
    }
    else if (right >= "01" and right <= "12"
        and left >= "00" and left <= "99") {
        cout << "YYMM" << endl;
        return 0;
    } else if (left >= "01" and left <= "12"
               and right >= "00" and right <= "99") {
        cout << "MMYY" << endl;
        return 0;
    } else {
        cout << "NA" << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  string s,t;
  cin>>s>>t;
  ll ans=0;
  for(int i=0;i<3;i++){
    if(s[i]==t[i]){ans++;}
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(void) {
	int a, b;
	string s;
	int count = 0;

	cin >> a >> b;

	for (int i = a; i <= b; i++) {
		s = to_string(i);
		if (s[0] == s[4] && s[1] == s[3]) {
			count++;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N,A,B;
    cin >> N >> A >> B;
    cout << min(N*A,B) << endl;

    return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    string s;
    cin >> n >> s;

    vector<int> dir(n, 0);
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'E') {
            dir[i] = 1;
        }
    }

    vector<int> cum(n, 0);
    for (int i = 0; i < n; ++i) {
        cum[i+1] = cum[i] + dir[i];
    }

    int ans = n;
    for (int i = 0; i < n; ++i) {
        int e, w;
        w = i - cum[i];
        e = cum[n] - cum[i+1];
        ans = min(ans, w+e);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2964
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long 
#define pb push_back
#define fo(i,N) for(int i = 0 ; i < N ; i++)
#define foo(i,x,N) for (int i = x; i < N ; i++)
#define fill(a,val) memset(a,val,sizeof(a))
#define fastio()  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define MAX 1234567
#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define inf 1e14+1
#define all(a) a.begin(),a.end()
int n;
int arr[22][22];
ll dp[22][1<<22];


ll solve(int i,int x)
{
  if ( i == n+1)
  {
    if ( x == 0)
      return 1;
    return 0;
  }
  if ( dp[i][x] != -1)
    return dp[i][x];

  int ans = 0;

  for(int k = 0; k < n ; k++)
  {
    bool avail = (((1<<k)&x)==0)?0:1;
    if( avail && arr[i][k+1])
    {
      ans = (ans%M + solve(i+1,x^(1<<k))%M)%M;
    }
  }
  return dp[i][x] = ans;
}

int main()
{ 
  cin >> n;
  foo(i,1,n+1)
  {
    foo(j,1,n+1)
    cin >> arr[i][j];
  }
  fill(dp,-1);

  cout << solve(1,(1<<n)-1);
}

Measured memory_bytes: 721152
from collections import defaultdict

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

count=defaultdict(int)
for i in range(N):
  n = a[i]
  count[n-1] += 1
  count[n] += 1
  count[n+1] += 1

print(sorted(count.values())[-1])

Measured memory_bytes: 23712
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int h,sum;
            sum = 0;
            string[] i = Console.ReadLine().Split(' ');
            h = int.Parse(i[0]);

            string[] a = Console.ReadLine().Split(' ');

            foreach (string s in a)
            {
                sum = sum + int.Parse(s);
            }

            if(sum >= h)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}

Measured memory_bytes: 18400
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    vector<int> a(n);
        rep(i,n) cin>>a.at(i);
    map<int,int> b;
    for(auto x:a){
        b[x] ++;
    }
    int ans=0;
    for(auto x:a){
        int t=b[x]+b[x-1]+b[x+1];
        ans=max(ans,t);
    }
    cout<<ans<<endl;
}
//./problem.exe

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

void solve()
{
    int n;
    cin>>n;
    int a[104],b[105];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    int cnt=0,f=0;
    for(int i=0;i<n;i++){
        if(a[i]==b[i]){
            cnt++;
            if(cnt==3) {
                    f=1;
                    break;
            }

        }
        else cnt=0;
    }
    if(f) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main()
{
    solve();
}


Measured memory_bytes: 3624