akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int ans = 1000000;
  for(int i = 1; i <= 100; i++) {
    int sum = 0;
    for(int j = 0; j < N; j++) {
      sum += (vec.at(j) - i) * (vec.at(j) - i);
    }
    if(sum < ans) {
      ans = sum;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
using namespace std;
int arr[1001];
int main()
{
    int n=0,quan=0;
    cin>>n;
    cin>>quan;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int sum=0;
    for(int i=0;i<quan;i++){
        sum+=arr[i];
    }
cout<<sum;
    return 0;
}


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

#define task "F"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (ll i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((ll)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const ll N = 2e6 + 4, mod = 1e9 + 7;
ll r1, r2, c1, c2, gt[N], igt[N];
ll power(ll x, ll y)
{
    x %= mod;
    ll res = 1;
    while (y)
    {
        if (y & 1) res = res * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return res;
}
inline ll C(ll k, ll n)
{
    return ((gt[n] * igt[k]) % mod * igt[n - k]) % mod;
}
ll res;
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> r1 >> c1 >> r2 >> c2;
	gt[0] = 1;
	rep(i, 1, c2 + r2 + 2) gt[i] = gt[i - 1] * i % mod;
	igt[c2 + r2 + 2] = power(gt[c2 + r2 + 2], mod - 2);
	Rep(i, c2 + r2 + 1, 0) igt[i] = igt[i + 1] * (i + 1) % mod;
	rep(r, r1, r2)
	{
	    res = (res + C(c2, c2 + r + 1) - C(c1 - 1, c1 + r) + mod) % mod;
	}
	cout << res;
}


Measured memory_bytes: 31488
/*
	Samrat De
	NIT Durgapur
	A Noob Coder
*/

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define li long int
#define ll long long int
#define vec(x) vector<x> 
#define st(x) set<x> 
#define mpp(x,y) map<x,y>
#define qq(x) queue<x>
#define pqq(x) priority_queue<x> 
#define min_heap(x) priority_queue<x, vector<x>, greater<x> >
#define search(x,y,z) binary_search(x,y,z)
#define pi(x,y) pair<x,y>
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rel(i,x,y) for(ll i=x-1;i>=y;i--)
#define rev(x) reverse(x.begin(),x.end())
#define mem(x,a) memset(x,a,sizeof(x))
#define mod 1000000007
#define nxt_per(x) next_permutation(x.begin(),x.end())
#define pb push_back
#define pf push_front
#define ub upper_bound
#define lb lower_bound
#define vp(x,y) vec(pi(x,y) )
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int dxx[8]={0,0,1,-1,-1,-1,1,1};
int dyy[8]={1,-1,0,0,-1,1,1,-1};

/*
unordered_map<ll,ll> um
um.reserve(1<<15);
um.max_load_factor(0.25);
*/
//srand(time(NULL));
//auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
//std::mt19937 mt(seed);

using namespace std;

int main()
{
	fastio;
// best of luck don't loose hope man	

	string s;
	cin>>s;
	ll count=0,ans=0;
	rep(i,0,s.size())
	{	if(s[i]=='B')
			count++;
		else
			ans+=count;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
	string s;
	cin >> s;
	int f = 0;
	for(int i=0;i<s.size();++i){
		if(s[i] == 'C' && f == 0){
			f = 1;
		}
		if(s[i] == 'F' && f == 1){
			f = 2;
			break;
		}
	}
	if(f == 2) cout << "Yes" <<endl;
	else cout << "No" <<endl;
	return 0;
}



Measured memory_bytes: 256
using System;

namespace ABC_093_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string a = S.Substring(0, 1);
            string b = S.Substring(1, 1);
            string c = S.Substring(2, 1);
            if (a != b && b != c && c != a)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());

        int[] V = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int[] C = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        int[] VV = new int[N];

        for(int i = 0; i < N; i++)
        {
            VV[i] = V[i] - C[i];
        }

        Array.Sort(VV);

        int ans = 0;

        foreach(var itm in VV.SkipWhile(n => n < 0))
        {
            ans += itm;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
package main

import (
  "fmt"
)

func main() {
  var n int 
  fmt.Scan(&n)
  for i := 1; i < 10; i++ {
    j := n / i
    if j >= 1 && j < 10 && i * j == n {
      fmt.Println("Yes")
      return
    }
  }
  fmt.Println("No")
}

Measured memory_bytes: 512
# 0や1のケースに注意
# index out of range
# 貪欲

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    a,b,h,m = map(int, input().split())
    jikan = 30*h + m/2
    hun = 6*m
    if jikan <= hun:
        kakudo = min(hun-jikan, 360-(hun-jikan))
    else:
        kakudo = min(jikan-hun, 360-(jikan-hun))

    res = a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo))
    print(res**0.5)

if __name__ == '__main__':
    main()

Measured memory_bytes: 65992
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ret = 0;
    for (int i = 0; i < n - 2; ++i) {
        if (s.substr(i, 3) == "ABC")
            ret++;
    }
    cout << ret << "\n";
    return 0;
}

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

const int maxn = 20010;
int n, m, cnt, st, ed, lev[maxn], head[maxn];
char mp[110][110];
struct edge { int to, cap, nxt; } e[5000010];

int id(int x, int y, int z) {
    return z * n * m + (x - 1) * m + y;
}

void add(int from, int to, int cap) {
    e[cnt] = (edge){to, cap, head[from]}, head[from] = cnt++;
    e[cnt] = (edge){from, 0, head[to]}, head[to] = cnt++;
}

int bfs(int s, int t) {
    memset(lev, 0, sizeof(lev));
    queue<int> q; q.push(s), lev[s] = 1;
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int i = head[v]; ~i; i = e[i].nxt) {
            if (e[i].cap && !lev[e[i].to]) {
                q.push(e[i].to), lev[e[i].to] = lev[v] + 1;
            }
        }
    }
    return lev[t];
}

int dfs(int v, int t, int f) {
    if (v == t) return f;
    int add = 0;
    for (int i = head[v]; ~i && add < f; i = e[i].nxt) {
        if (e[i].cap && lev[e[i].to] == lev[v] + 1) {
            int d = dfs(e[i].to, t, min(e[i].cap, f - add));
            if (d) e[i].cap -= d, e[i ^ 1].cap += d, add += d;
            else lev[e[i].to] = -1;
        }
    }
    return add;
}

int dinic(int s, int t) {
    int flow = 0;
    while (bfs(s, t)) flow += dfs(s, t, INT_MAX);
    return flow;
}

int main() {
    memset(head, -1, sizeof(head));
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%s", mp[i] + 1);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (mp[i][j] == '.') continue;
            if (mp[i][j] == 'S') st = id(i, j, 0);
            else if (mp[i][j] == 'T') ed = id(i, j, 1);
            add(id(i, j, 0), id(i, j, 1), mp[i][j] == 'o' ? 1 : INT_MAX);
            for (int k = 1; k <= n; k++) if (i ^ k) {
                if (mp[k][j] ^ '.') add(id(i, j, 1), id(k, j, 0), INT_MAX);
            }
            for (int k = 1; k <= m; k++) if (j ^ k) {
                if (mp[i][k] ^ '.') add(id(i, j, 1), id(i, k, 0), INT_MAX);
            }
        }
    }
    int ans = dinic(st, ed);
    printf("%d\n", ans > 1e9 ? -1 : ans);
    return 0;
}

Measured memory_bytes: 47616
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		if(y >= r && y <= H - r && x >= r && x <= W - r) {
			System.out.printf("Yes\n");
		} else {
			System.out.printf("No\n");
		}
	}
}


Measured memory_bytes: 26372
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define dump(x) (cerr << #x << " = " << x << endl)
#define dump2(x, y) (ceer << #x << ", " << #y << " = " << x << ", " << y << endl)

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

int s, n, t;
string weekday, ti;
int p, m;
int week;
double c;

void func(int& day, int& tim) {
	if(tim >= 1440) {
		tim -= 1440;
		day = (day + 1) % 7;
	}
}

bool match(int day, int tim) {
	if(week == 7 || day == week) {
		if(ti == "All" || (ti == "Day" && (360 <= tim && tim < 1080))
		   || (ti == "Night" && (tim < 360 || 1080 <= tim)))
			return true;
	}

	return false;
}

double calc(int day, int tim) {
	double res = 1.0;
	rep(hoge, m) {
		int nti = tim + s, nday = day;
		func(nday, nti);
		
		if(match(day, tim) && match(nday, nti)) {
			res *= c;
		}

		tim += t;
		func(day, tim);
	}

	return 1.0 - res;
}

int main()
{
	map<string, int> conv;
	conv["Sun"] = 0;
	conv["Mon"] = 1;
	conv["Tue"] = 2;
	conv["Wed"] = 3;
	conv["Thu"] = 4;
	conv["Fri"] = 5;
	conv["Sat"] = 6;
	conv["All"] = 7;
	for (;;) {
		cin >> s >> n >> t >> weekday >> ti >> p >> m;
		if (s == 0 && n == 0 && t == 0
		&& weekday == "None" && ti == "None"
		&& p == 0 && m == 0)
			break;

		c = pow(1.0 - 1.0 / p, n);
		
		week = conv[weekday];
		double ans = 0.0;
		for(int i = 0; i < 7; ++i)
			for(int j = 0; j < 1440; ++j)
				ans = max(ans, calc(i, j));

		printf("%.15lf\n", ans);		
	}
		
	return EXIT_SUCCESS;
}

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

int n;
ll a[10101], b[10101];

int main()
{
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ca = 0, cb = 0;
    rep(i, n)
    {
        if(a[i] >= b[i])
        {
            cb += a[i] - b[i];
        }
        else
        {
            if(a[i] % 2 != b[i] % 2)
            {
                b[i]++;
                cb++;
            }
            ca += (b[i] - a[i]) / 2;
        }
    }
    //cout << ca << " " << cb << endl;
    if(ca >= cb)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	UL A[2000];
	UL m[2000];
	
	void Solve() {
		UL N; cin >> N;
		ULL X; cin >> X;
		rep(i, N) cin >> A[i];
		rep(i, N) m[i] = 1000000001;

		ULL ans = 0;
		rep(i, N) ans += A[i];
		rep(x, N) {
			ULL ansbuf = 0;
			rep(i, N) {
				m[i] = min(m[i], A[(N - x + i) % N]);
				ansbuf += m[i];
			}
			ans = min(ans, ansbuf + X * x);
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

//int u[100000];
//int v[100000];
//long long w[100000];
int color[100000];
vector <pair <long long, int> > weight_edges[100000];

int flip_color(int c){
    if(c == 1){
        return 0;
    } 
    return 1;
}

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N - 1; i++){
        int u;
        int v;
        long long w;
        cin >> u >> v >> w;
        weight_edges[u - 1].push_back(make_pair(w, v - 1));
        weight_edges[v - 1].push_back(make_pair(w, u - 1));
    }

    for(int i = 0; i < N; i++){
        color[i] = -1;
    }
    queue <int> q;
    q.push(0);
    color[0] = 0;
    while(!q.empty()){
        int cur = q.front();
        q.pop();
        for(int i = 0; i < weight_edges[cur].size(); i++){
            long long weight = weight_edges[cur][i].first;
            int next = weight_edges[cur][i].second;
            if(color[next] < 0){
                if(weight % 2 == 1){
                    color[next] = flip_color(color[cur]);
                } else {
                    color[next] = color[cur];
                }
                q.push(next);
            }
        }
    }
    for(int i = 0; i < N; i++){
        cout << color[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 8320
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

int n;

int dfs(string s) {
	if (stoll(s)>n)return 0;
	int count = 0;
	if (s.find("7") != string::npos && s.find("5") != string::npos && s.find("3") != string::npos) {
			count = 1;
	}
	count += dfs(s + "7");
	count += dfs(s + "5");
	count += dfs(s + "3");
	return count;
}

signed main(void) {
	cin >> n;
	print(dfs("0"));
}

Measured memory_bytes: 256
N=int(input())
s=input()

rcnt=s.count("R")
gcnt=s.count("G")
bcnt=s.count("B")
sum=rcnt*gcnt*bcnt#条件1を満たす組み合わせの数

for i in range(N):
    for d in range(N):
        j=i+d
        k=j+d
        if k>=N:
            break
        if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:#等間隔の組み合わせを除く
            sum-=1
print(sum)

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


N = int(input())
xu = [input().split() for _ in range(N)]
ans=0
for i in range(N):
    if xu[i][1] == "BTC":
        ans+=float(xu[i][0])*380000
    else:
        ans+=float(xu[i][0])
print(ans)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    for(int i=0; i<n; ++i)
        cin >> x[i];
    sort(x.begin(), x.end());

    int ans = INT_MAX;
    for(int p=x.front(); p<=x.back(); ++p){
        int sum = 0;
        for(int i=0; i<n; ++i){
            int d = x[i] - p;
            sum += d * d;
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
using namespace std;
#define ll long long int
#define inf 0x3fffff
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define print(a) cout<<a
#define prints(a) cout<<a<<" "
#define println(a) cout<<a<<endl
#define fori(n) for(i=0;i<n;i++)
#define forj(n) for(j=0;j<n;j++)
#define fork(n) for(k=0;k<n;k++)


int main()
{
        int i,j,n,m;
        bool flag=0;
        scanf("%d %d",&n,&m);
        char mark[n][m];
        int val[n+2][m+2]={0};
        getchar();
        for(i=0;i<n;i++){
                for(j=0;j<m;j++){
                        scanf("%c",&mark[i][j]);
                        if(mark[i][j]=='.') flag=true;
                }
                getchar();
        }

        if(flag){
                for(i=0;i<n;i++){
                        for(j=0;j<m;j++){
                                if(mark[i][j]!='.'){
                                        val[i-1+1][j-1+1]+=1;
                                        val[i-1+1][j+1]+=1;
                                        val[i-1+1][j+1+1]+=1;
                                        val[i+1][j+1+1]+=1;
                                        val[i+1][1+j]+=1;
                                        val[i+1][1+j-1]+=1;
                                        val[i+1+1][1+j-1]+=1;
                                        val[i+1+1][1+j]+=1;
                                        val[i+1+1][1+j+1]+=1;
                                }
                        }
                }
        }

        for(i=0;i<n;i++){
                for(j=0;j<m;j++){
                        if(mark[i][j]=='.') printf("%d",val[i+1][j+1]);
                        else printf("%c",mark[i][j]);
                }
                puts("");
        }
        puts("");
}


Measured memory_bytes: 256
n,l=list(map(int,input().split()))
if l>0:
    print(int(n*(2*l+n-1)/2-l))
elif l<=0 and 0<=l+n-1:
    print(int(n*(2*l+n-1)/2))
else:
    print(int(n*(2*l+n-1)/2-(l+n-1)))

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<vector<int>> A(N,vector<int>(M));
  vector<int> B(M);
  //vector<int> C(N);

  for(int i = 0; i < N; i++){
    for(int j=0; j < M; j++){
      int aij;
      cin >> A.at(i).at(j);
    }
  } 
  
  for(int i = 0; i < M; i++){
    cin >> B.at(i);
  }
  
  for(int i = 0; i < N; i++){
    int ab=0;
    for(int j=0; j < M; j++){
      ab+=(A.at(i).at(j)*B.at(j));
     }
    cout << ab << endl;
    //C.at(i) =ab;
  } 
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 10000000000000007
#define eps 1e-13
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.9lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios::sync_with_stdio(false); cin.tie(0)
#define endl '\n'
int main()
{
    ll x,y;
    cin>>x>>y;
    if(x==0)
    {
        if(y>=0){cout<<y<<endl;}
        else cout<<-y+1LL<<endl;
        return 0;
    }
    if(y==0)
    {
        if(x<=0)cout<<-x<<endl;
        else cout<<x+1LL<<endl;
        return 0;
    }
    if(x>0)
    {
        if(y>0)
        {
            if(y>=x){cout<<y-x<<endl;return 0;}
            else {cout<<x-y+2LL<<endl;return 0;}
        }
        else
        {
            ll p=x+y;if(p<0)p=-p;
            cout<<p+1LL<<endl;
            return 0;
        }

    }
    else
    {
        if(y>0)
        {

            ll p=x+y;
            if(p<0)p=-p;
            cout<<p+1LL<<endl;
        }
        else
        {
            if(y>=x)
            {
                cout<<y-x<<endl;
            }
            else{cout<<x-y+2LL<<endl;}
        }
    }




}


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

void solve() {
    long long N, M, A, s = 0, ans = 0;
    cin >> N >> M;
    map<long long, long long> mp;
    mp[0] = 1;
    rep(i,N) {
        cin >> A;
        s += A;
        s %= M;
        ans += mp[s];
        mp[s]++;
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
}


Measured memory_bytes: 4224
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine


----------
data Heap a = Empty | Heap Int a (Heap a) (Heap a) deriving Show

empty = Empty

singleton :: a -> Heap a
singleton x = Heap 1 x Empty Empty

--併合
merge :: Ord a => Heap a -> Heap a -> Heap a
merge h Empty = h
merge Empty h = h
merge h1@(Heap _ x l1 r1) h2@(Heap _ y l2 r2)
    | x > y     = makeHeap x l1 (merge r1 h2)
    | otherwise = makeHeap y l2 (merge r2 h1)

rank :: Heap a -> Int
rank Empty = 0
rank (Heap r _ _ _) = r

makeHeap :: a -> Heap a -> Heap a -> Heap a
makeHeap x a b
    | ra >= rb  = Heap (rb + 1) x a b
    | otherwise = Heap (ra + 1) x b a
    where ra = rank a
          rb = rank b

--挿入
heapInsert :: Ord a => Heap a -> a -> Heap a
heapInsert h x = merge (singleton x) h

--リストから
heapFromList :: Ord a => [a] -> Heap a
heapFromList = foldl heapInsert Empty

--リストへ
heapToList :: Ord a => Heap a -> [a]
heapToList h | isEmpty h = []
             | otherwise = let (x, h') = deleteMax h in x : heapToList h'

--最大値の取り出し（削除）
deleteMax :: Ord a => Heap a -> (a, Heap a)
deleteMax Empty = error "Empty Heap"
deleteMax (Heap _ x a b) = (x, merge a b)

--最大値を見る（削除しない）
findMax :: Heap a -> a
findMax Empty = error "Empty Heap"
findMax (Heap _ x _ _) = x

--空か
isEmpty :: Heap a -> Bool
isEmpty Empty = True
isEmpty _     = False

----------

main = do
    [n,m] <- getIntList
    ab <- replicateM n $ do
        [a,b] <- getIntList
        return (a,b)
    
    let works = V.create $ do
            vec <- VM.replicate (10^5 + 1) empty
            forM_ ab $ \(a,b) -> do
                VM.modify vec (flip heapInsert b) a
            return vec
    
    let result = fst $ foldl' f (0,empty) [1..m]
         where f (s,h) i = (s+b, newh)
                  where h' = merge h $ works V.! i
                        (b, newh) | isEmpty h' = (0,empty)
                                  | otherwise = deleteMax $ h'

    print result

Measured memory_bytes: 45924
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	long long int S;
	cin >> S;

	long long int L;
	L = (long long int)pow(S, 0.5);
	if (L*L < S) L += 1;
	long long int D;
	D = L * L - S;
	long long int Lx, x, y;
	if (D == L)
	{
		Lx = L - 1;
		x = 0;
		y = 0;
	}
	else if (D > L)
	{
		Lx = L - 1;
		x = 1;
		y = D - L;
	}
	else
	{
		Lx = L;
		x = 1;
		y = D;
	}

	cout << 0 << " " << 0 << " " << x << " " << L << " " << Lx << " " << y << endl;

	return 0;
}


Measured memory_bytes: 384
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    stdin.read_until(b'\n', &mut Vec::new()).unwrap();
    let ans = stdin.split(b' ')
        .map(|r| {
            String::from_utf8(r.unwrap()).unwrap()
                .trim_right()
                .parse::<u32>().unwrap()
                .trailing_zeros()
        })
        .min()
        .unwrap();
    println!("{}", ans);
}

Measured memory_bytes: 4352
s = int(input())
a = [s]
ans = 1
while True:
  if a[-1]%2 == 0:
    b = a[-1]//2
  else:
    b = 3 * a[-1] + 1
  ans += 1
  if b in a:
    print(ans)
    break
  a.append(b)

Measured memory_bytes: 3060
import sys
import numpy as np
import itertools
import collections
import math
from collections import deque

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

h = itertools.combinations_with_replacement
p = itertools.permutations

def main():
    # input
    N, M = map(int, input().split())
    A = list(map(int, readline().split()))

    under = math.ceil(sum(A)/(4*M))
    #print(under)
    count = sum([1 for x in A if x >= under])

    if M <= count:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 21524
import sys
from itertools import compress


def solve(w):
    """ w[g]???????????¨???????????????????????????????????????
        ???????????? 1g????????? 2g????????? ??? 512g????????????????????????????????????????????????????????¢???
    """
    bin_w = '{0:010b}'.format(w)  # ?????????2?????°??¢??????(512g??????????????§???????????§???????????????0????????£?????°??????)
    result = [int(x) for x in bin_w]  # ??????????????????????????????????????°??????
    result.reverse()  # ???????????????????????¨???1g, 2g????????§?????????????????¨???????????????????????????????????????
    return result


if __name__ == '__main__':
    weights = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]  # ??????????????????

    # ??????????????\???
    for line in sys.stdin:
        w = int(line.strip())

        # ???????????????????±???????
        ans = solve(w)
        # print(ans)

        # ???????????????
        comp = compress(weights, ans)  # weights[]??????????????????ans[i]???1?????¨??????????????????
        print('{0}'.format(' '.join(map(str, comp))))

Measured memory_bytes: 7724
A=int(input())
B=int(input())
C=int(input())
X=int(input())
p=0
for a in range(0,A+1):  
    for b in range(0,B+1):
        for c in range(0,C+1):
            sum=500*a+100*b+50*c
            if X==sum:
                p=p+1

print(p)

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    double pi = 3.14159265359;
    double a, b, h, m; cin >> a >> b >> h >> m;
    double sita1 = (60 * h + m) / 2;
    double sita2 = m * 6; 
    double ans = (a * a) + (b * b) - (2.0 * a * b * cos(pi * (sita1-sita2) / 180));
    cout << std::fixed << std::setprecision(20) << pow(ans, 0.5)  << endl;
}

Measured memory_bytes: 4356
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for(int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for(int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for(auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(long long N, std::vector<long long> x, std::vector<long long> y) {
    if(N == 1) {
        print(1);
        return;
    }

    ll ans = INF;
    rep(i, 0, N) {
        rep(j, 0, N) {
            if(i == j || x[i] > x[j]) {
                continue;
            }
            ll p = x[j] - x[i];
            ll q = y[j] - y[i];
            ll cnt = 0;
            rep(k, 0, N) {
                rep(l, 0, N) {
                    if(k == l || x[k] > x[l]) {
                        continue;
                    }
                    ll dx = x[l] - x[k];
                    ll dy = y[l] - y[k];
                    if(dx == p && dy == q) {
                        cnt++;
                    }
                }
            }
            ans = min(ans, N - cnt);
        }
    }
    print(ans);
}

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


Measured memory_bytes: 256
using System;

namespace XCubic
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			//??\??????
			var x = int.Parse(Console.ReadLine());
			//?????????????±???????
			double dPow = System.Math.Pow(x, 3);
			Console.WriteLine (dPow);
		}
	}
}

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << endl;
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

void solve(){
    ll n;
    cin>>n;
    ll cnt[n+1]={0};
    for(ll i=2;i<=n;i++){
        for(ll j=2*i;j<=n;j+=i){
            cnt[j]++;
        }
    }
    ll ans=1;
    for(ll i=2;i<=n;i++){
        ans+=(cnt[i]+2)*i;
    }
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 81724
using namespace std;
#include<bits/stdc++.h>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define st first
#define nd second
#define FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define FORD(i,a,b) for(int i=(a),b_=(b);i>=b_;--i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define removeDuplicate(a) sort(a.begin(), a.end()); a.resize(distance(a.begin(), unique(a.begin(), a.end())))
 
const int N = 2e5 + 1;
const int MOD = 1e9 + 7;

int add (int a, int b) {
  return (a += b) >= MOD ? a - MOD : a;
}
 
int sub (int a, int b) {
  return (a -= b) < 0 ? a + MOD : a;
}
 
int mul (int a, int b) {
  return (long long) a * b % MOD;
}
 
int power(int a, long long n) {
  int res = 1;
  while(n) {
    if (n & 1LL) res = mul(res, a);
    a = mul(a, a);
    n >>= 1LL;
  }
  return res;
}
int inv(int a) {
  return power(a, MOD - 2);
}

class Binomial {
  vector <int> fact, inv; 
  int n; 
  public:
    Binomial() {};
    Binomial(int sz) : n(sz), fact(sz + 1), inv(sz + 1) {
      fact[0] = fact[1] = inv[0] = inv[1] = 1;
        for (int i = 2; i <= n; ++i) {
            fact[i] = 1LL * fact[i - 1] * i % MOD;
            inv[i] = (MOD - 1LL * (MOD / i) * inv[MOD % i] % MOD) % MOD;
        }
        for (int i = 2; i <= n; ++i) inv[i] = 1LL * inv[i] * inv[i - 1] % MOD;
    };
    int operator() (int y, int x) { // x<=y; x>=0
        if (x > y) return 0;
        return 1LL * fact[y] * inv[x] % MOD * inv[y - x] % MOD;
    }
} nCr(N);

int solve (int n, int r) {
    return nCr(n + r, r); 
}

int calc (int a, int b, int c, int d) {
    int res = mul(solve(a, b), solve(c, d)); 
    return res; 
}


int main() {
    #define TASK "TASK"
    // freopen(TASK".inp","r",stdin);
    // freopen(TASK".out","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int h, w, a, b;  
    cin >> h >> w >> a >> b;
    int ans = 0; 
    for (int i = b; i < w; ++i) {
        ans = add(ans, calc(i, h - a - 1, w - i - 1, a - 1));
    }
    cout << ans; 
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
int a,b;
  int arr[4]={0};
 cin>>a>>b;
  
arr[a]++;
arr[b]++;
for(int i=1;i<4;i++){
if(arr[i]==0)cout<<i;
}  
  return 0;
} 

Measured memory_bytes: 256
X, N = [int(x) for x in input().split()]

def main(X, N):
    if N == 0:
        return X
    arrp = [int(x) for x in input().split()]
    minus = X
    plus = X
    while True:
        if minus not in arrp:
            print(minus)
            exit()
        if plus not in arrp:
            print(plus)
            exit()
        minus -= 1
        plus += 1

print(main(X, N))

Measured memory_bytes: 9204
"""
                            pppppppppppppppppppp
                         ppppp  ppppppppppppppppppp
                      ppppppp    ppppppppppppppppppppp
                      pppppppp  pppppppppppppppppppppp
                      pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
       ppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppp
      pppppppppppppppppppppppppppppppppppppppppppppppp  ppppppppppppppppppppp
     ppppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppppp
    ppppppppppppppppppppppppppppppppppppppppppppppp    pppppppppppppppppppppppp
   pppppppppppppppppppppppppppppppppppppppppppppp     pppppppppppppppppppppppppp
  ppppppppppppppppppppppppppppppppppppppppppppp      pppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppppppp               pppppppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppp     pppppppppppppppppppppppppppppppppppppppppppppp
  ppppppppppppppppppppppppppp    pppppppppppppppppppppppppppppppppppppppppppppppp
    pppppppppppppppppppppppp  pppppppppppppppppppppppppppppppppppppppppppppppppp
     ppppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppppp
      pppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppp
       ppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
                              pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppp  pppppppp
                              ppppppppppppppppppppp    ppppppp
                                 ppppppppppppppppppp  ppppp
                                    pppppppppppppppppppp
"""


import sys
from functools import lru_cache, cmp_to_key
from collections import defaultdict as dd, deque, Counter as C
from bisect import bisect_left as bl, bisect_right as br, bisect
from heapq import heapify, heappop, heappush
# from math import sqrt
from math import ceil, log, floor
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var, end="\n"): sys.stdout.write(str(var)+end)
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n, k = sp()
arr = L()
low, high = 1, max(arr)
answer = max(arr)
while low <= high:
    mid = (low + high) >> 1
    req = 0
    for i in range(n):
        if arr[i] <= mid:
            continue
        else:
            temp = arr[i] // mid
            req += temp
    if req <= k:
        answer = min(answer, mid)
        high = mid - 1
    else:
        low = mid + 1
out(answer)


Measured memory_bytes: 93940
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#define ll long long
#define mod 100003
#define inf 0x3f3f3f3f
using namespace std;

const int N=105;

ll fm,fz,x;

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

int main()
{
    int a,b;
    while(cin>>a)
    {
        b=gcd(a,2);
        cout<<(2*a)/b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(ll x, ll y)
{
	return (x|y)&(~x|~y);	
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
	ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s,h;
	string str,str1;
	cin>>k>>n;
	ll arr[n];
	rep(i,0,n)
	{
		cin>>arr[i];
	}
	ll nn = 2*n-1;
	ll arr1[nn];
	rep(i,0,n)
	{
		arr1[(nn/2)+i]=arr[i];
	}
	a = arr[0];
	ll ind = (nn/2)-1;
	for(i=n-1;i>0;i--)
	{
		arr1[ind] = arr[i]-k;
		ind--;
	}
	ll mini = INT_MAX;
	// rep(i,0,nn)
	// {
	// 	cout<<arr1[i]<<" ";
	// }	
	// cout<<endl;
	rep(i,0,nn-n+1)
	{
		// cout<<arr1[i+n-1]-arr1[i]<<" ";
		mini = min(mini, arr1[i+n-1]-arr1[i]);
	}
	// cout<<endl;
	cout<<mini;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int N;
        cin>>N;
        if(!N)break;
        int rui[10000]={0};
        for(int i=1;i<=N;i++){
            int a;
            cin>>a;
            rui[i]=rui[i-1]+a;
        }
        int ans=-2000000000;
        //for(int i=0;i<=N;i++)printf("[%d]",rui[i]);
        for(int i=0;i<=N;i++){
            for(int j=i+1;j<=N;j++)ans=max(ans,rui[j]-rui[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1208
#https://juppy.hatenablog.com/entry/2018/11/17/%E8%9F%BB%E6%9C%AC_python_Binary_Indexed_Tree_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0
n, Q = map(int, input().split())
#A1 ... AnのBIT(1-indexed)
BIT = [0]*(n+1)

#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return
  

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

for i, x in enumerate(a):
  BIT_update(i+1, x)
  
for _ in range(Q):
  t, a, b = map(int, input().split())
  if t == 0:
    BIT_update(a+1, b)
  else:
    print(BIT_query(b)-BIT_query(a))

Measured memory_bytes: 132284
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>

const int N = 2e5 + 52;
struct edge {
	int to, next, w;
} e[N << 1];
int n, head[N], cnt;
void ad(int x, int y, int z) { e[++cnt] = {y, x[head], z}, x[head] = cnt; }

std::queue<int> q;
int dis[N];
int main() {
	memset(head, -1, sizeof head);
	memset(dis, 0x3f, sizeof dis), dis[1] = 1;
	scanf("%d", &n);
	for (int i = 1; i < n; i++) ad(i, (i + 1) % n, 1);
	for (int i = 1; i < n; i++) ad(i, i * 10 % n, 0);
	for (q.push(1); !q.empty(); q.pop())
		for (int x = q.front(), i = x[head], nx; ~i; i = e[i].next)
			if ((nx = e[i].to)[dis] > x[dis] + e[i].w) nx[dis] = x[dis] + e[i].w, q.push(nx);
	printf("%d", 0 [dis]);
}

Measured memory_bytes: 4480
# -*- coding: utf-8 -*-

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

N, M = map(int, input().split())
A = []
B = []
for i in range(N):
    A.append(input())
    
for i in range(M):
    B.append(input())

for i in range(N-M+1):
    for j in range(N-M+1):
        ok = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]: ok = False;
        if ok:
            print("Yes")
            exit(0)
print("No")


Measured memory_bytes: 4564
#include<stdio.h>

int main(void){
    int any;
    int count=0;
    int s = 0;
    int i;

    scanf("%d",&any);

    for(i = 1; i < any; i++){
        s = i + 1;
        if(s <= any){
            //printf("%d\n", s);
            count++;
        }
        for(; s <= any;){
            //printf("%d,%d\n", i,s);
            s = s + 2;
            if(s <= any){
                count++;
            }
        }
    }
    printf("%d",count);
}

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

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  if(A==5&&B==5&&C==7){cout<<"YES"<<endl;
                      }else if(A==5&&B==7&&C==5){cout<<"YES"<<endl;
                      }else if(A==7&&B==5&&C==5){cout<<"YES"<<endl;
                      }else{cout<<"NO"<<endl;}                                     
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int A;
    vector<string> day;
    day = { "SUN","MON", "TUE", "WED","THU","FRI","SAT"};
    for(int i = 0; i < 7; i++){
        if(S == day.at(i)){
           cout << 7 - i << endl;
        }
        else{
        }
    }
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,m,k,a,b,ch[100];
vector<int>v[100];
queue<int>que;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>m>>k;
        for(int i=0;i<k;i++){
            cin>>a;
            v[m-1].push_back(a-1);
        }
    }
    que.push(0);
    ch[0]=1;
    while(que.size()){
        int q=que.front();
        que.pop();
        for(auto x:v[q]){
            if(ch[x]==0){
                ch[x]=ch[q]+1;
                que.push(x);
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<ch[i]-1<<endl;
    }
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+100;
const int maxc=26;
const int mod=998244353;
ll dp[3500];
ll a[3500];
int main()
{
    int n,s;
    scanf("%d%d",&n,&s);
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    ll ans=0;
    for(int i=1;i<=n;i++){
        dp[0]++;
        for(int j=s;j>=a[i];j--){
            int u=j-a[i];
            if(u>=0&&u<=s){
                if(j==s)
                    ans=(ans+dp[u]*(n-i+1))%mod;
                else if(u)
                    dp[j]=(dp[j]+dp[u])%mod;
            }
        }
        if(a[i]<=s)
            dp[a[i]]=(dp[a[i]]+i)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}
/*

*/


Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>
#include<math.h>
typedef long long int lli;
lli gcd(lli a,lli b);
int main(void)
{
    lli N;
  	bool flag = false;
    scanf("%lld", &N);
    lli min = N-1;
    lli tmp;
  	lli j;
    for (lli i = ceil(sqrt(N)); i>=1; i--)
    {
      j = N/i;
        if(i*j==N){
       tmp = i+j-2;
       printf("%lld",tmp);
          return 0;
      }   
    }
    return 0;
}

Measured memory_bytes: 128