akhauriyash/Code-Regression huggingface dataset:
// g++ -Wall -Wextra -pedantic -std=c++17 -O3 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -fsanitize=address -fno-sanitize-recover -fstack-protector contest.cpp

#include <bits/stdc++.h>

// #define _GLIBCXX_DEBUG 1
// #define _GLIBCXX_DEBUG_PEDANTIC 1
// #define _FORTIFY_SOURCE 2

using namespace std;
#define int long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii;
typedef vector<ll> vl; typedef pair<ll,ll> pll; typedef vector< pair<ll,ll> > vll;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
const int MX = 400010;

int f[MX];
int rf[MX];

int C(int l,int k, int md) 
{
    if (k<0||k>l){
        return 0;
    }
    return f[l]*rf[k]%md*rf[l-k]%md;
}

void precfac() {
    f[0]=1;
    for (int i=1;i<MX;i++){
        f[i]=f[i-1]*i%MOD;
    }
    rf[MX-1]=powmod(f[MX-1],MOD-2, MOD);
    for (int i=MX-2;i>=0;i--){
        rf[i]=rf[i+1]*(i+1)%MOD;
    }
}

int fac(int x) {
	int ret=1;
	for(int i = 1; i <= x; i++) {
		ret*=i;
		ret%=MOD;
	}
	return ret;
}
signed main(void)
{
	IOS;
	int n,k; cin>>n>>k;
	int dig=0;
	while(n>0) {
		dig++;
		n/=k;
	}
	cout<<dig<<endl;
	time();
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

const int CMax = 100002;

int n, A[CMax];
string S;

int main(){
    cin >> S;
    n = S.length();
    cout << S[0] << n-2 << S[n-1];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=2019;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int sum[maxn],x=-1,ans=0;
string str;
bool flag;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> str;
	sum[0]=0;
	rep(sz(str)) sum[i+1]=(10*sum[i]+(str[i]-'0'))%2019;
	rep(sz(str)) sum[i+1]=sum[i+1]*Pow(10,300000-i)%2019;
	sort(sum,sum+sz(str)+1);
	//rep(sz(str)+1) print0(sum[i]);
	rep(sz(str)+1){
		flag=false;
		if(i==sz(str)) flag=true;
		else if(sum[i]!=sum[i+1]) flag=true;
		if(flag){
			//print1(i-x);
			ans+=(i-x)*(i-x);
			x=i;
		}
	}
	ans-=sz(str)+1;
	print1(ans>>1);
	return 0;
}

Measured memory_bytes: 5308
import math
N, M = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(M)]
lower = 10**(N-1)
upper = 10**N
if M==0:
    if N==1:
        print(0)
    elif N==2:
        print(10)
    else:
        print(100)
    exit()
if N==1:
    lower = 0
for n in range(lower, upper):
    nstr = str(n)
    flg = 0
    for i in range(M):
        if nstr[sc[i][0]-1] != str(sc[i][1]):
            flg = 1
            break
    if flg==0:
        print(n)
        exit()

print(-1)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int t, n;
    int B[100];
    cin >> t;

    while(t--){
        cin >> n;
        int max_up = 0, max_down = 0;
        for(int j = 0; j < n; j++){
            cin >> B[j];
        }
        for(int j = 0; j + 1 < n; j++){
            int x = B[j + 1] - B[j];
            int y = B[j] - B[j + 1];
            if(x >= max_up) max_up = x;
            if(y >= max_down) max_down = y;
        }
        cout << max_up << " " << max_down << endl;
    }
    return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdio>

using namespace std;



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


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

vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	string s;
	cin >> s;
	for(int i = 0;i < s.length();i++){
		cout << 'x';
	}
	cout << "\n";
}

Measured memory_bytes: 3624
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)


int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
     string s,sm="ABC";
     cin>>n>>k; set<int>se;
     while(k--){
        cin>>d;

        while(d--){
            cin>>p;
            se.insert(p);
        }

     }cout<<n-se.size()<<endl;

     return EXIT_SUCCESS;
}



Measured memory_bytes: 3660
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		int A = nextInt();
		int B = nextInt();
		int C = nextInt();
		int D = nextInt();
		myout(Math.min(A, B) + Math.min(C, D));
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 32708
#include<iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int m[200000];
	for (int i = 0; i < n; i++) {
		cin >> m[i];
	}
	int max=-1000000000, min = m[0];
	for (int i = 1; i < n; i++) {
		if(max<m[i]-min)max = m[i] - min;
		if (m[i] < min)min = m[i];
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 1940
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n-1)]
ab.sort()
px = [list(map(int, input().split())) for i in range(q)]
p = [0 for i in range(n)]
for i in px:
  p[i[0] - 1] += i[1]
s = ""
for i in ab:
  p[i[1]-1] += p[i[0]-1]
print(" ".join(map(str, p)))

Measured memory_bytes: 125584
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
using ll = long long int;
ll a[200001];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	ll totalsum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		totalsum += a[i];
	}

	ll sum = 0;
	for (int i = 0; i < n - 1; i++) {
		sum = (sum + a[i] * ((totalsum - a[i]) % MOD) % MOD) % MOD;
		totalsum -= a[i];
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 5216
#include <bits/stdc++.h>
#define ms(x, n) memset(x,n,sizeof(x));
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define rep2(i, a, b) for (int i = a; i >= b; --i)
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define mod(x) (x % 1000003)
#define deb(x) cout << #x << " " << x << endl;
#define yes cout << "yes" << endl;
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

int n;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    vector<int> a(n); vector<int> b(n + 1);
    forn(i, n+1) cin >> a[i];
    forn(i, n) cin >> b[i];
    ll ans = 0;
    forn(i, n) {
        if (b[i] >= a[i]) {
            b[i] -= a[i];
            ans += a[i];
            a[i] = 0;
//            cout << "ans1 : " << ans << endl;
            if (b[i] >= a[i + 1]) {
                b[i] -= a[i + 1];
                ans += a[i + 1];
                a[i + 1] = 0;
            } else {
                a[i + 1] -= b[i];
                ans += b[i];
                b[i] = 0;
            }
//            cout << "ans2 : " << ans << endl;
        } else {
            a[i] -= b[i];
            ans += b[i];
            b[i] = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;
ll INF = 1000000009;

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

void solve(){
    int n,y;
    cin >> n >> y;
    int x[n+10];
    rep(i,n){
        cin >> x[i];
        //x[i] = x[i]-y;
    }
    x[n] = y;
    sort(x,x+n+1);
    int v[n+10];
    for(int i=1; i<=n; i++){
        v[i-1] = x[i]-x[0];
    }
    //cout << v[0] << " " << v[1] << " " << v[2] << endl;
    int m;
    if(n==1) m = v[0];
    else{
        m=gcd(v[0],v[1]);
    for(int i=2; i<n; i++){
        m = gcd(m, v[i]);
    }
    }
    cout << m << endl;
}

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


Measured memory_bytes: 1024
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
        static void Main(string[] args)
        {
          //N,Qの入力を受け取る
          var NQ = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          var N = NQ[0];
          var Q = NQ[1];
          var adjlist = new List<int>[N+1];
          for(int i = 1;i < adjlist.Length ; ++i){
            adjlist[i] = new List<int>();
          }
          
          //節同士の繋がりを表現
          for(int i = 1; i < N ; ++i){
            var ab = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var a = ab[0];
            var b  = ab[1];
            adjlist[a].Add(b);
            adjlist[b].Add(a);
          }
          

          //操作を保存
          var queries = new Tuple<int,int>[Q];
          for (int i = 0; i < queries.Length; ++i){
            var px = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            queries[i] = Tuple.Create(px[0],px[1]);
          }          
          
          //自分に対しての操作を保存
          var selfPoints = new long[adjlist.Length];
          for(int i = 0; i < queries.Length ; i++){
            selfPoints[queries[i].Item1] += queries[i].Item2;
          }

          //解答を初期化
          var ancestralPoints = new long[adjlist.Length];
          for(int i = 0; i < adjlist.Length ; i++){
            ancestralPoints[i] = long.MinValue;
          }

          //キューに入っているものが次に見に行くものとなる
          var bfs = new Queue<int>();
          bfs.Enqueue(1);
          ancestralPoints[1] = selfPoints[1];
          
          while(bfs.Any())
          {
            int v = bfs.Dequeue();
            for(int j = 0; j < adjlist[v].Count; ++j){
             int u = adjlist[v][j];
             if(ancestralPoints[u] >=0){
              continue;
             }
             ancestralPoints[u] =+ ancestralPoints[v] + selfPoints[u];
             bfs.Enqueue(u);
            }
          }
          Console.WriteLine(string.Join(" ", ancestralPoints.Skip(1)));       
        }
 }
 


Measured memory_bytes: 59068
#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <cassert>
#include <complex>
#include <time.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,val) memset(A,val,sizeof(A))
#define ITER(it,a) for(__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define DBG1(a) cerr<<#a<<"="<<(a)<<"\n"
#define DBG2(a,b) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;


int main()
{
	//freopen("in.txt","r",stdin);
	int n;
	scanf("%d", &n);
	set<pair<int, int> > s;
	FOR(i, 0, n)
	{
		int x;
		scanf("%d", &x);
		x--;
		s.insert(MP(i, x));
	}

	int res = 0;

	for (set<pair<int, int> > ::iterator it = s.begin(); it != s.end(); it++)
	{
		int x = it->first;
		int y = it->second;
		if (s.count(MP(y, x))) res++;
	}

	cout << res / 2 << endl;

	return 0;
}

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

using namespace std;

string k;
int d;
int dp[10010][2][100];
const int MOD = 1e9 + 7;

int f(int pos, bool flag, int mod){
    if(pos == k.size()){
        if(mod == 0) return 1;
        else return 0;
    }

    int &ret = dp[pos][flag][mod];

    if(ret != -1) return ret;

    ret = 0;

    int mx = k[pos] - '0';

    if(!flag) mx = 10;

    for(int i = 0; i < mx; i++){
        ret = (ret + f(pos + 1, false, (mod + i) % d)) % MOD;
    }

    if(flag) ret = (ret + f(pos + 1, true, (mod + mx) % d)) % MOD;

    return ret;
}

int main(){
    getline(cin, k);
    scanf("%d", &d);

    memset(dp, -1, sizeof(dp));

    printf("%d\n", (f(0, true, 0) + MOD - 1) % MOD);
    
    return 0;
}

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

dp = [[[0] * 2501 for _ in range(51)] for _ in range(51)]
dp[0][0][0] = 1

for i in range(n):
    for j in range(n):
        for k in range(2501):
            if k + x[i] <= 2500:
                dp[i+1][j+1][k+x[i]] += dp[i][j][k]
            dp[i+1][j][k] += dp[i][j][k]


ans = 0
for j in range(1, n+1):
    ans += dp[n][j][j * a]

print(ans)

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

using namespace std;

int n,i,v[100010],d[100010];

int main()
{
    cin>>n;
    for(i=1;i<=n;i++)cin>>v[i];

    d[1]=0;
    for(i=2;i<=n;i++)
    {
        if(i-2>=1)d[i]=min(d[i-1]+abs(v[i]-v[i-1]), d[i-2]+abs(v[i]-v[i-2]));
        else d[i]=d[i-1]+abs(v[i]-v[i-1]);
    }

    cout<<d[n];
    return 0;
}


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

typedef long long ll;

const int MN = 200010;

int N, Q, A, B;
vector<int> query;
ll psum[MN];

struct BIT {
    vector<ll> tree;
    void init() {
        tree = vector<ll>(4 * N, 1e18);
    }
    void upd(int idx, ll val, int l, int r, int n) {
        if(idx < l || r < idx) return;
        if(l == r) {
            tree[n] = min(tree[n], val);
            return;
        }
        int m = (l + r)>>1;
        upd(idx, val, l, m, 2*n);
        upd(idx, val, m + 1, r, 2*n + 1);
        tree[n] = min(tree[2*n], tree[2*n + 1]);
    }
    ll quer(int a, int b, int l, int r, int n) {
        if(b < l || r < a) return 1e18;
        if(a <= l && r <= b) return tree[n];
        int m = (l + r)>>1;
        ll L = quer(a, b, l, m, 2*n);
        ll R = quer(a, b, m + 1, r, 2*n + 1);
        return min(L, R);
    }
} bit1, bit2;

ll dp[MN];

int main() {
    scanf("%d %d %d %d", &N, &Q, &A, &B);
    A--;
    B--;

    query.push_back(A);
    query.push_back(B);
    for(int i = 0; i < Q; i++) {
        int x; scanf("%d", &x);
        x--;
        query.push_back(x);
    }
    Q = query.size();

    for(int i = 1; i < Q; i++) {
        psum[i] = abs(query[i] - query[i - 1]);
        psum[i] += psum[i - 1];
    }

    bit1.init();
    bit2.init();
    for(int i = Q - 1; i >= 1; i--) {
        int p = query[i - 1];
        dp[i] = psum[Q - 1] - psum[i];
        dp[i] = min(dp[i], bit1.quer(0, p, 0, N - 1, 1) - psum[i] + p);
        dp[i] = min(dp[i], bit2.quer(p, N - 1, 0, N - 1, 1) - psum[i] - p);

        bit1.upd(query[i], dp[i] + psum[i - 1] - query[i], 0, N - 1, 1);
        bit2.upd(query[i], dp[i] + psum[i - 1] + query[i], 0, N - 1, 1);

        //cout << i << ' ' << dp[i] << endl;
    }
    printf("%lld", min(dp[1], abs(query[2] - query[0]) + dp[2]));
}


Measured memory_bytes: 17652
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
win = {"r": "p", "s": "r", "p": "s"}
point = {"r": R, "s": S, "p": P}
taka = []
ans = 0
for i in range(N):
    if i >= K:
        if win[T[i]] == taka[i - K]:
            taka.append("*")
        else:
            taka.append(win[T[i]])
            ans += point[win[T[i]]]
    else:
        taka.append(win[T[i]])
        ans += point[win[T[i]]]
print(ans)


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

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  int m = v.at(n-1);
  int s = 1000000000;
  rep(i,m+1){
    int a=0;
    rep(j,n){
      a += (v.at(j) - i)*(v.at(j) - i);
    }
    s = min(s,a);
  }
  cout << s << endl;
}

Measured memory_bytes: 256
E = "E"  # ->
W = "W"  # <-

n = int(input().rstrip())

line = input().rstrip()

bef_change_count = line[1:].count(E)
min_change_count = bef_change_count

for leader_i in range(1, n):
    change_count = bef_change_count
    if line[leader_i] == E and line[leader_i - 1] == E:
        change_count -= 1
    elif line[leader_i] == W and line[leader_i - 1] == W:
        change_count += 1

    bef_change_count = change_count
    min_change_count = min(change_count, min_change_count)

print(min_change_count)


Measured memory_bytes: 3672
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<list>
//#include<unordered_map>
using namespace std;
#define ll long long 
#define dd cout<<endl
#define lll __int128
const int mod=1e9+7;
const int inf=1e9+7;

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int a,b;
	
	while(cin>>a>>b)
	{
		if(b<=1)
		{
			cout<<0<<endl;
			continue;
		}
		if(a>=b)
		{
			cout<<1<<endl;
			continue;
		}
		
		int cnt=1;
		b-=a;
		
		cnt+=b/(a-1);
		
		if(b%(a-1)!=0)
			cnt++;
		
		cout<<cnt<<endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

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

int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};


int main(void) {
    /*
    double a, b, c;
    cin >> a >> b >> c;
    ansYes(c - a - b - (double)2 * sqrt((a * b)) > 0);
     */
    Int a, b;
    cin >> a >> b;
    if (a == 1 || b == 1) {
        cout << 1 << endl;
    }else {
        cout << (a / 2 + a % 2) * (b / 2 + b % 2) + (a / 2) * (b / 2) << endl;
    }
}




Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<string>

using namespace std;

int main(){
    int n;
    cin >> n;
    set<string> m;
    string s;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        m.emplace(s);
    }
    cout << m.size() << endl;
    return 0;
}

Measured memory_bytes: 19116
import sys
input = sys.stdin.readline

def main():
    # a = int(input())
    a, b = map(int, input().split())
    # a = list(map(int, input().split()))
    
    if b == 1:
        print(0)
    else:
        tmp = (b-a)/(a-1)
        if tmp - int(tmp) > 0:
            print(1 + int(tmp) + 1)
        else:
            print(1 + int(tmp))
        # print(1 + (b-a)//(a-1))


if __name__ == "__main__":
    main()

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

#define gcd(a,b)		__gcd(a,b)
#define lcm(a,b)		(a*b)/gcd(a,b)
#define ff              first
#define ss              second
#define int             long long
#define float			double
#define pb              emplace_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vc				vector<char>
#define vb				vector<bool>
#define vf				vector<float>
#define vs				vector<string>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int>>
#define hashmap         unordered_map
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             INT64_MAX
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(x)			x.begin(),x.end()
#define digits(x)		floor(log10(x))+1
#define FIO				ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

template<class T>
void printV(vector<T> a) {for (auto v : a)cout << v << " ";}
template<class T>
void readV(vector<T>& a) {int n = a.size(); for (int i = 0 ; i < n ; i++)cin >> a[i];}
template<class T>
void printA(T* a , int n) {for (int i = 0; i < n  ; i++)cout << a[i] << " ";}
template<class T>
void readA(T* a , int n) {for (int i = 0 ; i < n ; i++)cin >> a[i];}
auto clk = clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
void run_time() {cout << endl<<"Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;}

void aryan_pandeya() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}




int32_t main() {
	aryan_pandeya();
	FIO;

	bool ans = false;
	int n ;
	cin>>n ;

	pii a[n];
	for(int i = 0 ; i<n ; i++){
		cin>>a[i].ff>>a[i].ss;
	}

	for(int i = 0 ; i<n-2 ; i++){
		if(a[i].ff==a[i].ss and a[i+1].ff==a[i+1].ss and a[i+2].ff==a[i+2].ss){
			ans = true;
			break;
		}
	}
	ans?cout<<"Yes":cout<<"No";

	return 0;
}


Measured memory_bytes: 3636
//                                                  '-.-'
   //                                         ()      __.'.__
   //                                      .-:--:-.  |_______|
   //                               ()      \____/    \=====/
   //                               /\      {====}     )___(
   //                    (\=,      //\\      )__(     /_____\
   //    __    |'-'-'|  //  .\    (    )    /____\     |   |
   //   /  \   |_____| (( \_  \    )__(      |  |      |   |
   //   \__/    |===|   ))  `\_)  /____\     |  |      |   |
   //  /____\   |   |  (/     \    |  |      |  |      |   |
   //   |  |    |   |   | _.-'|    |  |      |  |      |   |
   //   |__|    )___(    )___(    /____\    /____\    /_____\
   //  (====)  (=====)  (=====)  (======)  (======)  (=======)
   //  }===={  }====={  }====={  }======{  }======{  }======={
   // (______)(_______)(_______)(________)(________)(_________)
   //
   // Credits :- Joan G. Stark
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
   //|                      AUTHOR - KASPAROVIAN                                     |
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define frr(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fr first
#define sc second
#define mk make_pair
#define endl '\n'
#define MOD 1000000007
#define in insert
#define sz(x) (ll)(x).size()
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
typedef pair<int,pi> ppi;
typedef vector<vi> graph;
template<class T> void mxi(T & a, const T & b) { a = max(a, b); }
template<class T> void mni(T & a, const T & b) { a = min(a, b); }
ld EPS=1e-9;
void solve()
{
  int x;
  cin>>x;
  cout<<(x^1)<<endl;

}
signed main()
{
  fast;
  int t,tab;
  t=1;
  tab=t;
  while(t--)
  {
    //cout<<"Case #"<<(tab-t)<<": ";
    solve();
  }
}
//APPROACHING A QUESTION
//+ Think of binary search (max of min etc also if n<=2*10^5)
//+ Think of common dp states (Even if it appears as maths but constraints are small)
//+ Check constraints
//+ Keep calm and enjoy the question
//+ Be sure to remove MOD from binpow (if needed)
//+ Try bidirectional analysis for constructive questions
//+ If given some sequence try thinking of prefix sums
//+ If constraints are too large maybe its simple maths
//+ In questions with binary operations think of bits independently and also the change pattern
//+ If two or more binary operations are given mostly there is a relation between them and an arithmatic operator

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

int main() {
    ll N; cin >> N;
    ll x = (N*(N-1)) / 2;
    cout << x << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

typedef vector<char> vc;
typedef vector<vc> vvc;

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

struct state {
	vvc f;
	int x, y, d;
	state(vvc f, int x, int y, int d) : f(f), x(x), y(y), d(d) {};
};

int main() {
	int w, h;
	while(cin >> w >> h, w) {
		vvc field(h, vc(w));
		int sx, sy;
		REP(i, h) {
			REP(j, w) {
				cin >> field[i][j];
				if(field[i][j] == '2') {
					sx = j, sy = i;
				}
			}
		}

		stack<state> Q;
		Q.push(state(field, sx, sy, 0));
		int ans = INF;
		while(!Q.empty()) {
			state st = Q.top();
			Q.pop();
			if(st.d == 10 || ans <= st.d) {
				continue;
			}

			REP(d, 4) {
				bool ok = false;
				int nx = st.x;
				int ny = st.y;
first:
				nx += dx[d];
				ny += dy[d];
				if(nx < 0 || w <= nx || ny < 0 || h <= ny) {
					continue;
				}
				switch(st.f[ny][nx]) {
				case '0':
				case '2':
					ok = true;
					goto first;
					break;
				case '1':
					if(ok) {
						st.f[ny][nx] = '0';
						Q.push(state(st.f, nx-dx[d], ny-dy[d], st.d+1));
						st.f[ny][nx] = '1';
					}
					break;
				case '3':
					ans = min(ans, st.d+1);
					break;
				}
			}
		}
	
		cout << (ans==INF ? -1 : ans) << endl;
	}

	return 0;
}

Measured memory_bytes: 1264
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,a;
	char s[1000];
	scanf("%d", &n);
	if (n % 2 == 1)printf("No");
	if (n % 2 == 0)
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%s", &s);
		}
		for (int i = 0; i < n / 2; i++)
		{
			if (s[i] == s[i + n / 2])a++;
		}
		if (a++ == n / 2)
		{
			printf("Yes");
		}else
		{
			printf("No");
		}
	}
	
	return 0;
}

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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

ll dp[1010][1010];

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h)cin >> s[i];
    dp[0][0] = 1;
    rep(i,h){
        rep(j,w){
            if(i!=0){
                if(s[i][j]!='#'){
                    dp[i][j] += dp[i-1][j];
                    dp[i][j] %= mod;
                }
            }
            if(j!=0){
                if(s[i][j]!='#'){
                    dp[i][j] += dp[i][j-1];
                    dp[i][j] %= mod;
                }
            }

        }
    }
    cout << dp[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    string s, t; cin >> s >> t;
    vector<_LL> index[26];
    _LL slen = s.length();
    _LL tlen = t.length();
    rep(i, slen)
    {
        index[s[i] - 'a'].push_back(i);
    }

    _LL loop = 0;
    _LL i = -1;
    rep(j, tlen)
    {
        int nextc = t[j] - 'a';
        if( index[nextc].size() == 0 )
        {
            cout << -1 << endl;
            return 0;
        }
        auto itr = upper_bound(index[nextc].begin(), index[nextc].end(), i);
        if( itr == index[nextc].end() )
        {
            loop++;
            i = index[nextc][0];
        }
        else
        {
            i = *itr;
        }
    }

    cout << loop * slen + i + 1 << endl;

    return 0;    
}

Measured memory_bytes: 4656
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int x = scanner.nextInt();
		    int a = scanner.nextInt();
		    int b = scanner.nextInt();
		    
		    if( Math.abs( x - a) > Math.abs( x - b ) ) 
		    {
		    	System.out.println("B");
		    }
		    else 
		    {
		    	System.out.println("A");
		    }
		    
		    scanner.close(); }
		  }

Measured memory_bytes: 21204
#include<stdio.h>

int main(){
  int n;
  int i;
  int p;

  scanf("%d",&n);
  while(n!=0){
    for(i=0;i<9;i++){
      scanf("%d",&p);
      n=n-p;
    }
    printf("%d\n",n);
    scanf("%d",&n);
  }

  return 0;
}

Measured memory_bytes: 600
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){for(var r=e.split("\n"),t=r[0].split(" "),n=(Number(t[0]),Number(t[1])),o=[],u=0;u<n;u++){var i=r[u+1].split(" "),f=Number(i[0])-1,l=Number(i[1])-1;o.push({a:f,b:l})}o.sort(function(e,r){return e.b-r.b});for(var c=0,a=-1,p=0;p<n;p++)o[p].a>a&&(a=o[p].b-1,c+=1);console.log(c)}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 33328
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			//			solveB();
			solveB2();
			// solveC();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int numN = nextInt();

		int resX = numN * 800;
		int resY = (numN / 15) * 200;

		out.println(resX - resY);
	}

	private void solveB() {
		int numN = nextInt();

		BigDecimal CONST = new BigDecimal(Math.pow(10, 9)).add(new BigDecimal("7"));
		BigDecimal res = BigDecimal.ONE;
		for (int i = 1; i <= numN; i++) {
			res = res.multiply(new BigDecimal(Integer.toString(i)));
		}

		out.println(res.remainder(CONST));
	}

	private void solveB2() {
		int numN = nextInt();
		long CONST = (long) (Math.pow(10, 9) + 7);

		long res = 1;
		for (int i = 1; i <= numN; i++) {
			res = (res * i) % CONST;
		}

		out.println(res);
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

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

int main(){
    string s;
    cin >> s;
    ll n = s.size();
    reverse(s.begin(), s.end());
    ll itr = 0;
    bool f = true;
    while(itr < n && f){
        if(s[itr] == 'm') {
            if(s.substr(itr, 5) != "maerd") f = false;
            itr += 5;
        } else if (s[itr] == 'e') {
            if(s.substr(itr, 5) != "esare") f = false;
            itr += 5;
        } else if (s[itr] == 'r') {
            if(s.substr(itr, 6) == "resare") itr += 6; 
            else if(s.substr(itr, 7) == "remaerd") itr += 7; 
            else f = false;
        }
    }
    if(itr != n) f = false;
    if(f) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

vector<pair<int64_t,int64_t>> soinsuu(int64_t n){
    vector<pair<int64_t,int64_t>> ret;
    for(int64_t i=2;i*i<=n;i++){
        if(n%i !=0) continue;
        int64_t ex=0;
        while(n%i ==0){
            ex++;
            n /= i; //n変更することで、それ以降の約数で割り切れることはない
        }
        ret.push_back(make_pair(i,ex));
    }
    //nが素数だった場合
    if(n!=1) ret.push_back(make_pair(n,1));
    return ret;
}


int main(){
    int64_t n,p;
    cin >> n >> p;
    int64_t ans=1;
    auto ps=soinsuu(p);
    for(auto i:ps){
        //cout << i.first<<" "<<i.second<<endl;
        ans *= pow(i.first,(i.second/n));
    }
    cout << ans << endl;
}

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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int n,a;
  cin >> n >> a;
  cout << n*n - a << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS



    string s;
    cin >> s;

    vector<int> v;

    for(int i = 0; i < s.size(); i++)
    {
      v.push_back(s[i]-'0');
    }



    for(int mask = 0; mask <= 7; mask++)
    {
     int ans = v[0];
     string ss;

      for(int i = 1; i <= 3; i++)
      {
        if(mask & (1<< (i-1)))
        {
          ans += v[i];
          ss.push_back('+');
        }
        else
        {
          ans -= v[i];
           ss.push_back('-');
        }
      }
     
      if(ans == 7)
      {
        int idx = 0;
        for(int i = 0; i < s.size(); i++)
        {
          cout << s[i];
          if(idx < ss.size())cout << ss[idx++];
        }
        cout << "=7";
        return 0;
      }
    }







    return 0; 
}


Measured memory_bytes: 3612
K, S = map(int,input().split())

ans = 0

for X in range(K+1):
    for Y in range(K+1):
        Z = S - (X + Y)
        if (Z >= 0 and Z <= K):
            # print("%d, %d, %d" % (X, Y, Z))
            ans += 1

print("%d" % ans)

Measured memory_bytes: 2940
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    // 入力
    let N = get!(usize);
    println!("{}", N / 3);
}

Measured memory_bytes: 4352
A, B, C, X, Y = map(int, input().split())

if A + B <= 2 * C:
    print(A * X + B * Y)
    exit()

else:
    if X > Y:
        if A > 2 * C:
            print(C * 2 * X)
            exit()
        else:
            print(C * 2 * Y + A * (X - Y))
            exit()
    elif X < Y:
        if B > 2 * C:
            print(C * 2 * Y)
            exit()
        else:
            print(C * 2 * X + B * (Y - X))
            exit()
    else:
        print(C * 2 * X)
        exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+5];
	for(register int i=1;i<=n;i++)  cin>>a[i];
	int b[105];
	memset(b,0,sizeof(b));
	for(register int i=1;i<=n;i++)  b[a[i]]=1;
	int ans=0;
	for(register int i=1;i<=100;i++)
		if(b[i]==1)  ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256