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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

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

  vi parent(N, -1);
  for (ll i = 1; i < N; i++) {
    cin >> parent[i];
    parent[i] -= 1;
  }

  vi X(N);
  for (ll i = 0; i < N; i++) {
    cin >> X[i];
  }

  vvi children(N);
  for (ll i = 0; i < N; i++) {
    if (parent[i] != -1) {
      children[parent[i]].push_back(i);
    }
  }

  vi v;

  // dfs
  {
    queue<ll> q;
    q.push(0);
    while (q.size()) {
      ll fr = q.front();
      q.pop();

      v.push_back(fr);

      for (ll to : children[fr]) {
        q.push(to);
      }
    }
  }

  reverse(v.begin(), v.end());

  vi Y(N, -1);

  for (ll i : v) {
    if (children[i].size() == 0) {
      Y[i] = 0;
      continue;
    }

    ll n = children[i].size();
    vvi dp(n, vi(5001, INF));
    for (ll j = 0; j < n; j++) {
      if (j == 0) {
        for (ll k = X[children[i][j]]; k <= 5000; k++) {
          dp[j][k] = min(dp[j][k], Y[children[i][j]]);
        }
        for (ll k = Y[children[i][j]]; k <= 5000; k++) {
          dp[j][k] = min(dp[j][k], X[children[i][j]]);
        }
      } else {
        for (ll k = X[children[i][j]]; k <= 5000; k++) {
          dp[j][k] = min(dp[j][k],
                         dp[j - 1][k - X[children[i][j]]] + Y[children[i][j]]);
        }
        for (ll k = Y[children[i][j]]; k <= 5000; k++) {
          dp[j][k] = min(dp[j][k],
                         dp[j - 1][k - Y[children[i][j]]] + X[children[i][j]]);
        }
      }
    }

    Y[i] = dp[n - 1][X[i]];

    if (Y[i] == INF) {
      cout << "IMPOSSIBLE" << endl;
      return 0;
    }
  }

  cout << "POSSIBLE" << endl;
}


Measured memory_bytes: 39424
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    final Scanner sc = new Scanner(System.in);
    final int num = sc.nextInt();
    final List<Long> a = new ArrayList<Long>();
    final long mod = (int) Math.pow(10, 9) + 7;

    for (int i = 0; i < num; i++) {
      a.add(sc.nextLong());
    }

    Long sum = 0L;
    for (int i = 1; i < a.size(); i++) {
      sum = (sum + a.get(i)) % mod;
    }

    Long total = 0L;
    for (int i = 0; i < a.size() - 1; i++) {
      if (i != 0) {
        sum -= a.get(i);
      }
      if (sum <= 0L) {
        sum += mod;
      }
      final Long addedNum = (a.get(i) * sum) % mod;
      total += addedNum;
      total %= mod;
    }

    System.out.println(total);
  }
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int pins[1000];
    fill(pins, pins + 1000, 0);
    for (char c: s) {
        for (int i = 0; i < 10; i++) {
            if (pins[i * 100] > 0) {
                for (int j = 0; j < 10; j++) {
                    if (pins[i * 100 + j * 10] > 1) {
                        pins[i * 100 + j * 10 + c - '0'] = 3;
                    } else if (j == c - '0') {
                        for (int k = 0; k < 10; k++) {
                            pins[i * 100 + j * 10 + k]++;
                        }
                    }
                }
            } else if (i == c - '0') {
                for (int j = 0; j < 100; j++) {
                    pins[i * 100 + j]++;
                }
            }
        }
    }
    int ans = 0;
    for (int x: pins) {
        if (x == 3)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
X, N = map(int, input().split())
P = list(map(int, input().split()))

C = list({i for i in range(0, 101+1)} - set(P))
C.sort()
dist = float('inf')
result = None
for i in C:
    if abs(X - i) < dist:
        result = i
        dist = abs(X - i)

print(result)

Measured memory_bytes: 9212
# https://atcoder.jp/contests/agc006/tasks/agc006_a

n = int(input())
s = input()
t = input()

string = s + t
ans = len(string)

for i in range(len(string)):
    for j in range(i, len(string)):
        sub = string[:i] + string[j:]
        if len(sub) >= n:
            if sub[:n] == s and sub[-n:] == t:
                ans = min(ans, len(sub))
print(ans)

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

// limit
#define mod1 22439423LL
#define mod2 42342432LL
#define mod3 56454765LL
#define mod4 66867574LL
#define oo 1000000007LL
#define OO 1000000000000000007LL
#define maxN 100007

// loop
#define fto(i, x, y) for(int i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(int i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(int i = (x); i <= (y); i += a)
#define fdtoa(i, x, y, a) for(int i = (x); i >= (y); i -= a)
#define ftosqrt(i, x, y) for(int i = (x); i*i <= (y); ++i)
#define ftoit(it, var) for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define fdtoit(rit, var) for (__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); ++rit)

// debug
#define debug cout << "*" << endl;
#define bug1d(a, x, y) { cout << #a << ": "; fto(_, x, y) cout << a[_] << ' '; cout << endl; }
#define bug2d(a, x, y, u, v) { cout << #a << ": " << endl; fto(i, x, y) {fto(j, u, v) cout << a[i][j] << ' '; cout << endl;}; cout << endl;}
#define bug(a) cout << #a << " = " << a << endl;
#define bug2(a, b) cout << #a << " = " << a << "; "; cout << #b << " = " << b << endl;
#define bug3(a, b, c) cout << #a << " = " << a << "; "; cout << #b << " = " << b << "; "; cout << #c << " = " << c << endl;

// operation
#define mp make_pair
#define pb push_back
#define pf push_front
// structure
#define ii pair<int, int>
#define iii pair<ii, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define matrix vector<vi>

// get value
#define FF first
#define SS second

// data type
#define ll long long
#define ull unsigned long long

// function
#define lb lower_bound
#define ub upper_bound

// const value
#define pi 3.14159265358979323846264338327950288419716939937510

using namespace std;

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T min(T a, T b, T c, T d) {
    return min(a, min(b, min(c, d)));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

template <class T>
T max(T a, T b, T c, T d) {
    return max(a, max(b, max(c, d)));
}

bool cmp(const ii& a, const ii& b) {return (a.FF > b.FF || (a.FF == b.FF && a.SS >= b.SS));}
ll GCD(ll a, ll b) {return (a%b) ? GCD(b, a%b) : b;}

const string namePro = "tmp";

ll a[maxN];

int main() {

    int n; scanf("%d", &n);
    fto (i, 1, n) scanf("%lld", &a[i]);

    ll res1 = 0LL;
    ll res2 = 0LL;

    ll preSum = -1LL;
    ll sum = 0LL;
    fto (i, 1, n) {
        sum += a[i];
        if (sum >= 0LL && preSum > 0LL) {
            res1 += sum+1LL;
            sum = -1LL;
        }
        else if (sum <= 0LL && preSum < 0LL) {
            res1 -= sum-1LL;
            sum = 1LL;
        }
        preSum = sum;
    }

    preSum = 1LL;
    sum = 0LL;
    fto (i, 1, n) {
        sum += a[i];
        if (sum >= 0LL && preSum > 0LL) {
            res2 += sum+1LL;
            sum = -1LL;
        }
        else if (sum <= 0LL && preSum < 0LL) {
            res2 -= sum-1LL;
            sum = 1LL;
        }
        preSum = sum;
    }

    cout << min(res1, res2) << endl;
    return 0; 
}

Measured memory_bytes: 1024
def CountingSort(A, B, k):
    C = [0 for i in range(k+1)]
    n = len(A)
    #C[i]???i???????????°????¨??????????
    for j in range(n):
        C[A[j]] += 1

    #C[i]???i??\????????°???????????°????¨??????????
    for i in range(1, k+1):
        C[i] = C[i] + C[i-1]

    for j in range(n)[::-1]:
        B[C[A[j]]-1] = A[j]
        #print(C[A[j]])
        C[A[j]] -= 1


n = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(n)]
CountingSort(A, B, max(A))
print(*B)

Measured memory_bytes: 229448
n = int(input())
ls_a = list(map(int, input().split()))

s = 0
S = 0
half = sum(ls_a)/2

for i in range(n):
    s = S
    S += ls_a[i]
    if S > half:
        break

print(int(min(abs(half - s)*2, abs(half - S)*2)))

Measured memory_bytes: 26220
#include <vector>
#include <iostream>
#include <map>

using namespace std;

//A must larger than B
long long gcd(long long A, long long B){
    if(B ==0) return A;
    else return gcd(B, A % B);
}

vector<pair<long long, long long> > prime_fac(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

// map<long long, long long> prime_fac(long long N){
//     map<long long, long long> res;
//     for(long long i=2; i<N; ++i){
//         if(N%i != 0) continue;
//         long long ex = 0;

//         while(N%i ==0){
//             ex++;
//             N /= i;
//         }
        
//         res[i] = ex;
//     }
//     if(N != 1) res[N] = 1;

//     return res;
// }


int main(){
    long long A, B;
    cin >> A >> B;

    long long g = gcd(A, B);

    // const auto& resA = prime_fac(A);
    // const auto& resB = prime_fac(B);

    // all the numbers should have 1 as the prime 
    const auto& res = prime_fac(g);
    long long ans = 1 + (long long)res.size();


    // for(auto pA: resA){
    //     if( resB.count(pA.first) > 0){
    //         count++;
    //     }
    // }


    cout << ans << endl;

}

Measured memory_bytes: 256
#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

import numpy as np
n, m = map(int, input().split( ))

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

for i in range(m):
    x,y=map(int,input().split(' '))
    unite(x-1,y-1)

# print(par)
print(-min(par))

Measured memory_bytes: 32444
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }

    void solve(){
        string s;
        cin>>s;
        ll total=0;
        for(int i=0;i<(int)s.size();i++){
            total+=(int)(s[i]-'0');
        }
        if(total%9==0)
            cout<<"Yes";
        else
        {
            cout<<"No";
        }
        
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

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

int main(){
  int n,i,cnt=0,saisho=0;
  cin>>n;
  char a;
  for(i=0;i<n;i++){
    cin>>a;
    if(a=='#'){
      cnt++;
    }else{
      cnt--;
    }
    saisho=min(saisho,cnt);
  }
  cout<<(n-cnt)/2+saisho;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 10007;
const ld PI = acosl(-1);

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

    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];

    auto isok = [&](int x) -> bool {
        ll res = 0;
        for (int i = 0; i < N; ++i)
            res += (A[i] - 1) / x;
        return res <= K;
    };

    ll ok = 1e9, ng = 0;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        (isok(mid) ? ok : ng) = mid;
    }

    cout << ok << endl;

    return 0;
}


Measured memory_bytes: 3964
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    N, X, Y = iip()
    X -= 1
    Y -= 1

    ret = 0

    result = []
    for k in range(1, N):
        ret = 0
        for i in range(N):
            ret += search(i, k, N, X, Y)
        result.append(str(ret))

    print("\n".join(result))

def search(a, k, N, X, Y):
    kouho = []

    if abs(a-X)+1+abs(a+k-Y) >= k and abs(a-Y) + 1 + abs(a+k-X) >= k:
        #print(f"追加 {a+k} a, k = {a}, {k} by 条件1")
        kouho.append(a+k)

    asy = k-abs(a-X)-1
    if asy < 0:
        pass
    elif asy == 0:
        if abs(a-X) + 1 <= abs(a-Y):
            kouho.append(Y)
            #print(f"追加 {Y} a, k = {a}, {k} by 条件6")
    else:
        if abs(a-(Y-asy)) > k:
            kouho.append(Y-asy)
            #print(f"追加 {Y-asy} a, k = {a}, {k} by 条件2")
        if abs(a-(Y+asy)) > k:
            #print(f"追加 {Y+asy} a, k = {a}, {k} by 条件3")
            kouho.append(Y+asy)

    asx = k-abs(a-Y)-1
    if asx < 0:
        pass
    elif asx == 0:
        if abs(a-Y) + 1 < abs(a-X):
            kouho.append(X)
            #print(f"追加 {X} a, k = {a}, {k} by 条件7")
    else:
        if abs(a-(X-asx)) > k:
            kouho.append(X-asx)
            #print(f"追加 {X-asx} a, k = {a}, {k} by 条件4")
        if abs(a-(X+asx)) > k:
            kouho.append(X+asx)
            #print(f"追加 {X+asx} a, k = {a}, {k} by 条件5")

    kakutei = []
    result = 0
    for kh in kouho:
        if kh == a:
            continue
        if kh < 0:
            continue
        if kh > N-1:
            continue
        if kh in kakutei:
            continue
        if kh < a:
            continue
        kakutei.append(kh)
        result += 1
    #print(f"--result開始 a, k = {a}, {k}")
    #print(result)
    #print(kakutei)
    #print("--result終了")
    return result



if __name__ == "__main__":
    main()

Measured memory_bytes: 73052
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}



int n, k;
ll DP[2002][2002][2], ways[2002];


ll dp(int i, int left, bool ok){
	int used = n-i  - left;
	if(left < 0)	return 0;
	if(used > k)	return 0;
	if(i == 1 && used != k){
		ll ans = 0;
		if(left > 0 && ok)
			ans = dp(1, left-1, true);
// cout<<"dp "<<i<<" "<<left<<" "<<ok<<" returns "<<ans<<endl;
		return ans;
	}
	if(used == k || i == 1){
// cout<<"dp "<<i<<" "<<left<<" "<<ok<<" returns 1"<<endl;
		return 1;
	}
	ll &ans = DP[i][left][ok];
	if(ans != -1)	return ans;

	ans = dp(i-1, left, true) + dp(i-1, left+1, false);
	ans %= MOD;
	if(left > 0 && ok){
		ans += dp(i, left-1, true);
		ans %= MOD;
	}
// cout<<"dp "<<i<<" "<<left<<" "<<ok<<" returns "<<ans<<endl;
	return ans;
}


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

    cin>>n>>k;

    ways[0] = ways[1] = 1;
    for(int i=2;i<=n;i++)
    	ways[i] = (ways[i-1] * 2) % MOD;

    memset(DP, -1, sizeof(DP));
    k--;
    ll ans = (dp(n, 0, false) * ways[n-k-1]) % MOD;
    cout<<ans;
    return 0;
}








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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template < typename T > 
struct BIT {
    vector < T > dat;

    BIT (int n) { dat.assign(n + 1, 0); }

    void add(int k, T x) {
        k++;
        while ( k < dat.size() ) dat[k] += x, k += k & -k;
    }

    T query(int k) {
        T sum = 0;
        k++;
        while ( k > 0 ) sum += dat[k], k -= k & -k;
        return ( sum );
    }

    int lower_bound(T x) {
        int l, r;
        l = -1, r = dat.size();
        while ( l + 1 < r ) {
            int m = (l + r) / 2;
            if ( query(m) >= x ) r = m;
            else l = m;
        }
        return ( r );
    }
};

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

    BIT<int> tree(M + 2);
    vint L(N), R(N);
    vector<Pi> length(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i] >> R[i];
        length[i] = Pi(R[i] - L[i] + 1, i);
    }
    sort(begin(length), end(length)); 
    int cur = 0;
    for (int i = 1; i <= M; i++) {
        while (cur < N && length[cur].first < i) {
            auto idx = length[cur].second;
            tree.add(L[idx], 1);
            tree.add(R[idx] + 1, -1);
            cur++;
        }
        int cnt = 0;
        for (int j = 0; j <= M; j += i) {
            cnt += tree.query(j);
        }
        cout << (N - cur) + cnt << el;
    }

    return ( 0 );
}

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

using ll=long long;
const ll z=0;

int main() {
  ll N,sum=z;
  cin >> N;
  vector<ll> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec[i];
    sum +=vec[i];
  }
  cout << sum-N << endl;
}

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

int main(void){
  int i;
  char s[1000];
  scanf("%s", &s);
  i = strlen(s);
  if(s[i - 1] == 's'){
    printf("%s", s);
    printf("es");
  }
  else{
    printf("%s", s);
    printf("s");
  }
  return 0;
}

Measured memory_bytes: 1728
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Inet4Address;
import java.nio.charset.IllegalCharsetNameException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int k = Integer.parseInt(st.nextToken());
            int[] a = new int[n];
            st = new StringTokenizer(br.readLine());
            for(int i=0 ; i<n ; i++) {
                a[i] = Integer.parseInt(st.nextToken());
            }
            Arrays.sort(a);
            
            long sum = 0;
            for(int i=0 ; i<k ; i++) {
                sum += a[i];
            }
            
            pw.println(sum);
        }
        finally {
            pw.flush();
            pw.close();
        }
    }
}



Measured memory_bytes: 33132
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

class State {
public:
  int pos;
  int cost;
  int prev_hand;
  int prev_pos;
  State(int _p,int _c) : pos(_p),cost(_c),prev_hand(-1000),prev_pos(-1000) {}
  State(int _p,int _c,int _ph,int _pp) : pos(_p),cost(_c),prev_hand(_ph),prev_pos(_pp) {}
  bool operator<(const State& s) const{
    return cost < s.cost;
  }
  bool operator>(const State& s) const{
    return cost > s.cost;
  }
};

struct DP{
  int cost;
  int prev_hand;
  int prev_pos;
  DP(int _c,int _ph,int _pp) : cost(_c),prev_hand(_ph),prev_pos(_pp){}
  DP() : cost(INF),prev_hand(-1000),prev_pos(-1000){}
};

int main(){
  int total_cells;
  while(~scanf("%d",&total_cells)){
    int dice[7];
    for(int i=1;i<=6;i++){
      scanf("%d",dice + i);
    }
    int start,goal;
    scanf("%d %d",&start,&goal);
    int stage[303];
    for(int i=1;i<=total_cells;i++){
      scanf("%d",stage + i);
    }
    
    priority_queue<State,vector<State>,greater<State> > que;
    que.push(State(start,0,-1000,-1000));

    DP dp[303];

    while(!que.empty()){
      State s = que.top();
      que.pop();

      if(dp[s.pos].cost <= s.cost) continue;

      dp[s.pos].cost = s.cost;
      dp[s.pos].prev_hand = s.prev_hand;
      dp[s.pos].prev_pos = s.prev_pos;

      for(int i=1;i<=6;i++){
        int dx1 = s.pos + dice[i];
        int dx2 = s.pos - dice[i];

        if(1 <= dx1 && dx1 <= total_cells){
          dx1 += stage[dx1];
          que.push(State(dx1,s.cost + 1,i,s.pos));
        }
        if(1 <= dx2 && dx2 <= total_cells){
          dx2 += stage[dx2];
          que.push(State(dx2,s.cost + 1,-i,s.pos));
        }
      }
    }

    vector<int> hands;
    int prev_x = goal;
    for(int round = 0;round <= 3000;round++){
      hands.push_back(dp[prev_x].prev_hand);
      prev_x = dp[prev_x].prev_pos;
      if(prev_x == start) break;
    }

    reverse(hands.begin(),hands.end());

    int hand_idx = 0;
    for(int round = 0;round <= 3000;round++){
      int num;
      scanf("%d", &num);
      
      if(num != abs(hands[hand_idx])){
        printf("0\n"); fflush(stdout);
      }

      else if(num == abs(hands[hand_idx])){
        if(hands[hand_idx] > 0){
          printf("1\n"); fflush(stdout);
        }
        else{
          printf("-1\n"); fflush(stdout);
        }
        hand_idx++;
      }

      if(hand_idx >= hands.size()) break;
    }
  }
}

Measured memory_bytes: 1304
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
template<class T> inline bool chmax(T& a, T b) { if(a<b) { a = b; return 1;} return 0; }
// clang-format on

int N;
ll K;
ll A[MAX_N];
const int MAX_DIGIT = 50;
ll dp[100][2];

int main(void)
{
  cin >> N >> K;
  REP(i, N) cin >> A[i];

  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;

  for (int d = 0; d < MAX_DIGIT; ++d) {
    ll mask = 1LL << (MAX_DIGIT - d - 1);

    int num = 0;
    for (int i = 0; i < N; i++)
      if (A[i] & mask) ++num;

    ll cost0 = mask * num;
    ll cost1 = mask * (N - num);

    if (dp[d][1] != -1) {
      chmax(dp[d + 1][1], dp[d][1] + max(cost0, cost1));
    }

    if (dp[d][0] != -1) {
      if (K & mask) {
        chmax(dp[d + 1][1], dp[d][0] + cost0);
      }
    }

    if (dp[d][0] != -1) {
      if (K & mask)
        chmax(dp[d + 1][0], dp[d][0] + cost1);
      else
        chmax(dp[d + 1][0], dp[d][0] + cost0);
    }
  }

  cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    int cntmax=0;
    
    for(int i=1; i<s.size()-1; i++){
        bool ss[26]={false}; 
        bool tt[26]={false};
        
        int cnt=0;
        
        for(int j=0; j<i; j++){
            ss[s[j]-'a']=true;
        }
        
        for(int j=i; j<s.size(); j++){
            tt[s[j]-'a']=true;
        }
        
        for(int j=0; j<26; j++){
            if(ss[j]&&tt[j]){
                cnt++;
            }
        }
        
        cntmax=max(cnt, cntmax);
        
    }
    
    cout<<cntmax<<endl;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int64 cnt[510][510] = {};

int main(void){
	int32 N, M, Q;
	cin >> N >> M >> Q;
	REP(i, M){
		int32 L, R;
		cin >> L >> R; L--; R--;
		cnt[L][R]++;
	}
	REP(i, N){
		REP(j, N){
			cnt[i][j+1] += cnt[i][j];
		}
	}
	REP(i, Q){
		int32 p, q;
		cin >> p >> q; p--; q--;
		int64 res = 0;
		FOR(i, p, q+1){
			res += cnt[i][q];
		}
	cout << res << endl;
	}
}


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

int main() {
    int N;
    string s, t;
    cin >> N >> s >> t;
    int l = s.length() + t.length();
    for (size_t i = 0; i < s.length(); i++) {
        if (string(t.begin(), t.begin() + i + 1) == string(s.end() - i - 1, s.end())) {
            l = s.length() + t.length() - i - 1;
        }
    }
    cout << max(N, l) << endl;
}


Measured memory_bytes: 256
let () =
	let h, w = Scanf.scanf "%d %d\n" (fun x y -> (x, y)) in
	Printf.printf "%s\n" (String.make (w + 2) '#');
	for i = 1 to h do
		Printf.printf "#%s#\n" (Scanf.scanf "%s\n" (fun x -> x))
	done;
	Printf.printf "%s\n" (String.make (w + 2) '#')


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int a, b, c;
  cin>>a>>b>>c;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    if (c%i==0) ans++;
  } 
  cout<<ans<<endl;
}



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

int main() {
	int N; cin >> N;
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}

	vector<char> S(N);
	for (int i = 0; i < N; i++) { cin >> S[i]; }

	int c = 1;
	for (int i = 0, j = 1; j < N; i++, j++) {
		if (S[i] == S[j]) {
		}
		else {
			c++;
		}
	}

	cout << c << endl;
}

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

int main(){
    vector<string> s = {"Sunny", "Cloudy", "Rainy"};
    string t;
    cin >> t;
    for (int i = 0; i < 3; i++){
        if (t == s[i]){
            cout << s[(i + 1) % 3] << endl;
            exit(0);
        }
    }
}

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

	#define scanI(n)    scanf("%d", &n)
	#define scanII(a, b) scanf("%d %d", &a, &b)
	#define scanIII(a, b, c) scanf("%d %d %d", &a, &b, &c)
	#define printI(n) printf("%d", n)
	#define printII(a,b) printf("%d %d", a, b)
	#define ALL(x) x.begin(), x.end()
	#define VI vector<int>
	#define LL long long
	#define PRINT(list) for(auto i : list) printf("%d ", i); printf("\n");
	#define PRINTARR(ar_, n_) for(int i_=0; i_<n_; i_++){printf("%d ", ar_[i_]);} printf("\n");
	#define DPRINT(dlist) for(auto list : dlist) { PRINT(list); printf("\n"); }
	#define INIT(ar, n, val) for(int _i=0; _i<n; _i++) ar[_i] = val;
	#define MOD 1000000007
        #define PI 3.142857
	#define MAX_OP [](int a, int b){return max(a,b);}
	#define MIN_OP [](int a, int b){return min(a,b);}


	using namespace std;

	void test(){

	}

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

        int chars[26] = {0};

        for(auto c : s)
            chars[c-'a']++;
        int i=0;
        for(; i<26; i++){
            if(!chars[i]){
                printf("%c\n", 97+i);
                break;
            }
        }
        if(i>=26)
            printf("None");
	    return 0;
	}



Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>

using namespace std;
typedef long long ll;

int H, W;
char c[55][55];
int xc[4] = {-1, 1, 0, 0};
int yc[4] = {0, 0, -1, 1};

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> H >> W;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            cin >> c[i][j];

    bool works = true;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
        {
            if (c[i][j] == '#')
            {
                bool found = false;
                for (int k = 0; k < 4; k++)
                {
                    int ni = i + xc[k], nj = j + yc[k];
                    if (ni < 0 || ni >= H || nj < 0 || nj >= W)
                        continue;
                    if (c[ni][nj] == '#')
                        found = true;
                }
                if (!found) works = false;
            }
        }
    if (works) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N_MAX = 40, ab_MAX = 10,inf=100000000;
int dp[N_MAX + 1][N_MAX*ab_MAX + 1][N_MAX*ab_MAX + 1];
int main() {
	int N, ma, mb; cin >> N >> ma >> mb;
	for (int i = 0; i < N_MAX + 1; i++) {
		for (int j = 0; j < N_MAX*ab_MAX + 1; j++) {
			for (int k = 0; k < N_MAX*ab_MAX + 1; k++) {
				dp[i][j][k] = inf;
			}
		}
	}
	dp[0][0][0] = 0;
	int A[N], B[N], C[N];
	for (int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N_MAX*ab_MAX + 1; j++) {
			for (int k = 0; k < N_MAX*ab_MAX + 1; k++) {
				if (dp[i][j][k] == inf) continue;
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
				dp[i + 1][j + A[i]][k+ B[i]] = min(dp[i + 1][j + A[i]][k + B[i]], dp[i][j][k] + C[i]);
			}
		}
	}
	int ans = inf;
	for (int j = 1; j < N_MAX*ab_MAX + 1; j++) {
		for (int k = 1; k < N_MAX*ab_MAX + 1; k++) {
			//if (dp[N][j][k] == inf) continue;
			if (ma*k == mb * j)  ans = min(ans, dp[N][j][k]);
		}
	}
  if(ans==inf) {cout<<-1<<endl; return 0;}
	cout << ans << endl;
}


Measured memory_bytes: 25984
n = int(input())
s = input()

w = []
for i in range(n):
  if s[i] == 'W':
    diff = 1
  else:
    diff = 0
  
  if i == 0:
    w += [diff]
  else:
    w += [w[i - 1] + diff]

min_turns = n
for i in range(n):
  if i == 0:
    turns = n - 1 - (w[n - 1] - w[i])
  elif i == n - 1:
    turns = w[i - 1]
  else:
    turns = w[i - 1] + n - (i + 1) - (w[n - 1] - w[i])
  
  if turns < min_turns:
    min_turns = turns

print(min_turns)

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

int main() {
    int n , k; cin >> n >> k;
    int x = 10000 , y = 5000 , z = 1000;
    int ansx , ansy , ansz;
    bool exted = false;

    for (int a = 0;a <= n; a++) {
        for (int b = 0;b + a <= n; b++) {
            int c = n -a -b;
            int total = x * a + y * b + z * c;
            if (k == total) {
                ansx = a;
                ansy = b;
                ansz = c;
                exted = true;
                break;
            } 
        }
    }
    if (exted) cout << ansx << " " << ansy << " " << ansz << endl;
    else cout << -1 << " " << -1 << " " << -1 << " " << endl;
    return 0;
}

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

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

	int n, x; cin >> n >> x;
	vector<int> a;
	a.push_back(x);
	for(int i = 0; i < n; i++) {
		int t; cin >> t;
		a.push_back(t);
	}
	sort(a.begin(), a.end());
	int ans = a[1] - a[0];
	for(int i = 1; i < a.size(); i++) {
		ans = __gcd(ans, a[i] - a[i - 1]);
	}
	cout << ans << endl;
  return 0;
}	


Measured memory_bytes: 892
package main

import (
	"fmt"
)

var n, m int

type ans struct {
	p int
	s string
}

type seiseki struct {
	pneCount int
	isAC     bool
}

func main() {
	fmt.Scan(&n)
	fmt.Scan(&m)

	ss := make(map[int]*seiseki)
	for i := 0; i < m; i++ {
		a := new(ans)
		fmt.Scan(&a.p)
		fmt.Scan(&a.s)

		if _, ok := ss[a.p]; !ok {
			ss[a.p] = &seiseki{}
		}
		if ss[a.p].isAC {
			continue
		}
		if a.s == "AC" {
			ss[a.p].isAC = true
		}
		if a.s == "WA" {
			ss[a.p].pneCount++
		}
	}

	account := 0
	wacount := 0
	for _, mm := range ss {
		if mm.isAC {
			account++
			wacount += mm.pneCount
		}
	}

	fmt.Printf("%d %d", account, wacount)
}


Measured memory_bytes: 8704
#include<bits/stdc++.h>
#include <bitset>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dcm(a) setprecision(a)<<fixed
#define MOD 1000000007
#define clr(memo, a) memset(memo,a,sizeof(memo))
#define PI acos(-1)

int const N=1e5+5;
int const inf=1e9+5;
void solve(){
int n;
cin>>n;
vector<int> dp(n,inf);
vector<int> v(n);
for(int i=0;i<n;i++)
    cin>>v[i];
dp[0]=0;
dp[1]=abs(v[1]-v[0]);
for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
}
cout<<dp[n-1]<<endl;
}
int main(){
    fast;

solve();

return 0;}


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

using namespace std;

int main()
{
   int n,k,ans=0;
   cin>>n>>k;
   int a[n];
   for(int i=0;i<n;i++) cin>>a[i];
   sort(a,a+n);
   for(int i=0;i<k;i++) ans+=a[i];
   cout<<ans;
   return 0;
}

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

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

    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> dist;
    for (size_t i = 0; i < a.size() - 1; i++) {
        dist.push_back(a[i + 1] - a[i]);
    }
    dist.push_back(k - a.back() + a.front());

    int max_dist = 0;
    int ans = 0;
    for (auto d : dist) {
        max_dist = max(d, max_dist);
        ans += d;
    }
    cout << ans - max_dist << endl;
}

Measured memory_bytes: 2168
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  int a,b;
  char op;
  while(true){
    cin >> a >> op >> b;
    if(op == '?'){
      break;
    }
    else{
      switch(op){
        case '+':
          cout << a+b << endl;
          break;
        case '-':
          cout << a-b << endl;
          break;
        case '*':
          cout << a*b << endl;
          break;
        case '/':
          cout << a/b << endl;
          break;
        default:
          break;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3120
loop {
m,f,r=gets.split(" ").map(&:to_i)
break if m==-1 && f==-1 && r==-1

grade="F"
if m == -1 or f == -1

elsif (m + f) >=80 
    grade= "A"
elsif (m + f) >=65
    grade= "B"
elsif (m + f)>=50
    grade="C"
elsif (m + f)>=30
    if r >= 50
        grade= "C"
    else
        grade= "D"
    end
end

puts grade


}








Measured memory_bytes: 6876
def exchange a, i, j
  tmps = a[i][0]
  tmpn = a[i][1]
  tmpid = a[i][2]
  a[i][0] = a[j][0]
  a[i][1] = a[j][1]
  a[i][2] = a[j][2]
  a[j][0] = tmps
  a[j][1] = tmpn
  a[j][2] = tmpid
end

def partition a, p, r
  x = a[r][1]
  i = p - 1
  for j in p..r-1
    if a[j][1] <= x
      i += 1
      exchange a,i,j
    end
  end
  exchange a,i+1,r
  i + 1
end

def quicksort a, p, r
  if p < r
    q = partition(a,p,r)
    quicksort a,p,q-1
    quicksort a,q+1,r
  end
end

def isStable a
  0.step(a.size - 2, 1).each do |i|
    p = a[i]
    n = a[i+1]
    return false if p[1] == n[1] && p[2] > n[2]
  end
  true
end

card = Array.new
$stdin.gets.to_i.times do |i|
  s,n = $stdin.gets.chomp.split(" ")
  card << [s, n.to_i, i]
end
quicksort card,0,card.size-1
puts (isStable(card))? "Stable" : "Not stable"
card.each do |d|
  printf "%s %d\n", d[0], d[1]
end

Measured memory_bytes: 31404
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a[n],max,min,i;
    for( i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    max=a[0];
    for(i=1;i<n;i++){
        if(max<a[i])
            max=a[i];
    }
    min=a[0];
    for(i=1;i<n;i++){
        if(min>a[i])
            min=a[i];
    }
    printf("%d\n",max-min);
        return 0;
}


Measured memory_bytes: 1708
from collections import Counter


MOD = 998244353


def power(a, n, p=MOD):
    res = 1
    for _ in range(n):
        res *= a
        res %= p
    return res


n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
    exit(0)

d = Counter(sorted(d))
if d[0] > 1:
    print(0)
    exit(0)

d = sorted(d.items())
prev_index = -1
prev_count = 1

ans = 1
for k, v in d:
    if k != prev_index+1:
        print(0)
        exit(0)
    ans *= power(prev_count, v)
    ans %= MOD
    prev_index = k
    prev_count = v
print(ans)


Measured memory_bytes: 20796
N = int(input())
A = list(map(int,input().split()))
L = [0]*N
H = [0]*N
for i,a in enumerate(A):
    if 0 <= i+a < N:
        L[i+a] += 1
    if 0 <= i-a < N:
        H[i-a] += 1
ans = 0
for l,h in zip(L,H):
    ans += l*h
print(ans)

Measured memory_bytes: 32236
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DAtCoderExpress2 solver = new DAtCoderExpress2();
        solver.solve(1, in, out);
        out.close();
    }

    static class DAtCoderExpress2 {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int m = in.scanInt();
            long dp[][] = new long[n + 1][n + 1];
            int q = in.scanInt();
            for (int i = 0; i < m; i++) {
                int l = in.scanInt();
                int r = in.scanInt();
                dp[l][r]++;
            }

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    dp[i][j] += dp[i][j - 1];
                }
            }


            for (int j = 1; j <= n; j++) {
                for (int i = 1; i <= n; i++) {
                    dp[i][j] += dp[i - 1][j];
                }
            }


            while (q-- > 0) {
                int x = in.scanInt();
                int y = in.scanInt();
                out.println(dp[y][y] - dp[x - 1][y]);
            }


        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



Measured memory_bytes: 31100
#include <iostream>
#include <cstdio>

using namespace std;

int n;
long long a[10001], b[10001];
long long sa, sb, na, nb;

int abs(int a)
{
    if (a<0) return -a;
    return a;
}

void read()
{
    cin >> n;
    for (int i=1;i<=n;++i) {cin >> a[i]; sa+=a[i];}
    for (int i=1;i<=n;++i) {cin >> b[i]; sb+=b[i];}
}

void solve()
{
    /*if (sa>sb) {cout << "NO"; return;}
    if (sa==sb)
    {
        for (int i=1;i<=n;++i)
        if (a[i]!=b[i]) {cout << "No"; return;}
        cout << "Yes"; return;
    }
    else
    {*/
        for (int i= 1; i<=n; ++i)
        {
            if (a[i]>b[i])
            {
                na+= a[i] - b[i];
            }
            if (b[i]>a[i])
            {
                nb+= (b[i] - a[i])/2;
            }
        }
        if (na>nb) {cout << "No"; return;}
        cout << "Yes";
    /*}*/
}

int main()
{
    //freopen("inp.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    read(); solve();
    return 0;
}


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

X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

res = []

for i in range(X):
    for j in range(Y):
        sup = min(K //((i+1)*(j+1)),Z)
        for k in range(sup):
            res.append(A[i]+B[j]+C[k])

res.sort(reverse=True)

for ans in res[:K]:
    print(ans)

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

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

    if(x>=30){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return 0;

}
/*


*/


Measured memory_bytes: 3512
#include <iostream>
#include <vector>
#include <string>
using namespace std;



int main()
{
	int N, M;
	vector<string> U;
	bool flag = true;
	string str;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> str;
		U.push_back(str);
	}

	cin >> M;

	for (int i = 0; i < M; i++) {
		cin >> str;

		bool f = false;

		for (int j = 0; j < N; j++) {
			if (str == U[j]) {
				if (flag == true) {
					cout << "Opened by " << U[j] << endl;
					flag = false;
				}
				else {
					cout << "Closed by " << U[j] << endl;
					flag = true;
				}
				f = true;
				break;
			}
		}

		if (f == false) {
			cout << "Unknown " << str << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3228
/**
 * 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() {

}

typedef long long ll;
ll a[123456];
unordered_map<ll, ll>mp;
// Returns value of Binomial Coefficient C(n, k) O(n)时间, O(1)空间
ll binomialCoeff(int n, int k)
{
	ll res = 1;

	// Since C(n, k) = C(n, n-k)
	if ( k > n - k )
		k = n - k;

	// Calculate value of [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
	for (int i = 0; i < k; ++i)
	{
		res *= ll(n - i);
		res /= ll(i + 1);
	}

	return res;
}
class DCandyDistribution {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n, m;
		in >> n >> m;
		mp.clear();
		memset(a, 0, sizeof(a));
		ll sum = 0;
		for (int i = 1; i <= n; ++i) {
			in >> a[i];
			a[i] += a[i-1];
			a[i] %= m;
			mp[a[i]]++;
		}
		for (auto it = mp.begin(); it != mp.end(); ++it) {
			if(it->second >= 2 && it->first != 0)sum += it->second * (it->second-1) / 2;
			else if(it->first == 0)sum += it->second * (it->second - 1) / 2;
			if(it->first == 0) sum += it->second;
//			sum += it->second;
		}
		out << sum << '\n';
	}
};


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

Measured memory_bytes: 4620
import java.util.*;

public class Main {
  public static void main(String[] args) {
    List<Integer> numsList = new ArrayList<Integer>();

    createNumsList(numsList);

    System.out.println(String.format("%d %d %d",  getSmallestVal(numsList),
                                                  getLargestVal(numsList),
                                                  getSummation(numsList)));
  }

  private static void createNumsList(List<Integer> numsList) {
    Scanner sc = new Scanner(System.in);
    int count = sc.nextInt();

    for (int i = 0; i < count; i++) {
      numsList.add(sc.nextInt());
    }
  }

  private static int getSmallestVal(List<Integer> numsList) {
    int minVal = 1000000;
    for (int num : numsList) {
      if (num < minVal) {
        minVal = num;
      }
    }
    return minVal;
  }

  private static int getLargestVal(List<Integer> numsList) {
    int maxVal = -1000000;
    for (int num : numsList) {
      if (num > maxVal) {
        maxVal = num;
      }
    }
    return maxVal;
  }

  private static long getSummation(List<Integer> numsList) {
    long result = 0;
    for (int num : numsList) {
      result += num;
    }
    return result;
  }
}

Measured memory_bytes: 42872
import numpy as np
n,m=map(int,input().split())
x=list(map(int,input().split()))

arr=np.array(sorted(x))
dif=np.diff(arr)

lis=dif.tolist()
lis=sorted(lis)

for i in range(n-1):
    if len(lis)>0:
        lis.pop()

print(sum(lis))

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

int days_of_month(int year, int month) {
    if (year % 3 == 0) return 20;
    if (month % 2 == 1) return 20;
    return 19;
}

int days_of_year(int year) {
    if (year % 3 == 0) return 200;
    return 195;
 }

int nokori_days(int year, int month, int day) {
    int result = 0;
    result += days_of_month(year, month) - day + 1;
    for(int m=month+1; m<=10; m++) {
        result += days_of_month(year, m);
    }
    for(int y=year+1; y<=999; y++) {
        result += days_of_year(y);
    }
    return result;
}

int main(void) {
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        int y, m, d;
        cin >> y >> m >> d;
        cout << nokori_days(y, m, d) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160