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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N; cin >> N;
    string S; cin >> S;
    int n[N][3]; REP(i,N)REP(j,3) n[i][j] = 0;
    REP(i,N){
        char c = S[i];
        if(c == 'R') n[i][0] = 1;
        else if(c == 'G') n[i][1] = 1;
        else n[i][2] = 1;
    }
    RREP(i,N-1){
        REP(j,3) n[i][j] += n[i+1][j];
    }

    ll ans = 0;
    REP(i,N-2)FOR(j,i+1,N-1){
        while(j < N-1 && S[i] == S[j]) j++;
        if(j == N-1) break;
        if(S[i]=='R' && S[j]=='G'){
            ans += n[j+1][2];
            if(j+(j-i)<N && S[j+j-i]=='B') ans--;
        }
        else if(S[i]=='R' && S[j]=='B'){
            ans += n[j+1][1];
            if(j+(j-i)<N && S[j+j-i]=='G') ans--;
        }
        else if(S[i]=='G' && S[j]=='R'){
            ans += n[j+1][2];
            if(j+(j-i)<N && S[j+j-i]=='B') ans--;
        }
        else if(S[i]=='G' && S[j]=='B'){
            ans += n[j+1][0];
            if(j+(j-i)<N && S[j+j-i]=='R') ans--;
        }
        else if(S[i]=='B' && S[j]=='R'){
            ans += n[j+1][1];
            if(j+(j-i)<N && S[j+j-i]=='G') ans--;
        }
        else if(S[i]=='B' && S[j]=='G'){
            ans += n[j+1][0];
            if(j+(j-i)<N && S[j+j-i]=='R') ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main()
{
    int a[3][3][2] = {};
    int n, b;
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> a[i][j][0];
        }
    }
    cin >> n;
    for(int k = 0; k < n; k++) {
        cin >> b;
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                if(a[i][j][0] == b) a[i][j][1] = 1;
            }
        }
    }
    int check = 0, ans = 0;
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            check += a[i][j][1];
        }
        if(check == 3) ans = 1;
        check = 0;
    }
    for(int j = 0; j < 3; j++) {
        for(int i = 0; i < 3; i++) {
            check += a[i][j][1];
        }
        if(check == 3) ans = 1;
        check = 0;
    }
    for(int i = 0; i < 3; i++) {
        check += a[i][i][1];
    }
    if(check == 3) ans = 1;
    check = 0;
    for(int i = 0; i < 3; i++) {
        check += a[i][2-i][1];
    }
    if(check == 3) ans = 1;
    check = 0;
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
const int INF=1e9+7;
typedef long long ll;
int a[30][30];
int main()
{
    int n,d,sum=0;
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<d;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            ll p=0;
            for(int k=0;k<d;k++)
            {
                p+=fabs((a[i][k]-a[j][k])*(a[i][k]-a[j][k]));
            }
            if((ll)sqrt(p)*(ll)sqrt(p)==p)
                sum++;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
def isPrime(n):
	i = 2
	while i*i <= n:
		if n % i == 0:
			return False
		i += 1
	return True

N = 1000
Prime = []

for i in range(2,N):
	if isPrime(i):
		Prime.append(i)
		
dic = {}
for i in Prime:
	dic[i] = 0

p = int(input())
for k in range(2, p+1):
	for i in Prime:
		while k % i == 0:
			k /= i
			dic[i] += 1

ans = 1
for i in Prime:
	ans *= (1+dic[i])

print(ans % 1000000007)

Measured memory_bytes: 3064
/*
 * atcoder/dp_3rd/l.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const int MAX = 3100;
ll N;
vector<ll> A;

/*
 * dp[l][r] := [l:r) まで取った時のX-Y
 * dp[l][r] = A[l] if r-l==1 and First
 * dp[l][r] = -A[l] if r-l==1 and not First
 * dp[l][r] = max(dp[l+1][r] + A[l], dp[l][r-1] + A[r-1]) if First
 * dp[l][r] = min(dp[l+1][r] - A[l], dp[l][r-1] - A[r-1]) if not First
 * First = (N-(r-l))%2==0
 */
ll dp[MAX][MAX] = {0};

void input() {
  cin >> N;
  ll a;
  loop(n,0,N) {
    cin >> a;
    A.push_back(a);
  }
}

ll minmax(ll a, ll b, int sign) {
  if (sign < 0) return min(a, b);
  else return max(a, b);
}

void solve() {
  for (int len=1; len<=N; len++) {
    int sign = ((N-len)%2==0) ? 1 : -1;
    for (int l=0; l+len<=N; l++) {
      if (len==1) { dp[l][l+len] = sign * A[l]; continue; }
      int r = l+len;
      dp[l][r] = minmax(dp[l+1][r] + sign * A[l], dp[l][r-1] + sign * A[r-1], sign);
    }
  }
  cout << dp[0][N] << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 73984
#include <iostream>
#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>;

const int di[] = {-1,0,1,0};
const int dj[] = {0,1,0,-1};

int main() {
    int h,w;
    cin >> h >> w;
    int ch,cw;
    cin >> ch >> cw;
    int dh,dw;
    cin >> dh >> dw;
    ch--; cw--; dh--; dw--;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    
    const int INF = 1e9;
    vector<vector<int>> dist(h, vector<int>(w,INF));
    dist[ch][cw] = 0;
    deque<P> q;
    q.emplace_back(ch,cw);

    while(!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        int d = dist[i][j];
        q.pop_front();
        
        rep(v,4) {
            int ni = i+di[v], nj = j+dj[v];
            if(ni < 0 || ni>=h || nj<0 || nj>=w) continue;
            if(s[ni][nj] == '#') continue;
            if(dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(ni,nj);
        }
        for (int ei = -2; ei <= 2; ei++) {
            for(int ej = -2; ej <= 2; ej++) {
                int ni = i+ei, nj = j+ej;
                if(ni < 0 || ni>=h || nj<0 || nj>=w) continue;
                if(s[ni][nj] == '#') continue;
                if(dist[ni][nj] <= d+1) continue;
                dist[ni][nj] = d+1;
                q.emplace_back(ni,nj);
            }
        }
    }
    int ans = dist[dh][dw];
    if(ans == INF) ans = -1;
    cout << ans << endl;
}

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

vector<int> suffix_array(string S) {
	vector<int> arr(S.size() + 1, 0);
	for (int i = 0; i < S.size(); i++) arr[i] = (S[i] - 'a') + 1;

	for (int i = 0; i < 18; i++) {
		vector<tuple<int, int, int>> tup;
		for (int j = 0; j < S.size(); j++) {
			tup.push_back(make_tuple(arr[j], arr[min((int)S.size(), j + (1 << i))], j));
		}
		sort(tup.begin(), tup.end());
		int id = 0;
		for (int j = 0; j < tup.size(); j++) {
			arr[get<2>(tup[j])] = id + 1;
			if (j + 1 < tup.size() && make_pair(get<0>(tup[j]), get<1>(tup[j])) != make_pair(get<0>(tup[j + 1]), get<1>(tup[j + 1]))) id = j + 1;
		}
	}
	vector<int> ret; for (int i = 0; i < S.size(); i++) ret.push_back(arr[i]);
	return ret;
}

int N, K; string S;

int main() {
	cin >> N >> K >> S; K = min(K, 15);

	for (int i = 0; i < K; i++) {
		string V = S; reverse(V.begin(), V.end());
		string W = S + V;
		vector<int> J = suffix_array(W);

		int minx = (1 << 30), ind = 0;
		for (int j = 0; j <= N; j++) {
			if (minx > J[j]) { minx = J[j]; ind = j; }
		}
		if (i != K - 1) { ind = N - ind; }
		S = W.substr(ind, N);
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 692
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const int maxN = 310, modP = 1e9 + 7;

#define foru(i, l, r) for (int i = l; i <= r; ++i)
#define ford(i, r, l) for (int i = r; i >= l; --i)
#define repu(i, r) for (int i = 0; i < r; ++i)
#define ll long long
#define F first
#define S second
#define mp make_pair
#define pint pair < ll, int >

int f[maxN][maxN][maxN], res, m, n, max_pos[maxN][4], min_pos[maxN][4];
vector < int > a;

bool check(int r, int g, int b) {
    a.clear();
    a.push_back(r);
    a.push_back(g);
    a.push_back(b);
    sort(a.begin(), a.end());
    if (min_pos[a[2]][1] <= a[1]) return false;
    if (min_pos[a[2]][2] <= a[0] || max_pos[a[2]][2] > a[1]) return false;
    if (max_pos[a[2]][3] > a[0]) return false;
    return true;
}

int sum(int x, int y) {
    ll tmp = x;
    tmp += y;
    if (tmp > modP) tmp -= modP;
    return tmp;
}

int dp(int i, int r, int g, int b) {
    if (f[r][g][b] != -1) return f[r][g][b];
    if (i > n) return 1;
    int tmp = 0;
    if (check(i, g, b)) tmp = sum(tmp, dp(i + 1, i, g, b));
    if (check(r, i, b)) tmp = sum(tmp, dp(i + 1, r, i, b));
    if (check(r, g, i)) tmp = sum(tmp, dp(i + 1, r, g, i));
    f[r][g][b] = f[r][b][g] = f[b][r][g] = f[b][g][r] = f[g][r][b] = f[g][b][r] = tmp;
    return tmp;
}

int main() {
    cin >> n >> m;
    foru(i, 1, n)
        foru(j, 1, 3) {
            max_pos[i][j] = 0;
            min_pos[i][j] = n + 1;
        }
    foru(i, 1, m) {
        int l, r, x;
        scanf("%d %d %d", &l, &r, &x);
        max_pos[r][x] = max(max_pos[r][x], l);
        min_pos[r][x] = min(min_pos[r][x], l);
    }
    memset(f, 255, sizeof(f));
    res = dp(1, 0, 0, 0);
    cout << res << endl;
}


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

int main() {
    string in, in2;
    cin >> in >> in2;
    int c = 0;
    for (int i = 0; i < 3; ++i) {
        if (in[i] == in2[i]) {
            ++c;
        }
    }
    cout << c << '\n';
    return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

const ll INF = (ll)(1e18) + 1;

bool isOk(const ll x, const ll K, const vector<ll>& a)
{
    ll total = 0;
    REP(i, a.size())
    {
        ll l = -1, r = a.size();
        if (a[i] > 0)
        {
            while(l + 1 < r)
            {
                ll pos = (l + r) / 2;
                if (a[i] * a[pos] < x) l = pos;
                else r = pos;
            }
            total += r;
        }
        else
        {
            while(l + 1 < r)
            {
                ll pos = (l + r) / 2;
                if (a[i] * a[pos] < x) r = pos;
                else l = pos;
            }
            total += a.size() - r;
        }
        if (a[i] * a[i] < x) total--;
    }
    total /= 2;
    return total < K;
}

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    sort(ALL(A));

    ll l = -INF, r = INF;
    while(l + 1 < r)
    {
        ll x = (l + r) / 2;
        if (isOk(x, K, A)) l = x;
        else r = x;
    }

    cout << l << endl;
}


Measured memory_bytes: 1792
function main(input){
    inputI = input.split('\n');
    inputST = inputI[0].split(' ');
    inputAB = inputI[1].split(' ');
    inputU = inputI[2].split(' ');
    inputS = inputST[0];
    inputT = inputST[1];
    inputA = parseInt(inputAB[0]);
    inputB = parseInt(inputAB[1]);

    if(inputU==inputS){
        inputA=inputA-1;
    }
    if(inputU==inputT){
        inputB=inputB-1;
    }

    console.log(inputA+' '+inputB);

}

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

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

using namespace std;

const int INF = 1 << 30;

string S;
vector< int > app[26];
int dp[300000], pre[300000], st[300000];

int rec(int idx)
{
  if(idx == S.size() + 1) return (0);
  if(~dp[idx]) return (dp[idx]);
  int ret = INF, nt = -1;
  for(int j = 0; j < 26; j++) {
    auto pos = rec(*upper_bound(begin(app[j]), end(app[j]), idx)) + 1;
    if(pos < ret) {
      ret = pos;
      nt = j;

      dp[idx] = ret;
      pre[idx] = nt;
      st[idx] = *upper_bound(begin(app[j]), end(app[j]), idx);
    }
  }
  return (ret);
}

void rec2(int idx)
{
  if(pre[idx] == -1) return;
  cout << (char) (pre[idx] + 'a');
  rec2(st[idx]);
}

int main()
{
  cin >> S;
  for(int i = 0; i < S.size(); i++) {
    app[S[i] - 'a'].push_back(i + 1);
  }
  for(int i = 0; i < 26; i++) {
    app[i].push_back((int) S.size() + 1);
  }

  memset(dp, -1, sizeof(dp));
  memset(pre, -1, sizeof(pre));
  cerr << rec(0) << endl;
  rec2(0);
  cout << endl;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
static const int MOD = 1e9 + 7;

const int MAX = 1000005;

struct Sieve {
    int n;
    vector<int> f, primes;

    Sieve(int n = 1) : n(n), f(n + 1) {
        // isPrimeで素数判定するとき
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; ++i) {
            // 素数でない場合continue
            // (印がついている場合)
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }

    bool isPrime(int x) { return f[x] == x; }

    // xを素因数分解する
    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }

    vector<pair<int, int>> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.empty()) return {};
        vector<pair<int, int>> res(1, make_pair(fl[0], 0));
        for (int p: fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};


const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

// 最小公倍数が膨大なサイズになるのでサイズになるので、
// 最小公倍数の値を素因数分解で持つ
int main() {
    Sieve sieve(1e6);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    map<int, int> mp;
    for (int i = 0; i < n; ++i) {
        auto f = sieve.factor(a[i]);
        // 素因数ごとに最大出現回数を記録
        for (auto p:f) {
            mp[p.first] = max(mp[p.first], p.second);
        }
    }

    mint lcm = 1;
    for (auto p : mp) {
        for (int i = 0; i < p.second; ++i) {
            lcm *= p.first;
        }
    }

    mint ans;
    for (int i = 0; i < n; ++i) {
        mint b = lcm / a[i];
        ans += b;
    }
    cout << ans.x;
    return 0;
}


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

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define lcm(a,b)     (a*b)/__gcd(a,b)
#define bs(v,x)      binary_search(v.begin(),v.end(),x)
#define ub(v,x)      upper_bound(v.begin(),v.end(),x)
#define lb(v,x)      lower_bound(v.begin(),v.end(),x)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) (a).begin(),(a).end() 
#define inp(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cerr<<endl;
#define printv(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout<<"\n";
#define Pi 3.14159265
#define reset(x) memset(x,'z',sizeof(x))
#define f first
#define s second
//#define m make_pair
#define PII pair<ll, ll> 
#define pq1 priority_queue<ll>
#define pq2 priority_queue<ll, vector<ll>,greater<ll>>
typedef long long ll;
typedef vector<ll> vll;
typedef bool B;
typedef double ff;
const ll INF=1e10;
const ll N = 100005;
char en='\n';   
ll m[100001];
         void solve()
         {
            string a; cin>>a;
            ll j=0;
            rep(i,0,a.size())
            {
               j+=ll(a[i]-'0');
            } 
            if(j%9==0)
               cout<<"Yes";
            else
               cout<<"No";
         } 
         int main() 
         { 
            ios_base::sync_with_stdio(false);cin.tie(NULL); 
            
            #ifndef ONLINE_JUDGE 
            freopen("input.txt", "r", stdin); 
            freopen("error.txt", "w", stderr); 
            freopen("output.txt", "w", stdout); 
            #endif 
            
            int t=1; 
            //cin>>t; 
            while(t--) 
            { 
               solve(); 
               cout<<"\n"; 
            } 
            
            cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
            return 0; 
         }                 


Measured memory_bytes: 3920
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

def main():
  MOD = 10**9+7
  n = int(input())
  T = [[] for _ in range(n)]
  for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    T[a].append(b)
    T[b].append(a)
  C = [[] for _ in range(n)]
  seen = [False]*n
  dp = [0]*n
  def dfs(v):
    cnt = 1
    seen[v] = True
    for nv in T[v]:
      if seen[nv]:
        continue
      C[v].append(nv)
      cnt += dfs(nv)
    dp[v] = cnt
    return cnt

  dfs(0)

  p = [1]*(n+1)
  inv = [1]*(n+1)
  inv_two = pow(2, MOD-2, MOD)
  for i in range(n):
    p[i+1] = p[i] * 2 % MOD
    inv[i+1] = inv[i] * inv_two % MOD
  ans = 0
  for i in range(n):
    s = 1
    t = 1
    cnt = 1
    for c in C[i]:
      l = dp[c]
      s *= inv[l]
      s %= MOD
      t += p[l] - 1
      t %= MOD
      cnt += l
    r = n - cnt
    s *= inv[r]
    s %= MOD
    t += p[r] - 1
    t %= MOD
    res = (1 - s*t) % MOD * inv_two
    res %= MOD
    ans += res
    ans %= MOD
  print(ans)

if __name__ == "__main__":
  main()

Measured memory_bytes: 218928
#include<bits/stdc++.h>
#define ll long long
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;
const ll M=500006;
ll f[M],inv[M];
ll expo(ll base,ll exponent){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

vector<bool>  prime(1000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=1000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=1000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

bool check(string s,char c)
{
	for(auto x:s)
	{
		if(x==c) return true;
	}
	return false;
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
 //    #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    ll tests=1;
   // cin>>tests;
    while(tests--)
    {
    	ll n,m,i,j;
    	cin>>n>>m;
    	vector<ll>h(n+1);
    	for(i=1;i<=n;i++) cin>>h[i];
    	vector<ll> graph[n+1];
    	for(i=0;i<m;i++)
    	{
    		ll a,b;
    		cin>>a>>b;
    		graph[a].pb(b);
    		graph[b].pb(a);
    	}
    	ll ans=0;
    	for(i=1;i<n+1;i++)
    	{
    		ll mx=0;
    		for(auto x:graph[i])
    		{
    			mx=max(mx,h[x]);
    		}
    		if(mx<h[i]) ans++;
    	}
    	cout<<ans;
    }

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> abc(n,vector<int>(3));
    vector<vector<int>> dp(n+1,vector<int>(3,0));
    queue<int> que;
    for(int i=0;i<n;i++){
        int a,b,c;
        cin >> a>>b>>c;
        abc.at(i).at(0)=a;
        abc.at(i).at(1)=b;
        abc.at(i).at(2)=c;
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k) continue;
                dp.at(i+1).at(k)=max(dp.at(i+1).at(k),dp.at(i).at(j)+abc.at(i).at(k));
            }
        }
    }
    int max_=max({dp.at(n).at(0),dp.at(n).at(1),dp.at(n).at(2)});
    cout << max_ << endl;

}

Measured memory_bytes: 11136
#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 a, b;
    cin >> a >> b;
    cout << a*b << " " << 2*(a+b) << endl;
    return 0;
}



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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

int solve(int n) {
	if(n == 1) return 1;
	return n + solve(n - 1);
}

int main() {
	int n;
	scanf("%d", &n);
	printf("%d\n", solve(n));
	return 0;
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Po pop_back
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
LL a, b;
    cin >> a >> b;
    string s, t;

    for(LL i = 0; i < a; i++){
        s.Pb((char)(b + '0'));
    }

    for(LL i = 0; i < b; i++){
        t.Pb((char)(a + '0'));
    }

    if(s >= t)
        cout << t;
    else
        cout << s;
    return 0;
}



Measured memory_bytes: 256
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#ifdef PERVEEVM_LOCAL
    #define debug(x) std::cerr << (#x) << ":\t" << (x) << std::endl
#else
    #define debug(x) 238;
#endif

#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define NAME "File"

using ll = long long;
using ld = long double;

#ifdef PERVEEVM_LOCAL
    std::mt19937 rnd(238);
#else
    std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const double PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
const int MOD = (int)1e9 + 7;

int add(int a, int b, int mod = MOD) {
    if (a + b >= mod) {
        return a + b - mod;
    }
    return a + b;
}

int sub(int a, int b, int mod = MOD) {
    if (a - b < 0) {
        return a - b + mod;
    }
    return a - b;
}

int mul(int a, int b, int mod = MOD) {
    return (int)(1ll * a * b % mod);
}

int binpow(int a, int n, int mod = MOD) {
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 0) {
        return binpow(mul(a, a, mod), n / 2, mod);
    } else {
        return mul(binpow(a, n - 1, mod), a, mod);
    }
}

int rev(int a, int mod = MOD) {
    return binpow(a, mod - 2, mod);
}

const int N = 110;
const int M = 100100;

int dp[N][M];
int pref[N][M];
int a[N];

void run() {
    int n, k;
    scanf("%d%d", &n, &k);

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

    dp[0][0] = 1;

    for (int i = 0; i <= k; ++i) {
        pref[0][i] = dp[0][i];

        if (i != 0) {
            pref[0][i] = add(pref[0][i], pref[0][i - 1]);
        }
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= k; ++j) {
            int l = std::max(0, j - a[i]);
            int r = j;

            dp[i][j] = pref[i - 1][r];
            if (l != 0) {
                dp[i][j] = sub(dp[i][j], pref[i - 1][l - 1]);
            }

            pref[i][j] = dp[i][j];
            if (j != 0) {
                pref[i][j] = add(pref[i][j], pref[i][j - 1]);
            }
        }
    }

    printf("%d\n", dp[n][k]);
}

int main(void) {
    // freopen(NAME".in", "r", stdin);
    // freopen(NAME".out", "w", stdout);

    auto start = std::chrono::high_resolution_clock::now();
    run();
    auto end = std::chrono::high_resolution_clock::now();

    #ifdef PERVEEVM_LOCAL
        std::cerr << "Execution time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
                  << " ms" << std::endl;
    #endif

    return 0;
}


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

using namespace std;

#define li long long int
#define ld long double
const int MX1 = 1e5 + 5;
const int MX2 = 1e6 + 5;
const li inf = 4e18;
const li mod = 1e9 + 7;

li power(li a, li b) { li res = 1; while (b) { if (b % 2) res = (res * a) % mod;
a = (a * a) % mod; b /= 2; } return res; }

li mmi(li a) { return power(a, mod - 2); }

li cntbit(li n) { li cnt = 0; while (n) { n &= (n - 1); cnt++; } return cnt; }

void solve() {
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.length(); i++) {
		if (s == t) {
			cout << "Yes";
			return ;
		}
		string a = "";
		for (int j = 0; j < s.length() - 1; j++) {
			a += s[j];
		}
		a = s[s.length() - 1] + a;
		s = a;
	}
	cout << "No";
}

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

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String agrs[])
    {
        Scanner in = new Scanner(System.in);
        double a = in.nextDouble();
        double b = in.nextDouble();
        double h = in.nextDouble();
        double m = in.nextDouble();
        h *= 30;
        m *= 6;
        h += m / 12;
        if(m == 0)
        {
            m = 360.0;
        }
        if(h == 0)
        {
            h = 360.0;
        }
        double angle = Math.min(Math.abs(h - m), Math.abs(m - h));
        angle /= 180;
        angle *= Math.PI;
        double hyp = Math.pow(a, 2) + Math.pow(b, 2) - (2 * a * b * Math.cos(angle));
        hyp = Math.sqrt(hyp);
        System.out.println(hyp);
    }
}


Measured memory_bytes: 37416
n = int(input())
cnt = [0]*4
jubje = ["AC", "WA", "TLE", "RE"]
for i in range(n):
    s = input()
    for j in range(4):
        if jubje[j] == s:
            cnt[j] += 1
for k in range(4):
    print(jubje[k],"x",cnt[k])


Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int x[3];
    cin >> x[0] >> x[1] >> x[2];
    SORT(x, 3);
    cout << x[0] * x[1] / 2 << endl;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

void get() {

}

class BCakesAndDonuts {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n;
		in >> n;
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				if(i * 4 + j * 7 == n){out << "Yes" << '\n'; return;}
			}
		}
		out << "No" << '\n';
	}
};


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

Measured memory_bytes: 256
#include<cstdio>
inline int geti()
{
	int x,f=1;char c;
	while((c=getchar())<'0'||c>'9') if(c=='-') f=-1;
	x=c-'0';
	while((c=getchar())>='0'&&c<='9') x=x*10+c-'0';
	return x*f;
}
inline int ab(int x)
{return x>0?x:-x;}

int n,t,a,b,now,n1,n2;

int main()
{
	n=geti();
	while(n--)
	{
		t=geti();a=geti();b=geti();
		int S=ab(n1-a)+ab(n2-b);
		if(((t-now)-S)&1||(t-now)<S)
		{
			puts("No");
			return 0;
		}
		else n1=a,n2=b,now=t;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var n, k, d int
	fmt.Scan(&n, &k)

	sunu := make([]int, n)
	for i := 0; i < k; i++ {
		fmt.Scan(&d)
		for j := 0; j < d; j++ {
			var temp int
			fmt.Scan(&temp)
			sunu[temp-1]++
		}
	}

	ans := 0
	for _, v := range sunu {
		if v == 0 {
			ans++
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 2452
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
string ss;
int main() {
	cin>>ss;
	if (ss=="SUN") puts("7");
	else if (ss=="MON") puts("6");
	else if (ss=="TUE") puts("5");
	else if (ss=="WED") puts("4");
	else if (ss=="THU") puts("3");
	else if (ss=="FRI") puts("2");
	else puts("1");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int i,n;
    unsigned long long s=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++) {
        if(i%3!=0 && i%5!=0) { s+=i; }
    }
    printf("%llu\n",s);

    return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
	x = 0;
	T f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
inline void d_read(double &x) {
	x = 0.0;
	int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	if (c == '.'){
		double num = 1.0;
		c = getchar();
		for (; isdigit(c); c = getchar()) x = x + (num /= 10) * (c ^ 48);
	}
	x *= f;
}

template <typename T>
inline void w(T x) {
	if (x > 9) w(x / 10);
	putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x, char c) {
	if (x < 0){
		putchar('-');
		x = -x;
	}
	w(x);
	putchar(c);
}
int a[100005], len;
int main(){
	long long n;
	read(n);
	while(n) {
		a[++ len] = (n - 1) % 26 + 1;
		if (n == 26) break;
		n -= a[len];
		n /= 26;
	}
	for (int i = len; i >= 1; i --) putchar(a[i] + 'a' - 1);
	return 0;
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int, int>
#define pll pair <ll, ll>
#define gcd __gcd
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 1e2+5;
const ll M = 1e5+5;

ll w[L], v[L];
ll ans[L][M];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll N, W;
    cin >> N >> W;
    
    for(ll i=1; i<=N; i++)
    {
        cin >> w[i] >> v[i];
    }

    for(ll i=0; i<=N; i++)
    {
        for(ll j=0; j<=W; j++)
        {
            if(!i || !j)
            {
                ans[i][j] = 0;
            }

            else if(j < w[i])
            {
                ans[i][j] = ans[i-1][j];
            }

            else
            {
                ans[i][j] = max(v[i]+ans[i-1][j-w[i]], ans[i-1][j]);
            }

            // cout << ans[i][j] << " ";
        }
        // cout << endl;
    }

    cout << ans[N][W] << endl;

    return 0;
}

Measured memory_bytes: 80128
A,B,C = map(int,input().split())

startR = A % B
i = 1
while True:
    
    R = A*i % B
    if R == C:
        print("YES")
        break
    
    if i != 1:
        if R == startR:
            print("NO")
            break
    
    i += 1

Measured memory_bytes: 9172
#include<cstdio>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<iostream>
#include<string>
using namespace std;
int main()
{
	priority_queue<long long>q;
	int m,n;
	long long op;
	long long sum=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
    {
		cin>>op;
		q.push(op);
	}
	while(m--)
	{
		op=q.top()/2;
		q.pop();
		q.push(op);
	}
	while(!q.empty())
	{
		sum+=q.top();
		q.pop();
	}
	cout<<sum<<endl;
	return 0;
}



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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> food(M);
  int K, A;
  for(int i=0; i<N; i++){
    cin >> K;
    for(int j=0; j<K; j++){
      cin >> A;
      food.at(A-1) += 1;
    }
  }
  int ans=0;
  for(int i=0; i<M; i++){
    if(food.at(i)==N) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
function main(input) {
  var args = input;
  var x = parseInt(args, 10);

  if (x === 7 || x === 5 || x === 3) {
    console.log('YES');
  } else {
    console.log('NO');
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
val Int.topDigit: Int
  get() = this.toString()[0].toString().toInt()
val Int.bottomDigit: Int
  get() = this % 10

fun main(args: Array<String>) {
  val N = readInt()
  val XL = (1..N).map { readInts() }.map { it[0] - it[1] to it[0] + it[1] }.sortedBy { it.second }
  var cnt = 0
  var rMax = Int.MIN_VALUE
  XL.forEach {
    val l = it.first
    var r = it.second
    if (rMax <= l) {
      rMax = r
      cnt++
    }
  }
  println(cnt)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 98944
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
using ll = long long;


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

  int N, M;
  cin >> N >> M;
  dsu d(N);
  ll ans = N - 1;

  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    if(!d.same(x, y)){
      d.merge(x, y);
      ans--;
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
const int N = 5010, M = 1e7+6;
int prime[M],pcnt,_v[M];
int k,x[N];
inline void sieve(int n = 10000000+2){
	_v[0]=_v[1]=1;
	for(int i=2;i<=n;i++){
		if(!_v[i])prime[++pcnt]=i;
		for(int j=1;j<=pcnt&&1ll*i*prime[j]<=n;j++){
			_v[i*prime[j]]=1;
			if(i%prime[j]==0)break;
		}
	}
}
int id1[N],id2[N],cnt1,cnt2;

struct node{int x,y,next;}edge[100010]; int len,first[N];
void adde(int x,int y){len++; edge[len].x=x; edge[len].y=y; edge[len].next=first[x]; first[x]=len;}
int chw[N],match[N];
bool dfs(int x)
{
  for(int k=first[x];k!=-1;k=edge[k].next)
  {
    int y=edge[k].y;
    if(!chw[y])
    {
      chw[y] = 1;
      if((match[y] == 0) || dfs(match[y])){match[y] = x; return 1;}
    }
  }
  return 0;
}

int main()
{
//	freopen("oatmeal.in","r",stdin);
//	freopen("oatmeal.out","w",stdout);
	sieve();
	cin >> k;
	for(int i=1;i<=k;i++){
		scanf("%d",&x[i]);
	}
	sort(x+1,x+k+1);
	for(int u=1,v;u<=k;u=v+1){
		v=u;
		while(v+1<=k&&x[v+1]==x[v]+1)++v;
		if(x[u]%2)id1[++cnt1]=x[u];
		else id2[++cnt2]=x[u];
		if((x[v]+1)%2)id1[++cnt1]=x[v]+1;
		else id2[++cnt2]=x[v]+1;
	}
	memset(first,-1,sizeof(first));
	for(int i=1;i<=cnt1;i++)for(int j=1;j<=cnt2;j++){
		if(!_v[abs(id1[i]-id2[j])]){
			adde(i,j);
			// cout << "?" << endl;
		}
	}
	// cout << cnt << endl;
	int ans=0;
	for(int i=1;i<=cnt1;i++){
		for(int j=1;j<N;j++)chw[j]=0;
		if(dfs(i))ans++;
	}
	//cout << cnt1 << " " << cnt2 << " " << ans << endl;
	cnt1-=ans,cnt2-=ans;
	if(cnt1%2==0){
		cout << cnt1+cnt2+ans << endl;
	}else{
		cout << cnt1+cnt2+ans+1 << endl;
	}
}


Measured memory_bytes: 42112
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 100000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int a,b,c,d;long long ans=0;
int main()
{
    a=read();b=read();read();c=read();d=read();read();read();
    ans=1LL*b+c/2*2+a/2*2+d/2*2;
    if(c&&a&&d) ans=max(ans,3LL+b+(c-1)/2*2+(a-1)/2*2+(d-1)/2*2);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
abc = [list(map(int,input().split())) for c in range(N)]
dp = [[0,0,0] for c in range(N)]
dp[0] = [abc[0][0],abc[0][1],abc[0][2]]
for i in range(1,N):
    for j in range(3):
        # print([dp[i-1][c] + abc[i][j] for c in range(3) if c != j])
        dp[i][j] = max([dp[i-1][c] + abc[i][j] for c in range(3) if c != j])
        # print(dp[i][j])

print(max([dp[N-1][i] for i in range(3)]))


Measured memory_bytes: 105172
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
vector<ll> a;
vector<ll> f;
ll n,k;
//A1*Fi1-a1*Fi1,A2*Fi2-a2*Fi2,An*Fin-an*Fin
bool check(ll mid){//最大値をmidに出来るか.
	//各aiの要素はmid/Fi以下であるべき.
	ll cost = 0;
	for(int i = 0;i < n;i++){
		ll aa = mid / f[i];
		if(aa < a[i])cost += a[i] - aa;
	}

	if(cost <= k)return true;
	else return false;
}


int main(){
	cin >> n >> k;
	a.resize(n);
	f.resize(n);

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

	sort(a.begin(),a.end(),greater<ll>());
	sort(f.begin(),f.end());

	ll ok = 1e18;
	ll ng = -1;
	while(ok - ng > 1){
		ll mid = (ok + ng) / 2;
		if(check(mid)){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}

	cout << ok << endl;
}


Measured memory_bytes: 3328
#include<stdio.h>
#include<string.h>
int main(void){
  char a[11],b[11],c[11];
  scanf("%s%s%s",a,b,c);
  puts(a[strlen(a)-1]==b[0]&&b[strlen(b)-1]==c[0]?"YES":"NO");
  return 0;
}

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

int main(){

    int n;
    cin >> n;

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

    bool aprooved = true;

    for(int i = 0; i < n; i++){
        if(a[i] % 2 == 0){
            if((a[i] % 3 != 0) && (a[i] % 5 != 0)){
                aprooved = false;
                break;
            }
        }
    }

    if(aprooved){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }

}


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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

d = dict(zip(A, B))
ans = d[A[0]]

for i in range(1, N):
    if A[i] - A[i-1] == 1:
        ans += d[A[i]] + C[A[i-1] -1]
    else:
        ans += d[A[i]]

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int ans=0;
int main(void){
	int a,b;
	cin>>a>>b;
	cout<<a*b-(a+b)+1<<endl;
}

Measured memory_bytes: 764
n=int(input())
y=[0 for _ in range(10**4+1)]
for j in range(1,100):
   for k in range(1,100):
      for u in range(1,100):
         a=j*j+k*k+u*u+j*k+k*u+u*j
         if a <= 10**4:
            y[a-1]+=1
for o in range(n):
   print(y[o])
            

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

vector<ll> enumerate_divisors(ll n){
    vector<ll> res;
    for(ll i = 1; i * i <= n; ++i){
        if(n % i == 0){
            res.push_back(i);
            if(n/i != i){res.push_back(n/i);}
        }
    }
    sort(res.begin(), res.end());
    return res;
}

vector<pll> prime_factorize(ll n){
    vector<pll> res;
    for(ll a = 2; a * a <= n; ++a){
        if(n % a != 0){continue;}
        ll ex = 0;

        while(n % a == 0){
            ++ex;
            n /= a;
        }

        res.push_back({a, ex});
    }

    if (n != 1) res.push_back({n, 1});
    return res;
}

int main(){
    ll n;
    cin >> n;
    ll ans = 0;

    vector<ll> divisors = enumerate_divisors(n);
    vector<pll> factorized = prime_factorize(n-1);

    for(auto k: divisors){
        if(k==1){continue;}
        ll num = n;
        while(num >= k){
            if(num%k == 0){
                num /= k;
            }else{
                num %= k;
            }
            if(num==1){ans++;}
        }
    }

    ll tmpval = 1;
    for(auto f: factorized){
        tmpval *= f.second+1;
    }
    tmpval--;

    ans += tmpval;

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 3580
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a = k()
b = l()
b.sort()
ans = 1
for i in b:
    if i == 0:
        print(0)
        sys.exit()
    else:
        ans *= i
    if ans > 10**18:
        print(-1)
        sys.exit()

print(ans)


Measured memory_bytes: 23536
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut b = 0;
    let mut c = 0;
    for i in 0..n {
        if a[i] % 4 == 0 {
            b += 1;
        } else if a[i] % 2 == 0 {
            c += 1;
        }
    }
    let mut d = n - b - c;
    if c > 0 {
        d += 1;
    }
    if d > b + 1 {
        println!("No",);
    } else {
        println!("Yes",);
    }
}


Measured memory_bytes: 6396
//edpc_c.cpp
//Sat Jan 12 15:23:40 2019

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int a[n+1],b[n+1],c[n+1];
	a[0] = 0; b[0] = 0; c[0] = 0;
	for (int i=1;i<n+1;i++){
		cin >> a[i] >> b[i] >> c[i];
	}

	int umi[n+1],yama[n+1],ie[n+1];
	umi[0] = 0; yama[0] = 0; ie[0] = 0;

	for (int i=1;i<n+1;i++){
		umi[i] = max(yama[i-1]+b[i],ie[i-1]+c[i]);
		yama[i] = max(umi[i-1]+a[i],ie[i-1]+c[i]);
		ie[i] = max(yama[i-1]+b[i],umi[i-1]+a[i]);
	}

	int ans = max(umi[n],yama[n]);
	ans = max(ans,ie[n]);
	cout << ans << endl;
}

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

using namespace std;

#define N_MAX 100000

int main(){
    int dp[N_MAX][3],N,a[N_MAX],b[N_MAX],c[N_MAX];
    memset(dp,0,N_MAX*sizeof(int));
    scanf("%d",&N);
    
    for(int i=0;i<N;i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
    }
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i=1;i<N;i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i];
    }

    int res = max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2]));

    printf("%d\n",res);
    return 0;
}

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

map<ll,ll>l2;

int main()
{
    ll n;
    //cin>>n;
    ll s=0;vector<ll>v;
    for(int i = 1; i<=5;i++){
        ll a,b;
        cin>>a;
        if(a==0)s=i;
    }
    cout<<s;

    return 0;
}


Measured memory_bytes: 3640
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


a, b = MI()
if a == 0 or b == 0 or (a < 0 and b > 0):
    print('Zero')
    exit()
if a > 0 and b > 0:
    print('Positive')
    exit()
if (-(a) - -(b) + 1) % 2 == 0:
    print('Positive')
    exit()
else:
    print('Negative')


Measured memory_bytes: 67436