akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;
 class Main{
    public static void main(String[] args) {
        MyScanner sc=new MyScanner();
        int n=sc.ni();
        int a=sc.ni();
        if(n%500 <= a) System.out.println("Yes");
        else System.out.println("No");
    }


    private static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int ni() {
          return Integer.parseInt(next());
      }
      float nf() {
        return Float.parseFloat(next());
    }
      long nl() {
          return Long.parseLong(next());
      }

      double nd() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }


int main() {
    ll n; cin >> n;
    ll sum = 0;
    for(ll i = 1; i <= n; ++i) {
        sum += (i*(n-i+1));
    }

    ll edge = 0;
    for(int i = 0; i < n-1; ++i) {
        ll u, v; cin >> u >> v;
        if(u > v) swap(u, v);
        ll left = u; ll right = n-v+1;
        edge += (left*right);
    }
    cout << sum-edge << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt(); //この個数を作るのに何分かかる
        int X = sc.nextInt(); //1度に作れるたこ焼き
        int T = sc.nextInt(); //1度に使う時間

        int outT = 0;

        while (N>0) {
            outT = outT+T;
            N=N-X;
        }
        System.out.println(outT);
    }
}

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

enum eKey{
	ENCYPTION,
	CONJUGATED,
};

void conv( string& s, int i, eKey e ){
	if ( e == CONJUGATED ){
		i = 26 - i;
	}
	for( unsigned j = 0; j < s.size(); ++j ){
		if ( s[ j ] >= 'a' && s[ j ] <= 'z' ){
			s[ j ] = ( s[ j ] - 'a' + i ) % 26 + 'a';
		}
	}
}

int main(){
	string s, sThe, sThis, sThat;
	while ( getline ( cin, s ) ){

		for( int i = 0; i < 26; ++i ){
			sThe = "the";
			sThis = "this";
			sThat = "that";
			conv( sThe, i , ENCYPTION );
			conv( sThis, i , ENCYPTION );
			conv( sThat, i , ENCYPTION );
			if ( s.find( sThe ) != string::npos ||
				 s.find( sThis ) != string::npos ||
				 s.find( sThat ) != string::npos ){
					conv( s, i, CONJUGATED );
					break;
			}
		}
			cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

class Main{
  static void swap(int[] a, int idx1, int idx2){
    int t = a[idx1]; a[idx1] = a[idx2]; a[idx2] = t;
  }

  static void quickSort(int[] a, int left, int right){
    int pl = left;
    int pr = right;
    int x  = a[(pl+pr)/2];

    do{
      while (a[pl] < x) pl++;
      while (a[pr] > x) pr--;
      if(pl <= pr)
         swap(a, pl++, pr--);
    }while(pl <= pr);

   if(left < pr) quickSort(a,left,pr);
   if(pl < right) quickSort(a,pl,right);
 }
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] p = new int[N];
    for(int i =0; i<N;i++){
      p[i] = sc.nextInt();
    }
    
    quickSort(p,0,N-1);
    
    int sum = 0;
    for(int i = 0; i<K; i++){
      sum += p[i];
    }
    System.out.println(sum);
  }
}

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

int main() {
	// your code goes here
	long long int x,y,m,i,f=0;
	cin>>x>>y;
	if(x%y==0)
	cout<<"-1"<<endl;
	else
	{
	    m=x;
	    for(i=2;m<=1000000000000000000;i++)
	    {
	        m=x*i;
	        if(m%y!=0)
	        {f=1;
	        break;
	        }
	    }
	    if(f==1)
	    cout<<m<<endl;
	    else
	    cout<<"-1";
	}
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
)

func main() {
	n := readInt()
	x := make([]int, n)
	for i := range x {
		x[i] = readInt()
	}

	ans := math.MaxInt64
	for p := 1; p < 101; p++ {
		c := 0
		for i := range x {
			c += (x[i] - p) * (x[i] - p)
		}
		ans = min(ans, c)
	}

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  scanf("%d", &n);

  
  vector<double> v, v_set;
  map<double, int> mp, mp_sum;
  map<double, int>point;
  REP(i,n){
    double tmp;
    scanf("%lf", &tmp);
    mp[tmp]++;
    v.pb(tmp);
  }

  REPI(itr,mp){
    v_set.pb(itr->first);
    point[itr->first] = 0;
  }

  SORTV(v_set);
  REP(i,v_set.size()-1){
    mp_sum[v_set[i+1]] += mp[v_set[i]] + mp_sum[v_set[i]];
  }

  REP(i,v_set.size()){
    point[v_set[i]] = mp_sum[v_set[i]] * 3 + (mp[v_set[i]] - 1);
  }

  REP(i,n){
    printf("%d\n", point[v[i]]);
  }


  return 0;
}




Measured memory_bytes: 4504
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

N, M, K = MI()
A = [0] + LI()
B = [0] + LI()

for i in range(1, N + 1):
    A[i] += A[i - 1]

for i in range(1, M + 1):
    B[i] += B[i - 1]
    
    if B[i] <= K:
        ans = i

ans = 0

for bk_a in range(N + 1):
    time = A[bk_a]

    if time > K:
        break
        
    l, r = -1, M + 1
    while abs(l - r) > 1:
        bk_b = (l + r) // 2

        if time + B[bk_b] <= K:
            l = bk_b
        else:
            r = bk_b
    
    bk_b = max(0, l)
    ans = max(ans, bk_a + bk_b)

print(ans)

Measured memory_bytes: 119812
while True :
    n = int(input())
    if n == 0 :
        break
    
    else :
        ans = 0
        while True :
            
            if n == 6174 :
                print(ans)
                break
            
            else :
                A = int(n / 1000)
                B = int((n%1000) / 100)
                C = int((n%100) / 10)
                D = n%10
                
                if A == B and A == C and A == D :
                    print("NA")
                    break
                
                else :
                    LIST = []
                    LIST.append(A)
                    LIST.append(B)
                    LIST.append(C)
                    LIST.append(D)
                
                    LIST.sort()
                    S = LIST[0] * 1000 + LIST[1] * 100 + LIST[2] * 10 + LIST[3]
                    L = LIST[3] * 1000 + LIST[2] * 100 + LIST[1] * 10 + LIST[0]
                    
                    n = L - S
                    ans += 1
    
                    


Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
//#pragma gcc optimize("O3")
//#pragma gcc optimize("unroll-loops")
#ifdef EVAH
    #define _WIN32_WINNT 0x0500
    //#include<windows.h>
#endif
#define openFile(n) ShellExecute(nullptr,"open",n,nullptr,nullptr,SW_SHOWNORMAL);
#define closeP(n) system((string("taskkill /im ")+n+" /f").c_str());
#define closeConsole PostMessage(GetConsoleWindow(), WM_CLOSE, 0, 0);
#define opf "output.txt"
#define ipf "input.txt"
#define mem(n,x) memset(n,x,sizeof(n));
#define sf scanf
#define pf printf
#define ff first
#define ss second
#define pb push_back
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define For(x,n) for(int i=x; i<n; i++)
#define stv v+2*(mid-tl+1)
#define LL long long int
#define N 100001

LL dp1[N],dp2[N],dp3[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    #ifdef EVAH
        //freopen(ipf,"r",stdin);
        //openFile(ipf);
        //closeConsole;
        //freopen(opf,"w",stdout);
    #endif

    LL n;
    cin >> n;
    vector<LL> one(n),two(n),three(n);
    For(0,n) cin >> one[i] >> two[i] >> three[i];
    dp1[0]=one[0],dp2[0]=two[0],dp3[0]=three[0];
    For(1,n) {
        dp1[i] = one[i]+max(dp2[i-1],dp3[i-1]);
        dp2[i] = two[i]+max(dp1[i-1],dp3[i-1]);
        dp3[i] = three[i]+max(dp1[i-1],dp2[i-1]);
    }
    cout << max(dp1[n-1],max(dp2[n-1],dp3[n-1])) << "\n";

    #ifdef EVAH
        //openFile(opf);
        //Sleep(3000);
        //closeP("notepad.exe");
        //closeConsole;
    #endif
}


Measured memory_bytes: 7920
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
sys.setrecursionlimit(int(1e+6))
MOD = int(1e+9) + 7
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

def main():
    N, K = i2nn()
    A = i2nn()
    # 選択の余地がない場合、全部掛けるしかない
    if N == K:
        n = 1
        for a in A:
            n = (n * a) % MOD
        print(n)
        return

    Ap = [ n for n in A if n >= 0]
    An = [-n for n in A if n < 0]
    Ap.sort()
    Ap.reverse()
    An.sort()
    An.reverse()
    Np = len(Ap)
    Nn = len(An)
    # 結果はプラスにしたい。Aiが全部マイナスかつKが奇数だとNG
    # 結果をプラスにできない場合、絶対値を最小化する
    if N == Nn and K % 2 == 1:
        n = 1
        A.sort()
        A.reverse()
        for i in range(K):
            n = (n * A[i]) % MOD
        print(n)
        return

    n = 1
    k = K
    i = 0
    j = 0
    # 結果をプラスに場合、プラスを維持しつつ、絶対値を最大化する
    # Kは偶数で考えたい。Kが奇数のとき、一番大きな正の数を取る
    if k % 2 == 1:
        n = (n * Ap[i]) % MOD
        i += 1
        k -= 1
    while k > 0:
        if Np - i < 2:
            n = (n * An[j]) % MOD
            j += 1
            n = (n * An[j]) % MOD
            j += 1
        elif Nn - j < 2:
            n = (n * Ap[i]) % MOD
            i += 1
            n = (n * Ap[i]) % MOD
            i += 1
        else:
            np = Ap[i] * Ap[i+1]
            nn = An[j] * An[j+1]
            if np >= nn:
                n = (n * np) % MOD
                i += 2
            else:
                n = (n * nn) % MOD
                j += 2
        k -= 2
    print(n)

main()


Measured memory_bytes: 35792
import std.algorithm;
import std.array;
import std.conv;
import std.numeric;
import std.range;
import std.stdio;
import std.string;

bool solve (int [] a, int n)
{
	auto total = a.sum (0L) - n;
	if (total & 1)
	{
		return true;
	}
	if (n & 1)
	{
		int [] p;
		foreach (i; 0..n)
		{
			if (a[i] == 1)
			{
				return false;
			}
			if (a[i] & 1)
			{
				p ~= [i];
			}
		}
		if (p.length == 1)
		{
			a[p.front] -= 1;
			auto g = a.reduce !(gcd);
			a[] /= g;
			return !solve (a, n);
		}
	}
	return false;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		writeln (solve (a, n) ? "First" : "Second");
	}
}


Measured memory_bytes: 4276
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
ll n, c[510], s[510], f[510];
int main() {
	cin >> n;
	for (int i = 1; i < n; i++) cin >> c[i] >> s[i] >> f[i];
	for (int i = 1; i < n; i++) {
		ll ans = s[i] + c[i];
		for (int j = i + 1; j < n; j++) {
			if (ans > s[j]) {
				ans = (ans - s[j] + f[j] - 1)/f[j]*f[j] + s[j] + c[j];
			}
			else ans = s[j] + c[j];
		}
		cout << ans << endl;
	}
	cout << 0 << endl;
	return 0;
}


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

void swap(int *a, int *b){
	int work;
	work = *a;
	*a = *b;
	*b = work;
}

int bubbleSort(int array[],int n){
	int cnt=0;
	bool flag=true;
	while(flag){
		flag = false;
		for(int j=n-1;j>0;j--){
			if(array[j]<array[j-1]){
				swap(&array[j],&array[j-1]);
				cnt++;
				flag = true;
			}
		}
	}
	return cnt;
}

void printArray(int array[],int n){
	for(int i=0;i<n;i++){
		if(i>0) cout << " ";
		cout << array[i];
	}
	cout << endl;
}

int main(){
	int n,cnt;
	cin >> n;
	int array[101];
	for(int i=0;i<n;i++){
		cin >> array[i];
	}
	cnt = bubbleSort(array,n);
	printArray(array,n);
	cout << cnt << endl;
}

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

typedef pair<int, int> pii;

class UnionFind{
private:
    //root, weight
    vector<pii> _root;
    
public:
    UnionFind(int n){
        _root.resize(n);
        for(int i=0; i<n; i++){
            _root[i] = pii(i, 0);
        }
    }
    
    pii root(int x){
        if(_root[x].first == x)
            return _root[x];
        
        auto e = root(_root[x].first);
        _root[x].first = e.first;
        _root[x].second += e.second;
        
        return _root[x];
    }
    
    bool unite(int x, int y, int w){
        if(is_same_group(x, y))
            return false;
        
        auto xv = root(x);
        auto yv = root(y);
        
        _root[yv.first] = pii(xv.first, w + xv.second - yv.second);
        
        return true;
    }
    
    bool is_same_group(int x, int y){
        return root(x).first == root(y).first;
    }
};

int N, M;

void solve(){
    auto uf = UnionFind(N);
    for(int i=0; i<M; i++){
        char c; cin >> c;
        
        if(c == '!'){ //unite
            int a, b, w; cin >> a >> b >> w; a--; b--;
            uf.unite(a, b, w);
        }
        if(c == '?'){ //root
            int a, b; cin >> a >> b; a--; b--;
            if(!uf.is_same_group(a, b)){
                cout << "UNKNOWN" << endl;
            }else{
                auto av = uf.root(a);
                auto bv = uf.root(b);
                cout << bv.second - av.second << endl;
            }
        }
    }
}

int main(){
    while(cin >> N >> M, N|M){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 4684
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int long long
#define endl "\n"
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define frr(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define pii pair<int,int>
#define R(a) ll a; cin >> a;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

#define RA(a, n) ll a[(n) + 1] = {}; fr(i, 1, (n)+1) {cin >> a[i];}
#define RM(a, n, m) int a[n + 1][m + 1] = {}; fr(i, 1, n+1) {fr(j, 1, m+1) cin >> a[i][j];}
#define reset(X) memset(X, 0, sizeof(X))
using vi=vector<int>;
const int inf = 1e18;
const int mod=1e9+7;
unsigned int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool isPrime(int n)
{   if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}
int f[200005];
int dp[2010];
ll go(ll x,ll y) {
	assert(x>=0&&y>=0);
	return f[x+y]*modInverse(f[x]*f[y],mod)%mod;
}
signed main()
{
    fastio;
    R(n);R(m);R(k);
    RA(a,n);
    RA(b,m);
    vector<int>p(n+1),q(m+1);
    p[1]=a[1];
    p[0]=0;
    fr(i,2,n+1)
    {
        p[i]=p[i-1]+a[i];
    }
    q[1]=b[1];
    q[0]=0;
    fr(i,2,m+1)
    {
        q[i]=q[i-1]+b[i];
    }
    int ans=0;
    fr(i,0,n+1)
    {
        auto it=upper_bound(q.begin(),q.end(),k-p[i])-q.begin();
        it-=1;
        if(it<0)continue;
        else
        {
            ans=max(ans,i+it);
        }
    }
    cout<<ans<<endl;
}


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

const int mx=1e5+1;
int n,k;
int h[mx],dp[mx];
int solve(int s) //s->no of stone
{
    if(s==n) return 0;
    if(dp[s]!=-1) return dp[s];
    int ret=INT_MAX;
    for(int i=1;i<=k;i++){
        if((i+s)<=n) ret=min(ret,abs(h[s+i]-h[s])+solve(s+i));
    }
    return dp[s]=ret;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);    return 0;

    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>h[i];
    memset(dp,-1,sizeof dp);
    cout<<solve(1);

    return 0;
}


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

int main(){
  int N, prev_mochi=0,mochi=0;
  cin >> N;
  vector<int> mochis(N), kagami_mochi;
  rep(i, N){
    cin >> mochis.at(i);
  }
  sort(mochis.begin(), mochis.end());
  rep(i,N){
    mochi = mochis.at(i);
    if(mochi == prev_mochi) continue;
    kagami_mochi.push_back(mochi);
    prev_mochi = mochi;
  }
  cout << kagami_mochi.size() << endl;
}

Measured memory_bytes: 256
import math

l = list(map(int,input().split()))
N = l[0]
D = l[1]
x = []
for i in range(N):
    x.append(list(map(float,input().split())))

ans = 0
for i in range(N):
    for j in range(i+1,N):
        dist = 0
        for k in range(D):
            dist = dist + (x[j][k] - x[i][k])**2
        dist = math.sqrt(dist)
        if(dist.is_integer()):
            ans = ans + 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    cout << setprecision(20);
    int N;cin >> N;
    vector<pair<double,double>> V(N);
    REP(i,N) cin >> V[i].first >> V[i].second;
    double C = 1.0;
    REPP(i,1,N+1) C*= i;
  	double ans = 0.0;
    REP(i,C){
        REPP(j,1,N){
            double A = V[j].first - V[j-1].first,B = V[j].second - V[j-1].second;
            ans += sqrt(A*A + B*B);
        }
        next_permutation(V.begin(),V.end());
    }

    cout << ans/C << endl;
}

Measured memory_bytes: 256
def b():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    thresh = sum(A) / (4*M)
    items = [a for a in A if a >= thresh]

    if len(items) >= M:
        print('Yes')
    else:
        print('No')


##########
if __name__ == "__main__":
    b()


Measured memory_bytes: 3060
fromA, toA, fromB, toB = map(int, input().split())

if fromA >= fromB:
  st = fromA
else:
  st = fromB
  
if toA <= toB:
  ed = toA
else:
  ed = toB

ret = ed - st
if ret < 0:
  ret = 0

print(ret)

Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//strcmp
typedef struct
{
    char zifu[101];
    int shu;
}yi;
int main()
{
    int x,y,ai,bi,i,j,cnt,max;
    char sz[101];
    yi a[101],b[101];
    scanf("%d",&x);
    ai=0;bi=0;
    for(i=0;i<x;i++)
    {
        scanf("%s",sz);
        cnt=1;
        for(j=0;j<=ai;j++)
        {
            if(strcmp(sz,a[j].zifu)==0)
            {
                cnt=0;
                a[j].shu++;
                break;
            }
        }
        if(cnt)
        {
            ai++;
            strcpy(a[ai].zifu,sz);
            a[ai].shu=1;
        }
    }
    fflush(stdin);

    scanf("%d",&y);
        for(i=0;i<y;i++)
    {
        scanf("%s",sz);
        cnt=1;
        for(j=0;j<=bi;j++)
        {
            if(strcmp(sz,b[j].zifu)==0)
            {
                cnt=0;
                b[j].shu++;
                break;
            }
        }
        if(cnt)
        {
            bi++;
            strcpy(b[bi].zifu,sz);
            b[bi].shu=1;
        }
    }
    for(i=1;i<=ai;i++)
    {
        for(j=1;j<=bi;j++)
        {
            if(strcmp(a[i].zifu,b[j].zifu)==0)
            {
                a[i].shu=a[i].shu-b[j].shu;
            }
            if(a[i].shu<0 )
                a[i].shu=0;
        }
    }
  //  for(i=0;i<ai;i++)
  //  {
      max=a[1].shu;
        for(j=2;j<=ai;j++)
        {
            if( max<a[j].shu )
            {
                max=a[j].shu;
                //temp=a[i].shu; a[i].shu=a[j].shu;a[j].shu=temp;
            }

        }
        printf("%d",max);
  //  }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;
ll MOD=998244353;

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(){
    ll N;cin>>N;
    for(ll h=1;h<=3500;h++){
        for(ll n=1;n<=3500;n++){
            ll mo = 4*n*h-N*n-N*h;
            if(mo==0)continue;
            if((N*h*n)%mo==0&&(N*h*n)/mo>0){
                cout<<h<<" "<<n<<" "<<(N*h*n)/mo<<endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
while True :
    n, m = map(int, input().split())
    if n == 0 and m == 0 :
        break
    
    count = 0
    for i in range(1, n-1) :
        for j in range(i+1, n) :
            for k in range(j+1, n+1) :
                if i + j + k == m :
                    count += 1
                    
    print(count)


Measured memory_bytes: 5596
#include<iostream>

using namespace std;

int main() {
  int a, b, c;
  
  cin >> a >> b >> c;
  
  if (a + b == c) cout << "Yes" << endl;
  else if (a == b + c) cout << "Yes" << endl;
  else if (b == a + c) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
  
}

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

using namespace std;

#define PI 3.14159265358979323846
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define N 100000

typedef long long ll;
typedef unsigned long long ull;

set<char> s;
char str[N + 2];

int main(){
	int n, i;

	for (i = 'a'; i <= 'z'; i++){
		s.insert(i);
	}

	scanf("%[^\n]%n", str, &n);

	for (i = 0; i < n; i++){
		s.erase(str[i]);
	}

	if (s.empty()){
		printf("None\n");
	}
	else{
		printf("%c\n", *s.begin());
	}

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string s1 ,s2;
	int a, b;
	cin >> a>>b;
	
	for (int i = 0; i < b; i++) {
		s1+= a + 48;
	}
	for (int i = 0; i < a; i++) {
		s2+=b+48;
	}
	cout << min(s1,s2) << endl;

	return 0;
}

Measured memory_bytes: 256
A, B, C = map(int,input().split())

if A == B:
    if C == 7:
        print("YES")
    else:
        print("NO")
elif B == C:
    if A == 7:
        print("YES")
    else:
        print("NO")
elif C == A:
    if B == 7:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define N 5005
#define pb push_back
using namespace std;
const int P=1e9+7;
bool __S;
int size[N],son[N],Q[N],father[N];
int b[N],sum[N],C[N][N],F[N][N],fac[N],n,m,root;
int Go[N<<1],Next[N<<1],Value[N<<1],End[N],cnt;
bool __T;
void up(int &x){if (x>=P) x-=P;}
void add(int u,int v){
  Go[++cnt]=v;Next[cnt]=End[u];End[u]=cnt;
}
int Root(int S){
  int h=0,t=1;Q[1]=S;father[S]=0;
  while (h<t){
    int x=Q[++h];size[x]=1;son[x]=0;
    for (int i=End[x],y;i;i=Next[i])
      if ((y=Go[i])!=father[x])
        father[Q[++t]=y]=x;
  }
  int ret=0;son[0]=n+1;
  for (int i=t;i;i--){
    int x=Q[i];
    son[x]=max(son[x],t-size[x]);
    if (son[x]<son[ret]) ret=x;
    if (father[x]) 
      size[father[x]]+=size[x],son[father[x]]=max(son[father[x]],size[x]);
  }return ret;
}
void DFS(int x,int fa){
	size[x]=1;
  for (int i=End[x],y;i;i=Next[i])
    if ((y=Go[i])!=fa){
      DFS(y,x),size[x]+=size[y];
      if (x==root) b[++m]=size[y];
    }
}
int solve(int n){
	C[0][0]=1;
	for (int i=1;i<=n;i++){
		C[i][0]=1;
		for (int j=1;j<=i;j++)
		  up(C[i][j]=C[i-1][j-1]+C[i-1][j]);
	}
	fac[0]=1;
	for (int i=1;i<=n;i++)
	  fac[i]=1ll*fac[i-1]*i%P;
	memset(F,0,sizeof(F));
  F[0][0]=1;
  for (int i=1;i<=m;i++) sum[i]=sum[i-1]+b[i];
  for (int i=0;i<m;i++)
    for (int j=0;j<=sum[i];j++)
      if (F[i][j])
        for (int k=0;k<=b[i+1];k++)
          up(F[i+1][k+j]+=1ll*F[i][j]*C[b[i+1]][k]%P*C[b[i+1]][k]%P*fac[k]%P);
  int ans=0;
  for (int i=0;i<=n;i++){
    int tmp=1ll*F[m][i]*fac[n-i]%P;
    if (i&1^1) up(ans+=tmp);else up(ans+=P-tmp);
  }
  return ans;
	/*b1+b2..+b_m=n
	//Ã¿Ò»¸öµã±ØÐëÖ¸Ïò±ð´¦£¬ÎÊ·½°¸Êý 
	F[0][0]=1;
	for (int i=1;i<=m;i++) sum[i]=sum[i-1]+b[i];
	for (int i=0;i<m;i++)
	  for (int j=0;j<=sum[i];j++)
	    if (F[i][j])
	      for (int k=0;k<=min(j,b[i+1]);k++)
	        up(F[i+1][j-k+b[i+1]]+=1ll*F[i][j]*C[j][k]%P*C[n-sum[i+1]][b[i+1]-k]%P);
	return F[m][1];*/ 
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){
	  int x,y;scanf("%d%d",&x,&y);
	  add(x,y);add(y,x);
	}
	//n=3;add(1,2);add(2,1);add(2,3);add(3,2);
	root=Root(1);
	DFS(root,0);
	int ans1=solve(n-1);
	b[++m]=1;
	int ans2=solve(n);
	printf("%d\n",(ans1+ans2)%P);
}

Measured memory_bytes: 196224
#!/usr/bin/env python3
#ABC47 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,t = map(int,input().split())
a = list(map(int,input().split()))
ma,mi,ans = 0,float('inf'),0
for i in range(n):
    if ma < a[i] - mi:
        ma = a[i] - mi
        ans = 1
    elif ma == a[i] - mi:
        ans += 1
    if mi > a[i]:
        mi = a[i]
    #print(i,ma,mi,ans)
print(ans)


Measured memory_bytes: 62832
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
// #include <bitset>
const int oo=2139063143;
const int N=10100;
const int P=1000000007;
using namespace std;
typedef long long LL;
typedef double db;
//char buf[1<<24],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
	if (x< 0) putchar('-'),x=-x;
	if (x>=10) print(x/10);
	putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
bool e[N][N];
char s[N];
int a[N];
queue <int> q;
int main ()
{
	// freopen (".in","r",stdin);
	// freopen (".out","w",stdout);
	int n; sc(n);
	for (int i=1; i<=n; i++)
	{
		scanf ("%s",s+1);
		for (int j=1; j<=n; j++)
			e[i][j]=s[j]=='1';
	}
	int ans=-1;
	for (int x=1; x<=n; x++)
	{
		memset (a,0,sizeof (int)*(n+1));
		while (q.size ()) q.pop ();
		a[x]=1;
		q.push (x);
		bool fg=1;
		int ma=0;
		while (q.size ())
		{
			int u=q.front (); q.pop ();
			for (int i=1; i<=n; i++) if (e[u][i])
			{
				if (!a[i]) a[i]=a[u]+1,q.push (i);
				else if (abs (a[i]-a[u])!=1) { fg=0; break; }
			}
				
			if (!fg) break;
		}
		if (fg)
		{
			for (int i=1; i<=n; i++)
				ma=max (ma,a[i]);
			ans=max (ans,ma);
		}
	}
	pr(ans);

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	int n; cin >> n;
	string s, t; cin >> s >> t;
	vector<int> memo(n,0);
	if (s[0] != t[0]) memo[0] = 1;
	for (int i = 1; i < n; i++) {
		if (s[i] == t[i]) continue;
		if (memo[i - 1] == 1) memo[i] = 2;
		else memo[i] = 1;
	}
	ll idx = 1,res=0;
	if (memo[0] == 0)res = 3;
	else {
		res = 6;
		idx++;
	}
	for (; idx < n; idx++) {
		if (memo[idx] == 0) {
			if (memo[idx - 1] == 0) res = (res * 2) % MOD;
		}
		else {
			if (memo[idx - 1] == 0) res = (res * 2) % MOD;
			else res = (res * 3) % MOD;
			idx++;
		}
	}
	cout << res << endl;
}


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

constexpr double EPS = 1e-9;

struct point {
	double x, y;
	point(double x_ = 0.0, double y_ = 0.0):x(x_), y(y_) {}
	point(const point &p):x(p.x), y(p.y) {}

	point operator+(const point &p) const {
		return point(x + p.x, y + p.y);
	}

	point operator-(const point &p) const {
		return point(x - p.x, y - p.y);
	}

	point operator*(double s) const {
		return point(x * s, y * s);
	}
};

double norm(const point &p) {
	return p.x * p.x + p.y * p.y;
}

double dot(const point &a, const point &b) {
	return a.x * b.x + a.y * b.y;
}

double cross(const point &a, const point &b) {
	return a.x * b.y - a.y * b.x;
}

struct line {
	point a, b;
	line(const point &a_, const point &b_):a(a_), b(b_){}
};

typedef vector<point> polygon;

int ccw(const point &a, point b, point c) {
	b = b - a;
	c = c - a;
	const double tmp = cross(b, c);
	if(tmp > EPS) return 1; // ccw
	if(tmp < -EPS) return -1; // cw
	if(dot(b, c) < 0) return 2; // c, a, b 順に一直線上
	if(norm(b) < norm(c)) return -2; // a, b, c 順に一直線上
	return 0; //a, c, b 順で一直線上
}

point crosspoint(const line &l, const line &m) {
	const double tmp = cross(l.b - l.a, m.b - m.a);
	if(abs(tmp) < EPS) return l.a; // 平行
	return m.a + (m.b - m.a) * (cross(l.b - l.a, l.a - m.a) / tmp);
}

// L.aからL.bを向いた時の左側を残して切断する．
polygon convex_cut(const polygon &P, const line &l) {
	polygon res;

	point prev = P.back();
	int pc = ccw(l.a, l.b, prev);

	for(const auto &curr : P) {
		const int cc = ccw(l.a, l.b, curr);

		if(pc != -1) {
			res.emplace_back(prev);
		}
		if(pc * cc < 0) {
			res.emplace_back(crosspoint(l, line(prev, curr)));
		}

		prev = curr;
		pc = cc;
	}

	return res;
}

bool ok(const polygon &P) {
	constexpr int MIN = 0;
	constexpr int MAX = 10000;
	polygon rest{point(MIN, MIN), point(MIN, MAX), point(MAX, MAX), point(MAX, MIN)};

	point prev = P.back();
	for(const auto &curr : P) {
		rest = convex_cut(rest, line(prev, curr));
		if(rest.empty()) return false;
		prev = curr;
	}

	return true;
}

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

	for(int n; cin >> n && n;) {
		polygon P(n);
		for(auto &e : P) cin >> e.x >> e.y;
		cout << ok(P) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
    using namespace std;
    
    typedef struct sta_ {
       long c; 
       long s; 
       long f; 
    } Sta;

    int main(){
      long n ;
      cin >> n ;
      long c , s , f;
      vector<Sta> v;
      for(int i = 1 ; i < n ; i++ ){
          cin >> c >> s >> f;
          Sta *sta1 = new Sta;
          sta1->c = c;
          sta1->s = s; 
          sta1->f = f;
          v.push_back(*sta1);
          
      }
      long ans;
      long temp;
      for(int i = 0 ; i < n ; i++ ){
          ans = 0;
          for(long j = i ; j < n - 1; j++){
              Sta sta2 = v[j];
              if(ans <= sta2.s){
                  ans = sta2.s;
              }else if(ans % sta2.f != 0){
                  ans += sta2.f - (ans % sta2.f);
              }
              ans += sta2.c;
          }
          cout << ans << endl;
      }
      
      return 0;
    }

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

int main(){
    int n;
    string s1,s2;
    int x = 0, y = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s1 >> s2;
        if(s1>s2) x=x+3;
        else if(s2>s1) y=y+3;
        else x++,y++;
    }
    cout << x << " " << y << endl;
    return 0;
}


Measured memory_bytes: 3140
from collections import OrderedDict 

# Function to remove all duplicates from string 
# and order does not matter 
def removeDupWithoutOrder(str): 
   
    # set() --> A Set is an unordered collection  
    #            data type that is iterable, mutable,  
    #            and has no duplicate elements. 
    # "".join() --> It joins two adjacent elements in 
    #               iterable with any symbol defined in  
    #               "" ( double quotes ) and returns a  
    #               single string 
    return "".join(set(str)) 
  
# Function to remove all duplicates from string  
# and keep the order of characters same 
def removeDupWithOrder(str): 
    s = "".join(OrderedDict.fromkeys(str)) 
    return "".join(sorted(s))

n = int(input())
s = input()
maxcnt = 0
oset = set()
for i in range(1,n):
    s1 = removeDupWithOrder(s[0:i])
    s2 = removeDupWithOrder(s[i:n])
    oset.add(s1+' '+s2)
ls = list(oset)
for x in ls:
    s1,s2 = map(str,x.split())
    cnt = 0
    for i in range(len(s1)):
        if s1[i] in s2:
            cnt += 1
    if maxcnt < cnt:
        maxcnt = cnt
print(maxcnt)

Measured memory_bytes: 3444
#include<iostream>

int main()
{
    int x[5]={0};
    for(int i=0; i<5; i++)
    {
        std::cin >> x[i];
        if(x[i] == 0)
        {
            std::cout << i+1;
            return 0;
        }
    }
    return 0;
}

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

using SyrupBeans.Competitive.Integer;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var ab = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
        var a = ab[0];
        var b = ab[1];

        var commonDivisors = new HashSet<long>(Divisibility.EnumerateDivisors(a));
        commonDivisors.IntersectWith(new HashSet<long>(Divisibility.EnumerateDivisors(b)));

        var k = 1;
        var candidates = new SortedSet<long>(commonDivisors);
        candidates.Remove(1);
        while (candidates.Any())
        {
            ++k;
            var t = candidates.Min + 1;
            while (t <= candidates.Max)
            {
                var view = candidates.GetViewBetween(t, candidates.Max);
                t = view.Min + 1;
                if (view.Min % candidates.Min != 0)
                {
                    continue;
                }
                candidates.Remove(view.Min);
            }
            candidates.Remove(candidates.Min);
        }

        Console.WriteLine(k);
    }
}

namespace SyrupBeans.Competitive.Integer
{
    using Integer = System.Int64;
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public static class Divisibility
    {
        
        /// <summary>O(log max(<paramref name="x" />, <paramref name="y" />))</summary>
        public static Integer Gcd(Integer x, Integer y) => x < 1 ? y : Gcd(y % x, x);

        /// <summary>O(sqrt(<paramref name="x" />))</summary>
        public static IEnumerable<Integer> EnumerateDivisors(Integer x)
        {
            var cache = new Stack<Integer>();
            for (Integer i = 1; i * i < x; ++i)
            {
                Integer r, d = Math.DivRem(x, i, out r);
                if (r != 0)
                {
                    continue;
                }
                yield return i;
                cache.Push(d);
            }
            if (cache.Any() && cache.Peek() * cache.Peek() == x)
            {
                cache.Pop();
            }
            while (cache.Any())
            {
                yield return cache.Pop();
            }
        }
    }
}


Measured memory_bytes: 19168
#[allow(dead_code)]
fn read_line(n: usize) -> String {
    let mut ss = String::new();
    for _i in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        ss.push_str(&s);
    }
    ss
}

macro_rules! parse {
    ($s:expr => $($r:tt)*) => {
        let s = $s;
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        parse!{s => $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main()
{
    parse!{
        n: usize,
    }
    let ans_f = n as f64 / 1.08;
    let ans_i = (ans_f + 0.999999) as usize;
    let ans_f2 = ans_i as f64 * 1.08;
    let ans_i2 = ans_f2 as usize;
    if n == ans_i2 {
        println!("{}", ans_i);
    }
    else {
        println!(":(");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <atcoder/segtree.hpp>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

ll op(ll a,ll b){
    return max(a,b);
}

ll e(){
    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;cin >>n>>k;
    Vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
    }
    const int MAX_A=300101;
    atcoder::segtree<ll,op,e>dp(MAX_A);
    for (int i = 0; i < n; ++i) {
        int l=a[i]-k;
        int r=a[i]+k+1;
        l=max(0,l),r=min(MAX_A,r);
        dp.set(a[i],dp.prod(l,r)+1);
    }
    ll ans=dp.all_prod();
    cout <<ans<<"\n";
}

Measured memory_bytes: 16144
//
// Created by ryo on 2019/11/23.
//

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

    int n;
    ll t = 0;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
        t += a[i];
    }

    ll p = 0;
    ll ans = INF;
    rep(i, n) {
        p += a[i];
        ll tt = t - p;
        chmin(ans, abs(p - tt));
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;
#define lc (x << 1)
#define rc (x << 1 | 1)

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' && ch > '9') && (ch != '-')) ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int const MAXN = 2e5 + 5;
int a[MAXN], b[MAXN], c[MAXN], n, cnt;
int t[MAXN * 4], tag[MAXN * 4];
inline void Init() { memset(t, 0, sizeof(t)), memset(tag, 0, sizeof(tag)); }
inline void Set(int x) { t[x] = 0, tag[x] = 1; }
inline void Pushdown(int x) { Set(lc), Set(rc), tag[x] = 0;}
void Modify(int x, int l, int r, int i, int j) {
  if (i <= l && r <= j) return Set(x);
  if (tag[x]) Pushdown(x);
  int mid = (l + r) >> 1;
  if (i <= mid) Modify(lc, l, mid, i, j);
  if (j > mid) Modify(rc, mid + 1, r, i, j);
}
void Change(int x, int l, int r, int to, int k) {
  if (l == r) {
    ++t[x];
    if (l != 1 && t[x] == (b[l] - b[l - 1]) * k)
      t[x] = 0, Change(1, 1, n, l - 1, k);
    return;
  }
  if (tag[x]) Pushdown(x);
  int mid = (l + r) >> 1;
  if (to <= mid) Change(lc, l, mid, to, k);
  else Change(rc, mid + 1, r, to, k);
}
int Query(int x, int l, int r, int to) {
  if (l == r) return t[x];
  if (tag[x]) Pushdown(x);
  int mid = (l + r) >> 1;
  if (to <= mid) return Query(lc, l, mid, to);
  else return Query(rc, mid + 1, r, to);
}

bool Check(int k) {
  Init();
  for (RI i = 2; i <= n; ++i)
    if (a[i] <= a[i - 1]) {
      Change(1, 1, n, a[i], k);
      if (a[i] + 1 <= n) Modify(1, 1, n, a[i] + 1, n);
    }
  if (b[1] == 1) return Query(1, 1, n, 1) < k;
  else return Query(1, 1, n, 1) / ((b[1] - 1) * k) < k;
}

int main() {

#ifdef LOCAL
  FILEIO("a");
#endif

  read(n);
  for (RI i = 1; i <= n; ++i) read(a[i]), b[i] = a[i];
  sort(b + 1, b + 1 + n);
  int len = unique(b + 1, b + 1 + n) - b - 1;
  for (RI i = 1; i <= n; ++i)
    a[i] = lower_bound(b + 1, b + 1 + len, a[i]) - b;
  int flag = 1;
  for (RI i = 1; i < n; ++i)
    if (a[i] >= a[i + 1]) flag = 0;
  if (flag) return puts("1"), 0;
  int l = 2, r = n, mid, ans;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (Check(mid)) ans = mid, r = mid - 1;
    else l = mid + 1;
  }
  printf("%d\n", ans);

  cerr << (double)(clock()) / CLOCKS_PER_SEC * 1000 << "ms" << endl;

  return 0;
}

// created by Daniel yuan

Measured memory_bytes: 9856
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<ll> a(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	vector<ll> b = a;

	sort(all(b));

	ll c = b[n / 2];

	for (int i = 0; i < n; i++)
	{
		ll res;
		if (a[i] < c)
		{
			res = b[n / 2];
		}
		else
		{
			res = b[n / 2 - 1];
		}

		println(res);
	}
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define met(a,b); memset(a,b,sizeof(a));
typedef long long ll;
using namespace std;
double pai=3.141592653589793;
 
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
 
// inline long long read() {
//     long long tmp=0, fh=1; char c=getchar();
//     while (c<'0'||c>'9') {if (c=='-') fh=-1; c=getchar();}
//     while (c>='0'&&c<='9') tmp=tmp*10+c-48, c=getchar();
//     return tmp*fh;
// }
int dp[100005];
struct nod
{
 /* data */
 int a,b;
}a[10005];
int main(){
    memset(dp,-1,sizeof(dp));
    int h,n;
    cin>>h>>n;
    for(int i=0;i<n;i++)
    {
        a[i].a=read();
        a[i].b=read();
    }
    dp[h]=0;
    for(int i=h;i>=0;i--)
    {
        if(dp[i]==-1) continue;
        for(int j=0;j<n;j++)
        {
            int u=max(0,i-a[j].a);
            if(dp[u]!=-1) dp[u]=min(dp[u],dp[i]+a[j].b);
            else dp[u]=dp[i]+a[j].b;
        }
    }
    cout<<dp[0];
}

Measured memory_bytes: 640
#!/usr/bin/env python3

from collections import deque

input()
A = input().split(' ')
A = list(map(int, A))
A = sorted(A)[::-1]

d = deque()

ret = 0

for a in A:
    if len(d) == 0:
        d.append(a)
    else:
        ret += d.popleft()
        d.append(a)
        d.append(a)

print(ret)


Measured memory_bytes: 105924