akhauriyash/Code-Regression huggingface dataset:
from queue import Queue

class Process:
	def __init__(self, name, time):
		self.name = name
		self.time = int(time)

	def set_time(self, time):
		self.time = time

n, q = map(int, input().split())
queue = Queue()
for i in range(n):
	name, time = map(str, input().split())
	queue.put(Process(name, time))

time_elapsed = 0
while queue.empty() != True:
	process = queue.get()
	time = process.time
	if time > q:
		process.set_time(time - q)
		time_elapsed += q
		queue.put(process)
	else:
		time_elapsed += min(time, q)
		print(process.name + ' ' + str(time_elapsed))


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

# A*B=Nとなるような1以上9以下の整数(A, B)が存在するかどうか全探索を行う
ans = 'No'
for i in range(1, 10):
  for j in range(1, 10):
    if i*j == N:
      ans = 'Yes'
      break
      
print(ans)

Measured memory_bytes: 9164
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;
using ll = long long;

const ll MOD = 998244353;
const ll INF = 1e18;
const double pi = acos(-1);
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()


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




int n;


void input(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    cin >> n;
    
     
}


 

void solve(){
    
    
    
    cout << n*n << endl;
}





signed main() {
    
    input();
    solve();
    return 0;
}



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

#define rep(i, s, t) for(int i = (s), i##E = (t); i <= i##E; ++i)

char s[10000];

int main()
{
	scanf("%s", s);
	rep(i, 0, strlen(s) - 9) printf("%c", s[i]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <iomanip>

using namespace std;

mt19937 Rand(16092002);
mt19937_64 BigRand(16092002);

typedef long long ll;

ll solve(int h, int w)
{
    ll ans = 1e18;
    for (int a = 0; a < h; a++)
    {
        ll cur = a * (ll) w;
        int x = h - a;
        int y = w;
        ll s1 = (x / 2) * (ll) w;
        ll s2 = (x / 2 + x % 2) * (ll) w;
        ans = min(ans, max(max(s1, s2), cur) - min(min(s1, s2), cur));
        s1 = x * (ll) (w / 2);
        s2 = x * (ll) (w / 2 + w % 2);
        ans = min(ans, max(max(s1, s2), cur) - min(min(s1, s2), cur));
    }
    return ans;
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int h, w;
    scanf("%d%d", &h, &w);
    printf("%lld\n", min(solve(h, w), solve(w, h)));
}

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

int main() {
 
  int N;
  cin >> N;
  
  vector<int> A(3*N);
  for(int i=0; i<3*N; i++){
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  
  int64_t ans=0;
  for(int i=0; i<2*N; i+=2){
    ans += A.at(i+1);
  }
 
  cout << ans << endl;
  
}


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

typedef long long ll;

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

    int n; cin >> n;
    map<string,int> mp1;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
        mp1[s[i]]++;
    }
    int m; cin >> m;
    vector<string> t(m);
    map<string,int> mp2;
    for(int i=0;i<m;i++){
        cin >> t[i];
        mp2[t[i]]++;
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        ans = max(ans,mp1[s[i]]-mp2[s[i]]);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int k,a,b;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;
  
  return 0;
}

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

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    if (0<=x-r && 0<=y-r && W>=x+r && H>= y+r){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3088
# coding: utf-8
def get_ln_inputs():
    return input().split()


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def get_composable_numbers(a, b, lim):
    result = set()
    result.add(0)
    if a < lim:
        result.add(a)
    if b < lim:
        result.add(b)

    for c in range(max(result), lim + 1):
        if (c - a) in result or (c - b) in result:
            result.add(c)

    return list(result)

def get_concentration(water, suger):
    return suger / (water + suger)

def max_below(array, limit):
    max_res = array[0]
    for elem in array:
        if elem > max_res and elem <= limit:
            max_res = elem
        elif elem >= limit:
            break

    return max_res

def main():
    a, b, C, D, E, F = get_ln_int_inputs()
    A = 100 * a
    B = 100 * b
    water_composables = sorted(list(map(lambda x: x * 100, get_composable_numbers(a, b, F // 100))))
    suger_composables = sorted(get_composable_numbers(C, D, (E * F) // 100))

    res_tuple = (A, 0)
    max_concentration = 0
    for i in range(1, len(water_composables)):
        water = water_composables[i]
        suger_max = max_below(suger_composables, min((water * E) // 100, F - water))
        mass = water + suger_max

        concentration = get_concentration(water, suger_max)
        if concentration > max_concentration:
            max_concentration = concentration
            res_tuple = (water + suger_max, suger_max)
    
    print(str(res_tuple[0]) + " " + str(res_tuple[1]))
    return

main()

Measured memory_bytes: 3188
//Disjoint Set

//Accepted 
//uva 793,273,10685
//
#include<iostream>
#include<vector>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

class Edge{
public:
  int from,to, cost;
  bool operator<(const Edge & a)const{
    if ( cost != a.cost)return cost<a.cost;
    else if ( from != a.from)return from < a.from;
    return to < a.to;
  }
};

int main(){
  int n;
  long long A, B;
  cin >> n >> A>>B;
  vector<Edge> edge;
  vector<int> in(n);
  for(int i = 0;i < n;i++){
    cin >> in[i];
  }
  for(int i = 0;i < n-1;i++){
    edge.emplace_back((Edge){i, i+1, in[i+1] - in[i]});
  }
  sort(begin(edge), end(edge));

  long long ans = (n-1) * B;
  long long tmp = (n-1) * B;
  for(int i = 0;i < edge.size();i++){
    tmp = tmp - B + edge[i].cost * A;
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


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

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

    set<int> S;

    for( int i = 0 ; i < n ; ++i ){
        int a;
        cin >> a;
        S.insert(a);
    }

    for( int i = 0 ; i <= 51 ; ++i ){
        if( S.count( x - i ) == 0 ) {
            cout << x - i ;
            return 0;
        } else if( S.count( x + i ) == 0 ){
            cout << x + i ;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 998244353
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000

int main(void) {
	ll n, k; cin >> n >> k;
	vector<P> s(k);
	
	rep(i, k) {
		cin >> s[i].first >> s[i].second;
	}

	vector<ll> dp(n + 2);
	dp[1] = 1;

	for (int i = 2; i <= n; i++) {
		dp[i] +=dp[i - 1];
		rep(j, k) {
			if (i - s[j].first >= 1) {
				if (i - s[j].second < 1) {
					dp[i] =(dp[i] +dp[i-s[j].first])% MOD;
				}
				else {
					dp[i] = (dp[i]+dp[i-s[j].first] - dp[i-s[j].second - 1])% MOD;
					if (dp[i] < 0) {
						dp[i] += MOD;
					}
				}
			}
		}
	}

	ll ans = dp[n] - dp[n - 1];
	if (ans < 0) {
		ans += MOD;
	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 4812
n=int(input())
a=list(map(int,input().split()))

dp=[0 for i in range(n)]
dp[0]=0
dp[1]=abs(a[0]-a[1])
for i in range(n-2):
    dp[i+2]=dp[i]+abs(a[i]-a[i+2])
    dp[i+1]=abs(min(dp[i+1],dp[i]+abs(a[i+1]-a[i])))
if(n>2):
    dp[-1]=min(dp[-2]+abs(a[-1]-a[-2]),dp[-3]+abs(a[-3]-a[-1]))
   
print(dp[-1])


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

int main()
{
    int n;
    cin >> n;
    string s = to_string(n);
    bool ans = false;
    for(int i = 0; i < 3; i++){
        if(s[i] == '7') ans = true;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl; 
}

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

using namespace std;

typedef int Weight;
const Weight INF = 1e9;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int f, int t, Weight c) :
        src(f), dst(t), weight(c) {}
};
bool operator<(const Edge &a, const Edge &b) {
    return a.weight != b.weight ? a.weight > b.weight :
        a.src != b.src ? a.src < b.src : a.dst < b.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef pair<Weight, int> Result;

Result visit(int p, int v, const Graph &g) {
    Result r(0, v);
    for (auto e = g[v].begin(); e != g[v].end(); ++e)
        if (e->dst != p) {
            Result t = visit(v, e->dst, g);
            t.first += e->weight;
            if (r.first < t.first) r = t;
        }
    return r;
}

Weight diameter(const Graph &g) {
    Result r = visit(-1, 0, g);
    Result t = visit(-1, r.second, g);
    return t.first; // (r.second, t.second) is farthest pair
}

int main()
{
    int n;

    while (cin >> n, n) {
        Graph g(n);
        vector<int> p(n - 1), d(n - 1);

        for (int i = 0; i < n - 1; ++i) {
            cin >> p[i];
            --p[i];
        }
        for (int i = 0; i < n - 1; ++i)
            cin >> d[i];

        for (int i = 1; i < n; ++i) {
            g[i].push_back(Edge(i, p[i - 1], d[i - 1]));
            g[p[i - 1]].push_back(Edge(p[i - 1], i, d[i - 1]));
        }


        vector<bool> cut(n, false);
        Weight res = 0;
        map<int, int> hash;
        int vertex = 0;

        // 葉の重みの加算
        for (int i = 0; i < n; ++i) {
            if (g[i].size() == 1) {
                cut[i] = true;
                res += g[i][0].weight;
                hash[i] = -1;
            }
            else
                hash[i] = vertex++;
        }

        Graph tree(vertex);
        for (int i = 0; i < n; ++i) {
            if (cut[i])
                continue;
            for (auto e = g[i].begin(); e != g[i].end(); ++e) {
                if (cut[e->dst])
                    continue;
                tree[hash[e->src]].push_back(Edge(hash[e->src],
                                                  hash[e->dst], e->weight));

                if (e->src < e->dst)
                    res += 3 * e->weight;
            }
        }

        res -= diameter(tree);
        cout << res << '\n';
    }

    return 0;
}

Measured memory_bytes: 1396
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
//#define MOD 1000000007
#define MOD 998244353
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
ll fact[400000];
ll nck(ll a,ll b){
	return fact[a]*ppow(fact[b],MOD-2)%MOD*ppow(fact[a-b],MOD-2)%MOD;
}
signed main(){
	fact[0]=1;
	for(int i=1;i<400000;i++)fact[i]=fact[i-1]*i%MOD;
	ll n,a,b,k;cin>>n>>a>>b>>k;
	if(a>b)swap(a,b);
	ll ans=0;
	for(ll i=0;i<=n;i++){//aを使う個数
		ll c=a*i;
		if(k<c||(k-c)%b!=0)continue;
		ll d=(k-c)/b;//bを使う個数
		if(d>n)continue;
		(ans+=nck(n,i)*nck(n,d)%MOD)%=MOD;
	}
	cout<<ans<<endl;
}
/*
300000 1 1 300000
*/

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

int n=-10;
long long int ans = -1000000000000000000;
vector<long long int> a;
vector<long long int> pl;
vector<long long int> mi;

priority_queue<long long int,  std::vector<long long int>, std::greater<long long int> > l;
priority_queue<long long int> r;


int main() {
	cin >> n;
	a.resize(3*n);
	for (int i = 0; i < 3*n; ++i) cin >> a.at(i);

	pl.resize(n+1);
	mi.resize(n+1);

	for (int i = 0; i < n; ++i) {

		l.push(a.at(i));
		pl.at(0) += a.at(i);
	}

	for (int i = 1; i <= n; ++i)
	{
		l.push(a.at(n+i-1));
		pl.at(i) = pl.at(i-1) + a.at(n+i-1) - l.top();
		l.pop();
	}

	for (int i = 2*n; i < 3*n; ++i) {
		r.push(a.at(i));
		mi.at(n) += a.at(i);
	}

	for (int i = n-1; i >= 0; --i)
	{
		r.push(a.at(n+i));
		mi.at(i) = mi.at(i+1) + a.at(n+i) - r.top();
		r.pop();
	}

	for (int i = 0; i <= n; ++i)
	{
		ans = max(ans, pl.at(i) - mi.at(i));
	}

	cout << ans << endl;
}

Measured memory_bytes: 6516
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	int ans=0;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(i*500+j*100+k*50==x){
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;

int main(){
    int w,n,x,y;
    scanf("%d",&w);
    vector<int> l(w+1);
    for(int i=0;i<w+1;i++){
        l[i]=i;
    }
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d,%d",&x,&y);
        swap(l[x],l[y]);
    }
    for(int i=1;i<w+1;i++){
        printf("%d\n",l[i]);
    }
    return 0;
}

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n, ans = 0;
    string s;
    cin >> n >> s;
    vector<int> tb(1000);
    for(int i = 0; i < 1000; i++) {
        int flg = 0;
        int d1 = i / 100, d2 = (i / 10) % 10, d3 = i % 10;
        int j;
        for(j = 0; j < n - 2; j++) {
            if((s[j] - '0') == d1) {
                flg++;
                break;
            }
        }
        j++;
        if(flg) {
            flg = 0;
            for(; j < n - 1; j++) {
                if((s[j] - '0') == d2) {
                    flg++;
                    break;
                }
            }
        }
        j++;
        if(flg) {
            flg = 0;
            for(; j < n; j++) {
                if((s[j] - '0') == d3) {
                    flg++;
                    break;
                }
            }
        }
        if(flg) {
            tb[i] = 1;
            //cout << d1 << d2 << d3 << endl;
        }
    }

    for(int i = 0; i < 1000; i++) {
        if(tb[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int K = in.nextInt();
			int X = in.nextInt();
			int Y = in.nextInt();
			int total = 0;
			if(N < K) {
				for(int i = 0; i < N; i++) {
					total += X;
				}
			}else{
				for(int i = 0; i < K; i++) {
					total += X;
				}
			}
			for(int i = 0; i < N - K; i++) {
				total += Y;
			}
			out.println(total);
		}
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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

	}
}


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

int main(){
    int A,B; cin>>A>>B;
    string S; cin>>S;

    bool flag=true;
    for(int i=0;i<S.length();i++){
        if(i==A){
            if(S[i]!='-') flag=false;
            continue;
        }
        if(!(S[i]>='0'&&S[i]<='9')) flag=false;
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
const int MAX = 510000;
//const ll mod = 1000000007;
const ll mod = 998244353;
int main() {
  int n,k;
  cin >> n >> k;
  vector<pair<int,int>> q;
  
  int st,en;
  ll r[n+1] = {};
  ll imos[n+1] = {};
  imos[0] = 1;
  for(int i = 0;i<k;i++){
    cin >> st >> en;
    q.push_back(make_pair(st,en));
  }  
  for(int i = 1;i<n;i++){
    //cout << i << " " << imos[i] << " " << imos[i-1]<< endl;
    imos[i] = imos[i-1]+ imos[i];
    for(int j = 0;j<q.size();j++){
      st = q[j].first;
      en = q[j].second;
      //cout << i << " " << imos[i] << endl;
      if(i+st <= n){
        imos[i+st] += imos[i];
        imos[i+st] %=mod;
      }
      if(i+en+1<=n){
        imos[i+en+1] -= imos[i];
        imos[i+en+1] %= mod;
      }
    }
  }
 
  cout << imos[n];
}


Measured memory_bytes: 6724
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n;
	cin >> n;
	VI a(n);
	REP(i, n) { cin >> a[i]; }
	sort(ALL(a));
	vector<bool> is_used(1000001, false);
	int result = 0;
	int duplicate = 0;
	REP(i, n) {
		if(is_used[a[i]]) {
			continue;
		}
		result++;
		if(i < n - 1 && a[i] == a[i + 1]) {
			duplicate++;
		}
		for(int j = 1; j * a[i] < 1000001; j++) {
			is_used[j * a[i]] = true;
		}
	}
	cout << result - duplicate << endl;
	return 0;
}


Measured memory_bytes: 4300
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
const long double PI=(acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n;
  cin>>n;
  vector<string> str(n);
  rep(i,n){
    cin>>str[i];
  }
  bool boo=true;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(str[i]==str[j]){
        boo=false;
      }
    }
  }
  for(int i=0;i<(n-1);i++){
    string ketsu=str[i];
    string atama=str[i+1];
    char k=ketsu[ketsu.size()-1];
    char a=atama[0];
    if(k!=a){
      boo=false;
    }
  }
  if(boo){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  } 
}

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

//defines
#define openin freopen("input.txt","r",stdin)
#define openout freopen("output.txt","w",stdout)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define int long long
#define mod 1000000007
#define repr(i,x,y) for (__typeof(x) i=x;i>=y;i--)
#define rep(i,x,y) for (__typeof(x) i=x;i<=y;i++)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

/* Print pair */
template <typename T,typename S>
ostream & operator << (ostream &os , const pair<T,S> &v) {
    os << "(" ;
    os << v.first << "," << v.second << ")" ;
    return os ;
}
/* Print vector */
template <typename T>
ostream & operator << (ostream &os , const vector<T> &v) {
    os << "[" ;
    int sz = v.size() ;
    for(int i = 0 ; i < sz ; ++i) {
        os << v[i] ;
        if(i!=sz-1)os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print set */
template <typename T>
ostream & operator << (ostream &os , const set<T> &v) {
    T last = *v.rbegin() ;
    os << "[" ;
    for(auto it : v) {
        os << it  ;
        if(it != last) os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print Map */
template <typename T,typename S>
ostream & operator << (ostream &os , const map<T,S> &v) {
    for(auto it : v) {
        os << it.first << " : " << it.second << "\n" ;
    }
    return os ;
}
int power(int a , int b)
{
    int res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % mod ;
        }
        b/=2 ;
        a = (a*a) % mod ;
    }
    return res ;
}

//debug
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int arr[200005] ; 
int32_t main()
{
    fast;
    int n , k ; 
    cin >> n >> k ; 
    rep(i,1,n) cin >> arr[i] ; 
    vector<int> temp ; 
    sort(arr + 1 , arr + 1 + n) ; 
    rep(i,1,n) {
        int j = i ; 
        while(j <= n && arr[j] == arr[i]) ++j ;
        int cnt = j - i ;
        temp.pb(cnt) ;  
        i = j - 1 ; 
    }
    sort(all(temp)) ; 
    if(temp.size() <= k) cout << 0 << endl ; 
    else {
        int r = temp.size() - k ;
        int idx = 0 , sum = 0;  
        while(r--) {
            sum += temp[idx++] ; 
        }
        cout << sum << endl ; 
    }
    return 0;
}


Measured memory_bytes: 3956
#include <stdio.h>

int main(void) 
{
	int H, W;
	scanf("%d%d", &H, &W);

	char buf[105];
	
	for (int i = 0; i < H; i++) {
		scanf("%s", buf);
		printf("%s\n%s\n", buf, buf);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;

const long long MOD = 1000000007;

void solve(long long N){
    map<LL, LL> cnts;
    for(LL i=2; i<=N; i++){
        LL tmp=i, j=2;
        while(j<=sqrt(i)){
            while(tmp%j==0){
                tmp/=j;
                cnts[j]++;
            }
            j++;
        }
        if(tmp>1)cnts[tmp]++;
    }
    LL ans=1;
    for(auto kv:cnts){
        ans = (ans*(kv.second+1))%MOD;
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int SURP = 1000000007;

int main(){
	long long int M,N;
	cin >> M >> N;
	if (M > N) {
		swap(M,N);
	}
	long long int ret = 0;
	if(M == 1){
		if (N == 1) ret = 1;
		else ret = N - 2;
	}else{
		ret = (N-2)*(M-2);
	}

	cout << ret << endl;
	return 0;
}


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

using namespace std;

struct Union_Find
{
	std::vector<int> par;
	std::vector<int> rank;
	std::vector<int> sz;
	//初期化
	void init(int n)
	{
		par.resize(n);
		rank.resize(n);
		sz.resize(n);
		for (int i = 0; i < n; ++i)
		{
			par[i] = i;
			rank[i] = 0;
			sz[i] = 1;
		}
	}

	//木の根を探す
	int find(int s)
	{
		if (par[s] == s)
		{
			return s;
		}
		return par[s] = find(par[s]);
	}

	//結合
	void unite(int x, int y)
	{
		int a = find(x), b = find(y);
		if (a == b)
		{
			return;
		}
		int size = sz[a] + sz[b];
		sz[a] = sz[b] = size;
		if (rank[a] < rank[b])
		{
			par[a] = b;
		}
		else
		{
			par[a] = b;
			if (rank[a] == rank[b])
			{
				++rank[b];
			}
		}
	}

	//二つの数の根が同じかどうか
	bool same(int x, int y)
	{
		return find(x) == find(y);
	}

	//サイズを返す
	int size(int n)
	{
		return sz[find(n)];
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	Union_Find uf;
	uf.init(n);
	vector<int> ans(n, -1);
	vector<set<int>> friends(n);
	vector<set<int>> guard(n);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		friends[min(a - 1, b - 1)].insert(max(a - 1, b - 1));
		uf.unite(a - 1, b - 1);
		ans[a - 1]--;
		ans[b - 1]--;
	}
	for (int i = 0; i < k; i++) {
		int c, d;
		cin >> c >> d;
		guard[min(c - 1, d - 1)].insert(max(c - 1, d - 1));
		if (uf.same(c - 1, d - 1)) {
			ans[c - 1]--;
			ans[d - 1]--;
		}
	}
	cout << ans[0] + uf.size(0);
	for (int i = 1; i < n; i++) {
		cout << " " << ans[i] + uf.size(i);
	}
	cout << "\n";
}

Measured memory_bytes: 21504
N = int(input())
S = input()

ans = 0

for i in range(N):
    X = S[:i]
    Y = S[i:]
    res = 0
    
    X = set(X)
    Y = set(Y)
    
    for j in X:
        if j in Y:
            res += 1
            
    ans = max(ans, res)
    
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
int main(){
  int a[5];
  for(int i=0;i<4;i++)scanf("%d",&a[i]);
  for(int i=0;i<4;i++){
    if(a[i]==1)for(int j=0;j<4;j++){
      if(a[j]==9)for(int k=0;k<4;k++){
        if(a[k]==7)for(int l=0;l<4;l++){
          if(a[l]==4){
            puts("YES");
            return 0;
          }
        }
      }
    }
  }
  puts("NO");
  return 0;
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.HashMap;

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

    static class BTwoColorsCardGame {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int res = 0;
            HashMap<String, Integer> blue = new HashMap<>();
            for (int i = 0; i < n; i++) {
                blue.merge(in.next(), 1, Integer::sum);
            }
            int m = in.nextInt();
            HashMap<String, Integer> red = new HashMap<>();
            for (int i = 0; i < m; i++) {
                red.merge(in.next(), 1, Integer::sum);
            }

            for (String s : blue.keySet()) {
                int cmp = blue.get(s) - red.getOrDefault(s, 0);
                res = Math.max(res, cmp);
            }
            out.println(res);
        }

    }
}



Measured memory_bytes: 29012
def f(x):
    if x==2:
        return 1
    if x<2 or x%2==0:
        return 0
    i=3
    while i<=x**(1/2):
        if x%i==0:
            return 0
        i+=2
    return 1

while True:
    n=int(input())
    if n==0:
        break
    else:
        s=0
        for i in range(2,n//2+1):
            m=n-i
            if f(m)==1 and f(i)==1:
                s+=1
        print(s)


Measured memory_bytes: 5636
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val Ss, Ts = List.fill(sc.nextInt())(sc.next()).groupBy(identity).view.mapValues(_.length)
  println(Ss.map{ case (s, count) => (count - Ts.getOrElse(s, 0)).max(0) }.max)
}


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

int main(){

    map<string,int> k;
    int n;
    cin >> n;

    rep(i,n){
        string a;
        cin >> a;
        k[a]++;
    }
    
    cout << k.size() << endl;

    return 0;
}


Measured memory_bytes: 19148
/*************************
author : coldbeer
2019-05-25 05:37:52 PM IST
*************************/
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"

typedef long long ll;
vector<ll> arr;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n,m; cin >> n >> m;
	arr.assign(n + 2,0);
	ll temp = m;
	while(temp--){
		int l,r; cin >> l >> r;
		arr[l] += 1;arr[r + 1] += -1;
	}
	for(int i = 2;i <= n;i++) arr[i] += arr[i - 1];

	ll ans = 0;
	for(int i = 1;i <= n;i++)
		if(arr[i] == m) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,m,v,p,a[100005];
bool check(ll x){
	ll y=a[x]+m,z=(v-p+1)*m;
	if(y<a[n-p+1])return false;
	for(int i=1;i<=n-p+1;i++)
		z-=min(m,max(0ll,y-a[i]));
	return z<=0;
}
int main(){
	n=read(),m=read(),v=read(),p=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	sort(a+1,a+n+1);
	ll l=1,r=n-p+1;
	while(l<r){
		ll mid=l+r>>1;
		if(check(mid))r=mid;
		else l=mid+1;
	}
	printf("%lld",n-l+1);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X;
//string S, T;

signed main(){
  cin >> N;
  vi A(N);
  rep(i,N) cin >> A[i];
  sort(all(A));
  cout << A[A.size()-1]-A[0] << endl;
  return 0;
}


Measured memory_bytes: 3560
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<int> vi;
set <int> st;
int n,k;
vector<int> videos(105);
double now=0;
queue<int> num;
string a,b;
int main(int argc,char const* argv[])
{
  cin >> a >> b;
  string c=a+b;
  int tmp=stoi(c);
  for(int i=1;i*i<=tmp;i++)
    {
      if(i*i==tmp)
	{
	  cout << "Yes" << endl;
	  return 0;
	}
    } 
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>

using namespace std;

const int MAXN = 2 * 100001;
long long a[MAXN];

int main() {
    int n, k;
    cin >> n >> k;
    for(int i = 1;i <= n;i ++){
        a[i % k]++;
    }
    long long sum = 0;
    for(int i = 0;i < MAXN;i ++){
        if(2 * i % k == 0)sum += a[i] * a[i] * a[i];
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
lst = list(map(int,input().split()))

diff = [(lst[i] - lst[i+1]) >= 0 for i in range(0,(len(lst)-1))]
diff

c = 0
clst = []
for i in range(0, len(diff)):
    if diff[i]:
        c += 1
    else:
        clst.append(c)
        c = 0
clst.append(c)
print(max(clst))

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vpll BA(N);
  REP(i,N){
    IN(BA[i].second, BA[i].first);
  }
  sort(ALL(BA));

  ll T = 0;
  REP(i,N){
    T += BA[i].second;
    if(T>BA[i].first){
      OUT("No");
      return 0;
    }
  }
  OUT("Yes");

  return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N;
vector<string> s;

int main(){
    cin >> N;
    s.resize(N);
    rep(i,N){
        cin >> s[i];
    }

    // define A = 0
    int cnt = 0;
    for(int B=0;B<N;B++){
        int A = 0;
        bool ok = true;
        rep(i,N){
            rep(j,N){
                int ni = N + j + B - A;
                int nj = N + i + A - B;
                ni %= N;
                nj %= N;

                if(s[i][j] != s[ni][nj]){
                    ok = false;
                    break;
                }
            }
            if(!ok) break;
        }
        if(ok) cnt++;
    }

    cout << cnt * N << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;

// 入力
int N;
long long W, weight[110], value[110];

// DP テーブル
long long dp[110][100010] = {};

int main() {
  cin >> N >> W;
  for (int i = 0; i < N; ++i)  cin >> weight[i] >> value[i];

  // ループ
  for (int i = 0; i < N; ++i) {
    for (int sum_w = 0; sum_w <= W; ++sum_w) {
      if (sum_w - weight[i] >= 0) { //i番目を追加する場合を考える
        chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
      }
      chmax(dp[i+1][sum_w], dp[i][sum_w]); //i番目を追加しない場合を考える
    }
  }
    // 答え
    cout << dp[N][W] << endl;
}

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

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const unsigned int mod = 1e9 + 7;

using namespace std;

int32_t main() {
	fastio;

	int n, m;
	cin >> n >> m;
	int tot = 0;
	while(m--) {
		int x;
		cin >> x;
		tot += x;
	}
	if(tot <= n)
		cout << n - tot;
	else
		cout << -1;

	return 0;
}


Measured memory_bytes: 3652
S=input()
A = ["AKIHABARA","KIHABARA","AKIHBARA","KIHBARA","AKIHABRA","KIHABRA","AKIHBRA","KIHBRA","AKIHABAR","KIHABAR","AKIHBAR","KIHBAR","AKIHABR","KIHABR","AKIHBR","KIHBR"]     
print("YES" if A.count(S)>=1 else "NO")

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

int main(void){
    string S;cin>>S;
    while (true) {
        string tmp = S.substr(0, S.size() - 2);
        if (tmp.substr(0, tmp.size() / 2) == tmp.substr(tmp.size() / 2, tmp.size()/ 2)) {
                cout << tmp.size() << endl;
                return 0;
        }
        S = tmp;
    }
    return 0;
}

Measured memory_bytes: 256
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    forn(i, n) cin >> a[i];
    map<ll, ll> c;
    c[0]++;
    c[a[0] % m]++;
    for (int i = 1; i < n; i++)
    {
        a[i] = a[i - 1] + a[i];
        c[a[i] % m]++;
    }
    ll ans = 0;
    for (auto it : c) ans = ans + (it.second - 1) * it.second / 2;
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int a,b;
	string s;
	bool flag=true;
	cin>>a>>b>>s;
	for(int i=0;i<s.length();i++)
	{
		if(i<a&&!isdigit(s[i]))flag=false;
		else if(i==a&&s[i]!='-')flag=false;
		else if(i>a&&!isdigit(s[i]))flag=false;
	}
	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#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, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


int cnt[15][15];

pii calcDigit(int n) {

	pii num;
	num.first = n % 10;
	while (n / 10) {
		n /= 10;
	}
	num.second = n;
	return num;
}

int main() {

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


	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int head = 0;
		int tail = 0;
		tie(tail, head) = calcDigit(i);
		cnt[head][tail]++;
	}

	int ans = 0;
	for (int i = 0; i <= 9; i++)
	{
		for (int j = 0; j <= 9; j++)
		{
			ans += cnt[i][j] * cnt[j][i];
		}
	}

	cout << ans << endl;


	return 0;
}



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

int main(){
  int N;
  cin >> N;
  
  vector<int> A(N + 1);
  for (int i = 0; i < N + 1; i++) {
    cin >> A.at(i);
  }
  
  vector<int> B(N);
  for (int i = 0; i < N; i++) { 
    cin >> B.at(i);
  }
  
  long long count = 0;
  long long tmp;
  
  for (int i = 0; i < N; i++) {
    if (B.at(i) - A.at(i) <= 0) {
      count += B.at(i);
    }
    else {
      tmp = B.at(i) - A.at(i);
      if (tmp - A.at(i + 1) <= 0) {
        count += B.at(i);
        A.at(i + 1) -= tmp;
      }
      else {
        count += A.at(i) + A.at(i + 1);
        A.at(i + 1) = 0;
      }
    }
  }
  
  cout << count << endl;
      
  
  return 0;
}

Measured memory_bytes: 1024