akhauriyash/Code-Regression huggingface dataset:
#include<set>
#include<cstdio>
#include<algorithm>
using namespace std;

#define MAXN 100000
int N;
int A[MAXN+5];

int main(){
    scanf("%d",&N);
    long long Sum=0;
    for(int i=1;i<=N;i++){
        scanf("%d",&A[i]);
        Sum+=A[i];
    }
    long long All=1ll*N*(N+1)/2;
    if(Sum%All)
        return !puts("NO");
    int k=Sum/All;
    for(int i=1;i<=N;i++){
        int d=A[i]-A[i-1==0?N:i-1];
        if(d-k>0||(k-d)%N!=0)
            return !puts("NO");
    }
    puts("YES");
}


Measured memory_bytes: 640
#include <cstdio>
#include <utility>
using namespace std;

int m,n,o[21];
pair<int,int> t[100];

int main(){
	scanf("%d%d",&m,&n);
	for(int i = 0; i < n; i++){
		scanf("%d%d",&t[i].first,&t[i].second);
	}
	for(int i = 1; i <= m; i++){
		o[i] = i;
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(o[t[j].first] > o[t[j].second]){
				int tmp = o[t[j].first];
				o[t[j].first] = o[t[j].second];
				o[t[j].second] = tmp;
			}
		}
	}
	for(int i = 1; i <= m; i++){
		for(int j = 1; j <= m; j++){
			if(o[j] == i){
				printf("%d\n",j);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 2760
#include<stdio.h>


int main()
{
	char a[26];
	int x = 0;
	scanf("%s",a);
	for (int i = 0; i < 26; i++) {
		for (int j = i+1; j < 26; j++) {
			if (a[i] == a[j]&&a[i]!=0)
				x++;
		}
	}
	if (x == 0) {
		printf("yes");
	}
	else {
		printf("no");
	}

    return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 300010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-6
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
char ch;
int main() {
	io(); cin >> ch;
	ch++;
	cout << ch;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

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

  char c;
  std::cin >> c;

  char d = (char)(c + 1);
  std::cout << d << std::endl;
}


Measured memory_bytes: 256
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int d, g;
    cin >> d >> g;
    vector<int> p(d), c(d);
    rep(i,d) cin >> p[i] >> c[i];
    int ans = INF;
    rep(is,1<<d) {
        int sum = 0;
        int now = 0;
        int mx = -1;
        rep(i,d) {
            if (is>>i&1) {
                sum += 100*(i+1)*p[i];
                sum += c[i];
                now += p[i];
            }
            else mx = i;
        }
        if (sum < g) {
            int x = 100*(mx+1);
            sum = g - sum;
            if ((sum+x-1)/x >= p[mx]) continue;
            now += (sum+x-1)/x;
        }
        ans = min(ans, now);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int n,m;

        n = s.nextInt();
        m = s.nextInt();

        ArrayList<Integer>[] adj = new ArrayList[3*n+5];
        for(int i=0;i<3*n+5;i++)
            adj[i] = new ArrayList<>();

        int a,b,src,dest;

        for(int i =0;i<m;i++)
        {
            a = s.nextInt();
            b = s.nextInt();

            adj[a].add(b+n);
            adj[a+n].add(b+2*n);
            adj[a+2*n].add(b);
        }

        src = s.nextInt();
        dest = s.nextInt();
        int[] dist = new int[3*n+5];
        for(int i=0;i<3*n+5;i++)
            dist[i]=-1;

        bfs(adj,dist,src,dest,n);

        if(dist[dest]==-1)
            System.out.println(-1);
        else
            System.out.println(dist[dest]/3);

    }

    static void bfs(ArrayList<Integer>[] adj,int[] dist,int src,int dest,int n)
    {
        Queue<Integer> q = new LinkedList<Integer>();
        q.add(src);

        dist[src] =0;
        while(q.size()>0)
        {
            int v = q.peek();
            q.remove();

            for(int u:adj[v])
            {
                if(dist[u]==-1)
                {
                    dist[u]=dist[v]+1;
                    q.add(u);
                }
            }
        }
    }
}

Measured memory_bytes: 123064
/*
[abc140] A - Password
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

int N;

ll solve() { return N * N * N; }

int main() {
    cin >> N;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let () =
        Scanf.sscanf (read_line ()) "%d" (
                fun n -> 
                        List.range 0 `To 7
                        |> List.map (fun elmnt ->
                                Int.pow 2 elmnt
                        )
                        |> List.filter (fun elmnt ->
                                elmnt <= n
                        )
                        |> List.max
        ) |> Printf.printf "%d\n"


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
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;}

int main(){
    double pi = 3.14159265;
    double r;cin >> r;
    cout << fixed << setprecision(12) << r*pi*2 << endl;
}

Measured memory_bytes: 3784
N,K = map(int,input().split())
INF = 10**12
Data = list(map(int,input().split()))
Data.insert(0,0)
DP = [INF]*(N+1)
DP[1]=0
for i in range(2,N+1):
    for j in range(1,K+1):
        if i-j >= 1:
            diff = abs(Data[i]-Data[i-j])
            DP[i] = min(DP[i],DP[i-j]+diff)
print(DP[N])

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

int main(void)
{
    int A, B;
    string S;
    cin >> A >> B;
    cin >> S;

    bool isPostalCode = true;

    if(S[A] != '-'){
        cout << "No" << endl;
        return 0;
    }

    for(int i = 0; i < (A + B + 1); i++){
        if(i == A)
            continue;

        if(S[i]  < '0' || S[i] > '9'){
            cout << "No" << endl;
            return 0;
        
        }
    }

    cout << "Yes" << endl;
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    
    constexpr int maxn = 2000 * 2000 + 1;
    
    bitset<maxn> g;
    
    g[0] = 1;
    
    int sums = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        sums += x;
        g = g | (g << x);
    }
    
    sums = (sums + 1) / 2;
    while (!g[sums]) {
        sums++;
    }
    
    cout << sums << endl;
    
    
    return 0;
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define lint long long
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;

lint ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	double l; cin>>l;
	long double ans = (l/3)*(l/3)*(l/3);
	cout<<fixed;
	cout<<setprecision(10)<<ans<<endl;
    return 0;
}

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

int main(){
    ll A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A), t(B), x(Q);
    for(ll i=0LL; i<A; i++){
        cin >> s[i];
    }
    for(ll i=0LL; i<B; i++){
        cin >> t[i];
    }
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    for(ll i=0LL; i<Q; i++){
        cin >> x[i];
    }

    for(int i=0; i<Q; i++){
        ll ans=0LL;
        decltype(s)::iterator its = upper_bound(s.begin(), s.end(), x[i]);
        decltype(t)::iterator itt = upper_bound(t.begin(), t.end(), x[i]);

        ll sl = *its, tl = *itt;
        if(its==s.end())sl=3e10;
        if(itt==t.end())tl=3e10;

        ll ss = *(its-1), ts = *(itt-1);
        if(its==s.begin())ss=-3e10;
        if(itt==t.begin())ts=-3e10;

        if( sl < tl ){
            ans = min( x[i] + sl - 2*ts, -x[i] + 2*sl - ts );
            ans = min( ans, tl - x[i] );
            ans = min( ans, x[i] - min(ss,ts) );
        }else{
            ans = min( x[i] + tl - 2*ss, -x[i] + 2*tl - ss );
            ans = min( ans, sl - x[i] );
            ans = min( ans, x[i] - min(ss,ts) );
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3712
/*                                  /   \                                 */      
/*                                 /*****\                               */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K             */
#include<vector>
#include<iostream>
#include<algorithm>                
#include<string.h>                 
#include<bits/stdc++.h>            
#include<cstring>                  
#include<map>                     
#include<cmath>                  
#include<set>
using namespace std;            
#define ll long long int        
#define ld long double
#define MOD 1000000007 
#define PI 3.1415926535897932384626433832795                                               
#define YY cout<<"YES"
#define NN cout<<"NO"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back 
#define fi first
#define se second
#define mkp make_pair    
#define sall(v ) sort(v.begin(), v.end())      
#define all(v )  v.begin(), v.end()      
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vll vector< pair<ll,ll> > 
#define mpl map<ll, ll>
#define pr pair<ll,ll>
ll pow1(ll n,ll p){if(p==0)return 1;ll x=pow1(n, p/2);x=(x*x);if(p%2==0) return x;else return (x*n);}
ll pd(ll x,ll y){if(x%y==0) return x/y;else return x/y+1;}  
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);	
	  ll t=1;


//	   cin>>t;
	      while(t--)
{
ll n,m,j,k,l,i;
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll ans=a*c;
if(a*b<=0||c*d<=0)
ans=0;
ans=max(ans,max(max(a*c,a*d),max(b*c,b*d)));
cout<<ans;
ee;

		
}
return 0;
}









Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  int a, b;
  cin >> a >> b;
  /*
  if(abs(a-b) > 20){
    cout << "-1\n";
    return 0;
  }*/

  int res = b*10;
  bool flg = false;
  REP(i,10){
    if(floor((res+i)*0.08) == a){
      res += i;
      flg = true;
      break;
    }
  }

  if(flg == false) res = -1;
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(void) {
    string num;

    cin>>num;
    int h = 0,sum = 0;
    for(int i = 0;i < num.size();i++) {
        h += num[i]-'0';
        sum = sum*10+num[i]-('0');
    }

    if(sum % h == 0) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;

#define MOD (int)(1e9+7)

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

int main() {
	int X,Y;cin>>X>>Y;

	if ((X + Y) % 3 || Y>2*X || X>2*Y)
	{
		cout<<0<<endl;
		return 0;
	}

	int dist = (X + Y)/3;

	int c = min(X-dist, Y-dist);

	long long ans = 1;
	for (int i = 0; i < c; i++)
	{
		ans *= dist-i;
		ans %= MOD;
		ans *= modinv(i+1, MOD);
		ans %= MOD;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = min(A)+min(B)
for i in range(m):
    x,y,c = map(int,input().split())
    tmp = A[x-1]+B[y-1]-c
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 70468
#include<stdio.h>
#include<math.h>
int main()
{
    int n, m, q, i, c, k, score=0, max;
    scanf("%d%d%d", &n, &m, &q);

    int seq[n], ai[50], bi[50], ci[50], di[50];

    for(i=0; i<q; i++){
        scanf("%d%d%d%d",  &ai[i], &bi[i], &ci[i], &di[i]);
    }

    for(i=0; i<n; i++){
        seq[i]=1;
    }
    max=score;
    while(1){

        score=0;
        for(i=0; i<q; i++){
            if((seq[bi[i]-1]-seq[ai[i]-1])==ci[i]){
                score+=di[i];
            }
        }
        if(max<score){
            max=score;
        }

        if(seq[0]==m) break;

        seq[n-1]++;

        if(seq[n-1]>m){
            for(c=n-1; c>=0; c--){
                if(seq[c]>m){
                    seq[c-1]++;
                    for(k=c; k<n; k++){
                        seq[k]=seq[c-1];
                    }
                }
                else break;
            }
        }
    }

    printf("%d\n", max);
    return 0;
}


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

int n,s;

int recursion(int sum,int num,int cnt){
  if(sum > s || cnt > n) return 0;
  if(cnt == n && sum == s) return 1;
  if(num > 9) return 0;
  int hoge = 0;
  hoge += recursion(sum+num,num+1,cnt+1);
  hoge += recursion(sum,num+1,cnt);
  return hoge; 
}

int main(){
  while(cin >> n >> s,n||s){
    cout << recursion(0,0,0) << endl;
  }
}

Measured memory_bytes: 1160
import std.stdio;
import std.string;

void main() {
	int H, W;
	string [] S;
	readf("%d %d\n", &H, &W);
	for(int i = 0; i < H; i++) {
		string s_;
		readf("%s\n", &s_);
		S ~= s_;
	}
	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			int [] dx = [ 1, 1, 1, 0, 0, 0,-1,-1,-1];
			int [] dy = [ 1, 0,-1, 1, 0,-1, 1, 0,-1];
			
			int cnt = 0;
			for(int k = 0; k < dx.length; k++) {
				int y = i+dy[k];
				int x = j+dx[k];
				if(0 <= y && y < H && 0 <= x && x < W) {
					cnt += S[y][x] == '#';
				}
			}
			if(S[i][j] == '#')
				writef("#");
			else
				writef("%d",cnt);
		}
		writeln();
	}
}


Measured memory_bytes: 636
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M = map(int, readline().split())

    is_solved = [False] * (N + 1)
    wa_cnt = [0] * (N + 1)

    for _ in range(M):
        p, s = readline().split()
        p = int(p)
        if s == "WA":
            if is_solved[p]:
                continue
            else:
                wa_cnt[p] += 1
        else:
            is_solved[p] = True

    ac = 0
    pena = 0
    for i in range(1, N+1):
        if is_solved[i]:
            ac += 1
            pena += wa_cnt[i]

    print(ac, pena)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4596
d = int(input())
cl = list(map(int, input().split()))
sl = []
for _ in range(d):
    sl.append(list(map(int, input().split())))

tl = []
# for _ in range(d):
#     tl.append(int(input()))

last_di = [-1]*26
ans = 0
for day in range(d):
    best_t = 0
    best_t_val = -999999999999
    for t in range(26):
        curr_val = sl[day][t]
        for i in range(26):
            if i == t: continue
            curr_val -= (day-last_di[i])*cl[i]
        if curr_val >= best_t_val:
            best_t = t
            best_t_val = curr_val
    tl.append(best_t+1)
    last_di[best_t] = day
    ans += best_t_val
    # print(ans)
    # print('-- {}---'.format(day))
    # print(best_t)
    # print(last_di)

for t in tl:
    print(t)

# for day, t in enumerate(tl):
#     ans += sl[day][t-1]
#     last_di[t-1] = day
#     for ld, c in zip(last_di, cl):
#         # if ld == -1: continue
#         ans -= (day-ld)*c
#     print(ans)

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/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(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vi a(n), b(n);
  rep(i,n) cin >> a[i] >> b[i];
  sort(all(a));
  sort(all(b));
  int ans;
  if(n % 2 == 1) {
    ans = b[n/2] - a[n/2] + 1;
  }
  else {
    ans = (b[n/2-1]+b[n/2]) - (a[n/2-1]+a[n/2]) + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4800
n=int(input())
S=[input() for _ in range(n)]

check=['M','A','R','C','H']
cnt=[0]*5
for i in range(n):
  for j in range(5):
    if S[i][0]==check[j]:
      cnt[j]+=1
      break
ans=0
for i in range(2**5):
  tmp=1
  flag=0
  for j in range(5):
    if i>>j&1:
      tmp*=cnt[j]
      flag+=1
  if flag==3:
    ans+=tmp
print(ans)

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

int main() {
  long long int X;
  cin >>X;
  if(X==0){
    cout<<0<<endl;
    return 0;
  }
  long long int amari=0;
  long long int shou;
  shou=X/500;
  amari=X%500;
  long long int kotae=shou*1000+amari/5*5;
  cout<<kotae <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
  const char* dlm = "";
  for(const auto& x:v) os << exchange(dlm, " ") << x;
  return os;
}
template<typename T>
T ncr(T n, T r){
  T ret=1;
  for(size_t i=n-r+1; i<=n; ++i) ret*=i;
  for(size_t i=1; i<=r; ++i) ret/=i;
  return ret;
}
int32_t main(){
  size_t n; cin>>n;
  vector<int64_t> a(n),s(n+1); for(auto&& x:a) cin>>x;
  s[0]=0; for(size_t i=1; i<n+1; ++i) s[i]=s[i-1]+a[i-1];
  // cout<<s<<endl;
  std::map<int64_t,size_t> m;
  for(const auto& x:s) ++m[x];
  // for(const auto& [k,v]:m) cout<<k<<' '<<v<<'\n';

  size_t ret=0;
  for(const auto& x:m){
    if(x.second>1) ret+=ncr<size_t>(x.second, 2);
  }
  cout<<ret<<endl;
}

Measured memory_bytes: 15872
N = gets.to_i
X = gets.split.map(&:to_i)

m = X.sort

lv = m[(N - 1) / 2]
rv = m[N / 2]

X.each do |x|
  if lv == rv
    puts lv
  elsif x <= lv
    puts rv
  else
    puts lv
  end
end


Measured memory_bytes: 23396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n, m, k;
    cin >> n >> m >> k;
    rep(i, 0, m + 1) {
        rep(j, 0, n + 1) {
            int sum = (n - j) * i + (m - i) * j;
            if (sum == k) {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl = vector<ll>; using vvl = vector<vl>;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
    ll n,m,k;cin >> n >> m >> k;
    vl a(0);
    a.push_back(0);
    rep(i,n){
        ll p = 0;cin >> p;
        a.push_back(a[a.size() - 1] + p);
    }
    vl b(0);
    b.push_back(0);
    rep(i,m){
        ll p = 0;cin >> p;
        b.push_back(b[b.size() - 1] + p);
    }
    ll Ans = 0;
    int x = m;
    rep(i,a.size()){
        if(a[i] > k) break;
        while(b[x]>k-a[i]&&x>=0) x--;
        Ans = max(Ans, i+x);
    }
    cout << Ans << endl;
}

Measured memory_bytes: 7992
N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = int(1E9+7)

C = []
for i in range(N-1):
    a = A[i]
    p = 0
    for j in range(i+1, N):
        if A[j] < a:
            p += 1
    C.append(p)
C.append(0)

D = []
for i in range(N):
    a = A[i]
    q = 0
    for j in range(N):
        if A[j] < a:
            q += 1
    D.append(q)

ans = 0
for i in range(N):
    ans += C[i]*K + D[i]*K*(K-1)//2
    ans = ans % mod
print(ans)

Measured memory_bytes: 42332
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	static final int MOD = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		//入力
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		//処理

		//出力
		if(Math.abs(a-b) <= w){
			out.println(0);
		}else{
			out.println(Math.min(Math.abs(b - a - w), Math.abs(a - b - w)));
		}
		out.flush();
	}
}

Measured memory_bytes: 23888
import java.util.Scanner;

public class Main {

  public static void main(final String[] args) {
    final var scanner = new Scanner(System.in);
    final var S = scanner.nextInt();

    switch (S % 10) {
      case 3:
        System.out.println("bon");
        break;
      case 0:
      case 1:
      case 6:
      case 8:
        System.out.println("pon");
        break;
      default:
        System.out.println("hon");
        break;
    }
  }
}


Measured memory_bytes: 35788
#include<stdio.h>
#include<string.h>
int main()
{
	char s[10];
	char c[10];
	scanf("%s",s);
	int l=strlen(s);
	int i=0,j=0;
	//printf("%s %d\n",s);
	while(i<l)
	{
		if(s[i]=='B'&&j>0)
			j--;
		else if(s[i]!='B')
		{
			c[j]=s[i];
			j++;
		}
		i++;
	}
	for(i=0;i<j;i++)
		printf("%c",c[i]);
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int main() {
   ll N, Y;
   cin >> N >> Y;
   for (int i = 0; i <= 2000; i++) {
      for (int j = 0; j <= 2000; j++) {
         int k = N - i - j;
         if (k >= 0 && k <= 2000 && 10000*i + 5000*j + 1000*k==Y) {
            printf("%d %d %d\n", i, j, k);
            return 0;
         }
      }
   }
   printf("%d %d %d\n", -1 , -1, -1);

   return 0;
}

Measured memory_bytes: 256
N = int(input())
line1 = input().split()
line2 = input().split()
valueList = [0]*N

def sumL1(n):
    work = 0
    for i in range(n+1):
        work += int(line1[i])
    return work

def sumL2(n):
    work =0
    for i in range(n,N):
        work += int(line2[i])
    return work
    
    
for i in range(N):
    valueList[i] = sumL1(i) + sumL2(i)
print(max(valueList))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
ld eps=1e-9;

struct op {
	long long int damage;
	long long int turn;
};
bool operator < (const op&l, const op&r) {
	return ld(l.damage)/ld(l.turn) > ld(r.damage)/ld(r.turn);
}
int main() {
	int N; cin >> N;
	int T, A, D, S; cin >> T >> A >> D >> S;
	vector<op>ops;
	long long int gettotal = 0;
	for (int i = 0; i < N; ++i) {
		long long int t, a, d, s; cin >> t >> a >> d >> s;
		
		const long long int getdam = max(0ll,a - D);
		if (s < S) {
			gettotal -= getdam;
		}
		const long long int mydam = A - d;
		if (mydam <= 0) {
			if (getdam <= 0) {
				continue;
			}
			else {

				cout << -1 << endl;
				return 0;
			}
		}
		else {
			const long long  int turn = (t-1) / mydam+1;
			ops.push_back(op{ getdam,turn });
		}
	}
	sort(ops.begin(), ops.end());
	long long int atsum = 0;
	for (auto o : ops) {
		atsum += o.damage;
	}
	for (auto o : ops) {
		ld about = ld(atsum)*ld(o.turn);
		if (about > 1e16) {
			gettotal =1e16;
			break;
		}
		gettotal += atsum*o.turn;
		if (gettotal >= T)break;
		atsum -= o.damage;
	}
	if (gettotal >= T)gettotal = -1;
	cout << gettotal << endl;
	return 0;
}

Measured memory_bytes: 3776
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

typedef long long ll;

ll N,S,W,Q;
ll a[100001];
ll p[100001];
ll rec[100001];
int main(){
  while(cin>>N>>S>>W>>Q&&(N|S|W|Q)){
    // p[i]=10^i
    p[0]=1;
    for(int i=1;i<100001;i++)
      p[i]=(p[i-1]*10)%Q;
    int g=S;
    for(int i=0;i<N;i++){
      a[i]=(g/7)%10;
      if(g%2==0)g=g/2;
      else g=(g/2)^W;
    }
    ll res=0;
    if(Q==2||Q==5){
      int cnt=0;
      for(int i=0;i<N;i++){
	if(a[i])cnt++;
	if(a[i]%Q==0)res+=cnt;
      }
    }
    else{
      map<int,int> m;
      m[0]=1;
      ll cur=0;
      for(int i=N-1;i>=0;i--){
	cur=(cur+p[N-i-1]*a[i])%Q;
	if(a[i])res+=m[cur];
	m[cur]++;
      }
    }
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 5292
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    if(a==1) a = 14;
    if(b==1) b = 14;
    if(a==b) cout << "Draw";
    if(a>b) cout << "Alice";
    if(a<b) cout << "Bob";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
)

var m map[int]int

func main() {
	var N, w int
	fmt.Scan(&N)
	p := 2
	n := 1
	if N == 1 {
		fmt.Println(1)
		return
	}
	for i := 2; i <= N; i++ {
		w = p + n
		p = n
		n = w
	}
	fmt.Println(w)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
ll modpow(long long a, long long n, long long mod2) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod2;
        a = a * a % mod2;
        n >>= 1;
    }
    return res;
}

int main() {
    ll n,ans = 0;
    cin >> n;
    vector<ll> a(n),b(n),c(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    for (int i = 0; i < n; ++i) cin >> c[i];
    sort(a.begin(),a.end());
    sort(c.begin(),c.end());

    for (int i = 0; i < n; ++i) {
        auto lw = lower_bound(a.begin(),a.end(),b[i]);
        auto up = upper_bound(c.begin(),c.end(),b[i]);
        ll d1 = distance(a.begin(),lw);
        ll d2 = distance(up,c.end());
        ans += d1*d2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	v := make([]int, n)
	c := make([]int, n)
	for i := range v {
		fmt.Scan(&v[i])
	}
	for i := range c {
		fmt.Scan(&c[i])
	}

	ans := 0
	for i := 0; i < n; i++ {
		if v[i] > c[i] {
			ans += v[i] - c[i]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int[] dp = new int[n + 1];
    for (int i = 0; i <= n; i++) {
      dp[i] = 100001;
    }
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
      dp[i + 1] = Math.min(dp[i] + 1, dp[i + 1]);
      for (int j = 6; i + j <= n; j *= 6) {
        dp[i + j] = Math.min(dp[i] + 1, dp[i + j]);
      }
      for (int j = 9; i + j <= n; j *= 9) {
        dp[i + j] = Math.min(dp[i] + 1, dp[i + j]);
      }
    }
    pw.println(dp[n]);
  }
}


Measured memory_bytes: 36092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

int main(int argc, char *argv[])
{
    int i, N;
    long long sum = 0, a = 0, b = 0, min = LLONG_MAX;
    static int list[2*100000];
    scanf("%d", &N);

    for ( i = 0; i < N; i++ ){
        scanf("%d", &list[i]);
        sum += list[i];
    }
    for ( i = 0; i < N-1; i++ ){
        a += list[i];
        b = sum - a;
        if ( min > llabs(a-b) ){
            min = llabs(a-b);
        }
    }
    printf("%lld\n", min);
    return 0;
}

Measured memory_bytes: 896
N = int(input())
f = [list(map(int, input().split())) for _ in range(N)]
p = [list(map(int, input().split())) for _ in range(N)]

ans = []
stk = []

stk.append([0] * N)

for i in range(10):
    len_stk = len(stk)
    for j in range(len_stk):
        total = 0
        arr = []
        for k in range(N):
            open_cnt = stk[j][k] + f[k][i]
            arr.append(open_cnt)
            total += p[k][open_cnt]
        ans.append(total)
        stk.append(arr)

print(max(ans))


Measured memory_bytes: 4084
while (h = gets.to_i) > 0
    field = h.times.map{gets.split.map(&:to_i)}
    
    score = 0
    continue = true
    while (continue)
        continue = false
        field.map! do |line|
            new_line = line.clone
            no,cnt = nil,0
            line.each_with_index do |e,x|
                no,cnt = e,0 if no != e
                cnt += 1
                if cnt >= 3 && no != 0
                    3.times do |j|
                        break if new_line[x-j] == 0
                        score += new_line[x-j].to_i
                        new_line[x-j] = 0
                        continue = true
                    end
                end
            end
            new_line
        end
        
        (h-2).downto(0) do |y|
            field[y].each_index do |x|
                0.upto(h-2-y) do |i|
                    break if field[y+i][x] == 0 || field[y+i+1][x] != 0
                    field[y+i+1][x], field[y+i][x] = field[y+i][x], 0
                end
            end
        end
    end
    p score
    
end


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

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

    s += s;

    vector<vector<int>> position(26, vector<int>());
    for (int i = 0; i < s.size(); i++)
    {
        position[s[i] - 'a'].push_back(i);
    }

    long long ans = 0;
    int current = -1;
    int next;
    for (char c : t)
    {
        if (position[c - 'a'].empty())
        {
            cout << -1 << endl;
            return 0;
        }

        next = *upper_bound(position[c - 'a'].begin(), position[c - 'a'].end(), current);
        ans += next - current;
        current = next;
        current %= s.size() / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1784
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int[] abc = new int[3];
        for (int i = 0; i < s.length(); i++) {
            abc[s.charAt(i) - 'a']++;
        }
        int min = Math.min(abc[0], Math.min(abc[1], abc[2]));
        int max = Math.max(abc[0], Math.max(abc[1], abc[2]));
        if (max - min <= 1) {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }

}


Measured memory_bytes: 23848
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
#define LL long long
#define MAXN 100000
#define Pr pair<int,int>
#define X first
#define Y second
int n,m,ans;
Pr a[MAXN+5];
bool cmp(Pr s1,Pr s2){
	return s1.Y>s2.Y;
}
priority_queue<Pr> Q;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int t;
		scanf("%d%d",&t,&a[i].X);
		a[i].Y=m-t+1;
	}
	sort(a+1,a+n+1,cmp);
	int tp=1;
	for(int i=m;i>=1;i--)
	{
		while(tp<=n&&a[tp].Y>=i)
			Q.push(a[tp]),tp++;
		if(!Q.empty()){
			ans+=Q.top().X;
			Q.pop();
		}
	}
	printf("%d",ans);
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

const int MAX = 1e5+10;

ll GCD(ll x, ll y) {
    if (x > y) swap(x, y);
    while (x) {
        ll z = x;
        x = y%x;
        y = z;
    }
    return y;
}

ll LCM(ll x, ll y) {
    ll g = GCD(x, y);
    return x / g * y;
}

int N, M;
int A[MAX];

int count_factor_2(ll x) {
    int count = 0;
    while ((x&1) == 0) {
        x >>= 1;
        count++;
    }
    return count;
}

bool check_factor_2() {
    int count = count_factor_2(A[0]);
    REP (i, N) if (count_factor_2(A[i]) != count) {
        return false;
    }
    return true;
}

ll solve() {
    if (!check_factor_2()) return 0;

    ll lcm = 1;
    REP (i, N) lcm = LCM(lcm, A[i] / 2);
    return M / lcm - M / lcm / 2;
}

int main() {
    cin >> N >> M;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<stack>

using namespace std;

static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
  stack<int> S;
  S.push(r);
  color[r] = c;

  while (!S.empty()) {
    int u = S.top(); S.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (color[v] == NIL) {
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assignColor() {
  int id = 1;
  for (int i = 0; i < n; i++) {
    color[i] = NIL;
  }
  for (int u = 0; u < n; u++) {
    if (color[u] == NIL) {
      dfs(u, id++);
    }
  }
}

int main() {
  int m, s, t;

  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  int q;
  cin >> q;

  for (int i =0; i < q; i++) {
    cin >> s >> t;
    if (color[s] == color[t]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}




Measured memory_bytes: 9004
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in read(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    N, Y = readi(2)
    for i in range(N + 1):
        for j in range(i + 1):
            a = j
            b = i - j
            c = N - i
            if a * 10000 + b * 5000 + c * 1000 == Y:
                print(a, b, c)
                return
    print(-1, -1, -1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 40176
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <math.h>
using namespace std;

bool OK(string in){
	for(int i = 0;i<in.size();i++){
		if (in[0] != in[i]) return false;
	}
	return true;
}

char ch(char a, char b){
	if (a != 'r' && b != 'r') return 'r';
	else if (a != 'g' && b != 'g') return 'g';
	else return 'b';
}

int main(){
	string in;
	while(cin >> in){
		if (in == "0") break;
		queue<string> que;
		que.push(in);
		vector<string> check(pow(3, in.size()));
		int n = 0;
		bool map[60000] = {};
		while(true){
			int que_size = que.size();
			bool flag = false;
			if(que_size == 0){
				cout << "NA" << endl;
				break;
			}
			for(int i = 0;i<que_size;i++){
				string que_front = que.front();
				que.pop();
				if(OK(que_front)){
					cout << n << endl;
					flag = true;
					break;
				}
				for (int j = 0; j < que_front.size() - 1; j++) {
					if (que_front[j] == que_front[j + 1]) continue;
					string for_push = que_front;
					for_push[j] = for_push[j + 1] = ch(que_front[j], que_front[j + 1]);
					int tmp = 0;
					for (int k = 0; k < for_push.size(); k++){
						if (for_push[k] == 'r') tmp += 2 * pow(3, k);
						else if (for_push[k] == 'g') tmp += pow(3, k);
					}
					if(!map[tmp]){
						map[tmp] = true;
						que.push(for_push);
					}
				}
			}
			if (flag) break;
			n++;
		}

	}
	return 0;
}

Measured memory_bytes: 3960
from sys import stdin
# import numpy as np
# import math
import fractions as math
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]

N = int(stdin.readline().rstrip().split()[0])
A = [int(x) for x in stdin.readline().rstrip().split()]

gcd_l = [0,A[0]]
gcd_r = [0,A[N-1]]
gcd_ = A[0]
for i in range(1, N-1):
  gcd_ = math.gcd(gcd_,A[i])
  gcd_l.append(gcd_)

gcd_ = A[N-1]
for i in range(1, N-1):
  gcd_ = math.gcd(gcd_, A[N-1-i])
  gcd_r.append(gcd_)
  
def gcd_0(a,b):
  if a==0:
    return b
  if b==0:
    return a
  return math.gcd(a,b)
  

gcd_list = [gcd_0(gcd_l[i], gcd_r[N-1-i]) for i in range(N)]
# print(gcd_l)
# print(gcd_r)
# print(gcd_list)

print(max(gcd_list))

Measured memory_bytes: 16060
import sys
from collections import defaultdict, deque
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    n, a, b = getList()
    nums = getList()

    ans = 0
    for i, j in zip(nums, nums[1:]):
        if a * (j - i) >= b:
            ans += b
        else:
            ans += a * (j - i)

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 87832
from typing import List


class UnionFind:
    """Union Find (Disjoint Set): O(α(N))
    References:
        https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp
        https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html
    """

    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        """Find the group (root) of vertex x in O(α(n)) amortized."""
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def __len__(self) -> int:
        """Count the number of groups (roots)."""
        return len(self.groups)

    @property
    def groups(self) -> List[int]:
        """Return the set of groups (roots) in O(n)."""
        return [i for i, r in enumerate(self._roots) if r < 0]

    def is_connected(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are connected in O(α(n)) amortized."""
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y in O(α(n)) amortized."""
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x

    def get_size(self, x: int) -> int:
        """Return the size of the group where vertex x belongs in O(α(n)) amortized."""
        return -self._roots[self[x]]


def unionfind():
    # https://judge.yosupo.jp/problem/unionfind
    # https://atcoder.jp/contests/practice2/tasks/practice2_a
    import sys

    readline = sys.stdin.buffer.readline

    N, Q = map(int, readline().split())
    tree = UnionFind(N)
    res = []
    for _ in range(Q):
        t, u, v = map(int, readline().split())
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


def arc032_b():
    # https://atcoder.jp/contests/arc032/tasks/arc032_2
    N, M, *AB = map(int, open(0).read().split())
    tree = UnionFind(N + 1)
    for a, b in zip(*[iter(AB)] * 2):
        tree.unite(a, b)
    print(len(tree) - 2)


if __name__ == "__main__":
    unionfind()
    # arc032_b()


Measured memory_bytes: 85288
#include<iostream>

using namespace std;

int main(){
    string s1,s2;
    cin>>s1>>s2;
    int n1 = s1.length();
    int n2 = s2.length();
    int dp[n1+1][n2+1];
    for (int i=0;i<=n1;i++)
    {
        for (int j=0;j<=n2;j++)
        {
            if (i==0 || j==0)
            dp[i][j] = 0;
            else if (s1[i-1]==s2[j-1])
            dp[i][j] = dp[i-1][j-1]+1;
            else
            dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
        }
    } 
    string res = "";
  	int i = n1;
    int j = n2;
    while (i>0 && j>0)
    {
      if(s1[i-1]==s2[j-1]) {
        res = s1[i-1]+res;
        i--;
        j--;
      }
      else if (dp[i-1][j] > dp[i][j-1])
        i--;
      else
        j--;
    }
  cout<<res<<endl;
}


Measured memory_bytes: 38268
import java.util.Scanner;

public class Main {

	public static int cnt=0;
	public static int[] L=new int[500000/2+2];
	public static int[] R=new int[500000/2+2];
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan =new Scanner(System.in);
		int n=scan.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++){
			arr[i]=scan.nextInt();
		}
		mergeSort(arr,n,0,n);
		arrPrint(arr);
		System.out.println(cnt);
	}

	private static void mergeSort(int[] arr, int n, int low, int high) {
		// TODO Auto-generated method stub
		if(low+1<high){
			int mid=(low+high)/2;
			mergeSort(arr, n, low, mid);
			mergeSort(arr, n, mid, high);
			merge(arr, n, low, mid,high);
		}
	}

	private static void merge(int[] arr, int n, int low, int mid,int high){
		// TODO Auto-generated method stub
		int n1=mid-low;
		int n2=high-mid;
		for(int i=0;i<n1;i++) L[i]=arr[low+i];
		for(int i=0;i<n2;i++) R[i]=arr[mid+i];
		L[n1]=R[n2]=2000000000;
		int i=0,j=0;
		for(int k=low;k<high;k++){
			cnt++;
			if(L[i]<=R[j]){
				arr[k]=L[i++];
				
			}
			else{
				arr[k]=R[j++];
			}
		}
	}

	public static void arrPrint(int[] arr){
		int i=0;
		for(i=0;i<arr.length-1;i++)
			System.out.print(arr[i]+" ");
		System.out.println(arr[i]);
	}
}



Measured memory_bytes: 171380
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int *c=(int *)calloc(n+1,sizeof(int));
  int i;
  int cnt=0;
  for(i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    if(a<=n){
      c[a]++;
    } else {
      cnt++;
    }
  }
  for(i=1;i<=n;i++){
    if(c[i]!=i){
      cnt+=(c[i]>i?c[i]-i:c[i]);
    }
  }
  printf("%d\n",cnt);
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <deque>

using namespace std;

int N;
int A[200005];
long long rez = 0;

int main(){
    cin >> N;
    for(int i = 1;i <= N;i++){
        cin >> A[i];
    }

    A[0] = -1;
    for(int i = 1;i <= N;i++){
        if(A[i] > A[i - 1] + 1){
            cout << -1;
            return 0;
        }
        else if(A[i] < A[i - 1] + 1){
            rez += A[i];
        }
        else{
            rez += (i != 1);
        }
    }
    cout << rez;
    return 0;
}


Measured memory_bytes: 1024