akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007LL;

///////////////////////////////////////////////////////////////////

template <uint_fast64_t Modulus> 
struct ModInt {
    using u64 = uint_fast64_t;

    u64 a;

    constexpr ModInt(const long long x = 0) noexcept : a(x >= 0 ? x % Modulus : (Modulus - (-x) % Modulus) % Modulus) {}
    constexpr u64 &value() noexcept {return a;}
    constexpr const u64 &value() const noexcept {return a;}
    constexpr ModInt operator+(const ModInt rhs) const noexcept {return ModInt(*this) += rhs;}
    constexpr ModInt operator-(const ModInt rhs) const noexcept {return ModInt(*this) -= rhs;}
    constexpr ModInt operator*(const ModInt rhs) const noexcept {return ModInt(*this) *= rhs;}
    constexpr ModInt operator/(const ModInt rhs) const noexcept {return ModInt(*this) /= rhs;}
    constexpr ModInt operator^(const long long rhs) const noexcept {return ModInt(*this) ^= rhs;}
    constexpr bool operator==(const ModInt &rhs) const noexcept {return a == rhs.a;}
    constexpr bool operator!=(const ModInt &rhs) const noexcept {return a != rhs.a;}
    constexpr ModInt &operator+=(const ModInt rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr ModInt &operator/=(ModInt rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp&1) *this *= rhs;
            exp >>= 1;
            rhs *= rhs;
        }
        return *this;
    }
    constexpr ModInt &operator^=(long long exp) noexcept {
        ModInt rhs = a;
        a = 1;
        while (exp) {
            if (exp&1) *this *= rhs;
            exp >>= 1;
            rhs *= rhs;
        }
        return *this;
    }

    friend ostream &operator<<(ostream& os, const ModInt& rhs) noexcept {return os << rhs.a;}
    friend istream &operator>>(istream& is, ModInt& rhs) noexcept {long long a; is >> a; rhs = a; return is;}
};

using mint = ModInt<MOD>;

/////////////////////////////////////////////////////////////////////////////////////

void DPL_5_J() {
    int N,K; cin >> N >> K;
    vector<vector<mint>> dp(N+1, vector<mint>(K+1));
    for (int i = 0; i <= K; i++) dp[0][i] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            dp[i+1][j] += dp[i+1][j-1];
            if (i+1 >= j) dp[i+1][j] += dp[i+1-j][j];
        }
    }
    cout << dp[N][K] << endl;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    DPL_5_J();
}


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

using namespace std;

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

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

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


Measured memory_bytes: 3748
s = list(map(int,input()))

n = int(len(s)/2)

a = [0]*len(s)
b = [0]*len(s)

for i in range(n):
  a[2*i] = 0
  a[2*i+1] = 1
  b[2*i] = 1
  b[2*i+1] = 0

if len(s)%2 ==1:
  a[len(s)-1] = 0
  b[len(s)-1] = 1 


an = 0
bn = 0

for j in range(len(s)):
  if a[j] != s[j]:
    an += 1
  if b[j] != s[j]:
    bn += 1

print(min(an, bn))


Measured memory_bytes: 11008
import java.util.*;

class Main {
	static Scanner sc =new Scanner(System.in);
	static int a;
	static int b;
		public static void main (String[]agrs){
			a =sc.nextInt();
			b =sc.nextInt();
			
			if (a>b){
				System.out.println("a > b");		
			}else if(a<b){
				System.out.println("a < b");
			}else if(a==b){
				System.out.println("a == b");
			}
	}

}

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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
int main(){
    string s;
    std::cin >> s;
    int n=s.size(),c=0;
    ll ans=0;
    rep(i,n){
        if(s[i]=='W'){
            ans+=i-c;
            c++;
        }
    }
    std::cout << ans << std::endl;
}

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

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T> inline bool chmax(T& lhs, const T& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T> inline bool chmin(T& lhs, const T& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

typedef long long lint;

int main() {

    lint num, fir, dif;
    cin >> num >> fir >> dif;

    if(dif == 0) {
        if(fir == 0) cout << "1\n";
        else cout << num + 1 << '\n';
        return 0;
    }

    if(dif < 0) fir = -fir, dif = -dif;
    map<lint, set<pair<lint, lint>>> segments;
    for(lint i = 0; i <= num; ++i) {
        lint lef = (i - 1) * i / 2, rig = (num - 1 + num - i) * i / 2 + 1;
        segments[(i * fir % dif + dif) % dif].insert(make_pair(i * fir + lef * dif, i * fir + rig * dif));
    }

    lint ans = 0;
    for(const auto& st : segments) {
        lint last_r = st.second.begin() -> first;
        for(const auto& p : st.second) {
            lint l = max(last_r, p.first);
            lint cnt = (p.second - l) / dif;
            ans += max(cnt, 0ll);
            chmax(last_r, p.second);
        }
    }

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

}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i,K){
        int d;
        cin >> d;
        rep(j,d){
            int num;
            cin >> num;
            A[num-1]++;
        }
    }
    int ans = 0;
    rep(i,N){
        if(A[i]==0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}
 
//char arr[107][107];
int main(){
	Lancer();
	double n, t, a,h, ind=1,res = 1000000000000000000,d;
	cin >> n >> t >> a;
	for (int i = 0; i < n; i++){
		cin >> h;
		d = t- (h*0.006);
		d = abs(d-a);
		//cout << d << endl;
		if (d < res){
			res = d;
			ind = i+1;
		}
	}
	cout << ind;
	cout << endl;
	return 0;
}

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

int main() {
    long long int a, b, c, d; cin >> a >> b >> c >> d;
    long long int ans = a * c;
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << endl;
}


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

int main() {

	//ifstream cin("INPUT.txt");
	//ofstream cout("OUTPUT.txt");

	int player, i, j, k;
	int point[200][3];
	int t;
	int result[200] = {0};

	cin >> player;

	for(i = 0; i < player; i++) {
		for(j = 0; j < 3; j++) {
			cin >> point[i][j];
		}
	}

	for(i = 0; i < player; i++) {
		for(j =  0; j < 3; j++) {
			t = 1;
			for(k = 0; k < player; k++) {
				if(i == k)
					continue;
				if(point[i][j] == point[k][j]) {
					t = 0;
					break;
				}
			}
			if(t == 1)
				result[i] += point[i][j];
		}
	}

	for(i = 0; i < player; i++) {
		cout << result[i] << endl;
	}

	return 0;

}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, answer = 0;
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        answer += 800;
        if (i % 15 == 0) {
            answer -= 200;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    set<ll> st;

    st.insert(a);
    st.insert(b);
    st.insert(c);

    cout << st.size() << endl;
}

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

int main() {
  int N;
  cin >> N;
      
  double sum;
  
  for (int i = 0; i < N; ++i) {
  	double x;
    string u;
    cin >> x >> u;
    
    if (u == "BTC") {
      x *= 380000.0;
    }
    
    sum += x; 
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c[] = new int[n-1];
        int s[] = new int[n-1];
        int f[] = new int[n-1];
        for(int i = 0; i < n-1; i++){
            c[i] = sc.nextInt();
            s[i] = sc.nextInt();
            f[i] = sc.nextInt();
        }

        for(int j = 0; j < n-1; j++) {
            int t = 0;
            for (int i = j; i < n - 1; i++) {
                if (t <= s[i]) {
                    t = s[i];
                    t += c[i];
                } else if (t % f[i] == 0) {
                    t += c[i];
                } else {
                    t +=f[i] - t % f[i] + c[i];
                }
            }
            System.out.println(t);
        }
        System.out.println(0);
    }
}

Measured memory_bytes: 26876
# https://atcoder.jp/contests/abc052/tasks/arc067_b
# 歩いたほうが良いのかテレポートしたほうが良いのか貪欲に選択していくだけでは？

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


import numpy as np
N, A, B = read_ints()
X = read_ints()

# 面倒なのでnumpy芸してええか？
X_diff = np.diff(X)
ans = 0
for d in X_diff:
    ans += min(B, d * A)
print(ans)


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

int main()
{
  int N, X, T;
  cin >> N >> X >> T;

  if (N % X == 0)
  {
    cout << N / X * T << endl;
  }
  else
  {
    cout << (N / X + 1) * T << endl;
  }
}


Measured memory_bytes: 3636
def examA():
    ABC =LI(); ABC.sort()
    if ABC[0]==ABC[-1]:
        print("Yes")
    else:
        print("No")
    return

def examB():
    N = I()
    S = SI()
    red = S.count("R")
    if red>N//2:
        print("Yes")
    else:
        print("No")
    return

def examC():
    N,Q = LI()
    S = SI()
    T = [LSI()for _ in range(Q)]
    l = -1; r = N
    while(r-l>1):
        cur = (r+l)//2
        now = copy.deepcopy(cur)
        flag = False
        for t,d in T:
            if S[now]==t:
                if d=="R":
                    now += 1
                else:
                    now -= 1
            if now==N:
                flag = True
                break
            if now==-1:
                break
        if flag:
            r = cur
        else:
            l = cur
    R = r
    l = -1; r = N
    while(r-l>1):
        cur = (r+l)//2
        now = copy.deepcopy(cur)
        flag = False
        for t,d in T:
            if S[now]==t:
                if d=="R":
                    now += 1
                else:
                    now -= 1
            if now==-1:
                flag = True
                break
            if now==N:
                break
        if flag:
            l = cur
        else:
            r = cur
    L = l
    ans = max(0,R-L-1)
    print(ans)
    return

def examD():
    N, X = LI()
    S = LI()
    S.sort(reverse=True)
    dp = [[0]*(X+1)for _ in range(N+1)]
    dp[0][X] = 1
    for i in range(N):
        s = S[i]
        for j in range(X+1):
            dp[i+1][j%s] += dp[i][j]
            dp[i+1][j%s] %= mod
        for j in range(X+1):
            dp[i+1][j] += dp[i][j]*(N-i-1)
            dp[i+1][j] %= mod
    #print(dp)
    ans = 0
    for i,d in enumerate(dp[-1]):
        ans += d*i
        ans %= mod
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""

Measured memory_bytes: 229984
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 
typedef long long ll;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
#define MAXN 2005
#define INF 1000000007


int main()
{ 
	FIN;
	
	#ifdef input
		//freopen("test1.txt", "r", stdin);
	#endif
	
	int x, n;
	cin >> x >> n;
	vector <int> v(n);
	forn(i,n) cin >> v[i];
	bool d=false;
	int pos = x;
	while(d==false)
	{
		d=true;
		forn(i,n) if(v[i]==pos) d=false;
		if(d==true) break;
		pos++;
	}
	int ans=pos;
	pos = x; d=false;
	while(d==false)
	{
		d=true;
		forn(i,n) if(v[i]==pos) d=false;
		if(d==true) break;
		pos--;
	}
	if(x-pos <= ans-x) ans=pos;
	cout << ans << endl;
	
	return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),m=sc.nextInt();
		int[] k=new int[m];
		int[][] s=new int[m][n];
		int[] p=new int[m];
		int[] sum=new int[m];
		int count=0;
		boolean flag=true;

		for(int i=0;i<m;i++) {
			k[i]=sc.nextInt();
			for(int j=0;j<k[i];j++) {
				s[i][j]=sc.nextInt();
			}
		}
		for(int i=0;i<m;i++) {
			p[i]=sc.nextInt();
		}
		for(int i=0;i<Math.pow(2, n);i++) {
			int[] status = new int[n];
			for(int j=0;j<n;j++) {//iを2進数にした場合にどこの桁が1になっているか判定し、1の場合はstatusに代入
				if((1&i>>j)==1) {
					status[j]=1;
				}
			}
			for(int h=0;h<m;h++) {
				for(int j=0;j<k[h];j++) {
					if(status[s[h][j]-1]==1)sum[h]++;
				}
			}
			//System.out.println("stauts"+Arrays.toString(status));
			//System.out.println("sum"+Arrays.toString(sum));
			for(int h=0;h<m;h++) {
				if(p[h]!=sum[h]%2)flag=false;
			}
			if(flag)count++;
			flag=true;
			Arrays.fill(sum, 0);
		}
		System.out.println(count);

	}
}



Measured memory_bytes: 22996
#include <iostream>

using namespace std;

int main(){
	int l = 10000, r = -1;
	int n;
	cin >> n;
	
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		
		if(a < l) l = a;
		if(a > r) r = a;
	}
	
	cout << (r-l) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll dp[2005];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    for(int i=3;i<=2000;i++){
        dp[i]=1;
        for(int j=i-1;j>=3;j--)
        {
            dp[i]=(dp[i]+dp[i-j])%MOD;
        }
    }
    int n;
    cin>>n;
    cout<<dp[n]<<endl;

    return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define ll long long int
#define pb push_back
#define for0(i,n) for(i=0;i<n;i++)
#define for1(i,n) for(i=1;i<n;i++)
#define for0r for(i=n-i-1;i>=0;i++)
#define mod 1000000007

/*aaj phi tumpe pyar aaya hai*/


using namespace std;
int main()
{
    ll n,m,sum=0;
    cin>>n>>m;
   
    
    
    sum=((n*(n-1))/2)+(m*(m-1)/2);
   
    cout<<sum<<endl;
return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  size_t n;
  std::cin >> n;
  std::vector<std::pair<int64_t, int64_t>> task;
  for (size_t i = 0; i < n; ++i) {
    int64_t a, b;
    std::cin >> a >> b;
    task.push_back(std::make_pair(b, a));
  }

  std::sort(task.begin(), task.end());
  int64_t now = INT64_MAX;
  for (auto itr = task.rbegin(), end = task.rend(); itr != end; ++itr) {
    if (itr->first < now) {
      now = itr->first;
    }

    now -= itr->second;
  }

  std::string result = "Yes";
  if (now < 0) {
    result = "No";
  }

  std::cout << result << std::endl;
  return 0;
}


Measured memory_bytes: 6512
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        Int L;
        cin >> L;
        vector<Int> A(L + 1);
        for (int i = 0; i < L; ++i) {
            cin >> A[i + 1];
        }

        vector<vector<Int>> dp(5, vector<Int>(L + 1));

        for (int idx = 1; idx <= L; ++idx) {
            dp[0][idx] = dp[0][idx - 1] + A[idx];

            Int add1 = A[idx] % 2;
            if (A[idx] == 0) add1 = 2;
            dp[1][idx] = min(dp[0][idx - 1], dp[1][idx - 1]) + add1;

            Int add2 = 1 - A[idx] % 2;
            dp[2][idx] = min({dp[0][idx - 1], dp[1][idx - 1], dp[2][idx - 1]}) + add2;

            dp[3][idx] = min({dp[0][idx - 1], dp[1][idx - 1], dp[2][idx - 1], dp[3][idx - 1]}) + add1;

            dp[4][idx] = min({dp[0][idx - 1], dp[1][idx - 1], dp[2][idx - 1], dp[3][idx - 1], dp[4][idx - 1]}) + A[idx];

        }

        Int ans = INFl;
        for (int i = 0; i < 5; ++i) {
            chmin(ans, dp[i][L]);
        }
        cout << ans << endl;

    }

};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 11264
import java.io.*;
import java.util.*;
public class Main
{
	int n,k;
	ArrayList<Integer> list[];
	final int inf=(int)(1e9+1);
	private void solve()throws IOException
	{
		n=nextInt();
		k=nextInt();
		list=new ArrayList[n+1];
		for(int i=0;i<=n;i++)
			list[i]=new ArrayList<>();
		for(int i=1;i<n;i++)
		{
			int u=nextInt();
			int v=nextInt();
			list[u].add(v);
			list[v].add(u);
		}
		int ans=inf;
		if(k%2==0)
		{
			for(int i=1;i<=n;i++)
				ans=Math.min(ans,count(i,0));
		}
		else
		{
			for(int i=1;i<=n;i++)
				for(int j:list[i])
					ans=Math.min(ans,count(i,j));
		}
		out.println(ans);
	}
	int count(int x,int y)
	{
		Queue<Integer> queue=new LinkedList<>();
		queue.add(x);
		queue.add(y);
		int dist[]=new int[n+1];
		Arrays.fill(dist,inf);
		dist[x]=0;
		dist[y]=0;
		while(!queue.isEmpty())
		{
			int v=queue.remove();
			for(int vv:list[v])
				if(dist[vv]>dist[v]+1)
				{
					dist[vv]=dist[v]+1;
					queue.add(vv);
				}
		}
		int c=0;
		for(int i=1;i<=n;i++)
			if(dist[i]>k/2)
				c++;
		return c;
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 148316
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (n, m) = readListOfInt() 
    val a = (0 until m).map { readInt() }

    val broken = (0..n).map { false }.toMutableList()
    a.forEach { broken[it] = true }

    val dp = (0..n).map { 0L }.toMutableList()
    dp[1] = if(broken[1]) 0L else 1L
    if(n > 1) {
        dp[2] = if(broken[2]) 0L else dp[1] + 1L

        for(i in 3..n) {
            val onestep = if(broken[i-1]) 0L else dp[i-1]
            val twostep = if(broken[i-2]) 0L else dp[i-2]
            dp[i] = if(broken[i]) 0L else (onestep + twostep) % MOD
        }
    }
    println(dp[n])
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


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

int main() {
	int res_price = 700;
	string str;
	std::cin >> str;
	
	for (int i = 0; i < 3; i++) {
		if (str[i] == 'o')
			res_price += 100;
	}
	
	printf("%d", res_price);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll A, B;
    cin >> A >> B;
    ll tmp = abs(A - B);
    if (tmp % 2 == 1) {
        print("IMPOSSIBLE");
        return 0;
    } 
        
    print(min(A,B) + tmp/2);
    return 0;
}

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

const int mod=1e9+7,N=3e6+9;
int fac[N],ifac[N];

int pw(int a,int t=mod-2){
    int x=1;
    while(t>0){
        if(t&1)x=x*a%mod;
        a=a*a%mod,t>>=1;
    }
    return x;
}
int C(int n,int r){
    if(r<0 or r>n)return 0;
    return fac[n]*ifac[r]%mod*ifac[n-r]%mod;
}
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    fac[0]=ifac[0]=1;
    for(int i=1;i<N;i++){
        fac[i]=i*fac[i-1]%mod;
        ifac[i]=pw(fac[i]);
    }
    int k;
    string st;
    cin >> k >> st;
    int m=(int)st.size()+k,n=(int)st.size(),ans=0;
    int x=1,y=pw(n,m-n),iv=pw(n);
    for(int i=n;i<=m;i++){
        int t=C(i-1,n-1)*pw(25,i-n)%mod*pw(26,m-i)%mod;
        ans=(ans+t)%mod;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 51120
#include<iostream>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>
using namespace std;

double manhattanDistance(const vector<int>& x, const vector<int>& y, const int n){
    double ret = 0;
    for(int i = 0; i < n; ++i){
        ret += abs(x[i] - y[i]);
    }
    return ret;
}

double minkowskiDistance(const vector<int>& x, const vector<int>& y, const int n, const int p){
    
    if(p == 1){
        return manhattanDistance(x, y, n);
    }
    
    double ret = 0;
    for(int i = 0; i < n; ++i){
        ret += pow(abs(x[i] - y[i]), p);
    }
    return pow(ret, (double) 1 / (double) p);
}

double ChebyshefDistance(const vector<int>& x, const vector<int>& y, const int n){
    double ret = 0;
    for(int i = 0; i < n; ++i){
        ret = max(ret, (double) abs(x[i] - y[i]));
    }
    return ret;
}

int main(){

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

    // マンハッタン距離 P = 1
    cout << fixed << setprecision(10) << minkowskiDistance(x, y, n, 1)  << endl;

    // ユークリッド距離 P = 2
    cout << fixed << setprecision(10) << minkowskiDistance(x, y, n, 2)  << endl;
    
    // P = 3
    cout << fixed << setprecision(10) << minkowskiDistance(x, y, n, 3)  << endl;

    // マンハッタン距離 P = ∞
    cout << fixed << setprecision(10) << ChebyshefDistance(x, y, n) << endl;

    return 0;
}


Measured memory_bytes: 3472
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
#define NIL -1

struct Tree{
	int left,right,parent;
};

Tree *T;
int n;

void preorder(int i){
	if(i == NIL) return;
	cout << " " << i;
	preorder(T[i].left);
	preorder(T[i].right);
} 

void inorder(int i){
	if(i == NIL) return;
	inorder(T[i].left);
	cout << " " << i;
	inorder(T[i].right);
}

void postorder(int i){
	if(i == NIL) return;
	postorder(T[i].left);
	postorder(T[i].right);
	cout << " " << i;
}

int main(){
	cin >> n;
	T = new Tree[n];
	int a,b,c;
	for(int i = 0;i < n;i++){
		T[i].left = T[i].right = T[i].parent = NIL;
	}
	for(int i = 0;i < n;i++){
		cin >> a >> b >> c;
		if(b != NIL){
			T[a].left = b;
			T[b].parent = a;
		}
		if(c != NIL){
			T[a].right = c;
			T[c].parent = a;
		}
	}
	int root;
	for(int i = 0;i < n;i++){
		if(T[i].parent == NIL) root = i;
	}
	cout << "Preorder" << endl;
	preorder(root);
	cout << endl <<"Inorder" << endl;
	inorder(root);
	cout << endl << "Postorder" << endl;
	postorder(root);
	cout << endl;
	return 0;
}

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

signed main()
{
    double N;

    cin >> N;

    double x = ceil((N / 1.08));

    int y = x * 1.08;


    if (y == (int)N)
    {
        cout << x << endl;
    }
    else
    {
        cout << ":(" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    ll X;
    scanf("%d%lld", &n, &X);

    vector<ll> b(n),L(n),U(n);
    vector<pair<ll,int> > z;
    ll pnt0 = 0;
    int i;
    for(i=0; i<n; i++) {
        scanf("%lld%lld%lld", &b[i], &L[i], &U[i]);
        ll tmp = U[i]*(X-b[i]) + L[i]*b[i];
        z.push_back(make_pair(tmp, i));
        pnt0 -= (L[i]*b[i]);
    }
    sort(z.rbegin(), z.rend());
    vector<ll> sz(n+1,0);
    for(i=0; i<n; i++) {
        sz[i+1]=sz[i]+z[i].first;
    }

    ll l=-1, r=X*n;
    while(r-l>1) {
        ll m = (l+r)/2;

        ll  num = m/X;
        ll  add = m%X;

        ll max=-LINF;
        for(i=0; i<n; i++) {
            ll sum = 0;
            if(i>=num) {
                sum = sz[num];
            }
            else {
                sum = sz[num+1] - z[i].first;
            }

            int id = z[i].second;
            if(add>=b[id]) {
                sum += U[id]*(add-b[id]) +L[id]*b[id];
            }
            else {
                sum += L[id]*(add-b[id]) +L[id]*b[id];
            }
            max = MAX(max,sum);
        }

        if( max+pnt0 >=0 ) {   //ok
            r = m;
        }
        else {
            l = m;
        }
    }
    printf("%lld\n", r);

    return 0;
}



Measured memory_bytes: 4976
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <ctime>
#include <cmath>
#include <bits/stdc++.h>
#include <string.h>
#define inf 0x7fffffff
using namespace std;
struct P
{
    int x,y,z;

    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x>a.x;
//        return z>a.z;
    }
};
vector<int> v;
int a,b,c,n,m,i,k,o[5][250022],d,e,dy[15]={0,0,-1,1,-1,1,-1,1},dx[15]={-1,1,0,0,1,1,-1,-1};
int l[211511];
//long long x,y,z[10055];
//P u[1000600];
//int j[500],j2[500];
//queue<int> q,q1;
stack<int> s;
queue<int> q;
long long x,y=0,z[99];

//deque<int> d;
//'1'==49;
//'A'==65;
//'a'==97;
//map<int, int > p[100010];
string r;
//char r[250010];

bool as(int a,int b)
{
     return a>b;

}


void f()
{
    for(int b=v.size()-2;b>=0;b--)
    {
        o[0][b]=max(o[0][b+1]-1,o[2][b+1])+v[b+1];
        o[1][b]=max(o[1][b+1]-1,o[2][b+1])+v[b];
        if(v[b+1]>1) o[1][b]=max(o[1][b],o[0][b+1]+v[b]);
        o[2][b]=max(max(o[0][b+1] , o[1][b+1] ), o[2][b+1] );
        //printf("%d %d %d\n",o[0][b],o[1][b],o[2][b]);
    }

}
//2147483647
int main()
{
    scanf("%d",&a);
    cin>>r;
    /*for(int t=0;t<250000;t+=5)
    {
        r[t]='1';
        r[t+1]='0';
        r[t+2]='1';
        r[t+3]='0';
        r[t+4]='0';
    }*/
    for(int t=0;t<r.size();t++)
    {
        //printf("%d\n",t);
        if((r[t]=='0'&&r[t+1]=='0')||t+1==r.size())
        {
            if(r[t]=='1') i++;

        if(i)
            v.push_back(i);
        //memset(o,0,sizeof(o));
        if(v.size()>1)
        {
            //for(int w=0;w<v.size();w++)
            //    printf("%d ",v[w]);
            //printf("%d\n",t);
            //printf("#%d %d\n",t,v.size());
        f();
        //o[0][0]=max(o[0][0],max(o[0][2]+v[0],max(o[1][2]+v[0],o[2][2]+v[0])));
        k+=max(o[0][0],max(o[1][0],o[2][0]));
        }
        for(;v.size();o[0][v.size()]=o[1][v.size()]=o[2][v.size()]=0,v.pop_back());

        o[0][v.size()]=o[1][v.size()]=o[2][v.size()]=0;
        i=0;
        }
        else if(r[t]=='0')
        {
            if(i)
            v.push_back(i);
            i=0;
        }
        else i++;
    }
    printf("%d",k);
}


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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
    int n,r;
    cin>>n>>r;
    
    if(n>=10){
        cout<<r<<endl;
    }else{
        cout<<r+100*(10-n)<<endl;
    }
}

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

C = []
S = []
F = []
for i in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(N-1):
    res = S[i] + C[i]
    for j in range(i+1,N-1):
        if res < S[j]:
            res = S[j] + C[j]
        else:
            t = (res - S[j]) % F[j]
            res += (F[j] - t) % F[j] + C[j]
    print(res)

print(0)

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(v) {for (auto x : v) cerr << x << ' '; cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n; scanf("%d", &n);
	multiset<int> s;
	for (int i = 0; i < n; i++) {
		int x; scanf("%d", &x);
		x = -x;
		auto it = s.upper_bound(x);
		if (it != s.end()) s.erase(it);
		s.insert(x);
	}
	printf("%lu\n", s.size());
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
using namespace std;
#define N 3

int main()
{
  int c[N][N];

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin >> c[i][j];
    }
  }

  int b[N];
  for(int i=0;i<N;i++){
    b[i] = c[0][i];
  }

  int a[N];
  a[0] = 0;
  a[1] = c[1][0] - b[0];
  a[2] = c[2][0] - b[0];

  for(int i=1;i<N;i++){
    for(int j=1;j<N;j++){
      if(c[i][j] != a[i] + b[j]){
        cout << "No\n";
        return 0;
      }
    }
  }

  cout << "Yes\n";
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
#define pb push_back
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)
cout << fixed << setprecision(2) << 3.14 << endl; //3.1

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

  ll n, m, count=0, ans=1;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  sort( s.begin(), s.end());
  rep(i,n-1){
    if(s[i]!=s[i+1]) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 9596
moji = list(input())
hako = []
yes = 0
for m in moji:
  if m not in hako:
    hako.append(m)
if len(hako) == 2:
  for h in hako:
    if moji.count(h) == 2:
      yes += 1
if yes == 2:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define mk make_pair
#define f first
#define s second
int main(){
  int n,w,h,q1,q2;
  while(cin>>n>>w>>h,h){
    vector<pair<int,int> >v;
    v.push_back(mk(w,h));
    for(int i=0;i<n;i++){
      cin>>q1>>q2;q1--;
      q2=q2%(v[q1].f+v[q1].s);
      if(q2<=v[q1].f){
        v.push_back(mk(q2,v[q1].s));
        v.push_back(mk(v[q1].f-q2,v[q1].s));
        if(q2>v[q1].f-q2)swap(v[v.size()-1],v[v.size()-2]);
        v.erase(v.begin()+q1);
      }
      else{
        q2-=v[q1].f;
        v.push_back(mk(v[q1].f,q2));
        v.push_back(mk(v[q1].f,v[q1].s-q2));
        if(q2>v[q1].s-q2)swap(v[v.size()-1],v[v.size()-2]);
        v.erase(v.begin()+q1);
      }
    }
    vector<int>p;
    for(int i=0;i<v.size();i++)
      p.push_back(v[i].f*v[i].s);
    sort(p.begin(),p.end());
    for(int i=0;i<p.size();i++){
      if(i)cout<<' ';
      cout<<p[i];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3128
x = int(input())
DP = [0]*(x+1)
DP[0] = 1
for i in range(x):
    if not DP[i]:
        continue
    for j in range(6):
        k = i+100+j
        if 0<=k<=x:
            DP[k] = 1
print(DP[-1])

Measured memory_bytes: 41452
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
  int n,a,b,out=0;
  cin >> n >> a >> b;

  for(int i=1;i<=n;i++){
    int i10000=i/10000;
    int i01000=(i-i10000*10000)/1000;
    int i00100=(i-i10000*10000-i01000*1000)/100;
    int i00010=(i-i10000*10000-i01000*1000-i00100*100)/10;
    int i00001=(i-i10000*10000-i01000*1000-i00100*100-i00010*10);
    int sum=i10000+i01000+i00100+i00010+i00001;
    if(sum>=a && sum<=b) out+=i;
  }

  cout << out << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    long long res = 0;
    for(int i = 1; i<=N; i++) {
        if(i % 3 != 0 && i % 5 != 0) res += i;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
class Dice
{
    //デフォルトはプライベート
    int top;
    int front;
    int right;
    int left;
    int back;
    int bottom;

public:
    Dice(int top, int front, int right, int left, int back, int bottom);
    void roll(char command[]);
    int get_top();
};
Dice::Dice(int top, int front, int right, int left, int back, int bottom)
{
    this->top = top;
    this->front = front;
    this->right = right;
    this->left = left;
    this->back = back;
    this->bottom = bottom;
}
void Dice::roll(char command[])
{
    int i = 0;
    while (*(command + i))
    {
        int tmp;
        switch (*(command + i))
        {
        case 'S':
            tmp = top;
            top = back;
            back = bottom;
            bottom = front;
            front = tmp;
            break;
        case 'N':
            tmp = top;
            top = front;
            front = bottom;
            bottom = back;
            back = tmp;
            break;
        case 'W':
            tmp = top;
            top = right;
            right = bottom;
            bottom = left;
            left = tmp;
            break;
        case 'E':
            tmp = top;
            top = left;
            left = bottom;
            bottom = right;
            right = tmp;
            break;
        }
        i++; //初め、while(*d.command)でd.command++にしてたが出来なかった。
    }
}
int Dice ::get_top()
{
    return top;
}
int main(void)
{
    //初めにDiceの初期値を与えることにする(コンストラクタ)
    int top, front, right, left, back, bottom;
    cin >> top >> front >> right >> left >> back >> bottom;
    Dice d(top, front, right, left, back, bottom); //コンストラクタ
    char command[101];
    cin >> command;
    d.roll(command);
    cout << d.get_top() << endl;
}



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

#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 FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)

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

inline int toInt(string s) { int x; istringstream iss(s); iss >> x; return x; }
template<class T> inline string toString(T x) { ostringstream oss; oss <<x ; return oss.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> pii;
typedef long long ll;

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

int main() {
  ll n;
  scanf("%lld", &n);
  vector<ll> a(n, 0), b(n, 0);
  REP(i, n) {
    scanf("%lld", &a[i]);
    if (i == 0) b[i] = a[i];
    else b[i] = b[i - 1] + a[i];
  }
  b.push_back(0);
  SORT(b);


  ll now = b[0];
  ll cnt = 1;
  ll res = 0;

  FOR(i, 1, n + 1) {
    if (now == b[i]) cnt++;
    else {
      res += cnt * (cnt - 1) / 2;
      now = b[i];
      cnt = 1;
    }
  }
  res += cnt * (cnt - 1) / 2;

  printf("%lld\n", res);

  return 0;
}



Measured memory_bytes: 6272
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vi adj[N];
int p[N];
int ans[N];
int dfs(int x,int par,int sum)
{
    ans[x]+=sum;
    ans[x]+=p[x];
    for(auto y:adj[x])
    {
        if(y!=par)
        {
            dfs(y,x,sum+p[x]);
        }
    }
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,q;
   cin>>n>>q;
   rep(i,0,n-1)
   {
       int u,v;
       cin>>u>>v;
       adj[u].pb(v);
       adj[v].pb(u);
   }
   while(q--)
   {
       int x,val;
       cin>>x>>val;
       p[x]+=val;
   }
   dfs(1,0,0);
   for(int i=1;i<=n;i++)
    cout<<ans[i]<<" ";


}



Measured memory_bytes: 25600