akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 2000000
#define AMAX 10000

void CountingSort(int *, int *, int, int);

int main(){
  int a[N];
  int n;
  int i;

  scanf("%d", &n);
  for(i=1;i<=n;i++){
    scanf("%d", &a[i]);
  }

  int b[n];
  CountingSort(a, b, n, AMAX);

  for(i=1;i<=n;i++){
    if(i == n) printf("%d\n", b[i]);
    else printf("%d ", b[i]);
  }

  return 0;
}

//kはcの要素数
void CountingSort(int *a, int *b, int n, int k){
  int c[k];
  int i, j;

  for(i=0;i<k;i++){
    c[i] = 0;
  }

  //c[i]にi(=a[j])の出現数を記録
  for(j=1;j<=n;j++){
    c[a[j]]++;
  }

  //c[i]にi以下の数の出現数を記録(要素足してけばいい)
  //c[0]は何もしなくてok(ここで考えるのは正の数だから0未満の数字は出現しない)
  for(i=1;i<=k;i++){
    c[i] += c[i-1];
  }

  for(j=n;j>=1;j--){
    b[c[a[j]]] = a[j];
    c[a[j]]--;
  }
}



Measured memory_bytes: 17444
# -*- coding: utf-8 -*-
import math

N = int(input()) #使用しない

maxn = 1000000000
for a in input().split():

    count = 0
    b = int(a)
    while( b % 2 == 0):
        b = b // 2
        count += 1

    maxn = min(maxn, count)

print(maxn)

Measured memory_bytes: 9100
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

ll dp[55][5000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,a;
  cin >> n >> a;
  vector<int> x(n);
  rep(i,n){
    cin >> x[i];
    x[i]-=a;
  }
  
  memset(dp,0,sizeof(dp));
  dp[0][2500]=1;
  rep(i,n){
    for(int j=0;j+x[i]<5000;j++){
      if(dp[i][j] == 0) continue;
      dp[i+1][j] += dp[i][j];
      dp[i+1][j+x[i]] += dp[i][j];
    }        
  }
  cout << dp[n][2500]-1 << endl;

  return 0;
}


Measured memory_bytes: 2432
n = int(input())
li = []
for i in range(n):
    a = input()
    a, b = a.split()
    b = int(b)
    c = i+1
    li.append([a, b, c])

li.sort(key=lambda x: (x[0], -1*x[1]))

for i in range(n):
    print(li[i][2])



Measured memory_bytes: 3060
n = int(input())
S = list(map(int, input().split()))

cnt = 0

def merge(left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = S[left:left+n1]
    R = S[mid:mid+n2]
    L.append(10e10)
    R.append(10e10)
    for j in range(n2):
        R[j] = S[mid+j]
    x = 0
    y = 0
    for k in range(left, right):
        cnt += 1
        if L[x] < R[y]:
            S[k] = L[x]
            x += 1
        else:
            S[k] = R[y]
            y += 1

def mergesort(left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergesort(left, mid)
        mergesort(mid, right)
        merge(left, mid, right)

mergesort(0, n)

print(*S)
print(cnt)


Measured memory_bytes: 61668
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

bool cmp(pair< int, int > a, pair< int, int > b)
{
  if(a.first != b.first) return(a.first > b.first);
  return(a.second < b.second);
}
int main()
{
  int N, p[100];
  
  while(scanf("%d", &N), N) {
    for(int i = 0; i < N; i++) {
      scanf("%d", &p[i]);
    }
    
    pair< int, int > dp[2][50001];
    fill_n(*dp, 2 * 50001, make_pair(-INF, INF));
    pair< int, int > *now = dp[0], *nxt = dp[1];
    
    now[0] = {0, 0};
    for(int i = 0; i < N; i++) {
      int mod = p[i] % 1000;
      if(1 <= mod && mod <= 500) {
        int rev = 1000 - mod - 500;
        for(int j = 50000; j >= rev; j--) {
          nxt[j] = min(nxt[j], {now[j - rev].first + 1, now[j - rev].second + p[i]}, cmp);
        }
      } else {
        int rev = (1000 - mod) % 1000;
        int need = (mod + 500) % 1000;
        for(int j = 50000; j >= 0; j--) {
          nxt[j] = min(nxt[j], now[j], cmp);
        }
        for(int j = 50000; j >= rev; j--) {
          nxt[j] = min(nxt[j], {now[j - rev].first, now[j - rev].second + p[i]}, cmp);
        }
        for(int j = need; j <= 50000; j++) {
          nxt[j - need] = min(nxt[j - need], {now[j].first + 1, now[j].second + p[i]}, cmp);
        }
      }
      swap(now, nxt);
      for(int j = 0; j <= 50000; j++) nxt[j] = {-INF, INF};
    }
    auto p = *min_element(now, now + 50000, cmp);
    printf("%d %d\n", p.first, p.second);
  }
}

Measured memory_bytes: 3944
x, n = (int(e) for e in input().split())
i = 0
if(n != 0):
    p = list(map(int, input().split()))
else:
    p = -1
flag_f = False
for j in range(n):
    if(p[j] == x):
        flag_f = True
if(flag_f == False):
    print(x)

while(flag_f == True):
    i += 1
    flag_p = False
    flag_m = False
    for j in range(n):
        if(p[j] == x+i):
            flag_p = True
        elif(p[j] == x-i):
            flag_m = True
    if(flag_m == False):
        print(x-i)
        break
    elif(flag_p == False):
        print(x+i)
        break

Measured memory_bytes: 63512
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  //ll ans;
  string S, T;
  cin >> A >> B >> K;
  ll count = 0;
  for(int i = 100; i>= 1; i--) {
    if (A%i == 0 && B%i==0) count++;
    if (count == K){
      cout << i << endl;
      return 0;
    }
  }
  
  

  
  //cout << ans << endl;
  

}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    while (true) {
        val (H, W) = readLine()!!.split(" ").map(String::toInt)
        if (H == 0 && W == 0) break
        (1..H).forEach { h ->
            (1..W).forEach { w ->
                print(if (h%2 xor w%2 == 0) "#" else ".")
            }
            println()
        }
        println()
    }
}


Measured memory_bytes: 41644
#include<iostream>
using namespace std;
long long dp[1002][1002],sum[1001][1002],C[1001][1001];
int main()
{
  int n,k,m;
  cin>>n>>k>>m;
  for (int i=1;i<=k+1;++i)
    {
     dp[1][i]=1;
     sum[1][i]=i;
    }
  for (int i=0;i<=n;++i)
    C[i][0]=1;
  for (int i=1;i<=n;++i)
    for (int j=1;j<=n;++j)
      C[i][j]=(C[i-1][j]+C[i-1][j-1])%m;
  for (int i=2;i<=n+1;++i)
    for (int j=1;j<=k+1;++j)
      {
        for (int t=1;t<=i-1;++t)
	  dp[i][j]=(dp[i][j]+dp[t][j]*sum[i-t][j-1]%m*C[i-2][t-1])%m;
	sum[i][j]=(sum[i][j-1]+dp[i][j])%m;
      }
  cout<<dp[n+1][k+1]<<endl;
  return 0;
}

Measured memory_bytes: 12160
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

using namespace std;

typedef long long ll;

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

    int N; cin >> N;
    vector<int> p(N);

    int sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
        sum += p[i];
    }

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

    cout << (sum - p.back() / 2) << endl;

    return 0;
}

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

int main() {
  LL n, k;
  cin >> n >> k;
  vector<LL> a(n);
  for (int i = 0; i < n; i ++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());

  LL def = 1000000000;
  for (int i = 0; i <= n - k; i ++) {
    LL tmp;
    for (int j = i; j < i + k; j ++) {
      tmp = a.at(i + k - 1) - a.at(i);
    }
    def = min(def, tmp);
  }

  cout << def << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
    //#define ll long long
    using namespace std;
    #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
    #define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
    #define ll long long
    #define pb push_back
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define mp make_pair
    #define N 2000001
    #define M 998244353
    #define INF 1000000000000000
  ll gcd(ll a,ll b)
  {
    if(b==0)return a;
    else return(gcd(b,a%b));
  }

int main()
{
  SPEED;
ll i;ll a[5];
for(i=0;i<5;i++)
{
  cin>>a[i];
  if(a[i]==0){cout<<i+1;return 0;}
}
}


Measured memory_bytes: 3660
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  int N, M;
  cin >> N >> M;

  vector<pair<long long, long long>> A(1<<20);
  for(int  i = 0;i < N;i++) {
    cin >> A[i].first >> A[i].second;
  }

  sort(A.begin(), A.begin()+N);

  long long ans = 0;
  for(int  i = 0;i < N;i++) {
    if(M > A[i].second) {
      ans += A[i].first*A[i].second;
      M -= A[i].second;
    } else {
      ans += M*A[i].first;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 2005;
const int INF = 924844033;

int n, k, tot;
ll ans;
ll fac[maxn], f[2][maxn], g[maxn][maxn][2];

int main(){
	scanf("%d%d", &n, &k);
	fac[0] = 1;
	REP(i, 1, n) fac[i] = fac[i - 1] * i % INF;
	int p = 0, q = 1;
	f[0][0] = 1;
	FOR(r, 0, 2 * k){
		int m = n / (k * 2);
		if(r < n % (k * 2))
			++m;
		REP(i, 0, m) REP(j, 0, i) FOR(o, 0, 2)
			g[i][j][o] = 0;
		g[0][0][0] = 1;
		FOR(i, 0, m) REP(j, 0, i) FOR(o, 0, 2) if(g[i][j][o]){
			int x = i * (2 * k) + r;
			(g[i + 1][j][0] += g[i][j][o]) %= INF;
			if(x - k >= 0 && !o)
				(g[i + 1][j + 1][0] += g[i][j][o]) %= INF;
			if(x + k < n)
				(g[i + 1][j + 1][1] += g[i][j][o]) %= INF;
		}
		//printf("r = %d\n", r);
		//REP(j, 0, m) printf("j = %d %d %d\n", j, g[m][j][0], g[m][j][1]);
		REP(j, 0, min(n, tot + m))
			f[q][j] = 0;
		REP(j, 0, tot) REP(j_, 0, min(m, n - j))
			(f[q][j + j_] += 1ll * f[p][j] * (g[m][j_][0] + g[m][j_][1]) % INF) %= INF;
		tot += m;
		swap(p, q);
	}
	REP(i, 0, n){
		//printf("i = %d %d %d\n", i, fac[n - i], f[p][i]);
		if(i & 1)
			((ans -= fac[n - i] * f[p][i] % INF) += INF) %= INF;
		else
			(ans += fac[n - i] * f[p][i] % INF) %= INF;
	}
	printf("%d\n", ans);
	return 0;
}

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

int main()
{
  int n, d;
  cin >> n >> d;
  int ans = n / (2 * d + 1);
  if (n % (2 * d + 1) == 0)
  {
    cout << ans << endl;
  }
  else
  {
    cout << ans + 1 << endl;
  }
}


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>

using namespace std;

int H, W, D, Q;

int main() {
  cin >> H >> W >> D;
  vector<pair<int, int>> v(H*W+1);
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      int a;
      cin >> a;
      v.at(a) = make_pair(i, j);
    }
  }
  cin >> Q;
  vector<int> ans(H*W+1);
  for (int i=1; i<=H*W; i++) {
    if (i<=D) {
      ans.at(i) = 0;
    } else {
      pair<int, int> first = v.at(i-D);
      pair<int, int> second = v.at(i);
      ans.at(i) = ans.at(i-D) + abs(first.first - second.first) + abs(first.second - second.second);
    }
  }
  for (int i=0; i<Q; i++) {
    int L, R;
    cin >> L >> R;
    cout << ans.at(R) - ans.at(L) << endl;
  }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int n;
int x[10] , y[10];
double dist(int i , int j){
    double dx = x[i-1] - x[j-1];
    double dy = y[i-1] - y[j-1];
    //cout << dx << dy << endl;
    double res =  pow(dx*dx+dy*dy,0.5);
    return res;
}

int main(void){
    // Your code here!
    cin >> n;
    rep(i,n) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(n);
    rep(i,n) v[i] = i+1;
    do {
        rep(i,n-1) sum += dist(v[i],v[i+1]);
    }while(next_permutation(v.begin(),v.end()));
    int Factorial = 1;
    for (int i = 2;i <=n;i++) Factorial *=i;
    cout << fixed << setprecision(10) << sum /Factorial << endl;
    

}


Measured memory_bytes: 512
import numpy as np

N = int(input())
s = input()
w = np.array(list(map(lambda x: 1 if x == 'W' else 0, s)))
e = np.array(list(map(lambda x: 1 if x == 'E' else 0, s)))
w = np.add.accumulate(w)
e = e[::-1]
e = np.add.accumulate(e)
e = e[::-1]
ans = []
for i in range(N):
    num = 0
    if 0 < i: num += w[i - 1]
    if i < N - 1: num += e[i + 1]
    ans.append(num)
print(min(ans))

Measured memory_bytes: 33196
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    int N, M;
    cin >> N >> M;

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

    vector<int> c(M);
    vector<int> d(M);
    for (int i = 0; i < M; i++)
    {
        cin >> c[i] >> d[i];
    }

    int diff;
    int minimum = INF;
    int location;
    int i, j;
    for (i = 0; i < N; i++)
    {
        location = 0;
        diff = 0;
        minimum = INF;
        for (j = 0; j < M; j++)
        {
            diff = abs(a[i] + (c[j] * -1)) + abs(b[i] + (d[j] * -1));
            // printf("diff = (%d - %d) + (%d - %d)\n", a[i], c[j], b[i], d[j]);
            // printf("diff = %d\n", diff);
            if (minimum > diff)
            {
                minimum = diff;
                location = j + 1;
            }
        }
        cout << location << endl;
    }
    return (0);
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
  int a,b,d,r;
  double f;
  scanf("%d %d",&a,&b); 

  d = a / b;
  r = a % b;
  f = (double)a / b; 

    printf("%d %d %f\n",d,r,f);

return 0;
}


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

int main()
{
	int m, n, a[100][100], b[100];
	cin >> n >> m;
	for (int i = 0;i < n;i++)
	{
		for (int j = 0;j < m;j++)
		{
			cin >> a[i][j];
		}
	}
	for (int i = 0;i < m;i++)
	{
		cin >> b[i];
	}
	for (int i = 0;i < n;i++)
	{
		int sum = 0;
		for (int j = 0;j < m;j++)
		{
			sum += a[i][j] * b[j];
		}
		cout << sum << endl;
	}
}

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

long gcd(long m, long n)
{
  if (m == 0)
    return n;
  if (n == 0)
    return m;

  if (m > n)
  {
    return gcd(n, m % n);
  }
  else
  {
    return gcd(m, n % m);
  }
}

long lcm(long m, long n, long gcd)
{
  return m * n / gcd;
}

long sub(long num, long c, long d)
{
  long g = gcd(c, d);
  long l = lcm(c, d, g);
  return num - num / c - num / d + num / l;
}

int main()
{
  long a, b, c, d;
  cin >> a >> b >> c >> d;

  //long g = gcd(c, d);
  //cout << g << " gcd\n";
  //cout << lcm(c, d, g) << " lcm\n";

  cout << sub(b, c, d) - sub(a - 1, c, d);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class A {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int A, B, C;
        Input(out A, out B, out C);
        if((A == B || B == C || C == A) && !(A == B && B == C)) {
            Console.WriteLine("Yes");
        } else {
            Console.WriteLine("No");
        }
        Out.Flush();
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll sq=sqrt(n);
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ll x=n/i;
        if(n%i==0)
        {
            x--;
        }
        ans +=x;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3692
from itertools import product
n,*X=map(int,input().split())
L=[int(input()) for _ in range(n)]
P=product(range(4),repeat=n)
ans=float("inf")
for i in P:
    cnt=[0]*3
    length=[0]*3
    for k in range(n):
        if i[k]==3:
            continue
        cnt[i[k]]+=1
        length[i[k]]+=L[k]
    if min(cnt)>0:
        tmp=sum([abs(length[i]-X[i])+10*(cnt[i]-1) for i in range(3)])
        ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const int maxn = 5e5 + 50;
typedef pair<int, int> P;

int arr[maxn];
int a, b, c, d, e, f, g;
void solve();
int main()
{
	int t = 1;
//	cin >> t;
	for(int i=0; i<t; i++)
	{
		solve();
	}
	return 0;
}

// type below

void solve()
{
	cin >> a >> b;
	int cnt[a + 50] = {0};
	for(int i=0; i<b; i++)
	{
		int t; cin >> t;
		for(int j=0; j<t; j++)
		{
			int tt; cin >> tt;
			cnt[tt] ++;
		}
	}
	int ans = 0;
	for(int i=1; i<=a; i++)
	{
		if(cnt[i] == 0) ans ++;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3596
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize; m],
    }

    let sum = a.into_iter().fold(0, |acc, e| acc + e);

    if sum > n {
        echo!(-1);
    } else {
        echo!(n - sum);
    }
}


Measured memory_bytes: 2252
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

int main()
{
  int n;
  cin >> n;
  vector<char> v(n,0);
  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
  }

  set<int> s(v.begin(), v.end());
  if (int(s.size()) == 3)
  {
    cout << "Three" << endl;
  }else if (int(s.size()) == 4)
  {
    cout << "Four" << endl;
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
a, b, k = map(int, input().split())
if (b - a) // 2 + 1 < k:
    print(*range(a, b + 1), sep="\n")
else:
    print(*sorted(set([*range(a, a + k)] + [*range(b - k + 1, b + 1)])),
          sep="\n")


Measured memory_bytes: 9068
a, b, c = map(int, input().split())
if a >= b:
  if b >= c:
    print(c, b, a)
  elif a <= c:
    print(b, a, c)
  else:
    print(b, c, a)
else:
  if a >= c:
    print(c, a, b)
  elif b >= c:
    print(a, c, b)
  else:
    print(a, b, c)

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 n, m, d;
    cin >> n >> m >> d;

    i64 x = d ? max(0l, n - 2 * d) : 0;
    i64 y = n - x;
    f64 t = ((f64) x * (2 / (f64) n) + (f64) y / (f64) n) / (f64) n;
    cout << t * (f64) (m - 1) << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

int main(void){

	int n;
	char s[30002];
	char x[3];
	int num;
	int f1[1000] = {};
	int f10[10][10] = {};
	int f100[10] = {};
	int i,j,k;
	int c;
	int dc;

	int a,b;


	c = 0;

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

	for(i=0;i<n-2;i++){

		x[0] = s[i];
		a = x[0] - '0';
		if(f100[a] == 1){
			continue;
		}


		for(j=i+1;j<n-1;j++){
			x[1] = s[j];
			b = x[1] - '0';

			if(f10[a][b] == 1){
				continue;
			}

			dc = 0;

			for(k=j+1;k<n&&dc<10;k++){

				x[2] = s[k];
				num = atoi(x);
				if(f1[num] == 0){
					f1[num] = 1;
					c++;
					dc++;
				}
			}

			f10[a][b] = 1;
		}
		f100[a] = 1;
	}

	printf("%d\n",c);


	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<math.h>
typedef long long ll;
using namespace std;
int main()
{
    int a;
    cin >> a ;
    cout << a + a * a + a * a * a;

    return 0;
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

int main()
{
  double a, b, h;
  cin>>a>>b>>h;
  double area = ((a + b)*h) / 2;
  cout<<area<<endl;
  return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
#define MAX_V 100005
#define MAX_E 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef priority_queue<P> PQ;

class Edge {
public:
    ll t, w;
    Edge (ll t, ll w): t(t), w(w) {}
};

ll N;
P x[100000], y[100000];
vector<Edge> G[200000];
ll d[100000], color[100000];

void prim() {
    ll i, u;
    for(i=0; i<N; i++) {
        d[i]=INF;
        color[i]=WHITE;
    }
    priority_queue<P> PQ;
    PQ.push(P(0, 0));
    d[0]=0;
    
    while(PQ.size()) {
        P f=PQ.top(); PQ.pop();
        u=f.second;
        
        color[u]=BLACK;
        if(d[u]<f.first*(-1)) continue;
        
        for(i=0; i<G[u].size(); i++) {
            Edge e=G[u][i];
            if(color[e.t]!=BLACK && d[e.t]>e.w) {
                d[e.t]=e.w;
                PQ.push(P(-d[e.t], e.t));
            }
            
        }
        
    }
    ll ans=0;
    for(i=0; i<N; i++) {
        ans+=d[i];
    }
    
    prin(ans);
}


void add_edge(ll s, ll t, ll w) {
    G[s].push_back(Edge(t, w));
    G[t].push_back(Edge(s, w));
}

int main(void) {
    ll i;
    cin >> N;
    for(i=0; i<N; i++) {
        cin >> x[i].first >> y[i].first;
        x[i].second=i;
        y[i].second=i;
    }
    sort(x, x+N);
    sort(y, y+N);
    
    for(i=0; i<N-1; i++) {
        add_edge(x[i].second, x[i+1].second, x[i+1].first-x[i].first);
        add_edge(y[i].second, y[i+1].second, y[i+1].first-y[i].first);
    }
    
    prim();
}


Measured memory_bytes: 21616
#include <iostream>

using namespace std;
#define pi 3.14159265

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, l = 0;
	long long N, A, B, c;
	cin >> N >> A >> B;

	c = B-A;
	ans = c*(N - 2) + 1;

	if (ans<0)ans = 0;

	cout << ans << endl;
	return 0;
}

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

main(){
    int n, a, b;
    cin >> n >> a >> b;
    int total = 0;
    int calc = 0;
    for (int x = 1;x <= n;x++){
        calc = 0;
        int y = x;
        while (y > 0){
            calc += y % 10;
            y = y / 10;
        }
        if (calc >= a && calc <= b) total += x;
    }

    cout << total << endl;
    return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359

int main(){
  ll N,K;
  cin>>N>>K;
  vector<pair<ll,ll>> a;

ll tmp1,tmp2;
  for(ll i=0;i<N;i++){
  cin>>tmp1>>tmp2;
  a.emplace_back(make_pair(tmp1,tmp2));
  }

  sort(ALL(a));

ll c=K;
  for(ll i=0;i<a.size();i++){
    c -= a[i].second;
    if(c<=0){
      cout<<a[i].first<<endl;
      break;
    }
  }

}


Measured memory_bytes: 2420
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);

int main()
{
  int n;
  int M[MAX][MAX];

  cin >> n;
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      M[i][j] = INFTY;
    }
  }

  for (int i = 0; i < n; ++i)
  {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; ++j)
    {
      int v, c;
      cin >> v >> c;
      M[u][v] = c;
    }
  }

  int d[MAX];
  bool visited[MAX];
  for (int i = 0; i < n; ++i)
  {
    d[i] = INFTY;
    visited[i] = false;
  }
  d[0] = 0;
  
  while (true)
  {
    int minv = INFTY;
    int u = -1;
    for (int i = 0; i < n; ++i)
    {
      if (!visited[i] && minv > d[i])
      {
        minv = d[i];
        u = i;
      }
    }
    if (u == -1) break;

    visited[u] = true;
    for (int v = 0; v < n; ++v)
    {
      if (!visited[v] && M[u][v] != INFTY)
      {
        if (d[v] > d[u] + M[u][v])
        {
          d[v] = d[u] + M[u][v];
        }
      }
    }
  }

  for (int i = 0; i < n; ++i)
  {
    cout << i << " " << d[i] << endl;
  }

  return 0;
}



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

#define MOD 1000000007
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795

const int INF = ~(1<<31);
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int32 N;
	cin>>N;
	int32 A[N+1];
	for(int i=1; i<=N; i++){
		cin>>A[i];
	}
	int32 swaps = 1;
	for(int i=1; i<= N;){
		if(A[i] != i){
			if(swaps > 0){
				swap(A[i],A[A[i]]);
				swaps--;
			}
			else{
				swaps--;
				cout<<"NO\n";
				break;
			}
		}
		else
			i++;
	}
	if(swaps!=-1){
		cout<<"YES\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int Lh,Lw,Sh,Sw;
  scanf("%d %d", &Lh, &Lw);
  scanf("%d %d", &Sh, &Sw);

  int all = Lh*Lw;
  int black = Sh*Lw + Sw*Lh - Sh*Sw;
  int white = all-black;

  printf("%d\n", white);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(false);cin.tie(0);
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define mx 1000000
using namespace std;

int main() {
  ios
  int t = 1;
  // cin>>t;
  while(t--) {
    int n = 5;
    int a,ans;
    for(int i = 0;i < n;i++) {
      cin>>a;
      if(!a)
        ans = i+1;
    }
    cout<<ans;
    cout<<'\n';
  }
  return 0;
}

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

typedef long long ll;

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

ll lcm(ll m, ll n) {
    if(m == 0 || n == 0) return(0);
    return(m * n / gcd(m, n));
}

int main(void) {
    ll a, b;
    
    while(scanf("%lld %lld", &a, &b) != EOF) cout << gcd(a, b) << " " << lcm(a, b) << endl;
    
    return(0);
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int pv[N][9][9][9];

string f[N];

int main(){
  fastIO;
  int n;
  cin >> n;
  int a, b, c;
  cin >> a >> b >> c;
  for(int i = 0 ; i <= n; i ++ ){
    for(int j = 0 ; j < 9; j ++ ){
      for(int p = 0 ;p < 9; p ++ ){
        for(int q = 0; q < 9; q ++ ){
          pv[i][j][p][q]=-1;
        }
      }
    }
  }
  pv[0][4][4][4] = 0;
  int rj, rp, rq;
  for(int i = 1; i <= n; i ++ ){
    cin >> f[i];
    for(int j = 0 ; j < 9; j ++){
      for(int p = 0 ; p < 9; p ++ ){
        for(int q = 0; q < 9; q ++ ){
          if(pv[i-1][j][p][q] == -1) continue;
          if(f[i] == "AB"){
            if(a + j - 4 + 1 >= 0 && b + p - 4 - 1 >= 0 && j<8 && p>0){
              pv[i][j+1][p-1][q]=0;
            }
            if(a + j - 4 - 1 >= 0 && b + p - 4 + 1 >= 0 && j>0 && p<8){
              pv[i][j-1][p+1][q]=1;
            }
          }
          else if(f[i] == "BC"){
            if(b + p - 4 + 1 >= 0 && c + q - 4 - 1 >= 0 && p < 8 && q > 0){
              pv[i][j][p+1][q-1]=0;
            }
            if(b + p - 4 - 1 >= 0 && c + q - 4 + 1 >= 0 && q < 8 && p > 0){
              pv[i][j][p-1][q+1]=1;
            }
          }
          else{
            if(a + j - 4 + 1 >= 0 && c + q - 4 - 1 >= 0 && j < 8 && q > 0){
              pv[i][j+1][p][q-1]=0;
            }
            if(a + j - 4 - 1 >= 0 && c + q - 4 + 1 >= 0 && q < 8 && j > 0){
              pv[i][j-1][p][q+1]=1;
            }
          }
        }
      }
    }
  }
  int cj = -1, cp = -1, cq = -1;
  for(int j = 0 ; j < 9; j ++ )
    for(int p = 0 ; p < 9; p ++ ){
      for(int q =0 ; q < 9; q ++ ){
        if(pv[n][j][p][q] != -1){
          cj = j;
          cp = p;
          cq = q;
        }
      }
    }
  if(cj == -1){
    cout << "No\n";
    return 0;
  }
  vector<char> ans;
  for(int i = n; i >= 1; i -- ){
    if(f[i] == "AB"){
      if(pv[i][cj][cp][cq]==0){
        cj--;
        cp++;
        ans.push_back('A');
      }
      else{
        cj++;
        cp--;
        ans.push_back('B');
      }
    }
    else if(f[i] == "BC"){
      if(pv[i][cj][cp][cq]==0){
        cp--;
        cq++;
        ans.push_back('B');
      }
      else{
        cp++;
        cq--;
        ans.push_back('C');
      }
    }
    else{
      if(pv[i][cj][cp][cq]==0){
        cj--;
        cq++;
        ans.push_back('A');
      }
      else{
        cj++;
        cq--;
        ans.push_back('C');
      }
    }
  }
  cout << "Yes\n";
  reverse(ans.begin(), ans.end());
  for(char p : ans)
    cout << p << "\n";
  return 0;
}

Measured memory_bytes: 291672
import os

def main():
	n,k,q = map(int, input().split())
	result = [0]*n
	
	for i in range(q):
		a = int(input())
		result[a-1] += 1
	for i in range(len(result)):
		result[i] = k + (result[i] - q)
	for i in result:
		if 0 < i:
			print("Yes")
		else:
			print("No")

if __name__ == "__main__":
	main()


Measured memory_bytes: 7844
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include<stdio.h>
#include <map>
using namespace std;

int uni[100100];

int oya(int a){
if (uni[a]<0){
	return a;
}
else{
	uni[a]=oya(uni[a]);
	return oya(uni[a]);
}
}

bool ren(int a,int b){
	a=oya(a);
	b=oya(b);
	if(a==b){
	return	false;
	}
	else{
		
	return true;	
	}
}


int main() {
	int co=0;
	
vector <pair<int, int> > be;
int e,v;
cin>>v>>e;
for(int y=0;y<v;y++){
	uni[y]=-1;
}
for(int u=0;u<e;u++){
	int z,x,c;
	cin>>z>>x>>c;
	be.push_back(pair<int, int>(c,z*100100+x));
}
sort(be.begin(), be.end());

for(int y=0;y<e;y++){
	int z,x,c;
	c=be[y].first;
	z=(be[y].second)/100100;
	x=(be[y].second)%100100;
	if(ren(z,x)==true){
		co=co+c;
		uni[oya(z)]=x;
	}
}
cout<<co<<endl;


	return 0;
}

Measured memory_bytes: 2084
package main

import "fmt"

func judge(N int) bool {
	a := []int{}
	n := N
	for n != 0 {
		j := n % 10
		if len(a) == 0 {
			a = append(a, j)
		} else if j != a[0] {
			return false
		}
		n /= 10
	}
	return true
}

func main() {
	var n int
	fmt.Scan(&n)
	for !judge(n) {
		n++
	}

	fmt.Println(n)
}


Measured memory_bytes: 512
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 1; i <= n; i++) {
			list.add(sc.nextInt());
		}
		List<Integer> sorted = (List<Integer>)list.clone(); 
		Collections.sort(sorted);

		int max = sorted.get(n - 1);
		int maxMinus1 = sorted.get(n - 2);
		for(int i = 0; i < n; i++) {
			int ai = list.get(i);
			if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			}
		}
	}
}

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

const int MAXN = 3000;
int N, T;

pair<int, int> ABs[MAXN];

int64_t DP[MAXN+10][MAXN];

int64_t f(int t, int i) {
    if (i == N) return 0;
    if (DP[t][i] != -1) return DP[t][i];
    int64_t ans = f(t, i+1);
    if (t < T) ans = max(ans, f(min(T+1, t+ABs[i].first), i+1)+ABs[i].second);
    return DP[t][i] = ans;
}

int main() {
    cin >> N >> T;
    for (int i = 0; i < N; ++i) cin >> ABs[i].first >> ABs[i].second;
    sort(ABs, ABs + N);
    memset(DP, -1, sizeof DP);
    cout << f(0, 0) << endl;
}

Measured memory_bytes: 71040
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	int sx, sy, tx, tx2, ty, ty2;
	cin >> sy >> sx;
	tx = tx2 = sx - 1, ty = ty2 = sy - 1;
	string S, T;
	cin >> S >> T;
	rep(i, 0, n) {
		if (S[i] == 'U')ty--;
		if (ty < 0) {
			puts("NO"); return 0;
		}
		if (T[i] == 'D')ty++;
		ty = min(h - 1, ty);

		if (S[i] == 'D')ty2++;
		if (ty2 >= h) {
			puts("NO"); return 0;
		}
		if (T[i] == 'U')ty2--;
		ty2 = max(0, ty2);

		if (S[i] == 'L')tx--;
		if (tx < 0) {
			puts("NO"); return 0;
		}
		if (T[i] == 'R')tx++;
		tx = min(w - 1, tx);

		if (S[i] == 'R')tx2++;
		if (tx2 >= w) {
			puts("NO"); return 0;
		}
		if (T[i] == 'L')tx2--;
		tx2 = max(0, tx2);
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 3892
#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 10234566667
#define int long long
vector<int> v;
void dfs(int num) {
    if (num > INF2) return;
    v.push_back(num);
    if(num % 10 !=  0) {
        dfs(num * 10 + num % 10 - 1);
    }
    dfs(num * 10 + num % 10);
    if(num % 10 != 9) {
        dfs(num * 10 + num % 10 + 1);
    }
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K; cin >> K;
    REP(i, 1, 9) dfs(i);
    sort(v.begin(), v.end());
    cout << v[K - 1] << endl;
    


    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int p[n];
  for(int i=0; i<n; i++) cin >> p[i];
  int c=1;
  int min=p[0];
  for(int i=0; i<n; i++){
    if(min>p[i]) {c++; min=p[i];}
  }
  cout << c;
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define mp make_pair
#ifdef LOCAL
#define debug(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define check(...) assert(__VA_ARGS__)
#else
#define debug(fmt, ...)
#define check(...)
#endif

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

    string s;
    cin >> s;

    vi cnt(2019);
    int acc = 0;
    cnt[0]++;
    int p10 = 1;
    ll ans = 0;
    repi(i, s.size() - 1, 0) {
        acc = (p10 * (s[i] - '0') + acc) % 2019;
        ans += cnt[acc];
        cnt[acc]++;
        p10 = p10 * 10 % 2019;
    }
    cout << ans;
}


Measured memory_bytes: 3376
#include <stdio.h>
#define MAX 1000
void c2s(char str[MAX]){
	int i;
	for(i = 0; str[i] != 0; i++){
		if(str[i] == ','){
			str[i] = ' ';
		}
	}
}
int main(void){
	int i;
	int counter = 0;
	int list[MAX];
	int id;
	double weight;
	double height;
	char str[MAX];
	while(1){
		if(scanf("%s",str) == EOF){break;}
		c2s(str);
		sscanf(str,"%d%lf%lf",&id,&weight,&height);
		if(weight / (height * height) >= 25){
			list[counter] = id;
			counter++;
		}
	}
	if(!counter){puts("ツ該ツ督鳴づ按つオ");}
	else{
		for(i = 0; i < counter; i++){
			printf("%d\n",list[i]);
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

int n,k;
vi a;

int main(){
	cin>>n>>k;
	for(int i=1;i*i<=n;i++) if(n%i==0){
		a.push_back(i);
		if(n/i!=i) a.push_back(n/i);
	}
	sort(a.begin(),a.end());
	int N=a.size();
	vl b(N);
	ll res=0;
	for(int i=0;i<N;i++){
		ll d=a[i],tmp=Pow(k,(d+1)/2);
		for(int j=0;j<i;j++) if(d%a[j]==0) tmp=(tmp-b[j]+mod)%mod;
		b[i]=tmp;
		(res+=b[i]*(d%2==0?d/2:d))%=mod;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int ia;
    int ib;
    int ic;
    int id;
    int oa;
    
    scanf("%d",&ia);
    scanf("%d",&ib);
    scanf("%d",&ic);
    scanf("%d",&id);
    
    if(ia > ib){
        ia = ib;
    }
        
    if(ic > id){
        ic = id;
    }
    
    printf("%d",ia+ic);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> ones(60);
  for(int i = 0; i < N; i++){
    cin >> A[i];
    for(int j = 0; j < 60; j++){
      if((A[i] >> j) & 1){
	ones[j]++;
      }
    }
  }
  ll res = 0;
  ll d = 1;
  for(int i = 0; i < 60; i++){
    res = ((((((N-ones[i]) * ones[i]) % MOD) * d) % MOD) + res) % MOD;
    d = (d * 2) % MOD;
  }
  cout << res  << endl;
}


Measured memory_bytes: 2560
N,K = map(int,input().split())
x = list(map(int,input().split()))
ans = float('inf')
for i in range(N-K+1):
    l,r = i,i+K-1
    ans = min(abs(x[r])+abs(x[l]-x[r]),min(ans,abs(x[l])+abs(x[r]-x[l])))
print(ans)


Measured memory_bytes: 62576
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
            int value1 = Math.abs(h[i - 2] - h[i]);
            int value2 = Math.abs(h[i - 1] - h[i]);
            dp[i] = Math.min(dp[i - 2] + value1, dp[i - 1] + value2);
        }
        System.out.println(dp[n - 1]);
    }
}


Measured memory_bytes: 49524
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> a(n);
    vector<bool> dp(k + 1, false);
    for (int i = 0; i < n; ++i) scanf("%d", a.begin() + i);
    for (int i = 1; i <= k; ++i) for (int j = 0; j < n; ++j) {
        if (a.at(j) > i) continue;
        dp.at(i) = dp.at(i) || !dp.at(i - a.at(j));
    }
    printf("%s\n", (dp.back() ? "First" : "Second"));
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

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

  int n;
  string s;
  cin>>n>>s;
  
  s.erase(unique(ALL(s)),s.end());
  cout<<s.size()<<endl;
  
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  if(n / 10 == 9){
    cout << "Yes" << endl;
  }
  else if(n % 10 == 9){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256