akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
    { for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
    { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
    { cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    reverse(all(s));
    stack<int> ans;
    int i = 0;
    while(i < n) {
        bool flag = 1;
        for(int j = m; j > 0; j--) {
            if (i + j > n) continue;
            if (s[i + j] == '0') {
                i += j;
                ans.push(j);
                flag = 0;
                break;
            }
        }
        if (flag) {
            cout << -1 << endl;
            return;
        }
    }
    while(!ans.empty()) {
        cout << ans.top() << " ";
        ans.pop();
    }
    cout << endl;
}

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


Measured memory_bytes: 3984
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    cnt, nega, posi = 0, 0, []
    for x, y in zip(a, b):
        if x < y:
            nega += y - x
            cnt += 1
        else:
            posi.append(x - y)
    if sum(posi) - nega < 0:
        print(-1)
        exit()
    posi.sort(reverse=True)
    i = 0
    while nega > 0:
        nega -= posi[i]
        cnt += 1
        i += 1
    print(cnt)

if __name__ == "__main__":
    main()

Measured memory_bytes: 24300
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

const int MOD = 1e9 + 7;
const int N = 3030;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    vi dp(n), tmp(n);
    dp[0] = 1;
    for (int i=0; i+1<n; i++) {
        if (s[i] == '<') {
            tmp[0] = 0;
            for (int j=1; j<=i+1; j++) {
                tmp[j] = (tmp[j-1] + dp[j-1]) % MOD;
            }
        }
        else {
            tmp[i+1] = dp[i+1];
            for (int j=i; j>=0; j--) {
                tmp[j] = (tmp[j+1] + dp[j]) % MOD;
            }
        }
        swap(dp, tmp);
    }
    int ans = 0;
    for (int x : dp) {
        ans = (ans + x) % MOD;
    }
    cout << ans << '\n';
}

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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, m;
    cin >> n >> m;
    vl s(m), c(m);
    rep(i, m) {
        cin >> s[i] >> c[i];
    }
    for (ll i = 0; i < 1000; ++i) {
        string num_str = to_string(i);
        if (num_str.size() != n) {
            continue;
        }
        bool ok = true;
        rep(j, m) {
            if (num_str[s[j] - 1] - '0' != c[j]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cout << num_str << '\n';
            return;
        }
    }
    cout << -1 << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

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

  p((int)sqrt(n) * (int)sqrt(n));
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  cin >> n >> m;
  vint x(n);
  rep(i, n) cin >> x[i];
  vint y(m);
  rep(i, m) cin >> y[i];

  int sumx = 0;
  rep(i, n) {
    sumx = (sumx + x[i]*i%mod - x[i]*(n-1-i)%mod + mod) % mod;
  }
  int sumy = 0;
  rep(i, m) {
    sumy = (sumy + y[i]*i%mod - y[i]*(m-1-i)%mod + mod) % mod;
  }
  cout << sumx*sumy%mod << endl;

  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

/**
 * Created by sonetsuyoshi on 2016/07/31.
 */
public class Main {

    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a <= c && c <= b) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21972
import sys


def in_ctrl():
    _input = [_.rstrip() for _ in sys.stdin.readlines()]
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    N = int(_input[0])
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    return N


def out_ctrl(s):
    print(s)


if __name__ == "__main__":
    N = in_ctrl()
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    for n in range(N+1):
        if n%3>0 and n%5>0:
            cnt += n
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    out_ctrl(cnt)

Measured memory_bytes: 65052
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int i,n,a,ans=0;
	std::cin >> n;
	for(i=1; i<=n; ++i){
		std::cin >> a;
		a %= 2;
		if(i%2 && a){
			++ans;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3592
from sys import stdin
input = stdin.readline


def main():
  N, K = list(map(int, input().split()))
  H = list(map(int, input().split()))
  H = sorted(H)

  if K == 0:
    print(sum(H))
    return
  print(sum(H[:-K]))


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 105276
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	FOR (i, 0, sz(s) - 1) 
	    if (s[i] == '?') s[i] = 'D';
	
	cout << s;
}



















Measured memory_bytes: 3748
#include <iostream>
using namespace std;
string b[8];
int main() {
    for (int i=0; i<8; i++) cin>>b[i];
    cout<<90<<endl;
    for (int i=0; i<8; i++) {
        for (int j=7; j>=0; j--) {
            cout<<b[j][i];
        }
        cout<<endl;
    }
    cout<<180<<endl;
    for (int i=7; i>=0; i--) {
        for (int j=7; j>=0; j--) {
            cout<<b[i][j];
        }
        cout<<endl;
    }
    cout<<270<<endl;
    for (int i=7; i>=0; i--) {
        for (int j=0; j<8; j++) {
            cout<<b[j][i];
        }
        cout<<endl;
    }
}

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


using namespace std;

#define ll long long
#define C2(a) ((((ll)(a) * (ll)((a)-1)) / 2LL) + (ll)(a))

int n;
int c[200005];
vector<int> graph[200005];
ll anscomp[200005];
int curfreq[200005];

int cglobal = 0;

void dfs(int node, int parent)
{
    int old_prt_freq = curfreq[c[parent]] + cglobal;
    /*for (int i = 1; i <= n; i++) {
        if (i != c[node]) curfreq[i]++;
    }*/
    cglobal++; curfreq[c[node]]--;
    for (int i = 0; i < graph[node].size(); i++) {
        int child = graph[node][i];
        if (child == parent) continue;
        dfs(child, node);
    }
    anscomp[c[parent]] += C2(curfreq[c[parent]] + cglobal - old_prt_freq);
    curfreq[c[parent]] = old_prt_freq - cglobal;
    if (parent == 0) {
        for (int i = 1; i <= n; i++) {
            anscomp[i] += C2(curfreq[i] + cglobal);
        }
    }
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", c + i);
    for (int i = 1; i < n; i++) {
        int a, b; scanf("%d%d", &a, &b);
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(1, 0);
    ll base = C2(n);
    for (int i = 1; i <= n; i++) {
        printf("%lld\n", base - anscomp[i]);
    }
    return 0;
}


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

int main() {
    int n, sum = 0;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d.at(i);
    }
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3604
import java.util.Scanner;

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

	/* 入力 */
	int n = scan.nextInt();
	int c1 = 0;  // B~A
	int c2 = 0;  // B~X
	int c3 = 0;  // X~A
	String[] s = new String[n];
	for(int i = 0; i < n; i++){
	    s[i] = scan.next();
	    if(s[i].charAt(0) == 'B' &&
	       s[i].charAt(s[i].length()-1) == 'A'){
		c1++;
	    }else if(s[i].charAt(0) == 'B'){
		c2++;
	    }else if(s[i].charAt(s[i].length()-1) == 'A'){
		c3++;
	    }
	}

	int AB = 0;
	for(int i = 0; i < n; i++){
	    AB += countAB(s[i]);
	}

	/* B~Aが0個だった場合 */
	if(c1 == 0){
	    AB += Math.min(c2,c3);
	}
	/* B~Aが1個以上の場合 */
	else{
	    /* X~A == B~Xの場合 */
	    if(c2 == 0 && c3 == 0){
		AB += (c1-1);
	    }else{
		AB += c1+Math.min(c2,c3);
	    }
	}

	System.out.println(AB);
    }

    /* 文字列中のABの数を数える */
    static int countAB(String s){
	int count = 0;
	for(int i = 0; i < s.length(); i++){
	    if(s.charAt(i) == 'A' && i != s.length()-1){
		if(s.charAt(i+1) == 'B'){
		    count++;
		}
	    }
	}

	return count;
    }
}


Measured memory_bytes: 31492
import sys
readline = sys.stdin.readline

N, Q = map(int, readline().split())
S = readline()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, readline().split())
    print(t[r-1] - t[l-1])

Measured memory_bytes: 7916
# 参考: https://atcoder.jp/contests/abc069/submissions/4321457
N = gets.to_i
AS = gets.split.map(&:to_i)

even = AS.count(&:even?)
four = AS.count { |a| a % 4 == 0 }
x = four
y = even - x
if x * 2 + 1 >= N || x * 2 + y >= N
  puts('Yes')
else
  puts('No')
end

Measured memory_bytes: 8452
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
#define endl "\n"
//#pragma GCC optimize(2)
using namespace std;
const int N=1e6+1;
const int M=1e9+7;
const double eps=1e-6;
typedef complex<double>C;
const double PI(acos(-1.0));
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a, LL b,LL M) { return b ? b & 1 ? a*pw(a, b - 1,M) % M : pw(a*a%M, b>>1,M) : 1; }
//log() = ln() , log(x)/log(y)=log(y)-base-x
//INT_MAX 127,INT_MIN 128
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
int main(){Accel
	LL n;
	cin>>n;
	LL t=0,s=0;
	while(n>=10)s+=n%10,n/=10,t++;
	if(n==1)cout<<max(t*9,s+n)<<endl;
	else cout<<max(s+n,t*9+n-1)<<endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define per(i,a,b) for(int i = a; i >= b; i--)
#define inf 9223372036854775807
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto& a : x)

int main(){
  ll l,n; cin >> l >> n;
  vi a,b; a.assign(n,0);
  rep(i,0,n) cin >> a[i];
  per(i,n-1,0) b.push_back(l-a[i]);
  vi s1,s2;
  s1.assign(n+1,0);
  s2.assign(n+1,0);
  rep(i,0,n) s1[i+1] = s1[i]+a[i];
  rep(i,0,n) s2[i+1] = s2[i]+b[i];
  ll ans = 0;
  /*
  rep(i,0,n) cout << a[i] << " "; cout << endl;
  rep(i,0,n) cout << b[i] << " "; cout << endl;
  rep(i,0,n+1) cout << s1[i] << " "; cout << endl;
  rep(i,0,n+1) cout << s2[i] << " "; cout << endl;
  */

  rep(i,0,n+1){
    ll x = i, y = n-i;
    if (x == 0) { ans = max(ans,b[y-1]); continue; }
    if (y == 0) { ans = max(ans,a[x-1]); continue; }
    if (x > y){
      ans = max(ans, a[x-1] + 2*s2[y] + 2*(s1[x-1]-s1[x-y-1]));
      ans = max(ans, b[y-1] + 2*s2[y-1] + 2*(s1[x]-s1[x-y]));
    } else if (y > x) {
      ans = max(ans, b[y-1] + 2*s1[x] + 2*(s2[y-1]-s2[y-x-1]));
      ans = max(ans, a[x-1] + 2*s1[x-1] + 2*(s2[y]-s2[y-x]));
    } else {
      ans = max(ans, 2*s2[y] + 2*s1[x] - min(b[x-1],a[x-1]));
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 6640
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<queue>
#include<algorithm>
#include<string.h>
#define PI acos(-1.0)
using namespace std; 

typedef long long ll;
ll gcd(ll x,ll y)
{	if(y==0) return x;
	return gcd(y,x%y);
}

int main()
{
	ll a,b;
	scanf("%lld%lld",&a,&b);
	ll x=a*b/gcd(a,b);
	if(x>a) printf("%lld\n",a);
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}


int main(){
	int k;
	cin >> k;
	priority_queue<ll, vector<ll>, greater<ll> > pq;
	for (ll i = 1; i <= 9; i++) pq.push(i);
	ll t;
	while(k--){
		t = pq.top();
		pq.pop();
		if(pq.size() > 100000) continue;
		string x = to_string(t);
		int n = x.size();

		if (x[n-1]-'0' == 9) pq.push(stoll(x + "8")), pq.push(stoll(x + "9"));
		else if (x[n-1]-'0' == 0) pq.push(stoll(x + "1")), pq.push(stoll(x + "0"));
		else {
			int val = x[n-1]-'0';
			pq.push(stoll(x + to_string(val-1)));
			pq.push(stoll(x + to_string(val)));
			pq.push(stoll(x + to_string(val+1)));
		}
	}
	cout << t;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
ll ncd(ll n,ll d){
    ll x = 1,y=1;
    if(d<0||d>n)return 0;
    for(int i=0;i<d;i++){
        x = x*(n-i)%mod;
        y = y*(i+1)%mod;
    }
    return x*modpow(y,mod-2,mod)%mod;
}
int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = modpow(2,n,mod)-1 -ncd(n,a)-ncd(n,b);
    ans%=mod;
    while(ans<0){
        ans+=mod;
    }
    cout <<ans <<endl;
}
    



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

int main() {
  int N,A=0;
  cin>>N;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(a%2==1){
      A++;
    }
  }
  if(A==0){
    cout<<"second"<<endl;
  }
  else{
    cout<<"first"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;

ll a[N];
int main()
{
	int n;
	cin >> n;
	ll sum = 0;
	for (int i=0; i<n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	ll x = 1LL * n * (n+1) / 2;
	if (sum % x != 0)
	{
		cout << "NO\n";
		return 0;
	}
	ll y = sum / x;
	for (int i=0; i<n; i++)
		if (a[i] < y)
		{
			cout << "NO\n";
			return 0;
		}
	for (int i=0; i<n; i++)
		if ((a[i] + y) % n != a[(i+1) % n] % n)
		{
			cout << "NO\n";
			return 0;
		}
	cout << "YES\n";
	return 0;
}

Measured memory_bytes: 1024
function main(input) {
  var c = input.trim();
  var alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
       "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
  var result = alphabet.indexOf(c);
  return alphabet[result + 1];
}
console.log(main(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7372
from scipy.sparse.csgraph import csgraph_from_dense,floyd_warshall
h,w=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]
a=[list(map(int,input().split())) for i in range(h)]
g=csgraph_from_dense(c,null_value=0)
d=floyd_warshall(g)
ans=0
for i in range(h):
  for j in range(w):
    if a[i][j]!=-1:
      ans+=d[a[i][j]][1]
print(int(ans))

Measured memory_bytes: 14056
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#include<list>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

#define mod 1000000007

vector<int> v(1000, 1);

void f(int n) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			v[i]++;
			n = n / i;
			i--;
		}
	}
	if (n != 1) {
		v[n]++;
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		f(i);
	}
	ll ans = 1;
	for (int i = 0; i < 1000; i++) {
		ans = (ans * v[i]) % mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s = list(input())
output = [0 for i in s]
ruiseki = 0
for p in range(len(s)):
    if s[p] == "R":
        if s[p+1] == "R":
            ruiseki+=1
        else:
            ruiseki+=1
            output[p] += ruiseki//2 + ruiseki%2
            output[p+1] += ruiseki//2
            ruiseki=0
    
ruiseki = 0
for q in range(len(s)-1, -1, -1):
    if s[q] == "L":
        if s[q-1]=="L":
            ruiseki+=1
        else:
            ruiseki+=1
            output[q] += ruiseki//2 + ruiseki%2
            output[q-1] += ruiseki//2
            ruiseki=0
print(" ".join(map(str,output)))

Measured memory_bytes: 11176
N = gets.to_i
F = N.times.map do
  gets.split.join.to_i(2)
end
P = N.times.map do
  gets.split.map(&:to_i)
end

max = -(10**7 * N)
(1..1023).each do |i|
  sum = 0
  N.times do |n|
    p = (F[n] & i).to_s(2).chars.count("1")
    sum += P[n][p]
  end
  max = [max, sum].max
end

p max



Measured memory_bytes: 1916
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

template<class Type> inline bool chmax(Type& a, Type b) { if (a < b) { a = b; return 1; } return 0; }
template<class Type> inline bool chmin(Type& a, Type b) { if (a > b) { a = b; return 1; } return 0; }

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

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

	vector<int> dp(n,INT_MAX);
	dp[0] = 0;
	for (int i = 0; i < n - 1; i++)
	{
		if (1 <= i)
		{
			dp[i + 1] = min(dp[i + 1], dp[i - 1] + abs(h[i + 1] - h[i - 1]));
		}
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
	}
	cout << dp[n - 1] << endl;
}

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

const int MOD = 1000000007;

const int N = 20 + 3;
const int M = 20 + 3;
const int K = (N - 1) * M;

const int T = 1 << 20;

int n, m, k;

int c[M][N];

int t;

int f[2][N][T];

int z = 0;

inline int lowbit(int n) {
	return n & -n;
}

inline int full(int j) {
	return (1 << (j)) - 1;
}

inline int func(int s, int j) {
	int top = s & ~full(j);
	int bottom = s & full(j);
	return top - lowbit(top) + (1 << j) + bottom;
}

inline int get(int s, int j) {
	return s & (1 << j);
}

void solve() {
	f[0][0][0] = 1;
	for (int _i = 0; _i < m; _i++) {
		int i = _i % 2;
		for (int j = 0; j < n; j++) {
			for (int s = 0; s < t; s++) {
				if (f[i][j][s] == 0) continue;
//				printf("%d %d %d : %d %d\n", _i, j, s, f[i][j][s], c[_i][j]);
				if (c[_i][j] != 1 && get(s, j) == 0) {
					f[i][j + 1][s] += f[i][j][s];
					f[i][j + 1][s] %= MOD;
				}
				if (c[_i][j] != 0) {
					f[i][j + 1][func(s, j)] += f[i][j][s];
					f[i][j + 1][func(s, j)] %= MOD;
				}
			}
		}
		memset(f[(i + 1) % 2], 0, sizeof f[(i + 1) % 2]);
		for (int s = 0; s < t; s++)
			f[(i + 1) % 2][0][s] = f[i][n][s];
	}
}

int main(int argc, char *argv[]) {
	memset(c, -1, sizeof c);
	scanf("%d%d%d", &n, &m, &k);
	n--;
	t = 1 << n;
	for (int i = 0; i < k; i++) {
		int a, b, c_;
		scanf("%d%d%d", &a, &b, &c_);
		c[a - 1][b - 1] = c_;
	}
	solve();
	int ans = 0;
	for (int s = 0; s < t; s++) {
		ans += f[(m - 1) % 2][n][s];
		ans %= MOD;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 188544
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint A, B, C;
	cin >> A >> B >> C;
	lint K;
	cin >> K;
	lint cnt = 0;
	while (1) {
		if (A < B) {
			break;
		}
		else {
			B *= 2;
			cnt++;
		}
	}
	while (1) {
		if (B < C) {
			break;
		}
		else {
			C *= 2;
			cnt++;
		}
	}
	if (cnt <= K) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

#include <cstdint>

template <std::uint_fast64_t Mod>
class ModInt {
  using u64 = std::uint_fast64_t;

 public:
  u64 val;

  constexpr ModInt(const u64 x = 0) noexcept : val(x % Mod) {}
  constexpr ModInt operator+(const ModInt rhs) const noexcept {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const noexcept {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr ModInt &operator+=(const ModInt rhs) noexcept {
    val += rhs.val;
    if (val >= Mod) {
      val -= Mod;
    }
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) noexcept {
    if (val < rhs.val) {
      val += Mod;
    }
    val -= rhs.val;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    val = val * rhs.val % Mod;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    u64 exp = Mod - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

template <typename T>
T power(T x, int n) {
  T ans{1};
  while (n) {
    if (n % 2) ans *= x;
    x *= x;
    n >>= 1;
  }
  return ans;
}

#include <numeric>

const int MOD = 1000000007;

using namespace std;
using mint = ModInt<MOD>;

void solve(int N, int K) {
  vector<mint> v(K+1,0);
  mint ans{0};
  for (int x = K; x; --x) {
    v[x] = power(mint(K/x),N);
    for (int i = 2; i*x <= K; i += 1) {
      v[x] -= v[i*x];
    }
    ans += v[x] * x;
  }

  cout << ans.val << endl;
}

int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  solve(N, K);
  return 0;
}


Measured memory_bytes: 4060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;


void solve(long long N, long long M, std::vector<long long> x, std::vector<long long> y, std::vector<long long> z){
    vector<ll> sum(N);
    ll ans=0;
    rep(i,2){
        rep(j,2){
            rep(k,2){
                rep(c,N){
                    sum[c]=((i*2-1)*x[c]+(j*2-1)*y[c]+(k*2-1)*z[c]);
                }
                sort(all(sum));
                ll tmp=0;
                rep(c,M){
                    tmp+=sum[sum.size()-1-c];
                }
                ans=max(ans,tmp);
            }
        }
    }
    op(ans);
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    std::vector<long long> z(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
        scanf("%lld",&z[i]);
    }
    solve(N, M, std::move(x), std::move(y), std::move(z));
    return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

using Graph = vector<vector<int>>;
Graph G;


void dfs(int v, vector<bool> &seen, int &res) {
    // flag立てる
    bool end = true;

    rep(i,seen.size()) {
        // まだ到達していない頂点があれば、続ける
        // 自分自身のチェックはしないようにする
        if (!seen[i] && i != v) end = false;
    }
    if (end) {
        // 全ての頂点に到達すれば、このパスはおk
        ++res;
        return;
    }
    seen[v] = true;
    for (auto nv : G[v]) {
        // 自分からいける、かつまだ行ってない場所にいく
        if (seen[nv]) continue;
        dfs(nv, seen, res);
    }
    // 1つ前の頂点に戻るときに、自分自身を未到達に戻しておく
    // 例えば、1 -> 2 -> 3, 1 -> 3 -> 2という２通りがあるとして
    // 今が1 -> 2の2だとする, ここから戻って 1 -> 3と行ったときに
    // 3から2へ行こうとするとすでに2を通ってるだとダメなので
    seen[v] = false;
}

int main() {
    int n, m; cin >> n >> m;
    G.assign(n, vector<int>());
    rep(i, m) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<bool> seen(n, false);
    int res = 0;
    dfs(0, seen, res);
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i){
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;

    if (l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if (r <= H && A[r] > A[largest]) largest = r;

    if (largest != i){
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int main(){
    cin >> H;

    for (int i=1; i<=H; i++) cin >> A[i];

    for (int i=H/2; i>=1; i--) maxHeapify(i);

    for (int i=1; i<=H; i++){
        cout << " " << A[i];
    }
    cout << endl;

    return 0;
}

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

#define MX 505
int c[MX],s[MX],f[MX],n;

int main()
{
    int i,j,x;
    scanf("%d",&n);
    for(i=1; i<n; i++)  scanf("%d %d %d",&c[i],&s[i],&f[i]);
    for(i=1; i<n; i++)
    {
        x = s[i];
        for(j=i; j<n; j++)
        {
            x = max(x,s[j]);
            if((x%f[j])!=0) x += (f[j]-(x%f[j]));
            x += c[j];
        }
        printf("%d\n",x);
    }
    puts("0");
    return  0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const int N = 2e5 + 10;
 
int main(){
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  cout << 1LL * n * (n - 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x.at(i);

    ll ans =1000000000;
    for(int i=0; i<102; i++){
        ll tmp = 0;
        for(int j=0; j<n; j++){
            tmp += pow(i-x.at(j), 2);
        }
        ans = min(tmp, ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <stack>
using namespace std;
const int MAXN=2e4+7;
char c[MAXN];
stack<int> s1,s3;
stack<pair<int,int> > s2;
int main () {
	scanf ("%s",c);
	int a=0,k=0,cur=0;
	while (c[cur]!='\0') {
		if (c[cur]=='\\') s1.push(cur);
		if (c[cur]=='/'&&!s1.empty()) {
			int tmp=s1.top(),stmp=0;
			s1.pop();
			a+=cur-tmp;
			while (!s2.empty()) {
				int i=s2.top().first,j=s2.top().second;
				if (i<tmp) break;
				s2.pop();
				stmp+=j;
			}
			s2.push(make_pair(tmp,cur-tmp+stmp));
		}
		cur++;
	}
	while (!s2.empty()) {
		s3.push(s2.top().second);
		s2.pop();
		k++;
	}
	printf ("%d\n%d",a,k);
	while (!s3.empty()) {
		printf (" %d",s3.top());
		s3.pop();
	}
	printf ("\n");
    return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	double n,d;
	int count=0;
	cin >> n >> d;
	d=d*d;
	while(n--){
		double x,y;
		cin >> x >> y;
		double s = x*x + y*y;
		if(s<=d){
			count++;
		}
	}
	cout << count << "\n";
	return 0;
}

Measured memory_bytes: 3752
N = int(input())
H = list(map(int, input().split()))

Hmax = H[0]
flag = 0
for i in range(N):
	if H[i] < Hmax - 1:
		flag = 1
		break
	if H[i] > Hmax:
		Hmax = H[i]

if flag == 1:
  	print('No')
else:
  	print('Yes')

Measured memory_bytes: 14396
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        scan.close();

        int money = 0;
        while(money < N){
            money = money + 1000;
        }
        System.out.println(money-N);
    }
}

Measured memory_bytes: 35700
#include <bits/stdc++.h>
using namespace std;
#define maxn 6000
#define INF 999999999
int n, W[maxn], f[2][2][maxn], g[maxn][2];

int read()
{
	int x = 0, k = 1;
	char c; c = getchar();
	while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * k; 
}

struct edge
{
	int cnp, to[maxn], last[maxn], head[maxn];
	edge() { cnp = 2; }
	void add(int u, int v) { to[cnp] = v, last[cnp] = head[u], head[u] = cnp ++; }
}E1; 

bool Down(int &x, int y)
{
	if(y >= INF) return 0;
	x = min(x, y); return 1;
}

void dfs(int u)
{
	for(int i = E1.head[u]; i; i = E1.last[i]) { int v = E1.to[i]; dfs(v); }
	for(int i = 0; i <= 1; i ++)
		for(int j = 0; j <= W[u]; j ++) f[0][i][j] = INF;
	f[0][0][0] = f[0][1][0] = 0; int pre = 0, now = 1;
	for(int i = E1.head[u]; i; i = E1.last[i])
	{
		int v = E1.to[i];
		for(int j = 0; j <= 1; j ++)
			for(int k = 0; k <= W[u]; k ++) f[now][j][k] = INF;
		for(int k = 0; k <= 1; k ++)
			for(int j = 0; j <= W[u]; j ++)
			{
				int flag = 0; 
				if(j - W[v] >= 0) flag = Down(f[now][k][j], f[pre][k][j - W[v]] + g[v][k]); 
				if(j - g[v][k ^ 1] >= 0) flag = Down(f[now][k][j], f[pre][k][j - g[v][k ^ 1]] + W[v]);
			}
		swap(pre, now);
	}
	g[u][0] = g[u][1] = INF;
	for(int k = 0; k <= 1; k ++)
		for(int j = 0; j <= W[u]; j ++)
			g[u][k] = min(g[u][k], f[pre][k][j]); 
}

int main()
{
	n = read();
	for(int i = 2; i <= n; i ++) { int x = read(); E1.add(x, i); }
	for(int i = 1; i <= n; i ++) W[i] = read();
	dfs(1);
	if(g[1][0] < INF || g[1][1] < INF) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 384
S = str(input())
T = ''
cnt = 0
while True:
    if S[cnt:cnt+5] == 'dream':
        try:
            if S[cnt:cnt+7] == 'dreamer' and (S[cnt+7] != 'a'):
                cnt += 7
                T = T + 'dreamer'
            else:
                T = T + 'dream'
                cnt += 5
        except IndexError:
            cnt += 7
            T = T + 'dreamer'

    elif S[cnt:cnt+5] == 'erase':
        try:
            if S[cnt:cnt+6] == 'eraser' and S[cnt+6] != 'a':
                cnt += 6
                T = T + 'eraser'
            else:
                cnt += 5
                T = T + 'erase'
        except IndexError:
            cnt += 6
            T = T + 'eraser'
    else:
        break

    if len(S) <= cnt:
        break

if S == T:
    print('YES')
else:
    print('NO')

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

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

/* void solve(long long N, vector<long long> a, vector<long long> b, vector<long long> c){ */
void solve(long long N, ll act[][3]){
    vector< vector<ll> > dp(N+100, vector<ll>(3));

/*     vector< vector<ll> > act(N, vector<ll>(3)); */
/*     rep(i, N) { */
/*         act[i][0] = a[i]; */
/*         act[i][1] = b[i]; */
/*         act[i][2] = c[i]; */
/*     } */

    rep(i, N) {
        rep(j, 3) {
            rep(k, 3) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + act[i][k]);
            }
        }
    }

    ll res = 0;
    rep(j, 3) chmax(res, dp[N][j]);
    cout << res << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    cin >> N;

    ll act[N][3];
    rep(i, N) {
        rep(j, 3) {
            cin >> act[i][j];
        }
    }

    solve(N, act);
    /* vector<long long> a(N); */
    /* vector<long long> b(N); */
    /* vector<long long> c(N); */

    /* for(int i = 0 ; i < N ; i++){ */
    /*     cin >> a[i]; */
    /*     cin >> b[i]; */
    /*     cin >> c[i]; */
    /* } */
    /* solve(N, move(a), move(b), move(c)); */
}


Measured memory_bytes: 8064
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n>>m;
		// n=s.length();
		// ll a[n];
		c=(n*(n-1))/2;
		c+=(m*(m-1))/2;
		cout<<c;

		
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
#define per(i, a, b) for (int i = a; i >= b; -- i)
const int N = 100005;
using namespace std;
int c[N], d[N], a[N], st[N], n; ll f[N], bit[2][N];
int find(int ave) {
	int l = 1, r = d[0];
	for ( ; l <= r; ) {
		int mid = (l + r) / 2;
		if (d[mid] == ave) return mid;
		if (ave < d[mid]) r = mid - 1;
			else l = mid + 1;
	}
	return 0;
}
void pre() {
	c[0] = d[0] = 0;
	rep(i, 1, n) c[++ c[0]] = a[i];
	sort(c + 1, c + c[0] + 1);
	for (int i = 1, j; i <= c[0]; i = j) {
		d[++ d[0]] = c[i];
		for (j = i + 1; j <= c[0] && c[i] == c[j]; ++ j);
	}
	rep(i, 1, n) a[i] = find(a[i]);
}
void put(int c, int x, int y) {
	for ( ; x <= d[0]; x += x & (- x))
		bit[c][x] += y;
}
ll get(int c, int x) {
	ll ret = 0;
	for ( ; x; x -= x & (- x)) ret += bit[c][x];
	return ret;
}
int main() {
	scanf("%d", &n);
	rep(i, 1, n) scanf("%d", &a[i]);
	int top = 1; st[1] = n;
	per(i, n - 1, 1) {
		for ( ; top && a[i] >= a[st[top]]; ) -- top;
		st[++ top] = i;
	}
	pre();
	rep(i, 1, n) put(0, d[0] - a[i] + 1, 1), put(1, d[0] - a[i] + 1, d[a[i]]);
	rep(i, 2, top) {
		ll ret = get(1, d[0] - a[st[i]] + 1) - (ll) get(0, d[0] - a[st[i]] + 1) * d[a[st[i]]];
		ret -= get(1, d[0] - a[st[i - 1]] + 1) - (ll) get(0, d[0] - a[st[i - 1]] + 1) * d[a[st[i - 1]]];
		f[st[i - 1]] = ret;
	}
	f[1] = 0;
	rep(i, 1, n) f[1] += d[a[i]];
	rep(i, 2, n) f[1] -= f[i];
	rep(i, 1, n) printf("%lld\n", f[i]);
	return 0;
}

Measured memory_bytes: 4992
R, C, K = map(int, input().split())
item = [[0]*C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    item[r-1][c-1] = v
dp = [[[0]*C for _ in range(R)] for _ in range(4)]
dp[1][0][0] = item[0][0]

for h in range(R):
    for w in range(C):
        if h!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h-1][w], dp[1][h-1][w],  dp[2][h-1][w],  dp[3][h-1][w])
            dp[1][h][w] = max(dp[1][h][w], dp[0][h-1][w]+item[h][w], dp[1][h-1][w]+item[h][w], dp[2][h-1][w]+item[h][w], dp[3][h-1][w]+item[h][w])
        if w!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h][w-1])
            dp[1][h][w] = max(dp[1][h][w], dp[1][h][w-1], dp[0][h][w-1]+item[h][w])
            dp[2][h][w] = max(dp[2][h][w], dp[2][h][w-1], dp[1][h][w-1]+item[h][w])
            dp[3][h][w] = max(dp[3][h][w], dp[3][h][w-1], dp[2][h][w-1]+item[h][w])
ans = []
for k in range(4):
    ans.append(dp[k][-1][-1])
print(max(ans))

Measured memory_bytes: 434748
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String[] x = new String[n];
        String[] u = new String[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.next();
            u[i] = sc.next();
        }

        double result = 0;
        for (int i = 0; i < n; i++) {
            if ("JPY".equals(u[i])) {
                result += Integer.parseInt(x[i]);
            }else {
                result += Double.parseDouble(x[i]) * 380000.0;
            }
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    char s[200000+5], t[200000+5];
    int c=0;
    
    scanf("%s", s);
    scanf("%s", t);
    
    for(int i=0; i<strlen(s); i++){
        if(s[i]!=t[i]){
            c++;
        }
    }
    
    printf("%d", c);
    
    return 0;
}


Measured memory_bytes: 2088
from collections import deque
from bisect import bisect_left
N = int(input())
A = [int(input()) for _ in range(N)]
queue = deque()
for a in A:
    pos = bisect_left(queue, a)
    if (pos == 0):
        queue.appendleft(a)
    else:
        queue[pos-1] = a
print(len(queue))


Measured memory_bytes: 53592
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, l, n, ans = 0, now;
  scanf("%lld%lld", &n, &k);
  ll v[n];
  for(i = 0; i < n; ++i) scanf("%lld", &v[i]);
  for(i = 0; i <= n; ++i) for(j = 0; j < n; ++j) if(i + j <= n && i + j <= k) {
    vector<ll> vec;
    now = 0;
    for(l = 0; l < i; ++l) {
      if(v[l] < 0) vec.push_back(v[l]);
      now += v[l];
    }
    for(l = n - j; l < n; ++l) {
      if(v[l] < 0) vec.push_back(v[l]);
      now += v[l];
    }
    sort(vec.begin(), vec.end());
    for(l = 0; l < vec.size() && l < k - i - j; ++l) now -= vec[l];
    if(ans < now) ans = now;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000500
using namespace std;
typedef long long LL;
inline int rd() {int r;scanf("%d",&r);return r;}

struct Edge{int b,v,n;}e[2*N];
int siz[N],h[N],cnt,mark,g,n;
LL ans;

void link(int a,int b,int v) {
	e[++cnt] = (Edge){b,v,h[a]}, h[a] = cnt;
}

void dfs(int u,int f,int p) {
	siz[u] = 1;
	int mx = 0;
	for (int i=h[u];i;i=e[i].n) {
		int v = e[i].b, cp = e[i].v;
		if (v == f) continue;
		dfs(v, u, cp);
		siz[u] += siz[v];
		mx = max(mx, siz[v]);
	}
	mx = max(mx, n-siz[u]);
	if (siz[u]*2 == n) mark = p;
	if (mx*2 <= n) g = u;
	ans += 2LL * p * min(siz[u], n-siz[u]);
}

int main() {
	n = rd();
	for (int i=1;i<n;i++) {
		int a = rd(), b = rd(), c = rd();
		link(a, b, c);
		link(b, a, c);
	}
	
	dfs(1,1,0);
	
	if (!mark) {
		mark = 2147483647;
		for (int i=h[g];i;i=e[i].n)
			mark = min(e[i].v, mark);
	}
	cout << ans - mark << endl;
	return 0;
}

Measured memory_bytes: 15488