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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<ll> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;


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

    vector<vector<int>> table(26);
    rep(i, ss.size()) {
        char c = ss[i];
        int j = c - 'a';
        table[j].push_back(i);
    }

    for (char c : t) {
        if (table[c - 'a'].empty()) {
            cout << -1 << endl;
            ret();
        }
    }

    ll prev = 0;
    for (char c : t) {
        int ci = c - 'a';
        int next = *lower_bound(table[ci].begin(), table[ci].end(), prev % s.size());
        ll add = next - (prev % s.size()) + 1;
        prev += add;
    }
    cout << prev << endl;

}

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

#define int long long

int N;
vector<vector<int> > arr, grid;

int dp(int i , int prev)
{
    if(grid[i][prev] != -1)
        return grid[i][prev];

    int ans=0;

    if(i==N){
         if(prev == 0) ans += max(arr[i][1] , max(arr[i][2] , arr[i][3]) );
    else if(prev == 1) ans += max(arr[i][2] , arr[i][3]);
    else if(prev == 2) ans += max(arr[i][1] , arr[i][3]);
    else if(prev == 3) ans += max(arr[i][1] , arr[i][2]);
    }

    else
    if(prev == 0)
        ans += max(max(dp(i+1, 1)+arr[i][1] , dp(i+1, 2)+arr[i][2]) , dp(i+1 , 3)+arr[i][3]);
    else if(prev == 1)
        ans += max(dp(i+1, 2)+arr[i][2] , dp(i+1 , 3)+arr[i][3]);
    else if(prev == 2)
        ans += max(dp(i+1, 1)+arr[i][1] , dp(i+1 , 3)+arr[i][3]);
    else if(prev == 3)
        ans += max(dp(i+1, 2)+arr[i][2] , dp(i+1 , 1)+arr[i][1]);

    return grid[i][prev] = ans;
}

signed main()
{
    cin>>N;

    arr.resize(N+1 , vector<int>(4));

    grid.resize(N+1, vector<int>(4,-1));

    for(int i=1 ; i<=N ; i++)
        for(int j=1 ; j<=3 ; j++)
            cin>>arr[i][j];

   cout<<dp(1,0);
}

Measured memory_bytes: 18944
/**
 *      purpose : CODE FESTIVAL 2017 qual A
 *      author  : kyomukyomupurin
 *      created : 2018-11-08 02:20:12
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

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

    int N, M, K; cin >> N >> M >> K;

    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= M; ++j) {
            if (M * i + N * j - 2 * i * j == K){
                print("Yes"); return 0;
            }
        }
    }
    print("No");
    
    return 0;
}

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



const int N = 1005, MOD = 1e9 + 7;



int n, m, dp[N][N];
char a[N][N];



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    dp[0][1] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
            if(a[i][j] == '.'){
                dp[i][j] += dp[i - 1][j];
                dp[i][j] += dp[i][j - 1];
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[n][m];
}


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

/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/**************************************/

/******** User-defined Function *******/
map<long long, long long> prime_factorize(long long n) {
    map<long long, long long> res;
    for (long long p = 2; p * p <= n; ++p) {
        while (n % p == 0) { ++res[p]; n /= p; }
    }
    if (n != 1) res[n] = 1;
    return res;
}
/**************************************/

/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    int ans = 0;
    for(int i=1; i<=n; i++){
        if(i%2==0) continue;

        map<ll,ll> mp = prime_factorize(i);
        int cnt = 1;
        for(auto x: mp){
            cnt *= (x.second + 1);
        }

        if(cnt==8) ans++;
    }

    cout << ans << endl;
}
/********  Main() Ends Here *************/


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


def main():
  S = input()[:-1]
  T = input()[:-1]

  num_op = 0
  for s, t in zip(S, T):
    if not s == t:
      num_op += 1

  print(num_op)


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

Measured memory_bytes: 9492
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N;
  cin >> N;
  vi A(N);
  cin >> A;

  vi C(100002,0);
  for(auto &p : A){
    if(p>0) C[p-1]++;
    C[p]++;
    C[p+1]++;
  }
  cout << *max_element(rng(C)) << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

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

using namespace std;
using ll = long long;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> as(n);
  int idx;
  rep(i, n) cin >> as[i];
  if ((n - k) % (k - 1) == 0) {
    cout << (n - k) / (k - 1) + 1 << endl;
  } else {
    cout << (n - k) / (k - 1) + 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

class Comb{
    // テーブルを作るのに O(NlogN)
    // 計算は O(1)
    int N;
    vector<long long> fact_num, fact_den;
    long long bipow(long long n, long long m) {
        if (m == 0) return 1;
        if (m % 2 == 0) {
            n = (n * n) % MOD;
            return bipow(n, m / 2) % MOD;
        } else
            return (n * bipow(n, m - 1)) % MOD;
    }
    void set_table(){
        fact_num.resize(N+1, 0);
        fact_den.resize(N+1, 0);
        vector<long long> fact_denpow(N+1, 0);

        fact_num[0] = 1;
        for(int i=1; i<=N; i++) fact_num[i] = (fact_num[i-1] * i) % MOD;
        for(int i=0; i<=N; i++) fact_denpow[i] = bipow(i, MOD-2);
        fact_den[0] = 1;
        for(int i=1; i<=N; i++) fact_den[i] = (fact_den[i-1] * fact_denpow[i]) % MOD;
    }
public:
    Comb(int N): N(N) { set_table(); }
    // nCk
    long long calc(long long n, long long k){
        if(k > n) return 0;
        return ((fact_num[n] * fact_den[k]) % MOD * fact_den[n-k]) % MOD;
    }
};

void add(long long &x, long long y){
    x = (x + y) % MOD;
}
void sub(long long &x, long long y){
    x = (x - y + MOD) % MOD;
}

int main(){
    int N, K;
    cin >> N >> K;
    vector<long long> A(N);
    REP(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    
    Comb comb(N);
    long long ans = 0;
    for(int i=0; i<=N-K; i++)
        sub(ans, (A[i] * comb.calc(N-i-1, K-1)) % MOD);
    for(int i=K-1; i<N; i++)
        add(ans, (A[i] * comb.calc(i, K-1)) % MOD);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define x first
// #define y second
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define pld pair <ld, ld>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >
#define cld complex <double>

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 1e6 + 100;

ll n, m, k, t;

vector <ll> S;

ll gets(ll l, ll r) {
    if (l > r) {
        return 0;
    }
    return S[r + 1] - S[l];
}

ll solve(vector <ll> A) {
    ll ans = A.back();
    ll q, w, e;
    S.resize(A.size() + 1);
    S[0] = 0;
    for (q = 0; q < n; q++) {
        S[q + 1] = S[q] + A[q];
    }
    for (q = 0; q < n; q++) {
        ll lastl = q + (n - q - 1) / 2;
        ll cntr = n - lastl - 1;
        ll dans = A[q] * 2 + 2 * (gets(q + 1, lastl)) + 
            2 * (m * cntr - gets(lastl + 1, n - 1));
        if ((n - q) % 2 == 0) {
            dans -= (m - A[lastl + 1]);
        }
        else {
            dans -= A[lastl];
        }
        // cout << q << " " << lastl << " LASTL DANS " << dans << endl;
        ans = max(ans, dans);
    }
    return ans;
}

int main() {
    ll q, w, e, a, b, c;
    cin >> m >> n;
    vector <ll> A(n);
    for (q = 0; q < n; q++) {
        cin >> A[q];
    }
    ll ans = solve(A);
    for (q = 0; q < A.size(); q++) {
        A[q] = m - A[q];
    }
    sort(all(A));
    ans = max(ans, solve(A));
    cout << ans;
    return 0;
}


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

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        scanner.nextLine();
        final Integer[] values = Arrays.stream(scanner.nextLine().split(" "))
                .map(Integer::parseInt).toArray(Integer[]::new);

        if (values.length == 2) {
            System.out.println(Math.max(values[0], values[1]));
            return;
        }

        int[] gcdL = new int[values.length];
        int[] gcdR = new int[values.length];

        gcdL[0] = values[0];
        gcdR[values.length - 1] = values[values.length - 1];
        for (int i = 1; i < values.length; i++) {
            gcdL[i] = gcd(gcdL[i - 1], values[i]);
            gcdR[values.length - i - 1] = gcd(gcdR[values.length - i], values[values.length - 1 - i]);
        }

        int max = 0;
        for (int i = 0; i < values.length; i++) {
            if (i == 0) {
                max = Math.max(max, gcdR[i + 1]);
            } else if (i == values.length - 1) {
                max = Math.max(max, gcdL[i - 1]);
            } else {
                max = Math.max(max, gcd(gcdL[i - 1], gcdR[i + 1]));
            }
        }

        System.out.println(max);
    }

    private static int gcd(int a, int b) {
        if (a == b) return a;
        if (a < b) return gcd(b, a);
        if (a % b == 0) return b;

        return gcd(b, (a % b));
    }
}

Measured memory_bytes: 54008
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int t;
    cin >> t;
    string s;
    cin >> s;
    if(s.length()<=t){
        cout << s;
    }
    else{
        for(int i=0;i<t;i++){
            cout<<s[i];
        }
        cout << "...";
    }
    return 0;
}


Measured memory_bytes: 3632
a = input()
b = input()
c = input()
x = input()
a=int(a)
b=int(b)
c=int(c)
x=int(x)
i=0
j=0
k=0
l=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if x==500*i+100*j+50*k:
                l=l+1
print(l)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
#define INF (2147483647)
#define mod (1000000007)

int main(void){
  int A,B,C;
  cin >> A >> B >> C;
  if((A==5 and B==5 and C==7)||(A==5 and B==7 and C==5)||(A==7 and B==5 and C==5)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;


int main(){
    int N;
    cin>>N;
    LL INF=1000000007;



    int isPrime[N+1];
    fill_n(isPrime,N+1,0);
    isPrime[0]=isPrime[1]=-1;
    REP(i,N+1){
        if(isPrime[i]<0)continue;
        int cnt =2;
        for(int j=i*2;j<N+1;j*=2)isPrime[j]=-1;
    }
    for(int i=1;i<=N;i++){
        int n=i;
        for(int j=1;j<=i;j++){
            if(isPrime[j]<0)continue;
            while(n%j==0){
                isPrime[j]++;
                n/=j;
            }
        }
    }
    LL ans =1;
    REP(i,N+1){
        if(isPrime[i]>0){
            ans*=(1+isPrime[i]);
            ans%=INF;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    static IO io = new IO();

    public static void main(String[] args) {

        double a, b, c, d, e, f;
        double x = 0;
        double y = 0;
        while (io.hasNext()) {
            a = io.nextInt();
            b = io.nextInt();
            c = io.nextInt();
            d = io.nextInt();
            e = io.nextInt();
            f = io.nextInt();
            x = Math.round(1000*(c*e-b*f)/(a*e-b*d))/1000.0;
            y = Math.round(1000*(c*d-a*f)/(b*d-a*e))/1000.0;
            System.out.printf("%.3f %.3f\n",x,y);
        }

    }

    static class IO extends PrintWriter {
        private final InputStream in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        IO() {
            this(System.in);
        }

        IO(InputStream source) {
            super(System.out);
            this.in = source;
        }

        boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }

        int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        }

        boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }

        int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }

        public void close() {
            super.close();
            try {
                in.close();
            } catch (IOException ignored) {
            }
        }
    }
}

Measured memory_bytes: 24476
import java.io.*;
import java.util.*;

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

		int l = in.nextInt();
		int r = in.nextInt();
		int d = in.nextInt();
		System.out.println(r/d - (l-1)/d);
	}
}



Measured memory_bytes: 35636
n, m = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(n)]
s.sort()

cost = 0
for si in s:
  if m >= si[1]:
    cost += si[1] * si[0] 
    m -= si[1]
    
  else:
    cost += int(m * si[0])
    break
    
print(cost)

Measured memory_bytes: 27756
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	string s, t;
	cin >> s >> t;
	int n = int(s.size()), m = int(t.size());
	vector<vector<int>> dp(n + 1, vector<int>(m + 1));
	vector<vector<pair<int, int>>> prev(n + 1, vector<pair<int, int>>(m + 1));
	for(auto i = 1; i <= n; ++ i){
		for(auto j = 1; j <= m; ++ j){
			dp[i][j] = dp[i - 1][j - 1] + (s[i - 1] == t[j - 1]), prev[i][j] = {i - 1, j - 1};
			if(dp[i][j] < dp[i - 1][j]){
				dp[i][j] = dp[i - 1][j], prev[i][j] = {i - 1, j};
			}
			if(dp[i][j] < dp[i][j - 1]){
				dp[i][j] = dp[i][j - 1], prev[i][j] = {i, j - 1};
			}
		}
	}
	string res;
	for(auto p = pair<int, int>{n, m}; p.first && p.second; ){
		auto q = prev[p.first][p.second];
		if(p.first - 1 == q.first && p.second - 1 == q.second && s[q.first] == t[q.second]){
			res += s[q.first];
		}
		p = q;
	}
	reverse(res.begin(), res.end());
	cout << res;
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 106112
while True:
  N,M = map(int,input().split())
  if N == M == 0:
    break
  else:
    L = []
    for i in range(N):
      L.append(list(map(int,input().split())))
    L = sorted(L, key = lambda x:x[1])
    L.reverse()
    ans = 0
    for i in range(len(L)):
      if M > 0:
        if M-L[i][0] >= 0:
          M -= L[i][0]
        else:
          ans += (L[i][0]-M)*L[i][1]
          M = 0
      else:
        ans += L[i][0]*L[i][1]
    print(ans)



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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int A, B;
	cin >> A >> B;
	if (A >= 13) {
		cout << B << endl;
	}
	else if(A<=5){
		cout << 0 << endl;
	}
	else {
		cout << B / 2 << endl;
	}

	return 0;
}

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


int main() {
  int64_t n,a,b,c,d,e;
  cin>>n>>a>>b>>c>>d>>e;
  int64_t z=min(a,min(b,min(c,min(d,e))));
  if(n%z==0){
    cout<<(n/z)+4;
  }
  else{
    cout<<(n/z)+5;
  }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split(sep=" ")))
Acounter = []
for i in range(0,N,1):
    Acounter.append(0)
for i in range(0,N-1,1):
    Acounter[A[i]-1]+=1
for i in range(0,N,1):
    print(Acounter[i])

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 987654321
#define IINF 2987654321987654321
#define MOD 1000000007

inline ll madd(ll a, ll b) { return (a+b)%MOD; }
inline ll msub(ll a, ll b) { return (a-b+MOD)%MOD; }
inline ll mmul(ll a, ll b) { return (a*b)%MOD; }

const int MAXN = 5050;
int n;
vector<int> adj[MAXN];
void readInput() {
	scanf("%d", &n);
	for(int i = 0; i < n-1; i++) {
		int u, v; scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
}

ll g[MAXN];
void preprocess() {
	g[2] = 1;
	for(int m = 4; m < MAXN; m += 2)
		g[m] = mmul(g[m-2], m-1);
}

ll dp[MAXN][MAXN][2], S[MAXN][2];
ll sz[MAXN], tmp[MAXN][2];
void dfs(int v, int p) {
	sz[v] = 1;
	dp[v][1][0] = 1;

	ll sum = 1;
	for(auto c : adj[v]) if(c != p) {
		dfs(c, v);
		sz[v] += sz[c];

		for(int m = 0; m <= (sum + sz[c]); m++)
			rep(x, 2) tmp[m][x] = 0;
		for(int m = 0; m <= (sum + sz[c]); m++)
			rep(x, 2) rep(y, 2) tmp[m][x^y^1] = madd(tmp[m][x^y^1], mmul(dp[v][m][x], S[c][y]));
		for(int m = 0; m <= sum; m++)
			for(int k = 0; k <= sz[c]; k++)
				rep(x, 2) rep(y, 2) tmp[m+k][x^y] = madd(tmp[m+k][x^y], mmul(dp[v][m][x], dp[c][k][y]));

		for(int m = 0; m <= (sum + sz[c]); m++)
			rep(x, 2) dp[v][m][x] = tmp[m][x];

		sum += sz[c];
	}

	for(int m = 0; m <= sz[v]; m++)
		rep(x, 2) S[v][x] = madd(S[v][x], mmul(dp[v][m][x], g[m]));

	// printf("[%d]: %lld, %lld\n", v, S[v][0], S[v][1]);
	// for(int m = 0; m <= sz[v]; m++)
	// 	rep(x, 2) printf("dp[%d][%d][%d] = %lld\n", v, m, x, dp[v][m][x]);
}


int main() {
	preprocess();
	readInput();
	dfs(1, -1);
	printf("%lld\n", msub(S[1][0], S[1][1]));
}

Measured memory_bytes: 394624
#include <stdio.h>

int main(){
    int N,R;
    int hyouji;
    int naibu;

    scanf("%d %d",&N,&R);

    if(N<10){
        hyouji = 100 * (10 - N);
        naibu = hyouji + R;
    }else{
        naibu = R;
    }
    printf("%d\n",naibu);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
long long int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
//↓,→,↑,←
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 

ll i,j,k,ii,jj;
ll n,m,num,sumxor,sum;
ll ans;
ll a,b,c,d,e,f,g,h,w,v;
char s[500005];
ll x[800005],y[800005],z[900005];
ll sex[500005];

int main(){	
	cin>>n;
	for(i=1;i<=n;i++){
		x[i%2]++;
	}
	p(x[0]*x[1]);


	

	
	return 0;
}

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

int main() {
  
  int X; cin >> X;
  
  int quotient = X / 100; int remainder = X % 100;
  
  if (X < 100) cout << "0" << endl;
  
  else if (1999 < X) cout << "1" << endl;
  
  else {
    
    if (remainder <= quotient * 5) cout << "1" << endl;
    
    else cout << "0" << endl;
       
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){
    int n,m;
    cin >> n >> m;
    if(n>=m){
        cout << 0 << endl;
        return 0;
    }else{
        vector<int> v(m);
        REP(i,m){
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        vector<int> distances(m - 1);
        REP(i, m-1){
            distances[i] = v[i + 1] - v[i];
        }
        sort(distances.begin(), distances.end(),greater<int>());
        int result = v[m-1]-v[0];
        REP(i,n-1){
            result -= distances[i];
        }
        cout << result << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
	//??\??????????????????
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //????????°?????????
        int numberCount = Integer.parseInt(br.readLine());
        //???????????¶????????°??????????????????
        String[] sNumbers = br.readLine().split(" ");
        //????????°?????????????????????
        int[] numbers = new int[numberCount];
        //?????????????????°????????????
        for(int i = 0 ; i < numberCount ; i++){
        	numbers[i] = Integer.parseInt(sNumbers[i]);
        }
        insertionSort(numbers);
	}
	
	private static void insertionSort(int[] numbers){
		displayNumbers(numbers);
		for(int i = 1 ; i < numbers.length ; i++){
			int currentNumber = numbers[i];
			int insertIndex = i;
			for(int y = i - 1 ; y >= 0 ; y--){
				if(currentNumber < numbers[y]){
					numbers[y + 1] = numbers[y];
					insertIndex = y;
				}else{
					break;
				}
			}
			numbers[insertIndex] = currentNumber;
			displayNumbers(numbers);
		}
	}
	
	private static void displayNumbers(int[] numbers){
		StringBuffer sb = new StringBuffer();
		for(int i = 0 ; i < numbers.length ; i++){
			sb.append(numbers[i]);
			sb.append(" ");
		}
		System.out.println(sb.toString().trim());
	}

}

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

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

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

int main(void){
    int N; cin >> N;
    VS S(N); REP(i,N) cin >> S[i];
    int n[26]; REP(i,26) n[i] = 0;
    REP(i,N) n[S[i][0]-'A']++;
    ll num[5]; num[0] = n['M'-'A']; num[1] = n[0]; num[2] = n['R'-'A']; num[3] = n[2]; num[4] = n['H'-'A'];
    ll ans = 0;
    REP(i,5-2)FOR(j,i+1,5-1)FOR(k,j+1,5){
        ans += num[i]*num[j]*num[k];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7296
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int N, c_total;
	vector<vector<int>> vec(2, vector<int>(110));
	vector<vector<int>> su(2, vector<int>(110));


	cin >> N;
	rep(j, 2)
	{
		rep(i, N)
		{
			cin >> vec.at(j).at(i);
			if (i == 0) {
				su.at(j).at(i) = 0;
			}
			su.at(j).at(i + 1) = su.at(j).at(i) + vec.at(j).at(i);
		}
	}

	int max_val = 0;

	rep(i, N)
	{
		c_total = (su.at(0).at(i + 1) - su.at(0).at(0)) + (su.at(1).at(N) - su.at(1).at(i));
		max_val = max(max_val, c_total);
	}

	cout << max_val << endl;

	return 0;
}

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

struct mint{
    ll x;
    mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
    mint& operator+=(const mint a){//operatorは構造体同士の比較に用いられる
        if((x +=a.x)>=mod) x-=mod;
        return *this;//thisとは現在のオブジェクトのこと
    }
    mint& operator-=(const mint a){
        if((x +=mod-a.x)>=mod) x-=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x*=a.x)%=mod;
        return *this;
    }
    mint operator+(const mint a){
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a){
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a){
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const{
        if(!t) return 1;
        mint a=pow(t>>1);
        a*=a;
        if(t&1) a*=*this;
        return a;
    }
    mint inv() const{
        return pow(mod-2);//逆元
    }

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

int main(void){
    ll n;
    cin>>n;
    string s1, s2;
    cin>>s1>>s2;
    vector<ll> v;
    if(n==1) {
        cout<<3<<endl;
        return 0;
    }
    rep(i, s1.size()){
        if(i==s1.size()-1) v.push_back(1);
        else if(s1[i+1]==s1[i]) {
            v.push_back(2);
            i++;
        }
        else v.push_back(1);
    }
    mint ans;
    if(v[0]==1) ans=3;
    else ans=6;
    for(ll i=1;i<=v.size()-1;i++){
        if(v[i]==2){
            if(v[i-1]==1) ans*=2;
            else ans*=3;
        }
        else {
            if(v[i-1]==1) ans*=2;
            else ans*=1;
        }
    }
    cout<<ans.x<<endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
    int r, d, x;
    cin >> r >> d >> x;
    for(int i = 0; i < 10; i++) {
        x = r * x -d;
        cout << x << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE MultiWayIf #-}
main :: IO ()
main = do
  [a, b, c, d] <- (map read . words) <$> getLine :: IO [Int]
  print $ if
    | b < c                      -> 0
    | a <= c && c <= b && b <= d -> b - c
    | c <= a && a <= d && d <= b -> d - a
    | c <= a && b <= d           -> b - a
    | a <= c && d <= b           -> d - c
    | d < a                      -> 0
    | otherwise                  -> 0


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
map<string, int> memo;
int main() {
    int n;cin >> n;
    
    for(int i = 0;i < n;i++) {
        string s;
        cin >> s;
        memo[s] +=1;
    }

    int maxv = 0;
    for(const auto& x : memo) {
        int v = x.second;
        if(v > maxv) maxv = v;
    }

    for(auto it = memo.begin(); it!=memo.end();it++) {
        if(it->second == maxv) {
            cout << it->first << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef multiset<ll> S;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}

vvi g;
vi depth;
void dfs(int i,int p){
    for(int x:g[i]){
        if(x==p)continue;
        depth[x]=depth[i]+1;
        dfs(x,i);
    }
}
int main(){
    ll n;cin>>n;
    g=vvi(n);
    depth=vi(n);
    rep(i,n-1){
        ll a,b;cin>>a>>b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    depth[0]=0;
    dfs(0,-1);
    ll k,d=0;
    rep(i,n)if(chmax(d,depth[i]))k=i;
    depth[k]=0;
    dfs(k,-1);
    rep(i,n)chmax(d,depth[i]);
    if((d+1)%3==2)cout<<"Second"<<endl;
    else cout<<"First"<<endl;
}


Measured memory_bytes: 22144
/*
 * main.c
 *
 *  Created on: 2019/06/22
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int N = 0, i = 0, ans = 0;
	int p[21] = {0};
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &p[i]);
	}
	for(i = 0; i < (N - 2); i++) {
		if((p[i] < p[i+1]) && (p[i+1] < p[i+2])) {
			ans++;
		} else if((p[i] > p[i+1]) && (p[i+1] > p[i+2])) {
			ans++;
		} else {
			//
		}
	}
	printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
def cara(n):
	kazu=[]
	ilo=[]
	a=int(input())
	una=a
	kazu.append(1)
	ilo.append(a)
	for n in range(n-1):
		a=int(input())
		if una==a:
			kazu[-1]+=1
		else:
			kazu.append(1)
			ilo.append(a)
			una=a
	return ilo,kazu
def kes(ilo,kazu):
	k=10000
	unanseer=sum(kazu)
	anseer=sum(kazu)
	for p in range(len(ilo)):
		n=0
		if kazu[p]>=3 :
			anseer=kurabe(ilo,kazu,p)
		n=0
		if p+2 < len(ilo) and ilo[p]==ilo[p+2] and kazu[p]+kazu[p+2]>=3 and kazu[p+1]==1:
			while p+2+n<len(ilo) and p-n>=0 and ilo[p-n]==ilo[p+2+n] and kazu[p-n]+kazu[p+2+n]>=4:
				n+=1
			if n>2500:
				print(n)
			unanseer=kensa(ilo,kazu,n,p)
		if unanseer<anseer:
			anseer=unanseer
		if anseer<k: 
			k=anseer
	return k
def kensa(ilo,kazu,n,p):
	k=0
	if n==0:
		for w in range(len(kazu)):
			k+=kazu[w]
	else:
		for q in range(0,p-n+1):
			k+=kazu[q]
		for i in range(p+2+n,len(kazu)):
			k+=kazu[i]
	return k
def kurabe(ilo,kazu,p):
	n=0
	a=0
	b=0
	k=0
	
	#上からもらう
	if p+1 < len(ilo):
		kazu[p+1]-=1
		kazu[p]+=1
		while 0<p-a and len(kazu)>p+1+a and ilo[p+1+a]==ilo[p-1-a] and kazu[p+1+a]+kazu[p-1-a]>=4:
			a+=1
		kazu[p+1]+=1
		kazu[p]-=1

	#下からもらう
	if p-1 >= 0:
		kazu[p-1]-=1
		kazu[p]+=1
		while len(kazu)>p+1+b and 0<p-b and ilo[p+b+1]==ilo[p-1-b] and kazu[p+b+1]+kazu[p-1-b]>=4:
			b+=1
		kazu[p-1]+=1
		kazu[p]-=1
	if a<b:
		n=b
	else:
		n=a
	for q in range(0,p-n):
			k+=kazu[q]
	for i in range(p+n,len(kazu)):
			k+=kazu[i]
	k-=3
	return k

while True:
	n=int(input())
	if n==0:
		break
	ilo,kazu=cara(n)
	print(kes(ilo,kazu))


Measured memory_bytes: 5804
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

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

using namespace std;
int main()
{
    int n;
    string s,t1,t2;

    cin>>n;
    cin>>s;
    if (n%2 == 0)
    {
        t1 = s.substr(0,n/2);
        t2 = s.substr(n/2, n/2);
        if(t1==t2)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    else
    {
        cout<<"No"<<endl;
    }

    return 0;

}



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

template <class T> void max_self(T &a , T b){
	a=max(a,b);
}
int main(){
	
	int  items, knapsack ;
	scanf("%d%d",&items,&knapsack);
	vector<ll> dp(knapsack+1,0);
	
	for(int i=0; i< items; ++i){
		int weight, value;
		scanf("%d%d",&weight,&value);
		for(int j=knapsack; j>=weight ; j--){
			max_self(dp[j], dp[j-weight]+value) ;
		}

	}
	ll ans=0;
	for(auto x : dp){
		max_self(ans,x);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
from collections import deque

N, D, A = map(int, input().split())
monsters = []
for _ in range(N):
    monsters.append(list(map(int, input().split())))

monsters.sort()
d = deque()
ans = 0
damage = 0
for x, h in monsters:
    while d:
        if d[0][0] >= x - D:
            break
        _, power = d.popleft()
        damage -= power
    h -= damage
    if h <= 0:
        continue
    attack = (h - 1) // A + 1
    
    ans += attack
    d.append((x + D, attack * A))
    damage += attack * A
print(ans)


Measured memory_bytes: 65652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

int dp1[8000][16010];
int dp2[8000][16010];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);
    string S; cin >> S;
    int X,Y; cin >> X >> Y;
    vi A,B;
    bool frag1 = true;
    bool frag2 = true;
    int cnt=0;
    rep(i,SZ(S)){
        if(S[i]=='F'){
            cnt++;
        } else {
            if(frag1){
                if(frag2) {X-=cnt; frag2=false;}
                else {
                    if(cnt>0) A.eb(cnt);
                }
                cnt=0;
                frag1=false;
            } else {
                if(cnt>0) B.eb(cnt);
                cnt=0;
                frag1=true;
            }
        }
    }
    if(cnt>0){
        if(frag1){
            if(frag2) X-=cnt;
            else A.eb(cnt);
        }
        else B.eb(cnt);
    }

    dp1[0][8001]=1;
    dp2[0][8001]=1;

    rep(i,SZ(A)){
        rep(j,16002){
            if(dp1[i][j]==1){
                dp1[i+1][j-A[i]]=1;
                dp1[i+1][j+A[i]]=1; 
            }
        }        
    }

    rep(i,SZ(B)){
        rep(j,16002){
            if(dp2[i][j]==1){
                dp2[i+1][j-B[i]]=1;
                dp2[i+1][j+B[i]]=1; 
            }
        }        
    }

    if(dp1[SZ(A)][X+8001] == 1 && dp2[SZ(B)][Y+8001] == 1){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 502144
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.ArrayList;

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

    static class TaskF {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            TaskF.Vertex[] vs = new TaskF.Vertex[n];
            for (int i = 0; i < n; ++i) vs[i] = new TaskF.Vertex(in.nextInt());
            for (int i = 0; i < n - 1; ++i) {
                TaskF.Vertex a = vs[in.nextInt() - 1];
                TaskF.Vertex b = vs[in.nextInt() - 1];
                a.adj.add(b);
                b.adj.add(a);
            }
            boolean first = true;
            for (int i = 0; i < n; ++i)
                if (vs[i].solve() == 1) {
                    if (first) first = false;
                    else out.print(" ");
                    out.print(i + 1);
                }
            out.println();
        }

        static class Vertex {
            int stones;
            List<TaskF.Vertex> adj = new ArrayList<>();
            int answer = 0;

            public Vertex(int stones) {
                this.stones = stones;
            }

            public int solve() {
                if (answer == -1) throw new RuntimeException();
                if (answer > 0) return answer;
                answer = -1;
                for (TaskF.Vertex v : adj)
                    if (v.stones < stones) {
                        int got = v.solve();
                        if (got == 2) {
                            answer = 1;
                            return answer;
                        }
                    }
                answer = 2;
                return answer;
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

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

    int n;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mp[a]++;
    }
    if (mp.count(0) && mp[0] == n) {
        cout << "Yes" << endl;
        return 0;
    }
    if (n % 3) {
        cout << "No" << endl;
        return 0;
    }
    if (mp.size() == 2 && mp.count(0) && mp[0] == n / 3) {
        cout << "Yes" << endl;
        return 0;
    }
    if (mp.size() != 3) {
        cout << "No" << endl;
        return 0;
    }
    int x = 0;
    for (auto &p : mp) {
        if (p.second != n / 3) {
            cout << "No" << endl;
            return 0;
        } else {
            x ^= p.first;
        }
    }
    cout << (x ? "No" : "Yes") << endl;
}

Measured memory_bytes: 3840
from itertools import permutations

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(int, input().split())) for _ in range(N)]

list0 = [0 for _ in range(C)]
list1 = [0 for _ in range(C)]
list2 = [0 for _ in range(C)]


for i in range(N):
    for j in range(N):
        if (i+j) % 3 == 0:
            list0[c[i][j]-1] += 1
        elif (i+j) % 3 == 1:
            list1[c[i][j]-1] += 1
        else:
            list2[c[i][j]-1] += 1

color = tuple(i for i in range(C))

ans = float('inf')
for c0, c1, c2 in permutations(color, 3):
    cost = 0
    for i in range(C):
        cost += D[i][c0] * list0[i]
        cost += D[i][c1] * list1[i]
        cost += D[i][c2] * list2[i]
    ans = min(ans, cost)

print(ans)


Measured memory_bytes: 7540
(let* ((n (read))
    (a (make-array n :initial-element 0))
    (beforenum 0)
    (times 0)
    (ans 0))

    (dotimes (i n)
        (setf (aref a i) (read))
    )
    (sort a #'<)
    
    (setq beforenum (aref a 0))
    (setq times 1)
    (loop for i from 1 to (- n 1) do
        (if (= (aref a i) beforenum)
            (incf times)
            (progn
                (if (not (zerop (rem times 2)))
                    (incf ans)
                )
                (setq beforenum (aref a i))
                (setq times 1)
            )
        )
    )
    (if (not (zerop (rem times 2)))
        (incf ans)
    )
    (princ ans)
)

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

int plustax(int p, int x) {
  return p * (100 + x) / 100;
}

int main() {
  int x, y, z;
  int temp;

  while(1) {
    cin >> x >> y >> z;
    if (x + y + z == 0) break;

    int max = 0;
    for(int i = 1; i <= z-1; i++) { 
      for(int j = 1; j <= z-1; j++) {
	if(plustax(i, x) + plustax(j, x) == z) {
	  if((temp = plustax(i, y) + plustax(j, y)) > max) {
	    max = temp;
	  }
	}	
      }
    }
    cout << max << endl;
  }
  return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string N;
  cin>>N;
  
  int sw=N.size()-1;
  
  if(N.at(sw)=='2'||N.at(sw)=='4'||N.at(sw)=='5'||N.at(sw)=='7'||N.at(sw)=='9'){
    cout<<"hon"<<endl;
  }else if(N.at(sw)=='0'||N.at(sw)=='1'||N.at(sw)=='6'||N.at(sw)=='8'){
    cout<<"pon"<<endl;
  }else{
    cout<<"bon"<<endl;
  }
}



  

Measured memory_bytes: 3628