akhauriyash/Code-Regression huggingface dataset:
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n,m,v,p;
    cin>>n>>m>>v>>p;
    vector<ll>a(n);
    for(ll i=0;i<n;i++)
        cin>>a[i];
    sort(all(a));
    ll s[100001];
    memset(s, 0, sizeof(s));
    s[0]=a[0];
    for(ll i=1;i<n;i++)
        s[i]=s[i-1]+a[i];
    ll ans=p;
    ll hisen=a[n-p];
    auto itn=lower_bound(a.begin(), a.begin()+n-p+1, hisen-m);
    ll X=itn-a.begin();
    for(ll i=X;i<n-p;i++){
                //m=m v=v-1
                ll test=a[i]+m;
                ll vs=v-1-i;
                //ll weizhi=n-p;
                //while(a[weizhi]==a[weizhi-1])
                    //weizhi--;
                vs-=p-1;
            if(vs<=0){
                ans+=n-p-i;
                break;
            }
            //cout<<vs<<endl;
            ll nokori=vs*m;
        
            //for(ll j=i+1;j<=n-p;j++){
               // cout<<test<<" "<<a[i]<<" "<<nokori<<endl;
               // nokori-=min(m,test-a[j]);
                //cout<<nokori<<endl;
           // }
        ll sum=s[n-p]-s[i];
        if(sum+nokori<=test*(n-p-i)){
            ans+=n-p-i;
            break;
        }
            //auto itn2=lower_bound(a.begin()+1+i, a.begin()+n-p, )
            //cout<<i<<" "<<nokori<<endl;
            
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 1792
#include<stdio.h>

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

    int ansI = a / b;
    int rem = a % b;
    double ansF = (double)((double)a / (double)b);
    printf("%d %d %f\n", ansI, rem, ansF);
}


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

N = int(input())
deck = list(map(int, input().split()))
Alice = 0
Bob = 0

for i in range(len(deck)):
    if i % 2 == 0:
        Alice += deck.pop(deck.index(max(deck)))
    else:
        Bob += deck.pop(deck.index(max(deck)))

print(Alice - Bob)



Measured memory_bytes: 2940
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 210;
int N;
int L;
int aji[Max];

int main(int argc, const char * argv[]) {
    cin >> N >> L;

    int all = 0;
    int absmin = 1000000;
    int absminidx = 0;

    rep(i, N) {
        aji[i] = L + i;
        all += aji[i];
        if (chmin(absmin, abs(aji[i]))) {
            absminidx = i;
        }
    }

    output(all - aji[absminidx]);
    return 0;
}

Measured memory_bytes: 256
#ifndef ___Geometry_Library
#define ___Geometry_Library

// ------ Includes ------ //
#include <cmath>
#include <complex>
#include <utility>
#include <algorithm>

// ------ Defines ------ //
typedef long double GType;
typedef std::complex<GType> Point;
typedef std::pair<Point, Point> Segment;

// ------ Constants ------ //
const GType EPS = 1.0e-10L;

// ------ Functions Level 1 ------ //
GType dot(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).real();
}
GType cross(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).imag();
}

#endif

#include <iostream>
using namespace std;
int q, xa, ya, xb, yb; Point v1, v2;
int main() {
	cin >> q;
	while (q--) {
		cin >> xa >> ya >> xb >> yb; v1 = Point(xb, yb) - Point(xa, ya);
		cin >> xa >> ya >> xb >> yb; v2 = Point(xb, yb) - Point(xa, ya);
		if (abs(cross(v1, v2)) < EPS) cout << 2 << endl;
		else if (abs(dot(v1, v2)) < EPS) cout << 1 << endl;
		else cout << 0 << endl;
	}
	return 0;
}

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

using namespace std;

int main(int, char**)
{
	int n;
	double ans = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		double x;
		string t;
		cin >> x >> t;
		if (t == "JPY")
			ans += x;
		else
			ans += x * 380000.0;

	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
																																																																																																																																																																																																																																																																																																																											
using namespace std;

namespace {
	const int N = (int) 1e5;
	vector <int> g[N];
}

template <typename T>
T abcd(int a, int b, int c, int d) {
	return a + b + c + d;
}

void fail() {
	cout << "NO\n";
	exit(0);
}

void suc() {
	cout << "YES\n";
	exit(0);
}

void solve() {
	int n;
	cin >> n;
	vector <int> a(n), diff(n);
	long long s = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}

	for (int i = 0; i < n; i++) {
		diff[i] = (a[(i + 1) % n] - a[i]); 
	}
	long long each = n * 1LL * (n + 1) / 2;
	if (s % each != 0) {
		fail();
	}
	s /= each;
	long long x = 0;
	for (int i = 0; i < n; i++) {
		long long cr = s - diff[i];
		if (cr < 0 || cr % n != 0) {
			fail();
		}
		x += cr / n;
	}
	if (x == s) {
		suc();
	} else {
		fail();
	}
}

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


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    int x, n; cin >> x >> n;
    vi v(n);
    map<int, bool> m;
    forn(n) { 
        cin >> v[i];
        m[v[i]] = true;
    }
    int k1 = 0, k2 = 0;
    int cnt1 = 0;
    int cnt2 = 0;
    for(int i = x; i >= -1; i--) {
        cnt1++;
        if(m[i] == false) {
            k1 = i;
            break;
        }
    }
    for(int i = x; i <= 101; i++) {
        cnt2++;
        if(m[i] == false) {
            k2 = i;
            break;
        }
    }
    if(cnt1 <= cnt2) {
        cout << k1;
    }
    else {
        cout << k2;
    }

    return 0;
}

Measured memory_bytes: 3664
#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;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    ll h,w;cin>>h >> w;
    if(h==1 || w ==1) {cout <<1 << endl;return 0;}
    else{
    if(h*w % 2 ) {cout << (h*w + 1) / 2 << endl;return 0;}//奇数の時//floor(h*w/2.0) +1 は15桁の巨大な数+1となって桁おちするからダメ
    else {cout << h*w/2 << endl;return 0; }//偶数の時
}
    /*ll count = 0;
    REP(i,h){
        REP(j,w){
                if((i+j)%2==0){
                    count++;
                }
        }
    }
    cout << count<<endl;
  */
}

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

using namespace std;

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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int kLoop = -1;
const int kYet = -2;

int main(void){
    for(int n; cin >> n;){
        vi p(n);
        rep(i, n){
            cin >> p[i];
        }

        vi to(n, kYet);
        rep(i, n){
            if(to[i] != kYet) continue;
            
            int pos = i, to_pos = kLoop;
            set<int> s;

            while(to[pos] != kLoop && s.insert(pos).second){
                if(p[pos] == 0){
                    to_pos = pos;
                    break;
                }
                pos += p[pos];
            }

            each(itr, s) to[*itr] = to_pos;
        }

        vi numTurn(n, inf);
        numTurn[0] = 0;
        bool end = false;

        while(!end){
            end = true;

            rep(i, n){
                if(numTurn[i] == kYet) continue;

                range(j, 1, 7){
                    int next_pos = to[min(n - 1, i + j)];

                    if(next_pos != kLoop && numTurn[i] + 1 < numTurn[next_pos]){
                        numTurn[next_pos] = numTurn[i] + 1;
                        end = false;
                    }
                }
            }
        }

        cout << numTurn[n - 1] << endl;
    }

	return 0;
}

Measured memory_bytes: 5756
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

fn main() {
    let (n,c) = {
        let xs = read_vec_i64();
        (xs[0] as usize, xs[1] as usize)
    };
    let ds = {
        let mut xs = vec![];
        for _ in 0..c {
            let ys = read_vec_i64();
            xs.push(ys);
        }
        xs
    };
    let xs = {
        let mut xs = vec![];
        for _ in 0..n {
            let ys = read_vec_i64();
            xs.push(ys);
        }
        xs
    };
    let mut count = [[0; 51]; 3];
    for y in 0..n {
        for x in 0..n {
            count[(x+y)%3][xs[y][x] as usize] += 1;
        }
    }
    let mut point = [[0; 51]; 3];
    for i in 0..3 {
        for j in 1..c+1 {
            let mut t = 0;
            for k in 1..c+1 {
                t += ds[k-1][j-1] * count[i][k];
            }
            point[i][j] = t;
        }
    }
    let mut res = 1i64 << 50;
    for i in 1..c+1 {
        for j in 1..c+1 {
            for k in 1..c+1 {
                if i == j { continue; }
                if j == k { continue; }
                if k == i { continue; }
                let t = point[0][i] + point[1][j] + point[2][k];
                res = min(res, t);
            }
        }
    }
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 6396
N=parse(Int,readline())
T=map(x->2parse(Int,x),split(readline()))
V=map(x->2parse(Int,x),split(readline()))
z=zeros(Int,10^5)
j=0
for v=V
	z[j+1]=min(z[j+1],v)
	u=shift!(T)
	for k=j+1:j+u
		z[k+1]=min(z[k]+1,v)
	end
	j+=u
end
s=m=0
for k=1:j
	s+=m=min(m+1,z[j-k+1])
end
println(s/4)


Measured memory_bytes: 119124
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

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

Measured memory_bytes: 256
N = int(input())
A_list = list(map(int, input().split()))

result = [0] * N
for i in range(N):
    if A_list[N - i - 1] == 1 and (N - i) * 2 > N:
        result[N - i - 1] = 1
    if A_list[N - i - 1] == 0 and (N - i) * 2 > N:
        result[N - i - 1] = 0
    if A_list[N - i - 1] == 1 and (N - i) * 2 <= N:
        tmp_sum = 0
        for r in range(N - i - 1, N, N - i):
            tmp_sum += result[r]
        if tmp_sum % 2 == 0:
            result[N - i - 1] = 1
        if tmp_sum % 2 == 1:
            result[N - i - 1] = 0
    if A_list[N - i - 1] == 0 and (N - i) * 2 <= N:
        tmp_sum = 0
        for r in range(N - i - 1, N, N - i):
            tmp_sum += result[r]
        if tmp_sum % 2 == 0:
            result[N - i - 1] = 0
        if tmp_sum % 2 == 1:
            result[N - i - 1] = 1

print(sum(result))
for i, r in enumerate(result):
    if r == 1:
        print(i + 1)

Measured memory_bytes: 7100
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    char c;
    cin >> c;
    if('A' <= c && c <= 'Z') cout << "A" << endl;
    else cout << "a" << endl;
    
    

    return 0;
}


Measured memory_bytes: 3656
#define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

const int MOD = 1000000007;

vector<ll> factorials;
void init_factorial(int N)
{
    factorials.assign(N+1, 1);
    rep(i, 2, N+1)
    {
        factorials[i] = factorials[i-1] *i;
        factorials[i] %= MOD;
    }
}

ll power_mod(ll n, ll m)
{
    ll res = 1;
    ll base = n;
    while (m > 0)
    {
        if (m&1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        m >>= 1;
    }
    return res;
}

ll inv_mod(ll n)
{
    return power_mod(n, MOD-2);
}

ll comb(ll n, ll m)
{
    if (m>n) return 0;
    m = min(m, n-m);
    ll res = factorials[n];
    res *= inv_mod(factorials[n-m]);
    res %= MOD;
    res *= inv_mod(factorials[m]);
    res %= MOD;
    return res;
}

int main()
{
    init_factorial(100005);
    int N, K;
    cin >> N >> K;
    vector<int> values(N);
    rep(i, 0, N) cin >> values[i];

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

    ll sum_max, sum_min;
    sum_max = sum_min = 0;
    rep(i, 0, N)
    {
        debug(i, comb(i, K-1));
        sum_max += (comb(i, K-1)*values[i])%MOD;
        sum_max %= MOD;
        sum_min += (comb(N-i-1, K-1)*values[i])%MOD;
        sum_min %= MOD;
    }
    ll ans = sum_max-sum_min;
    ans %= MOD;
    if (ans<0) ans += MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target ("avx")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int calcScore(vector<int> &plan, vector<int> &c, vector<vector<int>> &s) {
	int D = 365;
	int score = 0;
	vector<int> last(26, 0);
	for (int i = 0; i < D; i++) {
		score += s[i][plan[i]];
		last[plan[i]] = i;
		for (int j = 0; j < 26; j++) {
			score -= c[j] * (i - last[j]);
		}
	}
	return score;
}

int main() {
	int D;
	cin >> D;
	vector<int> c(26);
	for (int i = 0; i < 26; i++)cin >> c[i];
	vector<vector<int>> s(365,vector<int>(26,0));
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++)cin >> s[i][j];
	}
	
	vector<int> plan(365, 0);
	for (int i = 0; i < 365; i++)plan[i] = rand() % 26;
	int sc = calcScore(plan, c, s);

	for (int n = 0; n < 10000; n++) {
		int i = rand() % 365, j = rand() % 26, old = plan[i];
		plan[i] = j;
		int nsc = calcScore(plan, c, s);
		if (nsc > sc) {
			sc = nsc;
		}
		else {
			plan[i] = old;
		}
	}

	for (int i = 0; i < 365; i++) {
		cout << plan[i] + 1 << endl;
	}
}

Measured memory_bytes: 3672
c = [list(map(int, input().split())) for _ in range(3)]

ans = "Yes"
cnt = {i: [] for i in range(6)}
for i in range(3):
    for j in range(3):
        cnt[i].append(c[i][j] - c[(i + 1) % 3][j])
        cnt[i + 3].append(c[j][i] - c[j][(i + 1) % 3])
for ls in cnt.values():
    if min(ls) < max(ls):
        ans = "No"

print(ans)

Measured memory_bytes: 38384
import java.util.Map.Entry;
import java.util.*;

import org.w3c.dom.css.Counter;

public class Main {
//public class App {

    public static void main(String[] args){
     //スキャン
     Scanner s = new Scanner(System.in);
     // 入力
        long n = s.nextInt();
        long an = 0;
    for(long i = 1 ;i<=n;i++){

        if(i % 3 != 0  && i%5 !=0){
        an += i;
        }
        
    }
    System.out.println(an);
}

}

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

bool check(int i, int j, vector<int> v){
       int a = v[i];
       int b = v[i+1];
       int c = v[j];
       if( (a <= b && b <= c)  || (a >= b && b >= c))
          return true;
          
return false;
}
int main() {
int n; cin >> n;
vector<int> v(n);
for(int i =0; i < n; i++){
       cin >> v[i];
}
int cnt  =0;
int i = 0;
int j = i+2;
while(i < n-2 && j < n){
       if(check(i,j, v)) cnt++;
       i++;
       j++;
}

cout << cnt;

return 0;

}









  

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

int main() {
	long long int n,m,a,b;
	cin>>n>>m;
	int cnt=0;
	for (int i=0;i<n;i++){
		cin>>a>>b;
		long long int r=(a*a)+(b*b);
		//cout<<r<<endl;
		long double d=sqrt(r);
		//cout<<d<<endl;
		if (d<=m){
			cnt++;
		}
	}
	cout<<cnt;
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> vec(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  vector<int> tate(H, 0);
  vector<int> yoko(W, 0);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (vec.at(i).at(j) == '#')
        tate.at(i) = 1;
    }
  }
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {
      if (vec.at(j).at(i) == '#')
        yoko.at(i) = 1;
    }
  }
  for (int i = 0; i < H; i++) {
    if (tate.at(i) == 1) {
      for (int j = 0; j < W; j++) {
        if (yoko.at(j) == 1)
          cout << vec.at(i).at(j);
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, A, B, C): (usize, i64, i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };
    let l: Vec<i64> = (0..N)
        .map(|_| {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse().unwrap()
        })
        .collect();
    static INF: i64 = 1_000_000_000_000;

    fn f(i: usize, x: &Vec<i64>, c: &Vec<i64>, N: usize, X: &Vec<i64>, l: &Vec<i64>) -> i64 {
        if i == N && c.iter().all(|&a| a >= 1) {
            (0..3)
                .map(|i| (X[i] - x[i]).abs() + 10 * (c[i] - 1))
                .sum::<i64>()
        } else if i == N && c.iter().any(|&a| a == 0) {
            INF
        } else {
            *vec![
                f(
                    i + 1,
                    &vec![x[0] + l[i], x[1], x[2]],
                    &vec![c[0] + 1, c[1], c[2]],
                    N,
                    X,
                    l,
                ),
                f(
                    i + 1,
                    &vec![x[0], x[1] + l[i], x[2]],
                    &vec![c[0], c[1] + 1, c[2]],
                    N,
                    X,
                    l,
                ),
                f(
                    i + 1,
                    &vec![x[0], x[1], x[2] + l[i]],
                    &vec![c[0], c[1], c[2] + 1],
                    N,
                    X,
                    l,
                ),
                f(i + 1, x, c, N, X, l),
            ]
            .iter()
            .min()
            .unwrap()
        }
    }
    let ans = f(0, &vec![0, 0, 0], &vec![0, 0, 0], N, &vec![A, B, C], &l);

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


Measured memory_bytes: 4476
using System;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = int.Parse(_[0]);
            var m = int.Parse(_[1]);
            var x = int.Parse(_[2]);
            var a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

            var c1 = a.Where(i => i < x).Count();
            var c2 = a.Where(i => i > x).Count();

            Console.WriteLine(Math.Min(c1,c2));
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  vll num(100002, 0);
  ll t, n;std::cin >> n;
  re(i, n){
    std::cin >> t;
    num[t]++;num[t+1]++;
    if(t!=0) num[t-1]++;
  }
  ll ans = 0;
  re(i, 100002) ans = max(ans, num[i]);
  std::cout << ans << '\n';
}


Measured memory_bytes: 1024
from collections import Counter

N=int(input())
A=list(map(int,input().split()))
d=dict(Counter(A))
for num in d:
  if d[num]>=3:
    if d[num] %2==0:
      d[num]=2
    else:
      d[num]=1     
#print(d)

niko=0
ikko=0
for i in d:
  if d[i]==2:
    niko +=1
  else:
    ikko +=1
#print(niko,ikko)

ikko += niko
niko = niko%2
#print(niko,ikko)

if niko==0:
  print(ikko)
else:
  print(ikko-1)

Measured memory_bytes: 21724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char c = sc.next().charAt(0);
        switch(c) {
        case 'a':
        case 'i':
        case 'u':
        case 'e':
        case 'o':
            System.out.println("vowel");
            break;
        default:
            System.out.println("consonant");
            break;
        }
    }
}

Measured memory_bytes: 35576
#include<iostream>
using namespace std;
int ball[10];
int flag;  //1??????YES???0??????NO
void dfs(int left,int right,int depth){
  if(depth==10){ //???????????????????????§??\???????????????
    flag=1;
    return;
  }
  if(left<ball[depth])
    dfs(ball[depth],right,depth+1);
  if(right<ball[depth])
    dfs(left,ball[depth],depth+1);
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    flag=0;//????????°????????????
    for(int j=0;j<10;j++)
      cin>>ball[j];
    dfs(ball[0],0,1);//????????????????????\??????????????????
                     //3??????????????°?????±???
                     //?????????????????\?????????????????\???????????????????????§
                     //????????\?????????????????????????????????
    if(flag)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>          
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)	make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long MOD = 1000000007;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

vector<pii> c;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,t;
	cin >> n >> t;
	c.resize(n);
	int minv = INF;
	bool flg = true;
	rep(i,n){
		cin >> c[i].first >> c[i].second;
	}
	rep(i,n){
		if(c[i].second <= t){
			minv = min(minv,c[i].first);
			flg = false;
		}
	}
	if(flg) cout << "TLE\n";
	else cout << minv << '\n';
	return 0;
}


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

#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<typename T = ll>
vector<T> ga(ll n, bool oneIndexed = false) {
    vector<T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

template<typename T, typename A>
void pa(vector<T, A> const &a, ll begin = 0, ll end = -1) {
    if (end == -1)
        end = sz(a) - 1;
    for (ll i = begin; i <= end; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
}

set<ll> factors(ll n) {
    set<ll> ff;
    for (ll i = 1, s = sqrt(n); i <= s; i++) {
        if (n % i == 0) {
            ff.insert(i);
            if (i * i != n)ff.insert(n / i);
        }
    }
    return ff;
}

void solve() {
    ll n;
    cin >> n;

    set<ll> f1 = factors(n);
    set<ll> f2 = factors(n - 1);

    ll c = 0;
    for (auto f : f2) {
        if (f == 1) continue;
        if (f1.find(f) == f1.end()) {
            c++;
        }
    }

    for (auto f : f1) {
        if (f == 1) continue;
        ll on = n;
        while (on % f == 0) {
            on /= f;
        }
        if (on % f == 1) {
            c++;
        }
    }
    cout << c;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // ll t;cin >> t;while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <numeric>
#include <map>
#define REP(i, N) for(int i=0; i<N; i++)
using namespace std;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	int N;

	cin >> N;
  vector<int> A(N);
  multiset<int> num;
  
  for (auto& i : A) {
    cin >> i;
  }
  
  num.insert(*A.begin());
  int r = 1;

  
  for (auto it = A.begin() + 1; it != A.end(); ++it) {
    auto nit = num.lower_bound(*it);
    if (nit != num.begin()) {
      --nit;
      num.erase(nit);
    }
    num.insert(*it);
  }
  
  cout << num.size() << endl;

	return 0;
}


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

double stddev(std::vector<double> s){
    double m = 0;
    double v = 0;
    for(const double x : s){
        m += x / s.size();
        v += x * x / s.size();
    }
    return std::sqrt(v-m*m);
}

int main(){
    int n = 0;
    std::vector<double> s;
    double tmp = 0;
    while(std::cin >> n){
        if(n==0) break;
        while(n--){
            std::cin >> tmp;
            s.push_back(tmp);
        }
        std::cout << stddev(s) << std::endl;
        s.clear();
    }
    
}


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



void init();
void work();
int ca=1;
int main(){
//    freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
//    init();
//    int T;cin>>T;
//    while(T--)
    work();
    return 0;
}
void work(){
    int K,A,B;cin>>K>>A>>B;
    int t=A/K*K;
    if(t>=A||t+K<=B) cout<<"OK\n";
    else cout<<"NG";
}


Measured memory_bytes: 3652
n, m = map(int, input().split())
if m<n-1 or n+1<m:
    print(0)
    exit()
MOD = 10**9+7

ans = 1
for i in range(2, n+1):
    ans = (ans * i)%MOD
for i in range(2, m+1):
    ans = (ans * i)%MOD
if n == m:
    ans = (ans * 2)%MOD
print(ans)

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


typedef pair<int, int> pi;
typedef long long ll;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define sq(i) (a)*(a)



int main()
{

	ios_base::sync_with_stdio(0);	
	cin.tie(0);			
	cout.tie(0);	
	
	int n; cin >> n;
	int orig = 1000;
	
	while(orig < n)
	{
		orig += 1000;

		
		
		}
	int res = orig - n;
	cout << res;
}




Measured memory_bytes: 3676
// https://atcoder.jp/contests/

#include <iostream>
#include <set>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int a, b, c;
  set<int> s;

  cin >> a >> b >> c;

  s.insert(a);
  s.insert(b);
  s.insert(c);

  cout << s.size() << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100
void BubbleSort(int B[],int min,int max);
int main(void){
	int n,m,i,j,z,A[N],B[N],C[1000],tmp,max=0,min=40,cnt=0;
	char s[N],str[N],*line;

	for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
		line=strtok(str," ,");
		sscanf(line,"%d",&m);	
		line=strtok(NULL," ,");	
		sscanf(line,"%d",&n);
		if(m==0 && n==0)
			break;
		A[m]=n;
		B[m]=n;
		if(m>max)
			max=m;
		if(min>m)
			min=m;
		cnt++;
	}
	BubbleSort(B,min,max);
	j=0; B[cnt+1]=40;
	for(i=min;i<=cnt;i++){
		if(B[i]!=B[i+1])
			C[B[i]]=j++;
		else
			C[B[i]]=j;
	}
	for( ;fgets(s,sizeof(str),stdin)!=NULL; ){
		sscanf(s,"%d",&z);	
		printf("%d\n",C[A[z]]+1);
	}
	return 0;
}

void BubbleSort(int B[],int min,int max){
	int i,j,tmp;
	for(i=min;i<=max;i++){
		for(j=max;j>i;j--){	
			if(B[j] > B[j-1]){
				tmp = B[j-1];
				B[j-1] = B[j];
				B[j] = tmp;
			}
		}
	}
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((abs(a-b) <= d and abs(b-c) <= d) or  abs(a-c) <= d) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int n,x;
	cin >> n >> x;
	int ans=0;
	int mi=10000;
	rep(i,n) {
		int a; cin >> a;
		ans++;
		x-=a;
		mi=min(mi,a);
	}
	ans+=(x/mi);
	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B;
  cin>>A>>B;
  if(A==1&&B==2)cout<<3<<endl;
  else if(A==1&&B==3) cout<<2<<endl;
  else if(A==2&&B==3) cout<<1<<endl;
  else if(A==2&&B==1) cout<<3<<endl;
  else  if(A==3&&B==2)cout<<1<<endl;
  else if(A==3&&B==1) cout<<2<<endl;
}
  

Measured memory_bytes: 256
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int H, W;
    cin >> H >> W;
    vector<string> s(H + 2);

    REP(i, 2) {
        REP(j, W + 2) {
            s[0] += '.';
            s[H + 1] += '.';
        }
    }

    REP(i, H) {
        string sss;
        cin >> sss;

        s[i + 1] = '.' + sss + '.';
    }

    REP(i, H) {
        REP(j, W) {
            if (s[i + 1][j + 1] == '.') {
                continue;
            }
            int count = 0;

            if (s[i + 1 - 1][j + 1] == '#') {
                count++;
            }

            if (s[i + 1][j + 1 - 1] == '#') {
                count++;
            }
            if (s[i + 1 + 1][j + 1] == '#') {
                count++;
            }
            if (s[i + 1][j + 1 + 1] == '#') {
                count++;
            }
            debug(i, j);
            if (count == 0) {
                cout << "No";

                return;
            }
        }
    }

    cout << "Yes";
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0; i<n; i++) cin >> p[i];
    int count=0;

    for(int i=1; i<n-1; i++) {
        if((p[i] > p[i-1] && p[i] < p[i+1])||(p[i] < p[i-1] && p[i] > p[i+1])) {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3624
import sys
from copy import deepcopy
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,x = MI()
A = LI()
B = deepcopy(A)
A += A

ans = sum(B)
for k in range(1,N+1):
    for i in range(N):
        B[i] = min(B[i],A[N+i-k])
    ans = min(ans,sum(B)+k*x)

print(ans)


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

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

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()


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

    std::vector<string> s(n);
    REP(i, n) {
        string t;
        cin >> t;
        sort(ALL(t));
        s[i] = t;
    }

    sort(ALL(s));

    ll cnt = 0;
    ll pairs = 0;
    string left = "";
    REP(i, n) {
        if (s[i] == left) {
            pairs++;
        } else {
            cnt += pairs * (pairs-1) / 2;
            pairs = 1;
            left = s[i];
        }
    }
    cnt += pairs * (pairs-1) / 2;
    std::cout << cnt << '\n';

    return 0;
}


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

int main() {
    int n;
    cin>>n;
    if(n%2==1)
    {
        cout<<"No";
        return 0;
    }
	string s;
	cin>>s;
	int a=n/2;
	bool val=1;
	for(int i=0;i<a;i++)
	{
	    if(s[i]!=s[i+a])
	    {
	        val=0;
	        break;
	    }
	}
	if(val==1)
	cout<<"Yes";
	else
	cout<<"No";
	
	return 0;
	
}

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

const ll INF = 1LL<<60;

int main(){
	ll n,k;
	cin >> n >> k;
	vector<ll> p(n);
	vector<ll> c(n);
	rep(i,n) cin >> p[i], p[i]--;
	rep(i,n) cin >> c[i];
	//まずサイクル成分に分ける
	vector<bool> seen(n);
	ll ans = -INF;
	rep(i,n){
		vector<ll> score; //サイクル成分のスコアを格納
		if(!seen[i]){
			int idx = i;
			while(!seen[idx]){
				seen[idx] = true;
				score.push_back(c[idx]);
				idx = p[idx];
			}
			ll sum = 0;
			for(auto p: score) sum += p;
			//一つのサイクル成分について, 始点と終点を前通り試す。
			ll L = score.size();
			for (int a = 0; a < L; ++a) {
				ll ab_length = 0;
				ll ab_score = 0;
				for (int b = a + 1; b <= L + a ;++b) {
					int tempb = b % L;
					ab_length++;
					ab_score += score[tempb];
					if(ab_length > k) continue;
					ll ab_score_max = ab_score + max(sum, ll(0)) * ((k - ab_length) / L);
					ans = max(ans, ab_score_max);
				}
			}
		}
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 10000001;

int n, fact[N], inv[N], mod = 998244353;

int powlog(int a, int b){
    if(b == 0) return 1;
    int ret = powlog(a, b / 2);
    if(b % 2) return 1LL * ret * ret % mod * a % mod;
    return 1LL * ret * ret % mod;
}
int C(int n, int r){
    return 1LL * fact[n] * inv[r] % mod * inv[n - r] % mod;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    fact[0] = 1;
    for(int i = 1 ; i < N ; i++){
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    inv[N - 1] = powlog(fact[N - 1], mod - 2);
    for(int i = N - 2 ; i >= 0 ; i--){
        inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
    }
    cin >> n;
    int cur = 0;
    for(int i = n / 2 + 1 ; i <= n ; i++){
        cur = (cur + 1LL * C(n, i) * powlog(2, n - i)) % mod;
    }
    cout << (1LL * powlog(3, n) - 2 * cur + 2 * mod) % mod;
}


Measured memory_bytes: 78336
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

int N;
VI L;

int main() {
    cin >> N;
    REP (i, N) {
        int tmp;
        cin >> tmp;
        L.PB(tmp);
    }
    sort(ALL(L));
    int ans = 0;
    REP (i, N - 1) {
        FOR (j, i + 1, N) {
            auto itrl = upper_bound(L.begin() + i + 1, L.begin() + j, abs(L[i] - L[j]));
            auto itrr = lower_bound(L.begin() + i + 1, L.begin() + j, L[i] + L[j]);
            ans += itrr - itrl;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {


		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		ArrayList<Integer> a =new ArrayList<>();

		//得点列aを生成
		for(int i=0; i < n; i++) {
			a.add(Integer.parseInt(sc.next()));
		}

		//降順にソート
		Collections.sort(a, Collections.reverseOrder());

		int alice = 0;
		int bob = 0;

		for(int i=0; i<n; i++) {
			if(i%2==0) {
				alice+=a.get(i);
			}else {
				bob+=a.get(i);
			}
		}

		int dif = alice - bob;

		System.out.println(dif);

	}
}


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

int main() {
	int N;
	scanf("%d", &N);
	long *A = new long[N];
	bool * b = new bool[N];
	for (int i = 0; i < N; i++) {
		scanf("%ld", &A[i]);
		b[i] = true;
	}

	sort(A, A+N, greater<long>());
	
	long len[2] = {0};
	int count = 0;

	for (int i = 0; i < N - 1; i++) {
		if (b[i] && A[i] == A[i+1]) {
			b[i] = false;
			b[i+1] = false;
			len[count] = A[i];
			count++;
			if (count == 2)
				break;
		}

	}
	long S = len[0] * len[1];
	cout << S << endl;
}


Measured memory_bytes: 1152
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define range(i,b) rep(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int input;
	bool check;

	while(cin >> n){
		range(i,n){
			a = b = 0;
			check = true;
			range(i,10){
				cin >> input;
				if(input > a && input > b){
					if(a > b)
						a = input;
					else
						b = input;
				}else if(input > a){
					a = input;
				}else if(input > b){
					b = input;
				}else{
					check = false;
				}
			}
			if(check) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 1156