akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {

  int mod = 2019;

  string S;
  cin >> S;

  int N = S.size();
  reverse(S.begin(), S.end());
  
  long long sum;
  vector<int> v(mod);
  
  long long count = 1;
  long long answer = 0;
  
  int m = 0;

  for (int i = 0; i < N; i++) {
    v[m]++;
    sum += (S[i] - '0') * count % mod;
    count = count * 10 % mod;
    m = sum % mod;
    answer += v[m];
  }

  cout << answer << endl;

  return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

int find_vec(int a, vector<int> A){
    auto itr = find(A.begin(), A.end(), a);
    if(itr == A.end()){
        return -1;
    }else{
        return distance(A.begin(), itr);
    }
}

int main(){
    vector<int> A;

    for(int i = 0; i < 9; i++){
        int a;
        cin >> a;
        A.push_back(a);
    }

    int N;
    cin >> N;

    for(int i = 0; i < N; i++){
        int b;
        cin >> b;

        int p = find_vec(b, A);
        if(p > -1){
            A[p] = -1;
        }
    }

    if(A[0] + A[1] + A[2] == -3){
        cout << "Yes" << endl;
        exit(0);
    }

    if(A[3] + A[4] + A[5] == -3){
        cout << "Yes" << endl;
        exit(0);
    }

    if(A[6] + A[7] + A[8] == -3){
        cout << "Yes" << endl;
        exit(0);
    }

    if(A[0] + A[3] + A[6] == -3){
        cout << "Yes" << endl;
        exit(0);
    }

    if(A[1] + A[4] + A[7] == -3){
        cout << "Yes" << endl;
        exit(0);
    }

    if(A[2] + A[5] + A[8] == -3){
        cout << "Yes" << endl;
        exit(0);
    }

    if(A[0] + A[4] + A[8] == -3){
        cout << "Yes" << endl;
        exit(0);
    }

    if(A[2] + A[4] + A[6] == -3){
        cout << "Yes" << endl;
        exit(0);
    }

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


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int ans=-2000000000000000000;
    ans=max(ans,a*c);
    ans=max(ans,b*c);
    ans=max(ans,a*d);
    ans=max(ans,b*d);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3196
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>

using namespace std;
const int N=2e5+10,inf=1e9;
int dp[N][2];
char s[N];

int main(){
    int A,B,ans;
	cin >> A >> B;
    if(A>=13){
        ans = B;
    }else if(A>=6 && A<=12){
        ans = B/2;
    }else{
        ans = 0;
    }

	cout << ans << endl;
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    string N = sread();
    auto dp = new long[][](2, N.length + 1);
    dp[0][] = long.min;
    dp[1][] = long.min;
    dp[0][0] = 0;
    foreach (i; 0 .. N.length)
    {
        dp[0][i + 1] = dp[0][i + 1].max(dp[0][i] + N[i] - '0');
        dp[1][i + 1] = dp[1][i + 1].max(dp[0][i] + N[i] - '0' - 1, dp[1][i] + 9);
    }
    writeln(max(dp[0][N.length], dp[1][N.length]));
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

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...));
}

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);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}



int main() {
    ll N,A,B;
    cin >> N >> A >> B;

    if(A > B) pl(0)
    else if(N==1) {
        if(A==B) pl(1)
        else pl(0)
    } else {
        pl((N-2)*(B-A)+1)
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>
#include <atcoder/all>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif


using S = std::tuple<int, int, long long int, long long int>;
S op(S x, S y){
    return {std::get<0>(x) + std::get<0>(y), std::get<1>(x) + std::get<1>(y), 
            std::get<2>(x) + std::get<2>(y) + static_cast<long long int>(std::get<0>(x)) * std::get<1>(y),
            std::get<3>(x) + std::get<3>(y) + static_cast<long long int>(std::get<1>(x)) * std::get<0>(y)
    };
} 
S e(void){ return {0, 0, 0, 0}; }
using F = bool;
S mapping(F f, S x){
    return f ? S(std::get<1>(x), std::get<0>(x), std::get<3>(x), std::get<2>(x)) : x;
}
F composition(F f, F g){ return f != g; }
F id(void){ return false; }


using lazy_segment_t = atcoder::lazy_segtree< S, op, e, F, mapping, composition, id >;

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);
    int n, q; std::cin >> n >> q;
    std::vector<std::tuple<int, int, long long int, long long int>> A(n); 
    for(int i = 0; i < n; ++i){ 
        char c; std::cin >> c; if(c == '0') A[i] = {1, 0, 0, 0}; else A[i] = {0, 1, 0, 0};
    }
    lazy_segment_t ST(A);
    while(q--){
        char c; int x, y; std::cin >> c >> x >> y; --x;
        if(c == '1') ST.apply(x, y, true);
        else std::cout << std::get<3>( ST.prod(x, y) ) << '\n';
    }
    return 0;
}

Measured memory_bytes: 20336
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
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); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();

    string s;
    cin >> s;
    if (s == "SSS") cout << 0 << endl;
    else {
        int cnt = 1;
        rep (i, 2) {
            if (s[i] == s[i + 1] and s[i] == 'R') cnt++;
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3664
#include<math.h>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define rg register
#define il inline
using namespace std;
int n,w;
struct node{
	int a,b;
	bool operator <(node x)const{return b<x.b;}
}s[200010];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&s[i].a,&s[i].b);
	sort(s+1,s+n+1);
	for(int i=1;i<=n;++i){
		w+=s[i].a;
		if(w>s[i].b)return puts("No")&0;
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    char s[4];
    int len, cnt=0, m=0;
    
    scanf("%s", s);
    
    len=strlen(s);
    
    rep(i, len){
        if (s[i]=='R') {
            cnt++;
            if (cnt>m) {
                m=cnt;
            }
        } else {
            cnt=0;
        }
    }
    
    printf("%d", m);

    return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n, K;
    cin >> n >> K;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; ++i)  cin >> x[i] >> y[i];
    ll ans = 4e+18;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < i; ++j){
            int lx = min(x[i], x[j]), rx = max(x[i], x[j]);
            for(int k = 0; k < n; ++k){
                for(int l = 0; l < k; ++l){
                    int ly = min(y[k], y[l]), ry = max(y[k], y[l]);
                    int c = 0;
                    for(int m = 0; m < n; ++m){
                        if(x[m] < lx || x[m] > rx || y[m] < ly || y[m] > ry)    continue;
                        ++c;
                    }
                    if(c >= K){
                        ll S = (ll)(rx - lx) * (ry - ly);
                        chmin(ans, S);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3668
#include <iostream>
using namespace std;
int main(){
  long long a,b,k;
  cin >> a >> b >> k;
  if(a>=k) cout << a-k <<  " " << b << "\n";
  else if(a+b>=k) cout << 0 << " " << b-(k-a) << "\n";
  else cout << 0 << " " << 0 << "\n";
  return 0;
}

Measured memory_bytes: 3608
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
flag = False
answer = 1
for a in A:
    if A[-1] == 0:
        answer = 0
        break
    else:
        answer *= a
        if answer > 10 ** 18:
            flag = True
            break

if flag:
    print(-1)
else:
    print(answer)

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

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

  int n , r;
  cin >> n >> r;
  if (n > 10) {
    cout << r << endl;
  } else {
    cout << r + (100 * (10 - n)) << endl;
  }
  return 0;
}



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

using namespace std;

void solve()
{
	int n,m,r;
	cin >> n >> m >> r;
	vector<vector<long>> wf(n, vector<long>(n, INT_MAX));
	vector<int> rs(r);
	for (int i = 0; i < r; i++)
	{
		cin >> rs[i];
		rs[i]--;
	}
	sort(rs.begin(), rs.end());
	while (m--)
	{
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		wf[a][b] = wf[b][a] = c;
	}
	for (int k = 0; k < n; k++)
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
			}
		}
	}
	long ans = LONG_MAX;
	do
	{
		long res = 0;
		for (int i = 0; i < r-1; i++)
		{
			res += wf[rs[i]][rs[i+1]];
		}
		ans = min(res, ans);
	} while (next_permutation(rs.begin(), rs.end()));

	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 512
N, M = map(int, input().split(" "))
A = [int(a) for a in input().split()]

# A=[5,5,5,5,5,5,5,7,3,5]
# N=len(A)
# M=2

tmp=0
B=[0]
for i in A:
    tmp += i
    tmp = tmp % M
    B.append(tmp)

B.sort()
# print (B)
cnt=0
ret=0
for i in range(len(B)):
    if i ==0:
        cnt += 1
        prev=B[0]
        
    else:
        if B[i] == prev:
            cnt += 1
            
        else:
            ret += int(cnt*(cnt-1)/2)
            prev = B[i]
            cnt = 1

ret += int(cnt*(cnt-1)/2)

print (ret)

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

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

#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()
{
    bool ok=true;
    ll n,now=0;
    cin>>n;
    vector<pll> v(n);   //b,a
    for(int i = 0; i < n; i++)
    {
        ll a,b;
        cin>>a>>b;
        v[i]=make_pair(b,a);
    }
    sort(all(v));
    for(int i = 0; i < n; i++)
    {
        now+=v[i].second;
        if(now>v[i].first)
        {
            ok=false;
            break;
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

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

const int N = 5e3 + 100;
const int base = 313;
const int mod = 1e9 + 7;

int n;
string s;
int hashs[N];
int tavan[N];

void help1() {
	tavan[0] = 1;
	for (int i = 1; i < N; i++)
		tavan[i] = (1LL * tavan[i - 1] * base) % mod;
	for (int i = 1; i <= n; i++)
		hashs[i] = (1LL * hashs[i - 1] * base + s[i - 1]) % mod;
}

int gethash(int i, int j) {
	return (hashs[j] - 1LL * hashs[i] * tavan[j - i] % mod + mod) % mod;
}

bool check(int x) {
	set<int> se;
	int l = n - 2 * x;
	int mid = n - x;
	int r = n;
	while (l >= 0) {
		se.insert(gethash(mid, r));
		if (se.find(gethash(l, mid)) != se.end())
			return true;
		l--, mid--, r--;
	}
	return false;	
}

int main () {
	cin >> n >> s;
	help1();
	int l = 0; 
	int r = n;
	while (r - l > 1) {
		int mid = (r + l) / 2;
		if (check(mid))
			l = mid;
		else
			r = mid;
	}
	cout << l;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    int h[110000] = {}, dp[110000] = {};
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
    {
        int tmp = 1e9;
        for (int j = 1; j <= k && i - j >= 0; j++)
        {
            int hoge = abs(h[i] - h[i - j]) + dp[i - j];
            if (tmp > hoge)
                tmp = hoge;
        }
        dp[i] = tmp;
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1152
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int Mod=998244353;
const int N=5e5+5;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
int n,m,Ans,fac[N],inv[N];
int mod(int x){return x>=Mod?x-Mod:x;}
void Prepare(int maxn){
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=maxn;i++)fac[i]=1ll*fac[i-1]*i%Mod;
	for(int i=2;i<=maxn;i++)inv[i]=1ll*inv[Mod%i]*(Mod-Mod/i)%Mod;
	for(int i=2;i<=maxn;i++)inv[i]=1ll*inv[i-1]*inv[i]%Mod;
}
int C(int n,int m){return n<m?0:1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;}
int Pow(int x,int y){
	int ans=1;
	while(y){if(y&1)ans=1ll*ans*x%Mod;x=1ll*x*x%Mod;y>>=1;}
	return ans;
}
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();m=read();Prepare(max(n,m));
	for(int i=0;i<=min(n,m);i++){
		Ans=mod(Ans+1ll*(i&1?Mod-1:1)*C(n,i)%Mod*C(m,i)%Mod*fac[i]%Mod*Pow(m+1,n-i)%Mod*Pow(n+1,m-i)%Mod);
	}
	printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 7580
//
//  A - 500 Yen Coins.cpp
//  Practice
//
//  Created by Hajime Sakamoto on 2020/01/10.
//  Copyright © 2020 Hajime Sakamoto. All rights reserved.
//

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <iterator>

using namespace std;


int main(){
    int K;
    int X;
    
    
    cin >> K;
    cin >> X;
    
    if (K*500 >=X){
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    
    
    
    
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define mod 1000000007
#define maxn 100009
#define maxr 100009
double glb=0;
double distance(ll x,ll y,ll a ,ll b)
{
	double ans=(a-x)*(a-x)+(b-y)*(b-y);
	ans=(double)sqrt(ans);
	return ans;
}
ll fact(ll n)
{
	ll ans=1;
	frr(i,n+1,1)
	{
		ans*=i;
	}
	return ans;
}
void back(vector<PLL> arr,VI visit,ll n ,int i,double dis)
{
	visit[i]=1;
	double ans=0;
	int flag=1;
	fr(j,0,n)
	{
		if(visit[j]==0)
		{
			flag=0;
			double cal=distance(arr[i].F,arr[i].S,arr[j].F,arr[j].S);
			double temp=cal+dis;
			back(arr,visit,n,j,temp);
		}
	}
	if(flag==1)
		glb+=dis;
	return;
}
void solve()
{
	ll n;
	rl(n);
	vector<PLL> arr;
	fr(i,0,n)
	{
		ll x,y;
		rl2(x,y);
		arr.PB(MP(x,y));
	}
	VI visit(n,0);
	double ans=0;
	fr(i,0,n)
	{
		back(arr,visit,n,i,0);
	}
	ans=glb;
	n=fact(n);
	ans/=n;
	cout<<fixed<<setprecision(10);
	cout<<ans<<endl;
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 256
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let rec f a b = if b = 0 then a else f b (a mod b)
let _ = Array.fold_left f 0 a_s |> Printf.printf "%d\n"

Measured memory_bytes: 5504
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>
#include <bitset>
#include <cassert>

using namespace std;

long long M = 1000000007;

int main() {

    int D,T,S;
    cin>>D>>T>>S;

    if(S*T >= D) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
int fn(vector<int>& h, int n, vector<int>& t){
	int cost;

	t[n - 1] = 0;

	if(n > 1){
		t[n - 2] = abs(h[n - 2] - h[n - 1]) + t[n - 1];
	}

	for(int i = n - 3; i >= 0; i--){
		t[i] = min(abs(h[i + 1] - h[i]) + t[i + 1], abs(h[i + 2] - h[i]) + t[i + 2]);
	}

	return t[0];

}
int main(){
	int n;
	cin >> n;

	vector<int> h(n + 1);
	vector<int> t(n + 1, -1);

	for(int i = 0; i < n; i++){
		cin >> h[i];
	}

	cout << fn(h, n, t) << endl;
}

Measured memory_bytes: 1024
#include <cstdio>

int N;
char S[310][310];
char s[310][310];
int res;

int suc()
{
	int i, j;
	for(i=0; i<N; i++){
		for(j=0; j<N; j++)
			if(s[i][j] != s[j][i])
				return 0;
	}
	return 1;
}

void solve()
{
	int i, j, k;
	for(k=0; k<N; k++){
		for(i=0; i<N; i++){
			for(j=0; j<N; j++)
				s[i][j] = S[i][(j+k)%N];
		}
		if(suc() )
			res += N;
	}
	printf("%d\n", res);
}

int main()
{
	int i;
	scanf("%d", &N);
	for(i=0; i<N; i++)
		scanf("%s", S[i]);
	solve();
	return 0;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n*2];
		for (int i = 0; i < a.length; i++) {
			a[i] = scan.nextInt(); 
		}
		Arrays.sort(a);
		int min = 0;
		for (int i = 0; i < a.length; i+=2) {
			min += Math.min(a[i],a[i+1]);
		}
		System.out.println(min);
 	}

}


Measured memory_bytes: 9940
#include "bits/stdc++.h"
using namespace std;
const int maxn=2e5+10;
struct Item
{
	long long A,B;
};
int n;
Item a[maxn];
bool cmp(Item x,Item y)
{
	return x.B<y.B;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].A>>a[i].B;
	}
	sort(a,a+n,cmp);
	long long tim=0LL;
	for(int i=0;i<n;i++)
	{
		tim+=a[i].A;
		if(tim>a[i].B)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define INT_MAX 2147483647

int main(void){
    int N, T;
    scanf("%d%d", &N, &T);

    int *c, *t;
    c = (int*)malloc(N * sizeof(int));
    t = (int*)malloc(N * sizeof(int));

    int i;
    int min = INT_MAX;
    for(i=0; i<N; i++) {
        scanf("%d%d", &c[i], &t[i]);
        if(t[i] <= T) {
            if(c[i] < min) {
                min = c[i];
            }
        }
    }
    if(min != INT_MAX) {
        printf("%d\n", min);
    }
    else{
        printf("TLE\n");
    }

    free(c);
    free(t);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<set>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    string s;
    set<string> a;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        a.insert(s);
    }
    int m = a.size();
    cout << m << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int Q, H, S, D, N;

int main(){
    cin >> Q >> H >> S >> D;
    cin >> N;

    H = min(H, Q * 2);
    S = min(S, H * 2);
    D = min(D, S * 2);

    //cout << Q << H << S << D;

    ll ans = N / 2LL * D + N % 2LL * S;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<iterator>
#include<vector>
#include<string>
#include<map>

using namespace std;


#define mod(cans) cans%10**9+7
#define cin_pl(x,y) for(int i=0;i<x;i++){cin>>y[i];}
#define pl_twin(x,y,z) for(int i=0;i<x;i++){cin>>y[i]>>z[i];}
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define st(s) size_t size = s.length()
#define prians(Answer) cout<<Answer<<"\n"
#define com_div(x,Co) for(int i=1;i<x+1;i++){if(x%i==0){Co++;}}
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int>> matrix;
typedef pair<int,int> pr;
typedef vector<pr> vpt;
typedef greater<int> gi;
typedef vector<pr> vpii;
typedef vector<pair<ll,ll>> vpll;

int main()
{
int n;
cin>>n;
vpii p;
rep(i,n){
    int a,b;
cin>>a>>b;
p.push_back(make_pair(b,a));
}
sort(all(p));
int time=0,x;
rep(i,n)
{
    time+=p[i].second;
    if(time>p[i].first)
    {x=0;break;}
    else
    {
        x=1;
    }
    
}
TF(x);
}




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

int n,c[N][2],l[N][2];
vector<pair<ll,ll> > f[N];

bool cmp(pair<ll,ll> x,pair<ll,ll> y){
	return x.second<y.second;
}

bool check(ll k){
	for (int z=n;z>=1;z--){
		if (!c[z][0]){
			f[z].clear();
			f[z].push_back(make_pair(0,0));
			continue;
		}
		
		f[z].clear();int x=c[z][0],y=c[z][1];
		for (int i=0;i<(int)f[x].size();i++)
			f[x][i].first+=l[z][0],f[x][i].second+=l[z][0];
		for (int i=0;i<(int)f[y].size();i++)
			f[y][i].first+=l[z][1],f[y][i].second+=l[z][1];
		if (f[x].size()>f[y].size()) swap(x,y);
			
		sort(f[x].begin(),f[x].end(),cmp);
		sort(f[y].begin(),f[y].end());
		ll t=1ll<<60;
		for (int i=(int)f[x].size()-1,j=0;i>=0;i--){
			while (j<(int)f[y].size()&&f[x][i].second+f[y][j].first<=k)
				t=min(t,f[y][j].second),j++;
			if (j) f[z].push_back(make_pair(f[x][i].first,t));
		}
			
		sort(f[x].begin(),f[x].end());
		sort(f[y].begin(),f[y].end(),cmp);
		t=1ll<<60;
		for (int i=(int)f[x].size()-1,j=0;i>=0;i--){
			while (j<(int)f[y].size()&&f[y][j].second+f[x][i].first<=k)
				t=min(t,f[y][j].first),j++;
			if (j) f[z].push_back(make_pair(t,f[x][i].second));
		}
	}
	return !f[1].empty();
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=2;i<=n;i++){
		int x=read(),y=read();
		if (!c[x][0]) c[x][0]=i,l[x][0]=y;
		else c[x][1]=i,l[x][1]=y;
	}
	ll ans=-1;
	for (ll k=1ll<<40;k;k/=2)
		if (!check(ans+k)) ans+=k;
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 53128
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, R; 
  cin >> N >> R;

  cout << R+(10-min(N, 10ll))*100 << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int a[n+1];
    for(int i = 0; i < n+1; i++)    cin >> a[i];
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int b;  cin >> b;
        int d = min(b, a[i]);
        ans += d;
        b -= d;
        d = min(b, a[i+1]);
        ans += d;
        a[i+1] -= d;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

type restaurant struct {
	number int
	name   string
	rank   int
}

type restaurants []*restaurant

func (r restaurants) Len() int {
	return len(r)
}

func (r restaurants) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func (r restaurants) Less(i, j int) bool {
	if r[i].name == r[j].name {
		return r[i].rank >= r[j].rank
	}
	return r[i].name <= r[j].name
}

func main() {
	sc := NewScanner(os.Stdin)
	N := sc.NextInt()
	rs := make(restaurants, N)
	for i := 0; i < N; i++ {
		s := sc.Next()
		p := sc.NextInt()
		rs[i] = &restaurant{
			number: i + 1,
			name:   s,
			rank:   p,
		}
	}
	sort.Sort(rs)
	for _, r := range rs {
		fmt.Println(r.number)
	}
}

func vmin(v []int) int {
	mn := math.MaxInt32
	for i := 0; i < len(v); i++ {
		mn = min(mn, v[i])
	}
	return mn
}

func gcd(x, y int) int {
	if y > 0 {
		return gcd(y, x%y)
	}
	return x
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func max64(x, y float64) float64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func min64(x, y float64) float64 {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt64() int64 {
	i, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


Measured memory_bytes: 640
from collections import defaultdict
import math

def c():
    sosus = "2、3、5、7、11、13、17、19、23、29、31、37、41、43、47、53、59、61、67、71、73、79、83、89、97"
    sosus  = sosus.split("、")
    sosus = list(map(int,sosus))
    dic = dict(zip(sosus,len(sosus) * [0]))
    N =int(input())
    p = 0
    for i in range(2,N+1):
        lim = int(math.sqrt(i)) + 1
        cot = 0
        p = 0
        while   i != 1:
            p = sosus[cot]
            if i % p == 0:
                dic[p] += 1
                i = i // p
            else:
                cot += 1
        if i != 1:
            sosus[i] += 1
    ans = 0

    pats = [[14,4],[24,2]]
    for v in dic.values():
        if v >= 74:
            ans += 1

    for pat in pats:
        temp = 0
        temp2 = 0
        p1,p2 = pat
        for v in dic.values():
            if v>= p1:
                temp += 1
        for v in dic.values():
            if v>= p2:
                temp2 += 1
        ans += max(temp * (temp2 - 1),0)

    temp = 0
    temp2 = 0
    p1,p2 = 4,2
    for v in dic.values():
        if v>= p1:
            temp += 1
    for v in dic.values():
        if v>= p2:
            temp2 += 1
    ans += max(temp * (temp-1) //2 *  (temp2 - 2),0)
    print(ans)
if __name__ == "__main__":
    c()

Measured memory_bytes: 38384
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]
    Bs = [int(item) for item in input().split()]

    Ds = [a - b for a, b in zip(As, Bs)]

    cnt_minus = 0
    total_minus = 0
    minus_list = []

    cnt_plus_to_drow = 0
    plus_list = []

    for item in Ds:
        if item < 0:
            cnt_minus += 1
            total_minus += item
        else:
            plus_list.append(item)

    plus_list.sort()

    if sum(plus_list) >= abs(total_minus):
        for item in plus_list[::-1]:
            if total_minus >= 0:
                break

            total_minus += item
            cnt_plus_to_drow += 1

        print(cnt_minus + cnt_plus_to_drow)
    else:
        print(-1)

if __name__ == "__main__":
    resolve()


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

int main() {
  int a,b;
  cin >> a >> b;
  if( a > b ){
    for (int i = 0; i < a; i++){
      cout << b;
    }
  }else{
    for (int i = 0; i < b; i++){
      cout << a;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	// L(i): minimum cost at stone i
	//freopen("input.txt", "rt", stdin);
	int n;
	cin >> n;
	int k;
	cin >> k;
	vector<long long> dp(n, 1e+18);
	vector<int> vecN(n);
	for (auto& i : vecN) {
		cin >> i;
	}

	dp[0] = 0;

	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k; j++)
			if (i - j > -1)
				dp[i] = min(dp[i], dp[i - j] + abs(vecN[i] - vecN[i - j]));
	}

	cout << dp[n - 1] << endl;

	return 0;
}

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

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

if(a>b){t=a;a=b;b=t;}
if(b>c){t=b;b=c;c=t;}
if(a>b){t=a;a=b;b=t;}

cout<<a<<" "<<b<<" "<<c<<endl;

return 0;
}


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

const int MAX_V = 50;
const int MAX_S = MAX_V*50;
const ll INF = 1e18;

struct Edge {
    int to, a, b;
    Edge(int to, int a, int b):to(to),a(a),b(b) {}
};

struct Data {
    int v, s;
    ll x;
    Data(int v, int s, ll x):v(v),s(s),x(x) {}
    bool operator<(const Data& a) const {
        return x > a.x;
    }
};

vector<Edge> g[MAX_V];
ll dist[MAX_V][MAX_S+5];

int main(){
    int n,m,s; cin>>n>>m>>s;
    rep(i,m) {
        int u,v,a,b; cin>>u>>v>>a>>b;
        u--; v--;
        g[u].emplace_back(v,a,b);
        g[v].emplace_back(u,a,b);
    }

    rep(i,n)rep(j,MAX_S+5) dist[i][j] = INF;
    s = min(s,MAX_S);
    
    priority_queue<Data> q;
    
    auto push = [&](int v, int s, ll x){
        if(s<0) return;
        if(dist[v][s]<=x) return;
        dist[v][s] = x;
        q.emplace(v,s,x);
    };

    vector<int> c(n),d(n);
    rep(i,n) cin>>c[i]>>d[i];
    push(0,s,0);
    while(!q.empty()){
        Data hoge = q.top(); q.pop();
        int v = hoge.v, s=hoge.s;
        ll x = hoge.x;
        if(dist[v][s]!=x) continue;
        int nows = min(s+c[v],MAX_S);
        push(v,nows,x+d[v]);
        for(Edge e : g[v]){
            push(e.to, s-e.a, x+e.b);
        }
    }
    for(int i=1;i<n;i++){
        ll ans = INF;
        rep(j,MAX_S+5){
            ans = min(ans,dist[i][j]);
        }
        cout << ans << endl;
    }
}


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

int main() {
    int N, x;
    cin >> N >> x;
    vector< int > A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    int ans = 0;
    rep(i, N) {
        int a = A[i];
        if (a > x) break;
        x -= a;
        ++ans;
    }
    if (ans == 0) {
        cout << 0 << endl;
    } else if (ans == N && x > 0) {
        cout << ans - 1 << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();

        char[] c = S.toCharArray();

        int[] rem = new int[2019];
        rem[0] = 1;
        int ans = 0;
        long num = 0;
        for (int i = S.length() - 1; i >= 0; i--) {
            num += modpow(10, S.length() - i - 1, 2019) * (c[i] - '0') % 2019;
            int r = (int)num % 2019;
            ans += rem[r];
            rem[r]++;
        }
        System.out.println(ans);
    }

    private static long modpow(long a, long n, long mod) {
        long res = 1;
        while (n > 0) {
            if (n % 2 == 1)
                res = (res * a) % mod;
            a = (a * a) % mod;
            n >>= 1;
        }
        return res % mod;
    }
}


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

const int p = 100003;


int main(){
    int k;
    cin>>k;
    ll ans=0;
    REP(p,k){
        REP(q,k){
            REP(r,k){
                ans+=__gcd(r,__gcd(p,q));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3676
def main():
    s = list(input())[::-1]
    ary_mod = [0] * 2019
    ary_mod[0] = 1
    now = 0

    for i, ss in enumerate(s):
        now += int(ss) *pow( 10 , i, 2019)
        remind = now % 2019
        ary_mod[remind] += 1
    ans = 0
    for i, n in enumerate(ary_mod):
        ans += (n*(n-1)) // 2
    print(ans)
if __name__=='__main__':
    main()


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

int main(){
	int k,t;
	cin >> k >> t;
	vector<int> a(t);
	int m = 0;
	rep(i,t){
		cin >> a[i];
	}
	sort(a.rbegin(),a.rend());
	int ans = a[0] - 1;
	REP(i,t-1){
		ans -= a[i];
	}
	cout << max(ans, 0) << endl;
    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> A(n, 0);
  for(ll i=0; i<n; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<ll>{});
  ll ans = A[0];
  // 0 gets nothing
  // 1 gets A[0]
  // 2 gets A[1]
  // 3 gets A[1]
  // 4 gets A[2]
  // 5 gets A[2]
  for(ll i=2; i<n; i++) {
    ans += A[i/2];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4836
N=int(input())
c=input()
dp=[0]
bp=[0]
for i in range(N):
  if c[i]=='W':
    dp.append(dp[-1]+1)
    bp.append(bp[-1])
  else:
    dp.append(dp[-1])
    bp.append(bp[-1]+1)
ans=10**9
for i in range(N+1):
  ans=min(max(dp[i],bp[-1]-bp[i]),ans)
print(ans)

Measured memory_bytes: 19112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
using namespace std;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n,m; cin >> n >> m;
    
    vi fav(m, 0);
    rep(i,n){
        int k;cin>>k;
        rep(j,k){
            int a;cin>>a;
            a--;fav[a]++;
        }
    }
    
    int ans = 0;
    rep(i,m)if(fav[i]==n)ans++;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3608
str_len = int(input().rstrip())
str = input().rstrip()

rgb_nums_dict = {'R':str.count('R'), 'G':str.count('G'), 'B':str.count('B')}
total = 0
for i in range(str_len-2):
    for j in range(i+1,str_len-1):
        first_str = str[i]
        second_str = str[j]
        if first_str==second_str:
            continue
        else:
            if 2*j-i<str_len and second_str!=str[2*j-i]!=first_str:
                total-=1
                


for i in range(str_len):
    first_str = str[i]
    if first_str=='R':
        total += rgb_nums_dict['G']*rgb_nums_dict['B']
        
    elif first_str=='G':
        total += rgb_nums_dict['R']*rgb_nums_dict['B']
        
    else:#'B'
        total += rgb_nums_dict['R']*rgb_nums_dict['G']
        
    rgb_nums_dict[first_str]-=1
    if rgb_nums_dict[first_str]==0:
        break
    
print(total)


Measured memory_bytes: 73860
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let print_int n = Printf.printf "%d\n" n

let () = 
  let m = scan_int() and d = scan_int() in
  let rec loop mi di cnt =
    let d1 = di mod 10 and d10 = di / 10 in
    let cnt =
      if d1 > 1 && d10 > 1 && d1 * d10 = mi then cnt+1
      else cnt in
    if di = d then
      if mi = m then cnt
      else loop (mi+1) 1 cnt
    else loop mi (di+1) cnt in
  print_int (loop 1 1 0)

Measured memory_bytes: 384
n, k = map(int, input().split())
h = list(map(int, input().split()))

c = [1e9 for _ in range(n)]
c[0] = 0

for i in range(1, n):
    for j in range(1, min(i, k) + 1):
        c[i] = min(c[i], c[i - j] + abs(h[i] - h[i - j]))
print(c[-1])

Measured memory_bytes: 58848
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

#define NAME_MAX 10

struct process {
    struct process* next;
    char name[NAME_MAX + 1];
    int  time;
};

struct process_queue {
    struct process* head;
    struct process* tail;
    int count;
};

static void enqueue(struct process_queue* queue, struct process* process) {
    if ( queue->head == NULL ) {
        assert( queue->tail == NULL );
        assert( queue->count == 0 );

        queue->head = queue->tail = process;
        queue->tail->next = NULL;
        queue->count++;
    } else {
        queue->tail->next = process;
        queue->tail = process;
        queue->tail->next = NULL;
        queue->count++;
    }

    return;
}

static struct process* dequeue(struct process_queue* queue) {
    assert( queue->head != NULL && queue->tail != NULL );
    assert( queue->count > 0 );

    struct process* head = queue->head;

    if ( queue->head == queue->tail ) {
        assert( queue->count == 1 );
        queue->head = queue->tail = NULL;
    } else {
        queue->head = queue->head->next;
    }

    queue->count--;
    head->next = NULL;

    return head;
}

static int is_empty(struct process_queue* queue) {
    if ( queue->count == 0 ) {
        assert( queue->head == NULL || queue->tail == NULL );
        return 1;
    }
    assert( queue->head != NULL && queue->tail != NULL );
    return 0;
}

/* return elapsed time */
static int schedule(struct process_queue *queue, int q, int now) {
    assert( queue != NULL );
    assert( queue->head != NULL && queue->tail != NULL );
    assert( queue->count > 0 );
    int t;

    struct process* head = dequeue(queue);
    
    if ( head->time > q ) {
        t = q;
        head->time -= q;

        enqueue(queue, head);
    } else {
        t = head->time;

        printf("%s %d\n", head->name, now + t);
        free(head);
    }

    return t;
}

static struct process* read_process(void) {
    char buf[NAME_MAX + 1];
    int  time;
    int  ret;

    ret = fscanf(stdin, "%s %d\n", buf, &time) ;
    if (ret == EOF) {
        return NULL;
    }

    assert( ret == 2 );
    
    struct process* p = (struct process*)malloc(sizeof(struct process));
    assert( p != NULL );
    
    strcpy(p->name, buf);
    p->time = time;
    p->next = NULL;
    
    return p;
}

int main(int argc, char* argv[]) {
    int n, q;
    int ret;
    int i;
    struct process_queue queue = {
        .head = NULL,
        .tail = NULL,
        .count = 0
    };

    ret = fscanf(stdin, "%d %d\n", &n, &q);
    assert( ret == 2);

    for ( i = 0; i < n; i++ ) {
        struct process* p = read_process();
        assert( p != NULL );

        enqueue(&queue, p);
    }

    int t = 0;
    do {
        t += schedule(&queue, q, t);
    } while ( !is_empty(&queue) );

    return 0;
}



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

int N,M;
int X[100010];
int cnt[100010];
int p[100010];
int num[100010];

int main()
{
    cin >> N >> M;
    for(int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        cnt[x]++;

    }
    for(int i = 1; i < 100010; i++)
    {
        p[i % M] += cnt[i] / 2;
        num[i % M] += cnt[i];
    }

    int ans = 0;
    ans += num[0] / 2;
    if(M % 2 == 0)ans += num[M / 2] / 2;
    for(int i = 1; i <= M / 2; i++)
    {
        if(M % 2 == 0 && M / 2 == i)continue;
        int x = num[i], y = num[M - i];
        bool flip = false;
        if(x < y)
        {
            swap(x, y);
            flip = true;
        }
        int d = x - y;
        ans += min(d / 2, p[flip ? M - i : i]);
        ans += y;
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 1408