akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int MSB1(long long x) { int d = 0; while ((1LL << d) <= x) d++; return d; }

int main() {
    int n; cin >> n;
    vector<int> a(n);
    map<int, int> cnt;
    for (auto &ai: a) cin >> ai, cnt[ai]++;
    sort(a.rbegin(), a.rend());
    int ans = 0;
    for (int val: a) if (cnt[val]) {
        int rem = (1 << MSB1(val)) - val;
        int need = 1 + (val == rem);
        if (cnt[rem] >= need) {
            ans++, cnt[val]--, cnt[rem]--;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

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

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

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

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K; cin >> N >> K;
    int wa = 0;
    VI A(N);
    REP(i,N) {
        cin >> A[i];
        wa += A[i];
    }
    VI yaku;
    dump(wa)

    for(int i = 1; i*i <= wa; i++){
        if(wa%i == 0){
            if(i*i == wa) yaku.eb(i);
            else{
                yaku.eb(i);
                yaku.eb(wa/i);
            }
        }
    }
    sort(yaku.begin(),yaku.end(),greater<int>());
    //reverse(yaku.begin(),yaku.end());
    //cout << printVector(yaku) << endl;


    for(int i : yaku){
        dump(i)
        if(i == 1){
            cout << 1 << endl;
            return 0;
        }
        LL cur = 0;
        LL mi = 0;
        priority_queue<PII, vector<PII>, greater<PII>> que;
        REP(j,N){
            que.push(PII(A[j]%i, (i-A[j]%i)*-1 ));
            mi += (i-A[j]%i)*(-1);
        }
        while(!que.empty()){
            auto p = que.top(); que.pop();
            cur += p.first;
            dump(p.first)
            mi -= p.second;
            if(abs(cur) == abs(mi)) break;
        }
        if(cur <= K){
            cout << i << endl;
            return 0;
        }

        //if(i % 2 == 1){
        //    REP(j,N){
        //        //if(A[j]%i <= i/2) cost += A[j]%i;
        //    }
        //    if(cost <= K){
        //        cout << i << endl;
        //        return 0;
        //    }
        //}
        //else{
        //    int cnt = 0;
        //    REP(j,N){
        //        if(A[j]%i == i/2) cnt++;
        //        else if(A[j]%i < i/2) cost += A[j]%i;
        //    }
        //    if(cnt%2 == 1) cost += i/2;
        //    if(cost <= K){
        //        cout << i << endl;
        //        return 0;
        //    }

        //}
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <cstdio>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define irep(i, a) for (int i = 1; i <= a; i++)
#define mp make_pair
#define pb push_back
#define P pair<int, int>
#define ll long long

int n,ans;
string s[111111];
string tmp;
int acnt,bcnt,abcnt;
int at[111111],bt[111111],abt[111111];
bool use[111111];
int main()
{
  cin>>n;
  rep(i,n)cin>>s[i];
  rep(i,n){
    if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')abt[abcnt++]=i;
    else if(s[i][s[i].size()-1]=='A')at[acnt++]=i;
    else if(s[i][0]=='B')bt[bcnt++]=i;
  }

  int i=0,j=0,k=0;

  if(acnt>0&&abcnt>0){
    tmp+=s[at[0]],i++,use[at[0]]=1;

    rep(ii,abcnt){
      tmp+=s[abt[ii]];
      use[abt[ii]]=1;
    }

    while(true){

      if(j<bcnt){
        use[bt[j]]=1;
        tmp+=s[bt[j++]];
      }

      if(i<acnt){
        use[at[i]]=1;
        tmp+=s[at[i++]];
      }


      if(i>=acnt&&j>=bcnt)break;
    }
  }

  else if(abcnt==0){
    while(true){

    if(i<acnt){
      use[at[i]]=1;
      tmp+=s[at[i++]];
    }
    if(j<bcnt){
      use[bt[j]]=1;
      tmp+=s[bt[j++]];
    }

      if(i>=acnt&&j>=bcnt)break;
    }
  }


  else{

      rep(ii,abcnt){
        tmp+=s[abt[ii]];
        use[abt[ii]]=1;
      }

      while(true){

        if(j<bcnt){
          use[bt[j]]=1;
          tmp+=s[bt[j++]];
        }

        if(i<acnt){
          use[at[i]]=1;
          tmp+=s[at[i++]];
        }


        if(i>=acnt&&j>=bcnt)break;
      }

  }

  rep(i,n)if(!use[i])tmp+=s[i];
  //cout<<tmp<<endl;

  rep(i,tmp.size()-1)if(tmp[i]=='A'&&tmp[i+1]=='B')ans++;
  cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
n = gets.to_i
p = gets.split.map(&:to_i)
ans = 0
(0..n-3).each do |i|
  cnt = 0
  p[i,3].each do |pi|
    cnt += 1 if p[i+1] > pi
  end
  ans += 1 if cnt == 1
end
puts ans


Measured memory_bytes: 14368
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

int main()
{
    int N;
    while(1){
        cin >> N;
        if(N == 0) break;
        vector<pair<double, string> > name_efficiency(50);
        string l[50];
        int p[50], a[50], b[50], c[50], d[50], e[50], f[50], s[50], m[50];
        int income[50] = {0}, how_long[50] = {0};
        for(int i = 0; i < N; i++){
            cin >> name_efficiency[i].second >> p[i] >> a[i] >> b[i] >> c[i] >> d[i] >> e[i] >> f[i] >> s[i] >> m[i];
            income[i] -= p[i];
            how_long[i] += a[i] + b[i] + c[i] + d[i] + e[i];
            income[i] += f[i] * s[i];
            m[i]--;
            while(m[i] > 0){
                how_long[i] += d[i] + e[i];
                income[i] += f[i] * s[i];
                m[i]--;
            }
            double efficiency = (double) income[i] / how_long[i];
            name_efficiency[i].first = - efficiency;
        }
        sort(name_efficiency.begin(), name_efficiency.begin() + N);
        for(int i = 0; i < N; i++){
            cout << name_efficiency[i].second << endl;
        }
        cout << "#" << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include<iostream>
using namespace std;
int main(){
 int a,b,c;
 cin>>a>>b>>c;
 string ans="NO";
 for(int i=0;i<10000000;i++){
  int wa=i*a;
  if(wa%b==c){
   ans="YES";
   break;
  }
 }
 cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*

fun calcStandardDeviation(list: List<Int>): Double {
    val m = list.average()
    return Math.sqrt(list.map { Math.pow(it - m, 2.0) }.sum() / list.size)
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val answer = mutableListOf<Double>()
    while (true) {
        val n = scanner.nextInt()
        if (n == 0) {
            break
        }
        val list = mutableListOf<Int>()
        (1..n).forEach {
            list.add(scanner.nextInt())
        }
        answer.add(calcStandardDeviation(list))
    }
    answer.forEach {
        println(it)
    }
}


Measured memory_bytes: 31644
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int N,a,b;

int main(){
    cin>>N;
    a=0;
    while(a*4<=N){
        b=0;
        while(a*4+b*7<=N){
            if(a*4+b*7==N){
                out("Yes");
                return 0;
            }
            b++;
        }
        a++;
    }
    out("No");
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	int N;cin >> N;
	vector<int> L(N);
	int edge = 0;
	for (int i = 0;i < N;++i) {
		cin >> L[i];
		edge += L[i];
	}
	sort(L.begin(), L.end());
	cout << (edge - L[L.size() - 1] > L[L.size() - 1] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;cin>>s;
    int key=0;
    bool key_c=false;
    if(s[0]=='A'){
        key++;
        for(int i=2;i<s.length()-1;i++){
            if(s[i]=='C'&&key_c==false){
                key++;
                key_c=true;
            }
        }
        if(key_c==true){
            for(int i=0;i<s.length();i++){
                if(s[i]>='a'){
                    key++;
                }
            }
        }
    }
    if(key==s.length()){cout<<"AC"<<endl;}
    else{cout<<"WA"<<endl;}
}

Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use proconio::{fastout, input};
use std::cmp::*;
use std::collections::*;
use std::mem::*;
#[fastout]
fn main() {
    input! {
        a:i64,b:i64,
    }
    println!("{}", a * b);
}
static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;


Measured memory_bytes: 2136
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ar = br.readLine().split(" ");
        int n = Integer.parseInt(ar[0]);
        int m = Integer.parseInt(ar[1]);
        int l = Integer.parseInt(ar[2]);
        int[][] a = new int[n][m];
        int[][] b = new int[m][l];
        for(int i = 0; i < a.length; i++){
            ar = br.readLine().split(" ");
            for(int j = 0; j <a[i].length; j++){
                a[i][j] = Integer.parseInt(ar[j]);
            }
        }
        for(int i = 0; i < b.length; i++){
            ar = br.readLine().split(" ");
            for(int j = 0; j <b[i].length; j++){
                b[i][j] = Integer.parseInt(ar[j]);
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < l; j++){
                long ans = 0;
                for(int k = 0; k < m; k++){
                    ans += a[i][k] * b[k][j];
                }
                if(j == l-1){
                    System.out.println(ans);
                }else{
                    System.out.print(ans+" ");
                }
            }
        }
    }
}

Measured memory_bytes: 35492
use std::cmp;

macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn permutations(vec: &[usize]) -> Vec<Vec<usize>> {
    if let Some((n, rest)) = vec.split_first() {
        let prev = permutations(rest);
        prev.iter()
            .flat_map(|p| {
                let mut next = vec![];
                for i in 0..(p.len() + 1) {
                    let mut q = p.clone();
                    q.insert(i, *n);
                    next.push(q)
                }
                next
            })
            .collect()
    } else {
        vec![vec![]]
    }
}

fn main() {
    let (n, m, _) = scan!(usize, usize, usize);
    let rs = scan!(usize;;);
    let mut graph = (0..n)
        .map(|_| vec![1usize << 30; n])
        .collect::<Vec<Vec<_>>>();
    for _ in 0..m {
        let (a, b, c) = scan!(usize, usize, usize);
        graph[a - 1][b - 1] = c;
        graph[b - 1][a - 1] = c;
    }
    for i in 0..n {
        graph[i][i] = 0
    }

    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                let dist = graph[i][k] + graph[k][j];
                if graph[i][j] > dist {
                    graph[i][j] = dist;
                }
            }
        }
    }

    let perm = permutations(&rs);
    let mut ans = 1 << 30;
    for p in perm.iter() {
        let mut dist = 0;
        for (&from, &to) in p.iter().zip(p[1..].iter()) {
            dist += graph[from - 1][to - 1]
        }
        ans = cmp::min(ans, dist)
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll e = a * c;
    ll f = b * d;
    ll g = b * c;
    ll h = a * d;
    cout << max(max(max(e,f),g),h) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000
#define nil -1
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main() {
    long long int n,w=0,e=0,cnt=inf;
    cin>>n;
    string s;
    cin>>s;
    int b=s.size();
    for(int i=0;i<b;i++){
        if(s[i]=='W'){
            w++;
        }else{
            e++;
        }

    }
    int w1=0;
    int e1=0;
    for(int i=0;i<b;i++){
        if(s[i]=='W'){
            cnt=min(cnt,e1+e-e1);
            w1++;
        }else{
            e1++;
            cnt=min(cnt,w1+e-e1);
        }
    }
    cout<<cnt<<endl;
}


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

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

int main(){
	ll n;
	ll a[100100];
	cin >> n;
	rep(i,n) cin >> a[i];

	ll ans=0;

	ll sum = 0;
	for(int i=0;i<n;i++){
		sum += a[i];
		if(sum>=0){
			ans += abs(sum)+1;
			sum = -1;
		}
		i++;
		if(i>=n) break;
		sum += a[i];
		if(sum<=0){
			ans += abs(sum)+1;
			sum = 1;
		}
	}
	ll tans = 0;
	sum = 0;
	for(int i=0;i<n;i++){
		sum += a[i];
		// cout << "debug : " << sum<< endl;
		if(sum<=0){
			tans += abs(sum)+1;
			sum = 1;
		}
		i++;
		if(i>=n) break;
		sum += a[i];
		if(sum>=0){
			tans += abs(sum)+1;
			sum = -1;
		}
		
	}
	// cout << ans << " " << tans << endl;
	ans = min(ans,tans);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <algorithm>

using namespace std;

int N, M;
vector<int> P;
vector<vector<int>> S;

int dfs(vector<int>& array, int index) {
  if (index == N) {
#if 0
    for (int i=0;i<array.size();i++) {
      cout << array[i];
    }
    cout << endl;
#endif
    bool ok = true;
    for (int i=0;i<M;i++) {
      int count = 0;
      for (int j=0;j<S[i].size();j++) {
        if(array[S[i][j]-1]) count++;
      }
      if (count % 2 != P[i]) {
        ok = false;
        break;
      }
    }
    return ok ? 1 : 0;
  }
  int sum = 0;
  array[index] = 0;
  sum += dfs(array, index+1);
  array[index] = 1;
  sum += dfs(array, index+1);
  return sum;
}

int main()
{
  cin >> N >> M;
  for (int i=0;i<M;i++) {
    int k;
    cin >>  k;
    vector<int> _s;
    for (int j=0;j<k;j++){
      int s;
      cin >> s;
      _s.push_back(s);
    }
    S.push_back(_s);
  }
  for (int i=0;i<M;i++){
    int p;
    cin >> p;
    P.push_back(p);
  }
  vector<int> arr(N, 0);
  int ans = dfs(arr, 0);
  cout << ans << endl;
  return 0;
}


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

#define fi first
#define se second

const int N = 200200;
const int mod = 1e9 + 7;

using namespace std;

int n, k;
int a[N];
int t1[N][20];
int t2[N][20];
long long s1[N][20];
long long s2[N][20];

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n >> k;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        for(int i = 1, j = 0, h = 1; i <= n; i++){
                while(a[i] - a[j + 1] >= k){
                        j += 1;
                }
                while(h <= n && a[h] - a[i] < k){
                        h += 1;
                }
                t1[i][0] = s1[i][0] = j;
                t2[i][0] = s2[i][0] = h;
        }
        t2[n + 1][0] = n + 1;
        for(int i = 1; i < 20; i++){
                for(int j = 0; j <= n + 1; j++){
                        t1[j][i] = t1[t1[j][i - 1]][i - 1];
                        t2[j][i] = t2[t2[j][i - 1]][i - 1];
                        s1[j][i] = s1[j][i - 1] + s1[t1[j][i - 1]][i - 1];
                        s2[j][i] = s2[j][i - 1] + s2[t2[j][i - 1]][i - 1];
                }
        }
        int q;
        cin >> q;
        while(q--){
                int l, r;
                cin >> l >> r;
                int x = l, y = r;
                long long res = r - l + 1;
                for(int i = 19; i >= 0; i--){
                        if(t2[x][i] <= r){
                                assert(t1[y][i] >= l);
                                res -= s2[x][i];
                                res += s1[y][i];
                                res += (1 << i);
                                x = t2[x][i];
                                y = t1[y][i];
                        }
                }
                cout << res << "\n";
        }
}


Measured memory_bytes: 98212
#include<stdio.h>
int main()
{
    int A,N,T,B;
    scanf("%d %d",&N,&A);
    T=N*N;
    B=T-A;
    if(A>0)
    {
        printf("%d",B);
    }
    else
    {
        printf("%d",T);
    }
    return 0;
}


Measured memory_bytes: 128
N, W = map(int, input().split())
weight = []
value = []
for _ in range(N):
    w_tmp, v_tmp = map(int, input().split())
    weight.append(w_tmp)
    value.append(v_tmp)

INF = float('inf')

dp = [[INF for i in range(sum(value)+1)] for j in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(sum(value)+1):
        if j - value[i] >= 0:
            dp[i+1][j] = min(dp[i][j - value[i]] + weight[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

for j in range(sum(value)+1):
    if dp[N][j] <= W:
        res = j

print(res)

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

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

	int hour;
	int minute;
	int secound;

	hour = time / 3600;
	minute = time % 3600/60;
	secound = time - (3600 * hour + minute * 60);

	cout << hour << ":" << minute << ":" << secound << endl;
	
}


Measured memory_bytes: 3136
l, r = map(int, input().split())
c1 = l % 2019
c2 = r % 2019

if r-l != c2-c1 or r - l >= 2018:
    print(0)
    exit(0)
else:
    m = 2019
    for i in range(l, r):
        for j in range(i+1, r+1):
            if (i*j)%2019 < m:
                m = (i*j)%2019
    print(m)



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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int A, B;
	cin >>A >>B;
	cout <<6-A-B <<endl;
	return 0;
}



Measured memory_bytes: 256
N = int(input())
C=dict()
for i in range(N):
 A,B = [int(j) for j in input().split()]
 if not B in C:
   C[B] = []
 C[B] += [A]
C = sorted(C.items(), key=lambda C:C[0])
s=0
for k,v in C:
    s+=sum(v)
    if k<s:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 65984
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,t,x,y,bt=0,bx=0,by=0;
	cin>>n;
	while(cin>>t>>x>>y)
		if(t-bt<abs(x-bx)+abs(y-by)||(t-bt)%2!=(abs(x-bx)+abs(y-by))%2)
			cout<<"No"<<endl,exit(0);
	cout<<"Yes"<<endl;
}


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

using namespace std;

using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll k = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    k += a[i];
  }
  if (k % (((n + 1) * n) / 2)) {
    cout << "NO" << endl;
    return 0;
  }
  k /= (((n + 1) * n) / 2);
  vector<ll> sa(n);
  for (int i = 0; i < n; ++i) {
    sa[i] = a[(i + 1) % n] - a[i];
  }
  for (auto &&x : sa) {
    x -= k;
    if (x > 0) {
      cout << "NO" << endl;
      return 0;
    }
    if ((-x) % n != 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 1792
#include <iostream>

typedef long long ll;

const int MAX_N = 1e7;
ll x[MAX_N+1];

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

   std::fill(x, x+MAX_N+1, 2);
   x[1] = 1;
   for(int i=2; i<=N; ++i){
      for(int j=2*i; j<=N; j+=i) ++x[j];
   }

   ll ans = 0;
   for(ll K=1; K<=N; ++K){
      ans += K * x[K];
   }
   std::cout << ans << std::endl;

   return 0;
}


Measured memory_bytes: 81768
import sys
s = sys.stdin.readline().rstrip()
i = 0
l = len(s)
flag = True
while flag and i <= l:
  if s[i] != s[l-1]:
    flag = False
  i += 1
  l -= 1
l = len(s)
a = s[0:-(-(l-1)//2)]
i = 0
l = len(a)
while flag and i <= l:
  if a[i] != a[l-1]:
    flag = False
  i += 1
  l -= 1
b = s[(len(s) + 3)//2 - 1:]
i = 0
l = len(b)
while flag and i <= l:
  if b[i] != b[l-1]:
    flag = False
  i += 1
  l -= 1
if flag:
  print('Yes')
else:
  print('No')


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<double> p(n);
    rep(i,n) {
        double x;
        cin >> x;
        p[i] = (1+x)/2;
    }
    double sumk = 0;
    for (int i = 0; i <= k-1; i++) {
        sumk += p[i];
    }
    double ans = sumk;
    for (int i = 1; i <= n-k; i++) {
        sumk = sumk-p[i-1]+p[i+k-1];
        ans = max(ans, sumk);
    }
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 4756
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <ios>
#include <algorithm>
using namespace std;
int main(void){
  int N;
  cin >> N;

  vector<string>s(N);

  for(int i=0;i<N;i++){
    cin >> s[i];
  }

  int a = 0;
  int b = 0;
  int c = 0;
  int ans = 0;

  for(int i=0;i<N;i++){
    int n = s[i].length();
    for(int j = 0;j<n-1;j++){
      if(s[i][j] == 'A' && s[i][j + 1] == 'B')
      ans++;
    }
    if(s[i][n-1] == 'A' && s[i][0] == 'B')
    c++;
    else if(s[i][n-1] == 'A')
    a++;
    else if(s[i][0] == 'B')
    b++;
  }


  if(a != 0 || b != 0)
  cout << min(a,b) + c + ans << endl;
  else{
    if(c == 0 || c == 1)
    cout << ans << endl;
    else
    cout << c - 1 + ans << endl;
  }

  return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb(a) push_back(a)
#define pi pair<int,int>
#define f first
#define s second
#define endl "\n"
void solve()
{ 
  int x,n;
  cin>>x>>n;
  if(n==0)
  {
      cout<<x<<endl;
      return ;
  }
  int arr[105]={0};
  for(int i=0;i<n;i++)
  {
      int a;
      cin>>a;
      arr[a]++;
  }
  int id=-1,di=-1;
  for(int i=x;i<102;i++)
  {
      if(arr[i]==0)
      {
          id=i;
          break;
      }
  }
  //cout<<x<<" "<<x-1<<endl;
  for(int i=x-1;i>=0;i--)
  {
      if(arr[i]==0)
      {
          di=i;
          break;
      }
  }
 // cout<<id<<" "<<di<<endl;
  if(abs(id-x)>=abs(di-x))
  cout<<di<<endl;
  else
  cout<<id<<endl;
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
       solve();
    return 0;
} 

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

int main(){ 
  int x;
  cin >> x;
  int res = x / 500 * 1000;
  x %= 500;
  res += x / 5 * 5;
  cout << res << endl;
  return 0;  
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
string s;
stack<char> st;
int main(){
    ios::sync_with_stdio(0);
    cin>>s;
    for(int i=0; i<s.size(); i++){
        while(!st.empty() && s[i]==st.top()) st.pop();
        st.push(s[i]);
    }
    cout<<st.size()-1<<endl;
    return 0;
}

Measured memory_bytes: 3784
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
res = 0
for i in range(N):
    res += B[A[i]-1]
    if A[i] - A[i-1] == 1 and i>=1:
        res += C[A[i]-2]
print(res)

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

int main() {

	int A,B,C,D;
	int left,right;
	
	cin >> A >> B >> C >> D;
	
	left = A+B;
	right = C+D;
	
	if ( left > right ){
		cout << "Left" << endl;
	}
	else if ( right > left) {
		cout << "Right" << endl;
	}
	else {
		cout << "Balanced" << endl;
	}
}

Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string S;
	std::cin >> S;
	if (S.find(std::string("AC")) != S.npos)
		std::cout << "Yes\n";
	else
		std::cout << "No\n";
}


Measured memory_bytes: 256
import bisect

s,t=input(),input()
ls=len(s)
lt=len(t)
A=[[] for i in range(26+1)]
L=[0 for i in range(26+1)]

for i in range(ls):
  A[ord(s[i])-96].append(i+1)
  L[ord(s[i])-96]+=1
#print(A)

tmp=0
ans=0
for i in range(lt):
  ii=ord(t[i])-96

  if L[ii]==0:
    print(-1)
    exit()
  else:
    iii=bisect.bisect(A[ii],tmp)
    #print(t[i],A[ii],tmp,iii,ans)
    if iii==L[ii]:
      ans+=ls-tmp+A[ii][0]
      tmp=A[ii][0]
    else:
      ans+=A[ii][iii]-tmp
      tmp=A[ii][iii]
print(ans)  

Measured memory_bytes: 7696
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            (long N, long M) = Slice2<long>();
            var Ai = new string[N];
            for (var i = 0; i < N; ++i)
                Ai[i] = ReadLine();
            var Bi = new string[M];
            for (var i = 0; i < M; ++i)
                Bi[i] = ReadLine();
            for (var hs = 0; hs <= N - M; ++hs)
            {
                for (var ws = 0; ws <= N - M; ++ws)
                {
                    var flg = true;
                    for (var m = 0; m < M; ++m)
                    {
                        if (Ai[hs + m].Substring(ws, (int)M) != Bi[m])
                            flg = false;
                    }
                    if (flg)
                    {
                        WriteLine("Yes");
                        return;
                    }
                }
            }
            WriteLine("No");
        }
        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28712
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<climits>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

int main(){
    int a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
}


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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef double ld;
typedef pair<ll, ll> pll;

vector<vector<int> > g;
vector<int> color;
vector<int> best;

void dfs(int v, int dist, int curr, int c)
{
	best[v] = dist - curr;
	//cout << "!" << color[v] << " " << c << "\n";
	if (color[v] == 0) {
		color[v] = c;
	}
	if (dist == curr) {
		return;
	}
	for (int to : g[v]) {
		if (best[to] < dist - (curr + 1)) {
			dfs(to, dist, curr + 1, c);
		}
	}
}

int main()
{

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;

	g.resize(n);

	while (m--) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		g[u].pb(v);
		g[v].pb(u);
	}

	color.assign(n, 0);
	best.assign(n, -1);

	int q;
	cin >> q;
	vector<int> v(q), d(q), c(q);
	for (int i = 0; i < q; ++i) {
		cin >> v[i] >> d[i] >> c[i];
		--v[i];
	}

	for (int i = q - 1; i >= 0; --i) {
		int x = v[i];
		if (best[x] < d[i]) {
			dfs(x, d[i], 0, c[i]);
		}
	}

	for (int i = 0; i < n; ++i) {
		cout << color[i] << "\n";
	}

}


Measured memory_bytes: 8440
#include<iostream>
#include<algorithm>
#include<queue>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;

ll const MAX = 100005;
ll a[MAX];
ll b[MAX];

int main(){
	ll n, m;
	cin >> n >> m;
	b[0] = 0;
	REP(i, 1, n) {
		cin >> a[i];
		b[i] = (b[i - 1] + a[i]) % m;
	}
	ll cur = 0, next = 0;
	sort(b, b + n + 1);
	b[n + 1] = m + 1;
	ll ans = 0;
	while (1) {
		if (b[cur] == b[next]) {
			next++;
		}
		else {
			ans += (next - cur)*(next - cur - 1) / 2;
			cur = next;
			if (next == n + 1) { break; }
		}
	}
	cout << ans << endl;

}

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

int main()
{
	int n; cin >> n;
	string s, t; cin >> s >> t;
	
	string ans;

	for (int i = 0; i < n; i++) {
		ans += s.at(i);
		ans += t.at(i);
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
    string s;
    int q;
    cin >> s >> q;
    vector<T> qr(q);
    bool fore = true;
    rep(i, q) {
        int a, b;
        string c;
        cin >> a;
        if (a==2) {
            cin >> b >> c;
            if (b==1) {
                if (fore) {
                    s.insert(0, c);
                } else {
                    s += c;
                }
            } else {
                if (fore) {
                    s += c;
                } else {
                    s.insert(0, c);
                }
            }
        } else {
            fore = !fore;
        }
    }
    if (!fore) reverse(all(s));
    cout << s << endl;
    return 0;
}

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

int main(){
  int x; cin >>x;
  if(x==2){
    cout << 2 << endl;
    return 0;
  }
  
  bool prime;
  for(int i = x; ;i++){
    prime = true;
    for(int j=2; j*j<=i; j++){
      if(i%j==0){
        prime = false;
        break;
      }
    }
    if(prime){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

using namespace std;

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

    map<int, int> odd, even;
    for(int i = 0; i < n; i++){
        int num;
        cin >> num;
        if(i%2){
            odd[num]++;
        }else{
            even[num]++;
        }
    }

    int o_max = 0, e_max = 0, os = 0, es = 0;
    int ok, ek;
    for(auto& e : odd){
        if(e.second > o_max){
            o_max = e.second;
            ok = e.first;
        }
    }
    for(auto& e : even){
        if(e.second > e_max){
            
            e_max = e.second;
            ek = e.first;
        }
    }

    for(auto& e : odd){
        if(e.first == ok) continue;
        if(e.second > os){
            os = e.second;
        }
    }
    for(auto& e : even){
        if(e.first == ek) continue;
        if(e.second > es){
            es = e.second;
        }
    }

    if(ok != ek){
        cout << n/2-o_max + n/2-e_max << endl;
    }else{
        
        int len1 = n/2-o_max + n/2-es;
        int len2 = n/2-os + n/2-e_max;
        cout << ((len1 < len2)? len1 : len2) << endl;
    }
}

Measured memory_bytes: 8212
#include <bits/stdc++.h>
int M=1e9+7;
using namespace std;
int main() 
{
    long long n,m,ans=1; 
	cin>>n>>m; 
    if (abs(m-n)>1) 
	{
   	    cout << "0"<<endl;
	    return 0;
	}
    for (int i=1;i<=n;i++) 
	     ans=ans*i%M;
    for (int i=1;i<=m;i++) 
	    ans=ans*i%M;
    cout <<(n!=m?ans:ans*2%M)<< endl;
    return 0;
}

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

using namespace std;

#define _int64 long long

int a[210000];
int b[210000];

int main()
{
  int i,n,tmp;
  _int64 ans;
  scanf("%d",&n);
  tmp=2000000000;
  for (i=0;i<n;i++)
  {
    scanf("%d%d",&a[i],&b[i]);
    if (a[i]>b[i])
    {
      if (b[i]<tmp) tmp=b[i];
    }
  }
  if (tmp==2000000000)
  {
    printf("0\n");
    return 0;
  }
  ans=0;
  for (i=0;i<n;i++)
    ans+=a[i];
  ans-=tmp;
  printf("%lld\n",ans);
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
  var n, k int
  fmt.Scan(&n, &k)
  var s string
  fmt.Scan(&s)

  var list []int
  now, count := 1, 0
  for _, v := range s {
    if v == rune('0'+now) {
      count++
    } else {
      list = append(list, count)
      now = 1 - now
      count = 1
    }
  }
  if count != 0 {
    list = append(list, count)
  }
  if len(list)%2 == 0 {
    list = append(list, 0)
  }

  listRange := 2*k + 1
  sum := make([]int, len(list)+1)
  for i := 0; i < len(list); i++ {
    sum[i+1] = sum[i] + list[i]
  }

  var left, right, tmp, ans int
  for i := 0; i < len(list); i += 2 {
    left = i
    right = getMin(i+listRange, len(list))
    tmp = sum[right] - sum[left]
    ans = getMax(tmp, ans)
  }
  fmt.Println(ans)
}

func getMin(a int, b int) int {
  if a > b {
    return b
  }
  return a
}

func getMax(a int, b int) int {
  if getMin(a, b) == a {
    return b
  }
  return a
}


Measured memory_bytes: 5120
# -*- coding:utf-8 -*-

num = int(input())
min = 0
sa = -10000000000
for i in range(num):
    atai = int(input())
    if i == 0:
        min = atai
        continue
    sa_temp = atai - min
    if sa < sa_temp:
        sa = sa_temp
    if min > atai:
        min = atai
print(sa)

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

s = []
for i in range(n):
    s.append(input())

s.sort()

count_ = 0
max_ = 0
tmp = 'DUMMY'
ans = []
for i in range(n):
    if(tmp == s[i]):
        count_ += 1
    else:
        if(max_ < count_):
            max_ = count_
            ans = [tmp]
        elif(max_ == count_):
            ans.append(tmp)
        count_ = 1
        tmp = s[i]

if(max_ < count_):
    max_ = count_
    ans = [tmp]
elif(max_ == count_):
    ans.append(tmp)

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 82648
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
struct line
{
  ll slope,intercept;
  ll valueat(ll x0)
  {
    return intercept+slope*x0;
  }
  ll xintersect(line& l2)
  {
    return (ll)(ceil)((double)(l2.intercept-intercept)/(slope-l2.slope));
  }
};
struct dsa
{
  deque<pair<line,ll>> dq;//line and when line starts being useful
  void insert(line l)
  {
    if(dq.empty())
    dq.push_back({l,0});
    else
    {
      ll x;
      while(!dq.empty())
      {
        x=l.xintersect(dq.back().first);
        if(x<=dq.back().second)
        dq.pop_back();
        else
        break;
      }
      dq.push_back({l,x});
    }
  }
  ll query(ll x)
  {
    while(dq.size()>1)
    {
      if(dq[1].second<=x)
      dq.pop_front();
      else
      break;
    }
    return dq.front().first.valueat(x);
  }
};
int main()
{
  long long n,c;
  cin>>n>>c;
  vector<long long> v(n);
  for(int i=0;i<n;i++)
    cin>>v[i];
  vector<long long> dp(n);
  dsa ds;
  line l0{-2*v[0],v[0]*v[0]};
  ds.insert(l0);
  for(int i=1;i<n;i++)
  {
    dp[i]=v[i]*v[i]+c+ds.query(v[i]);
    line l{-2*v[i],dp[i]+v[i]*v[i]};
    ds.insert(l);
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 9476
#include <iostream>
#include <algorithm>
#include <cstring>
#define rep(i, a, n) for(int i = a;i < n;i++)
#define repr(i, a, n) for(int i = a;i > n;i--)
using namespace std;


int n, x;
int m[40];
int dp[1000010];
int p[1000000];


void sieve(){
	memset(p, 1, sizeof p);
	p[0] = p[1] = 0;
	for(int i = 2;i*i <= 1000000;i++){
		if(p[i]){
			for(int j = 2;i*j <= 1000000;j++)
				p[i*j] = 0;
		}
	}
}


void makeDP(){
	memset(dp, 0, sizeof dp);
	rep(i, 1, n+1){
		rep(j, 0, x+1){
			if(j >= m[i]) dp[j] = max(dp[j], dp[j-m[i]] + m[i]);
		}
	}
}


int main(){
	sieve();

	while(cin >> n >> x, n || x){
		rep(i, 1, n+1) cin >> m[i];

		makeDP();
		
		int ans = -1;
		repr(i, x, -1){
			if(p[dp[i]]){
				ans = dp[i];
				break;
			}
		}

		if(ans != -1) cout << ans << endl;
		else cout << "NA" << endl;
	}

	return 0;
}


Measured memory_bytes: 10892
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <string>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.length(), m = t.length();
  vector<vector<int>> dp(n, vector<int>(m, 0));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i] == t[j]) {
        dp[i][j] = (i > 0 && j > 0 ? dp[i-1][j-1]: 0) + 1;
      } else {
        dp[i][j] = max((i > 0 ? dp[i-1][j]: 0), (j > 0 ? dp[i][j-1]: 0));
      }
    }
  }
  string ans = "";
  int i = n-1, j = m-1;
  while (i >= 0 && j >= 0 && dp[i][j] > 0) { 
    if (s[i] == t[j]) {
      ans += s[i];
      --i; --j;
    } else {
      if (i > 0 && dp[i-1][j] == dp[i][j]) {
        --i;
      } else {
        --j;
      }
    }
  }
  reverse(ans.begin(), ans.end());
  cout <<  ans << '\n';

  return 0;
}


Measured memory_bytes: 38568
#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

int main() {
  int n;
  std::cin >> n;
  std::string s;
  std::set<std::string> set;
  for (int ni = 0; ni < n; ++ni) {
    std::cin >> s;
    set.insert(s);
  }
  std::cout << (set.size() == 3 ? "Three" : "Four") << std::endl;
  return 0;
}


Measured memory_bytes: 888
n = int(input())
a = list(map(int, input().split()))

idx_of_min = 0
idx_of_max = 0
for i, a_i in enumerate(a):
    if a_i < a[idx_of_min]:
        idx_of_min = i
    if a_i > a[idx_of_max]:
        idx_of_max = i

print(a[idx_of_max] - a[idx_of_min])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int m =1e5+50;
bool prime[m];
void find_prime()
{
    prime[1]=true;
    for(int i=2;2*i<=1e5+50;i++)
    {
        prime[2*i]=true;
    }
    for(int i=3;i<=sqrt(1e5+50);i+=2)
    {
        for(int j=3;j*i<=1e5+50;j+=2)
        {
            prime[j*i]=true;
        }
    }
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    memset(prime,false,sizeof(prime));
    find_prime();
    for(int i=n;;i++)
    {
        if(!prime[i])
        {
            cout<<i<<'\n';
            return 0;
        }
    }
}

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

using namespace std;
typedef long long ll;

ll con(ll a, ll b, ll c){
    ll res = a;
    res -= a / b;
    res -= a / c;
    res += a / (b * c / __gcd(b, c));
    return res;
}

int main(){
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    ll res = con (b, c, d) - con(a-1, c, d);
    cout << res;
    return 0;
}


Measured memory_bytes: 256
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        int x, y, z;
        cin >> x >> y >> z;
        if (x <= y * z)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    
    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
//C++ as C#
#define var auto
#define Max std::max
#define Min std::min
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

#ifdef _MSC_VER
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#define fseek_unlocked fseek
#endif

inline int read()
{
	int x = 0;
	int k;
	while (true)
	{
		k = getchar_unlocked();
		if (k < '0') break;
		x = x * 10 + k - '0';
	}
	return x;
}

void writeline(int x) {
	int s = 0;
	char f[8];
	while (x) {
		f[s++] = x % 10;
		x /= 10;
	}
	while (s--)
		putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}

int main()
{
	int h = read(), w = read();
	int columnAccum[2000] = {};
	int rowMax[2000] = {};
	int max = 0;
	for (int i = 0; i < h; i++)
	{
		int currentChain = 0;
		for (int j = 0; j < w; j++)
		{
			var c = getchar_unlocked() & 1;
			if (c)
			{
				max = Max(max, columnAccum[j] + rowMax[j]);
				for (int k = j - currentChain; k < j; k++)
					rowMax[k] = Max(rowMax[k], currentChain);
				currentChain = 0;
				rowMax[j] = 0;
				columnAccum[j] = 0;
			}
			else
			{
				currentChain++;
				columnAccum[j]++;
			}
		}
		for (int j = w - currentChain; j < w; j++)
			rowMax[j] = Max(rowMax[j], currentChain);
		getchar_unlocked();
	}
	for (int i = 0; i < w; i++)
		max = Max(max, columnAccum[i] + rowMax[i]);
	writeline(max - 1);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a;cin>>n;
  set<ll> s;
  rep(i,n) {cin>>a;s.insert(a);}
  if(s.size()==n) print("YES"); else print("NO");
  return 0;
}

Measured memory_bytes: 9600