akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int M = int.Parse(str[1]);
        int[,] A = new int[N,M];
        int[,] B = new int[N,M];
        for(int i=0;i<N;i++){
            str = Console.ReadLine().Split(' ');
            for(int j=0;j<M;j++){
                B[i,j] = int.Parse(str[j]) - 1;
                A[i,int.Parse(str[j])-1] = j;
            }
        }
        int bf = 1;
        int bl = N;
        while(bf != bl){
            int bc = (bf+bl)/2;
            bool b = true;
            {
                int[] X = new int[M];
                int[] Chosen = new int[N];
                int[] stack = new int[2*N];
                int p = 0;
                for(int i=0;i<N;i++){
                    X[B[i,0]]++;
                    if(X[B[i,0]] == bc+1){
                        stack[p] = B[i,0];
                        p++;
                    }
                }
                bool[] deleted = new bool[M];
                while(b && p != 0){
                    int C = stack[p-1];
                    p--;
                    deleted[C] = true;
                    for(int i=0;i<N;i++){
                        if(Chosen[i] == A[i,C]){
                            while(Chosen[i] <= M-1 && deleted[B[i,Chosen[i]]]){
                                Chosen[i]++;
                            }
                            if(Chosen[i] == M){
                                b = false;
                                break;
                            }
                            else{
                                X[B[i,Chosen[i]]]++;
                                if(X[B[i,Chosen[i]]] == bc+1){
                                    stack[p] = B[i,Chosen[i]];
                                    p++;
                                }
                            }
                        }
                    }
                }
            }
            if(b){
                bl = bc;
            }
            else{
                bf = bc+1;
            }
        }
        sb.Append(bf+"\n");
    }
}

Measured memory_bytes: 15712
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) noexcept {
    return b > a && (a = b, true);
}

template <class A, class B> inline bool chmin(A &a, const B &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline vector<T> make_v(const T &initializeValue, size_t sz) {
    return vector<T>(sz, initializeValue);
}

template <class T, class... Args>
inline auto make_v(const T &initializeValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initializeValue, args...))>(sz, make_v<T>(initializeValue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N; cin >> N;

    vector<intmax_t> x(N);
    vector<intmax_t> sorted(N);
    for (size_t i = 0; i < N; ++i) {
        cin >> x[i];
        sorted[i] = x[i];
    }

    sort(sorted.begin(), sorted.end());
    intmax_t Q2_idx = N / 2 - 1;
    intmax_t Q2 = sorted[Q2_idx];
    dump(Q2);

    for (const auto e: x) {
        if (e <= Q2) {
            cout << sorted[Q2_idx + 1] << "\n";
        } else {
            cout << sorted[Q2_idx] << "\n";
        }
    }

    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Pj(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100;
int dp[MC][MC][MC];

int main(){
	int A,B,C; cin >> A >> B >> C;
	repp(i,0,MC) repp(j,0,MC) repp(k,0,MC) dp[i][j][k] = 123456789;
	dp[A][B][C] = 0;
	repp(i,A,MC-2) repp(j,B,MC-2) repp(k,C,MC-2){
		dp[i+1][j+1][k] = min(dp[i+1][j+1][k],dp[i][j][k]+1);
		dp[i][j+1][k+1] = min(dp[i][j+1][k+1],dp[i][j][k]+1);
		dp[i+1][j][k+1] = min(dp[i+1][j][k+1],dp[i][j][k]+1);
		dp[i+2][j][k] = min(dp[i+2][j][k],dp[i][j][k]+1);
		dp[i][j][k+2] = min(dp[i][j][k+2],dp[i][j][k]+1);
		dp[i][j+2][k] = min(dp[i][j+2][k],dp[i][j][k]+1);
	}
	int ans = 123456789;
	repp(i,0,MC) ans = min(ans,dp[i][i][i]);
	cout << ans << endl;
	return 0;
}


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

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

using namespace std;

int n;
string mark[1100];
vector<int> arr[1100];

void dfs(int cur,int depth) {
  cout << string(depth,'.') << mark[cur] << endl;
  rep(i,arr[cur].size()) dfs(arr[cur][i],depth+1);
}

int main(){
  cin >> n;
  rep(i,n) arr[i].clear();
  rep(i,n){
    int k;
    cin >> k;
    cin >> mark[i];
    --k;
    if( k < 0 ) continue;
    arr[k].push_back(i);
  }
  dfs(0,0);
  return 0;
}

Measured memory_bytes: 1440
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n  = sc.nextInt();
        float f = 0f;
        for(int i=0; i<n ; i++){
            double amount = sc.nextDouble();
            String curr = sc.next();
            if(curr.equals("JPY"))
                f += amount;
            if(curr.equals("BTC"))
                f += amount*380000;
        }

        System.out.println(f);

    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char a, b;
  cin >> a >> b;
  
  if (a == 'H' && b == 'H') {
    cout << 'H' << endl;
  } else if (a == 'H' && b == 'D') {
    cout << 'D' << endl;
  } else if (a == 'D' && b == 'H') {
    cout << 'D' << endl;
  } else {
    cout << 'H' << endl;
  }
  
  
  return 0;  
}

Measured memory_bytes: 256
import math
import sys
input = sys.stdin.readline
INF = float("inf")


def isOK(m, K, arr):
    cnt = 0
    for a in arr:
        if a > m:
            cnt += a // m
    return cnt <= K


def binary_search(ok, ng, K, arr=[]):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if isOK(mid, K, arr):
            ok = mid
        else:
            ng = mid
    return ok


# 処理内容
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    ok = 10**9
    ng = 0
    ans = binary_search(ok, ng, K, A)
    print(ans)


if __name__ == '__main__':
    main()

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

typedef long long ll;
typedef pair <int , int> pii;

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int a , b , c , k;
   cin >> a >> b >> c >> k;
   int ans = 0;
   if(k <= a)
      ans += k;
   else{
      ans += a;
      k -= a;
      if(k > b){
         k -= b;
         ans -= k;
      }
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 3584
n,m,l = map(int, input().split())
A = [[0 for c in range(m)]for r in range(n)]
B = [[0 for c in range(l)]for r in range(m)]
C = [[0 for c in range(l)]for r in range(n)]

for r in range(n):
    A[r][:] = list(map(int, input().split()))
for r in range(m):
    B[r][:] = list(map(int, input().split()))
for row in range(n):
    for col in range(l):
        for i in range(m):
            C[row][col] += A[row][i]*B[i][col]
    print(*C[row][:])


Measured memory_bytes: 7040
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int main() {
  int n;
  cin >> n;
  int num1, num2, num3, num4;
  num1 = n / 500;
  num2 = n % 500;
  num3 = num2 / 5;
  cout << num1 * 1000 + num3 * 5;

  return 0;
}

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

int main(){
   int N;
   std::cin >> N;
   std::string S;
   std::cin >> S;
   int max = 0;
   for (int i=1; i<N; i++){
      std::string X = S.substr(0, i);
      std::string Y = S.substr(i, N-i);
      std::sort(X.begin(), X.end());
      std::sort(Y.begin(), Y.end());
      //std::cerr << X << " " << Y << std::endl;
      X.erase(std::unique(X.begin(), X.end()), X.end());
      Y.erase(std::unique(Y.begin(), Y.end()), Y.end());
      //std::cerr << X << " " << Y << std::endl;
      int cnt = 0;
      for (auto x : X){
         if (std::any_of(Y.begin(), Y.end(), [=](auto y){return y == x;})){
            cnt++;
         }
      }
      max = std::max(max, cnt);
   }
   std::cout << max << std::endl;
}



Measured memory_bytes: 256
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
dp = [[(1000,0) for i in range(w)] for j in range(h)]
if a[0][0] == ".":
  dp[0][0] = 0
  flg = 0
else:
  dp[0][0] = 1
  flg = 1
for i in range(h):
  for j in range(w):
    if i == j == 0:
      continue
    if i>0 and j == 0:
      dp[i][j] = dp[i-1][j]
      if a[i][j] != a[i-1][j]:
        dp[i][j] += 1
    elif j>0 and i == 0:
      dp[i][j] = dp[i][j-1]
      if a[i][j] != a[i][j-1]:
        dp[i][j] += 1
    else:
      if a[i][j] == a[i-1][j] and a[i][j] != a[i][j-1]:
        dp[i][j] = min(dp[i-1][j],dp[i][j-1]+1)
      if a[i][j] != a[i-1][j] and a[i][j] != a[i][j-1]:
        dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1]+1)
      if a[i][j] == a[i-1][j] and a[i][j] == a[i][j-1]:
        dp[i][j] = min(dp[i-1][j],dp[i][j-1])
      if a[i][j] != a[i-1][j] and a[i][j] == a[i][j-1]:
        dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1])
print((dp[-1][-1]+1)//2)

Measured memory_bytes: 45164
def main():
    N = int(input())  # 文字列または整数(一変数)
    A = list(map(int, input().split()))  # 整数のリスト

    d = {}

    for i in A:
        if not i in d.keys():
            d[i] = None
        else:
            print("NO")
            return
    else:
        print("YES")


if __name__ == '__main__':
    main()


Measured memory_bytes: 32948
#include<stdio.h>
int main(){
  int n,m;
  scanf("%d %d",&n,&m);
  int a[m];
  int i;
  for(i=0;i<m;i++){
    scanf("%d",&a[i]);
  }
  int sum=0;
  for(i=0;i<m;i++){
    sum=sum+a[i];
  }
  if(n-sum>=0){
    printf("%d\n",n-sum);
  }else{
    printf("-1\n");
  }
  return 0;
}


Measured memory_bytes: 1768
H, W = map(int, input().split())
A = []
q = []
for i in range(H):
  As = list(input())
  A.append(As)
  for j in range(W):
    if A[i][j] == "#":
      q.append((i, j))
r = 0
while q:
  q2 = []
  for i, j in q:
    if i-1 >= 0 and A[i-1][j] == ".":
      A[i-1][j] = "#"
      q2.append((i-1, j))
    if i+1 < H and A[i+1][j] == ".":
      A[i+1][j] = "#"
      q2.append((i+1, j))
    if j-1 >= 0 and A[i][j-1] == ".":
      A[i][j-1] = "#"
      q2.append((i, j-1))
    if j+1 < W and A[i][j+1] == ".":
      A[i][j+1] = "#"
      q2.append((i, j+1))
  q = q2
  r += 1
r -= 1
print(r)


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

ll r,w,c,unit;

bool solve(){
	cin >> r >> w >> c >> unit;
	if(r + w + c + unit == 0)return false;
	if(r >= w * c){
		//r　is too much
		cout << 0 << endl;
		return true;
	}else{
		cout << (w * c - r + unit - 1) / unit << endl;
		return true;
	}
}


int main(){
	while(solve()){}
	
	return 0;
}


Measured memory_bytes: 3096
////**********CODED BY :- DURGESH KUMAR***************////

/*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/
#include<bits/stdc++.h>
#define ll long long
#define ff double
#define endl "\n"
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');

using namespace std;

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

ll arr[n];

REP(i,n)
cin>>arr[i];
sort(arr+0,arr+n);
ff ans =(double)(arr[0]+arr[1])/2;
for(int i=2;i<n;i++)
{
ans=(double)(ans+arr[i])/2;
}
cout<<(double)ans<<endl;



return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N; cin >> N;
    string S; cin >> S;
    vector<array<Int, 3>> A(N + 1);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            A[i + 1][j] += A[i][j] + (S[i] == "RGB"[j]);
        }
    }
    Int ans = 0;
    for (int i = 1; i < N - 1; i++) {
        for (int j = 0; j < 3; j++) if (S[i] == "RGB"[j]) {
            ans += (A[N][(j+1)%3] - A[i+1][(j+1)%3]) * A[i][(j+2)%3];
            ans += (A[N][(j+2)%3] - A[i+1][(j+2)%3]) * A[i][(j+1)%3];
            for (int t = 1; i + t < N && i - t >= 0; t++) {
                if (S[i+t] != S[i] && S[i-t] != S[i] && S[i+t] != S[i-t]) {
                    ans--;
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


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

int main() {
  int A,B,C,S;
  cin >> A >> B >> C >> S;
  int a;
  a = A+B-S;
 if ( a <0){
   cout << A+a << endl;
 }
  else if ( A > S){
    cout << S << endl;
  }
  else{
    cout << A << endl;
  }
}


Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys


YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(a: int, b: int, c: int, d: int):
    print(YES if abs(a - c) <= d or abs(a - b) <= d >= abs(b - c) else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    solve(a, b, c, d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    int x, y;
    cin >> x >> y;
    
    for(int t=0;t<=100;t++){
        for(int k=0;k<=100;k++){
            if((t+k)==x && ((2*t + 4*k)==y)){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    
    for(int k=0;k<=100;k++){
        for(int t=0;t<=100;t++){
            if((t+k)==x && ((2*t + 4*k)==y)){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


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

int main()
{
    long long k, n;
    cin>>k>>n;
    long long a[n];
    vector<long long> seg;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(int i=1; i<n; i++)
    {
        seg.push_back(a[i]-a[i-1]);
    }
    seg.push_back(a[0]+k-a[n-1]);
    for(int i=0; i<n-2; i++)
    {
        seg.push_back(seg[i]);
    }
    int ans = INT_MAX;
    int sum=0;
    for(int i=0; i<n-1; i++)
    {
        sum+=seg[i];
    }
    ans=min(sum, ans);
    for(int i=1; i<n; i++)
    {
        sum=sum-seg[i-1]+seg[i+n-2];
        ans=min(sum, ans);
    }
    printf("%lld", ans);
}

Measured memory_bytes: 8048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;
    int cost = 0;
    rep(i,0,n) {
        if(a[i]==b[i] && b[i]==c[i]) {}
        else if(a[i]==b[i] || a[i]==c[i] || b[i]==c[i]) cost+=1;
        else cost+=2;
    }
    cout<<cost<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

int main() {
  int A, B;
  cin >> A >> B;

  int ans = 0;
  repp(i, A, B) {
    string S = to_string(i);
    if (S[0] == S[4] && S[1] == S[3]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import collections

N = int(input())
A = [int(i) for i in input().split()]

el_count = collections.Counter(A)

res = 0
for X in range(100000):
    tmp = el_count[X-1] + el_count[X] + el_count[X+1]
    if res < tmp:
        res = tmp

print(res)



Measured memory_bytes: 14564
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
long long a[2000], n, cnt, mod = 1000000007;
int main() {
	cin >> n; cnt = 1;
	for (int i = 1; i <= n; i++) {
		int p = i;
		for (int j = 2; j <= n; j++) {
			while (p%j == 0) { p /= j; a[j]++; }
		}
	}
	for (int i = 1; i <= n; i++) { cnt *= (a[i] + 1); cnt %= mod; }
	cout << cnt << endl;
	return 0;
}

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

using namespace std;
#define N = 1200;

int main()
{
    char c;
    int ans[26] = {0};

    while (cin>>c)
    {
        if( (int)'A' <= c && c <= (int)'Z')
        {
            c = c - (int)'A' + (int)'a';
        }
        if( (int)'a' <= c && c <= (int)'z')
            ans[(int)c -(int)'a' ]++;

    }

    for(int i=0;i<sizeof(ans)/sizeof(ans[0]);i++)
    {
        cout<< (char)(i+(int)'a') << " : " << ans[i]<<endl;
    }



    return 0;
}

Measured memory_bytes: 1140
N, M = map(int, input().split())
H_list = list(map(int, input().split()))

good_list = [True] * N

for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1

    if H_list[A] > H_list[B]:
        good_list[B] = False
    elif H_list[A] < H_list[B]:
        good_list[A] = False
    elif H_list[A] == H_list[B]:
        good_list[A] = False
        good_list[B] = False

ans = good_list.count(True)
print(ans)





# import sys
# sys.setrecursionlimit(100000000)

# N, M = map(int, input().split())
# H_list = list(map(int, input().split()))
# road_list = []


# graph_list = [[] for i in range(N)]

# for m in range(M):
#     A, B = map(int, input().split())
#     road_list.append([A, B])

#     A -= 1
#     B -= 1

#     graph_list[A].append(B)
#     graph_list[B].append(A)

# visited = [False] * N
# visited[0] = True
# LorS_list = [0] * N

# def dfs(current, graph_list):

#     global LorS_list
#     global visited

#     if len(graph_list[current]) == 0:
#         LorS_list[current] = 2

#     for i in graph_list[current]:
#         if visited[i] == False:
#             visited[i] = True


#             if H_list[current] > H_list[i] and LorS_list[current] != 1:
#                 LorS_list[current] = 2
#                 LorS_list[i] = 1

#             elif H_list[current] < H_list[i] and LorS_list[i] != 1:
#                 LorS_list[current] = 1
#                 LorS_list[i] = 2

#             elif H_list[current] == H_list[i]:
#                 LorS_list[current] = 1
#                 LorS_list[i] = 1

#             dfs(i, graph_list)


# start = 0
# while all(visited) == False:
#     visited[start] = True
#     dfs(start, graph_list)

#     if False in visited:
#         start = visited.index(False)



# ans = LorS_list.count(2)

# print(ans)

Measured memory_bytes: 20148
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

typedef  long long INT;

typedef long double ld;

using namespace std;
/*........................................Define functions.........................................*/

void move(ll& d1, ll&d2, ll cost) {

	if (d1 <= cost) {d2 += d1; d1 -= d1;}
	else {d1 -= cost; d2 += cost;}
	return ;
}


/*....................................Define global variables .....................................*/

ll d1, d2, d3, d4, d5, d6;



/*.........................................kemkemG0................................................*/
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	/*.........................................kemkemG0.............................................*/

	ll N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;

	d1 = N;

	REP(i,5) {
		move(d5,d6,E);
		move(d4,d5,D);
		move(d3,d4,C);
		move(d2,d3,B);
		move(d1,d2,A);
		if(d6==N){cout<<5<<endl; return 0;}
	}

	//1回でd6まで来る人数

	//cout<<d6<<endl;

	ll ans=ceil((long double)N/d6)+4;
	

	cout<<ans<<endl;






	return 0;
}




Measured memory_bytes: 3588
def main(N,A):
    count = 0
    while True:
        for i in range(N):
            if A[i] % 2 != 0:
                return count
                break
            else:
                A[i] = A[i] // 2
        count +=1

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

Measured memory_bytes: 3060
n=int(input())
c=input().split();d=c[:]
for i in range(n-1):
 for j in range(n-i-1):
  if c[j][1]>c[j+1][1]:c[j:j+2]=c[j+1],c[j]
 m=i
 for j in range(i,n):
  if d[m][1]>d[j][1]:m=j
 d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d);print(['Not s','S'][c==d]+'table')


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct star{int to,nxt,w;}a[1000010];
int head[1000010],cnt,n,fa[1000010],siz[1000010];
ll dis[1000010],a1,a2,b1,b2;
void add(int u,int v,int w){
    cnt++;
    a[cnt].to=v,a[cnt].nxt=head[u],a[cnt].w=w,head[u]=cnt;
}
struct data{
    long long a,b;
    friend bool operator < (data X,data Y){
        if(X.a!=Y.a)return X.a<Y.a;
        return X.b<Y.b;
    }
};
vector<data>X[1000010];
vector<data>v;
ll l,r,mid;
int ef(int l1,int l2,int x,int y){
    if(l2==0)return l2;
    int ll=0,rr=l2-1;
    while(ll<rr-1){
        int md=(ll+rr)>>1;
        a2=X[y][md].a,b2=X[y][md].b;
        if(b1+a2+dis[x]+dis[y]<=mid)ll=md;
        else rr=md;
    }
    a2=X[y][rr].a,b2=X[y][rr].b;
    if(b1+a2+dis[x]+dis[y]<=mid)return rr;
    a2=X[y][ll].a,b2=X[y][ll].b;
    if(b1+a2+dis[x]+dis[y]<=mid)return ll;
    else return l2;
}
void update(int u){
    int x=0,y=0;
    for(int i=head[u];i;i=a[i].nxt){
        int to=a[i].to;
        if(to==fa[u])continue;
        if(x==0)x=a[i].to;
        else y=a[i].to;
    }
    if(siz[x]>siz[y])swap(x,y);
    v.clear();
    for(int i=0;i<X[x].size();i++){
        a1=X[x][i].a,b1=X[x][i].b;
        if(ef(X[x].size(),X[y].size(),x,y)>=X[y].size())continue;
        long long aaa=a1+dis[x],bbb=b2+dis[y];
        data xx;xx.a=aaa;xx.b=bbb;
        v.push_back(xx);
        aaa=b2+dis[y],bbb=a1+dis[x];
        xx.a=aaa;xx.b=bbb;
        v.push_back(xx);
    }
    sort(v.begin(),v.end());
    int len=v.size();
    long long maxx=1000000000000000000;
    for(int i=0;i<len;i++)
        if(v[i].b<maxx)X[u].push_back(v[i]),maxx=v[i].b;
}
void dfs(int u,int f){
    int fl=0;
    for(int i=head[u];i;i=a[i].nxt){
        int to=a[i].to;
        if(to==f)continue;
        dis[to]=a[i].w;
        dfs(to,u);
        fl++;
        if(fl==2)update(u);
    }
    if(fl==0) X[u].push_back((data){0,0});
}
void deal_first(int u,int f){
    siz[u]=1;
    for(int i=head[u];i;i=a[i].nxt){
        int to=a[i].to;
        if(to==f)continue;
        fa[to]=u;
        deal_first(to,u);
        siz[u]+=siz[to];
    }
}
int check(){
    dfs(1,0);
    return X[1].size()>0;
}
int main(){
    scanf("%d",&n);
    for(int i=2,fa,val;i<=n;i++){
        scanf("%d%d",&fa,&val);
        add(fa,i,val);add(i,fa,val);r+=val;
    }
    deal_first(1,0);
    while(l<r-1){
        mid=(l+r)>>1;
        for(int i=1;i<=n;i++)X[i].clear();
        if(check())r=mid;
        else l=mid;
    }
    cout<<r<<endl;
}


Measured memory_bytes: 61812
// Never let them see you bleed...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int LG = 19, maxn = (1<<LG) + 10, mod = 924844033, inf = 1e9 + 10;

int Pow(int a, int b){
    int ans = 1;
    for(; b; b>>=1, a = 1ll * a * a % mod)
	if(b&1)
	    ans = 1ll * ans * a % mod;
    return ans;
}
vector<int> fnd_dv(int n){
    vector<int> ans;
    for(int i = 2; i*i <= n; i++){
	if(n % i == 0){
	    ans.PB(i);
	    while(n % i == 0)
		n/=i;
	}
    }
    if(n > 1)
	ans.PB(n);
    return ans;
}

vector<int> dv;

bool ok(int x){
    for(int p : dv){
	if(Pow(x, (mod-1)/p) == 1)
	    return 0;
    }
    return 1;
}

int W[maxn];

void ntt(int *a, int n, int w, bool rev = 0){    
    int N = 1<<n;
    for(int i = 0; i < N; i++){
	int x = 0;
	for(int j = 0; j < n; j++)
	    x+= bit(i, j) << (n-1-j);
	if(x < i)
	    swap(a[x], a[i]);
    }
    w = Pow(w, (mod-1) >> n);
    if(rev)
	w = Pow(w, mod-2);
    W[0] = 1;
    for(int i = 1; i < N; i++)
	W[i] = 1ll * W[i-1] * w % mod;
    for(int stp = 0; stp < n; stp++){
	int ln = 1<<stp;
	for(int l = 0; l < N; l+= ln+ln){
	    for(int i = 0; i < ln; i++){
		int A = a[l + i], B = 1ll * a[l + ln + i] * W[i<<(n-1-stp)] %mod;
		a[l+i] = (A+B) % mod;
		a[l+ln+i] = (A-B) % mod;
	    }
	}
    }
    if(rev){
	int rv = Pow(1<<n, mod-2);
	for(int i = 0; i < N; i++)
	    a[i] = 1ll * a[i] * rv % mod;	
    }
}

int a[maxn], b[maxn], ans[maxn], n;
vector<int> v[maxn];

int dfs(int u, int par = -1){
    int SZ = 1;
    for(int y : v[u]){
	if(y != par){
	    int num = dfs(y, u);
	    a[num]++;
	    a[n-num]++;
	    SZ+= num;
	}
    }
    return SZ;
}

int fac[maxn], ifac[maxn];

int C(int n, int k){
    if(n < 0 || k < 0 || n < k)
	return 0;
    return 1ll * fac[n] * ifac[k] % mod * ifac[n-k] % mod;
}

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

    fac[0] = 1;
    for(int i = 1; i < maxn; i++)
	fac[i] = 1ll * i * fac[i-1] % mod;
    ifac[maxn-1] = Pow(fac[maxn-1], mod-2);
    for(int i = maxn-2; i >= 0; i--)
	ifac[i] = 1ll * ifac[i+1] * (i+1) % mod;
    
    cin >> n;
    for(int i = 0; i < n-1; i++){
	int a, b;
	cin >> a >> b;
	v[a].PB(b);
	v[b].PB(a);
    }
    dfs(1);
    
    for(int i = 0; i <= n; i++){
	a[i] = 1ll * a[i] * fac[i] % mod;
    }
    for(int i = 0; i <= n; i++){
	b[i] = ifac[n-i];
    }
    
    ntt(a, LG, 5, 0);
    ntt(b, LG, 5, 0);

    for(int i = 0; i < (1<<LG); i++){
	a[i] = 1ll * a[i] * b[i] % mod;
    }
    
    ntt(a, LG, 5, 1);

    for(int i = 0; i <= n; i++){
	a[i] = 1ll * a[i+n] * ifac[i] % mod;
    }
    
    for(int i = 1; i <= n; i++){
	ans[i] = ((1ll * C(n, i) * n % mod) - a[i]) % mod;
	if(ans[i] < 0)
	    ans[i]+= mod;
	cout << ans[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 40960
#include <iostream>
#include <set>

using namespace std;

int main() {
  int a, b;
  int flg1 = 0, flg2 = 0, flg3 = 0, flg4 = 0;
  for (int i = 0; i < 3; ++i) {
    cin >> a >> b;
    switch (a) {
      case 1:
        ++flg1;
        break;
      case 2:
        ++flg2;
        break;
      case 3:
        ++flg3;
        break;
      case 4:
        ++flg4;
        break;
    }

    switch (b) {
      case 1:
        ++flg1;
        break;
      case 2:
        ++flg2;
        break;
      case 3:
        ++flg3;
        break;
      case 4:
        ++flg4;
        break;
    }
  }
  if (flg1 > 2 || flg2 > 2 || flg3 > 2 || flg4 > 2) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n = 1000000;

    int64_t k, x;
    cin >> k >> x;

    const auto* delim = "";
    for (auto i = max(-n, x - k + 1); i <= min(n, x + k - 1); ++i) {
        cout << delim << i;
        delim = " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// 298 round - 534 B
int main() {
	
	unsigned long long n,r,b;
	cin>>n>>b>>r;
	
	cout<<(n/(r+b))*b + (n%(r+b)>b?b:n%(r+b));
	
	return 0;
}

Measured memory_bytes: 256
h = gets.chomp.to_i
w = gets.chomp.to_i
n = gets.chomp.to_i

d = 0

if h<w
    i=0
    while d < n && i <= h
        d += w
        i+=1
    end
else
    i=0
    while d < n && i <= w
        d += h
        i+=1
    end
end

puts i

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<long long> a;
    for(int i=0;i<n;i++){
        int s;
        cin>>s;
        a.push_back(s);
    }
    sort(a.begin(),a.end(),greater<int>());
    vector<long long> e;
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]){
            e.push_back(a[i]);
            i++;
        }
    }
    if(e.size()<=1)cout<<0<<endl;
    else cout<<e[0]*e[1]<<endl;
    return 0;
}


Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,c,d,ans=0;
    cin>>n>>a>>b;
    for(int x=1;x<=n;x++)
    {
        d=0;
        c=x;
        while(c!=0)
        {
            d+=c%10;
            c/=10;
        }
        if(a<=d&&d<=b)
        {
            ans+=x;
        }
    }
    cout<<ans<<endl;
}

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

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

    if (x>=400 && x<=599) cout << " 8 " << endl;
    else if (x>=600 && x<=799) cout << " 7 "<< endl;
    else if (x>=800 && x<=999) cout << " 6 " << endl;
    else if (x>=1000 && x<=1199) cout << " 5 " << endl;
    else if (x>=1200 && x<=1399) cout << " 4 " << endl;
    else if (x>=1400 && x<=1599) cout << " 3 " << endl;
    else if (x>=1600 && x<=1799) cout << " 2 " << endl;
    else if (x>=1800 && x<=1999) cout << " 1 " << endl;

    return 0;
}

Measured memory_bytes: 3596
import math

n = int(input())
a = math.factorial(n)
b = (a*(n-1))/(n*(n-1)/2)
l=0

x_list = []
y_list = []

for i in range(n):
    x, y = map(int, input().split())
    x_list.append(x)
    y_list.append(y)

for j in range(n):
    for k in range(n):
        if j>=k:
            continue
        l += math.sqrt((x_list[j]-x_list[k])**2+(y_list[j]-y_list[k])**2)

print(l*b/a)

Measured memory_bytes: 3064
from itertools import accumulate

N = int(input())
L, R = [0], [0]
for i in range(N):
    li, ri = map(int, input().split())
    L.append(li)
    R.append(ri)

L.sort(reverse=True)
R.sort()

L = list(accumulate(L))
R = list(accumulate(R))

ans = 0
for k in range(N+1):
    ans = max(ans, 2*(L[k]-R[k]))

print(ans)


Measured memory_bytes: 18632
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>
#include<numeric>
#include<string>
#include<set>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int h, w, m; cin >> h >> w >> m;
  vector<pii> vert(h, {0, 0});
  vector<pii> hori(w, {0, 0});
  for(int i = 0; i < h; i++) vert[i].second = i;
  for(int i = 0; i < w; i++) hori[i].second = i;
  set<pii> st;
  for(int i = 0; i < m; i++){
    int y, x; cin >> y >> x;
    y--, x--;
    vert[y].first++;
    hori[x].first++;
    st.insert({y, x});
  }
  sort(vert.begin(), vert.end(), greater<pii>());
  sort(hori.begin(), hori.end(), greater<pii>());
  int mv = vert[0].first;
  int mh = hori[0].first;
  int ans = mv + mh - 1;
  for(int i = 0; i < h; i++){
    if(mv > vert[i].first) break;
    for(int j = 0; j < w; j++){
      if(mh > hori[j].first) break;
      if(st.find({vert[i].second, hori[j].second}) != st.end()){
        ans = mv + mh -1;
      }
      else{
        ans = mv + mh;
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 21912
s =input()
s1 = "dream"
s2= "dreamer"
s3 = "eraser"
s4 = "erase"
n=len(s)
res="NO"
while len(s)!=0 or s>4:
    n=len(s)
    if s[-5:]==s1 or s[-5:]==s4:
        s=s[:n-5]
    elif s[-7:]==s2:
        s=s[:n-7]
    elif s[-6:]==s3:
        s=s[:n-6]
    else:
        break
    if len(s)==0:
        res="YES"
        break
print(res)

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

const long long MOD = 1000000007;

ll twopower(ll n, ll p){
    ll res = 1;
    for(ll i=0; i< n; i++){
        res *= 2;
        res = res % p;
    }
    return res;
}

void solve(long long N, std::vector<long long> A){
    sort(A.begin(), A.end());
    //* check valid
    if(N%2==0){
        for(ll i=0; i< N; i++){
            if(A[i] != (i/2)*2+1) {
                cout << 0 << endl;
                return;
            }
        }
    }
    else{
        for(ll i=0; i< N; i++){
            if(A[i] != ((i+1)/2)*2) {
                cout << 0 << endl;
                return;
            }
        }
    }
    cout << twopower(N/2, MOD) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll k;
  cin >> k;
  ll ans = 0;
  repr(i, 1, k+1)repr(j, 1, k+1)repr(l, 1, k+1){
    ans += gcd(gcd(i, j), l);
  }
  print(ans);
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
 	if(ans==NONE){\
 	}else{\
 		cout << ans << endl;\
 	}
#define YESNO three(solve(),(OUT(YES),1),(OUT(NO),0))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p998 = 998244353;
const LL p107 = 1000000007;
const LL p = p107;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K,  Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
//LL A[SIZE],B[SIZE],C[SIZE];
LL solve(){
	LL a,b,c;
	cin >> a >> b >> c;
	if(c-a-b<=0) return 0;
	return 4*a*b<(c-a-b)*(c-a-b);

	return NONE;
}
 signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	LL T=1;

	REP(i,T){
		YesNo;
	}
	
//	YesNo;
//	YESNO;
//	three(solve(),OUT("First"),OUT("Second"));
	//cin >> N;
	return 0;
 
}


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

const int maxn=1e6+10;
int n,a[maxn],deg[maxn];
int ecnt,ebeg[maxn],eto[maxn],enxt[maxn];
bool win[maxn];

inline int read(){
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	x=c-48;
	while((c=getchar())>='0'&&c<='9')x=x*10+c-48;
	return x;
}
void write(int x){
	if(x>9)write(x/10);
	putchar(x%10+48);
}
inline void ae(int u,int v){
	++ecnt;
	enxt[ecnt]=ebeg[u];
	ebeg[u]=ecnt;
	eto[ecnt]=v;
}

int main(){
	n=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	for(int i=1,u,v;i<n;++i){
		u=read();v=read();
		if(a[u]<a[v])
			ae(u,v),++deg[v];
		else if(a[u]>a[v])
			ae(v,u),++deg[u];
	}
	queue<int> q;
	for(int i=1;i<=n;++i)
		if(!deg[i])
			q.push(i);
	while(!q.empty()){
		int pos=q.front();q.pop();
		for(int i=ebeg[pos],v;i;i=enxt[i]){
			v=eto[i];
			if(!win[pos])
				win[v]=true;
			if(!(--deg[v]))
				q.push(v);
		}
	}
	for(int i=1;i<=n;++i)
		if(win[i])
			write(i),putchar(' ');
	puts("");
	return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
const int mx = 1e5+7;

int ara[mx],prime[mx],cnt[mx];

void sievesolve()
{
    for(int i = 2; i <= mx; i++)
    {
        if(ara[i]== 0)
        {
            prime[i] = 1;
            for(int j = i*2; j < mx; j += i)
                ara[j] = 1;
        }
    }
    for(int i = 1; i < mx; i++)
    {
        if(prime[i] and prime[(i+1)/2]) cnt[i] = 1;
        cnt[i] += cnt[i-1];
    }
}

int main()
{
    sievesolve();
    int t;
    cin >> t;
    while(t--)
    {
        int a , b;
        cin >> a >> b;
        cout << cnt[b] - cnt[a-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
n, k = map(int, input().split())
vs = list(map(int, input().split()))
m = 0
r = min(n, k)
for a in range(r+1):
    for b in range(r-a+1):
        cd = k - (a + b)
        if b == 0:
            hold = sorted(vs[:a])
        else:
            hold = sorted(vs[:a] + vs[-b:])
        ap = hold[min(len([1 for x in hold if x < 0]), cd):]
        s = sum(ap)
        m = max(s, m)
print(m)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include <string.h>

int main(void)
{
	int a, b, t, c = 0, i;

	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &t);


	for(i=1; a*i <= t+0.5; i++){
		c += b;
	}
	
	printf("%d", c);



	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    map<char,int>m;
    int i,c=0;
    for(i=0;i<3;i++)
    {
        if(s[i]=='R')
            c++;
        
      }  
    if(c==3)
        cout<<'3';
   else if(c==1)
        cout<<'1';
   else if(c==2)
   {
        if(s=="RSR")
            cout<<'1';
        else
            cout<<'2';
    }
    else
    {
        cout<<'0';
    }

   
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int number_n, number_k, answer = 0;
      	number_n = Integer.parseInt(sc.next());
      	number_k = Integer.parseInt(sc.next());
      	if(number_k != 1) answer = number_n - number_k;
      	System.out.println(answer);
    }
}

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n; cin >> n;
  string s; cin >> s;

  int left = 0,right = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == '('){
      right++;
    }
    else {
      if(right == 0) left++;
      else right--;
    }
  }

  string ans;
  for(int i = 0; i < left; i++) ans = '(' + ans;
  ans += s;
  for(int i = 0; i < right; i++) ans += ')';
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 764
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int dist[2005][2005];
int cnt[2005];
int main(){
    int n, x, y;
    cin >> n >> x >> y;
    x--;y--;
    rep(i,n)rep(j,n)dist[i][j] = abs(i-j);
    dist[x][y] = dist[y][x] = 1;
    for(int k : {x, y}){
        rep(i,n)rep(j,n)dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
    }
    rep(i,n)rep(j,i)cnt[dist[i][j]]++;
    rep(i,n-1)cout << cnt[i+1] << "\n";
}


Measured memory_bytes: 15872