akhauriyash/Code-Regression huggingface dataset:
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                          ll                          long long int
#define                          mk                          make_pair
#define                          in(x)                       scanf("%lld",&x)
#define                          out(x)                      printf("%lld\n",x)
#define                          cy                          printf("YES\n")
#define                          cn                          printf("NO\n")
#define                          pi                          pair<ll,ll>
#define                          fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll inf=1e17;
const int mx=100005;

using namespace std;
vector<pi> adj[mx];
bool vis[mx];
ll dis[mx];

int main(){
    fast;
 ll edge ,vertex;
 cin>>vertex>>edge;
 ll i,c,u,v;
 for(i=1;i<=edge;i++){
    cin>>u>>v>>c;
    adj[u].push_back({v,c});
    adj[v].push_back({u,c});

 }
 for(i=2;i<=vertex;i++){
       adj[i].push_back({i-1,0});
 }
priority_queue<pi,vector<pi>,greater<pi> > q;

 for(i=1;i<=vertex;i++){
       dis[i]=inf;
 }
 dis[1]=0;
 q.push({dis[1],1});

 while(!q.empty()){
    pi temp;
    temp=q.top();
    q.pop();
    u=temp.second;
    ll cost=temp.first;
    if(vis[u])continue;
        vis[u]=1;
        for(auto x: adj[u]){
                v=x.first;
                c=x.second;

                if(dis[v]<=c+cost) continue;
                dis[v]=c+cost;
                q.push({dis[v],v});

        }

 }
   if(dis[vertex]>=inf) dis[vertex]=-1;
   cout<<dis[vertex]<<endl;
   return 0;
}


Measured memory_bytes: 15764
import os,re
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations
from sys import stdin,setrecursionlimit
from copy import deepcopy
setrecursionlimit(10**6)

n=int(input())
cnt=0
for i in range(1,n+1):
    if len(str(i))%2==1:
        cnt+=1
print(cnt)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
ll T, t[200005], ans;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    ll pos = 0;
    cin >> n >> T;
    rep(i, 0, n) cin >> t[i];
    ans = T;
    rep(i, 1, n) {
        ans += min(T, t[i]-t[i-1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(){
	int r,g,b,k,s=0;
	cin>>r>>g>>b>>k;
	while(true){
		if(g<=r){
			g=g*2;
			s++;
		}
		else if(b<=g){
			b=b*2;
			s++;
		}
		else{
			b=b*2;
			s++;
		}
		if(s==k) break;
	}
	if(b>g && g>r) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3608
N = int(input())
I = [tuple(map(int, input().split())) for _ in range(N)]

value = set()

for i in range(N):
    a, b = I[i]
    value.add(a)
    value.add(b)
value = list(value)
value.sort()
comp = {v : k for k, v in enumerate(value)}


M = len(value)

arr1 = [0 for _ in range(M)]
arr2 = [0 for _ in range(M)]

for i in range(N):
    a, b = I[i]
    arr1[comp[a]] += 1
    arr2[comp[b]] += 1

for i in range(M - 1):
    arr1[i + 1] += arr1[i]
    arr2[M - i - 2] += arr2[M - i - 1]


if N % 2 == 1:
    lt = 0
    rt = M - 1
    for i in range(M):
        if arr1[i] >= (N + 1)//2:
            lt = i
            break
    for i in range(M)[::-1]:
        if arr2[i] >= (N + 1)//2:
            rt = i
            break
    print(value[rt] - value[lt] + 1)

else:
    lt = 0
    rt = M - 1
    mlt = 0
    mrt = M - 1
    for i in range(M):
        if arr1[i] >= N//2:
            lt = i
            break
    for i in range(M):
        if arr1[i] >= N//2 + 1:
            mlt = i
            break
    for i in range(M)[::-1]:
        if arr2[i] >= N//2:
            rt = i
            break
    for i in range(M)[::-1]:
        if arr2[i] >= N//2 + 1:
            mrt = i
            break
    l = value[lt]
    r = value[rt]
    ml = value[mlt]
    mr = value[mrt]

    print(r + mr - l - ml + 1)

Measured memory_bytes: 173076
#pragma GCC optimize("Ofast")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>

using namespace std;

#define ll long long
#define ull unsigned long long
const ll MOD = 1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
	string S, T;
	cin >> S >> T;

	int A, B;
	cin >> A >> B;
	string U;
	cin >> U;

	if (S == U){
		cout << A-1 << " " << B << "\n";
	} else {
		cout << A << " " << B-1 << "\n";
	}




	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int m;
  cin>>m;
  if(n>m)
  {
    cout<<n+n-1<<endl;
    return 0;
  }
  else if(m>n)
  {
    cout<<m+m-1;
    return 0;
  }
  else
   cout<<m+n<<endl;
  return 0;    
}

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

int main(){
    int N;
    bool check = false;
    cin >> N;

    rep(i, 10){
        rep(j, 10){
            if(i * j == N){
                check = true;
            }
        }
    }

    cout << (check ? "Yes" : "No") << endl;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n, k;
    string s;
    cin >> n >> k >> s;

    // 0…01…10…01…10…0 みたいなやつ
    ll con0 = 0, con1 = 0;
    vector<ll> v;
    if(s[0]=='1') v.push_back(0);
    REP(i, n) {
        if(s[i]=='0') {
            if(con1 != 0) v.push_back(con1);
            con0++, con1=0;
        } else {
            if(con0 != 0) v.push_back(con0);
            con1++, con0=0;
        }
    }
    if(con0 != 0) v.push_back(con0);
    if(con1 != 0) v.push_back(con1);
    if(s.back()=='1') v.push_back(0);
    FOR(i, 1, v.size()) v[i] += v[i-1];

    ll ans = 0;
    for(ll i=0; i<v.size(); i+=2) {
        ll j=min((ll)v.size()-1, i+2*(k-1)+1);
        if(i==0) chmax(ans, v[j]);
        else chmax(ans, v[j] - v[i-2]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1528
import java.util.*;
      
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[][][] data = new int[4][3][10];
        int n = sc.nextInt();
        for(int i = 0;i < n;i++){
        	int b = sc.nextInt();
        	int f = sc.nextInt();
        	int r = sc.nextInt();
        	int v = sc.nextInt();
        	
        	data[b - 1][f - 1][r - 1] += v;
        }
        
        for(int i = 0;i < 4;i++){
        	for(int k = 0;k < 3;k++){
        		for(int j = 0;j < 10;j++){
        			System.out.print(" "+data[i][k][j]);
        		}
        		System.out.println();
        	}
        	if(i != 3){
        		System.out.println("####################");
        	}
        }
    }
}        

Measured memory_bytes: 21228
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n,ans=0;cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        ll x,y;cin>>x>>y;
        ans+=x;
        a[i]=x+y;
    }
    sort(a.rbegin(),a.rend());
    for(ll i=1;i<n;i+=2)ans-=a[i];
    cout<<ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

int main(){
    int n,m;cin>>n>>m;
    int conections[n];
    std::fill_n(conections,n,0);
    fore(i,0,m){
        int a,b;cin>>a>>b;
        a--;b--;
        conections[a]++;
        conections[b]++;
    }
    fore(i,0,n){
        cout<<conections[i]<<"\n";
    }
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) begin(c), end(c)

using namespace std;
using ll = long long;
// const int MOD = 1000000007;

inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int N;
	cin >> N;
	cout << lcm(2, N) << endl;
	return 0;
}

Measured memory_bytes: 256
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	string s;
	cin>>s;
	for (int i = 0; i < s.length(); i++){
		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: 3652
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long 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;
	}
	// for prime mod
	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;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};

int main() {
	int x, y;
	cin >> x>>y;
	int a;
	rep(a, x+1) {
		if (a * 2 + (x - a) * 4 == y) {

			cout <<"Yes" ;
			return 0;
		}
	}
	cout << "No";
}

//int m[500][26] = {};
//void func(string& s, int N, int i, vector<string>a, int J) {
//	int j;
//		for (j = 0; j < J; j++) {
//			if (m[J - 1 - i][(int)a[i][j] - 97] == 1) {
//		s += a[i][j];
//				break;
//			}
//			if (j == J - 1) {
//				s = "-1";
//				i = N - 1;
//				break;
//			}
//		}
//		i++;
//	if (i == N) {
//		
//	}
//	else {
//		func(s, N, i, a, J);
//	}
//}
//
//int main() {
//	ll N;
//	cin >> N;
//	vector<string>a(N);
//	
//	rep(i, N) {
//		cin >> a[i];
//	}
//	if (N == 1) {
//		cout << a[0];
//		return 0;
//	}
//	rep(i, N) {
//		rep(j, N) {
//			m[i][(int)a[i][j] - 97]=1;
//		}
//	}
//	string ans;
//
//	func(ans, N/2,0,a,N);
//
//	if (ans == "-1") {
//		cout <<ans;
//		return 0;
//	}
//		cout << ans;
//		
//		if (N % 2 == 1) {
//			cout << a[N / 2 + 1][0];
//		}
//	rep(i, N / 2) {
//
//	cout << ans[N/2-i-1];
//	
//	}
//}
//
//
//


Measured memory_bytes: 3628
#include <stdio.h>

int main(){
	int d,i,x,y,area,tmp;

	while(scanf("%d",&d) != EOF){
		area = 0;
		tmp = 600/d;
		for(i = 0;i < tmp;i++){
			x = d;
			y = x*x*i*i;
			area += x*y;
		}
		printf("%d\n",area);
	}

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int c;
  int b=0;
  if(S.size()%2==0){
    c=S.size()/2;
  }
  else{
    c=(S.size()-1)/2;
  }
  for(int i=0;i<c;i++){
    if(S[i]!=S[S.size()-(1+i)]){
      b++;
    }
  }
  cout << b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>

using namespace std;


int main(){

	int A, B, C;
	int answer;

	cin >> A >> B >> C;

	answer = C / A * B;

	cout << answer;

	return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,W = LI()
    a = [LI() for _ in range(n)]
    r = 0
    d = collections.defaultdict(int)
    d[0] = 0
    for w,v in a:
        for e,f in sorted(list(d.items()), key=lambda x: -x[0]):
            if e+w > W:
                continue
            if d[e+w] < d[e] + v:
                d[e+w] = d[e] + v

    return max(d.values())


print(main())


Measured memory_bytes: 7876
#include <iostream>
#include <cstring>

using namespace std;

int memo[100][10001];
int value[100];
int weight[100];
int NEGA_INF = -10000000;

int dp(int k, int w) {
    if (w < 0) { return NEGA_INF; }
    if (k == -1 || w < 0) { return 0; }
    if (memo[k][w] != -1) { return memo[k][w]; }
    return memo[k][w] = max(
            dp(k - 1, w - weight[k]) + value[k],
            dp(k - 1, w));
}

int main() {
    int n, w;
    cin >> n >> w;
    for (int i = 0; i < n; ++i) {
        cin >> value[i] >> weight[i];
    }
    memset(memo, -1, sizeof(memo));
    cout << dp(n - 1, w) << endl;
}

Measured memory_bytes: 7020
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

class Vector2d {
public:
    double x;
    double y;

    Vector2d(double x, double y) : x(x), y(y) {}
    Vector2d(const Vector2d &p) : x(p.x), y(p.y) {}

    Vector2d rotate60() {
        return Vector2d((x - sqrt(3) * y) / 2, (sqrt(3) * x + y) / 2);
    }
};

Vector2d operator+(const Vector2d& p1, const Vector2d& p2) {return Vector2d(p1.x + p2.x, p1.y + p2.y);}
Vector2d operator-(const Vector2d& p1, const Vector2d& p2) {return Vector2d(p1.x - p2.x, p1.y - p2.y);}
Vector2d operator*(const Vector2d& p1, int32_t n) {return Vector2d(p1.x * n, p1.y * n);}
Vector2d operator*(const Vector2d& p1, double d) {return Vector2d(p1.x * d, p1.y * d);}
Vector2d operator/(const Vector2d& p1, int32_t n) {return Vector2d(p1.x / n, p1.y / n);}
ostream& operator<<(ostream& os, const Vector2d& p) {
    os << fixed << setprecision(8) << p.x << " " << p.y;
    return os;
};


void koch_curve(int32_t n, Vector2d p1, Vector2d p2) {
    if (n > 0) {
        Vector2d s = p1 + (p2 - p1) / 3;
        Vector2d t = p1 + (p2 - p1) * 2 / 3;
        Vector2d u = s + (t - s).rotate60();

        koch_curve(n-1, p1, s);
        cout << s << endl;
        koch_curve(n-1, s, u);
        cout << u << endl;
        koch_curve(n-1, u, t);
        cout << t << endl;
        koch_curve(n-1, t, p2);
    }

    return;
}

int main() {
    int32_t n;

    cin >> n;

    cout << Vector2d(0, 0) << endl;
    koch_curve(n, Vector2d(0, 0), Vector2d(100, 0));
    cout << Vector2d(100, 0) << endl;

    return 0;
}

Measured memory_bytes: 3256
import java.util.*;

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

        long l = sc.nextInt();
        long r = sc.nextInt();
        long min = 2018;
        if (l - r > 2018) {
            System.out.println(0);
        } else {
            for (long i = l; i < r; i++) {
                for (long j = i + 1; j <= r; j++) {
                    if (i * j % 2019 < min) {
                        min = i * j % 2019;
                    }
                    if (min == 0)
                        break;
                }
                if (min == 0)
                    break;
            }
            System.out.println(min);
        }
    }
}

Measured memory_bytes: 23764
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


def get_int():
    return int(input())


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


def get_int_list():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


def main():
    n, k = get_int_list()
    if (n + 1) // 2 >= k:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


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

#define MOD 1000000007LL

long long fac[1000001],finv[1000001],inv[1000001];

void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<1000001;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}

long long COM(int n,int k){
	if(n<k)return 0;
	if(n<0 || k<0)return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
 
long long MODpow(long long a,int b){
	if(b==0)return 1;
	if(b%2==0){
		long long t=MODpow(a,b/2);
		return (t*t)%MOD;
	}
	return (a*MODpow(a,b-1))%MOD;
}

long long int gcm(long long a,long long b){
	long long r,tmp;
	if(a<b){
		tmp=a;
		a=b;
		b=tmp;
	}
	
	r=a%b;
	while(r!=0){
		a=b;
		b=r;
		r=a%b;
	}
	return b;
}

int main(){
	COMinit();
	
	int N;
	cin >> N;
	vector<long long> A(N);
	for(auto &i:A)cin >> i;
	
	vector<int> count(1111111,0);
	for(auto a:A){
		long long x=a;
		for(int i=2;i*i<=x;i++){
			int c=0;
			while(x%i==0){
				x/=i;
				c++;
			}
			count[i]=max(count[i],c);
		}
		if(x>1)count[x]=max(count[x],1);
	}
	
	long long L=1;
	for(int i=0;i<1111111;i++)if(count[i]>0)L=(L*MODpow(i,count[i]))%MOD;
	
	long long ans=0;
	for(auto a:A)ans=(ans+(L*inv[a])%MOD)%MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 28160
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
  int N;
  std::cin >> N;

  multiset<int> A;
  for (int ii=0; ii<N; ++ii) {
    int a;
    cin >> a;
    A.insert(a);
  }

  int alice = 0, bob = 0;
  bool is_alice = true;
  
  for (auto itr = A.rbegin(); itr != A.rend(); ++itr)  {
    if (is_alice)
      alice += *itr;
    else
      bob += *itr;
    is_alice = !is_alice;
  }
  
  std::cout << alice - bob << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
function Main(input) {

    input = input.split("\n");
    const numArray = input[0].split(" ");

    const sum = Number(numArray[0]);
    const legSum = Number(numArray[1]);

    const min = sum * 2;
    const max = sum * 4;


    if (legSum >= min && legSum <= max && legSum % 2 === 0) {
        console.log('Yes');
    } else {
        console.log('No');
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29524
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

template <typename T>
ostream& operator <<(ostream& ostr, const vector<T>& a) {
	ostr << "(";
	for (size_t i = 0; i < a.size(); ++i) {
		if (i) {
			ostr << ", ";
		}
		ostr << a[i];
	}
	ostr << ")";
	return ostr;
}

const int mod = 1000000007;

long long pw(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1ll) {
			res = res * a % mod;
		}
		b >>= 1;
		a = a * a % mod;
	}
	return res;
}

int main() {
	int n = nxt();
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nxt();
	}
	int mn = *min_element(all(a));
	int mx = *max_element(all(a));
	if (mx > mn + 1) {
		puts("No");
		return 0;
	}

	if (mn == mx) {
		if (mn == n - 1 || mn <= n / 2) {
			puts("Yes");
		} else {
			puts("No");
		}
		return 0;
	}

	int cnt = 0;
	for (int x : a) {
		if (x == mn) {
			++cnt;
		}
	}

	int min_possible = cnt + 1;
	int max_possible = cnt + (n - cnt) / 2;
	if (mx >= min_possible && mx <= max_possible) {
		puts("Yes");
	} else {
		puts("No");
	}

	return 0;
}

Measured memory_bytes: 640
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
#include <iterator>

#define all(x) x.begin(), x.end()
#define MOD 998244353
const unsigned int M = 1000000007;
const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve(){
   int n,k;
   cin>>n>>k;
   int arr[n];
   for(int i=0;i<n;i++){
       cin>>arr[i];
   }
   sort(arr,arr+n);
   int sum=0;
   for(int i=0;i<k;i++){
       sum+=arr[i];
   }
   cout<<sum;
}


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

    int T = 1;
    solve();

    return 0;
}

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


int main()
{
	int N;
	string str;
	cin>>str;
	N=str.size();
	str='2'+str;
	int flag=0;
	for(int i=1;i<=(N-1)/2;i++)
	{
		if(str[i]!=str[N-i+1])
		{
			flag=1;
			break;
		}
	}
	int t=(N-1)/2;
	for(int i=1;i<=t;i++)
	{
		if(str[i]!=str[t-i+1])
		{
			flag=1;
			break;
		}
	}
	if(flag)
	cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
  
struct Node{
  int l, p, r;

};
struct Node T[MAX];
int n;
 
int getDepth(int u){
 int d=0;
  for(;T[u].p != NIL; d++){
 u=T[u].p;
 
  }
  return d;
}
void print(int u){
  
  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,getDepth(u));
     
  if( T[u].p == NIL) printf("root, [");
   
else if(T[u].l == NIL) printf("leaf, [");
   
else printf("internal node, [");
     
  if( T[u].l != NIL){
    while(1){
       
if(T[T[u].l].r == NIL){
    printf("%d",T[u].l);
    break;
      }
       
else {
    printf("%d, ",T[u].l);
    T[u].l = T[T[u].l].r;
      }
    }
  }
    
  printf("]\n");
}
  
int main(){
  int i, j, k, id, c, l, t;
  
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
    
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &id, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d", &c);
        
      if(j == 0){
    T[id].l = c;
    T[c].p = id;
    t = c;
      }
      else{
    T[t].r = c;
    T[c].p = id;
    t = c;
      }
    }
  }
    
  for ( i = 0; i < n; i++ ){
 
 print(i);
  } 
return 0;
}

Measured memory_bytes: 1784
S=input()
N=len(S)

a=0
t=1
d=[0]*2019
d[0]=1
for i in range(N):
  a+=int(S[N-1-i])*t
  a%=2019
  t*=10
  t%=2019
  d[a]+=1

ans=0
for n in d:
  ans += n*(n-1)//2
print(ans)

Measured memory_bytes: 9328
# A, B = [int(i) for i in input().split(" ")]
# A = int(input())
# As = [int(i) for i in input().split(" ")]
# Ss = ["".join(sorted(input())) for _ in range(N)]

N, K, Q = [int(i) for i in input().split(" ")]
As = [int(input()) for _ in range(Q)]
buff = [K for _ in range(N)]
for a in As:
  i = a - 1
  buff[i] += 1
for b in buff:
    if b - Q > 0: print("Yes")
    else: print("No")



Measured memory_bytes: 10452
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int a,b;cin>>a>>b;
	cout<<6-a-b<<endl;
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var S = input[0].split("");
  var N =S.length+1;
  var min=0;
  var ans=0;
  var L = new Array(N);
  for(var i=0;i<N-1;i++){
    if(i==0&&S[i]=="<"){
      L[i]=0;
    }else if(S[i]==">"&&S[i+1]=="<"){
      L[i+1]=0;
    }else if(i==N-2&&S[i]==">"){
      L[i+1]=0;
    }
  }
  var h=0;
  var h2=0;
  var Lf = new Array(N).fill(0);
  var Lb = new Array(N).fill(0);
  for(var i=0;i<N-1;i++){
    if(L[i]==0){
      h=0;
    }
    if(S[i]=="<"){
      h++;
      Lf[i+1]=h;
    }else{
      h=0;
      Lf[i+1]=h;
    }
    if(L[N-1-i]==0){
      h2=0;
    }
    if(S[N-2-i]==">"){
      h2++;
      Lb[N-2-i]=h2;
    }else{
      h2=0;
      Lb[N-2-i]=h2;
    }
  }
  var ans=0;
  for(var i=0;i<N;i++){
    if(L[i]!=0){
      ans+=Math.max(Lf[i],Lb[i]);
    }
  }



  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29148
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
const int N = 1e9;
const int M = 1e9;
using namespace std;
#define INF 0x3f3f3f3f
#define e  2.718281828459045
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define ll long long

int main(){
	
	
	int l , r , d;
	cin >> l >> r >> d;
	
	int js = 0;
	for(int i = l; i <= r; i ++){
		
		if(i % d == 0) js++;
	} 
	
	cout << js << endl;
	return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int a[5010][210],st[5010][210],top[210];
long long ans,sum[5010],f[5010],ths[5010];
int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for (int i=2;i<=n;i++){int w;scanf("%d",&w);sum[i]=sum[i-1]+w;}
	for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) scanf("%d",&a[i][j]);
	for (int i=1;i<=n;i++)
	{
		for (int i=1;i<=n;i++) ths[i]=0;
		for (int j=1;j<=m;j++)
		{
			for (;top[j]&&a[i][j]>=a[st[top[j]][j]][j];top[j]--)
			{
				ths[st[top[j]-1][j]+1]+=a[i][j]-a[st[top[j]][j]][j];
				ths[st[top[j]][j]+1]-=a[i][j]-a[st[top[j]][j]][j];
			}
			ths[i]+=a[i][j];st[++top[j]][j]=i;
		}
		for (int j=1;j<=i;j++)
		{
			ths[j]+=ths[j-1];f[j]+=ths[j];
			ans=max(ans,f[j]-sum[i]+sum[j]);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>



using namespace std;



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


	char last;
	last = s[0];
	int num = 1;

	for (int i = 1; i < n; i++) {
		if (s[i] != last) {
			num++;
			last = s[i];
		}
	}

	cout << num  << endl;
}

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

struct Card{
  char patt;
  int num;
};

void display( std::vector<Card> A ){
    for( int i = 0; i < A.size(); i++ ){
      std::cout << A[i].patt << A[i].num;
      if( i < A.size()-1 ) std::cout << " ";
      else std::cout << std::endl;
  }
}

int sh_cnt = 0;
std::vector<int> G;

void insertionSort( std::vector<int>& A, int n, int g ){
  for( int i = g; i < n; i++ ){
    int v = A[i];
    int j = i - g;
    while( j >= 0 && A[j] > v ){
      A[j+g] = A[j];
      j = j - g;
      sh_cnt++;
    }
    A[j+g] = v;
  }
  return;
}

void shellSort( std::vector<int>& A, int n ){
  sh_cnt = 0;
  for( int h = 1; h < n; h*=2 ){
    G.push_back( h );
  }
  if( G.size() == 0 ) G.push_back( 1 );

  for( int i = G.size()-1; i >= 0; i-- ){
    insertionSort( A, n, G[i] );
  }
}



int bubbleSort( std::vector<Card>& A, int N ){
  int cnt = 0;
  for( int i = 1; i < N; i++ ){
    for( int j = i; j > 0; j-- ){
      if( A[j-1].num > A[j].num ){
        std::swap( A[j], A[j-1] );
        cnt++;
      } else  break;
    }
  }
  return cnt;
}

int selectionSort( std::vector<Card>& A, int N ){
  int cnt = 0;
  for( int i = 0; i < N-1; i++ ){
    int minj = i;
    for( int j = i+1; j < N; j++ ){
      if( A[minj].num > A[j].num ){
        minj = j;
      }
    }
    if( i != minj ){
      std::swap( A[minj], A[i] );
      cnt++;
    }
  }
  return cnt;
}

bool isSafe( const std::vector<Card> target, const std::vector<Card> base ){
  std::vector<char> patt(0);
  for( int i = 1; i <= 9; i++ ){
    for( int j = 0; j < base.size(); j++ ){
      if( base[j].num == i ){
        patt.push_back( base[j].patt );
      }
    }
  }

  for( int i = 0; i < target.size(); i++ ){
    if( target[i].patt != patt[i] )
      return false;
  }
  return true;
}

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

  shellSort( A, N );
  
  std::cout << G.size() << std::endl;
  for( int i = G.size()-1; i >= 0; i-- ){
    std::cout << G[i];
    if( i != 0 ) std::cout << " ";
    else std::cout << std::endl;
  }
  std::cout << sh_cnt << std::endl;
  for( auto& a: A ) std::cout << a << std::endl;
}



Measured memory_bytes: 6660
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>
 
using namespace std;
typedef long long LL;

const int maxn = 4005;
const int maxm = 2005;
const int mod = 1e9+7;

int dp[maxm],op[maxn],n,m,K,ans;
int main()
{
	#ifdef Amberframe
		freopen("agc009e.in","r",stdin);
		freopen("agc009e.out","w",stdout);
	#endif
	scanf("%d %d %d",&n,&m,&K);op[0]=1;
	for (int j=0;j<=m;j++) dp[j]=1;
	for (int i=1;i<=(n+m-1)/(K-1);i++)
	{
		for (int j=m;j>=K;j--) (dp[j]-=dp[j-K])%=mod;
		for (int j=max(0,i*(K-1)-n+1);j<=m;j++)
			if ((m-j)%(K-1)==0) ans=((LL)ans+dp[j]-op[j])%mod;
		for (int j=0;j<=m;j++) op[j]=dp[j];
		for (int j=1;j<=m;j++) (dp[j]+=dp[j-1])%=mod;
	}
	printf("%d",ans<0?ans+mod:ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
	#define N 100000

	int fac[N+100],invfac[N+100];

	int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
	int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
	int mul(int x,int y) {return 1ll*x*y%maxd;}
	ll qpow(ll x,int y)
	{
		ll ans=1;
		while (y)
		{
			if (y&1) ans=mul(ans,x);
			x=mul(x,x);y>>=1;
		}
		return ans;
	}
	int Inv(int x) {return qpow(x,maxd-2);}

	int C(int n,int m)
	{
		if ((n<m) || (n<0) || (m<0)) return 0;
		return mul(mul(fac[n],invfac[m]),invfac[n-m]);
	}

	void math_init()
	{
		fac[0]=invfac[0]=1;
		rep(i,1,N) fac[i]=mul(fac[i-1],i);
		invfac[N]=Inv(fac[N]);
		per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
	}
	#undef N
}
using namespace My_Math;

int main()
{
	ll n,k;
	cin >> n >> k;
	n%=k;
	ll ans=min(n,k-n);
	cout << ans;
	return 0;
}




Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
#include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);



int main() {
	int n, k;
	cin >> n >> k;
	int ans = 1;
	for (int i = 0; i < n; i++) {
		ans = min(ans * 2, ans + k);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var N,M,a,b int
  fmt.Scan(&N)
  fmt.Scan(&M)
  bridge := make([]int, N)
  for i := 0; i < M; i++ {
    fmt.Scan(&a)
    fmt.Scan(&b)
    bridge[a - 1] += 1
    bridge[b - 1] += 1
  }
  for _, v := range bridge {
    fmt.Println(v)
  }
}

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

#define el '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long ll;

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

  int n;
  cin >> n;
  vector<int> a(n);
  int cnt0 = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    while(a[i]){
      int r = i;
      while(r < n && a[r]){
        r++;
      }
      ans++;
      for(int j = i; j < r; j++){
        a[j]--;
      }
    }
  }
  cout << ans << el;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    cin >> K;
    int e = K/2;
    int o = K/2;
    if(K%2==0){
        cout << e*o <<  endl;
    }else{
        cout << e*(o+1) << endl;
    }

    return 0;
}

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

using namespace std;

const int maxn=1e3+5;
const int inf=0x3f3f3f3f;

typedef pair<int,int>P;

int h,w,n,sx,sy,book[maxn][maxn],goal[10],Next[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
char s[maxn][maxn];

int judge(int row,int col)
{
    if(row>=0&&row<h&&col>=0&&col<w){
        return 1;
    }
    return 0;
}

int bfs()
{
    int res=0;
    deque<P>q;
    for(int ci=0;ci<n;ci++){
        fill(book[0],book[0]+maxn*maxn,inf);
        q.push_back(P(sx,sy));
        book[sx][sy]=0;
        while(!q.empty()){
            int x=q.front().first;
            int y=q.front().second;
            q.pop_front();
            if((int)s[x][y]==49+ci){
                goal[ci]=book[x][y];
                sx=x;
                sy=y;
                break;
            }
            for(int i=0;i<4;i++){
                int nx=x+Next[i][0];
                int ny=y+Next[i][1];
                if(judge(nx,ny)&&s[nx][ny]!='X'&&book[nx][ny]==inf){
                    q.push_back(P(nx,ny));
                    book[nx][ny]=book[x][y]+1;
                }
            }
        }
        q.clear();
        res+=goal[ci];
    }
    return res;
}

int main()
{
    cin>>h>>w>>n;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>s[i][j];
            if(s[i][j]=='S'){
                sx=i;
                sy=j;
            }
        }
    }
    int res=bfs();
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 8048
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef pair<pll,pll> ppll;
typedef vector <ll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define N 100005
# define INF 0x3f3f3f3f
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
const ll M = 1000000007; 
ll ff[N];
ll ffinv[N];
ll xxx,yyy;
void EE(ll a,ll b)
{
    if(b==0)
    {
        xxx = 1;
        yyy = 0;
        return;
    }
    EE(b,a%b);
    ll tmp = xxx;
    xxx = yyy;
    yyy = tmp - (a/b)*yyy;
}
ll minv(ll x)
{
    EE(x,M);
    return (xxx%M + M)%M;
}
void pre()
{
    ff[1] = 1;
    ffinv[1] = minv(ff[1]);
    for(ll i=2;i<N;i++)
    {
        ff[i] = (ff[i-1]*i)%M;
        ffinv[i] = minv(ff[i]);
    }
}
ll nnccrr(ll x,ll y)
{
    if(y==0 || y==x)
        return 1;
    return ( (ff[x]%M) * ( ( (ffinv[x-y]%M) * (ffinv[y]%M) )%M) )%M; 
}
int main(){
	FAST;
	pre();
    ll n, k, m, z = 0, ans = 0, j, t = 0, x = 0, y = 0, c = 0, i;
    cin >> n >> k;  
    ll a[n];
    for ( i = 0 ; i < n ; i ++ ){
    	cin >> a[i];
    }
    sort (a , a+n);
    for ( i = 0 ; i <= n-k ; i ++ ){
    	ans = ( ans + ( a[i] * nnccrr(n-i-1 , k-1) ) % M + M ) % M ;
    }
    for ( i = n - 1 ; i >= k - 1 ; i -- ){
    	c = ( c + ( a[i] * nnccrr(i , k-1) ) % M + M ) % M ;
        //cout << c << " " << a[i] <<" " << i << " " << k-1 <<  "\n";
    }
    cout << ( c - ans + M) % M; 
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 10005;

int N;
LL a[MaxN + 5], b[MaxN + 5];
LL Sa, Sb, S;

void Init() {
	Sa = 0; Sb = 0;
	for(int i = 1; i <= N; i++) {
		scanf("%lld", &a[i]);
		Sa += a[i];
	}
	for(int i = 1; i <= N; i++) {
		scanf("%lld", &b[i]);
		Sb += b[i];
	}
	S = Sb - Sa;
}

void solve() {
	LL cnt = 0;
	for(int i = 1; i <= N; i++) {
		if(a[i] < b[i]) cnt += ((b[i] - a[i]) + 1) / 2;
	}
	if(cnt <= S) printf("Yes\n");
	else printf("No\n");
}

int main()
{
	while(scanf("%d", &N) != EOF)
	{
		Init();
		solve();
	}
	return 0;
}

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

int main() {
    int N;
    cin >> N;

    bool can = false;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == N) {
                can = true;
            }
        }
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	char s[4];
	cin >> s;
	rep(i, 3) {
		if (s[i] == '1') {
			cout << 9;
		}
		else {
			cout << 1;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n,b,f,r,v;
	int array[4][4][10];
	for (int i = 0; i < 4; i++) {
		for (int k = 0; k < 4; k++) {
			for (int p = 0; p < 10; p++) {
				array[i][k][p] = 0;
			}
		}
	}
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		array[b-1][f-1][r-1] += v;
	}
	
	for (int i = 0; i < 4; i++) {
		for (int k = 0; k < 3; k++) {
			for (int r = 0; r < 10; r++) {
                                printf(" ");
				printf("%d", array[i][k][r]);
			}
			printf("\n");
		}
		if (i < 3) {
			printf("####################\n");
		}
	}
	
}


Measured memory_bytes: 2736
#include"bits/stdc++.h"
using namespace std;

#define ll long long
#define INF INT_MAX/3
#define pi 2*acos(0.0)
#define eps 1e-14

const int MAX_N = (int)1e+5;
const int MAX_M = (int)1e+2;
int n, k;
int a[MAX_N];
int oddn = 0, evenn = 0;
void input()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 2 == 1) oddn++;
	}
}
void solve()
{
	if (oddn % 2 == 0) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}
int main() {
	input();
	solve();
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

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


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n){
        m = 2;
        vi h(n);
        vi dp(n + 1, MOD);
        dp[0] = 0;
        REP(i, n) {
            cin >> h[i];
            for(int j = max(0, i - m); j < i; j++) {
                chmin(dp[i], dp[j] + abs(h[i] - h[j]));
            }
        }
        cout << dp[n - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
//110
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include <vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    
    vector<string> vec(N);

    for(int i = 0; i < N; i++)
    {
        /* code */
        cin >> vec[i];
    }

    bool flag = true;
    for(int i = 1; i < N; i++)
    {
        /* code */
        if(vec[i].front() != vec[i-1].back()){
            flag = false;
        }
        for(int j = 0; j < i; j++)
        {
            /* code */
            if(vec[i] == vec[j]){
                flag = false;
            }
        }
        
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
ll A, B, n;

void solve()
{
    cin >> A >> B >> n;
    ll x = min(n, B - 1);
    cout << (A * x) / B - A * (x / B);
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 3596
H, N=(int(i) for i in input().split())
P=[[int(i) for i in input().split()] for  _ in range(N)]


dp=[0]
for i in range(1,H+1):
    l=[]
    for j in range(N):
        if P[j][0]>=i:
            l.append(P[j][1])
        else:
            l.append(dp[i-P[j][0]]+P[j][1])
    dp.append(min(l))
print(dp[H])

Measured memory_bytes: 43484
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, a, MIN = 10000, MAX = 0;
    cin >> n;
    rep(i, 0, n){
        cin >> a;
        MIN = min(MIN, a);
        MAX = max(MAX, a);
    }
    cout << MAX - MIN << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
S = input()
if '1'*M in S:
    print(-1)
    exit()
nums = []
cur = N
min_loc = N
for i in range(N)[::-1]:
    if cur-i > M:
        nums.append(cur-min_loc)
        cur = min_loc
    if S[i] == '0':
        min_loc = min(min_loc, i)
if cur > 0:
    nums.append(cur)
print(' '.join(map(str, nums[::-1])))


Measured memory_bytes: 11132