akhauriyash/Code-Regression huggingface dataset:
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

using ll = long long;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

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

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
    int X;
    cin >> X;
    cout << (X == 3 || X == 5 || X == 7 ? "YES" : "NO") << endl;
    return 0;
}


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

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ldb long double 
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int MOD = 1e9+7;
const int MX = 2e5+5;
const ll INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n)
{
 ll res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a*=a;
  n/=2;
}
return res;
}

ll abst(ll a)
{
 return ((a<0)?(-1*a):(a));
}

int main()
{
   int a,b;
   cin>>a>>b;
   if(a>=13)
    cout<<b<<'\n';
    else if(a>=6)
     cout<<(b/2)<<"\n";
     else
      cout<<0<<"\n";
      return 0;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int num[5];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    char c[5] = {'M','A','R','C','H'};
    int cnt = 0;
    for(int i = 0; i < n; ++i){
        string s; cin >> s;
        for(int j = 0; j < 5; ++j){
            if(s[0] == c[j]) num[j]++;
        }
    }
    long long ans = 0;
    for(int i = 0; i < 1<<5; i++){
        if(__builtin_popcount(i) != 3) continue;
        long long tmp = 1;
        for(int j = 0; j < 5; ++j){
            if((i>>j)&1) tmp *= num[j];
        }
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
 
int main(){
   	int dmin =100;
  	int N;
    cin >> N;
  	int sum = 0;  
  
  	for(int i=0;i<N;i++){
	  int A;
      cin >> A;
      int d =0;
      while(A%2==0){
        A /= 2;
        d++;
      }
      dmin = min(dmin,d);
    }
  cout << dmin;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N,M;
int use[11];
int dic[] = {0,2,5,5,4,5,6,3,7,6};
int dp[10009];


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>M;
    rep(i,M){
        int a;
        cin>>a;
        use[a]=1;
    }
    
    rep1(i,N) dp[i]=-INF;
    dp[0]=0;
    
    int maxn = 0;
    rep1(i,N){
        rep1(k,9) if(use[k]){
            int num = dic[k];
            if(i-num>=0&&dp[i-num]!=-INF){
                chmax(dp[i],dp[i-num]+1);
                chmax(maxn,dp[i]);
            }
        }
    }
    
    for(int i=dp[N];i>0;i--){
        for(int k=9;k>0;k--) if(use[k]){
            int num = dic[k];
            if(N-num>=0&&dp[N-num]==i-1){
                cout<<k;
                N-=num;
                break;
            }
        }
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int N;
bool U[200005];
int V[200005];
int lg2[200005];
priority_queue<pair<int,pair<int,int> >,vector<pair<int,pair<int,int> > >,greater<pair<int,pair<int,int> > > > H;
int RMQ[20][200005][2];
int getmin(int st,int dr,int p)
{
    if(dr<st)return 0;
    p=p^(!(st%2));
    int lg=lg2[dr-st+1];
    return (V[RMQ[lg][dr][p]]<V[RMQ[lg][st+(1<<lg)-1][p]] ? RMQ[lg][dr][p]:RMQ[lg][st+(1<<lg)-1][p]);
}
int main()
{
    lg2[0]=-1;
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>V[i];
        RMQ[0][i][i%2]=i;
        lg2[i]=1+lg2[i/2];
    }
    V[0]=1<<30;
    for(int k=1;k<20;k++)
    {
        for(int i=(1<<k);i<=N;i++)
        {
            RMQ[k][i][0]=(V[RMQ[k-1][i][0]]<V[RMQ[k-1][i-(1<<(k-1))][0]] ? RMQ[k-1][i][0]:RMQ[k-1][i-(1<<(k-1))][0]);
            RMQ[k][i][1]=(V[RMQ[k-1][i][1]]<V[RMQ[k-1][i-(1<<(k-1))][1]] ? RMQ[k-1][i][1]:RMQ[k-1][i-(1<<(k-1))][1]);
        }
    }
    H.push({V[getmin(1,N,1)],{1,N}});
    while(!H.empty())
    {
        pair<int,int> tmp=H.top().second;H.pop();
        if(tmp.first>=tmp.second)continue;
        int x=getmin(tmp.first,tmp.second,1);
        int y=getmin(x+1,tmp.second,1);
        H.push({V[getmin(tmp.first,x-1,1)],{tmp.first,x-1}});
        H.push({V[getmin(x+1,y-1,1)],{x+1,y-1}});
        H.push({V[getmin(y+1,tmp.second,1)],{y+1,tmp.second}});
        cout<<V[x]<<" "<<V[y]<<" ";
    }
    return 0;
}


Measured memory_bytes: 36468
#include <bits/stdc++.h>
#define SIGMA 26
using namespace std;
string sir;
set <int> s[SIGMA];
int q,op,l,r,pos,n;
char c;
int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    cin>>sir;
    sir="#"+sir;
    for(int i=1;i<=n;i++)
        s[sir[i]-'a'].insert(i);
    cin>>q;
    while(q--)
    {
        cin>>op;
        if(op==1)
        {
            cin>>pos>>c;
            s[sir[pos]-'a'].erase(pos);
            s[c-'a'].insert(pos);
            sir[pos]=c;
        }
        else
        {
            cin>>l>>r;
            int sol=0;
            for(int i=0;i<SIGMA;i++)
            {
                auto it=s[i].lower_bound(l);
                if(it!=s[i].end() && *it<=r)
                    sol++;
            }
            cout<<sol<<"\n";
        }   
    }
    return 0;
}

Measured memory_bytes: 24240
n, m, k = map(int, input().split())
mod = 998244353
ans = 0
x = 1
for i in range(k + 1):
    ans += (((m * pow(m - 1, n - i - 1, mod)) % mod) * x) % mod
    ans %= mod
    x = (x * (n - i - 1) * pow(i + 1, mod - 2, mod)) % mod
print(ans % mod)

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

using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
const ll MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;

struct pair_hash {
	template <class T1, class T2>
		std::size_t operator () (const std::pair<T1,T2> &p) const {
			auto h1 = std::hash<T1>{}(p.first);
			auto h2 = std::hash<T2>{}(p.second);

			return h1 ^ h2;  
		}
};

ll pw(ll te, ll tee) {
	if (tee == 0)	return 1;
	ll res = pw(te, tee / 2);
	return (tee % 2 ? te * res * res : res * res);
}


string s;
ll n, a, b;

void Read_input() {
	cin >> s;
}

void Solve() {
	string sp = s;
	n = s.size();
	reverse(sp.begin(), sp.end());
	for (ll i = 1; i < n; i++)
		if (s[i] == s[i - 1]) {
			a++;
			s[i] = (s[i] == '0' ? '1' : '0');
		}
	for (ll i = n - 2; i >= 0; i--)
		if (sp[i] == sp[i + 1]) {
			b++;
			sp[i] = (sp[i] == '0' ? '1' : '0');
		}
	cout << min(a, b);
}


int main() {

	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	//freopen("input.txt", "r", stdin),	freopen("output.txt", "w", stdout);

	Read_input(),	Solve();
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
typedef long long ll;
using namespace std;

void solve(void)
{
	vector<ll> x(4),ans(4);
	cin>>x[0]>>x[1]>>x[2]>>x[3];
	ans[0]=x[0]*x[2];
	ans[1]=x[0]*x[3];
	ans[2]=x[1]*x[2];
	ans[3]=x[1]*x[3];
	sort(ans.begin(),ans.end());
	cout<<ans[3]<<endl;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll testcase;
	//cin>>testcase;
	//while(testcase--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int a,b;
  string s;
  cin>>a>>b>>s;
  s[b-1]=s[b-1]-('A'-'a');
  cout<<s;
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,m;
  cin >> n >> m;
  vector<int32> sum(n);
  REP(i,m){
    int32 a,b;
    cin >> a >> b;
    --a;--b;
    if(a > b)swap(a,b);
    sum[a]++;
    sum[b]--;
  }
  REP(i,n-1){
    sum[i+1] += sum[i];
    // cout << sum[i] << endl;
  }
  REP(i,n-1){
    // cout << sum[i] << endl;
    if(sum[i] % 2){
      YES(false);
      return 0;
    }
  }
  YES(true);
  return 0;
}

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

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

    double a, b, x;
    cin >> a >> b >> x;

    x /= a;

    if(x*2 < a*b){
        double rad = atan2(2*x, b*b);
        double degree = rad*180/M_PI;

        printf("%.10f\n", 90-degree);
    }
    else{
        double rad = atan2(2*b-((2*x)/a), a);
        double degree = rad*180/M_PI;

        printf("%.10f\n", degree);
    }

    return 0;
}

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

using namespace std;

int main()
{
    int R,G,B,n;
    cin>>R>>G>>B>>n;
    int ans=0;
    for(int r=0;r<=(n/R);r++)
    {
        for(int g=0;g<=(n/G);g++)
        {
            int x=(R*r)+(g*G);
            if(n-x<0)
                break;
            if((n-x)%B==0){
                ++ans;
            }
        }
    }
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int x,int y) {
  if(x<y) {
    swap(x,y);
  }
  if(x%y==0) {
    return y;
  }
  return gcd(y,x%y);
}


int main() {
  int k;
  cin>>k;
  long long x=0;
  for(int i=1;i<=k;i++) {
    for(int j=1;j<=k;j++) {
      for(int y=1;y<=k;y++) {
        x+=gcd(gcd(i,j),y);
      }
    }
  }
  cout<<x;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,l,r,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>l>>r;
		ans+=(r-l+1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int a=0, b=0, k;
	string s;

	cin >> s;

	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '0') {
			a++;
		}
		else {
			b++;
		}
	}

	cout << min(a, b) * 2 << endl;


	return 0;
}

Measured memory_bytes: 512
mod = int(10 ** 9) + 7

def modinv(x, m = mod):
    b = m
    u = 1
    v = 0
    while b:
        t = x // b
        x -= t * b
        x, b = b, x
        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u

def main():
    n, k = map(int, input().split())

    if k > n-1:
        k = n-1

    factorial = [None for _ in range(200001)]
    factorial[0] = 1
    factorial[1] = 1
    for i in range(2, 200001):
        factorial[i] = (factorial[i-1] * i) % mod

    posCount = [None for _ in range(n+1)]
    for i in range(n+1):
        posCount[i] = (factorial[n] * modinv((factorial[i] * factorial[n-i]) % mod)) % mod

    placeCount = [None for _ in range(n+1)]
    placeCount[0] = 0
    for i in range(1, n+1):
        placeCount[i] = (factorial[n-1] * modinv((factorial[i-1] * factorial[(n-1)-(i-1)]) % mod)) % mod

    ans = 0
    for i in range(-1, -k-2, -1):
        ans = (ans + (posCount[i] * placeCount[i])) % mod
    if k == 1:
        ans -= 1
        if ans < 0:
            ans += mod

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 65484
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 3e5+5;

int row[N], column[N];
set<pair<int,int>> targets;

int main()
{
	int H, W;
	scanf("%d%d",&H,&W);
	int M; 
	scanf("%d",&M);
	for(int i=1;i<=M;i++)
	{
		int a, b;
		scanf("%d%d",&a,&b);
		row[a]++;
		column[b]++;
		targets.insert({a,b});
	}

	
	vector<pair<int,int>> R, C;
	for(int i=1;i<=H;i++) R.emplace_back(row[i],i);
	for(int i=1;i<=W;i++) C.emplace_back(column[i],i);

	sort(R.begin(), R.end());
	sort(C.begin(), C.end());

	int mx_R = R.back().first;
	int mx_C = C.back().first;

	int res = mx_R + mx_C - 1;

	for(auto it_R = R.end()-1;it_R->first==mx_R;it_R--)
	{
		for(auto it_C = C.end()-1;it_C->first==mx_C;it_C--)
		{
			if(targets.count({it_R->second, it_C->second}) == 0)
			{
				res = mx_R + mx_C;
				break;
			}
		}
	}

	printf("%d\n",res);
}


Measured memory_bytes: 28060
import Data.List
main = do
  [h, n] <- map read . words <$> getLine :: IO[Int]
  as <- map read . words <$> getLine :: IO [Int]
  putStrLn $ ans h as

ans :: Int -> [Int] -> String
ans h as = if (sum as) >= h
          then "Yes"
          else "No"




Measured memory_bytes: 45436
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    string S;
    cin >> S;
    int N = S.size();

    auto IsPal = [&] (string A) {
        for (int i = 0; i < A.size() / 2; i++) {
            if (A[i] != A[A.size() - i - 1])
                return false;
        }
        return true;
    };

    cout << (IsPal(S) && IsPal(S.substr(0, S.size() / 2)) && IsPal(S.substr(S.size() / 2 + 1, S.size() / 2)) ? "Yes\n" : "No\n");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int N, M, T;
	int i;
	int answer = 0;
	int a, pa = -1;
	if (scanf("%d%d%d", &N, &M, &T) != 3) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &a) != 1) return 1;
		if (i == 0) {
			if (a >= M) answer += a - M;
		} else {
			if (a - pa >= M + M) answer += (a - pa) - (M + M);
		}
		pa = a;
	}
	if ((T - pa) >= M) answer += (T - pa) - M;
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 596
#include<cstdio>
#include<cstring>
#include<iostream>

using namespace std;

int main()
{
	int s,w;
	cin >> s >> w;
	if(s > w){
		cout << "safe" << endl;
	}
	else{
		cout << "unsafe" << endl;
	}
	return 0;
	
 } 

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

ull gcd(ull x, ull y)
{
    if(!y) return x;
	else return gcd(y,(ull)x%y);
}


int main(){
	string s,t,x;
	ull s_size,t_size,x_size,memo,st_memo;
	
	x = "";
	cin >> s_size >> t_size;
	cin >> s >> t;
	
	memo = gcd(s_size, t_size);
	x_size = t_size*s_size / memo;
	
	/*
	if(memo == 1){
		if(t[0] != s[0]){
			cout << -1 << endl;
		}
		else{
			cout << x_size << endl;
		}
		return 0;
	}
	*/
	
	rep(i,0,memo){
		if(t[(t_size/memo)*i] != s[(s_size/memo)*i]){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << x_size << endl;
	
	/*
	if(s_size > t_size && s_size % t_size == 0){
		rep(i,0,s_size){
			if(t[i] != s[i*(s_size / t_size)]){
				cout << -1 << endl;
				return 0;
			}
		}
		cout << s_size << endl;
	}
	else if(t_size >= s_size && t_size % s_size == 0){
		rep(i,0,t_size){
			if(t[i*(s_size / t_size)] != s[i]){
				cout << -1 << endl;
				return 0;
			}
		}
		
		cout << t_size << endl;
	}
	else{
		memo = gcd(s_size, t_size);
		x_size = t_size*s_size / memo;
		
		rep(i,0,memo){
			if(t[t_size/memo] != s[s_size/memo]){
				cout << -1 << endl;
				return 0;
			}
		}
		cout << x_size << endl;
		
	}
	*/
	
	
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
  using namespace std;
   
  typedef long long ll;
  typedef long double ld;
  typedef pair<ll, ll> pi;
  typedef pair<ll, ll> pll;
  #define fi first
  #define se second
  #define pb push_back
  #define ppb pop_back

  int main() {
    int n,a[105],ans=0;
    cin >> n;
    for (ll i=1;i<=n;++i) {
      ll x;
      cin >> x;
      if (x%2==1 && i%2==1) ++ans;
    }
    cout << ans << endl;
    return 0;
  }

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b; cin >> a >> b;
	int c = 0;
	for(int i=a;i<=b;i++){
		int x = i%10;
		int y = (i/10)%10;
		int z = (i/1000)%10;
		int w = (i/10000)%10;
		if(x==w && y==z){
			c++;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#
# abc175 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """RRS"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """SSS"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """RSR"""
        output = """1"""
        self.assertIO(input, output)


def resolve():
    S = input()
    C = S.count("R")
    if C == 2 and "RR" not in S:
        print("1")
    else:
        print(C)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

inline std :: string operator * ( const bool& f, const std :: string& a )  {
	return f ? a : "" ;
}

int main ( )  {
	
	static std :: string qwq [] = { "Left", "Balanced", "Right" } ;
	
	int a, b, c, d ;

	scanf ( "%d%d%d%d", & a, & b, & c, & d ) ;

	std :: cout << ( a + b > c + d ) * qwq [0] + ( a + b == c + d ) * qwq [1] + ( a + b < c + d ) * qwq [2] << '\n' ;

}


Measured memory_bytes: 256
program example
	implicit none

	character(3) :: a
    integer :: i,wa=0
    
    read(*,*) a
    
    do i=1,3
    	if(a(i:i)=="7") then
        	wa=wa+1
        end if
    end do
    
    if(wa/=0) then
    
    	write(*,*) "Yes"
    else
    	write(*,*) "No"
        
    end if

end program


Measured memory_bytes: 2668
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

ok_count = 0
for _ in range(N):
    A = list(map(int, input().split()))
    total = 0
    for a, b in zip(A, B):
        total += a * b
    total += C
    if total > 0:
        ok_count += 1
print(ok_count)

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    int a, b, c, d;
    a = (n/1000);
    b = (n/100)%10;
    c = (n/10)%10;
    d = n%10;

    vstr ls = {"+", "-"};
    rep(i, 2) rep(j, 2) rep(k, 2) {
        int sum = a;
        if (i == 0) sum += b;
        else sum -= b;
        if (j == 0) sum += c;
        else sum -= c;
        if (k == 0) sum += d;
        else sum -= d;
        if (sum == 7) {
            cout << a << ls[i] << b << ls[j] << c << ls[k] << d << "=7" << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_126
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            List<Edge>[] graph = new List<Edge>[n];
            for (int i = 0; i < n; i++) graph[i] = new List<Edge>();
            for (int i = 0; i < n - 1; i++)
            {
                int[] uvw = ReadInts();

                int u = uvw[0] - 1;
                int v = uvw[1] - 1;
                int w = uvw[2];
                graph[u].Add(new Edge(v, w));
                graph[v].Add(new Edge(u, w));
            }

            Queue<int[]> queue=new Queue<int[]>();
            queue.Enqueue(new int[2] { 0, 0 });
            int[] color = new int[n];
            for (int i = 0; i < n; i++) color[i] = -1;
            while (queue.Count > 0)
            {
                int[] val = queue.Dequeue();
                if (color[val[0]] >= 0) continue;

                color[val[0]] = val[1];

                for(int i = 0; i < graph[val[0]].Count; i++)
                {
                    int to = graph[val[0]][i].to;
                    if (color[to] >= 0) continue;

                    int distance = graph[val[0]][i].distance;
                    int colorTmp = val[1];
                    if (distance % 2 > 0)
                    {
                        if (colorTmp == 0) colorTmp = 1;
                        else colorTmp = 0;
                    }

                    queue.Enqueue(new int[2] { to, colorTmp });
                }
            }

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

        class Edge {
            public int to;
            public int distance;
            public Edge(int to, int distance)
            {
                this.to = to;
                this.distance = distance;
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 31336
class Dice:
    def __init__(self,tb):
        self.table = tb
    def spin(self, dirc):
        directions = dirc
        table1 = self.table
        
        for direction in directions:
            res = [0]*6
            if direction == "N":
                #[1,2,4,8,16,32]
                #[2,32,4,8,1,16]
                res[0] = table1[1]
                res[1] = table1[5]
                res[2] = table1[2]
                res[3] = table1[3]
                res[4] = table1[0]
                res[5] = table1[4]
                
            elif direction == "S":
                #[1,2,4,8,16,32]
                #[16,1,4,8,32,2]
                res[0] = table1[4]
                res[1] = table1[0]
                res[2] = table1[2]
                res[3] = table1[3]
                res[4] = table1[5]
                res[5] = table1[1]
                
            elif direction == "E":
                #[1,2,4,8,16,32]
                #[8,2,1,32,16,4]
                res[0] = table1[3]
                res[1] = table1[1]
                res[2] = table1[0]
                res[3] = table1[5]
                res[4] = table1[4]
                res[5] = table1[2]

            elif direction == "W":
                res[0] = table1[2]
                res[1] = table1[1]
                res[2] = table1[5]
                res[3] = table1[0]
                res[4] = table1[4]
                res[5] = table1[3]
            
            table1 =  res
        self.table = table1
tb1 = list(map(int,input().split()))
directions = input()


dice1 = Dice(tb1)
dice1.spin(directions)
print(dice1.table[0])


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x, n;
    cin >> x >> n;
    
    int list[101], p[n];
    for(int i = 0;i < 101;i++){
        list[i] = 0;
    }
    for(int i = 0;i < n;i++){
        cin >> p[i];
        list[p[i]] = 1;
    }
    
    for(int i = 0;i <= 100;i++){
        if(x - i <= 0){
            cout << 0;
            return 0;
        }
        else if(list[x - i] == 0){
            cout << x - i;
            return 0;
        }
        if(x + i > 100){
            cout << 101;
            return 0;
        }
        else if(list[x + i] == 0){
            cout << x + i;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}

void solve()
{
    int A,B;
    cin >> A >> B;
    cout << max(0, A - 2 * B);
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 3632
import sys


for line in sys.stdin:
    weight = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
    ans = []
    n = bin(int(line))[2:]
    for i, x in enumerate(n[::-1]):
        if x == "1":
            ans.append(str(weight[i]))
    print(" ".join(ans))

Measured memory_bytes: 7644
#include <stdio.h>

int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W, &H, &x, &y, &r);
	if(0+r<=x && x<=W-r&&
	   0+r<=y && y<=H-r)
		printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 584
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        aa: [u128; n]
    };

    let lim = 10u128.pow(18);

    for &a in aa.iter() {
        if a == 0 {
            println!("0");
            return;
        }
    }

    let mut ans = 1u128;
    for &a in aa.iter() {
        ans *= a;
        if ans > lim {
            println!("-1");
            return;
        }
    }

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


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  bool ans = true;
  if (N % 2 != 0) ans = false;
  else {
    for (int i = 0; i < (N / 2); i++){
      if (S.at(i) != S.at(i + N / 2)) ans = false;
    }
  }
  if (ans == true) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const ll N=1005,inf=1e18,M=1e6;
ll w[M],ne[M],la[M],len[M],cst[M],t=1;
ll d[M],dep[M],s[M],ans,S,T,vis[M],cur[M];
void alink(ll x,ll y,ll z,ll l){
	w[++t]=y;
	ne[t]=la[x];
	la[x]=t;
	len[t]=z;
	cst[t]=l;
}
void link(ll x,ll y,ll z,ll l){
	alink(x,y,z,l);
	alink(y,x,0,-l);
}
void clear(){
	for (ll i=1;i<=T;i++)la[i]=0;
	t=1;
}
ll spfa(){
	for (ll i=1;i<=T;i++)s[i]=-inf,vis[i]=0;
	ll l=0,r=1;
	s[S]=0,d[1]=S,vis[S]=1;
	while (l<r){
		ll x=d[++l];
		for (ll y=la[x];y;y=ne[y]){
			ll z=w[y];
			if (s[z]<s[x]+cst[y]&&len[y]){
				s[z]=s[x]+cst[y];
				if (!vis[z]){
					d[++r]=z;
					vis[z]=1;
				}
			}
		}
		vis[x]=0;
	}
	l=0,r=1;vis[S]=1;
	while (l<r){
		ll x=d[++l];
		cur[x]=la[x];
		for (ll y=la[x];y;y=ne[y]){
			ll z=w[y];
			if (s[z]==s[x]+cst[y]&&len[y]&&!vis[z]){
				dep[z]=dep[x]+1;
				vis[z]=1;
				d[++r]=z;
			}
		}
	}
	return vis[T];
}
ll flow(ll x,ll val){
	if (x==T)return val;
	ll v1=val;
	for (ll y=cur[x];y;cur[x]=y=ne[y]){
		ll z=w[y];
		if (dep[z]!=dep[x]+1||!len[y]||s[z]!=s[x]+cst[y])continue;
		ll use=flow(z,min(len[y],val));
		val-=use;
		len[y]-=use;
		len[y^1]+=use;
		ans+=use*cst[y];
		if (!val)return v1;
	}return v1-val;
}
ll n,px[N],py[N],val[N];
ll L[N],R[N],U[N],D[N];
ll ty[N],lim[N],lc[N],k;
ll z1[N],z2[N],c1[N],c2[N];
int main(){
	cin>>n;
	for (ll i=1;i<=n;i++)scanf("%lld%lld%lld",&px[i],&py[i],&val[i]);
	cin>>k;
	for (ll i=1;i<=k;i++){
		scanf("\n");
		ty[i]=getchar();
		scanf("%lld%lld",&lc[i],&lim[i]);
	}
	t=0;
	for (ll i=1;i<=n;i++)
		z1[i]=++t,z2[i]=++t,L[i]=0,R[i]=100,U[i]=100,D[i]=0,c1[i]=++t,c2[i]=++t;
	S=++t,T=++t;t=1;
	ll max1=0;
	for (ll K=1;K<=n;K++){
		for (ll i=1;i<=n;i++)
			L[i]=0,R[i]=100,U[i]=100,D[i]=0;
		ans=0;clear();
		for (ll i=1;i<=k;i++){
			if (ty[i]=='L'){
				for (ll j=lim[i]+1;j<=K;j++)
					L[j]=max(L[j],lc[i]+1);
			}
			if (ty[i]=='R'){
				for (ll j=1;j<=K-lim[i];j++)
					R[j]=min(R[j],lc[i]-1);
			}
			if (ty[i]=='U'){
				for (ll j=1;j<=K-lim[i];j++)
					U[j]=min(U[j],lc[i]-1);
			}
			if (ty[i]=='D'){
				for (ll j=lim[i]+1;j<=K;j++)
					D[j]=max(D[j],lc[i]+1);
			}
		}
		for (ll i=1;i<=K;i++)link(S,z1[i],1,0),link(z2[i],T,1,0);
		for (ll i=1;i<=K;i++){
			for (ll j=1;j<=n;j++){
				if (L[i]<=px[j]&&px[j]<=R[i])
					link(z1[i],c1[j],1,0);
				if (D[i]<=py[j]&&py[j]<=U[i])
					link(c2[j],z2[i],1,0);
			}
		}
		for (ll i=1;i<=n;i++)link(c1[i],c2[i],1,val[i]);
		while (spfa()){
			if (s[T]>0)flow(S,1<<30);
			else break;
		}
		max1=max(max1,ans);
	}
	cout<<max1<<endl;
}

Measured memory_bytes: 20864
def main():
    N = int(input())
    a = list(map(int, input().split()))
    # 自分以外全体のxorがわかっている状態
    s = a[0]
    for i in range(1,N):
        s ^= a[i]
    ans = a
    for i in range(N):
        ans[i] ^= s
    print(*ans)

main()


Measured memory_bytes: 31432
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T3;
const int INF = 1000000000;

int main(){
	int n;
	cin >> n;
	int sum = 0;
	int ml = 0;
	for(int i = 0;i < n;i++){
		int l;
		cin >> l;
		ml = max(l,ml);
		sum += l; 
	}

	if(sum - ml > ml)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int INF = 1000000001;
int main()
{

int n,k;
cin>>n>>k;
vi v(n);
rep(i,n)
	cin>>v[i];
sort(All(v));
int m=INF;
rep(i,n-k+1){
	m=min(m,v[i+k-1]-v[i]);
}
cout<<m<<endl;

    return 0;
}

Measured memory_bytes: 640
w,a,b = (int(x) for x in input().split())

block1 = [a,a+w]
block2 = [b,b+w]

if a > b:
    tmp = block1
    block1 = block2
    block2 = tmp

if block1[0] <= block2[0] <= block1[1]:
    print(0)
else:
    print(block2[0] - block1[1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll> PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

ll a,b;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>a>>b;
    if(a<=5){
        print(0);
    }else if(a<=12){
        print(b/2);
    }else{
        print(b);
    }
    return 0;
}

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

//string s[110],t[110];
  //int A=0;
  //int Alice=0,Bob=0,count=0;
  //int memo;
  //int flag =1;
  //vector<int> a[110];//

int main() {
  int N;
  int sum = 0;
  int d[110];
  cin >> N;
  for(int i=0;i<N;i++) cin >> d[i];
  for(int i=0;i<N;i++){
      int score =0;
    for(int j=0;j<N;j++){
      if(d[j]==d[i]){
        score++;
        if(score>=2){
          d[j]=0;
        }
      }
    }
  }
    for(int i=0;i<N;i++){
  		if(d[i]==0){
          sum +=1;    
      }
    }
  cout << N-sum << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define inf INT_MAX

int main(){
    FASTIO
    int x; cin>>x;
    if(x==0) x= 1;
    else x = 0;
    cout<<x<<endl;
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
#define ll long long int
int main(){
    ll a, b, ans=-1;
    cin>>a>>b;
    ll w[a], v[a], dp[a][b+1];
    for (ll i=0; i<a; i++){
        for (ll j=0; j<=b; j++){
            dp[i][j]=-1;
        }
    }
    for (ll i=0; i<a; i++){
        cin>>w[i]>>v[i];
        dp[i][w[i]]=v[i];
    }
    for (ll i=0; i<a-1; i++){
        for (ll j=1; j<=b; j++){
            if (dp[i][j]==-1) continue;
            dp[i+1][j]=max(dp[i+1][j], dp[i][j]);
            if (j+w[i+1]>b) continue;
            dp[i+1][j+w[i+1]]=max(dp[i+1][j+w[i+1]], dp[i][j]+v[i+1]);
        }
    }
    for (ll j=1; j<=b; j++) ans=max(ans, dp[a-1][j]);
    cout<<ans<<endl;
}


Measured memory_bytes: 78336
s=input()
for i in range(int(input())):
    sou_com=input().split()
    if sou_com[0]=='print':
        print(s[int(sou_com[1]):int(sou_com[2])+1])
    elif sou_com[0]=='reverse':
        s=s[:int(sou_com[1])]\
        +s[int(sou_com[1]):int(sou_com[2])+1][::-1]\
        +s[int(sou_com[2])+1:]
    elif sou_com[0]=='replace':
        s=s[:int(sou_com[1])]\
        +sou_com[3]\
        +s[int(sou_com[2])+1:]

Measured memory_bytes: 7736
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();


int main(){
  string a,b;cin >> a >> b;
  string c,d;
  
  REP(i,atoi(b.c_str()))c+=a;
  REP(i,atoi(a.c_str()))d+=b;
  //cout<<c<<" "<<d<<endl;;
  if (c>=d)cout << d << endl;
  else cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct LasySegmentTree {
    int n;
    vector<ll> node, lazy;

    LasySegmentTree(vector<ll> v) {
        int sz = sz(v);
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2 * n - 1);
        lazy.resize(2 * n - 1);

        rep(i, sz) node[i + n - 1] = v[i];
        rrep(i, n - 2) node[i] = node[i * 2 + 1] + node[i * 2 + 2];
    }

    void eval(int k, int l, int r) {
        if (lazy[k] != 0) {
            node[k] += lazy[k];
            if (r - l > 1) {
                lazy[2 * k + 1] += lazy[k] / 2;
                lazy[2 * k + 2] += lazy[k] / 2;
            }
        }
        lazy[k] = 0;
    }

    void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (b <= l || r <= a) return;

        if (a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        } else {
            add(a, b, x, 2 * k + 1, l, (l + r) / 2);
            add(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = node[2 * k + 1] + node[2 * k + 2];
        }
    }

    ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (b <= l || r <= a) return 0;

        eval(k, l, r);
        if (a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
        ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
        return vl + vr;
    }
};

int main() {
    ll n, d;
    ll a;
    cin >> n >> d >> a;
    vector<ll> x(n), h(n);
    vector<pair<ll, ll>> vec(n);
    rep(i, n) {
        cin >> x[i] >> h[i];
        vec[i] = {x[i], h[i]};
    }
    sort(all(vec));
    sort(all(x));

    vector<ll> right(n);
    rep(i, n) {
        ll tmp = upper_bound(all(x), x[i] + 2 * d) - x.begin();
        right[i] = tmp;
    }

    vector<ll> z(n);
    rep(i, n) z[i] = vec[i].second;

    LasySegmentTree segt(z);
    ll ans = 0;
    rep(i, n) {
        ll hp = segt.getsum(i, i + 1);
        if (hp <= 0) continue;
        ll cnt = (hp + a - 1) / a;
        ll damage = a * cnt;
        segt.add(i, right[i], -damage);
        ans += cnt;
    }
    cout << ans << endl;
}


Measured memory_bytes: 19328
#include <stdio.h>

long long max(long long arr[], size_t count) {
    long long max_val = arr[0];
    for (size_t i = 0; i < count; i++) {
        max_val = (arr[i] > max_val) ? arr[i] : max_val;
    }
    return max_val;
}

void solve(long long a, long long b, long long c, long long d) {
    long long val[] = { a*c, a*d, b*c, b*d};
    long long ans = max(val, 4);
    printf("%lld\n", ans);
}

int main() {
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    long long d;
    scanf("%lld",&d);
    solve(a, b, c, d);
    return 0;
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node
{
    string s;
    int x,p;
}a[110];

bool cmp(node x,node y)
{
    if(x.s == y.s)  return x.x>y.x;
    return x.s<y.s;
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].s>>a[i].x;
        a[i].p=i+1;
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++)    cout<<a[i].p<<endl;
    return 0;
}


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

import collections

c = collections.Counter(a)

s = 0
for i in c:
    j = c[i]

    s += j * (j - 1) // 2

for i in range(n):
    j = c[a[i]]
    s2 = s - j * (j - 1) // 2 + max(0, (j - 1) * (j - 2) // 2)
    print(s2)


Measured memory_bytes: 24748
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=0;
	cin >>n;
	vector<ll> a(n);
	ll bef;
	rep(i,n){
		cin>>a[i];
	}

	rep(i,n){
		cin>>bef;
		a[i]-=bef;
	}
	sort(all(a));
	rep(i,n){
		if(a[i]<0){
			ans+=(a[i]*-1)/2;
		}else{
			ans-=a[i];
		}
	}

	cout<<solve(ans>=0)<<endl;
}
/*
1 2 3 +2  -> +2
5 2 2  +1  ->-1
-4 0  1 -> -3,-4
-2 0 0

3  1  4  1  5
2  7  1  8  2

1 -6  3 -7  3 -> -6,-13
1  0  0 -7  3
1  0  0 -1  0
3  0  0  0  0


2  7  1  8  2
3  1  4  1  5

-1 6  -3 7  -3
-1 6  -1 5  -1
*/

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>

int main(void)
{
    int n, i;
    double h, sum;
    int si[1000];

    while (1){
        scanf("%d", &n);
        
        //nに0が入力したらbreak
        if (n == 0){
            break;
        } 

        //配列siに数字を入力し合計を出す
        sum = 0;
        for (i = 0; i < n; i++){
            scanf("%d", &si[i]);
            sum += si[i];
        }

        sum /= n;

        //偏差と偏差の2乗を求める
        h = 0;
        for (i = 0; i < n; i++){
            h += pow(si[i] - sum, 2.0);
        }

        h /= n;

        //偏差の二乗の平方根
        //s = sqrt(ave);

        printf("%lf\n", pow(h, 1.0 / 2.0));
    }

    return (0);
}



Measured memory_bytes: 2100