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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = K; i < N; i++)
        cout << (A[i - K] < A[i] ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 998244353;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
public:
    int solve(int n, int k, vector<int>& arr) {
        vector<vector<vector<int64>>> dp(n + 1, vector<vector<int64>>(k + 1, vector<int64>(3)));
        //int64 dp[n + 1][k + 1][3] = {};
        dp[0][0][0] = 1;
        for(int i = 0; i < n; ++i) {
            for(int s = 0; s <= k; ++s) {
                (dp[i + 1][s][0] += dp[i][s][0]) %= mod;
                (dp[i + 1][s][1] += dp[i][s][0] + dp[i][s][1]) %= mod;
                (dp[i + 1][s][2] += dp[i][s][0] + dp[i][s][1] + dp[i][s][2]) %= mod;
                if(s + arr[i] <= k) {
                    (dp[i + 1][s + arr[i]][1] += dp[i][s][0] + dp[i][s][1]) %= mod;
                    (dp[i + 1][s + arr[i]][2] += dp[i][s][0] + dp[i][s][1]) %= mod;
                }
            }
        }
        return dp[n][k][2];
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i) cin >> arr[i];
    Solution sol;
    auto ret = sol.solve(n, k, arr);
    cout << ret << endl;
}

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

using namespace std;

int main()
{
	std::vector<int> durations;
	int max_interval = 0;
	int max_interval_idx = 0;
	for( int ii = 0; ii < 5; ++ii ){
		int tmp;
		cin >> tmp;
		durations.push_back(tmp);

		int interval = (10 - tmp%10);
		if( 0 < interval && interval < 10 && interval > max_interval){
			max_interval = interval;
			max_interval_idx = ii;
		}
	}
	
	for( int ii = 0; ii < 5; ++ii ){
		if( ii != max_interval_idx && durations[ii] % 10 > 0 ){
			durations[ii] += (10 - durations[ii]%10);
		}
	}
	
	int totalDuration = 0;
	for( const auto& d : durations ){
		totalDuration += d;
	}
	
	cout << totalDuration << endl;
	
	return 0;
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#define db(x) cout << "> " << #x << " = " \
	<< (x) << '\n'
#define db2(x, y) cout << "> " << #x << " = " \
	<< (x) << ", " << #y << " = " << (y) << '\n'
#define db3(x, y, z) cout << "> " << #x << \
	" = " << (x) << ", " << #y << " = " << \
	(y) << ", " << #z << " = " << (z) << '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
typedef map<int, int> mii;
typedef set<int> si;

int n, a, b;

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);
	cin >> n >> a >> b;
	cout << min(b, a * n) << '\n';
	return 0;
}


Measured memory_bytes: 256
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
//#define BIN_SEARCH(v, a) binary_search(v.begin(), v.end(), a)
//#define BIN_INSERT(v, a) v.insert(v.begin() + BIN_SEARCH(v, a) - 1, a)
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;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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; }
// template end

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

    ll n;
    in >> n;

    ll a_init, a_min, a_i;
    in >> a_i;
    a_min = a_i;
    vector<ll> v = {a_i};

    REP(i, n-1){
        in >> a_i;
        if(a_min >= a_i){
            ll idx = lower_bound(ALL(v), a_i) - v.begin();
            v.insert(v.begin() + idx, a_i);
            a_min = a_i;
        }else{
            ll idx = lower_bound(ALL(v), a_i) - v.begin();
            v.erase(v.begin() + idx - 1);
            idx = lower_bound(ALL(v), a_i) - v.begin();
            v.insert(v.begin() + idx, a_i);
            a_min = v[0];
        }
    }
    out << v.size() << endl;
}


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

H, W = map(int, readline().split())
G = [[0]*W for _ in range(H)]
L1 = [[0]*1000 for _ in range(W+H-1)]
geta1 = W-1
L2 = [[0]*1000 for _ in range(W+H-1)]
for i in range(H):
    S = [1 if s == '#' else 0 for s in readline().strip()]
    for j in range(W):
        G[i][j] = S[j]
        if S[j]:
            L1[i-j+geta1][i] = 1
            L2[i+j][i] = 1
for sub in range(W+H-1):
    for i in range(630):
        L1[sub][i] += L1[sub][i-1]
        L2[sub][i] += L2[sub][i-1]

res = 0
for su in range(2*max(H, W)+1):
    for w in range(max(0, su-H+1), min(W, su+1)):
        h = su-w
        if not G[h][w]:
            continue
        for k in range(1, min(h+1, W-w)):
            if not G[h-k][w+k]:
                continue
            idx1 = h+w-2*k
            if 0 <= idx1 < H+W-1:
                res += L2[idx1][h-k-1] - L2[idx1][h-2*k]
            idx2 = h+w+2*k
            if 0 <= idx2 < H+W-1:
                res += L2[idx2][h+k-1] - L2[idx2][h]

for mi in range(1-W, H):
    for w in range(max(0, -mi), min(W, H-mi)):
        h = mi + w
        if not G[h][w]:
            continue
        for k in range(1, min(H-h, W-w)):
            if not G[h+k][w+k]:
                continue
            idx1 = h-w-2*k + geta1
            if 0 <= idx1 < H+W-1:
                res += L1[idx1][h] - L1[idx1][h-k-1]
            idx2 = h-w+2*k + geta1
            if 0 <= idx2 < H+W-1:
                res += L1[idx2][h+2*k] - L1[idx2][h+k-1]

print(res)

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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double 
#define db double
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main()
{
    int n,m;
    cin>>n>>m;
    int arr[n+1];
    for(int i=1;i<=n;i++)
     cin>>arr[i];
    vi v[n+1];
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        int f=1;
        for(int j=0;j<v[i].size();j++)
        {
            int ch=v[i][j];
            if(arr[ch]>=arr[i])
            {
                f=0;
                break;
            }
        }
        if(f)
         cnt++;
    }
    cout<<cnt<<"\n";
      return 0;
}

Measured memory_bytes: 10232
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;;
const int maxn = 2e5 + 5;

int n;
string s;
map<vector<int>,int> mmap;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);	
	cin >> n;
	ll res = 0;
	for(int i = 0 ; i < n ; ++i){
		cin >> s;
		vector<int> cnt(26 , 0);
		for(int c : s)cnt[c - 'a']++;
		res += mmap[cnt]++;
	}
	cout << res;
}


Measured memory_bytes: 19072
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		HashMap<Integer, int[]> zahyo = new HashMap<>();

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int[] point = { a, b };
			zahyo.put(i, point);
		}
		// 距離の計算
		double len = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				len = len + Math.sqrt((zahyo.get(i)[0] - zahyo.get(j)[0]) * (zahyo.get(i)[0] - zahyo.get(j)[0]) + //
						(zahyo.get(i)[1] - zahyo.get(j)[1]) * (zahyo.get(i)[1] - zahyo.get(j)[1]));
			}
		}
		int add = 0;
		for (int i = 1; i < n; i++) {
			add = add + i;
		}
		System.out.println(len * (n - 1) / add);
	}

}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

ll dp[100005];
int n, W;
int w[105], v[105];

int main(){
    fio;
    cin >> n >> W;
    memset(dp,0x3f3f3f3f,sizeof(dp));
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
        for(int j = 1000 * n - v[i]; j >= 0; j--){
            dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
        }
    }
    for(int i = 1000 * n; i >= 0; i--){
        if(dp[i] <= W){
            cout << i << '\n';
            return 0;
        }
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
		using namespace std;
		#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
		#include <ext/pb_ds/assoc_container.hpp> 
		#include <ext/pb_ds/tree_policy.hpp> 
		using namespace __gnu_pbds; 
		#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
		 
		#define ff first
		#define ss second
		#define mp make_pair
		 
		#define pb push_back
		#define endl "\n"
		 
		#define int long long 
		#define double long double
		 
		#define bp __builtin_popcountllm
		#define inf 1e16
		const int N=1e5+5;
		const int M=105;
		const int MOD=1e9+7;
	
		void solve()
		{	
			int a,b,c;
			cin>>a>>b>>c;
			
			int x=4*a*b;
			if(c-a-b<0)
			{
				cout<<"No";
				return;
			}
			int z=(c-a-b)*(c-a-b);
			if(x<z)
			cout<<"Yes";
			else
			cout<<"No";
		}

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


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

alphabets = [chr(ord('a') + x) for x in range(26)]

tmp = []

def dfs(s, i):
    if len(s) == n:
        yield s
        return
    for j in range(i):
        for k in dfs(s+alphabets[j], i):
            yield k
    for k in dfs(s+alphabets[i], i+1):
        yield k

for w in dfs('', 0):
    print(w)

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

int s(int n) {
  int tot = 0;
  while (n) {
    tot += n % 10;
    n /= 10;
  }
  return tot;
}

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

  int n;
  cin >> n;
  string ans = (n % s(n)) ? "No" : "Yes";
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
# Peaks
import numpy as np
N,M = map(int,input().split())
h = np.array(list(map(int,input().split())))
x = dict()
for _ in range(M):
    a,b = map(int,input().split())
    if a-1 not in x.keys():
        x[a-1] = []
    if b-1 not in x.keys():
        x[b-1] = []
    x[a-1].append(b-1)
    x[b-1].append(a-1)
ans = 0
for k,v in x.items():
    cand = h[k]
    tied = h[np.array(v)]
    ans += [0, 1][sum(tied >= cand) == 0]
ans += N - len(x.keys())
print(ans)

Measured memory_bytes: 49416
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e3+5;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	cin >> n;
	ll mn = 2e9;
	for (int i = 0; i < n; i++)
	{
		ll x, cnt = 0;
		cin >> x;
		while(x % 2 == 0)
			x /= 2, cnt++;
		mn = min(mn, cnt);
	}
	cout << mn;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt(); // 46979秒
        int c = a / 3600; // 13時間
        int d = a - c * 3600;
        int e = d / 60;
        int f = d - e * 60;
        System.out.println(c + ":" + e + ":" + f);
        
	}
}


Measured memory_bytes: 26176
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;


int main(){
    int x[3];
    int x_p[3];
    int moves = 0;
    cin >> x[0] >> x[1] >> x[2];

    x_p[0] = x[0]%2;
    x_p[1] = x[1]%2;
    x_p[2] = x[2]%2;

    if (x_p[0]+x_p[1]+x_p[2] == 1){
      moves++;
      if (x_p[0] == 1) {
        x[1]++;
        x[2]++;
      }
      if (x_p[1] == 1) {
        x[0]++;
        x[2]++;
      }
      if (x_p[2] == 1) {
        x[0]++;
        x[1]++;
      }
    }
    if (x_p[0]+x_p[1]+x_p[2] == 2){
      moves++;
      if (x_p[0] == 0) {
        x[1]++;
        x[2]++;
      }
      if (x_p[1] == 0) {
        x[0]++;
        x[2]++;
      }
      if (x_p[2] == 0) {
        x[0]++;
        x[1]++;
      }
    }

    sort(x, x+3, greater<int>());

    moves += (x[0] - x[1])/2;
    moves += (x[0] - x[2])/2;

    cout << moves << endl;




  return 0;
}

Measured memory_bytes: 256
function Main(input) {
  const arr = input.split('\n');
  const n = arr[0];
  const m = arr[1].split(' ').map(x => Number(x));
  const result = Array.from({length: n}, (v, i) => 0);
  m.forEach(x => {
    result[x - 1] += 1;
  });

  console.log(result.join('\n'));

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

Measured memory_bytes: 54936
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //e
  int h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  vector<int> dp(h + 20001, 1 << 30);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= h + 20000; j++) {
      if (j - a[i] >= 0) dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
    }
  }
  int ans = 1 << 30;
  for (int i = h; i <= h + 20000; i++) ans = min(ans, dp[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] str = br.readLine().split(" ");
        int[] s = new int[n];

        for (String i : str) {
            s[Integer.parseInt(i) - 1]++;
        }
        for (int j : s) {
            System.out.println(j);
        }

    }
}


Measured memory_bytes: 64912
n,k=map(int,input().split())
V=list(map(int,input().split()))
ans=0
for i in range(n+1):
    for j in range(n-i+1):
        if i+j>k:
            continue
        tmp=V[:i]+V[n-j:]
        tmp.sort(reverse=True)
        for l in range(k-i-j):
            if tmp and tmp[-1]<0:
                tmp.pop()
            else:
                break
        ans=max(ans,sum(tmp))
print(ans)

Measured memory_bytes: 41836
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
abcd = [tuple(map(int, input().split())) for i in range(Q)]
ans = 0
for x in combinations_with_replacement(range(1, M+1), 10):
    tmp = 0

    for a, b, c, d in abcd:
        a -= 1
        b -= 1
        if x[a] + c == x[b]:
            tmp += d
    ans = max(ans, tmp)


print(ans)


Measured memory_bytes: 9084
import java.util.Scanner;

/**
 * Created by zzt on 17-1-29.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        int start = s.indexOf('A');
        int end = s.lastIndexOf('Z');
        System.out.println(end - start + 1);
    }
}

Measured memory_bytes: 14156
#include<iostream>
#include<vector>
#include<queue>
#define MOD 1000000007

using namespace std;

long long Dist[2][100005];
int Nr[2][100005];
vector<pair<int,int> > V[100005];
priority_queue<pair<long long,int> > Q;
pair<pair<int,int>,int> E[200005];

void getDist(int start, int cr)
{
    Dist[cr][start]=0;
    Nr[cr][start]=1;

    Q.push({0,start});
    while(!Q.empty())
    {
        long long cost=-Q.top().first;
        int nod=Q.top().second;
        Q.pop();

        if(cost!=Dist[cr][nod])
            continue;

        for(auto other:V[nod])
        {
            if(cost+other.second<Dist[cr][other.first])
            {
                Nr[cr][other.first]=0;
                Dist[cr][other.first]=cost+other.second;
                Q.push({-Dist[cr][other.first],other.first});
            }

            if(cost+other.second==Dist[cr][other.first])
                Nr[cr][other.first]=(Nr[cr][other.first]+Nr[cr][nod])%MOD;
        }
    }
}

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

    int n,m,s,t;
    cin>>n>>m>>s>>t;

    for(int i=1; i<=m; i++)
    {
        cin>>E[i].first.first>>E[i].first.second>>E[i].second;

        V[E[i].first.first].push_back({E[i].first.second,E[i].second});
        V[E[i].first.second].push_back({E[i].first.first,E[i].second});
    }

    for(int i=1; i<=n; i++)
        Dist[0][i]=Dist[1][i]=1000000000000000000LL;

    getDist(s,0);
    getDist(t,1);

    int rez=(1LL*Nr[0][t]*Nr[0][t])%MOD;
    long long cost=Dist[0][t];
    for(int i=1; i<=n; i++)
    {
        if(Dist[0][i]==Dist[1][i] && Dist[0][i]==cost/2)
            rez=(rez-(1LL*((1LL*Nr[0][i]*Nr[1][i])%MOD)*((1LL*Nr[0][i]*Nr[1][i])%MOD)%MOD)+MOD)%MOD;
    }

    for(int i=1; i<=m; i++)
    {
        int x=E[i].first.first;
        int y=E[i].first.second;
        int c=E[i].second;

        if(Dist[0][x]+Dist[1][y]+c>Dist[0][y]+Dist[1][x]+c)
            swap(x,y);

        if(Dist[0][x]+Dist[1][y]+c!=cost)
            continue;

        if(Dist[0][x]<(cost+1)/2 && Dist[0][x]+c>cost/2)
            rez=(rez-(1LL*((1LL*Nr[0][x]*Nr[1][y])%MOD)*((1LL*Nr[0][x]*Nr[1][y])%MOD)%MOD)+MOD)%MOD;
    }

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


Measured memory_bytes: 15220
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define PI 2*acos(0.0)
#define boost ios::sync_with_stdio(false);cin.tie(0)
/*ll arr[1000000];void seive(){memset(arr,1,sizeof(arr));arr[0]=arr[1]=0;for(ll i=2;i<=(sqrt(1000000));i++){if(arr[i]){for(ll j=(i+i);j<=1000000;j+=i){arr[j]=0;}}}}*/
int main()
{
 boost;
ll n;
cin>>n;
if(n%1000==0) cout<<0<<endl;
else 
cout<<1000-(n%1000)<<endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <utility>
#include <limits>
using namespace std;
const int MAX_N = 1e5 + 2;
int dp[MAX_N];
const int INF = numeric_limits<int>::max() / 2;
int main()
{
    int n;
    cin >> n;
    vector<int> hs;
    for(int i = 0; i < n; ++i)
    {
        int h;
        cin >> h;
        hs.push_back(h);
    }

    fill_n(dp, n, INF);
    dp[0] = 0;
    for(int i = 0; i < n; ++i)
    {
        dp[i+1] = min(dp[i] + abs(hs[i] - hs[i+1]), dp[i+1]);
        dp[i+2] = min(dp[i] + abs(hs[i] - hs[i+2]), dp[i+2]);
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1144
#include <stdio.h>
int main(){
    int a[100][100],low[100],top,n;
    bool f;
    while(1){
    scanf("%d",&n);
        if(n==0)return 0;
        f=true;
        top=0;
    for(int i=0;i<n;i++){
        low[i]=0;
        for(int j=0;j<n;j++){
            scanf("%d",&a[i][j]);
            if(a[i][j]<a[i][low[i]]){
                low[i]=j;
            }
        }
        if(a[i][low[i]]>a[top][low[top]])top=i;
    }
    for(int i=0;i<n&&f;i++){
        if(a[top][low[top]]<a[i][low[top]]){
            f=false;
            printf("0\n");
        }
    }
        if(f)printf("%d\n",a[top][low[top]]);
    }
}

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

int main() {
  int n, s, p, q, r, c, P, Q, R, C;
  while (cin >> n, n) {
    vector <vector<int>> u;
    vector<int> v;
    while (n--) {
      cin >> s >> p >> q >> r;
      c = 4 * p + 9 * q + 4 * r;
      u.push_back({s,p,q,r,c});
    }
    cin >> P >> Q >> R >> C;
    for (const auto& e : u) {
      if (e[1] <= P && e[2] <= Q && e[3] <= R && e[4] <= C) {
        v.push_back(e[0]);
      }
    }
    if (v.empty()) {
      cout << "NA\n";
    } else {
      for (const auto& e : v) {
        cout << e << "\n";
      }
    }
  }
}


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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  ll N;
  cin >> N;
  
  auto dfs = [&](auto&& f, int keta, ll sum){
    sum *= 26;
    if(N <= sum){
      N--;
      string ans(keta, 'a');
      int id = keta-1;
      while(N){
        ans[id] = N % 26 + 'a';
        N /= 26;
        id--;
      }
      cout << ans << endl;
      return;
    }
    N -= sum;
    f(f, keta+1, sum);
  };
  
  dfs(dfs, 1, 1);
  return 0;
}

Measured memory_bytes: 3536
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    int h,w;cin>>h>>w;
    while(h&&w){
        for(int i=0;i<h;i++){
            if(i%2==0){
            bool abc=1;
            for(int j=0;j<w;j++){
                if(abc==1){cout<<'#';abc=0;}
                else {cout<<'.';abc=1;}

            
            }cout<<Endl;
        }
        else{
            bool abc=0;
            for(int j=0;j<w;j++){
                if(abc==1){cout<<'#';abc=0;}
                else {cout<<'.';abc=1;}

            }cout<<endl;
        }
        }
 
        cin>>h>>w;
        cout<<endl;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

































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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    double a, b, x, ans;
    cin >> a >> b >> x;

    if(x<=a*a*b/2.0) ans = atan(a*b*b/2.0/x);
    else ans = atan((2*b-2*x/a/a)/a);

    ans *= 180.0/acos(-1);

    cout << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        if(n == 1) {
            System.out.println(0);
            System.exit(0);
        }
        
        System.out.println((n*(n-1))/2);
    }
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  int cnt=1;
  int now=0;
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    now+=l;
    if(now<=x)cnt++;
  }
  cout<<cnt<<endl;
  return(0);
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
l = sorted(a, reverse=True)
sum = sum(l) / 4 / m
count = 0

for i in range(len(l)):
    if l[i] >= sum:
        count += 1
    else:
        break


if count >= m:
    print("Yes")
else:
    print("No")


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

int main(){

	while(true){
		int n;
		int count = 0;
		cin >> n;
		if(n == 0){
			break;
		}

		bool* prime = new bool[(n * 2) + 5];

		for(int i = 1; i < n * 2 + 1; i++){
			prime[i] = 0;
		}
		prime[0] = 1;

		for(int i = 2; i <= n; i++){
			for(int j = 2; i * j <= n * 2; j++){
				if(prime[i * j - 1] == 0){
					prime[i * j - 1] = 1;
				}
			}
		}

		//for(int i = 0; i <= n * 2; i++){
		//	cout << "prime[" << i << "] = " << prime[i] << endl;
		//}

		for(int i = n; i <= n * 2 - 1; i++){
			if(prime[i] == 0){
				count++;
			}
		}

		cout << count << endl;
	}
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define INF 999999999
using LL = long long;
using VI = vector<int>;
struct card{char suit,value;};

void bubble(struct card a[],int n){
  rep(i,n){
    for(int j=n-1;j>=i;j--){
      if(a[j].value < a[j-1].value){
        card t = a[j];a[j] = a[j-1];a[j-1] = t;
      }
    }
  }
}
void select(struct card a[],int n){
  rep(i,n){
    int minj = i;
    REP(j,i,n){
      if(a[j].value<a[minj].value) minj = j;
    }
    card t = a[i];a[i] = a[minj];a[minj] = t;
  }
}
void print(struct card a[],int n){
  rep(i,n){
    if(i>0) cout << " ";
    cout << a[i].suit << a[i].value;
  }
  cout << endl;
}

bool isstable(struct card c1[],struct card c2[],int n){
  rep(i,n){
    if(c1[i].suit!=c2[i].suit) return false;
  }
  return true;
}

int main(){
  card c1[100],c2[100];
  int n;cin >> n;
  rep(i,n) cin >> c1[i].suit >> c1[i].value;
  rep(i,n) c2[i] = c1[i];
  bubble(c1,n);
  select(c2,n);
  print(c1,n);
  cout << "Stable" << endl;
  print(c2,n);
  if(isstable(c1,c2,n)){
    cout << "Stable" << endl;
  }else{
    cout << "Not stable" << endl;
  }

}



Measured memory_bytes: 3096
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    if (input[0][0] === '9' || input[0][1] === '9') {
        console.log('Yes');
    }
    else {
        console.log('No');
    }

    return 0;
}



Measured memory_bytes: 20808
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <map>
#include <queue>

using namespace std;
#define PI       3.14159265358979323846
#define MOD 1000000007

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef complex<double> P;

//container util
//------------------------------------------
#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 EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;

int dp[2][100];
int a[2][100];

int main() {
	int n;
	scanf("%d", &n);
	REP(i, 2) {
		REP(j, n) {
			scanf("%d", &a[i][j]);
		}
	}
	dp[0][0] = a[0][0];
	dp[1][0] = a[1][0]+a[0][0];
	FOR(j, 1, n)dp[0][j] = dp[0][j - 1] + a[0][j];
	FOR(j, 1, n)dp[1][j] = max(dp[0][j], dp[1][j - 1]) + a[1][j];
	cout << dp[1][n - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
            var m = line[0];
            var n = line[1];

            WriteLine(ModPow(m, n));
        }

        private static long ModPow(long m, long n)
        {
            long pow = 1;

            for(var i = 0; (1 << i) <= n; i++)
            {
                if(((n >> i) & 1) == 1)
                {
                    pow *= m % 1000000007;
                    pow %= 1000000007;
                }
                m *= m;
                m %= 1000000007;
            }

            return pow;
        }
    }
}



Measured memory_bytes: 18440
#include<bits/stdc++.h>
using namespace std;
const int N=305;
int n,k,mo;
int f[N][N];
int c[N][N];
int g[N];
int main(){
	scanf("%d%d%d",&n,&k,&mo);
	for (int i=0;i<=k+1;i++) f[0][i]=1;
	for (int i=0;i<=n;i++){
		c[i][0]=1;
		for (int j=1;j<=i;j++)
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%mo; 
	}
	for (int j=k;j>=0;j--){
		memset(g,0,sizeof(g));
		g[0]=1;
		for (int p=1;p<=n;p++)
			for (int q=1;q<=p;q++)
				g[p]=(g[p]+1ll*g[p-q]*c[p-1][q-1]%mo*f[q][j+1]%mo)%mo;
		for (int i=1;i<=n+1;i++)
			f[i][j]=(f[i][j+1]+g[i-1])%mo;
	}
	printf("%d\n",(f[n+1][0]-f[n+1][1]+mo)%mo);
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        var n = sc.nextInt();

        long ans = 0;

        for (int i = 1; i <= n; i++)
        {
            if (i.ToString().Length % 2 == 1) ans++;
        }

        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 15188
#include <iostream>

using namespace std;

int main()
{
    int first,second;
    cin>>first>>second;
    if (first>second){
        for(int i=0 ; i<first ; i++)
            cout<<second;}
        else if (first<second){
            for(int i=0 ; i<second ; i++)
            cout<<first;
        }else{
        for(int i=0 ; i<second ; i++)
            cout<<first;
        }
        

    return 0;
}

Measured memory_bytes: 256
main=do
 [n,m,x,y]<-map read.words<$>getLine
 a<-map read.words<$>getLine
 b<-map read.words<$>getLine
 putStrLn$(if null [k|k<-[x+1,x+2..y],maximum a < k, minimum b >= k] then [] else "No ")++"War"

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

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

    vector<ll> c(4);
    rep(i, 4) cin >> c[i];
    ll n;
    cin >> n;
    ll min_c = min(c[0]*8, min(c[1]*4, min(c[2]*2, c[3])));

    cout << (n/2)*min_c + (n%2!=0) * min(c[0]*4, min(c[1]*2, c[2])) << endl;



    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{

    int a,b,c;

    public void input(){
	Scanner scan = new Scanner(System.in);
	a = scan.nextInt();
        b = scan.nextInt();
	c = scan.nextInt(); 
        
    }
 


    public void output(){
	if(a < b && b < c){
         
	    System.out.println("Yes");
        }else{
	    System.out.println("No");
	}

      
    }
 public static void main(String[] args){
     Main p = new Main();
     p.input();
     p.output();
 }
}
  

Measured memory_bytes: 26040
#include<iostream>
using namespace std;
int main(){
    int a,b,s;
    char op;
    while(true){
        
        cin >> a >> op >> b;
        
        if(op == '?'){
            break;
        }else if(op == '+'){
            s = a+b;
        }else if(op == '-'){
            s =a-b;   
        }else if(op == '*'){
            s = a*b;
        }else if(op == '/'){
            s=a/b;
        }
        cout<<s<<endl;    
    }
    return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i <= (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (b); i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long

signed main()
{
    rootdada;
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
inline int add(int a,int b) {return a+=b,a>=MOD?a-MOD:a;}
inline int del(int a,int b) {return a-=b,a<0?a+MOD:a;}
inline int mul(int a,int b) {return 1LL*a*b%MOD;}
const int MAXN=110;
int C[MAXN][MAXN];
inline void initC(int N)
{
	for(int i=0;i<=N;i++) C[i][0]=1;
	for(int i=1;i<=N;i++)
		for(int j=1;j<=i;j++) C[i][j]=add(C[i-1][j-1],C[i-1][j]);
	return;
}
int dp[MAXN][MAXN][MAXN],up[MAXN],sum[MAXN];
inline void solve(int n,int m,int c)
{
	int r=m+(c<<1)-1;
	memset(dp,0,sizeof(dp)),dp[0][0][0]=1;
	for(int i=0;i<m;i++)
		for(int j=0;j<=up[i]&&(j<<1)+r<=n+m;j++)
		{
			int tmp=dp[i][j][0];
			for(int k=1;k<=up[m]&&j+(m-i)*k<=up[m];k++)
			{
				for(int l=1;i+l<=m&&j+k*l<=up[i+l];l++) dp[i+l][j+k*l][k]=add(dp[i+l][j+k*l][k],mul(tmp,C[i+l][l]));
				tmp=add(tmp,dp[i][j][k]);
			}
		}
	for(int i=0;i<=up[m]&&(i<<1)+r<=n+m;i++)
	{
		int tmp=0,tmp_=(i<<1)+r-m;
		for(int j=0;j<=i;j++) tmp=add(tmp,dp[m][i][j]);
		if(!tmp) continue;
		for(int j=0;j<=((m+1)<<1)&&tmp_+j<=n;j++) sum[tmp_+j]=add(sum[tmp_+j],mul(tmp,mul(C[m+c][c],C[(m+1)<<1][j])));
	}
	return;
}
char ch[MAXN];
int q[MAXN],pos[MAXN],vis[MAXN];
int n,k,ans;
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>k>>(ch+1);
	initC(100);
	for(int i=0;(i<<1)<=k;i++)
	{
		memset(vis,0,sizeof(vis));
		int cnt=0,L=1,R=0,s=0,r=1;
		for(int j=1;j<=k&&cnt<i;j++)
			if(ch[j]=='r') q[++R]=j;
			else if(L<=R) vis[q[L++]]=vis[j]=1,pos[++cnt]=j;
		if(cnt<i) continue;
		for(int j=1;j<=k;j++)
			if(!vis[j]&&ch[j]=='r') s++;
		pos[i+1]=k+1,up[i+1]=0;
		for(int j=0;j<=s;j++)
		{
			if(j)
			{
				while(vis[r]||ch[r]!='r') r++;
				vis[r]=1;
			}
			for(int t=i;t>0;t--)
			{
				up[t]=up[t+1];
				for(int t_=pos[t+1]-1;t_>pos[t];t_--)
					if(!vis[t_]) up[t]++;
				up[t]++;
			}
			reverse(up+1,up+i+1),solve(n,i,j);
		}
	}
	for(int i=1;i<=n;i++) ans=add(ans,mul(sum[i],C[n-1][i-1]));
	cout<<ans<<endl;
	return 0;
}

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

int main(){
	string s;
	cin >> s;
	int ans = 0;
	if(s.at(0) == '1') ans++;
	if(s.at(1) == '1') ans++;
	if(s.at(2) == '1') ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W, K = lr()
S = np.array([list(map(int, sr())) for _ in range(H)])
Scum = np.cumsum(S, axis=1)
INF = 10 ** 10
answer = INF
for pattern in range(1<<H-1):
    cnt = 0
    Tcum = Scum.copy()
    for i in range(H-1):
        if pattern>>i & 1:  # 切れ目
            cnt += 1
        else:
            Tcum[i+1] += Tcum[i]
    prev = -1
    w = 0
    Tcum = Tcum.tolist()
    while w < W:
        cut = False
        for i in range(H):
            if Tcum[i][w] - (Tcum[i][prev] if prev >= 0 else 0) > K:
                cut = True
                break
        if cut:
            if prev == w - 1:  # 1列でKをオーバー
                break
            cnt += 1
            prev = w - 1
        else:
            w += 1
    else:
        answer = min(answer, cnt)

print(answer)


Measured memory_bytes: 12684
#include <iostream>
using namespace std;
int n,x[200000],a[200000];
long long ans;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i&&a[i-1]+1<a[i]||!i&&a[i]){
            cout<<-1;
            return 0;
        }
    }
    for(int i=n-1;i;i--)if(a[i-1]>=a[i])ans+=a[i-1];
    cout<<a[n-1]+ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007

using namespace std;
int main(){
    FAST
    ll x,cnt=0,cnt2=100;; cin >> x;
    while(x>cnt2){
        cnt2+=cnt2/100;
        cnt++;
    }
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 3620
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

z=0
for i in range(0,N):
  if A[i]>=B[i]:
    z=z+B[i]
  else:
    z=z+A[i]
    if B[i]-A[i]<=A[i+1]:
      z=z+B[i]-A[i]
      A[i+1]=A[i+1]-(B[i]-A[i])
    else:
      z=z+A[i+1]
      A[i+1]=0

print(z)

Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 string s;
 string t;
 cin>>s>>t;
 int n=s.size(),m=t.size();
 vector<vector<int>> dp(n,vector<int>(m));
 vector<vector<pair<int,int>>> next(n,vector<pair<int,int>>(m));
 if(s[n-1]==t[m-1]){
  dp[n-1][m-1]=1;
 }
 else dp[n-1][m-1]=0;
 next[n-1][m-1]={-1,-1};
 for(int i=m-2;i>=0;i--){
  if(t[i]==s[n-1]) {dp[n-1][i]=1;next[n-1][i]={-1,-1};}
  else {dp[n-1][i]=dp[n-1][i+1];next[n-1][i]={n-1,i+1};}
 }
 for(int i=n-2;i>=0;i--){
  if(s[i]==t[m-1]) {dp[i][m-1]=1;next[i][m-1]={-1,-1};}
  else {dp[i][m-1]=dp[i+1][m-1];next[i][m-1]={i+1,m-1};}
 }
 for(int i=n-2;i>=0;i--){
  for(int j=m-2;j>=0;j--){
   if(s[i]==t[j]){
    dp[i][j]=dp[i+1][j+1]+1;
    next[i][j]={i+1,j+1};
   }
   else{
    if(dp[i+1][j]>dp[i][j+1]){
     dp[i][j]=dp[i+1][j];
     next[i][j]={i+1,j};
    }
    else{
     dp[i][j]=dp[i][j+1];
     next[i][j]={i,j+1};
    }
   }
  }
 }
 string ans="";
 pair<int,int> cur={0,0};
 while(cur!=make_pair(-1,-1)){
  if(s[cur.first]==t[cur.second]) ans+=s[cur.first];
  cur=next[cur.first][cur.second];
 }
 cout<<ans<<endl;
 return 0;
}

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

int main(){
	int n;
	scanf("%d", &n);
	for(int i=0;i<=n;i++){
		int rem = n-i*4;
		if(rem >= 0 && rem%7 == 0) return !printf("Yes\n");
	}
	printf("No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD (int64_t)1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector

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

string N;
int K;
cin >> N >> K;

// cnt[決めた桁数][smaller][0でない数の個数] = 個数
vector<VVI> cnt((int)N.size()+1, VVI(2, VI(N.size()+1, 0)));
cnt[0][0][0] = 1; // 0桁目で0でない数が0個ある数の個数

rep(i, 0, N.size()){
    int digit = N[i] - '0';
    rep(j, 0, 2)
        rep(k, 0, N.size()){
            if (cnt[i][j][k] == 0) continue;
            for(int d = 0; d <= (j ? 9 : digit); ++d){
                cnt[i+1][j || (d < digit)][k + (d > 0)] += cnt[i][j][k];
                // cout << "d= " << d << ", ";
                // cout << "cnt[" << i << "][" << j << "][" << k << "] = " << cnt[i][j][k] << ", ";
                // cout << "cnt[" << i+1 << "][" << (j || (d < digit)) << "][" << k + (d > 0) << "] = "
                //     << cnt[i+1][j || (d < digit)][k + (d > 0)] << "\n";
            }
        }
}

cout << cnt[N.size()][0][K] + cnt[N.size()][1][K] << "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
using namespace std;

const int MAXS = 1000100;
char str[MAXS];

int main() {

    scanf("%s", str);
    int sum = 0;
    int len = 0;

    while (str[len] != 0) {
        sum += (str[len++] - '0');
    }

    int ans = sum;
    // pay = needed + return

    const int INF = 1000000000;
    vector<vector <int>> pay(len, vector<int>(3, INF)); // 0 => paid, 1 => needed, 2 => needed+1
    pay[len-1][0] = (str[len-1] - '0');
    pay[len-1][1] = 0;

    for (int i = len-2; i >= 0; --i) {

        // for 362 => needed 2: => 0, needed 0 => 2
        // needed 6: 0+2, needed 7: 8+0, needed 0: min(2+6, 7+8) = 8
        // needed 0: min(8+3, 4+2+4, 4+8+3) = 10,
        // 402 - 362 = 40
        int c = (str[i] - '0');
        int pc = (str[i+1] - '0');
        pay[i][0] = min(pay[i+1][0]+c, min(c+1+pay[i+1][1]+(10-pc), c+1+pay[i+1][2]+(10-pc-1)));
        pay[i][1] = pay[i+1][0];
        pay[i][2] = min(pay[i+1][2] + (10-pc-1), pay[i+1][1] + (10-pc));
    }

    int c = (str[0] - '0');
    cout << min(pay[0][0],  min(1 + pay[0][2] + (10-c-1), 1 + pay[0][1] + (10-c))) << endl;

    return 0;
}

Measured memory_bytes: 55936
import java.util.Scanner;

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

		sc.nextInt();
		String s = sc.next();

		long[] m = new long[26];

		for (char c : s.toCharArray())
			m[c - 'a']++;

		long ans = 1;
		for (int i = 0; i < m.length; i++) {
			ans = ans * (m[i] + 1) % 1_000_000_007;
		}

		ans--;

		System.out.println(ans);

		sc.close();
	}

}


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

int main() {
    int n;
    cin >> n;
    vector<int> num(5);
    string s;
    for(int i = 0; i < n; i++)
    {
        cin >> s;
        if (s.at(0) == 'M') num.at(0)++;
        if (s.at(0) == 'A') num.at(1)++;
        if (s.at(0) == 'R') num.at(2)++;
        if (s.at(0) == 'C') num.at(3)++;
        if (s.at(0) == 'H') num.at(4)++;
    }

    long long res = 0;
    for(int i = 0; i < 3; i++)
    {
        for(int j = i + 1; j < 4; j++)
        {
            for(int k = j + 1; k < 5; k++)
            {
                res += (long long)num.at(i) * num.at(j) * num.at(k);
            }
            
        }
        
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        List<Character> list = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            list.add(s.charAt(i));
        }
        for (int i = 0; i < list.size() - 1; i++) {
            if (list.get(i) != list.get(i + 1)) {
                list.remove(i);
                list.remove(i);
                if (i == 0) {
                    i--;
                } else {
                    i -= 2; 
                }
            }
        }
        System.out.println(s.length() - list.size());
        sc.close();
    }
}

Measured memory_bytes: 27648