akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
K, S = map(int, input().split())
ans = 0

for X in range(K + 1):
    for Y in range(X, K + 1):
        Z = S - Y - X
        if Z >= Y and Z <= K:
                
            if len(set([X, Y, Z])) == 1:
                ans += 1
            elif len(set([X, Y, Z])) == 2:
                ans += 3
            else:
                ans += 6
print(ans)

Measured memory_bytes: 3064
import atexit
import io
import sys

buff = io.BytesIO()
sys.stdout = buff


@atexit.register
def write():
    sys.__stdout__.write(buff.getvalue())

l = map(int, raw_input().split())
l.sort()
if l[0] == l[2]:
	print 'Yes'
else:
	print 'No'

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int k;
    cin>>k;
    cout<<(k/2)*(k-k/2)<<endl;
 
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int N;
	long long int a[110];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
	}
	sort(a, a + N);
	printf("%lld", a[N-1] - a[0]);
	return 0;
}

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

t = [0]
x = [0]
y = [0]

for i in range(N):
    tadd, xadd, yadd = map(int, input().split())
    t.append(tadd)
    x.append(xadd)
    y.append(yadd)

ans = 'Yes'

for j in range(N):
    dt = t[j+1] - t[j]
    dist = abs(x[j+1] - x[j]) + abs(y[j+1] - y[j])

    if dt % 2 != dist % 2 or dt < dist:
        ans = 'No'
        break

print(ans)

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

int main(){
	int n;
	bool can = true;
	vector <string> w(100);

	cin >> n;

	cin >> w[0];
	for(int i=1; i<n; i++){
		cin >> w[i];
		if(w[i][0] != w[i-1][w[i-1].size()-1]){
			can = false;
		}
	
		for(int j=0; j<i; j++){
			if(w[i]==w[j]){
				can = false;
			}
		}
	}

	if(can) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
def min(a,i):
  x = a[0]
  for t in range(0, i):
    if x > a[t]:
      x = a[t]
  return x

def max(a,i):
  y = a[0]
  for t in range(0, i):
    if y < a[t]:
      y = a[t]
  return y

def sum(a,i):
  s = 0
  for t in range(0, i):
    s += a[t]
  return s

i = int(raw_input())
a = map(int, raw_input().split())
print "%d %d %d" % (min(a,i), max(a,i), sum(a,i))

Measured memory_bytes: 5004
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=200005;
char s[N];int tot,top,n,m,js;
int st[N],h[N],ne[N<<1],to[N<<1],va[N],vb[N],ban[N];
void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
int main()
{
	int x,y;
	n=read(),m=read();
	scanf("%s",s+1);
	for(RI i=1;i<=m;++i) {
		x=read(),y=read(),add(x,y),add(y,x);
		if(s[x]=='A') ++va[y]; else ++vb[y];
		if(s[y]=='A') ++va[x]; else ++vb[x];
	}
	for(RI i=1;i<=n;++i) if(!va[i]||!vb[i]) st[++top]=i,ban[i]=1;
	while(top) {
		x=st[top],++js,--top;
		for(RI i=h[x];i;i=ne[i]) {
			if(ban[to[i]]) continue;
			if(s[x]=='A') --va[to[i]];
			else --vb[to[i]];
			if(!va[to[i]]||!vb[to[i]]) st[++top]=to[i],ban[to[i]]=1;
		}
	}
	if(js<n) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 7040
n = int(input())
commands = [input().split() for i in range(n)]
a = []
for command in commands:
    if len(command) == 2:
        if command[0] == '0':
            a.append(int(command[1]))
        elif command[0] == '1':
            print(int(a[int(command[1])]))
    else:
        a.pop(len(a) - 1)




Measured memory_bytes: 59556
from string import ascii_lowercase


def main():
    string = input()
    count = {}
    for lcase in ascii_lowercase:
        count[lcase] = 0
    for s in string:
        count[s] += 1
    count = sorted(count.items(), key=lambda x: x[0])
    for i, count in enumerate(count):
        if count[1] == 0:
            print(ascii_lowercase[i])
            break
    else:
        print("None")


if __name__ == '__main__':
    main()



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

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr ll MOD=1000000007;
constexpr ll INF=1LL<<60;
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;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
    
    int N,M,A;
    while(1){
    cin>>N>>M>>A;
    if(!(N|M|A))break;
    vector<pair<int,int>> H[1010];
    rep(i,M){
        int h,p,q;
        cin>>h>>p>>q;
        H[1010-h].push_back({p,q});
    }
    rep(i,1010)
        for(auto id:H[i]){
            if(id.first==A)A=id.second;
            else if(id.second==A)A=id.first;
            else continue;
            break;
        }
    cout<<A<<endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;



void solve(){
    int n, m, k, ans = 0;
    cin>>n>>m;
    priority_queue <int> q;
    f(i,n)cin>>k,q.push(k);
    while(m--){
        k = q.top();
        q.pop();
        k /= 2;
        q.push(k);
    }
    while(!q.empty()){
        k = q.top();
        q.pop();
        ans += k;
    }
    cout<<ans;
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}

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

int main(){
    string s; cin >> s;
    int n = s.length();
    int ans = (n+1)/2;
    if(n%2 == 0){
        char left = s[n-1-ans], right = s[ans];
        while(left == right){
            ans++;
            if(ans == n) break;
            if(s[n-1-ans] == left) left = s[n-1-ans]; else break;
            if(s[ans] == right) right = s[ans]; else break;
        }
    }
    else{
        char left = s[n-ans], right = s[ans-1];
        while(left == right){
          	ans++;
            if(s[n-ans] == left) left = s[n-ans]; else{ ans--; break;}
            if(s[ans-1] == right) right = s[ans-1]; else{ ans--; break;}
          	if(ans == n) break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 200500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

int main() {
	FREOPEN();
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int n;
vector<int> h;
int main()
{
  cin >> n;
  h.resize(n);
  rep(i,n) cin >> h[i];

  int cnt = 0,res = 0;
  rep(i,n-1){
    if(h[i]>=h[i+1]) cnt++;
    else{
      res = max(res,cnt);
      cnt = 0;
    }
  }
  res = max(res,cnt);
  
  cout << res << "\n";
  
  
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <utility>
#include <math.h>
using namespace std;

int main() {
    int a;
    cin >> a;
    cout << 2 * 3.1415926535 * a << endl;
    return 0;
}

Measured memory_bytes: 3780
class UnionFind:
    #要素数nで初期化
    #インスタンス変数の初期化
    def __init__(self, n):
        #root : 木の要素数
        #rnk : 木の高さ(rank)
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    
    """ノードxのrootノードを見つける"""
    def Find_Root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x]) 
            return self.root[x]
    
    """木の合併"""
    def Union(self, x, y):
        #入力ノードの親を探索
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        
        #既に同じ木に所属する場合
        if (x==y):
            return 
        
        #異なる木に所属する場合 -> rnkから判断して合併する
        elif (self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            
            #rnkが同じ(深さが同じ)場合
            if self.rnk[x]==self.rnk[y]:
                self.rnk[y] += 1
    
    """xとyが同じグループに所属するか"""
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
    
    """ノードxが属する木のサイズ"""
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


n,m = map(int,input().split())
edge = []
for i in range(m):
    a,b = map(int,input().split())
    edge.append([a,b])

res = 0
for i in range(m):
    tmp_edge = edge[:i] + edge[i+1:]
    uf = UnionFind(n)
    for j in range(len(tmp_edge)):
        uf.Union(tmp_edge[j][0], tmp_edge[j][1])
    if not uf.isSameGroup(edge[i][0], edge[i][1]):
        res += 1
print(res)

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

void swap(int *x, int *y){
    int temp;

    temp = *x;
    *x = *y;
    *y = temp;
}

int main(){
    int hill[10];
    int i, j, max=0;
    int key;

    for (i = 0; i < 10; i++) {
        cin >> hill[i];
    }

    // insert sort
    for (i = 0; i < 10; i++) {
        j = i;
        while((j > 0) && hill[j-1] > hill[j]){
            swap(&hill[j-1], &hill[j]);
            j--;
        }
    }

    for (i = 9; i > 6; i--) {
        // printf("%d\n", hill[i]);
        cout << hill[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
        String s[] = br.readLine().trim().split(" ");
        int l = Integer.parseInt(s[0]);
        int r = Integer.parseInt(s[1]);
        int d = Integer.parseInt(s[2]);
        
        int f = (l/d)*d;
        int cnt=0;
        while(f<=r){
            if(f>=l) cnt++;
            f+=d;
        }
        out.println(cnt);
        
        br.close();out.flush();out.close();
    }
}

Measured memory_bytes: 32940
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		int[] l = new int[k];
		int[] r = new int[k];
		for (int i = 0; i < k; i++) {
			sa = br.readLine().split(" ");
			l[i] = Integer.parseInt(sa[0]);
			r[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		int mod = 998244353;
		FenwickTree ft = new FenwickTree(n);
		ft.add(0, 1);
		for (int i = 1; i < n; i++) {
			long sum = 0;
			for (int j = 0; j < k; j++) {
				int ll = Math.max(i - r[j], 0);
				int rr = Math.max(i - l[j] + 1, 0);
				sum += ft.sum(ll, rr);
				sum %= mod;
			}
			ft.add(i, sum);
		}
		System.out.println(ft.sum(n - 1, n));
	}
}

/**
 * Fenwick Tree（Binary Indexed Tree）
 */
class FenwickTree {
	private int n;
	private long[] data;

	/**
	 * 長さnの配列（a[0]～a[n-1]）を作る。初期値は全て0。<br>
	 * O(n)
	 * 
	 * @param n 配列の長さ
	 */
	public FenwickTree(int n) {
		this.n = n;
		data = new long[n];
	}

	/**
	 * 初期データを元にFenwick Treeを構成する。<br>
	 * O(n)
	 * 
	 * @param data 初期データ
	 */
	public FenwickTree(long[] data) {
		this(data.length);
		build(data);
	}

	/**
	 * a[p] += x を行う。<br>
	 * O(log n)
	 * 
	 * @param p 加算位置（0≦p＜n）
	 * @param x 加算値
	 */
	void add(int p, long x) {
		assert 0 <= p && p < n : "p=" + p;

		p++;
		while (p <= n) {
			data[p - 1] += x;
			p += p & -p;
		}
	}

	/**
	 * a[l] + ... + a[r-1] を返す。<br>
	 * O(log n)
	 * 
	 * @param l 開始位置（含む）    （0≦l≦r≦n）
	 * @param r 終了位置（含まない）（0≦l≦r≦n）
	 */
	long sum(int l, int r) {
		assert 0 <= l && l <= r && r <= n : "l=" + l + ", r=" + r;

		return sum(r) - sum(l);
	}

	/**
	 * a[0] + ... + a[r-1] を返す。<br>
	 * O(log n)
	 * 
	 * @param r 終了位置（含まない）（0≦r≦n）
	 */
	long sum(int r) {
		assert 0 <= r && r <= n : "r=" + r;

		long s = 0;
		while (r > 0) {
			s += data[r - 1];
			r -= r & -r;
		}
		return s;
	}

	private void build(long[] dat) {
		System.arraycopy(dat, 0, data, 0, n);
		for (int i = 1; i <= n; i++) {
			int p = i + (i & -i);
			if (p <= n) {
				data[p - 1] += data[i - 1];
			}
		}
	}
}


Measured memory_bytes: 35132
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k;
signed main()
{
	scanf("%lld%lld%lld",&k,&n,&m);
	if(m/k>(n-1)/k)
	printf("OK");
	else
	printf("NG");
    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v) {
  if (reachablefrom1[v]) return;
  reachablefrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}
void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

int main() {
  string s;
  cin >> s;
  rep(i, s.size()) {
    if (i % 2 == 0) {
      if (s[i] == 'L') {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if (s[i] == 'R') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main(){
  int a,b;
  cin >> a >>b;
  if(a >= 10 or b >= 10){
    cout << -1<<endl;
    return 0;
  }
  else{
    cout << a*b << endl;
    return 0;
  }
}

Measured memory_bytes: 256
x1,x2,x3,x4,x5,=map(int,input().split())
if 0 == x1:
    print("1")
elif 0 == x2:
    print("2")
elif 0 ==x3:
    print("3")
elif 0 == x4:
    print("4")
else:
    print("5")

Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<" "<<#x<<"="<<x

#define bit(k) (1LL<<(k))

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/
struct mint {
    ll x; // typedef long long ll;
    mint(ll _x=0):x((_x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint modpow(ll t) const {
        if (!t) return 1;
        mint a = modpow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return modpow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n,k;
    cin>>n>>k;
    combination c(n);
    k = min(k, n-1);
    mint ans = 0;
    rep(i,k+1){
        ans += c(n,i) * c(n-1-i+i, i);
    }
    cout<<ans.x<<endl;
}

Measured memory_bytes: 3328
import Data.List

solve :: String -> Bool
solve [_] = True
solve [a,b] = a /= b
solve s = length g == 3 && (maximum g - minimum g) <= 1
  where
    g = map length . group . sort $ s

main :: IO ()
main = do
    s <- getLine
    putStrLn $ if solve s then "YES" else "NO"

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

using namespace std;

#define int long long

int n, m, v, p; 

bool check(vector<int>& a, int mid){
	bool works = false;
		int left = v - (p - 1) - 1;
		if(left <= (n - mid - 1)){
			//means u dont need to increase anyone on the left of mid
			if(a[mid] + m >= a[p-1]){
				works = true;
			}else{
				works = false;
			}
		}else{
			works = true;
			int high = left - (n - mid - 1);
			//need to incremenet m*high times, at a max of m times
			int sum = 0;
			for(int i = p-1; i < mid; i++){
				if(a[mid] + m < a[i]){
					works = false; 
					break;
				}
				sum += (a[mid] + m) - a[i];

			}
			if(works && sum >= m*high){
				works = true;
			}else{
				works = false;
			}
			
		}
		return works;
}

signed main(){
	
	cin>>n>>m>>v>>p;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin>>a[i];
	}
	
	sort(a.rbegin(), a.rend());
//	
//	for(int b: a) cout<<b<<" ";
//	cout<<endl;
	
	int low = p, high = n-1, mid;
	while(low < high){
		mid = (low + high + 1)/2;
		//cout<<"BS: "<<low<<" "<<high<<" "<<mid<<endl;
		//check now
		
		bool works = check(a, mid);
		if(works){
			low = mid;
		}else{
			high = mid-1;
		}
	}
	mid = (low + high + 1)/2;
	if(check(a, mid) == false) mid--;
	
	cout<<mid+1<<endl;
	
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>

int main(){
    char str[1001];
    while(1){
        scanf("%s",str);
        if(str[0]=='0') break ;
        int sum=0;
        for(int i=0;i<strlen(str);i++){
            sum+=(str[i]-'0');
        }
        printf("%d\n",sum);
    }
    return 0;
    
}


Measured memory_bytes: 2680
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    unsigned long int H = 0, N = 0, sum = 0;
    cin >> H >> N;
    for(int i = 0 ; i < N ; i++){
        unsigned long int x = 0;
        cin >> x;
        sum += x;
    }
    if(sum >= H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b)
      cout << "a > b" << endl;
    else if (a < b)
      cout << "a < b" << endl;
    else
      cout << "a == b" << endl;    
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define maxn 200005 
#define ll long long
using namespace std;
int n,a[maxn],b[maxn],flag,tmp=1e9;
ll ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",&a[i],&b[i]);
		ans+=a[i];
		if(a[i]>b[i]) tmp=min(tmp,b[i]);
		if(a[i]!=b[i]) flag=true; 
	}
	ans-=tmp;
	if(flag) printf("%lld",ans);
	else printf("0");
}

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

using namespace std;

const int md = int(1e9) + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

const int N = 5050;
int dp[N][N];

int main() {
  int n;
  string s;
  cin >> n >> s;

  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= n; j++) {
      if (j == 0) {
        add(dp[i + 1][j], dp[i][0]); // B
      }
      else {
        add(dp[i + 1][j], mul(dp[i][j - 1], 2)); // 0 or 1
      }
      add(dp[i + 1][j], dp[i][j + 1]); // B
    }
  }

  int ans = dp[n][s.length()];
  ans = mul(ans, inv(power(2, s.length())));
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 98944
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  if(s1[s1.size()-1]==s2[0]&&s2[s2.size()-1]==s3[0])cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

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

int main() {
  int N;
  cin>>N;
  
  vector<string> w(N);
  for(int i=0;i<N;++i){
    cin>>w[i];
  }
  
  bool exist_same=false;
  bool not_shiritori=false;
  
  for(int i=0;i<N;++i){
    for(int j=i+1;j<N;++j){
      if(w[i]==w[j])
        exist_same=true;
    }
  }
  
  for(int i=0;i<N-1;++i){
    if(w[i].at(w[i].size()-1)!=w[i+1].at(0))
      not_shiritori=true;
  }
  
  if(exist_same || not_shiritori)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr 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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int N; cin >> N;
	vector<vector<int>>vec(N, vector<int>(3));
	rep(i, N)rep(j, 3)cin >> vec[i][j];
	vector<vector<int>>dp(N, vector<int>(3, 0));
	dp[0][0] = vec[0][0];
	dp[0][1] = vec[0][1];
	dp[0][2] = vec[0][2];
	REP(i, 1, N) {
		rep(j, 3) {
			rep(k, 3) {
				if (j == k)continue;
				chmax(dp[i][j], dp[i - 1][k] + vec[i][j]);
			}
		}
	}
	int ans = 0;
	rep(i, 3) {
		chmax(ans, dp[N - 1][i]);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	int a[n];

	zip(i, 0, n)
	{
		cin >> a[i];
	}
	sort(a, a + n, greater<int>());

	int ans = 0;
	if (n == 0)
	{
		cout << 0 << en;
		return 0;
	}
	if (n == 3)
	{
		ans += a[0] + a[1];
		cout << ans << en;
		return 0;
	}
	else if (n == 2)
	{
		ans += a[0];
		cout << ans << en;
		return 0;
	}
	else if (n % 2 == 1)
	{
		int i = 0;
		ans += a[0];
		int cnt = 0;
		for ( i = 1; i < n; i++)
		{
			if (cnt < (n - 3) / 2)
				ans += 2 * a[i], cnt++;
			else
				break;
		}
		ans += a[i];
		cout << ans << en;
		return 0;
	}
	int i = 0;
	i++;
	ans += a[i - 1];
	int cnt = 0;
	for (i = 1; i < n; i++)
	{
		if (cnt < (n - 2) / 2)
			ans += 2 * a[i], cnt++;
		else
			break;
	}
	//ans += a[i];
	//ans += a[i + 1];

	cout << ans << en;

	return 0;
}



Measured memory_bytes: 5140
#include<stdio.h>
#include<algorithm>
using namespace std;
int ABS(int a){return max(a,-a);}
bool palin(int a){
	int b=0;
	int c=a;
	while(c){
		b*=10;
		b+=c%10;
		c/=10;
	}
	return a==b;
}
int main(){
	int a;
	scanf("%d",&a);
	int ret=0;
	int d=99999999;
	for(int i=0;i<10000;i++){
		if(palin(i)){
			if(d>ABS(a-i)){
				d=ABS(a-i);
				ret=i;
			}
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 1024
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Xs = list(mapint())
cX = Xs[:]
cX.sort()

lm = cX[N//2-1]
rm = cX[N//2]

for x in Xs:
    if x<=lm:
        print(rm)
    else:
        print(lm)

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

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

/* 文字から数値に変換 */
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

/* 文字列から数値へ変換して key を生成する */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); /* 文字列を数値に変換 */
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) % M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); /* 文字列を数値に変換 */
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str);
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


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

	bool bad[20];

	bool res(int n){
		while(n>0){
			int x = n%10;
			if(bad[x]) return false;
			n = n/10;
		}
		return true;
	}

	int main(){
		
		int n,k;
		cin>>n>>k;
		
		while(k--){
			int x;
			cin>>x;
			bad[x] = 1;
		}
		
		while(!res(n)){
			//cout<<n<<endl;
			n++;
		}
		cout<<n;
	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mk make_pair
#define pb push_back
int main()
{
ios_base ::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m;cin>>n>>m;
int a[n];ll sum=0;
for(int i=0;i<m;i++)
{
	cin>>a[i];sum+=a[i];
}
if(sum>n){cout<<-1;}
else
{cout<<n-sum;

}
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = 2e18;
    ans = min(ans, (a % 2) * b * c);
    ans = min(ans, (b % 2) * a * c);
    ans = min(ans, (c % 2) * a * b);
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int main()
{
    int n ,i ,k ,t;
    scanf("%d%d",&n,&k);
    for(i = 0; i < n; i++)
        scanf("%d",&t);
    if((n-k)%(k-1)==0)
        printf("%d",1+(n-k)/(k-1));
    else printf("%d",2+(n-k)/(k-1));
    return 0;
}


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

using namespace std;

int main()
{

    vector<vector<int>> a(3, vector<int>(3));
    vector<vector<int>> r(3, vector<int>(3, 0));
    int n;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a.at(i).at(j);
        }
    }
    cin >> n;
    int b;
    for (int i = 0; i < n; i++)
    {
        cin >> b;
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                if (b == a.at(j).at(k))
                {
                    r.at(j).at(k) = 1;
                }
            }
        }
    }
    if (r.at(0).at(0) + r.at(0).at(1) + r.at(0).at(2) == 3 ||
        r.at(1).at(0) + r.at(1).at(1) + r.at(1).at(2) == 3 ||
        r.at(2).at(0) + r.at(2).at(1) + r.at(2).at(2) == 3 ||
        r.at(0).at(0) + r.at(1).at(0) + r.at(2).at(0) == 3 ||
        r.at(0).at(1) + r.at(1).at(1) + r.at(2).at(1) == 3 ||
        r.at(0).at(2) + r.at(1).at(2) + r.at(2).at(2) == 3 ||
        r.at(0).at(0) + r.at(1).at(1) + r.at(2).at(2) == 3 ||
        r.at(0).at(2) + r.at(1).at(1) + r.at(2).at(0) == 3)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()
ans = ""
for i in range(len(s)):
    if i % 2 == 0:
        ans = ans + s[i]
print(ans)


Measured memory_bytes: 27532
H,W = list(map(int,input().split()))
N=10

dist = []
for n in range(N):
    dist.append(list(map(int,input().split())))
dist=[list(x) for x in zip(*dist)]

from collections import deque
start = 1

color = {}
for n in range(N):
    color[n] = -1
    
cost = {}
for n in range(N):
    cost[n] = 10**10
    
parent = {}
for n in range(N):
    parent[n] = -1

cost[start] = 0
S = deque([])
while True:
    mincost = 10**10
    for n in range(N):
        if color[n] != 1 and cost[n] < mincost:
            mincost = cost[n]
            start = n
    
    if mincost == 10**10:
        break
    
    color[start] = 1
    
    for n in range(N):
        if color[n] != 1 and dist[start][n] != -1:
            if cost[start] + dist[start][n] < cost[n]:
                cost[n] = cost[start] + dist[start][n]
                parent[n] = start
                color[n] = 0

cost[-1]=0
ans=0
for h in range(H):
    W = list(map(int,input().split()))
    for w in W:
        ans += cost[w]
print(ans)

Measured memory_bytes: 68496
import heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
while t > 0:
	t -= 1
	n,k,q = map(int,input().split())	
	v = []
	l = []
	# v = list(map(int,input().strip().split()))[0:n]
	for i in range(q):
		p = int(input().strip())
		v.append(p)
	for i in range(n):
		l.append(0)
	for i in v:
		l[i-1] += 1
	# print(l)
	for i in range(n):
		if(l[i] <= q-k):
			print("No")
		else:
			print("Yes")
	# for i in range(n):
	# 	v[i] = -v[i]
	# heapq.heapify(v)
	# for i in range(m):
	# 	x = heapq.heappop(v)
	# 	x = -x
	# 	x = x//2
	# 	heapq.heappush(v,-x)
	# ans = 0
	# for i in range(n):
	# 	ans += (-heapq.heappop(v))
	# print(ans)


Measured memory_bytes: 85608
def compare(a, b):
    result = 0
    for i in range(len(a)):
        if a[i] != b[i]:
            result += 1
    return result

s = input()
t = input()

ls = len(s)
lt = len(t)

diff = []
for i in range(ls-lt+1):
    diff.append(compare(s[i:i+lt], t))
print(min(diff))

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);

  ll ans = 1;
  for (ll i = 2; i*i < g; i++) {
    if (g%i == 0) {
      ans++;
      while (g%i == 0) {
        g /= i;
      }
    }
  }
  if (g != 1) ans++;

  cout << ans << endl;
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

bool Found(const int32_t i, const vector<char> &A, const int32_t N) {
  constexpr int32_t kDigitNum = 3;
  const char digits[kDigitNum] = {static_cast<char>(i / 100), static_cast<char>((i / 10) % 10),
                                  static_cast<char>(i % 10)};
  int32_t cpos = 0;
  for (int32_t d = 0; d < kDigitNum; ++d) {
    while (cpos < N && digits[d] != A[cpos]) {
      ++cpos;
    }
    if (cpos >= N) {
      return false;
    }
    ++cpos;
  }
  return true;
}

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

  int32_t N;
  string S;
  cin >> N >> S;
  vector<char> A(N);
  for (int32_t i = 0; i < N; ++i) {
    A[i] = S.c_str()[i] - '0';
  }
  int32_t result = 0;
  for (int32_t i = 0; i <= 999; ++i) {
    if (Found(i, A, N)) {
      ++result;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 384
from math import ceil

N,K=map(int,input().split())
A=list(map(int,input().split()))

X=A.index(1)

M=float("inf")
for i in range(N):
    if i<=X<=i+K-1:
        P=ceil(i/(K-1))
        Q=ceil((N-i-1)/(K-1))
        M=min(M,P+Q)
print(M)


Measured memory_bytes: 84248
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<mint> left(n+2, 0), right(n+2, 0);
    for(int i = 0; i <= n; ++i){
        left[i+1] = left[i] + i;
    }
    for(int i = 1; i <= n+1; ++i){
        right[i] = right[i-1] + n + 1 - i;
    }
    mint ans = 0;
    for(int i = k; i <= n+1; ++i){
        ans += right[i] - left[i] + 1;
    }
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 6344
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e18 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   if(pow < 0) return 0;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(2e6 + 7)] , inv_fac[(int)(2e6 + 7)];
void precomp_factorial(){fac[0] = 1;for(ll i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(ll i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};

int main()
{
    ll n, p;
    cin >> n >> p;
    map <ll,ll> mp;
    for(ll i = 2; i*i <= p; i++){
        if(p%i == 0){
            while(p%i == 0){
                p /= i;
                mp[i]++;
            }
        }
    }
    if(p > 1) mp[p]++;
    ll ans = 1;
    for(auto x:mp){
        ll power = x.second*1LL/n;
        ans *= expo(x.first*1LL, power);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int A, B;
    cin >> A >> B;
    if(1 <= A && A <= 9 && 1 <= B && B <= 9)
        cout << A*B << "\n";
    else
        cout << -1 << "\n";
    return 0;
}


Measured memory_bytes: 256
// Undone
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int N; cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      auto itr = lower_bound(L.begin(), L.end(), L[i]+L[j]);
      if (itr == L.end()) {
        ans += N-j-1;
      } else {
        ans += itr-(L.begin()+j)-1;
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	map<string,ll>ch;
	for(ll i=0;i<n;i++){
		string t;
		cin>>t;
		sort(t.begin(),t.end());
		ch[t]++;
	}
	ll ans=0;
	for(auto itr=ch.begin();itr!=ch.end();itr++){
		ll val=itr->second;
		ans+=val*(val-1)/2;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//ori
#define MOD 1000000007
 
int main() {
  string s;
  cin >> s;
  int n, a, z;
  n = SZ(s);
  REP(i,n-1) {
    if(s.at(i) == 'A') {
      a=i;
      break;
    }
  }
  REP(i,n-1) {
    if(s.at(n-1-i) == 'Z') {
      z=n-1-i;
      break;
    }
  }
  int ans = z-a+1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100000000000000000;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll H,A;
    cin >> H >> A;
    cout << (H + A-1) / A << '\n'; 
}




Measured memory_bytes: 256
while True :
    C = input()
    
    if C == "-" :
        break
    else :
        m = int(input())
        
        for i in range(m) :
            h = int(input())
            c = C[0 : h]
            C = C[h : len(C) + 1]
            C += c
        
        print(C)


Measured memory_bytes: 5596
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}
void bubbleSort(int arr[], int n)
{
   int i, j;
   bool swapped;
   for (i = 0; i < n-1; i++)
   {
     swapped = false;
     for (j = 0; j < n-i-1; j++)
     {
        if (arr[j] > arr[j+1])
        {
           swap(&arr[j], &arr[j+1]);
           swapped = true;
        }
     }
 
     // IF no two elements were swapped by inner loop, then break
     if (swapped == false)
        break;
   }
} 

int main (){ int n; int k;
    cin>>n>>k; int arr[n];
     for(int i=0;i<n;i++){
        cin>>arr[i];
     }
     bubbleSort(arr, n);
     int sum=0;
   for(int i=n-1;i>n-k-1;i--){
         
         sum+=arr[i];

     }

cout<<sum;
     return 0;
}


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

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  
  int64_t x = B - A;
  if (!(x % 2)) {
    cout << (B - A) / 2 << endl;
  } else {
    int64_t df1 = 0,
            dfN = 0,
            n = 0;
    df1 = (A - 1) + (B - 1);
    dfN = (N - A) + (N - B);
    if (df1 < dfN) {
      if (A != 1) {
        n += A - 1;
        A = 1;
        B -= n;
      }
      B--;
      n++;
      //cout << n << A << B << endl;
      if (!(B - A)) {
        cout << n << endl;
      } else {
        //cout << B - A << endl;
        n += (B - A) / 2;
        cout << n << endl;
      }
    } else {
      if (B != N) {
        n += N - B;
        B = N;
        A += n;
      }
      A++;
      n++;
      if (!(B - A)) {
        cout << n << endl;
      } else {
        n += (B - A) / 2;
        cout << n << endl;
      }
    }
  }
}


Measured memory_bytes: 256
S = input()
if S == 'SAT':
    ans = 1
elif S == 'FRI':
    ans = 2
elif S == 'THU':
    ans = 3
elif S == 'WED':
    ans = 4
elif S == 'TUE':
    ans = 5
elif S == 'MON':
    ans= 6
else:
    ans = 7
print(ans)

Measured memory_bytes: 3060