akhauriyash/Code-Regression huggingface dataset:
#define max(a,b) ((a)>(b)?(a):(b))
int lcs[1002][1002];

int main(){
  char a[1002],b[1002];
  int i,j,_a,_b;scanf("%d",&i);
  while(~scanf("%s%s",a+1,b+1)){
    memset(lcs,0,sizeof(lcs));
    _a=strlen(a+1);_b=strlen(b+1);
    for(i=1;i<=_a;i++)
      for(j=1;j<=_b;j++)
        lcs[i][j]=max(max(lcs[i-1][j],lcs[i][j-1]),lcs[i-1][j-1]+(a[i]==b[j]));
    printf("%d\n",lcs[_a][_b]);
  }
  exit(0);
}

Measured memory_bytes: 4540
#include <iostream>


int main() {
    int N, M;
    std::cin >> N >> M;

    for (int i = 0; i < M; i++) {
        int a;
        std::cin >> a;
        N -= a;
    }

    if (N < 0) {
        std::cout << -1 << std::endl;
    } else {
        std::cout << N << std::endl;
    }

}


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


//It’s just pathetic to give up on something before you even give it a shot.
//Knowing you’re different is only the beginning. If you accept these differences you’ll be able to get past them and grow even closer.
//You can die anytime, but living takes true courage.
//Every journey begins with a single step. We just have to have patience.
//Life is not a game of luck. If you wanna win, work hard.
//It’s more important to master the cards you’re holding 
//than to complain about the ones your opponent was dealt.
//If you just submit yourself to fate, then that’s the end of it.
//Whatever you do, enjoy it to the fullest. That is the secret of life.
//I too will obtain everything that I desire. Not because someone asked me to do it, 
//but because I know in my heart that I have something worth fighting for.


#define ps push_back
#define le length
#define in insert
#define vint vector<int>
#define vlld vector<long long int>
#define pii pair<int,int>
#define mk make_pair
#define vst vector<string>
#define lld long long int 
#define FAST ios_base::sync_with_stdio(false),cin.tie(NULL)

int main()
{
	double L ;
	cin>>L;
	L /= (double)3;
	L *= (L*L);
	cout << fixed << setprecision(10) << L;
	return 0;
}

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

void solve(long long N, long long K, std::vector<long long> a, std::vector<long long> b) {
    vector<ll> bucket(1e5 + 1);
    rep(i, N) { bucket[a[i]] += b[i]; }

    ll prevcnt = 0;
    for (ll i = 1; i < 1e5 + 1; i++) {
        if (prevcnt < K && K <= prevcnt + bucket[i]) {
            cout << i << endl;
            return;
        } else {
            prevcnt += bucket[i];
        }
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
        scanf("%lld", &b[i]);
    }
    solve(N, K, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 5568
s = input()
t = input()

ls = len(s)
lt = len(t)

if ls < lt:
    print('UNRESTORABLE')
    exit()
anslist = []
for i in range(ls-lt+1):
    flag = True
    for j in range(lt):
        if s[i+j] != '?' and s[i+j] != t[j]:
            flag = False
    if flag:
        anslist.append(i)
if anslist:
    i = max(anslist)
    x = s[:i] + t + s[i+lt:]
    print(x.replace('?','a'))
else:
    print('UNRESTORABLE')

Measured memory_bytes: 61980
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int n,q,l,r,num;
  string s,t;
  cin >> n >> q;
  cin >> s;
  vector<int> a={};
  for(int i=0;i<n-1;i++){
    t=s.substr(i,2);
    if(t=="AC")
      a.push_back(i);
  }
  num=a.size();
  decltype(a)::iterator le,ri;
  size_t pos;
  for(int i=0;i<q;i++){
    cin >> l >> r;
    le=lower_bound(a.begin(),a.end(),l-1);
    ri=lower_bound(a.begin(),a.end(),r-1);
    pos=distance(le,ri);
    cout << pos << endl;
  }
  return 0;
}

Measured memory_bytes: 1276
using System;

namespace SmallLargeEqual
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a, b;
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);

            if (a < b)
                Console.WriteLine("a < b");
            else if (a > b)
                Console.WriteLine("a > b");
            else
                Console.WriteLine("a == b");
        }
    }
}

Measured memory_bytes: 5288
// D - Flat Subsequence
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/segtree>
int op(int a, int b){ return max(a,b); } // 処理
int e(){ return 0; } // 単位元
using MONOID = int;
using SEG_T = atcoder::segtree<MONOID, op, e>;

int main(){
	int n, k; cin>>n>>k;
	int SEGT_MAX = 0;
	vector<int> A(n); for(auto& a:A){
		cin>>a;
		SEGT_MAX = max(SEGT_MAX, a);
	}
	SEGT_MAX++;
	SEG_T seg(SEGT_MAX);
	int ans = 0;
	for(int& a:A){
		int l = max(0, a - k);
		int r = min(a + k + 1, SEGT_MAX);
		int longest = seg.prod(l, r); // [l,r)
		seg.set(a, longest + 1);
		ans = max(ans, longest + 1);
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 9600
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;

int main() {
  string a,b; cin >> a >> b;
  string num = a + b;
  int n = atoi(num.c_str());
  bool f = false;
  for ( int i = 1; i <= 1000; i++ ) {
    if ( i*i == n ) {
      f = true;
      break;
    }
  }
  if(f)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
/*	ex3_2
	L40S38	*/
#include<stdio.h>
int main(void){
  int N, r;
  scanf("%d",&N);
  //Nはいろはちゃんが数えようとしている数（本）
  r=N%10;//rはNの1の位の数
  if(r==3){
      printf("bon");
  }else if(r==0||r==1||r==6||r==8){
      printf("pon");
  }else{
      printf("hon");
  }
  return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>
#include <list>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;




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

    int n; cin>>n;
    vi p(n*n);
    for (int & i : p) cin>>i;

    vector<vi> _mp(n, vi(n));

    for (int i=0; i<n*n; ++i){
        int c = p[i]-1;
        _mp[c/n][c%n] = i;
    }
    const vector<vi> mp = _mp;

    vector<vi> ans(n, vi(n, INT_MAX));

    deque<pii> bfs;

    auto push = [&](pii pos, int len, bool back){
        if (ans[pos.first][pos.second] > len){
            if (back) bfs.push_back(pos);
            else bfs.push_front(pos);
            ans[pos.first][pos.second] = len;
        }
    };

    for (int i=0; i<= n-1; i++){
        for (int j=0; j<=n-1; j ++){
            int a = min(i, j);
            int na = min(n-1-i, n-1-j);
            ans[i][j] = min(a, na) +1;
        }
    }
    int res = 0;
    vector<vi> dirs({{0,1}, {0,-1}, {-1,0}, {1,0}});

    for (int i=0; i<n*n; ++i){
        int c = p[i]-1;
        res += ans[c/n][c%n]-1;
        ans[c/n][c%n]--;
        queue<pii> bfs;
        bfs.push({c/n, c%n});

        int cur = mp[c/n][c%n];

        while(!bfs.empty()){
            pii pos = bfs.front(); bfs.pop();
            for (vi &dir : dirs){
                int nx = pos.first + dir[0];
                int ny = pos.second + dir[1];
                int len = ans[pos.first][pos.second];
                if (nx >=0 && nx <n && ny>=0 && ny < n){
                    if (mp[nx][ny] < cur){
                        if (ans[nx][ny] > len){
                            ans[nx][ny] = len;
                            bfs.push({nx, ny});
                        }
                    } else {
                        if (ans[nx][ny] > len+1){
                            ans[nx][ny] = len+1;
                            bfs.push({nx, ny});
                        }
                    }
                }
            }
        }

    }


//    while(!bfs.empty()){
//        pii pos = bfs.front(); bfs.pop_front();
//        for (vi dir : dirs){
//            int nx = pos.first + dir[0];
//            int ny = pos.second + dir[1];
//            int len = ans[pos.first][pos.second];
//            if (nx >=0 && nx <n && ny>=0 && ny < n){
//                if (mp[nx][ny] < mp[pos.first][pos.second]){
//                    push({nx, ny}, len+1, 1);
//                } else {
//                    push({nx, ny}, len, 0);
//                }
//            }
//        }
//    }

//    int res = 0;
//    for (vi & va : ans){
//        for (int i : va) res += i;
//    }
    cout<<res;


}


Measured memory_bytes: 7120
N = int(input())
ans = 0
if N < 105:
  print(0)
else:
  for i in range(1,N+1):
    if i%2 == 1:
      cnt = 0
      for j in range(1,i+1):
        if i%j == 0:
          cnt += 1
      if cnt == 8:
        ans += 1
  print(ans)

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

using namespace std;

#define ll long long


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

    int n;
    cin >> n;

    string ans = "APPROVED";

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 0 && (a % 3 != 0 && a % 5 != 0)) {
            ans = "DENIED";
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli ans=0,n;
    cin>>n;
    vvi a(n+1,vi(3)),dp(n+1,vi(3));
    char ch;
    rep(i,n) cin>>a[i][0]>>a[i][1]>>a[i][2];
    rep(i,3) dp[0][i]=a[0][i];
    for(int i=1;i<n;i++){
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    ans=max(dp[n-1][1],dp[n-1][2]);
    ans=max(ans,dp[n-1][0]);
    out(ans);
}

Measured memory_bytes: 11136
#include<iostream>

using namespace std;

int main()
{
	int a,i,j;
	int card[4];
	int card2[20]={0};
	int flag=1;
	
	for(i=0;cin >> a;i++)
	{
		if(flag==0)
		{
			i=0;
			flag=1;
		}
		card2[a]=1;
		card[i]=a;
		if(i==2)
		{
			int rest;
			int ans=0;
			rest=20-(card[0]+card[1]);
			
			for(j=rest;j>0;j--)
			{
				if(card2[j]==0 && j<11)
					ans++;
			}
			
			if(ans>3)
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
			for(i=0;i<20;i++)
				card2[i]=0;
			flag=0;
		}
	}
}

Measured memory_bytes: 0
import sys

#+++++
	
def gcd(a,b):
	if a < b:
		a,b = b,a
	
	while b!=1:
		tt=a%b
		if tt==0:
			return b
		a,b=b,tt
		
	return b
	
def is_sosuu(v, pl):
	if v == 2:
		return True
	if v <= 1:
		return False
	for p in pl:
		if v %p==0:
			return False
	return True
	
def bbb(val):
	return int(val**(0.5))+1
	
def main():
	b , c = map(int, input().split())
	sk=gcd(b,c)
	
	#素因数分解。素数の数+1を出力
	ans=1
	sosuu_list=[]
	using=set()
	using.add(1)
	sss=sk
	for i in range(2,bbb(sss)+1):
		while sss % i == 0:
			sss = sss // i
			using.add(i)
			if bbb(sss) < i:
				using.add(sss)
				break
	using.add(sss)
	print(len(using))
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>

using namespace std;

int main()
{
	float D, T, S;
	cin >> D >> T >> S;
	
	if (D / S > T) cout << "No";
	else cout << "Yes";


	return 0;
}

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

typedef long long int ll;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    bool ok = true;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        
        if (x % 2 == 0)
        {
            if (x % 3 && x % 5)
            {
                ok = false;
                break;
            }
        }
    }
    
    if (ok)
        cout << "APPROVED\n";
    else
        cout << "DENIED\n";
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <algorithm>

typedef long long ll;
const ll MAXN = 1e6+5;

std::bitset<MAXN> is;
int pr[MAXN], primes = 0;
void sieve() {
  is[2] = true; pr[primes++] = 2;
  for (int i = 3; i < MAXN; i += 2) is[i] = 1;
  for (ll i = 3; i*i < MAXN; i += 2)
    if (is[i])
      for (ll j = i*i; j < MAXN; j += i)
        is[j]= 0;
  for (int i = 3; i < MAXN; i += 2)
    if (is[i])
      pr[primes++] = i;
}


ll N;

int main() {
  sieve();

  std::cin >> N;
  ll ans = 0;

  for (int i = 0; i < primes; ++i) {
    if (pr[i] > N)      break;
    int cnt = 0;
    while (N % pr[i] == 0) {
      cnt++;
      N /= pr[i];
    }
    for (int j = 1; j <= cnt; j++) {
      ans++;
      cnt -= j;
    }
  }
  if (N != 1)
    ans++;

  std::cout << ans << "\n";


  return 0;
}


Measured memory_bytes: 4072
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * メインクラス
 *
 */
public class Main {

	/**
	 * メインメソッド
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		// 標準入力を取得
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		long N = Long.parseLong(line);

		List<Long> ls = new ArrayList<Long>();
		line = br.readLine();
		for (String s : line.split(" ")) {
			ls.add(Long.valueOf(s));
		}
		Collections.sort(ls);

		long max = ls.get(ls.size() - 1);
		long others = 0;

		for (int i = 0; i < ls.size() - 1; i++) {
			others += ls.get(i);
		}

		if (max < others) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}	

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

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	string s, t; cin >> s >> t;
	for (int i = 0; i < n; ++i)
		cout << s[i] << t[i];
	cout << endl;
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int cnt=0;
  for(int i=0; i<S.size(); i++){
    if(S.at(i)=='x') cnt++;
  }
  if(cnt<=7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
#define ITEMS 104
#define WEIGHT 100008
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define forn(a,b,c) for(int a=b;a<c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
int n,s,w[ITEMS],v[ITEMS];
ll dp[ITEMS][WEIGHT], ans = 0;
ll value(int it, int wi)
{
    if(it >= n || wi <= 0)
        return 0;
    if(dp[it][wi] != -1)
        return dp[it][wi];
    if(w[it] > wi)
        return dp[it][wi] = value(it + 1, wi);
    return dp[it][wi] = max(value(it + 1, wi), v[it] + value(it + 1, wi - w[it]));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> s;
    forn(i,0,n)
    {
        cin >> w[i] >> v[i];
    }
    memset(dp, -1, sizeof(dp));
    ans = value(0,s);
    cout << ans;
    return 0;
}


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


template <typename T>
vector<T> dijkstra(const vector<vector<pair<int, T>>> &G, int source) {
    const T INF = numeric_limits<T>::max();
    using P = pair<T, int>;

    vector<T> dist(G.size(), INF);
    dist[source] = 0;

    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, source);

    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;

        for(auto edge : G[v]) {
            if(dist[edge.first] > dist[v] + edge.second) {
                dist[edge.first] = dist[v] + edge.second;
                que.emplace(dist[edge.first], edge.first);
            }
        }
    }

    return dist;
}

int main() {
    int N, M; cin >> N >> M;
    int r; cin >> r;
    vector<vector<pair<int, long long>>> G(N);
    for(int i=0; i<M; ++i) {
        int x, y; cin >> x >> y;
        long long d; cin >> d;
        G[x].emplace_back(y, d);
    }

    auto dist = dijkstra(G, r);
    for(int i=0; i<N; ++i) {
        if(dist[i] == numeric_limits<long long>::max()) cout << "INF\n";
        else cout << dist[i] << '\n';
    }
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    string s;
    cin >> s;
    for (char c : s) {
        if (c == '?') cout << 'D';
        else cout << c;
    }
    cout << '\n';
}

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

    solve();

    return 0;
}


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

int main(){
    unsigned long n,i;
    cin >> n;
    i=1;
    vector<unsigned long> table;
    while(i*i <= n){
        if(n%i == 0){
            table.emplace_back(i);
            table.emplace_back(n/i);
        }
        i += 1;
    }
    unsigned long sum = ULONG_MAX;
    for(int j=0; j<table.size(); j++){
        unsigned long tmp = n / table[j];
        sum = min(sum, tmp-1+table[j]-1);
    }
    cout << sum << endl;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){
  
  string s;
  cin >> s;
  string t = s;
  reverse(ALL(t));
  s == t ? cout << "Yes" << endl : cout << "No" << endl;




  return 0;
}

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

using namespace std;

typedef long long ll;

bool check(int x) {
  if(x == 1) return false;
  if(x == 2 or x == 3) return true;
  for(int i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}

int main() {
  int n; cin >> n;
  for(int i = n; ; i++) {
    if(check(i)) {
      cout << i << '\n';
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x, y;
	cin >> x >> y;
	if (x % y == 0) {
		dunk(-1);
		return 0;
	}
	ll time = 1;
	while (x * time <= 1e18) {
		x *= time;
		if (x % y != 0) {
			dunk(x);
			return 0;
		}
		time++;
	}
	dunk(-1);
	return 0;
}

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

int main(void) {

    int N;
    cin >> N;

    int L;
    int sum = 0;
    int max = 0;
    for (int i = 0; i < N; i++) {
        cin >> L;
        sum += L;
        if (max < L) {
            sum += max;
            max = L;
            sum -= L;
        }
    }

    if (sum > max) cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 3028
#include<cstdio>
using namespace std;
#define N 3050
int n,p,c[N][N],s[N][N];
int pw(int a,int b,int p){int as=1;while(b){if(b&1)as=1ll*as*a%p;a=1ll*a*a%p;b>>=1;}return as;}
int main()
{
	scanf("%d%d",&n,&p);
	for(int i=0;i<=n;i++)c[i][i]=c[i][0]=1;
	for(int i=2;i<=n;i++)
	for(int j=1;j<i;j++)
	c[i][j]=(c[i-1][j-1]+c[i-1][j])%p;
	s[1][1]=1;s[0][0]=1;
	for(int i=2;i<=n;i++)
	for(int j=1;j<=i;j++)
	s[i][j]=(1ll*j*s[i-1][j]+s[i-1][j-1])%p;
	int as=0;
	for(int i=0;i<=n;i++)
	{
		int tp=1ll*(i&1?p-1:1)*c[n][i]%p*pw(2,pw(2,n-i,p-1),p)%p;
		int s1=1,s2=pw(2,n-i,p);
		for(int k=0;k<=i;k++)
		as=(as+1ll*tp*(s[i][k]+1ll*s[i][k+1]*(k+1)%p)%p*s1)%p,s1=1ll*s1*s2%p;
	}
	printf("%d\n",as);
}//

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

#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//////////////////

#define int long long
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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 (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)

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

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

void solve(){
    string N;
    cin >> N;
    int t = 0;
    rep(i,N.size()){
        t += N[i]-'0';
    }
    if(t%9==0) Yes;
    else No;
}


signed main(){
    cout << fixed << setprecision(18);
//    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 3748
#include <stdio.h>
#include <string.h>

typedef struct{
  char a;
  int  num;
}data;

//バブルソートと比較し安定か安定じゃないか確かめる

int main(){
  data data[36],data1[36],data2[36],tmp_data;
  int i,j,n,minj,s=0,flag=0,flag2=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf(" %c %d",&data[i].a,&data[i].num);
    // printf("",data[i].a,data[i].num);
    data1[i]=data[i];
    data2[i]=data[i];
  }
  
  //for(i=0;i<n;i++)printf("%c%d  i=%d\n",data[i].a,data[i].num,i);

  //バブルソート
  flag =1;
  while(flag){
    flag =0;
    for(j=n-1;j>s;j--){
      //printf("hoge1\n"); 
      if(data1[j-1].num > data1[j].num){
	tmp_data = data1[j-1];
	data1[j-1] = data1[j];
	data1[j] = tmp_data;
	flag =1;
      }
     
    }
    s++;
  }
  
  for(i=0;i<n;i++){
    printf("%c%d",data1[i].a,data1[i].num);
    if(i!=n-1)printf(" ");
  }
  printf("\nStable\n");
  
      
  //セレクションソート
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){ //printf("hoge2\n"); 
      if(data2[j].num < data2[minj].num){
	minj =j;
      }
    }
    //printf("hoge3\n"); 
    tmp_data = data2[i];
    data2[i] = data2[minj];
    data2[minj] = tmp_data;
  }

  
  for(i=0;i<n;i++){
    printf("%c%d",data2[i].a,data2[i].num);
    if(i!=n-1)printf(" ");
    if(data1[i].a!=data2[i].a)flag2=1;
  }
  printf("\n");
  
  if(flag2==0)printf("Stable\n");
  else printf("Not stable\n");
  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, y;
  cin >> n >> y;
  for (int i = 0; i*10000 <= y; i++) {
    for (int j = 0; i*10000+j*5000 <= y; j++) {
      double k = (y-i*10000-j*5000)/1000.0;
      if (k == (int) k && i+j+(int)k == n) {
        cout << i << ' ' << j << ' ' << (int)k << endl;
        return 0;
      }
    }
  }
  cout << -1 << ' ' << -1 << ' ' << -1 << endl;
  return 0;
}

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

std :: set < int > cakes ;

int main ( )  {
	
	int n ;
	scanf ( "%d", & n ) ;
	
	for ( int i = 1 ; i <= n ; ++ i )  {
		static int r ;
		scanf ( "%d", & r ) ;
		cakes.insert ( r ) ;
	}

	return ! printf ( "%d\n", ( int ) cakes.size ( ) ) ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int main(){
	int N; cin >> N; 
	long long A[1010] = {}; 
	long long oddsum = 0; long long evensum = 0; 
	long long mx = -1000000007; 
	long long idx = -1; 
	bool pos[1010] = {}; 
	vector<int> odd, even, ans; 
	for(int i = 1; i <= N; i++) cin >> A[i]; 
	for(int i = 1; i <= N; i++){
		cin >> A[i]; 
		if(A[i] > mx){
			idx = i; mx = A[i]; 
		}
		if(A[i] >= 0) pos[i] = true; 
		if(i % 2 == 1&& A[i] >= 0){
			oddsum += A[i]; odd.push_back(i); 
		}
		else if(i % 2 == 0 && A[i] >= 0){
			evensum += A[i]; even.push_back(i); 
		}		
	}
	if(mx < 0){
		cout << mx << endl; 
		cout << N-1 << endl; 
		for(int i = N; i > idx; i--) cout << i << endl; 
		for(int i = 1; i < idx; i++) cout << 1 << endl; 
	}
	else if(oddsum >= evensum){
		cout << oddsum << endl; 
		for(int i = N; i > odd.back(); i--) ans.push_back(i); 
		for(int i = odd.back(); i >= odd.front(); i-= 2){
			if(!pos[i]) ans.push_back(i); 
		}
		for(int i = 1; i < odd.front(); i++) ans.push_back(1); 
		for(int i = 1; i < odd.size(); i++) ans.push_back(2); 
		cout << ans.size() << endl; 
		for(int i = 0; i < ans.size(); i++) cout << ans.at(i) << endl; 
	}
	else if(oddsum < evensum){
		cout << evensum << endl; 
		for(int i = N; i > even.back(); i--) ans.push_back(i); 
		for(int i = even.back(); i >= even.front(); i-= 2){
			if(!pos[i]) ans.push_back(i); 
		}
		for(int i = 1; i < even.front(); i++) ans.push_back(1); 
		for(int i = 1; i < even.size(); i++) ans.push_back(2); 
		cout << ans.size() << endl; 
		for(int i = 0; i < ans.size(); i++) cout << ans.at(i) << endl; 
	}  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second

using namespace std;

//int t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//cin>>t;
	//while(t--){}
	
	int n; cin>>n;
	vector<int> sub(n), bos(n);
	for(int i=1;i<n;i++){
		cin>>bos[i]; bos[i]--;
		sub[bos[i]]++;
	}
	for(int &s:sub)cout<<s<<"\n";

	return 0;	
}



Measured memory_bytes: 4772
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <iostream>
#include <algorithm>

using namespace std;

typedef vector<int> vi;
typedef long long ll;
#define pb push_back
#define pf push_front
#define siz(x) ((int)x.size())
#define rep(i,a,n) for (int i=(a);i<(n);++i)
#define per(i,a,n) for (int i=(n)-1;i>=(a);--i)

inline int read() {int x;scanf("%d",&x);return x;}

const int N=2e5+5;
const ll mod=1e9+7;

int n;

vi dep[N];
vi g[N];

void dfs0(int u,int h) {
  dep[h].pb(u);
  rep(i,0,siz(g[u])) {
    int v=g[u][i];
    dfs0(v,h+1);
  }
}

ll fac[N];

struct st {
  ll x0,x1,x2;
};

typedef deque<st> di;

di d[N];
int id[N];

void merst(di &a,di &b,int &ta,int &tb,int cnt) {
  if (siz(a)==0||siz(b)==0)  return;
  st x=a.front();a.pop_front();
  st y=b.front();b.pop_front();
  if (cnt==ta) ++ta,x.x0=(x.x0+x.x2)%mod,x.x2=0;
  if (cnt==tb) ++tb,y.x0=(y.x0+y.x2)%mod,y.x2=0;
  merst(a,b,ta,tb,cnt+1);
  st c;
  c.x0=x.x0*y.x0%mod;
  c.x1=(x.x0*y.x1%mod+x.x1*y.x0%mod)%mod;
  c.x2=(x.x0*y.x2%mod+x.x1*y.x2%mod+x.x2*y.x2%mod+x.x1*y.x1%mod+x.x2*y.x1%mod+x.x2*y.x0%mod)%mod;
  if (siz(a)>siz(b)) a.pf(c);
  else b.pf(c);
}

int tag[N];

void dfs(int u) {
  int t=n+1;
  rep (i,0,siz(g[u])) {
    int v=g[u][i];
    dfs(v);
    merst(d[t],d[id[v]],tag[t],tag[id[v]],0);
    if (siz(d[t])<siz(d[id[v]])) t=id[v];
  }
  if (t==n+1) t=u;
  st s;
  s.x0=s.x1=1,s.x2=0;
  id[u]=t;
  d[t].pf(s);
  tag[t]=0;
}

int main() {
  n=read();
  rep (i,0,n) g[read()].pb(i+1); ++n;
  fac[0]=1;
  rep (i,1,n+1) fac[i]=fac[i-1]*2ll%mod;
  dfs0(0,0);
  dfs(0);
  ll sum=0;
  di &s=d[id[0]];
  int now=0;
  while (!s.empty()) {
    ll k=s.front().x1;s.pop_front();
    sum+=fac[n-siz(dep[now])]*k%mod,sum%=mod,++now;
  }
  printf("%lld\n",sum);
  return 0;
}


Measured memory_bytes: 185600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <string>
#include <cmath>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long ll;
const int N = 2005;
const int MAX = 0x7ffffff;
const int mod = 1e9 + 7;

int n , k;
void slove()
{
	cin >> n >> k;
	ll a = 0;
	for(int i = k;i <= n + 1;i ++)
		a = (a + (ll)i * (n - i + 1) + 1) % mod;
	cout << a % mod << endl;
	return;
}
int main()
{
	SIS;
	slove();
	return 0;
}

Measured memory_bytes: 3692
#include<iostream>
#include<vector>
using namespace std;
bool p[50000];
int main(){
	for(int i=2;i*i<50000;i++)if(!p[i])for(int j=i+i;j<50000;j+=i)p[j]=1;
	vector<int> vp;for(int i=2;i<50000;i++)if(!p[i])vp.push_back(i);
	int m,a,b; while(cin>>m>>a>>b,m){
		int mp,mq,mx=0,area;
		for(int p=0;vp[p]*vp[p]<=m;p++)
		for(int q=p;(area=vp[p]*vp[q])<=m&&a*vp[q]<=b*vp[p];q++)
		if(area>mx)mx=area,mp=vp[p],mq=vp[q];
		cout<<mp<<" "<<mq<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

template<class T> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }


int main() {
    int N;  cin >> N;
    vector<int> A(N); rep(i, N) cin >> A[i];

    vector<int> B;
    B.pb(0);
    rep(i, N) B.pb(A[i]);
    B.pb(0);

    vector<int> diff;
    rep(i, N+1) diff.pb(B[i+1] - B[i]);

    int sum = 0;
    rep(i, N+1) sum += abs(diff[i]);

    vector<int> ans;
    rep(i, N) {
        int M = max(abs(diff[i]), abs(diff[i+1]));
        int m = min(abs(diff[i]), abs(diff[i+1]));
        if (diff[i] * diff[i+1] > 0) ans.pb(sum);
        else ans.pb(sum - m * 2);
    }

    rep(i, N) print(ans[i]);

    return 0;
}


Measured memory_bytes: 2936
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    long p = 1000000007;
    int N = Integer.parseInt(sc.nextLine());
    String[] S = sc.nextLine().split(" ");
    int r = 0, g = 0, b = 0;
    long ans = 1;
    for(int i = 0; i < N; i++){
      int M = Integer.parseInt(S[i]);
      int count = 0;
      if(r == M){
        count++;
      }
      if(g == M){
        count++;
      }
      if(b == M){
        count++;
      }
      ans *= count;
      ans %= p;
      if(r == M){
        r++;
      }else if(g == M){
        g++;
      }else if(b == M){
        b++;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 50832
N = int(input())
SI = list(input().split())
SB = SI.copy()

# bubble sort
for i in range(N):
	for j in range(N - 1, i, -1):
		if SB[j - 1][1] > SB[j][1]:
			x = SB[j - 1]
			SB[j - 1] = SB[j]
			SB[j] = x

# insertion sort
for i in range(N):
	ptr = i
	for j in range(i + 1, N):
		if SI[ptr][1] > SI[j][1]:
			ptr = j
	x = SI[i]
	SI[i] = SI[ptr]
	SI[ptr] = x

# print the answer!
for i in range(N):
	print(SB[i] + " " if i != N - 1 else str(SB[i]) + "\n", end='')
print("Stable")
for i in range(N):
	print(SI[i] + " " if i != N - 1 else str(SI[i]) + "\n", end='')
print("Stable" if SI == SB else "Not stable")



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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))
#define each(i, map) for (auto& i : map)

bool is_complete(const vector<int> &tmp, int &X)
{
    for (int i = 0; i < tmp.size(); ++i) {
        if (tmp[i] < X)
            return false;
    }
    return true;
}

int main()
{
    int N, M, X; cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M, 0));
    rep (i, 0, N) {
        cin >> C[i];
        rep (j, 0, M) {
            cin >> A[i][j];
        }
    }

    int ans = INF;
    for (int bit = 0; bit < (1 << N); ++bit) {
        int c = 0;
        vector<int> tmp(M, 0);
        for (int i = 0; i < N; ++i) {
            if (bit & (1 << i)) {
                for (int m = 0; m < M; ++m) {
                    tmp[m] += A[i][m];
                }
                c += C[i];
            }
        }
        if (is_complete(tmp, X))
            ans = min(ans, c);
    }

    if (ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

int main() {
	long long n, k, r, s, p;
	std::string t;

	std::cin >> n >> k >> r >> s >> p >> t;

	long long sum = 0;
	std::vector<int> v(k, -1);
	int pos = 0;

	for (size_t i = 0; i < n; i++)
	{
		if (v[pos] == -1) {
			if (t[i] == 'r') {
				sum += p;
				v[pos] = 2;
			}
			else if (t[i] == 's') {
				sum += r;
				v[pos] = 0;
			}
			else {
				sum += s;
				v[pos] = 1;
			}
		}
		else {
			if (t[i] == 'r') {
				if (v[pos] != 2) {
					sum += p;
					v[pos] = 2;
				}
				else {
					if (i + k < n) {
						if (t[i + k] == 'p') {
							v[pos] = 2;
						}
						else if (t[i + k] == 's') {
							v[pos] = 1;
						}
						else {
							v[pos] = 0;
						}
					}
				}
			}
			else if (t[i] == 's') {
				if (v[pos] != 0) {
					sum += r;
					v[pos] = 0;
				}
				else {
					if (i + k < n) {
						if (t[i + k] == 'p') {
							v[pos] = 2;
						}
						else if (t[i + k] == 's') {
							v[pos] = 1;
						}
						else {
							v[pos] = 0;
						}
					}
				}
			}
			else {
				if (v[pos] != 1) {
					sum += s;
					v[pos] = 1;
				}
				else {
					if (i + k < n) {
						if (t[i + k] == 'p') {
							v[pos] = 2;
						}
						else if (t[i + k] == 's') {
							v[pos] = 1;
						}
						else {
							v[pos] = 0;
						}
					}
				}
			}
		}
		pos++;
		if (pos >= k) pos = 0;
		//std::cout << sum << std::endl;
	}

	std::cout << sum << std::endl;

	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >>N;
	int x,y,z,a;
	x= N%10;
	y= N/10 % 10;
	z=N/100 %10;
	a=N/1000%10;

	if(x==y &&y==z){
		cout <<"Yes"<<endl;
	}
	else if(y==z && z==a){
		cout<<"Yes"<<endl;
		
	}
	else {
		cout <<"No"<<endl;
	
	}
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int d,n,ans=1;
	cin>>d>>n;
	FOR(i,0,d)ans*=100;
	if(n==100)n=101;
	cout<<ans*n;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if ((C + B - 1) / B <= (A + D - 1) / D) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

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

vector<ll> a;
ll m;
bool check(ll mid){
	ll cnt = 0;
	for(int val:a){
		cnt += (ll)(a.end() - lower_bound(a.begin(),a.end(),mid - val));
	}
	if(cnt >= m)return true;
	else return false;
}

int main(){
	int n;
	cin >> n;
	cin >> m;
	a.resize(n);
	for(int i = 0;i < n;i++)cin >> a[i];

	sort(a.begin(),a.end());

	//右手を選んで2分探索.
	//より小さいところではM回以上できることが保証される

	ll ng = 2 * 1e5 + 1;
	ll ok = 1;

	while(ng - ok > 1){
		ll mid = (ok + ng) / 2;
		if(check(mid)){
			ok = mid;
		}
		else ng = mid;
	}

	ll ans = 0;
	vector<ll> cnt(n,0);

	ll sum_cnt = 0;
	for(int i = 0;i < n;i++){
		auto p = lower_bound(a.begin(),a.end(),ok - a[i]);
		if(p != a.end()){
			sum_cnt += a.end() - p;
			cnt[p - a.begin()]++;
			ans += a[i] * (a.end() - p);
		} 
	}


	for(int i = 1;i < n;i++){
		cnt[i] += cnt[i-1];
	}
	for(int i = 0;i < n;i++){
		ans += cnt[i] * a[i];
	}
	if(sum_cnt > m)ans -= (sum_cnt - m) * ok;

	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    while (1) {
        int n;
        cin >> n;
        
        if (n == 0) return 0;
        
        int mx = 0;
        vector<int> ope, value[20];
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
            
            if (s.size() <= mx) {
                while (mx >= s.size()) {
                    int tmp;
                    if (ope[ope.size() - 1] == 1) {
                        tmp = 0;
                        while (!value[mx].empty()) {
                            tmp += value[mx][value[mx].size() - 1];
                            value[mx].pop_back();
                        }
                        value[mx - 1].push_back(tmp);
                    }
                    else {
                        tmp = 1;
                        while (!value[mx].empty()) {
                            tmp *= value[mx][value[mx].size() - 1];
                            value[mx].pop_back();
                        }
                        value[mx - 1].push_back(tmp);
                    }
                    ope.pop_back();
                    mx--;
                }
            }
            
            if (char(s[s.size() - 1]) == '+') {
                ope.push_back(1);  mx++;
            }
            else if (char(s[s.size() - 1]) == '*') {
                ope.push_back(2);  mx++;
            }
            else {
                value[s.size() - 1].push_back(int(s[s.size() - 1] - '0'));
            }
            
            if (i == n - 1) {
                while (mx != 0) {
                    int tmp;
                    if (ope[ope.size() - 1] == 1) {
                        tmp = 0;
                        while (!value[mx].empty()) {
                            tmp += value[mx][value[mx].size() - 1];
                            value[mx].pop_back();
                        }
                        value[mx - 1].push_back(tmp);
                    }
                    else {
                        tmp = 1;
                        while (!value[mx].empty()) {
                            tmp *= value[mx][value[mx].size() - 1];
                            value[mx].pop_back();
                        }
                        value[mx - 1].push_back(tmp);
                    }
                    ope.pop_back();
                    mx--;
                }
            }
            
        }
        
        for (int i = 0; i < value[0].size(); i++)
        cout << value[0][0] << endl;
        
    }
    
}



Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int MAX_N = 10010;
int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> A, dp(MAX_N, -INF);
int n, m;
int to_int(char ch) { return ch - '0'; }
void dfs(int sum, int pos, int digits)
{
    if(pos >= A.size()) return;
    if(dp[sum] > digits) return;
    dp[sum] = digits;
    dfs(sum, pos + 1, digits);
    if(sum + num[A[pos]] <= n) dfs(sum + num[A[pos]], pos, digits + 1);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    map<int, int> mp;
    for(int i = 0; i < m; i++)
    {
        int x; cin >> x;
        if(x > mp[num[x]]) mp[num[x]] = x;
    }
    for(auto x : mp) A.push_back(x.second);
    sort(A.begin(), A.end(), greater<int>());
    dfs(0, 0, 0);
    int digits = dp[n];
    string ans = "";
    while(n > 0)
    {
        if(digits == 0) break;
        for(int i = 0; i < A.size(); i++)
        {
            if(n - num[A[i]] < 0) continue;
            if(dp[n - num[A[i]]] == digits - 1)
            {
                ans += A[i] + '0';
                n -= num[A[i]];
                digits--;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A,B,C; cin>>A>>B>>C;
    if((A<= C && C<=B) || A >= C && C >= B)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }


}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n := scanInt(sc)
	results := map[string]int{}
	table := []string{"AC", "WA", "TLE", "RE"}
	for _ = range loop0(n) {
		results[scanString(sc)]++
	}
	for _, cat := range table {
		fmt.Printf("%s x %d\n", cat, results[cat])
	}
	return
}

func loop0(n int) chan int {
	return loop(0, n-1, 1)
}

func loop(s, e, d int) chan int {
	ch := make(chan int)
	go func() {
		for i := s; i <= e; i += d {
			ch <- i
		}
		close(ch)
	}()
	return ch
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2216