akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

#define PT pair<ll,ll>

unordered_map<ll, ll> MP;
//map<ll, ll> MP;
priority_queue<PT> PQ;

inline void keisan(ll n, ll k) {
	if (k > MP[n]) {
		MP[n] = k;
		PQ.push(mp(k, n));
	}
}

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


	int T;
	cin >> T;

	rep(t, T) {
		ll N, A, B, C, D;
		cin >> N >> A >> B >> C >> D;

		MP.clear();
		PQ = priority_queue<PT>();
		MP[N] = 1e18;
		PQ.push(mp(ll(1e18), N));
		ll owa = 0;
		ll are = ll(1e13) / D;

		while (PQ.size()) {
			auto p = PQ.top();
			PQ.pop();

			ll n = p.second;
			ll k = p.first;
			if (k <= owa) break;

			if (MP[n] != k) continue;
			if (n == 1) break;

			if (n <= are) {
				ll tmp = k - (n - 1) * D;
				if (tmp > owa) {
					owa = tmp;
				}
			}

			ll k2 = k - A;
			keisan(n / 2, k2 - D * (n % 2));
			if (n % 2) {
				keisan(n / 2 + 1, k2 - D * (n % 2));
			}

			k2 = k - B;
			int r = n % 3;
			keisan(n / 3, k2 - D * r);
			if (r) {
				keisan(n / 3 + 1, k2 - D * (3 - r));
			}

			k2 = k - C;
			r = n % 5;
			keisan(n / 5, k2 - D * r);
			if (r) {
				keisan(n / 5 + 1, k2 - D * (5 - r));
			}

		}
		co(ll(1e18) - max(MP[1], owa) + D);
	}

	Would you please return 0;
}

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

using namespace std;

int main(int argc, char* argv[]) {
  int n, a, b;
  cin >> n >> a >> b;

  string s;
  cin >> s;

  int passed = 0;
  int oversea_passed = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'a') {
      if (passed < a + b) {
        cout << "Yes" << endl;
        ++passed;
      } else {
        cout << "No" << endl;
      }
    } else if (s[i] == 'b') {
      if (passed < a + b && oversea_passed < b) {
        cout << "Yes" << endl;
        ++passed;
        ++oversea_passed;
      } else {
        cout << "No" << endl;
      }
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

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

c = {}

for i in a:
    c[i] = c.get(i, 0) + 1

ways = 0
for i in c:
    ways += c[i]*(c[i]-1)//2

for k in a:
    ans = ways-c[k]+1
    print(ans)


Measured memory_bytes: 26268
<?php
fscanf(STDIN, "%s", $a);
fscanf(STDIN, "%s", $b);


$count = 0;

if ($a[0] == $b[0])
  $count++;
if ($a[1] == $b[1]) 
  $count++;
if ($a[2] == $b[2])
  $count++;

echo $count;

Measured memory_bytes: 3700
while True:
    m = int(input())
    if m == 0: break
    star = list({tuple(map(int, input().split())) for i in range(m)})
    sx, sy = star[0]
    
    n = int(input())
    starset = {tuple(map(int, input().split())) for i in range(n)}
    for x, y in starset:
        flag = True
        for j in range(len(star)-1):
            dx = x + star[j+1][0] - sx
            dy = y + star[j+1][1] - sy
            if (dx, dy) not in starset:
                flag = False
                break

        if flag == True:
            print(x - sx, y - sy)
            break
    

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

int main() {
  int N, M;
  scanf("%d%d", &N, &M);

  vector<int> X(M, 0);
  for (int i = 0; i < M; i++) {
    scanf("%d", &X.at(i));
  }
  sort(X.begin(), X.end());

  vector<int> distance(M - 1, 0);
  for (int i = 0; i < M - 1; i++) {
    distance.at(i) = X.at(i + 1) - X.at(i);
  }
  sort(distance.begin(), distance.end(), greater<int>());
    
  long long ans = 0;
  for (int i = N - 1; i < M - 1; i++) {
    ans += (long long)distance.at(i);
  }

  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int S[13]={},H[13]={},C[13]={},D[13]={};
    int s[13]={},h[13]={},c[13]={},d[13]={};
    int i;
    int n,m;
    char a,b;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        
            scanf("%c",&a);
        
        scanf("%c %d",&b,&m);
        if(b=='S'){
            S[m-1]=m;
        }
        else if(b=='H'){
            H[m-1]=m;
        }
        else if(b=='C'){
            C[m-1]=m;
        }
        else if(b=='D'){
            D[m-1]=m;
        }
    }
    
    int j=0,k=0,l=0;
    m=0;
    for(i=0;i<13;i++){
        if(S[i]!=i+1){
            s[j]=i+1;
            j++;
        }
         if(H[i]!=i+1){
            h[k]=i+1;
            k++;
        }
         if(C[i]!=i+1){
            c[l]=i+1;
            l++;
        }
         if(D[i]!=i+1){
            d[m]=i+1;
            m++;
        }
    }
    
    for(i=0;i<j;i++){
        printf("S %d\n",s[i]);
    }
    for(i=0;i<k;i++){
        printf("H %d\n",h[i]);
    }
    for(i=0;i<l;i++){
        printf("C %d\n",c[i]);
    }
    for(i=0;i<m;i++){
        printf("D %d\n",d[i]);
    }
    
    return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int mod = 1e9+7;
const int mo = 1e9+7;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
int size[5050];
struct node{
	int to,next;
}e[100010];
ll base[5050],f[5050][5050],g[5050],h[5050],tot,n;
inline void add_edge(int from,int to){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;}
inline void Pre(int now,int ffa){
	size[now]=1;for(register int i=h[now];i;i=e[i].next){int to=e[i].to;if(to==ffa) continue;Pre(to,now);size[now]+=size[to];}
}
void DFS(int x,int ffa){
	for(int p=h[x];p;p=e[p].next)
	if (e[p].to!=ffa){
		int y=e[p].to;
		DFS(y,x);
	}
	f[x][1]=1;
	int pre=1;
	for(int p=h[x];p;p=e[p].next)
	if (e[p].to!=ffa){
		int y=e[p].to;
		for(int i=1;i<=pre;++i){
			g[i]=f[x][i];
			f[x][i]=0;
		}
		for(int i=1;i<=pre;++i)
			for(int j=1;j<=size[y];++j){
				f[x][i+j]=(f[x][i+j]+g[i]*f[y][j])%mo;
				if (j%2==0)f[x][i]=(f[x][i]+mo-g[i]*f[y][j]%mo*base[j/2]%mo)%mo;
			}
		pre+=size[y];
	}
}
 
//inline void DFS(int now,int ffa)
//{
//	for(register int i=h[now];i;i=e[i].next)
//	{
//		int to=e[i].to;if(to==ffa) continue;
//		DFS(to,now);
//	}
//	f[now][1]=1;int las=1;
//	for(register int i=h[now];i;i=e[i].next){
//		int to=e[i].to;if(to==ffa) continue;
//		for(register int j=1;j<=las;++j) g[j]=f[now][j],f[now][j]=0;
//		for(register int j=1;j<=las;++j){
//			for(register int k=1;k<=size[to];++k){
//				f[now][k+j]=(f[now][j+k]+1ll*g[j]*f[to][k]%mod)%mod;
//				if(k%2==0){
//					f[now][j]=(f[now][j]+mod-(1ll*g[j]*f[to][k]*base[k/2]%mod))%mod;
//				}
//			}
//		}las+=size[to];
//	}
//}
int main()
{
	n=read();
	for(register int i=1,u,v;i<n;++i) u=read(),v=read(),add_edge(u,v),add_edge(v,u);
	base[0]=1;for(register ll i=1;i<=n;++i) base[i]=1ll*base[i-1]*(2*i-1)%mod;
	Pre(1,0);
	DFS(1,0);ll ans=0;
	for(register int i=1;i<=n;++i) if(i%2==0) ans=(ans+f[1][i]*base[i/2]%mod)%mod;
	cout<<ans%mod;
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  string s;
  cin >> s;
  ll cnt = 0;
  ll res = 0;
  if(s[0] == 'g')cnt++;
  else cnt++,res--;
  for(ll i = 1;i < s.size();i++){
    if(s[i] == 'g'){
      if(cnt >= 1)cnt--,res++;
      else cnt++;
    }else{
      if(cnt >= 1)cnt--;
      else cnt++,res--;
    }
  }
  cout << res << endl;



  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
const int INF =0x7f7f7f7f;
const int MAXN=1e5+5;
int n,m,cnt;
int  f[MAXN];
int find(int x)
{
	if(x==f[x])
		return x;
	else
		return f[x]=find(f[x]);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		f[i]=i;
	while(m--)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		int fx=find(x);
		int fy=find(y);
		if(fx!=fy)
		{
			f[fx]=fy;
			cnt++;
		}
	}
	printf("%d\n",n-cnt);
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	while (s.length()>=4) {
		if (s == "dream" || s == "dreamer" || s == "erase" || s == "eraser")s = "";
		else if (s.substr(s.length() - 5) == "dream") s = s.substr(0, s.length() - 5);
		else if (s.substr(s.length() - 7) == "dreamer") s = s.substr(0, s.length() - 7);
		else if (s.substr(s.length() - 5) == "erase") s = s.substr(0, s.length() - 5);
		else if (s.substr(s.length() - 6) == "eraser") s = s.substr(0, s.length() - 6);
		else break;
	}
	if (s == "")cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] cr = sc.nextLine().split(" ");
        int c = Integer.parseInt(cr[0]); int r = Integer.parseInt(cr[1]);
        int[][] l = new int[c+1][r+1]; 
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < c;i++ ){
            String str = sc.nextLine();
            String[] tmp = str.split(" ");
            for(int j = 0; j < r;j++ ){
                int n = Integer.parseInt(tmp[j]);
                l[c][j]+=n; l[i][r]+=n; l[c][r]+=n;
            }
            sb.append(str+" "+l[i][r]+"\n");
        }
        for(int j = 0; j <= r;j++ ){
            if(j!=0) sb.append(" ");
            sb.append(l[c][j]);
        }
        System.out.println(sb);
    }
}


Measured memory_bytes: 30284
n,k=gets.split.map &:to_i
a=$<.map{|e|e.split.map &:to_i}.sort_by{|e|-e[1]}
c=Hash.new s=r=0
l=[]
i=k-1
a.each{|m,v|
	if l.size>=k
	next if c.has_key?(m)
	i=i.downto(0).find{|j|c[l[j][0]]>1}
	break if !i
	s-=l[i][1]
	c[l[i][0]]-=1
	l.delete_at(i)
	end
	s+=v
	c[m]+=1
	l<< [m,v]
	r=[r,s+c.size**2].max
}
p r

Measured memory_bytes: 20776
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, m; cin >> n >> m;
	double s = 0;
	vector<int> a(n);
	rep(i, n)
	{
		cin >> a[i];
		s += a[i];
	}
	s /= 4.0 * m;
	int res = 0;
	rep(i, n)
	{
		if (a[i] >= s)++res;
	}
	if (res >= m)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
(n,m) = map(int, input().split())
abss = []
for i in range(n):
    (a,b) = map(int, input().split())
    abss.append((a,b))

abss.sort()
sum = 0
for (a,b) in abss:
    if m > b:
        sum = sum + a*b
        m = m-b
    else:
        sum = sum + a*m
        break

print(sum)


Measured memory_bytes: 16892
// author - shreyanshjn (Shreyansh Jain)
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <ll, ll> PLL;
typedef pair <int,string> PIS;
typedef vector <int> vec;
typedef priority_queue<int> PQ;
/* #define input 1 */
#define INF 100000000000000000
#define endl '\n'
#define debug(x) cout<<#x<<": "<<x<<endl
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define sz(x) (int)(x).size()
#define len(x) (int)x.length()
#define rep(a,b,c) for(int a=b; a<c; a++)
#define fori(z,n)  for(int i=z;i<n;i++)
#define fork(z,n)  for(int k=z;k<n;k++)
#define forii(z,n) for(int i=z;i<=n;i++)
#define forkk(z,n) for(int k=z;k<=n;k++)
const int mod = 1e9 + 7;
int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
string trim(const string& str) {
    size_t first = str.find_first_not_of(' ');
    if (string::npos == first)
    {
        return str;
    }
    int last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}
int main() { 
    #ifdef input
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(15);
    string a, b; cin >> a >> b;
    int n = a.length();
    int m = b.length();
    int dp[n + 1][m + 1];
    fori(0, n + 1) dp[i][0] = 0;
    fori(0, m + 1) dp[0][i] = 0;
    fori(1, n + 1) {
        fork(1, m + 1) {
            if(a[i - 1] == b[k - 1])
                dp[i][k] = dp[i - 1][k - 1] + 1;
            else 
                dp[i][k] = max(dp[i - 1][k], dp[i][k - 1]);
        }
    }
    int i = n, k = m;
    string str = "";
    while(i >= 1 and k >= 1) {
        if(a[i - 1] == b[k - 1]) {
            str += a[i - 1];
            i--; k--;
        }
        else if(dp[i][k] == dp[i - 1][k]) {
            i--;
        }
        else {
            k--;
        }
    }
    reverse(str.begin(), str.end());
    cout << str << endl;
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}

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

const int INF=1<<30;

int main(){
  int N; cin >> N;
  string S; cin >> S;
  vector<int> vw(N);
  vector<int> ve(N);
  int sumw=0;
  int sume=0;
  for (int i=0;i<N-1;i++){
    if(S[i]=='W'){
      sumw++;
    }
    vw.at(i+1)=sumw;
  }
  for (int i=N-1;i>0;i--){
    if(S[i]=='E'){
      sume++;
    }
    ve.at(i-1)=sume;
  }
  int ans=INF;
  for (int i=0;i<N;i++){
    if(vw.at(i)+ve.at(i)<ans)
      ans=vw.at(i)+ve.at(i);
  }
  cout << ans << endl;
}

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

int A[1000];
vector<double> den(1000);

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

  vector<double> v(N);
  for (int i=0; i<N; i++) {
    cin >> v[i];
  }

  while(v.size() != 1) {
    std::sort(v.begin(), v.end(),std::greater<double>());
    v[v.size() - 2] = (v[v.size() - 2] + v[v.size() - 1])/2.0;
    v.pop_back();
  }

  cout.precision(numeric_limits<double>::max_digits10);
  cout << v[0] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

int main(){
  int N,x,y,ans=0;cin>>N;
  vector<int> A(N);
  vector<vector<int> > X(N,vector<int>(N-1)),Y(N,vector<int>(N-1));
  REP(i,0,N){
    cin>>A[i];
    REP(j,0,A[i]){
      cin>>x>>y;x--;X[i][j]=x;Y[i][j]=y;
    }
  }

  bool flg;
  int cnt,t_tmp;

  for (int bit = 0; bit < (1<<N); ++bit) {
    cnt=0;flg=true;
    for (int i = 0; i < N; ++i) {
      if(bit & (1<<i)) {
        cnt++;
        REP(j,0,A[i]){
          if(Y[i][j]!=((bit & (1<<X[i][j]))?1:0)){
            flg=false;
            break;
          }
        }
      }
      if(!flg)break;
    }
    if(flg)ans=max(ans,cnt);
  }
  print(ans)
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
// #include <vector>
// #include <algorithm> // to use min_element

using namespace std;

int sumdigits(int N){
	int i=0, m=0;
	while (N>0){
		m += N%10;
		N/=10;
	}

	return m;
}


int main(){
	int n, a, b;
	cin >>n >>a >> b;
	int i, j, count=0;
	for (i=1;i<=n;i++){
		j = sumdigits(i);
		if (j>=a && j<= b) count+=i;
	}
	cout << count;
return 0;
}

Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
N = ri()
S = list(Counter(rs_()))
print('Three' if len(S) == 3 else 'Four')

Measured memory_bytes: 63084
#pragma GCC target("avx")

#include <stdio.h>
int main(){
int i,n,s,M,m,S;
for(;scanf("%d",&n),n;printf("%d\n",(S-M-m)/(n-2)))for(i=S=M=0,m=1000;i<n;i++)scanf("%d",&s),M=M>s?M:s,m=m<s?m:s,S+=s;return 0;}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    string S; cin >> S;
    vector<string> V = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    int ans = 0;
    for (int i = 0; i < V.size(); i++) {
        if (V[i] == S) ans = 7 - i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in,java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*????????§Input*/
    int n;
    n = sc.nextInt();
    sc.close();

/*answer*/
    System.out.println(n * n * n);
  }
  
  public static void main(String[] args){
    (new Main()).run(System.in,System.out);
  }
}

Measured memory_bytes: 17156
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

const static float BTC = 380000.0;
int n;
float X[10], ans;
char S[10];
string U[10];

int main() {
    scanf("%d", &n);
    ans = 0.0;

    for ( int i = 0; i < n; i++ ) {
        scanf("%f %s", &X[i], S);
        U[i] = S;

        if ( U[i] == "JPY" ) {
            ans += X[i];
        } else {
            ans += BTC * X[i];
        }
    }

    printf("%f\n", ans);
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int n, k;
  readf("%s %s\n", &n, &k);
  readln.chomp.split.to!(int[]).count!(a => a >= k).writeln;
}


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

answer =0

if A==0:
    answer = 0
elif B==0:
    answer = N
else:
    tail=0
    if N%(A+B) > A:
        tail = A
    else:
        tail = N%(A+B)
    answer = A * (N//(A+B)) + tail

print(answer)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include<queue>

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n; ++i)
#define ALL(a) (a).begin(),(a).end()
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

bool compare_pair(pair<ll, ll> a, pair<ll, ll> b){
    if(a.first == b.first)return a.second > b.second;
    else return a.first < b.first;
}
int main(){
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> work(100010);
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        work[a].push_back(b);
    }

    ll ans = 0;
    priority_queue<ll, vector<ll>>  que;
    for(int i  = 1; i <= m; ++i){
        rep(j, work[i].size())que.push(work[i][j]);
        if(que.empty())continue;
        // cout << que.top() << endl;
        ans += que.top();
        que.pop();
    }
    cout << ans <<  endl; 
}

Measured memory_bytes: 5632
#include<stdio.h>
int main(){
	int n,b,f,r,v;
	scanf("%d",&n);
	int s[4][3][10]={};
	for(int a=0;a<n;a++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		s[b-1][f-1][r-1]=s[b-1][f-1][r-1]+v;
	}
	for(int c=0;c<4;c++){
		for(int d=0;d<3;d++){
			for(int e=0;e<10;e++){
				printf(" %d",s[c][d][e]);
			}
			printf("\n");
		}
		if(c==3)break;
		printf("####################\n");
	}
	
	return 0;
}

Measured memory_bytes: 2724
#include <stdio.h>
#include <string.h>
int main(void){
        char s[101],p[101];
        int len;
        int i,j;
        char c;

        scanf("%s\n%s",s,p);
        len = strlen(s);

        for(i=0;i<=len;i++){
                c = s[0];
                for(j=1;j<len;j++)
                        s[j-1] = s[j];
                s[len-1] = c;

                if(strstr(s,p)!=NULL){
                        puts("Yes");
                        return 0;
                }
        }
        puts("No");
        return 0;

}


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

int destance(int a[], int b[]) {
  return abs(a[0]-b[0]) + abs(a[1]-b[1]);
}

int closest(int a[], int b[][2], int m) {
  int des = numeric_limits<int>::max();
  int answer = 0;
  REP(i,m) {
    int n_des = destance(a, b[i]);
    if(des > n_des) {
      des = n_des;
      answer = i;
    }
  }
  return answer;
}

int main(void) {
  int N, M;
	cin >> N >> M;
  int a[N][2];
  int c[M][2];
  REP(i,N) { cin >> a[i][0] >> a[i][1]; }
  REP(i,M) { cin >> c[i][0] >> c[i][1]; }

  REP(i,N) { 
    int answer = closest(a[i], c, M);
    cout << answer + 1 << '\n';
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
string s;
using MIte = multimap<int, int>::iterator;

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

	int Max = max({ A + B,A - B,A * B });

	
	cout << Max << endl;

	return 0;
}

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

int main()
{
    int i,j,n,mini = 200,maxi = -200,ans = 1000000,sum = 0;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) {
       cin>>a[i];
        if(mini>a[i])
            mini = a[i];
        if(maxi<a[i])
            maxi = a[i];
    }

    for(i=mini;i<=maxi; i++)
    {
        sum = 0;
        for(j=0;j<n;j++){
            sum += (i-a[j])*(i-a[j]);
        }
        if(ans>sum)
            ans = sum;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3620
s = input()
t = input()

dp = [[0 for _ in range(len(t) + 1)] for _ in range(len(s) + 1)]

for i in range(1, len(s) + 1):
    for j in range(1, len(t) + 1):
        if (s[i-1] == t[j-1]) :
            dp[i][j] = dp[i-1][j-1] + 1
        else :
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

kotae = []

while(i > 0 and j > 0):
    if(dp[i][j] == dp[i-1][j]):
        i -= 1
    elif(dp[i][j] == dp[i][j-1]):
        j -= 1
    else:
        i -= 1
        j -= 1
        kotae.append(s[i])

kotae.reverse()
kotae = "".join(kotae)
print(kotae)

Measured memory_bytes: 119900
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
using namespace std;
int n,k;
int a[100005],dp[100005];
ll sol(int i)
{
    ll res=1e10;
    //cout<<i<<endl;
    if(dp[i]!=-1)return dp[i];
    if(i>=n-1)return 0;
    for(int j=1;j<=k;j++)
    {
        if(i+j<=n-1)
            res=min(res,sol(i+j)+abs(a[i]-a[i+j]));
    }
        return dp[i]=res;
}
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    memset(dp,-1,sizeof dp);
    cout<<sol(0);
}


Measured memory_bytes: 5760
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include <iomanip>
#include <queue>

#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

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; }
typedef long long ll;
typedef long double ld;
typedef std::pair <ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<P> vp;
    queue<P> vr;



    ll m = 0;
    ll p = 0;
    reps(i, n-1){
        p += n - (i + 1);
    }

    for(ll i = 2; i<=n; i++){
        m++;
        vp.push_back(make_pair(1, i));
    }

    for(ll i=2; i<n; i++){
        for(ll j = i+1; j<=n; j++){
            vr.push(make_pair(i, j));
        }
    }

    if(k > p){
        cout << "-1";
        return 0;
    }else{
        ll df = p - k;
        rep(i, df){
            m++;
            vp.push_back(vr.front());
            vr.pop();
        }
    }

    cout << m << endl;
    rep(i, vp.size()){
        cout << vp[i].first << " " << vp[i].second << endl;
    }
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {

	int n,x;
	cin >> n;
	vector<double> v;
	for (int i = 0;i < n;i++)
	{
		cin >> x; 
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	for (int i = 1;i < n;i++) {
		v[0] = (v[0] + v[1]) / 2;
		v.erase(v.begin() + 1);
		sort(v.begin(), v.end());
	}
	cout << v[0];
	return 0;
}

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

int main() {
  long L,R; cin >> L >> R;
  int modL = L % 2019;
  int modR = R % 2019;
  long ans;
  if (R - L >= 2019) {
    ans = 0;
  } else { 
    ans = 2019;
    for (long i =L; i<=R; i++) {
      for (long j =i+1; j<=R; j++) {
        long modIJ = i * j % 2019;
        ans = min(modIJ,ans);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3556
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc082/tasks/abc082_b

int main() {
    string s, t; cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if (s<t) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }


    return 0;
}


Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>

using namespace std;

long long N, M, H, W,re;
long long A[200001];
long long so[200000];
string S[100];
bool OK = true;
bool f;
vector <long long>vl;

int main() {
	cin >>N;
	H = 0;
	W = 0;

	so[0] = 2;
	H++;
	A[0] = 2;
	W++;
	for (int i = 3; i <= 55555; i++) {
		f = true;
		for (int j = 0; j < H; j++) {
			if (i%so[j] == 0) {
				f = false;
				break;
			}
		}

		if (f==true) {
			so[H] = i;
			H++;
			if (i % 5 == 2) {
				A[W] = i;
				W++;
				if (W >= N) {
					break;
				}
			}
		}

	}

	for (int i = 0; i < N; i++) {
		cout << A[i] << endl;
	}

	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<long long>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define couta(x) for(auto iter : x) p(iter)
#define yes(x) x ? cout << "Yes" << endl : cout << "No" << endl;
using namespace std;
typedef long long lint;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<vector<int> > VVI;
typedef vector<vector<long long> > VVLL;
typedef vector<vector<bool> > VVB;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
using UnweightedGraph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
const long long INF = 2000000000ll;
const long double PI = acosl(-1);
const long double EPS = 1e-7;
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; }

long long power(long long a, long long b) {return b?power(a*a,b/2)*(b%2?a:1):1;}
long long perm(long long N, long long K){
    long long x=1;
    for(long long i=1;i<=K;i++)
    {
        x=x*(N-i+1);
    }
    return x;
}
long long factorial(long long N) {return perm(N,N);}
long long comb(long long N,long long K) {return factorial(N)/factorial(K)/factorial(N-K);}
long long hcomb(long long N, long long K) {return comb(N+K-1, N-1);}

int dtoi(double d) {return round(d);}

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

long long mystoll(string s){
    long long ans = 0;
    for (int i = (int) s.length()-1; i >= 0; i--){
        ans += (s[i]-'0') * power(10,s.length()-1-i);
    }
    return ans;
}

template<class T>
long long SUM(T a) {
    long long sum = 0;
    for(auto itr : a) sum += itr;
    return sum;
}

void solve(int64_t R) {
    p((LD)R*PI*2);
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int64_t R;
    cin >> R;
    solve(R);
    return 0;
}


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

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

  if(ceil(n/1.08) < ceil((n+1) / 1.08)){
    cout << ceil(n/1.08) << endl;
    return 0;
  }

  cout << ":(" << endl;

  return 0;
}

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

int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int x, y;
	cin >> x >> y;
	if (500 * x >= y) cout <<  "Yes" ;
	else cout << "No";
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    l = [[] for i in range(N)]
    for i in range(M):
        l[A[i] - 1].append(B[i])
        l[B[i] - 1].append(A[i])
    nl = [list(set(x)) for x in l]
    cnt = 0
    for i, v in enumerate(nl):
        h = [H[j - 1] for j in v]
        if not h or H[i] > max(h):
            cnt += 1
    print(cnt)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, H, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 40140
x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

la = []

for i in range(x):
    s = x-i
    for n in range(max(y-5-3000//s,0),y):
        u = y-n
        for m in range(max(z-5-3000//(s*u),0),z):
            #print(s,u,m)
            la.append(a[i]+b[n]+c[m])

la = sorted(la)

for i in range(k):
    print(la[-i-1])


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

template< typename T >
T mod_pow(T x, T n, const T &p) {
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x) %= p;
        (x *= x) %= p;
        n >>= 1;
    }
    return ret;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<bitset<10>> light(M);
    vector<int> p(M);
    for (int i = 0; i < M; ++i) {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int s;
            cin >> s;
            light[i][s-1] = true;
        }
    }
    for (int i = 0; i < M; ++i) {
        cin >> p[i];
    }
    int cnt = 0;
    const int limit = mod_pow(2, N, 100000);
    for (int i = 0; i < limit; ++i) {
        bitset<10> bit = bitset<10>(i);
        bool ok = true;
        for (int j = 0; j < M; ++j) {
            if ((light[j] & bit).count() % 2 != p[j]) {
                ok = false;
                break;
            }
        }
        if (ok) cnt++;
    }

    cout << cnt << endl;
}


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

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    string ans = "NG";
    for (int i = A; i <= B; i++) if (i % K ==0) ans = "OK";
    cout << ans << endl;

    return 0;
}

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

const int MOD = 1e9 +7;

int main(void){
    int n, m;
    cin>>n>>m;
    char arr[n+1][m+1];

    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            arr[i][j]='.';
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
            cin>>arr[i+1][j+1];
    }
    int dp[n+1][m+1];
    memset(dp, 0, sizeof dp);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(i==1 && j==1) dp[i][j]=1;
            else{
                if(arr[i-1][j]=='.') dp[i][j]+=dp[i-1][j];
                if(arr[i][j-1]=='.') dp[i][j]+=dp[i][j-1];
            }
            dp[i][j]=dp[i][j]%MOD;
        }
    }
    cout<<dp[n][m]<<endl;

    return 0;
}


Measured memory_bytes: 5120
import java.util.*;

class Main {
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if(a == b){
  System.out.println(c);
}else if(a == c){
  System.out.println(b);
}else{
  System.out.println(a);
}

}
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const ll INF = 1e18L;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	scanf("%d", &n);
	vll ps(n+1);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &ps[i]);
		ps[i] += ps[i-1];
	}

	ll best = INF;
	for (int i = 2; i <= n-2; i++) {
		ll a = ps[i], b = ps[n] - ps[i];
		ll mina, maxa, mina1 = 0, maxa1 = INF, mina2 = 0, maxa2 = INF;
		int j = lower_bound(all(ps), a/2) - ps.begin();
		if (j > 1) {
			mina1 = min(ps[j-1], ps[i] - ps[j-1]);
			maxa1 = max(ps[j-1], ps[i] - ps[j-1]);
		}
		if (j < i) {
			mina2 = min(ps[j], ps[i] - ps[j]);
			maxa2 = max(ps[j], ps[i] - ps[j]);
		}
		if (maxa1 - mina1 < maxa2 - mina2) {
			mina = mina1;
			maxa = maxa1;
		}
		else {
			mina = mina2;
			maxa = maxa2;
		}

		ll minb, maxb, minb1 = 0, maxb1 = INF, minb2 = 0, maxb2 = INF;
		j = lower_bound(all(ps), ps[i] + b/2) - ps.begin();
		if (j > i + 1) {
			minb1 = min(ps[j-1] - ps[i], ps[n] - ps[j-1]);
			maxb1 = max(ps[j-1] - ps[i], ps[n] - ps[j-1]);
		}
		if (j < n) {
			minb2 = min(ps[j] - ps[i], ps[n] - ps[j]);
			maxb2 = max(ps[j] - ps[i], ps[n] - ps[j]);
		}
		if (maxb1 - minb1 < maxb2 - minb2) {
			maxb = maxb1;
			minb = minb1;
		}
		else {
			minb = minb2;
			maxb = maxb2;
		}

		best = min(best, max(maxa, maxb) - min(mina, minb));
	}
	printf("%lld\n", best);
}


Measured memory_bytes: 1792
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

lin = []
for i in range(n):
    lin.append(li[i][1:])

flat = [flatten for inner in lin for flatten in inner]

flat.sort()
point = 0
for i in range(1,m+1):
    if flat.count(i) == n:
        point += 1
print(point)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  
  int N1 = N % 100 % 10;
  int N10 = (N % 100 - N1) / 10;
  int N100 = (N - N10 - N1) / 100;
  
  if(N1 ==7 || N10 == 7 || N100 == 7){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n<1200)
        cout<<"ABC"<<endl;
    else if(n<2800)
        cout<<"ARC"<<endl;
    else
        cout<<"AGC"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int getParent(int *p, int idx)
{
  if(p[idx] == idx)
  { return idx; }
  else 
  { return p[idx] = getParent(p, p[idx]); }
  return -1;
}

int main()
{

  int n, nq;
  cin >> n;
  cin >> nq;

  int *a = new int[n];
  int *p = new int[n];

  for(int i = 0; i < n; ++i)
  { p[i] = i; }

  for(int i = 0; i < nq; ++i)
  {
    int q, x, y;
    cin >> q >> x >> y;

    if(q == 0)
    {
      // 処理 //
      y = getParent(p, y); 
      x = getParent(p, x); 
      p[y] = x;
    }
    else 
    {
      // 判定結果を出力
      if(getParent(p, x) == getParent(p, y))
      { cout << "1" << endl; }
      else 
      { cout << "0" << endl; }
    }

  }

  delete [] p;
  delete [] a;

  return 0;
}


Measured memory_bytes: 3164
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int H,W;
  while(~scanf("%d %d",&H,&W)){
    char stage[101][101];
    for(int y = 0; y < H; y++){
      int time = -1;
      bool has_cloud = false;
      char line[128];
      scanf("%s",line);
      for(int x = 0; x < W; x++){
        stage[y][x] = line[x];
        if(stage[y][x] == 'c'){
          time = 0;
          has_cloud = true;
        }

        printf("%d%s",time,(x == W - 1 ? "" : " "));
        if(has_cloud){
          time++;
        }
      }
      printf("\n");
    }
  }
}

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

int main()
{
    int n, cnt = 0, max = 0;
    cin >> n;
    
    string s;
    cin >> s;
    
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == 'I')
        {
            cnt++;
        }
        else if(s[i] == 'D')
        {
            cnt--;
        }
        if(cnt > max)
        {
            max = cnt;
        }
    }
    
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
 
int main(){
 int n;
  cin>>n;
  string s;
  cin>>s;
  if(n%2!=0) {
    cout<<"No"<<endl;
  }
  else{
    for(int i=0;i<n/2;i++){
      if(s[i]!=s[i+n/2]){
        cout<<"No"<<endl;
        break;
      }
      if(i==n/2-1){
        cout<<"Yes"<<endl;
      }
    }
  }
}

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

# dp[i][j] = 魔法iまでからダメージの総和がj以上になるように選んだ時の魔力の最小値
# dp[i][j] = min(dp[i][j - a] + b, dp[i - 1][j])

dp = [[float('inf')] * (H + 1)] * (N + 1)
for i in range(N + 1):
    dp[i][0] = 0
for i in range(1, N + 1):
    a, b = map(int, input().split())
    for j in range(H + 1):
        dp[i][j] = min(dp[i][max(0, j - a)] + b, dp[i - 1][j])
print(dp[N][H])

Measured memory_bytes: 50140
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int64_t n, k;
    cin >> n >> k;

    int cnt = 1;
    while (n >= k) {
        n /= k;
        cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
 
typedef long long tint;

const int INF = 1e6;
const long double PI = acos(-1);
 
int main() {
	int n, m, X, Y; cin >> n >> m >> X >> Y;
	vector<int> x (n), y (m);
	int maxiX = -1;
	forn(i, n){
		cin >> x[i];
		maxiX = max(maxiX, x[i]);
	}
	forn(i, m){
		cin >> y[i];
		
	}
	for(int Z=X+1;Z<=Y;Z++){
		int flag = 0;
		forn(i, m){
			if(y[i] < Z) flag = 1;
		}
		if(flag == 0 && maxiX < Z){
			cout << "No War" << endl;
			return 0;
		}
	}
	cout << "War" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int C[10001];
    for(int i = 0; i < 10001; i++) C[i] = 0;
    int n;
    scanf("%d",&n);
    int* A = new int[n];
    int* B = new int[n];
    for(int i = 0; i < n; i++){
        scanf("%d",&A[i]);
        C[A[i]]++;
    }
 
    for(int i = 0,j=0; i < 10001; i++){
        if(C[i] != 0){
            for(int k = 0; k < C[i]; k++){
                B[j++] = i;
            }
        }
    }
 
    for(int i = 0; i < n-1; i++) printf("%d ",B[i]);
    printf("%d\n",B[n-1]);
    delete[] A;
    delete[] B;
    return 0;
}



Measured memory_bytes: 17944
loop do
  cs = gets.split.map(&:to_i)
  break if cs == [0]
  cs.map! {|c| c >= 10 ? 10 : c }
  s = cs.inject 0, :+
  r = s <= 21 ? s : 0
  cs.count {|c| c == 1 }.times do |i|
    s += 10
    r = s if s <= 21
  end
  p r
end

Measured memory_bytes: 8816
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef int64_t lint;
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using lb = long double;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SI(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define debug(x) cerr << #x << ": " << x << "\n"//手動デバッグ
#define debugV(x) for(int i=0;i<((ll)(x).size());i++)cerr << #x <<"at:"<<i<< ": " << x[i] << "\n"//手動デバッグ 
#define YES(c) cout<<((c)?"YES\n":"NO\n"),0
#define Yes(c) cout<<((c)?"Yes\n":"No\n"),0
#define O(p) cout<<p<<"\n",0
#define OS(p) cout<<p<<" ",0
#define ON(p) cout<<p,0
//定数
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define endl "\n"//endlを置き換える
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定

const int dy[4]={1,0,-1,0};
const int dx[4]={0,1,0,-1};//^>v<

template<class T=int> T in(){
    T x;
    cin>>x;
    return (x);
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
//------------------------------------------------------------




//------------------------------------------------------------
int main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
//------------------------------------------------------------
    int d,t,s;cin>>d>>t>>s;
    if(d<=t*s)O("Yes");
    else O("No");
    
    
    
    
    
    
    
//------------------------------------------------------------
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
ary[1000000];
int isPrime(int n){
	int i;
	if(ary[n]==2){
		return 0;
	}
	else if(ary[n]==1){
		return 1;
	}
	if(n % 2 == 0){
		ary[n]=2;
		return 0;
	}
	for(i = 3; i * i <= n; i += 2)
		if(n % i == 0){
			ary[n]=2;
			return 0;
		}
	ary[n]=1;
	return 1;
}
c,n;int main(){
	ary[0]=2;
	ary[1]=2;
	ary[2]=1;
	for(;scanf("%d",&n)!=EOF;c=0){
		for(;n>0;n--){
			c+=isPrime(n);
		}
		printf("%d\n",c);
	}
	exit(0);
}

Measured memory_bytes: 4308
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int h[110];

int main() {


  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &h[i]);
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += max(h[i] - h[i - 1], 0);
  printf("%d\n", ans);

  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  const int md = 998244353;
  vector<vector<int>> dp(n + 1, vector<int>(s + 1));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      if (j + a[i] <= s) {
        (dp[i + 1][j + a[i]] += dp[i][j]) %= md;
      }
      (dp[i + 1][j] += (dp[i][j] << 1) % md) %= md;
    }
  }
  cout << dp[n][s] << '\n';
  return 0;
}


Measured memory_bytes: 38556