akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

// isDebug?
#ifndef ONLINE_JUDGE
#define _DEBUG
#endif

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// -* https://xn--kst.jp/blog/2019/08/29/cpp-comp/ *- Thx :)
// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    cout << __FILE__ << ": " << __LINE__ << ": " << __func__ << " -> ";   \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

// namespace / type / class / struct - alias, def:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;
const int FACN = 510000;

// Global Variables:
// ll fac[FACN], finv[FACN], inv[FACN];

// Prototype Declarations:
int gcd(int, int);
int lcm(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    int l, r, d, ans = 0;
    cin >> l >> r >> d;
    for(int i = l; i <= r; i++) {
        if(i % d == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}
// ===========================================

// Functions:
// 最大公約数 O(log(min(a, b)))
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
// 最小公倍数 O(log(min(a, b)))
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

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

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


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

int main(void){
    long long a,b,x,sum=0;
    cin>>a>>b>>x;

    if(a==0){
        sum+=b/x+1;
    }else
        sum+=b/x-(a-1)/x;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n, d, x, y, count = 0;
    scanf("%d %d", &n, &d);
    unsigned long long d_sqr = (unsigned long)d * (unsigned long)d;
    for (int i = 0; i < n; i++){
        scanf("%d %d", &x, &y);
        unsigned long long x_sqr = (unsigned long)x * (unsigned long)x;
        unsigned long long y_sqr = (unsigned long)y * (unsigned long)y;
        if (x_sqr + y_sqr <= d_sqr) {
            count++;
        }
    }
    printf("%d", count);
}

Measured memory_bytes: 1736
import scala.io.StdIn._

object Main extends App {


  val s = readLine()

  def solve() = {
    val len = s.length
    (0 until len/2).foldLeft(0) { (acc, i) =>
      if(s(i) == s(len-1-i)) acc else acc+1
    }
  }

  println(solve())

}



Measured memory_bytes: 54788
R = [0]*2019
s = input()

res = 0
for d in map(int, s):
    new = [0]*2019
    for i in range(2019):
        new[(i*10 + d)%2019] += R[i]
    new[d] += 1
    res += new[0]
    R = new
print(res)



Measured memory_bytes: 76064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	int H, W; cin >> H >> W;
	int cnt = 0;
	for (int i = 0; i < H; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < W; j++) {
			if (s[j] == '#')cnt++;
		}
	}
	if (cnt == H + W - 1)print("Possible"); else print("Impossible");



	return 0;
}

Measured memory_bytes: 764
s = str(input())
t = str(input())

slen = len(s)
tlen = len(t)

i = tlen
n = 0
a = 0
# tuu = [0] * tlen
# ans = [0] * tlen
max_count = 0
while i <= slen:
    ps = s[ n : i + tlen -1 ]
    count = 0
    for j in range(tlen):
        if ps[j] == t[j]:
            count += 1
#             tuu[j] = "True"
#             print("通った")
#     print(count)
    if max_count < count:
        max_count = count
    n += 1
    i += 1
print(tlen - max_count)

Measured memory_bytes: 9032
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
	int a[3];
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	sort(a, a + 3);
	printf("%d %d %d\n", a[0], a[1], a[2]);
	return 0;
}

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

int bubbleSort( int num[], int n ){
 bool flag = true;
 int count = 0;
 while( flag ){
  flag = false;
  for( int j=n-1; j>0; j-- ){
   if( num[j] < num[j-1] ){
    swap(num[j], num[j-1]);
    flag = true;
    count++;
   }
  }
 }

 return count;
}

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

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

 int b_count = bubbleSort( num, n );

 for( int i=0; i<n; i++ ){
  if( i!=n-1 ){
    cout << num[i] << " ";
  }else{
    cout << num[i] << endl;
  }
 }

 cout << b_count << endl;

 return 0;
}


Measured memory_bytes: 3100
import java.util.Arrays;
import java.util.Scanner;

//Sum of Prime Numbers
public class Main{

	public static void main(String[] args) {
		boolean[] p = new boolean[104730];
		int[] s = new int[10001];
		int k=0;
		s[k++]=0;
		Arrays.fill(p, true);
		for(int i=2;i<104730;i++){
			if(p[i]){
				s[k]=s[k-1]+i;
				k++;
				for(int j=i*2;j<104730;j+=i)p[j]=false;
			}
		}
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			System.out.println(s[n]);
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>

int main()
{
    int n;
    int d[50];
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&d[i]);

    int sum=0;
    for(int i=0;i<n;i++) sum+=d[i];
    int ans=0;
    for(int i=0;i<n;i++) ans+=(sum-=d[i])*d[i];
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
  	int a[n];
  	for (int i = 0; i < n; i++) cin >> a[i];
  	sort(a, a + n);
  	bool b = 1;
  	for (int i = 1; i < n; i++) if (a[i] == a[i-1]) b = 0;
  	cout << (b ? "YES" : "NO") << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

int main() {
    int lim = 1000010;
    vector<int> dp(lim, lim);
    vector<int> oddp(lim, lim);
    vector<int> lis;
    for (int i = 1; ; ++i) {
        int p = i * (i + 1) * (i + 2) / 6;
        if (p > lim) break;
        lis.push_back(p);
    }
    dp[0] = oddp[0] = 0;
    for (int i = 1; i < lim; ++i) {
        for (int j : lis) {
            if (j > i) break;
            dp[i] = min(dp[i], dp[i - j] + 1);
            if (j & 1)
                oddp[i] = min(oddp[i], oddp[i - j] + 1);
        }
    }
    while (1) {
        int n;
        cin >> n;
        if (!n) return 0;

        cout << dp[n] << " " << oddp[n] << "\n";
    }
}

Measured memory_bytes: 10464
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    string s; cin >> s;
    int idxC = INF;
    int idxF = INF;

    for(int i = 0; i < s.size(); i++) {
        if(idxC == INF && s[i] == 'C') idxC = i;
        if(s[i] == 'F') idxF = i;
    }

    if(idxF != INF && idxC < idxF) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# 解説AC
H, W = list(map(int, sys.stdin.readline().split()))
A = [list(sys.stdin.readline().rstrip()) for _ in range(H)]

R = []
B = []

for h in range(H):
    if h & 1:
        red = list('.' * (W - 1) + '#')
        blue = list('#' * (W - 1) + '.')
    else:
        red = list('.' + '#' * (W - 1))
        blue = list('#' + '.' * (W - 1))
    R.append(red)
    B.append(blue)

for h, w in itertools.product(range(H), range(W)):
    if A[h][w] == '#':
        R[h][w] = '#'
        B[h][w] = '#'

print('\n'.join(map(lambda r: ''.join(r), R)))
print()
print('\n'.join(map(lambda r: ''.join(r), B)))


Measured memory_bytes: 21448
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// M-SOL_2020_B
		Scanner sc = new Scanner(System.in);
		String Ans = "Yes";

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();

		while(B <= A) {
			B *= 2;
			K--;
		}
		while(C <= B) {
			C *= 2;
			K--;
		}

		if(K < 0) {
			Ans = "No";
		}
		System.out.println(Ans);

	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


Measured memory_bytes: 35676
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int CalcDigitSum(int n)
{
    if (n == 0) return 0;
    return n % 10 + CalcDigitSum(n / 10);
}

void _main()
{
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for (int i = 1; i <= N; ++i)
    {
        const int digitSum = CalcDigitSum(i);
        if (digitSum >= A && digitSum <= B)
        {
            ans += i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// header {{{
#define all(x) std::begin(x), std::end(x)
#define rall(x) std::rbegin(x), std::rend(x)
#define rep(i, begin, end) for (std::make_signed_t<std::remove_cv_t<decltype(end)>> i = (begin), i##_end = (end); i < i##_end; ++i)
#define repc(i, begin, last) for (std::make_signed_t<std::remove_cv_t<decltype(end)>> i = (begin), i##_last = (last); i <= i##_last; ++i)
#define repr(i, begin, last) for (std::make_signed_t<std::remove_cv_t<decltype(end)>> i = (begin), i##_last = (last); i >= i##_last; --i)
#define let const auto
using i64 = std::int64_t;
using u64 = std::uint64_t;
constexpr std::int32_t INF = 0x3f3f3f3f;
constexpr std::int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class Container, class = typename Container::value_type, std::enable_if_t<!std::is_same_v<Container, std::string>, std::nullptr_t> = nullptr>
std::istream& operator>>(std::istream& is, Container& v) {
    for (auto& e : v) is >> e;
    return is;
}

template <class Container, class = typename Container::value_type, std::enable_if_t<!std::is_same_v<Container, std::string>, std::nullptr_t> = nullptr>
std::ostream& operator<<(std::ostream& os, const Container& v) {
    for (auto it = std::begin(v); it != std::end(v); ++it) os << &" "[it == std::begin(v)] << *it;
    return os;
}

template <class T>
std::istream& operator,(std::istream& is, T& rhs) {
    return is >> rhs;
}

#define var(type, ...) \
    type __VA_ARGS__;  \
    std::cin >> __VA_ARGS__

inline void println() {
    std::cout << '\n';
}
template <class Head, class... Tail>
inline void println(Head&& head, Tail&&... tail) {
    std::cout << head << &" "[!sizeof...(tail)];
    println(std::forward<Tail>(tail)...);
}

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

template <class T, class U>
inline bool chmax(T& a, const U& b) {
    return b > a && (a = b, true);
}
// }}}

using namespace std;

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(12);

    var(i64, N);

    i64 ans = 0;
    for (i64 a = 1; a <= N; ++a) {
        ans += (N - 1) / a;
    }

    println(ans);

    return 0;
}



Measured memory_bytes: 3652
int main(f){
  float w;
  char*p[]={"light fly","fly","bantam","feather","light","light welter",
	       "welter","light middle","middle","light heavy","heavy"};
  while(scanf("%f",&w)!=-1){
    f=w>48?w>51?w>54?w>57?w>60?w>64?w>69?w>75?w>81?w>91?10:9:8:7:6:5:4:3:2:1:0;
    puts(p[f]);
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod = 1e9+7;
ll inf=1e18;

//WA

int main(void){
	ll N,K,a,ans=0;
	cin>>N>>K;
	rep(i,N)cin>>a;
	N-=K;
	ans++;
	if(N>0)ans+=ceil((double)N/(K-1));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        while (!isPrime(x)) {
            x += 1;
        }

        System.out.println(x);
    }

    private static boolean isPrime(long n) {
        if (n < 2) return false;
        if (n == 2 || n == 3) return true;
        if (n % 2 == 0 || n % 3 == 0) return false;
        long sqrtN = (long) Math.sqrt(n) + 1;
        for (long i = 6L; i <= sqrtN; i += 6) {
            if (n % (i - 1) == 0 || n % (i + 1) == 0) return false;
        }
        return true;
    }

}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {

		int n = sc.nextInt();

		int am[] = new int[112345];
		int bm[] = new int[112345];
		int tmp[] = am;
		int swp[] = bm;
		int t[];
		for (int i = 0; i < n; i++) {
			tmp[sc.nextInt()]++;

			t = tmp;
			tmp = swp;
			swp = t;
		}

		int mt1 = 0;
		int mt2 = 0;
		int mti1 = 0;
		int mti2 = 0;
		int ms1 = 0;
		int ms2 = 0;
		int msi1 = 0;
		int msi2 = 0;
		for (int i = 0; i < 112345; i++) {
			if(tmp[i] >= mt1){
				mt2 = mt1;
				mti2 = mti1;
				mt1 = tmp[i];
				mti1 = i;
			}else if(tmp[i] >= mt2){
				mt2 = tmp[i];
				mti2 = i;
			}
			if(swp[i] >= ms1){
				ms2 = ms1;
				msi2 = msi1;
				ms1 = swp[i];
				msi1 = i;
			}else if(swp[i] >= ms2){
				ms2 = swp[i];
				msi2 = i;
			}
		}

		if(mti1 != msi1){
			System.out.println(n - mt1 - ms1);
		}else{
			int max = Math.max((mt1+ms2), (mt2+ms1));
			System.out.println(n-max);
		}

	}
}


Measured memory_bytes: 57900
#include<stdio.h>
#include<algorithm>
using namespace std;
int fa[131072],rnk[131072],fw[131072];
int findroot(int x)
{
	if(fa[x]==x)
	{
		return x;
	}
	return findroot(fa[x]);
}
int chk(int u,int v)
{
	int ans=0;
	while(u!=v)
	{
		if(fw[u]<fw[v])
		{
			if(fw[u]>ans)
			{
				ans=fw[u];
			}
			u=fa[u];
		}
		else
		{
			if(fw[v]>ans)
			{
				ans=fw[v];
			}
			v=fa[v];
		}
	}
	return ans;
}
struct node{
	int u;
	int v;
	int w;
	bool operator<(node b) const
	{
		return w<b.w;
	}
};
node nn[262144];
int main()
{
	int n,m;
	long long x;
	scanf("%d%d%lld",&n,&m,&x);
	for(int i=1;i<=n;i++)
	{
		fa[i]=i;
		rnk[i]=1;
		fw[i]=1000000007;
	}
	for(int i=0;i<m;i++)
	{
		scanf("%d%d%d",&nn[i].u,&nn[i].v,&nn[i].w);
	}
	if(n<=2)
	{
		printf("0\n");
		return 0;
	}
	sort(nn,nn+m);
	long long s=0;
	int num=0;
	for(int i=0;i<m;i++)
	{
		int u=findroot(nn[i].u);
		int v=findroot(nn[i].v);
		if(u==v)
		{
			continue;
		}
		s+=nn[i].w;
		num++;
		if(rnk[u]>rnk[v])
		{
			fa[v]=u;
			fw[v]=nn[i].w;
		}
		else
		{
			if(rnk[u]==rnk[v])
			{
				rnk[v]++;
			}
			fa[u]=v;
			fw[u]=nn[i].w;
		}
	}
	if(num<n-1)
	{
		printf("0\n");
		return 0;
	}
	if(s>x)
	{
		printf("0\n");
		return 0;
	}
	int ss=2,ss2=2;
	if(s==x)
	{
		ss=1;
	}
	for(int i=0;i<m;i++)
	{
		int d=nn[i].w-chk(nn[i].u,nn[i].v);
		if(s+d>=x)
		{
			ss<<=1;
			if(ss>=1000000007)
			{
				ss-=1000000007;
			}
		}
		if(s+d>x)
		{
			ss2<<=1;
			if(ss2>=1000000007)
			{
				ss2-=1000000007;
			}
		}
	}
	ss-=ss2;
	if(ss<0)
	{
		ss+=1000000007;
	}
	printf("%d\n",ss);
	return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a * b % 2 != 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}
	
}


Measured memory_bytes: 22612
#include <iostream> 
#include <algorithm>
#include <functional>
#include <vector>
#include <bitset>
/*#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <string>
#include <cstring>
#include <fstream>*/

#define Rep(i,n) for(int i=0;i<n;i++)
#define pb(arr,el) arr.push_back(el)
#define ci(n) cin>>n
#define co(n) cout<<n<<endl

using namespace std;
const int INF=1e9+5;

int main(){
	int n,ans=1;
   ci(n);
   vector<int> arr(n);
   Rep(i,n){
     int x;
     ci(x);
	  arr[x-1]=i;
   }
   int tem=1;
   Rep(i,n-1){
   	  if(arr[i]<arr[i+1]) tem++;
	  else{ 
	  ans=max(ans,tem);
	  tem=1;
	  }
   }
   co(n-max(ans,tem));
   return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int S, W;
    cin >> S >> W;

    if(W >= S) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }

    return 0;
}

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

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    vector<int> B(N);
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for (int i = 0; i < N-1; i++){
        B.at(i)=A.at(i+1)-A.at(i);
    }
    
    B.at(N-1)=K-A.at(N-1)+A.at(0);

    
    int ans = -1;
    int M;
    
    for (int i = 0; i < N; i++){
        if (B.at(i)>ans){
            ans = B.at(i);
            M = i;
        }
    }
    
    int ans_f = K - B.at(M);
    
    cout << ans_f << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<stdio.h> //per fare input output con scanf and printf
#include<stdlib.h> //per fare qsort e bsearch
#include<string.h> // per fare strcpy(sarrivo, spartenza) strcat(str, aggiungo) strcmp(a,b) che da 0 se sono uguali
#include<math.h>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
 
using namespace std;
 
#define ld long double
#define ll long long int
#define vi vector <ll> 
#define pi pair <int, int>
#define binary(v, el) binary_search((v).begin(), (v).end(), (el))
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(n, t) get<(n)>((t)) // get element of a tuple
#define F first
#define S second
#define input(type, n) type n; cin >> n
#define FORN(n) for (ll i=0;i<(n); i++)
#define print(x) cout << x << endl
#include <iomanip>      // std::setprecision
#define M 1000*1000*1000+7
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll powermodp(ll x, ll y, ll p){
   // x^y mod p
   if (y==0) return 1;
   ll a = powermodp(x, y/2, p) % p;
   a = (a*a) % p;
   if (y%2) return (a*x)%p;
   return a;
}

ll inverse(ll a, ll p){
   if (a%p == 0) return 0;
   else return powermodp(a, p-2, p);
}

ll fatt (ll n, ll p) {
   ll res = 1;
   for (ll i = 1; i < n+1; ++i) {
      res *= i;
      res %= p;
   }
   return res;
}

ll bin (ll n, ll k, ll p) {
   return (fatt(n,p) * ((inverse(fatt(k,p), p))%p * (inverse(fatt(n-k,p), p))%p)%p)%p;
}

int main () {
   ll N,K; cin>>N>>K;
   ll p = 1000000007;
   for (ll i = 1; i <= K; ++i) {
      if (i-1>N-K) cout << 0 << endl;
      else {ll res = (bin(K-1,i-1, p) * bin(N-K+1, i, p)) % p;
      cout << res << endl;}
   }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define mp make_pair
#define P pair<ll,ll>
#define F first
#define S second
#define vll vector<ll>
#define pb push_back
#define M 1000000007
#define for1(i,n) for(ll i=1;i<=n;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define forab(i,a,b,c) for(ll i=a;i<=b;i+=c)
using namespace std;
int main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin >> n;
	ll ans = 0;
	if (n <= 1000)
	{
		ans = 1000 - n;
	}
	else
	{
		ll fac = n / 1000;
		if (n % 1000 == 0)
		{
			ans = 0;
		}
		else
		{
			fac++;
			ans = fac * 1000 - n;
		}
	}
	cout << ans << "\n";
	return 0;
}

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

int N, K;
ll a[20];

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> a[i];

    ll ans = 1.0e17;
    for (int i = 0; i < (1 << N); i++) {
        bitset<20> bt(i);
        if (bt.count() != K) continue;

        ll mx = 0;
        ll tmp = 0;
        for (int j = 0; j < N; j++) {
            if (bt[j] == 1) {
                if (mx < a[j]) {
                    mx = a[j];
                }
                else {
                    tmp += (mx + 1 - a[j]);
                    mx = mx + 1;
                }
            }
            else {
                mx = max(mx, a[j]);
            }
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
    

    return 0;
}

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

using namespace std;

ll n, k;
vector<ll> v;

ll util(ll len, ll limit){
    if(len<=limit)
        return 0;
    ll q=len/limit;
    return q;
}

bool works(ll len){
    ll cnt=0;
    for(ll i=0; i<n; i++){
        ll tmp=util(v[i], len);
        cnt+=tmp;
        if(cnt>k)
            return false;
    }
    return true;
}

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

	cin >> n >> k;
	v=vector<ll>(n);
	for(ll i=0; i<n; i++)
        cin >> v[i];
    ll i=1, j=*max_element(v.begin(), v.end()), ans=2e9;
    while(i<=j){
        ll mid=i+((j-i)/2);
        if(works(mid)){
            ans=min(ans, mid);
            j=mid-1;
        }
        else
            i=mid+1;
    }
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef pair <int,int> pii;
int N, T;
pii dish[3005];
int dp[6005];
int main() {
    cin >> N >> T;
    for (int i=1; i<=N; i++){
        scanf("%d %d", &dish[i].first, &dish[i].second);
    }
    sort(dish+1, dish+N+1);
    int ans = 0;
    for (int i=1; i<=N; i++){
        for (int j=0; j<=T-1; j++){
            ans = max(ans, dp[j]+dish[i].second);
        }
        for (int j=T-1; j>=dish[i].first; j--){
            dp[j] = max(dp[j], dp[j-dish[i].first]+dish[i].second);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	char s[3];
	char t[3];
	int count = 0;
	scanf("%s %s", s, t);
	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i]) {
			count++;
		}
	}
	printf("%d", count);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 4223352036854775007
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=400005;
const int NN=20005;
const ll md=998244353;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll n,x,m;
    cin >> n >> x >> m;
    ll a[N]={0};
    a[1]=x;
    map<ll,int> pos;
    pos[x]=1;
    int l=-1,r=-1;
    for (int i=2;i<=n;i++){
        x*=x;
        x%=m;
        if (pos[x]!=0){
            r=i-1;
            l=pos[x];
            break;
        }else {
            a[i]=x;
            pos[x]=i;
        }
    }
    if (l==-1){
        ll ans=0;
        for (int i=1;i<=n;i++){
            ans+=a[i];
        }
        cout << ans << E;
        r0;
    }
    ll sum=0;
    for (int i=l;i<=r;i++){
        sum+=a[i];
    }
    int len=r-l+1;
    ll ans=0;
    for (int i=1;i<=r;i++){
        ans+=a[i];
    }
    ans+=((n-r)/len)*sum;
    for (int i=l;i<=((n-r)%len)+l-1;i++){
        ans+=a[i];
    }
    cout << ans << E;
    r0;
}
/*








*/


Measured memory_bytes: 9852
import Data.Array
import Data.Bits
import Data.Bool
import qualified Data.ByteString.Char8 as C
import Data.List

main = C.interact $ put . sol . get

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines

put = C.pack . show

sol ([n,_]:es)= bitDP 1 (2^n-1)
  where
  e = accumArray (||) False ((1,1),(n,n)) $
    (\[a,b] -> ((a,b),True)) <$> es
  outvs vs v = [u | u <- [1..n], testBit vs (u-1), e!(min u v, max u v)]
  bitDP :: Int -> Int -> Int 
  bitDP p vs
    | popCount vs==1  = bool 0 1 $ 2^(p-1)==vs
    | otherwise       = sum [bitDP c vs' | c <- outvs vs' p]
    where
    vs' = clearBit vs (p-1)

Measured memory_bytes: 508
#include <stdio.h>
int main(void)
{
	int n, m;
	scanf("%d %d", &n, &m);
	if (n >= m)
	{
		if (n % m) printf("%d", n / m + 1);
		else printf("%d", n / m);
	}
	else
	{
		printf("1");
	}
}

Measured memory_bytes: 128
import std.stdio;
import std.string;
import std.conv;

void main() {
    int c = 0;
    int[] numstack;
    string[] opstack;
    int calc() {
        ulong i = 0;
        int x = numstack[i++];
        foreach (op; opstack) {
            switch (op) {
                case "+":
                    x += numstack[i++];
                    break;
                case "-":
                    x -= numstack[i++];
                    break;
                case "*":
                    x *= numstack[i++];
                    break;
                case "/":
                    x /= numstack[i++];
                default: break;
            }
        }
        return x;
    }
    for (int i = 0; ; i++) {
        if (i % 2 == 0) {
            int n = stdin.readln.chomp.to!int;
            numstack ~= n;
        } else {
            string op = stdin.readln.chomp;
            if (op == "=") {
                calc.writeln;
                break;
            }
            else opstack ~= op;
        }
    }
}

Measured memory_bytes: 1052
// INCLUDES
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define what_is(x) cerr << #x << 'is' << x << endl;
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
//HELPERS
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << '=' << a << endl;
err(++it, args...);
}
vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int h,n;
cin>>h>>n;
vector<int> v(n);
int sum = 0;
FOR(i,0,n)
cin>>v[i],sum+=v[i];
if(h>sum)
cout<<"No";
else
cout<<"Yes";
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
using namespace std;

int n;
vector<int> T;
vector<int> X;
vector<int> Y;

int main() {
  cin >> n;
  T.resize(n);
  X.resize(n);
  Y.resize(n);
  rep(i, n) cin >> T[i] >> X[i] >> Y[i];
  bool flag = true;
  rep(i, n) {
    if (X[i] + Y[i] > T[i]) {
      flag = false;
      break;
    }
    if ((T[i] - X[i] + Y[i]) % 2 != 0) {
      flag = false;
      break;
    }
  }
  if (flag) cout << "Yes";
  else cout << "No";
  return 0;
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;

    int h[n];
    rep(0, n) cin >> h[i];

    int a, b, max_h[n];
    bzero(max_h, sizeof(max_h));
    rep(0, m) {
        cin >> a >> b;
        max_h[a-1] = max(max_h[a-1], h[b-1]);
        max_h[b-1] = max(max_h[b-1], h[a-1]);
    }

    int cnt = 0;
    rep(0, n) {
        if (max_h[i] < h[i]) cnt++;
    }

    cout << cnt << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 4380
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
long long int lis[350000]={0};
int main(){
    while(1){
        long long int L,N,M;
        cin>>L;
        if(L==0)break;
        cin>>N>>M;
        for(int i=0;i<350000;i++)lis[i]=0;
        for(int i=1;i<N;i++)cin>>lis[i];
        sort(lis,lis+N);
        for(int i=0;i<N;i++)lis[i+N]=lis[i]+L,lis[i+2*N]=lis[i]+2*L;
        long long int ans=0;
        for(int i=0;i<M;i++){
            int a;cin>>a;
            a+=L;
            long long int l=0,r=3*N-1,mid;
            for(int j=0;j<20;j++){
                mid=(l+r)/2;
                if(a<=lis[mid])r=mid;
                else l=mid;
            }
            ans+=min(fabs(lis[r]-a),fabs(lis[r-1]-a));
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

using namespace std;

#define int long long
#define MOD 1000000007

#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 elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int n;

const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
vector<int> to[MAXV];

int id[MAXN][MAXN];
int toId(int i,int j){
    if(i>j){
        swap(i,j);
    }
    return id[i][j];
}

bool visited[MAXV];
bool caluculated[MAXV];
int dp[MAXV];//max length og path from v

int dfs(int v){

    if(visited[v]){
        if(!caluculated[v])return -1;
        return dp[v];
    }
    visited[v]=true;
    dp[v] = 0;
    for(int u:to[v]){
        int res = dfs(u);
        if(res ==-1) return -1;

        dp[v] = max(dp[v],res+1);
    }

    caluculated[v] = true;
    return dp[v];

}

signed main()
{

    cin >> n;
    vector<vector<int>> a(n, vector<int>(n - 1));
    rep(i, n)
    {
        rep(j, n - 1)
        {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    int V=0;
    rep(i,n)rep(j,n){
        if(i<j){
            id[i][j] = V++;
        }
    }

    rep(i,n){
        rep(j,n-1){
            a[i][j] = toId(i,a[i][j]);
        }
        rep(j,n-2){
            to[a[i][j+1]].pb(a[i][j]);
        }
    }

    int ans = 0;



    rep(i,V){
        int res = dfs(i);
        if(res==-1){
            cout <<-1<<endl;
            return 0;
        }
        ans = max(ans,res);
    }


    cout<<ans+1<<endl;

    return 0;
}


Measured memory_bytes: 48384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    if (a > m) continue;
    jobs[m-a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for (int i = m-1; i >= 0; --i) {
    for (int b : jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    vector<bool> A(1145140);
    int s;
    cin >> s;
    A[s] = 1;
    int ans = 0;
    for(int i = 2;;i++){
        if(s%2 == 0){
            s = s/2;
            if(A[s] == 1){
                ans = i;
                break;
            }
            A[s] = 1;
        }else{
            s = 3*s+1;
            if(A[s] == 1){
                ans = i;
                break;
            }
            A[s] = 1;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

struct shop{
    int value;
    int num;
};

bool asc(const shop l,const shop r){
    return l.value == r.value ? l.num < r.num : l.value < r.value;
}

int main(void){
    int n,m,i,j,c=0;
    long res=0;
    scanf("%d %d",&n,&m);
    vector<shop> l(n);
    for(i=0;i<n;i++){
        scanf("%d %d",&l[i].value,&l[i].num);
    }
    sort(l.begin(),l.end(),asc);
    i=0;
    while(c < m){
        res += l[i].value;
        l[i].num--;
        c++;
        if(l[i].num == 0)i++;
    }
    printf("%ld\n",res);
    return 0;
}

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

// #define ONLINE_JUDGE

#define V vector
#define P pair

using LL = long long;
#define FOR(i, x, y) \
    for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) \
    for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
    do {                                      \
        cerr << "\033[32;1m" << #x << " -> "; \
        err(x);                               \
    } while (0)
void err() { cerr << "\033[39;0m" << endl; }
template <template <typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
    for (auto v : a) cerr << v << ' ';
    err(x...);
}
template <typename T, typename... A>
void err(T a, A... x) {
    cerr << a << ' ';
    err(x...);
}
#else
#define dbg(...)
#endif
#define sz(x) (int)x.size()

LL bin(LL a, LL b, LL p) {
    LL res = 1;
    a = (a % p + p) % p;
    for (; b; b >>= 1, a = a * a % p)
        if (b & 1) res = res * a % p;

    return res;
}

const int N = 2e5+50;


int n, d;

P<int, int> p[N];
void solve() {
    scanf("%d%d", &n, &d);
    int ans = 0;
    for (int i=0; i<n; ++i) {
        scanf("%d%d", &p[i].first, &p[i].second);

        LL d1 = 1LL * p[i].first * p[i].first + 1LL * p[i].second * p[i].second;
        if (d1 <= 1LL * d * d) {
            ++ans;
        }
    }
    printf("%d\n", ans);
}

int main() {

    // int t;
    // cin >> t;
    // while (t--) solve();

    solve();

    return 0;
}

Measured memory_bytes: 5368
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  C = input()[:-1]

  nr = 0
  for c in C:
    if c == 'R':
      nr += 1

  ans = 0
  for i in range(nr):
    if C[i] == 'W':
      ans += 1

  print(ans)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 67644
#include<bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pq priority_queue
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define elif else if

using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pll=pair<ll,ll>;
using pss=pair<string,string>;
using pdd=pair<ld,ld>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};
const ld E=1e-9;

template<class T> void chmin(T &a, T b){a=min(a, b);}
template<class T> void chmax(T &a, T b){a=max(a, b);}

ll abs1(ll a){if(a>=0)return a;else return -a;}
ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1)ret*=a;a*=a;
    if(a>=p)a%=p;if(ret>=p)ret%=p;
    b=b>>1;
  }
  return ret;
}
int digit(ll a,ll b=10){int i=0;while(a!=0){a/=b;i++;}return i;}
ll gcd1(ll a,ll b){
  if(a==0 || b==0)return 0;
  ll n;while(a%b!=0){n=a%b;a=b;b=n;}return b;
}
ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];a[0]=n;b[0]=m;int i=1;
  while(b[i-1]!=0){a[i]=b[i-1];b[i]=a[i-1]%b[i-1];i++;}
  n=i;if(c%a[n-1]!=0)return 0;
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){ll cnt=x;x=y;y=cnt-(a[n-i-1]/b[n-i-1])*y;}
  return x;
}
ll modRev(ll a,ll p=MOD){
  a%=p;ll n=solveLinear(a,p,1);
  n%=p;if(n<0)return n+p;
  return n;
}
ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  ll ret=1;for(int i=1;i<=n;i++){ret=ret*i;if(ret>=p)ret%=p;}
  return ret;
}
ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  ll ret=1;rep(i,k){ret=ret*(n-i);if(ret>=p)ret%=p;}
  return ret;
}
ll binom(ll n,ll k,ll p=MOD){
  return (perm(n,k,p)*modRev(fact(k)))%p;
}
int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int n;
ll a[500];
ll val(ll x){
  int i;
  int b[n];
  rep(i,n)b[i]=a[i]%x;
  ll sum=0;
  rep(i,n){
    sum+=b[i];
  }
  ll p=sum/x;
  sort(b,b+n);
  sum=0;
  rep(i,n-p){
    sum+=b[i];
  }
  return sum;
}

int main(){
  int i,j,cnt=0;
  ll k;
  cin>>n>>k;
  ll sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  set<ll> s;
  ll p=(ll)ceil(sqrt(sum));
  for(i=1;i<=p;i++){
    if(sum%i==0){
      s.insert(i);
      s.insert(sum/i);
    }
  }
  vector<ll> v;
  for(auto i:s){
    v.pb(i);
  }
  sort(all(v),greater<ll>());
  for(i=0;i<v.size();i++){
    if(val(v[i])<=k){
      cout<<v[i]<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

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

using namespace std;
using namespace __gnu_pbds;

#define ll int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 105;
const int MAXK = 100005;

ll n, k, a[MAXN], dp[MAXK];      // Grundy number of val

ll rec(ll val)
{
	if(val < a[0]) return 0;
	if(dp[val] != -1) return dp[val];
	for(int i=0;i<n;i++)
		if(val >= a[i] && rec(val - a[i]) == 0) return dp[val] = 1;
	return dp[val] = 0;
}	

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

	cin >> n >> k;
	for(int i=0;i<n;i++) cin >> a[i];
	memset(dp, -1, sizeof(dp));
	if(rec(k)) cout << "First" << endl; 	   
    else cout << "Second" << endl;
    return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>
#include <stdlib.h>

double area(double a,double b,double c,double d, double e,double f);

int main()
{
    double x1,y1,x2,y2,xp,yp,x3,y3,a1,a2,a3;
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)==8)
    {
    a1=area(x1,y1,x2,y2,xp,yp);
    a2=area(x2,y2,x3,y3,xp,yp);
    a3=area(x3,y3,x1,y1,xp,yp);
    if((a1>=0 && a2>=0 &&a3>=0)||(a1<0 && a2<0 && a3<0))printf("YES\n");
    else printf("NO\n");
    }
    return 0;

}
 double area(double a,double b,double c,double d, double e,double f)
 {
     double total_area;
     total_area=(a*(d-f)-b*(c-e)+(c*f-d*e));
     return total_area;
 }

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll q, h, s, d;
    cin >> q >> h >> s >> d;
    ll n;
    cin >> n;
    ll ans1 = min({4*q, 2*h, s});
    ll ans2 = min({8*q, 4*h, 2*s, d});
    cout << (n%2) * ans1 + (n/2) * ans2 << endl;
    return 0;
}

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

int main (){
	int n, a[1010], max, min, i;
	
	cin >> n;
	
	for (i=0; i<n; i++){
		cin >> a[i];	
	}
	
	max = a[0];
	for (i=0; i<n; i++) {
		if (max < a[i]) max = a[i];
	}
	
	min = a[0];
	for (i=0; i<n; i++) {
		if (min > a[i]) min = a[i];
	}
	
	cout << max-min << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

input=sys.stdin.readline

N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)

c=input()[:N]

deg=[len(edge[i]) for i in range(N)]
leaf=set([])
for i in range(N):
    if deg[i]==1 and c[i]=="B":
        leaf.add(i)

ban=set([])
while leaf:
    v=leaf.pop()
    ban.add(v)
    deg[v]=0
    for nv in edge[v]:
        deg[nv]-=1
        if deg[nv]==1 and c[nv]=="B":
            leaf.add(nv)

for i in range(N):
    edge[i]=[nv for nv in edge[i] if nv not in ban]

root=-1
for i in range(N):
    if i not in ban:
        root=i

parent=[-2]*N
deq=deque([(root,-1)])
node=[]
while deq:
    v,pv=deq.popleft()
    parent[v]=pv
    node.append(v)
    for nv in edge[v]:
        if nv!=pv:
            deq.append((nv,v))

node=node[::-1]

for i in range(N):
    edge[i]=[nv for nv in edge[i] if nv!=parent[i]]

check=True
for i in range(N):
    check&=(deg[i]<=0)
if check:
    print(int(c[root]=="W"))
    exit()

cond=[0]*N
for v in range(N):
    if (deg[v]%2==1 and c[v]=="B") or (deg[v]%2==0 and c[v]=="W"):
        cond[v]+=1
    else:
        cond[v]-=1

lower=[0]*N
for v in node:
    res=0
    for nv in edge[v]:
        res=max(res,lower[nv])
    res+=1+cond[v]
    lower[v]=res

upper=[0]*N
node=node[::-1]
for v in node:
    n=len(edge[v])
    if n>1:
        left=[0]*n
        right=[0]*n
        for i in range(n-1):
            nv=edge[v][i]
            left[i]=max(left[i-1],lower[nv]+2+cond[v])
        nv=edge[v][-1]
        upper[nv]=left[n-2]+cond[nv]
        right[n-1]=lower[nv]+2+cond[v]
        for i in range(n-2,0,-1):
            nv=edge[v][i]
            upper[nv]=max(left[i-1],right[i+1])+cond[nv]
            right[i]=max(right[i+1],lower[nv]+2+cond[v])
        if edge[v][0]!=pv:
            nv=edge[v][0]
            upper[nv]=right[1]+cond[nv]
    if v!=root:
        for nv in edge[v]:
            upper[nv]=max(upper[nv],upper[v]+1+cond[nv])

base=sum(deg[i] for i in range(N))+sum(cond[i]==1 for i in range(N))
#print(deg)
#print(base)
#print(lower)
#print(upper)
#print(base)
print(base-max(max(upper),max(lower)))


Measured memory_bytes: 124276
n,m=map(int,input().split())
graph=[[] for i in range(n+1) ]
dist=[None for i in range(n+1)]
dist[0]=0
result=[True]

for i in range(m):
    l,r,d=(int(i) for i in input().split())
    graph[l].append((r,-d))
    graph[r].append((l,d))
def haba(i):
    if dist[i]== None:
        stack=[]
        dist[i]=0
        stack.append(i)
        while len(stack)!=0 :
            l=stack.pop()
            for r,d in graph[l]:
                b=dist[l]+d
                if dist[r]==None :
                    dist[r]=b
                    stack.append(r)
                elif dist[r]!=b:
                     result[0]=False
                     return
        return 
    else:
        return 

for i in range(n+1):
    haba(i)
if result[0]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 65892
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
	int q;
	while(cin >> q,q!=-1){
		double ans = q/2;
		while(1){
			if(fabs(ans*ans*ans -q) < 0.00001*q)break;
			ans = ans-((ans*ans*ans-q)/(ans*ans*3));
		}
		printf("%.6lf\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1192