akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
  int n;
  char x[1001],y[1001];
  int dp[1002][1002];
  


  //load n;
  cin >>n;
  for(int i=0;i<n;i++){
    //initialize
    for(int i=0;i<1002;i++){
      for(int j=0;j<1002;j++){
	dp[i][j]=0; 
      }
    }
    //load string
    scanf("%s",x);
    scanf("%s",y);
    //dp
    for(int j=0;j<strlen(x);j++){
      for(int k=0;k<strlen(y);k++){
	if(x[j]==y[k]){
	  dp[j+1][k+1]=dp[j][k]+1;
	}

	else{
 
	  if(dp[j][k+1]>dp[j+1][k]){
	    dp[j+1][k+1]=dp[j][k+1];
	  }

	  else{
	    dp[j+1][k+1]=dp[j+1][k];
	  }
	}
      }
    }

    //print
    cout <<dp[strlen(x)][strlen(y)]<<endl;
  }



  return 0;
}

Measured memory_bytes: 4832
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define amax(a, b) a = max(a, b)
#define INF 1e15

int main() {
    int n;
    cin >> n;
    int k = n / 2;
    ll a[n]; for (auto &ai:a) cin >> ai;
    ll dp[k + 1][3];
    fill(dp[0], dp[k+1], -INF);
    dp[0][0] = 0;
    for (int i=0; i<k; i++) {
        for (int x=0; x<3; x++) {
            for (int y=x; y<3; y++) {
                if (i*2 + y < n)
                    amax(dp[i+1][y], dp[i][x] + a[i*2 + y]);
            }
        }
    }
    cout << max({dp[k][0], dp[k][1], dp[k][2]}) << '\n';
    return 0;
}


Measured memory_bytes: 7572
n = int(input())
digit = len(str(n))

a = 0
if digit % 2 == 0:
  while digit > 0:
    if digit % 2 != 0:
      a += 10 ** digit - 10 ** (digit-1)
    digit -= 1
else:
  digit -= 1
  a += n - 10 ** (digit) + 1
  while digit > 0:
    if digit % 2 != 0:
      a += 10 ** digit - 10 ** (digit-1) 
    digit -= 1

print(a)

Measured memory_bytes: 2940
class BinaryIndexedTree:
    def __init__(self, size):
        size = 1 << (size-1).bit_length()
        self.data = [0] * (size+1)
        self.size = size
    
    def add(self, i, w):
        i += 1
        while i <= self.size:
            self.data[i] += w
            i += i & -i

    def sum(self, i):
        """
        [0,i)
        """
        result = 0
        while i > 0:
            result += self.data[i]
            i -= i & -i
        return result

    __getitem__ = sum

    def lower_bound(self, v):
        """
        return smallest i such that v < sum(data[:i])
        """

        s,pos = 0,0
        N = self.size
        k = N
        while k > 0:
            i = pos+k
            if i <= N:
                x = s+self.data[i]
                if x < v:
                    s = x
                    pos = i
            k >>= 1
        return pos


def naive(P):
    def it():
        for i in range(len(P)-1):
            for j in range(i+1,len(P)):
                yield sorted(P[i:j+1])[-2]
    return sum(it())

def solve(P):

    def it():
        bit = BinaryIndexedTree(len(P))
        for cnt, (v,i) in enumerate(sorted(((v,i) for i,v in enumerate(P)), reverse=True)):
            bit.add(i,1)
            c = bit.sum(i)
            
            low1 = -1 if c <= 0 else bit.lower_bound(c)
            low2 = -1 if c <= 1 else bit.lower_bound(c-1)
            up1 = len(P) if c > cnt-1 else bit.lower_bound(c+2)
            up2 = len(P) if c > cnt-2 else bit.lower_bound(c+3)
            yield v*((up1-i)*(low1-low2)+(i-low1)*(up2-up1))
    return sum(it())


if __name__ == '__main__':
    N = int(input())
    P = list(map(int,input().split()))
    print(solve(P))

Measured memory_bytes: 60964
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define A first
#define B second
#define make_pair MP
#define MOD 1000000007
#define MAXM 100005
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;

}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res,x);
        y = y>>1;
        x = mulmd(x,x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a-b;
    if(ret<0){
        ret+=MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int phi(int n){
    int result = n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n=n/i;
            }
            result-=result/i;
        }
    }
    if(n>1) result-=result/n;
    return result;
}

int gcd(int a, int b, int& x, int& y){
    if(a==0){
        x=0;
        y=1;
        return b;
    }
    int x1,y1;
    int d = gcd(b%a, a, x1, y1);
    x = y1 - (b/a)*x1;
    y = x1;
    return d;
}

int arr[100005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    string t;
    cin>>t;
    int sol=0;
    REP(i,3)
    {
        if(s[i]==t[i])
            sol++;
    }
    cout<<sol<<"\n";
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

A, B = map(int, input().split())

ans = 0
for n in range(A, B + 1):
    s = str(n)
    ans += s == s[::-1]
print(ans)


Measured memory_bytes: 6980
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, cnt = 0; cin >> n;
    ll a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 1; i < n; ++i)
        if(a[i] < a[i-1])
        {
            cnt += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    cout << cnt << '\n';
    return 0;
}

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

int main(){
    int N, M;
    cin >> N;
    vector<string> s(N);
    for (int n=0; n<N; n++){
        cin >> s.at(n);
    }
    cin >> M;
    vector<string> t(M);
    for (int m=0; m<M; m++){
        cin >> t.at(m);
    }
    int max_payment = 0;
    for (int n=0; n<N; n++){
        int payment = 0;
        for (int i=0; i<N; i++){
            if (s.at(n) == s.at(i)) payment++;
        }
        for (int j=0; j<M; j++){
            if (s.at(n) == t.at(j)) payment--;
        }
        if (payment > max_payment) max_payment = payment;
    }
    for (int m=0; m<M; m++){
        int payment = 0;
        for (int i=0; i<N; i++){
            if (t.at(m) == s.at(i)) payment++;
        }
        for (int j=0; j<M; j++){
            if (t.at(m) == t.at(j)) payment--;
        }
        if (payment > max_payment) max_payment = payment;
    }
    cout << max_payment << endl;
}

Measured memory_bytes: 256
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a) <<endl
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}
int n,a,b,c;
const int N=1e5+5;
vector<char>v;
map<char,int>p;
string s[N];
bool vis[N][2];

bool rec(int indx,bool pre)
{
    if(indx==n)
    {
        if(p['A']>=0&&p['B']>=0&&p['C']>=0)
        {
            cout<<"Yes\n";
            for(auto it:v)
            cout<<it<<'\n';

              exit(0);
        }

        return 0;
    }
  

    bool &re = vis[indx][pre];

    if(re)
    {
        return 0;
    }

    re=1;

    if(p[s[indx][0]]>0)
    {
        p[s[indx][0]]--;
        p[s[indx][1]]++;
        v.pb(s[indx][1]);
        rec(indx+1,0);
        v.pop_back();
        p[s[indx][0]]++;
        p[s[indx][1]]--;
    }
    if(p[s[indx][1]]>0)
    {
        p[s[indx][1]]--;
        p[s[indx][0]]++;
        v.pb(s[indx][0]);
        rec(indx+1,1);
        v.pop_back();
        p[s[indx][1]]++;
        p[s[indx][0]]--;
    }

    return 0;
}
signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	
    
    cin>>n;
    
    
    cin>>a>>b>>c;
    p['A']=a;
    p['B']=b;
    p['C']=c;
    for(int i=0;i<n;i++)cin>>s[i];

    rec(0,0);
    cout<<"No\n";
    return 0;
    

return 0;
}

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

int main()
{
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  int m = a[0];
  int ans = 1;
  for(int i = 1; i < n; i++){
    if(a[i] <= m){
      ans++;
      m = a[i];
    }
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 4424
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fast std::ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
 
 //string ans="";
/*ll solve(ll n )
 {
     if(n<12)
        return n;
     if(mp[n]==0)
            mp[n]=max(solve(n/2)+solve(n/3)+solve(n/4),n);
     return mp[n];
        
 }
*/
 
int main()
{
   
    fast;
    ll t=1,x=1;
    //cin>>t;
    while(t--)
    {
        ll i,n,k;
        cin>>n>>k;
        ll a[n];
        for(i=0;i<n;i++)
            cin>>a[i];
        for(i=k;i<n;i++)
        {
            if(a[i]>a[i-k])
                cout<<"Yes\n";
            else
                cout<<"No\n";
        }
    }
}

Measured memory_bytes: 5204
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int n; cin >> n;
    int a=0, b=0, c=0;
    int ans = 0;
    rep(i, n){
        string s; cin>> s;
        rep(j, s.size()){
            if(s[j]=='A' && s[j+1]=='B') ans++;
        }
            if(s[0]=='B' && s.back()=='A') c++;
            else if(s[0]=='B') b++;
            else if(s.back()=='A') a++;
    }

    if(c==0){
        ans += min(a, b);
    }else{  
        if(a+b>0) ans += c + min(a, b);
        else ans += c-1;
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    while(N != 0){
        vector<int> cnt(26,0);
        bool fin = false;
        for(int i=1; i<=N; i++){
            char now;
            cin >> now;
            if(fin) continue;
            cnt[now-'A']++;
            int mx=0,mx_id=-1;
            for(int j=0; j<26; j++){
                if(chmax(mx,cnt[j])){
                    mx_id = j;
                }
            }
            int mx2=0;
            for(int j=0; j<26; j++){
                if(j == mx_id) continue;
                chmax(mx2,cnt[j]);
            }
            if(mx > mx2 + N-i){
                cout << char(mx_id+'A') << " " << i << endl;
                fin = true;
            }
            
        }
        if(!fin){
            cout << "TIE" << endl;
        }
        cin >> N;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define  _(x)  cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v)  (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps=1e-6;
long long gcd(long long a, long long b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main() {

    int n, m, l;
    cn n;
    ct n*n*n,nl;







    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;
typedef pair<long double, lint> pa;

lint N, K, A;
lint arr[200001];

bool func(long double k) {
	lint cnt = 0;
	REP(i, N) {
		cnt += (arr[i] - 1) / k;
	}
	return cnt <= K;
}

int main() {
	cin >> N >> K;
	REP(i, N) {
		cin >> arr[i];
	}
	long double lb = 1, ub = 1e9 + 1;
	REP(_, 100){
		long double mid = (lb + ub) / 2;
		if (!func(mid)) lb = mid;
		else ub = mid;
	}
	if (func((lint)ub)) {
		cout << (lint)ub << endl;
	}
	else {
		cout << (lint)ub + 1 << endl;
	}
}

Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(10000) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n;
string s, t;

int rec(string v, int cnt){
    int id = n;
    for(int i=0;i<n;i++){
        if(v[i] != t[i]){
            id = i;
            break;
        }
    }
    if(id == n){
        return cnt;
    }
    int res = IINF;
    int d = (t[id] - v[id] + 10)%10;
    for(int i=id;i<n;i++){
        v[i] = '0' + (v[i]+d-'0')%10;
        res = min(res, rec(v, cnt+1));
    }
    return res;
}


int main() {
    while(cin >> n, n){
        cin >> s >> t;
        cout << rec(s,0) << endl;
    }
    return 0;
}



Measured memory_bytes: 3056
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#define Lens 105
#define Inf -1<<21
using namespace std;
int N;
int a[Lens];
int main()
{
	cin >> N;
	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = N-1; j > i; j--)
		{
			if (a[j] < a[j - 1])
			{
				swap(a[j], a[j - 1]);
				sum++;
			}
		}
	}
	for (int i = 0; i < N; i++)
	{
		if (i > 0)
			cout << ' ';
		cout << a[i];
	}
	cout << endl;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;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){
  fspcnt = 0;
  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 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(){
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  bool dame = false;
  rep(i,n){
    if(a.at(i) % 2 == 0 && a.at(i) % 3 != 0 && a.at(i) % 5 != 0){
      dame = true;
    }
  }
  if(dame){
    cout << "DENIED" << endl;
  }else{
    cout << "APPROVED" << endl;
  }
      

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;
 
int main() {
	int n,mina=MOD;
	cin >> n;
	string s[52];
	REP(i,n) cin >> s[i];
	int cnt[26]={},cnt1=0;
	REP(i,26) cnt[i]=MOD;
	REP(i,26){
		REP(j,n){
			cnt1=0;
			REP(k,s[j].length()){
				if(s[j][k]=='a'+i) cnt1++;
			}
			cnt[i]=min(cnt[i],cnt1);
		}
	}
	REP(i,26){
      	if(cnt[i]!=MOD)
			REP(j,cnt[i]) cout << (char)('a'+i);
	}
	return 0;
}

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

int main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans;
    if(a >= k){
        ans = k;
    }
    else if(a+b >= k){
        ans = a;
    }
    else{
        ans = a - (k-a-b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    t = 1
    for c in a:
        if c == t:
            t += 1
    if t == 1:
        return -1

    return n - t + 1


print(main())





Measured memory_bytes: 28100
#include <iostream>

int inf = 1 << 28;

int dijk(int n,int s, int **g) {
	int sum = 0;
	bool *used = new bool[n];
	int *d = new int[n];

	// std::cout << "n = " << n << " " << "s = " << s << std::endl;

	for(int j=0;j<n;j++){
		for(int i=0;i<n;i++){
			std::cout << g[j][i] << ",";
		}
		std::cout << std::endl;
	}

	for(int i = 0; i < n; i++)
		d[i] = inf;
	d[s] = 0;

	while(true) {
		int u = -1;
		for(int v = 0; v < n; v++)
			if(!used[v] && (u == -1 || d[v] < d[u]))
				u = v;

		// std::cout << "u = " << u << std::endl;

		if(u == -1) break;
		used[u] = true;

		for(int v = 0; v < n; v++)
			if(d[v] > d[u] + g[u][v])
				d[v] = d[u] + g[u][v];
	}

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

	// for(int i = 0; i < n; i++) {
	// std::cout << d[i] << std::endl;
	// }

	return sum;
}

int main() {
	do {
		int **g; // adjacency matrix, ?
		int *d;
		int *a, *b, *c;
		int edge = 0, min = 0, max = 0;
		int tmp = 0;

		std::cin >> edge;
		if(!edge) break;

		a = new int[edge];
		b = new int[edge];
		c = new int[edge];

		for(int i = 0;i < edge;i++) {
			std::cin >> a[i];
			std::cin >> b[i];
			std::cin >> c[i];
		}

		for(int i = 0; i < edge; i++) {
			if(max < a[i])
				max = a[i];
		}
		for(int i = 0; i < edge; i++) {
			if(max < b[i])
				max = b[i];
		}
		max++;

		g = new int*[max];
		d = new int[max];

		for(int i = 0; i < max; i++) {
			g[i] = new int[max];
		}

		for(int i = 0; i < max; i++)
			for(int j = 0; j < max; j++)
				g[i][j] = inf;

		for(int i = 0; i < edge; i++)
			g[b[i]][a[i]] = g[a[i]][b[i]] = c[i];

		for(int i=0;i<max;i++){
			g[i][i]=0;
		}

		for(int k=0;k<max;k++){
			for(int j=0;j<max;j++){
				for(int i=0;i<max;i++){
					if(g[i][k]+g[k][j]<g[i][j]){
						g[i][j]=g[i][k]+g[k][j];
					}
				}
			}
		}

		//for(int i = 0; i < max; i++)
		//	d[i] = dijk(max, i, g);

		for(int i = 0; i < max; i++){
			d[i]=0;
			for(int j=0;j<max;j++){
				d[i] += g[i][j];
			}
		}

		min = d[0];
		for(int i = 1; i < max; i++) {
			if(min > d[i]) {
				min = d[i];
				tmp = i;
			}
		}

		std::cout << tmp << " " << min << std::endl;
		for(int i = 0; i < max; i++)
			delete[] g[i];
		delete[] g;
		delete[] a;
		delete[] b;
		delete[] c;
		delete[] d;

	}while(true);
	return 0;
}

Measured memory_bytes: 0
n, m =map(int,input().split())
A = list(map(int,input().split()))
BC = [tuple(map(int,input().split()))for i in range(m)]

A.sort()
# 書き換え得点がでかい順に並べる
BC.sort(key= lambda x : -x[1])

i = 0
f=0
for b, c in BC:
    for j in range(b):
      # 見てるとこがはみ出してないかつ、cより小さい
      if i+j<n and A[i+j]<c:
        A[i+j]=c
      else: # もう走査しても意味ないからぶれーく
        break
    i+=b
print(sum(A))

Measured memory_bytes: 25192
#include<stdio.h>
int main(){
  int n,r,l,id,t,p,s=0,mi=1,max=0;
  int i,j;
  scanf("%d %d %d",&n,&r,&l);
  int d[100002][2]={0};
  for(i=0;i<r;i++){
    scanf("%d %d %d",&id,&t,&p);
    d[id][0]+=p;
    d[mi][1]+=t-s;
    s=t;
    if(p>0){
      if(max<d[id][0]){
	max=d[id][0];
	mi=id;
      }
      else if(max==d[id][0]&&mi>id)mi=id;
    }
    else{
      if(id==mi){
	max=d[1][0];
	mi=1;
	for(j=2;j<=n;j++){
	  if(max<d[j][0]){
	    max=d[j][0];
	    mi=j;
	  }
	}
      }
    }
    /*for(j=0;j<n;j++)printf("\t%d",d[j+1][0]);
    printf("\n");
    for(j=0;j<n;j++)printf("\t%d",d[j+1][1]);
    printf("\n\n");*/
  }
  d[mi][1]+=l-s;
  max=d[1][1];
  mi=1;//printf("\t%d",d[1][1]);
  for(i=2;i<=n;i++){//printf("\t%d",d[i][1]);
    if(max<d[i][1]){
      max=d[i][1];
      mi=i;
    }
  }
  printf("%d\n",mi);
  return 0;
}

Measured memory_bytes: 1392
K = int(input())
N = 50
a = [N-1] * N
for _ in range(K % N):
    a.sort()
    for p in range(N):
        if a[p] + N >= a[N - 1] - 1:
            for i in range(N):
                if i == p:
                    a[i] += N
                else:
                    a[i] -= 1
            break
for i in range(N):
    a[i] += K // N
print(N)
print(" ".join(map(str, a)))

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

int main() {
  int x, y;
  cin >> x >> y;
  for (int c = 0; c <= x; c++) {
    int t = x - c;
    int asi = c*2 + t*4;
    if (asi == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void) {
	int n, m;
	int taro[101], hana[101], ans[2];
	int t_sum, h_sum, min;

	while (1) {
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0) break;

		t_sum = h_sum = 0;
		for (int i = 0; i < n; i++) {
			scanf("%d", &taro[i]);
			t_sum += taro[i];
		}
		for (int j = 0; j < m; j++) {
			scanf("%d", &hana[j]);
			h_sum += hana[j];
		}

		min = 1000*1000;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if ((t_sum - taro[i] + hana[j]) == (h_sum - hana[j] + taro[i]) ){
					if (taro[i] + hana[j] < min) {
						min = taro[i] - hana[j];
						ans[0] = taro[i];
						ans[1] = hana[j];
					}
				}
			}
		}

		if (min == 1000 * 1000) {
			printf("-1\n");
			continue;
		}
		printf("%d %d\n", ans[0], ans[1]);
	}//endwhile
	return 0;
}


Measured memory_bytes: 1976
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 17
using namespace std;

int n, a[N][N];
long long c[1 << N], f[1 << N];

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            scanf("%d", &a[i][j]);
    for (int S = 0; S < (1 << n); ++S)
        for (int i = 0; i < n; ++i) if ((S >> i) & 1)
            for (int j = i + 1; j < n; ++j) if ((S >> j) & 1)
                c[S] += a[i][j];
    for (int S = 0; S < (1 << n); ++S)
        for (int T = S; T; T = (T - 1) & S) {
            f[S] = max(f[S], f[S ^ T] + c[T]);
        }
    cout << f[(1 << n) - 1];
    return 0;
}


Measured memory_bytes: 1280
# -*- coding: utf-8 -*-
import re
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def is_match(a, b):
    for _a, _b in zip(a, b):
        if (_a == _b or _a == '?'):
            continue
        else:
            return False
    return True


s = S()
t = S()

# s = s.replace('?', '.')
# pattern =   ''

if (t in s):
    print(s.replace('?', 'a'))
    exit()
if (len(s) < len(t)):
    print('UNRESTORABLE')
    exit()


if (is_match(s[-len(t):], t)):
    ans = s[:-len(t)] + t
    ans = ans.replace('?', 'a')
    print(ans)
    exit()
i = 0

for _s in reversed(s[len(t)-1:-1]):
    i += 1
    if (_s == t[-1] or _s == '?'):
        if (is_match(s[-i - len(t): - i], t)):
            ans = s[:-i - len(t)] + t + s[-i:]
            ans = ans.replace('?', 'a')
            print(ans)
            exit()


print('UNRESTORABLE')


Measured memory_bytes: 27232
package main

import "fmt"

func main() {
	var n string
	fmt.Scan(&n)

	for i := 0; i < pow(2, 3); i++ {
		sum := int(n[0] - '0')
		for j := 0; j < 3; j++ {
			if i>>uint(j)&1 == 1 {
				sum += int(n[j+1] - '0')
			} else {
				sum -= int(n[j+1] - '0')
			}
		}

		if sum == 7 {
			ops := make([]string, 3)
			for j := 0; j < 3; j++ {
				if i>>uint(j)&1 == 1 {
					ops[j] = "+"
				} else {
					ops[j] = "-"
				}
			}

			fmt.Printf("%d%s%d%s%d%s%d=7\n", n[0]-'0', ops[0], n[1]-'0', ops[1], n[2]-'0', ops[2], n[3]-'0')
			return
		}
	}
}

func pow(n, m int) (result int) {
	result = 1
	for i := 0; i < m; i++ {
		result *= n
	}
	return
}


Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	var w, h, x, y int
	fmt.Scanf("%d %d %d %d", &w, &h, &x, &y)

	ans1 := (float64(w) * float64(h)) / 2
	ans2 := 0

	if w == x*2 && h == y*2 {
		ans2 = 1
	}
	fmt.Printf("%v %v", ans1, ans2)
}


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

int main() {
	int N;
	std::cin >> N;
	std::string stone;
	std::cin >> stone;

	int count_R = 0;
	for (int i = 0; i < N; i++){
		if (stone[i] == 'R') {
			count_R++;
		}
	}

	int answer = 0;
	if (count_R == 0) {
		std::cout << 0 << std::endl;
		return 0;
	}
	for (int i = 0; i < count_R; i++) {
		if (stone[i] == 'W') {
			answer++;
		}
	}
	std::cout << answer << std::endl;
	return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
#define int long long
int rv[30];
struct node{
  int id,left,right,par;
  node(){par=-1;}
};
node t[30];
void dfs(int v,int p){
  if(p==0){
    cout<<" "<<t[v].id;
    if(~t[v].left)  dfs(rv[t[v].left ],p);
    if(~t[v].right) dfs(rv[t[v].right],p);
  }
  if(p==1){
    if(~t[v].left)  dfs(rv[t[v].left ],p);
    cout<<" "<<t[v].id;
    if(~t[v].right) dfs(rv[t[v].right],p);
  }
  if(p==2){
    if(~t[v].left)  dfs(rv[t[v].left ],p);
    if(~t[v].right) dfs(rv[t[v].right],p);
    cout<<" "<<t[v].id;
  }
}
signed main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++) cin>>t[i].id>>t[i].left>>t[i].right;
  for(int i=0;i<n;i++) rv[t[i].id]=i;
  for(int i=0;i<n;i++){
    //cout<<t[i].id<<":"<<t[i].left<<":"<<t[i].right<<endl;
    if(~t[i].left)  t[rv[t[i].left ]].par=t[i].id;
    if(~t[i].right) t[rv[t[i].right]].par=t[i].id;
  }
  for(int i=0;i<n;i++){
    if(t[i].par==-1){
      cout<<"Preorder"<<endl;
      dfs(i,0);
      cout<<endl;
      cout<<"Inorder"<<endl;
      dfs(i,1);
      cout<<endl;
      cout<<"Postorder"<<endl;
      dfs(i,2);
      cout<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3096
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
INF = 10 ** 20

def dfs(graph, root, n):
    dista = [INF for i in range(n)]
    visited = [0 for i in range(n)]
    dista[root - 1] = 0
    visited[root - 1] = 1
    d = deque()
    for edge in graph[root - 1]:
        d.append(edge)
    while(d):
        cur, nxt = d.pop()
        if not visited[nxt]:
            dista[nxt] = dista[cur] + 1
            visited[nxt] = 1
            for edge in graph[nxt]:
                d.append(edge)

    return dista

def dfs2(graph, root, n, dista):
    distb = [INF for i in range(n)]
    visited = [0 for i in range(n)]
    visited[root - 1] = 1
    distb[root-1] = 0
    d = deque()
    ans = dista[root-1]
    dec = 0
    # print(dista, distb)
    for edge in graph[root-1]:
        d.append(edge)
    while(d):
        # print(d)
        # print(distb)
        cur, nxt = d.pop()
        if not visited[nxt]:
            if distb[cur] + 1 <= dista[nxt]:
                if distb[cur] + 1 == dista[nxt]:
                    dec = 1
                visited[nxt] = 1
                distb[nxt] = distb[cur] + 1
                for edge in graph[nxt]:
                    d.append(edge)
                if ans < dista[nxt]:
                    ans = dista[nxt]

            # print(ans, cur, nxt, visited)

    return ans

def main():
    n, u, v = getList()
    graph = [[] for i in range(n)]
    dista = [INF for i in range(n)]
    distb = [INF for i in range(n)]
    for i in range(n-1):
        a,b = getList()
        graph[a-1].append((a-1, b-1))
        graph[b - 1].append((b-1, a - 1))
    # print(graph)
    if n == 3:
        print(1)
        return
    dista = dfs(graph, v, n)
    # print(dista)
    print(dfs2(graph, u, n, dista) - 1)
if __name__ == "__main__":
    main()



Measured memory_bytes: 73720
x = int(input())
p = x - 1
prime = False

if x == 2:
    print(2)
else:
    while prime == False:
        p += 1
        prime = True
        
        for i in range(2, p - 1):
            if p % i == 0:
                prime = False
                break
            
    print(p)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

double dp[111][3][3];
int const dx[]={1,0,0,-1};
int const dy[]={0,1,-1,0};

bool ok(int x, int y, int b){
    return 0<=x&&x<3&&0<=y&&y<3 && x*3+y!=b;
}

int main(){
    int n;;
    while(cin>>n && n){
        char s,t,b;
        cin>>s>>t>>b;
        memset(dp,0,sizeof(dp));
        int S=s-'A';
        int T=t-'A';
        int B=b-'A';
        dp[0][S/3][S%3]=1;
        rep(i,n){
            rep(x,3)rep(y,3){
                rep(d,4){
                    int nx=x+dx[d];
                    int ny=y+dy[d];
                    if(!ok(nx,ny,B)) dp[i+1][x][y]+=dp[i][x][y]/4;
                    else dp[i+1][nx][ny] += dp[i][x][y]/4;
                }
            }
        }
        printf("%.10lf\n",dp[n][T/3][T%3]);
    }
}

Measured memory_bytes: 1180
#include <stdio.h>

int main(void){

	int n;
	scanf("%d\n",&n);
	int a[n];
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}

	int max,min;
	long long sum=0;
	max=a[0];
	min=a[0];
	for(int j=0;j<n;j++){

		if(max<a[j]){
			max=a[j];
		}
		if(min>a[j]){
			min=a[j];
		}
		sum=sum+a[j];

	}

	printf("%d %d %ld\n",min,max,sum);

	return 0;

}

Measured memory_bytes: 1864
#include<iostream>
using namespace std;
int main()
{
    float d,s,t;
    cin>>d>>s>>t;
    float an=d/s;
    if(an<=t)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3720
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

int n;

vector <int> v[MAXN];
vector <pii> edge;

map <pii,int> col;

void paint(int node, int parent , int color)
{
	int tcol = 1;
	for (int i = 0; i < v[node].size(); ++i)
	{
		int child = v[node][i];
		if(child == parent) continue;
		
		if(tcol == color) tcol++;
		col[{node,child}] = tcol;
		col[{child,node}] = tcol;

		paint(child, node, tcol);
		tcol++;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	for (int i = 0; i < n-1; ++i)
	{
		int a,b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
		edge.pb({a,b});
	}

	//  node, parent , parent-edgecolor 
	paint(1,0,-1);

	int ans = 0;
	for (int i = 0; i < edge.size(); ++i)
		ans = max(ans, col[edge[i]]);

	cout << ans << endl;
	for (int i = 0; i < edge.size(); ++i)
		cout << col[edge[i]] << endl;

}

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

using Lint=long long;

int main()
{
   int N,K; cin>>N>>K;
   int R,S,P; cin>>R>>S>>P;
   string T; cin>>T;

   vector<int> cntR(N+1),cntS(N+1),cntP(N+1);
   for(int i=0;i<N;i++){
      cntR[i+1]=cntR[i]+(T[i]=='r');
      cntS[i+1]=cntS[i]+(T[i]=='s');
      cntP[i+1]=cntP[i]+(T[i]=='p');
   }

   auto score=[&](char c1,char c2)
   {
      if(c1=='r' and c2=='s') return R;
      if(c1=='s' and c2=='p') return S;
      if(c1=='p' and c2=='r') return P;
      return 0;
   };

   vector<int> dpR(N+1),dpS(N+1),dpP(N+1);
   int ans=0;
   for(int i=0;i<K;i++){
      dpR[i]=score('r',T[i]);
      dpS[i]=score('s',T[i]);
      dpP[i]=score('p',T[i]);
      int j=i+K;
      for(;j<N;j+=K){
         dpR[j]=max(dpS[j-K],dpP[j-K])+score('r',T[j]);
         dpS[j]=max(dpR[j-K],dpP[j-K])+score('s',T[j]);
         dpP[j]=max(dpR[j-K],dpS[j-K])+score('p',T[j]);
      }
      j-=K;
      ans+=max({dpR[j],dpS[j],dpP[j]});
   }
   cout<<ans<<endl;
   return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  ll A,B; cin >> A >> B;
  if(B%A==0){
    cout << B+A << endl;
  } else {
    cout << B - A << endl;
  }
}


Measured memory_bytes: 3528
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
#include <float.h>
using namespace std;


int main() {
	int x, y, z, count;
	cin >> x >> y >> z;
	count = (x - z) / (y + z);
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
int dx[] = {0 , 0 , 1 , -1 , 1 , 1 , -1 , -1};
int dy[] = {1 ,-1 , 0 , 0 , -1 , 1 ,  1 , -1};


int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n , x , y;
   cin >> n >> x >> y;
   vector<int> cnt(n);
   for(int i = 1 ; i <= n ; ++i){
      for(int j = i + 1 ; j <= n ; ++j){
         int sp = min(j - i , abs(x - i) + abs(y - j) + 1);
         cnt[sp]++;
      }
   }
   for(int i = 1 ; i < n ; ++i)
      cout << cnt[i] << '\n';

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int q = in.nextInt();
			int[] p = new int[n];
			int[] rank = new int[n];

			for (int i = 0; i < n; i++) {
				makeSet(p, rank, i);
			}

			for (int i = 0; i < q; i++) {
				int command = in.nextInt();
				int x = in.nextInt();
				int y = in.nextInt();
				if (command == 0) {
					unite(p, rank, x, y);
				} else if (command == 1) {
					if (isSame(p, x, y)) {
						out.println("1");
					} else {
						out.println("0");
					}
				}
			}
		}
	}

	static void makeSet(int[] p, int[] rank, int x) {
		p[x] = x;
		rank[x] = 0;
	}

	static boolean isSame(int[] p, int x, int y) {
		return findSet(p, x) == findSet(p, y);
	}

	static void unite(int[] p,int[] rank, int x, int y) {
		link(p, rank, findSet(p, x) ,findSet(p, y));
	}

	static void link(int[] p, int[] rank, int x, int y) {
		if (rank[x] > rank[y]) {
			p[y] = x;
		} else {
			p[x] = y;
			if (rank[x] == rank[y]) {
				rank[y]++;
			}
		}
	}

	static int findSet(int[] p, int x) {
		if (x != p[x]) {
			p[x] = findSet(p, p[x]);
		}
		return p[x];
	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}



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

int main() {
  string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  cout << (s < t ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<stack>
#include<string>
using namespace std;

#if 0

#endif

int main(){
  string word;
  stack<int> S;

  while(cin >> word){
    if(word == "+"){
      int a = S.top();
      S.pop();
      int b = S.top();
      S.pop();
      S.push(a+b);
    } else if (word == "-"){
      int a = S.top();
      S.pop();
      int b = S.top();
      S.pop();
      S.push(b-a);
    } else if (word == "*"){
      int a = S.top();
      S.pop();
      int b = S.top();
      S.pop();
      S.push(a*b);
    } else{
      S.push(stoi(word));
    }
  }
  cout << S.top() << endl;
}



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


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

int main(){
  int n; cin >> n;
  long long x, y; x = y = 1;
  for (int i = 0; i < n; i++) {
    long long a, b; cin >> a >> b;
    long long p = max((x-1)/a, (y-1)/b);
    x = (p+1) * a; y = (p+1) * b;
    //cout << x << "\t" << y << endl;
  }
  cout << x + y << endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[allow(dead_code)]
pub const M: u64 = 1_000_000_007;

fn main() {
    input! {
        n: usize,
        a: [u64;n+1]
    }

    let mut l = 0;
    let mut r = 0;
    let mut hmap = std::collections::HashMap::new();
    for i in 0..n+1 {
        if let Some(&src) = hmap.get(&a[i]) {
            l = src;
            r = i;
            break;
        }
        hmap.insert(a[i], i);
    }

    let all_comb = comb_series((n+1) as u64, M);
    let dup_comb = comb_series((l+n-r) as u64, M);
    for i in 0..n+1 {
        let dup = if dup_comb.len() > i {dup_comb[i]} else {0};
        let mut ret = (all_comb[i+1] as i64 - dup as i64) % M as i64;
        if ret < 0 {
            ret += M as i64;
        }
        println!("{}" ,ret);
    }
}

#[doc = " a / b modulo m == a * modinv(b, m) % m"]
#[allow(dead_code)]
fn modinv(a_: u64, m_: u64) -> u64 {
    let m = m_ as i64;
    let mut a = a_ as i64;
    let mut b = m as i64;
    let mut u = 1;
    let mut v = 0;
    while b != 0 {
        let t = a / b;
        a -= t * b;
        std::mem::swap(&mut a, &mut b);
        u -= t * v;
        std::mem::swap(&mut u, &mut v);
    }
    u %= m;
    if u < 0 {
        u += m
    };
    u as u64
}
#[doc = " nC0 ... nCn mod m"]
#[allow(dead_code)]
fn comb_series(n: u64, m: u64) -> Vec<u64> {
    let mut ret = vec![];
    let mut comb = 1;
    for i in 0..n + 1 {
        ret.push(comb);
        comb = comb * (n - i) % m * modinv(i + 1, m) % m;
    }
    ret
}



Measured memory_bytes: 12696