akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include<set>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;


//ABC078-C
int main() {
	ll N;
	scanf("%lld", &N);
	ll M;
	scanf("%lld", &M);

	ll time_one = M * 1900ll + (N - M) * 100ll;

	ll result = time_one << M;

	printf("%lld\n", result);
}


//AGC008-A
/*
int main() {
	ll x;
	scanf("%lld", &x);
	ll y;
	scanf("%lld", &y);
	
	ll result = INF;


	if (x == y) {
		result = 0;
	}
	else if (x < y) {
		if (x >= 0 && y >= 0) {
			result = y - x;
		}
		else if (x <= 0 && y <= 0) {
			result = y - x;
		}
		else {
			//x:- y:+

			if (abs(x) <= y) {
				result = 1ll + y - abs(x);
			}
			else if (abs(x) > y) {
				result = abs(x) - y + 1ll;
			}
		}
	}
	else if(x > y){
		if (x == 0) {
			result = abs(y) + 1ll;
		}
		else if (y == 0) {
			result = 1ll + x;
		}
		else if (x > 0 && y >= 0) {
			result = 1ll + x - y + 1ll;
		}
		else if (x < 0 && y <= 0) {
			result = 1ll + abs(y) - abs(x) + 1ll;
		}
		else {
			//x:+ y:-

			if (x >= abs(y)) {
				result = 1ll + x - abs(y);
			}
			else if(x < abs(y)) {
				result = abs(y) - x + 1ll;
			}
		}
	}

	printf("%lld\n", result);
}
*/


//ABC097-C
/*
int main() {
	string s;
	cin >> s;
	ll K;
	cin >> K;

	ll len = s.length();
	set<string> st;

	for (ll i = 0; i < len; i++) {
		for (ll j = 1; j <= min(K, len - i); j++) {
			st.insert(s.substr(i, j));
		}
	}

	vector<string> A;
	for (auto item : st) {
		A.push_back(item);
	}

	std::sort(A.begin(), A.end());

	cout << A[K - 1];

}
*/


//ABC99-C
/*
int main() {
	ll N;
	scanf("%lld", &N);

	vector<ll> dp(N + 1, INF);
	dp[N] = 0;

	for (ll i = N; i > 0; i--) {
		if (dp[i] == INF) {
			continue;
		}

		dp[i - 1] = min(dp[i - 1], dp[i] + 1);

		ll draw = 6;
		while (true) {
			if (i >= draw) {
				dp[i - draw] = min(dp[i - draw], dp[i] + 1);
			}
			else {
				break;
			}

			draw *= 6;
		}

		draw = 9;
		while (true) {
			if (i >= draw) {
				dp[i - draw] = min(dp[i - draw], dp[i] + 1);
			}
			else {
				break;
			}

			draw *= 9;
		}
	}

	printf("%lld\n", dp[0]);
}
*/

//ARC100-C
//L1�����̑��a���ŏ�������ɂ͒����l
/*
int main() {
	ll N;
	scanf("%lld", &N);
	vector<ll> A(N, 0);
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
	}

	vector<ll> B(N, 0);
	ll sum = 0;
	for (ll i = 0; i < N; i++) {
		B[i] = A[i] - (i + 1);
	}

	std::sort(B.begin(), B.end());

	ll b = B[N / 2];


	ll result = 0;

	for (ll i = 0; i < N; i++) {
		result += std::abs(A[i] - (b + i + 1));
	}

	printf("%lld\n", result);
}
*/

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

const int INF=1e9;

int main(){
    int N; cin >> N;
    
    vector<int> c;
    int dp[111111];
    
    c.push_back(1);
    for(int i=6; i<=N; i*=6) c.push_back(i);
    for(int i=9; i<=N; i*=9) c.push_back(i);
    
    fill(dp,dp+N+1,INF);
    dp[0]=0;
    
    for(int i=0; i<=N; i++){
        for(int j=0; j<c.size(); j++){
            if(i >= c[j]){
                //cout << i <<" "<< j <<" "<< dp[i] <<" "<< dp[i-c[j]]+1 << endl;
                dp[i] = min(dp[i], dp[i-c[j]]+1);
                //cout << "→ " << dp[i] << endl;
            }
        }
    }
    
    cout << dp[N] << endl;
}


Measured memory_bytes: 640
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 200005;
const ll mm = 1e+18;
void solve()
{
    int a[3];
    rep0(i,3) cin>>a[i];
    sort(a,a+3);
    if(a[0]==a[1]&&a[0]==5&&a[2]==7) cout<<"YES";
    else cout<<"NO";
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 100010;
const int maxD = 400;
const int maxH = 100; 
const int MOD = 1000000007;

int a[maxN];
int t[maxN];
int f[maxN];
int b[130];
int main()
{
	int n;
	scanf("%d",&n);
	int j = 1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int i=1;i<n;i++)
	{
		if(a[i] == a[i+1])
		{
			b[j] = a[i];
			int pos = upper_bound(a+1,a+1+n,a[i]) - a;
			if(pos - i>=4)
				f[j] = 1;
			i = pos-1;
			j++;
		}
		else
			continue;	
	}
	j--;
	if(f[j])
	{
		ll ans = (ll)b[j]*b[j];
		printf("%lld\n",ans);
	}
	else if(!f[j] && j>=2)
	{
		ll ans = (ll)b[j] * b[j-1];
		printf("%lld\n",ans);
	}
	else
	{
		puts("0");
	}
	return 0;
}  

Measured memory_bytes: 768
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] s = Console.ReadLine().Split();
		int N = int.Parse(s[0]);
		int M = int.Parse(s[1]);
		string[] t = Console.ReadLine().Split();
		int [] P = new int[N];
		for(var i=0;i<N;i++){
			P[i] = int.Parse(t[i]);
		}
		var uf = new UnionFind(N+1);
		int [] G = new int[N];
		for(var i=0;i<N;i++){
			G[i] = i;
		}
		int t1 = 0;
		int a = 0;
		for(var i=0;i<M;i++){
			string[] u = Console.ReadLine().Split();
			int K1 = int.Parse(u[0]);
			int K2 = int.Parse(u[1]);
			uf.Unite(K1,K2);
		}
		int count = 0;
		for(var i=0;i<N;i++){
			if(uf.IsSameGroup(i+1,P[i])){
				count += 1;
			}
		}
		Console.WriteLine(count);
	}
}
public class UnionFind
{
    private int[] data;
	public UnionFind(int size){
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(int x, int y){
        x = Root(x);
        y = Root(y);
        if (x != y){
            if (data[y] < data[x]){
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
	public bool IsSameGroup(int x, int y){
        return Root(x) == Root(y);
    }
    private int Root(int x){
        return data[x] < 0 ? x : data[x] = Root(data[x]);
    }
}

Measured memory_bytes: 22876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

int main(){
    string s,t;
    cin >> s >> t;
    rep(i,s.size()){
        if(s[i]!=t[i]){
            puts("No");
            return 0;
        }
    }
    int a,b;
    a = t.size();   b = s.size();
    if(a-b==1)
        puts("Yes");

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define lop(i,n,a) for(int i=0;i<n;i+=a)
#define rep(i,n,a) for(int i=a;i<n;i++)
#define inarr(arr,n) lop(i,n,1)cin>>arr[i]
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define pii pair<int,int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define hell 1000000007
using namespace std;
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
void sieve(int isprime[],int n){
   lop(i,n+1,1)isprime[i]=i;
   for(int p=2;p*p<=n;p++){
       if(isprime[p]){
           for(int i=p*p;i<=n;i+=p){
               isprime[i]=0;
           }
       }
   }
}
int isprime[1000001];
int solve(){
  int n;cin>>n;
  sieve(isprime,1000000);
  for(int i=n;i<=1000000;i++){
      if(isprime[i]){
          cout<<i<<endl;
          ret;
      }
  }
  ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}
 


Measured memory_bytes: 4224
x,n = map(int,input().split())

if n == 0:
  print(x)
  exit()

p = list(map(int,input().split()))

if x not in p:
  print(x)
  exit()

x1,x2 = x,x
for i in range(100):
  x1 -= 1
  x2 += 1
  if x1 not in p:
    print(x1)
    exit()
  if x2 not in p:
    print(x2)
    exit()

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

int main() {
	int a, b, k;
	vector<int> lst;
	cin >> a >> b >> k;
	for (int n = 1; n <= 100; n++) {
		if ((a % n) == 0 && (b % n) == 0)
			lst.push_back(n);
	}
	cout << *(lst.cend() - k);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int kelipatan, batas1, batas2;
	scanf("%d %d %d", &kelipatan, &batas1, &batas2);
	int temp=(batas2/kelipatan);
	if (temp*kelipatan >=batas1){
		printf("OK\n");
	}
	else printf("NG\n");
	return 0;
}

Measured memory_bytes: 1616
n, m = map(int, input().split())

is_acs = [False] * n
wa_counts = [0] * n

for _ in range(m):
    p, s = input().split()
    p = int(p) - 1

    if s == "AC":
        is_acs[p] = True

    elif not is_acs[p]:
        wa_counts[p] += 1


ac_count = 0
penalty_count = 0

for a, w in zip(is_acs, wa_counts):
    if a:
        ac_count += 1
        penalty_count += w

print(ac_count, penalty_count)


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

int main () {
  string S;
  cin >> S;
  if ( S.at(2)==S.at(3) && S.at(4)==S.at(5) ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

#define debug(x) cout<<#x<<"="<<x<<endl
#define RD(x) freopen((x),"r",stdin)
#define WT(x) freopen((x),"w",stdout)
#define pii pair<int,int>
#define PQ priority_queue
#define ll long long
#define pb push_back
#define mp make_pair
const int INF=0x7fffffff;

int a[53][53],n,m;
char c;

int main(){
	cin>>n>>m;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			cin>>c;
			if (c=='#'){
				a[i][j]-=100;
				a[i+1][j]++;
				a[i][j+1]++;
				a[i-1][j]++;
				a[i][j-1]++;
				a[i+1][j+1]++;
				a[i+1][j-1]++;
				a[i-1][j+1]++;
				a[i-1][j-1]++;
			}
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			if (a[i][j]<0) cout<<"#"; else cout<<a[i][j];
		}
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

vector<pair<int, int>> g[111111];
int a[111111], b[111111];
long c[111111], d[111111];
int main() {
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d%d%d%d", &u, &v, a + i, b + i);
		g[u].emplace_back(i, v);
		g[v].emplace_back(i, u);
	}
	fill(c, c + n + 1, 1e18);
	c[s] = 0;
	priority_queue<pair<long, int>, vector<pair<long, int>>, greater<pair<long, int>>> q;
	q.emplace(0, s);
	while (!q.empty()) {
		int u = q.top().second;
		q.pop();
		for (auto v : g[u]) {
			auto l = c[u] + a[v.first];
			if (c[v.second] <= l)
				continue;
			c[v.second] = l;
			q.emplace(c[v.second], v.second);
		}
	}
	fill(d, d + n + 1, 1e18);
	d[t] = 0;
	q.emplace(0, t);
	while (!q.empty()) {
		int u = q.top().second;
		q.pop();
		for (auto v : g[u]) {
			auto l = d[u] + b[v.first];
			if (d[v.second] <= l)
				continue;
			d[v.second] = l;
			q.emplace(d[v.second], v.second);
		}
	}
	vector<long> r;
	long M = 1e18;
	for (int i = n; i; i--)
		r.push_back(M = min(M, c[i] + d[i]));
	for (auto it = r.rbegin(); it != r.rend(); ++it)
		cout << long(1e15) - *it << '\n';
	cout << flush;
	return 0;
}


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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    int x, y, z;
    cin >> x >> y >> z;

    x -= z;
    x /= y+z;
    cout << x << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  ll N, M;
  cin >> N >> M;
  vector<ll> a(M), b(M), c(M);
  rep(i, M){
    cin >> a.at(i) >> b.at(i) >> c.at(i);
    a.at(i)--;
    b.at(i)--;
  }
  vector<ll> d(N, -1 * INF);
  d.at(0) = 0;
  ll cnt = 0;
  while(true){
    bool update = false;
    rep(i, M){
      if(d.at(b.at(i)) < d.at(a.at(i)) + c.at(i)){
        d.at(b.at(i)) = d.at(a.at(i)) + c.at(i);
        update = true;
      }
    }
    if(!update){
      break;
    }
    cnt++;
    if(cnt == N-1){
      break;
    }
  }
  vector<bool> positive(N, false);
  rep(i, N){
    rep(i, M){
      if(d.at(b.at(i)) < d.at(a.at(i)) + c.at(i)){
        d.at(b.at(i)) = d.at(a.at(i)) + c.at(i);
        positive.at(b.at(i)) = true;
      }
      if(positive.at(a.at(i))){
        positive.at(b.at(i)) = true;
      }
    }
  }
  if(positive.at(N-1)){
    cout << "inf" << endl;
  }
  else{
    cout << d.at(N-1) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() { 
    int n, a, b;
    cin >> n >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % n == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 1e9
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
#define pb push_back
#define all(s) s.begin(),s.end()
#define pie 3.14159265358979323846
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define frr(i,a,b) for(ll i=b-1;i>=a;i--)
#define gcd __gcd
#define con continue
#define pii pair<ll,ll>
const ll N=1e5+6;
ll n,a,b,x;
ll par[N];
void make_par(){
   for(ll i=0;i<N;i++)par[i]=i;
}
ll find_par(ll u){
   if(par[u]==u)return u;
   return par[u]=find_par(par[u]);
}
void union_par(ll a,ll b){
   a=find_par(a);
   b=find_par(b);
   par[a]=b;
   return;
}
signed main(){
    FASTIO;
    ll tt=1;
    //cin>>tt;
    while(tt--){
         ll k;
         string s="ACL";
         cin>>k;
         while(k--)cout<<s;
    }
}


Measured memory_bytes: 3604
S=input()
C1=S[0]=='A' and S[-1].islower()
C1=C1 and S[1].islower()
C2=0
C3=0
for i in S[2:len(S)-1]:
  if i=='C':
    C2+=1
  elif i.islower():
    C3=C3
  else:
    C3+=1
if C1 and C2==1 and C3==0:
  print('AC')
else:
  print('WA')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}
//cout << fixed << setprecision(15);
int N, M, K, H, W, L, R, X;
string S, T;

signed main(){
  cin >> N >> M;
  int ans = 0;
  int mn, mx; cin >> mn >> mx;
  rep(i,M-1){
    int a, b; cin >> a >> b;
    if (mx<a || mn>b) { COUT(0); return 0;}
    mn = max(mn, a);
    mx = min(mx,b);
  }  
  COUT(mx-mn+1);
  return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
int m,f,r,t;
int main(void){
    char c;
    for(;scanf("%d%d%d",&m,&f,&r),m!=-1||f!=-1;){
        t=m+f;
        if(m == -1 || f == -1){
            c='F';
        }else if(t>=80){
            c='A';
        }else if(t>=65){
            c='B';
        }else if(t>=50){
            c='C';
        }else if(t>=30){
            if(r>=50){
                c='C';
            }else
                c='D';
        }else{
            c='F';
        }
        printf("%c\n",c);
    }
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


string S;

int main() {
  cin >> S;

  bool good = true;
  REP(i, S.length()) {
    if ((i + 1) % 2 == 0 && S[i] == 'R') {
      good = false;
      break;
    }
    if ((i + 1) % 2 == 1 && S[i] == 'L') {
      good = false;
      break;
    }
  }

  cout << (good ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int s;
  cin >> s;
  int i = 1;
  set<int> st;
  st.insert(s);
  while (true) {
    i++;
    if (s % 2) {
      s = 3 * s + 1;
      if (st.count(s)) {
        cout << i;
        return 0;
      }
    } else {
      s /= 2;
      if (st.count(s)) {
        cout << i;
        return 0;
      }
    }
    st.insert(s);
  }
}


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

int main(){
  int a, b;
  cin >> a >> b;
  
  for (int i = -1; i < a + 1; i++){
    for (int j = -1; j < b + 1; j++){
      if (j == -1 || j == b || i == -1 || i == a) {
        cout << "#";
      }
      else {
        char x;
        cin >> x;
        cout << x;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if(0<=x-r&&H>=y+r&&W>=x+r&&0<=y-r)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}


Measured memory_bytes: 2052
n = int(input())
b = list(map(int, input().split()))

ans = []
for _ in range(n):
    for i, e in enumerate(reversed(b)):
        if e == len(b) - i:
            ans.append(b.pop(len(b) - i - 1))
            break
        else:
            continue

if len(ans) == n:
    for a in reversed(ans):
        print(a)
else:
    print(-1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int n;
    cin>>n;
    vector<P> schedule(n);
    rep(i, n) {
        int s, t;
        cin>>s>>t;
        schedule[i].first = t;
        schedule[i].second = s;
    }
    sort(schedule.begin(), schedule.end());
    int time = 0;
    int cnt = 0;
    for (auto s : schedule) {
        if (s.second > time) {
            cnt++;
            time = s.first;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

#define Len 10001

int main()
{
    int a, b, c;
    int cnt = 0;
    
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    
    if (a == 5){
        cnt++;
    }else if(a == 7){

    }else{
        printf("NO\n");
        return 0;
    }

    if (b == 5){
        cnt++;
    }else if(b == 7){

    }else{
        printf("NO\n");
        return 0;
    } 

    if (c == 5){
        cnt++;
    }else if(c == 7){

    }else{
        printf("NO\n");
        return 0;
    }

    if (cnt  == 2) 
        printf("YES\n");
    else
    {
        printf("NO\n");
    }
    
    
    return 0;
}   

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();

		if (x >= 30) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35656
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(long long H){
  ll sum=0;
  ll plus=1;
  while(H){
    H=H/2;
    sum+=plus;
    plus*=2;
    
  }
  op(sum)
}

// 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)
int main(){
    long long H;
    scanf("%lld",&H);
    solve(H);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	int ev = 0, od = 0;
	REP(i, n)
	{
		int a; cin >> a;
		if (a % 2) od++;
		else ev++;
	}
	cout << (od % 2 == 0 ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

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

  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n+1), b(m+1);
  for (int i = 0; i < n; i++) cin >> a[i+1];
  for (int i = 0; i < m; i++) cin >> b[i+1];
  for (int i = 1; i <= n; i++) a[i] += a[i-1];
  for (int i = 1; i <= m; i++) b[i] += b[i-1];

  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    if (a[i] > k) break;
    auto it = upper_bound(b.begin(), b.end(), k-a[i]);
    //cout << i << " " << (ll) (it - b.begin()) << endl;
    ans = max(ans, (ll)i - 1 + (ll)(it - b.begin()));
  }
  cout << ans << endl;
}


Measured memory_bytes: 6364
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = 302;
ll mod = (1e9 + 7);

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll sum_digits(ll n)
{
	ll ret=0;
	while (n)
	{
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here



int main()
{
	IOS;
	ll ans,y, t,n;
	cin >> n;
	string s;
	map<string, int> m;
	while (n--)
	{
		cin >> s;
		m[s]++;
	}
	cout << "AC x " << m["AC"] << endl;
	cout << "WA x " << m["WA"] << endl;
	cout << "TLE x " << m["TLE"] << endl;
	cout << "RE x " << m["RE"] << endl;

	return 0;
}

Measured memory_bytes: 3664
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, k := scanInt(), scanInt()
	a := scanInts(n)

	ps := make([]pii, n)
	for i := 0; i < n; i++ {
		if a[i] < 0 {
			ps[i] = pii{a[i] * -1, 1}
		} else {
			ps[i] = pii{a[i], 0}
		}
	}
	sort.Slice(ps, func(i, j int) bool { return ps[i].a > ps[j].a })

	ans := 1
	c := 0
	lp := -1
	lm := -1
	for i := 0; i < k; i++ {
		if ps[i].b > 0 {
			lm = i
		} else {
			lp = i
		}
		c += ps[i].b
	}

	if c%2 == 1 {
		p, m := -1, -1
		if lm != -1 {
			for i := k; i < n; i++ {
				if ps[lm].b != ps[i].b {
					m = i
					break
				}
			}
		}

		if lp != -1 {
			for i := k; i < n; i++ {
				if ps[lp].b != ps[i].b {
					p = i
					break
				}
			}
		}

		if p == -1 && m == -1 {
			for i := 0; i < k; i++ {
				ans = ans * ps[n-1-i].a % mod
			}
			fmt.Fprintln(wr, (-ans+mod)%mod)
			return
		} else if p == -1 {
			ps[lm] = ps[m]
		} else if m == -1 {
			ps[lp] = ps[p]
		} else {
			if ps[lm].a*ps[p].a < ps[lp].a*ps[m].a {
				ps[lm] = ps[m]
			} else {
				ps[lp] = ps[p]
			}
		}
	}

	for i := 0; i < k; i++ {
		ans = ans * ps[i].a % mod
	}
	fmt.Fprintln(wr, (ans+mod)%mod)
}

const mod = 1000000007

type pii struct{ a, b int }


Measured memory_bytes: 9052
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define MAXN 50
int n,t[MAXN+5],ans=0;
bool u[25];
void dfs(int x)
{
	if(x==n)
	{
		int Min=1e8,last=0;
		for(int i=1;i<24;i++)
			if(u[i])
			{
				Min=min(Min,i-last);
				last=i;
			}
		Min=min(Min,24-last);
		ans=max(ans,Min);
		return;
	}
	if(!u[t[x]])
		{u[t[x]]=true;dfs(x+1);u[t[x]]=false;}
	if(t[x]!=(24-t[x])%24 && !u[24-t[x]])
		{u[24-t[x]]=true;dfs(x+1);u[24-t[x]]=false;}
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&t[i]);
	t[n++]=0;
	if(n>24) {printf("0\n");return 0;}
	dfs(0);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
/**
  @file b.cpp
  @title B - Ordinary Number
  @url https://atcoder.jp/contests/abc132/tasks/abc132_b
**/

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

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

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

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

  int ans = 0;
  for (int i = 1; i < N - 1; i++) {
    int before_pi = p[i];

    vector<int> v;
    v.push_back(p[i - 1]);
    v.push_back(p[i]);
    v.push_back(p[i + 1]);
    sort(ALL(v));
    int after_pi = v[1];

    if (before_pi == after_pi) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  if (A <= 5) {
    cout << 0 << endl;
  } else if (A <= 12) {
    cout << B / 2 << endl;
  } else {
    cout << B << endl;
  }
  return 0;
}


Measured memory_bytes: 764
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    
    vector<vector<int>> A(n, vector<int>(n, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> A[i][j];
        }
    }

    bool ok = true;
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (A[i][j] > A[i][k] + A[k][j]) {
                    ok = false;
                }
            }
        }
    }

    if (!ok) {
        cout << -1 << '\n';
        return 0;
    }

    long long res = 0;

    vector<vector<bool>> used(n, vector<bool>(n, false));

    using PIII = pair<int, pair<int,int>>;
    priority_queue<PIII, vector<PIII>, greater<PIII>> pq;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
           pq.emplace(A[i][j], make_pair(i, j)); 
        }
    }

    while (!pq.empty()) {
        int d = pq.top().first;
        int x = pq.top().second.first;
        int y = pq.top().second.second;
        pq.pop();
        if (used[x][y]) {
            continue;
        }
        res += d;

        for (auto v : {x, y}) {
            int w = x + y - v;
            for (int i = 0; i < n; ++i) {
                if (v == i) {
                    continue;
                }
                if (i < v) {
                    if (A[i][v] == A[i][w] + d) {
                        used[i][v] = true;
                    }
                } else {
                    if (A[v][i] == d + A[i][w]) {
                        used[v][i] = true;
                    }
                }
            }
        }
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 4624
//(・ω・)
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
using namespace std;

int main(){
    string s;
    cin >> s;
    int a = s.size(),ans=1;
    for(int i=0; i<a-1; i++){
        s.pop_back();
        if(s.size()%2==0){
            for(int j=0; j<s.size()/2; j++){
                if(s[j]!=s[(s.size()/2)+j]) break;
                if(j==(s.size()/2)-1) ans=s.size();
            }
        }
        if(ans!=1) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

string S;
int p = 0;

bool cat() {
  if(S[p] == 'm') {
    p++;
    if(!cat()) return false;
    if(S[p++] != 'e') return false;
    if(!cat()) return false;
    if(S[p++] != 'w') return false;
  }
  return true;
}

int main(void) {
  cin >> S;
  cout << (cat() && p == S.length() ? "Cat" : "Rabbit") << endl;
  return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
char sq[110][110];
bool hang[110], lie[110];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i=1; i<=n; i++) scanf("%s", sq[i]+1);
	memset(hang, false, sizeof(hang)); memset(lie, false, sizeof(lie));
	for (int i=1; i<=n; i++) {
		bool flag=false;
		for (int j=1; j<=m; j++) 
			if (sq[i][j]=='#') {flag=true; break;}
		hang[i]=flag;
	}
	for (int i=1; i<=m; i++) {
		bool flag=false;
		for (int j=1; j<=n; j++) 
			if (sq[j][i]=='#') {flag=true; break;}
		lie[i]=flag;
	}
	for (int i=1; i<=n; i++) 
		if (hang[i]) {
			for (int j=1; j<=m; j++) 
				if (lie[j]) cout << sq[i][j];
			printf("\n");
		}
	return 0;
}

Measured memory_bytes: 256
// URL : https://atcoder.jp/contests/practice2/tasks/practice2_c
#include <atcoder/math>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n)    for (ll (i) = 0;   (i) < (n); ++(i))
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))

int main() {
    int T;
    cin >> T;
    while (T--) {
        int N, M, A, B;
        cin >> N >> M >> A >> B;
        cout << atcoder::floor_sum(N, M, A, B) << endl;
    }
}



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

int main() {
  
  string S;
  cin>>S;
  for(int i=0;i<S.size();i++){
    for(int j=0;j<=i;j++){
      if(S.at(i)=='Z'){
        S.at(i)='A';
      }
      else if(S.at(i)=='z'){
        S.at(i)='a';
      }
      else if(S.at(i)=='9'){
        S.at(i)='0';
      }
      else{
        S.at(i)=(char)(S.at(i) + 1);
      }
    }
  }
  cout<<S<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  long long  n,k,tmp;

  scanf("%lld %lld",&n,&k);

  tmp = n%k;
  if(tmp < k-tmp){
    printf("%lld\n",tmp);
  }else{
    printf("%lld\n",(k-tmp));
  }


  return 0;
}

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

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

using namespace std;

struct Data {
  int cur,time,bitmask,score;
};

int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
int maxi[20*20][1<<8][110],info[30][30][110];
int w,h,sp,n,g[10],d[10],s[10],e[10],limit,trans[10];
char field[30][30];

bool isValid(int x,int y) { return 0 <= x && x < w && 0 <= y && y < h; }

int getDiff(int bits1,int bits2){
  int ret = 0;
  int diff = bits1 ^ bits2;
  diff = diff & bits2;
  while( diff ){
    int here = diff & -diff;
    diff -= here;
    int pos = log2(here);
    ret += d[trans[pos]];
  }
  return ret;
}

void compute(){
  rep(tm,limit) {
    rep(i,h) rep(j,w) {
      info[i][j][tm] = 0;
      rep(k,4) {
        int nx = j + dx[k], ny = i + dy[k];
        if( !isValid(nx,ny) ) continue;
        if( field[ny][nx] == '.' ) continue;
        int index = field[ny][nx] - '0';
        if( s[index] <= tm && tm < e[index] ) {
          info[i][j][tm] |= (1<<(field[ny][nx]-'0'));
        }
      }
    }
  }

  deque<Data> deq;
  rep(i,h*w) rep(j,(1<<n)) rep(k,limit) maxi[i][j][k] = -1;
  deq.push_back((Data){sp,0,0,0});
  int answer = 0;
  while( !deq.empty() ){
    Data data = deq.front(); deq.pop_front();
    if( maxi[data.cur][data.bitmask][data.time] > data.score ) continue;
    int x = data.cur % w, y = data.cur / w;
    rep(i,4){
      int nx = x + dx[i], ny = y + dy[i];
      if( !isValid(nx,ny) ) continue;
      if( field[ny][nx] != '.' ) continue;
      if( data.time + 1 >= limit ) continue;
      int ntime = data.time + 1;
      int nbitmask = data.bitmask | info[ny][nx][ntime];
      int nscore = data.score + getDiff(data.bitmask,info[ny][nx][ntime]);
      if( maxi[nx+ny*w][nbitmask][ntime] < nscore ) {
        maxi[nx+ny*w][nbitmask][ntime] = nscore;
        answer = max(answer,nscore);
        deq.push_back((Data){nx+ny*w,ntime,nbitmask,nscore});
      }
    }
  }
  cout << answer << endl;
}

int main(){
  while( cin >> w >> h, w|h ){
    rep(i,h) rep(j,w) {
      cin >> field[i][j];
      if( field[i][j] == 'P' ) {
        field[i][j] = '.';
        sp = j + i * w;
      }
    }
    limit = 0;
    cin >> n;
    rep(i,n) {
      cin >> g[i] >> d[i] >> s[i] >> e[i];
      trans[g[i]] = i;
      limit = max(limit,e[i]);
    }
    compute();
  }
  return 0;
}

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

void bunkai(long long &N,set<long long> &S){
  for(int i=2;i<=sqrt(N);i++){
    if(N%i==0){
      N /= i;
      S.insert(i);
      bunkai(N,S);
      return;
    }
  }
  if(N!=1) S.insert(N);
  return;
}

int main() {
  long long A,B,ans=1;
  cin >> A >> B;
  set<long long> Sa,Sb;
  
  bunkai(A,Sa);
  bunkai(B,Sb);
  auto ita=Sa.begin() , itb=Sb.begin();
  while(ita!=Sa.end() && itb!=Sb.end()){
    if(*ita==*itb){
      ans++;
      ita++;
      itb++;
    }
    else if(*ita>*itb) itb++;
    else ita++;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_c

#include <bits/stdc++.h>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int>dp(3);
    for(int i = 0; i < N; ++i) {
        vector<int>act(3);
        vector<int>loc(3);
        for(auto&x: act)
            cin >> x;
        for(int i = 0; i < 3; ++i)
            for(int j = 0; j < 3; ++j)
                if(i != j) 
                    loc[j] = max(loc[j], dp[i]+act[j]);
        dp = loc;
    }
    cout << max(dp[0], max(dp[1], dp[2])) << endl;;
}

Measured memory_bytes: 256
{-# LANGUAGE LambdaCase #-}

-- {-# LANGUAGE Strict #-}
-- Strictなしだとどれくらい差が出るか見てみたかった

module Main where

import Control.Lens
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

type Point = (Int, Int)

type Strawberry = Point

type LeftTop = Point

type RightBottom = Point

type Area = (LeftTop, RightBottom)

main :: IO ()
main = do
  h : w : _ <- BS.getLine <&> toListOf (unfolded (BS.readInt . BS.dropWhile Char.isSpace))
  ipts <- replicateM h BS.getLine
  let strawberries :: [Strawberry]
      strawberries = ipts ^.. (indexing each <.> indexing each) . filtered (== fromIntegral (Char.ord '#')) . asIndex
  let answer = solve ((0, 0), (h - 1, w - 1)) strawberries
  prettyPrint h w answer

solve :: Area -> [Strawberry] -> [Area]
solve _ [] = error "program error"
solve cake [_] = [cake]
solve cake strawberries@(a : b : _) =
  if a ^. _1 == b ^. _1
    then verticalSplit (a ^. _2) strawberries
    else horizontalSplit (a ^. _1) strawberries
  where
    horizontalSplit p ss =
      let (top, bottom) = List.partition (\s -> s ^. _1 <= p) ss
       in solve (cake & _2 . _1 .~ p) top <> solve (cake & _1 . _1 .~ p + 1) bottom
    verticalSplit p ss =
      let (left, right) = List.partition (\s -> s ^. _2 <= p) ss
       in solve (cake & _2 . _2 .~ p) left <> solve (cake & _1 . _2 .~ p + 1) right

prettyPrint :: Int -> Int -> [Area] -> IO ()
prettyPrint h w cakes =
  let nums :: [Int]
      nums = VU.toList $ VU.create $ do
        vec <- VUM.new (h * w)
        ifor_ cakes $ \i cake ->
          sequence
            [ VUM.write vec (w * h' + w') (i + 1)
              | h' <- [cake ^. _1 . _1 .. cake ^. _2 . _1],
                w' <- [cake ^. _1 . _2 .. cake ^. _2 . _2]
            ]
        pure vec
   in putStrLn $
        nums ^.. unfolded (\case [] -> Nothing; xs -> Just $ List.splitAt w xs)
          & each . each %~ show
          & each %~ unwords
          & unlines


Measured memory_bytes: 27520
#pragma region header
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvs vector<vector<string>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr ll inf = INT32_MAX / 2;
constexpr ll INF = LLONG_MAX / 2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
signed main() {
    string S;
    cin >> S;
    int size = S.size();
    vector<int> date;
    rep(i, S.size() - 2) {
        string suuji=(S.substr(i, 3));
        int a=stoi(suuji);
        int b = abs(753 - a);
        date.push_back(b);
    }
    sort(date.begin(), date.end());
    cout << abs(date.at(0)) << endl;
}

Measured memory_bytes: 3596
x, y, a, b, c = 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, reverse=True)[:x]
b = sorted(b, reverse=True)[:y]

al = a + b + c
al.sort(reverse=True)

ans = sum(al[: x + y])

print(ans)

Measured memory_bytes: 22720
#include<iostream>
#include<string>
using namespace std;
const int N = 100000;

struct C
{
	string de;
	int n;
}card1[N], card2[N], L[N], R[N];

void merge(int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - (mid + 1);

	for (int i = 0; i <= n1; i++)
		L[i] = card1[left + i];
	for (int i = 0; i <= n2; i++)
		R[i] = card1[mid + 1 + i];

	L[n1 + 1].n = R[n2 + 1].n = (int)2e9;

	int i = 0, j = 0;
	for (int k = left; k <= right; k++)
	{
		if (L[i].n <= R[j].n)
			card1[k] = L[i++];
		else
			card1[k] = R[j++];
	}
}

void MergeSort(int left, int right)         //分治法
{
	if (left < right)
	{
		int mid = (left + right) / 2;
		MergeSort(left, mid);               //先将左边分割
		MergeSort(mid + 1, right);          //再将右边分割
		merge(left, mid, right);            //排序,组合
	}
}

int partition(int p, int r)
{
	int i = p;
	C temp;

	for (int j = p; j < r; j++)
	{
		if (card2[j].n <= card2[r].n)
		{
			temp = card2[i];
			card2[i] = card2[j];
			card2[j] = temp;

			i += 1;
		}
	}
	temp = card2[i];
	card2[i] = card2[r];
	card2[r] = temp;

	return i;
}

void QuickSort(int p, int r)
{
	int q;
	if (p < r)
	{
		q = partition(p, r);
		QuickSort(p, q - 1);
		QuickSort(q + 1, r);
	}
}

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

	int n;
	bool T = true;
	
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> card1[i].de >> card1[i].n;
		card2[i] = card1[i];
	}

	MergeSort(0, n - 1);
	QuickSort(0, n - 1);

	for (int i = 0; i < n; i++)
	{
		if (card2[i].de != card1[i].de)
			T = false;
	}

	if (T)
		cout << "Stable\n";
	else
		cout << "Not stable\n";

	for (int i = 0; i < n - 1; i++)
		cout << card2[i].de << " " << card2[i].n << endl;
	cout << card2[n - 1].de << " " << card2[n - 1].n << endl;

	return 0;
}


Measured memory_bytes: 14100