akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

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

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

    map<pair<int, int>,int> m;
    rep(i,n){
        int x, y, w;
        cin >> x >> y >> w;
        m[make_pair(x,y)] = w;
    }

    int maxi = 0;
    for(auto it:m){
        rep(j,4){
            int sum = m[ make_pair(it.first.first, it.first.second) ];
            rep(i,3){
                if(m.count(make_pair(it.first.first + dx[i] * mx[j], it.first.second + dy[i] * my[j]))){
                    sum += m[ make_pair(it.first.first + dx[i] * mx[j], it.first.second + dy[i] * my[j]) ];
                }
            }
            maxi = max(maxi, sum);
        }
    }
    cout << maxi << " / 1" << endl;
}

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

int main() {
  int N;
  int s1, s2, s3, s4;
  cin >> N;
  
  s4 = N/1000;
  s3 = (N-s4*1000)/100;
  s2 = (N-s4*1000-s3*100)/10;
  s1 = N%10;
  
  if ((s1==s2 && s2==s3) || (s2==s3 && s3==s4)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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; }
 
 const ll MOD = ll(1e9) +7;
ll dp[2][13];

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

    string S;
    cin >> S;

    rep(i, S.size())
    {
        FILL0(dp[(i+1)%2]);

        if(i==0)
        {
            if(S[i]!='?')
            {
                dp[(i+1)%2][(S[i]-'0')%13]=1;
            }
            else
            {
                rep(k, 10)
                {
                    dp[(i+1)%2][k%13]=1;
                }
            }
            continue;
        }

        rep(j, 13)
        {
            if(S[i]!='?')
            {
                dp[(i+1)%2][(j*10+S[i]-'0')%13]+=dp[i%2][j];  //13sinnsuu
                dp[(i+1)%2][(j*10+S[i]-'0')%13]%=MOD;
            }
            else
            {
                rep(k, 10)
                {
                    dp[(i+1)%2][(j*10+k)%13]+=dp[i%2][j];
                    dp[(i+1)%2][(j*10+k)%13]%=MOD;
                }
            }
            
        }
    }
    
    cout << dp[S.size()%2][5] << endl;

 

 

    return 0;
}
 

//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find



Measured memory_bytes: 512
#include <stdio.h>
int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if ((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5))
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

Measured memory_bytes: 128
# ＤＦＳ, パターン列挙_竹'n'本の使用パターン
'''
from collections import deque

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

queue = deque([[0],[1],[2],[-1]]) # 初期化_ここでは竹の使用パターン4つを設置
ptns = [] # パターン候補の器_初期化
 
while queue: # stackが空になるまでループ
    tmp = queue.pop() # パターンの候補を pop
    if len(tmp) == n: # 条件に合えば append
        ptns.append(tmp)
    elif len(tmp) < n: # 条件に合わなければ...
        w = tmp + [0] # パターンの候補を作成して...
        x = tmp + [1] # 〃
        y = tmp + [2] # 〃
        z = tmp + [-1]
        queue += [w, x, y, z]  # 積む

#print(ptns) # 竹の使用パターン

ans = 10**9
for i in range(len(ptns)):
    if 0 not in ptns[i] or 1 not in ptns[i] or 2 not in ptns[i]:
        continue
    abc = [0, 0, 0, -30]
    for j in range(n):
        tmp = ptns[i][j]
        if tmp >= 0:
            abc[tmp] += l[j]
            abc[3] += 10
    mp = abc[3]
    mp += abs(abc[0] - a)
    mp += abs(abc[1] - b)
    mp += abs(abc[2] - c)
    ans = min(ans, mp)

print(ans)

'''
# パターン列挙と探索を並行して処理

from collections import deque

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

queue = deque([[0],[1],[2],[-1]])

ans = 10**9
while queue:
    tmp = queue.pop()
    if len(tmp) == n:
        if 0 not in tmp or 1 not in tmp or 2 not in tmp:
            continue
        abc = [0, 0, 0, -30]
        for j in range(n):
            if tmp[j] >= 0:
                abc[tmp[j]] += l[j]
                abc[3] += 10
        mp = abc[3]
        mp += abs(abc[0] - a)
        mp += abs(abc[1] - b)
        mp += abs(abc[2] - c)
        ans = min(ans, mp)

    elif len(tmp) < n:
        w = tmp + [0]
        x = tmp + [1]
        y = tmp + [2]
        z = tmp + [-1]
        queue += [w, x, y, z]

print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int dp[s.size()+1];
	dp[0]=0;
	dp[1]=1;
	if(s[1]!=s[0])
		dp[2]=2;
	else
		dp[2]=1;
	for(int i=3;i<=s.size();i++)
	{
		if(s[i-1]!=s[i-2])
			dp[i]=dp[i-1]+1;
		else
			dp[i]=dp[i-3]+2;
	}
	cout<<dp[s.size()];
	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;
const ll INF = 1001001001;
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; }

int dp[5005][5005];

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  for(int i=n-1;i>=0;i--){
    for(int j=n-1;j>=0;j--){
      if(s[i]==s[j]) dp[i][j] = dp[i+1][j+1] + 1;
    }
  }
  int ans = 0;
  rep(i,n){
    rep(j,n){
      if(i>=j) continue;
      int ans1 = min(dp[i][j],j-i);
      ans = max(ans,ans1);
    }
  }
  cout << ans << endl;
  return 0;
  
}

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

using namespace std;
using ll = long long;

vector<int> dad, sizes;

void create(int n){
    dad.resize(n);
    sizes.assign(n, 1);
    for(int i = 0; i < n; i++)
        dad[i] = i;
}

int find_set(int u){
    return u == dad[u] ? (u) : (u = find_set(dad[u]));
}

void union_set(int u, int v){
    u = find_set(u);
    v = find_set(v);
    if(u != v){
        if(sizes[u] < sizes[v])
            swap(u, v);
        sizes[u] += sizes[v];
        dad[v] = u;
    }
}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    int i, n, m, j, u, v;
    cin >> n >> m;
    create(n);
    for(i = 0; i < m; i++){
        cin >> u >> v;
        u--; v--;
        union_set(u, v);
    }
    int ans = 0;
    for(i = 0; i < n; i++){
        ans = max(ans, sizes[find_set(i)]);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 4760
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint L;
string s, t;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> L;
	cin >> s >> t;
	if(t+s < s+t) swap(s, t);
	
	llint S = s.size(), T = t.size();
	string x, y;
	for(int i = 0; i <= L/S; i++){
		if((L-i*S)%T == 0){
			for(int j = 0; j < i; j++) x += s;
			for(int j = 0; j < (L-i*S)/T; j++) x += t;
			break;
		}
	}
	for(int i = L/S; i >= 0; i--){
		if((L-i*S)%T == 0){
			for(int j = 0; j < i; j++) y += s;
			for(int j = 0; j < (L-i*S)/T; j++) y += t;
			break;
		}
	}
	cout << min(x, y) << endl;
	
	return 0;
}

Measured memory_bytes: 1684
#include <iostream>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main()
{
    std::string str;
    std::cin>>str;
    int i,a,b;
    for(i=0;i<str.size();i++){
        if(str[i]=='A'){
            a = i;
            break;
        }
    }
    for(i=str.size()-1;i>=0;i--){
        if(str[i]=='Z'){
            b = i;
            break;
        }
    }
    std::cout<<b-a+1<<std::endl;
}


Measured memory_bytes: 3360
x1,x2,x3,x4,x5=map(int,input().split())
a=[]
a.append(x1)
a.append(x2)
a.append(x3)
a.append(x4)
a.append(x5)
for i in range(5):
    if a[i]==0:
        print(i+1)


Measured memory_bytes: 9012
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
struct node{
  struct node *prev;
  struct node *next;
  long key;
};
typedef struct node * NP;
NP MN(long);
void IN(NP);
void DN(NP);
void FI(long);
NP dummy;

int main(){
  long n,val;
  string op;

  scanf("%ld",&n);
  dummy = MN(0);
 
  while(n-- >0){
    cin >> op;
    scanf("%ld",&val);
    if(op == "insert"){
      IN(MN(val));
    }
    else{
      FI(val);
    }
  }

  for(NP n=dummy->next;n!=dummy;n = n->next){
    cout << n->key;
    if(n->next != dummy)printf(" ");
  }  
  printf("\n");

  return 0;
}


void FI(long value){
  NP n;
  dummy->key = value;
  for(n = dummy->next;;n=n->next){
    if(n->key == value)break;
  }
  if(n != dummy)DN(n);
    

}


void DN(NP th){
  th->prev->next = th->next;
  th->next->prev = th->prev;
  th->prev = th->next = th;
  free(th);
}


void IN(NP newn){
  newn->next = dummy->next;
  newn->next->prev = newn;
  dummy->next = newn;
  newn->prev = dummy;
}

NP MN(long key){
  NP n = (NP)malloc(sizeof(struct node));
  n->prev = n;
  n->next = n;
  n->key = key;
  return n;
} 

Measured memory_bytes: 16000
def main() :
    X,N = map(int,input().split())
    P_list = [int(i) for i in input().split()]
    P_set = set(P_list)

    # if (X not in P_set) :
    #     print(X)
    #     return

    distance = 0
    while(True) :
        ck = X - distance
        if (ck not in P_set) :
            print(ck)
            return
        
        ck = X + distance
        if (ck not in P_set) :
            print(ck)
            return
        
        distance += 1

main()

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

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORTASC(c) sort((c).begin(), (c).end())
#define SORTDESC(c, t) sort((c).begin(), (c).end(), std::greater<t>());
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

const double PI = acos(-1.0);

using ll = long long;
using namespace std;

int main()
{
    ll n, k;
    string s;

    cin >> n >> k >> s;

    if (s[k-1] == 'A'){
        s[k-1] = 'a';
    } else if (s[k-1] == 'B'){
        s[k-1] = 'b';
    } else {
        s[k-1] = 'c';
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
/*
    ALWAYS REMMEMBER:
        NEVER GIVE UP !
        DON'T MESS WITH ME !!!
        "" THE EXPERT IN ANYTHING WAS ONCE A BEGINNER ""
*/

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

void solve()
{
    ll n;
    cin >> n;
    if(n%2==0)
        cout << n/2 ;
    else 
        cout << n/2 +1 ;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	char s0[100], s1[200], s2[100];
	scanf("%s", s0);
	strcat(s1, s0);
	strcat(s1, s0);
	scanf("%s", s2);
	if(strstr(s1, s2) != NULL){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}	

Measured memory_bytes: 1784
#include <cstdio>
#include <algorithm>	
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int inf = 1e9 + 7; 
const int maxn = 2e5 + 5; 
LL b[maxn], d[maxn];

LL query(int p){
	LL res = 0;
	while(p > 0){
		res = max(b[p], res);
		p -= p & -p;
	}
	return res;
}

void add(LL x, int p){
	while(p < maxn){
		b[p] = max(b[p], x);
		p += p & -p;
	}
}	

LL w[maxn], h[maxn];
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	int n;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;

	for(int i = 0; i < n; ++i){
		cin >> h[i];
	}
	for(int i = 0; i < n; ++i){
		cin >> w[i];
	}
	for(int i = 0; i < n; ++i){
		d[i] = query(h[i]) + w[i];
		add(d[i], h[i]);
	}
	cout << *max_element(d, d + n) << endl;
	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long s1=0,s2=0;
	for(int i=1;i<=n;++i)
	{
		if(i%2==0)
		{
			s1++;	
		}	
		else
		{
			s2++;
		}
	}	
	cout<<s1*s2;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

bool count(int p,int q, vvi& input){
    int dist = 0;
    for(int i = 0; i < input[0].size(); i++){
        dist += (input[p][i] - input[q][i]) * (input[p][i] - input[q][i]);
    }

    if(static_cast<int>(sqrt(dist)) * static_cast<int>(sqrt(dist)) == dist){
        return true;
    }else{
        return false;
    }
}
int main(){
    int N,D; cin >> N >> D;
    vvi coordinates(N,vi(D));
    
    rep(i,N)rep(j,D) cin >> coordinates[i][j];

    int cnt = 0;
    rep(i,N) rep(j,N){
        if(count(i,j,coordinates)) cnt++;
    }

    cnt -= N;
    cnt /= 2;

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <cstring>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

typedef pair<int, int> P;

bool ps1(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first昇順
    return forall_a_in_P.first < forall_b_in_P.first;
}
bool ps2(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first降順
    return forall_a_in_P.first > forall_b_in_P.first;
}
bool ps3(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second昇順
    return forall_a_in_P.second < forall_b_in_P.second;
}
bool ps4(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second降順
    return forall_a_in_P.second > forall_b_in_P.second;
}


int main()
{
  int n;
  string p,q;
  cin>>n;
  rep(i,n){
      int num;
      cin>>num;
      stringstream ss;
      ss<<num;
      string tmp=ss.str();
      p+=tmp;
  }
  rep(i,n){
      int num;
      cin>>num;
      stringstream ss;
      ss<<num;
      string tmp=ss.str();
      q+=tmp;
  }
  vector<int>nu(n);
  rep(i,n){
      nu[i]=i+1;
  }
  deque<string>ans;
  do{
      string t;
      rep(i,n){
          stringstream ss;
          ss<<nu[i];
          t+=ss.str();
      }
      ans.push_back(t);

  }while(next_permutation(all(nu)));
  sort(all(ans));
  int a,b;
  rep(i,ans.size()){
      if(p==ans[i]){
          a=i;
      }
      if(q==ans[i]){
          b=i;
      }
  }
  cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int f(int x){
	string s=to_string(x);
	int ans=0;
	for(int i=0;i<s.size();i++){
		ans+=s[i]-'0';
	}
	return ans;
}
int main(){
	int n;
	cin>>n;
	if(n%f(n)==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n, a[52], cnt;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",a+i);
		if(a[i]==i)cnt++;
	}
	if(cnt==n||cnt==n-2) puts("YES");
	else puts("NO");
	return 0;
}

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

int main() {
  int p, ini_p;
  long long i = 0, candidate;

  cin >> candidate;
  cin >> p;
  while (candidate != 0) {
    int n[50] = {0};
    ini_p = p;
    for (i = 0; n[i%candidate] != ini_p; i++) {
      if (p == 0) {
        p = n[i%candidate];
        n[i%candidate] = 0;
      } else if (p > 0) {
        p--;
        n[i%candidate]++;
      }
      // cout << p << n[0] << n[1] << n[2] << endl;
    }
    cout << i % candidate << endl;
    cin >> candidate;
    cin >> p;
  }
  return 0;
}


Measured memory_bytes: 3036
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int k = Integer.parseInt(bf.readLine());
 		String input = bf.readLine();
 		if (input.length() <= k){
 			out.println(input);
 		}
 		else
 		{
 			
 			out.println(input.substring(0, k) + "...");
 		}
 				
 		out.close();
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25420
n, m=map(int, input().split())
a=list(map(int, input().split()))
d={1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
memo=[0]*(n+1)
memo[0]=0
memo[1]=-10**10
for i in range(2, n+1):
    res=-10**10
    for ai in a:
        if d[ai]>i:
            continue
        res=max(res, ai+memo[i-d[ai]]*10)
    memo[i]=res
print(memo[n])


Measured memory_bytes: 51292
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC172A
{
	class Program
	{
		static void Main(string[] args)
		{
			int s;

			int a = int.Parse(Console.ReadLine());

			s = a + a * a + a * a * a;

			Console.WriteLine(s);

		}
	}
}

Measured memory_bytes: 27520
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define inf 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n;
	cin>>n;
	int s;
	cin>>s;
	int a[n+1];
	int mo=998244353;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	int dp[3001]={};
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		for(int j=3000;j>=0;--j)
		{
			if(j-a[i]>=0)
				dp[j]=(dp[j]+dp[j-a[i]])%mo;
		}
		// cout<<i<<endl;
		dp[a[i]]+=i;
		dp[a[i]]%=mo;
		ans=(ans+(dp[s]))%mo;
	}
	cout<<ans;
	#ifdef ANIKET_GOYAL
		cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

int  N, K;

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

  cin >> N >> K;
  vi x(N);
  rep(i,N) cin >> x[i];
  int ans = INT_MAX;
  rep(i,N-K+1) {
    int j = i + K - 1;
    int ans2;
    if (x[i] > 0 && x[j] < 0 || x[i] < 0 && x[j] > 0) {
      ans2 = abs(x[i]) + abs(x[j]) + min(abs(x[i]), abs(x[j]));
    } else {
      ans2 = max(abs(x[i]), abs(x[j]));
    }
    ans = min(ans, ans2);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
n,m=map(int,input().split())
ac = [0] * n
wa = [0] * n

for i in range(m):
    p,s = map(str,input().split())
    p = int(p)
    if ac[p-1] != 1:
        if s == 'WA':
            wa[p-1] += 1
        elif s == 'AC':
            ac[p-1] += 1

for i in range(n):
    if ac[i] == 1:
        continue
    elif ac[i] == 0:
        wa[i] = 0
        
print(sum(ac),sum(wa))


Measured memory_bytes: 4596
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;

	bool is_ok = true;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != S[S.size() - i - 1]) is_ok = false;
	}

	for (int i = 0; i < (S.size() - 1) / 2; i++) {
		if (S[i] != S[(S.size() - 1) / 2 - i - 1])is_ok = false;
	}

	for (int i = (S.size() + 3) / 2; i < S.size(); i++) {
		if (S[i] != S[S.size() - i - 1])is_ok = false;
	}

	if (is_ok) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
  int n;
  cin >> n;
  int x[n];
  for(int i=0;i<n;i++) cin >> x[i];
  int ans[n+1];
  for(int i=0;i<n+1;i++) ans[i] = 0;
  for(int i=1;i<=n;i++){
    ans[i] = min(ans[max(i-1,0)]+abs(x[i-1]-x[max(i-2,0)]),ans[max(i-2,0)]+abs(x[i-1]-x[max(i-3,0)]));
  }
  cout << ans[n] << endl;
  return 0;
}
      
  


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

int main() 
{
	int a;
	cin >> a;
	vector<double>data(a);
	double bunbo = 0;
	for (int i = 0; i < a; i++)
	{
		cin >> data[i];
		bunbo = bunbo + (1.0 / data[i]);
	}


	cout << (1.0/bunbo)<< endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N;
vector<int>G[100005];
int dfs(int x,int p){
	int res=0;
	for(int i:G[x])if(i!=p){
		res^=dfs(i,x)+1;
	}
	return res;
}
signed main(){
	cin>>N;
	rep(i,N-1){
		int a,b;cin>>a>>b;a--;b--;
		G[a].pb(b);G[b].pb(a);
	}
	if(dfs(0,0))cout<<"Alice\n";
	else cout<<"Bob\n";
}


Measured memory_bytes: 10368
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<math.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
//小さい順
int compareInt(const void* a, const void* b){int aNum = *(int*)a;int bNum = *(int*)b;return aNum - bNum;}

long long _gcd(long long a,long long b){
    long long c;
    while(b!=0){c=a%b;a=b;b=c;}
    return a;
    
}
long long _lcm(long long a,long long b){long long c=_gcd(a,b);a/=c;return a*b;}

int main(void){
    int N;
    long long sum=0;
    scanf("%d",&N);
    int a[N+1],b[N];
    for(int i=0;i<=N;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<N;i++){
        scanf("%d",&b[i]);
    }
    for(int i=0;i<N;i++){
        if(a[i]>=b[i]){
            sum+=b[i];
        }else if(b[i]<=(a[i]+a[i+1])){
            sum+=b[i];
            a[i+1]-=(b[i]-a[i]);
        }else{
            sum+=a[i]+a[i+1];
            a[i+1]=0;
        }
    }
    printf("%lld",sum);
}
    


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VEC;

int main() {
  int N;cin>>N;
  if (N == 0) {
    OUT("0");
    return 0;
  }

  string ans;
  while (N) {
    if (N%2==0) {
      ans.push_back('0');
    } else {
      ans.push_back('1');
      N--;
    }
    N /= -2;
  }
  reverse(ALL(ans));
  OUT(ans);

  return 0;
}

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

using namespace std;

int main() {
    unordered_set<int> s;

    int d;
    cin >> d;

    for (int i = 0; i < d; i++) {
        int n;
        cin >> n;
        s.insert(n);
    }

    cout << s.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

string ans = "";
bool f(ll a){
    cout<<"? "<<ans<<a;
    rep(i, 15 - to_string(a).size() - ans.size()) cout<<9;
    cout<<endl;
    char c;
    cin>>c;
    return c == 'Y';
}
bool f2(ll a){
    cout<<"? "<<a<<endl;
    char c;
    cin>>c;
    return c == 'Y';
}

int main() {
    rep(i,9){
        if(f(4)){
            if(f(2)){
                if(f(1)) {
                    if(i == 0){
                        if(f2(1e+16)) {
                            ll temp = 9, re = 1;
                            while (!f2(temp)) {
                                re *= 10;
                                temp *= 10;
                                temp += 9;
                            }
                            cout <<"! "<< re << endl;
                            return 0;
                        }else{
                            ans.push_back('1');
                        }
                    }else{
                        ans.push_back(f(0) ? '0' : '1');
                    }
                }else{
                    ans.push_back('2');
                }
            }else{
                ans.push_back(f(3) ? '3' : '4');
            }
        }else{
            if(f(7)){
                if(f(6)){
                    ans.push_back(f(5) ? '5' : '6');
                }else{
                    ans.push_back('7');
                }
            }else{
                ans.push_back(f(8) ? '8' : '9');
            }
        }
    }
    ll temp = 10, re = 1;
    while (f2(temp)) {
        ++re;
        temp *= 10;
    }
    cout<<"! "<<ans.substr(0, re)<<endl;
}

Measured memory_bytes: 656
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int N;

/*Thanks AshishGup for the below Segment Tree Implementation.*/
struct node{
    int mn;
    node():mn(N){};
};

struct SegTree
{
    int n;
    vector<node> st;
    vector<bool> cLazy;
    vector<int> lazy;

    SegTree(int _n){
        n=_n;
        st.resize(4*n + 5);
        cLazy.assign(4*n + 5, false);
        lazy.assign(4*n + 5, N);
    }

    void merge(node &cur,node &lChild,node &rChild){
        cur.mn=min(lChild.mn,rChild.mn);
    }

    int leftIndex(int i){return 2*i+1;}
    int rightIndex(int i){return 2*i+2;}
    
    void propagate(int index,int l,int r){
        if(l!=r){
            int lindex=leftIndex(index);
            int rindex=rightIndex(index);
            cLazy[lindex]=1;
            cLazy[rindex]=1;
            lazy[lindex]=min(lazy[index],lazy[lindex]);
            lazy[rindex]=min(lazy[index],lazy[rindex]); 
        }
        st[index].mn=min(st[index].mn,lazy[index]);
        cLazy[index]=0;
    }

    void build(int index,int l,int r){
        if(l==r){
            st[index].mn = N;
            return;
        }
        int mid=(l+r)/2;
        int lindex=leftIndex(index);
        int rindex=rightIndex(index);
        build(lindex,l,mid);
        build(rindex,mid+1,r);
        merge(st[index],st[lindex],st[rindex]);
    }

    node query(int index,int l,int r,int pos){
        if(cLazy[index])    propagate(index,l,r);
        if(l==r)            return st[index];
        int mid=(l+r)/2;
        int lindex=leftIndex(index);
        int rindex=rightIndex(index);
        if(pos<=mid)    return query(lindex,l,mid,pos);
        else            return query(rindex,mid+1,r,pos);
    }   

    node query(int pos){return query(0,0,n-1,pos);}

    void update(int index,int l,int r,int ql,int qr,int val){
        if(cLazy[index])    propagate(index,l,r);
        if(qr<l || ql>r)    return;

        if(ql<=l && r<=qr){
            cLazy[index]=1;
            lazy[index]=val;
            propagate(index,l,r);
            return;
        }
        int mid=(l+r)/2;
        int lindex=leftIndex(index);
        int rindex=rightIndex(index);

        update(lindex,l,mid,ql,qr,val);
        update(rindex,mid+1,r,ql,qr,val);
        merge(st[index],st[lindex],st[rindex]);
    }
    void update(int l,int r,int val){update(0,0,n-1,l,r,val);}
};

main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE    
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout); 
    #endif

    ll n,q;cin>>n>>q;
    N=n-1;
    SegTree s1(n),s2(n);
    s1.build(0,0,n-1);
    s2.build(0,0,n-1);

    ll ans=0;
    for(int i=0;i<q;i++){
        int type,x;cin>>type>>x;
        x--;

        if(type==1){
            int end=s1.query(x).mn;
            ans+=end;       //-1
            s2.update(0,end-1,x);
        }else{
            int end=s2.query(x).mn;
            ans+=end;       //-1
            s1.update(0,end-1,x);
        }
        // cout<<ans-i-1<<"\n";
    }
    cout<<(n-2)*(n-2)-ans+q<<"\n";
}       

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

int main(){
     int n; cin>>n;
     n=2*n;
    
     int ans=0;
     int A[n];
     for(int i=0;i<n;i++)cin>>A[i];
    
     sort(A, A+n);

     int i=0;
     if(n%2)i=1;
     for(;i<n;i+=2){
          ans+=A[i];
     }
     cout<<ans;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	x := nextInt()
	switch x {
	case 7, 5, 3:
		fmt.Println("YES")
	default:
		fmt.Println("NO")
	}
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];



int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22){
        cout<<"bust"<<endl;
    }
    else{
        cout<<"win"<<endl;
    }
}


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

int main() {
	ll n,t=0,ans=100;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		while(a[i]>0 && a[i]%2==0){
			a[i]/=2;
			t++;
		}
		ans=min(ans,t);
		t=0;
	}
	cout << ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

vector<int> v[100010];
int main() {
    ll N, K;
    vector<ll> p(3);
    string T;
    cin >> N >> K;
    rep(i,3)cin >> p[i];
    cin >> T;
    vector<int> vt(N,-1);
    rep(i,N){
        if(T[i] == 'r')vt[i] = 0;
        if(T[i] == 's')vt[i] = 1;
        if(T[i] == 'p')vt[i] = 2;
    }
    rep(i,N)v[i%K].emplace_back(vt[i]);
    ll ans = 0;
    rep(i,N){
        auto t = v[i];
        int M = t.size();
        if(M == 0)break;
        // この配列についてdp
        vvec<ll> dp(M+1, vec<ll>(3,0));
        rep(j,M)rep(a,3)rep(b,3){
            // j => k
            if(a == b)continue;
            int kati = (b + 1) % 3;
            if(t[j] == kati){
                chmax(dp[j+1][b], dp[j][a] + p[b]);
            }
            else{
                chmax(dp[j+1][b], dp[j][a]);
            }
        }
        ans += *max_element(all(dp[M]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 12180
#include<stdio.h>
#define N 500001

int A[N],H;

int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

void maxHeapify(int i){
  int l,r,t,largest;
  l=left(i);
  r=right(i);
  if(l<=H&&A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=H&&A[r]>A[largest])
    largest=r;

  if(largest!=i){
    t=A[i];
    A[i]=A[largest];
    A[largest]=t;
    maxHeapify(largest);
  }
  }


void buildMaxHeap(){
  int i;
  for(i=H/2;i>=1;i--){
    maxHeapify(i);
}
}


int main(){
 int i;

  scanf("%d",&H);
  
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  buildMaxHeap();

  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}



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

int main() {
	int h, w, d;
	cin >> h >> w >> d;
	vector<pair<int, int>> p(h * w);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int a;
			cin >> a;
			p[a - 1] = make_pair(i, j);
		}
	}
	vector<int> m(h * w);
	for (int i = d; i < h * w; i++) {
		m[i] = m[i - d] + abs(p[i].first - p[i - d].first) + abs(p[i].second - p[i - d].second);
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		cout << m[r - 1] - m[l - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		
		int[][] arr=new int[n][3];
		
		for(int i=0;i<n;i++)
		{
			arr[i][0]=s.nextInt();
			arr[i][1]=s.nextInt();
			arr[i][2]=s.nextInt();
		}
		
		int[][] dp=new int[n][3];
		
		dp[0][0]=arr[0][0];
		dp[0][1]=arr[0][1];
		dp[0][2]=arr[0][2];
		
		for(int i=1;i<n;i++)
		{
			for(int j=0;j<3;j++)
			{
				if(j==0)
				{
					dp[i][0]=Math.max(dp[i-1][1]+arr[i][0],dp[i-1][2]+arr[i][0]);
				}
				else if(j==1)
				{
					dp[i][1]=Math.max(dp[i-1][2]+arr[i][1],dp[i-1][0]+arr[i][1]);
				}
				else
				{
					dp[i][2]=Math.max(dp[i-1][1]+arr[i][2],dp[i-1][0]+arr[i][2]);
				}
			}
		}
		
		System.out.println(Math.max(dp[n-1][2],Math.max(dp[n-1][0],dp[n-1][1])));
	}
	
}

Measured memory_bytes: 98676
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,Z,W;
  cin >> N >> Z >> W;
  ll a[2010];
  ll score=abs(Z-W);
  for(int i=1;i<=N;i++){
    cin >> a[i];
  }
  if(N==1){
    cout << abs(a[1]-W) << endl;
    return 0;
  }
  score=max(abs(a[N]-W),abs(a[N-1]-a[N]));
  cout << score << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int H,W,K;
string A[805];
int f[805][805];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int main(){
	cin >> H >> W >> K;
	P st;
	for(int i=0;i<H;i++){
		cin >> A[i];
		for(int j=0;j<W;j++){
			f[i][j]=INF;
			if(A[i][j]=='S'){
				st = P(i,j);
			}
		}
	}
	f[st.fi][st.sec]=0;
	queue<T> q;
	q.push(T(st,0));
	while(!q.empty()){
		T a = q.front();
		q.pop();
		int x = a.fi.fi, y = a.fi.sec;
		int v = a.sec;
		if(f[x][y]<v)continue;
		for(int d=0;d<4;d++){
			int nx = x+dx[d];
			int ny = y+dy[d];
			if(nx<0||nx>=H||ny<0||ny>=W)continue;
			if(A[nx][ny]=='#')continue;
			if(f[nx][ny]<=v+1)continue;
			//cout << nx << ' ' << ny  << ' ' << v+1 << endl;
			f[nx][ny]=v+1;
			q.push(T(P(nx,ny),v+1));
		}
	}
	/*for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(f[i][j]!=INF)cout << f[i][j];
			else cout << '*';
		}
		cout << endl;
	}*/
	int ans = INF;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(f[i][j]>K)continue;
			int d = INF;
			d = min(i,H-1-i);
			d = min(d,j);
			d = min(d,W-1-j);
			if(d==0)ans = 1;
			else{
				ans = min(ans,(d-1)/K+2);
			}
		}		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 10000000007; //10^9+7

bool dp[4001][16001];
int x,y,tx,ty,ax[4001],ay[4001];

void dfsx(int t,int n){
  if(dp[t][n+8000])return ;
  if(t<tx){
    dfsx(t+1,n+ax[t]);
    dfsx(t+1,n-ax[t]);
  }
  dp[t][n+8000]=1;
}

void dfsy(int t,int n){
	if(dp[t][n+8000]) return;
	if(t<ty){
		dfsy(t+1,n+ay[t]);
		dfsy(t+1,n-ay[t]);
	}
	dp[t][n+8000]=1;
}

int main()
{
	string s;
	cin>>s>>x>>y;
	bool fx=1;
	for(int i=0;i<s.length();i++){
		if(s[i]=='F'){
			if(fx) ax[tx]++;
			else ay[ty]++;
		}
		else{
			if(fx) fx=0,tx++;
			else fx=1,ty++;
		}
	}
	if(s[s.length()-1]=='F'){
		if(fx) tx++;
		else ty++;
	}
	dfsx(1,ax[0]);
	bool xx=dp[tx][8000+x]?1:0;
	memset(dp,0,sizeof(dp));
	dfsy(0,0);
	bool yy=dp[ty][8000+y]?1:0;
	if(xx&&yy) cout<<"Yes";
	else cout<<"No";
}

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

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

    string ans = "";
    while (N) {
        N--;
        ans += 'a' + (N % 26);
        N /= 26;
    }
    reverse(ans.begin(), ans.end());

    cout << ans << endl;
}

Measured memory_bytes: 3644