akhauriyash/Code-Regression huggingface dataset:
#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() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  reverse(h.begin(), h.end());
  rep(i, n - 1) {
    if (h[i] >= h[i + 1]) continue;
    if (h[i + 1] - h[i] == 1)
      h[i + 1]--;
    else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main()
{
  string s;
  cin>>s;
  int n=s.length();
  if (s[n-1]=='s')
    s=s+"es";
  else
    s=s+"s";
  //cout<<endl<<s[n-1]<<endl; 
  cout<<s;
  

}

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    string a, b;
    cin>>a>>b;
    if(a.length()>b.length()){
        cout<<"GREATER"<<endl;
    }
    else if(a.length()<b.length()){
        cout<<"LESS"<<endl;
    }
    else{
        if(a>b){
            cout<<"GREATER"<<endl;
        }
        else if(a<b){
            cout<<"LESS"<<endl;
        }
        else{
            cout<<"EQUAL"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
  "sort"
)

func scanNums(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}

func main() {
  var N int
  fmt.Scan(&N)
  
  nums := scanNums(N)
  sort.Sort(sort.IntSlice(nums))
  fmt.Println(nums[len(nums)-1] - nums[0])
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,m,k;cin>>n>>m;
    int a;
    vector<int>num(m,0);
    for(int i=0;i<n;i++){
        cin>>k;
        for(int j=0;j<k;j++){
        cin>>a;
        num.at(a-1)++;
        }
    }
  	int ans=0;
    for(int i=0;i<m;i++){
    if(num.at(i)==n)ans++;
    }
  	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 500000
 
int cnt,t[N];
 
void merge    (int A[], int left, int right);
 
main(){
  
  int n,A[N], i;
  scanf("%d", &n);
  
  for(i=0;i<n;i++) scanf("%d", &A[i]);
  merge(A,0, n-1);
  
  for(i=0;i<n-1;i++) printf("%d ",A[i]);
  printf("%d\n%d\n", A[n-1], cnt);
  
  return 0;
  
}

void merge (int A[], int left, int right){   
  int mid, i, j, k;
  
  if(left >= right) return;
  
  mid = (left + right) / 2;
  
  merge   (A, left, mid);
  
  merge(A, mid+1, right);
  
  for(i=left;i<=mid;i++) t[i] = A[i];
  for(i=mid+1,j=right;i<=right;i++,j--) t[i] = A[j];
  i = left;
  j = right;
  
  for(k=left;k<=right;k++,cnt++){
    if(t[i] <= t[j]) A[k] = t[i++];
    else A[k] = t[j--];
  }
  
}



Measured memory_bytes: 5600
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
int a[maxn];
ll n,m,tot;
ll sum[maxn];
ll res,ans;
int main()
{
   scanf("%lld%lld",&n,&m);

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

   sort(a+1,a+1+n);
   for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];

   int l=0,r=2e5+1;
   while(l<=r)
   {
       int mid=(l+r)/2;
       tot=0;
       for(int i=1;i<=n;i++)
       {
         int pos=lower_bound(a+1,a+1+n,mid-a[i])-a;
         tot+=n-pos+1;
       }
       if(tot>=m)
       {
           l=mid+1;
           res=mid;
       }
       else
       {
           r=mid-1;
       }
   }
    tot=0;
   //cout<<ans<<endl;
   for(int i=1;i<=n;i++)
   {
        int  pos=lower_bound(a+1,a+n+1,res-a[i])-a;
        ans+=sum[n]-sum[pos-1]+a[i]*(n-pos+1);
        tot+=n-pos+1;
   }
   printf("%lld\n",ans-res*(tot-m));

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int par[100000];
int dep[100000];
int siz[100000];

void dfs(const Graph& G, int v, int prev) {
	par[v] = prev;
	dep[v] = prev == -1 ? 0 : dep[prev] + 1;
	for (auto to : G[v]) if (to != prev) {
		dfs(G, to, v);
		siz[v] += siz[to];
	}
	siz[v]++;
}

int main()
{
	int N;
	cin >> N;
	Graph G(N);
	for (int i = 0, a, b; i < N - 1; i++) {
		cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(G, 0, -1);
	int t = N - 1;
	for (int i = 0; i < (dep[N - 1] - 1) / 2; i++) {
		t = par[t];
	}
	if (siz[t] * 2 >= N) {
		puts("Snuke");
	}
	else {
		puts("Fennec");
	}
	return 0;
}


Measured memory_bytes: 14720
while True:
  a = int(input())
  if a == 0:break
  b=(1000-a)//500
  c=(1000-a-500*b)//100
  d=(1000-a-500*b-100*c)//50
  e=(1000-a-500*b-100*c-50*d)//10
  f=(1000-a-500*b-100*c-50*d-10*e)//5
  g=1000-a-500*b-100*c-50*d-10*e-5*f
  print(b+c+d+e+f+g)


Measured memory_bytes: 5588
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int n, m, p, a[12345], ans;
signed main() {
	cin >> n >> m >> p;
	for (int i = 0; i < m; i++) { cin >> a[i]; a[i] -= p; if (a[i] < 0)a[i] += n; }
	sort(a, a + m);
	ans = min(n - a[0], a[m - 1]);
	for (int i = 0; i < m - 1; i++) {
		ans = min(ans, a[i] + (n - a[i + 1]) + min(a[i], n - a[i + 1]));
	}
	cout << ans*100 << endl;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
const int64_t INF=9999999999999999;
int main() {
 int N,K;
 cin>>N>>K;
 vector<int>h(N);
 int count=0;
 for(int i=0;i<N;i++){
    cin>>h[i];
    if(h[i]>=K){count++;}
 }
 
 cout<<count<<endl;
 return 0;}

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

using namespace std;

const int MOD = 1000000007;
int main(void) {
    int n;
    cin >> n;
    vector<int> A(n);
    map<int, bool> already;
    for (auto &a: A) cin >> a;
    int cnt = 0;
    bool can = true;
    for (auto a : A) {
        float x = (float) (a + n - 1) / 2.0f;
        int ix = (int) x;
        bool same = 2 * ix == (n - 1);
        if (floor(x) == x) {
            if (same) {
                if (already[x]) {
                    can = false;
                    break;
                }
            } else {
                if (!already[x]) cnt++;
            }
            already[x] = true;
        } else {
            can = false;
            break;
        }
    }
    if (!can) {
        cout << 0 << endl;
        return 0;
    }

    long long ans = 1;
    for (int i = 0; i < cnt; ++i) {
        ans = ans * 2 % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5968
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N,C;cin>>N>>C;
  vector<int64_t>x(N);
  vector<int64_t>v(N);
  for(int i=0;i<N;i++){
  cin>>x.at(i);
    cin>>v.at(i);
  }vector<int64_t>V1(N);
  V1.at(0)=v[0];
  for(int i=1;i<N;i++)
    V1.at(i)=V1.at(i-1)+v.at(i);
  for(int i=0;i<N;i++)
    V1.at(i)-=x.at(i);
  vector<int64_t>V2(N);
  V2.at(0)=v[N-1];
  for(int i=1;i<N;i++)
    V2.at(i)=V2.at(i-1)+v.at(N-1-i);
  for(int i=0;i<N;i++)
    V2.at(i)-=(C-x.at(N-1-i));
  vector<int64_t>V1best(N);V1best[0]=V1[0];
  for(int i=1;i<N;i++)
    V1best[i]=max(V1best[i-1],V1[i]);
  vector<int64_t>V2best(N);V2best[0]=V2[0];
  for(int i=1;i<N;i++)
    V2best[i]=max(V2best[i-1],V2[i]);
  int64_t ans=0;
  ans=max(ans,V1best[N-1]);
  ans=max(ans,V2best[N-1]);
  for(int i=0;i<N-1;i++)
    ans=max(V1[i]-x[i]+V2best[N-2-i],ans);
   for(int i=0;i<N-1;i++)
    ans=max(V2[i]+x[N-1-i]-C+V1best[N-2-i],ans);
cout<<ans<<endl;
  return 0;
}

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

string s;
int n, a=-1, z;

int main(){
	cin>>s;
	n=s.size();
	
	for(int i=0; i<n; i++){
		if(a==-1&&s[i]=='A') a=i;
		else if(s[i]=='Z') z=i;
	}
	cout<<z-a+1<<endl;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int h,w,k; cin>>h>>w>>k;
	string s[h]; rep(i,h) cin>>s[i];
	int a[h][w]; CLR(a);
	int now=0;
	map<int,int> c;
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='#') c[i]++;
		}
	}

	queue<int> z,q;
	rep(i,h){
		if(c[i]==0){
			z.push(i);
			continue;
		}
		q.push(i);
		int next=now+1;
		rep(j,w){
			a[i][j]=next;
			if(s[i][j]=='#') next=min(now+c[i],next+1);
		}
		now=next;
	}

	while(q.size()>1&&!z.empty()){
		if(z.front()<q.front()){
			rep(j,w) a[z.front()][j]=a[q.front()][j];
			z.pop();
		}else{
			q.pop();
		}
	}
	while(!z.empty()){
		rep(j,w) a[z.front()][j]=a[q.front()][j];
		z.pop();
	}

	rep(i,h){
		rep(j,w) cout<<a[i][j]<<' ';
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int n,ans=1;
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		ans=(1ll*ans*i)%mod;
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include <bits/stdc++.h>

#define ull unsigned long long
#define ll long long
#define inf 0x3f3f3f
#define endl '\n'
#define pii pair<long long,long long>

using namespace std;

const int maxn=5000;
const int mod=1e9+7;

double p[maxn];

string k[maxn];
ll q[maxn];

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>k[i]>>q[i];
    }
    string x;
    cin>>x;
    int ans=0;
    for(int i=n-1;i>=0;i--) {
        if(x==k[i]) {
            break;
        }
        ans+=q[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
def dist(x,y):
  result=0;
  for i in range(len(x)):
    result+=(x[i]-y[i])*(x[i]-y[i])
  return result
def isSquare(x):
  s=int(math.sqrt(x))
  return s*s==x

N,D=[int(i) for i in input().split()];
X=[[int(i) for i in input().split()]for j in range(N)];
ans=0;
for i in range(N):
  for j in range(i+1,N):
    if(isSquare(dist(X[i],X[j]))):
      ans+=1
print(ans)
    

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int count;
  count = 0;
  int checker;
  checker = 0;
  int checka;
  checka = 0;
  if (S.at(0) == 'A') {
    checka++;
  }
  for (int i = 2; i < S.size()-1; i++) {
    if( S.at(i) == 'C') {
      count++;
    }
  }
  for (int i = 1; i < S.size(); i++) {
    if( isupper(S.at(i))) {
      checker++;
    }
  }
  if (checka == 1 && count == 1 && checker == 1) {
    cout << "AC" << endl;
  }
   else {
     cout << "WA" << endl;
   }
}
     

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

long n, q;
// 木
vector<vector<long>> to;
vector<long> ans;
void dfs(long i, long p);

int main() {
  cin >> n >> q;
  to.assign(n, vector<long>());
  rep(i, n - 1) {
    long a, b;
    cin >> a >> b;
    // 0-indexed に揃える
    a--;
    b--;
    // aからbへのエッジを追加
    to[a].push_back(b);
    // 無向グラフなので逆方向のエッジも追加
    to[b].push_back(a);
  }

  ans.resize(n);
  rep(i, q) {
    long p, x;
    cin >> p >> x;
    // 0-indexedに変換
    p--;
    ans[p] += x;
  }

  dfs(0, -1);

  rep(i, ans.size()) { cout << ans[i] << " "; }
  cout << endl;
}

// p: 親ノード
void dfs(long i, long p = -1) {
  for (auto v : to[i]) {
    // 親には戻らない
    if (v == p) {
      continue;
    }

    ans[v] += ans[i];
    dfs(v, i);
  }
}


Measured memory_bytes: 24320
import math

a,b,x = map(int,input().split())

z = 2*b-2*x/(a*a)
if z > b:
    print(math.degrees(math.atan(a*b*b/(2*x))))
else:
    print(math.degrees(math.atan((2*b-2*x/(a*a))/a)))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ll long long
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int n=2*b+1;
	cout<<floor((a-1)/n)+1<<endl;
	return 0;
}

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

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

    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<6;i++)if(s[i]=='1')ans++;
    cout<<ans<<endl;

}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = (a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (a); i <= (long long)(n); i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std;

int main(void)
{
    int n, m;
    cin >> n >> m;

    v_double a(n);
    double sum = 0;
    irep(i,n) {
        cin >> a[i];
        sum += a[i];
    }

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

    auto it = lower_bound(a.begin(), a.end(), sum/(4*m));

    if (it != a.end()) {
        auto pos = std::distance(a.begin(), it);
        if((int) pos <= n-m) { 
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}
/** atcoder **/


Measured memory_bytes: 256
//om namah shivaaay//
#include <bits/stdc++.h>
#define input int t;cin>>t;while(t--)
#define Om_namah_Shivaay ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL),cout.precision(10)
 #define ll long long
 #define vi  vector<int>vec
 #define pb push_back
 #define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
 #define f(i, a, b) for (int i = 0; i < (b); i++)
 #define w(t) int t;cin>>t;while(t --)
#define fr(i, a, b) for (int i = (a); i >= (b); i--)
 const int N=1e5 +5;
 using namespace std;
 int main()
 {
    Om_namah_Shivaay;
    string s;
    int m=0,n=0,o=0,p=0;
    input{
			cin>>s;
		if(s=="AC")
		   m++;
        else if(s=="WA")
          n++;		
        else if(s=="TLE")
        o++;		
        else 	
		  p++;
	  }
		
		cout<<"AC x "<<m<<endl; 
		cout<<"WA x "<<n<<endl; 
		cout<<"TLE x "<<o<<endl; 
		cout<<"RE x "<<p<<endl; 
}


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

using namespace std;

#define PROBLEM "B"
#define TESTC ""

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
typedef pair<int, int> P;
#define F first
#define S second
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define LL long long

int main()
{
	#ifdef DBG
	freopen(PROBLEM TESTC ".in", "r", stdin);
	freopen(PROBLEM ".out", "w", stdout);
	#endif

	string str;
	while(cin >> str)
	{
		bool flag = 0;
		for(int i = 0; i < str.size(); i++)
		{
			if(i % 2 == 0)
			{
				if(str[i] == 'L')
				{
					cout << "No\n";
					flag = 1;
					break;
				}
			}
			else
			{
				if (str[i] == 'R')
				{
					cout << "No\n";
					flag = 1;
					break;
				}
			}
		}
		if(!flag)
			cout << "Yes\n";
	}
	return 0;
}

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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  for(int i = 0; i < n; i++){
    cin >> l.at(i);
  }

  int pos = 0;
  int ans = 1;
  for(int i = 0; i < n; i++) {
    pos += l.at(i);
    if(pos > x) break;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	alphabets = [chr(ord('a')+i) for i in range(26)]
	mod_list = []
	while n > 26:
		mod_list.append(n % 26)
		n = n // 26
	if n > 0:
		mod_list += [n]
	ans = ''
	def minus_one(i):
		if mod_list[i] != 0:
			mod_list[i] -= 1
		else:
			minus_one(i+1)
			mod_list[i] = 25
		return mod_list[i]
	for i in range(len(mod_list)):
		if i < len(mod_list) -1 or mod_list[i] > 0:
			ans = alphabets[minus_one(i)] + ans
	print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 27120
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	if (a+b>=10) cout<<"error";
	else cout<<(a+b);
	return 0;
}


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

int MOD=1000000007;
int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}
int gyaku(int n){
    return modpow(n,MOD-2);
}
signed main() {
int n,k;
cin>>n>>k;
vector<int>a(n);
rep(i,n)cin>>a[i];
sort(a.begin(),a.end());
//combmaekeisan
vector<int>kai(100002);
kai[0]=1;
rep(i,100001){
  kai[i+1]=(i+1)*kai[i]%MOD;
}
//suuretunowa
vector<int>s(n-k+2);
for(int i=k;i<=n;i++){
  s[i+1-k]=(s[i-k]+(kai[i-2]*gyaku(kai[k-2]))%MOD*gyaku(kai[i-k])%MOD)%MOD;
}
int ans=0;
//tasu
for(int i=n-1;i>=k-1;i--){
  ans=(ans+s[i-k+2]*a[i]%MOD)%MOD;
  while(ans<0)ans+=MOD;
}
//hiku
for(int i=0;i<=n-k;i++){
  ans=(ans-s[n-k-i+1]*a[i]%MOD)%MOD;
  while(ans<0)ans+=MOD;
}

cout<<ans<<endl;
}


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

#define LL long long
const int N = 1e5 + 5;
int n, m, x, y, s, t, vis[3][N];
queue<pair<int,int>> q;
vector<int> g[N];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    cin >> n >> m;
    while(m--) {
        cin >> x >> y;
        g[x].push_back(y);
    }    

    cin >> s >> t;
    q.push({s, 0});
    vis[0][s] = 1;

    while(!q.empty()) {
        pair<int,int> u = q.front();
        q.pop();
        if(u.first == t && u.second % 3 == 0) return cout << u.second / 3, 0;

        int d = u.second + 1;
        for(int v : g[u.first]) if(vis[d % 3][v] == 0) vis[d % 3][v]++, q.push({v, d});
    }
    cout << -1;
}

Measured memory_bytes: 10268
n,k = map(int,input().split())
list1 = [int(input()) for i in range(n) ]
list1.sort()
treemin = 10**9
for i in range(len(list1)-k+1):
	treemin = min(treemin,list1[i+k-1]-list1[i])
print(treemin)

Measured memory_bytes: 50392
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static void Swap<T>(ref T a, ref T b)
    {
	var t = a;
	a = b;
	b = t;
    }

    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int H, W, h, w;
	var t = ReadIntArray();
	H = t[0];
	W = t[1];
	t = ReadIntArray();
	h = t[0];
	w = t[1];

	int ans = (H-h)*(W-w);
	WriteLine(ans);
    }
}


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

#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front

typedef long long int ll;
typedef pair<int, int> ii; // are aligned to the right like this
typedef vector<ii> vii;  //vector pair
typedef vector<int> vi;   //vector integer
typedef vector<string> vs; //vector string

int main() 
{
    	string s1,s2;
    cin>>s1>>s2;
    int min=s2.length();
    for(int i=0;i<s1.length()-s2.length()+1;i++)
    {
        int c=0;
        for(int j=0;j<s2.length();j++)
        {
            if(s1[i+j]!=s2[j])
                c++;
            
        }
        if(c<min)
          min=c;  
    }
    
    cout<<min;
}
 




/*



*/

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define watch(x) cerr << (#x) << " is " << (x) << endl;
using namespace std;
const int MAXN = 100001;
const int INF = 1234567890;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	n %= 10;
	if (n == 3){
		cout << "bon";
	}
	else if (n == 0 or n == 1 or n == 6 or n == 8){
		cout << "pon";
	}
	else{
		cout << "hon";
	}
	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
 
signed main(void){
    int N;
    cin>>N;
    char s[N];
    for (int i=0;i<N;i++){
      cin >> s[i];
    }
    int red=0;
    int blue=0;
    for(int i=0;i<N;i++){
      if(s[i]=='R'){
        red++;
      }else{
        blue++;
      } 
    }
    if(red>blue){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;

namespace {

#define VEVE(i, a, b) for (ll i = a, __##i = b; i < __##i; ++i)
#define DYDY(i, a, b) for (ll i = a, __##i = b; i > __##i; --i)
#define RARA(x, seq) for (auto &x : seq)
#define SIZE(x) ((ll)(x.size()))
#define ALL(x) x.begin(), x.end()

typedef int ll;
typedef double dd;

void Solve(ll) {
  ll n;
  string str;
  cin >> n >> str;
  vector<ll> pos[2];
  VEVE(i, 0, 2 * n) {
    pos[str[i] - 'a'].push_back(i);
  }
  vector<pair<ll, ll>> ab, ba;
  VEVE(i, 0, n) {
    if (pos[0][i] < pos[1][i])
      ab.emplace_back(pos[0][i], pos[1][i]);
    else
      ba.emplace_back(pos[1][i], pos[0][i]);
  }
  ba.emplace_back(1e7, 1e7 + 1);
  auto is_less = [&](const vector<ll>& a, const vector<ll>& b) {
    VEVE(i, 0, min(SIZE(a), SIZE(b))) if (str[a[i]] != str[b[i]]) {
        return str[a[i]] < str[b[i]];
      }
    return SIZE(a) < SIZE(b);
  };
  // max string starting at ba-segment >= i
  vector<vector<ll>> dp(SIZE(ba) + 1);
  queue<ll> eds;
  DYDY(i, SIZE(ba) - 2, -1) {
    while (not eds.empty())
      eds.pop();
    eds.push(ba[i].second);
    vector<ll> now;
    now.push_back(ba[i].first);
    VEVE(j, i + 1, SIZE(ba)) {
      while (not eds.empty() and ba[j].first > eds.front()) {
        now.push_back(eds.front());
        eds.pop();
      }
      if (eds.empty()) {
        dp[i] = now;
        RARA(v, dp[j]) {
          dp[i].push_back(v);
        }
        break;
      } else {
        eds.push(ba[j].second);
        now.push_back(ba[j].first);
      }
    }
    if (is_less(dp[i], dp[i + 1]))
      dp[i] = dp[i + 1];
  }
  auto seq = dp.front();
  RARA(oth, ab) {
    if (seq.empty() or oth.first > seq.back()) {
      seq.push_back(oth.first);
      seq.push_back(oth.second);
    }
  }
  string res;
  RARA(idx, seq) res += str[idx];
  cout << res << endl;
}

void Init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
}

int32_t main() {
#ifdef AZN
  freopen("input.txt", "r", stdin);
#endif
  Init();
  ll tests = 1;
//  cin >> tests;
  VEVE(test, 1, tests + 1) Solve(test);
  return 0;
}
// bbaababababa

Measured memory_bytes: 38528
#include <stdio.h>

#define MAX 25

typedef struct{
  int l,r,par;
} node;

node N[MAX];

void init(int);
void Preorder(int);
void Inorder(int);
void Postorder(int);

int main(){
  int n,i,id,l,r;
  int p;

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

  for(i = 0 ; i < n ; i++){
    scanf("%d%d%d" ,&id ,&l ,&r);

    if(l != -1){
      N[id].l = l;
      N[l].par = id;
    }
    if(r != -1){
      N[id].r = r;
      N[r].par = id;
    }
  }

  for(i = 0 ; i < n ; i++){
    if(N[i].par == -1){
      p = i;
      break;}
}

puts("Preorder");
Preorder(p);
puts("");

puts("Inorder");
Inorder(p);
puts("");

puts("Postorder");
Postorder(p);
puts("");

return 0;
}

void init(int n){
  int i;

  for(i = 0 ; i < n ; i++){
    N[i].par = N[i].l = N[i].r = -1;
  }
}

void Preorder(int p){
  if(p != -1){
    printf(" %d" ,p);
    Preorder(N[p].l);
    Preorder(N[p].r);
  }
}

void Inorder(int p){
  if(p != -1){
    Inorder(N[p].l);
    printf(" %d" ,p);
    Inorder(N[p].r);
  }
}

void Postorder(int p){
  if(p != -1){
    Postorder(N[p].l);
    Postorder(N[p].r);
    printf(" %d" ,p);
  }
}


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

#define int long long

#define inf 1000000007LL
#define mod 1000000007LL

#define rep(i, n) for(int i = 0; i < (n); i++)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)
#define rfor(i, s, t) for(int i = (t) - 1; i >= (s); i--)

signed main() {
  int n, p;
  cin >> n >> p;
  int now[2] = {1, 0};
  rep(i, n) {
    int w;
    cin >> w;
    w %= 2;
    int p0 = now[w];
    int p1 = now[w ^ 1];
    now[0] += p0;
    now[1] += p1;
  }
  cout << now[p] << endl;
}


Measured memory_bytes: 256
n = int(input())
s = {}
m = 1
for i in range(n):
  p = input()
  if p in s:
    s[p] += 1
    if m < s[p]:
      m = s[p]
  else:
    s[p] = 1

l = [kv[0] for kv in s.items() if kv[1] == m]

l.sort()

for i in l:
  print(i)

Measured memory_bytes: 32096
#include <iostream>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <cstring>

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))

#define INF (int)1e9+7

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

using namespace std;

typedef long long ll;

int main(){
    int a,b,c;
    int x,y;

    cin >> a >> b >> c >> x >> y;

    int p = max(x, y);

    ll plan[4];
    plan[0] = a*x + b*y;
    plan[1] = a*max(x - y, 0) + 2*c*y;
    plan[2] = b*max(y - x, 0) + 2*c*x;
    
    ll mini = INF;
    rep(i, 3){
        mini = min(mini, plan[i]);
    }
    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
  ll n,k;ll now=0;ll h[400005]={0};
  ll L[12]={0};ll R[12]={0};ll M=998244353;
int main(){
  cin>>n>>k;
  for(int i=1;i<=k;i++)cin>>L[i]>>R[i];
  for(int j=1;j<=k;j++){h[L[j]+1]++;h[R[j]+1+1]--;}
  for(int i=2;i<n;i++){
    now+=h[i];
    if(now<0)now+=100*M;
    now%=M;
    for(int j=1;j<=k;j++){h[L[j]+i]+=now;h[R[j]+i+1]-=now;}
  }
  cout<<((now+h[n])+100*M)%M<<endl;}


Measured memory_bytes: 6708
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
char a[N],b[N];
vector<int> pos[26];
int v[N];
int nxt[N];
int n;
int q[N],hed=1,tail=0;
int main()
{
	scanf("%d",&n);
	scanf("%s%s",a+1,b+1);
	if(!strcmp(a+1,b+1)){
		puts("0");
		return 0;
	}
	for(int i=0;i<26;i++)pos[i].push_back(0);
	for(int i=1;i<=n;i++){
		pos[a[i]-'a'].push_back(i);
		v[a[i]-'a']++;
	}
	nxt[n+1]=n;
	int ans=0;
	for(int i=n;i;i--){
		nxt[i]=nxt[i+1];
		if(b[i]==b[i-1])continue;
		int R=min(nxt[i+1],i);
		int c=b[i]-'a';
		while(v[c]&& pos[c][v[c]]>R)v[c]--;
		if(v[c]){
			nxt[i]=pos[c][v[c]];
		}else {
			puts("-1");
			return 0;
		}
		while(hed<=tail){
			if(q[hed]-(tail-hed+1)+1>i){
				hed++;
			}else{
				break;
			}
		}
		q[++tail]=nxt[i];
		if(i!=nxt[i]){
			ans=max(ans,tail-hed+1);
		}
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 16968
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
using ll = long long;
using P = pair<ll,ll>;
 
int main (){
  string s;
  ll n;
  cin>>s>>n;
  deque<char> d;
  rep(i,s.size()){
    char a = s.at(i);
    d.push_back(a);
  }
  ll a = 0;
  rep(i,n){
    ll t;cin>>t;
    if (t == 1){
      a++;
    }
    else {
      ll f;
      char p;
      cin>>f>>p;
      if (f == 1){
        if (a%2 == 0){
          d.push_front(p);
        }
        else{
          d.push_back(p);
        }
      }
      else{
        if (a%2 == 0){
          d.push_back(p);
        }
        else {
          d.push_front(p);
        }
      }
    }
  }
  ll m = d.size();
  if (a%2 == 0){
    rep(i,m){
      cout << d.at(i);
    }
  }
  else {
    rep(i,m){
      cout << d.at(m-1-i);
    }
  }
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int nums[10];
	while(1){
		for(int i = 0; i < 10; i++){
			char ch;
			cin>>ch;
			nums[i]=ch-'0';
		}
		if(cin.eof())
			break;


		for(int i = 9; i >= 0; i--){
			int nn[10];
			for(int j = 0; j < i; j++){
				nn[j]=(nums[j]+nums[j+1])%10;
			}
			for(int j = 0; j < 10; j++){
				nums[j]=nn[j];
			}
		}
		cout<<nums[0]<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

bool f(pair<int, int> a, pair<int, int> b){

}


int main() {
    int n;
    cin >> n;
    vector<ll> v;

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        ans -= b;
        v.emplace_back(a+b);
    }
    sort(v.begin(), v.end(), greater<>());
    for (int i = 0; i < n; ++i) {
        if(i%2 == 0) ans += v[i];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long

int main(void){
    ll n;
    cin >> n;
    ll x[n];
    ll check = 0;
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        cin >> x[i];
        ans += x[i]*x[i];
    }
    sort(x, x+n);
    for(ll i = 1; i <= 100; i++){
        check = 0;
        for(ll j = 0; j < n; j++)
            check += abs(i-x[j])*abs(i-x[j]);
        ans = min(ans, check);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
void Rec(int,int);
 
int P[41],I[41],Po[41],n,now=0,s;
 
int main()
{
  int i;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&P[i]);
  }
  for(i=0;i<n;i++){
    scanf("%d",&I[i]);
  }
  Rec(0,n);
  for(i=0;i<n-1;i++){
    printf("%d ",Po[i]);
  }
  printf("%d\n",Po[i]);
return 0;
}
 
void Rec(int l,int r)
{
  int c,m;
  if(l>=r)return;
  c=P[now++];
  m=Find(c);
  Rec(l,m);
  Rec(m+1,r);
  //printf("%d ",c);
  Po[s++]=c;
   
}
 
int Find(int c)
{
  int i;
  for(i=0;i<n;i++){
    if(c==I[i])return i;
  }
  return 0;
}


Measured memory_bytes: 2092
#include<cstdio>
#include<algorithm>
using namespace std;
#define INF 1000000000
int N,M,n,m;
int main()
{
	scanf("%d%d%d%d",&N,&M,&n,&m);
	if(N%n==0&&M%m==0)
	{
		printf("No\n");
		return 0;
	}
	int k=(INF-1)/(n*m-1);
	int l=k*(n*m-1)+1;
	l=-l;
	printf("Yes\n");
	for(int i=1;i<=N;i++)
	{
		for(int j=1;j<=M;j++)
			if(i%n==0&&j%m==0)
				printf("%d ",l);
			else printf("%d ",k);
		printf("\n");
	}
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020, maxk = 10100, maxs = 1000100;
using bs = bitset<maxk>;
using ii = pair<int,int>;
bs can[maxn];
string s[maxn];
char ss[maxk];
int len[maxn];
ii q[2][maxs];
int tp[2];
int main(){
	int n, k; scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++) {
		scanf("%s", ss);
		s[i] = ss;
	}
	for(int i = 0; i < n; i++) len[i] = s[i].size();
	can[n][0] = 1;
	for(int i = n - 1; i >= 0; i--) can[i] = can[i + 1] | (can[i + 1] << len[i]);
	for(int i = 0; i < n; i++) if(k - len[i] >= 0 && can[i + 1][k - len[i]]) q[0][tp[0]++] = {i, 0};
	int cur = 0;
	string res;
	for(int i = 1; i <= k; i++){
		char best = 'z';
		tp[cur] = min(tp[cur], 20000);
		for(int j = 0; j < tp[cur]; j++) best = min(best, s[q[cur][j].first][q[cur][j].second]);
		res.push_back(best);
		int f = n;
		tp[cur ^ 1] = 0;
		for(int j = 0; j < tp[cur]; j++){
			int x = q[cur][j].first, y = q[cur][j].second;
			if(s[x][y] != best) continue;
			if(y + 1 == len[x]) f = min(f, x);
			else q[cur ^ 1][tp[cur ^ 1]++] = {x, y+1};
		}
		for(int j = f + 1; j < n; j++){
			if(k - i - len[j] >= 0 && can[j + 1][k - i - len[j]]){
				q[cur ^ 1][tp[cur ^ 1]++] = {j, 0};
			}
		}
		cur ^= 1;
	}
	printf("%s\n", res.c_str());
	return 0;
}



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

int main() {

  string l = "yuiophjklnm";
  while(1) {
      string s;
      cin >> s;

      if(s == "#") break;

      int ans = 0;
      bool r = false;
      for(int i = 0; i < s.size(); i++) {

        bool flag = false;
        for(int j = 0; j < l.size(); j++) {
          if(s[i] == l[j]) {
            flag = true;
            break;
          }
        }

        if(flag) {
          if(!r && i != 0) ans++;
          r = true;
        } else {
          if(r && i != 0) ans++;
          r = false;
        }
      }
      cout << ans << endl;
  }

	return 0;
}

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

int main(){
  string march = "MARCH";
  int N;
  cin >> N;
  long long C[26];
  fill(C,C+26,0);
  for(int i = 0; i < N; ++i){
    string s;
    cin >> s;
    ++C[s[0]-'A'];
  }
  long long ans = 0;
  for(int i = 0; i < 5; ++i){
    for(int j = 0; j < i; ++j){
      for(int k = 0; k < j; ++k){
        ans += C[march[i]-'A']*C[march[j]-'A']*C[march[k]-'A'];
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define W while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007

int main() {
    FASTIO;
    ll n,k,rem,d,s;
    cin>>n>>k;
    if(n%k==0)
    cout<<0;
    else
    {
        rem=n%k;
        s=abs(rem-k);
        d=min(rem,s);
        cout<<d;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	private static final int BASE = -2;
	public static void main(String[] args) {
	  FastReader sc = new FastReader();
	  int n = sc.nextInt();
	  String res = "";
	  if (n == 0) {
		  System.out.println("0");
		  System.exit(0);
	  } else {
		  while (n != 0) {
			  int d = n % BASE;
			  n /= BASE;
			  if (d < 0) {
				  d = d - BASE;
				  n++;
			  }
			  res = d + res;
		  }
	  }
	  System.out.println(res);
	  System.exit(0);
  }
  
  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() { 
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


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

using namespace std;

#define inf (int)1e9
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;

const int N = 123456;
const int M = 1234567;

#define Cft C
#define Dft D

int Cft[N];
int Dft[N];

int query(int x, int t){

	int ans = 0;
	while(x){
		ans = max(ans, t ? C[x] : D[x]);
		x -= x & -x;
	}

	return ans;
}


void add(int x, int val, int t){

	while(x <= 123456){
		t? C[x] = max(C[x], val) : D[x] = max(D[x], val);
		x += x & -x;
	}
}

int main(int argc, char const *argv[])
{
	
	#ifdef Cyborg1o1
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif	

	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int a, b, c;

	cin >> a >> b >> c;

	if(c >= a && c <= b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;				
	
}

Measured memory_bytes: 256
n, blue, red = list(map(int, input().split()))

if blue == 0:
    print(0)
    exit()

if n <= blue:
    print(n)
    exit()

if n <= blue + red:
    print(blue)
    exit()

q = n // (blue + red)
r = n % (blue + red)

cnt = q * blue

while True:
    if r >= blue:
        cnt += blue
        r -= blue
        if r <= red:
            break
        elif r > red:
            r -= red
    else:
        cnt += r
        break

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}}; ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
/*!* [modint] *!*/
/*+* 剰余環整数 *+*/
struct int_m;
int_m invmod(int_m);
int_m powmod(int_m, i64);
struct int_m {
    static i64 m;
    i64 v;
    int_m() {}
    int_m(i64 x) { v = (x % m + m) % m; }
    int_m operator+(const int_m &y) const { return v + y.v > m ? v + y.v - m : v + y.v; }
    int_m operator-(const int_m &y) const { return v - y.v < 0 ? v - y.v + m : v - y.v; }
    int_m operator*(const int_m &y) const { return (v * y.v) % m; }
    bool operator==(const int_m &y) const { return v == y.v; }
    bool operator!=(const int_m &y) const { return v != y.v; }
    void operator+=(const int_m &y) { *this = *this + y; }
    void operator-=(const int_m &y) { *this = *this - y; }
    void operator*=(const int_m &y) { *this = *this * y; }
    friend istream &operator>>(istream &ist, int_m &m) { ist >> m.v; return ist; }
    friend ostream &operator<<(ostream &ost, int_m m) { ost << m.v; return ost; }
    int_m operator^(const i64   &y) const {
        int_m v = 1; int p = y;
        for (int_m b = *this; p > 0; p >>= 1, b *= b) if (p & 1) v *= b;
        return v;
    }
    void operator^=(const i64   &y) { *this = *this ^ y; }
    // for prime mod
    int_m operator/(const int_m &y) const { return *this * (y ^ (m - 2)); }
    void operator/=(const int_m &y) { *this = *this / y; }
};
i64 int_m::m;

/*!* [modfact] *!*/
/*+* 剰余階乗
     requirement: modint *+*/
struct ModFact {
    static vector<int_m> val, inv;
    static void Init(int N) { // O(N)
        val = vector<int_m>(++N, 1), inv = vector<int_m>(N, 1);
        for(int i = 1; i < N; i++) val[i] = val[i - 1] * i;
        inv[N - 1] = int_m(1) / val[N - 1];
        for(int i = N - 1; i > 0; i--) inv[i - 1] = inv[i] * i;
    }
};
vector<int_m> ModFact::val, ModFact::inv;
int_m Permutation(int n, int m) {
    if(n < m || m < 0 || n < 0) return 0;
    return ModFact::val[n] * ModFact::inv[n - m];
}
int_m Combination(int n, int m) {
    if(n < m || m < 0 || n < 0) return 0;
    return ModFact::val[n] * ModFact::inv[m] * ModFact::inv[n - m];
}
int_m Combination(vector<int> &n) {
    int s = accumulate(n.begin(), n.end(), 0);
    int_m r = ModFact::val[s];
    for(auto x : n) r *= ModFact::inv[x];
    return r;
}
int_m Multichoose(int n, int m) { return Combination(n + m - 1, m); }

int main() {
    int_m::m = 1e9 + 7;
    const int M = 26;
    int K, L, N;
    cin >> K;
    string S;
    cin >> S;
    L = S.size(), N = K + L;
    ModFact::Init(N);
    int_m ans = 0;
    for(int h = 0; h <= N - L; h++) {
        ans += Combination(N - h - 1, L - 1) *
               (int_m(M) ^ h) *
               ((int_m)(M - 1) ^ (N - h - L));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35592
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
a,v=NM()
b,w=NM()
t=N()
l=abs(a-b)
if w>=v:
    print("NO")
else:
    if (v-w)*t>=l:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9208
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, bufio.MaxScanTokenSize)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	defer out.Flush()

	k, _ := strconv.Atoi(next())
	s := next()

	if len(s) > k {
		fmt.Fprintln(out, s[:k]+"...")
	} else {
		fmt.Fprintln(out, s)
	}
}


Measured memory_bytes: 1764
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define INF 1e14+1
typedef long long int ll;
typedef pair<ll,ll> mypair;


int main(){
	int n;
	cin>>n;
vector<vector<mypair> > g(n+1);
for(int i=0;i<n-1;i++){
ll a,b,c;
cin>>a>>b>>c;
g[a].push_back(mypair(c,b));
g[b].push_back(mypair(c,a));
}
//cout<<"ok"<<endl;
ll p,k;
cin>>p>>k;
//cout<<p<<' '<<k<<endl;
vector<ll> cost(n+1,INF);
priority_queue<mypair> q;
q.push(mypair(0,k));
//cout<<INF<<endl;
while(!q.empty()){
	
	mypair now= q.top();
	//cout<<-now.first<<' '<<now.second<<endl;
	q.pop();
	if(-now.first>cost[now.second])continue;
	cost[now.second]=-now.first;
	//cout<<now.second<<endl;
	//cout<<g[now.second].size()<<endl;
	for(int i=0;i<g[now.second].size();i++){
	q.push(mypair(now.first-g[now.second][i].first,g[now.second][i].second));
	}

	}
//	cout<<"ok"<<endl;
//	for(int i=0;i<n;i++)cout<<cost[i]<<endl;
	for(int i=0;i<p;i++){
	ll x,y;
	cin>>x>>y;
	
	cout<<cost[x]+cost[y]<<endl;
	}
	return 0;
}


Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
namespace IO
{
    const int __S=(1<<20)+5;char __buf[__S],*__H,*__T;
    inline char getc()
    {
        if(__H==__T) __T=(__H=__buf)+fread(__buf,1,__S,stdin);
        if(__H==__T) return -1;return *__H++;
    }
    template <class __I>inline void read(__I &__x)
    {
        __x=0;int __fg=1;char __c=getc();
        while(!isdigit(__c)&&__c!='-') __c=getc();
        if(__c=='-') __fg=-1,__c=getc();
        while(isdigit(__c)) __x=__x*10+__c-'0',__c=getc();
        __x*=__fg;
    }
    inline void readd(double &__x)
    {
        __x=0;double __fg=1.0;char __c=getc();
        while(!isdigit(__c)&&__c!='-') __c=getc();
        if(__c=='-') __fg=-1.0,__c=getc();
        while(isdigit(__c)) __x=__x*10.0+__c-'0',__c=getc();
        if(__c!='.'){__x=__x*__fg;return;}else __c=getc();
        double __t=1e-1;while(isdigit(__c)) __x=__x+1.0*(__c-'0')*__t,__t=__t*0.1,__c=getc();
        __x=__x*__fg;
    }
    inline void reads(char *__s,int __x)
    {
        char __c=getc();int __tot=__x-1;
        while(__c<'a'||__c>'z') __c=getc();
        while(__c>='a'&&__c<='z') __s[++__tot]=__c,__c=getc();
        __s[++__tot]='\0';
    }
    char __obuf[__S],*__oS=__obuf,*__oT=__oS+__S-1,__c,__qu[55];int __qr;
    inline void flush(){fwrite(__obuf,1,__oS-__obuf,stdout);__oS=__obuf;}
    inline void putc(char __x){*__oS++ =__x;if(__oS==__oT) flush();}
    template <class __I>inline void print(__I __x)
    {
        if(!__x) putc('0');
        if(__x<0) putc('-'),__x=-__x;
        while(__x) __qu[++__qr]=__x%10+'0',__x/=10;
        while(__qr) putc(__qu[__qr--]);
    }
    inline void prints(const char *__s,const int __x)
    {
        int __len=strlen(__s+__x);
        for(int __i=__x;__i<__len+__x;__i++) putc(__s[__i]);
    }
    inline void printd(long double __x,int __d)
    {
        long long __t=(long long)floor(__x);print(__t);putc('.');__x-=(double)__t;
        while(__d--)
        {
            long double __y=__x*10.0;__x*=10.0;
            int __c=(int)floor(__y+1e-9);if(__c==10) __c--;
            putc(__c+'0');__x-=floor(__y);
        }
    }
    inline void el(){putc('\n');}inline void sp(){putc(' ');}
}using namespace IO;
pair<int,int>a[250005];int cnt,cur,n,b[250005];stack<pair<int,int> >c;
void GG(){prints("No\n",0);flush();exit(0);}
int main()
{
	read(n);for(int i=1;i<=n;i++) read(a[i].first),a[i].second=i;sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		cnt=cur=1;b[a[i].first]=a[i].second;
		for(;cur<a[i].first&&cnt<a[i].second;cur++) if(!b[cur]) b[cur]=a[i].second,cnt++;
		if(cnt<a[i].second) GG();
		for(int j=1;j<=n-a[i].second;j++) c.push(make_pair(a[i].first,a[i].second));
	}
	for(int i=n*n;i;i--) if(!b[i])
	{
		if(c.top().first>=i) GG();
		b[i]=c.top().second;c.pop();
	}
	prints("Yes\n",0);for(int i=1;i<=n*n;i++) print(b[i]),sp();flush();
}

Measured memory_bytes: 5248
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n;
	while(cin >> n){
		cout << 1 + n * (n + 1) / 2 << endl;
	}

	return 0;
}



Measured memory_bytes: 3160