akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){

  int q;
  cin>>q;
  deque <int> a;
  for(int i=0;i<q;i++){
    int n,d;
    cin>>n>>d;
    if(n==2){
      if(d) a.pop_back();
      else a.pop_front();
    }
    else if(n) cout<<a[d]<<endl;
    else {
      int x;
      cin>>x;
      if(d) a.push_back(x);
      else a.push_front(x);
    }
  }
  return 0;

}



Measured memory_bytes: 4616
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include <numeric>
#include<iomanip>

using namespace std;

int main() {
	int n;
	cin >> n;
	
	vector<pair<int, int>>x;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		x.emplace_back(a, b);
	}
	int n2 = n;
	for (int i = 1; i < n; i++) {
		n2 *= i;
	}
	int n3 = n - 1;
	for (int i = 1; i < n - 1; i++) {
		n3 *= i;
	}
	n3 *= 2;
	float sum = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			sum += (float)sqrt((x[i].first - x[j].first) * (x[i].first - x[j].first) + (x[i].second - x[j].second) * (x[i].second - x[j].second))*n3;
		}
	}
	cout << setprecision(8)<<(float)sum / n2 << endl;
}

Measured memory_bytes: 256
def check_palindrome(s):
    return s == s[::-1]


def submit():
    s1 = input()
    n = len(s1)
    s2 = s1[:(n - 1)//2]
    s3 = s1[(n + 3)//2 - 1:]

    if check_palindrome(s1) and \
        check_palindrome(s2) and \
        check_palindrome(s3):
        print("Yes")
    else:
        print("No")


submit()




Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
    int R[MAX], n;
    
    cin >> n;
    for (int i = 0; i < n; i++) cin >> R[i];
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for (int i = 1; i < n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    cout << maxv << endl;
    
    return 0;
}


Measured memory_bytes: 3856
# ABC 079 C

A, B, C, D = map(int, input())
for f in [('{}'*7).format(A, x, B, y, C, z, D)
          for x in '+-'
          for y in '+-'
          for z in '+-']:
    if eval(f) == 7:
        print('{}=7'.format(f))
        break

Measured memory_bytes: 3060
fn read<T: std::str::FromStr>() -> T {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().split_whitespace()
		.map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
	(0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
	/// Return `true` if the slice was permuted, `false` if it is already
	/// at the last ordered permutation.
	fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
	/// Original author in Rust: Thomas Backman <serenity@exscape.org>
	fn next_permutation(&mut self) -> bool {
		// These cases only have 1 permutation each, so we can't do anything.
		if self.len() < 2 { return false; }

		// Step 1: Identify the longest, rightmost weakly decreasing part of the vector
		let mut i = self.len() - 1;
		while i > 0 && self[i-1] >= self[i] {
			i -= 1;
		}

		// If that is the entire vector, this is the last-ordered permutation.
		if i == 0 {
			return false;
		}

		// Step 2: Find the rightmost element larger than the pivot (i-1)
		let mut j = self.len() - 1;
		while j >= i && self[j] <= self[i-1]  {
			j -= 1;
		}

		// Step 3: Swap that element with the pivot
		self.swap(j, i-1);

		// Step 4: Reverse the (previously) weakly decreasing part
		self[i..].reverse();

		true
	}
}

fn main() {
	let (n, k) = {
		let tmp: Vec<usize> = read_vec();
		(tmp[0], tmp[1])
	};

	let s: String = read();
	let s: Vec<char> = s.chars().collect();

	let mut score = 0;

	for i in 0..n-1 {
		if s[i] == s[i+1] { score += 1; }
	}

	let ans = std::cmp::min(n-1, score+ 2*k);

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


Measured memory_bytes: 4352
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <list>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int N;
const int MAX_N = 3001;
int dp[MAX_N][MAX_N];
bool visited[MAX_N][MAX_N];
int A[MAX_N];

int rec(int i, int j) {
    if (j < i) return 0;
    if (visited[i][j]) return dp[i][j];

    visited[i][j] = true;

    if (N % 2 == (j - i + 1) % 2) {
        dp[i][j] = max(A[i] + rec(i+1, j), A[j] + rec(i, j-1));
    } else {
        dp[i][j] = min(-A[i] + rec(i+1, j), -A[j] + rec(i, j-1));
    }

    return dp[i][j];
}

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    
    cout << rec(0, N-1) << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

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

    int N;
    cin >> N;
    vector<int> A;
    A.push_back(0);

    int tmp_A;
    for(int i = 0; i < N; i++){
        cin >> tmp_A;
        A.push_back(tmp_A);
    }

    A.push_back(0);

    int total = 0;
    for(int i = 0; i < A.size()-1; i++){
        total += abs(A[i+1]-A[i]);
    }

    for(int i = 1; i <= N; i++){
        cout << total - abs(A[i] - A[i-1])
        - abs(A[i] - A[i+1]) + abs(A[i+1]-A[i-1]) << endl;
    }

    
    return 0;
}


Measured memory_bytes: 1784
N = int(input())
AN = list(map(int,input().split()))

ans = 1		#切らない場合1
beforeDiff = 0

for i in range(1,N):
	diff = AN[i] - AN[i-1]
	
	if beforeDiff==0:	#符号を維持
		beforeDiff = diff
	elif beforeDiff*diff < 0:	#以前と符号が逆なら区切る
		beforeDiff = 0	#長さ1では切らず、次のループでdiffを代入させるため0
		ans += 1
				#以前と符号が同じなら何もしない
print(ans)

Measured memory_bytes: 15020
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
#include <climits>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  // int INF = INT_MAX;
  // ll mod = 1000000007;
  // lld PI = 3.141592653;


  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
     int n;
     cin>>n;
     cout<<1-n<<"\n";



}

Measured memory_bytes: 3184
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Max(x, y) (((x) > (y)) ? (x) : (y))
#define Min(x, y) (((x) < (y)) ? (x) : (y))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 1e3 + 10;
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
int N, K;
signed main()
{
    N = read(), K = read();
    int ans = K;
    for (ri i = 2; i <= N; ++i) {
        ans = ans * (K - 1);
    }
    writeln(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl


int main(){
  ll h,w,d;cin>>h>>w>>d;
  pl a[d+2][h*w/d+2];
  ll temp=0;
  rep(i,h){
    rep(j,w){
      cin>>temp;
      a[temp%d][temp/d]=mp(i+1,j+1);
    }
  }
  ll c[d+2][h*w/d+2];
  rep(i,d){
    c[i][0]=0;
    rep(j,h*w/d+1){
      c[i][j+1]=abs(a[i][j+1].fi-a[i][j].fi)+abs(a[i][j+1].se-a[i][j].se);
    }
  }
  ll b[d+2][h*w/d+2];
  rep(i,d){
    b[i][0]=0;
    rep(j,h*w/d+1){
      b[i][j+1]=b[i][j]+c[i][j+1];
    }
  }
  ll q;cin>>q;
  ll l,r;
  rep(i,q){
    cin>>l>>r;
    cout<<b[r%d][r/d]-b[l%d][l/d]<<endl;
  }
  return 0;

}

Measured memory_bytes: 8832
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            }
            for ( int i = 0; i < H; i++ ){
                for ( int j = 0; j < W; j++ ){
                    if(i%2==1){
                        if(j%2==1) {
                            System.out.printf("#");
                        }else{
                            System.out.printf(".");
                        }
                    }else{
                        if(j%2==1) {
                            System.out.printf(".");
                        }else{
                            System.out.printf("#");
                        }
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}



Measured memory_bytes: 55208
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define DBG(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll p = 1e9+7;
const ll INF = 1LL << 60;

ll dp[3333][3333];
ll n,a[3333];
ll rec(int l,int r){
  if(dp[l][r]!=INF)return dp[l][r];
  if(n%2!=(r-l)%2)return dp[l][r]=max(rec(l+1,r)+a[l],rec(l,r-1)+a[r]);
  return dp[l][r]=min(rec(l+1,r)-a[l],rec(l,r-1)-a[r]);
}

int main(){
  cin>>n;
  fill_n(*dp,3333*3333,INF);
  for(int i=0;i<n;i++){
    cin>>a[i];
    dp[i][i]=a[i]*(n%2?1:-1);
  }
  cout<<rec(0,n-1)<<endl;
  return 0;
}


Measured memory_bytes: 87168
n, m, k = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a, b = [0], [0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

ans = 0
j = m
for i in range(n+1):
    if a[i] > k: break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 40;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string t; cin >> t;
  int n = t.size();
  string ans = "";
  rep(i, n) {
    if(t[i] != '?') ans += t[i];
    else ans += 'D';
  }
  cout << ans << endl;
}


Measured memory_bytes: 3864
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
    A_in, B_in = map(int, input().split())
    A[i] = A_in
    B[i] = B_in


A.sort()
B.sort()
if N % 2 == 1:
    print(B[(N+1)//2 - 1] - A[(N+1)//2 - 1] + 1)
else:
    d_B_med = (B[N//2 - 1] + B[N//2])
    d_A_med = (A[N//2 - 1] + A[N//2])
    print(d_B_med - d_A_med + 1)


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

def Find(x, par):
  if par[x] < 0:
    return x
  else:
    # 経路圧縮
    par[x] = Find(par[x], par)
    return par[x]

def Unite(x, y, par, rank):
  x = Find(x, par)
  y = Find(y, par)

  if x != y:
    # rankの低い方を高い方につなげる
    if rank[x] < rank[y]:
      par[y] += par[x]
      par[x] = y
    else:
      par[x] += par[y]
      par[y] = x
      if rank[x] == rank[y]:
        rank[x] += 1

def Same(x, y, par):
  return Find(x, par) == Find(y, par)

def Size(x, par):
  return -par[Find(x, par)]

n, m = map(int, input().split())
L = [[0, 0] for _ in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    L[i][0] = a
    L[i][1] = b

par = [-1]* n
rank = [0]*n

ans = n*(n-1)//2
anss = [0]*m
for i in reversed(range(m)):
    anss[i] = ans
    a = L[i][0]
    b = L[i][1]
    if not Same(a, b, par):
        ans = max(0, ans-Size(a, par)*Size(b, par))
        Unite(a, b, par, rank)
    #print(par)

for i in range(m):
    print(anss[i])


Measured memory_bytes: 94256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
typedef pair<int,int>pii;
const int mxN=1e5+10,M=1e9+7;
int mod(int x){
    x%=3;
    if(x<0)x+=3;
    return x;
}
int n;
int vac[mxN][3];
int dp[mxN][3];
int solve(int dia,int at){
    if(dia==n-1){
        return dp[dia][at]=vac[dia][at];
    }
    if(dp[dia][at]>=0)return dp[dia][at];

    return dp[dia][at]=vac[dia][at]+max(solve(dia+1,mod(at+1)),solve(dia+1,mod(at+2)));

}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>vac[i][0]>>vac[i][1]>>vac[i][2];
    }
    solve(0,0);
    solve(0,1);
    solve(0,2);
    cout<<max(dp[0][0],max(dp[0][1],dp[0][2]));

}

Measured memory_bytes: 8832
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

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


using namespace std;

int main() {
	
	double n;
	cin >> n;
	double a = 0;
	for (int i = 1; i <= n; i++)if(i%2)a++;
	cout << setprecision(20);
	cout << a / n << endl;

	
	return 0;
	



}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s;

    cin >> s;

    for (int i = 0; i < 19; i++)
    {
        if (s[i] == ',')
            cout << ' ';
        else
            cout << s[i];
    }

    cout << endl;

    return 0;
}

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

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

    string sY = s.substr(0,4);
    string sM = s.substr(5,2);
    string sD = s.substr(8,2);

    long iYmd = atoi((sY + sM + sD).c_str());
    
    if(iYmd <= 20190430)
    {
        cout << "Heisei" << endl;
    }
    else
    {
        cout << "TBD" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
fun solve(d:Int, t:Int, s:Int){

    if(d <= t*s){
        println("Yes")
    }
    else{
        println("No")
    }

}

fun main(){
    val (d, t, s) = readLine()!!.split(" ").map{it.toInt()}
    solve(d,t,s)
}

Measured memory_bytes: 36376
#include<bits/stdc++.h>
#define LiangJiaJun main
using namespace std;
char sa[100004],sb[100004];
int la,lb;
int LiangJiaJun(){
    scanf("%s",sa+1);
    scanf("%s",sb+1);
    for(int i=1;i<=3;i++)if(sa[i]!=sb[3-i+1])return puts("NO"),0;
    puts("YES");
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll cnt = 0;
    ll R = in(), G = in(), B = in(), N = in();
    for (ll r = 0; r * R <= N; ++r) {
        for (ll g = 0; r * R + g * G <= N; ++g) {
            ll tmp = N - r * R - g * G;
            if (tmp >= 0 && tmp % B == 0)++cnt;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int MOD = 1000000007;
using ll = long long;
int main(){
    ll n;
    cin>>n;
    ll A[n+1];
    ll B[n];
    for(int i=0; i<=n; i++){
        cin>>A[i];
    }
    for(int i=0; i<n; i++){
        cin>>B[i];
    }
    ll co=0;
    for(int i=n-1; i>=0; i--){
        if (A[i+1]>=B[i]){
            co+=B[i];
        }
        else{
            if (A[i]>=B[i]-A[i+1]){
                co+=B[i];
                A[i]=A[i+1]+A[i]-B[i];
            }
            else{
                co+=A[i+1]+A[i];
                A[i]=0;
            }
        }
        
    }
    cout<<co<<endl;
}


Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
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<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#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 sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    int N; cin >> N; ll K; cin >> K;
    ll sum = 0;
    ll data[N];
    F0R(i, N) cin >> data[i];
    F0R(i, N) sum += data[i];
    vl facs;
    FOR(i, 1, 25000) {
        if (sum % i == 0) {
            ll A = i;
            ll B = sum / i;
            facs.pb(A);
            facs.pb(B);
        }
    }

    ll ans = 1;
    F0R(i, sz(facs)) {
        multiset<ll> vals;
        ll totalCost = 0;
        ll used = 0;

        F0R(j, N) {
            vals.insert(data[j] % facs[i]);
            totalCost += facs[i] - (data[j] % facs[i]);
        }
        for (auto it = vals.begin(); it != vals.end(); it++) {
            used += *it;
            totalCost -= facs[i] - *it;
            if (used == totalCost && used <= K) ans = max(ans, facs[i]);
        }
    }

    cout << ans << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343
// license: https://github.com/bqi343/USACO/blob/master/LICENSE


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	x := scanInt()

	fmt.Fprintln(wr, x/500*1000+x%500/5*5)
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

struct Node2 {
    int key;
    Node2 *left;
    Node2 *right;
    Node2 *parent;
public:
    Node2(Node2 *l, Node2 *r, Node2 *p, int k) : left(l), right(r), parent(p), key(k) {};
};

class BinarySearchTree2 {
private:
    Node2 *root;
    void preorder(Node2 node);
    void inorder(Node2 node);
public:
    void insert(int n);
    BinarySearchTree2() {root = 0;}
    void print() {
        inorder(*root);
        cout << endl;
        preorder(*root);
        cout << endl;
    }
    bool find(int n);
};

void BinarySearchTree2::preorder(Node2 node) {
    cout << " " << node.key;
    if (node.left != 0) {
        preorder(*node.left);
    }
    if (node.right != 0) {
        preorder(*node.right);
    }
}

void BinarySearchTree2::inorder(Node2 node) {
    if (node.left != 0) {
        inorder(*node.left);
    }
    cout << " " << node.key;
    if (node.right != 0) {
        inorder(*node.right);
    }
}

void BinarySearchTree2::insert(int n) {
    Node2 *z = new Node2(0,0,0,n);
    Node2 *y = 0;
    Node2 *x = root;
    while (x != 0) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        }else {
            x = x->right;
        }
    }
    z -> parent = y;
    if (y == 0) {
        root = z;
    }else if (z->key < y->key) {
        y->left = z;
    }else {
        y->right = z;
    }
}

bool BinarySearchTree2::find(int n) {
    Node2 *p = root;
    while(p != 0) {
        if (p->key < n) {
            p = p->right;
        }else if (p->key == n) {
            return true;
        }else {
            p = p->left;
        }
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    string s;
    BinarySearchTree2 tree;
    REP(i,n) {
        cin >> s;
        if (s[0] == 'i') {
            int j;
            cin >> j;
            tree.insert(j);
        }else if (s[0] == 'p'){
            tree.print();
        }else {
            int j;
            cin >> j;
            if (tree.find((j))) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int one = n%10;
  string ans;
  if (one == 3) {
      ans = "bon";
  } else if (one == 0 || one == 1 || one == 6 || one == 8) {
      ans = "pon";
  } else {
      ans = "hon";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>

int main(){
  int N, K;
  scanf("%d %d", &N, &K);
  long i;
  long sum = 0;
  long a = 1000000007;
  for (i = (long)K; i <= (long)N + 1L; i++) {
    //unsigned long min, max;
    //min = (i * (2 * 0 + i - 1)) / 2;
    //max = (i * (2 * N - i + 1)) / 2;
    long b = (((2L * i * (N - i + 1L)) / 2L) + 1L) % a;
    sum = (sum + b) % a;
    //printf("%lu\n", b);
  }
  printf("%ld\n", sum);
  return 0;
}

Measured memory_bytes: 1732
import collections
def main():
    N,M = map(int, input().split())
    A = [0]*M
    B = [0]*M
    road = [[] for i in range(N)]
    for i in range(M):
        A[i],B[i] = map(lambda x:x-1, map(int, input().split()))
        road[A[i]].append(B[i])
        road[B[i]].append(A[i])
    
    # 距離を1から増やしていけば高々O(N)で済む
    # 新しく行ける部屋が無くなったら終わり
    remainroom = [True for i in range(N)]
    sign = [-1]*N
    cur = [0]
    while len(cur)>0:
        # 行ける部屋全てについて
        new = []
        for i in cur:
            for j in road[i]:
                if remainroom[j]:
                    remainroom[j]=False
                    sign[j] = i
                    new.append(j)
        cur = new

    # 出力
    coll = collections.Counter(remainroom)
    if coll.get(True,0)>0:
        print("No")
    else:
        print("Yes")
        for i in range(1,N):
            print(sign[i]+1)

main()


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

int main(void){
	int n;
	int a[200];
	int swap = 0;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}


	for(int i=0; i<n; i++){
		for(int j=n-1; j>=i+1; j--){
			if(a[j] < a[j-1]){
				int temp = a[j];
				a[j] = a[j-1];
				a[j-1] = temp;
				swap++;
			}
		}
	}

	for(int i=0; i<n; i++){
		if(i!=n-1) printf("%d ", a[i]);
		else printf("%d\n", a[i]);
	}
	printf("%d\n", swap);
	
	return 0;
}

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

using namespace std;

class Cakes{
public:
    long a, b, c;
    Cakes(long a, long b, long c) : a(a), b(b), c(c){}

    bool operator<(const Cakes& other) const{
	return (a > other.a);
    }
};

void insert(priority_queue<pair<long, Cakes>>& q,
	    set<int>& tbl,
	    vector<long>& A,
	    vector<long>& B,
	    vector<long>& C,
	    long a, long b, long c){
    int h = (a << 20) + (b << 10) + c;
    long v = A.at(a)+B.at(b)+C.at(c);
    if(tbl.find(h) == tbl.end()){ // h is not found in tbl
	q.push(make_pair(v, Cakes(a,b,c)));
	tbl.insert(h);
    }
}

int main(){

    int X, Y, Z;
    int K;

    cin >> X >> Y >> Z >> K;

    vector<long> A(X);
    vector<long> B(Y);
    vector<long> C(Z);

    for(int i = 0; i < X; i++){
	cin >> A.at(i);
    }
    for(int i = 0; i < Y; i++){
	cin >> B.at(i);
    }
    for(int i = 0; i < Z; i++){
	cin >> C.at(i);
    }

    sort(A.begin(), A.end()); reverse(A.begin(), A.end());
    sort(B.begin(), B.end()); reverse(B.begin(), B.end());
    sort(C.begin(), C.end()); reverse(C.begin(), C.end());

    priority_queue<pair<long, Cakes>> q;
    set<int> tbl;

    insert(q, tbl, A, B, C, 0, 0, 0);

    vector<long> ans;
    while(ans.size() < K){
	auto v = q.top(); q.pop();
	ans.push_back(v.first);
	int a, b, c;
	a = v.second.a;
	b = v.second.b;
	c = v.second.c;
	if(a != X-1){
	    insert(q, tbl, A, B, C, a+1, b, c);
	}
	if(b != Y-1){
	    insert(q, tbl, A, B, C, a, b+1, c);
	}
	if(c != Z-1){
	    insert(q, tbl, A, B, C, a, b, c+1);
	}
    }

    sort(ans.begin(), ans.end()); reverse(ans.begin(), ans.end());
    for(auto a: ans){
	cout << a << endl;
    }
    
    /*
    vector<long> BC;
    
    for(long b: B){
	for(long c: C){
	    BC.push_back(b + c);
	}
    }
    sort(BC.begin(), BC.end()); reverse(BC.begin(), BC.end());

    vector<long> ABC;
    for(int i = 0; i < min(K, (int)BC.size()); i++){
	for(int j = 0; j < min(K, (int)A.size()); j++){
	    ABC.push_back(A.at(j) + BC.at(i));
	}
    }
    sort(ABC.begin(), ABC.end()); reverse(ABC.begin(), ABC.end());

    for(int i = 0; i < K; i++){
	cout << ABC.at(i) << endl;
    }
    */    
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;

int main(){
  int n,cnt=1;
  cin>>n;
  if(n==1 || n==2){cout<<4<<endl;return 0;}
  while(n!=4){
    if(n%2==0) n/=2;
    else n=(n*3)+1;
    cnt++;
  }
  cout<<cnt+3<<endl;
  return 0;
}


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

int main() {
  int N, num, ans;
  cin >> N;
  ans = 0;
  for (int i = 1; i < N+1; i += 2) {
    num = 0;
    for (int j = 1; j < i+1; j++) {
      if (i % j == 0) {
        num++;
      }
    }
    if (num == 8) {
      ans++;
    }
  }
  cout << ans <<endl;
}


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

int main() {

	int n, capac;
	scanf("%d", &n);
	scanf("%d", &capac);
	
	unsigned long peso[n];
	unsigned long valor[n];
	unsigned long mPesVal[capac+1];
	
	for(int i = 0;i < n;i++){
		//scanf("%lu", (peso+i));
		//scanf("%lu", (valor+i));
		
		cin >> *(peso + i) >> *(valor + i);
	}
	
	for(int i = 0;i <= capac;i++){
		*(mPesVal + i)=0;
	}
	for(int i = 0;i < n;i++){
		for(int j = capac;j >= peso[i];j--){
		  *(mPesVal + j) = max(*(mPesVal + j), (*(mPesVal + (j - *(peso + i))) + *(valor + i)));
		  //printf("*(dp + %d) = %x\n", j, *(dp + j));
		}
	}
	
	cout << *(mPesVal + capac) << endl;
	//return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n;
bool ok[22][22];
ll d[22][2097153];
ll md=1e9+7;
int main()
{
	cin >>n;
	for (int i=0;i<n;i++) 
		for (int j=0;j<n;j++)
			cin >>ok[i][j];
	for (int i=0;i<n;i++) d[0][1<<i]=ok[0][i];
	for (int i=1;i<n;i++)
	{
		for (int j=0;j<(1<<n);j++)
		{
			if (__builtin_popcount(j)!=i+1) continue;
			for (int k=0;k<n;k++)
			{
				if (!ok[i][k] || !(j&(1<<k))) continue;
				d[i][j]=(d[i][j]+d[i-1][j^(1<<k)])%md;
			}
		}
	}
	cout <<d[n-1][(1<<n)-1];
	return 0;
}

Measured memory_bytes: 309504
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    S = input()
    S += "$"

    ans = 0 
    cnt = 0
    for s in S: 
        if s in ('A', 'T', 'C', 'G'):
            cnt += 1
        else:
            ans = max(ans, cnt)
            cnt = 0

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8960
#include <bits/stdc++.h>
typedef long long LL;

const LL mod = 998244353;

LL add(LL x, LL y) {return (x+y)%mod;}
LL mul(LL x, LL y) {return (x*y)%mod;}
LL pow2(LL n)
{
	LL ret = 1, tmp = 2;
	while (n)
	{
		ret = mul(ret, tmp);
		tmp = mul(tmp, tmp);
		n >>= 1;
	}
	return ret;
}

const int maxN = 3003;
LL dp[maxN][maxN], nums[maxN];
LL N, S;

int main()
{
	LL ans = 0;
	std::cin >> N >> S;
	for (int i=0; i<N; ++i) std::cin >> nums[i];
	std::sort(nums, nums+N);
	dp[0][0] = 1;
	for (int i=0; i<N; ++i)
		for (int x=0; x<=S; ++x)
	{
		dp[i+1][x] = dp[i][x]*2%mod;
		if (x-nums[i] >= 0)
			dp[i+1][x] = (dp[i+1][x] + dp[i][x-nums[i]])%mod;
	}
	std::cout << dp[N][S];
}

Measured memory_bytes: 74040
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int N, S;
vector<int> A;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S;
		A.push_back(S);
	}
	sort(A.begin(), A.end());
	A.erase(unique(A.begin(), A.end()), A.end());
	if (N == A.size()) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int main() {
  // 庭の動物の総数
  int X;
  // 足の総数
  int Y;
  
  cin >> X >> Y;
  
  bool exist = false;
  
  if (X * 2 == Y) {
    cout << "Yes" << endl;
    return 0;
  } else if (X * 4 == Y) {
    cout << "Yes" << endl;
    return 0;
  } else {
  	for (int i = 0; i < X; i++) {
  		int turu = 2 * (i +1);
  	  int kame = 4 * (X - (i +1));
    
  	  if (turu + kame == Y) {
    	exist = true;
      	break;
 	   }
  	}
    
    if (exist) {
  		cout << "Yes" << endl;
  	} else {
  		cout << "No" << endl;
 	 }
  }

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  map<char, ll> mp;
  rep(i, s.size()) mp[s[i]]++;
  bool ans = true;
  if(mp['N'] > 0 && mp['S'] == 0) ans = false;
  if(mp['S'] > 0 && mp['N'] == 0) ans = false;
  if(mp['W'] > 0 && mp['E'] == 0) ans = false;
  if(mp['E'] > 0 && mp['W'] == 0) ans = false;
  cout << (ans ? "Yes" : "No") << endl;
}

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

const int MAXN = 300005;

char str[MAXN];

int a[MAXN], b[MAXN], c[MAXN], d[MAXN], n;

int main()
{
	scanf("%d", &n);
	scanf("%s", str+1);
	for (int i = 1; i <= n; i++) {
		a[i] = b[i] = (str[i] == 'E');
		c[i] = d[i] = (str[i] == 'W');
	}
	for (int i = 1; i <= n; i++) a[i] += a[i-1], c[i] += c[i-1];
	for (int i = n; i >= 1; i--) b[i] += b[i+1], d[i] += d[i+1];
	int ans = n;
	for (int i = 1; i <= n; i++)
		ans = min(ans, b[i+1]+c[i-1]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5248
import math
N = int(input())
A = sorted([int(v)-i for i, v in enumerate(input().split(), start=1)])

if N % 2 == 1:
    ans = sum([abs(a-A[N//2]) for a in A])
else:
    b0 = (A[N//2-1]+A[N//2])//2
    b1 = math.ceil(A[N//2-1]+A[N//2])
    ans = min(sum([abs(a-b0) for a in A]), sum([abs(a-b1) for a in A]))

print(ans)


Measured memory_bytes: 26608
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
 
  int main(){
    ll n,k,s;cin>>n>>k>>s;
    vector<ll>p(n);
    int count=0;
    for(int i=0;i<n;i++)
    {
       if(count<k)
       {
         p.at(i)=s;
         count++;
       }
      else if(s!=1e9)
        p.at(i)=1e9;
      else
        p.at(i)=1e9-1;
    }
    for(int i=0;i<n;i++)
      cout<<p.at(i)<<" ";
  }
      
      
      
      
    


Measured memory_bytes: 2048
n, m, x = map(int, input().split())
c = [0 for i in range(n)]
a = [[0 for j in range(m)] for i in range(n)]

for i in range(n):
  ary = list(map(int, input().split()))
  c[i] = ary[0]
  for j in range(m):
    a[i][j] = ary[j + 1]

ans = 10 ** 10
for i in range(2 ** n):
  cost = 0
  point = [0 for i in range(m)]
  for j in range(n):
    if i & (2 ** j) > 0:
      cost += c[j]
      for k in range(m):
        point[k] += a[j][k]
  flag = True
  for j in range(m):
    if point[j] < x:
      flag = False
      break
  if flag:
    ans = min(ans, cost)

print(ans if ans < 10 ** 10 else -1)

Measured memory_bytes: 9260
use std::cmp::max;
use std::cmp::min;

use itertools::Itertools;

fn solve(n: usize, ps: &[u64], qs: &[u64]) -> usize {
    let mut p = 0;
    let mut q = 0;
    for (i, v) in (1..=n as u64).permutations(n).enumerate() {
        if v == ps {
            p = i
        }
        if v == qs {
            q = i
        }
    }
    max(q, p) - min(q, p)
}

fn main() {
    let n = read_1();
    let ps = read_vec();
    let qs = read_vec();

    println!("{}", solve(n, &ps, &qs));
}

// utils

fn read_1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|c| c.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2164
ls = []
cnt = 2
while 1:
    ls1 = list(map(int,input().split()))
    if ls1[0] == 0 and ls1[1] == 0:
        break
    else:
        ls.append(list(ls1))
        ls1.clear()
for i in range(len(ls)):
    for j in range(ls[i][0]):
        for l in range(ls[i][1]):
            #print("cnt",cnt)
            if j%2==0:
                if cnt%2==0:
                    print("#",end="")
                    cnt += 1
                else:
                    print(".",end="")
                    cnt +=1
            else:
                if cnt%2==0:
                    print(".",end="")
                    cnt += 1
                else:
                    print("#",end="")
                    cnt +=1
        cnt = 2
        print()
    print()



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

#define rep(i, n) for(int (i) = 0; i < (n); ++(i))

using ll = long long int;
const ll MOD = 1e9 + 7;

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

  std::map<ll, int> mp;
  rep(i, N) {
    ll A;
    std::cin >> A;
    if(mp[A] != 0) {
      std::cout << "NO" << '\n';
      return 0;
    } else {
      ++mp[A];
    }
  }
  std::cout << "YES" << '\n';
}


Measured memory_bytes: 12800
import java.io.*;
import java.util.*;

public class Main {
	static final int MOD = 1_000_000_007;

	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int l = sc.nextInt();
		
		int[] a = new int[n];
		
		int index = 0;
		int e = 100;
		
		//一番0に近いのを選ぶ
		
		for(int i = 0; i < n; i++) {
			a[i] = l + (i+1) - 1;
			if(Math.abs(a[i]) <= Math.abs(e)) {
				e = a[i];
				index = i;
			}
		}
		
		int res = 0;
		
		for(int i = 0; i < n; i++) {
			if(i != index) {
				res+=a[i];
			}
		}
		
		out.println(res);
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

	public static long min(long... a) {
		long min = Long.MAX_VALUE;
		for(int i = 0; i < a.length; i++) {
			if(a[i] < min) min = a[i];
		}
		return min;
	}

	public static long max(long... a) {
		long max = Long.MIN_VALUE;
		for(int i = 0; i < a.length; i++) {
			if(a[i] > max) max = a[i];
		}
		return max;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21204
S = str(input())

S_list = [int(S[:2]), int(S[2:])]


if 1 <= S_list[1] and S_list[1] <= 12 and 1 <= S_list[0] and S_list[0] <= 12:
    print('AMBIGUOUS')
elif 1 <= S_list[1] and S_list[1] <= 12:
    print('YYMM')
elif  1 <= S_list[0] and S_list[0] <= 12:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 38256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
    int n;
    cin>>n;
    int t, a;
    cin >> t >> a;
    vi v(n);
    rep(i,n){
        cin>>v[i];
    }
    double min = 1<<30;
    int ans;
    rep(i, n)
    {
        double aa = t - 0.006 * v[i];
        double dist = fabs(aa - a);
        if (min > dist)
        {
            min = dist;
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int cnt;
bool query(long long x)
{
    cnt++;
    assert(cnt <= 64 && 1 <= x && x <= (long long)(1e18));

    printf("? %lld\n", x);
    fflush(stdout);
    char c;
    scanf(" %c", &c);
    return c == 'Y';
}

void ans(long long x)
{
    printf("! %lld\n", x);
    fflush(stdout);
    exit(0);
}

int main()
{
    int i;
    long long q = 10;
    bool ok = 0;
    for(i = 0; i < 9; i++)
    {
        if(!query(q))
        {
            ok = 1;
            break;
        }
        q *= 10;
    }

    if(!ok)
    {
        // 1, 10, ..., 10^9
        int s = 0;
        int g = 9;
        while(s < g)
        {
            int x = (s + g) / 2;
            long long q = 5;
            for(i = 0; i < x; i++)
                q *= 10;

            if(query(q))
                g = x;
            else
                s = x + 1;
        }

        long long q = 1;
        for(i = 0; i < s; i++)
            q *= 10;
        ans(q);
    }
    else
    {
        // [q/10+1 , q-1]
        long long s = q / 10 + 1;
        long long g = q - 1;
        while(s < g)
        {
            long long x = (s + g) / 2;
            long long q = x * 10;
            if(query(q))
                g = x;
            else
                s = x + 1;
        }
        ans(s);
    }
    return 0;
}

Measured memory_bytes: 596
import java.util.Scanner
import scala.io.StdIn._

object Main extends App {

  val k = readInt()
  val Array(a, b) = readLine().split(" ").map(_.toInt)


  def solve(): String = {
    val largest = (b/k) * k
    if(largest >= a) "OK" else "NG"
  }

  println(solve())

}



Measured memory_bytes: 54756
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 998244353;

long long int N, M, K, H, W, L, R;


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

	cin >> K >> N;
	vector<vector<int>>ncr(4001, vector<int>(2001,0));
	ncr[0][0] = 1;
	for (int i = 1; i <= 4000; i++) {
		ncr[i][0] = 1;
		for (int j = 1; j <= 2000; j++) {
			ncr[i][j] = ncr[i - 1][j - 1] + ncr[i - 1][j];
			ncr[i][j] %= MOD;
		}
	}
	vector<long long int>ans;
	vector<long long int>by(4001,1);
	for (int i = 1; i <= 4000; i++) {
		by[i] = by[i - 1] * 2;
		by[i] %= MOD;
	}
	for (int i = 2; i <= K * 2; i++) {
		if (i % 2) {
			int two = 0;
			int one = K;
			for (int j = 1; j <= K; j++) {
				if (i - j >= 1 && i - j <= K && i - j > j) {
					two++;
					one -= 2;
				}
			}
			//cout << i << " " << two << " " << one << endl;
			long long int ret = 0;
			for (int j = 0; j <= two; j++) {
				if (one + j - 1 >= 0) {
					long long int box = 0;
					box += ncr[two][j] * by[j];
					box %= MOD;
					box *= ncr[N + one - 1][one + j - 1];
					box %= MOD;
					ret += box;
					ret %= MOD;
				}
			}
			ans.push_back(ret);
		}
		else {
			long long int ret = 0;
			int two = 0;
			int one = K - 1;
			for (int j = 1; j <= K; j++) {
				if (i - j >= 1 && i - j <= K && i - j > j) {
					two++;
					one -= 2;
				}
			}
			//cout << i << " " << two << " " << one << endl;
			for (int j = 0; j <= two; j++) {
				long long int box = 0;
				if (one + j - 1 >= 0) {
					box += ncr[two][j] * by[j];
					box %= MOD;
					box *= ncr[N + one - 1][one + j - 1];
					box %= MOD;
					ret += box;
					ret %= MOD;
				}
			}
			for (int j = 0; j <= two; j++) {
				long long int box = 0;
				if (one + j - 1 >= 0) {
					box += ncr[two][j] * by[j];
					box %= MOD;
					box *= ncr[N + one - 2][one + j - 1];
					box %= MOD;
					ret += box;
					ret %= MOD;
				}
			}
			ans.push_back(ret);
		}
	}
	for (auto i : ans)cout << i << endl;
	return 0;
}

Measured memory_bytes: 31872
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	bool flag1, flag2, flag3;
	int count = 0;
	for(int i = 0; i < 1000; i++) { //000~999まで
		flag1 = false;
		flag2 = false;
		flag3 = false;
		//それぞれの位の値を取得
		int tmp = i;
		int hundred_pl = tmp / 100;
		tmp = tmp % 100; 
		int ten_pl = tmp / 10;
		tmp %= 10;
		int one_pl = tmp;
		for(int j = 0; j < n; j++) {
			if(!flag1 && (s.at(j) - '0' == hundred_pl)) {
				flag1 = true;
				continue;
			} 
			if(flag1 && !flag2 && (s.at(j) - '0' == ten_pl)) {
				flag2 = true;
				continue;
			}
			if(flag1 && flag2 && (s.at(j) - '0' == one_pl)) {
				// cout << s.at(j) << " " << one_pl << endl;
				// cout << " " <<  j << endl;
				flag3 = true;
				break;
			}
		}
		if(flag3) {
			count++;
		}
	}
	std::cout << count << endl;
}

Measured memory_bytes: 256