akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  long long n;
  cin>>n;
  long long ans = 0;
  for(long long k = 2; k <= 1'000'000; k++){
    if(k > n)break;
    if(n % (k * k) != 0)continue;
    long long temp = n;
    while(temp % k == 0){
      temp /= k;
    }
    if(temp % k == 1) ans++;
  }
  ans++;
  for(long long k = 2; k <= 1'000'000; k++){
    if(k >= n)break;
    if(n % k != 0)continue;
    long long temp = n / k;
    if(temp % k == 1) ans++;
  }
  vector<long long> primes;
  for(long long i = 1; i < 1'000'000; i++){
    if(prime_(i)){
      primes.push_back(i);
    }
  }
  vector<pair<long long, long long>> pcnt;
  long long temp = n - 1;
  long long nums = 1;
  for(long long p: primes){
    if(temp % p != 0)continue;
    long long cnt = 0;
    while(temp % p == 0){
      temp /= p;
      cnt++;
    }
    nums *= (cnt + 1);
  }
  if(temp > 1){
    nums *= 2;
  }
  nums--;
  ans += nums;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include <string>
#include<vector>
#include<algorithm>
#include <cstdlib>
using namespace std;
int main(){
    int n,ans=0;
    int b=0,c=0;
    cin >> n ;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    } 
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for(int i=0;i<n;i++){
        if(i%2 == 0){
            b += a[i];
        }else{
            c += a[i];
        }
    }
    ans = b-c;
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 256
import sys
from collections import deque
from functools import lru_cache
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    a, b, c, d = read_values()
    print(max(a * c, a * d, b * c, b * d))


if __name__ == "__main__":
    main()



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

int main(){
#define int int64_t
  int N;
  cin >> N;

  int t = 1;
  int a = 1;

  for(int i = 0;i < N;i++){
    int ti,ai;
    cin >> ti;
    cin >> ai;
    if(ti < t){
      if(ai < a){
	if((a/ai) < (t/ti)){
	  a = ((t + ti - 1)/ti)*ai;
	  t = ((t + ti - 1)/ti)*ti;
	  // std::cout << t << " " << a << " aaa" << std::endl;
	}else{
	  a = ((a + ai - 1)/ai)*ai;
	  t = ((a + ai - 1)/ai)*ti;
	  // std::cout << t << " " << a << " bbb" << std::endl;
	}
      }else{
	a = ((t + ti - 1)/ti)*ai;
	t = ((t + ti - 1)/ti)*ti;
	// std::cout << t << " " << a << " ccc" << std::endl;
      }
    }else{
      if(ai < a){
	a = ((a + ai - 1)/ai)*ai;
	t = ((a + ai - 1)/ai)*ti;
	// std::cout << t << " " << a << " ddd" << std::endl;
      }else{
	a = ai;
	t = ti;
	// std::cout << t << " " << a << " eee" << std::endl;
      }
    }
  }

  std::cout << (a + t) << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)3e5+5;
const int mod = (int)1e9+7;

int n, k;
int a[M], val[4*M], dp[M];

void update(int ind, int s, int e, int q)
{
	if(s == e)
	{
		val[ind] = dp[q];
		return;
	}
	int mid = (s+e)/2;
	if(q <= mid) update(2*ind, s, mid, q);
	else update(2*ind+1, mid+1, e, q);
	val[ind] = max(val[2*ind], val[2*ind+1]);
}

int query(int ind, int s, int e, int qs, int qe)
{
	if(s >= qs && e <= qe) return val[ind];
	if(s > qe || e < qs) return -1e10;
	int mid = (s+e)/2;
	int a1 = query(2*ind, s, mid, qs, qe);
	int a2 = query(2*ind+1, mid+1, e, qs, qe);
	return max(a1, a2);
}

void solve()
{
	int ans = 0;
	memset(val, 0, sizeof val);
    cin>>n>>k;
    f(i, 0, n) cin>>a[i];
    f(i, 0, n)
    {
    	int s = max(0ll, a[i]-k);
    	int e = a[i]+k;
    	int x = query(1, 0, M, s, e);
    	// cout<<s<<' '<<e<<' '<<x<<'\n';
    	dp[a[i]] = x+1;
    	ans = max(ans, dp[a[i]]);
    	update(1, 0, M, a[i]);
    	// f(i, 0, n) cout<<dp[a[i]]<<' ';
    	// cout<<endl;
    }
    cout<<ans<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 17716
A, B, C, D, E, F = map(int, input().split())

w = set()
for i in range(F // (100 * A) + 1):
    for j in range(F // (100 * B) + 1):
        a = (A * i + B * j) * 100
        if a < F:
            w.add(a)
w.remove(0)

s = set()
t = E * F // 100
for i in range(t // C + 1):
    for j in range(t // D + 1):
        b = C * i + D * j
        if b < t:
            s.add(b)
s = list(s)
s.sort()

best_concentration = -1
best_a = -1
best_b = -1
for a in w:
    for b in s:
        if a + b > F:
            break
        if b > E * a // 100:
            break
        concentration = 100 * b / (a + b)
        if concentration > best_concentration:
            best_concentration = concentration
            best_a = a
            best_b = b
print(best_a + best_b, best_b)


Measured memory_bytes: 3188
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll x, ll k) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++)
		sum *= (x--);
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for (int i = k + 1; i <= n; i++) {
		ans += (i - k)*floor(n*1.0 / i);
		if (n%i > 0) {
			ans += max(0ll, n - (i*(int)ceil(n*1.0 / i) - (i - k)) + 1);
			if (k == 0) ans--;
		}
	}
	cout << ans << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm> 
#include<cstring>
#define ios ios::sync_with_stdio(false)
#define mem(arr) memset(arr,0,sizeof(arr))
using namespace std;
typedef long long ll;
const ll maxn = 1e6 + 10;
const ll mod = 1e9 + 7; 
ll ksm(ll a, ll b, ll p)
{
    ll res = 1;
    while(b)
	{
        if (b&1) 
			res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}
int main()
{
	int n;
	ll ans;
    cin>>n;
    ans = ((ksm(10,n,mod) % mod + ksm(8,n,mod) % mod - (2 * (ksm(9,n,mod) % mod)) % mod) + mod) % mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include<cstdio>
using namespace std;
template<typename T>
T max(T a, T b){
  if(a > b)
    return a;
  return b;
}
int main(){
  int T{};
  int S{};
  int data;
  for(int i{} ; i < 4 ; i++){
    scanf("%d",&data);
    T += data;
  }
  for(int i{} ; i < 4 ; i++){
    scanf("%d",&data);
    S += data;
  }
  printf("%d\n",max(T,S));
}



Measured memory_bytes: 2744
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int a;

int main(){
	cin >> a;
	if (a < 1200) {
		cout << "ABC";
	} else if (a < 2800) {
		cout << "ARC";
	} else {
		cout << "AGC";
	}
	
	
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	bool seven = 0;
	for (char ch : s) if (ch == '7') seven = 1;
	if (seven) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 3652
macro_rules! get {
    (Vec<$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) => {
        {
            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; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (N, K) = get!(i64, i64);

    let ans = if K == 1 || (N + 1) / K >= 2 {
        "YES"
    } else {
        "NO"
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
n,k=map(int,input().split())
s=input()
ct=0
for i in range(n-1):
  if s[i]=='R' and s[i+1]=='L':ct+=1
x=ct
ct-=min(ct,k)
ct*=2
if s[0]==s[n-1]:
  ct+=1
elif s[0]=='L':
  if x<k:
    ct+=1
  else:
    ct+=2
else:
  if x<=k:
    ct+=1
print(n-ct)

Measured memory_bytes: 3316
n,y = map(int,input().split() )
a,b,c=-1,-1,-1
for i in range(n+1):
  mannogaku = 10000*i
  for j in range(n-i+1):
    kingaku = mannogaku + 5000*j + 1000*(n-i-j)
    if kingaku == y:
      a=i
      b=j
      c=n-i-j
      break  
    else:
      continue  
print(a,b,c)      

Measured memory_bytes: 40940
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, w;
    cin >> n >> w;
    vector< pair<int, int> > items(n + 1);
    vector< vector<long long> > res(n + 1, vector<long long>(w + 1, 0));
    for (int i = 1; i <= n; ++i) cin >> items[i].first >> items[i].second;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= w; ++j) {
            res[i][j] = res[i - 1][j];
            if (items[i].first <= j && items[i].second + res[i - 1][j - items[i].first] > res[i][j])
                res[i][j] = items[i].second + res[i - 1][j - items[i].first];
        }
    }
    cout << res[n][w];
    return 0;
}


Measured memory_bytes: 80256
#include <cstdio>
#include <cmath>

using namespace std;

inline double out(double ax,double ay,double bx,double by){
	return bx * ay - by * ax;
}

int main(void){
	double x1, y1, x2, y2, x3, y3, px, py;
	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&px,&py) != EOF){
		if((out(px - x1,py - y1,x2 - x1,y2 - y1) > 0 && out(px - x2,py - y2,x3 - x2,y3 - y2) > 0 && out(px - x3,py - y3,x1 - x3,y1 - y3) > 0) || (out(px - x1,py - y1,x2 - x1,y2 - y1) < 0 && out(px - x2,py - y2,x3 - x2,y3 - y2) < 0 && out(px - x3,py - y3,x1 - x3,y1 - y3) < 0)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}

	return 0;
}

Measured memory_bytes: 1040
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define all(x) (x).begin() , (x).end()
#define inf 1000000000
#define mod 1000000007

void dbg(){
	cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
	cerr << h << " ";
	dbg(t...);
}

#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__  << "): ", dbg(__VA_ARGS__)
#else 
#define debug(...)
#endif

const int max_n = 1e5 + 9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
void solve(){
	int h , w;
    cin >> h >> w;

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

    int dp[h][w];
    memset(dp , 0 , sizeof(dp));
    dp[0][0] = 1;
    for(int i = 0 ; i < h ; i++){
        for(int j = 0 ; j < w ; j++){
            if(s[i][j] == '#'){
                dp[i][j] = 0;
            }
            else{
                if(i - 1 >= 0)dp[i][j] = (dp[i][j] + dp[i-1][j])%mod;
                if(j - 1 >= 0)dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
            }
            // cout << dp[i][j] << " ";
        }
        // cout << "\n";
    }
    cout << dp[h-1][w-1] << "\n";
}
signed main(){
	int t = 1;
	// cin >> t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> M(N);
  for(int i = 0; i<N; i++){
    cin >> M.at(i);
  }
  int sum;
  for(int j = 0; j<N; j++){
    sum += M.at(j);
  }
  int ave = sum/N;
  int HP1,HP2;
  for(int k = 0; k < N; k++){
    HP1 += (M.at(k)-ave)*(M.at(k)-ave);
  }
  for(int l = 0; l<N;l++){
    HP2 += (M.at(l)-ave-1)*(M.at(l)-ave-1);
  }
  if(HP1<HP2){
    cout<<HP1<<endl;
  }
  else{
    cout<<HP2<<endl;
  }
}


Measured memory_bytes: 256
def is_prime(x, i):
  if i*i > x:
    return True
  elif x % i == 0:
    return False
  else:
    return is_prime(x, i+1)
  
def gen_prime(x):
  if is_prime(x, 2):
    return x
  else:
    return gen_prime(x+1)
    
if __name__ == "__main__":
  import sys
  sys.setrecursionlimit(10240)
  x = int(input())
  print(gen_prime(x))


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

using namespace std;

int
main(void){
	int n, m; cin >> n >> m;
	vector<string> vec(n);
	for(int i = 0; i < n; i++){
		cin >> vec[i];
	}
	vector<vector<bool> > flag(n, vector<bool> (m, true));
	for(int i = 0; i < n; i++){
		bool first = true;
		for(int j = 0; j < m; j++){
			if(vec[i][j] == '.') continue;
			if(first == true){
				first = false;
				if(j == m - 1){
					flag[i][j] = false;
				}
				else if(vec[i][j + 1] != vec[i][j]){
					flag[i][j] = false;
					first = true;
				}
			}
			else{
				if(j != m - 1){
					if(vec[i][j] != vec[i][j + 1]){
						first = true;
					}
				}
			}
		}
	}
	for(int j = 0; j < m; j++){
		bool first = true;
		for(int i = 0; i < n; i++){
			if(vec[i][j] == '.') continue;
			if(first == true){
				first = false;
				if(i == n - 1){
					flag[i][j] = flag[i][j] | false;
				}
				else if(vec[i + 1][j] != vec[i][j]){
					flag[i][j] = flag[i][j] | false;
					first = true;
				}
				else{
					flag[i][j] = true;
				}
			}
			else{
				flag[i][j] = true;
				if(i != n - 1){
					if(vec[i][j] != vec[i + 1][j]){
						first = true;
					}
				}
			}
		}
	}
	bool ans = true;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			ans = ans & flag[i][j];
		}
	}
	if(ans) cout << "Yes";
	else cout << "No";
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
int getGCD(int a,int b){
  if(b == 0){
    return a;
  }else{
    return getGCD(b,a%b);
  }
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  
  int n,m;
  cin >> n >> m;
  string s,t;
  cin >> s;
  cin >> t;
  int gcd = getGCD(n,m);
  ll lcd = (ll)n*m/gcd;
  if(n < m){
    int tmp = m;
    m = n;
    n = tmp;
    string tmps = s;
    s = t;
    t = tmps;
  }
  
  umap<int,char> map;
  int mdash = lcd/n;
  
  REP(i,n){
    map[i*mdash] = s[i];
  }
  int ndash = lcd/m;
  REP(i,n){
    if(map.find(i*ndash)!=map.end() && map[i*ndash]!=t[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << lcd << endl;
  return 0;
}


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

void max_prime(long long n, vector<long long> &v) {
    long long m = sqrt(n) + 1;

    for (long long i = 1; i <= m; i++) {
        if (n % i == 0) {
            v.emplace_back(i);
        }
    }
}

int main() {

    long long n;
    cin >> n;

    vector<long long> v;

    max_prime(n, v);

    long long min_res = 1100000000000;
    for (long long i = 0; i < v.size(); i++) {
        long long a = v[i];
        long long b = n / v[i];
        long long temp = a + b - 2;

        if (temp < min_res) {
            min_res = temp;
        }
    }

    cout << min_res << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#define MAX 1000001

using namespace std;

bool dp[MAX];
int n,est;
int value[31];


int isPrime(int N){

  for( int i = 2 ; i*i + 1 < N ; i++ ){
    if( N % i == 0 ) return 0;
  }
  return N;

}

void solve(void){

  dp[0] = true;
  for( int i = 0 ; i < n ; i++ ){
    for( int j = value[i] ; j <= est ; j++ ){
      if( dp[j - value[i]] ) dp[j] = true;
    }
  }
}

int main(void){


  while( cin >> n >> est , n + est ){

    fill( dp , dp + MAX , false );

    for( int i = 0 ; i < n ; i++ )
      cin >> value[i];

    solve();

    int ans = 0;
    for( int i = est ; i >= 2 ; i-- ){
      if( dp[i] ){
	ans = isPrime(i);
	if( ans ) break;
      }
    }
    if( ans ) cout << ans << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
const ll INF = 1LL<<60;
 
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
 
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
   	
   	vector<int> A(3);
  
  	cin >> A[0] >> A[1] >> A[2];
  
  	sort(A.begin(), A.end());
  
  	int sub_from_max = 2 * A[2] - A[1] - A[0];
  
  	if(sub_from_max % 2 == 0){
      cout << sub_from_max / 2 << endl; 
    }else{
      cout << (sub_from_max+1) / 2 + 1 << endl;
    }
  
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

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

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s, t;
    cin >> s >> t;
    rep (i, s.size()) {
        string tmp;
        tmp = s.substr(i);
        tmp += s.substr(0, i);
        if (tmp == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

    int n,k;

    cin >> n >> k;

    if(n % 2 == 1){
        if(k > n / 2 + 1){
            cout << "NO";
        }else cout << "YES";
    }else{
        if(k > n / 2){
            cout << "NO";
        }else cout << "YES";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        if (x < a) {
            System.out.println(0);
        } else {
            System.out.println(10);
        }
    }
}

Measured memory_bytes: 22740
N, K = map(int, input().split())
x = list(map(int, input().split()))
m = float("INF")
for i in range(N - K + 1):
    m = min(m, x[i + K - 1] - x[i] + min(abs(x[i + K - 1]), abs(x[i])))
print(m)


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

int main(){
int A,B,C,D;
  string S;
  cin>>A>>B>>C>>D;
  int E=C-A;
  int F=D-B;
  for(int i=0;i<E;i++)
    cout<<'R';
  for(int i=0;i<F;i++)
    cout<<'U';
  for(int i=0;i<E;i++)
    cout<<'L';
  for(int i=0;i<F;i++)
    cout<<'D';
  cout<<'D';
  for(int i=0;i<E+1;i++)
    cout<<'R';
  for(int i=0;i<F+1;i++)
    cout<<'U';
  cout<<'L';
  cout<<'U';
  for(int i=0;i<E+1;i++)
    cout<<'L';
  for(int i=0;i<F+1;i++)
    cout<<'D';
  cout<<'R'<<endl;
}

Measured memory_bytes: 256
<?php 
$values = array_map('intval', explode(' ', fgets(STDIN)));
$n = $values[0];
$min = $values[1];
$max = $values[2];

// 1 <= x <= N  
// 1. 各行の和をどのように出力するか
// 0埋めして、array_sumで合計を求めて、min max間であればOK？
// 2. それらの総和を求める
$arry = [];
$result = 0;
for ($i=1; $i <= $n; $i++) {
    if ($i < 10) {
        // 01 02のように0埋めする
        $i = str_pad($i, 2, 0, STR_PAD_LEFT);
    }
    // 文字列にして、１文字ずつに変換し、array_sumで配列の合計を求める
    $sum = array_sum(str_split(strval($i)));    
    // str_split(strval($i));
    if ($min <= $sum && $sum <= $max) {
        $result += (int)$i;
    }
}
echo $result;

Measured memory_bytes: 15784
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll H[N];
    rep(i, N){
        cin >> H[i];
    }
    sort(H, H + N, greater<ll>());

    ll ans = 0;
    if(K < N){
        for(ll i = K; i < N; i++){
            ans += H[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
int f(int n){
    if(n%2==0) return n/2;
    else return 3*n+1;
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int s;
    cin  >> s;
    vector<int>a(1000000);
    a[0] = s;
    int ans;
    REP1(i,1000000){
        a[i]= f(a[i-1]);
        bool flag = true;
        REP(j,i){
            REP(k,j){
            if(a[k]==a[j] ){ 
                flag = false;
                ans = j;
                cout << ans +1 << endl;
                return 0;
                 
            }
            
        }
        
    }
    }


}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
//区間l(l,r)の範囲を二次元座標で考える
//二次元累積和
int s[510][501];
int main(){
    int N,M,Q;
    cin >> N >> M >> Q;
    rep(i,M) {
        int l,r;
        cin >> l >> r;
        s[l][r]++;
    }
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            s[i][j] += s[i-1][j] + s[i][j-1] - s[i-1][j-1];
        }
    }
    rep(i,Q){
        int p,q;
        cin >> p >> q;
        cout << s[q][q] - s[q][p-1] - s[p-1][q] + s[p-1][p-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1920
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int x = 0;
		int max = 0;
		for (int i = 0; i < n; i++ ) {
			if (s.charAt(i) == 'I') {
				x++;
			} else {
				x--;
			}
			if (max < x) {
				max = x;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
# define NMAX 105
# define WMAX 10005
# define DIAGONAL 1
# define STRAIGHT 0

using namespace std;

struct item
{
    int value;
    int weight;
};

typedef struct item Item;
Item items[NMAX];
int C[NMAX][WMAX]; // 书上原始状况都为NMAX+1
int G[NMAX][WMAX];
int N,W;

void input()
{
    cin >> N >> W;
    for(int i=1; i<=N ; i++)
    {
        cin>> items[i].value >> items[i].weight;
    }
};

void compute()
{
    for(int i=0;i<=W;i++)
    {
        C[0][i]=0;
        G[0][i]=DIAGONAL;
    }
    for(int i=0;i<=N;i++)C[i][0]=0;

    for(int n=1;n<=N;n++)
    {
        for(int w=1;w<=W;w++)
        {
            if(items[n].weight<=w)
            {
                if(items[n].value+C[n-1][w-items[n].weight]>C[n-1][w])
                {
                    C[n][w]=items[n].value+C[n-1][w-items[n].weight];
                    G[n][w]=DIAGONAL;
                    //cout<< "选择的物品是~~~："<< n << endl;
                    //cout<< "C==" << C[n][w]<< endl;
                }
                else
                {
                    C[n][w]=C[n-1][w];
                    G[n][w]=STRAIGHT;
                }
            }
            else
            {
                C[n][w]=C[n-1][w];
                G[n][w]=STRAIGHT;
            }
        }
    }
};

int main()
{
    input();
    compute();
    int maxvalue=C[N][W];
    cout<< maxvalue <<endl;
    for(int i=1;i<=N;i++)
    {
        //if(G[i][W]==DIAGONAL) cout<< "选择的物品是："<< i << endl;
    }
    return 0;
}

/*
4 5
4 2
5 2
2 1
8 3

4 8
4 2
5 2
2 1
8 3
 */
 


Measured memory_bytes: 10984
#include <stdio.h>
#include <math.h>
#include <string.h>


int main (void){
        int H,W,gyou=1,mode=0;
        int a[501][501];
        int kaisu=0;
        int ans[250000][4];
        scanf("%d %d\n",&H,&W );
for (int i = 1; i <= H; i++) {
  for (int j = 1; j <= W; j++) {
    scanf("%d",&a[i][j]);
    a[i][j]=a[i][j]%2;
  }
}

while(gyou<=H){
  if (gyou%2==1) {//奇数行
    for (int i = 1; i <= W; i++) {
      mode=a[gyou][i];
      if (mode==1) {
        if (i==W) {
          if (gyou!=H) {
            kaisu++;
            ans[kaisu][0]=gyou;
            ans[kaisu][1]=W;
            ans[kaisu][2]=gyou+1;
            ans[kaisu][3]=W;
            a[gyou+1][W]++;
          }
        }else{
          kaisu++;
          ans[kaisu][0]=gyou;
          ans[kaisu][1]=i;
          ans[kaisu][2]=gyou;
          ans[kaisu][3]=i+1;
          a[gyou][i+1]++;
        }
      }
    }
  }

  if (gyou%2==0) {//偶数行
    for (int i = W; i >= 1; i--) {
      mode=a[gyou][i];
      if (mode==1) {
        if (i==1) {
          if (gyou!=H) {
            kaisu++;
            ans[kaisu][0]=gyou;
            ans[kaisu][1]=1;
            ans[kaisu][2]=gyou+1;
            ans[kaisu][3]=1;
          a[gyou+1][1]++;
        }
        }else{
          kaisu++;
          ans[kaisu][0]=gyou;
          ans[kaisu][1]=i;
          ans[kaisu][2]=gyou;
          ans[kaisu][3]=i-1;
          a[gyou][i-1]++;
        }
      }
    }
  }
gyou++;
}
printf("%d\n", kaisu);
for (int i = 1; i <= kaisu; i++) {
  printf("%d %d %d %d\n",ans[i][0],ans[i][1],ans[i][2],ans[i][3] );
}

        return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    double x,sumx=0;
    ll suml=0;
    string u;
    rep(i, n) {
        cin >> x >> u;
        if (u == "JPY")suml += x;
        else sumx += x;
    }

    double sums = suml + (sumx * 380000.0);
    cout << fixed << setprecision(16) << sums << endl;
    return 0;
}

Measured memory_bytes: 256
// ref: https://img.atcoder.jp/abc099/editorial.pdf
// ref: http://xxxasdfghjk999.hatenablog.jp/entry/2018/07/27/220336

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, C; cin >> N >> C;
    vector<vector<int>> vvD(C, vector<int>(C));
    vector<vector<int>> vvT(3, vector<int>(C, 0));
    for(int r=0;r<C;++r){for(int c=0;c<C;++c){ cin>>vvD[r][c]; }}
    for(int r=0;r<N;++r){for(int c=0;c<N;++c){ int tmp; cin>>tmp; vvT[(r+c)%3][tmp-1]+=1; }}
    /*
     * vvT[0][ 0~ C-1 ]: mod==0 の要素について，0~ C-1 種類の色がそれぞれ幾つあるかを保持している．
     * vvT[1][ 0~ C-1 ]: mod==1 の要素について，0~ C-1 種類の色がそれぞれ幾つあるかを保持している．
     * vvT[2][ 0~ C-1 ]: mod==2 の要素について，0~ C-1 種類の色がそれぞれ幾つあるかを保持している．
     */
    
    int ret=INT_MAX;
    for(int p=0; p<C; ++p){
        for(int q=0; q<C; ++q){
            if(p==q){ continue; } // skip the same color
            for(int r=0; r<C; ++r){
                if(r==p || r==q){ continue; } // skip the same color
                
                // 自分自身への変換は，vvD 行列の対角成分が 0 のため，考慮しなくてよい．
                int tt=0;
                for(int i=0; i<C; ++i){ tt+=vvD[i][p]*vvT[0][i]; } // mod==0 の色を全て p に塗り替える場合の違和感の総和 // vvD[i][p]: wrongness of cnv-ing i2p, vvT[0][i]: num of color-[i] in mod [0].
                for(int i=0; i<C; ++i){ tt+=vvD[i][q]*vvT[1][i]; } // mod==1 の色を全て q に塗り替える場合の違和感の総和 // vvD[i][q]: wrongness of cnv-ing i2q, vvT[1][i]: num of color-[i] in mod [1].
                for(int i=0; i<C; ++i){ tt+=vvD[i][r]*vvT[2][i]; } // mod==2 の色を全て r に塗り替える場合の違和感の総和 // vvD[i][r]: wrongness of cnv-ing i2r, vvT[2][i]: num of color-[i] in mod [2].
                
                if(tt < ret){ ret=tt; }
            }
        }
    }
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define MOD 1000000009
using namespace std;
typedef long long ll;
int main()
{
  int N;
  cin >> N;
  vector<int > d(N);
  REP(i, N) cin >> d[i];
  sort(d.begin(), d.end());
  //  REP(i, N) cout << d[i] << endl;
  int l = d[N/2 - 1];
  int r = d[N/2 ];
  // cout << l << endl;
  // cout << r << endl;
  cout << r - l << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){
  int i,n,a[100];
  scanf("%d",&n);
  for(i=0;i<n;i++) 
    scanf("%d",&a[i]);
  for(i=1;i<=n;i++){
    printf("%d",a[n-i]);
    if(i==n)
      printf("\n");
    else
      printf(" ");
  }
  return 0;
}



Measured memory_bytes: 2112
#pragma GCC optimize("O3", "unroll-loops")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		int ai; cin >> ai;
		a[i] = ai * n;
	}
	int avr = accumulate(a.begin(), a.end(), 0) / n;
	vector<int> dis(n);
	for (int i = 0; i < n; ++i)
		dis[i] = abs(a[i] - avr);
	int mn = 10000000;
	for (int i = 0; i < n; ++i)
		mn = min(mn, dis[i]);
	for (int i = 0; i < n; ++i) {
		if (dis[i] == mn) {
			cout << (i) << endl;
			exit(0);
		}
	}
	return 0;
}

Measured memory_bytes: 256
def main():
    k, s = map(int, input().split())
    ans = 0
    for z in range(s//3, k+1):
        for y in range((s-z)//2, s-z+1):
            x = s-z-y
            if x <= y and y <= z:
                if x == y and y == z:
                    ans += 1
                elif x == y or y == z:
                    ans += 3
                else:
                    ans += 6
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 39792
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

const int MAX = 1010101;

long long fac[MAX], finv[MAX], inv[MAX];

void binom_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long binom(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll, ll> prime_factor(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n]++;
    }
    return res;
}

int N, M;

int main()
{
    binom_init();
    cin >> N >> M;
    auto facts = prime_factor(M);
    ll ans = 1;
    for (auto e : facts)
    {
        auto k = e.first;
        auto v = e.second;
        ans *= binom(N - 1 + v, v);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 23936
#include <iostream>
#include <algorithm>
#define INF 100000000

using namespace std;

int N, A, B, C;
int L[8];


int dfs(int n, int a, int b, int c) {
    if (n == 0) {
        if (a == 0 || b == 0 || c == 0) {
            return INF;
        } else {
            return abs(a - A) + abs(b - B) + abs(c - C) - 30;
        }
    }

    int l = L[n - 1];
    int ret0 = dfs(n - 1, a, b, c);
    int ret1 = dfs(n - 1, a + l, b, c) + 10;
    int ret2 = dfs(n - 1, a, b + l, c) + 10;
    int ret3 = dfs(n - 1, a, b, c + l) + 10;

    return min({ret0, ret1, ret2, ret3});
}

int main() {
    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; i++) cin >> L[i];

    cout << dfs(N, 0, 0, 0) << endl;

    return 0;
}


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

using namespace std;
int h,w,a,b;
int main()
{
    ios::sync_with_stdio(false);
    cin>>h>>w>>a>>b;
    for(int i=0;i<b;i++){
        for(int j=0;j<a;j++){
            cout<<0;
        }
        for(int j=a;j<w;j++){
            cout<<1;
        }
        cout<<endl;
    }
    for(int i=b;i<h;i++){
        for(int j=0;j<a;j++){
            cout<<1;
        }
        for(int j=a;j<w;j++){
            cout<<0;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
// #pragma GCC optimize("O2")
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef multiset <ll> mms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define deb(x) cout << #x << " " << x << endl;
#define ff first
#define ss second
#define pb(v) push_back(v)
#define lb(v) lower_bound(v)
#define ub(v) upper_bound(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b) {
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s) {
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v) {
	forl(i,v.size()) cout<<v[i]<<" ";
	cout<<"\n";
}
void pa(ll *v, ll size) {
	forl(i,size) cout<<v[i]<<" ";
	cout<<"\n";
}
void removeDups(mv &v) {
	sort(all(v));
	mv::iterator it = unique(v.begin(), v.end());
	v.resize(distance(v.begin(), it));
}
inline ld kthRoot(ld n, ll k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}
ll power(ll x, ll y, ll p) {
	ll res=1;
	x=x%p;
	while(y>0) {
		if(y&1) res = (res*x)%p;
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x, ll mod) {
	if(x>=mod) x%=mod;
}

ll mod = 1e9 + 7;

ll arr1[200005], arr2[200005];
void thisIsMain() {
	ll n;
	cin>>n;
	forl(i,n) cin>>arr1[i];
	forl(i,n) cin>>arr2[i];
	sort(arr2, arr2 + n, greater < ll > ());
	// pa(arr1, n);
	// pa(arr2, n);
	ll i = 0, j = n - 1;
	forl(k,n) {
		if(arr1[k]  == arr2[k]) {
			if(arr1[i] != arr2[k] && arr2[i] != arr2[k]) {
				swap(arr2[i], arr2[k]);
				i ++ ;
			} else {
				if(arr1[j] != arr2[k] && arr2[j] != arr2[k]) {
					swap(arr2[j], arr2[k]);
					j -- ;
				} else {
					cout<<"No\n";
					return ;
				}
			}
		}
	}
	forl(i,n) if(arr1[i] == arr2[i]) {
		cout<<"No\n";
		return ;
	}
	cout<<"Yes\n";
	pa(arr2, n);
}

int main(void)
{
	fastio
	ll t = 1;
	// cin>>t;
	while(t--) thisIsMain();
	return 0;
}

Measured memory_bytes: 6716
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#define INT long long int
#define Mod 1000000007
using namespace std;
INT A[2010];
int main(){
    INT a, i, j,s;
    cin >> a;
    A[0]=1;
    A[3]=1;
    A[4]=1;
    A[5]=1;
    for(i=6;i<=a;i++){
        s = 0;
        for(j=3;j<=i;j++){
            s = (s + A[i-j]) % 1000000007;
        }
        A[i]=s;
    }
    cout << A[a] <<endl;
}


Measured memory_bytes: 3644
def main():
	s = input()
	md = 10 ** 9 + 7

	dp = [[0 for _ in range(4)] for _ in range(len(s) + 1)] 
	dp[len(s)][3] = 1

	d_q = {"?":3, "A":1, "B":1, "C":1}
	
	d_abc = [
	{"?":1, "A":1, "B":0, "C":0},
	{"?":1, "A":0, "B":1, "C":0},
	{"?":1, "A":0, "B":0, "C":1},
	]

	for i in reversed(range(0, len(s))):
		dp[i][3] = (dp[i + 1][3] * d_q[s[i]]) % md

	for j in reversed(range(3)):
		dp[len(s) - 1][j] = 0
		for i in reversed(range(0, len(s))):
			dp[i][j] = (dp[i + 1][j] * d_q[s[i]] + dp[i + 1][j + 1] * d_abc[j][s[i]]) % md
		
	print(dp[0][0] % md)

if __name__ == '__main__':
	main()

Measured memory_bytes: 27604
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
  int rootn;
bool compare(p3 a,p3 b){
    if((a.fi.fi/rootn) != (b.fi.fi/rootn))
        return (a.fi.fi/rootn) < (b.fi.fi/rootn);
    return a.fi.se<b.fi.se;
}
int brr[500001]={0};
int dif=0;
void add(int x){
    if(brr[x]==0) dif++;
    brr[x]++;
}
void rem(int x){
    if(brr[x]==1) dif--;
    brr[x]--;
}
 int arr[500001];
int main()
{
    int n;
    
  string s;
  cin>>n;
  rootn= static_cast<int>(sqrt(n));
  rootn= max(rootn,1000);
  //cout<<rootn<<endl;
  int k;
  cin>>k;
 
  sa(arr,n,d);
  int m=0;
  v(p3) vv;
  rep(i,k){
      int a,b;
      cin>>a>>b;
      a--,b--;
      vv.pb(mk(mk(a,b),i));
  }
  sort(vv.begin(),vv.end(),compare);
  int ll=0,rr=-1;
  v(int) ans(k);
  rep(i,k){
     // cout<<vv[i].fi.fi<<" "<<vv[i].fi.se<<endl;
    int l=vv[i].fi.fi;
    int r=vv[i].fi.se;
    while(rr<r){
        rr++;
        add(arr[rr]);
    }
    while(r<rr){
        rem(arr[rr]);
        rr--;
    }
    while(ll<l){
        rem(arr[ll]);
        ll++;
    }
    while(l<ll){
        ll--;
        add(arr[ll]);
    }
    ans[vv[i].se]=dif;
  }
  rep(i,k) cout<<ans[i]<<"\n";
  //cout<<endl;
}


Measured memory_bytes: 15476
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	llint n, p;
	cin >> n >> p;
	vllint a(n);
	int cnt = 0;
	rep(i, n) {
		cin >> a[i];
		a[i] %= 2;
		cnt += a[i];
	}
	llint ans = 1;
	if (p == 1 && cnt == 0) {
		ans = 0;
	}
	if (p == 0 && n == 1 && a[0] == 1) {
		ans = 0;
	}
	if (cnt == 0) {
		rep(i, n) {
			ans *= 2;
		}
	}
	else {
		rep(i, n - 1) {
			ans *= 2;
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

typedef long long ll;
typedef pair <int, int> pii;

const int N = 1e5 + 5;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);	
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if(s == u)
		a--;
	else
		b--;
	cout << a << " " << b << "\n";
}

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

int main() {

	int a, b, c, d, sml_ab = 0, sml_cd = 0;
	cin >> a >> b >> c >> d;

	a > b ? sml_ab = b : sml_ab = a;
	c > d ? sml_cd = d : sml_cd = c;

	cout << sml_ab + sml_cd;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    int ans = (x-a)%b;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env pypy3

import collections


def solve(n, xs):
    tmp = []
    for i, x in enumerate(xs):
        if i == 0:
            tmp.append(x)
        else:
            tmp.append(tmp[i - 1] + x)
    tmp.insert(0, 0)
    ctr = collections.Counter(tmp)
    res = 0
    for _, v in ctr.items():
        res += v * (v - 1) // 2
    return res


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    print(solve(n, xs))


if __name__ == '__main__':
    main()


Measured memory_bytes: 113152
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<random>
#include<deque>
#include<cstdio>
#include<fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2000100;
const int mod = (int)pow(10, 9) + 7;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define ppp pair<pp,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
#define print(s) cout<<s<<endl
#define inp(s) cin>>s
string yn(bool b) { return (b ? "Yes" : "No"); }
string YN(bool b) { return (b ? "YES" : "NO"); }
ll n;
vector<ll>v;
int main() 
{
	cin >> n;
	while (n!=0) {
		ll m = n;
		v.push_back(abs(n)%2);
		n /= -2;
		if (m < 0 && abs(m) % 2 != 0)++n;
	}
	if (v.size() == 0)cout << 0 << endl;
	for (int i = v.size() - 1; i >= 0; --i)cout << v[i];
	cout << "" << endl;
	return 0;
}

Measured memory_bytes: 256