akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main(void)
{
  int i, j, box, n, A[100000];

  cin >> n;

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

  int x = A[n - 1];
  i = 0;

  for(j = 0;j < n - 1;j++){
    if(A[j] <= x){
      box = A[i];
      A[i] = A[j];
      A[j] = box;
      i++;
    }
  }

  box = A[n - 1];
  A[n - 1] = A[i];
  A[i] = box;

  for(j = 0;j < n - 1;j++){
    if(j == i){
      cout << '[' << A[j] << "] ";
    }
    else{
      cout << A[j] << ' ';
    }
  }

  cout << A[j] << endl;
  
  return 0;
}



Measured memory_bytes: 3480
import array
import itertools
from collections import defaultdict, deque


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


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


def solve():
    def fill(queue):
        footsteps = [[None] * width for _ in range(height)]

        for x, y in queue:
            footsteps[y][x] = 0

        s = 0
        while queue:
            queue2 = deque()
            s += 1
            while queue:
                x, y = queue.popleft()

                if x > 0 and footsteps[y][x - 1] is None:
                    queue2.append((x - 1, y))
                    footsteps[y][x - 1] = s
                if x < width - 1 and footsteps[y][x + 1] is None:
                    queue2.append((x + 1, y))
                    footsteps[y][x + 1] = s
                if y > 0 and footsteps[y - 1][x] is None:
                    queue2.append((x, y - 1))
                    footsteps[y - 1][x] = s
                if y < height - 1 and footsteps[y + 1][x] is None:
                    queue2.append((x, y + 1))
                    footsteps[y + 1][x] = s

            queue = queue2

        return s - 1

    height, width = tuple(input_ints())
    field = [input() for _ in range(height)]
    queue = deque()

    for y, line in enumerate(field):
        for x, c in enumerate(line):
            if c == '#':
                queue.append((x, y))
    # queue.append((10, 10))


    return fill(queue)


def main():
    print(solve())


main()


Measured memory_bytes: 107744
import itertools

n = int(raw_input())
li = list()
for m in range(0,n):
    li.append(raw_input())

m = len(filter(lambda x: x[0]=="M" ,li))
a = len(filter(lambda x: x[0]=="A" ,li))
r = len(filter(lambda x: x[0]=="R" ,li))
c = len(filter(lambda x: x[0]=="C" ,li))
h = len(filter(lambda x: x[0]=="H" ,li))

con = [m, a, r, c, h]
print sum(map(lambda x: x[0]*x[1]*x[2] , list(itertools.combinations(con, 3))))

Measured memory_bytes: 11904
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec; typedef pair<int, int> pi;
int dd[] = { 0, 1, 0, -1, 0 };


int main()
{
	while (true)
	{
		int W, H;
		cin >> W >> H;
		if (W == 0 && H == 0)
		{
			break;
		}
		int C[1000][1000];
		for (int i = 0; i < 1000; i++)
		{
			for (int j = 0; j < 1000; j++)
			{
				C[i][j] = 0;
			}
		}
		int height = 0;
		for (int i = 0; i < 2 * H - 1; i++)
		{
			if (i % 2)
			{
				for (int j = 0; j < W; j++)
				{
					cin >> C[height * W + j][(height + 1) * W + j];
				}
				height++;
			}
			else
			{
				for (int j = 0; j < W - 1; j++)
				{
					cin >> C[height * W + j][height * W + j + 1];
				}
			}

		}

		int B[30][30];
		for (int i = 0; i < 30; i++)
		{
			for (int j = 0; j < 30; j++)
			{
				B[i][j] = MOD;
			}
		}
		B[0][0] = 1;

		queue<pi> Q;
		Q.push(pi(0, 0));
		while (!Q.empty())
		{
			int ty = Q.front().first; int tx = Q.front().second;
			if (ty == H - 1 && tx == W - 1)
			{
				break;
			}
			Q.pop();
			for (int r = 0; r < 4; r++)
			{
				int y = ty + dd[r];
				int x = tx + dd[r + 1];
				if (y < 0 || y >= H || x < 0 || x >= W)continue;
				if (C[y * W + x][ty * W + tx] || C[ty * W + tx][y * W + x])continue;
				if (B[y][x] != MOD)continue;
				B[y][x] = B[ty][tx] + 1;
				Q.push(pi(y, x));
			}
		}
		if (B[H - 1][W - 1] != MOD)
		{
			cout << B[H - 1][W - 1] << endl;
		}
		else
		{
			cout << 0 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 6984
#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (int)(1e9 + 21)
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int long long
#define ll long long 
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define in(x) scanf("%intd", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define fi first
#define se second
#define kitna se
#define endl "\n"
#define pi pair<int, int>
#define LL long long 
const int MAXN = (int)((1e5) + 10);
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  
bool isPrime(int N){ for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int nax =  (int)(1*1e5+10);
 
// int SPF[N+5];
 
// void SOF()
// {
//     SPF[1] = 1;
//     for (int i=2; i<N; i++)
//         SPF[i] = i;
//     for (int i=4; i<N; i+=2)
//         SPF[i] = 2;
 
//     for (int i=3; i*i<N; i++)
//         {
//         if (SPF[i] == i)
//             {
//             for (int kon=i*i; kon<N; kon+=i)
//                 if (SPF[kon]==kon)
//                    SPF[kon] = i;
//             }
//         }
// }
int a[nax];
int n; 
int dp[nax]; 
int k;
int func(int ind)
{
	if(ind==(n-1))
		return 0;
	else if(dp[ind]!=-1) return dp[ind];
	else
	{
		int ans = 1e9+5; 
		for(int i = 1;i<=k;i++)
		{
			if(ind+i<n)
				ans = min(ans,abs(a[ind+i]-a[ind]) + func(ind+i));
 
		}
		return dp[ind] = ans; 
	}
 
}
 
 
 
 
 
signed main(){
 
int t=1; 
//cin >> t;
// string s; 
// getline(cin,s);
 
while(t--)
{
    cin >> n >> k;
    for0(i,n) cin >> a[i]; 	
    ini(dp,-1); 
    cout << func(0); 
 
}
 
rr;
}

Measured memory_bytes: 11388
#include <iostream>

using namespace std;

int main() {
	int a, b, count;

	while (cin >> a >> b) {
		a += b;
		count = 0;

		while (a > 0) {
			a /= 10;
			count++;
		}

		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
import java.util.*;

public class Main {    
    public static void main(String[] args){        
        Scanner sc = new Scanner(System.in);                                
         
        int x = 0;
       
        int N = sc.nextInt();
        String S = sc.next();
        
        int max = 0;
        for(int i = 0;i < N;i++){
           if(S.charAt(i) == 'I'){
               x += 1;
           }
           if(S.charAt(i) == 'D'){
               x  -= 1;
           }
           max = Math.max(x,max);
        }        

        System.out.println(max);

    }            
}
        
        

Measured memory_bytes: 22740
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n, i, rankcnt = 0;
		n = sc.nextInt();
		int[] point = new int[n+1];
		int[] rank = new int[n+1];
		for(i = 0; i < n*(n-1)/2; i++) {
			int teamA = sc.nextInt();
			int teamB = sc.nextInt();
			int pointA = sc.nextInt();
			int pointB = sc.nextInt();
			if(pointA > pointB) point[teamA] += 3;
			else if(pointA == pointB) {
				point[teamA] += 1;
				point[teamB] += 1;
			} 
			else point[teamB] += 3;
		}
		for(i = 1; i <= n; i ++) rank[i] = 1;
		for(i = 1; i <= n; i++) {
			for(int j  = 1; j <= n; j++) {
				if(point[i] < point[j]) rank[i]++;
			}
		}
		for(i = 1; i <= n; i++) System.out.println(rank[i]);
	}
}

Measured memory_bytes: 42060
N = int(input())
s = ""
i = 0

while N != 0:
    if N % 2 == 0:
        s += "0"
        N //= 2
    else:
        s += "1"
        if i % 2 == 0:
            N = (N - 1)//2
        else:
            N = (N + 1)//2
    i += 1

if s == "":
    print("0")
else:
    print(s[::-1])

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
const int mod = 1e9+7;
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; }

int dp[105][4][2];

int main(){
    string s; cin >> s;
    int n = s.size();
    int k; cin >> k;
    dp[0][0][0] = 1;
    rep(i,n)rep(j,4)rep(b,2){
        int nd = s[i] - '0';
        rep(td, 10){
            int ni = i+1, nj = j, nb = b;
            if(td != 0) nj++;
            if(nj > k) continue;
            if(b == 0){
                if(nd > td) nb = 1;
                if(nd < td) continue;
            }
            dp[ni][nj][nb] += dp[i][j][b];
        }
    }
    cout << dp[n][k][0] + dp[n][k][1] << endl;
}


Measured memory_bytes: 256
use std::io::Write;

fn bfs(r: usize, g: &[Vec<usize>]) -> Vec<usize> {
    let n = g.len();
    let mut dp = vec![n; n];
    dp[r] = 0;
    let mut q = std::collections::VecDeque::new();
    q.push_back(r);
    while let Some(v) = q.pop_front() {
        for &u in g[v].iter() {
            if dp[u] > dp[v] + 1 {
                dp[u] = dp[v] + 1;
                q.push_back(u);
            }
        }
    }
    dp
}

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let x: usize = it.next().unwrap().parse().unwrap();
    let y: usize = it.next().unwrap().parse().unwrap();
    let mut g = vec![vec![]; n];
    for i in 1..n {
        g[i - 1].push(i);
        g[i].push(i - 1);
    }
    g[x - 1].push(y - 1);
    g[y - 1].push(x - 1);
    let mut cnt = vec![0; n];
    for i in 0..n {
        let d = bfs(i, &g);
        for d in d.iter() {
            cnt[*d] += 1;
        }
    }
    for c in cnt.iter().skip(1) {
        let ans = *c / 2;
        writeln!(out, "{}", ans).ok();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4352
(let ((str (read-line)))
  (defun char-down-p (a)
    (<= 97 (char-code a) 122))
  (if (and (char= #\A (aref str 0))
           (= 1 (count #\C (subseq str 2 (- (length str) 1)) :test #'char=))
           (equal "AC" (remove-if #'char-down-p str)))
      (princ "AC")
      (princ "WA")))

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

int N,M;
vector<int> G[5003];
int Gs[5003];

void solve(){
  queue<int> q;
  for(int i=1;i<=N;i++) 
    if( Gs[i] == 0 ) q.push( i );
  vector<int> res;
  bool f = false;
  while( !q.empty() ){
    if( q.size() > 1 ) f = true;
    int p = q.front(); q.pop();
    res.push_back( p );
    for(int i=0;i<(int)G[p].size();i++){
      int to = G[p][i];
      Gs[to]--; if( Gs[to] == 0 ) q.push(to);
    }
  }
  for(int i=0;i<(int)res.size();i++) cout << res[i] << endl;
  cout << f << endl;
}

int main(){
  cin >> N >> M;
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    G[a].push_back( b );
    Gs[b]++;
  }
  solve();
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 100000000000007
using namespace std;
using pii=pair<int,int>;
using LL=int64_t;



vector<pair<int64_t, int64_t>> fs;//素因数分解の素数，指数のペア
 
void prime_factorize(LL N){
   //vector<pair<LL, LL>> res;
   for (LL a = 2; a * a <= N;a++) {
	   if(N % a == 0){
	   LL ex = 0; //指数
 
	   //割れる限り割り続ける
	   while (N % a == 0) {
		   ++ex;
		   N /= a;
	   }
 
	   fs.push_back(make_pair(a, ex));
       }
   }
 
   //最後に残った数について
   if ( N != 1) fs.push_back(make_pair(N, 1));
   
}
	
void factorization(int64_t base){//baseを素因数分解
    //base未満のiが約数か
    for(int i=2;i*i<=base;i++){
        //iで割り切れるなら限界まで割る
        
        if(base%i==0){
            int64_t cnt=0;
            while(base%i==0){
                base/=i;
                cnt++;
            }
            fs.push_back(make_pair(i,cnt));
        }
    }
    //baseが素数
    if(base>1){
        fs.push_back(make_pair(base,1));
    }
}
int main(){
    int64_t n;
    cin>>n;
    
    
    //factorization(n);
    prime_factorize(n);
    int64_t ans=0;
    for(auto p : fs){
        int64_t e;
        e=p.second;
        int k=1;
        while(e-k>=0){
            e-=k;
            k++;
            ans++;
        }
    }

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

Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <iomanip>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  double hig = 0.006, a,b,c,tmp,Abs;
  int ans = 1;
  cin >> a >> b >> c >> tmp;
  Abs = abs(c - b + tmp*hig);
  rep(i,a-1){
    cin >> tmp;
    if(Abs>abs(c - b + tmp*hig)){
      Abs = abs(c - b + tmp*hig);
      ans = i + 2;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3752
#include<stdio.h>
#include<math.h>

int main(void){

  int n,x,i,j;
  scanf("%d",&n);
  scanf("%d",&x);

  int L[n];
  int D[n+1];

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

  int jamp = 1;

  D[0] = 0;

  for(i=1;i<n+1;i++){
    D[i] = D[i-1] + L[i-1];

    if(D[i] <= x){
        jamp++;
    }
  }

  printf("%d",jamp);

  return 0;
}


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

int main(){
  int H, W;
  cin >> H >> W;
  while(H != 0 || W != 0){
    
    for(int i = 0;i < H; i++){
      if(i%2 == 0){
        //偶数列目の処理
        for(int j = 0;j < W/2;j++){
        cout << "#.";
      }
      if(W%2 == 1){
        cout << "#";
      }
      }else{
        //奇数列目の処理
        for(int j = 0;j < W/2;j++){
          cout << ".#";
        }
        if(W%2 == 1){
          cout << ".";
        }
      }
      
      cout << endl;
    }
  cout << endl;
  cin >> H >> W;
}
  return 0;
}


Measured memory_bytes: 3112
#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";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
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, E, F, K,L, W, H, P, Q, R, X, Y;
  ll ans;
  string S, T;
  cin >> N;
  double n2;
  if (N%2 == 0) cout << 0.5 << endl;
  else {
    ll N_2 = N/2;
    n2 = (double)(N-N_2)/(double)N;
    cout << n2 << endl;
  }
  
  
   




}


Measured memory_bytes: 256
# E - This Message Will Self-Destruct in 5s
from collections import defaultdict


def main():
    N, *A = map(int, open(0).read().split())
    cnt = defaultdict(int)
    ans = 0
    for i, a in enumerate(A, 1):
        cnt[i + a] += 1
        ans += cnt[i - a]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62412
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll x;
    cin >> x;
    ll a = x / 500;
    ll b = (x % 500) / 5;
    cout << a * 1000 + b * 5 << endl;
    return 0;
}

Measured memory_bytes: 256
// g++ -std=c++14
#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(c) c.begin(),c.end()
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

bool isLunlun(ll num){
	int prev = num%10;
	num /= 10;
	while(num != 0){
		int curr = num%10;
		num /= 10;
		if(abs(curr - prev) > 1){
			return false;
		}
		prev = curr;
	}
	return true;
}

bool countHelper(string s, int ind, int& cnt, ll bound){
	ll num = stoll(s);
	// tr(num);
	if(num > bound){
		return false;
	}
	cnt++;
	int dig = s[ind] - '0';
	for(int i = -1; i < 2; i++){
		int new_dig = dig + i;
		if(new_dig >= 0 and new_dig < 10){
			char ch = '0' + new_dig;
			bool okay = countHelper(s + ch, ind + 1, cnt, bound);
			if(!okay){
				break;
			}
		}
	}
	return true;
}

int count(ll num){
	int cnt = 0;
	for(int i = 1; i < 10; i++){
		string s = "";
		char ch = '0' + i;
		s += ch;
		int temp = 0;
		countHelper(s, 0, temp, num);
		cnt += temp;
	}
	return cnt;
}

int main(){
  _
  int k;
  cin >> k;
  ll lo = 1, hi = 4e9;
  ll ans = -1;
  while(lo <= hi){
  	ll mid = (lo + hi)/2;
  	int cnt = count(mid);
  	bool poss = isLunlun(mid);
  	if(cnt == k and poss){
  		ans = mid;
  		break;
  	}
  	if(cnt >= k){
  		hi = mid - 1;
  	}
  	else{
  		lo = mid + 1;
  	}
  }
  cout << ans << "\n";
  // cout << count(23);
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = (m); i < (int)(n); i++)

using mint = modint998244353;

// モノイド
struct S {
    mint x, w;
    S(mint x = 0, mint w = 1) : x(x), w(w) {}
};

S op(S a, S b) { return S(a.x * b.w + b.x, a.w * b.w); }
// モノイドの単位元
S e() { return S(); }

// 写像の中身: fffffに変換する
S mapping(int f, S a) {
    if (f == 0) return a;
    return S((a.w - 1) / 9 * f, a.w);
}

// 関数合成
// gが先なので注意
int composition(int f, int g) {
    if (f == 0) return g;
    return f;
}

int id() { return 0; }

int main() {
    int N, Q;
    cin >> N >> Q;
    lazy_segtree<S, op, e, int, mapping, composition, id> t(N);

    // 初期化
    rep(i, N) t.set(i, S(1, 10));  //なんで10-> 10^1 = 10だから
    rep(i, Q) {
        int l, r, d;
        cin >> l >> r >> d;
        --l;
        t.apply(l, r, d);
        S ans = t.all_prod();
        printf("%d\n", ans.x.val());
    }
    return 0;
}

Measured memory_bytes: 9900
n, a, b = map(int, input().split())
 
if a == 0:
  print(0)
elif a + b == 0:
  print(0)
else:
  q1, mod1 = divmod(n, (a + b))
  if mod1 < a:
    ans = q1 * a + mod1
  else:
    ans = (q1 + 1) * a
  print(ans)

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

int main()
{
    int k, n, i;
    char s[105];

    cin >> k;
    cin >> s;
    n=strlen(s);

    if(n<=k) cout << s << endl;
    else if(n>k)
    {
        for(i=0; i<k; i++)
        {
            cout << s[i];
        }
        cout << "..." << endl;
    }

    return 0;
}


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

int main(void) {
    string S;cin>>S;
    int year = stoi(S.substr(0, 4));
    int month = stoi(S.substr(5, 2));
    if (year >= 2020 || (year == 2019 && month >= 5)) cout << "TBD" << endl;
    else cout << "Heisei" << endl;
    return 0;
}

Measured memory_bytes: 504
#include<stdio.h>
#include<string.h>
typedef struct{
    char t[101];
    char h[101];
}CARD;
int main(void)
{
    CARD card[1000];
    int n;
    int tsc=0;  /*太郎得点*/
    int hsc=0;  /*花子得点*/
    int count=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s %s\n",card[i].t,card[i].h);
    }
    n=n-1;
    while(n>=count){
        if(strcmp(card[count].t,card[count].h)==0){
            hsc=hsc+1;
            tsc=tsc+1;
        }
        if(strcmp(card[count].t,card[count].h)>0){
            tsc=tsc+3;
        }
        if(strcmp(card[count].t,card[count].h)<0){
            hsc=hsc+3;
        }
        count++;
    }
    printf("%d %d\n",tsc,hsc);
    return 0;
}


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

const int MAXN = 510;
int N;
int K;
int A[MAXN];

int totSum;

int B[MAXN];

void check(int x) {
	int remSum = 0;
	for (int i = 0; i < N; i++) {
		B[i] = A[i] % x;
		remSum += B[i];
	}
	int cnt = N - remSum / x;

	nth_element(B, B + cnt, B + N);
	if (accumulate(B, B + cnt, 0) <= K) {
		cout << x << '\n';
		exit(0);
	}
}

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> A[i];

	totSum = accumulate(A, A + N, 0);
	int rt = int(sqrt(totSum));
	for (int x = 1; x <= rt; x++) {
		if (totSum % x == 0) {
			check(totSum / x);
		}
	}
	for (int x = rt; x >= 1; x--) {
		if (totSum % x == 0) {
			check(x);
		}
	}

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 3;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

struct Edge
{
    int from, to, cost, hour, company;
};

using Graph = vector<vector<Edge>>;

struct State
{
    int pos, hour, cost;
};

bool operator<(const State &e, const State &f)
{
    return e.cost > f.cost;
}

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

    int N, M, H, K;
    while (cin >> N >> M >> H >> K, N || M || H || K)
    {
        Graph g(N);
        for (int i = 0; i < M; i++)
        {
            int a, b, c, h, r;
            cin >> a >> b >> c >> h >> r;
            a--;
            b--;
            r--;
            g[a].push_back(Edge{a, b, c, h, r});
            g[b].push_back(Edge{b, a, c, h, r});
        }
        int st, gt;
        cin >> st >> gt;
        st--;
        gt--;
        int P;
        cin >> P;
        vector<int> mask(P, 0), p(P, 0);
        vector<int> bitDP(1 << K, INF);
        bitDP[0] = 0;
        for (int i = 0; i < P; i++)
        {
            int l;
            cin >> l >> p[i];
            for (int j = 0; j < l; j++)
            {
                int k;
                cin >> k;
                k--;
                mask[i] |= (1 << k);
            }
            for (int j = 0; j < (1 << K); j++)
            {
                bitDP[j | mask[i]] = min(bitDP[j | mask[i]], bitDP[j] + p[i]);
            }
        }
        int res = INF;
        for (int b = 0; b < (1 << K); b++)
        {
            if (bitDP[b] == INF)
                continue;
            // dp[i][j] := i 番目の駅に 時間 j に着く最小コスト
            vector<vector<int>> dp(N, vector<int>(H + 1, INF));
            priority_queue<State> q;
            dp[st][0] = 0;
            q.push(State{st, 0, 0});
            while (!q.empty())
            {
                State s = q.top();
                q.pop();
                int pos = s.pos, hour = s.hour, cost = s.cost;
                if (dp[pos][hour] < cost)
                    continue;
                for (const auto &e : g[pos])
                {
                    int to = e.to, c = e.cost, h = e.hour, r = e.company;
                    if (b & (1 << r))
                        c = 0;
                    if (hour + h > H)
                        continue;
                    if (dp[to][hour + h] <= cost + c)
                        continue;
                    dp[to][hour + h] = cost + c;
                    q.push(State{to, hour + h, dp[to][hour + h]});
                }
            }
            for (int i = 0; i <= H; i++)
            {
                res = min(res, bitDP[b] + dp[gt][i]);
            }
        }
        cout << (res == INF ? -1 : res) << endl;
    }
}



Measured memory_bytes: 3240
# https://atcoder.jp/contests/abc074/tasks/abc074_b

import itertools
import collections
import bisect

def main():
    N = int(input())
    K = int(input())
    X = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        ans += min(abs(X[i]), abs(K - X[i])) * 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#B - Some Sums
N,A,B = map(int,input().split())

def some_sum(n):
    n = str(n)
    n = list(n)
    n = [int(j) for j in n]
    return sum(n)
    
count = 0
for k in range(A,N+1):
    if A <= some_sum(k) <= B:
        count += k
print(count)

Measured memory_bytes: 9040
from collections import defaultdict

n, m = map(int, input().split())
ab = (list(map(int, input().split())) for _ in range(m))

cnt = defaultdict(int)
for a, b in ab:
    cnt[a] += 1
    cnt[b] += 1
ans = all(cnt[i] % 2 == 0 for i in cnt)
print('YES' if ans else 'NO')


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int mx = *max_element(A.begin(), A.end());
  int sum = accumulate(A.begin(), A.end(), 0L);
  cout << ((mx < sum - mx) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
<?php
while($list = fgets(STDIN)){
    $input[] = trim($list);
}
$array = explode(" ",$input[1]);
$count = 0;
$result = 0;
foreach($array as $one){
   if($count == 0){
       $count = 1;
       $corrent = $one;
   }elseif($one == $corrent){
       $count = $count +1;
       if($count%2 == 0){
          $result = $result + 1;
       }
   }else{
        $count = 1;
        $corrent = $one;
   }
}
echo $result;
?>

Measured memory_bytes: 3828
import sys

# import bisect
# from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    k, n = list(map(int, readline().split()))
    a = list(map(int, readline().split()))

    d = [0] * (n - 1)
    d[0] = (k - a[-1]) + a[0]

    for i in range(1, n - 1):
        d[i] = a[i + 1] - a[i]

    print(k - max(d))


if __name__ == '__main__':
    main()


Measured memory_bytes: 71976
#include <iostream>

using namespace std;

int main() {
	int N;
	int A[100000];
	int count[100000] = {};
	int d = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		count[A[i]]++;
		if (count[A[i]] > 1)	d++;
	}
	if (d % 2 == 1)	d++;
	cout << N - d << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("YES\n")
#define outn printf("NO\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
/*------------------------------------------------------------*/

int main(){
	string a,b;
	cin>>a>>b;
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])outy;
	 else outn;
}

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


const int MOD = 1e9 + 7;
int dp[1<<10][1<<10];

char s[1<<10][1<<10];
 



int main () {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, m; 
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> s[i];
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) if ((i != 0 or j != 0) and s[i][j] == '.') {
      (dp[i][j] = (j ? dp[i][j - 1] : 0) + (i ? dp[i - 1][j] : 0)) %= MOD;
    }
  }
  cout << dp[n - 1][m - 1] << '\n';
}


Measured memory_bytes: 5248
s=raw_input()
n=input()
ans=0
for i in range(n):
    r=raw_input()
    for j in range(len(r)):
        flag=True
        for k in range(len(s)):
            ri=(j+k)%len(r)
            if r[ri]!=s[k]:
                flag=False
        if flag:
            ans+=1
            break
print ans

Measured memory_bytes: 4228
import java.util.*;
class Main{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args){
		long[] in = new long[Integer.parseInt(s.next())];
		for (int i = 0; i < in.length; i++) {
			in[i]=Long.parseLong(s.next());
		}
		reverse(in);
		boolean b = false;
		for(long l:in) {
			if(b)
				System.out.print(" ");
			b=true;
				System.out.print(l);
		}
		System.out.println();
	}
	static void swap(long[] l, int a, int b) {
		l[a] += l[b];
		l[b]  = l[a] - l[b];
		l[a] -= l[b];
	}
	static void reverse(long[] b) {
		for (int c = 0; c < b.length / 2; c++) {
			swap(b, c, b.length - 1 - c);
		}
	}

}

Measured memory_bytes: 26028
#include <iostream>
#include <algorithm>

using namespace std;

bool check(int a[], int n, int k, int x) {
    int b[n+1];
    for (int i = 0; i < n; i++) {
        b[i+1] = a[i] % x;
    }
    sort(b+1, b+n+1);

    int ps[n+1];
    for (int i = 0; i <= n; i++) {
        ps[i] = i == 0 ? 0 : ps[i-1] + b[i];
    }

    int ss[n+1];
    for (int i = n + 1; i > 0; i--) {
        ss[i] = i == n + 1 ? 0 : ss[i+1] + (x - b[i]);
    }

    int t = 0;
    for (int i = 0; i <= n; i++) {
        if (ps[i] == ss[i+1]) {
            t = ps[i];
            break;
        }
    }

    return t <= k;
}

int main() {
    ios::sync_with_stdio(false);

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

    int ans = 0;
    for (int i = 1; i * i <= s; i++) {
        if (s % i == 0) {
            if (check(a, n, k, i)) {
                ans = max(ans, i);
            }
            if (check(a, n, k, s / i)) {
                ans = max(ans, s / i);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter

S = input()

ans = 0

for s in range(len(S)):
    for e in range(s + 1, len(S) + 1):
        if set(S[s:e]) <= set({'A', 'T', 'C', 'G'}):
            ans = max(ans, e - s)
        # print(s, e, S[s:e], set(S[s:e]), set(S[s:e]) <= set({'A', 'T', 'C', 'G'}))
print(ans)

Measured memory_bytes: 38384
import java.util.Scanner

val sc = Scanner(System.`in`)

fun main(args : Array<String>) {
    val n = sc.nextInt()
    val a1 = listOfInt(n)
    val a2 = listOfInt(n)

    var max = 0
    for (i in 0 until n) {
        val sum = a1.take(i+1).sum() + a2.takeLast(n-i).sum()
        if (sum > max) max = sum
    }

    println(max)
}

fun listOfInt(n: Int) = (1..n).map { sc.nextInt() }.toList()

Measured memory_bytes: 31520
#include<iostream>
#define mod 1000000007
using namespace std;
#define LL long double
int main() 
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    string T;
    cin >> S >> T;
    LL N=S.size();
    LL M=T.size();
    LL ans=M;
    for(LL i=0;i<N-M+1;i++)
    {
        LL count=0;
        string temp;
        temp=S.substr(i,M);
        for(LL j=0;j<M;j++)
        {
            if(T[j]!=temp[j])
                count++;
        }
        ans=min(count,ans);
    }
    cout<<ans;

}
 
 

Measured memory_bytes: 3852
#include <stdio.h>
int main(void){
  int N, a, b, c, x = 0;
  scanf("%d", &N);
a = N % 10;
b = N % 100 / 10;
c = N / 100;
if(a != 7){
  if(b != 7){
    if(c != 7){
      printf("No\n");
      x += 1;
    }
  }
}
if (x == 0) printf("Yes\n");
return 0;
}

Measured memory_bytes: 1644
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
lis = list(map(int,input().split()))
ans = 100000000000
num = 0
for i in range(102):
    if i not in lis:
        if ans > abs(i-x):
            ans = abs(i-x)
            num = i
print(num)


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

int main()
{
    int N, K;
    double answer = 0;
    cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
    {
        cin >> p.at(i);
    }

    vector<int> maxx(N, 0);
    int waku = 0;

    for (int i = 0; i < K; i++)
    {
        waku += p.at(0+i);    
    }

    maxx.at(0) = waku;
    for (int i = 0; i < N-K; i++)
    {
        maxx.at(i+1) += waku - p.at(i) + p.at(i+K);
        waku = waku - p.at(i) + p.at(i+K); 
    }
    
    sort(maxx.begin(), maxx.end());
    reverse(maxx.begin(), maxx.end());

    answer = (double)(maxx.at(0)+K)/2;

    cout << setprecision(12) << answer;
    

    
}

Measured memory_bytes: 1792
import itertools
N, a, b, c = [int(_) for _ in input().split()]
L = [int(input()) for _ in range(N)]
ans = 10**10
for K in itertools.product(range(4), repeat=N):
    A = [[] for _ in range(4)]
    for i in range(N):
        A[K[i]] += [L[i]]
    if len(A[1]) and len(A[2]) and len(A[3]):
        cost = 10 * (N - len(A[0]) - 3)
        cost += abs(a - sum(A[1]))
        cost += abs(b - sum(A[2]))
        cost += abs(c - sum(A[3]))
        ans = min(cost, ans)
print(ans)


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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> m(N+1,1);
    for ( int i = 2; i <= N; ++i){
        for ( int j = 1; j <= N; ++j){
            if ( i * j > N ) break;
            m[i*j] = m[i*j] + 1;
        }
    }
    
    int64_t s = 0;
    for ( int64_t i = 1; i <= N; ++i ){
        s = s + i * m[i];
    }
    
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 81332
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)

signed main(){
  while(1){
    int d,w;
    cin>>d>>w;
    if(d==0&&w==0) break;
    int a[10][10];
    lp(i,d){
      lp(j,w){
	cin>>a[i][j];
      }
    }
    int ans=0;
    lp(iu,d-2){
      lp(jh,w-2){
	for(int is=iu+2;is<d;is++){
	  for(int jm=jh+2;jm<w;jm++){
	    int soto=10,naka=-1,nsum=0;
	    for(int i=iu;i<=is;i++){
	      for(int j=jh;j<=jm;j++){
		if(i==iu||i==is||j==jh||j==jm){
		  soto=min(soto,a[i][j]);
		}
		else{
		  naka=max(naka,a[i][j]);
		  nsum+=a[i][j];
		}
	      }
	    }
	    if(soto>naka){
	      ans=max(ans,(is-iu-1)*(jm-jh-1)*soto-nsum);
	    }
	  }
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}





Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main() {
  int N;
	cin >> N;
	vector<ll> a(N);
	vector<pair<int, int>> op; // 操作

	ll absmax = 0;
	ll max_id = -1;
	rep(i, N) {
		cin >> a[i];
		if(absmax < abs(a[i])) {
			max_id = i;
			absmax = abs(a[i]);
		}
	}

	if(a[max_id]>0) {
		rep(i, N-1) {

			while(a[i]>a[i+1]) { // 高々2回で完了する
				a[i+1] += a[max_id];
				op.push_back(make_pair(max_id+1, i+2));

				if(a[max_id]<a[i+1]) {
					max_id = i;
				}
			}

		}
	} else if(a[max_id]<0){ // a[max_id] <0 
		rep(j, N-1) {
			int i = N-2-j;
			while(a[i]>a[i+1]) { // 高々2回で完了する
				a[i] += a[max_id];
				op.push_back(make_pair(max_id+1, i+1));

				if(a[max_id]>a[i]) {
					max_id = i;
				}
			}

		}
	}


	cout << op.size() << endl;
	rep(i, op.size()) {
		cout << op[i].first << ' ' << op[i].second << endl;
	}
	
	// cout << "after a[]: " << endl;
	// rep(i, N) cout << a[i] << ' ';
	// cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
#define rep(i,n) for(int i=0; i<n; ++i)
using ll = long long;
const ll Inf = (1ULL << 62) -1;

ll n=0, wmax=0;
vector<ll> w, v;

int main() {
    cin >> n >> wmax;
    w.resize(n);
    v.resize(n);
    rep(i,n) cin >> w[i] >> v[i];

    vector<ll> dp(wmax+1);
    rep(i,n) {
        ll weight = w[i];
        for (int r = wmax - weight; r >= 0; --r) {
            dp[r+weight] = max(dp[r+weight], dp[r]+v[i]);
        }
    }

    ll ans = *max_element(dp.begin(), dp.end());
    cout << ans << endl;
    return 0;
}


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

int n;
double x[100],y[100];

double distance(double p){
  double sum=0;
  for(int i=0;i<n;i++){
    double w=abs(x[i]-y[i]);
    sum += pow(w,p);
  }
  return pow(sum,1.0/p);
}

int main(){
  cout<<fixed<<setprecision(12);

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  for(int i=0;i<n;i++){
    cin>>y[i];
  }
  
  cout<< distance(1) <<endl;
  cout<< distance(2) <<endl;
  cout<< distance(3) <<endl;

  double mx=0;
  for(int i=0;i<n;i++){
    mx=max(mx, abs(x[i]-y[i]) );
  }
  cout<< mx <<endl;
  
  return 0;
}




Measured memory_bytes: 3464
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let st: Vec<String> = read_vec();
    println!("{}{}", st[1], st[0]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <stack>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
#include <cstdio>
 
using namespace std;
 
int main() {
	int n, m; cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	vector<pair<int, int> > cb(m);
	vector<long long> d(n);
	for (int i = 0; i < m; ++i) {
		int b, c; cin >> b >> c;
		cb[i].first = c; cb[i].second = b;
	}
	sort(cb.begin(), cb.end(), greater<pair<int, int> >());
	sort(a.begin(), a.end());
	int tmp = 0;
	for (int i = 0; tmp < n && cb.size() > i; ++i) {
		for (int j = 0; j < cb[i].second; ++j) {
			if(tmp < n) d[tmp++] = cb[i].first;
		}
	}
	long long ans = 0;
	tmp = 0;
	for (int i = 0; i < n; ++i) {
		if (i <= d.size() && a[i] < d[tmp]) ans += d[tmp++];
		else ans += a[i];
	}
	cout << ans << endl;
 
	return 0;
}

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

int main(){
  long long a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0){
cout<<"1"<<endl;
  } else if(b==0){
cout<<"2"<<endl;
  } else if(c==0){
cout<<"3"<<endl;
  }
else if(d==0){
cout<<"4"<<endl;
}else if(e==0){
cout<<"5"<<endl;
}
}

Measured memory_bytes: 3564
import java.util.Scanner;

public class Main {

	private static final String SHARP = "#";
	private static final String DOT = ".";

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int answer = 0;

		if (B < C || D < A) {
			answer = 0;
		} else {
			answer = Math.min(B, D) - Math.max(A, C);
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 23764
def count_sort_2(arr, max_element=10000):
    c = [0] * (max_element + 1)

    for ele in arr:
        c[ele] += 1
    for i in range(1, max_element + 1):
        c[i] += c[i - 1]

    arr_copy = list(arr)
    n = len(arr)
    for i in range(n - 1, -1, -1):
        arr[c[arr_copy[i]] - 1] = arr_copy[i]
        c[arr_copy[i]] -= 1


if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    # count_sort(arr)
    count_sort_2(arr)

    arr = map(str, arr)
    print(' '.join(arr))



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

int main()
{
  unsigned int N;
  cin >> N;
  unsigned int N1 = N % 10;
  if (N1 == 3)
  {
    cout << "bon" << endl;
  }
  else if (N1 == 0 || N1 == 1 || N1 == 6 || N1 == 8)
  {
    cout << "pon" << endl;
  }
  else
  {
    cout << "hon" << endl;
  }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	auto A=vecin(N);
	int M=in();
	auto B=vecin(M);

	out(includes(ALL(A),ALL(B))?1:0);
	return 0;
}


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

typedef long long ll;
#define forn(i,n) for(ll i=0;i<n;++i)

int main(){
	ll t=1;
	//cin>>t;
	while(t--){
		ll n,y;
		cin>>n;
		ll x[n];
		forn(i,n)cin>>x[i];
		forn(i,n){
			cin>>y;
			x[i]-=y;
		}
		sort(x,x+n);ll sum=0;
		for(ll i=n-1;i>=0;--i){
			if(x[i]<=0)break;
			sum+=x[i];
		}
		cout<<sum<<endl;
	}
	return 0;
}


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

int amountOfOdd(int n){
    int ans = 0;
    for(int q = 1; q <= n; q++){
        if(q % 2 != 0){
            ans++;
        }
    }
    return ans;
}

int main(){

    int k = 0;
    cin >> k;
    int ans = amountOfOdd(k);
    ans *= (k - ans);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256