akhauriyash/Code-Regression huggingface dataset:
hw, *ss = open(0).read().splitlines()

H, W = map(int, hw.split())

ss = list(map(list, ss))

from itertools import product

for h in range(H):
    for w in range(W):
        if ss[h][w] == '#':
            continue
        ans = 0
        for i,j in product([-1,0,1], [-1,0,1]):
            if 0 <= h+i < H and 0 <= w+j < W:
                ans += (ss[h+i][w+j] == '#')
        ss[h][w] = ans

for s in ss:
    print(''.join(map(str, s)))

Measured memory_bytes: 74552
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long A = sc.nextLong();
		long B = sc.nextLong();
		
		System.out.println((A+B) % 2 == 0 ? (A+B)/2 : "IMPOSSIBLE");
	}
	
}



Measured memory_bytes: 21844
def solve(n,a1):
    dp=[[0 for i in range(3)]for j in range(n)]
    dp[0][0]=a1[0][0]
    dp[0][1]=a1[0][1]
    dp[0][2]=a1[0][2]
    for i in range(1,n):
        dp[i][0]=a1[i][0]+max(dp[i-1][1],dp[i-1][2])
        dp[i][1]=a1[i][1]+max(dp[i-1][2],dp[i-1][0])
        dp[i][2]=a1[i][2]+max(dp[i-1][1],dp[i-1][0])
        
    return max(dp[n-1][0],dp[n-1][1],dp[n-1][2])
    


n=int(input())
a1=[[int(i) for i in input().split()]for j in range(n)]

print(solve(n,a1))

Measured memory_bytes: 45684
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    ll n; string s; cin >> n >> s;
    vector<ll> w(n, 0), e(n, 0);
    rep(i, n) w[i] = w[i == 0 ? 0 : i-1] + (s[i] == 'W' ? 1 : 0);
    for(ll i = n-1; i >= 0; --i) e[i] = e[i == n-1 ? n-1 : i+1] + (s[i] == 'E' ? 1 : 0);

    ll ans = 99999999;
    rep(i, n){
        ll ww = w[i], ee = e[i];
        if(s[i] == 'W') ww--;
        else ee--;
        ans = min(ans, ww+ee);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  int k; cin >> k;
  unordered_set<int> was;
  int value = 0, count = 0, ans = -1;
  while(true) {
    value = (value * 10 + 7) % k;
    if(was.count(value)) {
      break;
    }
    count++;
    was.insert(value);
    if(value == 0) {
      ans = count;
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;
int main()
{
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }  
  
  
  int a_max=*(max_element(a.begin(),a.end()));
  int a_min=*(min_element(a.begin(),a.end()));
  
  vector<int> cnt(a_max+3,0);
  for(int i=0;i<N;i++){
    cnt[a[i]]++;
    cnt[a[i]+1]++;
    cnt[a[i]+2]++;
  }
  int ans=*(max_element(cnt.begin(),cnt.end()));
  cout<<ans;
}


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

using namespace std;

int n,i,j;
int tablica[100003];
int dp[100003][4];

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(i=0;i<n;i++){
        for(j=0;j<3;j++){
            cin >> dp[i][j];
        }
    }
    for(i=1;i<n;i++){
        dp[i][0]+=max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]+=max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]+=max(dp[i-1][0],dp[i-1][1]);
    }
    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

V = [0]*(1 << N)
for s in range(1 << N):
    r = 0
    for i, Ai in enumerate(A):
        if not s & (1 << i):
            continue
        for j in range(i+1, N):
            if not s & (1 << j):
                continue
            r += Ai[j]
    V[s] = r

U = [-10**10]*(1 << N)
U[(1 << N) - 1] = 0
for state in range((1 << N)-1, 0, -1):
    s = state
    v = U[state]
    while s:
        s = (s - 1) & state
        U[s] = max(U[s], v + V[state ^ s])
print(U[0])

Measured memory_bytes: 45020
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
 
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}

void solve(){
    int n,k;
    cin >> n >> k;
    vector<double>v(n+5);
    FOR(i,1,n+1)cin >> v[i];
    int lo = 1,hi = inf;
    while(lo < hi){
        int mid = (lo+hi)/2,tot = 0;
        FOR(i,1,n+1){
            int x = (int)ceil(v[i]/mid);
            tot += x-1;
        }
        if(tot <= k)hi = mid;
        else lo = mid+1;
    }
    cout << lo << "\n";
}
 
signed main()
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...

Measured memory_bytes: 4808
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int D;
    cin >> D;
    switch (D) {
    case 25:
        cout << "Christmas";
        break;
    case 24:
        cout << "Christmas Eve";
        break;
    case 23:
        cout << "Christmas Eve Eve";
        break;
    case 22:
        cout << "Christmas Eve Eve Eve";
        break;
    default:
        ;
    }
    cout << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long

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

	int t[55] = {0};
	int n, m;
	cin >> n >> m;

	for (int i = 1; i <= m*2; i++)
	{
		int tmp;
		cin >> tmp;
		t[tmp]++;
	}

	for (int i = 1; i <= n; i++)
	{
		cout << t[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 384
unittest
{
	assert( [ "3", "1 2 3" ].parse.expand.solve == "YES" );
	assert( [ "5", "1 2 3 4 5" ].parse.expand.solve == "NO" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	return ( as.count!( ( a ) => a % 2 == 1 ) % 2 == 0 ) ? "YES" : "NO";
}


Measured memory_bytes: 5944
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        v: [usize; 3],
    }
    let mut v = v;
    let mut count = 0;
    for vi in v.iter() {
        if vi % 2 == 0 {
            count += 1;
        }
    }
    let mut ans = 0;
    if count == 1 {
        ans += 1;
        for vi in v.iter_mut() {
            if *vi % 2 == 1 {
                *vi += 1;
            }
        }
    }
    if count == 2 {
        ans += 1;
        for vi in v.iter_mut() {
            if *vi % 2 == 0 {
                *vi += 1;
            }
        }
    }
    let max = v.iter().max().unwrap();
    for vi in v.iter() {
        ans += (max - vi) / 2;
    }
    println!("{}", ans);
}


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

int main() {
  // input
  vector<int> a(5);
  int k;
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }
  cin >> k;
  if (a[4] - a[0] > k) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = (int)2e5 + 5;
const int mod = (int)1e9 + 7;
using namespace std;

ll a[maxn];

int main()
{
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	ll ans = 0, h = 0;
	int j = 0;
	for(int i = 0; i < n; i++){
		for( ; j < n; j++){
			if((h|a[j]) != h + a[j]) break;
			else{
				h += a[j];
				ans += (j - i + 1);
			}
		}
		h -= a[i];
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int s = max(B, D) - min(A, C);
  int ans = (max(A, B)-min(A, B)) + (max(C, D) - min(C, D)) - s;
  ans = max(ans, 0);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
H = list(map(int,input().split()))
Count = list()
cnt = 0
for i in range(n-1):
    if H[i]<H[i+1]:
        Count.append(cnt)
        cnt = 0
        continue
    else:
        cnt +=1
else:
    Count.append(cnt)
print(max(Count))
        
    

Measured memory_bytes: 14252
#define GBN_USE_C
#ifdef GBN_USE_C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#else
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#endif

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

typedef char str255[256];
int  StrLen(char *s       ) { for(int ptr = 0;; ++ptr) if(!s[ptr]) return ptr; } 
// char * の後ろから n 文字削除
void StrDel(char *s, int n) { int l = StrLen(s); s[l - n + 1] = '\0'; }

const int coordMin = -1000000;
const int coordMax =  1000000;

int main()
{
    int K, X; scanf("%d %d", &K, &X);
    int count = 0;
    for (int i = X - K + 1; i <= X + K - 1; ++i, ++count)
        if ((coordMin <= i) && (i <= coordMax))
            if (!count) printf("%d", i);
            else printf(" %d", i);
    puts("");

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  int count = 0;
  bool ans = false;
  for (int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  for (int i = 0; i < N; i++){
    if (a.at(i) == (count + 1)){
      count++;
      ans = true;
    }
  }
  if (ans) cout << N - count << endl;
  else cout << -1 << endl;
}

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

int main() {
	int n;
    cin >> n;
    if (n < 105) cout << "0";
    else if (105 <= n && n < 135) cout << "1";
    else if (135 <= n && n < 165) cout << "2";
    else if (165 <= n && n < 189) cout << "3";
    else if (189 <= n && n < 195) cout << "4";
    else cout << "5";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    double ans1 = (double)(w * h) / 2;
    int ans2 = 0;
    if (w % 2 == 0 && h % 2 == 0) {
        if (w / 2 == x && h / 2 == y) {
            ans2 = 1;
        }
    }

    if (x == 0 || y == 0) ans2 = 0;
    cout << fixed;
    cout << setprecision(10) << ans1 << " ";
    cout << ans2 << endl;
    return 0;
}


Measured memory_bytes: 256
S = input()
if S[0]=='M':
  print(6)
elif S[2]=='E':
  print(5)
elif S[0] == 'W':
  print(4)
elif S[1] == 'H':
  print(3)
elif S[0] == 'F':
  print(2)
elif S[1] == 'A':
  print(1)
else:
  print(7)


Measured memory_bytes: 2940
#include <stdio.h>
#include <math.h>
int main(void){
  int n,m,i,j,min,man,index;
  int a[50],b[50],c[50],d[50];
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++) scanf("%d%d",&a[i],&b[i]);
  for(i=0;i<m;i++) scanf("%d%d",&c[i],&d[i]);
  for(i=0;i<n;i++){
    index=1;
    min=abs(a[i]-c[0])+abs(b[i]-d[0]);
    for(j=1;j<m;j++){
      man=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(man<min) {min=man;index=j+1;}
    }
    printf("%d\n",index);
  }
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#pragma warning (disable:4996)

#define ORDER 1000000000000000000

int main() {
	//input
	int N;
	(void)scanf("%d", &N);
	
	//output
	long long A, pi = 1;
	for (int i = 0; i < N; i++) {
		(void)scanf("%lld", &A);
		if (A == 0) {
			pi = 0;
			break;
		}
		if (pi > (ORDER / A)) {
			pi = -1;
			continue;
		}
		if (pi != -1)pi *= A;
	}
	printf("%lld", pi);
}

Measured memory_bytes: 1692
#include <bits/stdc++.h>
#include <boost/math/common_factor.hpp>
using namespace std;

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }


// ***************************************

vector<int> ans;


int main(void){

    int N, W;
    cin >> N >> W;

    vector<pair<int, int>> items(N);

    int w, v;
    REP(i, N) {
        cin >> w >> v;
        items[i] = { w, v };
    }

    vector<vector<ll>> dp(W + 1, vector<ll>(N + 1));

    REP(j, N){
        w = items[j].first;
        v = items[j].second;
        REP(i, W + 1) {
			dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
            if (i - w < 0) continue;

			dp[i][j + 1] = max(dp[i][j + 1], dp[i - w][j] + v);
        }
    }

    cout << dp[W][N] << endl;

    return 0;
}

Measured memory_bytes: 82304
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    string s;
    cin >> s;
    for(char c: s){
        if(c == '9'){
            output("Yes");
            return 0;
        }
    }
    output("No");
    
    return 0;
}

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

typedef long long ll;
typedef struct {
	ll x,y;
} _pos;
int main () {
	int n,K;cin >> n >> K;
	_pos pos[n];for (int i = 0;i < n;i++) {
		cin >> pos[i].x >> pos[i].y;
	}
	ll ans = 9223372036854775000;
	for (int i = 0;i < n;i++) {
		for (int j = i;j < n;j++) {
			for (int k = j;k < n;k++) {
				for (int l = k;l < n;l++) {
					ll x[]={pos[i].x,pos[j].x,pos[k].x,pos[l].x};
					ll y[]={pos[i].y,pos[j].y,pos[k].y,pos[l].y};
					sort(x,x+4);
					sort(y,y+4);
					int cnt=0;
					for (int m = 0;m < n;m++) {
						if (x[0]<=pos[m].x&&pos[m].x<=x[3]&&y[0]<=pos[m].y&&pos[m].y<=y[3]) {
							cnt++;
						}
					}
					if (cnt>=K) ans = min(ans,(x[3]-x[0])*(y[3]-y[0]));
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(LL i=0; i<(n); i++)
#define FOR(i, m, n) for(LL i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back
#define INF INT_MAX

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

int main() {
	int n;
	cin >> n;
	VI a(n);
	REP(i, n)cin >> a[i];

	SORT(a);
	int i = 0, ans = 0;
	while (i < n) {
		int elem = a[i], cnt = 0;
		while (i < n && a[i] == elem) { cnt++; i++; }
		//cout << elem << "は" << cnt << "個\n";
		ans += elem > cnt ? cnt : cnt - elem;
	}
	cout << ans << endl;
}

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

int p[10];
int ans=100000;
int n,k;
void dfs(int sum,int q){
	//printf("%d %d\n",sum,q);
	if(sum>=n){ans=min(ans,sum);return;}
	if(q>10000)return;
	for(int i=0;i<10;i++){
		if(!p[i]){/*printf("%d\n",i);*/dfs(sum+q*i,q*10);}
	}
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<k;i++){
		int c;
		scanf("%d",&c);
		p[c]=1;
	}
	dfs(0,1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
key=[]
value=[]
for i in range(m):
    a,b=map(int,input().split())
    if a==1:
        value.append(b)
    if b==n:
        key.append(a)
key_set=set(key)
value_set=set(value)
match_list=list(key_set&value_set)
if match_list:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 21836
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if solve(a, b) {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}
func solve(a int, b int) bool {
	var x int
	x = a * b
	if x%2 == 1 {
		return true
	}
	return false
}


Measured memory_bytes: 512
N = int(input())
p_list = list(map(int, input().split()))

count = 0
for i in range(N-1):
    if p_list[i] == i + 1:
        count += 1
        p_list[i+1] = p_list[i]
if p_list[N-1] == N:
    count += 1
print(count)



Measured memory_bytes: 14008
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;
ll x,y;

bool dp1[2][20000];
bool dp2[2][20000];

int main(){
	cin >> s >> x >> y;
	vector<ll> vl[2];
	bool f = 0;
	ll cnt = 0;
	bool ok = true;
	bool F = false;
	rep(i,s.size()){
		if(s[i] == 'T'){
			ok = false;
			if(cnt > 0)vl[f].push_back(cnt);
			cnt = 0;
			f = !f;
		}
		else{
			if(ok)F = true;
			cnt++;
		}
	}
	if(cnt > 0)vl[f].push_back(cnt);
	
	dp1[0][10000] = true;
 	rep(i,vl[0].size()){
		rep(j,20000)dp1[(i+1)%2][j] = false;
		rep(j,20000){
			if(j+vl[0][i] < 20000)dp1[(i+1)%2][j+vl[0][i]] |= dp1[i%2][j];
			if(!F && j-vl[0][i] >= 0)dp1[(i+1)%2][j-vl[0][i]] |= dp1[i%2][j];
		}
		F = false;
	}

	dp2[0][10000] = true;
	rep(i,vl[1].size()){
		rep(j,20000)dp2[(i+1)%2][j] = false;
		rep(j,20000){
			if(j+vl[1][i] < 20000)dp2[(i+1)%2][j+vl[1][i]] |= dp2[i%2][j];
			if(j-vl[1][i] >= 0)dp2[(i+1)%2][j-vl[1][i]] |= dp2[i%2][j];
		}
	}
	// rep(i,20000){
	// 	if(dp2[1][i])cout << i << endl;
	// }
	if(dp1[vl[0].size()%2][10000+x] && dp2[vl[1].size()%2][10000+y])cout << "Yes" << endl;
	else cout << "No" << endl;
}





Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(a,b,c) for(ll a=b;a<c;a++)
#define ll long long
#define endl '\n'
#define pb(a) push_back(a)

int main() {
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int n;
	cin >> n;
	ll ans = 0;
	ll divs[n + 1] = {0};
	rep(i, 1, n + 1) {
		for (int j = i; j < n + 1; j += i) {
			divs[j]++;
		}
	}
	rep(i, 1, n + 1) {
		ans += i * divs[i];
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 81676
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

double dp_[110][110];
bool lose[110], back[110];
int N,T,L,B;
int next(int j, int spot){
    j+=spot;
    if(j>N){
        j = N-(j-N);
    }
    return j;
}

int main(){
    while(cin>>N>>T>>L>>B && N){
        memset(dp_,0,sizeof(dp_));
        memset(lose,0,sizeof(lose));
        memset(back,0,sizeof(back));
        auto dp=dp_+1;
        dp[0][0] = 1;
        rep(i,L){ int x;cin>>x; lose[x]=true; }
        rep(i,B){ int x;cin>>x; back[x]=true; }
        rep(i,T){
            rep(j,N+1){
                if(j==N){
                    dp[i+1][N]+=dp[i][N];
                    continue;
                }
                loop(k,1,7){
                    int x=next(j,k);
                    if(back[x]){
                        dp[i+1][0] += dp[i][j]/6;
                    }else if(lose[x]){
                        dp[i+2][x] += dp[i][j]/6;
                    }else{
                        dp[i+1][x] += dp[i][j]/6;
                    }
                }
            }
            // rep(j,N+1){
            //     printf("%.2lf ", dp[1+i][j]);
            // }
            // puts("");
        }
        printf("%.10lf\n", dp[T][N]);
    }
}

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


int main() {
  int k,s; cin >> k >> s;
  int count=0;
  
  for(int i=0; i < k+1; i++){
    for(int j=0; j < k+1; j++){
          if(s-k <= i+j && i+j <= s){
          count++;
          }
    }
  }
  
  cout << count << endl;
}


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


int main(){
    int a,b;
    cin >> a >> b;
    if(a>=10 || b>=10) cout << -1 << endl;
    else cout << a*b << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        boolean solved = false;
        for(long n = 1; n < 3501; n++) {
            if (solved) break;
            for(long w = 1; w < 3501; w++) {
                if (solved) break;
                long denominator = 4*n*w - N*n - N*w;
                if (denominator == 0) continue;
                long numerator = N*n*w;
                if (denominator > 0 && numerator%denominator == 0) {
                    long h = numerator/denominator;
                    System.out.print(h);
                    System.out.print(" ");
                    System.out.print(n);
                    System.out.print(" ");
                    System.out.print(w);
                    System.out.println(" ");
                    solved = true;
                }
            }
        }
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <cstring>
#include <string>

#define MAXN 105
#define MAXK 100005

using namespace std;

int arr[MAXN];
bool dp[MAXK];

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

    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    dp[0] = false;
    for(int i = 1; i <= k; i++) {
        bool act = false;
        for(int j = 0; j < n; j++) {
            if(i - arr[j] >= 0 && !dp[i - arr[j]]) {
                act = true;
                break;
            }
        }
        dp[i] = act;
    }
    cout << (dp[k] ? "First\n" : "Second\n");

    return 0;
}

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


int main(){
    int n;
    cin >> n;
    int a;
    vector<int> relate(n);
    for (int i = 0; i < n; i++){
        relate[i] = 0;
    }
    for (int i = 0; i < n-1; i++){
        cin >> a;
        relate[a-1]++;
    }
    for (int i = 0; i < n; i++){
        cout << relate[i] << endl;
    }
}

Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull A=9999973,B=950527;

int H,W;
char T[1005][1005];
ull t[1005][1005];
ull t2[1005][1005];
int h,w;
char U[1005][1005];


int main(){
  scanf("%d %d",&H,&W);
  for(int i=0;i<H;i++)scanf("%s",T[i]);
  scanf("%d %d",&h,&w);
  for(int i=0;i<h;i++)scanf("%s",U[i]);
  
  ull target=0;  
  for(int i=0;i<h;i++){
    ull key=0;
    for(int j=0;j<w;j++){
      key=key*B+U[i][j];
    }
    target=target*A+key;
  }

  ull C=1;
  for(int i=0;i<w;i++)C*=B;
  
  for(int i=0;i<H;i++){
    ull key=0;
    for(int j=0;j<W;j++){
      key=key*B+T[i][j];
      if(j-w>=0)key-=T[i][j-w]*C;
      t[i][j]=key;
      t2[i][j]=t[i][j];
    }
  }
  
  C=1;
  for(int i=0;i<h;i++)C*=A;
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(i)t[i][j]+=t[i-1][j]*A;
      if(i-h>=0)t[i][j]-=t2[i-h][j]*C;
      if(t[i][j]==target){
        if(i-h+1>=0&&j-w+1>=0)
          printf("%d %d\n",i-h+1,j-w+1);
      }
    }
  }


  return 0;
}



Measured memory_bytes: 20816
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;


int main()
{
	int n, alice = 0, bob = 0;
	int a[110];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	sort(a, a + n);

	for (int i = 0; i < n; i++)
	{
		if (i % 2 == 0)
		{
			alice += a[i];
		}
		else
		{
			bob += a[i];
		}
	}
	cout << abs(alice - bob) << endl;
	return 0;
}

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

typedef long long int ll;
ll arr[102][2];
ll dp[102][100002];
ll n,w;

ll func(ll i,ll j)
{
	if(dp[i][j]!=-1)
		return dp[i][j];
	if(j>=arr[i][0])
		dp[i][j] = max(func(i-1,j),func(i-1,j-arr[i][0])+arr[i][1]);
	else
		dp[i][j] = func(i-1,j);
	return dp[i][j];
}

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> w;
	ll i,j;
	for(i=1;i<=n;i++)
	{
		cin >> arr[i][0] >> arr[i][1];
		for(j=0;j<=w;j++)
			dp[i][j]=-1;
	}

	for(i=0;i<=w;i++)
	{
		if(arr[0][0]<=i)
			dp[0][i] = arr[0][1];
		else
			dp[0][i]=0; 
	}
	for(i=1;i<=n;i++)
		dp[i][0]=0;
	ll ans = func(n,w);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 79232
#include<bits/stdc++.h>
#define ll long long
#define p 998244353
#define inv2 499122177
using namespace std;
int mu[1000010],ss[1000010],cnt;bool pri[1000010];
int a[200010],tong[1000010];
int h[1000010],f[1000010];
int n,m,k;
int inv[1000010];
void init(int N){
    mu[1]=1;
    for(int i=2;i<=N;i++){
        if(!pri[i])ss[++cnt]=i,mu[i]=-1;
        for(int j=1;i*ss[j]<=N&&j<=cnt;j++){
            pri[i*ss[j]]=1;
            if(i%ss[j]==0){
                mu[i*ss[j]]=0;
                break;
            }
            mu[i*ss[j]]=-mu[i];
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]),tong[a[i]]++;
    inv[1]=1;
    for(int i=2;i<=1000000;i++)inv[i]=1ll*inv[p%i]*(p-p/i)%p;
    init(1000000);
    for(int i=1;i<=1000000;i++){
        for(int j=i;j<=1000000;j+=i)(h[i]+=1ll*tong[j]*j%p)%=p,
        (f[i]+=1ll*j*tong[j]%p*j%p)%=p;
    }
    for(int i=1;i<=1000000;i++)
    f[i]=1ll*((1ll*h[i]*h[i]%p-f[i])%p+p)%p*inv2%p;
    ll ans=0;
    for(int k=1;k<=1000000;k++)
    for(int T=k;T<=1000000;T+=k)
    (ans+=1ll*inv[k]*mu[T/k]%p*f[T]%p)%=p;cout<<ans;
    return 0;
}

Measured memory_bytes: 23424
N,M = (int(i) for i in input().split())
AB = []

for i in range(N):
  AB.append([int(i) for i in input().split()])

AB = sorted(AB,key=lambda x:x[0])

count = 0
ans = 0

for A,B in AB:
  if count + B > M:
    ans += A*(M-count)
    break
  else:
    ans += A*B
    count += B


print(ans)


Measured memory_bytes: 23520
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    int n;
    cin>>n;
    vector<double> a(n);
    rep(i,0,n)cin>>a[i];
    double sum=0;
    rep(i,0,n){
        sum+=1/a[i];
    }
    cout<<setprecision(6)<<fixed<<1/sum<<endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#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 FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

vector<ll> a;


int main(int argc, char const *argv[]) {
    int n,m; std::cin >> n >> m;
    std::priority_queue<ll> a; REP(i,n) {
        ll temp; std::cin >> temp;
        a.push(temp);
    }

    REP(i,m) {
        ll temp = a.top(); a.pop();
        a.push(temp/2);
    }
    ll ans = 0; REP(i,n) {
        ans += a.top(); a.pop();
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1400
import sys
INF = (sys.maxint)/3

def SmallestWindow(S, a_list):
	i = 0
	j = 0
	tmpS = 0
	res = INF
	while 1 :
		while tmpS < S and i <len(a_list):
			tmpS += a_list[i]
			i = i+1
		if (tmpS <S):
			break
		res = min (res, i-j)
		tmpS -=a_list[j]
		j += 1
	if res == INF:
		res = 0
	return res
		

def main():
	N, S = map(int, raw_input().split())
	a_list = map(int, raw_input().split())
	print SmallestWindow(S, a_list)

if __name__ == '__main__':
	main()

Measured memory_bytes: 14752
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
int a[10][10][10];
int cnt[10][10];
 
bool check2(int x, int y, int z, int dx, int dy, int dz, int s, int t) {
  if(a[x][y][z]!=t) return false;
  if(s==m) return true;
  return check2(x+dx,y+dy,z+dz,dx,dy,dz,s+1,t);
}
bool check(int t) {
  bool ck=false;
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      for(int l=0; l<n; l++) {
    if(ck) continue;
    if(a[i][j][l]==t) {
      if(j<=n-m) {
        if(check2(i,j,l,0,1,0,1,t)) ck=true;
        if(l<=n-m) {
          if(check2(i,j,l,0,1,1,1,t)) ck=true;
        }
        if(l>=m-1) {
          if(check2(i,j,l,0,1,-1,1,t)) ck=true;
        }
      }
      if(i<=n-m) {
        if(check2(i,j,l,1,0,0,1,t)) ck=true;
        if(l<=n-m) {
          if(check2(i,j,l,1,0,1,1,t)) ck=true;
        }
        if(l>=m-1) {
          if(check2(i,j,l,1,0,-1,1,t)) ck=true;
        }
      }
      if(i<=n-m && j<=n-m) {
        if(check2(i,j,l,1,1,0,1,t)) ck=true;
        if(l<=n-m) {
          if(check2(i,j,l,1,1,1,1,t)) ck=true;
        }
        if(l>=m-1) {
          if(check2(i,j,l,1,1,-1,1,t)) ck=true;
        }
      }
      if(i>=m-1 && j<=n-m) {
        if(check2(i,j,l,-1,1,0,1,t)) ck=true;
        if(l<=n-m) {
          if(check2(i,j,l,-1,1,1,1,t)) ck=true;
        }
        if(l>=m-1) {
          if(check2(i,j,l,-1,1,-1,1,t)) ck=true;
        }
      }
      if(l<=n-m) {
        if(check2(i,j,l,0,0,1,1,t)) ck=true;
      }
    }
      }
    }
  }
  return ck;
}
 
int main() {
  while(cin >> n >> m >> k && n) {
    memset(a,0,sizeof(a));
    memset(cnt,0,sizeof(cnt));
    int T=1;
    int ans=0;
    for(int i=1; i<=k; i++) {
      int x,y;
      cin >> x >> y;
      x--;y--;
      a[x][y][cnt[x][y]]=T;
      cnt[x][y]++;
      if(ans) continue;
      if(check(T)) {
    ans=i;
    continue;
      }
      if(T==1) T=2;
      else T=1;
    }
    if(!ans) cout << "Draw" << endl;
    else {
      if(T==1) cout << "Black " << ans << endl;
      else cout << "White " << ans << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1168
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N, A;
	cin >> N >> A;
	cout << N * N - A;
}

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

N, W = map(int, input().split())
vs = []
ws = []
for i in range(N):
    v, w = map(int, input().split())
    vs.append(v)
    ws.append(w)

dp = [-float('inf') for i in range(W+1)]
dp[0] = 0
max_w = 0
for w in range(W+1):
    for i in range(N):
        if w - ws[i] < 0 :
            continue
        dp[w] = max(dp[w], dp[w-ws[i]]+vs[i])
        max_w = max(max_w, dp[w])

#print(dp[W])
print(max_w)



Measured memory_bytes: 5944
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int h,a; cin >> h >> a;
  cout << (h+a-1)/a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <math.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n1,n2) for(int i=n1;i<n2;i++)
using namespace std;
typedef long long ll;
int main() {
    int n,k;
    cin >> n >> k;
    int res = (n-2)/(k-1)+1;
    cout << res << endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.*;

class Main {

	static int MAX = 1000000;
	static boolean isPrime[] = new boolean[MAX+2];

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		seive();
		for(;;){
			int n = in.nextInt(), ub = in.nextInt();
			if(n==0 && ub==0) return ;
			int a[] = new int[n];
			for(int i=0; i<n; i++){
				a[i] = in.nextInt();
			}
			int ans = solve(a, ub);
			if(ans < 0) System.out.println("NA");
			else System.out.println(ans);
		}
	}
	
	static int solve(int[] a, int ub){
		boolean ok[] = new boolean[ub+1];
		ok[0] = true;
		for(int i=0; i<ub; i++)if(ok[i]){
			for(int j=0; j<a.length; j++)if(i+a[j] <= ub){
				ok[i + a[j]] = true;
			}
		}
		int ans = -1;
		for(int i=ub; i>0; i--)if(ok[i] && isPrime[i]){
			ans = i;
			break;
		}
		
		return ans;
	}
	
	static void seive(){
		for(int i=1; i<=MAX; i++) isPrime[i] = true;
		for(int i=2; i*i<=MAX; i++)if(isPrime[i]){
			for(int j=2*i; j<=MAX; j+=i)
				isPrime[j] = false;
		}
	}
}

Measured memory_bytes: 16000
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    long long int N;
    cin>>N;
    long long int mincou=0,minabs=2100000000;
    long long int ans=0;
    for(int i=0;i<N;i++){
        long long int a;
        cin>>a;
        if(a<0)mincou++;
        minabs=min(minabs,abs(a));
        ans+=abs(a);
    }
    if(mincou%2==0)cout<<ans<<endl;
    else cout<<ans-2*minabs<<endl;
    return 0;
}


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

typedef int64_t i64;
typedef uint64_t ui64;

class graph{
public:
    struct adj{
        int index;
        int start;
        int to;
        i64 cost;
    };
    int nd;
    int eg;
    vector<adj> *node;
    vector<adj> edge;
    graph(int n,int m){
        nd=n;
        eg=m;
        node=new vector<adj>[nd]{};
        edge={};
    }
    void add_dir(int i,int s,int t,i64 c){
        node[s].push_back({i,s,t,c});
        edge.push_back({i,s,t,c});
    }
    void add_undir(int i,int s,int t,i64 c){
        node[s].push_back({i,s,t,c});
        node[t].push_back({i,t,s,c});
        edge.push_back({i,s,t,c});
    }
    void refr(void){
        for(int i=0;i<nd;i++) vector<adj>().swap(node[i]);
        delete[] node;
        vector<adj>().swap(edge);
    }
    bool IsLink(void);
    void DFS(int r,i64 *&p,bool *&vst);
    bool IsPlus(void);
    void BellmanFord(int s,i64 *&d);
    void Dijkstra(int s,i64 *&d);
    void BFS(int s,i64 *&d);
    void WarshallFloyd_dir(i64 **&d);
    void WarshallFloyd_undir(i64 **&d);
    i64 WMST_dir(int r);
    i64 WMST_undir(void);
    void Edmonds(int r,vector<adj> &p);
    void Kruscal(vector<adj> &p);
    void Prim(vector<adj> &p);
    void Artic(vector<int> &p);
    void Artic_sub(int r,int &k,int par,vector<int> &p,int *&ord,int *&low,bool *&vst);
    void Bridge(vector<adj> &p);
    void Bridge_sub(int r,int &k,int par,vector<adj> &p,int *&ord,int *&low,bool *&vst);
    void SCC(int *&c);
    void SCC_sub1(int r,vector<int> &vs,bool *&vst);
    void SCC_sub2(int r,int k,int *&c,bool *&vst,graph &rg);
    void Cumul(int s,i64 *&d);
};

void graph::SCC(int *&c){
    graph rg(nd,eg);
    for(int i=0;i<edge.size();i++) rg.add_dir(edge[i].index,edge[i].to,edge[i].start,edge[i].cost);
    vector<int> vs;
    bool *vst=new bool[nd]{};
    for(int i=0;i<nd;i++){
        if(!vst[i]) SCC_sub1(i,vs,vst);
    }
    for(int i=0;i<nd;i++) vst[i]=0;
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
        if(!vst[vs[i]]){
            SCC_sub2(vs[i],k,c,vst,rg);
            k++;
        }
    }
    delete[] vst;
    rg.refr();
}

void graph::SCC_sub1(int r,vector<int> &vs,bool *&vst){
    vst[r]=1;
    for(const auto &i:node[r]){
        if(!vst[i.to]) SCC_sub1(i.to,vs,vst);
    }
    vs.push_back(r);
}

void graph::SCC_sub2(int r,int k,int *&c,bool *&vst,graph &rg){
    vst[r]=1;
    c[r]=k;
    for(const auto &i:rg.node[r]){
        if(!vst[i.to]) SCC_sub2(i.to,k,c,vst,rg);
    }
}

int main(void){
    int v,e;
    scanf("%i%i",&v,&e);
    graph g(v,e);
    int s,t;
    for(int i=0;i<e;i++){
        scanf("%i%i",&s,&t);
        g.add_dir(i,s,t,1);
    }
    int *c=new int[v];
    g.SCC(c);
    int q;
    scanf("%i",&q);
    for(int i=0;i<q;i++){
        scanf("%i%i",&s,&t);
        if(c[s]==c[t]) printf("1\n");
        else printf("0\n");
    }
    return 0;
}



Measured memory_bytes: 6396
import java.io.*;

public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br =
		new BufferedReader(new InputStreamReader(System.in));
		
		String str=br.readLine();
		long sum=0;
		long num1=Long.parseLong(str);
		
		for(long i=0;i<=num1;i++){
			if(i%3!=0&&i%5!=0){
				sum+=i;
			}
		}
		
		System.out.println(sum);
	}
}

Measured memory_bytes: 32620
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <random>
using namespace std;

const int N_MAX = 1e+5;
int N;
int K;
int h[N_MAX];
int dp[N_MAX];

int solve (int i){
	if (i == N-1) return 0;
	if (dp[i] != -1) return dp[i];

	int min_cost = abs(h[i] - h[i+1]) + solve(i+1);

	for (int j = min(i+K, N-1); j >= i+2; --j)
	{
		min_cost = min(
			min_cost,
			abs(h[i] - h[j]) + solve(j)
		);
	}
	return dp[i] = min_cost;
}

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

	for (int i=0; i<N; ++i)
	{
		cin >> h[i];
		dp[i] = -1;
	}

	cout << solve(0) << endl;

	return 0;
}


Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int a,b,c,d,e,f,x[10000],y[10000];
int main()
{
	cin>>a>>b>>c>>d>>e>>f;
	x[0]=y[0]=1;
	for(int i=0;i<=f;i++)
	{
		if(x[i])x[i+100*a]=x[i+100*b]=1;
		if(y[i])y[i+c]=y[i+d]=1;
	}
	int w=100*a,s=0;
	for(int i=100;i<=f;i+=100)
		if(x[i])for(int j=0;j<=min(i/100*e,f-i);j++)
			if(y[j]&&s*i<j*w)w=i,s=j;
	cout<<w+s<<' '<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
#include <iomanip>
using namespace std;
    
#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int n;
int p[21];

int main(){
    cin >> n;
    rep(i,n){
        cin >> p[i];
    }

    int cnt = 0;
    for(int i=1; i<n-1; i++){
        if(p[i] != *max_element(&p[i-1], &p[i+2]) && p[i] != *min_element(&p[i-1], &p[i+2])){
            cnt ++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=1e6+5,Mo=998244353,iv=Mo+1>>1;

int n,m,c[N],g[N],inv[N],p[N],mu[N];
bool vis[N];

void pre(int N) {
	mu[1]=1;
	fo(i,2,N) {
		if (!vis[i]) p[++p[0]]=i,mu[i]=-1;
		fo(j,1,p[0]) {
			int k=i*p[j];if (k>N) break;
			vis[k]=1;if (!(i%p[j])) break;
			mu[k]=-mu[i];
		}
	}
}

int main() {
	n=read();
	fo(i,1,n) {
		int x=read();
		c[x]++;m=max(m,x);
	}
	pre(m);
	fo(i,1,m) fo(j,1,m/i) (g[i]+=(ll)j*c[i*j]%Mo*i%Mo)%=Mo;
	inv[0]=inv[1]=1;fo(i,2,m) inv[i]=(ll)(Mo-Mo/i)*inv[Mo%i]%Mo;
	int ans=0;
	fo(i,1,m) {
		int ret=0;
		fo(j,1,m/i) (ret+=(ll)mu[j]*g[i*j]*g[i*j]%Mo)%=Mo;
		(ans+=(ll)ret*inv[i]%Mo)%=Mo;
	}
	fo(i,1,m) (ans-=(ll)c[i]*i%Mo)%=Mo;
	ans=(ll)ans*iv%Mo;
	printf("%d\n",(ans+Mo)%Mo);
	return 0;
}

Measured memory_bytes: 18560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  if(s[0] == s[1]){
    cout << 1 SP 2 << endl;
    return 0;
  }
  rep(i,s.length()-2){
    if(s[i] == s[i+2] || s[i+1] == s[i+2]){
      cout << i+1 SP i+3 << endl;
      return 0;
    }
  }
  cout << -1 SP -1 << endl;
  return 0;
}


Measured memory_bytes: 512