akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))

n_case1 = 0
n_case2 = 0
n_case3 = 0

for point in P:
    if point <= A:
        n_case1 += 1
    elif point <= B:
        n_case2 += 1
    else:
        n_case3 += 1

min_case = min([n_case1, n_case2, n_case3])
ans = min_case
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>

#define div 1000000000+7

typedef long long ll;

using namespace std;

void solve() {
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(s[i] != ','){
            cout << s[i];
        }else{
            cout << " ";
        }
    }
}

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


Measured memory_bytes: 256
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
#define N (ll)(1e6+3)
#define INF (ll)(1e18+3)
#define MOD (ll)(1e9+7)
 
#define ll long long
#define rep(i,a,n) for(ll i = a; i < n; i++)
#define per(i,a,n) for(ll i = n-1; i >= a; i--)
 
//using namespace __gnu_pbds;
using namespace std;
 
// typedef
// tree<
//     pair<ll,ll>,
//     null_type,
//     less<pair<ll,ll>>,
//     rb_tree_tag,
//     tree_order_statistics_node_update>
// ordered_set;
 
 
ll n;
ll par[N];
vector<ll> g[N];
ll d[N];
 
void dfs(ll u, ll p) {
    vector<ll> v;
 
    rep(i,0,g[u].size()) {
        ll ch = g[u][i];
        if (ch == p) continue;
        dfs(ch,u);
        v.push_back(d[ch]);
    }
 
    if (v.size() == 1)
        d[u] = v[0]+1;
    else {
        ll mask = 0;
        rep(i,0,v.size()) {
            mask ^= (v[i]+1);
        }
        d[u] = mask;
    }
}
 
void solve() {
    cin >> n;
    rep(i,0,n-1) {
        ll a, b; cin >> a >> b; a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0,0);
    if (d[0]) {
        cout << "Alice" << endl;
    }
    else {
        cout << "Bob" << endl;
    }
}
 
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 40192
package main

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

func main() {
	scanner := makeWordScanner()
	r := eGetInt(scanner)
	fmt.Println(3 * r * r)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}

func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
def abc106_b():
    n = int(input())
    have_8_divisors = 0

    def count_up_divisor(check_num):
        cnt = 0
        for i in range(1, check_num + 1):
            # 1からcheck_numを順に探索して、nの約数かどうか判断して、約数の時はカウント
            if check_num % i == 0:
                cnt += 1
        return cnt

    for i in range(1, n + 1):
        # 偶数の時はスキップ
        if i % 2 == 0:
            continue

        result = count_up_divisor(i) == 8
        if result:
            have_8_divisors += 1

    print(have_8_divisors)

if __name__ == '__main__':
    abc106_b()

Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=(n);i<(x);++i)
#define rem(i,n,x) for(int i=(n);i>=(x);--i)
#define pb push_back
using ll = long long;

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

	if (a - b * 2 >= 0) cout << a - b * 2 << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
mod = 10**9 + 7
import numpy as np
n, k = map(int,readline().split())
a = np.array(readline().split(),np.int64)
f = 0
r = 0
for i in range(n):
    for j in range(i+1, n):
        if a[i] > a[j] :
            r += 1
        elif a[i] < a[j]:
            f += 1
print((f * k * (k-1) // 2 % mod + r * k * (k+1) // 2 % mod) % mod)

Measured memory_bytes: 12424
#include <stdio.h>

int main (void) {
    int n, x, y, z;
    int res;

    for (;;) {
        res = 0;
        scanf ("%d %d", &n, &x);
        if (n==0 && x==0) break;
        for (int i=1; i<=n; i++) {
            y=x-i;
            if (y<=2*i) break;
            for (int j=i+1; j<=n; j++) {
                z=y-j;
                if (z<=j) break;
                if (z>j && z<=n) res++;
            }
        }
        printf ("%d\n", res);
    }
    
    return 0;
}


Measured memory_bytes: 2048
def function(X):
    if X=='SRS':
        return 1
    elif X[1] == 'S':
        if (X[0] == 'R') or (X[2] == 'R'):
            return 1
        else:
            return 0
    else:
        if (X[0] == 'R') and (X[2] == 'R'):
            return 3
        elif (X[0] == 'R') or (X[2] == 'R'):
            return 2
        else:
            return 0


if __name__ == '__main__':
    X = input()
    print(function(X))


Measured memory_bytes: 61704
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

string s;

int main() {
    cin >> s;

    for (int i = 0; i < s.length(); i++) {
        cout << 'x';
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#define INT long long int
using namespace std;

INT A[200100], B[200100];
INT n, m, k,i,ans, j;
int main(){
    cin >> n >> m >>k;
    for(i=1;i<=n;i++){
        cin >> A[i];
        A[i] = A[i] + A[i-1];
    }
    for(i=1;i<=m;i++){
        cin >> B[i];
        B[i] = B[i] + B[i-1];
    }
    A[n+1] = 9999999999999999ll;
    B[m+1] = 9999999999999999ll;
    i=n;
    while(A[i]>k) i--;
    j=0;
    for(;i>=0;i--){
        while(A[i]+B[j]<=k) j++;
        ans = max(ans,i+j-1);
    }
    cout << ans <<endl;
}


Measured memory_bytes: 6664
def solve():
    N = int(input())

    if N % 2 != 0:
        print(0)
    else:
        cnt = 0
        i = 1
        while N >= 5 ** i * 2:
            cnt += N // (5**i*2)
            i += 1
    
        print(cnt)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int[][] c = new int[3][3];

    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        c[i][j] = sc.nextInt();
      }
    }

    int[] a = new int[3];
    a[0] = 0;
    int[] b = { c[0][0], c[0][1], c[0][2] };
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];

    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if ((a[i] + b[j]) != c[i][j]) {
          System.out.println("No");
          return;
        }
      }
    }

    System.out.println("Yes");

  }
}

Measured memory_bytes: 35864
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;


int main(){
	int n,m,tmp;
  	long t = 0;
	cin >>m >> n;
	rep(i, n){
		cin >> tmp;
      	t += tmp;
	}
	cout << (t >= m ? "Yes" : "No")<< endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

dictionary = {}
input_num = int(raw_input())
counter = 0
while counter < input_num:
    command, key = raw_input().split(' ')
    if command[0] == 'i':
        dictionary[key] = None
    else:
        if key in dictionary:
            print 'yes'
        else:
            print 'no'

    counter += 1

Measured memory_bytes: 32964
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
string s;
cin>>s;
int n=s.length();
rep(i,0,n-1)
{
	if(s[i]=='?')
	{
		ol("D");
	}
	else
	{
		ol(s[i]);
	}
}
return 0;
}



Measured memory_bytes: 3780
/*******************************\
   Name:    REAJUL HAQUE REAYZ  |
   School:  COMILLA UNIVERSITY  |
            CSE (5TH BATCH)     |
********************************/
#include<bits/stdc++.h>
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define mem(x,y) memset(x , y , sizeof(x))
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const ll MOD = 1000000007;
const int MAX = 55550;

bool not_prime[MAX+3];
int prime[MAX+3], cnt_prime;
void sieve()
{
    not_prime[0]=true;
    not_prime[1]=true;
    prime[cnt_prime++]=2;
    for(int i=4; i<=MAX; i+=2) not_prime[i]=true;
    for(int i=3; i<=MAX; i+=2)
    {
        if(!not_prime[i])
        {
            prime[cnt_prime++]=i;
            for(int j=i+i; j<=MAX; j+=i) not_prime[j] = true;
        }
    }
}
int main(){
    sieve();
    int n;
    cin>>n;
    vector<int>v;
    for(int i=0; i<cnt_prime; i++){
        int x = prime[i];
        if(x%5==1) v.pb(x);
        if(v.size()==n) break;
    }
    for(int i=0; i<n; i++) cout<<v[i]<<" "; cout<<endl;
	return 0;
}


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

using namespace std;

template <class T> inline T updmax(T& a, T b) { return a = max(a, b); }
template <class T> inline T updmin(T& a, T b) { return a = min(a, b); }

template <unsigned long long mod> class modint {
public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod - this->v); }
	modint& operator+=(const modint rhs) {
		v += rhs.v;
		if (v >= mod) v -= mod;
		return *this;
	}
	modint& operator-=(const modint rhs) {
		if (v < rhs.v) v += mod;
		v -= rhs.v;
		return *this;
	}
	modint& operator*=(const modint rhs) {
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a) {
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp) {
			if (exp % 2) { ret *= a; }
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint& operator/=(modint rhs) {
		(*this) *= inverse(rhs);
		return *this;
	}
	friend ostream& operator<<(ostream& os, modint& u) {
		os << u.v;
		return (os);
	}
	friend istream& operator>>(istream& is, modint& u) {
		is >> u.v;
		return (is);
	}
};

const int MOD = 998244353;
using mint = modint<MOD>;

const int MAX = 100005;
mint fac[MAX], invfac[MAX], inv[MAX];

void facinit() {
	fac[0] = fac[1] = 1;
	invfac[0] = invfac[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i;
		inv[i] = -inv[MOD % i] * (MOD / i);
		invfac[i] = invfac[i - 1] * inv[i];
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	string s;
	cin >> n >> s;
	mint ret = 1;
	vector<int> cnt(8, 0);
	for (int i = 0; i < n; i++) ret *= i + 1;
	for (int i = 0; i < 3 * n; i++) {
		int x = (s[i] == 'R') ? 1 : (s[i] == 'G') ? 2 : 4;
		if (cnt[(~x) & 7]) {
			cnt[(~x) & 7]--;
			continue;
		}
		bool flag = false;
		for (int j = 0; j < 3; j++) {
			if (cnt[1 << j]) {
				if ((1 << j) == x) {
					cnt[x]++;
					ret *= cnt[x];
				} else {
					cnt[(1 << j) | x]++;
					ret *= cnt[(1 << j) | x];
					cnt[(1 << j)]--;
				}
				flag = true;
				break;
			}
		}
		if (!flag) cnt[x]++;
	}
	cout << ret << "\n";
	return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int n;
int val[100005];
int calc(int x) {
	int ans = 0;
	while(x) {
		ans += x%10;
		x/=10;
	}
	return ans;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) val[i] = calc(i);
	int ans = 100000;
	for(int i=1;i<=n-1;i++) ans = min(ans, val[i]+val[n-i]);
	printf("%d",ans);
}

Measured memory_bytes: 640
from collections import deque
 
H, W = map(int, input().split())
S = [input() for _ in range(H)]
 
INF = 10**15
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
 
answer = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      continue
    else:
      dist = [[INF for _ in range(W)] for _ in range(H)]
      dist[i][j] = 0
      stack = deque([(i, j)])
      
      while stack:
        s = stack.popleft()
        si, sj = s
        for di, dj in d:
          if 0 <= si + di <= H - 1 and 0 <= sj + dj <= W - 1 and S[si + di][sj + dj] != "#":
            if dist[si + di][sj + dj] > dist[si][sj] + 1:
              dist[si + di][sj + dj] = dist[si][sj] + 1
              stack.append((si + di, sj + dj))
      #print(dist)
 
      max_dist = 0
      for ii in range(H):
        #print(dist[ii])
        for jj in range(W):
          if dist[ii][jj] != INF:
            max_dist = max(max_dist, dist[ii][jj])
      #print("")
      answer = max(max_dist, answer)
      
print(answer)

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

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

const int INF = 1000000000000;
int dist[210][210];

signed main() {
	rep(i, 200) rep(j, 200) dist[i][j] = INF;
	rep(i, 200) dist[i][i] = 0;
	
	int N, M, R;
	cin >> N >> M >> R;

	vector<int> r;
	inputVector(r, R);

	rep(i, M) {
		int A, B, C;
		cin >> A >> B >> C;
		A--; B--;
		dist[A][B] = C;
		dist[B][A] = C;
	}

	rep(k, N) rep(i, N) rep(j, N) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

	vector<int> perm;
	rep(i, R) perm.push_back(i);

	int ret = INF;
	do {
		int tmp = 0;
		rep(i, R - 1) {
			tmp += dist[r[perm[i]] - 1][r[perm[i + 1]] - 1];
		}
		ret = min(ret, tmp);
	} while (next_permutation(all(perm)));

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())

int main()
{
    ll X;
    cin >> X;
    ll dest = 0;
    ll i = 1;
    while(X > dest) {
        dest += i;
        ++i;
    }
    printf("%lld\n", i-1);
    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<ll> a(N+2);
  vector<ll> b(N+1);
  rep(i,N+1) cin >> a[i];
  rep(i,N) cin >> b[i];
  ll ans =0;
  rep(i,N+1){
    if(b[i]>a[i]){
      ll diff = min(a[i+1],b[i]-a[i]);
      a[i+1] -= diff;
      ans += a[i]+diff;
      // b[i] -= a[i];
      // a[i] = 0;
    }else{
      ans += b[i];
      // a[i] -= b[i];
      // b[i]=0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    static int[] aArr;
    static int[] fArr;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		long total = 0;
		aArr = new int[n];
		fArr = new int[n];
		for (int i = 0; i < n; i++) {
		    aArr[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
		    fArr[i] = sc.nextInt();
		}
		Arrays.sort(aArr);
		Arrays.sort(fArr);
		long left = -1;
		long right = (long)aArr[n - 1] * fArr[n - 1];
		while (right - left > 1) {
		    long m = (right + left) / 2;
		    if (check(k, m)) {
		        right = m;
		    } else {
		        left = m;
		    }
		}
		System.out.println(right);
	}
	
	static boolean check(long k, long x) {
	    for (int i = 0; i < aArr.length; i++) {
	        k -= Math.max(0, aArr[i] - x / fArr[fArr.length - i - 1]);
	        if (k < 0) {
	            return false;
	        }
	    }
	    return true;
	}
}


Measured memory_bytes: 101228
s = input()
s2 = (len(s)-1) // 2
s3 = (len(s)+3) // 2
if s != s[::-1]:
    print("No")
else:
    if s[0:s2] != ''.join(list(reversed(s[0:s2]))):
        print("No")
    else:
        if s[s3-1::] != ''.join(list(reversed(s[s3-1::]))):
            print("No")
        else:
            print("Yes")


Measured memory_bytes: 3060
#pragma 03
#pragma GCC target("avx")
#pragma GCC optimization ("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define int long long
#define eb emplace_back
#define ef emplace_front
#define rep(i, x, n) for (int i = x; i < n; ++i)
#define mp make_pair
#define fi first
#define se second
#define ii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vii vector<pair<int, int>>
#define reverse(s) reverse(s.begin(), s.end())
#define ld long double
#define vs vector<string>
#define inf INT_MAX
#define vc vector<char>
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vb vector<bool>
#define lb(a, x) lower_bound(a.begin(), a.end(), x)
#define ub(a, x) upper_bound(a.begin(), a.end(), x) 
#define vvi vector<vi>
#define mine(a) min_element(a.begin(),a.end())
#define maxe(a) max_element(a.begin(), a.end())
#define iota(a,i) iota(a.begin(),a.end(),i)
#define fileopen(filename) if (fopen(filename".INP", "r")) {freopen(filename".INP", "r", stdin);freopen(filename".OUT", "w", stdout);}
vvi adj;
vi p;
vii m;
void dfs(int x, int par) {
    for (int i : adj[x]) {
        if (i != par) {
            dfs(i, x);
            if (m[i].first == inf) continue;
            else if (m[x].first == inf) {
                m[x].first = m[i].first - 1;
                m[x].second = m[i].second + 1;
            }
            else {
                int h = m[i].first - 1, y = m[i].second + 1;
                if (h % 2 != m[x].first % 2 || y % 2 != m[x].second % 2) {
                    cout << "No";
                    exit(0);
                }
                m[x].first = max(m[x].first, h);
                m[x].second = min(m[x].second, y);
                if (m[x].first > m[x].second) {
                    cout << "No";
                    exit(0);
                }
            }
        }
    }
}
void build(int x, int par) {
    for (int i : adj[x]) {
        if (i != par) {
            if (m[i].second == inf || p[x] + 1 >= m[i].first && p[x] + 1 <= m[i].second) p[i] = p[x] + 1;
            else if (p[x] - 1 >= m[i].first && p[x] - 1 <= m[i].second) p[i] = p[x] - 1;
            build(i, x);
        }
    }
}
signed main() {
    fileopen("");
    fastio;
    int n, k;
    cin >> n;
    m.resize(n + 1, mp(inf, inf));
    adj.resize(n + 1);
    p.resize(n + 1, inf);
    rep(i, 0, n - 1) {
        int x, y;
        cin >> x >> y;
        adj[x].emplace_back(y);
        adj[y].emplace_back(x);
    }
    cin >> k;
    rep(i, 0, k) {
        int x;
        cin >> x;
        cin >> p[x];
        m[x] = mp(p[x], p[x]);
    }
    dfs(1, 1);
    if (p[1] == inf) p[1] = m[1].first;
    /*rep(i, 1, n + 1) {
        for (int j : s[i]) cout << j << " ";
        cout << endl;
    }
    cout << 'a' << endl;*/
    cout << "Yes" << endl;
    build(1, 1);
    rep(i, 1, n + 1) cout << p[i] << endl;
    return 0;
}

Measured memory_bytes: 17112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>

using namespace std;

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

  int ans = (A - 1) * (B - 1);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
    int count=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        if(i%2!=0){
            int f=0;
            for(int j=1;j<=i;j++){
                if(i%j==0) f++;
            }
            if(f==8) count++;
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))




signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n;
	map<string, int>mp;
	vector<string>s(n); 
	rep(i, n) {
		cin >> s[i];
		mp[s[i]]++;
	}
	cin >> m;
	vector<string>t(m); 
	rep(i, m) {
		cin >> t[i];
		mp[t[i]]--;
	}
	int ans = 0;
	rep(i, n) {
		ans = max(ans, mp[s[i]]);
	}
	rep(i, m) {
		ans = max(ans, mp[t[i]]);
	}
	cout << ans << endl;
	return 0;
}

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

LL n;
LL ans = 0, three, five, seven;
string tmp;

void solve(LL a) {
  if (a > n) return;

  three = 0, five = 0, seven = 0;
  tmp = to_string(a);

  for (int i = 0; i < tmp.size(); i ++) {
    if (tmp[i] == '3') three ++;
    else if (tmp[i] == '5') five ++;
    else if (tmp[i] == '7') seven ++;
  }
  if (three && five && seven) ans ++;

  solve(a*10 + 3);
  solve(a*10 + 5);
  solve(a*10 + 7);
}

int main() {
  cin >> n;

  solve(0);

  cout << ans << endl;
}


Measured memory_bytes: 256
s = gets.chomp.split("").map &:ord
t = gets.chomp.split("").map &:ord

def convert(str)
	w = []
	result = []
	count = 0
	str.each{ |x|
		if w[x] == nil then
			w[x] = count.to_s
			count += 1
		end
		result << w[x]
	}
	result
end

if convert(s) == convert(t) then
	puts "Yes"
else
	puts "No"
end


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int D, K;

void s() {
   int ans = 100, cnt = 0;
   for (int i = 1; ; i++) {
      if (i % ans != 0) {
         cnt++;
      }
      if (cnt >= K) {
         cout << i << endl;
         break;
      }
   }
}

void f() {
   int ans = 100, cnt = 0;
   for (int i = 1; ; i++) {
      if (i%ans == 0 && (i/ans)%ans != 0) {
         cnt++;
      }
      if (cnt >= K) {
         cout << i << endl;
         break;
      }
   }
}

void t() {
   int ans = 100, cnt = 0;
   for (int i = 1; ; i++) {
      if (i%ans == 0 && (i/ans)%ans == 0 && (i/ans/ans)%ans != 0) {
         cnt++;
      }
      if (cnt >= K) {
         cout << i << endl;
         break;
      }
   }
}

int main() {
   cin >> D >> K;

   if (D == 0) {
      s();
   } else if (D == 1) {
      f();
   } else {
      t();
   }

   return 0;
}

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

int main(){
	int n, i;
	int a[100];
	
	cin >> n;
	
	for(i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for(i = n - 1; i >= 0; i--){
		if(i != n - 1){
			cout << " ";
		}
		cout << a[i];
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n,m;
  cin >> n >> m;
  cout << n*(n-1)/2+m*(m-1)/2 << endl;
return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N,S,t;
  cin >> N;
  t=N;
  while(t>0){
    S+=t%10;
    t/=10;
  }
  if(N%S==0){
    cout<< "Yes" << endl;
  }
  else{
    cout<< "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
//const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L //setprecision(15)

int div(int n) {
	int res = 0;
	while ( 1 ) {
		if (n % 2 == 0) {
			res++; n /= 2;
		} else {
			break;
		}
	}
	return res;
}


int main() {
	int N; cin >> N;
	int n0 = 0, n1 = 0, n2 = 0;
	rep(i, N) {
		int tmp; cin >> tmp;
		int ma = div(tmp);
		if (ma == 0) n0++;
		else if (ma == 1) n1++;
		else n2++;
	}
	if ( N % 2 == 0 ) {
		if ( N / 2 < n0 ) cout << "No" << endl;
		else if ( n0 > n2 ) cout << "No" << endl;
		else cout << "Yes" << endl;
	} else {
		if (N/2 + 1 < n0) cout << "No" << endl;
		else if ( n0 > n2 + 1 ) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
}

Measured memory_bytes: 3532
# A - Colorful Transceivers

a, b, c, d = map(int, input().split())

if abs(c - a) <= d:
    print('Yes')
elif abs(c - a) > d and abs(c - b) <= d and abs(b - a) <= d:
    print('Yes')
elif abs(c - a) > d and abs(c - b) > d:
    print('No')
elif abs(c - a) > d and abs(c - b) <= d and abs(b - a) > d:
    print('No')

Measured memory_bytes: 9196
#include<stdio.h>
#include<algorithm>
using namespace std;
int p[300000];
int min(int a,int b){return a<b?a:b;}
int main(){
	int d,n,m;
	int i,j;
	while(1){
	scanf("%d %d %d",&d,&n,&m);
	if(d==0)return 0;
	p[0]=0;p[1]=d;p[2]=d*2;
	for(i=1;i<n;i++){
		scanf("%d",&p[i*3]);
		p[i*3+1]=p[i*3]+d;
		p[i*3+2]=p[i*3]+d*2;
	}
	sort(p,p+n*3);
	int ans=0;
	for(i=0;i<m;i++){
		int q;
		scanf("%d",&q);
		q+=d;
		int r=lower_bound(p,p+n*3,q)-p;
		int l=r-1;
		ans+=min(q-p[l],p[r]-q);
	}
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 2216
import java.util.HashMap;
import java.util.Scanner;

public class Main {


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

		for (int i = 0; i < S.length(); i++) {
			cube[i] = S.substring(i, i+1);
		}

		HashMap<String, Integer> map = new HashMap<>();
		for (int i = 0; i < S.length(); i++) {
			if (!map.containsKey(cube[i])) {
				map.put(cube[i], 1);
			} else {
				int cnt = map.get(cube[i]);
				map.put(cube[i], cnt+1);
			}
		}

		if (!map.containsKey("0") || !map.containsKey("1")) {
			System.out.println(0);
			return;
		}

		int cnt0 = map.get("0");
		int cnt1 = map.get("1");

		System.out.println(Math.min(cnt0, cnt1)*2);
 	}
}


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

int n,dp[100010][2];
vector<int> v[100010];

void dfs(int u,int pr)
{
	dp[u][0]=1;dp[u][1]=1;
	for(int i=0;i<v[u].size();i++) if(v[u][i]!=pr){
		dfs(v[u][i],u);
		dp[u][0]*=(dp[v[u][i]][0]+dp[v[u][i]][1]);
		if(dp[u][0]>=MOD) dp[u][0]%=MOD;
		dp[u][1]*=(dp[v[u][i]][0]);
		if(dp[u][1]>=MOD) dp[u][1]%=MOD;
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1,-1);
	cout<<(dp[1][0]+dp[1][1])%MOD<<endl; 
	return 0;
}

Measured memory_bytes: 14208
N = int(input())
# A = list(map(int,input().split()))
A = [-1] + list(map(int,input().split()))
B = [0] * (N+1)
for i in range(N, 0, -1):
  tmp = 0
  for j in range(2*i, N+1, i):
    tmp += B[j]
  if tmp%2 != A[i]:
    B[i] = 1

print(B.count(1))
if B.count(1) > 0:
  print(" ".join(map(str, [ i for i,b in enumerate(B) if b==1 ])))

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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

void solve(long long N, std::vector<long long> a) {
    auto ans = 0;
    rep(i, N) {
        while (a[i] % 2 == 0) {
            a[i] /= 2;
            ans++;
        }
    }
    cout << ans << 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: 3776
//written by newbiechd
#include <cstdio>
using namespace std;
const int N = 1000007, yyb = 1e9+ 7;
long long f[N], s;
int main() {
    register int n, i;
    scanf("%d", &n);
    f[n] = n, f[n - 1] = 1ll * n * n % yyb;
    for (i = n - 2; i > 0; --i)
        s = (s + f[i + 3]) % yyb,
            f[i] = (f[i + 1] + s + 1ll * (n - 1) *(n - 1) + i + 1) % yyb;
    printf("%lld", f[1]);
    return 0;
}


Measured memory_bytes: 7936
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
int n, k, h[123456], dp[123456];
signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> h[i];
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		dp[i] = dp[i - 1] + 10000000000;
		for (int j = max((int)0, i - k); j < i; j++) {
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
		}
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1920
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

char s[10];
int main() {
	scanf("%s", s);
	int upp = (s[0] - '0') * 10 + (s[1] - '0');
	int low = (s[2] - '0') * 10 + (s[3] - '0');
	if (upp == 0 || 12 < upp) {//yy
		if (low == 0 || 12 < low)//yy
			printf("NA\n");
		else//yy/mm
			printf("YYMM\n");
	}
	else {//yy/mm
		if (low == 0 || 12 < low)//yy
			printf("MMYY\n");
		else//yy/mm
			printf("AMBIGUOUS\n");
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007

using namespace std;

void input() {
	int n;
	cin>>n;
	
	int ans=0;
	
	for(int i=1;i<=(n);i++) {
		ans += (n-1)/i;
	}
	
	cout<<ans;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	input();

	return 0;
}



Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int sum[4][2010][2010];
string S[2010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    int ans = 0;
    rep(i, H) cin >> S[i];
    rep(i, H) {
        rep(j, W) {
            rep(k, 4) {
                if (S[i][j] == '.') sum[k][i + 1][j + 1]++;
            }
        }
    }
    rep(i, H) {
        rep(j, W) {
            sum[0][i + 1][j + 1] += sum[0][i + 1][j];
            if (S[i][j] == '#') sum[0][i + 1][j + 1] = 0;
        }
    }
    rep(i, H) {
        RREP(j, W - 1, 0) {
            sum[1][i + 1][j + 1] += sum[1][i + 1][j + 2];
            if (S[i][j] == '#') sum[1][i + 1][j + 1] = 0;
        }
    }
    rep(j, W) {
        RREP(i, H - 1, 0) {
            sum[2][i + 1][j + 1] += sum[2][i + 2][j + 1];
            if (S[i][j] == '#') sum[2][i + 1][j + 1] = 0;
        }
    }
    rep(j, W) {
        rep(i, H) {
            sum[3][i + 1][j + 1] += sum[3][i][j + 1];
            if (S[i][j] == '#') sum[3][i + 1][j + 1] = 0;
        }
    }
    rep(i, H) {
        rep(j, W) {
            int tmp = 0;
            rep(k, 4) tmp += sum[k][i + 1][j + 1];
            ans = max(ans, tmp - 3);
            //cout << tmp << " ";
        }
        //cout << endl;
    }
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 67584
while True:
    combination_count = 0
    answer_set = set()
    item, target = map(int, input().split())
    
    if item == 0 and target == 0:
        break
    
    for i in range(1, item+1):
        for j in range(i+1, item+1):
            for k in range(j+1, item+1):
                if i + j + k == target and (i, j, k) not in answer_set:
                    combination_count += 1
                    answer_set.add((i, j, k))
    print(combination_count)    


Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int d,g,i;
    cin>>d>>g;
    int p[d],c[d];
    for (i=0;i<d;i++)
        cin>>p[i]>>c[i];
    int ans=INT_MAX,mask;
    for (mask=0;mask<(1<<d);mask++)
    {
        int s=0,cnt=0,left=-1;
        for (i=0;i<d;i++)
        {
            if ((mask>>i)&1)
            {
                s+=p[i]*100*(i+1)+c[i];
                cnt+=p[i];
            }
            else
                left=i;
        }
        if (s<g)
        {
            int rem=g-s;
            if (rem<(left+1)*100*p[left])
            {
                int extra;
                if (rem%((left+1)*100)==0)
                    extra=rem/((left+1)*100);
                else
                    extra=rem/((left+1)*100)+1;
                if (extra<p[left])
                    cnt+=extra;
                else
                    continue;
            }
            else
                continue;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

template<typename T> bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

template<typename T> bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}

using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    
    vvvll F(N,vvll(5,vll(2)));
    for(ll i=0;i<N;i++)for(ll j=0;j<5;j++)cin>>F[i][j][0]>>F[i][j][1];
    vvll P(N,vll(11));
    for(ll i=0;i<N;i++)for(ll j=0;j<11;j++)cin>>P[i][j];
    ll ans=-LLMAX;
    for(ll i=1;i<pow(2,10);i++){
        bool J[5][2];
        ll ii=i;
        for(ll k=0;k<5;k++){
            for(ll j=0;j<2;j++){
                if(ii%2==0) J[k][j]=false;
                else J[k][j]=true;
                ii/=2;
            }
        }
        
        vll count(N,0);
        for(ll j=0;j<N;j++){
            for(ll k=0;k<5;k++){
                for(ll l=0;l<2;l++){
                    if(F[j][k][l]==1 && J[k][l]==1){
                        //printf("cccccount[%d]=%d\n",j,count[j]);
                        count[j]++;
                    }
                }
            }
        }
        
        ll sum=0;
        for(ll j=0;j<N;j++){
            sum+=P[j][count[j]];
           // printf("count[%d]=%d\n",j,count[j]);
            //p//rintf("P[%d][%d]=%d\n",j,count[j],P[j][count[j]]);
        }
        //printf("sum=%d\n",sum);
        chmax(ans,sum);
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int maxn = 1e5 + 7;
int n, k;
int tree[maxn];

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> tree[i];
	}
	sort(tree, tree + n);
	int cur = 1e9+1;
	for (int i = 0; i <= n - k; i++) {
		if (tree[i+k-1] - tree[i] < cur)
			cur = tree[i+k-1] - tree[i];
	}
	cout << cur << endl;
}

Measured memory_bytes: 640
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   
    int n = Integer.parseInt(br.readLine());
    
    int[] a = new int[n];
    int[] b = new int[n];
    String[] data = br.readLine().split(" ");
    int temp;
    for (int i=0; i<n; i++){
      temp = Integer.parseInt(data[i])-1;
      a[temp]++;
      b[i] = temp;
    }
    long sum = 0;
    for (int i=0; i<n; i++){
      sum += ((long) a[i]*((long) a[i]-1))/2;
    }
    long result;
    for (int i=0; i<n; i++){
      result = sum - ((long) a[b[i]]*((long) a[b[i]]-1))/2 + ((long) (a[b[i]]-1)*((long) a[b[i]]-2))/2;
      System.out.println(result);
    }
  }
}


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

using namespace std;

typedef long long ll;

int M[1000005];

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	string s;
	cin >> n >> s;
	int q;
	cin >> q;
	while(q--){
		int k;
		cin >> k;
		int d = 0, m = 0;
		ll dm = 0, dmc = 0;
		for(int i = 0; i < k; i++){
			if(s[i] == 'D') d++;
			else if(s[i] == 'M'){
				m++;
				dm += d;
			}
			else if(s[i] == 'C'){
				dmc += dm;
			}
			M[i] = m;
		}
		for(int i = k; i < n; i++){
			if(s[i - k] == 'D'){
				d--;
				dm -= M[i - 1];
			}
			else if(s[i - k] == 'M'){
				m--;
			} 
			if(s[i] == 'D') d++;
			else if(s[i] == 'M'){
				m++;
				dm += d;
			}
			else if(s[i] == 'C') dmc += dm;
			M[i] = m;
		}
		cout << dmc << endl;
	}
}

Measured memory_bytes: 5276
def solve(x, y, a, b, c, p, q, r):
    p = sorted(p)[::-1]
    q = sorted(q)[::-1]
    r = sorted(r)[::-1]
    v = sorted(p[:x] + q[:y])
    n = len(v)
    t = sum(v)
    for i in range(min(n,c)):
        if v[i] < r[i]:
            t += r[i] - v[i]
    return t

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
print(solve(x, y, a, b, c, p, q, r))

Measured memory_bytes: 23328
S = input()
ans = 0

big = [0]*(len(S)+1)
for i in range(len(S)):
  if S[i] == "<":
    big[i+1] = big[i] +1
  else:
    big[i+1] = 0
  
small = [0]*(len(S)+1)
for i in range(len(S)-1, -1, -1):
  if S[i] == ">":
    small[i] = small[i+1] + 1
  else:
    small[i] = 0
    
for b, s in zip(big, small):
  ans += max(b, s)

print(ans)

Measured memory_bytes: 27300
def main():
    n = int(input())
    times = list(map(int, input().split(' ')))
    n = int(input())
    drinks = [list(map(int, input().split(' '))) for _ in range(n)]
    all_time = sum(times)
    for drink in drinks:
        print(all_time - (times[drink[0]-1] - drink[1]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 62892
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string.h>
#include<algorithm>
int a[1000000];
int main() {

	int s, tmp,br = 0;
	

	scanf("%d", &s);
	a[0] = s;

	for (int i = 1; i < 1000000; i++) {
		if(a[i - 1] % 2 == 0) a[i] = a[i - 1] / 2;
		else if (a[i - 1] % 2 == 1)a[i] = a[i - 1] * 3 + 1;
		
		for (int j = 0; j < i; j++) {
			if (a[j] == a[i]) {
				tmp = i + 1;
				br = 1;
				break;
			}
		}
		if (br == 1)break;
	}
	
	printf("%d\n", tmp);


	return(0);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();

		if(a%2 == 1 && b%2 == 1) {
			System.out.println("Odd");
		}
		else {
			System.out.println("Even");
		}
	}
}

Measured memory_bytes: 21712
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

vector<int> ta;
int r[1009];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 2; i <= n; i++) {
		int ti = i;
		for (int j = 2; j <= ti; j++) 
			if (ti % j == 0) {
				ti /= j; ta.push_back(j);
				j = 1;
			}
	}
	sort(ta.begin(), ta.end());
	int c = 1, r2 = 0, r4 = 0;
	for (int i = 1; i < ta.size(); i++) {
		if (ta[i] == ta[i - 1])
			c++;
		else {
			for (int j = 0; j <= c; j++)
				r[j]++;
			c = 1;
		}
	}
	for (int j = 0; j <= c; j++)
		r[j]++;
	cout << r[4] * (r[4] - 1) / 2 * (r[2] - r[4]) + r[4] * (r[4] - 1) * (r[4] - 2) / 2 + r[14] * (r[4] - r[14]) + r[14] * (r[14] - 1) + r[24] * (r[2] - r[24]) + r[24] * (r[24] - 1) + r[74] << '\n';
	return 0;
}

Measured memory_bytes: 256
class Array
  def diff; (size-1).times.map { |i| self[i + 1] - self[i] }.to_a end
end
INF = 0xffffffffffffffff
# mod = 998244353
# mod = 10 ** 9 + 9
mod = 10 ** 9 + 7
PI = Math::PI
dx = [ 1,  0, -1,  0,  1,  1, -1, -1]
dy = [ 0,  1,  0, -1,  1, -1,  1, -1]
eight = [0, 1, 1, 0, -1, -1, 1, -1, 0]
def max(a,b);       a > b ? a : b                              end
def min(a,b);       a < b ?  a : b                             end
def swap(a,b);      a, b = b, a                                end
def gi;             gets.to_s.to_i                             end
def gf;             gets.to_s.to_f                             end
def gs;             gets.to_s.chomp                            end
def gmi(n=nil); n.nil? ? gets.to_s.split.map{|t|t.to_i} : n.times.map{ gets.to_s.to_i } end
def gmf(n=nil); n.nil? ? gets.to_s.split.map{|t|t.to_f} : n.times.map{ gets.to_s.to_f } end
def gms(n=nil); n.nil? ? gets.to_s.split : n.times.map{ gets.to_s.chomp } end
def ga2i(h);        h.times.map{ gets.to_s.split.map{|t|t.to_i} }      end
def gm(h);        Array.new(h){ gets.to_s.split.map{|t|t.to_i} }      end
def yn(f); puts f ? "Yes" : "No" end
#def YN(f); puts f ? "YES" : "NO" end
def yes(f=nil); f.nil? ? (puts "Yes"; exit) : (puts f ? "Yes" : "No") end
def no(f=nil); f.nil? ? (puts "No"; exit) : (puts f ? "Yes" : "No") end
def yay(f=nil); f.nil? ? (puts "Yay!"; exit) : (puts f ? "Yay!" : ":(") end

def an(n,d=0) Array.new(n,d)end
def an2(n,m,d=0) Array.new(n){an(m,d)}end
def an3(n,m,l,d=0) Array.new(n){an2(m,l,d)}end
def zeros(n); an2(n,n) end
def eye(n); an2(n,n).each_with_index{|e,i|e[i]=1} end # 単位行列 identity matrix
# n = gets.to_s.to_i
# a = gets.to_s.split.map{|t|t.to_i}
# s = gets.to_s.chomp
# m = Array.new(n){ gets.split.map{|t|t.to_i} }

# n = gets.to_s.to_i
s = gets.to_s.chomp
# a = gets.to_s.split.map{|i|i.to_i}

yn s.include?("7")

# puts ans






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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    string s;
    cin >> s;
    int diff = 9999;
    REP(i, s.size()-2) {
        string subs = s.substr(i, 3);
        int v = abs(stoi(subs) - 753);
        diff = min(diff, v);
    }
    cout << diff << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int h,n;
    scanf(" %d %d",&h,&n);
    int su = 0;
    for(int i = 0; i < n;++i){
        int te;scanf(" %d",&te);
        su += te;
    }
    if(su >= h)puts("Yes");
    else puts("No");
    return 0;
}


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

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

    vector<int> g1 { 1, 3, 5, 7, 8, 10, 12 };
    vector<int> g2 { 4, 6, 9, 11 };

    for (int i = 0; i < g1.size(); i++)
    {
        for (int j = 0; j < g1.size(); j++)
        {
            if (x == g1[i] && y == g1[j])
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    for (int i = 0; i < g2.size(); i++)
    {
        for (int j = 0; j < g2.size(); j++)
        {
            if (x == g2[i] && y == g2[j])
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256