akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
typedef long long ll;

int main(void)
{

    int h, m, k;
    int h2, m2;
    cin >> h >> m >> h2 >> m2 >> k;
    cout << (60 * (h2 - h) + (m2 - m) - k) << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#include <ctype.h>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, char> pic;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {

	while (max_n >= x)
	{
		bit[x]++;
		x += x & -x;
	}
}
void sub(int x) {
	while (max_n >= x)
	{
		bit[x]--;
		x += x & -x;
	}
}


void solv() {
	
	ll n;
	cin >> n;
	int a[10010];
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	int q;
	cin >> q;
	int res = 0;
	for (size_t i = 0; i < q; i++)
	{
		int p;
		cin >> p;
		int *v = lower_bound(a, a + n, p);
		if (*v == p) res++;
	}
	cout << res << endl;
}
int main() {
	//	COMinit();
	solv();
	return 0;
}



Measured memory_bytes: 3172
#include <stdio.h>
#include <stdlib.h>
 
int main(void) {
 int n;
 scanf("%d",&n);
 long  int sum1=0,a_count[100001] = {0},t;
 for(int i=0;i<n;i++){
  scanf("%ld",&t);
  //aの和と数値ごとの出現回数を格納する。
  a_count[t]++;//数値ごとの出現回数
  sum1+=t;//aの和
 }
 int q;
 scanf("%d",&q);
 int b[q],c[q];
 for(int i=0;i<q;i++){
  scanf("%d%d",&b[i],&c[i]);
  sum1+=(c[i]-b[i])*a_count[b[i]];
  a_count[c[i]] += a_count[b[i]];
  a_count[b[i]] = 0;
  printf("%ld\n",sum1);
 }
 
}

Measured memory_bytes: 3296
#include <bits/stdc++.h>
#define ll long long
#define li long int
#define ld long double
#define pl pair<long long, long long>
#define pi pair<int, int>
#define ppl pair<pl, ll>
#define ppi pair<int, pi>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LLFOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define MOD 1000000007
#define M2 998244353
//std::cout <<setprecision(30) << av << endl;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--){
        ll x;
        cin >> x;
        ll a = 100;
        int d=0;
        while(a<x){
            a = a+a/100;
            d++;
        }
        cout << d << endl;

    }
}


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

int main() {
	string s;
	cin >> s;
	int k = 1000;
	for(int i = 0;i < s.size() - 2;i++)
	{
		int d = abs(753 - stoi(s.substr(i,3)));
		if(k > d)
		{
			k = d;
		}
	}
	cout << k << 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++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,T;
  cin >>n>>T;
  int ans = 1001;
  rep(i,n){
    int c,t;
    cin >>c>>t;
    if(t > T) continue;
    ans = min(ans,c);
  }
  if(ans == 1001) cout << "TLE" << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int a[3], sum=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	sort(a, a+3);
	for(int i=0;i<2;i++){
		sum += abs(a[i] - a[i+1]);
	}
	cout<<sum;
	return 0;
}

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

int main() {
    int a, k, 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: 3624
#include<iostream>
#include<cmath>
using namespace std;


bool PrimeNumbers2( int x )
{
    for( int i = 2; i <= sqrt(x); i++)
    {
        if( x % i == 0 )
            return false;
    }
    return true;
}


int main() 
{
    int num;
    int count = 0;                      //素数の数をカウントする

    while( cin >> num )
    {
        if( PrimeNumbers2(num) )
            count++;
    }

    cout << count << endl;

    return 0;
}


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

int main(){
    
    // 1. 入力情報.
    LL N, ans = 0;
    scanf("%lld", &N);
    
    // 2. 奇数ならば, 0.
    if(N & 1){
        puts("0");
        return 0;
    }
    
    // 3. 偶数の場合は, N / 2 を 5 で 割ったものを, 逐次加算.
    N >>= 1;
    while(N) ans += N / 5, N /= 5;
    
    // 4. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] A = new long[N];
        Map<Long, Long> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
            map.merge(A[i], 1L, Long::sum);
        }
        long sum = Arrays.stream(A).sum();
        int Q = scan.nextInt();
        for (int i = 0; i < Q; i++) {
            long B = scan.nextLong();
            long C = scan.nextLong();
            if (map.containsKey(B)) {
                long count = map.get(B);
                sum += (C - B) * count;
                map.remove(B);
                if (!map.containsKey(C)) {
                    map.put(C, 0L);
                }
                long t = map.get(C);
                map.put(C, t + count);
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 67848
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<pair<int,int>> x(n),a(n);
    for(int i=0;i<n;i++){
        cin>>x[i].first>>x[i].second;
    }
    int cnt=0;
    for(int i=0;i<n;i++){
        a[i].second=x[i].first-x[i].second;
        a[i].first=x[i].first+x[i].second;
    }
    sort(All(a));
    int M = -inf;
    for(int i=0;i<n;i++){
        if(M<=a[i].second){
            cnt++;
            M=a[i].first;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define Maxn 100000
int f[Maxn + 5];
string s;
int n,q,lft,rgt;
int main(){
	cin >> n >> q;
	cin >> s;
	for(int i = 2;i <= n;i++){
		f[i] = f[i - 1];
		if (s[i - 2] == 'A' && s[i - 1] == 'C')
		   f[i]++;		
	}
	for(int i = 1;i <= q;i++){
		cin >> lft >> rgt;
		cout << f[rgt] - f[lft] << endl;
	}	
	return 0;
} 

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;

int N;
vector<vector<vector<double>>> dp(301, vector<vector<double>>(301, vector<double>(301)));
//dp.at(x).at(y).at(z):1x個2y個3z個の期待値

double rec(int x, int y, int z) {
    if (x < 0 || y < 0 || z < 0) return 0;
    if (x == 1 && y == 0 && z == 0) return N;
    double res = dp.at(x).at(y).at(z);
    if (res != 0) return res;
    res = x * rec(x - 1, y, z);
    res += y * rec(x + 1, y - 1, z);
    res += z * rec(x, y + 1, z - 1);
    res += N;
    res /= x + y + z;
    return dp.at(x).at(y).at(z) = res;
}

int main() {
    cin >> N;
    int a;
    vector<int> x(3);
    for (int i = 0; i < N; i++) {
        cin >> a;
        x.at(a - 1)++;
    }
    printf("%.16f\n", rec(x.at(0), x.at(1), x.at(2)));
}

Measured memory_bytes: 216960
#include<iostream>
#include<vector>
using namespace std;
int chmax(int a, int b){
    return a>b?a:b;
}

int GCD(int a, int b){
    return b?GCD(b, a%b):a;
}

int main(){
    int N; cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];

    vector<int>left(N+1, 0), right(N+1,0);
    for(int i=0; i<N; i++) left[i+1]=GCD(left[i], a[i]);
    for(int i=N-1; i>=0; i--) right[i]=GCD(right[i+1],a[i]);

    int res=0;
    for(int i=0; i<N; i++){
        int l=left[i];
        int r=right[i+1];
        res=chmax(res, GCD(l, r));
    }
    cout << res << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<VI> VVI;
template<class T> T gcd( T a, T b ) {
	return !b ? a : gcd( b, a % b );
}
template<class T> T lcm( T a, T b ) {
	return a / gcd( a, b ) * b;
}
template<class T> string print_v( vector<T> v ) {
	OSS oss;
	for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end();
			++it_i ) {
		oss << *it_i << ", ";
	}
	return oss.str();
}

int solve( VI X, int n, int t, int e ) {
    for ( int i = 0; i < n; ++ i ) {
        for ( int j = t - e; j <= t + e; ++ j ) {
            if ( j % X[i] == 0 ) return i + 1;
        }
    }
    return -1;
}

int main() {
    int n, t, e;
    while ( cin >> n >> t >> e ) {
        VI X( n );
        for ( int i = 0; i < n; ++ i ) {
            cin >> X[i];
        }
        cout << solve( X, n, t, e ) << endl;
    }
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
 int n; cin >> n;
 bool works = 1;
 for (int i = 0; i < n; i++) {
  	int x; cin >> x;
    if (x % 2 == 0 && x % 3 != 0 && x % 5 != 0) works = 0;
 }
 cout << (works ? "APPROVED" : "DENIED") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define int             long long
#define pb              push_back
#define mp              make_pair
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define nl			    "\n";
#define w(x)            int x; cin>>x; while(x--)
#define fr(i,n)         for (int i = 0; i < n; ++i)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)



int main()
{
	FIO;

	int n;cin>>n;
	int h[n];
	fr(i,n) cin>>h[i];
	int dp[n]={0};
	dp[1]=abs(h[1]-h[0]);
	for (int i =2; i < n; ++i)
	{
		int op1=dp[i-1]+abs(h[i-1]-h[i]);
		int op2=dp[i-2] + abs(h[i-2]-h[i]);
		dp[i]=min(op1 , op2);
	}
	cout<<dp[n-1];
}


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

//define of gcd and lcm//
ll gcd(ll a,ll b){
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

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

int main(){
    ll a,b;
    cin>>a>>b;
    cout<<lcm(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 256
//dfs版 
#include<iostream>
#include<cctype>
#include<queue>
#include<cstdio>
#include<cmath>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<map>
#include<utility>
#include<iomanip>
#include<set>
#include<stack>
#define lowbit(i) ((i)&(-i))
using namespace std;
typedef long long ll;typedef pair<int,int> pii;
typedef pair<ll,ll> pll;typedef vector<string> vss;
typedef vector<int> vii;typedef vector<pii> vpi;
typedef vector<ll> vll;typedef vector<pll> vpl;typedef long double ld;
typedef unsigned long long ul;typedef queue<int> qii;typedef queue<pii> qpi;
int n,x,y,dp[100005],res,t;
vii v[100005];
int mx=0,deg[1000005];
qii q;
int main()
{
// 	freopen("","r",stdin);
// 	freopen("","w",stdout);
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
		deg[x]++;
		deg[y]++;
	}
	for(int i=0;i<n;i++){
		if(v[i].size()>mx)
			mx=v[i].size();
	}
	if(mx<=2){
		puts("1");
		return 0;
	}
	for(int i=0;i<n;i++){
		if(deg[i]==1) q.push(i);
	}
	while(!q.empty()){
		int p=q.front(),to=-1;q.pop();
		for(int i=0;i<v[p].size();i++){
			to=v[p][i];
			if(deg[to]!=1) break;
		}
		if(deg[to]==2){
			deg[to]=1;
			q.push(to);
		}
	}
	for(int i=0;i<n;i++){
		if(deg[i]==1) continue;
		t=0;
		for(int j=0;j<v[i].size();j++){
			int to=v[i][j];
			if(deg[to]==1) t++;
		}
		res+=max(0,t-1);
	}
	cout<<res<<'\n';
	return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

const int MAXN = 100000 + 1000;

int n;
map<pair<int, int>, int> edg_cnt;
multiset<int> edg[MAXN];
queue<pair<int, int> > que;

void no()
{
	cout << "NO" << endl;
	exit(0);
}

void yes()
{
	cout << "YES" << endl;
	exit(0);
}

void solve()
{
	int m = 0;
	while(!que.empty())
	{
		int x = que.front().first, y = que.front().second;
		que.pop();
		if(edg_cnt[make_pair(x, y)] < 2) continue;
		// cerr << x << ' ' << y << endl;
		m++;
		if(edg[x].size() < edg[y].size())
			swap(x, y);
		for(multiset<int>::iterator it = edg[y].begin(); it != edg[y].end(); it++)
		{
			int z = *it;
			edg_cnt[make_pair(y, z)]--;
			edg[z].erase(edg[z].find(y)), edg_cnt[make_pair(z, y)]--;
			if(z == x) continue;
			edg[x].insert(z), edg_cnt[make_pair(x, z)]++;
			edg[z].insert(x), edg_cnt[make_pair(z, x)]++;
			if(edg_cnt[make_pair(x, z)] == 2)
				que.push(make_pair(x, z));
		}
		edg[y].clear();
	}
	if(m == n - 1)
		yes();
	else
		no();
}	

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 1; i <= 2 * (n - 1); i++)
	{
		int x, y;
		cin >> x >> y;
		edg[x].insert(y), edg_cnt[make_pair(x, y)]++;
		edg[y].insert(x), edg_cnt[make_pair(y, x)]++;
		if(edg_cnt[make_pair(x, y)] == 2)
			que.push(make_pair(x, y));
	}

	solve();

	return 0;
}


Measured memory_bytes: 62080
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}


int main(){
    string a;
    cin>>a;
    for(ll bit=0;bit<(1<<3);bit++){
        ll sum = a[0]-'0';
        string s;
        s += (char)(a[0]);
        for(ll i=0;i<3;i++){
            if(bit & (1<<i)){
                sum+=a[i+1]-'0';
                s+='+';
                s+=(char)(a[i+1]);
            }else{
                sum-=a[i+1]-'0';
                s+='-';
                s+=(char)(a[i+1]);
            }
        }
        if(sum == 7){
            cout<<s<<"=7"<<endl;
            return 0;
        }
    }
    return 0;
}
 
    
    



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

# Insert all the data into dictionary
stores = []
for _ in range(N):
  a, b = list(map(int, input().split()))
  stores.append([a,b])

stores = sorted(stores, key=lambda x:x[0])

m = 0
money = 0

for store in stores:
  money += min(store[1], M - m) * store[0]
  m += min(store[1], M - m)
  if m == M:
    break
print(money)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void tokenize(std::string const &str, const char delim,
			std::vector<std::string> &out)
{
	// construct a stream from the string
	std::stringstream ss(str);

	std::string s;
	while (std::getline(ss, s, delim)) {
		out.push_back(s);
	}
}

void Main() {
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if (U == S){A -= 1;} else {B -= 1;}
    cout << A << " " << B << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)      type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
const double pi = 3.1415926535897932384626433;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void JH(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    string s;cin>>s;
    int n=s.length();
    for(int i=0;i<n;i++){
        if(s[i]=='?'){
            s[i]='D';
        }
    }
    for(int i=0;i<n;i++){
        if(s[i]=='P' or s[i]=='D')
            cnt++;
    }
    cout<<s<<endl;
}

int32_t main()
{
    FILE_IO();FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();}cerr<<"Execution time: "<<(double)(clock()-beg)/1000<<"s ";
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
using ulli = unsigned long long int;

int main(){
	string s;
	ulli K;
	cin >> s >> K;
	for(ulli i = 0; i < s.size(); i++){
		ulli need = 26 - (s[i] - 'a');
		if(s[i] != 'a' && K >= need){
			K -= need;
			s[i] = 'a';
		}
	}
	s[s.size() - 1] = 'a' + (s[s.size() - 1] - 'a' + K) % 26;
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 640
N,M = map(int,input().split())
L = []
ans = []
for i in range(M) :
    L.append(list(map(int,input().split())))
    ans.append([])

C = []
for i in range(N+1) :
    C.append([])

for i, (p,y) in enumerate(L) :
    C[p].append([y,i])

for p in range(N+1) :
    for i,(y,_) in enumerate(sorted(C[p])) :
        ans[_] = str(p).zfill(6) + str(i+1).zfill(6)
for i in range(M) :
    print(ans[i])


Measured memory_bytes: 55108
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
 
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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

signed main()
{
  int x,y,z,k;
  cin>>x>>y>>z>>k;
  vector<ll> a(x), b(y), c(z);
  rep(i,x) cin>>a[i];
  rep(i,y) cin>>b[i];
  rep(i,z) cin>>c[i];
  sort(a.rbegin(),a.rend());
  sort(b.rbegin(),b.rend());
  sort(c.rbegin(),c.rend());
  vector<ll> ab(x*y);
  rep(i,x){
    rep(j,y) {
      ab.push_back(a[i]+b[j]);
    }
  }
  sort(ab.rbegin(),ab.rend());
  vector<ll> abc(k*z);
  rep(i,k){
    rep(j,z){
      abc.push_back(ab[i]+c[j]);
    }
  }
  sort(abc.rbegin(),abc.rend());
  rep(i,k) cout<<abc[i]<<endl;
}


Measured memory_bytes: 64632
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
c=0
for i in range(n-1):
  if A[i]+1==A[i+1]:
    c+=C[A[i]-1]
print(sum(B)+c)

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

int main() {
  string S;
  int ANS;
  cin >> S;
    if (S == "SUN") {
    	ANS = 7;
  	}
   	if (S == "MON") {
    	ANS = 6;
  	}
  	if (S == "TUE") {
    	ANS = 5;
  	}
	if (S == "WED") {
    	ANS = 4;
  	}
	if (S == "THU") {
    	ANS = 3;
  	} 
	if (S == "FRI") {
    	ANS = 2;
  	}
 	if (S == "SAT") {
    	ANS = 1;
  	} 
  cout << ANS << endl;
}
  

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int x = Integer.parseInt(str[2]);
    int[] c = new int[n];
    int[][] a = new int[n][m];
    
    for(int i = 0; i<n; i++) {
      str = in.readLine().split(" ");
      c[i] = Integer.parseInt(str[0]);
      for(int j = 0; j<m; j++) {
        a[i][j] = Integer.parseInt(str[j+1]);
      }
    }
    
    long ans = Long.MAX_VALUE;
    
    loop1: for(int i = 0; i<Math.pow(2,n); i++) {
      boolean ok = true;
      long res = 0;
      loop2: for(int k = 0; k<m; k++) {
        long sum = 0;
        for(int j = 0; j<n; j++) {
          if((1&i >> j) == 1) {
            res += c[j];
            sum += a[j][k];
          }
          //System.out.println(sum);
        }
        if(sum < x) {
          ok = false;
          break loop2;
        }
        //System.out.println();
      }
      //System.out.println(res/m);
      if(ok) {
        ans = Math.min(ans,res/m); 
      }
    }
    
    if(ans == Long.MAX_VALUE) {
      System.out.println(-1);
    } else {
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 32984
import sys

N = int(sys.stdin.readline())
ps = [int(x) for x in sys.stdin.readline().split(" ")]


wrong_count = 0
for i in range(0, N):
    if ps[i] == i + 1:
        continue
    wrong_count += 1

if wrong_count == 0 or wrong_count == 2:
    print("YES")
else:
    print("NO")


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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char> > S(H+2, vector<char>(W+2));
  int score = 0;
  for (int i=0; i<W+2; i++) S[0][i] = '#';
  for (int i=1; i<H+1; i++){
    string t;
    S[i][0] = '#';
    cin >> t;
    for (int j=0; j<W; j++){
      if (t[j] == '.') score++;
      S[i][j+1] = t[j];
    }
    S[i][W+1] += '#';
  }
  for (int i=0; i<W+2; i++) S[H+1][i] = '#';
  queue<vector<int> > start;
  start.push({1,1});
  int count = 1;
  S[1][1] = '#';
  while (true){
    count++;
    queue<vector<int> > nextst;
    while(!start.empty()){
      vector<int> check;
      check = start.front();
      start.pop();
      for (int i: {-1,0,1}){
        for (int j:{-1,0,1}){
          if ((abs(i)>0) && (abs(j)>0)) continue;
          if ((check[0]+i == H) && (check[1]+j == W)){
            cout << score - count << endl;
            return 0;
          } else if (S[check[0]+i][check[1]+j] == '.'){
            nextst.push({check[0]+i,check[1]+j});
            S[check[0]+i][check[1]+j] = '#';
          }
        }
      }
    }
    start = nextst;
    if (start.empty()) break;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn calc_max_v(a: f64, b: f64, angle: f64) -> f64 {
    let b_prime = b - (a * angle.tan());
    if b_prime >= 0.0f64 {
        (a.powf(2.0) * b) - (a.powf(3.0) * angle.tan() / 2.0)
    } else {
        b.powf(2.0) / angle.tan() * a / 2.0
    }
}

fn main(){
    let (a, b, x): (f64, f64, f64) = (read(), read(), read());

    let mut angle: f64 = 0.0;
    let mut range: f64 = 45.0;

    loop {
        let max_v = calc_max_v(a, b, angle.to_radians());
        let delta = (max_v - x).abs();
        
        if delta < 1e-6 {
            break;
        }

        if max_v > x {
            angle += range;
        } else {
            angle -= range;
        }

        range /= 2.0;
    }

    println!("{}", angle);
}


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

int n,m,l,r,d,dist[100010];
vector<pair<int,int> > v[100010];
bool vis[100010];

inline bool dfs(int loc,int dis)
{
    if(vis[loc]) return dist[loc]!=dis;
	vis[loc]=true;dist[loc]=dis;
	for(int ii=0;ii<v[loc].size();ii++){
	    int t1=v[loc][ii].first,t2=v[loc][ii].second;
	    if(dfs(t1,dis+t2)) return true;
    }
	return false;
}

int main()
{
    cin>>n>>m;
	for(int i=1;i<=m;i++){
	    scanf("%d%d%d",&l,&r,&d);
	    v[l].push_back(make_pair(r,d));
	    v[r].push_back(make_pair(l,-d));
	}
	for(int i=1;i<=n;i++) if(!vis[i]&&dfs(i,0)){
	    cout<<"No"<<endl;
	    return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 11136
/**
  @file a.cpp
  @title A - Takahashi Calendar
  @url https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_a
**/

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

int main() {
  int M, D;
  cin >> M >> D;

  int ans = 0;
  int i, d1, d10, m;
  for (m = 2; m <= M; m++) {
    for (i = 20; i <= D; i++) {
      d1  = i % 10;
      d10 = i / 10;
      if (d1 >= 2 && d10 >= 2 && d1 * d10 == m) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
ll dp[3010][3010][5] = {}; // i行目j列に居て、今の行でk個アイテムを拾っているときの最大値
ll item[3010][3010] = {};
void Main(){
    int r,c,k;
    cin >> r >> c >> k;
    For(i,0,k){
        int x, y;
        ll v;
        cin >> x >> y >> v;
        item[x][y] = v;
    }
    For(i,1,r+1){
        For(j,1,c+1){
            dp[i][j][0] = dp[i][j-1][0];
            ll nax = 0;
            For(k,0,4){
                nax = max(nax, dp[i-1][j][k]);
            }
            dp[i][j][0] = max(dp[i][j][0], nax);
            For(k,1,4){
                dp[i][j][k] = dp[i][j-1][k];
                if(item[i][j] > 0){
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + item[i][j]);
                    if(k == 1){
                        dp[i][j][k] = max(dp[i][j][k], nax + item[i][j]);
                    }
                }
            }
        }
    }
    /*For(k,0,4){
        For(i,1,r+1){
            For(j,1,c+1){
                cout << dp[i][j][k] << " ";
            }
            cout << endl;
        }
        cout << endl;
    }*/
    For(k,0,4) ans = max(ans, dp[r][c][k]);
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 426572
#include <iostream>
#include <cstring>
#include <utility>
#include <queue>
#include <vector>
using namespace std;

int n, k, t1, t2, m = 1e9 + 7, dp[100005];
vector<int> g[100005];

int f(int p, int pr) {
    if(dp[p] != -1)
        return dp[p];
    int c = 1;
    if(pr == -1)
        c = k;

    int j = 2;
    if(pr == -1)
        j = 1;
        
    for(int i: g[p])
        if(i != pr)
            c = 1ll * c * f(i, p) % m * (k - (j++)) % m;
    return dp[p] = c;
}

int main() {
    cin >> n >> k;
    memset(dp, -1, sizeof dp);
    for(int i = 0; i < n - 1; ++i)
        cin >> t1 >> t2, g[t1].push_back(t2), g[t2].push_back(t1);
    
    cout << f(1, -1) << endl; 
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    vector<char> vec(s.size());
    for(int i = 0; i < s.size(); i++){
        vec.at(i) = s.at(i);
    }
    sort(vec.begin(), vec.end());
    int count = 0;
    for(int i = 0; i < s.size()-1; i++){
        if(vec.at(i) == vec.at(i + 1)){
            count++;
            break;
        }
    }
    if(count != 0){
        cout << "no" << endl;
    } else {
        cout << "yes" << endl;
    }
}


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

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

  int ans=0;

  if(L>0){
    for(int i=1;i<N;i++){
      ans += L+i;
    }
  } else if(L+N-1<0){
    for(int i=0;i<N-1;i++){
      ans += L+i;
    }
  } else {
    for(int i=0;i<N;i++){
      ans += L+i;
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		int a[] = new int[n];
		int d[] = new int[n];
		int ans = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = 0; i < n-1; i++) {
			d[i] = a[i+1]-a[i];
		}
		d[n-1] = k-a[n-1]+a[0];
		Arrays.sort(d);
		for(int i = 0; i < n-1; i++) {
			ans+=d[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 87248
# ユニオンファインド
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
b=[]
a.sort()
# aの各点に通し番号を振る
for i in range(n):
    a[i].append(i)

# 繋ぐ点の候補は上下左右の４つ
# 左右に繋ぐ辺を追加
for i in range(n):
    if i==0:
        b.append([a[i][2],a[i+1][2], a[i+1][0]-a[i][0]])
    elif i==n-1:
        b.append([a[i][2],a[i-1][2], a[i][0]-a[i-1][0]])
    else:
        b.append([a[i][2],a[i-1][2], a[i][0]-a[i-1][0]])
        b.append([a[i][2], a[i + 1][2], a[i + 1][0] - a[i][0]])

a.sort(key=lambda x:x[1])
# 上下に繋ぐ辺を追加
for i in range(n):
    if i==0:
        b.append([a[i][2],a[i+1][2], a[i+1][1]-a[i][1]])
    elif i==n-1:
        b.append([a[i][2],a[i-1][2], a[i][1]-a[i-1][1]])
    else:
        b.append([a[i][2],a[i-1][2], a[i][1]-a[i-1][1]])
        b.append([a[i][2], a[i + 1][2], a[i + 1][1] - a[i][1]])

b.sort(key=lambda x:x[2])

uf=UnionFind(n)
ans=0
cnt=0
# クラスカル法
for x,y,z in b:
    if not uf.same(x,y):
        uf.union(x,y)
        cnt+=1
        ans+=z
        if cnt==n-1:
            break
print(ans)

Measured memory_bytes: 126076
#include <stdio.h>

int search(char editor[]);

int main(void)
{
	char str[11];
	char editor[11] = "          ";
	int n = 0, i;
	
	scanf("%s", str);
	
	for(i = 0; str[i] != '\0'; i++) {
		if(str[i] != 'B') {
			editor[n] = str[i];
		}
		else if(n - 1 >= 0) {
			editor[n - 1] = ' ';
		}
		n = search(editor);
	}
	printf("%s", editor);
	return 0;
}
int search(char editor[])
{
	int i;
	
	for(i = 0; editor[i] != ' '; i++);
	
	return i;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
    int a,b;
    
    scanf("%d %d",&a,&b);
    
    if (a < b){
        printf("a < b\n");
    }
    else if (a > b){
        printf("a > b\n");
    }
    else if (a == b){
        printf("a == b\n");
    }
    
    return 0;
}


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

using namespace std;

int main(void){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> s(M);
    vector<int> p(M);
    for(int i = 0; i < M; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int sij;
            cin >> sij;
            s[i].push_back(sij - 1);
        }
    }
    for(int i = 0; i < M; i++) cin >> p[i];
    int ans = 0;
    for(int n = 0; n < (1 << N); n++){
        int nn = n;
        vector<int> sw(N);
        for(int i = 0; i < N; i++){
            sw[i] = nn % 2;
            nn /= 2;
        }
        vector<int> sum(M, 0);
        int count = 0;
        for(int i = 0; i < M; i++){
            for(auto itr = s[i].begin(); itr != s[i].end(); itr++){
                sum[i] += sw[*itr];
            }
            if(sum[i] % 2 == p[i]) count++;
            
            // cout << i << " " << sum[i] << endl;
        }
        if(count == M) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {

    val (X, Y) = readLine()!!.split(" ").map { it.toInt() }

    for (a in 0..100) {
        for (b in 0..100) {
            if ((a+b)==X && (2*a+4*b)==Y) {
                println("Yes")
                return
            }
        }
    }
    println("No")

}

Measured memory_bytes: 36360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	string line;
	int r,i,c;
	for(;cin>>line,line!="0";cout<<r<<endl){
		vector<int>v(11);
		for(r=i=0;i<line.size();i++){
			c=line[i]-'0';
			reverse(v.begin()+1,v.end());
			rotate(v.begin(),v.begin()+(11-c),v.end());
			r+=v[0];
			if(c)v[c]++;
		}
	}
}
/*
R言語で
(0:10*10)%%11
を実行すると
0 10  9  8  7  6  5  4  3  2  1
が得られる。すなわち第1要素から末端を逆転すれば良い。
また、
(0:10*10+1)%%11
を実行すると
1  0 10  9  8  7  6  5  4  3  2
が得られる。これはrotate(11-1)である。
以上によりin-placeな実装が可能である。
*/

Measured memory_bytes: 1340
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	String str = sc.nextLine();
    	SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd");
    	Date date = sdFormat.parse(str);
    	String str2 = "2019/05/01";
    	Date date2 = sdFormat.parse(str2);
    	sc.close();
    	System.out.println(date2.after(date) ? "Heisei" : "TBD");
    }
}

Measured memory_bytes: 22096
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}


int main(){
  int N;
  cin >> N;
  string X;
  vector<string> s(N);
  vi t(N);
  bool flag = false;
  int ans=0;
  rep(i,N) cin>>s.at(i)>>t.at(i);
  cin >> X;


  rep(i,N){
    if(flag){
      ans += t.at(i);
    }
    if(flag==false){
      if(s.at(i) == X){
        flag = true;
      }
    }

  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int ab[26]={};
    string s;
    while(getline(cin,s)){
        for(int i=0;i<s.size();i++){
            if(s[i]>='a'&&s[i]<='z')ab[s[i]-'a']++;
            else if(s[i]>='A'&&s[i]<='Z')ab[s[i]-'A']++;
        }    
            
    }
    for(int i=0;i<26;i++){
        cout<<(char)('a'+i)<<" "<<":"<<" "<<ab[i]<<"\n";   
    }
    return 0;
}



Measured memory_bytes: 3156
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,x,y = MI()
dp = [[[10**4]*401 for i in range(401)] for n in range(N+1)]
# dp[n][i][j] = 薬品1~nを用いて、タイプAをiグラム、タイプBをjグラムを作った時に必要な最小予算

dp[0][0][0] = 0
for n in range(1,N+1):
    a,b,c = MI()
    for i in range(401):
        for j in range(401):
            if i >= a and j >= b:
                dp[n][i][j] = min(dp[n-1][i][j],dp[n-1][i-a][j-b]+c)
            else:
                dp[n][i][j] = dp[n-1][i][j]

z = min(dp[N][x*i][y*i] for i in range(1,min(400//x,400//y)+1))
print(-1 if z == 10**4 else z)


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

// #include <iomanip>

int main() {
  int H, W;
  std::cin >> H >> W;

  std::vector<std::vector<bool>> A(H, std::vector<bool>(W));
  std::vector<std::vector<int>> dist(H, std::vector<int>(W, 3000));

  for (int y=0; y<H; y++) {
    for (int x=0; x<W; x++) {
      char a;
      std::cin >> a;
      A[y][x] = (a == '#');
      if (A[y][x]) dist[y][x] = 0;
    }
  }


  // for (int y=0; y<H; y++) {
  //   for (int x=0; x<W; x++) {
  //     std::cerr << std::setw(5) << dist[y][x];
  //   }
  //   std::cerr << std::endl;
  // }
  // std::cerr << std::endl;

  for (int y=0; y<H; y++) {
    for (int x=1; x<W; x++) {
      if (! A[y][x])
        dist[y][x] = dist[y][x-1] + 1;
    }
  }

  // for (int y=0; y<H; y++) {
  //   for (int x=0; x<W; x++) {
  //     std::cerr << std::setw(5) << dist[y][x];
  //   }
  //   std::cerr << std::endl;
  // }
  // std::cerr << std::endl;

  for (int y=0; y<H; y++) {
    for (int x=W-2; x>=0; x--) {
      if (! A[y][x])
        dist[y][x] = std::min(dist[y][x], dist[y][x+1] + 1);
    }
  }

  // for (int y=0; y<H; y++) {
  //   for (int x=0; x<W; x++) {
  //     std::cerr << std::setw(5) << dist[y][x];
  //   }
  //   std::cerr << std::endl;
  // }
  // std::cerr << std::endl;

  for (int y=1; y<H; y++) {
    for (int x=0; x<W; x++) {
      if (! A[y][x])
        dist[y][x] = std::min(dist[y][x], dist[y-1][x] + 1);
    }
  }

  // for (int y=0; y<H; y++) {
  //   for (int x=0; x<W; x++) {
  //     std::cerr << std::setw(5) << dist[y][x];
  //   }
  //   std::cerr << std::endl;
  // }
  // std::cerr << std::endl;

  for (int y=H-2; y>=0; y--) {
    for (int x=0; x<W; x++) {
      if (! A[y][x])
        dist[y][x] = std::min(dist[y][x], dist[y+1][x] + 1);
    }
  }

  // for (int y=0; y<H; y++) {
  //   for (int x=0; x<W; x++) {
  //     std::cerr << std::setw(5) << dist[y][x];
  //   }
  //   std::cerr << std::endl;
  // }
  // std::cerr << std::endl;

  int ans = 0;

  for (int y=0; y<H; y++) {
    for (int x=0; x<W; x++) {
      ans = std::max(ans, dist[y][x]);
    }
  }

  std::cout << ans;

  return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

ll N, M, S, T, X, Y;
vector<ll> E[100010];

ll wfs(ll *count, ll s, ll t) {
  bool visited[100010];
  REP(i, 0, N) visited[i] = false;
  REP(i, 0, N) count[i] = 0;

  ll dist;
  queue<pii> q;
  q.push(pii(0, s));

  while(q.size()) {
    ll d = q.front().first, v = q.front().second;
    q.pop();

    if(visited[v]) continue;
    visited[v] = true;

    count[d]++;

    if(v == t) {
      dist = d;
      break;
    }

    REP(i, 0, E[v].size()) if(!visited[E[v][i]]) q.push(pii(d + 1, E[v][i]));
  }

  return dist;
}

int main(void) {
  cin >> N >> M >> S >> T; S--; T--;
  REP(i, 0, M) {
    cin >> X >> Y; X--; Y--;
    E[X].push_back(Y);
    E[Y].push_back(X);
  }

  ll scount[100010], tcount[100010];
  ll sdist = wfs(scount, S, T);
  ll tdist = wfs(tcount, T, S);

  ll ans = 0;
  REP(i, 0, sdist - 1) ans += scount[i] * tcount[tdist - i - 2];
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12252
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    int A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    --A; --B; --C; --D;
    string S;
    cin >> S;
    
    bool bRet = true;
    if (C < D) {
        for (int n = A; n < D; ++n) {
            if (S[n] == '#' && S[n+1] == '#') {
                bRet = false;
                break;
            }
        }
    } else {
        for (int n = A; n < C; ++n) {
            if (S[n] == '#' && S[n+1] == '#') {
                bRet = false;
                break;
            }
        }
        if (bRet) {
            bRet = false;
            for (int n = B-1; n <= D-1; ++n) {
                if (S[n] == '.' && S[n+1] == '.' && S[n+2] == '.') {
                    bRet = true;
                    break;
                }
            }
        }
    }

    if (bRet) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return 0;
}


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

using namespace std;
struct student{
char s[22];
int p,xiabiao;

}stu[120];
bool cmp(student x,student y)
{
    if(strcmp(x.s,y.s)!=0)
    return strcmp(x.s,y.s)<0;
    else
        return x.p>y.p;
}
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=1;i<=n;i++)
        {
            cin>>stu[i].s>>stu[i].p;
            stu[i].xiabiao=i;

        }
        sort(stu+1,stu+1+n,cmp);
        for(int i=1;i<=n;i++)
        {
            cout<<stu[i].xiabiao<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;

  cin >> N;
  cin >> K;

  vector <long int> HP(N);

  for(int i = 0; i < N; i++){
      cin >> HP.at(i);
  }

  sort(HP.begin(),HP.end());

  long int totalAttack = 0;
  for(int i = 0; i < N -K; i++){
      totalAttack += HP.at(i);
  }

  cout << totalAttack << endl;
}

Measured memory_bytes: 1792
import sys

N, M = map(int, sys.stdin.readline().split())
AB = [None] * N
for i in range(N):
    AB[i] = list(map(int, sys.stdin.readline().split()))

AB.sort()
cnt = 0
ans = 0

for a,b in AB:
    if cnt + b < M:
        ans += a * b
        cnt += b
    else:
        ans += a * (M - cnt) 
        break

print(ans)

Measured memory_bytes: 27804
#include<bits/stdc++.h>
using namespace std;
#define b1 1e18+7
long long a1[100000];
int main()
{
    int a,b;
   cin>>a>>b;
    for (int i=1;i<=a;i++)
    {
        cin >> a1[i];
    }
    long long ans=b1;
    for (int i=1;i+b-1<=a;i++)
    {
        long long x=a1[i+b-1]-a1[i];
        if ((a1[i]<0) && (a1[i+b-1]<0)) x+=abs(a1[i+b-1]);
        if ((a1[i]>0) && (a1[i+b-1]>0)) x+=a1[i];
        if ((a1[i]<0) && (a1[i+b-1]>0)) x+=min(-a1[i],a1[i+b-1]);
        ans=min(ans,x);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
def checkPrime(n):
    m = 2
    max = n
    while m < max:
        if n%m == 0:
            return False
        else:
            max = n//m
            m += 1
    return True

n = int(input())
cnt = 0
for ni in range(n):
    num = int(input())
    if checkPrime(num):
        cnt += 1
print(cnt)


Measured memory_bytes: 5608
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int n,x,m,i,sum=0,mi=1000;
  cin>>n>>x;
  for(i=0;i<n;i++)
  {
    cin>>m;
    sum+=m;
    mi=min(mi,m);
  }
  int ans=(x-sum)/mi+n;
  cout<<ans<<endl;

}

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

/*
 * ?????°??¶???????????????????????????
 */

int main(){
    int N,W;
    cin >> N >> W;
    vector<int> v(N),w(N);
    for(int i=0;i<N;i++) cin >> v[i] >> w[i];

    vector<vector<int>> dp(N+1,vector<int>(W+1,0));

    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(j-w[i]>=0)
                dp[i+1][j] = max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
            else
                dp[i+1][j] = max(dp[i][j],dp[i+1][j]);
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 6836
N = int(input())
heap = list(map(int, input().split()))

for i, a in enumerate(heap, start=1):  
    print(f'node {i}: key = {a}, ', end='')
    
    if i//2 != 0:
        print(f'parent key = {heap[i//2 -1 ]}, ', end='')
        
    if 2 * i <= N:
        print(f'left key = {heap[2*i - 1]}, ', end='')

    if 2 * i + 1 <= N:
        print(f'right key = {heap[2*i]}, ', end='')
    print("")


Measured memory_bytes: 5700
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);

  auto u = s[0..2].to!int, v = s[2..4].to!int;
  if (1 <= u && u <= 12 && 1 <= v && v <= 12)
    writeln("AMBIGUOUS");
  else if (1 <= u && u <= 12)
    writeln("MMYY");
  else if (1 <= v && v <= 12)
    writeln("YYMM");
  else
    writeln("NA");
}


Measured memory_bytes: 256