akhauriyash/Code-Regression huggingface dataset:
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

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

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

string s, t;
int k;

int dp[310][310];
int dp2[310][310];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> s;
	cin >> k;
	t = s;
	reverse(t.begin(), t.end());
	int n = s.size();
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= n; ++j)
			dp[i][j] = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) {
			if (s[i - 1] == t[j - 1]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	for (int i = 1; i <= k; ++i) {
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= n; ++j)
				dp2[i][j] = 0;
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j) {
				if (s[i - 1] == t[j - 1]) {
					dp2[i][j] = dp2[i - 1][j - 1] + 1;
				}
				else {
					dp2[i][j] = max({dp2[i - 1][j], dp2[i][j - 1], dp[i - 1][j - 1] + 1});
				}
			}
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= n; ++j)
				dp[i][j] = dp2[i][j];
	}
	int ans = 0;
	for (int i = 1; i < n; ++i)
		ans = max(ans, 2 * dp[i][n - i]);
	for (int i = 0; i < n; ++i) {
		ans = max(ans, 2 * dp[i][n - 1 - i] + 1);
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string[] cin = Console.ReadLine().Split();
        long n = long.Parse(cin[0]);
        long k = long.Parse(cin[1]);
        long[] basket = new long[100001];
        for (long i = 0; i < n; i++)
        {
            cin = Console.ReadLine().Split();
            basket[long.Parse(cin[0])] += long.Parse(cin[1]);
        }

        long ans = 0;
        for (long i = 1; i < 100001; i++)
        {
            k -= basket[i];
            if (k <= 0)
            {
                ans = i;
                break;
            }
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 15816
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <sstream>
#include <numeric>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<long long> luca(n+1);
    luca[0] = 2;
    luca[1] = 1;
    for(int i = 2; i <= n; i++){
        luca[i] = luca[i-1] + luca[i-2];
    }
    cout << luca[n] << endl;
    return 0;

}


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

using namespace std;

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

	int ans = 0;
	for (int i = 1; i <= N; ++i) {
		if (2 * i < N) { ++ans; }
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    A, B, K = [int(_) for _ in input().split()]
    
    l = 0
    for i in range(A):
        #print(B % (A-i-1))
        #exit()
        if A % (A-i) == 0 and B % (A-i) == 0:
            #print("A")
            l = l + 1
            #print(l)
            if l == K:
                print(A-i)
                exit()
    
main()


Measured memory_bytes: 2940
import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())

AB = [list(map(int,readline().split())) for i in range(N)]

AB = sorted(AB, key = lambda x:x[0])
amount = 0
for a,b in AB:
  amount += b
  if amount >= K:
    print(a)
    break


Measured memory_bytes: 29824
N, M = gets.split.map(&:to_i)

cities = Hash.new { |h, k| h[k] = [] }
list = []

M.times do
  c, y = gets.split.map(&:to_i)
  list << [c, y]
  cities[c] << y
end

order = Hash.new { |h, k| h[k] = Hash.new }

cities.each do |k, v|
  v.sort!

  v.sort.each.with_index(1) do |y, i|
    order[k][y] = i
  end
end

list.each do |c, y|
  puts "%06d%06d" % [c, order[c][y]]
end



Measured memory_bytes: 64380
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
int cnt[213456];
signed main() {
	int n, a = 0, b; cin >> n;
	vector<vector<long long>>aa(n, vector<long long>(2));
	for (int h = 0; h < n; h++) {
		cin >> aa[h][1] >> aa[h][0];
	}
	sort(aa.begin(), aa.end());
	for (int h = 0; h < n; h++) {
		a += aa[h][1];
		if (aa[h][0] < a) { cout << "No" << endl; return 0; }
	}
	cout << "Yes" << endl;
	return 0;
}

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

using ld=long double;
int main(){
    int n,m,l;
    cin>>n>>m>>l;
    vector<ld> p(n);
    vector<int> t(n),v(n);
    for(int i=0;i<n;i++){
        cin>>p[i]>>t[i]>>v[i];
        p[i]/=100;
    }

    vector<vector<ld>> pos(n,vector<ld>(m+1,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<=m;j++){
            pos[i][j]=j*log(p[i]+1e-30)+(m-j)*log(1-p[i]+1e-30);
            for(int k=0;k<j;k++){
                pos[i][j]+=log(m-k)-log(k+1);
            }
            pos[i][j]=exp(pos[i][j]);
        }
        // vector<vector<ld>> comb(m+1,vector<ld>(m+1,0));
        // comb[0][0]=1;
        // for(int j=0;j<=m;j++){
        //     for(int k=0;k<=j;k++){
        //         if(k==0){
        //             comb[j][k]=(p[i]==1 ? ld(0) : ld(pow(1-p[i],ld(j))));
        //         }
        //         else if(k==j){
        //             comb[j][k]=(p[i]==0 ? ld(0) : ld(pow(p[i],j)));
        //         }
        //         else{
        //             comb[j][k]=comb[j-1][k-1]*p[i]+comb[j-1][k]*(1-p[i]);
        //         }
        //     }
        // }
        // pos[i]=comb[m];
    }
    vector<vector<ld>> possum(n,vector<ld>(m+2));
    for(int i=0;i<n;i++){
        partial_sum(pos[i].begin(),pos[i].end(),possum[i].begin()+1);
    }

    vector<ld> res(n,0);
    for(int i=0;i<n;i++){
        if(v[i]==0) continue;
        for(int x=0;x<=m;x++){
            ld sc=pos[i][x];
            for(int j=0;j<n;j++){
                if(i==j || v[j]==0) continue;
                ld z=0;
                for(int y=0;y<=m;y++){
                    if(l*v[j]+x*t[i]*v[i]*v[j]<l*v[i]+y*t[j]*v[i]*v[j]){
                        z+=pos[j][y];
                    }
                }
                sc*=z;
            }
            res[i]+=sc;
        }
    }
    cout<<setprecision(8)<<fixed;
    for(int i=0;i<n;i++){
        cout<<res[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3796
results = []
while True:

    n,x = map(int ,raw_input().split())
    
    if n is x is 0:
        break
    s = 0
    for i in xrange(1,n+1):
        for j in xrange(1,n+1):
            for k in xrange(1,n+1):
                if i+j+k == x:
                    if i != j and j != k and k != i :
                        s+=1
       
    results.append(s/6)

for i in results:
    print i

Measured memory_bytes: 6380
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  ll ans = 0;
  ll V[110];
  ll revV[110];
  rep(i, N) {
      cin >> V[i];
  }
  rep(i, N) {
      revV[N - 1 - i] = V[i];
  }
  rep(i, N + 1) {
    rep(j, N + 1) {
      if(i + j <= K && i + j <= N) {
        ll ret = 0;
        priority_queue<ll, vector<ll>, greater<ll>> pque;
        rep(k, i) {
          pque.push(V[k]); ret += V[k];
        }
        rep(k, j) {
          pque.push(revV[k]); ret += revV[k];
        }
        rep(k,min(i + j, K - i - j)) {
          ll rem = pque.top(); pque.pop();
          if(rem < 0) ret -= rem;
        }
        ans = max(ans, ret);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long

using namespace std;

int main(void)
{
    LL n;
    while(cin >> n)
    {
        LL cnt = n/11*2;
        n = n % 11;
        if(n == 0)
            cnt += 0;
        else if(n <= 6)
            cnt++;
        else
            cnt+=2;
        cout << cnt << endl;
    }

}


Measured memory_bytes: 256
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    #前から見ると最短でできる
    # + 後ろから見ると最遅でできる　→最短でも最遅でも変わらぬ日数で扱うべきなら必須
    N,K,C=MI()
    S=input()
    
    fast=[0]*N
    slow=[0]*N
    inf=10**10
    day=1#何日目にやるか
    i=0
    while i<N:
        if S[i]=="x":
            i+=1
        else:
            fast[i]=day
            day+=1
            i+=C+1
    
    #最遅の場合，後ろから見ているのでdayの順番も逆にしている
    i=N-1
    day=1
    while i>=0:
        if S[i]=="x":
            i-=1
        else:
            slow[i]=day
            day+=1
            i-=C+1
            
            
    ans=[]
    for i in range(N):
        if fast[i]*slow[i]!=0:
            if fast[i]+slow[i]==K+1:
                ans.append(i)
                
                
    for i in range(len(ans)):
        print(ans[i]+1)
            
        
            
            
    
        
    

main()


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    int a = 0, b = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') {
            ++a;
        }
    }
    int ans = max(a, b);
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') {
            --a;
        } else {
            ++b;
        }
        int now = max(a, b);
        ans = min(ans, now);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3756
N = int(input())
lis = input().split()
a = int(lis[0])
b = int(lis[1])

#print(a, b)

li = []
zero = 0

for i in range(a, b+1):
    if i % N == 0:
        print("OK")
        zero = 1
        break

if zero == 0:
    print("NG")

Measured memory_bytes: 9184
k = int(input())
nums = "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"


nums = [ int(i.rstrip()) for i in nums.split(',')]

print(nums[k-1])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repb(i, n) for (int i = (int)n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[])
{
    int h, w;
    string tmp;
    int ans1, ans2;
    cin >> h >> w;
    rep(i, h)
    {
        rep(j, w)
        {
            cin >> tmp;
            if (tmp[0] == 's' && tmp[1] == 'n' && tmp[2] == 'u' && tmp[3] == 'k' && tmp[4] == 'e')
            {

                ans1 = i;
                ans2 = j;
            }
        }
    }
    cout << char('A' + ans2) << ans1 + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    int ret = 0;
    rep(i,n){
        int a;cin >> a;
        if((i+1)%2 == 1 && a%2 == 1)ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
using namespace std;

int64_t calcGCD(int64_t a,int64_t b){
    int64_t p = a;
    int64_t q = b;
    int64_t c = a%b;
    while(c != 0){
        p = q;
        q = c;
        c = p%q;
    }
    return q;
}
int fk(int n){
  if(n==0){
    return 1;
  }else{
    return fk(n-1)*n;
  }
}

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  rep(i,n){
    cin >> p.at(i);
  }
  rep(i,n){
    cin >> q.at(i);
  }
  vector<bool> flagv(n);
  int pd = 0;
  rep(i,n){
    int ayumi = 0;
    rep(j,n){
      if(p.at(i) == j+1){
        pd += ayumi*fk(n-1-i);
        flagv.at(j) = true;
        break;
      }else if(!flagv.at(j)){
        ayumi++;
      }
    }
  }   
  vector<bool> flagva(n);
  int qd = 0;
  rep(i,n){
    int ayumi = 0;
    rep(j,n){
      if(q.at(i) == j+1){
        qd += ayumi*fk(n-1-i);
        flagva.at(j) = true;
        break;
      }else if(!flagva.at(j)){
        ayumi++;
      }
    }
  }
  cout << abs(pd-qd) << endl;
}

Measured memory_bytes: 256
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int N, D; cin >> N >> D;
  int ans = 0;
  while (N > 0) {
    ans++;
    N -= D*2+1;
  }
  cout << ans << endl;
}



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

int main() {
  string S;
  cin >> S;
  
  if(S=="KIHBR" || S=="AKIHBR" || S=="KIHABR" || S=="KIHBAR" ||
     S=="KIHBRA" || S=="AKIHABR" || S=="AKIHBAR" || S=="AKIHBRA" ||
     S=="KIHABAR" || S=="KIHABRA" || S=="KIHBARA" || S=="AKIHABAR" ||
     S=="AKIHABRa" || S=="AKIHBARA" || S=="KIHABARA" || S=="AKIHABARA"){
    cout << "YES" << endl;
  }
  
  else{
    cout << "NO" << endl;
  }
  
}
  
  

Measured memory_bytes: 3624
from sys import stdout
def main():
    n, m = map(int, raw_input().split())
    a = map(int, raw_input().split())
    if m == 1:
        print a[0]
        if n == 1:
            print 1
            print 1
        else:
            print 2
            print 1, n - 1
        return
    if sum(x % 2 for x in a) > 2:
        print "Impossible"
        return
    a.sort(key=lambda x: x%2)
    a = a[-1:] + a[:-1]
    t = a[:]
    t[0] += 1
    t[-1] -= 1
    if not t[-1]:
        t.pop()
    stdout.write(' '.join(map(str, a)))
    stdout.write('\n')
    stdout.write(str(len(t)) + '\n')
    stdout.write(' '.join(map(str, t)))
    stdout.write('\n')
main()


Measured memory_bytes: 2696
D,G = map(int,input().split())
pc = [list(map(int,input().split())) for _ in range(D)]
ans = float('inf')
for i in range(1<<D):
    score = 0
    cnt = 0
    for j in range(D):
        if i&(1<<j):
            score += pc[j][0]*(j+1)*100+pc[j][1]
            cnt += pc[j][0]
    if score>=G:
        ans = min(ans,cnt)
    else:
        for j in range(D)[::-1]:
            if i&(1<<j):
                continue
            for k in range(pc[j][0]):
                score += 100*(j+1)
                cnt += 1
                if score>=G:
                    break
            if score>=G:
                break
        ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 42224
//master
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        double n = sc.nextDouble();
        p(Math.PI*n*2);
    }
    public static <T> void p(T message) {
        System.out.println(message);
    }

    public static <T> void pe(T message) {
        System.err.println(message);
    }

    public static <T> void pp(T message) {
        System.out.print(message);
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 33316
N, K = map(int, input().split())
xy = [tuple(map(int, input().split())) for _ in range(N)]
xy.sort(key=lambda t: t[0])
ans = 10**20

for i in range(N):
    for j in range(i+K-1, N):
        xlen = xy[j][0]-xy[i][0]
        ys = []
        
        for k in range(i, j+1):
            ys.append(xy[k][1])
            
        ys.sort()
        ylen = 10**20
        
        for k in range(len(ys)-K+1):
            ylen = min(ylen, ys[k+K-1]-ys[k])
        
        ans = min(ans, xlen*ylen)
    
print(ans)

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

int main (){
  
  int N, K;
  cin >> N >> K;
  vector<bool> check(N);
  
  int d = 0;
  
  
  
  for(int j = 1; j < K + 1; j++){
    cin >> d ;
    
    for( int w = 0; w < d; w++){
      int n ;
      cin >> n;
      n = n-1;
      check.at(n) = 1;
    }
    
    
    
    
    
  }
  
                       
                       
    int sum = 0;
  for(int q = 0; q < N; q++){
    
    if(check.at(q) == 0)
      sum++;
    
    
    
    
  }
  
  cout << sum << endl ;
}

Measured memory_bytes: 3636
#include<vector>
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	vector<bool> era(1000000,true);
	era[0]=false;
	for(int i=2;i<1000;i++){
		if(era[i])	for(int j=i*i;j<1000000;j+=i)	era[j]=false;
	}

	for(int n,bud;cin>>n>>bud,n;){
		vector<int> menu(n);
		for(int i=0;i<n;i++)	cin>>menu[i];

		vector<bool> knap(bud+1);
		knap[0]=true;
		for(int i=0;i<n;i++){
			for(int j=0;j<bud;j++){
				if(knap[j] && j+menu[i]<=bud)
					knap[j+menu[i]]=true;
			}
		}

		bool b=false;
		for(int i=bud;i>=0;i--){
			if(knap[i] && era[i]){
				cout<<i<<endl;
				b=true;
				break;
			}
		}
		if(!b)	cout<<"NA"<<endl;
	}

	return 0;
}

Measured memory_bytes: 1148
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    string s;char rem;cin>>s;int ans=0;bool skip=false;
    for(int i=0;i<s.size();i++){
        if(skip){rem='A';ans++;skip=false;continue;}
        if(i==0){rem=s[0];ans++;}
        else{
            if(rem==s[i]){
                skip=true;
            }
            else{
                rem=s[i];ans++;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
bool chmin(ll& a, ll& b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll& b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
string s;
ll saiki(ll x, ll i, ll k) {
    if (i == 0) {
        if (x == n - 1 && k == 1)return 9;
        if (k == 0)return 1;
        if (x == n - 1)return 0;
        return saiki(x + 1, 0, k) + saiki(x + 1, 0, k - 1) * 9;
    }
    a = s[x] - '0';
    if (x == n - 1 && k == 1)return a;
    if (k == 0)return 1;
    if (a == 0)return saiki(x + 1, 1, k);
    return saiki(x + 1, 0, k) + saiki(x + 1, 0, k - 1) * (a - 1) + saiki(x + 1, 1, k - 1);
}
int main() {
    cin >> s >> k;
    n = s.length();
    if(n<k){
    	cout<<0<<endl;
    }
    else cout << saiki(0, 1, k) << endl;
}

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

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios()
{
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = 510;

int n, m;
char a[N][N], b[N][N], c[N][N];

int main()
{
    init_ios();
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    	for (int j = 1; j <= m; ++j) {
    		cin >> a[i][j];
    		if (i == 1 || j == 1 || i == n || j == m) {
    			b[i][j] = '#';
    			c[i][j] = '.';
    		}
    	}
    for (int i = 2; i < n; ++i)
    	for (int j = 2; j < m; ++j) {
    		b[i][j] = a[i][j];
    		c[i][j] = '#';
    	}
    for (int i = 2; i < n; ++i) {
    	bool jest = false;
    	int licz = 0;
    	for (int j = 2; j < m; ++j)
    		if (a[i][j] == '#') {
    			++licz;
    			while (a[i][j+1] == '#')
    				++j;
    			jest = true;
    		}
    	if (jest) {
    		int ile = 0;
    		for (int j = 2; j < m; ++j) {
    			if (a[i][j] == '.') {
    				if (i&1) {
    					b[i][j] = '#';
    					c[i][j] = '.';
    				}
    			}
    			else {
    				++ile;
    				while (a[i][j+1] == '#')
    					++j;
    			}
    		}
    	}
    }
    for (int i = 1; i <= n; ++i) {
    	for (int j = 1; j <= m; ++j)
    		cout<<b[i][j];
    	cout<<"\n";
    }
    cout<<"\n";

    for (int i = 1; i <= n; ++i) {
    	for (int j = 1; j <= m; ++j)
    		cout<<c[i][j];
    	cout<<"\n";
    }
}

Measured memory_bytes: 1536
from functools import lru_cache
import sys
sys.setrecursionlimit(10**7)

N = int(input())
MOD = 10**9 + 7
S = ['A', 'G', 'C', 'T']
M = set(['AGC', 'GAC', 'ACG'])

for s in S:
    M.add(s + 'AGC')
    M.add(s + 'GAC')
    M.add(s + 'ACG')
    M.add('A' + s + 'GC')
    M.add('AG' + s + 'C')

@lru_cache(maxsize=None)
def search(prev, length):
    if length >= N:
        return 1

    ret = 0

    for s in S:
        T = prev + s
        if not T in M:
            T = T[:: -1][: 3][:: -1]
            ret += search(T, length + 1)
    return ret % MOD

ans = search('', 0)
print(ans)


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

#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 rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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

    int r, g, b, n;
    cin >> r >> g >> b >> n;

    ll ans = 0;
    rep(i, n+1){
        rep(j, n+1){
            if((n - r*i - g*j) / b >= 0 && (n - r*i - g*j) % b == 0){
                ans++;
            }
        }
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int a,b,c,n,d[10],l[10];
int MIN(int a,int b){return a<b?a:b;}
int f(int m){
  int i,ans=1e9,s[4]={};
  int u[4]={};
  if(n==m){
    ans=0;
    for(i=0;i<n;i++){
      s[d[i]]+=l[i];
      if(d[i]-3)ans+=10*u[d[i]];
      u[d[i]]=1;
    }
    if(u[0]*u[1]*u[2]==0)return 1e9;
    return abs(a-s[0])+abs(b-s[1])+abs(c-s[2])+ans;
  }
  for(i=0;i<4;i++){
    d[m]=i;
    ans=MIN(ans,f(m+1));
  }
  return ans;
}
int main(){
  int i;
  scanf("%d %d %d %d",&n,&a,&b,&c);
  for(i=0;i<n;i++)scanf("%d",&l[i]);
  f(0);
  printf("%d\n",f(0));
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>


using namespace std;

int main(){


    map<int, bool> nums;

    int a, b, k;
    cin >> a >> b >> k;

    for (int i = a; i <= (min(a + k - 1, b)); i++){
        if (nums.find(i) == nums.end()){
            nums[i] = true;
        } 
    }

    for (int j = b; j >= (max(b - k + 1, a)); j--){
        if (nums.find(j) == nums.end()){
            nums[j] = true;
        } 
    }

    for(map<int, bool>::const_iterator it = nums.begin(); it != nums.end(); ++it)
    { 
        cout << it->first << endl;
    }  


    return 0;
}

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

int main(){

    int n;
    cin>>n;
    int ans=0;
    int before=n+1;
    vector<int> a(n),b(n),c(n-1);

    for(int i=0;i<n;i++) cin>>a.at(i);
    for(int i=0;i<n;i++) cin>>b.at(i);
    for(int i=0;i<n-1;i++) cin>>c.at(i);

    for(int i=0;i<n;i++){

        ans+=b.at(a.at(i)-1);
        if(i>0&&a.at(i)==a.at(i-1)+1) ans+=c.at(a.at(i)-2);

    }
    cout<<ans<<endl;





    return 0;
}

Measured memory_bytes: 256
n = int(input())

d = {}
for i in range(n):
  t = input()
  if t in d.keys():
    d[t] += 1
  else:
    d[t] = 0

s = sorted(list(set(d.keys())))
m = max(d.values())

for s in s:
  if d[s] == m:
    print(s)


Measured memory_bytes: 42460
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]
def MI(): return map(int, input().split())

#1
#1_A
"""
x,y,s,t = map(float, input().split())
a = int(input())
s-=x
t-=y
while a:
    a -= 1
    p,q = map(float, input().split())
    p-=x
    q-=y
    ans_x = s*(q*t+p*s)/(t*t+s*s)
    ans_y = t*(q*t+p*s)/(t*t+s*s)
    print(x+ans_x, y+ans_y)
"""

#1_B
"""
p1x,p1y,c,d = MI()
q = II()
if p1x == c:
    f = 0
elif p1y == d:
    f = 1
else:
    f = 2
    m = (d-p1y)/(c-p1x)
for _ in range(q):
    px,py = MI()
    if not f:
        a = 2*p1x-px
        b = py
    elif f == 1:
        a = px
        b = 2*p1y-py
    else:
        a = (2*py+(1/m-m)*px+2*m*p1x-2*p1y)/(m+1/m)
        b = -1/m*(a-px)+py
    print(a,b)
"""

#1_C
"""
def inner_product(a,b):
    return a[0]*b[0]+a[1]*b[1]

def cross_product(a,b):
    return a[0]*b[1]-a[1]*b[0]
p,q,c,d = MI()
a = [c-p,d-q]
r = II()
for _ in range(r):
    c,d = MI()
    b = [c-p,d-q]
    co = inner_product(a,b)
    si = cross_product(a,b)
    if si == 0:
        if co >= 0:
            if a[0]**2+a[1]**2 >= b[0]**2+b[1]**2:
                print("ON_SEGMENT")
            else:
                print("ONLINE_FRONT")
        else:
            print("ONLINE_BACK")
    elif si > 0:
        print("COUNTER_CLOCKWISE")
    else:
        print("CLOCKWISE")
"""

#2
#2_A
def inner_product(a,b):
    return a[0]*b[0]+a[1]*b[1]

def cross_product(a,b):
    return a[0]*b[1]-a[1]*b[0]
q = II()
for i in range(q):
    s,t,a,b,x,y,c,d = MI()
    a = [a-s,b-t]
    b = [c-x,d-y]
    co = inner_product(a,b)
    si = cross_product(a,b)
    if not si:
        print(2)
    elif not co:
        print(1)
    else:
        print(0)



Measured memory_bytes: 5640
#include "bits/stdc++.h"
using namespace std;

int bubbleSort(vector<int> &A, int N);

int main(void){

  int N;
  cin >> N;

  vector<int> A(N);
  for(int i = 0; i < N; i++) cin >> A.at(i);
  int count = bubbleSort(A, N);

  for(int i = 0; i < N; i++)
  {
    cout << A.at(i);
    if(i == N-1) cout << endl;
    else cout << " ";
  }
  cout << count << endl;

  return 0;

}

int bubbleSort(vector<int> &A, int N)
{
  int count = 0;
  bool flag = true;
  while(flag)
  {
    flag = false;
    for (int j = N-1; 0 < j; j--)
    {
      if(A.at(j) < A.at(j-1))
      {
        swap(A.at(j), A.at(j-1));
        flag = true;
        count++;
      }
    }
  }
  return count;
}


Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
bool rev(int a,int b){
    return a>b;
}

//高橋君とお肉
//https://atcoder.jp/contests/arc029/tasks/arc029_1
// 入力
int n;

// DPテーブル
//int dp[5][210];
int main()
{

	cin >> n;
	long sum = 0;
	vector<int>h(n);
	for (int i = 0; i < n; ++i)
		cin >>h[i];
    rep(i,n){
        sum+=abs(h[i]-h[i-1]);           
    }
    vector<int>dp(n+1);
	// DP初期条件: dp[0][j] = 0

		dp[0] = 0;

	// DPループ
	for (int i = 0; i < n; ++i)
	{
			if(i>0){
				dp[i + 1]= min(dp[i] +abs(h[i+1]-h[i]), dp[i-1]+abs(h[i+1]-h[i-1]));
            }else if(i==0){
                dp[1]=dp[0]+abs(h[0]-h[1]);
            }
		
	}
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int MOD = 998244353;
inline void Add(int& x,int y) {
  x = x + y >= MOD ? x + y - MOD : x + y;
}
inline void Sub(int& x,int y) {
  x = x - y < 0 ? x - y + MOD : x - y;
}
int power(int a,int b) {
  int ret = 1;
  while (b) {
    if (b&1) ret = 1ll * ret * a % MOD;
    a = 1ll * a * a % MOD;
    b >>= 1;
  }
  return ret;
}

map<string,int> mp;
void stringAnd(string& a,string b) {
  int l = (int)a.size();
  rep (i, 0, l-1) {
    if (a[i] == '0' || b[i] == '0')
      a[i] = '0';
    else a[i] = '1';
  }
}
int dfs(string str) {
  if (!str.size()) return 1;
  if (mp.count(str)) return mp[str];
  int& ret = mp[str];
  int len = str.size();
  Add(ret, dfs(str.substr(0, len-1)));
  if (str[len-1] == '1')
    Add(ret, dfs(str.substr(0, len-1)));
  rep (a, 1, len/2) {
    string tmp = str.substr(len - a, a);
    for (int t = 2; a * t <= len; ++ t) {
      stringAnd(tmp, str.substr(len - t * a, a));
      Add(ret, 1ll * dfs(tmp) * dfs(str.substr(0, len - t * a)) % MOD);
    }
  }
  return ret;
}
int main() {
  string str;
  cin >> str;
  cout << dfs(str) << endl;
  return 0;
}


Measured memory_bytes: 5504
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>

using namespace std;

#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
int main() {
	
	
	int x;
	cin >> x ;


	cout << 800 * x - 200 * (x / 15) << endl;




	return 0;
}

Measured memory_bytes: 256
# include<iostream>

int main(){

    int i,j,k,n;
    int num;
    int card[4][13]={0};//配列の初期化
    std::string mark;

    std::cin>>n;

    for(k=1;k<=n;k++){

        std::cin>>mark>>num;

        if(mark=="S"){
            card[0][num-1]=1;
        }
        else if(mark=="H"){
            card[1][num-1]=1;
        }
        else if(mark=="C"){
            card[2][num-1]=1;
        }
        else{
            card[3][num-1]=1;
        }
    }

    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(card[i][j]==0){
                if(i==0){
                    std::cout<<"S "<<j+1<<std::endl;
                }
                else if(i==1){
                    std::cout<<"H "<<j+1<<std::endl;
                }
                else if(i==2){
                    std::cout<<"C "<<j+1<<std::endl;
                }
                else{
                    std::cout<<"D "<<j+1<<std::endl;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3088
a=int(input())
b=[int(i) for i in input().split()]


e=b
f=0
for j in range(10000):
	d=0
	#print(e)
	for i in range(a):
		if e[i]%2==0 and sum(e)!=0:
			d=d+1
		else:
			break
	#print(d)
	if d==a:
		f=f+1
	e=[k/2 for k in e]
print(f)


Measured memory_bytes: 3060
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
if __name__ == "__main__":
    def check(n):
        if n == 1:
            return False
        i = 2
        while i*i <= n:
            if n%i == 0:
                return False
            i += 1
        return True
    f = [0 for i in range(100001)]
    for i in range(1,100001):
        f[i] += f[i-1]
        if check(i):
            if check((i+1)//2):
                f[i] += 1
    q = I()
    for i in range(q):
        l,r = LI()
        print(f[r]-f[l-1])

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve


Measured memory_bytes: 52912
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxn=100000+10;
int x[maxn],xx[maxn],w[maxn];
int i,j,k,l,r,s,t,n,m;
ll c; 
int main(){
    scanf("%d%d%d",&n,&l,&t);
    fo(i,1,n) scanf("%d%d",&x[i],&w[i]);
    fo(i,1,n){
        if (w[i]==2) w[i]=-1;
        r=x[i]+w[i]*t;
        if (r>0) (c+=r/l)%=n;
        else if (r<0) (c+=(r+1)/l-1)%=n;
        xx[i]=(r%l+l)%l;
    }
    sort(xx+1,xx+n+1);
    c=(c+n)%n;
    fo(i,c+1,n) printf("%d\n",xx[i]);
    fo(i,1,c) printf("%d\n",xx[i]);
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  int n; cin >> n;
  if(n%2==1) cout << (n+1) / 2 << endl;
  else cout << n/2 << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
int MOD = 1000000007;\
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> X(N);
	vector<int> Y(N);
	double res = 0;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i];
	}

	
	for (int i = 0; i < N; i++) {
		if (X[i] == 0 && Y[i] == 0)continue;
		double a = -atan2(Y[i], X[i]) + 1e-9;
		double tmp1X = 0;
		double tmp1Y = 0;
		double tmp2X = 0;
		double tmp2Y = 0;
		for (int j = 0; j < N; j++) {
			double x = cos(a) * X[j] - sin(a) * Y[j];
			double y = sin(a) * X[j] + cos(a) * Y[j];
			if (y > 0) {
				tmp1X += x;
				tmp1Y += y;
			}
			else {
				tmp2X += x;
				tmp2Y += y;
			}
		}

		//cerr << tmp1X <<" " <<  tmp1Y << endl;
		//cerr << hypot(tmp2X, tmp2Y) << endl;

		res = max(res, hypot(tmp1X, tmp1Y));
		res = max(res, hypot(tmp2X, tmp2Y));

	}


	cout << fixed << setprecision(15) << res << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
	long int n,m;
	//printf("好きな整数を1～200個入力します。入力する文字数を入力してください。\n");
	scanf("%d", &m);
	//printf("好きな整数を入力してください。\n");
	int count = 0;
	int escape = 0;
	int a[200];
	for (int i = 0;i < m;i++)
	{
		scanf("%d", &a[i]);
	}

	while (1)
	{
		for (int i = 0;i < m;i++)
		{
			if (a[i] % 2 == 1)
			{
				escape = 1;
				break;
			}
			a[i] = a[i] / 2;
		}
		if (escape == 1)
		{
			break;
		}
		count++;
	}
	//printf("試行回数は%d回です。", count);
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 760
import Data.Functor( (<$>))
import Control.Monad( replicateM)
import Data.List( transpose)

main = do
    let
	readLine = (read <$>) . words <$> getLine

    [r,c] <- readLine
    rows <- replicateM r readLine
    let
	addSum list = list++[sum list]

	answer = transpose $ addSum <$> (transpose $ addSum <$> rows)

	printList list = do
		putStr . unwords $ show <$> list
		putStrLn ""

    printList `mapM_` answer



Measured memory_bytes: 8192
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  ll v;
  cin >> n >> v;
  vector<ll> a(n), b(n), c(n), d(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n; ++i) cin >> c[i];
  for (int i = 0; i < n; ++i) cin >> d[i];
  vector<ll> ab;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      ab.push_back(a[i] + b[j]);
    }
  }
  sort(ab.begin(), ab.end());
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      auto it1 = upper_bound(ab.begin(), ab.end(), v - (c[i] + d[j]));
      auto it2 = lower_bound(ab.begin(), ab.end(), v - (c[i] + d[j]));
      ans += it1 - it2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = INT64_MAX;
static const long long MOD = (ll)1e9+7;

#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

class BipartiteMatching {
    vector<vector<ll> > G;
    vll match;
    vector<bool> vis;
    ll N;
    BipartiteMatching(){}
    bool dfs(ll v) {
        vis[v] = true;
        for(auto &u:G[v]) {
            ll w = match[u];
            if(w < 0 || !vis[w] && dfs(w)) {
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }
public:
    BipartiteMatching(ll size) {
        G.resize(size);
        N = size;
    }
    void initialize(ll size) {
        G.clear();
        G.resize(size);
        N = size;
    }
    void unite(ll u, ll v) {
        G[u].push_back(v);
        G[v].push_back(u);
    }
    ll search() {
        ll res = 0;
        match.assign(N, -1);
        for(int v = 0; v < N; v++) {
            if(match[v] < 0) {
                vis.assign(N, false);
                if(dfs(v)) res++;
            }
        }
        return res;
    }
};

void solve() {
    ll N;
    cin >> N;
    vll a(N), b(N), c(N), d(N);
    BipartiteMatching g(N*2);
    REP(i, N) cin >> a[i] >> b[i];
    REP(i, N) cin >> c[i] >> d[i];
    REP(i, N){
        REP(j, N) {
            if(a[i] < c[j] && b[i] < d[j]) {
                g.unite(i, N+j);
            }
        }
    }
    out(g.search());
}

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


Measured memory_bytes: 384
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val xs = readLine()!!.split(" ").map { it.toInt() - 1 }
  val invalids = xs.mapIndexed { index, x -> index == x }.toBooleanArray()
  var count = 0
  for (i in 0 until n) {
    if (invalids[i]) {
      invalids[i] = false
      if (i + 1 < n) invalids[i + 1] = false
      count++
    }
  }
  println(count)
}


Measured memory_bytes: 49840
// Binary Search Tree I
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root, nil;

//  二分探索木へkを挿入 //
void insert(int k){
  Node y = nil; // x の親
  Node x = root; // T の根
  Node z;
  
  //z->parent = y;
  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = nil;
  z->right = nil;

  while(x != nil){
    y = x;   // 親を設定
    if(z->key < x->key)x = x->left; // 左の子へ移動
    else x = x->right;            // 右の子へ移動
  }
  z->parent = y;

  if(y == nil)root = z; // T が空の場合
  else if(z->key < y->key)y->left = z; // z を y の左の子にする
  else y->right = z; // z を y の右の子にする
}

// 再帰を使って中間順巡回(Inorder)で表示
void printInorder(Node u){
  if(u == nil)return;
  printInorder(u->left);
  printf(" %d", u->key);
  printInorder(u->right);
}

// 再帰を使って先行順巡回(Preorder)で表示
void printPreorder(Node u){
  if(u == nil)return;
  printf(" %d", u->key);
  printPreorder(u->left);
  printPreorder(u->right);
}

int main(){
  int n, i, x;
  char com[10];
  
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      printInorder(root);
      printf("\n");
      printPreorder(root);
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll x;
	cin >> x;
	ll c = 0;
	ll ans = 100;

	while (ans < x) {
		c++;
		ans = ans + (ans / 100 );
	}

	cout << c << endl;
}

Measured memory_bytes: 3572
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "vector"
#include "string"
#include "map"
#include "algorithm"
#include "functional"
#include "set"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

long long int gcd(long long int a, long long int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

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

	cin >> N >> M;
	cout << (N - gcd(N, M)) * 3 << endl;
	return 0;
}


Measured memory_bytes: 256