akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char s[100005]={},ans[100005]={};
int check(int n)
{
	int l=n-1, r=1;
	for(int i=0;i<n;i++){
		if( (s[i]=='o'&&ans[i]=='S')||(s[i]=='x'&&ans[i]=='W') ){
			if(ans[l]!=ans[r]) return 0;
		}
		else{
			if(ans[l]==ans[r]) return 0;
		}
		l++; r++;
		if(l==n) l=0;
		if(r==n) r=0;
	}
	return 1;
}
void FS(int n)
{
	for(int k=1;k<=4;k++){ //四种假设情况
		memset(ans,0,sizeof(ans));
		if(k==1) {ans[0]='S'; ans[1]='S';} //羊羊
		if(k==2) {ans[0]='S'; ans[1]='W';} //羊狼
		if(k==3) {ans[0]='W'; ans[1]='S';} //狼羊
		if(k==4) {ans[0]='W'; ans[1]='W';} //狼狼
		for(int i=1;i<n-1;i++){
			if(s[i]=='o'){
				if(ans[i]=='S') ans[i+1]=ans[i-1]; //羊o则两边为同种动物
				else{ //狼o则两边为不同动物
					if(ans[i-1]=='S') ans[i+1]='W';
					else ans[i+1]='S';
				}
			}
			else{
				if(ans[i]=='S'){ //羊X则两边为不同动物
					if(ans[i-1]=='S') ans[i+1]='W';
					else ans[i+1]='S';
				}
				else ans[i+1]=ans[i-1]; //狼X则两边为同种动物
			}
		}
		if(check(n)==1){
			printf("%s\n",ans);
			return;
		}
	}
	printf("-1\n");
}
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",s);
	FS(n);
	return 0;
}

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

int main(){
  int r, c, table[101][101];
  cin >> r >> c;

  /* 追加分の初期化 */
  for(int i=0; i<r; i++)
    table[i][c] = 0;
  for(int i=0; i<c+1; i++)
    table[r][i] = 0;

  /* Input */
  for(int i=0; i<r; i++){
    for(int j=0; j<c; j++){
      cin >> table[i][j];
      table[i][c] += table[i][j];
      table[r][j] += table[i][j];
      table[r][c] += table[i][j];
    }
  }

  /* Output */
  for(int i=0; i<r+1; i++){
    for(int j=0; j<c+1; j++){
      if(j > 0) cout << " ";
      cout << table[i][j];
    }
    cout << endl;
  }
  return 0;
}


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

using namespace std;

int main()
{

    string s;
    cin>>s;
    int count;
    if(s=="SSS")
        count=0;
    else if(s=="SSR" || s=="SRS"||s=="RSS"||s=="RSR")
        count=1;
    else if(s=="SRR"||s=="RRS")
        count=2;
    else
        count=3;
        
    
    cout<<count;

}


Measured memory_bytes: 3512
def keta_sum(n):
    sum = 0
    while n>0:
        sum += n%10
        n = n//10 
    return(sum)
N,A,B = map(int,input().split())
SUM = 0
for i in range(1,N+1):
  ki = keta_sum(i)
  if ki >= A and ki <= B:
    SUM += i
print(SUM)

Measured memory_bytes: 9108
A,B =list(map(int, input().split()))

print(100,100)

x1 = ''.join(['.']*100)
y1 = ''.join(['#']*100)

for i in range(25):
    x = ['.'] * 100
    for j in range(50):
        if B>1:
            x[2*j] = '#'
            B -= 1
    print(''.join(x))
    print(x1)

for i in range(25):
    print(y1)
    y = ['#'] * 100
    for j in range(50):
        if A>1:
            y[2*j] = '.'
            A -= 1
    print(''.join(y))




Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;                                                            
#define pb push_back                                                            
#define mp make_pair                                                                                                                                
#define sqr(a) ((a) * (a))                                                      
#define io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   
#define co() cout.precision(10);                                                
#define F for(li i=0;i<n;i++)
#define fo(i,a,n) for(i=a;i<n;i++)
#define ne cout<<"\n"; 
#define nec cout<<"\n";continue; 
#define test int t;cin>>t;while(t--)
#define first ff
#define second ss
//#define oj #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif

typedef long long li;
typedef long double ld;

const li mod = 1e9+7;

int main() 
{
    io();
    li p=1;
    li x,n,i;
    	cin>>n;
    	li a[n],c=0;
    	F {cin>>a[i];
		if(i>0){
		if(a[i]<a[i-1]){
		c+=(a[i-1]-a[i]);a[i]=a[i-1];}
		}
	//	cout<<a[i]<<" ";
		}
		cout<<c;
}

Measured memory_bytes: 5168
#include <stdio.h>

int main(){
    unsigned long long int n,d,d2,x,y,point_num = 0;

    scanf("%llu %llu", &n, &d);
    d2 = d*d;
    for(auto i=0; i<n; ++i){
        scanf("%llu %llu", &x, &y);

        if(x*x + y*y <= d2){
            point_num++;
        }
    }

    printf("%llu", point_num);
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    vector<ll> A;
    A.resize(3);
    cin >> A[0] >> A[1] >> A[2];
    sort(A.begin(), A.end());
    cout << (A.back() % 2) * A[0] * A[1] << endl;
    return 0;
}


Measured memory_bytes: 256
# 入力
n = gets.chomp.to_i
s = gets.chomp

b_count = 0
w_count = s.count(".")

min = b_count + w_count
n.times do |i|
  if s[i] == "#" then
    b_count += 1
  else
    w_count -= 1
  end
  sum = b_count + w_count
  min = sum if sum < min
end

# 出力
puts min



Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        char c;
        cin>>c;
        char d=' ';
        if(c>='a'&&c<='z')
            d='a';
        else
            d='A';
        cout<<d<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

int bsearch(int *a,int key,int n){
  int left,right,mid;
  left=0;
  right=n;
  while(left<right){
    mid=(left+right)/2;
    if(a[mid]==key) return 1;
    else if(key<a[mid]) right=mid;
    else left=mid+1;
  }
  return 0;
}
  
int main(){
  int i,j,r,key,n,q,S[100000],T[50000],c=0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&S[i]);
  
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
    c+=bsearch(S,T[i],n);
  }

  printf("%d\n",c);

  return 0;
}

  



Measured memory_bytes: 2308
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  ll x;cin>>x;
  int h = x / 500;
  int f = (x - h*500) / 5;
  p(h*1000+f*5);
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) ((a) < (b) ? (b) : (a))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007)

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



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

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



int main() {
	string S;
	int i, j, k;
	//ll N, M, K;
	int N, M, K;

	int H[100001];
	cin >> N >> M;
	rep(i, 0, N) {
		cin >> H[i];
	}

	int color[100000] = { 0 };
	rep(i, 0, M) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		if (H[a] < H[b]) {
			color[a] = -1;
		}
		else if (H[a] > H[b]) {
			color[b] = -1;
		}
		else {
			color[a] = -1;
			color[b] = -1;
		}
	}

	int ans = 0;
	rep(i, 0, N) {
		if(color[i]==0)
			ans++;
	}

	cout << ans;
	return 0;

}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> glid(h, vector<char> (w));
  
  rep(i, h) {
    rep(j, w) {
      cin >> glid[i][j];
    }
  }
  
  //行検索
  vector<bool> row(h);
  rep(i, h) {
    bool flg = true;
    char color = glid[i][0];
    rep(j, w) {
      if(glid[i][j] == '.') {
//        cout << "true (" << i+1 << "," << j+2 << ")" << endl;
        continue;
      } else {
//        cout << "false" << endl;
        flg = false;
        break;
      }
    }
    if(flg) {
//        cout << "flgtrue" << endl;
        row[i] = true;
    }
  }
  
  //列検索
  vector<bool> col(w);
  rep(i, w) {
    bool flg = true;
    rep(j, h) {
      if(glid[j][i] == '.') continue;
      else {
        flg = false;
        break;
      }
    }
    if(flg) col[i] = true;
  }
  
  //
  rep(i, h) {
    if(!row[i]) {
      rep(j, w) {
        if(!col[j]) cout << glid[i][j];
      }
      cout << endl;
    }
  }   
  
  return 0;
}


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

using namespace std;

int h, w, s;
int sum[32][32];
int grp[32][32][32][32];
int pow[32][32][32][32];

int getS(int sx, int sy, int gx, int gy){
	int res = sum[gx][gy];
	if(sx>0) res -= sum[sx-1][gy];
	if(sy>0) res -= sum[gx][sy-1];
	if(sx>0&&sy>0) res += sum[sx-1][sy-1];
	return res;
}

pair<int,int> search(int sx, int sy, int gx, int gy){
	if(grp[sx][sy][gx][gy]!=-1) return make_pair(grp[sx][sy][gx][gy], pow[sx][sy][gx][gy]);
	pair<int, int> res = make_pair(1, s-(sum[h-1][w-1]-getS(sx,sy,gx,gy)));
	for(int i=sx;i<gx;i++){
		if(sum[h-1][w-1]-getS(sx, sy, i, gy) > s) continue;
		if(sum[h-1][w-1]-getS(i+1, sy, gx, gy) > s) continue;
		pair<int,int> p1 = search(sx, sy, i, gy);
		pair<int,int> p2 = search(i+1, sy, gx, gy);
		res = max(res, make_pair(p1.first+p2.first, min(p1.second, p2.second)));
	}
	for(int i=sy;i<gy;i++){
		if(sum[h-1][w-1]-getS(sx, sy, gx, i) > s) continue;
		if(sum[h-1][w-1]-getS(sx, i+1, gx, gy) > s) continue;
		pair<int,int> p1 = search(sx, sy, gx, i);
		pair<int,int> p2 = search(sx, i+1, gx, gy);
		res = max(res, make_pair(p1.first+p2.first, min(p1.second, p2.second)));
	}
	grp[sx][sy][gx][gy] = res.first;
	pow[sx][sy][gx][gy] = res.second;
	return res;
}

int main(){
	while(cin >> h >> w >> s, h){
		memset(grp, -1, sizeof(grp));
		memset(pow, -1, sizeof(pow));
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> sum[i][j];
				if(i-1>=0) sum[i][j] += sum[i-1][j];
				if(j-1>=0) sum[i][j] += sum[i][j-1];
				if(i-1>=0&&j-1>=0) sum[i][j] -= sum[i-1][j-1];
			}
		}
		pair<int, int> res = search(0, 0, h-1, w-1);
		cout << res.first << " " << res.second << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<utility>
#include<queue>
#define mod 998244353
#define pb push_back
#define ll long long
using namespace std;
ll fas[2018][2018];
int main(){
	int n,x;
	ll ans=-1;
	vector<ll> a;
	cin>>n>>x;
	a.pb(0);
	for(int i=0;i<n;i++){
		int y;
		cin>>y;
		a.pb(y);
	}
	a[0]=a[n];
	for(int i=0;i<n;i++){
		ll res=0;
		for(int j=1;j<=n;j++){
			if(i==0){
				fas[i][j] = a[j];
			}
			else{
				fas[i][j] = min(fas[i-1][j], a[(j-i+n)%n]);
			}
			res += fas[i][j];
		}
		res += (ll)x*i;
		if(res < ans || ans==-1)ans = res;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 31744
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)

signed main(){
	int h, a;
	cin >> h >> a;
	if(h%a == 0)cout << h/a << endl;
	else cout << h / a + 1 << endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<double,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

void Main(){
    int N,K; cin >> N >> K;
    vector<int> A(N); REP(i,N) cin >> A[i]; SORT(A);

    int l = 0, r = A.back();
    while(r-l>1){
        int x = (l+r)/2;
        ll cnt = 0;
        REP(i,N){
            ll t = (A[i]+x-1)/x;
            cnt += t-1;
        }
        if(cnt<=K) r = x;
        else l = x;
    }
    cout << r << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = 0;
  for(int i=0;i<S.size();i++)  {
    if(S.at(i) != S.at(S.size()-i-1)){
      N++;
    }
  }
  cout << N/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr int INF = 1e9;
int main(){ 
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];

  auto bfs = [&](int sx, int sy) {
    vector<int> d(h*w, INF);
    queue<P> que;
    que.push(make_pair(sx, sy));
    d[sx*w+sy] = 0;
    int mx = 0;
    while (!que.empty()) {
      auto u = que.front(); que.pop();
      rep(i,4) {
        int x = dx[i] + u.first, y = dy[i] + u.second;
        if (x < 0 || y < 0 || x >= h || y >= w) continue;
        if (s[x][y] == '#') continue;
        if (d[x*w+y] != INF) continue;
        d[x*w+y] = d[u.first*w+u.second] + 1;
        mx = max(mx, d[x*w + y]);
        que.push(make_pair(x, y));
      }
    }
    return mx;
  };
  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      res = max(res, bfs(i, j));
    }
  }
  cout << res << 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 n; cin >> n;
	map<int, int> M;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		M[x]++;
	}
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		if (M[x] == 0) {
			cout << "NO" << endl;
			return 0;
		}
		M[x]--;
	}
	cout << "YES" << endl;
	return 0;
}



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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r)
{
    if(l >= r) return ;
    int root = pre[pos++];
    int m = distance(in.begin(), find(in.begin(), in.end(), root));
    rec(l, m);
    rec(m+1, r);
    post.push_back(root);
}

void solve()
{
    pos = 0;
    rec(0, pre.size());
    for(int i=0; i<n; i++)
    {
        if(i) cout << " ";
        cout << post[i];
    }
    cout << endl;
}

int main()
{
    int k;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> k;
        pre.push_back(k);
    }
    for(int i=0; i<n; i++)
    {
        cin >> k;
        in.push_back(k);
    }
    solve();
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

struct UnionFind
{
    vector<long long> d;
    UnionFind(long long n = 0) : d(n, -1)
    {
    }

    //root : -size, not root: root
    long long root(long long x){
        if(d[x] < 0){
            return x; 
        }
        return d[x] = root(d[x]);
    }

    bool unite(long long x, long long y){
        x = root(x);
        y = root(y);
        if(x == y){
            return false;
        }
        if(d[x] > d[y]){
            swap(x, y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    long long size(long long x){
        return -d[root(x)];
    }

    bool issame(long long a, long long b){
        return root(a) == root(b);
    }
};

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, k, l; cin >> n >> k >> l;
    
    UnionFind road(n);
    UnionFind train(n);
    rep(i, k){
        ll p, q; cin >> p >> q; p--; q--;
        if(!road.issame(p, q)){
            road.unite(p, q);
        }
    }
    rep(i, l){
        ll r, s; cin >> r >> s; r--; s--;
        if(!train.issame(r, s)){
            train.unite(r, s);
        }
    }

    map<pair<ll,ll>,ll> mp;
    rep(i, n){
        mp[{road.root(i),train.root(i)}] ++;
    }

    rep(i, n){
        cout << mp[{road.root(i), train.root(i)}] << " ";
    }
    br;
}

Measured memory_bytes: 15104
import collections

N, K = map(int, input().split())
city_list = list(map(int, input().split()))
th_list = []
n = 0
for i in range(N):
    th_list.append(n)
    n = city_list[n] - 1

c = collections.Counter(th_list)
for i in range(N):
    if c[th_list[i]] > 1:
        break
list = [x for x, l in enumerate(th_list) if l == th_list[i]]

if K > N:
    print(th_list[(K - list[0]) % (list[1] - list[0]) + list[0]] + 1)
else:
    print(th_list[K] + 1)

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

/*
cin.tie(0);
ios::sync_with_stdio(false);
*/
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k, i, j;
	cin >> n >> k;
	vector<char> p(n);
	for (i = 0; i < n; i++) {
		string s;
		cin >> s;
		p[i] = s[0];
	}
	sort(p.begin(),p.end());
	vi num(26);
	for (i = 0; i < n; i++) {
		num[p[i] - 'A']++;
	}
	sort(num.begin(), num.end(), greater<int>());
	ll ans = 0;
	while (true) {
		for (i = 0; i < k; i++) {
			if (num[i] == 0) {
				cout << ans << endl;
				return 0;
			}
			num[i]--;
			n--;
		}
		ans++;
		sort(num.begin(), num.end(), greater<int>());
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    rep(i, y2 - y1) {
        cout << "U";
    }
    rep(i, x2 - x1) {
        cout << "R";
    }
    rep(i, y2 - y1) {
        cout << "D";
    }
    rep(i, x2 - x1) {
        cout << "L";
    }
    cout << "L";
    rep(i, y2 - y1 + 1) {
        cout << "U";
    }
    rep(i, x2 - x1 + 1) {
        cout << "R";
    }
    cout << "DR";
    rep(i, y2 - y1 + 1) {
        cout << "D";
    }
    rep(i, x2 - x1 + 1) {
        cout << "L";
    }
    cout << "U" << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

vl A,F;
ll N,K;

ll need(ll t){
    ll res=0;
    rep(i,N){
        res+=max((ll)0,(A[i]-t/F[i]));
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    A.resize(N),F.resize(N);
    rep(i,N){
        cin >> A[i];
    }
  	rep(i,N){
      	cin >> F[i];
    }
    sort(A.begin(),A.end());
    sort(F.begin(),F.end());
    reverse(F.begin(),F.end());
    ll ok=INF,ng=-1;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        if(need(mid)>K){
            ng=mid;
        }
        else{
            ok=mid;
        }
    }
    cout << ok << endl;
}


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

using namespace std;

int main(int qtd, char* nome[])
{
    ios::sync_with_stdio(false);

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int maior;
    maior = max(a, b);
    maior = max(c, maior);

    while(k--){
        if(a >= maior)
            a *= 2;
        else
        if(b >= maior)
            b *= 2;
        else
        if(c >= maior)
            c *= 2;
    }
    cout << a+b+c;

    return 0;
}


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

D=[]
for i in range(n):
    d = l+i
    D.append(d)

if l+1>0 :
    mind = min(D)
elif l+n<=0:
    mind = max(D)
else:
    mind = 0


ans = sum(D)-mind
print(ans)



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

char convert(string& str, int index){
    if(0 <= index-1 && str[index-1] == 'P')
        return 'D';
    if(index+1 < str.size() && str[index+1] != 'P')
        return 'P';
    return 'D';
}

int main(){
    string str;
    cin >> str;
    for(int index = 0; index < str.size() ; ++index){
        if(str[index] == '?'){
            str[index] = convert(str, index);
        }
    }
    cout << str;
    return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int>h(n);
  rep(i,n) cin >> h[i];
  
  int count = 0;
  int ans = 0;
  
  for(int i=0; i<n-1; ++i) {
    if(h[i] >= h[i+1]) count++;
    else count = 0;
    ans = max(ans, count);
  }
  cout << ans << endl;
  

}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}




int main()
{
    string S;

    cin >> S;

    if(S[0]=='7' || S[1]=='7' || S[2]=='7'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

 
    return 0;

}

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

using namespace std;

int main(){ 
 string X; cin >> X; int n = X.size();
  vector<int> cnt(n,0); 
  int res = 0; int ans = 0;
  for(int i  = 0; i < n; i++){
    if( res == 0){ 
      if( X[i] == 'S'){ res++;}}
    else{
      if( X[i] == 'S'){ res++;}
      else{ res--; ans += 2;}
    }
    cnt[i] = res;}
  
  cout << n - ans << endl; return 0;}

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

using namespace std;

void hawawa()
{
  unsigned long long n, k;
  cin >> n >> k;
  unsigned long long ans = 0;
  if (k == 0) {
    cout << n * n << "\n";
    return;
  }
  for (int i = k + 1; i <= n; i++) {
    unsigned long long s = n % i;
    if (k <= s) {
      ans += s - k + 1;
    }
    ans += (i - k) * (n / i);
  }
  cout << ans << "\n";
}

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

Measured memory_bytes: 256
import collections as C
import sys
s = input()
t = input()

if len(set(s)) != len(set(t)):
    print("No")
    sys.exit()

ans = [0] * len(s)
stock = C.Counter([])
for i in range(len(s)):
    if s[i] not in stock.keys():
        stock[s[i]] = t[i]
    ans[i] = stock[s[i]]

ss = "".join(ans)

print("Yes") if ss == t and len(list(stock.keys())) == len(list(stock.values())) else print("No")


Measured memory_bytes: 5680
using System;

class Program
{
    static void Main(string[] args)
    {
        var a = int.Parse(Console.ReadLine());
        var b = int.Parse(Console.ReadLine());
        var c = int.Parse(Console.ReadLine());
        var d = int.Parse(Console.ReadLine());
        Console.WriteLine(Math.Min(a, b) + Math.Min(c, d));
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

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

using namespace std;

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

    ll N, K;
    cin >> N >> K;

    if (2*K-1 <= N) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

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

#define ll long long
#define MAXN 110
#define MAXW 100010

using namespace std;

ll dp[MAXN][MAXW];

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, w;
    cin >> n >> w;

    int weight[n];
    ll value[n];
    for(int i = 0; i < n; i++)
        cin >> weight[i] >> value[i];
    
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= w; j++) {
            dp[i][j] = dp[i - 1][j];

            if(j >= weight[i - 1])
                dp[i][j] = max(dp[i][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]);
        }
    }

    ll ans = 0;
    for(int i = 1; i <= w; i++)
        ans = max(ans, dp[n][i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 81732
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)

struct Tree {
    Tree * ch[2];
    Tree(){
        ch[0] = ch[1] = nullptr;
    }
};

Tree * parse(string::iterator b, string::iterator e){
    if(b==e) return nullptr;
    auto res = new Tree();
    int d = 0;
    for(auto it = b; it != e; ++it){
        if(*it=='('){
            d++;
        } else if(*it==','){
            if(d==1){
                res->ch[0] = parse(b+1,it);
                res->ch[1] = parse(it+1,e-1);
            }
        } else if(*it==')'){
            d--;
        }
    }
    return res;
}

Tree * intersect(Tree * t, Tree * u){
    Tree * res = new Tree();
    rep(i,2){
        if(t->ch[i]!=nullptr && u->ch[i]!=nullptr){
            res->ch[i] = intersect(t->ch[i],u->ch[i]);
        }
    }
    return res;
}

Tree * unite(Tree * t, Tree * u){
    if(t==nullptr && u==nullptr) return nullptr;
    Tree * res = new Tree();
    if(t!=nullptr && u!=nullptr){
        rep(i,2) res->ch[i] = unite(t->ch[i], u->ch[i]);
    } else {
        if(t==nullptr) swap(t,u);
        rep(i,2) res->ch[i] = unite(t->ch[i], nullptr);
    }
    return res;
}

void print(Tree* t){
    cout << "(";
    if(t->ch[0] != nullptr) print(t->ch[0]);
    cout << ",";
    if(t->ch[1] != nullptr) print(t->ch[1]);
    cout << ")";
}

int main(){
    char c;
    while(cin>>c){
        string s,t; cin >> s >> t;
        auto a = parse(all(s)), b = parse(all(t));
        if(c=='i') print(intersect(a,b));
        else print(unite(a,b));
        cout << endl;
    }
}

Measured memory_bytes: 1200
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;

#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define Rep(i, a, b) for (int (i) = (a) - 1; (i) < (b); (i)++)
#define REP(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define Sort(a, len, cmp) sort(a + 1, a + len + 1, cmp)
#define ass(a, sum) memset(a, sum, sizeof(a))

#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define ENDL cout << endl
#define SZ(x) ((int)x.size())

typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> Vi ;
typedef pair <int, int> Pii ;
typedef pair <ll, ll> Pll ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
typedef map <ll, ll> mll ;

const int N = 2010 ;
const double eps = 1e-8 ;
const int iinf = INT_MAX ;
const ll linf = 2e18 ;
const double dinf = 1e30 ;
const int MOD = 1000000007 ;

inline int read(){
    int X = 0, w = 0 ;
	char ch = 0 ;
    while (!isdigit(ch)) { w |= ch == '-' ; ch = getchar() ; }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar() ;
    return w ? - X : X ;
}

void write(int x){
     if (x < 0) putchar('-'), x = - x ;
     if (x > 9) write(x / 10) ;
     putchar(x % 10 + '0') ;
}

void print(int x) {
	cout << x << endl ;
	exit(0) ;
}

void PRINT(string x) {
	cout << x << endl ;
	exit(0) ;
}

void douout(double x){
	 printf("%lf\n", x + 0.0000000001) ;
}

int vis[N], ok[N][N], in[N], a[N] ;
vector <int> g[N] ;
int n ;

void dfs(int rt) {
	vis[rt] = 1 ;
	for (int i = 1; i <= n; i++)
	if (!vis[i] && ok[rt][i]) {
		in[i]++ ;
		g[rt].pb(i) ;
		dfs(i) ;
	}
}

void Top() {
	priority_queue <int> q ;
	for (int i = 1;  i <= n; i++) if (!in[i]) q.push(i) ;
	while (!q.empty()) {
		int now = q.top() ;
		q.pop() ;
		cout << a[now] << " " ;
		for (int i = 0; i < SZ(g[now]); i++) q.push(g[now][i]) ;
	}
}

signed main(){
	scanf("%d", &n) ;
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]) ;
	sort(a + 1, a + n + 1) ;
	clr(ok) ;
	for (int i = 1; i <= n; i++)
	for (int j = i + 1; j <= n; j++)
	if (__gcd(a[i], a[j]) != 1) ok[i][j] = ok[j][i] = 1 ;
	for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i) ;//连通块
	Top() ;
}

/*
写代码时请注意：
	1.是否要开Long Long？数组边界处理好了么？
	2.实数精度有没有处理？
	3.特殊情况处理好了么？
	4.做一些总比不做好。
思考提醒：
	1.最大值和最小值问题可不可以用二分答案？
	2.有没有贪心策略？否则能不能dp？
*/


Measured memory_bytes: 16384
import java.util.Scanner;

public class Main {
    public static void main(String[] argv) {
        Scanner scanner = new Scanner(System.in);

        String line = scanner.nextLine();
        int n = Integer.parseInt(line);

        String ballStr = scanner.nextLine();
        String[] ballStrs = ballStr.split(" ");
        int[] balls = new int[n];
        int i = 0;
        for (String ballS : ballStrs) {
            balls[i++] = Integer.parseInt(ballS);
        }

        long[] map = new long[n + 1];
        for (int ball : balls) {
            map[ball]++;
        }

        long total = 0;

        for (long key : map) {
            if (key > 1) {
                total += key * (key - 1) / 2;
            }
        }

        for (int ball : balls) {
            long count = map[ball];
            System.out.println(total - (count - 1));
        }
    }
}

Measured memory_bytes: 71204
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin >> n;
    vector <ll> arr(n);
    for (int z=0;z<n;z++){
        cin >> arr[z];
    }
    ll ans = 0;
    for (int z=0;z<n;z++){
        while (arr[z] % 2 == 0 && arr[z] > 0){
            arr[z] /= 2;
            ans++;
        }
    }
    cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  if(s.at(0) == 'S'){
    cout << "Cloudy" << endl;
  }
  if(s.at(0) == 'C'){
    cout << "Rainy" << endl;
  }
  if(s.at(0) == 'R'){
    cout << "Sunny" << endl;
  }
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

h, w = MAP()
ans = h * w // 2
if h % 2 == 1 and w % 2 == 1:
    ans += 1
if h == 1 or w == 1:
    ans = 1
print(ans)

Measured memory_bytes: 5780
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

int main()
{
    int n;
    cin >> n;
    
    long sum=0;
    vector<int> a(100001);
    rep(i,n){
      int tmp;
      cin >> tmp;
      a.at(tmp)++;
      sum+=tmp;
    }

    int q;
    cin >> q;
    rep(i,q){
      int b,c;
      cin >> b >> c;

      int cnt = a.at(b);
      sum = sum + cnt*(c-b);
      cout << sum << endl;

      a.at(c) += a.at(b);
      a.at(b) = 0;
    }
}


Measured memory_bytes: 3784
import java.util.*;
import java.io.*;
public class Main
{
    public static long query(long[] arr, int i, int j){
        if(i == 0){
            return arr[j];
        }
        return arr[j] - arr[i-1];
    }
    public static long solve(long[] prefix, int i, int j, long[][] dp){
        if(i >= j){
            return 0;
        }
        if(dp[i][j] != -1){
            return dp[i][j];
        }
        dp[i][j] = Long.MAX_VALUE;
        for(int k = i; k <= j; k++){
            dp[i][j] = Math.min(dp[i][j], solve(prefix, i, k, dp) + solve(prefix, k+1, j, dp) + query(prefix, i, k) + query(prefix, k+1, j));
        }
        return dp[i][j];
    }
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine().trim());
		String[] s = br.readLine().trim().split(" ");
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
		    arr[i] = Integer.parseInt(s[i]);
		}
		long[] prefix = new long[n];
		prefix[0] = arr[0];
		for(int i = 1; i < n; i++){
		    prefix[i] = prefix[i-1] + arr[i];
		}
		long[][] dp = new long[n+1][n+1];
		for(int i = 0; i < dp.length; i++){
		    for(int j = 0; j < dp.length; j++){
		        dp[i][j] = -1;
		    }
		}
		System.out.println(solve(prefix, 0, n-1, dp));
	}
}


Measured memory_bytes: 24608
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

a = [0]*3
b = []
for i in range(3):
    b.append(c[0][i]-a[0])
for i in range(1, 3):
    a[i] = c[i][0]-b[0]

for i in range(3):
    for j in range(3):
        if a[i]+b[j] != c[i][j]:
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int H = stdIn.nextInt();
		int N = stdIn.nextInt();
		int A[] = new int[N];
		int sum = 0;
		for(int i = 0; i < N; i++){
			A[i] = stdIn.nextInt();
			sum = sum + A[i];
		}
		if(H - sum > 0){
			System.out.println("No");
		}
		else{
			System.out.println("Yes");
		}
		stdIn.close();
	}
}

Measured memory_bytes: 59208
#include <cstdio>
#include <cctype>
#include <bitset>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
inline int gc()noexcept { return getchar_unlocked(); }
inline int input()noexcept {
	int v = 0; char c = gc();
	for (; isdigit(c); c = gc()) {
		v *= 10;
		v += c - '0';
    }
	return v;
}
int cnt[100002];
int main() {
  int n = input(), m = input();
  int a1 = 0, a2 = 0;
  rep(i, m) {
    int p = input(); --p;
    char c = gc(); gc(); gc();
    if (cnt[p] != -1) {
      switch(c) {
        case 'A':
          ++a1;
          a2 += cnt[p];
          cnt[p] = -1;
          break;
        case 'W':
          ++cnt[p];
          break;
      }
    }
  }
  printf("%d %d", a1, a2);
}

Measured memory_bytes: 640
def ringos_favorite_numbers(D: int, N: int) -> int:
    if N == 100:
        return (N + 1) * (100 ** D)
    return N * (100 ** D)


if __name__ == "__main__":
    D, N = map(int, input().split())
    ans = ringos_favorite_numbers(D, N)
    print(ans)


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

const int M = 1e3;

int val[M], cost[M], n, memo[10001];

int solve(int h) {
    if (h < 1)
        return 0;
    int &result = memo[h];

    if (result == -1) {
        result = 2e9;
        for (int i = 0; i < n; i++)
            result = min(result, solve(h - val[i]) + cost[i]);
    }
    return result;
}

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

    memset(memo, -1, sizeof memo);
    int h;
    cin >> h >> n;
    for (int i = 0; i < n; i++)
        cin >> val[i] >> cost[i];
    cout << solve(h) << '\n';
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int main(){
    ll k,a,b,cnt=1;
    cin>>k>>a>>b;
    if((b-a)<2){
        cout<<k+1<<endl;
    }else{
        if(a>k)cout<<k+1<<endl;
        else{
            rep(i,k){
                if(cnt<a)cnt++;
                else if(i==k-1){
                    cnt++;
                }
                else{
                    cnt-=a;
                    cnt+=b;
                    i++;
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

//a=97,z=122

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

using namespace std;

int main(){
  int a,b;
  string op;
  vector<int> ans;
  while(1){
    cin >> a >> op >> b;
    if(op == "+"){
      ans.push_back(a+b);
    }else if(op == "-"){
      ans.push_back(a-b);
    }else if(op == "*"){
      ans.push_back(a*b);
    }else if(op == "/"){
      ans.push_back(a/b);
    }else if(op == "?"){
      break;
    }
  }
  for(int i=0;i<ans.size();i++){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3180
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::{fastout, input, marker::*};
use std::collections::*;
//use std::cmp::*;
//use std::num;
//use petgraph::unionfind::UnionFind;

#[fastout()]
fn main() {
    input! {
        N:i64
    }
    if N < 357 {
        println!("0");
        return;
    }
    let mut n = N.clone();
    let mut S = Vec::with_capacity(10);
    while n > 0 {
        S.push(N % 10);
        n = n / 10;
    }
    let l = S.len();
    let mut A = vec![0; l];
    A[0] = 7;
    A[1] = 5;
    A[2] = 3;

    let mut ans = 0;
    let mut m = 3;
    //println!("n={}", N);
    while m <= N {
        //  println!("A={:?},m={}", A, m);
        ans += 1;
        match next(A) {
            Some((B, c)) => {
                A = B;
                m = c
            }
            None => break,
        };
    }
    println!("{}", ans);
}
fn next(X: Vec<i64>) -> Option<(Vec<i64>, i64)> {
    let mut max_flag = true;
    let mut A = X.clone();
    for i in 0..A.len() {
        if A[i] == 3 || A[i] == 5 {
            A[i] = A[i] + 2;
            max_flag = false;
            break;
        } else if A[i] == 7 {
            A[i] = 3;
        } else {
            // A[i] == 0
            A[i] = 3;
            max_flag = false;
            break;
        }
    }
    if max_flag {
        return None;
    }
    let mut sevens = 0;
    let mut fives = 0;
    let mut threes = 0;
    for i in 0..A.len() {
        match A[i] {
            3 => threes += 1,
            5 => fives += 1,
            7 => sevens += 1,
            _ => (),
        };
    }
    if sevens == 0 || fives == 0 || threes == 0 {
        return next(A);
    }
    let mut ans = 0;
    for i in 0..A.len() {
        ans += A[i] * 10i64.pow(i as u32);
    }
    Some((A, ans))
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner kbScanner = new Scanner(System.in);
		
		int w = kbScanner.nextInt();
		int h = kbScanner.nextInt();
		int x = kbScanner.nextInt();
		int y = kbScanner.nextInt();
		int r = kbScanner.nextInt();
		
		String str;
		
		if(judge(w, h, x, y, r)){
			str = "Yes";
		}else{
			str = "No";
		}
		
		System.out.println(str);
	}
	
	private static boolean judge(int w, int h, int x, int y, int r){
		if(x - r < 0 || y - r < 0){
			return false;
		}
		if(y + r > h || x + r > w){
			return false;
		}
		
		return true;
	}
}

Measured memory_bytes: 26392
import java.util.Scanner;
import java.util.Arrays;

// 解説通りのb→cを確定後、a→b,cで計算する方法
public class Main {
    public static void main(String[] args) throws Exception {
        // 入力
        Scanner sc = new Scanner(System.in);
        int n=Integer.parseInt(sc.next());
        int[] a=new int[n];
        for(int i=0;i<n;i++)    a[i]=Integer.parseInt(sc.next());
        int[] b=new int[n];
        for(int i=0;i<n;i++)   b[i]=Integer.parseInt(sc.next());
        int[] c=new int[n];
        for(int i=0;i<n;i++)    c[i]=Integer.parseInt(sc.next());
        Arrays.sort(a); Arrays.sort(b); Arrays.sort(c);
        
        // 各b[i]に対し、何個のcが選べるか
        // Arrays.binarySearchですが、全部ソートすることで実は計算量を落とせます。
        // 詳しくは以下のコードを読んで欲しいのですが、sはiがNのループを回る間に1回だけNのループを回るのでO(N+N)=O(N)です。
        int[] cnum=new int[n];
        int s=0;
        for(int i=0;i<n;i++){
            while(s<n&&b[i]>=c[s])  s++;
            cnum[i]=n-s;
        }
        // cnumの累積和
        long[] accum=new long[n+1];
        for(int i=n-1;i>=0;i--){
            accum[i]=accum[i+1]+cnum[i];
        }
        // accumを利用して、各a[i]に対し使用可能なb,cの組み合わせを足していく
        // これも同様の手法で行きます。
        long ret=0;
        s=0;
        for(int i=0;i<n;i++){
            while(s<n&&a[i]>=b[s])  s++;
            ret += accum[s];
        }
        System.out.println(ret);
    }
}


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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define RFOR(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[ ";
    for (auto a : v) os << a << " ";
    os << "]";
    return os;
}

int main() {
    string S, T;
    cin >> S;
    cin >> T;

    ll ans = S.size();
    REP(i, S.size()) {
        if (S[i] == T[i]) ans--;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3904