akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

template<typename T>
vector<T> dijkstra(int s,vector<vector<pair<int,T>>> &G){
    const T INFINF=numeric_limits<T>::max();
    using P=pair<T,int>;
    int n=G.size();
    vector<T> d(n,INFINF);
    vector<int> b(n,-1);//previous point
    priority_queue<P,vector<P>,greater<P>> q;
    d[s]=0;
    q.emplace(d[s],s);
    while(!q.empty()){
        P p=q.top();q.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(auto& e:G[v]){
            int u=e.first;
            T c=e.second;
            if(d[u]>d[v]+c){
                d[u]=d[v]+c;
                b[u]=v;
                q.emplace(d[u],u);
            }
        }
    }
    return d;
}

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

    int n,m,s,t;
    cin>>n>>m>>s>>t;s--,t--;
    vector<vector<pair<int,ll>>> gy(n),gs(n);
    rep(_,m){
        int u,v;ll yen,snk;
        cin>>u>>v>>yen>>snk;
        u--,v--;
        gy[u].push_back(make_pair(v,yen));
        gy[v].push_back(make_pair(u,yen));
        gs[u].push_back(make_pair(v,snk));
        gs[v].push_back(make_pair(u,snk));
    }
    auto v1=dijkstra(s,gy);
    auto v2=dijkstra(t,gs);

    //両替所をiとするときの旅行コストcost[i]
    vector<ll> cost(n);
    rep(i,n){
        cost[i]=v1[i]+v2[i];
    }
    vector<ll> ans(n);
    ans[n-1]=cost[n-1];
    ll mugen1337=ans[n-1];
    for(int i=n-2;i>=0;i--){
        mugen1337=min(mugen1337,cost[i]);
        ans[i]=mugen1337;
    }
    rep(i,n){
        cout<<((ll)1e15-ans[i])<<endl;
    }
    return 0;
}

Measured memory_bytes: 20088
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);
    static StringBuffer sb = new StringBuffer();
    public static void main(String args[]){
        int N=sc.nextInt(),dt,dx,dy,t=0,x=0,y=0;
        String res="Yes";
        for(int i=0;i<N;i++){
            dt=t;dx=x;dy=y;
            t=sc.nextInt();x=sc.nextInt();y=sc.nextInt();
            int D=Math.abs(x-dx)+Math.abs(y-dy),T=t-dt;
            if(T<D||D%2!=T%2){
                res="No";
                break;
            }
        }
        System.out.println(res);
    }
}

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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int N;
int solve(int i, VI& xs, VI& ys){
  if(i == N){
	for(int y: ys)
	  if(y % 2 == 0)
		return 1;
	return 0;
  }

  int res = 0;
  for(int d=-1;d<=1;++d){
	ys[i] = xs[i] + d;
	res += solve(i+1, xs, ys);
  }
  return res;
}

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

  cin >> N;
  VI xs(N);
  REP(i,N) cin >> xs[i];

  VI ys(N);
  cout << solve(0, xs, ys) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int S[1000000];
int T[1000000];
int Scount;
int Tcount;
int count;
int i,j;
 
int binarySearch(int);
int main(){
 
 
  scanf("%d",&Scount);
 
  for(count = 0;count < Scount;count++){
    scanf("%d",&S[count]);
  }
 
  scanf("%d",&Tcount);
 
  for(count = 0;count < Tcount;count++){
    scanf("%d",&T[count]);
  }
  count = 0;
 
  for(i = 0;i < Tcount;i++){
  if(binarySearch(T[i])==1)count++;
  }
 
  printf("%d\n",count);
  return 0;
}
 
int binarySearch(int key){
  int left;
  int right;
  int mid;
 
  left = 0;
  right = Scount;
  while(left < right){
    mid = (left+right)/2;
    if(S[mid]==key)return 1;
    else if(key < S[mid])right = mid;
    else left = mid + 1;
  }
  return 0;
}

Measured memory_bytes: 4896
#include <stdio.h>

inline long long min(long long a, long long b)
{
    if (a<b)    return a;
    else        return b;
}

int main(void)
{
    int Q, H, S, D;
    long long N, sum;


    scanf("%d%d%d%d", &Q, &H, &S, &D);
    scanf("%ld", &N);

    long long n2L = N/2;
    long long n1L = N%2;

    long long s1L = 4*Q;
    s1L = min(s1L, 2*H);
    s1L = min(s1L, S);

    long long s2L = s1L*2;
    s2L = min(s2L, D);

    sum = s2L*n2L + s1L*n1L;


    printf("%ld\n", sum);

    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<lpong long>
#define vi vector<vi>
struct edge{
  struct treev* to;
  ll length;
};
struct treev{
  int num;
  vector<edge> nexts;
};
struct input{
  int u;
  int v;
  ll w;
};
  ll n,k;
  ll ans;
  bool flag=false;
bool cmp(const input &a, const input &b)//ソート用
{
  if(a.u!=b.u){
    return a.u<b.u;
  }else{
    return a.v<b.v;

  }
}
ll fact(ll begin,ll num){
  if(begin<num){
    return 0;
  }
  ll ans=1;
  for(ll i=begin;i>begin-num;i--){
    ans*=i;
    ans%=d9_7;
  }
  return ans;
}
vector<treev*> vs;
treev* createtreenode(int num){
  treev* newt=new treev;
  if(newt==NULL){
    cout << "memory error" << endl;
    while(1){
      num=1;//メモリエラー対策
    }
  }
  newt->num=num;
  newt->nexts={};
  //cout << "fff" << endl;
  return newt;
}
void insertree(ll len,int Va,int Vb){//結ぶ頂点を
  vs[Va]->nexts.push_back({vs[Vb],len});
  vs[Vb]->nexts.push_back({vs[Va],len});
  return;
}
void DFS(treev* root,ll depth,treev* pre){
  if(flag==true)return;
  //cout << "eee" << endl;
  //ここにやりたい処理を書く
  ll cnt=0;
  for(auto i:root->nexts){
    if(pre==i.to){
      continue;
    }
    cnt+=1;
  }
  if(cnt>k-2 && depth >=2){
    flag = true;
    return;
  }else if(cnt>k-1 && depth ==1){
    flag=true;
    return;
  }
  //cout<<"test"<<cnt <<" "<<depth<<endl;
  if(depth==0){
    ans*=fact(k-1,cnt);
  }else{
    ans*=fact(k-2,cnt);
  }
  ans%=d9_7;
  for(auto i:root->nexts){
    if(pre==i.to){
      continue;
    }
    DFS(i.to,depth+i.length,root);
  }
  return;
}
int main(void){
  cin>>n>>k;
  rep(i,n){
    vs.push_back(createtreenode(i));
  }
  ll a,b;
  ans=k;
  rep(i,n-1){
    cin>>a>>b;
    insertree(1,a-1,b-1);
  }
  DFS(vs[0],0,NULL);
  if(flag==true){
    cout<<0<<endl;
  }else{
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 14452
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    string A, B;
    cin >> A >> B;
    int N = sz(A), M = sz(B);
    int a[N+1][2], b[M+1][2];
    rep(j, 2) a[N][j] = N;
    rep3(i, N-1, 0){
        rep(j, 2) a[i][j] = a[i+1][j];
        a[i][A[i]-'0'] = i;
    }
    rep(j, 2) b[M][j] = M;
    rep3(i, M-1, 0){
        rep(j, 2) b[i][j] = b[i+1][j];
        b[i][B[i]-'0'] = i;
    }
    int dp[N+1][M+1];
    fill(dp[0], dp[N+1], inf);
    rep3(i, N, 0){
        rep3(j, M, 0){
            rep(k, 2){
                int ni = a[i][k], nj = b[j][k];
                if(ni == N && nj == M) chmin(dp[i][j], 0);
                else chmin(dp[i][j], dp[min(ni+1, N)][min(nj+1, M)]+1);
            }
        }
    }
    int n = dp[0][0];
    string ans;
    int x = 0, y = 0;
    rep(i, n){
        rep(j, 2){
            int nx = min(a[x][j]+1, N), ny = min(b[y][j]+1, M);
            if(dp[nx][ny] == n-i-1){
                ans += '0'+j;
                x = nx, y = ny;
                break;
            }
        }
    }
    rep(j, 2){
        if(a[x][j] == N && b[y][j] == M){
            ans += '0'+j;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 65832
N=int(input())
A=[int(input()) for i in range(N)]
A.sort()
if N&1:
  print(max(2*(sum(A[N//2+1:])-sum(A[:N//2+1]))+A[N//2]+A[N//2-1],2*(sum(A[N//2:])-sum(A[:N//2]))-A[N//2+1]-A[N//2]))
else:
  print(2*(sum(A[N//2:])-sum(A[:N//2]))-A[N//2]+A[N//2-1])

Measured memory_bytes: 82668
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

// GCD, LCM
// https://youtu.be/8lm8o8L9Bmw?t=2285
// https://youtu.be/XI8exXVxZ-Q?t=3595
// https://youtu.be/F2p_e6iKxnk?t=843
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 main() {

    ll A,B,C,D;
    cin >> A >> B >>C >>D;
    //CDで割り切れる個数をもとめる。
    ll canDivideCD = (B/C) -(A-1)/C + (B/D) -(A-1)/D;
    ll lcmCD = lcm(C,D);
    canDivideCD -= (B/(lcmCD) -(A-1)/(lcmCD)); 
    cout << (B+1-A)-canDivideCD << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

s = list(input())
K = int(input())
leng = len(s)
from heapq import heappush, heappop
Q = []
for i in range(leng):
    heappush(Q, (s[i], i))

se = set()
cnt = 0
while 1:
    a, idx = heappop(Q)
    if a not in se:
        se.add(a)
        cnt += 1
    if cnt==K:
        break
    if idx!=leng-1:
        heappush(Q, (a+s[idx+1], idx+1))

print(a)

Measured memory_bytes: 77276
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

template <typename T> inline constexpr bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline constexpr bool chmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
template <typename ite> void scan_ite(ite start, ite end) {
  for (auto i = start; i != end; i++)
    cin >> (*i);
}
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int main() {
  int s, w;
  cin >> s >> w;
  if (w >= s) {
    cout << "unsafe\n";
  } else {
    cout << "safe\n";
  }
}


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;

int index(int n)
{
    int index = 0;
    while(n > 0) {
        n /= 10;
        index++;
    }
    return index;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;

    int ab = a * pow(10, index(b)) + b;

    for (int i = 1; i <= 10000; i++) {
        if (ab == i * i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]


def main():
    n = ni()
    hs = na()

    ds = [hs[i] - hs[i+1] for i in range(len(hs)-1)]
    mx = 0
    v = 0
    for i in range(len(hs)-1):
        if ds[i] >= 0:
            v += 1
            mx = max(mx, v)
        else:
            v = 0

    print(mx)
            
        

if __name__ == '__main__':
    main()


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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long N, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c) {
    vvi dp(N + 1, vi(3, 0));
    rep(i, N) {
        dp[i + 1][0] = a[i] + max(dp[i][1], dp[i][2]);
        dp[i + 1][1] = b[i] + max(dp[i][0], dp[i][2]);
        dp[i + 1][2] = c[i] + max(dp[i][1], dp[i][0]);
    }
    cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    std::vector<long long> c(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
        scanf("%lld", &b[i]);
        scanf("%lld", &c[i]);
    }
    solve(N, std::move(a), std::move(b), std::move(c));
    return 0;
}


Measured memory_bytes: 8064
#include<iostream>
#include<cstdio>
using namespace std;
const int N=100005;
int w,h,k;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
long long solve(int w,int h)
{
	long long res=0;
	for(int d=0;d<h;d++)
		for(int a=1;a<w;a++)
		{
			int R=2*k-a*d+gcd(d,w)-2;
			if(R<0) break;
			int b=min(h-1-d,R/w);
			int tmp=b;
			b++;
			if(b+d<h&&w*b-gcd(w-a,b+d)-gcd(a,b)<=R) tmp++;
			if(d==0) res+=tmp;
			else res+=tmp*2;
		}
	return res*2;
}
int main()
{
	scanf("%d%d%d",&w,&h,&k);
	printf("%lld",solve(w,h)+solve(h,w));
	return 0;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
long long fun(int a,int b){
  int c;
  c=b/a;
   for(int i=2;i<b/a;i++){
     c-=b/(a*i);
   }
  return c;
}
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int gcdm(int a, int b,int c)
{
 
   {
       return(gcd(gcd(a,b),c));
   }
}
long long count(int n)
{long long r;
 r=0;
  for(int i=1;i<n+1;i++){
    for(int j=1;j<n+1;j++){
      for(int w=1;w<n+1;w++){
        r+=gcdm(i,j,w);
        }
    }
  }
    return r;
  }
  

int main(){
  int n;
  cin>>n;
 cout<<count(n)<<endl;
}

Measured memory_bytes: 3636
let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d\n" @@ fun n ->
  let k = upper_bound 0 (n + 2) @@ fun k -> k * (k - 1) / 2 <= n in
  if k * (k - 1) / 2 <> n then
    print_endline "No"
  else begin
    Printf.printf "Yes\n%d\n" k;
    for i = 0 to k - 1 do
      Printf.printf "%d" (k - 1);
      for j = 0 to k - 1 do
        if i + j <> k - 1 then
          let i, j =
            if i + j < k - 1
            then i, j
            else k - j - 1, k - i - 1 in
        Printf.printf " %d" @@ succ @@ (2 * (k - 1) - i + 1) * i / 2 + j
      done;
      print_newline ()
    done
  end


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int x;
    cin >> x;
    bool dp[100000 + 1];
    fill(dp, dp + 100000 + 1, false);

    dp[0] = true;  // 0 yen
    for (int i = 1; i <= 99; i++) {
        dp[i] = false;  // 1~99 yen
    }
    for (int i = 100; i <= 105; i++) {
        dp[i] = true;  // 100~105 yen
    }
    for (int i = 106; i <= 100000; i++) {
        for (int j = 0; j < 6; j++) {
            if (dp[i - 100 - j]) {  // Is i-100 ~ i-105 yen = true?
                dp[i] = true;       // i yen
            }
        }
    }
    if (dp[x])
        puts("1");
    else
        puts("0");
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	int n;
	lli k;
	cin >> n >> k;
	vector<lli> v((int)1e5+1, 0);
	for(int i=0; i<n; i++){
		lli a,b;
		cin >> a >> b;
		v[a] += b;
	}
	int ans = 0;
	for(int i=0; i<=(int)1e5; i++){
		if(v[i]==0) continue;
		k -= v[i];
		if(k<=0){
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1152
// C - Streamline
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()

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

	vi X(M); rp(i,M) cin>>X[i];
	sort(all(X));

	vi P;
	int pre = X[0];
	rp(i,M-1){
		int now = X[i+1];
		P.push_back(abs(now-pre));
		pre = now;
	}
	sort(all(P));

	ll ans = 0;
	rp(i,M-N) ans += (ll)P[i];
	cout<< ans <<endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;


int main()
{
    char s[51][51];
    int h,w,i,j,con,ans,k,l;
    ans=0;

    for(i=0; i<=50; i++)
    {
        for(j=i; j<=50; j++)
        {
            s[i][j]=s[j][i]='.';
        }
    }
    scanf("%d%d",&h,&w);
    getchar();
    ans++;

    if(ans!=1) printf("\n");
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            scanf("%c",&s[i][j]);
        }
        getchar();
    }
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            if(s[i][j]!='#')
            {
                con=0;
                for(k=-1; k<=1; k++)
                {
                    for(l=-1; l<=1; l++)
                    {
                        if(s[i+k][j+l]=='#')
                            con++;
                    }
                }
                s[i][j]='0'+con;
            }
        }
    }


    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            printf("%c",s[i][j]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <functional>
#include <numeric>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <stdio.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;

int n, a[2005], x;
int v[2005][2005];

int main(){
	cin >> n >> x;
	for(int i=0; i<n; i++){
		cin >> a[i];
		v[0][i] = a[i];
	}
	for(int i=1; i<n; i++){
		for(int j=0; j<n; j++){
			v[i][j] = v[i-1][j];
		}
		rotate(v[i], v[i] + 1, v[i] + n);
	}
	lint ret = 1e18;
	for(int i=0; i<n; i++){
		lint tmp = 1ll * i * x;
		for(int j=0; j<n; j++){
			if(i) v[i][j] = min(v[i][j], v[i-1][j]);
		}

		for(int j=0; j<n; j++){
			tmp += v[i][j];
		}
		ret = min(ret, tmp);	}
	cout << ret << endl;
}



Measured memory_bytes: 15872
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード<br/>
 * https://atcoder.jp/contests/abc056/submissions/4757789 にも参照
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int k = scanner.nextInt();
			int[] a = new int[n];
			IntStream.range(0, n).forEach(i -> a[i] = scanner.nextInt());
			if (1 == n) {
				System.out.println((k > a[0]) ? 1 : 0);
				return;
			}
			Arrays.sort(a);

			int ng = 0, ok = n + 1;
			while (ok - ng > 1) {
				int mid = (ok + ng) / 2;
				if (isNeeded(mid, n, k, a)) {
					ok = mid;
				} else {
					ng = mid;
				}
			}
			System.out.println(ng);
		}
	}

	/**
	 * @param now
	 * @param n
	 * @param k
	 * @param a
	 * @return now番目のカードが必要かどうか
	 */
	private static boolean isNeeded(int now, final int n, final int k, final int[] a) {
		boolean[][] dp = new boolean[n + 1][k + 1];
		IntStream.range(0, n + 1).forEach(i -> Arrays.fill(dp[i], false));
		dp[0][0] = true;
		IntStream.rangeClosed(1, n).forEach(i -> IntStream.rangeClosed(0, k).forEach(j -> {
			if (i == now) {
				// ぬくカードの場合
				dp[i][j] = dp[i - 1][j];
			} else {
				if (dp[i - 1][j]) {
					dp[i][j] = true;
					if (j + a[i - 1] <= k) {
						dp[i][j + a[i - 1]] = true;
					}
				}
			}
		}));
		for (int i = k - 1; i >= Math.max(k - a[now - 1], 0); i--) {
			if (dp[n][i]) {
				return true;
			}
		}
		return false;
	}
}


Measured memory_bytes: 232708
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
using namespace std;
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	string a1="dangerous",b1="delicious",c1="safe";
	int x,a,b;
	cin>>x>>a>>b;
	if(x+a<b){
		cout<<a1;
		return 0; 
	}
	else{
		if(b<=x-1){
			cout<<b1;
			return 0;
		}
		else{
			cout<<c1;
			return 0;
		}
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(str) for str in input().split()]


def sad(A, b):
    return sum([abs(a - (b + i)) for a, i in zip(A, range(1, len(A) + 1))])

B = [A[i] - (i + 1) for i in range(N)]
B.sort()

print(sad(A, B[(N - 1) // 2]))

Measured memory_bytes: 27796
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
A = sorted(LI())
m = A.pop()
diff = INF
for a in A:
    if diff > abs(a - m / 2):
        diff = abs(a - m / 2)
        k = a


print(m, k)


Measured memory_bytes: 57712
def Array_list(array_list,m,n):
    if n == 0:
        return array_list
    else:
        array_list_next = []
        for array in array_list:
            for i in range(array[len(array)-1],m+1):
                array_list_next.append(array+[i])
        return Array_list(array_list_next,m,n-1)

def main():
    N,M,Q = map(int,input().split())
    abcd = [list(map(int,input().split())) for _ in range(Q)]

    L = [[i] for i in range(1,M+1)]
    array_list = Array_list(L,M,N)

    ans,tmp = 0,0
    for array in array_list:
        tmp = 0
        for a,b,c,d in abcd:
            if array[b-1] - array[a-1] == c:
                tmp += d
        ans = max(tmp,ans)

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 63864
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
ll x = 1;
int main(){
	scanf("%lld",&n);
	for(int i = 0;i<n;i++){
		ll a;
		scanf("%lld",&a);
		ll y = __gcd(x,a);
		x/=y;
		x*=a;
		}
		printf("%lld\n",x);
	}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

    int n, a[3];
    cin >> n >> a[0] >> a[1] >> a[2];
    int x1[n], x2[n];
    for (int i = 0; i < n; i++) {
        char c1, c2;
        cin >> c1 >> c2;
        x1[i] = c1 - 'A';
        x2[i] = c2 - 'A';
    }

    int ans[n];
    for (int i = 0; i < n; i++) {
        if (a[x1[i]] == 0 && a[x2[i]] == 0) {
            cout << "No" << endl;
            return 0;
        }

        if (a[x1[i]] == 1 && a[x2[i]] == 1 && a[3-x1[i]-x2[i]] == 0 && i < n - 1) {
            if (x1[i] != x1[i+1] || x2[i] != x2[i+1]) {
                ans[i] = x1[i] == x1[i+1] || x1[i] == x2[i+1] ? x1[i] : x2[i];
            } else {
                ans[i] = x1[i];
            }
        } else {
            ans[i] = a[x1[i]] < a[x2[i]] ? x1[i] : x2[i];
        }

        a[ans[i]]++;
        a[x1[i]+x2[i]-ans[i]]--;
    }

    cout << "Yes" << endl;
    for (int i = 0; i < n; i++) {
        cout << (char)(ans[i] + 'A') << endl;
    }

    return 0;
}


Measured memory_bytes: 4832
import sys
i=input
n = int(i())
r0 = int(i())
r1 = int(i())
mx = r1-r0
mn = min(r1,r0)
for i in map(int,sys.stdin.readlines()):
    a=i-mn
    if mx<a:
        mx=a
        if 0>a:mn=i
    elif mn>i:mn=i
print(mx)

Measured memory_bytes: 19828
#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); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "YES"
#define no "NO"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

string O,E;
int main(){
    cin >> O >> E;
    string ans = "";
    rep(i,sz(O)) ans += O[i], ans += E[i];
    if(sz(O) > sz(E)) ans.pop_back();
    pr(ans);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll N;

int main(){

    string S;

    cin >> S;

    ll A = stoi(S.substr(0, 2));
    ll B = stoi(S.substr(2, 2));

    if(1 <= A && A <= 12){
        if(1 <= B &&B <= 12){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if(1 <= B && B <= 12){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }
} 

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

int main(void)
{
    int a;
    string s;
    cin >>a;
    cin >>s;

    if(a >= 3200){
        printf("%s\n", s.c_str());
    }else{
        printf("red\n");
    }
    return 0;
}

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

int main(){
    int n; cin >> n;
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            if(n == i*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
        
    }
    cout << "No" << endl;
    

    return 0;
}

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

A = list(map(int, input().split()))

num_4 = 0
num_2 = 0
num_odd = 0

for i in A:
    if i % 4 == 0:
        num_4 += 1
    elif i % 2 == 0:
        num_2 += 1

num_odd = n - num_2 - num_4

if n - num_4*2 == num_2 or n - num_4 * 2 == 1 or num_2 > n//2 or num_4 + 1 > n//2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>

int main() {

    ll N;
    cin >> N;
    vl A(3e5 + 10);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll MOD = 1e9 + 7;
    ll ans = 0;

    ll sum;
    ll t = 1;
    int count = 0;
    while(count < 60) {
        sum = 0;
        for (int i = 0; i < N; i++) {
            if (A[i] & t) sum++;
        }
        ll tmp;
        tmp = t % MOD;
        tmp = (tmp * sum) % MOD;
        tmp = (tmp * (N -sum)) % MOD;
        ans = (ans + tmp) % MOD;

        count++;
        t *= 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a[300008];

int main(){
	cin >> n;
	for(ll i = 1; i <= 3*n; i++){cin >> a[i];}
	
	sort(a+1, a+(3*n+1));
	
	ll ans = 0;
	for(ll i = 0; i < n; i++){
		ans += a[3*n-2*i-1];
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define N 5000
#define Mo 1000000007
#define I ((Mo + 1) / 2)
typedef long long LL;
int n, k, a[N];
LL sum;

int main() {
    //freopen("sample.in", "r", stdin);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    LL ans = 0;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++) {
            if (j == i) continue;
            if (a[j] < a[i]) sum++;
            if (a[j] < a[i] && j > i) ans++;
        }
    ans = ans * k % Mo;
    ans = (ans + sum * k % Mo * (k - 1) % Mo * I % Mo) % Mo;
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    s = int(input())
    logs = {s: 1}
    for m in range(2, 1000000):
        if s % 2 == 0:
            s //= 2
        else:
            s = 3 * s + 1
        if s in logs:
            print(m)
            exit()
        logs[s] = m


main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(sdj) cout<<(sdj)<<endl 

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;




int main(){
    int H,N;
    cin>>H>>N;
    ll sum=0;
    F0R(i,N){
        ll a;
        cin>>a;
        sum+=a;
    }
    if(sum>=H){
        out("Yes");
    }else{
        out("No");
    }
    return 0;
}


Measured memory_bytes: 256
def tenlog(n):
    ans = 0
    while n != 0:
        ans += 1
        n //= 10
    return ans

import time
s = time.time()
#prime = p_prime(10**5)
p = [i for i in range(1,10**5+1)]
g = time.time()
#print(g-s)

N = int(input())
ans = float("inf")
for i in p:
    if N%i == 0:
        #print(i)
        ans = min(ans, max(tenlog(i), tenlog(N//i)))
print(ans)

Measured memory_bytes: 45420
import math

A, B, C, D = map(int, input().split(' '))

taikyu_t = math.ceil(A / D)
taikyu_a = math.ceil(C / B)

if taikyu_a <= taikyu_t:
    # takahashi win
    print('Yes')
else:
    # aoki win
    print('No')


Measured memory_bytes: 9160
#include<iostream>

int main() {
	int a,b,k,n,m;
	std::cin >> a >> b >> k;

	for (int i = 0; i < k; i++) {

		if (i % 2 == 0) {
			if (a % 2 == 1) {
				a--;
			}

			a = a / 2;
			b = b + a;

			//std::cout << a << b << std::endl;
		}
		else {
			if (b % 2 == 1) {
				b--;
			}

			b = b / 2;
			a = a + b;

			//std::cout << a << b << std::endl;
		}

		//std::cout << i << std::endl;

	}



	std::cout <<a<<" "<<b<< std::endl;
	return 0;
}

Measured memory_bytes: 256
//In the name of Allah
//Ya Ali!
#include <bits/stdc++.h>

using namespace std;
typedef long long ll ;

const ll maxn = 2000 * 101 ;
const ll INF = 1e18 ;

#define f first
#define s second

ll n , ans = 0;
deque<ll> v ;

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

string s1 ;
cin >> s1 ;
ll x = 1 ;

for(int i = 1 ; i < s1.size() ; i ++){
    if(s1[i] == s1[i-1])x ++ ;
    else{
        v.push_back(x) ;
        x = 1 ;
    }
}
v.push_back(x) ;
n = v.size() ;

for(int i = 1 ; i < n ; i ++){
    if((v[i] % 3 == 2 && v[i-1] % 3 == 2) || (v[i] % 3 == 2 && v[i] % 3 == 0) || (v[i] % 3 == 0 && v[i-1] % 3 == 2)){
        ans ++ ;
        v[i] -- ;
        v[i-1] -- ;
    }
}
for(int i = 0 ; i < n ; i ++){
    ans += (v[i]/3)*2 + (v[i] % 3 != 0) ;
}
cout << ans ;
 return 0;
}
/*
                  _     _   __
            /_\  (_    (_)  __)
           /   \  _) . (_) (__
*/


Measured memory_bytes: 2068
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

void solve()
{
	char c;
	cin >> c;
	if(isupper(c))
	{
		cout << "A\n";
	}
	else
	{
		cout << "a\n";
	}
	
}

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

Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    N *= 4;
    long long ans = 0;
    vector<pair<pair<double, long long>, int>> v(4);
    v[0] = make_pair(make_pair(Q/0.25, Q), 1);
    v[1] = make_pair(make_pair(H/0.5, H), 2);
    v[2] = make_pair(make_pair(S/1.0, S), 4);
    v[3] = make_pair(make_pair(D/2.0, D), 8);
    sort(v.begin(), v.end());
    while(N > 0){
        for(int i=0; i<3; i++){
            if(v[i].second > N) continue;
            long long tmp = N / v[i].second;
            ans += v[i].first.second * tmp;
            N -= tmp * v[i].second;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#coding: utf-8
N, K = map(int, input().split())
snukes = set([i+1 for i in range(N)])
d = []
for k in range(K):
    input()
    for a in map(int, input().split()):
        if a in snukes:
            snukes.remove(a)
print(len(snukes))

Measured memory_bytes: 9144
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n = n_in()
xy = [l_in() for _ in range(n)]

left = 0
right = 2000

from itertools import combinations
import math
def check(r):
    allprox = True
    for (x1,y1),(x2,y2) in combinations(xy, 2):
        dx = x1-x2
        dy = y1-y2

        d2 = dx*dx+dy*dy

        if d2 < 10**-16:
            continue

        allprox = False
        
        if d2/4 > r*r:
            continue

        h = math.sqrt(r*r-d2/4)
        d = math.sqrt(d2)

    
        px,py= (x1+x2)/2, (y1+y2)/2

        qx,qy = px-dy/d*h, py+dx/d*h
        if all((qx-x3)*(qx-x3) + (qy-y3)*(qy-y3) <= r*r for x3,y3 in xy if (x1 != x3 or y1 != y3) and (x2 != x3 or y2 != y3)):
            return True
        
        qx,qy = px+dy/d*h, py-dx/d*h
        if all((qx-x3)*(qx-x3) + (qy-y3)*(qy-y3) <= r*r for x3,y3 in xy if (x1 != x3 or y1 != y3) and (x2 != x3 or y2 != y3)):
            return True
    else:
        return allprox

while right-left > 10**-10:
    mid = (left+right)/2
    if check(mid):
        right = mid
    else:
        left = mid

print((left+right)/2)
    


Measured memory_bytes: 3316
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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


int main()
{
	int n; cin >> n;
	int res = 0;

	for (int i = 1; i <= n; i++) {
		if (i % 2 != 0) {
			res++;
		}
	}

	float answer = res;
	float N = n;

	cout << (answer / N);


	return 0;

}

Measured memory_bytes: 3768
// Problem : A - Registration
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Muallif: Azimjon Mehmonali o'g'li

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define sqr(x) (x) * (x)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define rALL(a) a.rbegin(), a.rend()
#define SORT(a) sort(ALL(a))
#define sc scanf
#define pr printf
#define xatop(a) cerr << #a << " = " << a << endl;
#define jsatr debug(__LINE__)
#define INF 1000000000
#define mod 1000000007

int main() {
	string s, t;

	cin >> s >> t;

	int n = s.size();
	if (s == t.substr(0, n))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define PRINT(s) cout << s << endl;
#define FOR(i, n) for (int i = 0; i < (n); i++)

int main() {
    int n;
    cin >> n;
    map<string, int> prisemap;
    int count = 0;
    int i;
    FOR(i, n) {
        string prise;
        cin >> prise;
        prisemap[prise]++;
        if (prisemap[prise] == 1) {
            count++;
        }
    }
    PRINT(count)
}


Measured memory_bytes: 19240
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k=0;double s=0,m;cin>>n;
  vector<int>a(n);for(int i=0;i<n;i++){cin>>a.at(i);s+=a.at(i);}
  s/=n;
  if(n==1)cout<<0<<endl;
  else{
    m=abs(a.at(0)-s);
    for(int i=1;i<n;i++){
      if(m>abs(a.at(i)-s)){
        m=abs(a.at(i)-s);
        k=i;
      }
    }
    cout<<k<<endl;
  }
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) int(a.size())
#define re return
using namespace std;
int main()
{
	char a,b,c;
	cin>>a>>b>>c;
	if (a==b && b==c)  cout<<"No";
	else if (a==b || b==c || a==c)  cout<<"Yes";
	else  cout<<"No";
	re 0;
}

Measured memory_bytes: 256
s = list(input())

count = 0

for i in range(0,len(s)):
  sign = (i+1)%2
  if sign == 1 and s[i] == "L":
    count = 1
  elif sign == 0 and s[i] == "R":
    count = 1
    
if count == 1:
  ans = "No"
elif count == 0:
  ans = "Yes"

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cap,rev;};//ikisaki youryou gyakuhen
class MF{//max flow
	public:
	int n;
	vector<vector<edge> >G;//[MAX];
	vector<bool>used;//[MAX];
	MF(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int from, int to, int cap){
		edge q={to,cap,int(G[to].size())};
		G[from].push_back(q);
		q={from,0,int(G[from].size()-1)};
		G[to].push_back(q);
	}
	int dfs(int v,int t, int f) {
		if(v==t)return f;
		used[v]=1;
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(used[e.to]||e.cap<=0) continue;
			int d =dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
		return 0;
	}
	int mf(int s,int t) {//from s to t,ford_fulkerson
		int flow=0,f;
		while(1){
			used=vector<bool>(n,false);
			f=dfs(s,t,inf);
			if(f==0)return flow;
			flow+=f;
		}
	}
};
int f(vi w){
	int n=w.size();
	MF mf(2*n+2);
	int s=2*n,t=s+1;
	rep(i,n)mf.add_edge(s,i,1);
	rep(i,n)mf.add_edge(n+i,t,1);
	rep(i,n)rep(j,n)if(i!=j&&w[i]%w[j]==0)
		mf.add_edge(i,n+j,1);
	return n-mf.mf(s,t);
}
int res;
vi out;
void F(vi w){
	if(w.size()==0)return;
	vi go;
	rep(i,w.size()-1)if(w[i+1]%w[0]&&w[0]%w[i+1])
		go.pb(w[i+1]);
	int flow=f(go);
//	cout<<" "<<flow<<endl;
//	rep(i,go.size())cout<<go[i]<<" ";cout<<endl;
	if(flow==res-1-out.size()){
		out.pb(w[0]);
		F(go);
	}else{
		w.erase(w.begin());
		F(w);
	}
}
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	map<int,int>ma;
	rep(i,n)ma[in[i]]=i+1;
	res=f(in);
	F(in);
	rep(i,out.size())cout<<ma[out[i]]<<(i==out.size()-1?"\n":" ");
}

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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;
typedef vector<pair<string,ll> > svp;

#define spc        ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define PI         2*acos(0.0)
#define lb         lower_bound
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define btpc       __builtin_popcountll
#define sp(x)      cout<<fixed<<setprecision(x)

const   long long  cs=2e5+5;
const   long long  inf=1e18;
const   long long  mod=1e9+7;
void solve()
{
    ll t,n,m,a,b,c,d,e,i,j,k,x,y,z,cnt=0,cnt1=0;
    bool flag = false;   vector<string> v,v1;

    string s,s1;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>s;
        v.pb(s);
    }
    sort(all(v));
    for(i=0;i<n;i++)
    {
        s1.append(v[i]);
    }
    cout<<s1<<endl;


}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

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

    // ll tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}


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

int res[100][100];

int main()
{
	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 100; j++) {
			res[i][j] = 1;
		}
	}
	int A, B;
	cin >> A >> B; A--, B--;
	int x = 0, y = 0;
	for (int i = 0; i < A; i++) {
		res[x][y] = 0;
		x += 2;
		if (x >= 50) {
			x = 0;
			y += 2;
		}
	}
	x = 51, y = 0;
	for (int i = 0; i < B; i++) {
		res[x][y] = 1;
		x += 2;
		if (x >= 100) {
			x = 51;
			y += 2;
		}
	}
	cout << 100 << ' ' << 100 << endl;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			cout << (res[i][j] ? '#' : '.');
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>A(N);
  int cnt=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(i+1!=A[i])cnt++;
  }
  if(cnt==2||cnt==0){
    cout<<"YES"<<endl;
    return 0;
  }
  cout<<"NO"<<endl;

}

Measured memory_bytes: 3580
w = input()
w_list = list(w)
alpha_list = [0] * 26
alpha_num = 0

alpha_fun = lambda c: ord(c) - ord('a')

for i in w_list:
    alpha_list[alpha_fun(i)] += 1

flg_num = 0
flg = False

for j in alpha_list:
    if j == 0 or j % 2 == 0:
        flg = True
    else:
        flg = False
        break

if flg:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,k) = get!(usize, usize);
    println!("{}", min!(k-n%k, n%k));
}


Measured memory_bytes: 8572