akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int a[10001];
int main() {
	int n,c;
	cin>>n;
	
	for (int i=1;i<=n;i++){
		int s=(i*i);
		if (s>=n) continue;
		for (int j=1;j<=n;j++){
			s=(i*i)+(j*j);
			if (s>=n) continue;
			for (int k=1;k<=n;k++){
				s=(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(k*i);
				
				if (s>n){
					break;
				}
				a[s]=a[s]+1;
			}
		}
	}
	for (int i=1;i<=n;i++){
		cout<<(a[i])<<endl;
	}
	
	return 0;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

// 空白がある位置を二分探索で絞り込んでいく
int main(){
    ll n; cin >> n;
    vector<string> mw(n);

    cout << 0 << endl;
    cin >> mw[0];
    if(mw[0] == "Vacant") return 0;
    cout << n-1 << endl;
    cin >> mw[n-1];
    if(mw[n-1] == "Vacant") return 0;

    ll l = 0, r = n-1;
    for(ll i=0; i<20; i++){
        ll mid = (l+r)/2;
        cout << mid << endl;
        cin >> mw[mid];
        if(mw[mid] == "Vacant") return 0;
        if((((mid-l+1)%2 == 0) && (mw[l] == mw[mid])) || (((mid-l+1)%2 == 1) && (mw[l] != mw[mid]))) r = mid;
        else l = mid;
    }
    return 0;
}

Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int main()
{
    while(cin>>s)
    {
        int n = s.size();
        ll ans=0;
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='A')
            {
                cnt++;
                if(i+2<n && s[i+1]=='B' && s[i+2] == 'C')
                {
                     ans+=cnt;
                     s[i+2]='A';
                     i+=1;
                     cnt--;
                }
            }
            else
            {
                cnt=0;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
int main(){ 
	int k; cin >> k;
	int lcm = 360 * k / __gcd(360, k);
	cout << lcm / k << endl; 
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define PB push_back
#define LL long long
const int mod = 924844033;
using namespace std;
int mult(int a , int b)
{
	return (a * (LL)b) % mod;
}
void Add(int &a , int b)
{
	a = a + b >= mod ? a + b - mod : a + b;
}
int add(int a , int b)
{
	return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a , int b)
{
	return a - b < 0 ? a - b + mod : a - b;
}
int fact[2005];
int c[2005][2005];
void init()
{
	fact[0] = 1;
	for(int i = 1; i <= 2000; i++)
	{
		fact[i] = mult(fact[i - 1] , i);
	}
	for(int i = 0; i <= 2000; i++)
	{
		c[i][0] = 1;
		for(int j = 1; j <= i; j++)
			c[i][j] = add(c[i - 1][j] , c[i - 1][j - 1]);
	}
}
int dp[2002][2002][4];
int main()
{
	ios_base::sync_with_stdio(0);
	init();
	int n ,k;
	cin >> n >> k;
	
	if(k <= n / 2)
	{	
		int ans = fact[n];
		vector<int> idx;
		for(int i = 0; i < k; i++)
		{
			for(int j = i; j < n; j += k)
			{
				idx.PB(j);
			}
		}
		idx.PB(-1);
		dp[0][0][0] = 1;
		for(int i = 0; i < n; i++)
		{
			for(int k = 0; k <= i; k++)	
			{
				for(int mask = 0; mask < 4; mask++)
				{
					int newMask = mask >> 1;
					if(idx[i + 1] < idx[i])
						newMask = 0;
					Add(dp[i + 1][k][newMask] , dp[i][k][mask]);
					if(idx[i + 1] >= idx[i])
						Add(dp[i + 1][k + 1][newMask | 2] , dp[i][k][mask]);
					if(!(mask & 1) && i && idx[i] >= idx[i - 1])
						Add(dp[i + 1][k + 1][newMask] , dp[i][k][mask]);
				}
			}
		}
			
		for(int i = 1; i <= n; i++)
		{
			if(i % 2)
				ans = sub(ans  , mult(fact[n - i] , dp[n][i][0]));
			else
				ans = add(ans  , mult(fact[n - i] , dp[n][i][0]));
		}
		cout << ans;

		return 0;
	}
	int ans = fact[n];
	int cnt = 2 * (n - k);

	//cout << ans << endl;
	for(int i = 1; i <= cnt; i++)
	{
		if(i % 2)
			ans = sub(ans  , mult(fact[n - i] , c[cnt][i]));
		else
			ans = add(ans  , mult(fact[n - i] , c[cnt][i]));
		//cout << ans << endl;
	}
	cout << ans;
}

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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}
double distance(double x1, double y1, double x2, double y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> a(n);
    for (size_t i = 0; i < n; i++)
    {
        int b, c;
        cin >> b >> c;
        a[i] = {b, c};
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    int bought = 0;
    for (size_t i = 0; i < n; i++)
    {
        if (bought + a[i].second >= m)
        {
            ans += a[i].first * (m - bought);
            break;
        }
        else
        {
            ans += a[i].first * a[i].second;
            bought += a[i].second;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int N; cin >> N;
    bool res = true;
    int t = 0, x = 0, y = 0;
    for (int i = 0; i < N; ++i) {
        int nt, nx, ny; cin >> nt >> nx >> ny;
        int dist = abs(x - nx) + abs(y - ny);
        if (nt - t < dist) res = false;
        if ((nt - t) % 2 != dist % 2) res = false;
        t = nt, x = nx, y = ny;
    }
    cout << (res ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Data.List (group)

main :: IO ()
main = getLine >> solve <$> map read <$> words <$> getLine >>= print

solve :: [Int] -> Int
solve xs | null os = 1
         | otherwise = (+1) . maximum . map length $ os
  where os = filter ((== 1) . head) . group $ xs



Measured memory_bytes: 4164
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
typedef pair<ll,ll> p; 

int main() {
    ll k,x;
  cin>>k>>x;
  if(500*k >= x)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
using ll = long long;

template <class T>
ostream& operator <<(ostream& os, vector<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

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


int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    const int bucket_size = ceil(sqrt(100000));
    int N;
    cin >> N;
    V<V<int>> bucket_list;
    V<int> cur_bucket;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        cur_bucket.emplace_back(tmp);
        if ((int)cur_bucket.size() == bucket_size) {
            bucket_list.emplace_back(cur_bucket);
            cur_bucket.clear();
        }
    }
    if (cur_bucket.size()) bucket_list.emplace_back(cur_bucket);
    V<int> gcd_in_bucket;
    int num_buckets = bucket_list.size();
    for (int i = 0; i < num_buckets; i++) {
        int cur_gcd = 0;
        for (int j = 0; j < bucket_list.at(i).size(); j++) {
            cur_gcd = gcd(bucket_list.at(i).at(j), cur_gcd);
        }
        gcd_in_bucket.emplace_back(cur_gcd);
    }
    int max_gcd = 0;
    for (int bucket_idx = 0; bucket_idx < num_buckets; bucket_idx++) {
        max_gcd = gcd(gcd_in_bucket.at(bucket_idx), max_gcd);
    }

    for (int bucket_idx = 0; bucket_idx < num_buckets; bucket_idx++) {
        int gcd_from_other_buckets = 0;
        for (int other_bucket_idx = 0; other_bucket_idx < num_buckets; other_bucket_idx++) {
            if (other_bucket_idx == bucket_idx) continue;
            gcd_from_other_buckets = gcd(gcd_in_bucket.at(other_bucket_idx), gcd_from_other_buckets);
        }
        for (int idx_of_ignored = 0; idx_of_ignored < bucket_list.at(bucket_idx).size(); idx_of_ignored++) {
            int cur_gcd = gcd_from_other_buckets;
            for (int other_idx = 0; other_idx < bucket_list.at(bucket_idx).size(); other_idx++) {
                if (other_idx == idx_of_ignored) continue;
                cur_gcd = gcd(bucket_list.at(bucket_idx).at(other_idx), cur_gcd);
            }
            max_gcd = max(max_gcd, cur_gcd);
        }
    }
    cout << max_gcd << "\n";
}


Measured memory_bytes: 640
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    string s;
    cin >> s;

    bool ans = true;
    sort(s.begin(), s.end());

    if (s == "abc"s) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
#define  fi first
#define  se second 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int dx[4]={-1,0,1,0}, dy[4]={0,-1,0,1} ,INF=1e9+9;


int main()
{
    string s,t;
    cin>>s>>t;
    for(int i=s.size()-t.size();i>=0;i--){
        int j=0;
        for(j=0;j<t.size();j++)if(s[i+j]!=t[j]&&s[i+j]!='?')break;
        if(j==t.size()){
            for(int k=0;k<t.size();k++) s[i+k]=t[k];
            rep(i,s.size()) if(s[i]=='?')s[i]='a';
            cout<<s<<endl;
            exit(0);
        }
    }
    cout<<"UNRESTORABLE\n";

    return 0;
}

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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileRead freopen("input.txt", "r", stdin);
#define fileWrite freopen("output.txt", "w", stdout);

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}

//-------------------------------------------------------------------\\

int main()
{
    
    int n;
    cin>>n;
    ll sum=0;
    map<int,ll>m;
    for0(i,n) {
        int x; cin>>x;
        sum+=x;
        m[x]++;
    }

    int q; cin>>q;
    while(q--){
        int x,y; cin>>x>>y;
        sum-=m[x]*x;
        sum+=y*m[x];
        m[y]+=m[x];
        m[x]=0;
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 9444
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

int x[1001], n;
vector<int> child[1001];

int d[1001];
int up[1001];
int dd[2][5001];

void dfs(int u) {
  if (child[u].empty()) {
    up[u] = 0;
    return;
  }
  for (int i = 0; i < child[u].size(); i++)
    dfs(child[u][i]);
  memset(dd[0],(1<<29),sizeof(int)*5001);
  memset(dd[1],(1<<29),sizeof(int)*5001);
  dd[1][0] = 0;
  int from = 1, to = 0;
  for (int i = 0; i < child[u].size(); i++) {
    int w1 = up[child[u][i]], w2 = x[child[u][i]];
    //cout << "w1,w2:" << w1 << "," << w2 << endl;
    for (int j = 0; j <= x[u]; j++) {
      dd[to][j] = (1 << 29);
      if (j >= w1 && dd[to][j] > dd[from][j - w1] + w2){
        dd[to][j] = dd[from][j - w1] + w2;
        //cout << "d1" << endl;
        //cout << u << ":" << j << ":" << dd[to][j] << endl;
      }
      if (j >= w2 && dd[to][j] > dd[from][j - w2] + w1){
        dd[to][j] = dd[from][j - w2] + w1;
        //cout << "d2" << endl;
        //cout << u << ":" << j << ":" << dd[to][j] << endl;
      }
    }
    from ^= 1; to ^= 1;
  }
  int ret = (1 << 30);
  //cout << "dd: " ;
  for (int j = 0; j <= x[u]; j++){
    //cout << dd[from][j] << " ";
    if (dd[from][j] < ret) ret = dd[from][j];
  }
  //cout << endl;
  up[u] = ret;
  //cout << "up[u]:" << up[u] << endl;
}

int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    child[p].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    scanf("%d", &x[i]);
  memset(d, -1, sizeof(d));
  dfs(1);
  if (up[1] == (1 << 29)) puts("IMPOSSIBLE");
  else puts("POSSIBLE");
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int n,m;
  int i,j,k;
  int mat[100][100]={{}};
  int ve[100]={};
  cin >> n >> m;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      cin >> mat[i][j];
    }
  }
  for(j=0;j<m;j++) cin >> ve[j];
  for(i=0;i<n;i++){
    int x=0;
    for(j=0;j<m;j++) x+=mat[i][j]*ve[j];
    cout << x << endl;		       
  }
  
  return 0;
}


Measured memory_bytes: 3152
from collections import Counter
N=int(input())
C=list(input())

# RRRRWWWW ok
count=Counter(C)
ws=count["W"]
rs=count["R"]

outws=0
outrs=0
for i in range(N):
    c=C[i]
    if c=="R":
        if not 0<=i<rs:
            outrs+=1
    else:
        if 0<=i<rs:
            outws+=1

ans=max(outrs, outws)
print(ans)

Measured memory_bytes: 83684
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(n: int, a: int, b: int):
    return (pow(2, n, MOD) - 1 - mod_combination(MOD, n, a) - mod_combination(MOD, n, b)) % MOD

def mod_range(mod, start, stop=None, step=1):    
    if stop == None:
        stop = start
        start = 0
    return map(lambda i: i % mod, range(start, stop, step))

def mod_inv(mod, n):
    '''
    >>> mod_inv(3, 2)
    2
    >>> mod_inv(1000000007, 2)
    500000004
    '''
    return pow(n, mod-2, mod)

def mod_permutation(mod, n, r):
    '''
    >>> mod_permutation(1000000007, 10, 2)
    90
    >>> mod_permutation(7, 10, 2)
    6
    '''
    m = 1
    for i in mod_range(mod, n-r+1, n+1):
        m = (m * i) % mod
    return m

def mod_factorial(mod, n):
    '''
    >>> mod_factorial(1000000007, 10)
    3628800
    >>> mod_factorial(7, 6)
    6
    '''
    return mod_permutation(mod, n, n)

def mod_combination(mod, n, r):
    '''
    >>> mod_combination(1000000007, 10, 2)
    45
    >>> mod_combination(7, 10, 2)
    3
    '''
    return mod_permutation(mod, n, r) * mod_inv(mod, mod_factorial(mod, r)) % mod

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    print(solve(n, a, b))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  unordered_map<int, int> mp;
  rep(i, 3) {
    mp[a[i]]++;
  }
  YORN(mp[5] == 2 && mp[7] == 1);
  return 0;
}

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

using ll = long long;
using ii = pair<int, int>;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll a, b, c, d;

  cin >> a >> b >> c >> d;

  ll ans = LLONG_MIN;

  ans = max(ans, max(a * c, a * d));
  ans = max(ans, max(b * c, b * d));

  cout << ans << endl;

  return 0;
}


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

// 基本テンプレート
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// 型
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// 定数
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
#define int ll
    int n;
    cin >> n;
    int a=1;
    int b=1;
    rep(i,n) {
        int x, y;
        cin >> x >> y;
        int n = max(a/x+(a%x>0), b/y+(b%y>0));
        a = x*n;
        b = y*n;
    }
    cout << a +  b << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv){
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int a,b; cin >> a >> b;
	if(a==1 && b==2)out(3);
	if(a==2 && b==1)out(3);
	if(a==1 && b==3)out(2);
	if(a==3 && b==1)out(2);
	if(a==2 && b==3)out(1);
	if(a==3 && b==2)out(1);

}




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

int main(){
    int c = 0;
    while(1){
        int n; cin >> n;
        if(n == 0) break;
        if(c > 0) cout << endl;
        int coin[4];
        cin >> coin[0] >> coin[1] >> coin[2] >> coin[3];
        int sum = 10*coin[0] + 50*coin[1] + 100*coin[2] + 500*coin[3];
        sum -= n;
        //cout << "sum " << sum << endl;
        //500???
        coin[3] -= sum / 500;
        sum %= 500;

        //100???
        coin[2] -= sum / 100;
        sum %= 100;

        //50???
        coin[1] -= sum / 50;
        sum %= 50;

        //10???
        coin[0] -= sum / 10;

        if(coin[0] > 0) cout << 10 << " " << coin[0] << endl;
        if(coin[1] > 0) cout << 50 << " " << coin[1] << endl;
        if(coin[2] > 0) cout << 100 << " " << coin[2] << endl;
        if(coin[3] > 0) cout << 500 << " " << coin[3] << endl;
        c++;
    }

    return 0;
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 
int main(){
    int n, m ;
    cin >> n >> m ;
    int ans = 0 ;
    int pen = 0 ;
    vector<vector<string>> str(n) ;
    rep(i, m){
        int p ;
        string s ;
        cin >> p >> s ;
        p-- ;
        str[p].push_back(s) ;
    }
    rep(i, n){
        int f  = str[i].size() ;
        rep(j, f){
            if(str[i][j] == "WA") {
                pen++ ;
            }
            else if (str[i][j] == "AC"){
                ans++ ;
                break ;
            }
            if(j == f - 1){
                pen -= f ;
            }
        }
    }
    cout << ans << " " << pen << endl ;
} 

Measured memory_bytes: 10364
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vii vector<ii>
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define pin(n) in(n.first) >> n.second
#define vin(a, n) for (ll i=0; i<n; ++i) in(a[i])
#define viin(a, n) for (ll i=0; i<n; ++i) in2(a[i].first, a[i].second);
#define out(n) cout << n
#define outs(n) out(n) << ' '
#define outn(n) out(n) << '\n'
#define out2(n, m) cout << n << ' ' << m
#define out2s(n, m) out2(n, m) << ' '
#define out2n(n, m) out2(n, m) << '\n'
#define pout(n) out2(n.first, n.second)
#define pouts(n) pout(n) << ' '
#define poutn(n) pout(n) << '\n'
#define vout(a) for (auto i : a) outs(i)
#define viout(a) for (auto i : a) out2n(i.first, i.second)
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pp(a, b) emplace_back(make_pair(a, b))
#define fori(i, n) for (ll i=0; i<n; ++i)
#define foris(i, a, b) for (ll i=a; i<b; ++i)
#define ford(i, n) for (ll i=n-1; i>=0; --i)
#define fords(i, a, b) for (ll i=a; i>=b; --i)
#define forr(i, a) for (auto i : a)
const int mod = (int)(1e9) + 7;
//endregion
string a, b;
int total;

int main() {
    io();
    in2(a, b);
    fori (i, 3) total += (a[i] == b[i]);
    out(total);
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

vector<int> G[100000];
vector<pii> bridges;
int ord[100000], low[100000];
bool checked[100000];

int k;

void dfs(int v, int p)
{
	checked[v] = true;
	ord[v] = k++;
	low[v] = ord[v];

	for (int i = 0; i != G[v].size(); i++)
	{
		if (!checked[G[v][i]])
		{
			dfs(G[v][i], v);
			low[v] = min(low[v], low[G[v][i]]);
			if (ord[v] < low[G[v][i]])
			{
				bridges.push_back(pii(min(v, G[v][i]), max(v, G[v][i])));
			}
		}
		else if (G[v][i] != p)
		{
			low[v] = min(low[v], ord[G[v][i]]);
		}
	}
}

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

	int V, E;
	scanf("%d %d", &V, &E);

	for (int i = 0; i < E; i++)
	{
		int s, t;
		scanf("%d %d", &s, &t);

		G[s].push_back(t);
		G[t].push_back(s);
	}

	dfs(0, -1);

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

	for (auto& p : bridges)
	{
		printf("%d %d\n", p.first, p.second);
	}
	return 0;
}


Measured memory_bytes: 7236
const lines=readlines()
input()=shift!(lines)
int(x)=parse(Int,x)
intLine()=map(int,split(input()))
function inE(e)
    u,v=intLine()
    push!(e[u],v)
end
function bfs(e,f,s,t)
    q=Array{Int,1}[[s,1]]
    while !isempty(q)
        v,m=shift!(q)
        u=m>2?1:m+1
        for w=e[v]
            if f[w,u]<0
                f[w,u]=f[v,m]+1
                push!(q,[w,u])
            end
        end
    end
end
function main()
    n,m=intLine()
    e=Array{Int,1}[[]for i=1:n]
    for i=1:m;inE(e);end
    s,t=intLine()
    f=ones(Int,(n,3))*-3
    f[s,1]=0
    bfs(e,f,s,t)
    show(f[t,1]÷3)
end
main()

Measured memory_bytes: 166340
import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
l = []
for v in itertools.permutations(list(range(1, n+1))):
    l.append(v)
l = [0] + l
print(abs(l.index(tuple(p))-l.index(tuple(q))))

Measured memory_bytes: 14052
#include <iostream>
#include <vector>
#define lld long long int
#include <map>
using namespace std;
lld counter= 0;
int main() {
	int n ;
	cin >> n;
	vector <lld> heights(n+1,0);
	vector <lld> arr1(n+1,0);
	map <lld,int> arr2;
	for(int ii  = 0; ii < n ;ii++){
	    lld temp;
	    cin >> temp;
	    heights[ii+1] = temp;
	}
	for(int ii  =1; ii < n+1;ii++){
	    arr1[ii] = ii - heights[ii];
	    auto it = arr2.find(ii+ heights[ii]);
	    if(it != arr2.end()){
	        (it->second)++;
	    }
	    arr2.insert(make_pair(ii+ heights[ii],1));
	}
	for(int ii = 1 ;ii < n+1;ii++){
	    lld check = arr1[ii];
	    auto it = arr2.find(check) ;
	    if(it != arr2.end()){
	        counter+= it->second;
	    }
	}
	cout << counter;
	return 0;
}


Measured memory_bytes: 18328
// Problem : E - Sequence Sum
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// $%U%$
// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	ll n,x,m;
	cin >> n >> x >> m;
	vector<ll> ans((int)1e5+10);
	map<ll,ll> mp;
	ans[0]=x;
	mp[x]=1;
	ll re,rs;
	int f=0;
	for(ll i=1;i<n;++i)
	{
		ans[i]=power(ans[i-1],2,m);
		if(mp[ans[i]]!=0)
		{
			re=i-1;
			rs=mp[ans[i]]-1;
			f=1;
			break;
		}
		mp[ans[i]]=i+1;
	}
	if(f==0)
	{
		ll fans=0;
		for(int i=0;i<n;++i)
		fans+=ans[i];
		cout << fans << endl;
		return;
	}
	vector<ll> sum(re+1);
	ll fans=0;
	for(ll i=0;i<=re;++i)
	{
		if(i==0)
		sum[i]=ans[i];
		else
		sum[i]=ans[i]+sum[i-1];
		if(i==rs-1)
		fans+=sum[i];
	}
	n-=rs;
	ll temp;
	if(rs-1>=0)
	temp=sum[re]-sum[rs-1];
	else
	temp=sum[re];
	ll len=(re-rs+1);
	fans+=(n/len)*temp;
	n%=len;
	for(ll i=rs;i<rs+n;++i)
	fans+=ans[i];
	cout << fans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}


Measured memory_bytes: 7384
#include <iostream>

using namespace std;

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

	for (int i = 1; i <= 9; ++i)
		for (int j = 1; j <= 9; ++j)
			cout << i << "x" << j << "=" << i * j << endl;

	return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1, 0, 1, 1, -1, -1}, dx = {1,-1,0,0, 0, 1, -1, 1, -1};
//vector<int> dy = {0, 0, 1, -1}, dx = {1, -1, 0, 0};

int main(void){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    vector<bool> A(100010);
    ll N, M;
    cin >> N >> M;
    ll l, r;
    ll mini = 0, maxi = INF;
    for(int i = 0; i < N; i++){
        cin >> l >> r;
        mini = max(mini, l);
        maxi = min(maxi, r);
    }
    cout << max(maxi - mini + 1, 0LL) << endl;
    
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::vector<long long> A){
    sort(all(A));
    vector<bool> valid(A.back()+1, true);
    int answer = 0;
    rep(i,0,N) {
        if (!valid[A[i]]) continue;
        valid[A[i]] = false;
        if (!(i<N-1 && A[i+1] == A[i])) {
            answer++;
        }
        rep(j,2,INT_MAX) {
            if (A[i] * j > A.back()) break;
            valid[A[i] * j] = false;
        }
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4864
//https://beta.atcoder.jp/contests/tenka1-2018/tasks/tenka1_2018_f
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int N;
int a[2123456];
int *b;
constexpr int mod = 998244353;
vector<int> pos[313245];
int put[312345];
void no(){
    cout<<0<<endl;
    exit(0);
}
int main(){
    cin>>N;
    LL ret = 1;
    for(int i:range(N)){
        int x;
        cin>>x;
        x--;
        a[i]=a[i+N]=a[i+2*N]=a[i+3*N]=x;
    }
    int *b=a;
    for(int i:range(N)){
        if(a[i]!=0&&a[i+1]==0){
            b=a+i+1;
            break;
        }
    }
    b+=N;
    LL del = 0;
    int k=0;
    while(k<N&&b[k]==0)k++;
    if(k==0)no();
    if(k==N){
        for(int i:range(N)){
            ret*=i+1;
            ret%=mod;
        }
        cout<<ret<<endl;
        return 0;
    }
    for(int i:range(N)){
        pos[b[i]].push_back(i);
    }
    for(int i:range(N)){
        int m=pos[i].size();
        for(int j:range(m-1)){
            if(pos[i][j]+1!=pos[i][j+1])no();
        }
        if(m>k)no();
        if(m>0){
            int pre = b[pos[i].front()-1];
            int nxt = b[pos[i].back()+1];
            if(m==k){
                put[i]=pos[i].front();
            }
            else{
                if(pre<i&&nxt<i){
                    put[i]=pos[i].front();
                    ret*=put[i]-max(put[pre],pos[i].back()-k);
                    ret%=mod;
                }
                else if(pre<i){
                    put[i]=pos[i].back()-k+1;
                }
                else if(nxt<i){
                    put[i]=pos[i].front();
                }
                else no();
            }
            if(pre<i){
                del+=put[i]-put[pre]-1;
            }
            if(nxt<i){
                del+=(N+put[nxt]-put[i])%N-1;
            }

        }
        else{
            ret*=del;ret%=mod;
            del--;
            if(ret==0)no();
        }
        //cout<<del<<" "<<ret<<endl;
    }
    //cout<<0<<endl;
    //return -1;
    cout<<ret<<endl;

    return 0;
}

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

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

    if (b < c)
        puts("0");
    else if (d < a)
        puts("0");
    else
    {
        vector<int> s = {a, b, c, d};
        sort(s.begin(), s.end());
        cout << s[2] - s[1];
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

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

    vector<ll> A(N);
    ll ans=0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        ans+=A[i];
    }
    vector<ll> mi(N);
    for(int i=0;i<N;i++) mi[i]=A[i];

    for(int k=0;k<N;k++){
        ll tmp=x*k;
        for(int i=0;i<N;i++){
            mi[i]=min(mi[i],A[(i-k+N)%N]);
            tmp+=mi[i];
        }
        ans=min(ans,tmp);
    }
    cout << ans << endl;

    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll K, N;
  cin >> K >> N;
  vector<ll> a(N+1);
  rep(i, N)
    cin >> a[i];
  a[N] = a[0] + K;
  ll m = -1;
  rep(i, N+1) {
    chmax(m, a[i+1]-a[i]);
  }
  cout << (K-m) << endl;
  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>

using namespace std;
int main() {
	int n; cin >> n;
	vector<int>a(n);
	for (auto& e : a)cin >> e;

	double ans = 0;
	for (auto e:a) {
		ans += 1.0 / (double)e;
	}
	printf("%.5f\n", 1.0/ans);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;


int main() {
	int N;
	int K;
	int h[100001];
	cin >>N >> K;
	K = K - 1;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	sort(h, h + N);
	long long out = 10000000000;
	long long temp;
	for (int i = 0; i+K < N; i++) {
		temp = h[i + K] - h[i];
		if (temp < out) {
			out = temp;
		}
	}
	
	cout << out;

	return 0;
}

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

using namespace std;
#define int long long
const int N = 666666 ,inf = 0x3f3f3f3f;

signed main(){
	string s;
	int p=0;
	cin>>s;
	for(int i=0;i<s.size();i++)	p+=(int)(s[i]-'0');
	if(p%9) cout<<"No";else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3720
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
static const int MAX=200000;

int main(){
    int n,R[MAX];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>R[i];
        
    }
    
    int maxv=-10000000000;
    int minv=R[0];
    for(int i=1;i<n;i++){
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3880
#include <bits/stdc++.h>
#define _itr ::iterator
#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define ford(i, x, y) for (ll i = x; i > y; --i)
#define forne(i, x, y) for (ll i = x; i <= y; ++i)
#define forde(i, x, y) for (ll i = x; i >= y; --i)
#define rd(x) cin >> x; cin.ignore();
#define rdstr(x) getline(cin, x);
#define rdarr(x, y) for (ll i = 0; i < y; ++i) cin >> x[i];
#define rdmtr(x, y, z) for (ll i = 0; i < y; ++i) for (ll j = 0; j < z; ++j) cin >> x[i][j];
#define pb push_back

#define X first
#define Y second

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

const ll MaxN = 2e5 + 7;
const ll MaxM = 5e3 + 7;
const ll MDL = 1e9 + 7;
const ll INF = 1e18 + 7;

typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef ll arr[MaxN];

ll REPIT = 1;

const bool MQ = false;

ll s(ll a, ll b){ return ((a % MDL) + (b % MDL)) % MDL; }
ll m(ll a, ll b){ return ((a % MDL) * (b % MDL)) % MDL; }

ll n;
arr so;

void Solve()
{
    cin >> n; rdarr(so, n);
    ll res = 0, sum = so[0];
    forn(i, 1, n)
    {
        res = s(res, m(sum, so[i]));
        sum = s(sum, so[i]);
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef OFFLINE
    freopen("input.inp", "r", stdin);
    #endif
    if (MQ == true)
    {
        rd(REPIT);
    }
    while (REPIT--) Solve();
    cout.flush();
    #ifdef OFFLINE
    fclose(stdin);
    #endif
}


Measured memory_bytes: 5212
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}

int main() {
  ll n, p;
  cin >> n >> p;

  map<ll, ll> fac = prime_factor(p);
  ll ans = 1;
  for (auto& kv : fac) {
    ll p, s;
    tie(p, s) = kv;
    ans *= pow(p, s/n);
  }

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


Measured memory_bytes: 256
N = int(input())
rate = [0] * 9
for a in [int(x) for x in input().split()]:
  rate[min(a, 3200) // 400] += 1

ret = 0
for r in rate[:-1]:
  if r:
    ret += 1

print(max(ret, 1), ret + rate[-1])

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

using namespace std;

void knap(vector<pair<int,int> > a,int W){
    int n=a.size();
    long long dp[n+1][W+1];
    for(int i=0;i<n+1;i++){
        for(int j=0;j<=W;j++){
            if(i==0 || j==0){
                dp[i][j]=0;
                continue;
            }
            long long val=a[i-1].second;
            long long wt=a[i-1].first;
            if(wt<=j){
                dp[i][j]=max(val+dp[i-1][j-wt],dp[i-1][j]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W];
}

int main(){
    long long n,w;
    cin>>n>>w;
    vector<pair<int,int> > a(n);
    for(int i=0;i<n;i++){
        cin>>a[i].first>>a[i].second;
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            if(a[j].first==a[j+1].first){
                if(a[j].second>a[j+1].second){
                    swap(a[j],a[j+1]);
                }
            }
        }
    }
    knap(a,w);
    return 0;
}

Measured memory_bytes: 79104
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<string.h>
#include<limits.h>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
const int maxn = 25;
char str[maxn][maxn];
int vis[maxn][maxn];
struct node {
	int x,y;
} dot[maxn];
int dir[][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int n,m;
int ans = 0,res = 0;                                  // 找到结束的条件是关键,如何找到呢？
int main(void) {
	int BFS(int start_x,int start_y);
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= n; i ++) {
		for(int j = 0; j <= m; j ++) {
			scanf("%c",&str[i][j]);
		}
	}
	ans = 0;
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= m; j ++) {
			if(str[i][j] == '#') continue;
			res = BFS(i,j);
			ans = max(ans,res);
		}
	}
	cout << ans << endl;
	return 0;
}

bool Check(int x,int y) {
	if(x < 1 || y < 1 || x > n || y > m) return false;
	if(vis[x][y] || str[x][y] == '#') return false;
	if(str[x][y] == '.') return true;
}

int BFS(int start_x,int start_y) {
	memset(vis,0,sizeof(vis));
	int count = 0;                  // 复原
	queue<node>queues;
	while(!queues.empty()) queues.pop();
	node first,second;
	first.x = start_x,first.y = start_y;
	queues.push(first);
	vis[start_x][start_y] = 1;
	while(!queues.empty()) {
		int s = queues.size();
		for(int j = 0; j < s; j ++) {
			first = queues.front();
			queues.pop();
			for(int i = 0; i < 4; i ++) {
				second.x = first.x + dir[i][0];
				second.y = first.y + dir[i][1];
				if(!Check(second.x,second.y)) continue;
				queues.push(second);
				vis[second.x][second.y] = 1;
			}
		}
        if(!queues.empty()) {                         
        	count ++;
		}
	}
	return count;
}

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

int main()
{
    int n,m;
    scanf("%d %d\n",&n,&m);
    int **A = malloc(sizeof(int*)*n);
    int p;
    for(p=0;p<n;p++){
        A[p] = malloc(sizeof(int)*m);
    }
    int *B = malloc(sizeof(int)*m);
    int i,j;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            if(j!=m-1){
                scanf("%d ",&A[i][j]);
            }else{
                scanf("%d\n",&A[i][j]);
            }
        }
    }
    int k;
    for(k=0;k<m;k++){
        if(k!=m-1){
            scanf("%d\n",&B[k]);
        }else{
            scanf("%d",&B[k]);
        }
    }
    
    int a,b;
    for(a=0;a<n;a++){
        int sum=0;
        for(b=0;b<m;b++){
            sum+=A[a][b]*B[b];
        }
        printf("%d\n",sum);
    }
    return 0;
}



Measured memory_bytes: 2096
n = int(input())
t, a = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]

ans = 0
m = 10000

for i, h in enumerate(H):
    if m > abs(a - (t - h*0.006)):
        ans = i
        m = abs(a - (t - h*0.006))

print(ans+1)

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
int h, w, j, i;
for( ; ; ){
    scanf("%d%d", &h, &w); 
    if(h==0 && w==0) break;
    for(j=0; j<h; j++){ 
        for(i=0; i<w; i++){
            printf("#");
        }
        printf("\n");
    }
printf("\n");
}
return 0;
}

Measured memory_bytes: 1760