akhauriyash/Code-Regression huggingface dataset:
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, m;
bool a[1010101], b[1010101];
int aa, bb;
const int mod = 1e9 + 7;
int pa, pb;

int main(){
    INIT;
    cin >> n >> m;
    REP(i, n){
        cin >> aa;
        a[aa] = 1;
    }
    REP(i, m){
        cin >> bb;
        b[bb] = 1;
    }
    LL ans = 1;
    for(int i = n*m;i >= 1;i--){
        if(!a[i] && !b[i]){
            (ans *= pa*pb - (n*m - i)) %= mod;
        }else{
            if(a[i])pa++;
            if(b[i])pb++;
            if(a[i]&&b[i])continue;
            else if(a[i])(ans *= pb) %= mod;
            else if(b[i])(ans *= pa) %= mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
map<int,int> m;
signed main(){
	string s;
	cin>>s;
	f(i,s.size()){
		if(i%2==0) cout<<s[i];
	}
	puts("");
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);
#define int long long
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds_;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds;


int binomialCoeff(int n,int r){
    int res=1;
    if(r>n-r)r=n-r;
    for(int i=0;i<r;i++){
        res*=(n-i);
        res/=(i+1);
    }
    return res;
}



int power(int x,int n,int mod){
//(x^n)%mod
    int result=1;
    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

int inverseMod(int x,int mod){

return power(x,mod-2,mod);
}


int32_t main() {

    simplify

    char c;
    cin>>c;

    if(c<='Z' && c>='A'){
        cout<<"A";
    }
    else{
        cout<<"a";
    }




    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int x, n;
  cin>>x>>n;
  if(n == 0){
    cout << x << endl;
    return 0;
  }
  int p[n];
  REP(i, n) cin>>p[i];
  int exist[110] = {};
  REP(i, n) exist[p[i]] = true;
  //int l, r;
  int tl= x, tr = x;
  while(exist[tl]) tl--;
  while(exist[tr]) tr++;
  if(x - tl <= tr - x){
    cout << tl << endl;
  }else{
    cout << tr << endl;
  }
  return 0;
}


Measured memory_bytes: 3684
readlines.map(&:to_f).each do |input_num|
  sequence = [input_num]
  2.upto(10) do |i|
    if i.even?
      sequence.push(sequence[i - 2] * 2)
    else
      sequence.push(sequence[i - 2] / 3)
    end
  end

  printf "%.8f\n", sequence.inject(&:+)
end

Measured memory_bytes: 8632
#include <iostream>
#include <string>
using namespace std;
class ACoffee {
public:
	void solve(std::istream& in, std::ostream& out) {
	    string S;
	    in >> S;

	    if (S[2] == S[3] && S[4] == S[5]) {
	        out << "Yes" << endl;
	    } else {
	        out << "No" << endl;
	    }
	}
};


int main() {
	ACoffee solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N;cin>>N;
    vi L(N);
    int total=0;
    for(int i=0;i<N;i++){
        cin>>L[i];
        total+=L[i];
    }
    sort(ALL(L));
    cout<<((L[N-1]<total-L[N-1])?"Yes":"No")<<endl;
}

Measured memory_bytes: 3624
x = int(input())

if x < 7:
    print(1)
elif 7 <= x <= 11:
    print(2)
else:
    if x % 11 > 6:
        print((x // 11) * 2 + 2)
    elif x % 11 > 0:
        print((x // 11) * 2 + 1)
    else:
        print((x // 11) * 2)


Measured memory_bytes: 2940
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	string s;
	REP(i,3){
		cin>>s;
		cout<<char(s[0]-'a'+'A');
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;

template <typename UnaryPredicate>
long long binsearch(long long l, long long r, UnaryPredicate p)
{ // [l, r), p is monotone
    assert(l < r);
    --l;
    while (r - l > 1)
    {
        long long m = (l + r) / 2;
        (p(m) ? r : l) = m;
    }
    return r; // = min { x | p(x) }
}

const int inf = 1e9 + 7;
int count_battle(vector<int> const &s, int m, int x)
{
    int n = s.size();
    int l = 1;
    auto getexp = [&](int s_i) {
        return s_i < l + x ? max(1, x - abs(l - s_i)) : 0;
    };
    if (getexp(s[0]) == 0)
        return inf; // impossible
    int cnt = 0;
    int i = 0;
    for (; cnt < m + 3; ++cnt)
    {
        if (getexp(s[n - 1]) != 0)
        {
            ++cnt;
            break;
        }
        while (i + 1 < n and s[i + 1] <= l)
            ++i;
        int j = i;
        while (j + 1 < n and getexp(s[j]) <= getexp(s[j + 1]))
            ++j;
        l += getexp(s[j]);
    }
    return cnt;
}

int solve(vector<int> const &s, int m)
{
    int n = s.size();
    int y = binsearch(2, s[n - 1] + 100, [&](int x) {
                return count_battle(s, m, x) < m;
            }) -
            1;
    int cnt = count_battle(s, m, y);
    if (cnt == inf or cnt < m)
        return -1;
    return y;
}

int main()
{
    while (true)
    {
        int n, m;
        scanf("%d%d", &n, &m);
        if (n == 0 and m == 0)
            break;
        vector<int> s(n);
        repeat(i, n) scanf("%d", &s[i]);
        int result = solve(s, m);
        printf("%d\n", result);
    }
    return 0;
}


Measured memory_bytes: 3100
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val x = sc.nextInt()
    val ca = (0 until n).map {
        sc.next().toInt() to (0 until m).map { sc.next().toInt() }
    }
    println(problem167c(n, m, x, ca))
}

fun problem167c(
    n: Int,
    m: Int,
    x: Int,
    ca: List<Pair<Int, List<Int>>>
): Int {
    val list = mutableListOf<Int>()
    fun select(current: Int, amount: Int, score: IntArray) {
        if (current >= n) {
            if (score.all { it >= x }) {
                list.add(amount)
            }
            return
        }
        select(current + 1, amount, score.copyOf())
        for (i in 0 until m) {
            score[i] += ca[current].second[i]
        }
        select(current + 1, amount + ca[current].first, score.copyOf())
    }
    select(0, 0, IntArray(m))
    return list.min() ?: -1
}

Measured memory_bytes: 41780
# frozen_string_literal: true

line = readlines.map(&:chomp)

demon = line[0].split(' ')
escaper = line[1].split(' ')
t = line[2].to_i

distance = (escaper[0].to_i - demon[0].to_i).abs
speed = (demon[1].to_i - escaper[1].to_i)

if t * speed >= distance
  puts 'YES'
else
  puts 'NO'
end


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

int main() {
	char S[100000];
	scanf("%s",S);
	int len = strlen(S);
	/*odd 1*/
	int cnt_1 = 0;
	for (int i = 0; i < len; i++) {
		if (i%2 == 0 && S[i] == '1') {
			cnt_1++;
		}
		if (i%2 == 1 && S[i] == '0') {
			cnt_1++;
		}
	}
	int cnt_2 = 0;
	for (int i = 0; i < len; i++) {
		if (i%2 == 0 && S[i] == '0') {
			cnt_2++;
		}
		if (i%2 == 1 && S[i] == '1') {
			cnt_2++;
		}
	}
	if (cnt_1 >= cnt_2) printf("%d\n",cnt_2);
	else printf("%d\n",cnt_1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
// head
const int maxn = 2e5 + 5, maxm = 2e3 + 5;
int n, a[maxn], b[maxn];
LL f[maxm<<1][maxm<<1], ans, fac[maxm<<2], inv[maxm<<2];

LL ksm(LL a, LL b) {
	LL res = 1;
	while(b) {
		if(b&1) res = res*a%mod;
		b /= 2;
		a = a*a%mod;
	}
	return res;
}

LL comb(LL a, LL b) {
	return fac[a]*inv[b]%mod*inv[a - b]%mod;
}

int main() {
	cin>>n;
	rep(i, 1, n) {
		cin>>a[i]>>b[i];
		f[maxm - a[i]][maxm - b[i]]++;
	}
	fac[0] = inv[0] = 1;
	rep(i, 1, maxm*4 - 1)
	    fac[i] = fac[i - 1]*i%mod, inv[i] = ksm(fac[i], mod - 2);
	rep(i, 1, maxm*2 - 1)
	    rep(j, 1, maxm*2 - 1)
	        f[i][j] = (f[i][j - 1] + f[i - 1][j] + f[i][j])%mod;
	rep(i, 1, n) 
		ans = (ans + f[maxm + a[i]][maxm + b[i]] - comb(2*a[i] + 2*b[i], 2*a[i]))%mod;
	cout<<(ans + mod)*inv[2]%mod<<endl;
}


Measured memory_bytes: 130888
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;

int main() {

    int n;
    cin >> n;

    string s;
    cin >> s;

    int cnt_w = 0;
    int cnt_e = 0;
    for (int i = 0; i < n; i++) {

        if (s[i] == 'E') {
            cnt_e ++;
        } else {
            cnt_w ++;
        }
    }

    int change_min = n;
    int change_w = 0;
    int change_e = cnt_e;

    for (int i = 0; i < n; i++) {
        if (s[i] == 'E') {
            change_e --;
        }
        if (change_e + change_w <= change_min) {
            change_min = change_e + change_w;
        }
        if (s[i] == 'W') {
            change_w ++;
        }
    }

    cout << change_min << endl;

    return 0;    

}

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

ll mod = 1e9+7;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}
int main() {
    int N;
    cin >> N;
    vector<ll> x(N);
    for (int i = 0; i < N; i++) cin >> x[i];
    vector<ll> p(N+1, 0);
    vector<ll> psum(N+1, 0);
    psum[0] = 1;
    for (int i = 1; i <= N; i++) {
        p[i] = psum[i-1]*modinv(i)%mod;
        psum[i] = (psum[i-1] + p[i] + 1) % mod;
        //cout << p[i] << " " << psum[i] << endl;
    }
    ll ans = 0;
    for (int i = 1; i <= N-1; i++) {
        ans += p[i] * (x[i]-x[i-1]);
        ans %= mod;
    }
    for (int i = 2; i <= N-1; i++) {
        ans = ans * i % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(void)
{
	int a, b, k;
	scanf("%d", &k);

	scanf("%d %d", &a, &b);

	if ((b / k) * k  >= a || k == 1)
	{
		printf("OK");
	}
	else
	{
		printf("NG");
	}

	return 0;
}

Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define maxn 100005
#define MOD 1000000007
#define INF 1000000000000000000
#define lim 20

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll power(ll a, ll b){
    if(b == 0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}

void solve(){
    ll n, k;
    cin >> n >> k;
    ll ans = 0;

    ll dp[k+1];
    memset(dp, 0, sizeof(dp));

    dp[k] = 1;
    ans = k;
    for(ll i = k-1; i > 0; i--){
        ll x = k/i;
        dp[i] = power(x, n);
        for(ll j = i+i; j <= k; j+=i){
            dp[i] = (dp[i] + MOD - dp[j])%MOD;
        }
        ans += (dp[i]*i)%MOD;
        ans %= MOD;
    }
    cout << ans;

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


Measured memory_bytes: 4368
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#include <queue>
#include <map>
 
#define fir first
#define sec second
#define sz(s) (s).size();
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i,j,k) for(int (i)=(j);(i)<=(k);(i)++)
#define repdown(i, j, k) for(int (i)=(j);(i)>=(k);(i)--)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
using ll = long long;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;
 
const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = 10241024;
long double INFD = 100100100;
 
//_____________________________________Templates_________________________________________//
 
template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
 
//mainly use for dynamic prog
template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}
 
inline void IN(void){
  return;
}
 
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}
 
inline void OUT(void){
  cout << "\n";
  return;
}
 
template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}
 
//_____________________array calc____________________________________//
/*
vvi mul(vvi &A, vvi &B){
  vvi C(A.size(), vi(B.size()))
  rep(i,A.size()){
    rep(j,B.size()){
      rep(k,B[0].size()){
        C[i][j] = (C[i][j] A[i][k] + B[k][j]) % Mod;
      }
    }
  }
 
  return C;
}
 
vvi pow(vvi A, ll n){
  vvi B(A.size(), vi(A.size()));
  rep(i=0;i<A.size();i++){
    B[i][i] = 1;
  }
 
  while (n >0){
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n = n >> 1;
  }
  return B;
}
*/
//_____________________Bynary Indexed Tree __________________________//
/*
const max_st = (1 << 15) - 1;
int bit[max_st];
int sum (int i){
  int s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}
 
void add(int i, int x){
  while(i <= n){
    bit[i] += x;
    i += i & -i;
  }
}
*/
//_____________________　following sorce code_________________________//
vll dp(500000);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  ll N, W;IN(N, W);
  rep(i,0,N-1){
    int a,b;IN(a,b);
    repdown(j,W,a){
      chmax(dp[j], dp[j-a]+b);
    }
  }
  OUT(dp[W]);
  return 0;
}

Measured memory_bytes: 4224
n,m,s = map(int,input().split())
road = [[] for _ in range(n)]
#print(road)
for _ in range(m):
  u,v,a,b = map(int,input().split())
  u -= 1
  v -= 1
  road[u].append([v,a,b])
  road[v].append([u,a,b])
#print(road)
coin = []
for _ in range(n):
  c,d = map(int,input().split())
  coin.append([c,d])
if s >= 2500:
  s = 2499
inf = 10**18
#print('#')
arr = [[inf for _ in range(2500)] for _ in range(n)]
c,d = coin[0]
#print(c,d)
#print(len(arr[0]))
for i in range(2500):
  if i <= s:
    arr[0][i] = 0
  elif i - c < 0:
    arr[0][i] = arr[0][0]+d
  else:
    arr[0][i] = arr[0][i-c]+d
now = {0}
#print(road)
for _ in range(50):
  #print(now)
  last = now
  now = set()
  for x in last:
    for y in road[x]:
      #print('#',x,y)
      v,a,b = y
      now.add(v)
      c,d = coin[v]
      for i in range(2500):
        if i + a < 2500:
          arr[v][i] = min(arr[v][i],arr[x][i+a]+b)
      for i in range(2500):
        if i - c < 0:
          arr[v][i] = min(arr[v][i],arr[v][0]+d)
        else:
          arr[v][i] = min(arr[v][i],arr[v][i-c]+d)
for ii in range(1,n):
  print(arr[ii][0])
#print(arr[0])

Measured memory_bytes: 70132
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define uset unordered_set
#define ll long long
#define lll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
#define Lets_be_precise cout<<fixed<<setprecision(10)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
	cin>>v[i];
}
//#define cerr if(false)cerr//uncomment to remove cerr from program...
void solveforthiscase(const int & test)
{//deb(test);
cin>>n>>k;
cout<<min(n%k,(k-n%k));









return ;
}

int main()
{
	ios_base::sync_with_stdio(false);
	Lets_be_precise;
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 256
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
t = [int(input()) for _ in range(n)]

print(lcm(*t))

Measured memory_bytes: 9480
#include<stdio.h>

int main(void)
{
  char s[4+1];
  scanf("%s", s);
  int i;
  int ans=0;
  for(i=0; i<4; i++){
    if(s[i]=='+'){ans+=1;}
    else{ans-=1;}
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
def bb
    n,m = gets.chomp.split(/\s/).map{|x| x.to_i}

    aa = gets.chomp.split(/\s/).map{|x| x.to_i}[1..-1]
    for i in 2..n
        aa &= gets.chomp.split(/\s/).map{|x| x.to_i}[1..-1] # 先頭は捨てる
    end

    puts aa.length
end

bb


Measured memory_bytes: 1916
from enum import Enum


class Mst(object):
    """ minimum spanning tree """
    INFINITY = 999999999
    class Status(Enum):
        """ ?????????????¨??????¶??? """
        white = 1  # ????¨????
        gray = 2  # ?¨???????
        black = 3  #?¨???????

    def __init__(self, data):
        num_of_nodes = len(data)+1
        self.color = [Mst.Status.white] * (num_of_nodes + 1)  # ????????????????¨??????¶???
        self.M = self._make_matrix(data)  # data????????????????????£??\??????
        self.d = [Mst.INFINITY] * num_of_nodes
        self.p = [-1] * num_of_nodes

    def _make_matrix(self, data):
        graph_table = []
        for d in data:
            t = [self.inf_or_num(x) for x in d]
            graph_table.append(t)
        return graph_table

    def inf_or_num(self, n):
        if n == -1:
            return Mst.INFINITY
        else:
            return n

    def prim(self):
        self.d[0] = 0
        self.p[0] = -1

        while True:
            mincost = Mst.INFINITY
            for i in range(len(self.d)-1):
                if self.color[i] != Mst.Status.black and self.d[i] < mincost:
                    mincost = self.d[i]
                    u = i

            if mincost == Mst.INFINITY:
                break

            self.color[u] = Mst.Status.black
            for v in range(len(self.d)-1):
                if self.color[v] != Mst.Status.black and self.M[u][v] != Mst.INFINITY:
                    if self.M[u][v] < self.d[v]:
                        self.d[v] = self.M[u][v]
                        self.p[v] = u
                        self.color[v] = Mst.Status.gray

        results = []
        for i in range(len(self.p)):
            if self.p[i] != -1:
                results.append(self.M[i][self.p[i]])
        return sum(results)



if __name__ == '__main__':
    # ??????????????\???
    n = int(input())
    data = []
    for _ in range(n):
        data.append(list(map(int, input().strip().split(' '))))

    mst = Mst(data)
    print(mst.prim())

Measured memory_bytes: 8288
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 3e6 + 17;
ll a[N], b[N], cnt = 1, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[N];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    for(ll i = 0; i < s.size(); i ++)
    {
        if(s[i] == '9')
        {
            s[i] = '1';
        }
        else
        if(s[i] == '1')
        {
            s[i] = '9';
        }
    }
    cout << s;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n){
    cin >> v[i];
  }
  
  int a=1,count=0;
  rep(i,n){
    a=v[a-1];
    count++;
    if(a==2){
      break;
    }
  }
  if(a==2){
    cout << count << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		char[] ch = scanner.next().toCharArray();
		int[] c = new int[n];  
		int[] d = new int[n];
		for(int i = 0; i < n; i++){
			if(i == 0) {
				c[0] = 0;
				d[0] = 0;		
			}
			if(i == n-1) {
				break;
			}else {
				if(ch[i] == 'W') {
					c[i+1] = c[i]+1;
				}else {
					c[i+1] = c[i];
				}
				if(ch[n-1-i] == 'E') {
					d[i+1] = d[i]+1; 
				}else{
					d[i+1] = d[i];
				}
			}
		}
		int ans = n;
		for(int r = 0; r < n; r++) {
			int tmp = c[r]+ d[n-1-r];
			if(tmp < ans) ans = tmp;
		}
		System.out.println(ans);
	}

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int n,a,b;
    cin >>n >> a >> b;
    cout << min(a*n,b) << endl;
    return 0;
}

Measured memory_bytes: 256
n=gets.to_i
a=[]
n.times do
  a.push(gets.split.map(&:to_i))
end
b=Array.new(n).map{[nil]*n}
r=[]
0.upto(n-3) do |i|
  (i+1).upto(n-2) do |j|
    g = 1.0*(a[i][0]-a[j][0])/(a[i][1]-a[j][1])
    g=10**9 if a[i][1]-a[j][1] == 0
    t=0
    (j+1).upto(n-1) do |k|
      c=false
      2.times do |l|
        if a[i][l]==a[j][l] && a[i][l]==a[k][l]
          c=true
        end
      end
      gg = 1.0*(a[i][0]-a[k][0])/(a[i][1]-a[k][1])
      gg = 10**9 if a[i][1]-a[k][1] == 0
      if g == gg
        c=true
      end
      if c
        cc=true
        if !b[k][i]
          b[k][i]=true
        else
          cc=false
        end
        if !b[k][j]
          b[k][j]=true
        else
          cc=false
        end
        if cc
          t+=1
        end
      end
    end
    r.push(t+2) if t!=0
  end
end
tt=0
if n>=3
  tt+=(g=n*(n-1)*(n-2)/6)
  (n-3).times do |i|
    tt+=(g=g*(n-3-i)/(4+i))
  end
  r.each do |e|
    tt-=(g=e*(e-1)*(e-2)/6)
    (e-3).times do |i|
      tt-=(g=g*(e-3-i)/(4+i))
    end
  end
end
p tt%998244353
  
  

Measured memory_bytes: 2300
def dfs(arr, accm=0):
	if len(arr) == 1:
		return arr[0]

	s1 = arr[0] * (2 ** (len(arr) - 2)) + dfs(arr[1:])

	_arr = list(arr[1:])
	_arr[0] += arr[0] * 10
	s2 = dfs(_arr)

	return s1 + s2

s = input()
arr = [int(a) for a in s]

print(dfs(arr))



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

int main(){
	bool p[1000000];
	int num[1000000];
	int c,n;
	
	for(int i=0;i<1000000;i+=2)p[i] = false ;

	for(int i=1;i<1000000;i+=2)p[i] = true ;
	
	p[1] = false;
	p[2] = true;
	
	c=3;
	while(c < 1000){
		for(int i=3*c; i < 1000000; i+=2*c)p[i] = false;
		do{c+=2;}while(!p[c]);
	}
	
	c=0;
	for(int i = 0 ; i < 1000000 ; i++){
		if(p[i])c++;
		num[i] = c;
	}
	
	while(cin>>n)cout<<num[n]<<endl;
}

Measured memory_bytes: 6040
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const int maxn=2e5+10;
int n,m,k,ans,a[maxn],b[maxn],c[maxn];
void add(int x){
    while(x<=m) ++c[x],x+=lowbit(x);
}
int pre(int x){
    int ret=0;
    while(x)
        ret+=c[x],x-=lowbit(x);
    return ret;
}
main()
{
    cin>>n>>k;int i;
    for(i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        a[i]-=k;a[i]+=a[i-1];
        b[i]=a[i];
    }
    sort(b+1,b+1+n);
    m=unique(b+1,b+1+n)-b-1;
    for(i=1;i<=n;i++){
        ans+=a[i]>=0;
        a[i]=lower_bound(b+1,b+1+m,a[i])-b;
    }
    for(i=1;i<=n;i++){
        ans+=pre(a[i]);
        add(a[i]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4992
n = int(input())
s = str(input())

out = []
for i in range(len(s)):
    if ord(s[i])+n <= 90:
        out.insert(i, chr(ord(s[i])+n))
    else:
        out.insert(i, chr(ord(s[i])-26+n))

for i in range(len(s)):
    print(out[i], end = '')

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

typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll n, k;
	cin >> n >> k;
	k--;
	vector<ll> arr(n);
	for(ll& x : arr) cin >> x;
	sort(arr.begin(), arr.end());
	
	ll lo = -2e18, hi = 2e18;
	
	while(lo < hi) {
		ll mid = lo + (hi-lo)/2;
		
		ll cnt = 0; // number of products >= mid
		
		for(int i = 0; i < n; i++) {
			if(arr[i] > 0) {
				cnt += lower_bound(arr.begin(), arr.end(), arr[i], [&](ll x, ll y) { return x*y <= mid; }) - arr.begin();
			} else if(arr[i] < 0) {
				cnt += arr.end() - lower_bound(arr.begin(), arr.end(), arr[i], [&](ll x, ll y) { return x*y > mid; });
			} else {
				cnt += mid >= 0 ? n : 0;
			}
			if(arr[i]*arr[i] <= mid) cnt--;
		}
		
		cnt /= 2;
		if(cnt <= k) {
			lo = mid + 1;
		} else {
			hi = mid;
		}
	}
	
	cout << hi << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}
int main()
 {
//     #ifndef ONLINE_JUDGE
//     freopen("input.txt","r",stdin);
//     freopen("output.txt","w",stdout);
//     #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a;
    cin>>a;
    string s;
    cin>>s;
    if(a<3200)
    {
        cout<<"red";
    }
    else
    {
        cout<<s;
    }
    // #ifndef ONLINE_JUDGE
    //     cout<<"\nTime Elapsed : "<< 1.0*clock() / CLOCKS_PER_SEC << " s\n";
    // #endif
    
    return 0;
}

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

pair<ll, ll> store[1007];

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

    for (ll i = 1; i <= n; i++) cin >> store[i].first >> store[i].second;

    ll x = store[1].first, y = store[1].second;
    for (ll i = 2; i <= n; i++) {
        ll curx = store[i].first;
        ll cury = store[i].second;

        if (curx >= x && cury >= y) {x = curx; y = cury; continue;}

//        else if (x > y) {
//            ll v1 = x / curx;
//            if (x % curx) v1++;
//
//            x = v1 * curx;
//            y = v1 * cury;
//        }
//
//        else if (y > x) {
//            ll v1 = y / cury;
//            if (y % cury) v1++;
//
//            x = v1 * curx;
//            y = v1 * cury;
//        }


        ll v1 = x / curx;
        if (x % curx) v1++;

        ll v2 = y / cury;
        if (y % cury) v2++;

        x = curx * max(v1, v2);
        y = cury * max(v1, v2);

    }

    cout << x + y << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(_,k){
    priority_queue<int,vector<int>,greater<int>> s,t;
    rep(i,n) s.emplace(max(0,i-a[i])), t.emplace(min(n-1,i+a[i]));
    vector<int> v(n);
    int m = n;
    rep(i,n){
      while(!s.empty()&&s.top()<=i) s.pop();
      v[i] = (n-s.size())-(n-t.size()) ;
      m = min(m,v[i]);
      while(!t.empty()&&t.top()<=i) t.pop();
    }
    swap(a,v);
    if(m==n) break;
  }
  rep(i,n) cout << a[i] << " "; cout << endl;
}


Measured memory_bytes: 7136
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (k, s) = get!(usize, usize);
    let mut r: usize = 0;
    for i in 0..k+1 {
        for j in 0..k+1 {
            if i + j > s { continue; }
            if s - (i + j) <= k { r += 1; }
        }
    }
    println!("{}", r);
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const double INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

ll const MAX_N = 1e5 + 10;
bool done[MAX_N];

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


int main() {
	ll i, j;
	ll N;
	cin >> N;
	vll A(N);
	for (auto& e : A)cin >> e;
	ll m1, m2;
	m1 = max(A[0], A[1]);
	m2 = min(A[0], A[1]);

	for (i = 2; i < N;i++) {
		if (A[i] > m1) {
			ll tmp = m1;
			m1 = A[i];
			m2 = tmp;
		}
		else if (A[i] > m2) {
			m2 = A[i];
		}
	}
	for (i = 0; i < N; i++) {
		if (A[i] == m1) {
			cout << m2 << endl;
		}
		else {
			cout << m1 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const int mod = 1e9+7;

signed main(){
    IOS;
    int n,k,l=0,r=0; cin >> n >> k;
    rep(i,0,k){
        l+=i;
        r+=(n-i);
    }
    int ans = r-l+1;
    for(int i = k;i<=n;i++){
        l+=i;
        r+=(n-i);
        ans = (ans + r-l+1)%mod;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll  = long long;
template <typename T> T In() {
    T t;
    cin >> t;
    return t;
}
template <typename T> vector<T> ReadVec1(int N) {
    vector<T> vec(N);
    for(int i = 0; i < N; i++)
        vec[i] = In<T>();
    return move(vec);
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(j, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}

int main() {
    constexpr int M = 1001;
    int N = In<int>();
    auto list = vector<ll>(M, 0);
    auto sums = vector<ll>(M);
    for(int i = 0; i < N; i++) {
        list[In<int>()]++;
    }
    sums[0] = list[0];
    for(int i = 1; i < M; i++) {
        sums[i] = sums[i - 1] + list[i];
    }
    ll ans = 0;

    // a != b != c
    for(int a = 1; a < M; a++) {
        if(list[a] == 0) {
            continue;
        }
        for(int b = a+1; b < M; b++) {
            ans += (sums[min(a + b - 1, M - 1)] - sums[b])*list[a]*list[b];
         }
    }

    // a=b !=c
    for(int ab = 1; ab < M; ab++) {
        for(int c = ab + 1; c < min(2 * ab , M ); c++){
            ans += list[c] * list[ab] * (list[ab] - 1) / 2;
        }
    }
    //a != b = c
    for(int a = 1; a < M; a++) {
        for(int bc = a + 1; bc < M; bc++) {
            ans += list[a] * list[bc]*(list[bc]-1)/2;
        }
    }

    // a=b=c
    for(int abc = 1; abc < M; abc++) {
        ans += list[abc] * (list[abc] - 1) * (list[abc] - 2) / 6;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    long N = sc.nextLong();
    long M = sc.nextLong();
    long ans;
    if(N == 1){
      if(M == 1) ans = 1;
      else ans = M - 2;
    }
    else if(N == 2) ans = 0;
    else{
      if(M == 1) ans = N - 2;
      else ans = N * M - 2 * (M+N) + 4;
    }
    out.println(ans);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 21844
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sn = new Scanner(System.in);
		int N = sn.nextInt();
		int K = sn.nextInt();
		char[] D = new char[10];
		for(int i = 0; i < K; ++i) D[i] = (char)('0' + sn.nextInt());
		
		int ans = N;
		while(ans < 10000000){
			String pay = String.valueOf(ans);
			boolean flag = true;
			for(int i = 0; i < pay.length(); ++i){
				for(int j = 0; j < K; ++j){
					if(pay.charAt(i) == D[j]){
						flag = false;
						break;
					}
				}
				if(!flag) break;
			}
			if(flag) break;
			++ans;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 15240
#include <iostream>
#define N_MAX 100
#include <string>
using namespace std;

int N,A,B,i,j,k;
string S;
int a[N_MAX];
int num[N_MAX] = {0};
int ans=0;
int r,g,b;

int main(){
  cin >> S;
  if (S[3] == '7'){
    S[3] = '8';
  }
  cout << S << endl;
}

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

using namespace std;

typedef long long int ll;

const int N = (int) 1e5 + 10;
const ll oo = 1e18;

int n, k;
ll a[N];
ll memo[N];

ll dp(int at) {
    if(at == n) return 0;
    if(at > n) return oo;
    if(memo[at] != -1) return memo[at];
    ll ans = oo;
    for(int x = at + 1; x <= at + k && x <= n; ++x) {
        int cost = abs(a[at] - a[x]);
        ans = min(ans, cost + dp(x));
    }
    return memo[at] = ans;
}

void solve() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    memset(memo, -1, sizeof(memo));
    cout << dp(1) << endl;
}

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

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n][3], dp[n][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++)
            cin>>arr[i][j];
    }
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    for(int i=1;i<n;i++){
        dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define inf 1e17
#define MAX_SIZE 1000005 

void pr(int arr[], int size) 
{ for (ll i=0; i < size; i++) {printf("%d ", arr[i]); }cout << endl;}

int main () {
  ll t = 1;
//   cin >> t;
  while(t--){
    ll n , k;
    cin >> n >> k;
    ll a[n];
    ll freq[n+1] = {};
    for(ll i = 0;i < n; i++){
        cin >> a[i];
        freq[a[i]]++;
    }
    vector<ll> u ;
    for(ll i = 0;i < n+1; i++){
         if(freq[i]){
             u.push_back(freq[i]);
         }
    }
    
    ll cnt =  u.size() ;
    if(cnt <= k){
        cout << 0 << endl;
    }
    else{
        sort(u.begin() , u.end());
        ll sum = 0;
        for(ll i = 0;i < cnt - k;i++){
            sum += u[i];
            // cout << u[i] << endl;
        }
        cout << sum << endl;
    }
    }
    return 0;
}


Measured memory_bytes: 5492
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    string s, t;
    cin >> s>>t;

    bool f = false ;
    for (int i = 0; i < s.length(); ++i) {
        string ss = s.substr(i) + s.substr(0,i);
        if(ss == t) {
            f = true; break;
        }
    }
    if(f) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char *argv[])
{
    char next[300], prev[300], sub[300];
    int m, h;

    for (;;) {
        scanf("%s", prev);
        if (prev[0] == '-')
            break;
        scanf("%d", &m);
        for (int i = 0; i < m; i++) {
            scanf("%d", &h);
            strncpy(sub, prev, h);
            sub[h] = '\0';
            strcpy(next, &prev[h]);
            strcat(next, sub);
            strcpy(prev, next);
        }
        printf("%s\n", next);
    }

    return 0;
}



Measured memory_bytes: 2096
#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> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	string s;
	cin >> s;
	rep(i, 3) {
		if (s[i] == '1') {
			s[i] = '9';
			continue;
		}
		if (s[i] == '9') {
			s[i] = '1';
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <queue>
#include <cstring>
#include <set>
#include <list>
#include <map>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vvi> vvvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;

#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define forn(i, a, b) for(int i = a; i < b; i++)

#define pb push_back
#define mp make_pair

int main()
{

    ll n,s;
    cin>>n>>s;
    for (ll b = 2; b<=1000000; b++) {
        ll N = n;
        ll sum = 0;
        while(N>0) {
            sum+=N%b;
            N/=b;
        }
        if(sum == s) {
            cout<<b;
            return 0;
        }
    }
    for(ll nb = 100000; nb > 0; nb--) {
        ll ost = s - nb;
        if(ost <0) continue;
        if(ost>n) continue;
        ll A = n-ost;
        if(A%nb != 0) continue;
        if(A/nb <= ost) continue;
        cout<<A/nb;
        return 0;
    }
    if(s==n) cout<<s+1;
    else cout<<-1;
    
    
    
}



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

#define ll long long

int main(){
  ll N; cin>>N;
  vector<ll> Q(N);
  for(int i=0;i<N;i++){
    cin>>Q[i];
    if(i)
      Q[i]+=Q[i-1];
  }
  Q.push_back(0);
  sort(Q.begin(),Q.end());
  ll cnt=0,cp=0;
  for(int i=0;i<N+1;i++){
    cp++;
    if(i!=N&&Q[i]==Q[i+1]){}
    else{
      cnt+=cp*(cp-1)/2;
      cp=0;
    }
  }
  cout<<cnt;
}

Measured memory_bytes: 4480