akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<long long int,int> P;
struct vertex{
    vector<P> E;//cost,to
};
#define INF 5000000001
vertex V[100000];
long long int minimum[100000];

int main(){
    int NV,NE,r;
    cin>>NV>>NE>>r;
    fill(minimum,minimum+100000,INF);
    for(int i=0;i<NE;i++){
        int s,t,d;
        cin>>s>>t>>d;
        V[s].E.emplace_back(d,t);
    }

    priority_queue<P,vector<P>,greater<P>> que;
    que.emplace(0,r);
    minimum[r]=0;
    while(!que.empty()){
        P p = que.top();que.pop();
        int cost = p.first, from = p.second;
        if(cost>minimum[from]) continue;
        for(auto& e:V[from].E){
            if(cost+e.first<minimum[e.second]){
                minimum[e.second]=cost+e.first;
                que.emplace(cost+e.first,e.second);
            }
        }
    }
    for(int i=0;i<NV;i++){
        if(minimum[i]==INF){
            cout<<"INF"<<endl;
        }else{
            cout<<minimum[i]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 19504
n, k = map(int, input().split())
d = {}
for _ in range(n):
    a, b = map(int, input().split())
    d[a] = d.get(a, 0) + b

cnt = 0
for i, v in sorted(d.items(), key=lambda x: x[0]):
    cnt += v
    if cnt >= k:
        print(i)
        break


Measured memory_bytes: 15072
H, W = map(int, input().split())
s_list = ["."*(W+2)]
for h in range(H):
    s_list.append("." + input() + ".")
s_list.append("."*(W+2))

ans_list = []
for h in range(1, H+1):
    for w in range(1, W+1):
        if s_list[h][w]=='#':
            if s_list[h-1][w]=='#':
                ans = True
            elif s_list[h+1][w]=='#':
                ans = True
            elif s_list[h][w-1]=='#':
                ans = True
            elif s_list[h][w+1]=='#':
                ans = True
            else:
                ans = False
            ans_list.append(ans)

if len(ans_list)==sum(ans_list):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  swap(a, b);
  swap(a, c);

  cout << a << " ";
  cout << b << " ";
  cout << c << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from itertools import accumulate

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = list(accumulate(a))

    ans = 10**18

    for j in range(2):# 偶数行が正か奇数行が正
        ans2 = 0
        diff = 0
        for i in range(n):
            p = a[i] + diff
            # print(a[i],diff)
            if (i+j) % 2 == 0 and p <= 0:# 正になる
                ans2 += abs(p)+1
                diff += abs(p)+1
            elif (i+j) % 2 == 1 and p >= 0:# 負になる
                ans2 += abs(p)+1
                diff -= abs(p)+1

        ans = min(ans, ans2)
    print(ans)

if __name__ == "__main__":
    main()


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

int main(){
    int x; cin >> x;
    int i = x;
    bool check = false;
    while(i<=2*x){
        int j = 2;
        while(j<i/2+1){
            if(i%j==0){
                break;
            }
            j++;
        }
        if(j==i/2+1){
            check = true;
            break;
        }
        i++;
    }
    if(check)cout << i << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
#define pii pair<int, pair<int, int>>
const double pi = acos(-1);
const int sz = 200002;
ll n, m, q, k;

int main() {
	io
	int t = 1;
	// cin>>t;
	while(t--) {
		cin>>n>>m>>k;
		int ans =0;
		for(int i = n; i <= m; i++) if(i%k == 0) ans++;
		cout<<ans;
	}
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if(a + b == 15){
        cout << "+" << endl;
    }else if(a*b == 15){
        cout << "*" << endl;
    }else{
        cout << "x" << endl;
    }
}


Measured memory_bytes: 768
#include <stdio.h>

int main()
{
	int N;
	scanf("%d",&N);
	double x;
	char u[10];

	double sum = 0;
	while ( N-- ) {
		scanf("%lf %s",&x,u);
		if ( u[0] == 'J' ) {
			sum += x;
		} else {
			sum += x * 380000.0;
		}
	}
	printf("%.5f\n",sum);
	return 0;
}

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

public class Main {

	public static void main(String[] args) {

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String line = reader.readLine();
			int x = Integer.parseInt(line);
			System.out.println(x * x * x);
		} catch (IOException e) {
			System.out.println(e);
		}
	}

}


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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cin >> s;
    cout << "A" << s.at(0) << "C" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

char s[105];
int k;

int main() {
  scanf("%d %s", &k, s);
  if (strlen(s) <= k)
    printf("%s\n", s);
  else {
    for (int i = 0; i < k; i++) printf("%c", s[i]);
    printf("...\n");
  }
}

Measured memory_bytes: 1664
#include <stdio.h>

int main()
{
  int a, b, c, result;
  scanf("%d %d %d", &a, &b, &c);
  if (c - (a - b) > 0)
  {
    result = c - (a - b);
  }
  else
  {
    result = 0;
  }
  printf("%d", result);
  return 0;
}

Measured memory_bytes: 128
import  math

def pow(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

H = int(input())

#print(int(math.log2(H)))
print(pow(2,int(math.log2(H))+1)-1)


Measured memory_bytes: 9296
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void){
    //入力部分
    int H, W, D;
    cin>>H>>W>>D;

    int x[W * H];
    int y[W * H];

    int tmp;
    for(int i = 0; i < W * H; i++){
        cin>>tmp;
        tmp--;
        x[tmp] = i / W;
        y[tmp] = i % W;
    } 

    int Q;
    cin>>Q;
    int L[Q];
    int R[Q];
    for(int i = 0; i < Q; i++){
        cin>>L[i]>>R[i];
        L[i]--;
        R[i]--;
    }
    //入力部分終わり

    int memo[W * H];
    for(int i = 0; i < W * H; i++){
        if(i < D){
            memo[i] = 0;
        }else{
            memo[i] = memo[i-D] + abs(x[i]-x[i-D]) + abs(y[i] - y [i-D]);
        }
    }
    
    for(int i = 0; i < Q; i++){
        cout<<memo[R[i]] - memo[L[i]]<<endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF=1e9+7,MAXN=2e5+10,MAXM=4e5+10;
struct node {
	int u,v;
	LL w;
	node() {
		u=v=w;
	}
	node(int x,int y,LL z) {
		u=x;
		v=y;
		w=z;
	}
	friend bool operator<(node x,node y) {
		return x.w<y.w;
	}
} e[MAXM];
int sz;
inline void add(int x,int y,LL z) {
	e[++sz]=node(x,y,z);
}
int fa[MAXN];
int findset(int x) {
	return fa[x]==x?x:fa[x]=findset(fa[x]);
}
int N,Q;
LL d[MAXN];
int main() {
	scanf("%d%d",&N,&Q);
	memset(d,0x3f,sizeof(d));
	for(int i=1,ii,jj; i<=Q; i++) {
		LL kk;
		scanf("%d%d%lld",&ii,&jj,&kk);
		add(ii,jj,kk);
		d[ii]=min(d[ii],kk+1);
		d[jj]=min(d[jj],kk+2);
	}
	for(int i=0; i<N; i++)
		d[i]=min(d[i],d[(i+N-1)%N]+2);
	for(int i=0; i<N; i++)
		d[i]=min(d[i],d[(i+N-1)%N]+2);
	for(int i=0; i<=N; i++)
		add(i,(i+1)%N,d[i]);
	sort(e+1,e+sz+1);
	for(int i=1; i<N; i++)
		fa[i]=i;
	LL cnt=N-1,ans=0;
	for(int i=1; i<=sz&&cnt; i++) {
		int f1=findset(e[i].u),f2=findset(e[i].v);
		if(f1!=f2) {
			ans+=e[i].w;
			fa[f1]=f2;
			cnt--;
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 11136
#include<iostream>
#include<cstdio>
#include<algorithm>
int a[15];
using namespace std;
int main(){
	int n;
	cin>>n;
	int maxn = 0;
	int sum = 0;
	for(int i = 0; i < n; i++){
		cin>>a[i];
		sum+=a[i];
		maxn = max(maxn,a[i]); 
	} 
	if(sum-maxn > maxn)
		cout<<"Yes"<<endl;
	else 
		cout<<"No"<<endl;
}

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

int main(){
  int r,g,b,n;
  int counter=0;
  cin>>r>>g>>b>>n;
  for(int i=0;i<=3000;i++){
    for(int j=0;j<=3000;j++){
      if(n-i*r-j*g>=0&&(n-i*r-j*g)%b==0){
        counter++;
      }
    }
  }
  cout<<counter<<endl;
}

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

using namespace std;

typedef long long int64;

int main(void){
    int64 P,Q,R;
    cin>>P>>Q>>R;
    cout<<min(P+Q,min(Q+R,R+P))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int p=1e9+7,c,i,mx,k,k1,a[100001];
int ax(int n)
{
	if(n==1)
	return c;
	long long l=ax(n/2);
	if(n%2==0)
	return (l*l)%p;
	
	return ((l*l)%p*c)%p;
}
main(){
	int n;
	ios::sync_with_stdio(0);
	cin>>n>>k;
	k1=k;
	for(k1=k;k1>0;k1--)
	{
		if(k/k1==1)
		{
			a[k1]=1;
			continue;
		}
		c=k/k1;
		a[k1]=ax(n);
		for(i=2;i<=c;i++)
		{
			a[k1]-=a[i*k1];
			a[k1]%=p;
			a[k1]+=p;
			a[k1]%=p;
		}
	}
	for(i=1;i<=k;i++)
	{
		mx+=((long long)a[i]*i)%p;
		mx%=p;
	}
	cout<<mx;
}


Measured memory_bytes: 4036
#include<stdio.h>
int main() {
	int A, B, C, D, E, F;
	scanf("%d%d%d%d%d%d", &A, &B, &C, &D, &E, &F);
	//A = 1, B = 2, F = 200;
	//C = 10, D = 20, E = 15;

	int a, b, c, d, x, y;
	double noudo = 0, noudomax = 0, noudolim = 0;
	int ansa = 0, ansb = 0;

	noudolim = (double)E / (100 + (double)E);
	for (a = 0; a <= F / (100 * A); a++)
	{
		for (b = 0; b <= F / (100 * B); b++)
		{
			for (c = 0; c <= F / C; c++)
			{
				for (d = 0; d <= F / D; d++)
				{
					x = 100 * A * a + 100 * B * b;
					y = C * c + D * d;
					if (x > 0)
					{
						if (x + y <= F)
						{
							noudo = (double)y / ((double)x + (double)y);
							if (noudo <= noudolim)
							{
								//printf("a:%d b:%d c:%d d:%d \n", a, b, c, d);
								//printf("noudo:%lf \n", noudo);
								//printf("noudomax:%lf \n", noudomax);
								if (noudo > noudomax && x != 0)
								{
									noudomax = noudo;
									ansa = x + y;
									ansb = y;
									//printf("a:%d b:%d c:%d d:%d \n", a, b, c, d);
									//printf("noudo:%lf \n", noudo);
									//printf("noudomax:%lf \n", noudomax);
									//printf("%d %d\n", x + y, y);
								}
								//printf("\n");
							}
						}
					}
				}
			}
		}
	}
	if (noudomax == 0)
	{
		ansa = 100*A;
	}
	printf("%d %d\n", ansa, ansb);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
#define ALL(X) X.begin(), X.end()
using lint = long long;
template <typename T>
void print_container(std::vector<T> vec)
{
    for (auto iter = vec.begin(); iter != vec.end(); ++iter)
    {
        std::cout << *iter << " ";
    }
    std::cout << std::endl;
}

int main() {
    lint n, k;
    scanf("%lld", &n);
    scanf("%lld", &k);

    std::vector<std::pair<lint, lint>> sushi;

    for (int i = 0; i < n; ++i) {
        lint t, d;
        scanf("%lld", &t);
        scanf("%lld", &d);

        sushi.emplace_back(d, t);
    }

    std::sort(ALL(sushi), std::greater<std::pair<lint, lint>>());

    std::set<lint> appear;
    std::multiset<lint> red;

    lint idx = 0;
    lint del_sum = 0;
    lint kind_num = 0;

    for (; idx < k; ++idx) {
        auto cur_sushi = sushi[idx];
        lint cur_del = cur_sushi.first;
        lint cur_kind = cur_sushi.second;
        del_sum += cur_del;
        if (appear.find(cur_kind) == appear.end()) {
            appear.insert(cur_kind);
            kind_num++;
        }
        else {
            red.insert(cur_del);
        }
    }

    lint score = del_sum + kind_num*kind_num;

    for (; idx < n; ++idx) {
        auto cur_sushi = sushi[idx];
        lint cur_del = cur_sushi.first;
        lint cur_kind = cur_sushi.second;

        if (red.size() == 0) {
            break;
        }

        if (appear.find(cur_kind) == appear.end()) {
            del_sum -= *red.begin();
            del_sum += cur_del;
            red.erase(red.begin());

            appear.insert(cur_kind);
            kind_num++;

            score = std::max(score, del_sum + kind_num*kind_num);
        }
    }

    std::cout << score << "\n";


    return 0;
}


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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}



int main() {
	int N,M,C; cin >> N >> M >> C;
	V<int> B(M);
	REP(i,M) cin >> B[i];
	int ans = 0;
	REP(i,N){
		int cnt = C;
		REP(j,M) {
			int A; cin >> A;
			cnt += A*B[j];
		}
		if(cnt>0) ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int n = sc.nextInt();
        int array[] = new int[w];
        for (int i = 0; i < w; i++) array[i] = i+1;
        for (int i = 0; i < n; i++){
            String line = sc.next();
            String spl[] = line.split(",");
            int a = Integer.parseInt(spl[0]) - 1;
            int b = Integer.parseInt(spl[1]) - 1;
            int tmp = array[a];
            array[a] = array[b];
            array[b] = tmp;
        }
        for (int i = 0; i < w; i++){
            System.out.println(array[i]);
        }
    }
}

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

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

using namespace std;

int n, a, b;

int main(){
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var S = readLine()!! .toCharArray()
    var map = mutableMapOf<Char, Int>()
    S.forEach {
        val n = map.get(it) ?: 0
        map.put(it, n+1)
    }
    var ans = "No"
    if (map.count() == 2) {
        /*if (map.values.all { it == 2})*/ ans = "Yes"
    }
    println(ans)
}


Measured memory_bytes: 31852
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

vll fac(100100,1) ;

ll modpow(ll a,ll b){
	ll res = 1 ;
	while(b>0){
		if(b&1) res = res*a%mod ;
		b >>= 1 ;
		a = a*a%mod ;
	}
	return res ;
}

ll ncr(ll n,ll r){
	if(n<0||r<0||n<r) return 0 ;
	if(n==r||r==0) return 1 ;
	return fac.at(n)*modpow(fac.at(n-r),mod-2)%mod*modpow(fac.at(r),mod-2)%mod ;
}

int main(){
	for(int i=2;i<fac.size();i++) fac.at(i) = fac.at(i-1)*i%mod ;
	ll n,k ;
	cin >> n >> k ;
	vll a(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i) ;
	mysort(a) ;
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		ll sub = (ncr(i,k-1)-ncr(n-i-1,k-1))*a.at(i) ;
		ans += sub ;
		ans %= mod ;
//		cout << ans << endl ;
	}
	cout << ans << endl ;
}



Measured memory_bytes: 1792
#include <string>
#include <iostream>
using namespace std;
bool check(string s, string t, string u) {
	int ls = 0, lt = 0;
	for (int i = 0; i < u.size(); i++) {
		if (i % 2 == 0) {
			while (ls <= s.size()) {
				if (ls == s.size()) return false;
				if (u[i] == s[ls]) {
					ls++;
					break;
				}
				ls++;
			}
		}
		else {
			while (lt <= t.size()) {
				if (lt == t.size()) return false;
				if (u[i] == t[lt]) {
					lt++;
					break;
				}
				lt++;
			}
		}
		// cout << i << ' ' << ls << ' ' << lt << endl;
	}
	return true;
}
int main() {
	string s, t;
	cin >> s >> t;
	if (check(s, t, s) || check(t, s, s)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3172
n = int(input())
D = list(map(int,input().split()))
m = int(input())
T = list(map(int,input().split()))

p = {}
for d in D:
    if d not in p:
        p[d] = 1
    else:
        p[d] += 1

for t in T:
    if t not in p:
        print('NO')
        exit()
    if p[t] == 0:
        print('NO')
        exit()
    p[t] -= 1
    
print('YES')

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

string S, T;
int pos[26][100100];

signed main() {
    cin >> S >> T;
    set<char> ss;
    for (char s:S) {
        ss.insert(s);
    }
    for (char t:T) {
        if (ss.count(t) == 0) {
            cout << -1 << endl;
            return 0;
        }
    }

    rep(i, 26)rep(j, 100100)pos[i][j] = -1;

    rep(i, S.size()) {
        int c = S[i] - 'a';
        pos[c][i] = i;
    }
    rep(c, 26) {
        int k = 0;
        while (k < S.length() && pos[c][k] == -1) {
            k++;
        }
        if (k == S.length())continue;
        int prev = pos[c][k];
        for (int j = k - 1; j >= 0; --j) {
            if (pos[c][j] == -1)pos[c][j] = prev;
            else {
                assert(0);
            }
        }
        for (int j = S.length() - 1; j > k; --j) {
            if (pos[c][j] == -1)pos[c][j] = prev;
            else {
                prev = pos[c][j];
            }
        }
    }
    int num = 0;
    int prev = -1;
    rep(i, T.size()) {
        int cur = pos[T[i] - 'a'][(prev + 1) % S.length()];
        if (cur <= prev)num++;
        prev = cur;
    }
    cout << num * S.length() + prev + 1 << endl;
    return 0;
}


Measured memory_bytes: 20864
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def f(x, s):
    if min(x, s) < 0: return 0
    if max(x, s) < 2:
        if x and s: return 2
        else: return 1
    if (x, s) in memo: return memo[x, s]
    res = f(x >> 1, s >> 1) + f(x - 1 >> 1, s - 1 >> 1) + f(x >> 1, s - 2 >> 1)
    res = memo[x, s] = res % md
    return res

memo = {}
md = 10 ** 9 + 7

def main():
    n = II()
    print(f(n, n))

main()


Measured memory_bytes: 3064
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextLong()

    // 最終的にできた数 = 10^N * M と表した時の N が答え
    // 10 = 2 * 5
    // 偶数スタートなら偶数しかかからないし
    // 奇数スタートなら奇数しかかからないので
    // 最初から10がかかっている数しかカウントされない
    // 奇数スタートの場合, 常に0個である
    // 偶数スタートの場合, N (<= 10^18) の10の倍数のみを調べ
    // それらを10で割った時の合計が答え
    // だが, 全列挙したところで　10^17 あるので間に合わない
    // N以下の XXXXX00 が何通りあるか？を 調べていく
    // XXXXX 通り ?
//    def solve(N: Long): Long = {
//      if (N % 2 == 1) return 0
//      val NARR: Array[Long] = N.toString.map(_ - '0').map(_.toLong).toArray
//      val L = N.toString.length
//      def loop(i: Int, acm: Long): Long =
//        if (i < L) {
//          loop(i + 1 , acm + (1 until i).foldLeft(NARR(0))((b, n) => b * 10L + NARR(n)))
//        } else acm
//      loop(1, 0)
//    }

    def solve(N: Long): Long = {
      if (N % 2 == 1) return 0
      def loop(denom: Long, acm: Long): Long =
        if (denom <= N) {
          loop(denom * 5, acm + N / denom)
        } else acm
      loop(10, 0)
    }

    println(solve(N))
  }

}


Measured memory_bytes: 27332
import java.io.*;

public class Main {
    public static void main(String[] args) {
        int a, b, c;

        try (InputScanner is = new InputScanner(System.in)) {
            a = is.ni();
            b = is.ni();
            c = is.ni();
        }
        if (a + b + c >= 22) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }

    }

    //-------------------------------------------------------------------
    public static class InputScanner implements Closeable {
        private final BufferedReader br;
        private String[] element;
        private int elementIndex;

        public InputScanner(InputStream is) {
            this.br = new BufferedReader(new InputStreamReader(is));
        }

        public String next() {
            return this.nextElement();
        }

        //next int
        public int ni() {
            return Integer.parseInt(this.nextElement());
        }

        //next long
        public long li() {
            return Long.parseLong(this.nextElement());
        }

        //next int array
        public int[] nia(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = this.ni();
            }
            return arr;
        }

        private void readLine() {
            try {
                this.element = this.br.readLine().split("\\s");
            } catch (IOException e) {
                e.printStackTrace();
            }
            this.elementIndex = 0;
        }

        private String nextElement() {
            if (!hasElement()) {
                this.readLine();
            }
            return this.element[this.elementIndex++];
        }

        private boolean hasElement() {
            return this.element != null && this.element.length > this.elementIndex;
        }

        @Override
        public void close() {
            if (this.br != null) {
                try {
                    this.br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
//-------------------------------------------------------------------
}


Measured memory_bytes: 22868
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;





int main(void) {

    double a, b, x;
    cin>>a>>b>>x;
    double s = x/a;
    if(s >= a*b/2) {
        double h = ((a*b-s)*2)/a;
        printf("%.7f\n", atan2(h,a)/(2*M_PI)*360);
    } else {
        double h = s*2/b;
        printf("%.7f\n", atan2(b,h)/(2*M_PI)*360);
    }
    


}



Measured memory_bytes: 256
N,A,B=map(int,input().split())
T=[int(i) for i in input().split()]
ans=0
for i in range(N-1):
  if B>=A*(T[i+1]-T[i]):
    ans+=A*(T[i+1]-T[i])
  else:
    ans+=B
    
print(ans)
    
                                      

Measured memory_bytes: 62832
S = list(input())
x = int("".join(S[0:2]))
y = int("".join(S[2:4]))
if 1 <= x <= 12:
    if 1 <= y <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1 <= y <= 12:
        print("YYMM")
    else:
        print("NA")
pass


Measured memory_bytes: 9160
let rec calc (r,i,n,k) =
    if i==n then r else calc((r+k) mod i,i+1,n,k);;
 
while true do
    let nkm = Array.of_list (List.map int_of_string (Str.split (Str.regexp " ") (read_line ()))) in
        if nkm.(0)==0 then exit(0) else (print_int((calc(0,1,nkm.(0),nkm.(1))+nkm.(2)) mod nkm.(0)+1); print_string "\n") done;;

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

int main(){
  int a,b,c;

  cin >> a >> b >> c;
  
  //a,bを入れ替える
  swap(a,b);
  //a,cを入れ替える
  swap(a,c);
  
  cout<< a << " " <<  b << " " << c ;
  
  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,a[1700005];
char s[1700005];
void mov()
{
	if (a[1]==1) a[1]=0;
	else
	{
		for (int i=1;i<n;i++)
			if (a[i]==a[i+1]) a[i]^=1;
		//if (a[n]==0)
		a[n]=1;
	}
}
int main()
{
	scanf("%d%d%s",&n,&k,s+1);
	for (int i=1;i<=n;i++)
		a[i]=s[i]=='A';
	/*
	for (int i=1;i<=k;i++)
		mov();
	*/
	int l=1,r=n,now=0;
	for (int i=1;i<=k;i++)
	{
		if ((a[l]^now)==1) a[l]^=1;
		else
		{
			l++;r++;
			a[r]=now;now^=1;
		}
		if (i>n*2&&(k-i)%2==0) break;
	}
	for (int i=l;i<=r;i++)
		putchar((a[i]^now)?'A':'B');
}

Measured memory_bytes: 3072
S = list(input())
t = []
N = len(S)

for i in range(N):
  if S[0] == "B":
    S.pop(0)
    if len(t) > 0:
      t.pop(-1)
  else:
    t.append(S[0])
    S.pop(0)

print(*t, sep = "")


Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
ll mod;



template<typename T>
struct SegmentTree{
private:
    int n;
    T E;
    vector<T> node;
    inline void updatef(T& x,T& y){
        //x = y;
        x += y;
        //x = max(x,y);
        //x = min(x,y);
    }
    inline T queryf(T& x,T& y){
        //return x*y;
        return (x+y)%mod;
        //return max(x,y);
        //return min(x,y);
    }

public:
    SegmentTree(int sz,T E_):E(E_){
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
    }

    SegmentTree(vector<T>& A,T E_):E(E_){
        int sz=A.size();
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
        rep(i,sz)node[i+n-1]=A[i];
        for(int i=n-2;i>=0;--i){
            node[i]=queryf(node[2*i+1], node[2*i+2]);
        }
    }
    void update(int k,T x){
        k+=n-1;
        updatef(node[k],x);
        while(k>0){
            k=(k-1)/2;
            node[k]=queryf(node[2*k+1], node[2*k+2]);
        }
    }
       //[a,b)での和を返す
    T get(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=a||b<=l)return E;
        if(a<=l&&r<=b)return node[k];
        T xl=get(a,b,2*k+1,l,(l+r)/2);
        T xr=get(a,b,2*k+2,(l+r)/2,r);
        return queryf(xl, xr);
    }
};

void solve(ll a,ll b){
    cin>>mod;
    SegmentTree<ll> sg(101010,0);
    for(ll i=0;i<=b-a;++i){
        ll cur=a+i;
        ll ret=0;
        while(cur){
            if(cur<a)break;
            ll d=1;
            while(d<=cur)d*=10;
            d/=10;
            d=max(d,a);
            ret+=sg.get(d-a, cur-a+1);
            cur/=10;
        }
        ++ret;
        sg.update(i,ret);
    }
    cout<<sg.get(0,101010)<<endl;
}
int main(){
    ll a,b;
    while(cin>>a>>b,a!=0)solve(a,b);
    return 0;
}


Measured memory_bytes: 5144
n, y = map(int, input().split())
for a in range(n + 1):
  for b in range(n - a + 1):
    c = n - a - b
    if 10000 * a + 5000 * b + 1000 * c == y:
      print(a, b, c)
      exit()
print("-1 -1 -1")

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

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

    //I don't care about anybody, and fuck ratings! I'll go to google!
    int n, l, r; cin>>n;
    vector<int> a(n);
    for(int i = 0; i<n; i++) cin>>a[i];
    sort(a.begin(), a.end());

    int ans = 0;
    for(int i = n-1; i>=0; i--){
        l = 0;
        r = i-1;
        while(l<r){
            if(a[l]+a[r]>a[i]){
                ans += r-l;
                r--;
            }
            else l++;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int h, w;
  while(1){
        scanf("%d %d", &h, &w);
        if(h == 0 && w == 0){break;}
        for(int i = 0; i < h; i++){
          for(int j = 0; j < w; j++){
                if(i == 0 || i == h-1 || j == 0 || j == w -1){
                  printf("#");
                }else{
                  printf(".");
                }
          }
          printf("\n");
        }
        printf("\n");
  }
  return 0;
}


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

long long mod = 1000000000 + 7;

long long modplus(long long a, long long b){
	long long ans = a + b;
	ans %= mod;
	return ans;
}

long long modminus(long long a, long long b){
	long long ans = a - b;
	ans %= mod;
	if(ans < 0) ans += mod;
	return ans;
}

long long modmul(long long a, long long b){
	long long ans = (a % mod) * (b % mod);
	ans = ((ans % mod) + mod) % mod;
	return ans;
}

long long modpow(long long A, long long P){
	long long a = A, p = P;
	if(p == 0) return 1;
	if(p == 1) return a;
	long long adash = modmul(a,a);
	if(p % 2) return modmul(modpow(adash, p / 2), a);
	else return modpow(adash, p / 2);
}

long long moddiv(long long a, long long b){
	long long divisor = modpow(b, mod - 2);
	return modmul(a,divisor);
}

long long comb(long long n, long long m){
	if(n == 0)return 1;
	if(m == 0)return 1;
	if(n < m) return 0;
	long long ans = 1;
	for(long long i=0;i<m;i++){
		ans = modmul(ans, n-i);
	}
	for(long long i=0;i<m;i++){
		ans = moddiv(ans, i+1);
	}
	return ans;
}

int main(){
	long long S;
	cin >> S;
	long long A[S+1];
	for(int i=0;i<min((long long)3,S + 1);i++){
		A[i] = 0;
		// cout << A[i] << endl;
	}
	if(S > 2)A[3] = 1;
	// cout << A[3] << endl;
	for(int i = 4;i<=S;i++){
		A[i] = modplus(A[i - 3], A[i - 1]);
		// cout << A[i] << endl;
	}
	cout << A[S] << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
ll dp[200][100500]={};
ll min(ll a,ll b){
  if(a<b)return a;
  else return b;
}
ll inf=1005000000000;
int main(){
  int n;
  ll sup;
  cin>>n>>sup;
  vector<ll> v(n+5);
  vector<ll> w(n+5);
  for(int i=1;i<=n;i++){
    cin>>w[i]>>v[i];
  }
  dp[0][0]=0;
  for(ll i=1;i<100500;i++){
    dp[0][i]=inf;
  }
  for(ll i=1;i<=n;i++){
    //    dp[i][v[i]]=min(dp[i-1][v[i]],w[i]);
    for(ll j=1;j<100001;j++){
      if(j>=v[i]){
	dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
      }
      else dp[i][j]=dp[i-1][j];
    }
  }
  ll ans=0;
  for(ll i=100000;i>0;i--){
    if(dp[n][i]<=sup){
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 80128
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        String[] Astr = br.readLine().split(" ");
        String[] Bstr = br.readLine().split(" ");
        String[] Cstr = br.readLine().split(" ");
        
        int[] A = new int[N];
        int[] B = new int[N];
        int[] C = new int[N-1];
        
        for(int i = 0; i < N; i++){
            A[i] = Integer.parseInt(Astr[i]);
            B[i] = Integer.parseInt(Bstr[i]);
            if(i != N-1) C[i] = Integer.parseInt(Cstr[i]);
        }
        
        int sum = 0;
        
        for(int i = 0; i < N; i++){
            sum += B[A[i] -1];
            if( (i < N - 1) && (A[i] + 1 == A[i+1]) ) sum += C[A[i]-1];
        }
        
        System.out.println(sum);
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
    cin>>N>>K;
    vec t(N), d(N);
    rep(i,N) cin>>t[i]>>d[i];
    vec ord(N);
    rep(i,N) ord[i] = i;
    sort(ord.begin(),ord.end(),[&](ll x, ll y){
        if(d[x] == d[y]) return t[y] < t[x];
        return d[y] < d[x];
    });
    vec rest(0);//種類数に影響ない寿司のおいしさを入れていく
    set<ll> kind;
    ll ans = 0;
    rep(i,K){
        ll index = ord[i];
        auto ite = kind.find(t[index]);
        ans += d[index];
        if(ite == kind.end()){
            kind.insert(t[index]);
        }else{
            rest.push_back(d[index]);
        }
    }
    ll temp = ans;
    ll rindex = rest.size() - 1;
    ans += kind.size()*kind.size();
    reps(i,K,N){
        if(K == kind.size()) break;
        ll index = ord[i];
        auto ite = kind.find(t[index]);
        if(ite == kind.end()){
            kind.insert(t[index]);
            temp -= rest.at(rindex--) - d[index];
            ll comp = temp + kind.size()*kind.size();
            ans = max(ans,comp);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6012
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll INF = (1 << 28);
const ll MOD = 1000000007;
const ll dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const ll Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
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; }
//setprecision(15)有効数字15桁
//-std=c++14
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);}
ll h, n;
vector<pair<double,ll> > di;
vector<ll> a, b;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h>>n;
    for (ll i = 0; i < n; i++)
    {
        ll temp,temp1;
        cin >> temp>>temp1;
        a.push_back(temp);
        b.push_back(temp1);
    }
    ll dp[n+1][h+1];
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=h;j++){
            dp[i][j]=10000000000;
            if(j==0){
                dp[i][j]=0;
            }
        }
    }
    dp[0][0]=0;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<=h;j++){
            ll temp=j+a[i];
            if(j+a[i]>h){
                temp=h;
            }
            dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
            dp[i+1][temp]=min(dp[i][temp],min(dp[i+1][j]+b[i],dp[i+1][temp]));
            //dp[i+1][temp]=min(dp[i][j]+b[i],dp[i+1][temp]);
        }
    }
    /*
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=h;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<"\n";
    }
    */
    cout << dp[n][h] << "\n";
}



Measured memory_bytes: 78464
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
    do {                                                                       \
    } while (0)
#define dump(x)                                                                \
    do {                                                                       \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

void solve() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    PII ans = MP(-1, -1);
    REP(i, 0, 31) REP(j, 0, 31) REP(k, 0, 3001) {
        int water = (i * a + j * b) * 100;
        int max_sugar = min((i * a + j * b) * e, f - water);
        if (k * c > max_sugar)
            break;
        if (water + k * c > f)
            break;
        int l = ((max_sugar - k * c) / d) * d;
        int sugar = k * c + l;
        if (water + sugar == 0)
            continue;
        if (ans.first == -1) {
            ans.first = water + sugar;
            ans.second = sugar;
        } else if (sugar * ans.first > (water + sugar) * ans.second) {
            ans = MP(water + sugar, sugar);
        }
    }
    cout << ans.first << " " << ans.second << endl;
}

int main() {
    solve();

    return 0;
}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

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

    int N; cin >> N;
    vector<string> ABC(3); cin >> ABC;

    int ans = 0;
    rep(i, N) {
        if (ABC[0][i] == ABC[1][i] && ABC[1][i] == ABC[2][i]) {
        } else if (ABC[0][i] == ABC[1][i] || ABC[1][i] == ABC[2][i] || ABC[2][i] == ABC[0][i]) {
            ans += 1;
        } else {
            ans += 2;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{int i,j,k,sum,tmp;
	j=0;
	char S[100001];
	scanf("%s",S);
	k=strlen(S);
	
	for(i=1;i<=k-1;i++){
		if(S[i]!=S[i-1]){
			j++;}}
			printf("%d",j);
			
			
}

Measured memory_bytes: 256
# 上底の長さがa、下底の長さがb、高さがhの台形の面積
a = int(input())
b = int(input())
h = int(input())

# 台形の面積を求める公式（上程＋下底）＊高さ/２
area = int((a + b) * h / 2)
# 面積を出力
print(area)

Measured memory_bytes: 9088
#include <stdio.h>
#include<string.h>
int main(){
    char s[15];
    int i;
    char ans[15]="";
    scanf("%s",s);
    for(i=0;i<strlen(s);i++){
        switch(s[i]){
                case'0':
                case'1':
                    ans[strlen(ans)]=s[i];
                break;
        
                case'B':
                    ans[strlen(ans)-1]='\0';
        break;
            default:
                break;
        }
    }
    printf("%s\n",ans);
    
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdlib>
using namespace std;
int N;
int A[200];
const int INF=1000000000;

int main(){
    //最大値と最小値の絶対値を求める
    cin>>N;
    for(int i=0;i<N;++i)cin>>A[i];
        int res_min=INF;
        int res_max=-INF;
        for(int i=0;i<N;++i){
            if(res_min>A[i])res_min=A[i];
            if(res_max<A[i])res_max=A[i];
        }
    cout<<abs(res_max-res_min);
}

Measured memory_bytes: 3188
h,w = map(int,raw_input().split())
d = [map(int,raw_input().split()) for i in range(10)]
for t in xrange(10):
	for i in range(10):
		for j in range(10):
			for k in range(10):
				d[i][j] = min(d[i][j], d[i][k] + d[k][j])
arr = [map(int,raw_input().split()) for i in range(h)]

print sum(sum(d[a][1] if a>=0 else 0 for a in aa) for aa in arr)

Measured memory_bytes: 2948
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(),(x).end()
#define pushb push_back()
#define popb pop_back()
#define makep make_pair
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv);
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v);
template<typename T> ll gcd(T a,T b);
template<typename T> ll lcm(T a,T b);
int main(){
    vector<int> a(5);
    for(auto& x:a){
        cin>>x;
    }
    int k;cin>>k;
    if(a[4]-a[0]>k){
        cout<<":("<<endl;
        return 0;
    }
    cout<<"Yay!"<<endl;
    return 0;
}

Measured memory_bytes: 256
# include "algorithm"
# include "iostream"
# include "cstdio"
# define lowbit(x) (x&-x)

using namespace std;

const int maxm=2e5+10;

int N;
int H[maxm],A[maxm];
long long Tree[maxm];

void Update(int x,long long Data){
	while(x<=N){
		Tree[x]=max(Tree[x],Data);
		x+=lowbit(x);
	}
	return;
}

inline long long Query(int x){
	register long long Result=0;
	while(x){
		Result=max(Result,Tree[x]);
		x-=lowbit(x);
	}
	return Result;
}

int main(){
	register int i;
	register long long Ans=0,Now;
	scanf("%d",&N);
	for(i=1;i<=N;i++) scanf("%d",H+i);
	for(i=1;i<=N;i++) scanf("%d",A+i);
	for(i=1;i<=N;i++){
		Now=Query(H[i]-1)+A[i];
		Ans=max(Ans,Now);
		Update(H[i],Now);
	}
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 3328
n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
for i in range(n):
    t[i+1]=t[i]+(1 if s[i:i+2]=="AC" else 0)

for i in range(q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])


Measured memory_bytes: 7748