akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A;
  int abs_sum = 0;
  vector<int> pA;
  vector<int> mA;
  rep(i, N) {
    int A;
    cin >> A;
    abs_sum += abs(A);
    if (0 <= A)
      pA.emplace_back(A);
    else
      mA.emplace_back(A);
  }
  sort(pA.begin(), pA.end());
  sort(mA.begin(), mA.end(), greater<int>());

  int plus = pA.size();
  int minus = mA.size();
  int pi = 0;
  int mi = 0;
  if (plus == 0) {
    if (minus == 2) {
      cout << mA[1] - mA[0] << endl;
      cout << mA[1] << " " << mA[0] << endl;
      return 0;
    }
    abs_sum += (2 * mA[0]);
    cout << abs_sum << endl;
    cout << mA[0] << " " << mA[1] << endl;
    pA.emplace_back(mA[0] - mA[1]);
    mi = 2;
    minus -= 2;
    plus = 1;
  } else if (minus == 0) {
    if (plus == 2) {
      cout << pA[1] - pA[0] << endl;
      cout << pA[1] << " " << pA[0] << endl;
      return 0;
    }
    abs_sum -= (2 * pA[0]);
    cout << abs_sum << endl;
    cout << pA[0] << " " << pA[1] << endl;
    mA.emplace_back(pA[0] - pA[1]);
    pi = 2;
    plus -= 2;
    minus = 1;
  } else {
    cout << abs_sum << endl;
  }

  while (plus && minus) {
    if (plus <= minus) {
      cout << pA[pi] << " " << mA[mi] << endl;
      pA[pi] -= mA[mi++];
      --minus;
    } else {
      cout << mA[mi] << " " << pA[pi] << endl;
      mA[mi] -= pA[pi++];
      --plus;
    }
  }
  return 0;
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define debug(x) cerr<<#x<<" "<<x<<endl;

signed main() {
  int n;cin>>n;
  int s,t;
  bool isFirst=true;
  for(int i=0;i<n;++i){
    int p,q;cin>>p>>q;
    if(isFirst){
      s=p;t=q;
      isFirst=false;
      continue;
    }
    
    int tmp = max((s+p-1)/p, (t+q-1)/q);
    s=tmp*p;
    t=tmp*q;
    debug(s);
    debug(t);
  }
  cout<<s+t<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

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

  int one = N % 10;

  switch (one) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
      break;
    default:
      break;
  }
}


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





int main(){

  int n;
  cin>>n;


bool s=true;
  for(int i=1;i<=9;i++){
    if(100*i+10*i+i >=n && s){
      cout<<100*i+10*i+i<<endl;
       s=false;
    }
  }

}


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

const double EPS = 1e-10;

int main(){
	int n, k, l;
	double t, u, v;
	cin >> n >> k >> t >> u >> v >> l;
	VI d(l);
	REP(i,n){
		int x;
		cin >> x;
		d[x] = 1;
	}
	double ans = 0.0, res = 0.0;
	int x = 0;
	REP(i,l){
		x += d[i];
		if (x > k){
			x = k;
			res = t;
		}
		if (res < EPS && x > 0){
			x--;
			res = t;
		}
		if (res > EPS){
			ans += 1.0/v;
			res -= 1.0/v;
		}else{
			ans += 1.0/u;
		}
	}

	printf("%.10f\n", ans);

    return 0;
}

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

#define st first
#define nd second
typedef pair<int, int> pii;

const int INF = 1e9;
const int N = 1e5 + 7;
pii elems[N];

int main()
{
	int n;
	scanf("%d", &n);

	int x, l;
	for (int i = 0; i < n; ++i)
	{
		scanf("%d%d", &x, &l);
		elems[i] = make_pair(x + l, x - l);
	}

	sort(elems, elems + n);

	int cur = -INF, res = 0;
	for (int i = 0; i < n; ++i)
		if (cur <= elems[i].nd)
		{
			++res;
			cur = elems[i].st;
		}

	printf("%d", res);

	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main() {
	//入力
	string S;
	cin >> S;

	//処理
	// A <-> T C <-> G

	map<char, char> m;
	m['A'] = 'T';
	m['T'] = 'A';
	m['C'] = 'G';
	m['G'] = 'C';

	char ans = m[S[0]];

	//出力
	cout << ans << endl;
}



Measured memory_bytes: 256
#![allow(non_snake_case)]
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let Q:usize = 1000_000_007;
    let mut R:usize = 0;
    let mut G:usize = 0;
    let mut B:usize = 0;
    let N:usize = sc.read();
    let A:Vec<usize> = sc.vec(N);
    if A[0] > 0{
        println!("0");
        return
    }
    let mut dp:Vec<usize> = vec![0;N];
    dp[0] = 3;
    R += 1;
    for i in 1..N{
        if (A[i] != R) && ( A[i] != G) && (A[i] != B){
            println!("0");
            return
        }
        if (R == G) && ( G == B ){
            dp[i] = dp[i-1]*3%Q;
            R += 1;
            continue
        }
        if (R == A[i]) && (G == A[i]){
            dp[i] = dp[i-1]*2%Q;
            R += 1;
            continue
        }
        if (G == A[i]) && (B == A[i]) {
            dp[i] = dp[i-1]*2%Q;
            G += 1;
            continue
        }
        if (B == A[i]) && (R == A[i]) {
            dp[i] = dp[i-1]*2%Q;
            B += 1;
            continue

        }
        if R == A[i]{
            dp[i] = dp[i-1];
            R += 1;
            continue
        }
        if G == A[i]{
            dp[i] = dp[i-1];
            G += 1;
            continue
        }
        if B == A[i]{
            dp[i] = dp[i-1];
            B += 1;
            continue
        }
    }
    println!("{}", dp[N-1]);


}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}




Measured memory_bytes: 6396
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a;
    for(;n;n/=10)a.push_back(n%10);
    std::reverse(a.begin(),a.end());
    std::cout<<a.front()+9*(a.size()-1)
        -!std::all_of(a.begin()+1,a.end(),[](lint x){return x==9;})
        <<'\n';
}


Measured memory_bytes: 256
S = int(input())
mod = int(1e+9)+7

bikkuri = [1 for _ in range(10*S)]
for i in range(1,10*S):
    bikkuri[i] = (bikkuri[i-1]*i)%mod


max_kosuu = S//3
answer = 0
for kosuu in range(1,max_kosuu+1):
    amari = S - kosuu*3
    pattern = (bikkuri[amari+kosuu-1] * pow(bikkuri[kosuu-1],mod-2,mod) * pow(bikkuri[amari], mod-2, mod))%mod
    answer = (answer + pattern)%mod

print(answer)

Measured memory_bytes: 9516
import sys

n = int(input())
a = list(map(int,input().split()))

a_even = [i for i in a if i%2==0]
# print(a_even)
for x in a_even:
    if x%3==0 or x%5==0:
        pass
    else:
        print('DENIED')
        # print(x)
        sys.exit()
print('APPROVED')

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

int main(){
	int n=read(),k=read();
	if (k==1) puts("0");
		else printf("%d\n",n-(k-1)-1);
}

Measured memory_bytes: 3664
# -*- coding: utf-8 -*-
import sys
N=input()
A=map(int, sys.stdin.readline().split())

L=[]
for i,a in enumerate(A):
    if i==0:
        L.append(a)
    else:
        L.append(L[-1]+a)

ans=float("inf")
for x in L:
    y=L[-1]-x
    ans=min(ans,abs(x-y))

print ans

Measured memory_bytes: 59580
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
bool prime[N];
int f[N];
int main()
{
    for(int i=0;i<=N;i++)
        prime[i]=true;
    prime[0]=prime[1]=false;
    for(int i=2;i<=N;i++)
        if(prime[i])
            if(i*1ll*i<=N)
                for(int j=i*i;j<=N;j+=i)
                    prime[j]=false;
    f[1]=0;
    for(int i=3;i<=N;i++)
        if(i&1)
            if(prime[i] && prime[(i+1)/2])
                f[i]=f[i-2]+1;
            else
                f[i]=f[i-2];
        else
            f[i]=f[i-1];
    int q;
    cin>>q;
    while(q--)
    {
        int l,r;
        cin>>l>>r;
        cout<<f[r]-f[l-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int N;
struct ball {
	int x;
	int y;
	bool color;
};

ball a[200];

int main(void)
{
	int res = 0;
	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> a[i].x >> a[i].y;
		a[i].color = true;
	}
	for (int i = 0; i < N; i++) {
		cin >> a[i + N].x >> a[i + N].y;
	}

	sort(a, a + 2*N, [](const auto & a, const auto & b) {
		if (a.x == b.x)
			return a.y < b.y;
		return a.x < b.x;
	});

	std::set<int> s;

	for (int i = 0; i < 2*N; i++) {
		if (a[i].color) {
			s.insert(a[i].y);
		}
		else {
			if (s.upper_bound(a[i].y) != s.begin()) {
				s.erase(std::prev(s.upper_bound(a[i].y)));
				res++;
			}
		}
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <tuple>
#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>
#include <climits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
// #define dump(x) cerr << #x << " = " << (x) << endl;
// #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
//                       << " " << __FILE__ << endl;

int main()
{
    long n;
    cin >> n;
    n = n * (n - 1) / 2;
    cout << n << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
ll mod                = 1e9 + 7;
const double PI       = acos(-1);
int main() {
	int n,m;
	ll ans = 0LL;
	ll cnt = 0LL;
	cin >> n >> m;
	V x(n), y(m);
	cin >> x >> y;
	int count = n - 1;
	for (int i = n - 1; i >= 0; i--) {
		cnt += x[i] * count;
		count -= 2;
		cnt %= mod;
	}
	ans = cnt;
	cnt   = 0;
	count = m - 1;
	for (int i = m - 1; i >= 0; i--) {
		cnt += y[i] * count;
		count -= 2;
		cnt %= mod;
	}
	cout << ans*cnt%mod << endl;
}

Measured memory_bytes: 4816
#include <iostream>


using namespace std;

int main()
{
	int n, d, x;
	cin >> n;
	cin >> d >> x ;
	int a[n];
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt += (d-1)/a[i] + 1;
	}
	cout << x+cnt << endl;	


    return 0;
}



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

int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < 4; ++i) {
		if (s[i] == '+') ++ans;
		else --ans;
	}
	cout << ans << endl;
}



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

def solve():
    N = int(input())
    S = input()
    if N%2 != 0:
        print("No")
        return

    l_str = S[0:N//2]
    r_str = S[N//2:]

    if l_str == r_str:
        print("Yes")
        return

    print("No")

if __name__ == "__main__":
    solve()


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

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

fn main() {
    let n:usize = read();
    let k:usize = read();
    let v:Vec<usize> = (0..n).map(|_| read()).collect();

    println!("{}", v.into_iter().filter(|&x| x >= k).count());
}

Measured memory_bytes: 2668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int e=(a+d-1)/d;
  int f=(c+b-1)/b;
  if(e>=f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<stdio.h>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
int main()
{

    int t,n,i,arra[1000];
    string s;
        cin>>n;
        cout<<n+n*n+n*n*n<<endl;
    return 0;
}



Measured memory_bytes: 3600
import sys
import numpy as np

# N 時計の数
n = int(input())

# Ti 各時計が1周する秒数
t = []
for i in range(n):
    t.append(int(input()))
    
# 最大公約数を求める
def gcb(a, b):
    if b == 0:
        return a
    return int(gcb(b, a % b))

def lcm(a, b):
    g = gcb(a, b)
    return a * b // g

if (n == 1):
    print(t[0])
else:
    ans = 1
    for num in t:
        ans = lcm(ans, num)
    print(int(ans))


Measured memory_bytes: 12408
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 10000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
// input vector
template<typename T>
void invec(vector<T> &A){for(T& a : A) cin >> a;}


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

int X, Y, Z, K; cin >> X >> Y >> Z >> K;
VI A(X), B(Y), C(Z);  
invec(A);
invec(B);
invec(C);

VI D;
rep(x, 0, X) rep(y, 0, Y)
    D.push_back(A[x] + B[y]);
sort(ALL(D), greater<i64>());

VI ans;
int m = min(K, X*Y);
rep(k, 0, m) rep(z, 0, Z)
    ans.push_back(D[k] + C[z]);
sort(ALL(ans), greater<i64>());

rep(i, 0, K)
    cout << ans[i] << "\n";

}
// 書いて考える．場合分け
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



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

#A
def A():
    return

#B
def B():
    n,X = LI()
    x = LI()
    for i in range(n-1):
        x[i+1] += x[i]
    x.insert(0,0)
    ans = float("inf")
    f = [5,5]
    for i in range(n):
        f.append(f[-1]+2)
    for k in range(1,n+1):
        i = 0
        a = n
        d = (k+n)*X
        while a > 0:
            d += f[i]*(x[a]-x[max(0,a-k)])
            a -= k
            i += 1
        ans = min(ans,d)
    print(ans)
#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


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

int main(){
  int n,m; cin >> n >> m;
  vector<P> vec;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    vec.push_back(P(a,1));
  }
  for(int i = 0; i < m; i++){
    int b, c; cin >> b >> c;
    vec.push_back(P(c,b));
  }
  sort(vec.begin(), vec.end());
  ll ans = 0;
  for(int i = 0; i < n; i++){
    P temp = vec[vec.size() - 1];
    vec.pop_back();
    ans += temp.first;
    temp.second--;
    if(temp.second > 0){
      vec.push_back(temp);
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long LL;

const int N = 2e3, M = 4e6, MOD = 1e9 + 7;

int n, k, f[N + 5][N + 5], fac[M + 5], ifac[M + 5];

inline void add(int &x, const int &y) {
	(x += y) >= MOD && (x -= MOD);
}
inline int pow(int x, int k) {
	int ans = 1;
	for (; k > 0; k >>= 1, x = (LL)x * x % MOD) {
		if (k & 1) {
			ans = (LL)ans * x % MOD;
		}
	}
	return ans;
}
inline int inv(int x) {
	return pow(x, MOD - 2);
}
void init(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; i++) {
		fac[i] = (LL)fac[i - 1] * i % MOD;
	}
	ifac[n] = inv(fac[n]);
	for (int i = n; i >= 1; i--) {
		ifac[i - 1] = (LL)ifac[i] * i % MOD;
	}
}
inline int binom(int n, int m) {
	return (LL)fac[n] * ifac[m] % MOD * ifac[n - m] % MOD;
}
int main() {
	scanf("%d%d", &n, &k);
	if (k == 1) {
		printf("1\n");
		return 0;
	}
	init(n * k);
	f[0][0] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n && j <= i; j++) {
			if (i < n) {
				add(f[i + 1][j], f[i][j]);
			}
			if (j < n) {
				add(f[i][j + 1], (LL)f[i][j] * (n - j) % MOD * binom(n * k - i - j * (k - 1) - 1, k - 2) % MOD);
			}
		}
	}
	printf("%d\n", f[n][n]);
	return 0;
}

Measured memory_bytes: 48680
import heapq
from collections import defaultdict

N = int(input())

graph = defaultdict(list)

for i in range(N - 1):
	a, b, w = list(map(int, input().split()))
	graph[a - 1].append([b - 1, w])
	graph[b - 1].append([a - 1, w])


dist_node = [float("inf") for i in range(N)]
ques, s = list(map(int, input().split()))
s = s - 1
dist_node[s] = 0


Q = []
heapq.heappush(Q, (dist_node[s], s)) 

while Q: 
	dis, v = heapq.heappop(Q)
	if dist_node[v] < dis:
		continue
	for u, w in graph[v]:
		alt = dis + w
		if dist_node[u] > alt:
			dist_node[u] = alt
			heapq.heappush(Q, (alt, u))


for i in range(ques):
	x, y = list(map(int, input().split()))
	print(dist_node[x - 1] + dist_node[y - 1])

Measured memory_bytes: 63764
#include <iostream>
#include <algorithm>

int main(int argc, char const* argv[])
{
	std::string str;
	std::cin >> str;
	bool d[0x80]{};
	for (auto c : str) {
		d[c] = true;
		if (d['N'] && d['S'] && d['E'] && d['W']) {
			std::cout << "Yes" << std::endl;
			return 0;
		}
	}
	auto n = d['N'];
	auto s = d['S'];
	auto e = d['E'];
	auto w = d['W'];
	if (n==s && e==w) {
		std::cout << "Yes" << std::endl;
	} else {
		std::cout << "No" << std::endl;
	}
	
	return 0;
}


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

int main(void)
{
    int X;
    cin >> X;

    if (X == 3 || X == 5 || X == 7)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int n, y, m, d, i, j;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) {
		int sum = 0;
		scanf("%d %d %d", &y, &m, &d);
		if (y % 3 && m % 2==0) sum += (20 - d);
		else sum += (21 - d);
		for (j = m + 1; j <= 10; ++j) {
			if (y % 3 && j % 2==0) sum += 19;
			else sum += 20;
		}
		for (j = y + 1; j < 1000; ++j) {
			if (j % 3) sum += 195;
			else sum += 200;
		}
		printf("%d\n", sum);
	}
	return 0;
}


Measured memory_bytes: 2696
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long M, long[] A) {
    string[long] nums;
    if (A.canFind(1)) nums[2] = "1";
    if (A.canFind(2)) nums[5] = "2";
    if (A.canFind(3)) nums[5] = "3";
    if (A.canFind(4)) nums[4] = "4";
    if (A.canFind(5)) nums[5] = "5";
    if (A.canFind(6)) nums[6] = "6";
    if (A.canFind(7)) nums[3] = "7";
    if (A.canFind(8)) nums[7] = "8";
    if (A.canFind(9)) nums[6] = "9";
    
    const NONE = "0";
    string[long] memo;
    string maxNumMadeOf(long matches) {
        if (matches in memo)
            return memo[matches];
        if (matches == 0)
            return "";
        if (matches < 0)
            return NONE;

        return memo[matches] = nums.byKeyValue
            .map!(t => t.value ~ maxNumMadeOf(matches - t.key))
            .filter!(s => !s.canFind(NONE))
            .chain([NONE])
            .reduce!maxStr;
    }

    return maxNumMadeOf(N);
}


pure string maxStr(string a, string b) {
    if (a.length != b.length)
        return a.length < b.length ? b : a;
    return max(a, b);
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long M;
    M = input.front.to!long;
    input.popFront;

    long[] A = new long[](cast(size_t) (M));
    foreach (i; 0 .. cast(size_t) (M)) {
        A[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, M, A);
    else
        solve(N, M, A).writeln;
}


Measured memory_bytes: 108668
#include<bits/stdc++.h>
using namespace std;
int main(){
    char s[100000];
    scanf("%s",s);
    for (int i=0;i<strlen(s)-2;i++) {
        if (s[i]==s[i+1] || s[i]==s[i+2] || s[i+1]==s[i+2]) {
            printf("%d %d\n",i+1,i+3);
            return 0;
        }
    }
    if (strlen(s)==2 && s[0]==s[1]) printf("1 2\n");
    else printf("-1 -1\n");
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<sstream>

using namespace std;

string itos(int n) {
	stringstream ss;
	ss << n;
	return ss.str();
}

int main() {
	int n, k,ans;
	cin >> n >> k;
	vector<char> D(k);
	for (int i = 0; i < k; i++)cin >> D[i];
	for (ans = n; ; ans++) {
		string ns = itos(ans);
		bool flag = true;
		for (int i = 0; i < k; i++) {
			if (find(ns.begin(), ns.end(), D[i]) != ns.end())flag = false;
		}
		if (flag)break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int N,M,X,Y,flag = 0,i,j,xmost = -100,ymin = 100;
    int xhaika[101],yhaika[101];
    
    scanf("%d %d %d %d",&N,&M,&X,&Y);

    for(i = 0; i < N; i++){
        scanf("%d",&xhaika[i]);
        if(xmost < xhaika[i]){
            xmost = xhaika[i];
        }
    }
    
    for(i = 0; i < M; i++){
        scanf("%d",&yhaika[i]);
        if(ymin > yhaika[i]){
            ymin = yhaika[i];
        }
    }
    
    for(i = 0;i < N; i++){
        if(flag == 1)break;
        for(j = 0; j < M; j++){
            if(xhaika[i] >= yhaika[j] || Y - X < 0 ){
                flag = 1;
                break;
            }
            if(xmost <= X || ymin >= Y){
                flag = 1;
                break;
            }
        }
    }
    
    if(flag == 0){
        printf("No War");
    }
    if(flag == 1){
        printf("War");
    }
    
    return 0;
}


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

int main(){
    string S;
    cin >> S;
    if(S[2] == S[3] && S[4] == S[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#B
HW = input().split(' ')
H = int(HW[0])
W = int(HW[1])
if H == 1 or W == 1:
    print(1)
elif H % 2 == 0 and W % 2 == 0:
    print(int((W / 2) * H))
elif H % 2 == 1 and W % 2 == 1:
    print(int(W * (H // 2) + W // 2 + 1))
elif H % 2 == 1 and W % 2 ==0:
    print(int((W / 2)* H))
else:
    print(int((H / 2)* W))

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

using namespace std;

int main()
{
    int n, b, f, r, v;
    int a1[3][10]={};
    int a2[3][10]={};
    int a3[3][10]={};
    int a4[3][10]={};

    scanf("%d", &n);
    for(int i = 0; i<n; i++)
    {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        switch(b)
        {
            case 1:
                a1[f-1][r-1] += v;
                if(a1[f-1][r-1] < 0) a1[f-1][r-1] = 0;
                if(a1[f-1][r-1] > 9) a1[f-1][r-1] = 9;
                break;
            case 2:
                a2[f-1][r-1] += v;
                if(a2[f-1][r-1] < 0) a2[f-1][r-1] = 0;
                if(a2[f-1][r-1] > 9) a2[f-1][r-1] = 9;
                break;
            case 3:
                a3[f-1][r-1] += v;
                if(a3[f-1][r-1] < 0) a3[f-1][r-1] = 0;
                if(a3[f-1][r-1] > 9) a3[f-1][r-1] = 9;
                break;
            case 4:
                a4[f-1][r-1] += v;
                if(a4[f-1][r-1] < 0) a4[f-1][r-1] = 0;
                if(a4[f-1][r-1] > 9) a4[f-1][r-1] = 9;
                break;
            default:
                ;
        }
    }

    for(int _f=0; _f < 3; _f++)
    {
        for(int _r=0; _r < 10; _r++)
        {
            printf(" %d", a1[_f][_r]);
        }
        printf("\n");
    }
    printf("####################\n");

    for(int _f=0; _f < 3; _f++)
    {
        for(int _r=0; _r < 10; _r++)
        {
            printf(" %d", a2[_f][_r]);
        }
        printf("\n");
    }
    printf("####################\n");

    for(int _f=0; _f < 3; _f++)
    {
        for(int _r=0; _r < 10; _r++)
        {
            printf(" %d", a3[_f][_r]);
        }
        printf("\n");
    }
    printf("####################\n");

    for(int _f=0; _f < 3; _f++)
    {
        for(int _r=0; _r < 10; _r++)
        {
            printf(" %d", a4[_f][_r]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 3196
#include <stdio.h>
int main(void){
  int a,b,c,d,i;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  for(i=0; i<100; i++){
    c = c-b;
    if(c <= 0){
      printf("Yes");
      break;
    }
    a = a-d;
    if(a <= 0){
      printf("No");
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1728
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(long.Parse).ToArray();

		long m = a.Min(), M = a.Max();
		var s = Math.Abs(m) <= Math.Abs(M) ? M : m;
		var x = Enumerable.Range(0, n).First(i => a[i] == s);
		var r = new List<string>();

		if (s > 0)
		{
			for (int i = 1; i < n; i++)
			{
				while (a[i - 1] > a[i])
				{
					a[i] += a[x];
					r.Add($"{x + 1} {i + 1}");
				}

				if (a[i] > a[x]) x = i;
			}
		}
		if (s < 0)
		{
			for (int i = n - 2; i >= 0; i--)
			{
				while (a[i] > a[i + 1])
				{
					a[i] += a[x];
					r.Add($"{x + 1} {i + 1}");
				}

				if (a[i] < a[x]) x = i;
			}
		}

		Console.WriteLine(r.Count);
		Console.WriteLine(string.Join("\n", r));
	}
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef int32_t i32;
typedef vector<bool> vbool;
typedef vector<string> vstr;
typedef vector<long long> vll;
typedef vector<pair<ll,ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<pair<ll,ll>>> vvpll;
typedef list<long long> lll;
typedef pair<ll,ll> pll;

#define senor_SR ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
#define mp make_pair
#define fff first
#define sss second
#define sz(v) v.size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>=b;i--)
#define FILL(a,b,c) for(ll i=0;i<c;i++) a[i]=b;

#define all(a) a.begin(),a.end()
#define allr(v) v.rbegin(),v.rend()
 
#define setpri(x) setprecision(x)
#define pv(x) cout<<#x<<" : "<< (x)<<" | "
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define farr(a,n) for(long long i=0;i<n;i++) cin>>a[i];
#define fvec(vec,n) for(long long i=0;i<n;i++) { tmp;cin>>tmp;vec.pb(tmp);}
#define parr(a) for(long long i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define pvec(vec) for(long long i=0;i<vec.size();i++) cout<<vec[i]<<" "; cout<<endl;
#define prvec(v) for(long long i=v.size()-1;i>=0;i--) cout<<v[i]<<" "; cout<<endl;
#define pvecpair(v) for(long long i=0;i<v.size();i++) cout<<v[i].first<<" "<<v[i].second<<endl;
 
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define MAX_INT 100000
#define MOD 1000000007

const int N = 100000+5;
 
int main()
{
	senor_SR;
	
	int n;cin>>n;
	
	int a[n],b[n];
	farr(a,n);farr(b,n);
	
	ll fac[n+1];
	fac[0]=1;
	FOR(i,1,n+1)
		fac[i]=fac[i-1]*i;
	
	ll a1[n];
	a1[0]=a[0]-1;
	FOR(i,1,n)
	{
		int cnt=a[i]-1;
		for(int j=i-1;j>=0;j--)
			if(a[j]<a[i])
				cnt--;
		a1[i]=cnt;
	}
	ll b1[n];
	b1[0]=b[0]-1;
	FOR(i,1,n)
	{
		int cnt=b[i]-1;
		for(int j=i-1;j>=0;j--)
			if(b[j]<b[i])
				cnt--;
		b1[i]=cnt;
	}
		
	//parr(a1);parr(b1);
	ll ans=0;
	FOR(i,0,n)
	{
		ans+=(a1[i]-b1[i])*fac[n-i-1];	
	}
	cout<<abs(ans);
	
    return 0;   
    
}

Measured memory_bytes: 256
"""
二部探索的なのをやるのな
"""
N = int(input())
sex = {"Male":0, "Female":1}
print(0)
s = input()
init = sex[s]

"""
0 1 2 3 4 5 0
F M   M     F

"""

def f(x):
    print(x)
    s = input()
    ind = sex[s]
    # 
    if x%2 == (ind+init)%2:
        return False
    else:
        return True 

r = N
l = 0
while r - l > 1:
    mid  = (r + l) // 2
    if f(mid):
        r = mid
    else:
        l = mid
    
    

Measured memory_bytes: 3660
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
const long double EPS = 1e-9;
 
#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c)
#define rsort(a,n) sort(a,a+n,greater<>())
 
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100;
 
int main(void){
    ll a,b,c;
    ll answer = 0;
    
    in2(a,b);
    if (b < 10) c = a * 10 + b;
    else if (b < 100) c = a * 100 + b;
    else c = a * 1000 + b;
    
    rep(i,1000) if (i * i == c) {prl("Yes");return 0;}

    prl("No");
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define int long long
using namespace std;
signed main() {
    string s;
    cin >> s;
    bool flag = true;
    if(s.size()%2!=0){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i = 0; i < s.size() / 2; i += 2) {
        if(s[i] != 'h' || s[i + 1] != 'i') flag = false;
    }
    if(flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
C = list(map(int, input().split()))
query = []

for i in range(Q):
  l, r = map(int, input().split())
  query.append((i, l, r))

query.sort(key = lambda x: x[2])

class BIT:
  from operator import add, sub
  X_unit = 0
  X_f = add
  X_f_rev = sub

  def __init__(self, seq):
    N = len(seq)
    self.N = N
    self.X = seq[:]
    for i in range(self.N):
      j = i + ((i+1) & -(i+1))
      if j < self.N:
        self.X[j] = self.X_f(self.X[i], self.X[j])
  
  def set_val(self, i, x):
    while(i < self.N):
      self.X[i] = self.X_f(self.X[i], x)
      i += (i+1) & -(i+1)

  def cum_val(self, i):
    res = self.X_unit
    while(i > -1):
      res = self.X_f(res, self.X[i])
      i -= (i+1) & -(i+1)
    return res

  def fold(self, L, R):
    return self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1))

GJ = [-1]*N
bit = BIT([0]*N)
ans = [0]*Q
st = 0

for i in range(N):
  if GJ[C[i]-1] != -1:
    bit.set_val(GJ[C[i]-1], -1)
  GJ[C[i]-1] = i
  bit.set_val(i, 1)
  if st < Q:
    while query[st][2] == i+1:
      ans[query[st][0]] = bit.fold(query[st][1]-1, query[st][2])
      st += 1
      if st == Q:
        break

print(*ans, sep="\n")

Measured memory_bytes: 232836
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
ll s,w;
cin>>s>>w;
if(w>=s)
    cout<<"unsafe";
else
    cout<<"safe";
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	int n;
	cin >> n;
	int a[n], b[n];
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (ll i = 0; i < n; i++) {
		cin >> b[i];
	}
	
	reverse(b, b + n);
	
	ll lpt = 0, rpt = n - 1;
	
	for (ll i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			if (b[lpt] != b[i] && a[lpt] != b[i]) {
				swap(b[i], b[lpt]);
				++lpt;
			} else if (b[rpt] != b[i] && a[rpt] != b[i]) {
				swap(b[i], b[rpt]);
				--rpt;
			} else {
				cout << "No\n";
				return;
			}
		}
	}
	
	for (ll i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			cout << "No\n";
			return;
		}
	}
	
	cout << "Yes\n";
	for (ll i = 0; i < n; i++) {
		cout << b[i] << " ";
	}
	cout << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cout << fixed << setprecision(10);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


Measured memory_bytes: 5156
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
p = [int(i) for i in input().split()]
par = [-1]*n
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

def same(x,y):
    return find(x) == find(y)
  
for i in range(m):
  x,y = [int(i) for i in input().split()]
  unite(x-1,y-1)
  
ans = 0
for i,pi in enumerate(p):
  if pi == i+1:
    ans += 1
  else:
    if same(pi-1,i):
      ans += 1
      
print(ans) 

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

int main(void){
    char alpha;
    cin >> alpha;
    for(char a = 'a' ; a <= 'z' ; a++){
        if(a == alpha){
            cout << 'a' << endl;
            return 0; 
        } 
    }
    cout << 'A' << endl;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main() {
  long long x;
  cin >> x;

  while(1){
    bool can = true;
    for(int i = 2; i < x; i++){
      if(x % i == 0){
        can = false;
        break;
      }
    }

    if(can){
      cout << x << endl;
      return 0;
    }
    else{
      x++;
    }
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
i64 INF = 1e12;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 k;
    cin >> k;
    string st;
    cin >> st;

    if (st.size() <= k) {
        cout << st;
        return 0;
    }
    string s2 = st.substr(0,k);
    cout << s2 << "..." << endl;

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

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

	vector<int32_t> x(N), y(N), h(N);
	int32_t positive_height_index = -1;
	for (int32_t i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] > 0)
			positive_height_index = i;
	}

	for (int32_t cx = 0; cx <= 100; cx++) {
		for (int32_t cy = 0; cy <= 100; cy++) {
			bool matched = true;
			int32_t H = h[positive_height_index] + abs(x[positive_height_index] - cx) + abs(y[positive_height_index] - cy);
			for (int32_t i = 0; i < N; i++) {
				int32_t value = max(H - abs(x[i] - cx) - abs(y[i] - cy), 0);
				if (value != h[i]) {
					matched = false;
					break;
				}
			}
			if (matched) {
				cout << cx << " " << cy << " " << H << endl;
				return 0;
			}
		}
	}

	return 0;
}


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

int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if (H == 0 && W == 0)break;
        for ( int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (i == 0 || j == 0 || i == H-1 || j == W-1){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
        cout << endl;
        }
    cout << endl;
    }
return 0;
}
    


Measured memory_bytes: 3076
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int M,T,P,R,m[2010],t[2010],p[2010],J[2010];

void main2(){
	int solved[55]={},penal[55]={},failed[55][11]={};
	rep(i,R){
		if(J[i]==0){
			solved[t[i]]++;
			penal[t[i]]+=m[i]+failed[t[i]][p[i]]*20;
		}else{
			failed[t[i]][p[i]]++;
		}
	}
	pair<pi,int> team[55];
	rep2(i,1,T+1){
		team[i] = mp(mp(-solved[i],penal[i]),-i);
	}
	sort(team+1,team+T+1);
	rep2(i,1,T+1){
		cout<<-team[i].sec;
		if(i==T)cout<<endl;
		else cout<<(team[i].fir == team[i+1].fir ? "=":",");
	}
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>M>>T>>P>>R && M){
		rep(i,R)cin>>m[i]>>t[i]>>p[i]>>J[i];
		main2();
	}
}

Measured memory_bytes: 1236
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while(sc.hasNext()){
			P p1=new P(sc.nextDouble(),sc.nextDouble());
			P p2=new P(sc.nextDouble(),sc.nextDouble());
			P p3=new P(sc.nextDouble(),sc.nextDouble());
			P p4=new P(sc.nextDouble(),sc.nextDouble());

			ln(P.isVertical(p1, p2, p3, p4)?"YES":"NO");
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}
class P{
	double x;
	double y;
	P(double _x,double _y){
		x=_x;
		y=_y;
	}

	public static double dot(P a,P b){
			return a.x*b.x+a.y*b.y;
	}

	public static boolean isVertical(P a1,P a2,P b1,P b2){
		return Math.abs(dot(a2.s(a1),b2.s(b1)))<Double.MIN_NORMAL;
	}
	public P a(P a){
		return new P(x+a.x,y+a.y);
	}
	public P s(P a){
		return new P(x-a.x,y-a.y);
	}
}

Measured memory_bytes: 12000
s=input()
if s=="MON":
  print(6)
elif s=="TUE":
  print(5)
elif s=="WED":
  print(4)
elif s=="THU":
  print(3)
elif s=="FRI":
  print(2)
elif s=="SAT":
  print(1)
else:
  print(7)

Measured memory_bytes: 2940