akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


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

	ll n;
	cin >> n;
	vector<ll> b(n+1,0),ans;
	FOR(i,1,n+1)cin>>b[i];

	FORR(i,1,n+1){
		ll idx,B=0;
		FOR(j,1,i+1){
			if(B<=b[j] && b[j]==j){
				idx = j;
				B = b[j];
			}
		}
		ans.push_back(B);
		if(B==0){
			cout << -1 << endl;
			return 0;
		}
		vector<ll> p;
		p.push_back(0);
		FOR(j,1,i+1){
			if(j!=idx)p.push_back(b[j]);
		}
		b = p;
	}
	FORR(i,0,n){
		cout << ans[i] << endl;
	}

}

Measured memory_bytes: 256
h,w = map(int, input().split())
m=[]

for i in range(h):
  m.append(input())

ans=[["#"]*(w) for _ in range(h)]
for i in range(h):
  for j in range(w):
    cnt = 0
    if h > i-1 >= 0:
      if m[i-1][j] == "#":
        cnt += 1
      if w > j-1 >=0 and m[i-1][j-1] == "#":
        cnt += 1
      if w > j+1 >=0 and m[i-1][j+1] == "#":
        cnt += 1
    if h > i+1 >= 0:
      if m[i+1][j] == "#":
        cnt += 1
      if w > j-1 >=0 and m[i+1][j-1] == "#":
        cnt += 1
      if w > j+1 >=0 and m[i+1][j+1] == "#":
        cnt += 1
      
    if w > j-1 >=0 and m[i][j-1] == "#":
      cnt += 1
    if w > j+1 >=0 and m[i][j+1] == "#":
      cnt += 1
    if m[i][j] != "#":
      ans[i][j] = str(cnt)

for i in range(h):
  print("".join(ans[i]))

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

int main() {
    int n;
    std::set<string> st;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string ipt;
        cin >> ipt;
        st.insert(ipt);
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 15552
p = input()
a = int(p.split()[0])
b = int(p.split()[1])
k = int(p.split()[2])
for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        a /= 2
        b += a
    else:
        if b % 2 == 1:
            b -= 1
        b /= 2
        a += b 
print(str(int(a)) + " " + str(int(b)))

Measured memory_bytes: 3064
H, W = map(int, input().split())
a = [input() for _ in range(H)]

W_bList = []
H_bList = []

#Width から黒のある列をリスト化する
for i in range(W):
    w = []
    for j in range(H):
        w.append(a[j][i])  

    #print("W",i, w)
    if len(set(w)) == 2 or set(w) == set("#"):
        W_bList.append(i)

#Hight から黒のある行をリスト化する
for i in range(H):
    h = []
    for j in range(W):
        h.append(a[i][j])  

    #print("H", i, h)
    if len(set(h)) == 2 or set(h) == set("#"):
        H_bList.append(i)

#リストから答えとなる部分だけを抜き出す
#print(W_bList, H_bList)

for hl in H_bList:

    ans = ""
    
    for wl in W_bList:
        ans += str(a[hl][wl])

    print(ans)

Measured memory_bytes: 3064
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

n = 0
for i in 0..a
    for j in 0..b
        for k in 0..c
            n += 1 if i * 500 + j * 100 + k * 50 == x
        end
    end
end
puts n

Measured memory_bytes: 1788
//In the name of God!
#include <bits/stdc++.h>

const int maxn = 1e5 + 12;
using namespace std;
multiset<int> s;
int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, t, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> t;
        s.insert(t);
    }
    while(m--){
        t = *prev(s.end());
        s.erase(prev(s.end()));
        s.insert(t / 2);
    }
    long long ans = 0;
    for(int i : s)
        ans += i;
    cout << ans;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <unordered_set>

int main()
{
  int64_t a, b, c, k;
  std::cin >> a >> b >> c >> k;
  int64_t ans = 0;
  int64_t count = 0;
  if (k <= a)
  {
    std::cout << k << std::endl;
    return 0;
  }
  ans += a;
  count += a;
  if (k <= count + b)
  {
    std::cout << ans << std::endl;
    return 0;
  }
  count += b;
  std::cout << ans - (k - count) << std::endl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
 
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{
	fastio;
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);

	int h,a;
	cin>>h>>a;

	int cnt=0;
	while(1){
		if(h<=0){
			break;
		}
		h=h-a;
		cnt++;
	}
	cout<<cnt;

	return 0;
}

Measured memory_bytes: 256
/*input
5 3
50 100 80 120 80
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{int res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(int* a, int* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int sum = 0;
	for(int i = 0; i < k; i++) {
		sum += a[i];
	}
	cout << sum << endl;
	return 0;
}

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

int cntfct(int n,int p)
{
	int ans=0,pp=p;
	while(pp<100)
	{
		ans+=n/pp;
		pp*=p;
	}
	return ans;
}

int main()
{
	int p[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
	int n;
	cin>>n;
	int cf[15];
	for(int i=0;i<15;i++)cf[i]=cntfct(n,p[i]);
	int c2=0,c4=0,c14=0,c24=0,c74=0;
	for(int i=0;i<15;i++)
	{
		if(cf[i]>=2)c2++;
		if(cf[i]>=4)c4++;
		if(cf[i]>=14)c14++;
		if(cf[i]>=24)c24++;
		if(cf[i]>=74)c74++;
	}
	cout<<c74+c24*(c2-1)+c14*(c4-1)+c4*(c4-1)*(c2-2)/2<<endl;
	return 0;
}

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

x = [False]*(10**6+1)

a.sort()
for i in range(1, n):
    if a[i] == a[i-1]:
        if x[a[i]]:
            continue
        else:
            x[a[i]] = True
            for r in range(a[i], 10 ** 6 + 1, a[i]):
                x[r] = True
ans = 0
for v in a:
    if x[v]:
        continue
    ans += 1
    for i in range(v, 10**6+1, v):
        x[i] = True

print(ans)


Measured memory_bytes: 117068
from itertools import combinations_with_replacement


def main():
    n_ints, max_int, n_queries = map(int, input().split())

    queries = [list(map(int, input().split())) for _ in range(n_queries)]

    possible_sequences = combinations_with_replacement(range(1, max_int+1), n_ints)

    max_score = 0
    for sequence in possible_sequences:
        score = 0

        for i, q in enumerate(queries):
            a, b, c, d = q
            if sequence[b-1] - sequence[a-1] == c:
                score += d

        max_score = max(max_score, score)

    print(max_score)


if __name__ == "__main__":
    main()


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

int  bubblesort(int A[], int N);

int main(){
    int N, ans;
    int A[100];
    cin >> N;
    for (int i=0; i<N; i++){
        cin >> A[i];
    }
    ans = bubblesort(A, N);
    for (int i=0; i<N; i++){
        cout << A[i];
        cout << (i != N-1 ? " " : "\n");
    }
    cout << ans << endl;
}

int bubblesort(int A[], int N){
    int tmp;
    int sum=0;
    int end=0;
    for (int i=0; i<N; i++){
        for (int j=N-1; j>i; j--){
            if (A[j] < A[j-1]){
                swap(A[j], A[j-1]);
                sum++;
            }
        }
        end++;
    }
    return sum;
}


Measured memory_bytes: 3076
#include<stdio.h>
int main(void)
{
	int w,h,n,x[10000],y[10000],a,b,m=0,i;
	scanf("%d %d %d", &w, &h, &n);
	for(i=0; i<n; i++)
	scanf("%d %d", &x[i], &y[i]);
	for(i=1; i<n; i++)
	{
		a=x[i]-x[i-1];
		b=y[i]-y[i-1];
		if(a*b>0)
		{
			if(a>0)
			{
				if(a>b)
				m+=a;
				else
				m+=b;
			}
			if(a<0)
			{
				a*=-1;
				b*=-1;
				if(a>b)
				m+=a;
				else
				m+=b;
			}
		}
		else
		{
			if(a<0)
			a*=-1;
			if(b<0)
			b*=-1;
			m+=a+b;
		}
	}
	printf("%d\n", m);
	
	return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
// make pair, tuple
// __gcd(int, int)
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }

int main(){
    int a,b;cin >> a >> b;
    cout << (a + (b - 1)) / b;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	long long n, i, j, k, ans, x;
	cin >> n;
	vector<long long> a(n), b(n), c(n), aa(n), bb(n), cc(n), sa(n), sb(n), sc(n);
	vector<long long>::iterator it;
	for (i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end());
	for (i = 0; i < n; i++) cin >> b[i]; sort(b.begin(), b.end());
	for (i = 0; i < n; i++) cin >> c[i]; sort(c.begin(), c.end());

	aa.assign(n, 1);
	for (i = 0; i < n; i++) sa[i] = i + 1;

	for (i = 0; i < n; i++) {
		it = lower_bound(a.begin(), a.end(), b[i]);
		x = it - a.begin();
		if (x == 0) bb[i] = 0;
		else bb[i] = sa[x - 1];
		if (i == 0) sb[i] = bb[i];
		else sb[i] = sb[i - 1] + bb[i];
	}

	for (i = 0; i < n; i++) {
		it = lower_bound(b.begin(), b.end(), c[i]);
		x = it - b.begin();
		if (x == 0) cc[i] = 0;
		else cc[i] = sb[x - 1];
		if (i == 0) sc[i] = cc[i];
		else sc[i] = sc[i - 1] + cc[i];
	}

	ans = sc[n - 1];
	cout << ans << "\n";


	return 0;
}



Measured memory_bytes: 7424
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n, r;
	cin >> n >> r;

	int inner_rating = 0;
	if (n >= 10) {
		inner_rating = r;
	} else {
		inner_rating = r + 100 * (10 - n);
	}

	cout << inner_rating << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;;
int main() {
	int n,k,a[55],sum=0;
	cin>>n>>k;
	for(int i=0; i<n; i++) cin>>a[i];
	for(int i=0; i<n-1; i++)
		for(int j=i+1; j<n; j++)
			if(a[i]<a[j]) swap(a[i],a[j]);
	for(int i=0; i<k; i++) sum+=a[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


float sum;
float sugar;
float con;


int main() {
  float a,b,c,d,e,f;
  scanf("%f%f%f%f%f%f", &a,&b,&c,&d,&e,&f);
  a *= 100;
  b *= 100;
  
  int anssum = -1;
  int anssugar = -1; 
  float anscon = -1;

  for(int i=0;i*a<=3000;++i){
    for(int j=0;j*b<=3000;++j){
      for(int k=0;k*c<=1500;++k){
        for(int l=0;l*d<=1500;++l){
          bool sumok=false;
          bool conok=false;
          sum = a*i+b*j+k*c+l*d;
          sugar = c*k+l*d;
          if(sum<=f) sumok = true;
          con = sugar/sum;
          // if(sum == 200) cout << con << " " << e/(100+e) << endl;
          if(con>anscon && con<=e/(100+e) && sumok){
            anssum = sum;
            anssugar = sugar;
            anscon = con;
            // if(sum == 190) cout << con << " " << e/(100+e) << endl;
          }
        }
      }
    }
  }

  cout << anssum << " " << anssugar << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 998244353
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pll a, pll b)//true for a before b
{
	if(a.F*b.S < b.F*a.S)
		return 1;
	if(a.F*b.S > b.F*a.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (1e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;
const int SQRT = BUCK+9;



void solve()
{
	long long a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k % 2LL == 0LL)
		cout << (a-b) << '\n';
	else
		cout << (b-a) << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": "; holy shit
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 256
import os
import sys
import numpy as np

sys.setrecursionlimit(2147483647)
INF = float('inf')

if os.getenv('LOCAL'):
    sys.stdin = open('_in.txt')

N = int(sys.stdin.readline())
A, B = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N - 1)]))
C = list(map(int, sys.stdin.readline().split()))


def shortest_path(start, graph):
    stack = [(start, 0)]
    dists = [INF] * (N + 1)
    dists[start] = 0
    while stack:
        v, vw = stack.pop()
        for u, w in graph[v]:
            if dists[u] == INF:
                dists[u] = vw + w
                stack.append((u, vw + w))
    return dists


#: :type: list of (list of (int, int))
graph = [[] for _ in range(N + 1)]
for a, b in zip(A, B):
    graph[a].append((b, 1))
    graph[b].append((a, 1))

# 適当に root 決める
root = 1
distances = shortest_path(root, graph)[1:]

# 葉から小さい順に埋めてく
ans = np.zeros(N, dtype=int)
C.sort(reverse=True)
for i, di in enumerate(np.argsort(distances)):
    ans[di] = C[i]

print(sum(C) - max(C))
print(*ans)


Measured memory_bytes: 24028
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


ll a[1100],b[1100];
vector<ll> dp(11000,INF);
main(){
  ll h,n,ans=0;
  cin>>h>>n;
  rep(i,0,n)cin>>a[i]>>b[i];
  dp[0]=0;
  rep(i,0,n){
    rep(j,0,h+1){
      dp[min(j+a[i],h)]=min(dp[min(j+a[i],h)],dp[j]+b[i]);
    }
  }
  cout<<dp[h];
}


Measured memory_bytes: 384
N, M, Q = map(int, input().split())
requirements = {}
for _ in range(Q):
    A, B, C, D = map(int, input().split())
    requirements[(A, B, C)] = D

def get_score(A):
    global requirements
    score = 0
    for elt in requirements:
        if A[elt[1]-1] - A[elt[0]-1] == elt[2]:
            score += requirements[elt]
    return score

A = []
ans = 0

def solve(A):
    global ans
    global requirements
    if len(A) == 0:
        for integer in range(1, M+1):
            solve(A + [integer])
    elif len(A) < N:
        for integer in range(A[-1], M+1):
            solve(A + [integer])
            
    else:
        ans = max(ans, get_score(A))
        

solve(A)
print(ans)


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

using namespace std;

int count_divisors(int n, int c) {
	int d = 0;

	for (int i = 1; i*i <= n; i++) {
		if (n % i == 0) {
			d++;
			if (i != n / i) {
				d++;
			}
		}
	}
	return d;
}

int main() {
	int n;

	cin >> n;


	int ans = 0;

	for (int c = 1; c <= n-1; c++) {
		int d = n - c;
		ans += count_divisors(d, c);
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

ll N;
vector<vector<pll>> A;   //誰がなに、second==1->正直
ll ans = 0;

void judge(ll c) {
	VLL res(N,0);
	ll sum = 0;
	for (ll n = 0; n < N; n++) {
		if (c & ((ll)1 << n)) {
			res[n] = 1;
			sum++;
		}
	}
	for (ll n = 0; n < N; n++) {
		if (res[n] == 0)continue;
		for (ll t = 0; t < A[n].size(); t++) {
			ll x = A[n][t].first;
			ll y = A[n][t].second;
			if (res[x] != y) {
				return;
			}
		}
	}
	ans = max(ans, sum);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> N;
	A.resize(N);
	for (ll n = 0; n < N; n++) {
		ll a;
		cin >> a;
		A[n].resize(a);
		for (ll t = 0; t < a; t++) {
			ll x, y;
			cin >> x >> y;
			x--;
			A[n][t] = pll(x, y);
		}
	}
	for (ll c = 0; c < ((ll)1 << N); c++) {
		judge(c);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cstring>
using namespace std;

typedef long long ll;

int a[200005];
bool vis[1000005];
void solve()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    int maxn = a[n];
    int ans = n;
    for (int i = 1; i <= n; i++)
    {
        while (i < n && a[i] == a[i + 1])
        {
            vis[a[i]] = 1;
            --ans;
            ++i;
        }
        if (vis[a[i]])
        {
            --ans;
        }
        for (int j = 1; a[i] * j <= maxn; j++)
            vis[a[i] * j] = 1;
    }
    cout << ans << endl;
}
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 5216
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

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


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

int main() {
  int n;
  string s;
  int x=0;
  int Max=0;
  cin>>n;
  cin>>s;
  
  for(int i=0;i<n;i++){
    if(s.at(i)=='I')x++;
    if(s.at(i)=='D')x--;
    Max=max(Max,x);
  }
  
  cout<<Max<<endl;
}


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

typedef long long ll;
typedef long double ld;

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    string s;

    cin >> s;

    replace(all(s), ',', ' ');

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

a,b,c,d= NextInts() #高橋体力a 青木体力c

while((a>0) and (c>0)):
	c-=b
	if c<=0:
		break
	a-=d
if a<c:
	print("No")
else:
	print("Yes")

Measured memory_bytes: 9096
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define dd double
#define ld long double
#define f(i,a,b) for(ll i = a; i < b; i++)
#define fr(i,a,b) for(ll i = b;i>=a;i--)
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vpll vector< pii >
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define Sort(v) sort(v.begin(), v.end(), sortbysec)
#define MEM(a, b) memset(a, (b), sizeof(a))

ll power(ll x, ll y, ll p)  
{  
    ll res = 1;      
    x = x % p; 
                
    while (y > 0)  
    {   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}  

 

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

ll n;
cin>>n;

ll st = 1;
ll ans = 0;
while(1)
{
    if(st > n)
    break;
   if(st*10 <= n)
   {
       if(st == 1)
       ans += 9;
       else
       ans += st*9;

       st *= 100;
   }
   else
   {
       ans += n-st+1;
       st *= 100;
   }
   
}

cout<<ans<<endl;




}


Measured memory_bytes: 3644
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0)break;

		vector<int> taro_card;
		vector<int> hnk_card;

		//taro_card.resize(n);
		//hnk_card.resize(n);

		for(int i=0;i<n;i++){
			int tmp;
			scanf("%d",&tmp);
			taro_card.push_back(tmp);
		}
		for(int i=1;i<=2*n;i++){
			bool flag = false;
			for(int j=0;j<n;j++){
				if(i == taro_card[j]){
					flag = true;
					break;
				}
			}
			if(!flag){
				hnk_card.push_back(i);
			}
		}
		
		sort(taro_card.begin(),taro_card.end());
		sort(hnk_card.begin(),hnk_card.end());
		int field = taro_card[0];
		taro_card[0] = 0;
		bool act = true;
		while(1){
			if(act){
				bool flag = false;
				for(int i=0;i<hnk_card.size();i++){
					if(field < hnk_card[i] && hnk_card[i] != 0){
						field = hnk_card[i];
						hnk_card[i] = 0;
						flag = true;
						break;
					}
				}
				if(!flag)field = 0;
				act = false;
			}

			else{
				bool flag = false;
			   	for(int i=0;i<taro_card.size();i++){
					if(field < taro_card[i] && taro_card[i] != 0){
						field = taro_card[i];
						taro_card[i] = 0;
						flag = true;
						break;
					}
				}
				if(!flag) field = 0;
				act = true;
			}
			
			int t=0,h=0;
			for(int i=0;i<n;i++){
				if(taro_card[i] != 0)t++;
				if(hnk_card[i] != 0)h++;
			}
			if(t == 0 || h == 0){
				printf("%d\n%d\n",h,t);
				break;
			}
		}
	}
	return 0;
}

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

typedef long long ll;

int main() {
    ll Q, H, S, D, N, X;
    cin >> Q >> H >> S >> D >> N;
    X = min({Q * 4, H * 2, S});
    if (X * 2 < D) cout << X * N << endl;
    else cout << N / 2 * D + (N % 2) * X << endl;
}

Measured memory_bytes: 256
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
A = int(readline())
B = int(readline())
AB = []
AB.append(A)
AB.append(B)
S = [1,2,3]
for i in range(3):
    if S[i] not in AB:
        print(S[i])
        sys.exit()

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1001001001;

const int mod = 1000000007;

ll gcd(ll x, ll y) {
    if (y == 0) {
        return x;
    }
    return gcd(y, x % y);
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    // cで割り切れる物の数
    ll ub_p_c = b / c;
    ll ua_p_c = a / c;
    ll bet_ab_p_c = ub_p_c - ua_p_c;

    // dで割り切れる物の数
    ll ub_p_d = b / d;
    ll ua_p_d = a / d;
    ll bet_ab_p_d = ub_p_d - ua_p_d;

    ll g = lcm(c, d);

    // cdで割り切れる物の数
    ll ub_p_cd = b / g;
    ll ua_p_cd = a / g;
    ll bet_ab_p_cd = ub_p_cd - ua_p_cd;

    ll ans = (b - a) - bet_ab_p_c - bet_ab_p_d + bet_ab_p_cd;

    if (a % c != 0 && a % d != 0) {
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 *
 * @author masa
 */
public class Main implements Comparable {

    private String rest_name;
    private int rest_score;
    private int rest_no;

    public Main(String rest_name, int rest_score, int rest_no) {
        this.rest_name = rest_name;
        this.rest_score = rest_score;
        this.rest_no = rest_no;
    }

    public int compareTo(Object arg_obj) {
        Main obj = (Main) arg_obj;
        int str_comp = this.rest_name.compareTo(obj.rest_name);
        if (str_comp == 0) {
            if (this.rest_score < obj.rest_score) {
                return 1;
            } else if (this.rest_score > obj.rest_score) {
                return -1;
            } else {
                return 0;
            }
        }
        return str_comp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int rest_num = sc.nextInt();

        Main obj;
        String line;
        ArrayList<Main> rest_list = new ArrayList<>();

        for (int i = 0; i < rest_num; i++) {
            obj = new Main(sc.next(), sc.nextInt(), i + 1);
            rest_list.add(obj);
        }
        Collections.sort(rest_list);
        for (Main item : rest_list) {
            System.out.println(item.rest_no);
        }
    }
}


Measured memory_bytes: 19924
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

int main() {
	string s;
	int cnt = 0;
	bool check = true;

	cin >> s;
	if (s.size() % 2 == 0) {
		rep(i, s.size()) {
			if (check) {
				if (s[i] == 'h') {
					check = false;
					cnt++;
				}
			}
			else {
				if (s[i] == 'i') {
					check = true;
					cnt++;
				}
			}
		}
		if (cnt == s.size()) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

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

signed main(){
  int N,M,K;
  cin>>N>>M>>K;
  vector<int> A(N),B(M);
  rep(i,N)cin>>A[i];
  rep(i,M)cin>>B[i];
  int total=0;
  rep(i,M)total+=B[i];
  int j=M,ans=0;
  rep(i,N+1){
    while(j>0&&total>K){
      j-=1;
      total-=B[j];
    }
    if(total>K)break;
    ans=max(ans,i+j);
    if(i==N)break;
    total+=A[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6408
import math 
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
  
  
x = int(input())

while True:
  if is_prime(x):
    print(x)
    break
  x += 1

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array)
#define inin freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

int main(){
   // inin
    IOS
    ll n,m,x;
    cin>>n>>m>>x;
    ll c[n];
    
    ll a[n][m];
    fo(i,n){
      cin>>c[i];
      fo(j,m){
        cin>>a[i][j];
      }
    }
    //dbg(a[1][0]);
    ll ans=1000000000000000000;

    fo(i,(1<<n)){
      bool can=true;
      std::vector<ll> count(m,0);
      ll cost=0;
      fo(j,n){
        //dbg2(i,j);
        if((i&(1<<j))) {
          cost+=c[j];
          fo(k,m){
            count[k]+=a[j][k];
          }

        }
      }
      //dbg2(cost,count[2]);
      fo(p,m){
        if(count[p]>=x) ;
        else can=false;
      }
      if(can) ans=min(ans,cost);

    }
     if(ans<1000000000000000000) cout<<ans<<endl;
     else cout<<-1<<endl;
    

}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int[] a = new int[n];
        int[] count = new int[200001];
        long[] comb = new long[200001];
        long[] diff = new long[200001];
        long cn = 0;
        int ai, c;
        long ci;
        for (int i = 0; i < 200001; i++) {
            count[i] = 0;
            comb[i] = 0;
        }
        for (int i = 0; i < n; i++) {
            ai = Integer.parseInt(scanner.next());
            a[i] = ai;
            count[ai] += 1; 
        }
        // System.out.prlongln(Arrays.toString(count));
        for (int i: a) {
            c = count[i];
            ci = cmb(c);
            comb[i] = ci;
            diff[i] = ci - cmb(c-1);
        }
        for (long i: comb) {
            cn += i;
        }
        for (int i: a) {
            System.out.println(cn-diff[i]);
        }
    }
    public static long cmb(long x) {
        if (x < 2) {
            return 0;
        }
        return (x*(x-1))/2;
    }
}

Measured memory_bytes: 77396
/*********************************************************************
* AUTHOR : ANSHU KUMAR                                               *
* ABOUT :  IT DOESN'T MATTER HOW SLOW I GO, AS LONG AS I NEVER STOP  *
* INSTITUTION : IEM KOLKATA                                          *
**********************************************************************/

//try to think at least 30min(with full concentration).

#include <bits/stdc++.h>

using namespace std;

#define int             long long
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define MOD             1000000007
#define INF             1e18
#define PI              3.1415926535897932384626433832795
#define sp(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define endl            '\n'
#define da(arr,type,n)  type *arr=new type[n];


/********** Euclidean Algorithm for GCD **********/
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



/********** Fast Power Exponentiation ***********/
int power(int a, int b) {
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res % MOD * a % MOD) % MOD;
		a = (a % MOD * a % MOD) % MOD;
		b >>= 1;
	}
	return res;
}



/********** FAST I/O ************/
void fastIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}



/********** PROGRAM START ***********/

int32_t main()
{
	fastIO();
	int ans = 0;
	for (int i = 1; i <= 5; i++)
	{
		int x;
		cin >> x;
		if (x == 0)
		{
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	string s; cin>>s;
	int cnt=0;
	rep(i,s.length()){
		if(s[i]=='C' && cnt==0) cnt++;
		if(s[i]=='F' && cnt==1) cnt++;
	}
	puts(cnt==2?"Yes":"No");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    int  a = 0, un = 0;
    bool ok = 1;
    rep(i,n){
        string s;
        cin >> s;
        // cout << endl << a << " " << un << endl;
        if(a < un) ok = 0;
        if(s == "A"){
            a++;
        }else{
            un++;
        }
    }
    if(a != un) ok = 0;
    if(ok)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 10; 

int cost[N][N];

void solve() {
    int H, W;
    cin >> H >> W;
    int n=10;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> cost[j][i]; // tran
        }
    }
    auto dijkstra = [&](int s){
        vector<int> d(n, INF);
        vector<bool> trk(n, false);
        d[s] = 0;
        while (true) {
            int mindis = INF;
            int u = -1;
            for (int i = 0; i < n; i++) {
                if (!trk[i] && d[i] < mindis) {
                    u = i; mindis = d[i];
                }
            }
            if (!~u) break;
            trk[u] = true;
            for (int v = 0; v < n; v++) {
                if (!trk[v] && d[v] > d[u] + cost[u][v]) {
                    d[v] = d[u] + cost[u][v];
                }
            }
        }
        return d;
    };
    auto d = dijkstra(1);
    vector<int> cnt(10);
    for (int _ = 0; _ < H; _++) {
        for (int _ = 0; _ < W; _++) {
            int x; cin >> x;
            if (x!=-1)cnt[x]++;
        }
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
        res += cnt[i] * d[i];
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

int main() {
  int n;
  vector<int> v;
  while (1) {
    cin >> n;
    if (n == -1) break;
    v.clear();
    while (n) {
      v.push_back(n%4);
      n /= 4;
    }
    if (!v.size()) {
      cout << "0" << endl;
    } else {
      for (vector<int>::reverse_iterator it=v.rbegin(); it!=v.rend(); ++it) {
        cout << *it;
      }
      cout << endl;
    }
  }
  return 0;
}

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

int main(){
    string str ,com, p;
    int q,a,b;
    
    cin >> str >> q;
    for(int t=0; t<q; t++){
        cin >> com >> a >> b;
        if(com== "print"){
            cout << str.substr(a, b-a+1) << endl;
        } else if(com=="reverse"){
            string tmp = str.substr(a, b-a+1);
            int n = tmp.size();
            for(int i=0; i<n; i++)str[i+a]=tmp[n-i-1];
        }else if(com=="replace"){
            cin>>p;
            str=str.replace(a, b-a+1, p);
        }
    }
    
    return 0;
}


Measured memory_bytes: 3208
#include <string>
#include <vector>
#include <iostream>

using namespace std;

int main()
{
    int n, a; string decimal;
    
    cin >> n;
    
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        
        decimal += to_string(a);
    }

    int ptr = 0;
    
    while(true)
    {
        if(decimal.find(to_string(ptr)) == string::npos)
        {
            break;
        }
        
        ptr++;
    }
    
    cout << ptr << endl;
    
    return 0;
}

Measured memory_bytes: 3292
#include <iostream>
#include<string>

using namespace std;

int main()
{
 char str[100];
  cin>>str;

for(int i=0;str[i]!='\0';i++)
   {
      if(str[i]>='A'&&str[i]<='Z')
          {str[i]='x';}
      else if (isupper(str[i]))
            str[i] = tolower(str[i]);
      else str[i]='xx';
   }
     cout<<str;


	return 0;
}

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

int main(){
    int n,tcnt,hcnt;
    string t,h;
    tcnt = 0;
    hcnt = 0;
    cin >> n;
    
    for(int i=0;i<n;i++){
        cin >> t >> h;
        if(t==h){tcnt++; hcnt++;}
        else if(t>h) tcnt += 3;
        else if(t<h) hcnt += 3;
    }
    cout << tcnt <<" "<< hcnt << endl;
    return 0;
}


Measured memory_bytes: 3184
import bisect
n=int(input())
ll=list(map(int, input().split()))
ll=sorted(ll)

  
ans=0
for i in range(len(ll)-1):
  for j  in range(i+1,len(ll)):
    a,b=ll[i],ll[j]
    ans+=bisect.bisect_left(ll,a+b)-(j+1)
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>
int main(void)
{
	int h, r, sum;

	scanf("%d %d", &h, &r);
	sum = h + r;
	if (sum > 0) {
		printf("1\n");
	}
	else if (sum == 0) {
		printf("0\n");
	}
	else if (sum < 0) {
		printf("-1\n");
	}
	return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
    using namespace std;
    #define int long long
    constexpr int INF = 1000000000 + 8;
    signed main()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << setprecision(10);
     
        int h, n;
        cin >> h >> n;
        vector<int> a(n), b(n);
        for (int i = 0; i < n; i++)
        {
            cin >> a[i] >> b[i];
        }
     
        // dp[i][j]: 魔法iまで見たとき ダメージj以上を与えるのに必要な最小の魔力
        vector<vector<int>> dp(n + 1, vector<int>(h + 1, INF));
        dp[0][0] = 0;
     
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j <= h; j++)
            {
                // 魔法使った 使わなかった
                if (j - a[i] >= 0)
                    dp[i + 1][j] = min(dp[i + 1][j - a[i]] + b[i], dp[i][j]);
                else
                {
                    dp[i + 1][j] = min(dp[i + 1][0] + b[i], dp[i][j]);
                }
            }
        }
     
        cout << dp[n][h] << endl;
    }

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int left = a+b;
  int right = c+d;

  if (left > right) {
    cout << "Left" << endl;
  } else if (right > left) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }

}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
	int N =	Integer.parseInt(sc.next());
	int a =	0;
	int max	= 0;
	int min	= 1001;
        for(int i = 0; i<N; i++) {
            a = Integer.parseInt(sc.next());
            max	= Math.max(max,a);
            min	= Math.min(min,a);
        }
	System.out.println(max-min);
    }
}

Measured memory_bytes: 22996
from collections import defaultdict
N = int(input())
A = input()
B = input()
C = input()
lis = [defaultdict(int) for i in range(N)]

for i in range(N):
    lis[i][A[i]] += 1
    lis[i][B[i]] += 1
    lis[i][C[i]] += 1

comp = []
for i in range(N):
    comp.append(max(lis[i], key=lis[i].get))
comp = "".join(comp)
count = 0
for i in range(N):
    for word in lis[i]:
        if word == comp[i]:
            continue
        else:
            count += lis[i][word]
print(count)


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

int main(){
  string s;
  cin >> s;
  int n=0;
  int k=s.size();
  for(int i=0;i<k;i++){
    if(s[i]=='x') n++;
  }
  cout << (n>7?"NO":"YES") << endl;
}
    


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

memo = [-1 for _ in range(N+1)]

def dp(i):
    if i == 1:
        return 0
    elif i == 2:
        memo[i] = abs(h[i-2]-h[i-1])
        return memo[i]
    elif memo[i] >= 0:
        return memo[i]
    else:
        memo[i] = min(
            dp(i-1) + abs(h[i-2]-h[i-1]),
            dp(i-2) + abs(h[i-3]-h[i-1])
        )
        return memo[i]

for i in range(1, N):
    dp(i)

print(dp(N))

Measured memory_bytes: 13924
import sys
input = sys.stdin.readline
import string
import sys
import math

ALPHABET = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
result = []

def alphabet_decimal(v):
    quotient = math.floor(v / len(ALPHABET))
    surplus = v % len(ALPHABET)
    quotient -= 1 if surplus == 0 else 0
    surplus = len(ALPHABET) if surplus == 0 else surplus
    result.append(surplus)
    if len(ALPHABET) < quotient:
        alphabet_decimal(quotient)
    elif len(ALPHABET) < v:
        result.append(quotient)
    return "".join([ALPHABET[i - 1] for i in reversed(result)])
def main():
    N = int(input())
    ans = alphabet_decimal(N).lower()
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 68772
import sys

N, M = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))
A = []
B = []
for i in range(M):
    temp_A, temp_B = map(int, sys.stdin.readline().split())
    A.append(temp_A)
    B.append(temp_B)

dame = []
for i in range(M):
    if H[B[i]-1] > H[A[i]-1]:
        dame.append(A[i])
    if H[A[i]-1] > H[B[i]-1]:
        dame.append(B[i])
    if H[A[i]-1] == H[B[i]-1]:
        dame.append(A[i])
        dame.append(B[i])
print(N - len(set(dame)))





Measured memory_bytes: 24460
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n, m, k;
	cin >> n >> m >> k;
	vector<int>a(n);
	vector<int>b(m);
	vector<int>A(n + 1);//Aの机からi冊読んだときのページ数の合計
	vector<int>B(m + 1);
	A[0] = B[0] = 0;
	rep(i, n) {
		cin >> a[i];
		A[i + 1] = A[i] + a[i];
	}
	rep(i, m) {
		cin >> b[i];
		B[i + 1] = B[i] + b[i];
	}
	int ans = 0;
	int j = m;
	rep(i, n+1) {
		if (A[i] > k)break;
		while ((A[i] + B[j]) > k) {
			j--;
		}
		ans = max(ans, i + j);
	}
	print(ans);
}

Measured memory_bytes: 9568
#include <bits/stdc++.h>
#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

#define FOR(i,n) for(ll i=0;i<n;i++)

struct edge{ll to,cost;};

vector<ll>uni_path(100000),uni_train(100000);

ll modpow(ll a,ll b){
   if(b==0)return 1;
   else if(b%2==0){
      ll half_pow = b/2;
      ll half = modpow(a,half_pow);
      return half*half%MOD;
   }
   else{
      return a*modpow(a,b-1)%MOD;
   }
}

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0);
   int N;
   cin >> N;
   vector<int>a(N);
   FOR(i,N)cin >> a[i];

   bool up = false;
   bool ans = true;
   sort(a.begin(),a.end());
   for(int i=0;i<N;i++){
      if(i==0&&N%2==1 && a[0]!=0){
         ans=false;
      }
      else if(i==0&&N%2==1 && a[0]==0)continue;
      else if(N%2==1&&i%2==0)ans=false;
      else if(N%2==0&&i%2!=0)ans=false;
      else if(a[i] != a[i+1])ans=false;
      else if(a[i] == a[i+1])i++;
   }
   ll num = 0;
   if(N%2==0){
      num = modpow(2,N/2);
   }
   else{
      num = modpow(2,(N-1)/2);
   }

   if(ans) cout << num << endl;
   else cout << 0 << endl;
   return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int n,m,u,v;
vector<int> vct[100005];
deque<int> dq;
bool vis[100005];
int unfin(bool fr){
	int np = fr?dq.front():dq.back();
	for(auto it:vct[np]){
		if(!vis[it]){
			vis[it] = true;
			return it;
		}
	}
	return 0;
}
int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;++i){
		scanf("%d%d",&u,&v);
		vct[u].push_back(v), vct[v].push_back(u);
	}
	dq.push_front(1);
	dq.push_front(vct[1][0]);
	vis[1] = vis[vct[1][0]] = true;
	while(true){
		int a,b;
		a = unfin(true);
		b = unfin(false);
		if(a+b){
			if(a) dq.push_front(a);
			if(b) dq.push_back(b);
		} else {
			break;
		}
	}
	printf("%d\n",(int)dq.size());
	for(int i=(int)dq.size()-1;i>=0;--i){
		printf("%d",dq[i]);
		if(i) printf(" ");
	}
	puts("");
}

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

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

	for (int x = 0; x <= N; ++x) {
		for (int y = 0; y <= N; ++y) {
			int z = N - (x + y);
			if (10000 * x + 5000 * y + 1000 * z == Y && x + y + z <= N && 0 <= z) {
				cout << x << ' ' << y << ' ' << z << endl;
				return 0;
			}
		}
	}
	cout << -1 << ' ' << -1 << ' ' << -1 << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n=0,x=0,m=0,i=0,j=0,y=0,count=0,z=0;
cin >> x ;
for(i=-1000;i<=1000;i++){
	for(j=-1000;j<=1000;j++){
      	z = (long long int)(pow(i,5)-pow(j,5));
    	if(z==x){break;}
      	//if(i==2&&j==-1){cout << z<<" ";}
      //cout << z <<" ";
      //if(j%100==0)cout << j <<" ";
    }
  if(j!=1001){break;}
  //cout << pow(i,5)<<" ";
}
  cout << i <<" "<< j <<endl;
}

Measured memory_bytes: 4048