akhauriyash/Code-Regression huggingface dataset:
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n,k;
	cin>>n>>k;
	vi v(n);
	rep(i,n){
		cin>>v[i];
	}	
	ll max1 = 0;
	ll x  = 1;
	repa(i,1,n){
		x *= i;
		x %= mod;
	}
	ll y = 1;
	repa(i,1,k){
		y *= i;
		y %= mod;
	}
	ll z = 1;
	repa(i,1,n-k+1){
		z *= i;
		z %= mod;
	}
	x *= inverse(y);
	x %= mod;
	x *= inverse(z);
	x %= mod;
	ll x1 = x;
	sort(all(v),greater<ll>());
	rep(i,n-k+1){	
		ll temp = v[i];
		temp += mod;
		temp %= mod;
		temp *= x;
		temp %= mod;
		max1 += temp;
		max1 %= mod;
		x *= inverse(n-i-1);
		x %= mod;
		x *= (n-k-i);
		x %= mod;
	}
	sort(all(v));
	x = x1;
	ll min1 = 0;
	rep(i,n-k+1){	
		ll temp = v[i];
		temp += mod;
		temp %= mod;
		temp *= x;
		temp %= mod;
		min1 += temp;
		min1 %= mod;
		x *= inverse(n-i-1);
		x %= mod;
		x *= (n-k-i);
		x %= mod;
	}
	ll ans = max1 - min1;
	ans += mod;
	ans %= mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using lint = int_least64_t;
using namespace std;

#include<vector>
template<typename T>
class SegmentTree
{
	public:

	int N;
	vector<T> tree;

	T unit;
	T (*func)(T, T);

	SegmentTree(vector<T>& src, T unit, T (*func)(T, T))
	{
		this->unit = unit;
		this->func = func;

		const int size = (int)src.size();
		N = 1;
		while(N < size)
			N *= 2;

		tree.resize(2*N - 1);
		for(int i = 0; i < N; i++)
			tree[i] = unit;

		for(int i = 0; i < size; i++)
			update(i, src[i]);
	}

	void update(int i, const T value)
	{
		i = i + N-1;

		tree[i] = value;
		while(i > 0)
		{
			i = (i - 1) / 2;
			tree[i] = func(tree[2*i+1], tree[2*i+2]);
		}
	}

	T get(int i)
	{
		return tree[i + N-1];
	}

	T answer(int tl, int tr, int l = 0, int r = -1, int i = 0)
	{
		if(r < 0)
			r = N;

		if(tr <= l || r <= tl)
			return unit;

		if(tl <= l && r <= tr)
			return tree[i];

		const T ansl = answer(tl, tr, l, (l+r)/2, 2*i+1);
		const T ansr = answer(tl, tr, (l+r)/2, r, 2*i+2);

		return func(ansl, ansr);
	}

};

int add(int x, int y)
{
	return x + y;
}

bool cmp(const pair<int, pair<int, int>>& x, const pair<int, pair<int, int>>& y)
{
	int xf  = x.first;
	int xss = x.second.second;
	int yf  = y.first;
	int yss = y.second.second;

	if(xss == yss)
		return xf < yf;
	return xss < yss;
}

int main()
{
	int N, M, Q;
	vector<pair<int, pair<int, int>>> v;
	int p[100010] = {};
	int q[100010] = {};

	cin >> N >> M >> Q;
	for(int i = 0; i < M; i++)
	{
		int L, R;
		cin >> L >> R;
		v.push_back({0, {L-1, R}});
	}
	for(int i = 0; i < Q; i++)
	{
		cin >> p[i] >> q[i];
		p[i]--;
		v.push_back({1, {p[i], q[i]}});
	}

	sort(v.begin(), v.end(), cmp);

	vector<int> src(N, 0);
	SegmentTree<int> sg(src, 0, add);
	int ans[510][510] = {};
	for(auto&& p: v)
	{
		int l = p.second.first;
		int r = p.second.second;
		bool isquery = (p.first == 1);
		
		if(isquery)
			ans[l][r] = sg.answer(l, r);
		else
			sg.update(l, sg.get(l)+1);
	}

	for(int i = 0; i < Q; i++)
		cout << ans[p[i]][q[i]] << endl;
		
	return 0;
}



Measured memory_bytes: 9328
#include <bits/stdc++.h> 
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    ll ro,co;
    cin>>ro>>co;
    ll mod = 1e9+7;

    vector< vector<ll>> dp(ro+1, vector<ll> (co+1,0));
    dp[0][0] = 1;

    for(ll i=0;i<ro;i++)
    {
        string s;
        cin>>s;
        for(ll j=0;j<co;j++)
        {
            if(s[j] == '.')
            {
                if(i>0)
                {
                    dp[i][j] += dp[i-1][j];
                    dp[i][j] %= mod;
                }
                if(j>0)
                {
                    dp[i][j] += dp[i][j-1];
                    dp[i][j] %= mod;
                }
            }
            else
            dp[i][j] = 0;

        }
    }
    cout<<dp[ro-1][co-1]<<endl;

    return 0;
}


Measured memory_bytes: 8064
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

# sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, A):

    return N - sum(A) if N - sum(A) >= 0 else -1


def main():
    N, M = read_int_n()
    A = read_int_n()
    print(slv(N, M, A))


if __name__ == '__main__':
    main()


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

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

	int N; cin >> N;

	map<char, int> cnt;
	for (char c = 'a'; c <= 'z'; c++) {
		cnt[c] = 55;
	}

	for (int i = 0; i < N; i++) {
		string s; cin >> s;
		map<char, int> scnt;
		for (auto c : s) {
			scnt[c]++;
		}
		for (char c = 'a'; c <= 'z'; c++) {
			cnt[c] = min(cnt[c], scnt[c]);
		}
	}

	string ans;
	for (auto p : cnt) {
		for (int i = 0; i < p.second; i++) {
			ans += p.first;
		}
	}
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
/*
                Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
    {   if(n % 2 ==1)
        result=(result * x) % M;
        x=(x*x)% M;
        n=n/2;
    }
return result % M;
}      
bool isPrime(int n) 
{ 
if (n <= 1) 
    return false; 
if (n <= 3) 
    return true; 
if (n % 2 == 0 || n % 3 == 0) 
    return false; 
for (int i = 5; i * i <= n; i = i + 6) 
    if (n % i == 0 || n % (i + 2) == 0) 
        return false; 
return true; 
} 
signed main()
{   jaldi
    int n;
    cin>>n;
    int a[n],i,sum=0;
    for(i=0;i<n;i++)
    {   cin>>a[i];
        sum+=a[i];
    }
    sort(a,a+n);
    sum-=a[n-1];
    sum+=a[n-1]/2;
    cout<<sum;
}   

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

using namespace std;

using ll = long long;
using ld = long double;
using li = __int128;
using uli = unsigned __int128;

#define fi first
#define se second

template <typename T> void s_min(T& a, T b) {
	if (a > b) a = b;
}

template <typename T> void s_max(T& a, T b) {
	if (a < b) a = b;
}

const int MAXN = 110, MAXK = 1e5 + 5, mod = 1e9 + 7;
int N, K, a[MAXN];
ll dp[MAXN][MAXK];

int main() {
	ios_base::sync_with_stdio(0);

	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> a[i];
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		vector<ll> pref(K + 1);
		pref[0] = dp[i - 1][0];
		for (int j = 1; j <= K; j++) {
			pref[j] = (pref[j - 1] + dp[i - 1][j]) % mod;
		}
		for (int j = 0; j <= K; j++) {
			dp[i][j] = pref[j];
			int factor = j - a[i] - 1;
			if (factor >= 0) dp[i][j] = (dp[i][j] - pref[factor] + mod) % mod;
		}
	}
	cout << dp[N][K];

	return 0;
}

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

using namespace std;

int main() {
	int N;
	cin>>N;
	vector<int> nums(N);
	vector<int> smallest(N);
	for (auto &x : nums) {
		cin>>x;
	}

	int ans = 1;
	smallest[0] = nums[0];
	for (int i = 1;i < nums.size();++i) {
		if (nums[i] < smallest[i-1]) {
			smallest[i] = nums[i];
		}
		else {
			smallest[i] = smallest[i-1];
		}
	}

	for (int i = 1;i < nums.size();++i) {
		if (nums[i] <= smallest[i-1]) {
			ans += 1;
		}
	}
	

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


Measured memory_bytes: 1792
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    try {
      val a = sc.nextInt
      val b = sc.nextInt

      val d = a/b
      val r = a%b
      val f = a.toDouble / b.toDouble
      println(s"$d $r "+f"$f%f")
    } catch {
      case e: NoSuchElementException =>
        println("error: stdin is not found. Please take numbers.")
    }
  }
}

Measured memory_bytes: 45216
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 87;
vector<int> g[N];
int dp[N];
int dfs(int u)
{
    if (dp[u] != -1)
        return dp[u];
    dp[u] = 0;
    for (int v : g[u])
        dp[u] = max(dp[u], dfs(v) + 1);
    return dp[u];
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
    }
    fill_n(dp, n + 1, -1);
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans = max(ans, dfs(i));
    cout << ans << endl; 
}


Measured memory_bytes: 7552
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll a,b,c,k;
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	if (k%2==0)printf("%lld",a-b);
	else printf("%lld",b-a);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int isprime(int);

int main()
{
  int n,sum = 0,i,a[10000];

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

  for(i = 0;i < n;i++)
    {
      if(isprime(a[i]) == 0) continue;
      if(isprime(a[i]) == 1) sum++;
    }
  printf("%d\n",sum);
  return 0;
}
int isprime(int x)
{
  int i;
  double a;
  
  if(x == 2) return 1;

  if(x < 2 || x % 2 == 0) return 0;

  i = 3;
  a = sqrt(x);
  while(i <= a)
    {
      if(x % i == 0) return 0;
      i = i + 2;
    }
  return 1;
}



Measured memory_bytes: 2128
N, K = map(int, input().split())
if N < 2*K - 1:
    print(-1)
else:
    A = [a for a in range(K, K+N, 2)]
    A += [a for a in range(K+1, K+N, 2)]
    B = [b for b in range(K+2*N-N//2-1, K+N-1, -1)]
    B += [b for b in range(K+2*N-1, K+2*N-N//2-1, -1)]
    C = [c for c in range(K+2*N, K+3*N)]
    [print(*p) for p in list(map(list, zip(A, B, C)))]


Measured memory_bytes: 31352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define inf 1001001001
using namespace std;
typedef long long ll;
int main(void) {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int mx = -101;
    rep(i, n) {
        int c; cin >> c;
        mx = max(mx, c);
    }
    int mi = 101;
    rep(i, m) {
        int c; cin >> c;
        mi = min(mi, c);
    }
    if(x < mx && mx < mi && mi <= y) cout << "No War";
    else cout << "War";
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
from bisect import bisect_left


n, m = map(int, input().split())
a = list( map(int, input().split()))
a.sort()

bc = [tuple(map(int,input().split())) for i in range(m)]
bc = sorted(bc, reverse=True, key=lambda x: x[1])

i = 0
d = []
for b, c in bc:
    d.extend([c]*b)
    if len(d) >= n:
        break

ans = 0
for i in range(n):
    if i < len(d):
        ans += max(a[i], d[i])
    else: ans += a[i]

print(ans)


Measured memory_bytes: 77292
n,k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)

ofs = []
line = [1]
hash = {}
hash[1] = 0
piv = 1

n.times do |c|
  piv = a[piv-1]
  if !hash[piv].nil?
    ofs = line.take(hash[piv])
    line = line.drop(hash[piv])
    break
  end
  hash[piv] = c+1
  line << piv
end

if k < ofs.length
  puts("#{ofs[k]}")
else
  k -= ofs.length
  puts("#{line[k%line.length]}")
end

Measured memory_bytes: 39272
def main():
    x1, y1, x2, y2 = list(map(int, input().split()))

    ans = ''

    # 1
    for i in range(y2 - y1):
        ans += 'U'
    for i in range(x2 - x1):
        ans += 'R'
    for i in range(y2 - y1):
        ans += 'D'
    for i in range(x2 - x1):
        ans += 'L'

    # 2
    ans += 'L'
    for i in range(y2 - y1 + 1):
        ans += 'U'
    for i in range(x2 - x1 + 1):
        ans += 'R'
    ans += 'D'
    ans += 'R'
    for i in range(y2 - y1 + 1):
        ans += 'D'
    for i in range(x2 - x1 + 1):
        ans += 'L'
    ans += 'U'
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
n, m = map(int, input().split())
a = list(map(int, input().split()))

bc = []

for _ in range(m):
    b, c = map(int, input().split())
    bc.append((b, c))

bc = sorted(bc, key=lambda x: x[1], reverse=True)

cnt = 0

for b, c in bc:
    cnt += b
    a += [c] * b
    if cnt >= n:
        break

print(sum(sorted(a,reverse=True)[:n]))

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

int main(){
  double x1,x2,y1,y2;
  double dist;
  cin>>x1>>x2>>y1>>y2;

  dist= sqrt((y1-x1)*(y1-x1)+(y2-x2)*(y2-x2));

  printf("%.10lf",dist);

  return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};
int n,m;
int fie[6105][6105];
vector<int> xi;
vector<int> yi;
int a[1005],b[1005],c[1005];
int d[1005],e[1005],f[1005];

bool isInf(){
	for(int i=0;i<=yi.size()*2;i++){
		if(fie[i][0]==1 || fie[i][xi.size()*2]==1){
			return true;
		}
	}
	for(int i=0;i<=xi.size()*2;i++){
		if(fie[0][i]==1 || fie[yi.size()*2][i]==1){
			return true;
		}
	}
	return false;
}

int main(void){
	scanf("%d%d",&n,&m);
	xi.push_back(0);
	yi.push_back(0);
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		xi.push_back(a[i]);
		xi.push_back(b[i]);
		yi.push_back(c[i]);
	}
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&d[i],&e[i],&f[i]);
		xi.push_back(d[i]);
		yi.push_back(e[i]);
		yi.push_back(f[i]);
	}
	sort(xi.begin(),xi.end());
	xi.erase(unique(xi.begin(),xi.end()),xi.end());
	sort(yi.begin(),yi.end());
	yi.erase(unique(yi.begin(),yi.end()),yi.end());
	for(int i=0;i<n;i++){
		int lx=lower_bound(xi.begin(),xi.end(),a[i])-xi.begin();
		lx=lx*2+1;
		int rx=lower_bound(xi.begin(),xi.end(),b[i])-xi.begin();
		rx=rx*2+1;
		int y=lower_bound(yi.begin(),yi.end(),c[i])-yi.begin();
		y=y*2+1;
		for(int i=lx;i<=rx;i++){
			fie[y][i]=-1;
		}
	}
	for(int i=0;i<m;i++){
		int x=lower_bound(xi.begin(),xi.end(),d[i])-xi.begin();
		x=x*2+1;
		int ly=lower_bound(yi.begin(),yi.end(),e[i])-yi.begin();
		ly=ly*2+1;
		int ry=lower_bound(yi.begin(),yi.end(),f[i])-yi.begin();
		ry=ry*2+1;
		for(int i=ly;i<=ry;i++){
			fie[i][x]=-1;
		}
	}
	queue<P> que;
	int sx=lower_bound(xi.begin(),xi.end(),0)-xi.begin();
	int sy=lower_bound(yi.begin(),yi.end(),0)-yi.begin();
	sx=sx*2+1;
	sy=sy*2+1;
	que.push(P(sx,sy));
	fie[sy][sx]=1;
	while(que.size()){
		P p=que.front();
		que.pop();
		int cx=p.first;
		int cy=p.second;
		for(int i=0;i<4;i++){
			int nx=cx+dx[i];
			int ny=cy+dy[i];
			if(ny<0 || ny>yi.size()*2 || nx<0 || nx>xi.size()*2){
				continue;
			}
			if(fie[ny][nx]==0){
				fie[ny][nx]=1;
				que.push(P(nx,ny));
			}
		}
	}
	if(isInf()){
		printf("INF\n");
		return 0;
	}
	ll ans=0;
	for(int i=0;i+1<yi.size();i++){
		for(int j=0;j+1<xi.size();j++){
			if(fie[i*2+2][j*2+2]==1){
				ll dx=xi[j+1]-xi[j];
				ll dy=yi[i+1]-yi[i];
				ans+=dx*dy;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 146864
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)

long long parse_int(const std::string &s, size_t &i) {
    long long res=0;
    while (s[i] >= '0' && s[i] <= '9') 
        res = res*10 + s[i++]-'0';

    return res;
}

long long operate(long long lhs, char op, long long rhs) {
    if (op == '+') {
        return lhs + rhs;
    } else if (op == '-') {
        return lhs - rhs;
    } else if (op == '*') {
        return lhs * rhs;
    } else {
        assert(0);  // tsurai
        return -123456789;  // not reached
    }
}

long long parse_expr(const std::string &s, size_t &i, const std::vector<std::string> &ops, int prec) {
    if (ops[prec].empty()) {
        if (s[i] == '(') {
            long long tmp=parse_expr(s, ++i, ops, 0);
            s[++i];  // ')'
            return tmp;
        } else {
            return parse_int(s, i);
        }
    }

    long long res=parse_expr(s, i, ops, prec+1);
    while (i < s.length()) {
        if (!std::count(ops[prec].begin(), ops[prec].end(), s[i]))
            return res;

        char op=s[i++];
        long long tmp=parse_expr(s, i, ops, prec+1);
        res = operate(res, op, tmp);
    }

    return res;
}

int main() {
    char buf[256];
    scanf("%s", buf);
    std::string s=buf;

    char oplist[256]={};
    long long res=LLONG_MIN;
    for (int i=0; i<27; ++i) {
        oplist['+'] = i % 3;
        oplist['-'] = (i/3) % 3;
        oplist['*'] = (i/9) % 3;

        std::vector<std::string> ops(4);
        for (char c: {'+', '-', '*'})
            ops[oplist[int(c)]].push_back(c);

        if (ops[0].empty()) continue;
        if (ops[0].length() < 3 && ops[1].empty()) continue;

        size_t index=0;
        res = std::max(res, parse_expr(s, index, ops, 0));
    }

    printf("%lld\n", res);
}

Measured memory_bytes: 3360
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d,n,ar[100010],i,j,k,mini=100010;
    while(cin>>n>>k)
    {
      for(i=0;i<n;i++)
      {
          cin>>ar[i];
      }
      a=0;
      sort(ar,ar+n);
      for(i=0;i<n;)
      {
          i=i+(k-1);
          if(i==n-1)
          {
              a++;
              break;
          }


          if(i>=n)
          {
             a++;
             break;
          }
         else
         {
            a++;
         }
      }
     cout<<a<<endl;

    }
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

const int N = 1e5+5;

ll n, v[101], w[101], wt, dp[101][N];

void solve()
{
       cin>>n>>wt;
       rep(i,1,n+1) cin>>w[i]>>v[i];
       rep(i,1,N) dp[0][i]=inf;
       // imp: dp[0][0] = 0
       rep(i,1,n+1)
       {
              rep(j,0,N)
              {
                     dp[i][j]=dp[i-1][j];
                     if(j>=v[i]) dp[i][j]=min(dp[i][j], dp[i-1][j-v[i]]+w[i]);
              }
       }
       ll ans=0;
       rep(j,0,N) if(dp[n][j]<=wt) ans=j;
       cout<<ans;
}


int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 79232
def alpha2num(alpha):
    num=0
    for index, item in enumerate(list(alpha)):
        num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1)
    return num

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

N = int(input())
S = input()

ans = ''
for i in S:
    tmp = alpha2num(i)
    if tmp + N <= 26:
        ans += num2alpha(tmp+N)
    else:
        ans += num2alpha(tmp+N-26)

print(ans)

Measured memory_bytes: 3188
//ABC155C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	cin >> n;
	map<string, int> x;
	string s;
	for(int i=0;i<n;i++){
		cin >> s;
		x[s]++;
	}
	int num = 0;
	for(const auto& i:x){
		int a = i.second;
		num = max(num,a);
	}
	for(auto i=x.begin();i!=x.end();i++){
		if(i->second == num){
			cout << i->first << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 25216
#include <stdio.h>
int n, m, ans;
int p[200000];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", p + i);
	}
	m = n;
	for (int i = 0; i < n; i++) {
		if (m >= p[i])ans++;
		if (m > p[i])m = p[i];
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 896
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

for i, a in enumerate(s):
    for j, b in enumerate(a):
        flg = False
        if b == "#":
            if 0 <= i - 1:
                if s[i-1][j] == "#":
                    flg = True
            if 0 <= j - 1:
                if s[i][j-1] == "#":
                    flg = True
            if i + 1 <= h-1:
                if s[i+1][j] == "#":
                    flg = True
            if j + 1 <= w-1:
                if s[i][j+1] == "#":
                    flg = True
        else:
            continue
        if not flg:
            print("No")
            exit()
else:
    print("Yes")


Measured memory_bytes: 39536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);
		int n=stdin.nextInt();
		int x=stdin.nextInt();
		int sum=0;
		int y=0;
		int min=10000;
		for(int i=0;i<n;i++) {
			y=stdin.nextInt();
			sum=sum+y;
			if(y<min) {
				min=y;
			}
		}
		System.out.println(n+(x-sum)/min);
		

	}

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,m,n) for(ll i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back



ll kaijou(ll x, ll n){
    ll tmp=1;
    rep(i,n){
        tmp*=x;
        tmp%=MOD;
    }
    return tmp;

}





int main(){

    int n;
    cin>>n;

    ll zeronasi=kaijou(9,n);
    ll bothnasi=kaijou(8,n);

    ll zenbu=kaijou(10,n);

    ll answer=zenbu-(2*zeronasi-bothnasi);

    while (answer<0){
        answer+=MOD;
    }


    answer%=MOD;

    cout<<answer<<endl;





}

Measured memory_bytes: 3616
import java.util.*;
import java.math.*;

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

	int count = 0;
	int sum = 0;
	double average = 0;
	while(sc.hasNext()){
	    count++;
	    String[] line = sc.next().split(",");
	    int money = Integer.parseInt(line[0]);
	    int num = Integer.parseInt(line[1]);

	    sum += money*num;
	    average += num;
	}

	average = average/count;
	BigDecimal bi = new BigDecimal(String.valueOf(average));
	average = bi.setScale(0,BigDecimal.ROUND_HALF_UP).doubleValue();

	System.out.println(sum);
	System.out.println((int)average);
    }
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
//for(int i=0;i<n;i++)

int main(){
  long long h, w;
  cin >> h >> w;
  
  if(h==1||w==1) cout << 1 << endl;
  else cout << (h*w+1)/2 << endl;
  return 0;
}


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

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
const int MOD = 1000000007;

typedef long long ll;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll LCM(ll x, ll y)
{
    return x * y / GCD(x, y);
}

using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main()
{
    ll n;
    cin >> n;
    ll i = floor(sqrt(n));
    ll ans = 0;
    while (true) {
        if (n % i == 0) {
            ll j = n / i;
            ans = i + j - 2;
            break;
        }
        i--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
def find_min_moves_num(N, X):
        X.sort()
        D = []
        for i in range(len(X) - 1):
                D.append(X[i + 1] - X[i])
        D.sort()
        min_moves = 0
        for i in range(len(D) - (N - 1)):
                min_moves += D[i]
        return min_moves


N, _ = [int(v) for v in input().split()]
X = [int(v) for v in input().split()]
print(find_min_moves_num(N, X))

Measured memory_bytes: 13832
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    string s;
    cin >> s;
    bool f = 0;
    rep(i, 3) if(s[i] == s[i+1]) f = 1;
    cout << (f ? "Bad" : "Good") << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K;
	cin >> N >> K;

	if (K>(N-1)*(N-2)/2) {
		cout << -1 << "\n";
	}
	else {
		Int M = (N - 1) + ((N - 1) * (N - 2) / 2 - K);
		Int len = (N - 1) * (N - 2) / 2 - K;

		cout << M << "\n";

		for (Int i = 0; i < N-1; i++) {
			cout << 1<<" "<<i+2 << "\n";
		}

		Int cnt = 0;
		Int s = 2;
		Int g = 3;
		while (cnt<len) {
			cout << s<<" "<<g << "\n";
			if (g==N) {
				s++;
				g = s + 1;
				cnt++;
				continue;
			}
			else {
				g++;
				cnt++;
				continue;
			}
		}
		
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  int a, b, c;
  cin >> a >> b >> c;
  int ma = max(a, max(b, c));
  cout << a + b + c - ma << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
a = int(S[:2])
b = int(S[2:])

if a > 12:
	if b > 12:
		print("NA")
	elif b > 0:
		print("YYMM")
	else:
		print("NA")

if 0 < a <= 12:
	if b > 12 or b == 0:
		print("MMYY")
	else:
		print("AMBIGUOUS") 

if a == 0:
	if b > 12:
		print("NA")
	elif 0 < b <= 12:
		print("YYMM")
	else:
		print("NA")

Measured memory_bytes: 3064
n,k=map(int,input().split())
s=input()
if s[k-1]=='A':
    if k>1:
        print(s[0:k-1]+'a'+s[k:n])
    else:
        print('a'+s[k:n])
elif s[k-1]=='B':
    if k>1:
        print(s[0:k-1]+'b'+s[k:n])
    else:
        print('b'+s[k:n])
else:
    if k>1:
        print(s[0:k-1]+'c'+s[k:n])
    else:
        print('c'+s[k:n])

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int m[55],p[55];
long long v[55];
int siz[55];
int t[55];
bool cmp(const int &x,const int &y)
{
	return v[x]*siz[y]<v[y]*siz[x];
}
long long dp[202020];
void getmin(long long &a,long long b)
{
	if(a==-1)
		a=b;
	else
		a=min(a,b);
}
int main()
{
	int n,x,d,nn,cnt,h,ns;
	long long nv,now,ans=0;
	long long nowv;
	scanf("%d%d%d",&n,&x,&d);
	scanf("%d",&m[1]);
	for(int i=2;i<=n;i++)
		scanf("%d%d",&m[i],&p[i]);
	memset(siz,0,sizeof(siz));
	memset(v,0,sizeof(v));
	for(int i=n;i>=1;i--)
	{
		siz[i]++;
		v[i]+=m[i];
		if(i>1)
		{
			siz[p[i]]+=siz[i];
			v[p[i]]+=v[i];
		}
	}
	for(int i=1;i<=n;i++)
		t[i]=i;
	sort(t+1,t+1+n,cmp);
	nn=n*n*n;
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	for(int ii=1;ii<=n;ii++)
	{
		int i=t[ii];
		if(i==1)
			cnt=n;
		else
			cnt=min(n,d);
		for(int j=0;cnt;j++)
		{
			if(cnt>=(1<<j))
				h=(1<<j);
			else
				h=cnt;
			nv=v[i]*h;
			ns=siz[i]*h;
			cnt-=h;
			for(int k=nn;k>=ns;k--)
				if(dp[k-ns]!=-1)
					getmin(dp[k],dp[k-ns]+nv);
		}
	}
	for(int i=0;i<=nn;i++)
		if(dp[i]!=-1&&dp[i]<=x)
		{
			now=i;
			nowv=x-dp[i];
			for(int jj=1;jj<=n;jj++)
			{
				int j=t[jj];
				h=nowv/v[j];
				if(j!=1)
					h=min(h,max(d-n,0));
				now+=siz[j]*h;
				nowv-=h*v[j];
			}
			ans=max(now,ans);
		}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
long long i,n,a[3009],d[3009][3009];
bool b[3009][3009];
long long dp(int l,int r){
    if(l==r) return d[l][r]=a[l];
    if(b[l][r]) return d[l][r];
    b[l][r]=1;
    d[l][r]=max(a[l]-dp(l+1,r),a[r]-dp(l,r-1));
    return d[l][r];
}
int main()
{
    cin>>n;
    for(i=0;i<n;i++) cin>>a[i];
    cout<<dp(0,n-1);
    return 0;
}


Measured memory_bytes: 78592
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] cnt = new int[101];
		int max = 0;
		while(sc.hasNext()){
			int num = sc.nextInt();
			cnt[num]++;
			if(max < cnt[num]) max = cnt[num];
		}
		for (int i = 0; i < cnt.length; i++) {
			if (max == cnt[i]) System.out.println(i);
		}
	}
}

Measured memory_bytes: 26016
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int i_index;
int tmp;
int main(){
    cin >> N;
    int T; cin >> T;
    int t[N];
    rep(i, N) cin >> t[i];
    rep(i, N - 1){
        if(t[i + 1] - t[i] >= T)
            ans += T;
        else
            ans += t[i + 1] - t[i];
    }
    ans += T;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
public class Main {
    static java.util.Scanner scanner = new java.util.Scanner(System.in);
 
    public static void main(String[] args) {
        int n = scanner.nextInt(), m = scanner.nextInt(), c = scanner.nextInt();
        int[] b = new int[m];
        for (int i = 0; i < m; i++)
            b[i] = scanner.nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < m; j++) {
                sum += (b[j] * scanner.nextInt());
            }
            sum += c;
            if (sum > 0) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(auto& x: A) cin >> x;

    unordered_map<ll, ll> mp;
    for(auto& x: A) mp[x]++;
    
    ll sum = 0;
    for(auto& p: mp) sum += p.second * (p.second-1) / 2;

    for(auto& x: A) cout << sum - mp[x] + 1 << endl;
}

Measured memory_bytes: 10568
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll h(vll f,vll p,ll n,ll x){
  if(x==1&&n==0){
    return 1;
  }
  else if(x==1){
    return 0;
  }
  else if(x<2+f[n-1]){
    return h(f,p,n-1,x-1);
  }
  else if(x==(2+f[n-1])){
    return 1+p[n-1];
  }
  else if(x<3+2*f[n-1]){
    return p[n-1]+1+h(f,p,n-1,x-2-f[n-1]);
  }
  else if(x==3+2*f[n-1]){
    return 2*p[n-1]+1;
  }
}
  
int main(){
  ll n,x;
  cin>>n>>x;
  vll f(51);
  vll p(51);
  f[0]=1;
  p[0]=1;
  for(int i=1;i<51;i++){
    f[i]=f[i-1]*2+3;
    p[i]=p[i-1]*2+1;
  }
  COUT(h(f,p,n,x));
}


Measured memory_bytes: 256
N = int(input())

ans = 0
for i in range(N):
  ans += i+1

fizz = 0
for i in range(N//3):
  fizz += i+1
fizz = fizz*3

buzz = 0
for i in range(N//5):
  buzz += i+1
buzz = buzz*5

fizzbuzz =0
for i in range(N//15):
  fizzbuzz += i+1
fizzbuzz = fizzbuzz*15

print(ans - fizz - buzz + fizzbuzz)

Measured memory_bytes: 9196
n=int(input())
a=list(map(int,input().split()))

#print(a)
c=-100
for i in range(n):
    if(c<a[i]):
        c=a[i]-1
    elif(c==a[i]):
        c=a[i]
    else:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 14396
#include<stdio.h>
#include<string.h>

int main(void){
  int n, i, ac, wa, tle, re;
  ac = 0;
  wa = 0;
  tle = 0;
  re = 0;
  char input[256];

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%s",input);
    if(input[0] == 'A'){
      ac++;
    }else if(input[0] == 'W'){
      wa++;
    }else if(input[0] == 'T'){
      tle++;
    }else{
      re++;
    }
  }
  

  printf("AC x %d\n",ac);
  printf("WA x %d\n",wa);
  printf("TLE x %d\n",tle);
  printf("RE x %d\n",re);

  return 0;
}


Measured memory_bytes: 1732
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,k,i,ans=1,a,b;
    cin >> n >> k;
    for(i=0;i<n;i++){
        a = ans * 2;
        b = ans + k;
        ans = min(a,b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <vector>
using namespace std;

int main() {
  while(1) {
    int a, b;
    cin >> a >> b;
    if(a == 0 && b == 0) break;
    int otsuri = b - a;

    int sum1000 = 0;
    int sum500 = 0;
    int sum100 = 0;
    sum1000 += otsuri/1000;
    otsuri %= 1000;
    sum500 += otsuri/500;
    otsuri %= 500;
    sum100 += otsuri/100;
    otsuri %= 100;

    cout << sum100 << ' ' << sum500 << ' ' << sum1000 << endl;


  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int x,hp=0,y;
    cin>>x;
    while(x>=5){
        if(x>=500){
            x=x-500;
            hp+=1000;
        }
        else{
            y=x/5;
            x=x-5*y;
            hp+=y*5;
        }
        
    }
    cout<<hp;
        
    
}


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

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

    ll right = powl(x, 1.0 / 5.0) + 100;
    for (ll i = -right; i <= right; i++)
    {
        long long pw = powl(i, 5);
        ll jdz = pw - x;
        if (jdz < 0)
        {
            jdz = -jdz;
        }
        long long b = powl(jdz, 1.0 / 5.0);
        if (powl(b, 5) == pw - x)
        {
            cout << i << " " << b << endl;
            return 0;
        }
        else if (powl(-b, 5) == pw - x)
        {
            cout << i << " " << -b << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3652
import sys
readline = sys.stdin.readline

N = int(readline())
S = readline().rstrip()

R, G, B = 'R', 'G', 'B'

nr, ng, nb = (S.count(v) for v in (R, G, B))

ans = nr * ng * nb

for w in range(1, N // 2 + 1):
    for i in range(N):
        if i + 2*w >= N:
            break
        if S[i] != S[i + w] and S[i + w] != S[i + 2*w] and S[i + 2*w] != S[i]:
            ans -= 1

print(ans)

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

void getMax(char max[],int i){
    int j;
    char tmp;
    for(j=i;j>0;j--){
        if(max[j]>max[j-1]){
            tmp=max[j];
            max[j]=max[j-1];
            max[j-1]=tmp;
        }
        else break;
    }
}
void getMin(char min[],int i){
    int j;
    char tmp;
    for(j=i;j>0;j--){
        if(min[j]<min[j-1]){
            tmp=min[j];
            min[j]=min[j-1];
            min[j-1]=tmp;
        }
        else break;
    }
}
void differential(){
    int i;
    char max[9],min[9];
    char c;
    for(i=0;i<8;i++){
        scanf(" \n%c",&c);
        max[i]=min[i]=c;
        getMax(max,i);
        getMin(min,i);
    }
    max[i]=min[i]='\0';
    printf("%d\n",atoi(max)-atoi(min));
}
int main(){
    int i;
    
    int n;
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        differential();
    }
    
    return 0;
}


Measured memory_bytes: 2024
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[] strings = new String[10];
        int n = 0;
        String buf;
        while(!(buf = sc.next()).equals("-")){
            int m = sc.nextInt();
            for(int i = 0; i < m; i++){
                buf = shuffle(buf, sc.nextInt());
            }
            strings[n] = buf;
            n++;
        }
        for(int i = 0; i < n; i++){
            System.out.println(strings[i]);
        }
    }

    public static String shuffle(String str, int h){
        return new StringBuilder().append(str.substring(h)).append(str.substring(0, h)).toString();
    }
}



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

int main() {
  int A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;
  if(X<Y) cout<<min({A*X+B*Y,2*C*X+B*(Y-X),2*C*Y})<<endl;
  else if(Y<X) cout<<min({A*X+B*Y,2*C*Y+A*(X-Y),2*C*X})<<endl;
  else cout<<min(A*X+B*Y,2*C*X)<<endl;
}

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

using namespace std;

int main (int argc, char const* argv[]){
    int a1,a2,a3,a4,b1,b2,b3,b4;
    int hit=0, blow=0, input;
    vector<int> A(4), B(4);
    
    while(cin >> A[0]>> A[1]>> A[2]>> A[3]){
        cin >> B[0]>> B[1]>> B[2]>> B[3];
        
        hit=0, blow=0;
        
        //count hit 
        for(int i=0;i<4;i++){
            if(A[i]==B[i]) hit++;
        }
        //count blow
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                if(A[i]==B[j])blow++;
            }
        }
        blow -= hit;
        A.clear();
        B.clear();
        
        cout << hit <<" " <<blow << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int a,b;
	while(cin>>a>>b)
	{
		cout<<a*b-(a+b-1)<<endl;	
	} 
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long 
#define inf 1000000007 
#define sort(vec) sort((vec).begin(),(vec).end());
#define rever(vec) reverse((vec).begin(),(vec).end());
#define unsort(vec) sort((vec)); rever((vec));
using namespace std;

int main() {
	ll n;
	cin>>n;
	vector<string>vec(n);
	for(ll i=0;i<n;i++) {
		cin>>vec[i];
	}
	bool ans=true;
	for(ll i=0;i<n-1;i++) {
		string a=vec[i];
		string b=vec[i+1];
		if(a[a.size()-1]!=b[0]) {
			ans=false;
			break;
		}
	}
	for(ll i=0;i<n;i++) {
		for(ll j=0;j<n;j++) {
			if(i!=j) {
				if(vec[i]==vec[j]) {
					ans=false;
				}
			}
		}
	}
	if(ans) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int a, b, c = 0;
	while(cin >> a >> b && (a || b))
	{
		if(c++) cout << endl;

		int flag = 0;
		REP(i, a, b + 1)
			if((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
				cout << (++flag ? i : 0 ) << endl;

		if(!flag)
			cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
import itertools
N, M = map(int, input().split())
e = set([])
for i in range(M):
    a, b = map(int, input().split())
    e.add((a, b))
ans = 0
for i in list(itertools.permutations(range(2, N + 1))):
    a = 1
    for b in i:
        if (a, b) in e or (b, a) in e:
            a = b
            continue
        break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 40304
#include<stdio.h>

int main(){
  int n;
  int i,j;
  int sum;
  int min,mink = -1 ,dif1=0, dif2=0;
  sum = 0;

  scanf("%d",&n);

  if(n<2 || n>100){
    return 0;
  }

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

    sum += a[i];
  }

  for(i=0;i<n;i++){
      dif1 =0, dif2 = 0;
    for(j=0;j<=i;j++){
       dif1 += a[j];
    }
    dif2 = sum - dif1;

    if(dif2 > dif1)
      min = dif2 - dif1;
    else{
      min = dif1 - dif2;
    }

    if(mink == -1){
      mink = min;
    }else if(mink > min){
      mink = min;
    }
  }

  printf("%d",mink);
  return 0;
}


Measured memory_bytes: 128
X = int(input())
a = [100, 101, 102, 103, 104, 105]
dp = [[False]*100010 for _ in range(10)]
dp[0][0] = True

for j in range(X+1):
    for i in range(6):
        dp[i+1][j] |= dp[i][j]
        if j >= a[i]:
            dp[i+1][j] |= dp[i][j-a[i]]
            dp[i+1][j] |= dp[i+1][j-a[i]]
if dp[6][X]:
    print(1)
else:
    print(0)

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

string s;
int ans;

int main() {
	cin >> s;
	for (int i = 1; i <= 4; i++) {
		if (s[i - 1] == s[i]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

# from numba import njit
from math import gcd
from functools import reduce
# input = stdin.readline

# @njit
def solve(n,a):
  ans = reduce(gcd,a)
  return ans



def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  print(solve(N,a))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 20516
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin >> N;
    cout << 800 * N - 200 * (N / 15) << "\n";
}

Measured memory_bytes: 256
import sys

def solve():
    dx = (-1, 0, 1, 0,)
    dy = (0, -1, 0, 1,)

    while 1:
        N = int(sys.stdin.readline().rstrip())

        if N == 0:
            return

        pos = [None] * N
        pos[0] = (0, 0)

        top = 0
        btm = 0
        left = 0
        right = 0

        for i in range(N - 1):
            ni, di = map(int, sys.stdin.readline().split())
            x, y = pos[ni]
            x += dx[di]
            y += dy[di]
            pos[i + 1] = (x, y)
            top = max(top, y)
            btm = min(btm, y)
            left = min(left, x)
            right = max(right, x)

        print(right - left + 1, top - btm + 1)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 7680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

ll dp[2001][2001];

template <class T>
void chmax(T &a, T b) {
    if (b > a) a = b;
}

struct P {
    bool operator<(const P& p) const {
        return a > p.a;
    }
    int a, i;
};

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

    int n;
    cin >> n;

    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        p[i] = { a, i };
    }
    sort(p.begin(), p.end());

    for (int k = 0; k < n; k++) {
        for (int i = 0; i <= k; i++) {
            int j = k - i;
            chmax(dp[i][j + 1], dp[i][j] + (ll)p[k].a * (n - 1 - j - p[k].i));
            chmax(dp[i + 1][j], dp[i][j] + (ll)p[k].a * (p[k].i - i));
        }
    }

    ll r = 0;
    for (int i = 0; i <= n; i++) {
        chmax(r, dp[i][n - i]);
    }

    cout << r << endl;

    return 0;
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,t,d[3001];
pair<int,int> a[3001];

void nhap()
{
    scanf("%d %d",&n,&t);
    for (int i=1;i<=n;++i)
    {
        scanf("%d %d",&a[i].first,&a[i].second);
    }
    sort(a+1,a+1+n);
    t--;
}

void process()
{
    int ma=0;
    for (int i=1;i<=n;++i)
    {
        ma=max(ma,d[t]+a[i].second);
        for (int j=t;j>=0;--j)
        {
            if (j-a[i].first>=0)
            {
                d[j]=max(d[j],d[j-a[i].first]+a[i].second);
            }
        }
    }
    cout<<ma;
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 256