akhauriyash/Code-Regression huggingface dataset:
N, M = [int(x) for x in input().split()]

max_l = 0
min_r = 1e06

for _ in range(M):
	l, r = sorted([int(x) for x in input().split()])
	
	if max_l < l:
		max_l = l
	if r < min_r:
		min_r = r

print(max(min_r-max_l+1, 0))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;
    vi A(N), B(N), C(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];
    SORT(A); SORT(B); SORT(C);

    vi btoc(N, 0);
    rep(i, N) {
        auto it = upper_bound(ALL(C), B[i]);
        btoc[i] = C.end()-it;
    }
    vi bcsum(N+1, 0);
    rep(i, N) {
        bcsum[N-i-1] = bcsum[N-i] + btoc[N-i-1];
    }

    int res = 0;
    rep(i, N) {
        auto it = upper_bound(ALL(B), A[i]);
        res += bcsum[it-B.begin()];
        //cout << it-B.begin() << endl;
    }

    cout << res << endl;

    return 0;
}

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

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    int N;
    
    while(cin >> N && N)
    {
        vector<vector<int>> stage(N, vector<int> (N + 1, 0));

        rep(i, N) rep(j, N + 1) cin >> stage[i][j];

        vector<int> dp(1 << N, iINF);

        dp[0] = 0;

        rep(bit, (1 << N))
        {
            rep(i, N)
            {
                if((bit >> i & 1)) continue;

                int cost = stage[i][0];

                rep(j, N)
                {
                    if(!(bit & (1 << j))) continue;

                    cost = min(cost, stage[i][j + 1]);
                }

                int now = (bit | (1 << i));

                dp[now] = min(dp[now], dp[bit] + cost);
            }
        }

        cout << dp[(1 << N) - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 3420
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
d = inl()
acc = 0
for i in range(n-1):
  for j in range(i+1,n):
    acc += d[i]*d[j]
print(acc)


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

struct Edge {
    int from,to;
    Edge(int f,int t) : from(f), to(t){}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

class LowLink {
    public:
        LowLink(int n) : mGraph(n), mOrd(n), mLow(n), mUsed(n,false) {}
        void add_edge(int u, int v){
            mGraph[u].emplace_back(u,v);
            mGraph[v].emplace_back(v,u);
        }
        // e(u,v)が橋　<=> ord[u] < low[v]
        // 頂点vが関節点 <=> ord[u] <= low[v]となるvの子uが存在
        int dfs(int v,int pv,int k){
            mUsed[v] = true;
            mOrd[v] = mLow[v] = k++; // 訪れた順
            bool is_articulation = false;
            int cnt = 0;
            for(Edge nv : mGraph[v]){
                if(!mUsed[nv.to]){ // まだ訪れてない
                    ++cnt;
                    k = dfs(nv.to,v,k);
                    mLow[v] = min(mLow[v], mLow[nv.to]);

                    is_articulation |= ~pv && mOrd[v] <= mLow[nv.to];
                    if(mOrd[v] < mLow[nv.to]) mBridges.emplace_back(minmax(v,nv.to));
                } else if(nv.to != pv){ // 後退辺だったら
                    mLow[v] = min(mLow[v], mOrd[nv.to]);
                }
            }
            is_articulation |= pv == -1 && cnt > 1;
            if(is_articulation) mArticulationPoints.push_back(v);

            return k;
        }

        void Init(){
            int k = 0;
            for(int i = 0; i < mGraph.size(); ++i){
                if(!mUsed[i]) k = dfs(i,-1,k);
            }
        }

        vector<pair<int,int> > GetBridges(){ return mBridges;}
        vector<int> GetArticulationPoints(){ return mArticulationPoints;}

    private:
        Graph mGraph;
        vector<int> mOrd;
        vector<int> mLow;
        vector<bool> mUsed;
        vector<pair<int,int> > mBridges;
        vector<int> mArticulationPoints;
};


int main(){
    int V,E,s,t;
    cin >> V >> E;
    LowLink lowlink(V);
    for(int i = 0; i < E; ++i){
        cin >> s >> t;
        lowlink.add_edge(s,t);
    }
    lowlink.Init();
    auto ans = lowlink.GetArticulationPoints();
    sort(ans.begin(),ans.end());
    for(auto e : ans){ cout << e << endl;}
    return 0;
}



Measured memory_bytes: 5232
import fractions
a, b, c, d = map(int, input().split())
g = fractions.gcd(c, d)
lcm = c*d//g
A = (a-1) - (a-1)//c - (a-1)//d + (a-1)//lcm
B = b - b//c - b//d + b//lcm
print(B-A)

Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	ll n,a;
	cin>>n>>a;
	cout<<(n*n)-a;
	return;
}
int main()
{
	fast;
	int q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3620
n=int(input())
a=list(map(int,input().split()))
a=[0]+a+[0]

cost_sum=0

for i in range(n+1):
    cost_sum += abs(a[i+1]-a[i])

for i in range(1,n+1):
    if (a[i]-a[i-1])*(a[i]-a[i+1])<0:
        print(cost_sum)
    else:
        cut_sum= abs(a[i]-a[i-1])+abs(a[i+1]-a[i])-abs(a[i+1]-a[i-1])
        print(cost_sum-cut_sum)

Measured memory_bytes: 14172
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define jkl int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    ll x, y;
    cin >> x >> y;
    print(x + y / 2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;

signed main() {
    int N, K;
    cin >> N >> K;
    
    int ans = 0;
    for( int i = K; i <= N+1; i++ ){
        int saisyo = (i-1)*i/2;
        int saidai = (2*N+1-i)*i/2;
        ans += saidai-saisyo+1;
        ans %= MOD;
    }
    cout << ans << endl;
    
    
}


Measured memory_bytes: 3604
import java.util.*;
public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
      String val = sc.nextLine();
      String ans = "";

    if(val.endsWith("s")){
      ans = "es";
    }else{
        ans = "s";
    }
    
      System.out.println(val+ans);   
  }
}

Measured memory_bytes: 39340
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    bool ok = false;
    for (ll i = 0; i < N; i++) {
        //i回は大きくなり,N - 1 - i回は小さくなる
        ll max = A + i * D - (N - 1 - i) * C;
        ll min = A + i * C - (N - 1 - i) * D;
        if (min <= B && B <= max) {
            ok = true;
            break;
        }
    }

    if (ok){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}


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

using namespace std;

int main(int argc, char* argv[])
{
    int fromNum, toNum, target;
    cin >> fromNum >> toNum >> target;
    
    int count = 0;

    for(int i = fromNum; i <= toNum; i++)
    {
        if(target%i == 0) count++;
    }
    cout << count <<endl;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG arc/arc063/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    string s;
    cin >> s;
    ll ans = 0;
    rep(i, s.length() - 1){
        if(s[i] != s[i + 1]) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 512
n = int(input())
p = [int(input()) for i in range(n)]

a = [0 for i in range(n)]

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

b = [1]
for i in range(1,n):
    if a[i-1]<a[i]:
        b[-1]+=1
    else:
        b.append(1)
print(n-max(b))


Measured memory_bytes: 73764
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
    return x>y;
}
const int N=10005;
const int mod=1e9+7;
int main()
{
    std::ios::sync_with_stdio(false);
    int n,l;
    cin>>n>>l;
    string a;
    priority_queue<string,vector<string>,greater<string> >q;
    for(int i=0;i<n;i++){
        cin>>a;
        q.push(a);
    }
    while(q.size()>0){
        string b=q.top();
        cout<<b;
        q.pop();
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 9e18
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


int main(void) {
	string s;
	cin >> s;
	int N = s.size();
	vi num(26, 0);
	rep(i, N) {
		num[s[i] - 'a']++;
	}
	int odd = 0, center_char = 0;
	rep(i, 26) {
		if (i == 'x' - 'a')continue;
		if (num[i] % 2 == 1) {
			odd++;
			center_char = i;
		}
	}
	if (odd > 1) {
		cout << -1 << endl;
		return 0;
	}
	// xを抜いて回文である必要がある
	vc x;
	rep(i, N) {
		if (s[i] != 'x')x.push_back(s[i]);
	}
	rep(i, x.size() / 2) {
		if (x[i] != x[x.size() - 1 - i]) {
			cout << -1 << endl;
			return 0;
		}
	}

	vi n;
	int tmp = 0;
	rep(i, N) {
		if (s[i] != 'x') {
			n.push_back(tmp);
			tmp = 0;
		}
		else {
			tmp++;
		}
	}
	n.push_back(tmp);

	ll ans = 0;
	rep(i, n.size()) {
		ans += abs(n[i] - n[n.size() - 1 - i]);
	}

	cout << ans / 2 << endl;

	return 0;
}

Measured memory_bytes: 1148
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ls st<<1
#define rs st<<1|1
#define CLR(a,b) memset(a,(b),sizeof(a))

const int MAXN = 1e5+11;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;

/*-------------------------------------------------------*/
int abc(int x)
{
    if(x < 0) return -x;
    return x;
}
int x[MAXN], y[MAXN], t[MAXN];
void init_1(int x)
{
    for(int i = 1; i <= x; i++) {
        cout <<'U';
    }
}
void init_2(int x)
{
    for(int i = 1; i <= x; i++) {
        cout <<'R';
    }
}
void init_3(int x)
{
    for(int i = 1; i <= x; i++) {
        cout <<'D';
    }
}
void init_4(int x)
{
    for(int i = 1; i <= x; i++) {
        cout <<'L';
    }
}
int main() {
    int sx, sy, tx, ty;
    cin >> sx >>sy >> tx >> ty;
    int yy = ty-sy;
    int xx = tx-sx;
    init_1(yy); init_2(xx);
    init_3(yy); init_4(xx);
    xx++, yy++;
    cout << 'L';
    init_1(yy);init_2(xx);
    cout << "DR";
    init_3(yy);init_4(xx);
    cout << "U\n";

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define pb push_back
#define em emplace
#define vv vector<ll>
#define fr(i,x) for(int i=0;i<x;i++)
#define MAX 10000005
int dx[4] = {-1,0,0,1};
int dy[4] = {0,-1,1,0};

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    
    if(a.first == b.first) return a.second<b.second;
    return (a.first < b.first); 
}

//ll a[MAX];
void sieve(){
    for (int i = 1; i < MAX; i++)
    {
        for (int j = i; j <= MAX; j+=i)
        {
           // a[j]++;
        }
        
    }
    
}
int countDigit(ll n){
    ll c = 0;
    while (n!=0)
    {
        c++;
        n/=10;
    }
    return c;
    
}
ll v[100005] = {false};
void dfs(vector<vector<ll>>&g,ll n){
    v[n] = true;
    for (ll i = 0; i < g[n].size(); i++)
    {
       ll x = g[n][i];
       if(v[x]) continue;
       else {
       dfs(g,x);}
    }
    
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,a,b,m;
    cin >> n >> m;
    vector<vector<ll>>g(n+1);
    for (ll i = 0; i < m; i++)
    {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a); 
    }
    ll c = 0;
    for (ll i = 1; i <= n; i++)
    {
        if(v[i]) continue;
        else{
            dfs(g,i);
            c++;
        }
        
    }
    
    cout << c-1<< endl;
    
    
    
    
   
}

Measured memory_bytes: 11132
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll x, a, b;
    scanf("%lld %lld %lld", &x, &a, &b);
    printf((abs(x-a)<abs(x-b))?"A\n":"B");
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
N = int(input())
strs = 26
ans = ''
while True:
  if N <= strs:
    ans += chr(N + 96)
    break
  if N % strs == 0:
    ans += 'z'
    N = N //strs - 1
  else:    
    ans += chr(N % strs + 96)
    N = N // strs
print(ans[::-1])

Measured memory_bytes: 61788
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>w(n),sum(n);
  for (int i=0; i<n; i++){
    cin >> w[i];
  }
  sum[0]=w[0];
  for (int i=1; i<n; i++){
    sum[i] = sum[i-1] +w[i];
  }
  int ans = 100000000;
  for (int i=0; i<n; i++){
    int t=abs(sum[n-1]-sum[i]*2);
    ans = min(t,ans);
  }
  cout << ans;
}


Measured memory_bytes: 256
n = 0
nums = []

def dfs(i,num):
  if (i==n-1):
    nums.append(num)
    return False
  if (dfs(i+1,num+'+')):
    return True
  if (dfs(i+1, num + '_')):
    return True
  return False

def calc():
  ans = 0
  p = 0
  for num in nums:
    for i in range(n):
      if (i==n-1):
        ans += int(s[p:n])
      elif (num[i]=='+'):
        ans += int(s[p:i+1])
        p = i + 1
    p = 0

  return ans

s = input()
n = len(s)
dfs(0,"")
print(calc())


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





void solve(long long N, long long H, long long W){
    cout<<(N-H+1)*(N-W+1)<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    solve(N, H, W);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int64_t N,K,Z=0,Q=1000000007;
  cin>>N>>K;
  for (int i=K; i<=N+1; i++) {
    Z = (Z + i * (N+1-i) + 1) % Q;
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define REP(i, n) for (LL i = 0; i < (LL)(n); i++)
#define REP2(i, n) for (LL i = 1; i <= (LL)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(x.begin(), x.end(),0LL)
#define vLL(v,n) vector<LL> v(n); REP(i,n)cin>>v[i];
#define vstr(v,n) vector<string> v(n); REP(i,n)REP(i,n)cin>>v[i];
LL INF = 1e9 + 1;
LL MOD = 1e9+7;
  LL zero,a,b,c,d,e,n,m,l,k,r,x,y,z,odd,ans=INF,ans2=0,h,w;
string s,S,t;
int main() {
ios_base::sync_with_stdio(false);
cin >> a >> b;
REP2(i,10000){
   if(floor(i*0.08)==a&&floor(i*0.1)==b){
       cout << i << endl;
       return 0;
   }
}
cout  << -1 <<endl;
return 0;
}

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

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

typedef long long LL;

int main(){
  int n,m,t;
  cin >> n >> m >> t;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int ans=a[0]-m;
  for(int i=1;i<n;i++){
    ans+=max(a[i]-a[i-1]-2*m,0);
  }
  ans+=max(t-a[n-1]-m,0);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <set>
#include <stdlib.h>
#include <cmath>
using namespace std;

int d, c[29], s[409][29], p[409], cp[29], rs;
set<int> st[29];

int cc()
{
	for (int i = 0; i < 26; i++)
		cp[i] = 0;
	int ans = 0;
	for (int i = 1; i <= d; i++) {
		for (int j = 0; j < 26; j++) {
			if (p[i] == j) {
				cp[j] = i;
				ans += s[i][j];
			}
			else
				ans -= (i - cp[j]) * c[j];
		}
	}
	return ans;
}

void rm(int n, int k)
{
	auto pi = st[k].find(n);
	auto l = pi; l--;
	auto r = pi; r++;
	int pl = (n - (*l) - 1), pr = ((*r) - n - 1), plr = ((*r) - (*l) - 1);
	st[k].erase(n);
	rs -= s[n][k];
	rs += pl * (pl + 1) / 2 * c[k]; rs += pr * (pr + 1) / 2 * c[k];
	rs -= plr * (plr + 1) / 2 * c[k];
}

void ins(int n, int k)
{
	auto r = st[k].lower_bound(n);
	auto l = r; l--;
	int pl = (n - (*l) - 1), pr = ((*r) - n - 1), plr = ((*r) - (*l) - 1);
	st[k].insert(n);
	rs += s[n][k];
	rs -= pl * (pl + 1) / 2 * c[k]; rs -= pr * (pr + 1) / 2 * c[k];
	rs += plr * (plr + 1) / 2 * c[k];
}

void up(int n, int k)
{
	rm(n, p[n]);
	p[n] = k;
	ins(n, p[n]);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> d;
	for (int i = 0; i < 26; i++) {
		cin >> c[i];
		st[i].insert(0); st[i].insert(d + 1);
	}
	for (int i = 1; i <= d; i++) {
		for (int j = 0; j < 26; j++)
			cin >> s[i][j];
		p[i] = rand() % 26;
		st[p[i]].insert(i);
	}
	rs = cc();
	double k = 100, sc = 350, kt = 0.9993;
	for (int i = 0; i < 4000000; i++) {
		double e1 = rs;
		int n = (rand() % d) + 1, kp = (rand() % 25) + 1;
		int hk = p[n], tk = (hk + kp) % 26;
		up(n, tk);
		int e2 = rs;
		double pb = exp((e2 - e1) / (k * sc));
		if (pb < rand() / (double)RAND_MAX)
			up(n, hk);
		k *= kt;
	}
	for (int i = 1; i <= d; i++)
		cout << p[i] + 1 << '\n';
	return 0;
}

Measured memory_bytes: 4388
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string.h>
#define N 200
int main() {
	char s[N] = "", x[N] = "", ss[N] = "";
	int flg = 0;
	char n[2][5] = { { "No" },{ "Yes" } };
	fgets(s, sizeof(s), stdin);
	fgets(x, sizeof(x), stdin);
	s[strlen(s) - 1] = '\0';
	x[strlen(x) - 1] = '\0';
	strcat(ss, s);
	strcat(s, ss);
	if (strstr(s, x) != NULL) flg = 1;
	printf("%s\n", n[flg]);
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h;
	cin>>h;
	ll ans=0;
	ll now=1;
	while(h){
		ans+=now;
		now*=2;
		h/=2;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
C=input()
if(C=="a"):
  print("b")
if(C=="b"):
  print("c")
if(C=="c"):
  print("d")
if(C=="d"):
  print("e")
if(C=="e"):
  print("f")
if(C=="f"):
  print("g")
if(C=="g"):
  print("h")
if(C=="f"):
  print("i")
if(C=="i"):
  print("j")
if(C=="j"):
  print("k")
if(C=="k"):
  print("l")
if(C=="l"):
  print("m")
if(C=="m"):
  print("n")
if(C=="n"):
  print("o")
if(C=="o"):
  print("p")
if(C=="p"):
  print("q")
if(C=="q"):
  print("r")
if(C=="r"):
  print("s")
if(C=="s"):
  print("t")
if(C=="t"):
  print("u")
if(C=="u"):
  print("v")
if(C=="v"):
  print("w")
if(C=="w"):
  print("x")
if(C=="x"):
  print("y")
if(C=="y"):
  print("z")

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

int main(){
    ll x,y,z,k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x),b(y),c(z);
    rp(i,x) cin >> a.at(i);
    rp(i,y) cin >> b.at(i);
    rp(i,z) cin >> c.at(i);
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    reverse(c.begin(),c.end());
    priority_queue<ll> que;
    rp(i,x){
        rp(j,y){
            rp(l,z){
                if((i+1)*(j+1)*(l+1)<=k)
                que.push(a.at(i)+b.at(j)+c.at(l));
            }
        }
    }
    rp(i,k){
        ll ans;
        ans=que.top(); que.pop();
        cout << ans << endl;
    }
    return 0;
}

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

int main(void){
    int n;
    vector<int> seq;
    cin>>n;
    seq.resize(n);
    for(int i=0;i<n;i++){
        cin>>seq[i];
    }
    int mod4=0,mod2=0,other=0;
    for(vector<int>::const_iterator cit=seq.begin();cit!=seq.end();cit++){
        if(*cit%4==0){
            mod4++;
        }
        else if(*cit%2==0){
            mod2++;
        }
        else {
            other++;
        }
    }
    if(mod4+1>=other){
        if(mod2%2==0){
            cout<<"Yes"<<endl;
        }
        else if(mod2%2!=0&&mod4>=other){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;

int main()
{
    int a, b;
    while(~scanf("%d%d",&a,&b))
    {
        int n = 0, x = 1,c = b;
        while(c > 0)
        {
            c /= 10;
            n++;
        }
        while(n > 0)
        {
             x *= 10;
             n--;
        }
        int temp = a * x + b;
        int token = (int)sqrt(temp);
        if(token * token == temp)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int N;
int Point[100];
int High=-1;
int Low=1001;
int main()
{
	while(true){
		scanf("%d",&N);
		if(N==0)break;
		High=-1;Low=1001;
		int sum=0;
		for(int i=0;i<N;i++){
			scanf("%d",&Point[i]);
			sum+=Point[i];
			High=max(Point[i],High);
			Low=min(Point[i],Low);
		}
		printf("%d\n",(sum-High-Low)/(N-2));
	}
}

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

int main() {
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<time.h>
#include<cstdlib>
typedef long long ll;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mm(a) memset(a,0,sizeof(a))
#define lr rt<<1
#define rr rt<<1|1
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0);
#define inf 0x3f3f3f3f
#define eqs 1e-8
#define lb(x) (x&(-x))
#define ch(a) (int(a-'a')+1)
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef pair<int,int> pii;
const double pi=acos(-1);
const int maxn=200005;
//const ll Mod=1000000007;
const ll Mod=998244353;
using namespace std;



ll n,z;
ll a[maxn];
int v[maxn];

int main()
{
    sync;
    double d,a;
    cin>>d;
    a=d/3.0;
    printf("%.9lf\n",a*a*a);
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

def printa(A):
  for i in range(N - 1):
    print(A[i] ,end=' ')
  print(A[N - 1],)
  
printa(A)
for i in range(1, N):
  v = A[i]
  j = i - 1
  while j >= 0 and A[j] > v:
    A[j+1] = A[j]
    j -= 1
  A[j+1] = v
  printa(A)


Measured memory_bytes: 5980
import java.awt.Point;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int w[];
	static int v[];
	static int n;
	static int dp[];
	static int d;

	public static void main(String[] args) throws java.io.IOException {
		Scanner sc = new Scanner(System.in);
		int c = 1;
		while (true) {
			d = sc.nextInt();
			if (d == 0)
				break;
			n = sc.nextInt();
			dp = new int[d + 1];
			w = new int[n];
			v = new int[n];
			for (int i = 0; i < n; i++) {
				String tmps[] = sc.next().split(",");
				v[i] = Integer.parseInt(tmps[0]);
				w[i] = Integer.parseInt(tmps[1]);
			}
			// dp[x] x::持てる量
			Arrays.fill(dp, -1);
			dp[0] = 0;
			for (int i = 0; i < n; i++) {
				for (int j = d; j >= w[i]; j--) {
					if (dp[j - w[i]] >= 0)
						dp[j] = Math.max(dp[j], dp[j - w[i]] + v[i]);
				}
			}
			int max_v = 0;
			int min_w = d;
			for (int i = 0; i < d + 1; i++) {
				if (dp[i] > max_v) {
					max_v = dp[i];
					min_w = i;
				}
			}
			System.out.println("Case " + c + ":");
			System.out.println(max_v);
			System.out.println(min_w);
			c++;

		}
	}
}

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

import sys
sys.setrecursionlimit(300000)


def solve(N: int, S: str):
    ret = ''
    for c in S:
        ret +=  chr(ord('A') + (ord(c) - ord('A') + N) % 26)
    print(ret)
    return

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
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

double memo[51][100*51 + 1];

int main(){
  while(true){
    int x = getInt();
    int y = getInt();
    int z = getInt();

    int r[4];
    int ee[51];
    int ea[51];
    
    if(x + y + z == 0) break;

    REP(i,y+1) REP(j, 100*50+1) memo[i][j] = 0;
    REP(i,y+1) ee[i] = ea[i] = 0;

    REP(i,x) r[i] = getInt();
    REP(i,z){
      int n = getInt();
      ee[n] = getInt();
      ea[n] = getInt();
    }

    memo[0][0] = 1.0;
    REP(i,y){
      REP(j,i*100+1){
	REP(k,x){
	  int nextPos = i + r[k];
	  int earn    = j;
	  if(nextPos > y) nextPos = y;

	  switch(ee[nextPos]){
	  case 1:
	    nextPos += ea[nextPos];
	    break;
	  case 2:
	    earn += ea[nextPos];
	    break;
	  case 3:
	    earn -= ea[nextPos];
	    break;
	  }

	  if(nextPos > y) nextPos = y;
	  if(earn < 0) earn = 0;
	  memo[nextPos][earn] += memo[i][j] / x;
	}
      }
    }

    double ans = 0.0;
    REP(i, y*100+1) ans += i * memo[y][i];

    print((int)floor(ans + 1e-10));
  }
  return 0;
}

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

int main(){
    ll n,m,x;
    cin>>n>>m>>x;
    ll ans_0=0;
    ll ans_1=0;
    vector<ll> a(m);
    for(ll i=0;i<m;++i){
        cin>>a[i];
    }
    for(ll i=x;i<=n;++i){
        for(ll j=0;j<m;++j){
            if(a[j] == i){
                ans_0++;
            }
        }
    }
    for(ll i=x;i>=0;--i){
        for(ll j=0;j<m;++j){
            if(a[j] == i){
                ans_1++;
            }
        }
    }
    cout<<min(ans_0,ans_1)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int INF = 1 << 20;
const int dy[4] = {-1, 0, 1, 0};
const int dx[4] = {0, 1, 0, -1};
int H, W;
string s[50];
int dis[50][50];

bool contain(int y, int x) {
  return y >= 0 && y < H && x >= 0 && x < W;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> H >> W;
  int tmp = 0;
  for (int i = 0; i < H; i++) {
    cin >> s[i];
    for (int j = 0; j < W; j++) {
      tmp += s[i][j] == '#';
    }
  }
  queue<pii> que;
  que.emplace(0, 0);
  fill_n((int*)dis, 50 * 50, INF);
  dis[0][0] = 1;
  while (!que.empty()) {
    int y, x;
    tie(y, x) = que.front(); que.pop();
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (contain(ny, nx) && s[ny][nx] != '#' && dis[ny][nx] == INF) {
        dis[ny][nx] = dis[y][x] + 1;
        que.emplace(ny, nx);
      }
    }
  }
  if (dis[H - 1][W - 1] == INF) cout << -1 << endl;
  else cout << H * W - dis[H - 1][W - 1] - tmp << endl;

  return 0;
}

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

using namespace std;
typedef long long Int;
#define MOD (1000000007)
Int n, q, x, y;
Int a[3240];
Int dp[3240][3240];

Int pw(Int a, Int n){
  if(n == 0)return 1;
  Int res = pw(a, n/2);
  res = res * res % MOD;
  if(n % 2)res *= a;
  return res % MOD;
}

int main(){
  cin >> n >> q;
  for(Int i = 0;i < n;i++)cin >> a[i];
  for(Int i = 0;i < n;i++){
    for(Int j = 0;j < n;j++){
      dp[i][j] = a[i] < a[j];
    }
  }
  for(Int i = 0;i < q;i++){
    cin >> x >> y;
    x--,y--;
    Int a = dp[x][y] + dp[y][x];
    if(a % 2)a += MOD;
    dp[x][y] = a / 2;
    dp[y][x] = a / 2;
    for(Int j = 0;j < n;j++){
      if(j == x || j == y)continue;
      Int a = (dp[x][j] + dp[y][j]) % MOD;
      if(a % 2)a += MOD;
      a /= 2;
      dp[x][j] = dp[y][j] = a;
    }
    
    for(Int j = 0;j < n;j++){
      if(j == x || j == y)continue;
      Int a = (dp[j][x] + dp[j][y]) % MOD;
      if(a % 2)a += MOD;
      a /= 2;
      dp[j][x] = dp[j][y] = a;
    }
  }
  Int res = 0;
  for(Int i = 0;i < n;i++){
    for(Int j = 0;j < i;j++){
      res += dp[i][j];
      res %= MOD;
    }
  }
  cout << res * pw(2, q) % MOD<< endl;
  return 0;
}

Measured memory_bytes: 78080
/*
 Educational Dp Contest Atcoder
 
 */

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define all(x) x.begin(),x.end()

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}

const ll MOD =998244353;
const ll hell=1000000007;
const int INF=1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

const int N=100005;
int dp[N][2];vi adj[N];
void dfs(int u,int p)
{
    dp[u][0]=1;
    dp[u][1]=1;
    for(int v:adj[u])
    {
        if(v^p)
        {
            dfs(v,u);
            dp[u][0]=(dp[u][0]*(dp[v][0]+dp[v][1])%hell)%hell;
            dp[u][1]=(dp[u][1]*dp[v][0])%hell;
        }
    }
}

void solve()
{
    
    int n;
    cin>>n;
    int u,v;
    for(int i=1;i<n;i++)
    {
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1,0);
    int ans=(dp[1][0]+dp[1][1])%hell;
    cout<<ans<<endl;
    
}

int32_t main()
{
    
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 10496
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int N; cin >> N;
  if (N < 1000) cout << "ABC" << endl;
  else          cout << "ABD" << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


struct point {
    ll x;
    ll y;
    point(ll _x, ll _y): x(_x), y(_y) {}
};

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;cin>>h>>w;
    vector<string> a(h);
    vector<vector<ll>> dist(h,vector<ll>(w,100000000));
    queue<point> que;
    rep(i,h) {
        cin>>a[i];
    }
    rep(i,h) {
        rep(j,w) {
            if (a[i][j]=='#') {
                dist[i][j] = 0;
                for(ll x=-1;x<=1;x+=2) {
                    if (i+x>=0 && i+x<h && a[i+x][j]=='.' && dist[i+x][j] > 1) {
                        dist[i+x][j] = 1;
                        que.emplace(i+x,j);
                    }
                    if (j+x>=0 && j+x<w && a[i][j+x]=='.' && dist[i][j+x] > 1) {
                        dist[i][j+x] = 1;
                        que.emplace(i,j+x);
                    }
                } 
            }
        }
    }
    ll res = 0;
    while(!que.empty()) {
        auto now = que.front();
        que.pop();
        chmax(res, dist[now.x][now.y]);
        ll d = dist[now.x][now.y];
        for(ll x=-1;x<=1;x+=2) {
            if (now.x+x>=0 && now.x+x<h && a[now.x+x][now.y]=='.' && dist[now.x+x][now.y] > d+1) {
                dist[now.x+x][now.y] = d+1;
                que.emplace(now.x+x,now.y);
            }
            if (now.y+x>=0 && now.y+x<w && a[now.x][now.y+x]=='.' && dist[now.x][now.y+x] > d+1) {
                dist[now.x][now.y+x] = d+1;
                que.emplace(now.x,now.y+x);
            }
        } 
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 17168
#include<algorithm>
#include<cstring>
#include<stdio.h>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a==1){printf("YES\n");return 0;}
	for(int i=a;i<=a*100;i+=a)
		if(i%b==c){printf("YES\n");return 0;}
	printf("NO\n");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <math.h>
using namespace std;

/*
すべての要素を１にしたいので，区間全体を１に広げる操作をする．
１が含まれる範囲Kの区間を重なるように実行すれば良い．つまり区間の数が答えである．
mこの区間で覆える範囲は，[1, (K-1)m+1] = N
*/
int main() {
  double N, K;
  cin >> N >> K;
  
  int ans = ceil((N-1) / (K-1));
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

const int mn = 200000;

ld dp[21][mn];

ld dist(ld a, ld b) {
	return abs(b - a) / a;
}

int n;
void solve() {
	vector<int> h(n); rep(i, n)cin >> h[i];
	rep(i, n + 1) {
		rep(j, mn) {
			dp[i][j] = INF;
		}
	}
	dp[0][1] = 0;
	rep(i, n) {
		rep1(j, mn - 1) {
			for (int k = j; k < mn; k += j) {
				ld c = dist(h[i], k);
				dp[i + 1][k] = min(dp[i + 1][k], max(dp[i][j],c));
			}
		}
	}
	ld ans = INF;
	rep(i, mn) {
		ans = min(ans, dp[n][i]);
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(9);
	while (cin >>n,n) {
		solve(); break;
	}
	//stop
	return 0;
}


Measured memory_bytes: 68856
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
template<typename T> inline void in(T &e){cin>>e;}
template<typename T> inline void out(T e){cout<<e<<endl;}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n,k;

signed main(){
    io();
    cin>>n>>k;
    out(n%k==0?0:1);

    return 0;
}


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

int main(){
    char m;
    int n, x, y;
    cin >> x;
    int z[4][13];
    n = 13;
    for (int p = 1; p <= n; p++){
        z[0][p-1] = 0;
        z[1][p-1] = 0;
        z[2][p-1] = 0;
        z[3][p-1] = 0;
    }
    for (int q = 1; q <= x; q++){
        cin >> m >> y;
        if (m == 'S'){
            z[0][y-1] = 1;
        } else if (m == 'H'){
            z[1][y-1] = 1;
        } else if (m == 'C'){
            z[2][y-1] = 1;
        } else if (m == 'D'){
            z[3][y-1] = 1;
        }
    }
    for (int a = 1; a <= n; a++){
        if (z[0][a-1] == 0){ //S
            cout << "S " << a << endl;
        }
    }
    for (int b = 1; b <= n; b++){
        if (z[1][b-1] == 0){ //H
            cout << "H " << b << endl;
        }
    }
    for (int c = 1; c <= n; c++){
        if (z[2][c-1] == 0){ //C
            cout << "C " << c << endl;
        }
    }
    for (int d = 1; d <= n; d++){
        if (z[3][d-1] == 0){ //D
            cout << "D " << d << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
int top,s[1000];
void push(int x){
    s[++top]=x;
}
int pop(){
    top--;
    return s[top+1];
}
int main(){
int a,b;
top=0;
char S[100];
while(scanf("%s",S)!=EOF){
    if(S[0]=='+'){
        a=pop();
        b=pop();
        push(a+b);
    }else if(S[0]=='-'){
        b=pop();
        a=pop();
        push(a-b);
    }else if(S[0]=='*'){
        a=pop();
        b=pop();
        push(a*b);
    }else{
        push(atoi(S));
    }
}
printf("%d\n",pop());
return 0;
}

Measured memory_bytes: 2736
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0)cout<<"Alice"<<endl;
    else cout<<"Borys"<<endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>/*
#include <unordered_map>
#include <functional> //greater
#include <algorithm> //sort
#include <iostream>
#include <iterator>
#include <utility> //pair
#include <sstream>
#include <cstring> //memset
#include <complex>
#include <cassert>
#include <random>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype> //isaplha, tolower
#include <deque>
#include <queue>
#include <stack>
#include <array>
#include <cmath> //sqrt, sin
#include <ctime>
#include <list>
#include <map>
#include <set>
//*/

//#define int long long
#define uns unsigned
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl '\n'
using namespace std;

template<class T> ostream &operator<<(ostream &os, const pair<T,T> &p){
	return os<<"("<<p.fi<<","<<p.se<<")";}
template<class T> ostream &operator<<(ostream &os, const pair<const T,T> &p){
	return os<<"("<<p.fi<<","<<p.se<<")";}
template<class T> ostream &operator<<(ostream &os, const array<T,3> &p){
	return os<<"("<<p[0]<<","<<p[1]<<","<<p[2]<<")";}
template<class T> ostream &operator<<(ostream &os, const vector<T> &p){
	for(auto x: p) os<<x<<' '; return os;}
#define dbug(x) cerr<<">>>> "<<#x<<" = "<<x<<endl
#define _ <<", "<<
#define FOR(X,L,R) for(int X=L;X<R;X++)
#define FI(I,X) for(auto I=(X).begin();I!=(X).end();I++)
#define print(X) {cerr<<"{ ";FI(I,X)cerr<<*I<<' ';cerr<<"}"<<endl;}
#define mset(V,X) memset(V,X,sizeof(V))
#define all(X) (X).begin(),(X).end()
#define upperb(V,X) (int)(upper_bound(all(V),(X))-V.begin())
#define lowerb(V,X) (int)(lower_bound(all(V),(X))-V.begin())

const double EPS = 1e-9, PI = acos(-1);
const ll LINF = 0x3f3f3f3f3f3f3f3f, mod = 1e9+7;
const int INF = 0x3f3f3f3f, SZ = 2e5+20;

int n,c;
vector<pii> v;//w,v;
int res,aux;
double c2,aux2;
int sf[110];
void bt(int i){
	if(i == n) return;
	//if(sf[i] + aux <= res) return;
	aux2 = 0; c2 = c;
	for(int j=i; j<n && c2; j++){
		if(v[j].fi <= c2){
			c2 -= v[j].fi; aux2 += v[j].se;
		} else {
			aux2 += (v[j].se*c2)/v[j].fi;
			c2 = 0;
		}
	}
	if(aux2 + aux <= res) return;
	if(v[i].fi <= c){
		c -= v[i].fi;
		aux += v[i].se;
		if(aux > res) res = aux;
		bt(i+1);
		aux -= v[i].se;
		c += v[i].fi;
	}
	bt(i+1);
}

int32_t main(){
	ios::sync_with_stdio(false);cin.tie(0);
	
	cin>>n>>c;
	FOR(i,0,n){
		int x,y; cin>>x>>y;
		//w.pb(x); v.pb(y);
		v.pb({x,y});
	}
	//random_shuffle(all(v));
	sort(all(v),[](pii a, pii b){
		return (a.se+0.0)/a.fi > (b.se+0.0)/b.fi;
	});
	//for(int i=n-1; i>=0; i--) sf[i] = v[i].se+sf[i+1];
	
	bt(0);
	cout<<res<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
const ll _max = 2 * 100000 + 10;
ll ans, n, k, s[_max];

int main() {
	cin >> n >> k;
	repi(i, 0, n) {
		ll temp;
		cin >> temp;
		s[temp]++;
	}
	if (k < n) {
		sort(s, s + _max);
		reverse(s, s + _max);
		repi(i, k, _max) ans += s[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792