akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MAX_int = (1 << 31) - 1;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("battleship.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    ll a[n][2];
    rep(i, 0, n)
        cin >> a[i][0] >> a[i][1];
    ll ans = 0, curr = 0;
    repb(i, n - 1, -1)
    {
        a[i][0] += curr;
        ll d = (a[i][0] + a[i][1] - 1) / a[i][1] * a[i][1] - a[i][0];
        ans += d;
        curr += d;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <climits>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n;
    cin >> n;
    vector<ll>a(n),b(n);
    ll ans = 0;
    rep(i,n){
        cin >> a[n-i-1] >> b[n-i-1];
    }
    rep(i,n){
        a[i]+=ans;
        if(a[i]%b[i])ans+=b[i]-a[i]%b[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
//IN THE NAME OF GOD;
//Test By Dev-C++5.11
#include<bits/stdc++.h>
#define ll  long long
#define isc ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ld long double
#define ss string
#define ww while
#define vl vector<ll>
#define pb push_back
#define in insert
#define itr iterator
#define gt goto
#define rep(i,n,j) for(ll i=n;i<j;i++)
#define tep(i,n,j) for(ll i=n;i>=j;i--)
#define co(n) cout << n ;
#define pll pair<ll,ll>
using namespace std;

ll bmm(ll a, ll b) {
	if (b == 0) return a;
	else return bmm(b, a%b);
}
ll kmm(ll a, ll b) {
	return(a*b) / bmm(a, b);
}

const ll mod = 1e9 + 7;
const ll MAXN = 2e5+5;

ll n;

int main() {
	isc;
	cin >> n;
	if(n%2==0){
		n/=2;
		cout << n-1;
	}
	else{
		n--;n/=2;
		cout << n;
	}
	return 0;
}


Measured memory_bytes: 256
//bit全探索
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

bool red[110000];
int cnt[110000];

int main(){cout<<fixed<<setprecision(10);
		   int n,m;
           cin>>n>>m;
           int x,y;
           red[1]=1;
           rep(i,0,n)cnt[i+1]=1;
           rep(i,0,m){
             cin>>x>>y;
             if(red[x])red[y]=1;
             cnt[x]--;
             cnt[y]++;
             if(cnt[x]==0)red[x]=0;
           }
           int ans=0;
           rep(i,0,n)if(red[i+1]&&cnt[i+1]>0)ans++;
           cout<<ans<<endl;
}

Measured memory_bytes: 4024
import itertools
N = int(input())
P = [int(x) for x in input().split()]
Q = [int(y) for y in input().split()]

BUF_1 = [0] * N
for i in range(N) :
    BUF_1[i] = i+1
buf_2 = 0
buf_3 = 0
buf_4 = 0
j = 0
for i in itertools.permutations(BUF_1) :
    j += 1
    if tuple(P) == i :
        buf_2 = j
        buf_4 += 1
    if tuple(Q) == i :
        buf_3 = j
        buf_4 += 1
    if buf_4 == 2 :
        break

print(abs(buf_2 - buf_3))

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int m=in.nextInt();
		int ar1 = 0,ar2=0;
		Graph g = new Graph(n);
		
		for(int i=0;i<m;i++) {
			ar1= in.nextInt();
			ar2= in.nextInt();
			g.addEdge(ar1-1,ar2-1);
		}
		
		System.out.println(g.getAns());
	}
}

class Graph{
	int N;
	ArrayList<Integer>[] listy;
	private boolean[] visited;
	private int[] val;
	Graph(int n){
		N=n;
		val = new int[n];
		visited = new boolean[n];
		listy = new ArrayList[n];
		for(int i=0;i<n;i++) {
			listy[i] = new ArrayList<Integer>();
		}
	}
	public int getAns() {
		for(int i=0;i<N;i++) {
			if(visited[i]!=true) {
				int x = DFS(i);
				val[i]=x;
			}
		}
		int maxy=-1;
		for(int i=0;i<N;i++) {
			maxy= Math.max(maxy,val[i]);
		}
		return maxy-1;
				
	}
	private int DFS(int i) {
		visited[i] = true;
		
		Iterator<Integer> x = listy[i].listIterator();
		int maxy=0;
		while(x.hasNext()) {
			int j = x.next();
//			System.out.println("Parent: " + (i+1) + " Son: "+(j+1));

			if(visited[j]!=true) {
				int cu = DFS(j);
				val[j] =cu;
			}
//			System.out.println("Value for "+ (j+1) + " is "+val[j]);
			maxy = Math.max(maxy, val[j]);
		}
		return maxy+1;
	}
	
	public void addEdge(int ar1, int ar2) {
		listy[ar1].add(ar2);
	}
}

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

#define ll long long int

int main(){
    int n;
    cin>>n;
    if(n == 1){
        cout<<"Hello World";
        return 0;
    }
    int a,b;
    cin>>a>>b;
    cout<<a+b;
    return 0;
}


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

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

    vector<i64> a(n), f(n);
    for (auto& e : a) cin >> e;
    for (auto& e : f) cin >> e;
    sort(begin(a), end(a));
    sort(begin(f), end(f), greater<>());

    i64 l = -1, r = INT64_MAX / 2;
    while (abs(r - l) > 1) {
        i64 mid = (r + l) / 2;

        i64 c = 0;
        for (i32 i = 0; i < n; i++) {
            c += max(0l, a[i] - mid / f[i]);
        }

        (c > k ? l : r) = mid;
    }

    cout << r << endl;
}


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

int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a % b);
}

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

  vector<int> y(n);
  for(int i = 0; i < n; ++i) {
    cin >> y.at(i);
  }

  for(int i = 0; i < n; ++i) {
    y.at(i) -= x;
  }

  int answer = abs(y.at(0));

  for(int i = 0; i < n; ++i) {
     answer = max(abs(answer), abs(y.at(i)));
  }


  for(int i = 0; i < n-1; ++i) {
    answer = min(abs(answer), abs(gcd(y.at(i), y.at(i+1))));
  }
  cout << abs(answer) << endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
string a;
int main(){
  cin>>a;
  if(a[0]=='A'&&a[1]=='A'&&a[2]=='A') cout<<"No";
  else if(a[0]=='B'&&a[1]=='B'&&a[2]=='B') cout<<"No";
  else cout<<"Yes";
  
  

}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(dp,-1,sizeof dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;
const int Mx = 100010;
int dp[3010][3010],n,m;
string Ans = "",s,t;

int Solve(int i=0,int j=0)
{
    if(i == n || j == m)
        R 0;
    int &Res = dp[i][j];
    if(Res != -1)
        R Res;
    Res = Solve(i+1,j);
    Res = max(Res,Solve(i,j+1));
    if(s[i] == t[j])
        Res = max(Res,1+Solve(i+1,j+1));
    R Res;
}

void Get_Path(int i=0,int j=0)
{
    if(i == n || j == m)
        R;

    if(s[i] == t[j] && (dp[i][j] == 1+dp[i+1][j+1] || dp[i+1][j+1]==-1))
    {
        Ans += s[i];
        Get_Path(i+1,j+1);
    }
    else if(dp[i+1][j] == dp[i][j])
    {
        Get_Path(i+1,j);
    }
    else
    {
        Get_Path(i,j+1);
    }
}

int main()
{

    SPEED;
    cin >> s >> t;
    n = s.sz,m=t.sz;
    Mdp;
    Solve();
    Get_Path();
    cout << Ans << endl;


    R 0;
}


Measured memory_bytes: 36096
import sys
sys.setrecursionlimit(10 ** 9)

N, M = map(int, input().split())
P_to_L = [[] for i in range(N)]  # 人から言語へのグラフ
L_to_P = [[] for i in range(M)]  # 言語から人へのグラフ

for i in range(N):
    info = list(map(int, input().split()))
    for l in info[1:]:
        P_to_L[i].append(l - 1)
        L_to_P[l - 1].append(i)


P_visited = [False] * N  # 訪問済み人
L_visited = [False] * M  # 訪問済み言語


def dfs(n, p_to_l):
    if p_to_l:
        P_visited[n] = True
        for to in P_to_L[n]:
            if not L_visited[to]:
                dfs(to, False)
    else:
        L_visited[n] = True
        for to in L_to_P[n]:
            if not P_visited[to]:
                dfs(to, True)


dfs(0, True)
print('YES' if all(P_visited) else 'NO')


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

#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax_v(ary) *max_element(all(ary))
#define vmin_v(ary) *min_element(all(ary))
#define vmax_id(ary) distance((ary).begin(),max_element(all(ary)))
#define vmin_id(ary) distance((ary).begin(),min_element(all(ary)))

using ll = int64_t;
using pll = pair<ll,ll>;
using vl = vector<ll>;

const ll INF=INT64_MAX;
const double EPS=1e-10;
const double PI=acos(-1.0);

void init(){cin.tie(0);ios::sync_with_stdio(false);}
//----------------------------------------------------

int main(){
  init();
  vl h(10);

  for(int i=0;i<10;i++){
    cin >> h[i];
  }

  sort(all(h),[](const ll &x,const ll &y){return x>y;});

  for(int i=0;i<3;i++){
    cout << h[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3176
import sys
from itertools import accumulate


def _tsundoku(n, m, k, a, b):
    a_temp = tuple(accumulate(a, initial=0))
    b_temp = tuple(accumulate(b, initial=0))

    ans = 0
    b_index = m
    for a_index in range(n + 1):
        if a_temp[a_index] > k:
            break
        while a_temp[a_index] + b_temp[b_index] > k:
            b_index -= 1
        else:
            ans = max(ans, a_index + b_index)
    return ans


def tsundoku(f):
    readline = f.readline
    n, m, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))

    return _tsundoku(n, m, k, a, b)


def main():
    ans = tsundoku(sys.stdin.buffer)
    print(ans)


if __name__ == '__main__':
    main()


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

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
const ll MOD = 1000000007;
const int SIZE = 110000;
ll inv[SIZE],fac[SIZE],finv[SIZE];
void make(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<SIZE;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll n,m;

int main() {
    make();
    std::cin >> n>>m;
    // mの素因数分解
    ll tmp_m = m;
    std::unordered_map<ll, ll> soin;
    while(tmp_m!=1){
        ll flag = false;
        for (int i = 2; i <= sqrt(tmp_m)+1; i++) {
            if(tmp_m % i ==0){
                soin[i]+=1;
                tmp_m/=i;
                flag = true;
                break;
            }
        }
        
        if(!flag){
            soin[tmp_m]+=1;
            break;
        }
    }
    ll select = 1;
    for(auto&e :soin){
        select %= MOD;
        select *= fac[e.second + n-1] * finv[e.second] %MOD * finv[n-1] %MOD;
    }
    select %= MOD;
    
    std::cout << select << std::endl;
    

}


Measured memory_bytes: 2816
#include <stdio.h>

int gcd(int x,int y){
  int n1,n2,k1;
  if(x>y){
    n1=x;  n2=y;
  }
  else{
    n1=y;  n2=x;
  }
  while((n1%n2)!=0){
    k1=n1;
    n1=n2;
    n2=(k1%n2);
  }
  return n2;
}

void main(){
  int i,j,k,n,g;
  long sum=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      for(k=1;k<=n;k++){
        g=gcd(i,j);
        g=gcd(g,k);
        sum+=g;
      }
    }
  }
  printf("%ld",sum);
}

Measured memory_bytes: 1732
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
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; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int X, N;
	cin >> X >> N;
	vector<int>p(N);
	rep(i, N)cin >> p[i];
	sort(p.begin(), p.end());
	P ans = { INF,INF }; //絶対値、数字
	for (int i = -5; i <= 105; i++) {
		bool b = false;
		for (int j = 0; j < N; j++) {
			if (i == p[j]) {
				b = true;
				break;
			}
		}
		if (b)continue;
		ans = min(ans, { abs(X - i),i });
	}
	cout << ans.second;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int k, s, z, ans = 0;
    cin >> k >> s;

    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            z = s - x - y;
            if (z >= 0 && z <= k) ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    c = input()
    next = ord(c) + 1
    print(chr(next))
    return

if __name__=='__main__':
    main()


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

class UnionFind {
private: vector<int> p, r;
public:
    int comp;
    UnionFind(int n) { r.assign(n, 0); p.assign(n, 0); comp = n;
    for (int i = 0; i < n; ++i) p[i] = i;}

    int findset(int i) { return (p[i] == i) ? i : (p[i] = findset(p[i])); }

    bool unionset(int i, int j) {
        int x = findset(i), y = findset(j);
        if (x != y) {
            --comp;
            if (r[x] > r[y]) p[y] = x;
            else {p[x] = y; if (r[x] == r[y]) ++r[y];}
            return true;
        }
        else return false;
    }
};

#define fi first
#define sc second
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
#define MOD 1000000007
typedef long long ll;

int n, m;
ll x;
vector<iii> el;
vector<ii> al[1005];
bool inMst[2005];
int diff[2005];
int t;
int maxEdge = 0;

bool dfs(int u, int p) {
    if (u == t) return true;
    bool found = false;
    for (auto v : al[u]) {
        if (v.fi == p) continue;
        if (dfs(v.fi, u)) {
            found = true;
            maxEdge = max(maxEdge, v.sc);
            break;
        }
    }
    return found;
}

ll expo(int b, int p) {
    if (p == 0) return 1;
    if (p == 1) return b;
    if (p % 2 == 1) return (expo(b, p-1) * b) % MOD;
    else {
        ll tmp = expo(b, p/2) % MOD;
        return (tmp * tmp) % MOD;
    }
}

int main() {
    //freopen("in.txt", "r", stdin);
    scanf("%d%d%lld", &n, &m, &x);
    for (int i = 0; i < m; ++i) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        el.push_back(iii(w, ii(u-1, v-1)));
    }
    sort(el.begin(), el.end());

    memset(inMst, 0, sizeof inMst);
    UnionFind UF(n);
    ll mst = 0;
    for (int i = 0; i < el.size(); ++i) {
        iii e = el[i];
        if (UF.comp == 1) break;
        if (UF.unionset(e.sc.fi, e.sc.sc)) {
            mst += e.fi;
            inMst[i] = true;
            al[e.sc.fi].push_back(ii(e.sc.sc, e.fi));
            al[e.sc.sc].push_back(ii(e.sc.fi, e.fi));
        }
    }

    for (int i = 0; i < el.size(); ++i) {
        if (inMst[i]) {diff[i] = -1; continue;}
        iii e = el[i];
        t = e.sc.sc; maxEdge = 0; dfs(e.sc.fi, -1);
        diff[i] = e.fi - maxEdge;
        assert(diff[i] >= 0);
    }

    ll d = x - mst;
    if (d < 0) printf("0\n");
    else {
        sort(diff, diff+m);
        int lo = lower_bound(diff, diff+m, d) - diff;
        int eq = (upper_bound(diff, diff+m, d) - diff) - lo;
        int up = m - lo - eq;
        lo -= (n-1);

        ll ans = (2 * (((expo(2, eq) - 1) * expo(2, up)) % MOD)) % MOD;
        if (d == 0)
            ans = (ans + (((expo(2, n-1) - 2) * expo(2, m-n+1)) % MOD)) % MOD;
        printf("%lld\n", ans);
    }
}


Measured memory_bytes: 384
package main

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

func main() {
	a := getStdin()
	if 'a' <= a[0] && a[0] <= 'z' {
		fmt.Printf("a\n")
	} else {
		fmt.Printf("A\n")
	}
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func getStdin() string {
	return readLine()
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 1812
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);
int K, n;
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> K >> n;
    vi a(n);
    for (int &x: a) cin >> x;
    int ans = K - (a[n - 1] - a[0]);
    for (int i = 1; i < n; i++) ans = max(ans,a[i] - a[i - 1]);
    cout << K - ans;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v)
    is >> x;
  return is;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int n;

int rev(int x) {
  static int dig[20];
  for (int i = 0; i < n; ++i) {
    dig[i] = x % 3;
    x /= 3;
  }
  int ret = 0;
  for (int i = 0; i < n; ++i)
    ret = ret * 3 + dig[i];
  return ret;
}

int ch[1000005][3];
bool tag[1000005];
int val[1000005], ans[1000005];

int cnt, v;

int build(int k) {
  int o = ++cnt;
  if (k == 0) {
    val[o] = rev(v++);
    return o;
  }
  ch[o][0] = build(k - 1);
  ch[o][1] = build(k - 1);
  ch[o][2] = build(k - 1);
  return o;
}

void pd(int o) {
  if (tag[o]) {
    tag[o] = false;
    swap(ch[o][1], ch[o][2]);
    for (int i = 0; i < 3; ++i) tag[ch[o][i]] ^= 1;
  }
}

void ad(int o, int k) {
  if (k == 0)
    return;
  pd(o);
  swap(ch[o][1], ch[o][2]);
  swap(ch[o][0], ch[o][1]);
  ad(ch[o][0], k - 1);
}

int dfn;
void dfs(int o, int k) {
  if (k == 0) {
    ans[val[o]] = rev(dfn++);
    return;
  }
  pd(o);
  for (int i = 0; i < 3; ++i)
    dfs(ch[o][i], k - 1);
}

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n;
  string t;
  cin >> t;
  int root = build(n);
  for (char c : t) {
    if (c == 'S')
      tag[root] ^= 1;
    else
      ad(root, n);
  }
  dfs(root, n);
  int m = pow(3, n);
  cout << vector<int>(ans, ans + m);

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 21728
def solve():
    X, Y = map(int, input().split())
    if (2 * Y - X) % 3 > 0 or (2 * X - Y) % 3 > 0: print(0)
    else:
        a = (2 * Y - X) // 3
        b = (2 * X - Y) // 3
        if a >= 0 and b >= 0:
            mod = 7 + 10 ** 9
            fact = [0] * (2 * 10 ** 6 + 1)
            revfact = [0] * (2 * 10 ** 6 + 1)
            fact[1] = 1
            for i in range(2, 2 * 10 ** 6 + 1):
                fact[i] = (i * fact[i-1]) % mod
            revfact[2 * 10 ** 6] = pow(fact[2 * 10 ** 6], mod - 2, mod)
            for i in reversed(range(2 * 10 ** 6)):
                revfact[i] = ((i + 1) * revfact[i + 1]) % mod

            print((fact[a + b] * revfact[a] * revfact[b]) % mod)
        else: print(0)

    

    return 0

if __name__ == "__main__":
    solve()

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

#define str(a) to_string(a)
#define int long long
#define pb push_back
#define mp make_pair
#define SORT(c) sort(c.begin(),c.end())
#define max_heap priority_queue<int>
#define min_heap priority_queue< int,vector<int>, greater<int> >
#define mod 1000000007
#define setbits(x) __builtin_popcount(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define start(t) int x;cin>>x;while(x--)
#define inf LLONG_MAX
#define sync ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"






int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int n; cin >> n;
	vector<int> h(n + 1);
	for (int i = 1; i <= n; i++)
		cin >> h[i];
	h[0] = 0;
	int dp[n + 1];
	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);
	cerr << dp[1] << " " << dp[2] << endl;
	for (int i = 3; i <= n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
		cerr << dp[i] << " ";
	}
	cerr << endl;
	cout << dp[n] << endl;

}











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

using namespace std;

//typedef
//------------------------------------------
template<class T> using V = vector<T>;
using VI = V<int>;
using VVI = V<VI>;
using VS = V<string>;
using LL = long long;
using ULL = unsigned long long;
using VLL = V<LL>;
using VVLL = V<VLL>;
template<class T, class U> using P = pair<T, U>;
using PII = P<int, int>;
using PLL = P<LL, LL>;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

template<class T> inline T updmax(T &a, T b){return a = max(a,b);}
template<class T> inline T updmin(T &a, T b){return a = min(a,b);}

const int MOD = 1000000007;

#define MAX 5005

LL fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void facinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

LL comb(int n, int r){
    if(n < 0 || r > n || r < 0)return 0;
    return (((fac[n]*finv[r])%MOD) * finv[n-r])%MOD;
}

LL H(int n, int r){
    return comb(n+r-1, r);
}

int main(){
    int n,k;
    scanf("%d%d", &n, &k);
    facinit();
    REP(i, k){
        printf("%lld\n", (comb(k-1, i) * H(i+2, n-k-i))%MOD);
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
int dpans(int a[],int n,int k)
{

    int dp[n]={0};
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {

        dp[i]=INT_MAX;

        for(int j=i-1;j>=1&&(i-j)<=k;j--)
            {

                dp[i]=min(dp[i],abs(a[j]-a[i])+dp[j]);

            }
  //            cout<<"adg";
    }

    return dp[n];
}
main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=1;i<=n;i++)cin>>a[i];
    cout<<dpans(a,n,k);
}


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

################ DANGER ################
test = ""
#test = \
"""
5 2
8 7 6
rsrpr
ans 27
"""

"""
7 1
100 10 1
ssssppr
ans 211
"""

"""
30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr
ans 4996
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################  
        
n, k = map(int, input2().split())
r, s, p = map(int, input2().split())
t = list(input2())

rsp = {"r", "s", "p"}

for i in range(k, n-1):
    if t[i] == t[i-k]:
        t[i] = rsp - {t[i], t[i+1]}
        
if t[n-1] == t[n-1-k]:
    t[n-1] = rsp - {t[n-1]}

ans = (t.count("r") * p +
       t.count("s") * r +
       t.count("p") * s)

print(ans)



Measured memory_bytes: 14776
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n,m,o,x;
    cin>>n>>m>>o>>x;
    int gu=n+m+o;
    int mx=max(n,max(m,o));
    gu-=mx;
    while(x--)
    {
        mx*=2;
    }
    cout<<mx+gu<<NL;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];

    for(ll i = n-2; i >= 0; i--)
    {
        if(a[i] > a[i+1]) a[i]--;
        if(a[i] > a[i+1]) ANS("No");
    }
    ANS("Yes");

}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define pll pair<long long,long long>
using namespace std;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++){
	    cin>>a[i];
    }
    int c[n]={0};
    while(m--){
	int x,y;
	cin>>x>>y;
	x--;
	y--;
	c[x]=max(c[x],a[y]);
	c[y]=max(c[y],a[x]);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(c[i]<a[i])ans++;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 5224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
string s;
ll t;
ll ret = 0;

void input() {
  IN(s);
}

void solve() {
  N = s.length();
  REP(i, N/2) {
    char c1 = s[i];
    char c2 = s[N - 1 - i];
    if (c1 != c2) {
      ret++;
    }
  }
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,k;
    cin >> n >> k;
    vi h(n);
    rep(i,n) cin >> h.at(i);
    sort(h.begin(), h.end(), greater<>());
    int64_t res = 0;
    if(k<n){
        for(int64_t i=k; i<n; i++){
            res += h.at(i);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
typedef long long ll;
 
int main(){
	
  	ll a,b,k;
  	cin>>a>>b>>k;
  	if(k<=a)
    	a-=k;
  	else{
      	b-=(k-a);
      	a=0;
    }
  	if(b<0)
      	b=0;
	cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
as = gets.split
  .each_with_object(Hash.new(0)) { |a, h| h[a.to_i] += 1 }
  .select { |_, v| v >= 2 }
  .sort.reverse

ans = 0
prev = 0

as.each do |k, v|
  s = v >= 4 ? [prev * k, k ** 2].max : prev * k

  if s > ans
    ans = s
    break
  end

  prev = k
end

puts ans


Measured memory_bytes: 15488
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <tuple>
#include <utility>
#define MAX_N 1010
#define LIMIT 1000010
#define CENTER 501
using namespace std;
const int dy[] = {0, -1, 0, 1};
const int dx[] = {1, 0, -1, 0};
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef struct res
{
	int id, num, last;
} table_t;
table_t table[MAX_N][MAX_N];
bool isPrime[LIMIT];
//int table[MAX_N][MAX_N];
//bool visit[MAX_N][MAX_N];
//P dp[MAX_N][MAX_N];
int sy, sx, n, m;
void make_prime()
{
	fill(isPrime, isPrime + LIMIT, true);
	isPrime[0] = isPrime[1] = false;
	for (int i = 2; i * i < LIMIT; i++)
	{
		if (!isPrime[i])
			continue;
		for (int j = i * 2; j < LIMIT; j += i)
			isPrime[j] = false;
	}
}
void init_table()
{
	for(int i = 0; i < MAX_N; i++)
	{
		for(int j = 0; j < MAX_N; j++)
		{
			table[i][j].id = table[i][j].last = 0;
			table[i][j].num = -1;
		}
	}
}
void make_cave()
{
	int dir = 0, ok = 1, cnt = 0, flag = 0;
	int y, x;
	y = x = MAX_N / 2;
	for (int i = 1; i <= m; i++)
	{
		if (i == n)
		{
			sy = y;
			sx = x;
		}
		table[y][x].id = i;
		//dp[y][x].second = i;
		y += dy[dir];
		x += dx[dir];
		cnt++;
		if (cnt == ok)
		{
			dir = (dir + 1) % 4;
			flag++;
			cnt = 0;
			if (flag == 2)
			{
				flag = 0;
				ok++;
			}
		}
	}
}
//残骸
/*P dfs(int y, int x)
{
	if(dp[y][x].second == -1)
		return {0, -2};
	if(dp[y][x].second > 0)
		return dp[y][x];
	P ret = max({dfs(y + 1, x - 1), dfs(y + 1, x), dfs(y + 1, x + 1)});
	if(ret.second == -2)
	{
		ret.second = dp[y][x].second;
	}
	if(isPrime[dp[y][x].second] && isPrime[ret.second])
	{
		ret.second = max(dp[y][x].second, ret.second);
		ret.first++;
	}
	visit[y][x] = true;
	dp[y][x] = ret;	
	for(int i = MAX_N / 2 - 20; i < MAX_N / 2 + 20; i++)
	{
		for(int j = MAX_N / 2 - 20; j < MAX_N / 2 + 20; j++)
		{
			if(i == y && j == x)
				printf("%5d", dp[i][j].first);
			else
				printf("%5d", dp[i][j].second);
		}
		cout << endl;
	}
	cout << endl;

	return ret;
}
*/
table_t dfs(int y, int x)
{
	table_t ret;
	int id, num, last;
	if(table[y][x].id == 0)
	{
		ret.id = ret.num = ret.last = 0;
	}
	else if(table[y][x].num >= 0)
		ret = table[y][x];
	else
	{
		num = last = 0;
		id = table[y][x].id;
		for(int i = -1; i <= 1; i++)
		{
			ret = dfs(y + 1, x + i);
			if(ret.num > num)
			{
				num = ret.num;
				last = ret.last;
			}
			else if(ret.num == num)
			{
				last = max(ret.last, last);
			}
		}
		if(isPrime[id])
		{
			if(num == 0)
				last = id;
			num++;
		}
		ret.id = id;
		ret.num = num;
		ret.last = last;
		table[y][x] = ret;
	}
	return ret;
}
int main()
{
	make_prime();
	while (cin >> m >> n, n | m)
	{
		//memset(dp, -1, sizeof(dp));
		init_table();
		//memset(visit, false, sizeof(visit));
		make_cave();
		table_t ans = dfs(sy, sx);
		/*
		for(int i = MAX_N / 2 - 20; i < MAX_N / 2 + 20; i++)
		{
			for(int j = MAX_N / 2 - 20; j < MAX_N / 2 + 20; j++)
				printf("%5d", table[i][j].last);
			cout << endl;
		}
		*/
		cout << ans.num << " " << ans.last << endl;
	}
	return 0;
}


Measured memory_bytes: 16140
//
// ~oisín~ C++ Template
//

#include                <bits/stdc++.h>
#define MX_N            5001
#define mp              make_pair
#define mod7            1000000007
#define modpi           314159
#define PI              3.141592653589793238
#define pb              push_back
#define FastIO          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define All(a)          a.begin(),a.end()
#define fi              first
#define se              second
#define ll              long long int
#define ull             unsigned long long int

int kx[8]  =            {+2, +2, -2, -2, +1, +1, -1, -1};
int ky[8]  =            {+1, -1, +1, -1, +2, -2, +2, -2};
int d9x[9] =            {+1, +1, +1, +0, +0, +0, -1, -1, -1};
int d9y[9] =            {+1, +0, -1, +1, +0, -1, +1, +0, -1};
int dx4[4] =            {+0, +0, +1, -1};
int dy4[4] =            {+1, -1, +0, +0};

ll gcd(ull a, ull b){
    return (a==0)?b:gcd(b%a,a);
}

ll lcm(ull a, ull b){
    return a*(b/gcd(a,b));
}

const long long INF = 1e18;

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n], b[n];
    for(int i=0;i<n;++i){
        cin >> a[i];
        cin >> b[i];
    }
    sort(a, a+n);
    sort(b, b+n);
    double L, H;
    ll ans;
    if(n % 2 == 0){
        L = ((double)a[n/2 - 1] + (double)a[n/2])/2;
        H = ((double)b[n/2 - 1] + (double)b[n/2])/2;
        ans = round(2.0*(H-L)+1.0);
    }else{
        L = a[n/2];
        H = b[n/2];
        ans = round(H-L+1.0);
    }
    cout << ans << endl;
}


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

using namespace std;

using ll = long long int;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(A);
    scanInt(B);
    scanInt(Q);
    scanVecLLInt(S, A);
    scanVecLLInt(T, B);
    scanVecLLInt(X, Q);
    set<ll> S_set_ascend;
    set<ll, greater<ll>> S_set_descend;
    set<ll> T_set_ascend;
    set<ll, greater<ll>> T_set_descend;
    REP(a, A){
        S_set_ascend.emplace(S[a]);
        S_set_descend.emplace(S[a]);
    }
    REP(b, B){
        T_set_ascend.emplace(T[b]);
        T_set_descend.emplace(T[b]);
    }
    REP(q, Q){
        auto& x = X[q];
        bool sr_flag = false;
        bool sl_flag = false;
        bool tr_flag = false;
        bool tl_flag = false;
        auto sr_it = S_set_ascend.lower_bound(x);
        if (sr_it != S_set_ascend.end()) sr_flag = true;
        auto sl_it = S_set_descend.lower_bound(x);
        if (sl_it != S_set_descend.end()) sl_flag = true;
        auto tr_it = T_set_ascend.lower_bound(x);
        if (tr_it != T_set_ascend.end()) tr_flag = true;
        auto tl_it = T_set_descend.lower_bound(x);
        if (tl_it != T_set_descend.end()) tl_flag = true;
        ll result = numeric_limits<ll>::max();
        if (sr_flag && tr_flag){
            result = min(result, max(abs(*sr_it - x), abs(*tr_it - x)));
        }
        if (sl_flag && tl_flag){
            result = min(result, max(abs(*sl_it - x), abs(*tl_it - x)));
        }
        if (sr_flag && tl_flag){
            const auto x1 = abs(*sr_it - x);
            const auto x2 = abs(*tl_it - x);
            result = min(result, min(x1, x2) * 2 + max(x1, x2));
        }
        if (sl_flag && tr_flag){
            const auto x1 = abs(*sl_it - x);
            const auto x2 = abs(*tr_it - x);
            result = min(result, min(x1, x2) * 2 + max(x1, x2));
        }
        cout << result << endl;
    }
}


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

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

void solve() {
	long n,x,t;
	cin >> n >> x >> t;

	cout << (n+x-1)/x * t;
	// cerr << n/x << " " << ceil(n/x);
}
int main() {
    
    ios_base::sync_with_stdio(false);cin.tie(NULL); 
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt","w",stderr);
    #endif



    solve();
    
   

     cerr<<"\ntime taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
   return 0; 
}

Measured memory_bytes: 3776
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;



int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   map<string,int> freq;

   int N;
   cin >> N;
   REP(i, N) {
      string verdict;
      cin >> verdict;
      ++freq[verdict];
   }

   for (string verdict : {"AC", "WA", "TLE", "RE"}) {
      cout << verdict << " x " << freq[verdict] << endl;
   }

   return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
 
/*  
    
*/
 
void test_case(){
    int n, k; cin >> n >> k;
    
    vector < int > l(k), r(k);
    for(int i = 0; i < k ; i++){
        cin >> l[i] >> r[i];
    }
     
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());    
    ll mod = 998244353;
    vector < ll > res(n, 0);
    res[0] = 1;
    
    vector < ll > sd(k, 0);
    for(int i = 1; i < n; i++){
        for(int j = 0; j < k; j++){
            if(  i - l[j] < 0 )
                continue;
                
            if( i - r[j] > 0){
                sd[j] += res[i-l[j]];
                sd[j] -= res[i-r[j]-1];
                
            }    
            else{
                sd[j] += res[i-l[j]];
            }
            //if( i == 1 && j == 
            
            sd[j] += mod;
            sd[j] %= mod;
            res[i] += sd[j];
            res[i] %= mod;
        }
    }
    
    cout << res[n-1] << endl;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int t; t = 1;
    //cin >> t;
    while(t--)
        test_case();
    return 0;
}

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

int main() {
    int k, t;
    cin >> k >> t;
    vector<int> a(t);
    for (int i = 0; i < t; ++i) cin >> a[i];
    int sum = accumulate(a.begin(), a.end(), 0);
    int mx = *max_element(a.begin(), a.end());
    cout << max(0, mx - 1 - (sum - mx)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vint x(n), xs(n);
    rep(i, n) cin >> x[i];
    xs = x;
    sort(all(xs));
    int m1 = xs[n/2-1], m2 = xs[n/2];
    if (m1 == m2) {
        rep(i, n) cout << m1 << endl;
        return 0;
    }
    rep(i, n) {
        if (x[i] > m1) cout << m1 << endl;
        else cout << m2 << endl;
    }
    return 0;
}

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

#[warn(dead_code)]
fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
   let s = read::<String>();
   s.split(delimiter)
      .map(|e| e.parse().ok().unwrap())
      .collect::<Vec<T>>()
}

fn calc(n:i64, k:i64) -> (i64) {
    k * (n+n-k+1) / 2 - k * (k-1) / 2 + 1
}

fn main() {
    let nk = readn::<i64>(" ");
    let n = nk[0];
    let k = nk[1];
    let m = 1000000007 as i64;
    let mut ans: i64 = 0;
    for i in k..(n+2) {
        ans += calc(n, i) % m;
        ans %= m;
    }
    println!("{}", ans);
}


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

using namespace std;

int main(){
    int N,A[100001],dp[100001];

    cin>>N;

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

    dp[1]=0;
    dp[2]=abs(A[2]-A[1]);
    for(int i=3;i<=N;i++){
        dp[i]=min( dp[i-1]+abs(A[i]-A[i-1]) , dp[i-2]+abs(A[i]-A[i-2]) );
    }

    cout<<dp[N]<<endl;

    return 0;
}

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

int main(){
	int H = 1;
	int W = 1;

	cin >> H >> W;
	while(H != 0 & W != 0){
		for(int h=0; h<H; h++){
			for(int w=0; w<W; w++){
				if (h%2==0) {
					if(w%2==0) {cout << "#";} else {cout << ".";}	
				}else{
					if(w%2==0) {cout << ".";} else {cout << "#";}	
				}
			}
			cout << "" << endl;
		}
		cout << "" << endl;
		cin >> H >> W;
	}

	return 0;
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<vector<int>> m(n+1,vector<int>(3,0));//R=0,G=1,B=2
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R')
        {
            m[i+1][0]=m[i][0] + 1;
            m[i+1][1]=m[i][1];
            m[i+1][2]=m[i][2];
        }
        else if(s[i]=='G')
        {
            m[i+1][1]=m[i][1] + 1;
            m[i+1][0]=m[i][0];
            m[i+1][2]=m[i][2];
        }
        else
        {
            m[i+1][2]=m[i][2] + 1;
            m[i+1][0]=m[i][0];
            m[i+1][1]=m[i][1];
        }
    }
    // for(int i=0;i<=n;i++)
    // {
    //     cout<<m[i][0]<<" "<<m[i][1]<<" "<<m[i][2]<<endl;
    // }
    long long ans = 0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            if(s[i]!=s[j])
            {
                if(s[i]!='R' && s[j]!='R')
                {
                    if(j+(j-i)<n && s[j+(j-i)]=='R')
                        ans--;
                    ans+=m[n][0]-m[j][0];
                }
                else if(s[i]!='G' && s[j]!='G')
                {
                    if(j+(j-i)<n && s[j+(j-i)]=='G')
                        ans--;
                    ans+=m[n][1]-m[j][1];
                }              
                else
                {
                    if(j+(j-i)<n && s[j+(j-i)]=='B')
                        ans--;
                    ans+=m[n][2]-m[j][2];
                }  
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3776