akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

char rtable[26];

string affine(const string &s, int a, int b) {
	string ret = s;
	for (int i = 0; i < ret.size(); i++)
		ret[i] = ((ret[i]-'a')*a + b) % 26 + 'a';
	return ret;
}

void setrtable(int a, int b) {
	for (int x = 0; x < 26; x++) {
		int y = (x*a + b) % 26;
		rtable[y] = (char)(x + 'a');
	}
}

int main() {
	int n; cin >> n;
	string s;
	getline(cin, s); // dummy
	for (int i = 0; i < n; i++) {
		getline(cin, s);
		int aa, bb;
		bool found = false;
		for (int a = 1; a < 26 && !found; a += 2) {
			if (a == 13) continue;
			for (int b = 0; b < 26; b++) {
				string a1 = affine("this", a, b);
				string a2 = affine("that", a, b);
				if (s.find(a1) != string::npos || s.find(a2) != string::npos) {
					aa = a, bb = b;
					found = true;
					break;
				}
			}
		}
		setrtable(aa, bb);
		for (int j = 0; j < s.size(); j++) {
			if (s[j] >= 'a' && s[j] <= 'z')
				cout << rtable[s[j] - 'a'];
			else
				cout << s[j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val n, t, a = sc.nextInt()
  val h: IndexedSeq[Double] = for (_ <- 1 to n) yield sc.nextDouble()
  val ans = h.zipWithIndex.minBy {
    case (x, _) => ((t - x * 0.006) - a ).abs
  }._2 + 1
  println(ans)
}


Measured memory_bytes: 30144
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
typedef long long int ll;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll N;
	cin>>N;
	vector<ll>v(N);
	for(int i=0;i<N;i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	//reverse(v.begin(),v.end());
	ll total=0;
	ll n=N/2;
	int cont=(N%2==0 ? 0 : 1);
	for(int i=0;i<N-1;i++){
		//cout<<i<<" : "<<v[n]<<" n:"<<n<<" cont:"<<cont<<"\n";
		total+=v[n];
		cont=(cont==1 ? 0 : 1);
		n+=(cont==0 ? 1 : 0);
	}
	cout<<total;
}

Measured memory_bytes: 4724
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1e18

struct edge{int to,cost;};
 
void dijkstra(int start, VI t, vector<vector<double> > &d, vector<vector<edge> > graph){
    int n = t.size();
    d[start][(1<<n)-1] = 0.0;
    priority_queue<pair<double, P>, vector<pair<double, P> >, greater<pair<double, P> > > q;
    q.push(make_pair(0.0, P(start, (1<<n)-1)));
    while (!q.empty()){
        pair<double, P> a = q.top();
        q.pop();
        int now = a.second.first;
        int tic = a.second.second;
        if(d[now][tic] < a.first) continue;
        REP(i,graph[now].size()){
            edge e = graph[now][i];
            int next = e.to;
            int dis = e.cost;
            REP(j,n){
                if (!((tic >> j) & 1)) continue;
                double cost = (double)dis/t[j];
                int tic_next = tic - (1<<j);
                if (d[next][tic_next] > d[now][tic] + cost){
                    d[next][tic_next] = d[now][tic] + cost;
                    q.push(make_pair(d[next][tic_next], P(next, tic_next)));
                }
            }
        }
    }
}

int main() {
    int n, m, p, a, b;
    while (cin >> n >> m >> p >> a >> b && n){
        a--;
        b--;
        VI t(n);
        REP(i,n) cin >> t[i];
        vector<vector<edge> > e(m);
        while (p--){
            int x, y, z;
            cin >> x >> y >> z;
            x--;
            y--;
            edge ed;
            ed.to = y;
            ed.cost = z;
            e[x].push_back(ed);
            ed.to = x;
            e[y].push_back(ed);
        }
        vector<vector<double> > dist(m,vector<double>(1<<n,INF));
        dijkstra(a, t, dist, e);
        double ans = INF;
        REP(i,1<<n) ans = min(ans, dist[b][i]);
        if (ans == INF) cout << "Impossible" << endl;
        else printf("%.10f\n", ans);
    }

    return 0;
}

Measured memory_bytes: 4612
import sys
N=int(input())
placeT=[0]*(N+1);placeX=[0]*(N+1);placeY=[0]*(N+1);
for i in range(N):
    placeT[i+1],placeX[i+1],placeY[i+1]=map(int,input().split())
for i in range(1,N+1):
    t0=placeT[i-1];x0=placeX[i-1];y0=placeY[i-1];
    t=placeT[i];x=placeX[i];y=placeY[i];
    if abs(x-x0)+abs(y-y0)>t-t0:
        print("No");sys.exit();
    else:
        if (abs(x-x0)+abs(y-y0)-(t-t0))%2!=0:
            print("No");sys.exit();
print("Yes")

Measured memory_bytes: 11636
fn main() {
    let n: usize = read();
    let mut a = vec![vec![0;n];n];

    let mut stack = vec![(0,n,1)];
    while let Some((l,len,lv)) = stack.pop() {
        match len {
            2 => a[l][l+1] = lv,
            3 => {
                a[l][l+1] = lv;
                a[l+1][l+2] = lv;
                a[l][l+2] = lv + 1;
            }
            _ => {
                for i in l..l+len/2 {
                    for j in l+len/2..l+len {
                        a[i][j] = lv;
                    }
                }
                stack.push((l,len/2,lv+1));
                stack.push((l+len/2,(len+1)/2,lv+1));
            }
        }
    }

    for i in 0..n-1 {
        for j in i+1..n {
            print!("{} ",a[i][j]);
        }
        print!("\n");
    }
}
fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}

fn read<T: std::str::FromStr>() -> T{
    get_line().parse().ok().unwrap()
}

Measured memory_bytes: 4604
import networkx as nx

def factorial(n, mod):
    fac = [0] * (n + 1)
    inv = [0] * (n + 1)
    fac[0], inv[0] = 1, 1
    for i in range(1, n + 1):
        fac[i] = fac[i-1] * i % mod
        inv[i] = inverse(fac[i], mod)
    return fac, inv

def inverse(a, mod):
    a %= mod # 除数が正なら正になる
    p = mod
    x, y = 0, 1
    while a > 0:
        n = p // a
        p, a = a, p % a, 
        x, y = y, x - n * y
    return x % mod # 除数が正なら正になる

mod = 1000000007

n, k = map(int, input().split())
graph = nx.Graph()
graph.add_nodes_from(range(n))

graph.add_edges_from([tuple(map(lambda x : int(x) - 1, input().split())) for _ in range(n-1)])
if nx.degree(graph)[0] + 1 > k:
    print(0)
    quit()

fac, inv = factorial(k, mod)
ans = fac[k] * inv[k - nx.degree(graph)[0] - 1] % mod # nx.degree(graph)[0]:グラフの頂点0から出ている枝の数
for parent, child in nx.dfs_edges(graph, 0): # nx.dfs_edges(graph, 0):グラフの頂点0からDFS
    m = nx.degree(graph)[child]
    if m + 1 > k:
        print(0)
        quit()
    ans = ans * fac[k-2] % mod * inv[k-1-m] % mod
print(ans)


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

using namespace std;

int n;
long long h[301][301];
long long rs;

int main()
{
	std::ios_base::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n;++i) for (int j=0;j<n;++j) cin>>h[i][j];
	for (int i=0;i<n;++i)
	{
		for (int j=0;j<i;++j)
		{
			long long mi=3000000000;
			for (int k=0;k<n;++k)
			{
				if (k==i) continue;
				if (k==j) continue;
				mi=min(mi,h[k][j]+h[i][k]);
			}
			if (mi<h[i][j])
			{
				cout<<-1<<endl;
				return 0;
			}
			if (mi>h[i][j]) rs+=h[i][j];
		}
	}
	cout<<rs<<endl;
}


Measured memory_bytes: 1024
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}
use input::*;

fn main() {
    let (w, a, b): (usize, usize, usize);
    input!(w, a, b);
    if a > b + w {
        p(a - b - w);
    } else if a + w < b {
        p(b - a - w);
    } else {
        p(0);
    }
}

Measured memory_bytes: 4352
while line = gets
    t1, t2 = line.chomp.split.map(&:to_f)
    grade = "NA"
    if t1 < 35.5 && t2 < 71.0
        grade = "AAA"
    elsif t1 < 37.5 && t2 < 77.0
        grade = "AA"
    elsif t1 < 40.0 && t2 < 83.0
        grade = "A"
    elsif t1 < 43.0 && t2 < 89.0
        grade = "B"
    elsif t1 < 50.0 && t2 < 105.0
        grade = "C"
    elsif t1 < 55.0 && t2 < 116.0
        grade = "D"
    elsif t1 < 70.0 && t2 < 148.0
        grade = "E"
    end
    puts grade
end


Measured memory_bytes: 6868
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    string str = "";
    while (n != 0)
    {
        int r = n % 2;
        if (r < 0) r += 2;
        
        str += (char)('0' + r);
        
        n = (n - r) / (-2);
    }
    
    reverse(str.begin(), str.end());
    if (str == "") str = "0";
    
    cout << str << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
rev_A = A[::-1]

box = [0 for i in range(N)]

for i in range(N, 0, -1):
    i -= 1
    
    if i >= N//2:
        box[i] = A[i]
    else:
        ans = A[i]
        for j in range((i+1)*2-1, N, i+1):
            ans += box[j]
        box[i] = ans % 2

ans_count = 0
ans_numbers = []
for i, count in enumerate(box):
    if count == 1:
        ans_count += 1
        ans_numbers.append(i + 1)

print(ans_count)
if ans_count != 0:
    print(*ans_numbers)


Measured memory_bytes: 72380
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let m: u32 = read();
    println!("{}", 48 - m);
}


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

using namespace std;

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

  vector<int> cnt(n, 0);
  for (int i = 0; i < n - 1; ++i) {
    int a;
    cin >> a;
    a--;
    cnt[a]++;
  }
  for (int i = 0; i < n; ++i) {
    cout << cnt[i] << '\n';
  }
  return 0;
}



Measured memory_bytes: 3996
n = int(input())
a_list = list(map(int, input().split()))
Alice = 0
Bob = 0
while n > 0:
    max_Alice = max(a_list)
    s = str(max_Alice)
    a_list[a_list.index(max(a_list))] = 0
    Alice += int(s)
    n -= 1
    if n == 0:
        break
    else:
        max_Bob = max(a_list)
        t = str(max_Bob)
        a_list[a_list.index(max(a_list))] = 0
        Bob += int(t)
        n -= 1
print(Alice - Bob)


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

using ll = long long;
using ld = long double;

const int N = 2e5;

ll pre[N + 69];
ll ans = 1e18;

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

  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    pre[i] = pre[i - 1] + x;
  }
  for(int i = 1; i <= n - 1; i++) {
    ans = min(ans, abs(2 * pre[i] - pre[n]));
  }
  cout << ans << '\n';
  
  return 0;
}

Measured memory_bytes: 5184
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

bool check(int i, string& s, vector<char>&t, vector<char>&d, int c){
  for(int j=0; j<t.size(); j++){
    if(s[i]==t[j]){
      if(d[j]=='R')i++;
      else i--;
    }
  }
  return i==c;
}

int main(){
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  s.insert(s.begin(), '#');
  vector<char>t(q), d(q);
  s.push_back('#');
  for(int i=0; i<q; i++)cin >> t[i] >> d[i];
  int ok1=0, ng1=n+1;
  while(ng1-ok1>1){
    int mid=(ok1+ng1)/2;
    if(check(mid, s, t, d, 0)){
      ok1=mid;
    }
    else {
      ng1=mid;
    }
  }
  int ok2=n+1, ng2=0;
  while(ok2-ng2>1){
    int mid=(ok2+ng2)/2;
    if(check(mid, s, t, d, n+1)){
      ok2=mid;
    }
    else {
      ng2=mid;
    }
  }
  cout << ng2-ok1;
  cerr << ok1 << endl;
  cerr << ng1 << endl;
  cerr << ng2 << endl;
  cerr << ok2 << endl;
  return 0;
}


Measured memory_bytes: 960
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
const int maxn = 4000000;
int grid[111][111];
int M(){
    int h, w;
    if(!~scanf("%d %d", &h, &w)) return 0;
    int n;
    cin >> n;
    int x = 0, y = 0, d = 1;
    for(int e = 1; e <= n; e++){
        int qtd;
        cin >> qtd;
        while(qtd--){
            grid[x][y] = e;
            if(y == w-1 && d == 1){
                x++;
                d = -1;
            } else if(y == 0 && d == -1){
                x++;
                d = 1;
            } else
                y += d;
        }
    }
    for(int e = 0; e < h; e++)
        for(int f = 0; f < w; f++)
            printf("%d%c", grid[e][f], " \n"[f == w-1]);
    return 1;
}
int main(){
    while(M());
    return 0;
}


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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

ll powbin(ll base, ll p)
{
	ll mul;

	if (p == 1) mul = base;
	else {
		mul = (ll)powbin(base, p / 2);
		mul = (mul * mul) % MOD;
		if (p % 2) mul *= base;
	}

	return mul % MOD;
}

ll combination(ll n, ll r)
{
	ll num = 1, den = 1;
	
	for (ll i = n; i >= n - r + 1; i--) {
		num = (num * i) % MOD;
	}
	for (ll i = r; i >= 1; i--) {
		den = (den * i) % MOD;
	}
	return (num * powbin(den, MOD - 2)) % MOD;
}

int main()
{
	int n, a, b;
	ll ans = 1;

	cin >> n >> a >> b;

	ans = powbin(2, n) - 1;

	ans = (ans + MOD - combination(n, a)) % MOD;
	ans = (ans + MOD - combination(n, b)) % MOD;

	cout << ans << endl;

	return 0;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            DateTime time = DateTime.Parse(S);

            if(time <= new DateTime(2019, 4, 30))
            {
                Console.WriteLine("Heisei");
            }
            else
            {
                Console.WriteLine("TBD");
            }
        }
    }
}


Measured memory_bytes: 13792
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

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

int main(){
    ll a, b, k; cin >> a >> b >> k;
    ll d = a-k;
    if(a-k<0){
        cout << 0 << " ";
        d = abs(d);
        if(b-d<0) cout << 0 << endl;
        else cout << b-d << endl;;
    }
    else{
        cout << d << " " << b << endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<set>

using namespace std;
const int maxn = 5e4 + 10;
int x[maxn], dp[maxn], s[maxn];
int w, n;
bool ok(int m){
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;
    int k = 0;
    for(int i = 1; i <= n; i++) if(dp[i - 1]){
        for(int j = k; j <= n; j++){
            if(j <= i) continue;
            int sp = w - (s[j] - s[i - 1]);
            if(sp < (j - i)) break;
            int d = sp / (j - i);
            if(sp % (j - i)) d++;
            if(d <= m){
                dp[j] = 1; k = j;
            }
        }
    }
    return n == k || s[n] - s[k] + n - k - 1 <= w;
}
int main(){
    //int w, n;
    while(~scanf("%d%d", &w, &n), w + n){
        s[0] = 0;
        for(int i = 1; i <= n; i++){
            scanf("%d", &x[i]);
            s[i] = s[i - 1] + x[i];
        }
        int l = 1, r = w - 2, m;
        while(r > l){
            m = (l + r) / 2;
            if(ok(m)) r = m;
            else l = m + 1;
        }

        printf("%d\n", l);
    }
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll inf = 1000000000000;

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

  ll cnt = inf;
  for (ll i = 1; i <= (N/i); i++) {
    if (N % i != 0) continue;
    cnt = min(cnt, (i + (N/i) - 2));
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
PATTERNS = [[1, 1, 1], [1, 1, -1], [1, -1, 1], [1, -1, -1], [-1, 1, 1], [-1, 1, -1], [-1, -1, 1], [-1, -1, -1]]

n, m = gets.split(' ').map(&:to_i)
cakes = Array.new(n).map{ gets.split(' ').map(&:to_i) }

if m > 0
  scores = PATTERNS.map{|p|
    cakes.map{|c| c[0]*p[0] + c[1]*p[1] + c[2]*p[2] }.max(m).inject(:+)
  }

  puts scores.max
else
  puts 0
end

Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N,M;
  cin>>N>>M;
  Yes(N==M);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> T;
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  ll n,q;cin>>n>>q;
  vector<T> v;
  rep(i,n){
    ll s,t,x;cin>>s>>t>>x;
    v.push_back(T(s-x,P(-1,x)));
    v.push_back(T(t-x,P(0,x)));
  }
  rep(i,q){
    ll d;cin>>d;
    v.push_back(T(d,P(1,d)));
  }
  sort(all(v));
  multiset<ll> m;
  rep(i,v.size()){
    if(v[i].second.first==-1){
      m.insert(v[i].second.second);
    }else if(v[i].second.first==1){
      if(m.empty()) cout<<-1<<endl;
      else cout<<*m.begin()<<endl;
    }else{
      m.erase(m.lower_bound(v[i].second.second));
    }
  }
}

Measured memory_bytes: 26600
'use strict';
function main(input) {
  input = input.split("\n");
  const sNum = input[0];
  let stations = [];
  let rtn = [];

  for(let i=1; i<sNum; i++){
    stations.push(input[i].split(" "));
  }
  for(let i=0; i<stations.length; i++){
      stations[i] = stations[i].map(n => Number(n));
  }
  for(let i=0; i<stations.length; i++){
    // stations[i] = stations[i].map(n => Number(n));
    let total = 0;
    for(let j=i; j<stations.length; j++){
        // 到着した駅の開通式開始までの時刻が到着時刻より大きい
        if(total < stations[j][1]){
            total = stations[j][1]; // 発車時刻を待つ
        // 到着した駅の発車時刻が到着時刻より大きい
        }else if(total < stations[j][2]){
            total = stations[j][1]; // 発車時刻を待つ
        }else if(total % stations[j][2] != 0){
            // 到着時に発車間隔が合わなければ、 合わない分だけ待つ
            total += stations[j][2] - (total % stations[j][2])
        }
        total += stations[j][0]; // 乗車時間を追加
    }
    rtn.push(total);
  }
  rtn.push(0);
  console.log(rtn.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7868
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String b = sc.next();
		String c = sc.next();
		String ans = "";
		int i = 1;
		while(true) {
			ans += b.substring(i-1,i);
			ans += c.substring(i-1,i);
			if(a==i) {break;}
			i++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
var  a:array[0..60,0..60]of  longint;
     ch:char;
     i,j,k,l,h,t:longint;
begin
  readln(h,t);
  for  i:=1  to  h  do
    begin
      for  j:=1  to  t  do
        begin
          read(ch);
          if  ch='#'  then  a[i,j]:=-1
                      else  a[i,j]:=0;
        end;
      readln;
    end;
  for  i:=1  to  h  do
    for  j:=1  to  t  do
      begin
        if  a[i,j]<>-1  then  continue;
        for  k:=i-1  to  i+1  do
          for  l:=j-1  to  j+1  do
            if  a[k,l]<>-1  then
              inc(a[k,l]);
      end;
  for  i:=1  to  h  do
    begin
      for  j:=1  to  t  do
        if  a[i,j]=-1  then  write('#')
                       else  write(a[i,j]);
      writeln;
    end;
end.

Measured memory_bytes: 128
//Author:- Yatin Patel
//Mail:- yatinpatel.gt@gmail.com

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FILEIN ifstream fin;fin.open("input.txt");
#define FILEOUT ofstream fout;fout.open("output.txt");

using namespace std;
using namespace __gnu_pbds;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "  ";
    err(++it, args...);
}

#define FAST ios::sync_with_stdio(false);ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))

#define MOD 1000000007
#define INF LONG_MAX
#define MINF LONG_MIN

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll power(ll x, unsigned ll y){
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}

//#define fin cin
//#define fout cout

int main(){

    FAST;
    ll r,g,b,n;
    cin>>r>>g>>b>>n;
    ll ans = 0;
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=n;j++){
            ll k = (n - (i*r) - (j*g))/b;
            if(k<0)
            continue;
            if((i*r)+(j*g)+(k*b)==n){
                ans++;
            }
        }
    }
    cout<<ans;
    return 0;
}






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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int X;
    cin >> X;
    for (int t = 1;; ++t) {
        if (X * t % 360 == 0) {
            cout << t << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	string s; cin >> s;
	string t(s.size(), 'x');
	cout << t << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    string s,t;
    cin >> s >> t;
    bool ok = true;
    rep(i,s.size()){
        if(s[i]==t[i]);
        else ok = false;
    }
    if(!ok) cout << "No" << endl;
    else{
        if(t.size() == s.size()+1) cout << "Yes" << endl;
        else cout << "No"<< endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

bool isMonth(int num){
    if(1<=num and num<=12){
        return true;
    } else{
        return false;
    }
}

int main () {
    int input;
    cin>>input;
    int n1, n2;
    n1=input/100;
    n2=input%100;

    bool ismonth_1 = isMonth(n1);
    bool ismonth_2 = isMonth(n2);

    if(ismonth_1 == true and ismonth_2 == true){
        cout<<"AMBIGUOUS"<<endl;
    }else if (ismonth_1==true and ismonth_2 == false){
        cout<<"MMYY"<<endl;
    }else if (ismonth_1==false and ismonth_2 == true){
        cout<<"YYMM"<<endl;
    }else{
        cout<<"NA"<<endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for(auto& u:arr) cin >> u;
    sort(arr.begin(), arr.end());
    int pos = arr.end() - lower_bound(arr.begin(),arr.end(),k);
    printf("%d\n",pos);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string a,b;
    cin >> a >> b;
    string res = "No";
    rep(i,1000){
        if(i*i==stoi(a+b)){
            res = "Yes";
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >>n;
    vector<int> b(n-1);
    for(int i = 0; i < n-1; i++)
        cin >>b[i];
    vector<int> c(n, INT_MAX);
    c[0] = b[0];
    c[n-1] = b[n-2];
    for(int i = 1; i < n-1; i++)
        c[i] = min(b[i-1], b[i]);
    cout <<accumulate(c.begin(), c.end(), 0);
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	stones := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &stones[i])
	}
	fmt.Println(solve(N, stones))
}

func solve(N int, stones []int) int {
	dp := make([]int, N)
	dp[0] = 0
	if N == 1 {
		return dp[0]
	}
	dp[1] = abs(stones[1] - stones[0])
	for i := 2; i < N; i++ {
		// dp[i]: min_{j=1}^2(dp[i-j]+abs(arr[i]-arr[i-j]))
		dp[i] = min(dp[i-1]+abs(stones[i]-stones[i-1]), dp[i-2]+abs(stones[i]-stones[i-2]))
	}
	return dp[N-1]
}

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

Measured memory_bytes: 7464
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,ll>
#define x first
#define y second
#define mp make_pair
#define pb push_back
struct node
{
	int l,r;
	ll v;
}t[800010];
int n,m;
ll f[200010],vl[200010],lazy[800010],ans;
vector<pii> vr[200010];
void pushdown(int k)
{
	if (!lazy[k])
	{
		return;
	}
	t[k<<1].v+=lazy[k];
	t[k<<1|1].v+=lazy[k];
	lazy[k<<1]+=lazy[k];
	lazy[k<<1|1]+=lazy[k];
	lazy[k]=0;
}
void pushup(int k)
{
	t[k].v=max(t[k<<1].v,t[k<<1|1].v);
}
void build(int k,int l,int r)
{
	t[k].l=l;
	t[k].r=r;
	if (l==r)
	{
		return;
	}
	int mid=(l+r)>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
}
void update(int k,int x,int y,ll v)
{
	int l=t[k].l;
	int r=t[k].r;
	if (l==x && r==y)
	{
		t[k].v+=v;
		lazy[k]+=v;
		return;
	}
	pushdown(k);
	int mid=(l+r)>>1;
	if (x>mid)
	{
		update(k<<1|1,x,y,v);
	}
	else if (y<=mid)
	{
		update(k<<1,x,y,v);
	}
	else
	{
		update(k<<1,x,mid,v);
		update(k<<1|1,mid+1,y,v);
	}
	pushup(k);
}
ll query(int k,int x)
{
	int l=t[k].l;
	int r=t[k].r;
	if (x>=r)
	{
		return t[k].v;
	}
	pushdown(k);
	int mid=(l+r)>>1;
	if (x<=mid)
	{
		return query(k<<1,x);
	}
	else
	{
		return max(t[k<<1].v,query(k<<1|1,x));
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=0;i<m;i++)
	{
		int l,r;
		ll a;
		scanf("%d%d%lld",&l,&r,&a);
		vl[l]+=a;
		vr[r].pb(mp(l,a));
	}
	build(1,0,n);
	for (int i=1;i<=n;i++)
	{
		update(1,0,i-1,vl[i]);
		//cerr<<vl[i]<<endl;
		f[i]=query(1,i-1);
		//cerr<<"now: "<<t[8].v<<endl;
		ans=max(ans,f[i]);
		update(1,i,i,f[i]);
		for (int j=0;j<vr[i].size();j++)
		{
			update(1,0,vr[i][j].x-1,-vr[i][j].y);
			//cerr<<-vr[i][j].y<<endl;
		}
		//cerr<<i<<" "<<f[i]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}
/*
6 8
5 6 3
4 5 1
3 5 -1
2 6 3
1 4 5
1 5 -9
5 6 2
5 5 -3
*/
//ÎªÅÂ¶àÇé£¬²»×÷Á¯»¨¾ä¡£
//¡ª¡ªÄÉÀ¼ÈÝÈô¡¶µûÁµ»¨¡·

Measured memory_bytes: 29056
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll n, m, sum, ans = 1;
  cin >> n >> m;
  ll l = 1, r = 1000000001LL, mid;
  while(r-l>1){
    mid = (l + r) / 2;
    if(mid*n<=m){
      l = mid;
    }else{
      r = mid;
    }
  }
  while(l>0){
    sum = m - n * l;
    if(sum%l==0){
      ans = l;
      break;
    }else{
      l--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
    #define endl '\n'
    #define modulo 1000000007
    //#define int long long
    #pragma GCC optimize("-Ofast")
    #define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096
    #define sinDegrees(x) sin((x) * PI / 180.0)
    using namespace std;
    int power(int x, unsigned int y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return (power(x, y / 2) * power(x, y / 2))%modulo;
    else
        return (x * power(x, y / 2) * power(x, y / 2))%modulo;
}
    /*#include "testlib.h"
    int main(int argc, char* argv[])
    {
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    registerGen(argc, argv, 1);
    int n =rnd.next(2,10000),k;
    cout<<n<<'\n';
    int nn=n;
    k=1;
    while(n--){
    k=rnd.next(k,min(k*2,1000000000));
    cout <<k<<' ';
    }
    cout<<'\n';
    k=1;
    while(nn--){
    k=rnd.next(k,min(k*2,1000000000));
    cout <<k<<' ';
    }
    }*/
    bool comp(pair<pair<int,int>,int>a,pair<pair<int,int>,int>b){
    return a.second>b.second;
    }
    int32_t main()
    {
    //freopen("output.txt","w", stdout);
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int a=n/1.08;
    if((int)(a*1.08)==n)
    cout<<a;
    else{
    if((int)((a+1)*1.08)==n)
    cout<<a+1;
    else
    cout<<":(";
    }
    return 0;
    }


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include<algorithm> 
using namespace std;
// main() is where program execution begins.



int main() {
    long long int N,M,a,b,cost,sum;
    cin >> N >> M;
    vector< pair <long long int,long long int> > vect;

    for (int i = 0; i < N; ++i)
    {
    	cin>>a>>b;
    	vect.push_back( make_pair(a,b));
    }


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

    sum=0;
    cost=0;
    for (int i = 0; i < N; ++i)
    {
    	if (sum+vect[i].second <= M)
    	{
    		sum = sum + vect[i].second;
    		cost = cost + vect[i].first * vect[i].second; 
    	}
    	else{
    		cost = cost + vect[i].first * (M - sum);
    		break; 
    	}
    }

    cout << cost << endl;


   

   

   return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, m, t; cin >> n >> m >> t;
  vi a(n);
  REP(i, n) cin >> a[i];

  vector<bool> time(t, true);
  REP(i, n) {
    FOR(j, a[i]-m, min(t, a[i] + m)) {
      time[j] = false;
    }
  }

  int ans = 0;
  REP(i, t) {
    ans += time[i];
  }
  cout << ans << endl;
}



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

using namespace std;

void solve()
{
	string S;
	cin >> S;
	int l = S.size();
	for (int i = 0; i < l-1; i++)
	{
		if (S[i] == S[i+1])
		{
			cout << i+1 << ' ' << i+2 << endl;
			return;
		}
	}
	for (int i = 0; i < l-2; i++)
	{
		if (S[i] == S[i+2])
		{
			cout << i+1 << ' ' << i+3 << endl;
			return;
		}
	}
	cout << -1 << ' ' << -1 << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 512
n = int(input())
a_list = list(map(int, input().split()))

sign = 1
ret = 0

for i in range(len(a_list)):
    ret += sign * a_list[i]
    sign *= -1

r_list = []
r_list.append(str(ret))

tmp = ret

for i in range(len(a_list)-1):
    tmp = (a_list[i] - (int(tmp) // 2)) * 2
    r_list.append(str(tmp))

print(' '.join(r_list))


Measured memory_bytes: 73092
#include <cstdio>

using namespace std;

int main() {
    int a, b, c, d, e, k;
    scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &k);
    printf("%s\n", (e - a > k ? ":(" : "Yay!"));
    return 0;
}


Measured memory_bytes: 128
n = gets.to_i
x,y = n.times.map{gets.split.map(&:to_i)}.transpose

a = n.times.map{|i|(x[i]+y[i])%2}
if a.all?{|t|t==1} != a.any?{|t|t==1}
  p -1
  exit
end

def donyoku d,gx,gy,even
  sx,sy = 0,0
  w = ""
  
  d.size.times{|i|
    difx = gx-sx
    dify = gy-sy
    if difx==0 && dify==0
      w += ?U
      sy += d[i]
    elsif difx.abs > dify.abs
      sign = difx/difx.abs
      w += [??,?R,?L][sign]
      sx += d[i]*sign
    else
      sign = dify/dify.abs
      w += [??,?U,?D][sign]
      sy += d[i]*sign
    end
  }
  
  if !(sx==gx && sy==gy)
    puts "ゴールは#{gx},#{gy}、着いたのは#{sx},#{sy}"
    puts "だめじゃん"
  end
  
  puts w
end

even = (a[0]==0)

d = 38.times.map{|i| 2**i}.reverse
d += [1] if even
p d.size
puts d*" "

n.times{|i|
  #まるなげ
  donyoku(d,x[i],y[i],even)
}


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

int main() {
    string str;
    cin >> str;
    if(str == "AAA" || str == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  while(cin >> n, n != 0){
    int k, ans = 0;
    bool nasu = false;
    rep(i, n){
      cin >> k;
      if(k >= 1){
	ans ++;
      }
      if(k >= 2){
	nasu = true;
      }
    }
    if(!nasu){
      cout << "NA\n";
    } else {
      cout << ans + 1 << '\n';
    }
  }
  return 0;
}



Measured memory_bytes: 3220
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    int maxi = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    vector<int> dp(h + 1, INT_MAX);
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= h; j++){
            dp[j] = min(dp[j], b[i] + (a[i] < j ? dp[j - a[i]] : 0));
        }
    }
    cout << dp[h] << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
//2019/3/14
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();

		boolean flag = false;

		//最初の文字をチェック
		if(S.charAt(0) != 'A') {

			flag = true;

		}else {

			int C = 0;

			for(int i=2;i<=S.length()-2;i++) {

				if(S.charAt(i) == 'C') C++;

			}

			if(C!=1) flag = true;

			char a = 0;

			for(int i=0;i<S.length();i++) {

				a = S.charAt(i);

				if(!(a=='A' || a=='C' || ((int)a>=97) && (int)a<=122)) flag = true;
			}
		}

		if(flag) System.out.println("WA");

		else System.out.println("AC");
	}

}


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

int main()
{
  long long A, B, K;
  cin >> A >> B >> K;
  if (A + B <= K)
  {
    cout << 0 << " " << 0 << endl;
  }
  else if (A >= K)
  {
    cout << A - K << " " << B << endl;
  }
  else
  {
    cout << 0 << " " << B - K + A << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  if (N<1000 || N>9999){
    return 0;
  }
  if ((N/10)%111==0 || (N%1000)%111==0){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
// 15パズル ( 反復深化法 )
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>

#include<vector>
#include<map>
#include<queue>

using namespace std;

#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle
{
    int f[N2], space, MD;
};

Puzzle state;
// 深さの制限
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz)
{
    int sum = 0;

    for(int i = 0; i < N2; i++)
    {
        if( pz.f[i] == N2 )
        {
            continue;
        }

        sum += MDT[i][pz.f[i] - 1];
    }

    return sum;
}

bool isSolved()
{
    for(int i = 0; i < N2; i++)
    {
        if( state.f[i] != i + 1 )
        {
            return false;
        }
    }

    return true;
}

bool dfs(int depth, int prev)
{
    if( state.MD == 0 )
    {
        return true;
    }

    // 現在の深さにヒューリスティックを足して制限を超えたら枝を刈る
    if( depth + state.MD > limit )
    {
        return false;
    }

    int sx = state.space / N;
    int sy = state.space % N;
    Puzzle tmp;

    for(int r = 0; r < 4; r++)
    {
        int tx = sx + dx[r];
        int ty = sy + dy[r];

        if( tx < 0 || ty < 0 || tx >= N || ty >= N )
        {
            continue;
        }

        if( max(prev, r) - min(prev, r) == 2 )
        {
            continue;
        }

        tmp = state;

        // マンハッタン距離の差分を計算しつつ、ピースをスワップ
        state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
        state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
        swap(state.f[tx * N + ty], state.f[sx * N + sy]);
        state.space = tx * N + ty;

        if( dfs(depth + 1, r) )
        {
            path[depth] = r;
            return true;
        }

        state = tmp;
    }

    return false;
}

// 反復深化
string iterative_deepening(Puzzle in)
{
    // 初期状態のマンハッタン距離
    in.MD = getAllMD(in);

    for(limit = in.MD; limit <= LIMIT; limit++)
    {
        state = in;

        if( dfs(0, -100) )
        {
            string ans = "";

            for(int i = 0; i < limit; i++)
            {
                ans += dir[path[i]];
            }

            return ans;
        }
    }

    return "unsolvable";
}

int main()
{
    for(int i = 0; i < N2; i++)
    {
        for(int j = 0; j < N2; j++)
        {
            MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
        }
    }

    Puzzle in;

    for(int i = 0; i < N2; i++)
    {
        cin >> in.f[i];

        if( in.f[i] == 0 )
        {
            in.f[i] = N2;
            in.space = i;
        }
    }

    string ans = iterative_deepening(in);
    cout << ans.size() << endl;

    return 0;
}



Measured memory_bytes: 3232
#include <iostream>

int main(void){
    long x, y = 100;
    int i = 0;
    std::cin >> x;
    while(true){
        if(y >= x) break;
        y += y / 100;
        ++ i;
    }
    std::cout << i << std::endl;

    return 0;
}

Measured memory_bytes: 3564
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

from collections import deque

d = deque([[0]]) #(頂点、長さ)
from copy import copy
ans = 0
while len(d):
    vs = d.popleft()
    for w in edge[vs[-1]]:
        if w not in vs:
            vs_copy = copy(vs)
            vs_copy.append(w)
            if len(vs_copy)==N:
                ans += 1
            else:
                d.append(vs_copy)
print(ans)

Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n, a[100000], dp[100000];
    scanf("%d", &n);
    for(int i=0; i<n; ++i)
        scanf("%d", a+i);
    dp[n-1] = 0;
    dp[n-2] = abs(a[n-2] - a[n-1]);
    for(int i=n-3; i>=0; --i)
    {
        dp[i] = min( dp[i+1] + abs(a[i]-a[i+1]), dp[i+2]+abs(a[i]-a[i+2]) );
    }
    cout << dp[0];
    return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict
def query(result, p, b, c):
    result += (c-b) * p[b]
    p[c] += p[b]
    p[b] = 0
    return result, p
N = int(input())
A = [int(i) for i in input().split()]
p = defaultdict(int)
for i in range(N):
    p[A[i]]+= 1
result = sum(A)
Q = int(input())
for i in range(Q):
    b, c = [int(i) for i in input().split()]
    result, p = query(result, p, b, c)
    print(result)

Measured memory_bytes: 94596
#include<stdio.h>
int main(){
  int a, b, c, cont = 0, i;
  scanf("%d %d %d", &a, &b, &c);
  for(i = a;i <= b;i++){
    if(c % i == 0)cont++;
  }
  printf("%d\n", cont);
  scanf("%d", &a);
  return 0;
}


Measured memory_bytes: 2100
#include <bits//stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,k) for(int i=n;i<k;i++)
#define P make_pair
#define F first
#define S second
#define M LLONG_MAX
signed main(void){
    int n,m,ans,w,p,q;
    ans=0;
    string s,s1,s2;
    vector<int> v;
    v={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};
    cin>>n;
    cout<<v[n-1]<<endl;
    
}


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


int main(){
    
    int n;
    cin>>n;
    
    for(int i=3;i<=n;i++){
        if(i%3==0 || i%10==3)
            cout<<" "<<i;
        else{
            int x=i;
            while(1){
                
                if(x%10 == 3){
                    cout<<" "<<i;
                    break;
                    
                }
                if(x/10 ==0)break;
                x /=10;
            }
        }
    }
    
    cout <<endl;
    return 0;
}


Measured memory_bytes: 3088