akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
int main(){
  ll n ,d;
  cin >> n ;
  string  s ;
  cin >> s ;
  char c ;
  for(int i=0 ; i< s.size() ;i++)
  {
       d =s[i]-'A' ;
       d=(d+n)%26 ;
      c= d+'A' ;

       cout << c ;
  }

    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const int N = 5e2+9, M = 1e5+9, OO = 0x3f3f3f3f,MOD = 1e9 + 7;
int n;
LL memo[N][N],csum[N];
LL solve(int l=1,int r=n)
{
  if(l==r) return 0;
  LL &ret = memo[l][r];
  if(~ret) return ret;

  ret = LONG_LONG_MAX;
  for(int i=l;i<r;++i)
  {
    ret = min(ret,solve(l,i)+solve(i+1,r)+(csum[r]-csum[l-1]));
  }
  
  return ret; 
}

int main()
{
  memset(memo,-1,sizeof memo);
  scanf("%d",&n);
  for(int i=1;i<=n;++i)
  {
    LL x;
    scanf("%lld",&x);
    csum[i]+=csum[i-1]+x;
  }
  printf("%lld\n",solve());
  
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

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

using namespace std;

#define int long long

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) begin(a),end(a)
#define PB push_back
#define fst first
#define scd second

using pii=pair<int, int>;
using vpii=vector<pair<int, int>>;
const int inf = 3e18;

struct edge{ int to,cost; };

vector<edge> G[100010];
int d[100010], height[100010];
int N, M, X;
int H[100010];

void dijk(int s, int h)
{
    priority_queue<pii, vpii, greater<pii>> q;

    memset(height, -1, sizeof(height));
    fill_n(d, N+1, inf);
    height[s] = h;
    d[0] = 0;

    q.push(pii(0, s));

    while (q.size()) {
        pii p = q.top(); q.pop();

        int v = p.scd, c = p.fst;
        int cur_h = height[v];

        for (edge &e : G[v]) {
            if (H[v] - e.cost < 0) continue;
            // H[v] - e.cost >= 0
            int nxc = c + e.cost;
            if (height[v] - e.cost < 0) {
                nxc += e.cost - height[v];
            }

            if (height[v] - e.cost > H[e.to]) {
                nxc += height[v] - e.cost - H[e.to];    
            }

            if (d[e.to] > nxc) {
                d[e.to] = nxc;
                q.push(pii(d[e.to], e.to));

                height[e.to] = min(H[e.to], max(height[v] - e.cost, 0ll));
            }
        }
    }
}

signed main()
{
    cin >> N >> M >> X;

    rep(i, N) { cin >> H[i]; }

    rep(i, M) {
        int a, b, t; cin >> a >> b >> t;
        --a, --b;
        G[a].PB(edge{b, t});
        G[b].PB(edge{a, t});
    }

    dijk(0, X);

    int ans = d[N - 1];

    if (ans == inf) ans = -1;
    else ans += H[N - 1] - height[N - 1];

    cout << ans << endl;
}

Measured memory_bytes: 23880
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,i,j,k;
  cin>>n;
  vector<int>a(n);
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  long long int sum=0,num=(n*(n-1)*(n-2))/6;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      k=j+1;
      while(k<n){
        if(a[i]+a[j]<=a[k])
        sum++;
        k++;
      }
    }
  }
  cout<<num-sum<<"\n";
  return 0;
}

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

int top=0;
char s[10000];

struct
{
  int a[1000];
  void push(int n)
{
    a[++top]=n;
}
int pop()
{
    top--;
    return a[top+1];
}
}mystack;

int main()
{

    int x,y;
    while(scanf("%s",s)!=EOF)
    {
        if(s[0]=='+')
        {
            x=mystack.pop();
            y=mystack.pop();
            mystack.push(x+y);
        }
        else if(s[0]=='-')
        {
            y=mystack.pop();
            x=mystack.pop();
            mystack.push(x-y);
        }
        else if(s[0]=='*')
        {
            x=mystack.pop();
            y=mystack.pop();
            mystack.push(x*y);
        }
        else
            mystack.push(atoi(s));

    }

        printf("%d\n",mystack.pop());
    return 0;
}

Measured memory_bytes: 2724
// C - Otoshidama
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N,Y; cin>>N>>Y; Y /= 1000;
	int minZ = max(0, N-(Y-N)/4);
	rp(z, minZ, minZ+5){
		int y = max(0, (-Y+10*N-9*z)/5);
		int x = N - y - z;
		if(x*10 + y*5 + z != Y) continue;
		printf("%d %d %d\n", x, y, z);
		return 0;
	}
	puts("-1 -1 -1");
}

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

using namespace std;

#define MOD 1000000007
#define N 102
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define pld pair <ld, ld>

vector < pld > pts;

bool comp(pld x, pld y){
	return (atan2(x.ss, x.ff) < atan2(y.ss, y.ff));
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int i, j, b, n; cin>>n;
	ld x, y, ans = 0, xsum, ysum;
	for(i=0; i<n; i++){
		cin>>x>>y;
		if(x != 0 || y != 0){
			pts.pb({x, y});
		}
	}
	n = pts.size();
	if(n){
		sort(pts.begin(), pts.end(), comp);
		for(i=0; i<n; i++){
			xsum = 0; ysum = 0;
			for(j=0; j<n; j++){
				xsum = xsum + pts[(i+j)%n].ff;
				ysum = ysum + pts[(i+j)%n].ss;
				ans = max(ans, xsum*xsum + ysum*ysum);
			}
		}	
	}
	ans = sqrt(ans);
	cout<<setprecision(40)<<fixed<<ans;
	return 0;
}

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

namespace AtCoder
{
    class Abc167D
    {
        public static void Main()
        {
            var nk = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            var n = nk[0];
            var k = nk[1];
            var a = Console.ReadLine().Split(' ').Select(i => int.Parse(i) - 1).ToArray();

            var towns = new List<int>();
            var passed = new byte[n];

            var next = 0;
            while (++passed[next] < 2)
            {
                towns.Add(next);
                next = a[next];
            }

            var head = 0;
            while (towns[head] != next)
                head++;

            if (k <= head)
                Console.WriteLine(towns[(int)k] + 1);
            else
            {
                k -= head;
                var m = towns.Count - head;
                Console.WriteLine(towns[head + (int)(k % m)] + 1);
            }
        }
    }
}


Measured memory_bytes: 45000
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
check = [0]*N
ans = 0
for i in range(N):
    if i < K or T[i] != T[i-K] or not check[i-K]:
        ans += P if T[i] == 'r' else R if T[i] == 's' else S
        check[i] = 1
print(ans)

Measured memory_bytes: 4084
while True:
    a, b = map(int, input().split())
    if a == b == 0:
        break
    for i in range(a):
        if i % 2 == 0:
            for ii in range(b):
                if ii % 2 == 0:
                    print('#', end='')
                else:
                    print('.', end='')
            print()
        else:
            for ii in range(b):
                if ii % 2 == 0:
                    print('.', end='')
                else:
                    print('#', end='')
            print()
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int loop = 0;
    while(true){
        loop++;
        int x;
        cin >> x;
        if(x == 0)break;
        cout << "Case " << loop << ": " << x << endl;
    }
    return 0;
}
 
 



Measured memory_bytes: 3084
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = (1ll << 31) - 1;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<typename T>
struct RangeUpdateQuery {
	int n;
	vector<int>d;
	RangeUpdateQuery(int m) {
		for (n = 1; n < m; n <<= 1);
		d.assign(2 * n, INF);
	}
	int find(int i) {
		update(i, i + 1);
		return d[n + i];
	}
	void update(int a, int b, int x = -1, int k = 1, int l = 0, int r = -1) {
		if (r == -1)r = n;

		if (r <= a || b <= l)return;
		else if (a <= l&&r <= b) {
			if (x >= 0)d[k] = x;
			return;
		}
		else {
			if (d[k] != INF)d[2 * k] = d[2 * k + 1] = d[k], d[k] = INF;
			update(a, b, x, 2 * k, l, (l + r) / 2);
			update(a, b, x, 2 * k + 1, (l + r) / 2, r);
		}
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	RangeUpdateQuery<int> ruq(n);
	rep(i, 0, q) {
		int com; cin >> com;
		if (com) {
			int x; cin >> x;
			cout << ruq.find(x) << endl;
		}
		else {
			int s, t, x; cin >> s >> t >> x;
			ruq.update(s, t + 1, x);
		}
	}
	return 0;
}

Measured memory_bytes: 3896
#pragma GCC optimize(2)

#include "bits/stdc++.h"

using namespace std;

//#define _DEBUG
#define all(a) begin(a), end(a)
#define MOD 1000000007
#define PII pair<int, int>
#define complete_unique(a) a.erase(unique(begin(a), end(a)), end(a))
#define mst(x, a) memset(x, a, sizeof(x))
typedef vector<int> VI;
typedef long long ll;

ll quick_pow(ll a, ll b) {
    long long res = 1;
    while (b) {
        if (b & 1)
            res = a * res;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) {
    a = abs(a), b = abs(b);
    while (b != 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

bool is_prime(int n) {
    if (n == 0) return false;
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    int j = sqrt(n);
    for (int i = 2; i <= j; ++i) {
        if (n % i == 0) return false;
    }
    return true;
}

ll reverse_num(ll n) {
    ll x = 0, t = n;
    while (t != 0) {
        x = x * 10 + t % 10;
        t /= 10;
    }
    return x;
}

const int N = 1005;
int mem[N][N];
vector<vector<int>> road;
int r;

int dfs(int row, int col) {
    if (mem[row][col] != -1) {
        return mem[row][col];
    }
    if (row == r) {
        return 0;
    }
    int res = max(dfs(row + 1, col), dfs(row + 1, col + 1)) + road[row][col];
    mem[row][col] = res;
    return res;
}

int n;
int idx1 = 0, idx2 = 0;
VI x;
VI y;
VI temp;
bool visited[10];
int cnt=0;

bool check(vector<int> a1, vector<int> a2) {
    for (int i = 0; i < a1.size(); ++i) {
        if (a1.at(i) != a2.at(i)) return false;
    }
    return true;
}

void traceback() {
    if (temp.size() == n) {
        cnt++;
//        cout << cnt << endl;
        if (check(temp, x)) {
            idx1 = cnt;
        }
        if (check(temp, y)) {
            idx2 = cnt;
        }
        return;
    }
    for (int i = 1; i <= n; ++i) {
        if (!visited[i]) {
            temp.push_back(i);
            visited[i] = true;
            traceback();
            temp.pop_back();
            visited[i] = false;
        }
    }
}

void solve() {
    cin >> n;
    x = vector<int>(n);
    y = vector<int>(n);
    for (auto &it:x) cin >> it;
    for (auto &it:y) cin >> it;
    traceback();
    cout << abs(idx1 - idx2);
}

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
    // 加速输入和输出
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}



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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    map<ll, ll> cnt;
    for (int i = 0; i < n; i++) {
        ans += cnt[-(a[i] - i)];
        cnt[a[i] + i]++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 27816
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T &a, T b) {if (a < b) {a = b;return 1;}return 0;}
template<class T> inline bool chmin(T &a, T b) {if (a > b) {a = b;return 1;}return 0;}

int main(){
  double r;
  cin >> r;
  const double PI=3.14159265358979323846;
  cout << std::fixed << std::setprecision(15) << 2 * r * PI << endl;
}


Measured memory_bytes: 3772
mod = 10**9+7


def inv(x):
    return pow(x, mod - 2, mod)


def nCr(n, k):
    return fact[n] * inv_fact[k] % mod * inv_fact[n-k] % mod

N, K = map(int, input().split())
if K == 1:
    print(0)
    quit()
A = [int(x) for x in input().split()]
A.sort()

fact = [1, 1]
inv_fact = [1, 1]
for i in range(2, N + 1):
    fact.append(fact[-1] * i % mod)
    inv_fact.append(inv(fact[-1]))


comb_sum = [0]
for i in range(N):
    if K - 2 + i > N:
        break
    comb_sum.append((comb_sum[-1] + nCr(K-2+i, K-2)) % mod)
ans = 0
for i in range(N):
    cnt = N - K + 1 - i
    if cnt > 0:
        ans = (ans + (mod - comb_sum[cnt]) * A[i]) % mod
    cnt = i + 2 - K
    if cnt > 0:
        ans = (ans + comb_sum[cnt] * A[i]) % mod
print(ans)


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

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.bigin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>

using namespace std;

int main(){
    int r,d;
    vi x(11);
    cin >> r >> d >> x[0];
    Lrep(i,1,11) x[i] = x[i-1] * r - d;
    Srep(10) cout << x[i + 1] << endl;
}

Measured memory_bytes: 3628
import java.math.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuffer ans = new StringBuffer(sc.next());
        int q = sc.nextInt();
        int t = 0;
        int f = 0;
        int tmp = 0;
        StringBuffer forw = new StringBuffer();
        StringBuffer back = new StringBuffer();
        String c = "";
        for (int i = 0; i < q; i++) {
            tmp = sc.nextInt();
            if (tmp == 1) {
                t++;
            } else {
                f = sc.nextInt();
                c = sc.next();
                if ((t % 2 == 1 && f == 2) || (t % 2 == 0 && f == 1)) {
                    forw.append(c);
                } else {
                    back.append(c);
                }
            }
        }
        ans = forw.reverse().append(ans).append(back);
        if (t % 2 == 1)
            ans.reverse();
        System.out.println(ans.toString());
        sc.close();
    }
}

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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	if (N == 1 && M == 2) {
		cout << 3 << endl;
	}
	else if (N == 2 && M == 1) {
		cout << 3 << endl;
	}
	else if (N == 1 && M == 3) {
		cout << 2 << endl;
	}
	else if (N == 3 && M == 1) {
		cout << 2 << endl;
	}
	else if (N == 2 && M == 3) {
		cout << 1 << endl;
	}
	else {
		cout << 1 << endl;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	vector<int>ans(N, 0);
	rep(i, N - 1) {
		int A;
		cin >> A;
		A--;
		ans[A]++;
	}
	rep(i, N)cout << ans[i] << endl;
}

Measured memory_bytes: 4792
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N, K = map(int, input().split())
A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]

for k in range(K):
    lst = [0] * (N + 1)
    for i, a in enumerate(A):
        left = max(i - a, 0)
        right = min(N - 1, i + a)
        lst[left] += 1
        lst[right + 1] -= 1
    tmp = 0
    for i in range(N):
        tmp += lst[i]
        A[i] = tmp

    flag = 1
    for i in range(N):
        if A[i] != N:
            flag = 0
            break

    if flag:
        print(*([N] * N))
        exit()

print(*A)
    
    
    
    
    

Measured memory_bytes: 155916
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int64_t K, X;
    cin >> K >> X;
    if (500 * K >= X) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

const int N = 200005;
const int mod = 1e9+7;
int add(int a, int b) {
	return a + b < mod ? a + b : a + b - mod;
}
int mul(int a, int b) {
	return int(1LL * a * b % mod);
}
int fexp(int b, int e = mod - 2) {
	int ans = 1;
	while(e) {
		if(e & 1) ans = mul(ans, b);
		b = mul(b, b);
		e /= 2;
	}
	return ans;
}

int fat[N], ifat[N];
int C(int n, int k) {
	if(k > n) return 0;
	return mul(mul(fat[n], ifat[n - k]), ifat[k]);
}

int n;
vector<int> g[N];

int dp[N];
int sz[N];


int f(int u, int p) {
	sz[u] = 1;
	for(int v : g[u]) if(v != p) {
		f(v, u);
		sz[u] += sz[v];
	}
	int &ans = dp[u];
	ans = 1;
	int left = sz[u] - 1;
	for(int v : g[u]) if(v != p) {
		ans = mul(ans, mul(C(left, sz[v]), dp[v]));
		left -= sz[v];
	}
	return ans;
}

int ans[N];
void dfs(int u, int p) {
	ans[u] = dp[u];

	for(int v : g[u]) if(v != p) {
		int oldu = dp[u];
		int oldv = dp[v];

		assert(sz[u] == n);
		dp[u] = mul(dp[u], fexp(mul(C(sz[u] - 1, sz[v]), dp[v])));
		sz[u] -= sz[v];
		sz[v] += sz[u];
		dp[v] = mul(dp[v], mul(C(sz[v] - 1, sz[u]), dp[u]));
		assert(sz[v] == n);
		dfs(v, u);
		sz[v] -= sz[u];
		sz[u] += sz[v];
		dp[v] = oldv;
		dp[u] = oldu;
	}
}

int main() {

	fat[0] = 1;
	for(int i = 1; i < N; i++) fat[i] = mul(i, fat[i - 1]);
	ifat[N - 1] = fexp(fat[N - 1]);
	for(int i = N - 2; i >= 0; i--) ifat[i] = mul(i + 1, ifat[i + 1]);

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}

	f(1, 1);

	dfs(1, 1);

	for(int i = 1; i <= n; i++) {
		printf("%d\n", ans[i]);
	}
}


Measured memory_bytes: 18924
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int k = sc.nextInt();			
			int n = sc.nextInt();
			int[] aArray = new int[n];
			
			for(int i = 0 ; i < n ; i++ ) {
				aArray[i] = sc.nextInt();
			}
			
			PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
			
			for(int i = 0 ; i < n ; i++ ) {
				if ( i == 0 ) {
					int dist = k - aArray[n-1] + aArray[0];
					pq.add(dist);
				}
				else {
					pq.add(aArray[i] - aArray[i-1]);
				}
			}
			
			int max = pq.poll();
			
			System.out.println(k - max);
			
		}
	}

}

Measured memory_bytes: 78204
#coding:utf-8
import sys,math
from collections import defaultdict
n,m=map(int,raw_input().split())
A=[];B=[]
for i in range(m):
    a,b=map(int,raw_input().split())
    A.append(a);B.append(b)
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]
        self.size = [1 for i in range(size)]
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.size[y] += self.size[x]
        else:
            self.parent[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def getsize(self, x):
        return self.size[self.find(x)]

def C(n, r):
    if n<r: return 0
    return math.factorial(n)/(math.factorial(r)*math.factorial(n-r))

uf = UnionFind(n+1)
ans=n*(n-1)/2
Ans = [ans]
A.reverse();B.reverse()
for a,b in zip(A,B):
    ag=uf.find(a)
    bg=uf.find(b)
    aS=uf.getsize(a)
    bS=uf.getsize(b)
    uf.union(ag,bg)
    if ag!=bg:
        ans -= aS*bS    
    Ans.append(ans)

for ans in list(reversed(Ans))[1:]:
    print(ans)


Measured memory_bytes: 26216
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a;
	getline(cin,a);
	for (int i = 0; i < a.size(); i++) {
		char b = a.at(i);
		if (65 <= b && b <= 90) {
			printf("%c", b + 32);
		}
		else if (97 <= b && b <= 122) {
			printf("%c", b - 32);
		}
		else { printf("%c", b); }
	}
	cout << endl;
}


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

const string YES = "Yes";
const string NO = "No";

long long n;
vector<string> S;
string ans[100005];


void dfs(long long i, long long A, long long B, long long C) {
  if (A < 0 || B < 0 || C < 0) return;
  if (i == n) {
    cout << "Yes" << endl;
    for (int j=0; j<n; j++) cout << ans[j] << endl;
    exit(0);
  } else {
    if (S[i] == "AB") {
      ans[i] = 'A';
      dfs(i+1, A+1, B-1, C);
      ans[i] = 'B';
      dfs(i+1, A-1, B+1, C);
    } else if (S[i] == "AC") {
      ans[i] = 'A';
      dfs(i+1, A+1, B, C-1);
      ans[i] = 'C';
      dfs(i+1, A-1, B, C+1);
    } else {
      ans[i] = 'B';
      dfs(i+1, A, B+1, C-1);
      ans[i] = 'C';
      dfs(i+1, A, B-1, C+1);
    }
  }
}

void solve(long long N, long long A, long long B, long long C, std::vector<std::string> s){
  n = N;
  S = s;
  dfs(0, A, B, C);
  cout << "No" << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    std::vector<std::string> s(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> s[i];
    }
    solve(N, A, B, C, std::move(s));
    return 0;
}


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

int d, c[26];
int s[365][26];

int t[365];

int tot_penalty;
void data_input() {
	scanf("%d", &d);
	rep(i, 26) scanf("%d", &c[i]);
	rep(i, d) rep(j, 26) scanf("%d", &s[i][j]);
	rep(i, 26) tot_penalty += c[i];
}

int calc_score() {
	int last[26] = {0};
	int rv = 0;
	int penalty = 0;



	rep(i, d) {
		int date = i + 1;
		int choice;
		int mx = -1;
		rep(j, 26) {
			int sc = s[i][j] + c[j] * (date - last[j]);
			if (sc > mx) {
				choice = j;
				mx = sc;
			}
		}
		penalty += tot_penalty - c[choice] * (date - last[choice]);
		last[choice] = date;
		rv += s[i][choice] - penalty;
		//cout << rv << endl;
		cout << choice+1 << endl;
	}
	return rv;
}

int main() {
	data_input();

//	rep(i, d) {
//		cin >> t[i];
//		t[i]--;
//	}

	// cout << calc_score() << endl;
	calc_score();
}


Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  vector<int> res(n);
  for(int i = 0;i < n;i++){
    res[i] = 0;
  }
  for(int i = 0;i < n - 1;i++){
    int a;
    cin >> a;
    a--;
    res[a]++;
  }
  for(int i = 0;i < n;i++){
    cout << res[i] << endl;
  }
  return 0;
}

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

int main(){
  int n ; cin >> n ;
  char c ;
  vector<int> pass(n) ;
  for(int i=0; i<n; i++){
    cin >> c ;
    if(c=='0')
      pass.at(i) = 0 ;
    else if(c=='1')
      pass.at(i) = 1 ;
    else if(c=='2')
      pass.at(i) = 2 ;
    else if(c=='3')
      pass.at(i) = 3 ;
    else if(c=='4')
      pass.at(i) = 4 ;
    else if(c=='5')
      pass.at(i) = 5 ;
    else if(c=='6')
      pass.at(i) = 6 ;
    else if(c=='7')
      pass.at(i) = 7 ;
    else if(c=='8')
      pass.at(i) = 8 ;
    else if(c=='9')
      pass.at(i) = 9 ;
  }
  int cnt = 0 ;
  int j ;
  bool can ;
  for(int i=0; i<1000; i++){
    can = false ;
    j = 0 ;
    for(;j<n;j++)
      if(pass.at(j)==i/100){
        can = true ;
        break ;
      }
    if(can)
      can = false ;
    else
      continue ;
    for(j+=1;j<n;j++)
      if(pass.at(j)==i%100/10){
        can = true ;
        break ;
      }
    if(can)
      can = false ;
    else
      continue ;
    for(j+=1;j<n;j++)
      if(pass.at(j)==i%10){
        can = true ;
        break ;
      }
    if(can)
      cnt++ ;
    else
      continue ;
  }
  cout << cnt << endl ;
}

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

int frog(int *h, int n, int k, int* dp){

    if(n==1) return dp[n]=0;

    if(n==2) return dp[n]=abs(h[n]-h[n-1]);

    if(dp[n]!=-1) return dp[n];

    dp[n] = abs(h[n]-h[n-1]) + frog(h,n-1,k,dp);
    for(int i=0;i<k+1&&n-i>0;i++){
        dp[n]=min(dp[n],abs(h[n]-h[n-i])+frog(h,n-i,k,dp));
    }

    return dp[n];

}

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

    int h[100005];
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }

    int dp[100005];
    for(int i=1;i<=n;i++)
        dp[i] = -1;

    // for(int i=1;i<n;i++){
    //     dp[i] = INT_MAX;
    //     for(int j=i-1;(i-j)<=k && j>=0;j--){
    //         dp[i] = min(dp[i],abs(h[i]-h[j]) + dp[j]);
    //     }
    // }

    cout<<frog(h,n,k,dp);

    return 0;
}


Measured memory_bytes: 12224
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author varunvats32
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CWelcomeToAtCoder solver = new CWelcomeToAtCoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class CWelcomeToAtCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();

            // Skip the extra newline
            in.nextLine();

            Map<Integer, CWelcomeToAtCoder.Pair> map = new HashMap<>();

            for (int i = 1; i <= M; i++) {
                String l = in.nextLine();
                String[] token = l.split(" ");
                Integer p = Integer.parseInt(token[0]);
                String sub = token[1];

                if (map.containsKey(p)) {
                    if (!map.get(p).succeed)
                        if (sub.equals("WA"))
                            map.put(p, new CWelcomeToAtCoder.Pair(map.get(p).count + 1, false));
                        else
                            map.put(p, new CWelcomeToAtCoder.Pair(map.get(p).count, true));
                } else {
                    if (sub.equals("WA"))
                        map.put(p, new CWelcomeToAtCoder.Pair(1, false));
                    else
                        map.put(p, new CWelcomeToAtCoder.Pair(0, true));
                }
            }


            long pen = 0;
            long cor = 0;

            for (Map.Entry<Integer, CWelcomeToAtCoder.Pair> entry : map.entrySet()) {
                if (entry.getValue().succeed) {
                    cor += 1;
                    pen += entry.getValue().count;
                }
            }


            out.println(cor + " " + pen);
        }

        static class Pair {
            int count;
            boolean succeed;

            public Pair(int c, boolean s) {
                count = c;
                succeed = s;
            }

        }

    }
}



Measured memory_bytes: 116956
#include<bits/stdc++.h>
#define pir pair<int,int>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
#define rsort(x,y) sort(x,y),reverse(x,y)
#define fr first
#define se second
using namespace std;
typedef long long ll;
const int Maxn=2100000;
const int inf=0x3f3f3f3f;

int n,a[Maxn],k,ans[Maxn],bj[Maxn];
pair<pir,pir > q[Maxn];

signed main() {
    // freopen("test.in","r",stdin);
    scanf("%d%d",&n,&k);
    int x=sqrt(n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=k;i++) {
        scanf("%d%d",&q[i].fr.se,&q[i].se.se);
        q[i].fr.fr=q[i].se.se/x;
        q[i].se.fr=i;
    }
    sort(q+1,q+k+1);
    int r=n,l=n+1,sxz=0;
    for(int i=1;i<=k;i++) {
        while(l<q[i].fr.se) {
            if(bj[a[l]]==1) sxz--;
            bj[a[l]]--;
            l++;
        }
        while(l>q[i].fr.se) {
            l--;
            if(!bj[a[l]]) sxz++;
            bj[a[l]]++;
        }
        while(r>q[i].se.se) {
            if(bj[a[r]]==1) sxz--;
            bj[a[r]]--;
            r--;
        }
        while(r<q[i].se.se) {
            r++;
            if(!bj[a[r]]) sxz++;
            bj[a[r]]++;
        }
        ans[q[i].se.fr]=sxz;
    }
    for(int i=1;i<=k;i++) printf("%d\n",ans[i]);
    return 0;
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

res = 0
for i in range(1,n+1):
    if i%2 == 1:
        x = make_divisors(i)
        if len(x) == 8:
            res += 1
print(res)

Measured memory_bytes: 38384
// AOJ 0099 Surf Smelt Fishing Contest II

#include <iostream>
#include <climits>

using namespace std;

const int MAX_N = 1 << 20;
int dat[2 * MAX_N - 1]; // 各節点に最大値を持つセグメント木
int n, n_dat, q;

void dat_init();
void dat_set(int i, int x);
void dat_add(int i, int x);
bool dat_is_leaf(int i);
pair<int, int> dat_max();

int
main()
{
    cin >> n;
    cin >> q;
    cin.ignore();

    dat_init();

    while (q--) {
        int a, v;
        pair<int, int> m;

        cin >> a;
        // 0-indexed にする
        a--;
        cin >> v;
        cin.ignore();

        dat_add(a, v);

        // 獲得数が最も多い参加者の番号とその獲得数を出力する
        m = dat_max();
        cout << m.first + 1 << " " << m.second << endl;
    }

    return 0;
}

// セグメント木の初期化
void
dat_init()
{
    int i;

    // 簡単のため、要素数を 2 の冪乗にする
    n_dat = 1;
    while (n_dat < n) n_dat *= 2;

    // 値の初期化
    for (i = 0; i < 2 * n_dat - 1; i++) dat[i] = INT_MIN;
    for (i = 0; i < n; i++) dat_set(i, 0);
}

// i 番目の値を x にする
void
dat_set(int i, int x)
{
    // 葉の節点
    i += n_dat - 1;
    dat[i] = x;

    // 登りながら更新
    while (i > 0) {
        i = (i - 1) / 2;
        dat[i] = max(dat[2 * i + 1], dat[2 * i + 2]);
    }
}

// i 番目の値に x を加算する
void
dat_add(int i, int x)
{
    // 葉の節点
    i += n_dat - 1;
    dat[i] += x;

    // 登りながら更新
    while (i > 0) {
        i = (i - 1) / 2;
        dat[i] = max(dat[2 * i + 1], dat[2 * i + 2]);
    }
}

// 最大値とそれに対応する番号のペアを返す。
// 複数の i が同じ最大値に対応するならば、最小の i を返す。
pair<int, int>
dat_max()
{
    int i = 1;
    int j = 2;

    for (;;) {
        if (dat[i] >= dat[j]) {
            // 最大値が左に存在するか、左右で同じ
            if (dat_is_leaf(i)) return pair<int, int>(i - n_dat + 1, dat[i]);
            i = 2 * i + 1;
        } else {
            // 最大値が右に存在する
            if (dat_is_leaf(i)) return pair<int, int>(j - n_dat + 1 , dat[j]);
            i = 2 * j + 1;
        }
        j = i + 1;
    }
}

// 要素 i が葉かどうかを返す
bool
dat_is_leaf(int i)
{
    return i >= n_dat - 1;
}

Measured memory_bytes: 9352
#include <iostream>
#include <stdlib.h>

#define N_MAX 99999

using namespace std;

typedef struct _a{
	char name[10];
	int time;
} P;

int main(){

	int i;
	int n;
	int q;
	int head;
	int tail;
	int res_time = 0;
	char temp[10];
	P A[N_MAX];

	cin >> n;
	cin >> q;

	for (i = 0; i < n; i++){
		cin >> A[i].name;
		cin >> A[i].time;
	}

	head = 0;
	tail = n - 1;

	while (1){
		// process
		// ??????????????´??°
		A[head].time -= q;

		// ????????????
		if (A[head].time <= 0){
			res_time += q + A[head].time;
			cout << A[head].name << ' ' << res_time << endl;
			if (tail == head){
				break;
			}
		}
		else {
			// ?????£?????´??°
			tail++;
			if (tail == N_MAX){
				tail = 0;
			}
			A[tail] = A[head];
			res_time += q;
		}

		// ?????´??°
		head++;
		if (head == N_MAX){
			head = 0;
		}
	}

	return 0;
}

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

int main(void) {
    int i, j, k, n, x, c;
    while (1) {
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        c = 0;
        for (i = 1; i <= n - 2; i++) {
            for (j = i + 1; j <= n - 1 ; j++) {
                for (k = j + 1; k <= n; k++) {
                    if (i + j + k == x) c++;
                }
            }
        }
        cout << c << endl;
    }
    return 0;
}

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

cntA, sumA = 0, 0
for i in range(N):
    sumA += A[i]
    if i % 2 == 0:
        if sumA <= 0:
            cntA += abs(sumA) + 1
            sumA += abs(sumA) + 1
    else:
        if sumA >= 0:
            cntA += abs(sumA) + 1
            sumA -= abs(sumA) + 1
    
cntB, sumB = 0, 0
for i in range(N):
    sumB += A[i]
    if i % 2 != 0:
        if sumB <= 0:
            cntB += abs(sumB) + 1
            sumB += abs(sumB) + 1
    else:
        if sumB >= 0:
            cntB += abs(sumB) + 1
            sumB -= abs(sumB) + 1

print(min(cntA, cntB))

Measured memory_bytes: 20144
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }
 
    return false;
}
 
 
//深さ優先
vector<int> seen;
vector<ll> h;
 
//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){

    seen[v] = 0; //v探索済み
 
    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }
 
    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}


int n;

void dfs(string s, char mx){
    if(s.length()==n){
        cout<<s<<endl;
    }else{
        for(char c='a';c<=mx;c++){
            dfs(s+c,((c==mx) ? (char)(mx+1) : mx));
        }
    }
}


int mod = 1000000007;
int m,k;

int dfs(int cnt,int pred, int sk){
    int sum=0;
    if(cnt==n){
        return 1LL;
    }
    for(int i=1;i<=m;i++){
        if(i==pred){
            if(sk+1<=k){
                sum+=dfs(cnt+1,i,sk+1)%mod;
            }
        }else{
            sum+=dfs(cnt+1,i,sk)%mod;
        }
    }

    return sum;
}

int num(int n,int a,int b){
    return n-(n/a)-(n/b)+(n/(a/gcd(a,b)*b));
}

vector<pair<int,int>> soinsuu(int n){
    vector<pair<int,int>> ret;
    for(int i=2;i*i<=n;i++){
        if(n%i !=0) continue;
        int ex=0;
        while(n%i ==0){
            ex++;
            n /= i; //n変更することで、それ以降の約数で割り切れることはない
        }
        ret.push_back(make_pair(i,ex));
    }
    //nが素数だった場合
    if(n!=1) ret.push_back(make_pair(n,1));
    return ret;
}


signed main(){ 
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;

    int t1=h1*60+m1;
    int t2=h2*60+m2;

    cout<<t2-t1-k<<endl;
}  

Measured memory_bytes: 3632
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

enum INF(T) = T.max / 3;

bool chmin(T)(ref T a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}

void main() {
  int[] NMR = readln.chomp.split.to!(int[]);
  int N = NMR[0],
      M = NMR[1],
      R = NMR[2];
  int[] rs = readln.chomp.split.to!(int[]);
  int[201][201] dp;

  foreach (i, ref col; dp) {
    foreach (j, ref e; col) {
      if (i == j) {
        e = 0;
      } else {
        e = INF!int;
      }
    }
  }

  foreach (_; 0..M) {
    int[] ABC = readln.chomp.split.to!(int[]);
    int A = ABC[0],
        B = ABC[1],
        C = ABC[2];

    if (dp[A - 1][B - 1] > 0) {
      dp[A - 1][B - 1] = dp[B - 1][A - 1] = C;
    }
  }

  foreach (i; 0..N) {
    foreach (j; 0..N) {
      foreach (k; 0..N) {
        chmin(dp[j][k], dp[j][i] + dp[i][k]);
      }
    }
  }

  int ans = int.max;

  foreach (r; rs.permutations) {
    int t;
    foreach (i; 0..R-1) {
      t += dp[r[i] - 1][r[i+1] - 1];
    }
    chmin(ans, t);
  }

  writeln(ans);
}


Measured memory_bytes: 1404
#include "bits/stdc++.h"
using namespace std;
set<int>S;

bool f(int n) {
	while (n >0) {
		int num = n % 10;
		n /= 10;
		if (S.count(num) == 1) {
			return false;
		}
	}
	return true;
}

int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0;i<K;++i) {
		int num;
		cin >> num;
		S.insert(num);
	}
	while (true) {
		if (f(N)) {
			break;
		}
		N++;
	}
	cout << N <<endl;
	return 0;
}

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

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    if(s[k-1] == 'A') s[k-1] = 'a';
    else if(s[k-1] == 'B') s[k-1] = 'b';
    else s[k-1] = 'c';

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll prime[1000005],cnt;
bool vis[1000005]; 
ll ans=0;
const ll A[64]={0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10}; 
inline void solve(int n){
	for(int i=2;i<=n;i++){
		if(!vis[i]) prime[cnt++]=i;
		for(int j=0;j<cnt&&i*prime[j]<=n;j++){
			vis[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
}
inline void calc(long long n){
	for(int i=0;i<cnt;++i){
		if(n%prime[i]==0){
			long long x=prime[i];
			long long a=0;
			while(n%x==0){
				a++;
				n/=x;
			}
			ans+=A[a];
		}
	}
	if(n!=1){
		ans++;
	}
}
int main(){
	solve(1e6);
	cin>>n;
	calc(n);
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 5236
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define For(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Foz(i, a) For(i, 0, a)
#define Doz(i, a) Dor(i, 0, a)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n, k;
	cin >> n >> k;
	vi p(n);
	Foz(i, n) cin >> p[i];
	int mx = 0, sm = 0;
	Foz(i, k) sm += p[i];
	mx = sm;

	For(i, k, n) {
		sm += p[i];
		sm -= p[i - k];
		ckmax(mx, sm);
	}
	
	cout << fixed << setprecision(17);
	cout << (double)(mx + k) / 2.0 << '\n';
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*y/gcd(x,y);
}

int main(){
	ll N,M; cin>>N>>M;
    ll ans=0;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    sort(A.begin(),A.end());
    vector<P> p(M);
    rep(i,M){
        ll B,C; cin>>B>>C;
        p[i]=mp(C,B);
    }
    sort(p.begin(),p.end(),greater<P>());
    
    ll i=0,n=0;
    while(i<M){
        for(int j=1;j<=p[i].second;j++){
            if(p[i].first>A[n]) A[n++]=p[i].first;
            else{
                rep(k,N){
                    ans+=A[k];
                }
                cout<<ans<<endl;
                return 0;
            }
        }
        i++;
    }
    rep(i,N){
        ans+=A[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(a<b&&b<c){cout<<a<<" "<<b<<" "<<c<<endl;}
else if (a<=c&&c<=b){cout<<a<<" "<<c<<" "<<b<<endl;}
else if (b<=a&&a<=c){cout<<b<<" "<<a<<" "<<c<<endl;}
else if (b<=c&&c<=a){cout<<b<<" "<<c<<" "<<a<<endl;}
else if (c<=a&&a<=b){cout<<c<<" "<<a<<" "<<b<<endl;}
else if (c<=b&&b<=a){cout<<c<<" "<<b<<" "<<a<<endl;}

	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner=new Scanner(System.in);
		int n=scanner.nextInt();
		
		int[] arr=new int[n];
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			arr[i]=scanner.nextInt();
		}
		res[0]=arr[0];
		int length=1;
		for(int i=1;i<n;i++){
			if(res[length-1]<arr[i])
				res[length++]=arr[i];
			else{
				int p=lowbound(res,0,length,arr[i]);
				//System.out.println(p);
				res[p]=arr[i];
			}
		}
		System.out.println(length);
	}

	private static int lowbound(int[] arr, int beg, int end, int x) {
		// TODO Auto-generated method stub
		int mid=(beg+end)/2;
		while(beg<end){
			if(x<=arr[mid])
				end=mid;
			else beg=mid+1;
			mid=(beg+end)/2;
		}
		return beg;
	}

}



Measured memory_bytes: 70672
a,b,c,k=map(int,input().split())

x=0
y=0
if(a>=k):
    x=k
    k=0
else:
    x=a
    k=k-a
if(b>=k):
    k=0
else:
    k=k-b
if(c>=k):
    y=k
    k=0
print(x-y)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
int main()
{
    fastio();
   
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll x,n;
        cin>>x>>n;
        set<ll> s;
        for(ll i=-200;i<200;i++)
        {
            s.insert(i);
        }
        for(int i=0;i<n;i++)
        {
            ll y;
            cin>>y;
            s.erase(y);
        }
        ll ans=0,min=2000;
        for(auto it =s.begin();it!=s.end();it++)
        {
            //cout<<*it<<" "<<x<<" "<<ans<<" "<<abs(*it-x)<<endl;
            if(abs(*it-x)<min)
            {
                min = abs(*it-x);
                ans = *it;
            }
        }
        cout<<ans<<endl;
    }
    
}

Measured memory_bytes: 3672
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;

#define ll int64_t
const ll MOD = 1e9 + 7;


int main()
{

  ll n, m;
  cin >>  n >> m;
  ll ans = 0;

  if (abs(n - m) <= 1) {
    ans = 1;
    for (ll i = n; i >= 1 ; i--) {
      ans = (ans * i) % MOD;
    }
    for (ll i = m; i >= 1 ; i--) {
      ans = (ans * i) % MOD;
    }

    if (n == m)ans *= 2;
    ans = ans % MOD;

    cout << ans << endl;
  } else {
    cout << ans << endl;
  }


  return 0;
}


Measured memory_bytes: 256