akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int min = 700000;
            int max = 0;
            for(int i = 0; i < S.Length; i++)
            {
                if (S.Substring(i, 1) == "A")
                {
                    min = Math.Min(min, i);
                }
                else if(S.Substring(i,1) == "Z")
                {
                    max = Math.Max(max, i);
                }
            }
            Console.WriteLine(max - min + 1);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


//Console.WriteLine(ans);


Measured memory_bytes: 35944
fun main(args: Array<String>) {
    readLine()
    var l = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    var nl = mutableListOf<Int>()
    var c = 0
    while(l.all{ it % 2 == 0}){
        nl = mutableListOf<Int>()
        c += 1
        l.forEach{nl.add(it / 2)}
        l = nl
    }
    println(c)
}


Measured memory_bytes: 36036
#include <stdio.h>

int main(void){
  int i, j, H, W;

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

    for(i = 0; i < H; i++){
      for(j = 0; j < W; j++){
        if(i % 2 == 0){
          if(j == W - 1){
            if(j % 2 == 0)
              printf("#");
            if(j % 2 == 1)
              printf(".");
            printf("\n");
            continue;
          }
          if(j % 2 == 0)
            printf("#");
          if(j % 2 == 1)
            printf(".");
        }
        if(i % 2 == 1){
          if(j == W - 1){
            if(j % 2 == 0)
              printf(".");
            if(j % 2 == 1)
              printf("#");
            printf("\n");
            continue;
          }
          if(j % 2 == 0)
            printf(".");
          if(j % 2 == 1)
            printf("#");
        }
      }
      if(i == H - 1)
        printf("\n");
    }
  }
  return 0;
}

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

const ll INF = 1e15;

int main() {
    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vector<ll> A(X+1); for (int i = 0; i < X; i++) cin >> A[i]; A[X] = -INF;
    vector<ll> B(Y+1); for (int i = 0; i < Y; i++) cin >> B[i]; B[X] = -INF;
    vector<ll> C(Z+1); for (int i = 0; i < Z; i++) cin >> C[i]; C[X] = -INF;
    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());
    map<vector<int>, bool> check;
    priority_queue<pair<ll, vector<int>>> q;
    q.push({A[0]+B[0]+C[0], {0, 0, 0}});
    for (int _ = 0; _ < K; _++) {
        pair<ll, vector<int>> t = q.top();
        q.pop();
        printf("%lld\n", t.first);
        int i = t.second[0];
        int j = t.second[1];
        int k = t.second[2];
        if (!check[{i+1, j, k}]) {
            check[{i+1, j, k}] = true;
            q.push({A[i+1] + B[j] + C[k], {i+1, j, k}});
        }
        if (!check[{i, j+1, k}]) {
            check[{i, j+1, k}] = true;
            q.push({A[i] + B[j+1] + C[k], {i, j+1, k}});
        }
        if (!check[{i, j, k+1}]) {
            check[{i, j, k+1}] = true;
            q.push({A[i] + B[j] + C[k+1], {i, j, k+1}});
        }
    }
}


Measured memory_bytes: 1408
from operator import itemgetter

n = int(input())
R = [list(map(int, input().split())) for i in range(n)]
B = sorted([list(map(int, input().split())) for _ in range(n)], key = itemgetter(0))
pair = 0

for b in B:
   L = [r for r in R if r[0] < b[0] and r[1]<b[1]]
   if len(L) != 0:
       s = L[0]
       for l in L:
           if s[1] < l[1]:
               s = l
       R.remove(s)
       pair += 1
           
print(pair)

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (N); i++)
#define rep2(i, j, N, M) rep(i, N) rep(j, M)
#define rep3(i, j, k, N, M, L) rep(i, N) rep(j, M) rep(k, L)
#define REP(i, init, N) for (int i = (init); i < (N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

constexpr int W = 5;
int H;
VVI ts;

int score;

bool can_remove(int y, int x0) {
    int c = ts[y][x0];
    if (c == 0) return false;

    int cnt = 0;

    REP(x, x0, W) {
        if (ts[y][x] != c) break;
        ++cnt;
    }

    return cnt >= 3;
}

void remove_ts(int y, int x0) {
    int c = ts[y][x0];

    REP(x, x0, W) {
        if (ts[y][x] == c) {
            score += ts[y][x];
            ts[y][x] = 0;
        } else {
            return;
        }
    }
}

void fall_down() {
    for (int y = H - 1; y >= 0; --y) {
        rep(x, W) {
            REP(y2, y + 1, H) {
                if (ts[y2][x] == 0) {
                    ts[y2][x] = ts[y2 - 1][x];
                    ts[y2 - 1][x] = 0;
                }
            }
        }
    }
}

bool remove_all_ts() {
    bool removed = false;

    rep2(y, x, H, W) {
        if (can_remove(y, x)) {
            remove_ts(y, x);
            removed = true;
        }
    }

    return removed;
}

void dump() {
    rep(y, H) {
        rep(x, W) {
            cout << ts[y][x] << " ";
        }
        cout << endl;
    }
}

int solve() {
    score = 0;

    while (remove_all_ts()) {
        fall_down();
    }

    return score;
}

int main(void) {
    while (cin >> H, H) {
        ts.clear();
        ts.resize(H, VI(W));

        rep2(y, x, H, W) {
            cin >> ts[y][x];
        }

        cout << solve() << endl;
    }

	return 0;
}

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

#define fi                      first
#define se                      second
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define pll                     pair< long long int, long long int> 
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x)                   ((int)x.size())

#define FOR(i,a,b)              for(int i = a; i < b; ++i)
#define REV(i,a,b)              for(int i = a; i >= b; --i)
#define FORE(i,a,b)             for(int i = a; i <= b; ++i)

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void solve();

int32_t main()
{
        fast;
        int t = 1;
        // cin >> t;
        for(int i = 1; i <= t; ++i)
                solve();
        cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}
map<string,int> mp;
std::vector<string> ans;
int n;

string k = "";

void f(int idx) {
        if(SZ(k) == n) {
                ans.pb(k);
                return;
        }
        for(int i = 0; i < idx; ++i) {
                k.pb((char)(i + 'a'));
                if(mp[k] == 0) {
                        f(idx);
                        mp[k] = 1;
                }
                k.pop_back();
        }
        k.pb((char)(idx + 'a'));
        f(idx + 1);
        k.pop_back();
        return;
}

void solve() {
        cin >> n;
        f(0);
        sort(all(ans));
        for(auto i:ans) {
                cout << i << endl;
        }
}

Measured memory_bytes: 17908
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    ll H,W,m;cin>>H>>W>>m;

    vec<ll> h(m), w(m);

    vec<ll> ch(H), cw(W);
    vec<vec<ll>> d(W);
    rep(i, m){
        cin>>h[i]>>w[i];
        h[i]--;w[i]--;
        ch[h[i]]++;
        cw[w[i]]++;
        dump(w[i], h[i]);
        d[w[i]].pb(h[i]);
    }
    dump(d);

    ll mw = 0;
    rep(j, 0, W){
        chmax(mw, cw[j]);
    }

    ll cnt_mw = 0;
    vec<ll> cnt(H);
    rep(j, 0, W){
        if (cw[j] == mw) {
            cnt_mw++;
            each(x, d[j]){
                dump(j, x);
                cnt[x]++;
            }
        }
    }
    dump(cnt);
    dump(cnt_mw);

    ll ans = 0;
    rep(i, H){
        ll res = ch[i] + mw;
        if (cnt_mw == cnt[i]) res--;
        chmax(ans, res);
    }
    cout << ans << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 31440
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(), _##i=(a).end(); i!=_##i; ++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(), _##i=(a).rend(); i!=_##i; ++i)
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define INF (int)1e9
#define EPS 1e-9
#define SYNC std::ios::sync_with_stdio(false)
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

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

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 1001001001;

int main(){
    int n, k;
    int v[51];
    
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> v[i];
    
    int lim = min(n, k);
    int max = -INF;
    for(int a = 0; a <= lim; a++){
        for(int b = lim - a; b >= 0; b--){
            vector<int> v2;
            for(int i = 0; i < a; i++) v2.push_back(v[i]);
            for(int i = n-1; i >= (n-b); i--) v2.push_back(v[i]);
            
            sort(v2.begin(), v2.end());
            int i;
            for(i = 0; i < k-(a+b); i++){
                if(i >= v2.size() || v2[i] >= 0) break;
            }
            int sum = 0;
            for(; i < v2.size(); i++) sum += v2[i];
            if(max < sum) max = sum;
        }
    }
    
    cout << max << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef pair<int,int> P;
typedef pair<P,int> Q;
#define fi first
#define sc second
int num[105],len[105];
int cnt[105][105];
int m,t,p,r;

int main(){
	while(1){
		cin>>m>>t>>p>>r;
		if(m == 0) return 0;
		rep(i,105)rep(j,105){
			num[i] = len[i] = cnt[i][j] = 0;
		}
		rep(i,r){
			int a,b,c,d; cin>>a>>b>>c>>d; b--;
			if(d != 0){
				cnt[b][c]++;
			}
			else{
				num[b]++;
				len[b] += a+cnt[b][c]*20;
			}
		}
		vector<Q>vec;
		rep(i,t) vec.push_back(Q(P(num[i],-len[i]),i));
		sort(vec.begin(),vec.end(),greater<Q>());
		for(int i=0;i<vec.size();i++){
			cout << vec[i].sc+1 ;
			if(i != vec.size()-1){
				if(vec[i].fi == vec[i+1].fi) cout << "=" ;
				else cout << "," ;
			}
		}
		cout << endl;
	}
}



Measured memory_bytes: 3176
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([a[i] - b[i] for i in range(n)])
k = sum(x < 0 for x in c)
neg = -sum(c[:k])
pos = c[len(c) - 1]

if sum(c) < 0:
  print(-1)
elif k == 0:
  print(0)
else:
  for i in range(n):
    if pos >= neg:
      print(k + i + 1)
      break
    else: pos += c[len(c) - 2 - i]

Measured memory_bytes: 18492
import sys

H, W, *A = map(int, sys.stdin.read().split())

ans = []
n = 0
ans_append = ans.append
for i in range(H*W-1):
    if i % W == W-1:
        continue
    if A[i] % 2:
        A[i+1] += 1
        n += 1
        ans_append(map(str, (i//W+1, i%W+1, (i+1)//W+1, (i+1)%W+1)))
for i in range(W-1, W*H-1, W):
    if A[i] % 2:
        A[i+W] += 1
        n += 1
        ans_append(map(str, (i//W+1, i%W+1, i//W+2, i%W+1)))

print(n)
print('\n'.join(' '.join(row) for row in ans))


Measured memory_bytes: 54080
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad
import Control.Monad.ST
import Debug.Trace

traceQ :: (Show a) => String -> a -> a
-- traceQ label a = trace (label ++ ": " ++ show a) a
traceQ _ a = a

traceZ :: String -> a -> a
-- traceZ = trace
traceZ _ a = a

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

solve :: Int -> Int -> [[Int]] -> Bool
solve valN valM lrds = runST (act valN valM lrds)

act :: Int -> Int -> [[Int]] -> ST s Bool
act valN valM lrds = do
  vec <- VM.new (valN+1)
  forM_ [1 .. valN] $ \i -> VM.write vec i (i, 0)
  act1 lrds vec

act1 :: [[Int]] -> VM.MVector s (Int, Int) -> ST s Bool
act1 [] _ = return True
act1 ([l,r,d]:lrds) vec = do
  b <- step l r d vec
  if b
    then act1 lrds vec
    else return False

step :: Int -> Int -> Int -> VM.MVector s (Int, Int) -> ST s Bool
step l r d vec = do
  (grpL, coordL) <- reGroup vec l
  (grpR, coordR) <- reGroup vec r
  if grpL == grpR
    then if coordL + d == coordR
         then return True
         else return False
    else do
         VM.write vec grpR (grpL, coordL + d - coordR)
         return True

reGroup :: VM.MVector s (Int, Int) -> Int -> ST s (Int, Int)
reGroup vec x = do
  (grp, coord) <- VM.read vec x
  if x == grp then return (grp, coord)
    else do
    (newGrp, newCoord) <- reGroup vec grp
    let newXVal = (newGrp, newCoord + coord)
    VM.write vec x newXVal
    return newXVal
        

main :: IO ()
main = do
  conts <- B.getContents
  let [valN, valM] : lrds = map bsReadInts (B.lines conts)
      answer = solve valN valM lrds
  putStrLn (if answer then "Yes" else "No")


Measured memory_bytes: 4220
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
	char n,h,w;
	int ans;

	scanf("%hhd",&n);
	scanf("%hhd",&h);
	scanf("%hhd",&w);

	ans = (n-h+1) * (n-w+1);

	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 128
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------

int main(void){
    int x, y;

    cin >> x >> y;

    cout << x + y / 2 << endl;
}



Measured memory_bytes: 256
#nの素数判定
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

X=int(input())

while(True):
    if is_prime(X):
        break
    X+=1

print(X)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int a = n % 10;
  int b = (n % 100 - a)/10;
  int c = (n % 1000 - 10*b - a)/100;
  int d = (n % 10000 - 100 * c - 10*b -a)/1000;
  if(a==b && b==c) cout << "Yes" << endl;
  else if(b==c && c==d) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3592
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = list(input())

    isWA = False
    if S[0] != 'A':
        isWA = True

    if S[2:-1].count('C') != 1:
        isWA = True

    for s in S:
        if s == 'A' or s == 'C':
            continue
        if s.isupper():
            isWA = True

    if isWA:
        print('WA')
    else:
        print('AC')
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.*;
import java.io.*;

import static java.lang.Character.isUpperCase;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        int[] C = new int[N-1];

        for(int i = 0; i < N; i++){
            A[i] = in.nextInt();
        }
        for(int i = 0; i < N; i++){
            B[i] = in.nextInt();
        }
        for(int i = 0; i < N-1; i++){
            C[i] = in.nextInt();
        }

        int totalAnswer = 0;
        for(int turn = 0; turn < N; turn++){
            // A[turn] => dish
            // 'dish' => B[dish] points milege

            int dish = A[turn];



            totalAnswer += B[dish-1];

            //Additionally Case
            int addition = 0;
            // jo hum abhi kha rahe h = A[turn] ---- i+1
            // isse pehle jo khayi = A[turn-1] --- i

            if(turn!=0 && A[turn-1] + 1 == A[turn]){
                totalAnswer+=C[(dish-1) - 1];
            }

        }
            System.out.println(totalAnswer);







        }







    }
















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

using namespace std;
using ll = long long;

int main() {
    vector<ll> mae(2005,2LL);
    mae[0]=0;
    for(int i = 1;i < 2005;++i) {
        mae[i]+=mae[i-1];
    }
    int n,K;
    cin>>n>>K;
    vector<pair<ll,int>> books;
    for(int i = 0;i < n;++i) {
        ll c;
        int g;
        cin>>c>>g;
        --g;
        books.emplace_back(c,g);
    }

    vector<vector<vector<ll>>> dp(2,vector<vector<ll>>(10,vector<ll>(n+1,0)));
    dp[0][books[0].second][1]=books[0].first;
    for(int i = 1;i < n;++i) {
        int dpind=i%2;
        int dppreind=1-dpind;
        for(int j = 0;j < 10;++j) {
            int k=1;
            while(k<=n&&dp[dppreind][j][k]!=0) {
                if(books[i].second==j) {
                    dp[dpind][j][k]=max(dp[dppreind][j][k],dp[dppreind][j][k-1]+books[i].first+mae[k-1]);
                }
                else {
                    dp[dpind][j][k]=dp[dppreind][j][k];
                }
                ++k;
            }
            if(books[i].second==j) {
                dp[dpind][j][k]=max(dp[dppreind][j][k],dp[dppreind][j][k-1]+books[i].first+mae[k-1]);
            }
            else {
                dp[dpind][j][k]=dp[dppreind][j][k];
            }
        }
    }

    int li=(n-1)%2;



    vector<vector<ll>> ep(10,vector<ll>(K+1,0));
    for(int i = 0;i <= K;++i) {
        ep[0][i]=dp[li][0][i];
    }

    for(int i = 1;i < 10;++i) {
        for(int j = 0;j <= K;++j) {
            ep[i][j]=ep[i-1][j];
        }
        for(int k = 1;k <= n;++k) {
            if(dp[li][i][k]==0)break;
            for(int j = 0;j <= K;++j) {
                if(j<k)continue;
                ep[i][j]=max(ep[i][j],ep[i-1][j-k]+dp[li][i][k]);
            }
        }

    }

    cout<<ep[9][K]<<endl;

    return 0;
}



Measured memory_bytes: 3380
#include <iostream>
#include <cmath>

using namespace std;

int main(void){

  double xa,ya,ra;
  double xb,yb,rb;

  int n;
  cin >> n;
  
  for( int i = 0 ; i < n ; i++ ){
    
    cin >> xa >> ya >> ra >> xb >> yb >> rb;
    
    double rx = xa - xb;
    double ry = ya - yb;
    double r = sqrt( pow( rx , 2 ) + pow( ry , 2 ) );
   
    if( ra > rb + r ) cout << "2" << endl; 
    else if(  rb > ra + r ) cout << "-2" << endl;
    else if( r <= ra + rb ) cout << "1" << endl;
    else cout << "0" << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
int main (void)
{
    int A,B;
    scanf("%d%d",&A,&B);
    if(A>=13)
        printf("%d\n",B);
    else if(A>5)
        printf("%d\n",B/2);
    else
        printf("%d\n",0);
return 0 ;
}


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

using namespace std;

typedef long long ll;
const ll M=1e9+7;

ll myPow(int m,int n)
{
    ll ans=1;
    ll res=m;
    while(n)
    {
        if(n&1) ans=ans*res%M;
        res=res*res%M;
        n>>=1;
    }
    return ans;
}

int main()
{
    int m,n;
    while(cin>>m>>n)
    {
        cout<<myPow(m,n)<<endl;
    }

    return 0;
}



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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	string ans = "Yes";
	int cnt = 0;
	rep(i, n) {
		if(a[i] * 4 * m >= sum) cnt++;
	}
	if(cnt < m) ans = "No";
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int n;
int arr[100100];

int main() {
    int i;

    scanf("%d",&n);
    for (i=1;i<=n;i++) scanf("%d",&arr[i]);
    int res = 0;
    for (i=0;i<=n;i++) res += abs(arr[i]-arr[i+1]);
    for (i=1;i<=n;i++) {
        printf("%d\n",res+abs(arr[i-1]-arr[i+1])-abs(arr[i-1]-arr[i])-abs(arr[i]-arr[i+1]));
    }

    return 0;
}


Measured memory_bytes: 1664
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    #a, b, c, d, e = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    for i in range(1, 6):
        if N[i-1] == 0:
            print(i)

resolve()

Measured memory_bytes: 61580
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int A,B,C;
  cin>>A>>B>>C;
  int i=0;
  for(;A%2==0 && B%2==0 && C%2==0;i++){
    int a=(B+C)/2,b=(A+C)/2,c=(A+B)/2;
    A=a,B=b;C=c;
    if(i>=30){
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<i<<endl;
}

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;

int main() {
    const double PI=3.14159265358979323846;
    double a, b; cin >> a >> b;
    double h, m; cin >> h >> m;
    double x = h * 30 + m * 0.5;
    double y = m * 6.0;
    double z = abs(x - y);

    double r = z * PI / 180.0;
    double co = cos(r);
    double aa = pow(a, 2.0);
    double bb = pow(b, 2.0);
    double cc = 2.0 * a * b * co;

    double ans = aa + bb - cc;
    cout << setprecision(20) << sqrt(ans) << endl;

}


Measured memory_bytes: 4228
#include<iostream>
using namespace std;
int main(){
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}, n;
    cin >> n;
    cout << a[n-1];
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	  #define endl "\n"
	  #define ll long long int
	  #define mod 1000000007
	  #define inf 1000000000000000001;
	  using namespace std;
	  int main()
	  {
	    //  #ifndef ONLINE_JUDGE
	    //  // for getting input from input.txt
	    //  freopen("input.txt", "r", stdin);
	    //  // for writing output to output.txt
	    //  freopen("output.txt", "w", stdout);
	    // #endif
	    std::ios::sync_with_stdio(false);
	    cin.tie(NULL);
	    int a,b,c,d;
	    cin>>a>>b>>c>>d;
	    cout<<(a-c)*(b-d)<<endl;;
	    return 0;
	  }


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stdlib.h>
#define INF (1e9+7)
#define distance(x1,y1,x2,y2) sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
#define rep(i,N) for(ll i=0;i<N;i++)
#define rep2(i,j,k) for(ll i=j; i<k;i++)
typedef long long int ll;
using namespace std;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using vs=vector<string>;
using vvs=vector<vector<string>>;

template <typename T>
void print(T v){
    for(size_t i=0;i<v.size();i++){
        cout<<i<<": "<<v[i]<<endl;}
}

template <typename T>
void print2(T v){
    for(size_t i=0;i<v.size();i++){
        cout<<i<<": ";
        for(size_t j=0;j<v[0].size();j++){
            cout<<v[i][j]<<" ";
        }
        cout<<endl;
    }
}

void p(vector<int> v){
    for(size_t k=0;k<v.size();k++){
        cout<<v[k]<<" ";
    }
    cout<<endl; 
}
    

int main(){    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    //vvl v(5,vl(3,-1));
    
    ll a,b,c,x,y,temp,ans;
    cin>>a>>b>>c>>x>>y;
    
    if(x<y){
        temp=a;
        a=b;
        b=temp;
        temp=x;
        x=y;
        y=temp;
    }
        
    ll ans1=c*(x*2);
    ll ans2=c*(y*2)+a*(x-y);
    ll ans3=a*x+b*y;
    
    ans=min(ans1,ans2);
    ans=min(ans,ans3);
    
    cout<<ans<<endl;
        
    
    return 0;}

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

const double pi = acos(-1.0);

int main() {
    int a, b, h, m;
    scanf("%d%d%d%d", &a, &b, &h, &m);// don't forget &
    int w = m;
    h *= 60;
    m *= 12;
    h += w;
    if (h > m) {
        swap(h, m);
    }
    m -= h;
    if (m > 360) {
        m = 720 - m;
    }
    //printf("%f\n",pi);
    double c = pi * m / 360;
    
    double x = 1.0 * a * a + 1.0 * b * b - 2.0 * a * b * cos(c);
    
    printf("%.10f", sqrt(x));
    
    return 0;
}


Measured memory_bytes: 2600
N, D = map(int,input().split())
dots = []
for i in range(N):
    dots.append(list(map(int,input().split())))
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        tmp = 0
        for k in range(D):
            tmp+=(dots[i][k]-dots[j][k])**2
        if (tmp**0.5).is_integer():
            cnt+=1

print(cnt)

Measured memory_bytes: 3188
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

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

const int MX=1e5+10;

int N;
int t[30][30];
int memo[(1)<<(21)];

int solve(int m){
	int i=0;
	for(int j=0; j<N; j++) if((m)&((1)<<(j))) i++;
	if(i==N) return 1;

	if(memo[m]!=-1) return memo[m];

	int ans=0;
	for(int j=0; j<N; j++) if(t[i][j]==1 && ((m)&((1)<<(j)))==0) ans+=solve((m)|((1)<<(j))),ans%=MOD;
	return memo[m]=ans;
}


int32_t main(){
   boost;
   IO();

   memset(memo,-1,sizeof(memo));
   cin>>N;
   for(int i=0; i<N; i++) for(int j=0; j<N; j++) cin>>t[i][j];

   cout << solve(0) << endl;

   

   return 0;
}



Measured memory_bytes: 20008
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(long long x,long long int y){
    return x>y;
}

int main(){
    long long int n,big=0,small=0,v=0;
    cin>>n;
    long long int k[n];
    for(int i=0;i<n;i++)
        cin>>k[i];
    sort(k,k+n,cmp);
    for(long long int i=1;i<n;i++){
        if(k[i]==k[i-1] && v==0){
            v=1;
            big=k[i];
            i+=1;
            continue;
        }
        if(k[i]==k[i-1]&& v==1){
            small=k[i];
            break;
        }
    }
    cout<<small*big<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using pii = pair<int, int>;
using ll = long long int;
using ld = long double;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
// ll mod(long long val) {
//     long long res = val % MOD;
//     if (res < 0) res += MOD;
//     return res;
// }
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }

int n;
vector<ll> a;

ll solve() {
    vector<ll> dp(n + 5, INT_MAX);
    for (int i = 0; i < n; ++i) {
        auto it = lower_bound(dp.begin(), dp.end(), a[i] + 1);
        *it = a[i];
    }
    return distance(dp.begin(), lower_bound(dp.begin(), dp.end(), INT_MAX));
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        a.push_back(-t);
    }
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 1908
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

s=input().rstrip()
print(s[0]+str(len(s)-2)+s[-1])

Measured memory_bytes: 3316
#C
N = int(input())
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
dp=[[0 for i in range(3)] for j in range(N+1)]
dp[1][0]=a[0]
dp[1][1]=b[0]
dp[1][2]=c[0]
for i in range(2,N+1):    
    for j in range(3):
        if j==0:
            w=a[i-1]
        elif j==1:
            w=b[i-1]
        else:
            w=c[i-1]
        dp[i][j]=max(dp[i-1][(j+1)%3]+w,dp[i-1][(j+2)%3]+w)
print(max(dp[-1])) 

Measured memory_bytes: 89896
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
const int MAX = 1e5;
typedef long long ll;
typedef pair<char,int> P;

vector<int> tr[MAX+1];
int par[MAX+1],n,q;
int mark[MAX+1];

void init(){
    for(int i = 0 ; i < MAX ; i++){
        par[i] = i;
    }
}

int find(int x){
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
}

void unite(int x,int y){
    x = find(x); y = find(y);
    if(x == y) return;
    
    par[y] = x;
}

bool same(int x,int y){
    return find(x) == find(y);
}

int tmp[MAX+1];
void rec(int x,int y,int z){
    int t = z;
    tmp[x] = y;
    if(mark[x]){
        t = x;
    }
    unite(t,x);
    
    for(int i = 0 ; i < tr[x].size() ; i++){
        rec(tr[x][i],x,t);
    }
}

int main(){
    int p,num;
    char m;
    while(cin >> n >> q , n + q){
        ll sum = 0;
        stack<P> st;
        init();
        fill(mark,mark+MAX,0);
        fill(tmp,tmp+MAX,0);
        mark[0] = 1;
        for(int i = 0 ; i < MAX ; i++){
            tr[i].clear();
        }
        for(int i = 1 ; i < n ; i++){
            cin >> p; --p;
            tr[p].push_back(i);
        }
        for(int i = 0 ; i < q ; i++){
            cin >> m >> num; --num;
            st.push(P(m,num));
            
            if(m == 'M'){
                ++mark[num];
            }
        }
        rec(0,0,0);
        while(q--){
            P p = st.top(); st.pop();
            if(p.first == 'Q'){
                sum += find(p.second)+1;
            }
            else{
                --mark[p.second];
                if(!mark[p.second]) {
                    unite(tmp[p.second],p.second);
                }
            }
        }
        cout << sum << endl;
    }
    
    return 0;
}

Measured memory_bytes: 13768
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=105;
double a[N];int n;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%lf",&a[i]);
	sort(a+1,a+1+n);
	fp(i,2,n)a[i]=(a[i-1]+a[i])*0.5;
	printf("%.10lf\n",a[n]);
	return 0;
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

a = sorted(P[:X] + Q[:Y])
ans = sum(a)

for i in range(min(X + Y, C)):
    if a[i] < R[i]:
        ans += R[i] - a[i]

print(ans)

Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

map<int,int> t;
int main(){
    int n,q,m,dt;
    while(cin>>n>>q,n){
        t.clear();
        rep(i,n){
            cin>>m;
            rep(j,m){
                cin>>dt;
                ++t[dt];
            }
        }
        int mx=-1,ans;
        for(auto it:t){
            if(mx<it.second) mx=it.second,ans=it.first;
        }
        cout<<(mx>=q?ans:0)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <random>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 998244353 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

const int MAX = 1e7 ;

class SGT{
	public :
	ll num[MAX] ;
	ll d = INF ;
	ll n = 1 ;
	
	void init(vll &a){
		while(n<a.size()) n *= 2 ;
		for(int i=0;i<n;i++){
			if(i<a.size()) num[i+n-1] = a.at(i) ;
			else num[i+n-1] = d ;
		}
		for(int i=n-2;i>=0;i--){
			num[i] = min(num[i*2+1],num[i*2+2]) ;
		}
	}
	
	void update(int i,ll a){
		i += n-1 ;
		num[i] = a ;
		while(i){
			i = (i-1)/2 ;
			num[i] = min(num[i*2+1],num[i*2+2]) ;
		}
	}
	
	ll query(int a,int b,int l,int r,int cur){
		if(a<=l&&r<=b) return num[cur] ;
		if(r<=a||b<=l) return d ;
		ll r1 = query(a,b,l,(l+r)/2,cur*2+1) ;
		ll r2 = query(a,b,(l+r)/2,r,cur*2+2) ;
		return min(r1,r2) ;
	}
} ;

int main(){
	ll n,q ;
	cin >> n >> q ;
	static SGT sgt1,sgt2 ;
	vll sub(n-1,n-2) ;
	sgt1.init(sub) ;
	sgt2.init(sub) ;
	ll ans = (n-2)*(n-2) ;
	while(q--){
		ll t,x ;
		cin >> t >> x ;
		if(t==1){
			ll tmp = sgt1.query(x-1,sgt1.n,0,sgt1.n,0) ;
			ans -= tmp ;
			sgt2.update(tmp,min(x-2,sgt2.num[tmp+sgt2.n-1])) ;
			// cout << tmp << endl ;
		}else{
			ll tmp = sgt2.query(x-1,sgt2.n,0,sgt2.n,0) ;
			ans -= tmp ;
			sgt1.update(tmp,min(x-2,sgt1.num[tmp+sgt1.n-1])) ;
			// cout << tmp << endl ;
		}
		// cout << "this is ans : " << ans << endl ;
		// for(int i=0;i<n-1;i++) cout << sgt1.num[i+sgt1.n-1] << " " ; cout << endl ;
		// for(int i=0;i<n-1;i++) cout << sgt2.num[i+sgt2.n-1] << " " ; cout << endl ; 
	}
	cout << ans << endl ;
}

Measured memory_bytes: 13004
#include<bits/stdc++.h>
using namespace std;
int main(){
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a-c) <= d) cout << "Yes" << endl;
    else{
        if(a<b){
            if(a+d >= b){
                if(b+d >= c) cout << "Yes" << endl;
                else cout << "No" << endl;
            }
            else cout << "No" << endl;
        }
        if(a>b){
            if(b+d >= a){
                if(a+d >= c) cout << "Yes" << endl;
                else cout << "No" << endl;
            }
            else cout << "No" << endl;
        }
    }
return 0;
}


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

constexpr int MAX_N = 31, MAX_C = 1000001;
int n, max;
int cost[MAX_N];
bool dp[MAX_C];
bool prime_num[MAX_C];

int main() {
	while (1) {
		std::cin >> n >> max;
		if (n + max == 0)
			break;
		std::memset(prime_num, false, sizeof(prime_num));
		std::memset(dp, false, sizeof(dp));
		for (int i = 0; i < n; ++i)
			std::cin >> cost[i];
		for (int i = 2; i * i <= max; ++i) {
			if (!prime_num[i]) {
				for (int j = 2; i*j <= max; ++j)
					prime_num[i*j] = true;
			}
		}
		int ans = 0;
		for (int i = 0; i < n; ++i)
			dp[cost[i]] = true;

		for (int i = 1; i <= max; ++i) {
			for (int j = 0; j < n; ++j) {
				if (i + cost[j] <= max&&dp[i])
					dp[i + cost[j]] = true;
			}
		}
		for (int i = max; i >= 0; --i) {
			if (dp[i] && !prime_num[i]) {
				ans = i; 
				break;
			}
		}
		if (!ans)
			std::cout << "NA" <<std::endl;
		else
			std::cout << ans << std::endl;
	}
	return 0;
}

Measured memory_bytes: 5000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Solve(int N, int[][] queries)
        {
            var reds = new bool[N];
            var counts = Enumerable.Repeat(1, N).ToArray();
            reds[0] = true;
            foreach (var query in queries)
            {
                int a = query[0] - 1;
                int b = query[1] - 1;
                if (reds[a]) { reds[b] = true; }
                if (--counts[a] == 0) { reds[a] = false; }
                ++counts[b];
            }
            return reds.Count(red => red);
        }
        static void Main(string[] args)
        {
            var V = ReadInts();
            int N = V[0];
            int M = V[1];
            var queries = new int[M][];
            for (int i = 0; i < M; ++i) { queries[i] = ReadInts(); }
            Console.WriteLine(Solve(N, queries));
        }
    }
}


Measured memory_bytes: 22216
#include <iostream>
#include <string>
int main(){std::string s;int c[101]={},a=1;std::cin>>s;for(int i=0;i!=s.size();++i)++c[s[i]-97];for(int i=0;i!=26;++i)a=(c[i]%2?0:a);std::cout<<(a?"Yes":"No")<<"\n";}

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

int main()
{
	int n;
	cin >> n;
	string a;
	cin >> a;
	string aa="ABC";
	int c=0;
	int pos=0;
	for(int i=0;i<n;i++)
    {
        if(a[i]==aa[pos])
        {
            pos++;
            if(pos==3)
            {
                c++;
                pos=0;
            }
        }else
        {
            pos=0;
            if(a[i]==aa[pos])
            {
                pos++;
            }
        }
    }
    cout << c << endl;
}


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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []

    def f():
        r,c,m = LI()
        a = [[1] * (c+2)] + [[1] + [None if c == '.' else 1 for c in S()] + [1] for _ in range(r)] + [[1] * (c+2)]
        cost = [[1] * (c+2)] + [[1] + LI() + [1] for _ in range(r)] + [[1] * (c+2)]
        on = [[1] * (c+2)] + [[1] + LI() + [1] for _ in range(r)] + [[1] * (c+2)]
        off = [[1] * (c+2)] + [[1] + LI() + [1] for _ in range(r)] + [[1] * (c+2)]
        ms = [tuple(map(lambda x: x+1, LI())) for _ in range(m)]
        e = collections.defaultdict(list)
        for i in range(1,r+1):
            for j in range(1,c+1):
                if a[i][j]:
                    continue
                for di,dj in dd:
                    if a[i+di][j+dj]:
                        continue
                    e[(i,j)].append(((i+di,j+dj), 1))

        def search(s):
            d = collections.defaultdict(lambda: inf)
            d[s] = 0
            q = []
            heapq.heappush(q, (0, s))
            v = collections.defaultdict(bool)
            while len(q):
                k, u = heapq.heappop(q)
                if v[u]:
                    continue
                v[u] = True

                for uv, ud in e[u]:
                    if v[uv]:
                        continue
                    vd = k + ud
                    if d[uv] > vd:
                        d[uv] = vd
                        heapq.heappush(q, (vd, uv))

            return d

        ad = {}
        for k in ms:
            if k in ad:
                continue
            ad[k] = search(k)
        ti = 0
        td = collections.defaultdict(list)
        c = ms[0]
        td[c].append(0)
        for t in ms[1:]:
            while c != t:
                cc = ad[t][c]
                for di,dj in dd:
                    ni = c[0] + di
                    nj = c[1] + dj
                    n = (ni, nj)
                    if ad[t][n] == cc - 1:
                        ti += 1
                        td[n].append(ti)
                        c = n
                        break

        r = 0
        for k,v in sorted(td.items()):
            i = k[0]
            j = k[1]
            cs = cost[i][j]
            onf = on[i][j] + off[i][j]
            tr = onf
            for vi in range(len(v)-1):
                sa = v[vi+1] - v[vi]
                tr += min(cs * sa, onf)
            r += tr

        return r

    while True:
        rr.append(f())
        break

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 69160
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    ll N,K;
    cin >> N >> K;
    map<ll,ll> mp;
    REP(_,N) {
        ll a,b;
        cin >> a >> b;
        if(mp.count(a) == 0)mp[a] = b;
        else mp[a]+=b;
    }
    for (const auto &it: mp) {
        K -= it.second;
        if (K<=0) {
            cout << it.first << endl;
            return;
        }
    }
    string s;
    cin >> s;
    cout << s << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 4224