akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main () {
	int a,b,c;
	while ((a!=0)||(b!=0)) {
		cin >> a >> b;
		if ((a!=0)||(b!=0))
			if (a<b) {
				cout<< a << " " << b << endl;
			} else cout<< b << " " << a << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3080
import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int a1 = sc.nextInt();
        int a2 = sc.nextInt();
        int a3 = sc.nextInt();

        if (a1 + a2 + a3 >= 22) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
	}
}


Measured memory_bytes: 21204
n = int(input())
blues = []
for i in range(n):
  blues.append(input())
m = int(input())
reds = []
for j in range(m):
  reds.append(input())
pairs = {}
count = 0
count_b = 0
count_r = 0
setted_blues = set(blues)
setted_reds = set(reds)
for k in setted_blues:
  count_b = blues.count(k)
  pairs[k] = count_b
for l in setted_reds:
  count_r = reds.count(l)
  for m,n in pairs.items():
    if m == l:
      count = n - count_r
      pairs[m] = count
sorted_pairs = sorted(pairs.items(),key = lambda x:x[1],reverse = True)
answer = sorted_pairs[0][1]
if answer < 0:
  answer = 0
print(answer)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<complex>
#include<bitset>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

signed main() {
    int N;
    cin >> N;
    int ans = 0;
    int prev = 0;
    rep(i, N) {
        int a;
        cin >> a;
        if (prev && a) {
            ans++;
            a--;
        }
        ans += a / 2;
        a -= 2 * (a / 2);
        prev = a;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(),K = sc.nextInt();
		int ans = 0;
		for(int i = 0; i< N; i++) {
			int b = sc.nextInt();
			int min = Math.min(K-b, b);
			ans += min*2;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#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];
}

int dp[3][100010];

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

    vector<int> a(N), b(N), c(N);
    rep(i, N) cin >> a[i] >> b[i] >> c[i];

    rep(i, N) {
        rep(j, 3) {
            rep(k, 3) {
                if (j == k) continue;
                int val = k == 0 ? a[i] : k == 1 ? b[i] : c[i];
                dp[j][i + 1] = max(dp[j][i + 1], dp[k][i] + val);
            }
        }
    }

    cout << max({dp[0][N], dp[1][N], dp[2][N]}) << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e20);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a>b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a<b ? : a = b; }



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

    vint wei(N + 1);
    vint val(N + 1);

    rep(i, N) {
        int w, v;
        cin >> w >> v;
        wei[i + 1] = w;
        val[i + 1] = v;
    }

    v2ll dp(N + 1, vll(100000 + 1, INF));
    dp[0][0] = 0;
    
    REP(i, 1, N + 1) {
        REP(j, 0, 100000 + 1) {
            if (j - val[i] >= 0 && dp[i - 1][j - val[i]] != INF) {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i]] + wei[i]);
            }
            else
                dp[i][j] = dp[i - 1][j];
        }
    }
    ll max_value = 0;
    REP(j, 1, 100000 + 1) {
        if (dp[N][j] <= W)
            max_value = max(max_value, ll(j));
    }
    cout << max_value << endl;

    return 0;
}

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

using namespace std;

typedef long long int64;

using Weight = int64;
using Flow = int64;

struct Edge
{
  int src, dst;
  Weight weight;
  Flow cap;

  Edge() : src(0), dst(0), weight(0) {}

  Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};

using Edges = std::vector< Edge >;
using Graph = std::vector< Edges >;
using Array = std::vector< Weight >;
using Matrix = std::vector< Array >;

void add_edge(Graph &g, int a, int b, Weight w = 1)
{
  g[a].emplace_back(a, b, w);
  g[b].emplace_back(b, a, w);
}

void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

void bellmanFord(const Graph &g, int s)
{
  int n = g.size();
  const Weight inf = std::numeric_limits< Weight >::max() / 8;
  Edges es;
  for(int i = 0; i < n; i++)
    for(auto &e : g[i]) es.emplace_back(e);
  std::vector< Weight > dist(n, -inf);
  dist[s] = 0;
  for(int i = 0; i <= 2 * n; i++) {
    for(auto &e : es) {
      if(dist[e.src] != inf && dist[e.dst] < dist[e.src] + e.weight) {
        if(i > n && e.dst == g.size() - 1) {
          cout << "inf" << endl;
          return;
        }
        dist[e.dst] = dist[e.src] + e.weight;
      }
    }
  }
  cout << dist[g.size() - 1] << endl;
}

int main()
{
  int N, M;
  cin >> N >> M;
  Graph g(N);
  for(int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    add_arc(g, a, b, c);
  }
  bellmanFord(g, 0);

}

Measured memory_bytes: 384
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

static const int NMAX  = 1e5+5;
static const int PHI = 26;

vector<int> occ[PHI];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    cin >> s >> t;
    int n = (int) s.length();
    int m = (int) t.length();

    for(int i =0; s[i]; ++i)
    {
        occ[s[i]-'a'].push_back(i+1);
    }
    
    int cycles = 0, idx = 0;
    for(int i =0; t[i]; ++i)
    {
        if(occ[t[i] -'a'].empty())
        {
            cycles = 0;
            idx = -1;
            break;
        }
        auto it = upper_bound(occ[t[i]-'a'].begin(), occ[t[i]-'a'].end(), idx);
        if(it == occ[t[i] - 'a'].end())
        {
            idx = *occ[t[i]-'a'].begin();
            ++cycles;
        }
        else
        {
            idx = *it;
        }
    }

    cout << 1LL * cycles * n + idx;
    return 0;
}

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

int M, N;
double P[16][16];
double dp[17][1 << 16][16];

int main(void) {
  cin >> M >> N;
  for(int i = 0; i < M; i++) for(int j = 0; j < N; j++) cin >> P[i][j];

  /* 状態:
   *   dp[i][S][j] =
   *     集合Sのねこをすでに使っていて,
   *     敵iとねこjが戦うときに最善の行動をした場合の確率
   * 基底:
   *   dp[N][S][j] = 1
   *   where S in [0, 1 << N), j in [0, M)
   * 遷移:
   *   dp[i][S][j] = dp[i + 1][S][j] * P[j][i] + max(dp[i][S | (1 << k)][k]) * (1 - P[j][i])
   *   where k not in S
   */

  for(int S = 0; S < (1 << M); S++) for(int j = 0; j < M; j++) dp[N % 2][S][j] = 1;

  for(int i = N - 1; i >= 0; i--) {
    for(int S = 0; S < (1 << M); S++) for(int j = 0; j < M; j++) dp[i % 2][S][j] = 0;

    for(int S = (1 << M) - 1; S >= 0; S--) {
      for(int j = 0; j < M; j++) if(S & (1 << j)) {
        double win = dp[(i + 1) % 2][S][j] * P[j][i];

        double lose = 0;
        for(int k = 0; k < M; k++) if(!(S & (1 << k))) {
          lose = max(lose, dp[i % 2][S | (1 << k)][k] * (1 - P[j][i]));
        }

        dp[i % 2][S][j] = max(dp[i % 2][S][j], win + lose);
      }
    }
  }

  double ans = 0;
  for(int i = 0; i < M; i++) ans = max(ans, dp[0][1 << i][i]);
  printf("%.15lf\n", ans);
}


Measured memory_bytes: 19672
from collections import defaultdict
import heapq


def get_first_try(K, ts, ds):
    eats = []
    non_eats = []
    for i in range(len(ts)):
        t = ts[i]
        d = ds[i]
        heapq.heappush(eats, (d, t))
        if len(eats) > K:
            non_eats.append(heapq.heappop(eats))
    return [(t, d) for d,t in eats], [(t, d) for d,t in non_eats]

def count_kinds(eats):
    kinds = defaultdict(int)
    for e in eats:
        kinds[e[0]] += 1
    return kinds

def calc_satisfaction(eats, eat_kinds):
    s = 0
    for e in eats:
        s += e[1]
    return s + calc_bonus(eat_kinds)


def calc_bonus(kinds):
    x = 0
    for k in kinds:
        if kinds[k] > 0:
            x += 1
    return x**2


def solve(N, K, ts, ds):
    eats, non_eats = get_first_try(K, ts, ds)
    eat_kinds = count_kinds(eats)
    satisfaction = calc_satisfaction(eats, eat_kinds)
    sorted_eats = sorted(eats, key=lambda x: x[1])
    sorted_non_eats = sorted(non_eats, key=lambda x: x[1], reverse=True)
    n_kinds = len(eat_kinds)

    max_satisfaction = satisfaction

    i = 0
    j = 0
    while i < len(sorted_eats) and j < len(sorted_non_eats):
        t, d = sorted_eats[i]
        if eat_kinds[t] == 1:
            i += 1
            continue
        t2, d2 = sorted_non_eats[j]
        if eat_kinds[t2] > 0:
            j += 1
            continue
        prev_bonus = n_kinds ** 2
        eat_kinds[t] -= 1
        eat_kinds[t2] += 1
        n_kinds += 1
        current_bonus = n_kinds ** 2
        satisfaction = satisfaction - d + d2 - prev_bonus + current_bonus
        if max_satisfaction < satisfaction:
            max_satisfaction = satisfaction
        i += 1
        j += 1

    return max_satisfaction


N, K = list(map(int, input().split(' ')))

ts = []
ds = []
for i in range(N):
    t, d = list(map(int, input().split(' ')))
    ts.append(t)
    ds.append(d)

print(solve(N, K, ts, ds))

Measured memory_bytes: 28444
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> x(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>x[i];
    sum+=x[i];
  }
  sum/=n;
  int ans=100000000;
  for(int i=-500;i<500;i++){
    int tmp=0;
    for(int j=0;j<n;j++){
      tmp=max(tmp,abs((sum+i)-x[j]));
    }
    ans=min(ans,tmp);
  }
  cout<<ans<<'\n';
  return(0);
}


Measured memory_bytes: 3120
import math

x,y = map(int,input().split())
t=0
if y<=9:
    t=10*x+y
elif y<=99:
    t=100*x+y
else:
    t=1000*x+y
if math.sqrt(t).is_integer():
    print("Yes")
else:
    print("No")
#print(t)

Measured memory_bytes: 3060
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<stdio.h>
#include<math.h>
using namespace std;

#define rep(i,n) for(long long i = 0; i < n; i++)

typedef long long ll;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;

const ll INF = ll(1e18) + 1;
const int intINF = 1e9 * 2 + 3;
//--------------------------------------------------

ulli gcd(ulli a, ulli b) {return (b <= 0) ? a : gcd(b, a % b);}
ulli lcm(ulli a, ulli b) {return a * b / gcd(a, b);}

bool isPrime(int n)
{
	if (n <= 3)return n > 1;
	if (n % 2 == 0)return false;
	if (n % 3 == 0)return false;
	for (int i = 5; i * i < n; i += 6) {
		if (n % i == 0 || n % (i + 2) == 0) { return false; }
	}
	return true;
}
//---------------------------------------------------



void Main()
{
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
}


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

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef long long int Int;
const int L = 8;
const Int MOD = 1000000;

void countXY(Int ys, Int yt, Int xs, Int xt, Int &x, Int &y, string &s){
  if(ys != -1) FOR(i, ys, yt) if(s[i] == 'x') ++y;
  if(xs != -1) FOR(i, xs, xt) if(s[i] == 'x') ++x;
}

Int countPattern(Int x, Int y, string s){
  bool t = 1;
  REP(i, s.length()) if(s[i] == '1') t = 0;
  Int a = 1, b = 1;
  REP(i, x) a = (a * 2 % MOD);
  REP(j, y) b = (b * 2 % MOD);
  if(t) b = (b - 1 + MOD) % MOD;
  return (a % MOD) * (b % MOD) % MOD;
}

bool check(string s){
  bool f = 0;
  REP(i, s.length()){
    if(s[i] == 'x') return 1;
    if(s[i] == '1') f = 1;
  }
  return f;
}

bool check_pref(string &s, string tar){
  REP(i, tar.length()) if(s[i] != 'x' && s[i] != tar[i]) return 0;
  return 1;
}

int main() {
  Int N;
  while(cin >>N && N){
    vector<string> v(N);
    REP(i, N) cin >>v[i];
    vector<Int> dp(N + 1, 0);
    dp[0] = 1;
    REP(i, N){
      if(check_pref(v[i], "0")){
        Int x = 0, y = 0;
        countXY(-1, -1, 1, L, x, y, v[i]);
        dp[i + 1] = ((dp[i] * countPattern(x, y, "1") % MOD) + dp[i + 1]) % MOD;
      }
      if(i + 1 < N && check_pref(v[i], "110") && check_pref(v[i + 1], "10") && check(v[i].substr(3, 4))){
        Int x = 0, y = 0;
        countXY(3, L - 1, L - 1, L, x, y, v[i]);
        countXY(-1, -1, 2, L, x, y, v[i + 1]);
        dp[i + 2] = ((dp[i] * countPattern(x, y, v[i].substr(3, 4)) % MOD) + dp[i + 2]) % MOD;
      }
      if(i + 2 < N && check_pref(v[i], "1110") && check_pref(v[i + 1], "10") && check_pref(v[i + 2], "10") && check(v[i].substr(4, 4) + v[i + 1].substr(2, 1))){
        Int x = 0, y = 0;
        countXY(4, L, -1, -1, x, y, v[i]);
        countXY(2, 3, 3, L, x, y, v[i + 1]);
        countXY(-1, -1, 2, L, x, y, v[i + 2]);
        dp[i + 3] = ((dp[i] * countPattern(x, y, v[i].substr(4, 4) + v[i + 1].substr(2, 1)) % MOD) + dp[i + 3]) % MOD;
      }
      if(i + 3 < N && check_pref(v[i], "11110") && check_pref(v[i + 1], "10") && check_pref(v[i + 2], "10") && check_pref(v[i + 3], "10") && check(v[i].substr(5, 3) + v[i + 1].substr(2, 2))){
        Int x = 0, y = 0;
        countXY(5, L, -1, -1, x, y, v[i]);
        countXY(2, 4, 4, L, x, y, v[i + 1]);
        countXY(-1, -1, 2, L, x, y, v[i + 2]);
        countXY(-1, -1, 2, L, x, y, v[i + 3]);
        dp[i + 4] = ((dp[i] * countPattern(x, y, v[i].substr(5, 3) + v[i + 1].substr(2, 2)) % MOD) + dp[i + 4]) % MOD;
      }
    }
    cout <<dp[N] <<endl;
  }
  return 0;
}

Measured memory_bytes: 1276
from sys import stdin

s = stdin.readline().rstrip()
li = [0]*(len(s)+1)
point = 0
for i in range(len(s)):
    if s[i] == "<":
        point += 1
        li[i+1] = point
    else:
        point = 0

li = li[::-1]
s = s[::-1]
ns = ""

for i in s:
    if i == "<":
        ns += ">"
    else:
        ns += "<"

point = 0

for i in range(len(ns)):
    if ns[i] == "<" and li[i+1] <= point:
        point += 1
        li[i+1] = point
    elif i == 0 or ns[i] == "<" and li[i+1] > point:
        point = 0
    else:
        point = 0

print(sum(li))

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

#define MAX 1000000000

long long count =  0;

void merge(int* A, int left, int mid, int right) {
    int L[100001];
    int R[100001];
    int n1 = mid - left;
    int n2 = right - mid;
    
    for(int i = 0; i < n1; ++i) {
        L[i] = A[left + i];
    }
    L[n1] = MAX;
    
    for(int i = 0; i < n2; ++i) {
        R[i] = A[mid + i];
    }
    R[n2] = MAX;
    
    int i = 0;
    int j = 0;
    for(int k = left; k < right; ++k) {
        if(L[i] <= R[j]) {
            A[k] = L[i];
            ++i;
        } else {
            A[k] = R[j];
            ++j;
            count += n1 - i;
        }
    }
}

void mergeSort(int* A, int left, int right) {
    if(left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(void) {
    int n;
    int a[200000];
    int b[200000];

    cin >> n;
    
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = a[i];
    }
    
    mergeSort(b, 0, n);

    cout << count << endl;
    
}


Measured memory_bytes: 5428
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
using namespace std;

int main() {
	int n; cin >> n;
	cout << 24 + (24-n) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map < string, int > ans;
const int dx[] = {1, -1, 4, -4};
void bfs() {
    queue < string > q;
    string ori = "01234567";
    ans.clear();
    ans[ori] = 0;
    q.push(ori);

    while (!q.empty()) {
        string now = q.front();
        q.pop();

        int x;
        for (int i = 0; i < 8; i++) {
            if (now[i] == '0') {
                x = i;
                break;
            }
        }
        for (int i = 0; i < 4; i++) {
            int tx = x + dx[i];
            if (tx < 0 || tx >= 8) continue;
            if (x == 3 && i == 0) continue;
            if (x == 4 && i == 1) continue;

            string tstr = now;
            swap(tstr[tx], tstr[x]);
            if (!ans.count(tstr)) {
                ans[tstr] = ans[now] + 1;
                q.push(tstr);
            }
        }
    }
}
int main() {

    bfs();
    string line;
    while (getline(cin, line)) {
        auto sz = remove(line.begin(), line.end(), ' ');
        line.erase(sz, line.end());
        cout << ans[line] << endl;
    }
    return 0;
}

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

using namespace std;

const int MAXN = 55555;
bool p[MAXN + 5];

void sieve() {
  for (int i = 0; i <= MAXN; ++i) p[i] = true;
  p[0] = false;
  p[1] = false;
  for (int i = 2; i <= MAXN; ++i) {
    if (p[i]) {
      for (int j = i * 2; j <= MAXN; j += i) p[j] = false;
    }
  }
}

int main() {
  int N;
  scanf("%d", &N);

  sieve();
  vector<int> ans;
  int cur = 2;
  while ((int)ans.size() < N) {
    if (cur % 5 == 1 && p[cur]) ans.push_back(cur);
    cur++;
  }
  for (int i = 0; i < N; ++i) {
    if (i == N - 1) cout << ans[i] << endl;
    else cout << ans[i] << " ";
  }
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int mod=1000000007;
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int h,i,j,w;
	cin>>h>>w;
	char p[h][w];
	long long dp[h][w];
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		cin>>p[i][j];
	}
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(i=1;i<w;i++)
	{
		if(p[0][i]=='.')
			dp[0][i]=dp[0][i-1];
	}
	for(i=1;i<h;i++)
	{
		if(p[i][0]=='.')
			dp[i][0]=dp[i-1][0];
	}
	for(i=1;i<h;i++)
	{
		for(j=1;j<w;j++)
		{
			if(p[i][j]=='.')
				dp[i][j]=dp[i-1][j]+dp[i][j-1];
			if(dp[i][j]>=mod)
				dp[i][j]-=mod;
		}
	}
	cout<<dp[h-1][w-1]<<"\n";
	return 0;
}

Measured memory_bytes: 12340
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 200005;
const ll mm = 1e+18;
void solve()
{
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    repp(i,l,r+1){
        if(i%d==0) ans++;
    }
    pr(ans);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nx;
    }
    return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    int x = (int)s.size();
    int y = (int)t.size();
    struct data{
        int from_x, from_y, length;
        char z;
    };
    data ini;
    ini.from_x = 0;
    ini.from_y = 1;
    ini.length = 0;
    ini.z = '0';
    vector<vector<data>> ans(x+1, vector<data>(y+1, ini));
    for (int i = 0; i < x; i++){
        for (int j = 0; j < y; j++){
            if (s[i] == t[j]){
                ans[i+1][j+1].from_x = i;
                ans[i+1][j+1].from_y = j;
                ans[i+1][j+1].length = ans[i][j].length + 1;
                ans[i+1][j+1].z = s[i];
            }
            else {
                if (ans[i+1][j].length >= ans[i][j+1].length) ans[i+1][j+1] = ans[i+1][j];
                else ans[i+1][j+1] = ans[i][j+1];
            }
        }
    }

    string out = "";
    int nx = ans[x][y].from_x;
    int ny = ans[x][y].from_y;
    if (ans[x][y].z != '0') out += ans[x][y].z;
    while (nx != 0 && ny != 0){
        if (ans[nx][ny].z != '0') out += ans[nx][ny].z;
        int tx = ans[nx][ny].from_x;
        int ty = ans[nx][ny].from_y;
        nx = tx;
        ny = ty;
    }
    reverse(out.begin(), out.end());
    cout << out << endl;
}

Measured memory_bytes: 141184
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

ll f(ll x){
    bitset<45> ret(0);
    if(x%4==1 || x%4 == 2) ret.set(0);

    for(ll i=1;i<44;i++){
        ll amari = x%((ll)(1ull<<(i+1)));
        //cout << amari << endl;
        if(amari%2==0 && amari>=(ll)(1ull<<i)){
            ret.set(i);
        }
    }
    return (ll)(ret.to_ullong());
}

int main(){
    ll a,b; cin >> a >> b;
    bitset<45> fa(f(a-1));
    bitset<45> fb(f(b));
    //cout << fa <<" " << fb <<  endl;
    bitset<45> ans = (fa^fb);
    cout << (ll)(ans.to_ullong()) << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String arg[]){
        Scanner scan=new Scanner(System.in);
        int x=scan.nextInt();
        int y=scan.nextInt();
        if(x==2){
            if(y!=2){
                System.out.println("No");
            }
            else if(y==2){ 
                System.out.println("Yes");
            }
        }
        else if(x==4||x==6||x==9||x==11){
            if(y==4||y==6||y==9||y==11){
                System.out.println("Yes");
            }
            else{
                System.out.println("No");
            }
        }
        else if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
            if(y==4||y==6||y==9||y==11||y==2){
                System.out.println("No");
            }
            else{
                System.out.println("Yes");
            }
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin>>N>>M;
    map<ll,ll> mp;
    ll sum = 0;
    mp[0]++;
    REP(i,N){
        ll a;
        cin>>a;
        sum += a;
        mp[sum%M]++;
    }
    ll ans = 0;
    for(auto x:mp){
        ans += x.second*(x.second-1)/2LL;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<double>x(N);
  vector<string>u(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> u.at(i);
  }

  double sum = 0;
  for (int i = 0; i < N; i++) {
    if (u.at(i) == "JPY"){
      sum += x.at(i);
    }
    else {
      sum += x.at(i)*380000.0;
    }
  }
  printf("%.8lf\n", sum);
}
  



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

using i64 = std::int64_t;

#define REP(i, n) for (i64 i = 0; i < (n); ++i)

namespace io {
  constexpr int is = 1 << 17;
  char ib[is], *ip = ib + is, it;
  inline char getc() {
    if (ip == ib + is) { read(STDIN_FILENO, ib, is); ip = ib; }
    return *ip++;
  }
  inline i64 scan() {
    i64 r = 0;
    if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
    else while ((it = *ip++) & 16) r = r * 10 + it - '0';
    return r;
  }
  constexpr int os = 1 << 17;
  char ob[os], *op = ob, ot;
  inline void putc(const char c) {
    *op++ = c;
    if (op == ob + os) { write(STDOUT_FILENO, ob, os); op = ob; }
  }
  /* x shoud be greater than or equal to zero */
  inline void print(i64 x) {
    char d[20];
    int i = 0;
    while (true) {
      d[i] = x % 10 + 48;
      x /= 10;
      ++i;
      if (x <= 0) break;
    }
    while (i--) {
      putc(d[i]);
    }
  }
  inline void flush() {
    write(STDOUT_FILENO, ob, op - ob);
  }
}

using P = pair<i64, i64>;

i64 collect(const vector<vector<P>> &G, i64 u, i64 v, i64 p) {
  if (u == v) return 0;
  for (auto e : G[u]) {
    if (e.first == p) continue;
    i64 s = collect(G, e.first, v, u);
    if (s != -1) {
      return s | (1LL << e.second);
    }
  }
  return -1;
}

signed main() {
  i64 n = io::scan();
  auto G = vector<vector<P>>(n);
  REP(i, n - 1) {
    i64 a = io::scan() - 1;
    i64 b = io::scan() - 1;
    G[a].emplace_back(b, i);
    G[b].emplace_back(a, i);
  }
  i64 m = io::scan();
  auto paths = vector<i64>(m, 0);
  REP(j, m) {
    i64 u = io::scan() - 1;
    i64 v = io::scan() - 1;
    paths[j] = collect(G, u, v, -1);
  }
  i64 ans = 0;
  REP(s, 1LL << m) {
    i64 mask = 0;
    REP(j, m) {
      if ((s >> j) & 1) {
        mask |= paths[j];
      }
    }
    if (__builtin_parityll(s)) {
      ans -= 1LL << (n - 1 - __builtin_popcountll(mask));
    } else {
      ans += 1LL << (n - 1 - __builtin_popcountll(mask));
    }
  }
  io::print(ans);
  io::flush();
}


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

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}

int main() {
    int c1 = 0, c2 = 0, c3 = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (x % 2 != 0)
            ++c1;
        else if (x % 4 != 0)
            ++c2;
        else
            ++c3;
    }
    if (c2 == 0) {
        if (c1 > c3 + 1)
            cout << "No\n";
        else
            cout << "Yes\n";
    }
    else {
        if (c1 > c3)
            cout << "No\n";
        else
            cout << "Yes\n";
    }
    return 0;
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  if( a == b ){
    cout << "Draw";
  }
  else if( a < b ){
    if( a == 1 ){
      cout << "Alice";
    }
    else{
      cout << "Bob";
    }
  }
  else{
    if( b == 1 ){
      cout << "Bob";
    }
    else{
      cout << "Alice";
    }
  } 

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
#define input(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,h,w,t,p,q,ans=0;
vl v1,v2;

ll solve(){
    rep(i,n){
        a=min(v2[i],v1[i]);
        v1[i]-=a;
        v2[i]-=a;
        ans+=a;
        b=min(v1[i+1],v2[i]);
        v1[i+1]-=b;
        v2[i]-=b;
        ans+=b;
    }

    return ans;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    input(v1,n+1);
    input(v2,n);
    
    cout<<solve()<<endl;
}

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

int main(){
    int N;
    double answer_gyaku = 0;

    cin >> N;
    for(int i = 0; i < N; i++){
        double A;
        cin >> A;
        answer_gyaku += (1 / A);
    }

    cout << (1 / answer_gyaku) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int N;
	long long A[100];

	scanf("%d", &N);
	for(int i=0;i<N;i++){
		scanf("%lld", &A[i]);
	}

	sort(A,A+N);
	printf("%lld\n", A[N-1]-A[0]);

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        int T = sc.nextInt();
        int S = sc.nextInt();
        if (D <= T*S) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35696
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int a, b, c;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c;
    if (a == b) {
        if (a != c) cout << "Yes\n";
        else cout << "No\n";
    } else if (b == c) {
        if (b != a) cout << "Yes\n";
        else cout << "No\n";
    } else if (c == a) {
        if (b != a) cout << "Yes\n";
        else cout << "No\n";
    } else cout << "No\n";
    return 0;
}


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

bool binarySearch(int A[], int n, int key) {
    int left = 0;
    int right = n;

    while (left < right) {
        int middle = (left + right) / 2;
        if (A[middle] == key) {
            return true;
        }
        if (A[middle] > key) {
            right = middle;
        } else {
            left = middle + 1;
        }
    }
    return false;
}

int main() {
    int N;
    cin >> N;
    int S[N];
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }
    int Q;
    cin >> Q;
    int found = 0;
    for (int i = 0; i < Q; i++) {
        int k;
        cin >> k;
        if (binarySearch(S, N, k)) {
            found++;
        }
    }
    cout << found << endl;

    return 0;
}

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

#define ED return 0;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) long(pow(x,y))
const long long int mod = 1000000007;
unsigned long long int gcd(unsigned long long int a, unsigned long long int b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B;
    cin >> A >> B;
    if(A % 2 == 1 && B % 2 == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

#define NIL 500003;

int n, heap[500000];
void maxheapify(int *, int);
int left(int *, int);
int right(int *, int);
void buildmaxheap(int *);

main() {
  int i;
  
  scanf("%d", &n);
  
  for(i = 1; i < n + 1; i++) {
    scanf("%d", &heap[i]);
  }
  
  buildmaxheap(heap);
  
  for(i = 1; i < n + 1; i++) {
    printf(" %d", heap[i]);
  }
  printf("\n");
  return 0;
}

void maxheapify(int *a, int i) {
  int largest, l, r, tmp;
  l = left(a, i);
  r = right(a, i);
  if(l <= n && a[l] > a[i]) {
    largest = l;
  }
  else {
    largest = i;
  }
  if(r <= n && a[r] > a[largest]) {
    largest = r;
  }
  if(largest != i) {
    tmp = a[i];
    a[i] = a[largest];
    a[largest] = tmp;
    maxheapify(a, largest);
  }
}

int left(int *a, int i) {
  if(n < 2 * i) {
    return NIL;
  }
  else {
    return 2 * i;
  }
}
int right(int *a, int i) {
  if(n < (2 * i + 1)) {
    return NIL;
  }
  else {
    return 2 * i + 1;
  }
}

void buildmaxheap(int *a) {
  int i;
  for(i = (n / 2); i >= 1; i--) {
    maxheapify(a, i);
  }
}

Measured memory_bytes: 2552
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int a[310][310];
int used[310];
int cnt[310];
int n,m; 
int check(int x)
{
	for(int i=1;i<=n;i++)
		a[i][0]=1;
	memset(used,0,sizeof(used));
	memset(cnt,0,sizeof(cnt));
	int now;
	int num;
	while(1)
	{
		num=-1;
		for(int i=1;i<=n;i++)
		{
			now=a[i][0];
			cnt[a[i][now]]++;
			if(cnt[a[i][now]]>x)
				num=a[i][now];
		}
		if(num==-1)
			return -1;
		used[num]=1;
		for(int i=1;i<=n;i++)
		{
			while(a[i][0]<=m&&used[a[i][a[i][0]]])
				a[i][0]++;
			if(a[i][0]>m)
				return 0;
	    }
	    memset(cnt,0,sizeof(cnt));
	}
}
int main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
			{
				scanf("%d",&a[i][j]);
			}
		int l=0;
		int r=n;
		int ans;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(check(mid))
			{
				ans=mid;
				r=mid-1;
			}
			else
				l=mid+1;
		}
		printf("%d\n",ans);
	}
} 

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);
		
		while(true)
		{
			String str = stdIn.next();
			
			if(str.charAt(0) == '0')
			{
				break;
			}
			
			int ans = 0;
			
			for(int i=0;i<str.length();i++)
			{
				ans += (int)str.charAt(i)-48;
			}
			
			System.out.println(ans);
			
		}
	}
}

Measured memory_bytes: 17384
#include<iostream>
using namespace std;
main()
{
	string S,T,U;
	int A,B;
	cin>>S>>T>>A>>B>>U;
	if(S==U)
	{
		A--;
	}
	else if(U==T)
	{
		B--;
	}
	cout<<A<<" "<<B<<endl;
}


Measured memory_bytes: 3604
import java.util.*;

public class Main{  
    public static void main(String[] args){

        Scanner sc1 =new Scanner(System.in);
        int N=sc1.nextInt();
        int K=sc1.nextInt();

        if(N%K==0){
            System.out.println(0);
        }else{
            System.out.println(1);
        }
        
    }
}

Measured memory_bytes: 21972
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
int main(void){
  ll x,y;
  cin>>x>>y;
  if((ll)abs(x-y)<=1){
  	cout<<"Brown";
  }else{
    cout<<"Alice";
  }
  return 0;
}

Measured memory_bytes: 256
using System;


namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            double a = double.Parse(input[0]);
            double b = double.Parse(input[1]);
            double c = double.Parse(input[2]);
            double S = 0.5 * a * b *Math.Sin(c * (Math.PI/180));
            double d = Math.Sqrt( Math.Pow(a,2) +  Math.Pow(b,2) - 2 * a * b * Math.Cos(c * (Math.PI / 180)));
            double L = a + b + d;
            double h = b * Math.Sin(c * (Math.PI / 180));
            Console.WriteLine("{0:f8} ", S );
            Console.WriteLine("{0:f8}" , L );
            Console.WriteLine("{0:f8}", h);
        }
    }
}

Measured memory_bytes: 9436
N=int(input())
A=0
B=0
ans=0
AB=0
for i in range(N):
    S=input()
    ans+=S.count("AB")
    if S[0]=="B" and S[-1]=="A":
        AB+=1
    elif S[0]=="B":
        B+=1
    elif S[-1]=="A":
        A+=1
C=min(A,B)
if A==0 and B==0:
    print(ans+max(0,AB-1))
elif C==0:
    print(ans+AB)
else:
    print(ans+AB+min(A,B))

Measured memory_bytes: 3064
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int ll
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vi v(n);
	ll sum = 0;
	vi p(n+1,0);
	rep(i,n){
		cin>>v[i];
		p[v[i]]++;
	}
	vi cnt(n+1,0);
	rep(i,n+1){
		cnt[p[i]]++;
	}
	cnt[0] = 0;
	vi pre(n+1,0),pre1(n+1,0);
	repa(i,1,n+1){
		pre[i] = pre[i-1]+cnt[i];
		pre1[i] = pre1[i-1] + i*cnt[i];
	}
	vi f(n,0);
	repa(i,1,n+1){
		f[i-1] = pre1[i];
		f[i-1] += i*(pre[n] - pre[i]);
		f[i-1] /= i;
	}
	repa(i,1,n+1){
		int l = 0;
		int r = n-1;
		int ans = 0;
		while(l <= r){
			int mid = (l+r)/2;
			if(f[mid] >= i){
				ans = mid+1;
				l = mid+1;
			}
			else{
				r = mid-1;
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}

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

int main()
{
	int K, N, m=0, s=0;
	cin >> K >> N;
	vector<int> A(N);
	vector<int> D(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 1; i < N; i++) {
		D[i - 1] = A[i] - A[i - 1];
	}
	D[N - 1] += K - A[N - 1] + A[0];
	for (int i = 0; i < N; i++) {
		if (D[i] > m) m = D[i];
		s += D[i];
	}
	cout << s - m << endl;
	return 0;
	
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int n,m,k;
  cin >> n >> m >> k;

  REP(i,n+1)REP(j,m+1){
    if(m*i + n*j - 2*i*j == k){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}



Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<random>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<unordered_map>
#include<time.h>
#define int long long
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace std;
int n, a[51], dp[51][50001], p;
int solve(int i, int sum) {
	if (i == n) {
		if (sum % 2 == p)
			return 1;
		return 0;
	}
	if (dp[i][sum] != -1)
		return dp[i][sum];
	int ans = 0;
	ans+=solve(i + 1, sum + a[i]);
	ans += solve(i + 1, sum);
	return dp[i][sum] = ans;
}
signed main() {
	cin >> n >> p;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i <= n ; i++) {
		for (int j = 0; j < 5000; j++) {
			dp[i][j] = -1;
		}
	}
	cout << solve(0, 0) << endl;
}

Measured memory_bytes: 17024
let () =
  let open Int64 in
  let len, b = Scanf.scanf "%d %Ld\n" (fun a b -> a, b) in

  let arr = Array.make len (0L,0L) in
  for i = 0 to (len-1) do
    let c = Scanf.scanf "%Ld %Ld\n" (fun a b -> a, b) in
    Array.set arr i c
  done;

  let arr_l = Array.make len (0L,0L) in
  let arr_r = Array.make len (0L,0L) in
  let arr_l2 = Array.make len (0L,0L) in
  let arr_r2 = Array.make len (0L,0L) in

  let t = ref (0L,0L) in
  for i = 0 to (len-1) do
    let distance = fst (Array.get arr i) in

    let cal = Int64.add (snd (Array.get arr i)) 
        ( if (i=0) then 0L else (snd (Array.get arr_l (i-1)))) in

    let d_sub = if (i=0) then 0L else (fst (Array.get arr_l (i-1))) in
    let d_sub = Int64.sub distance d_sub in
    let cal = Int64.sub cal d_sub in

    let tt = (distance, cal) in
    if (cal > (snd !t))
    then (
      t := tt
    )
    else ();
    Array.set arr_l i tt;
    Array.set arr_l2 i !t;
  done;

  let u = ref (0L,0L) in
  for i = 0 to (len-1) do
    let i = len-1-i in
    let distance = Int64.sub b (fst (Array.get arr i)) in
    let cal = Int64.add (snd (Array.get arr i))
        (if (i=len-1) then 0L else (snd (Array.get arr_r (i+1))) ) in

    let d_sub = if (i=len-1) then 0L else (fst (Array.get arr_r (i+1))) in
    let d_sub = Int64.sub distance d_sub in
    let cal = Int64.sub cal d_sub in

    let tt = (distance, cal) in
    if (cal > (snd !u))
    then (
      u := tt
    )
    else ();
    Array.set arr_r i tt;
    Array.set arr_r2 i !u;
  done;

  let v = ref (0L,0L) in
  for i = 0 to (len-1) do
    let j = if (i=len-1) then 0 else i+1 in

    let d_l = fst (Array.get arr_l2 i) in
    let d_r = 
      if (j = 0) then
        0L
      else
        fst (Array.get arr_r2 j) in
    let d_sub = if d_l > d_r then d_r else d_l in

    let cal_l = snd (Array.get arr_l2 i) in
    let cal_r = 
      if (j = 0) then
        0L
      else
        snd (Array.get arr_r2 j) in
    let cal = Int64.sub (Int64.add cal_l cal_r) d_sub in

    if (cal > (snd !v))
    then (
      let tt = (0L, cal) in
      v := tt
    )
    else ();
  done;
 
  let res = max (max (snd !t) (snd !u)) (snd !v) in
  Printf.printf "%Ld" res;

Measured memory_bytes: 27776
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#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>
#include<stdio.h>
#include<cstring>
//namespace
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 all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*考えを書くスペース


*/

//main.cpp----------------------------
#define MAX 100000

int a, b, c;

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

  if(a==b && b==c) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 764