akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdlib.h>
#include<algorithm>

using namespace std;

int main(){
    int N;
    long K;
    cin >> N >> K;

    long A[N];
    long F[N];

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

    for(int i=0; i<N; i++){
        int f;
        cin >> f;
        F[i] = f;
    }

    sort(A, A + N);
    sort(F, F + N, greater<long>() );

    long lower = -1;
    long upper = 1e12 + 1;

    while(upper - lower > 1){
        long middle = (upper + lower) / 2;
        long trn = 0;
        for(int i=0; i<N; i++){
            trn += max((A[i] - middle / F[i]), (long)0);
        }

        if(trn <= K){
            upper = middle;
        }
        else{
            lower = middle;
        }
    }
    
    cout << upper << endl;
    
    return 0;
}

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

int main(){
	int a[4],t;
	
	while(cin >> a[0] && a[0] != -1){
		int blow=0,hit=0;
		for(int i=1;i<4;i++)
			cin >> a[i];
		for(int i=0;i<4;i++){
			cin >> t;
			if(a[i] == t)hit++;
			else for(int i=0;i<4;i++)if(a[i]==t)blow++;
		}
		cout << hit << " " << blow << endl;
	}
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;
typedef pair< int, P > PP;

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

int n;
ll a[100000], b[100000];
vector<P> v;
int used[100000];
ll suma, sumb, ans;

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

	cin >> n;
	REP(i, n) {
		cin >> a[i] >> b[i];
		v.pb(P(a[i], i)), v.pb(P(b[i], i));
		suma += a[i], sumb += b[i];
	}
	ans = min(suma, sumb);
	sort(ALL(v));
	REP(i, n) used[v[i].se]++;
	ll sum = 0;
	bool flg = false;
	REP(i, n) {
		if (used[i] == 2) flg = true;
		sum += v[i].fi;
	}      
    if (!flg) {
		REP(i, n) {
			ans = min(ans, sum - min(a[i], b[i]) + v[n + (int)(v[n].se == i)].fi);
		}
	}
	else ans = min(ans, sum);
	cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3952
#include<iostream>
#include<string>
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    bool ok(true);
    if(s.size()+1 != t.size())ok = false;
    for(int i(0);i<s.size();i++){
        if(s[i] != t[i])ok = false;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3128
n, k = map(int, input().split())
a = list(map(int, input().split()))
t, s = 0, 0

for i in range(n-1):
  for j in range(i+1, n):
    if a[i] > a[j]:
      t += 1
      
a.sort()
l = [ i for i in range(n) ]
for i in range(1, n):
  if a[i] == a[i-1]:
    l[i] = l[i-1]
s = sum(l)
    
print((k*t%1000000007 + s*k*(k-1)//2%1000000007)%1000000007)

Measured memory_bytes: 41308
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //String word = sc.next();
        String array = "";
        String array_cp = "";
        array = sc.nextLine();
        for(int i=0;i<array.length();i++){
            if(Character.isUpperCase(array.charAt(i))){
                array_cp +=  array.substring(i,i+1).toLowerCase();
            }else if(Character.isLowerCase(array.charAt(i))){
                array_cp +=  array.substring(i,i+1).toUpperCase();
            }else{
                array_cp +=  array.substring(i,i+1);
            }
        }
        System.out.println(array_cp);
        sc.close();
    }
}


Measured memory_bytes: 31852
#include <stdio.h>

int gcd(int x, int y){
    if (y == 0) return x;
    else return gcd(y, x % y);
}

int main(){
    int x, y, z;
    while (scanf("%d %d", &x, &y) != -1)
        z = gcd(x, y), printf("%d %d\n", z, y / z * x);
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 

using namespace std;

int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());

    string t;
    cin >> t;
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import math

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

flag=True
cout=-1;

while flag:
    cout+=1
    for i in range(n):
        if a[i]%2 is int(0):
            a[i]=int(a[i]/2)
        else:
            flag=False


print(cout)

Measured memory_bytes: 3060
n = int(input())
S = [int(x) for x in input().split()]
q = int(input())
T = [int(x) for x in input().split()]

def BinarySearch(S,T):
    count = 0
    for i in range(q):
        left = 0
        right = n
        #right = n-1だとヒットするのがS[n-1]のみのときに見つからない
        #left < rightとmidは切り捨てより常にmid < right
        while left < right:
            mid = int((left + right) / 2)
            if T[i] == S[mid]:
                count += 1
                break
            elif T[i] < S[mid]:
                right = mid
            else:
                left = mid + 1
    return count

print(BinarySearch(S,T))



Measured memory_bytes: 16896
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int n = nextInt();
		int k = nextInt();
		
		int[] a = new int[n];
		
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		
		long[] prefPos = new long[n + 1];
		long[] suffPos = new long[n + 1];
		
		long[] pref = new long[n + 1];
		
		for (int i = 0; i < n; i++) {
			prefPos[i + 1] = prefPos[i] + Math.max(a[i], 0);
			pref[i + 1] = pref[i] + a[i];
		}
		
		for (int i = n - 1; i >= 0; i--) {
			suffPos[i] = suffPos[i + 1] + Math.max(a[i], 0); 
		}
		
		long ans = 0;
		
		for (int pos = 0; pos + k <= n; pos++) {
			
			long here = Math.max(pref[pos + k] - pref[pos], 0);
			
			here += prefPos[pos];
			here += suffPos[pos + k];
			
			ans = Math.max(ans, here);
		}
		
		out.println(ans);
		
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 30472
(defun input (n)
  (let ((a (make-array n)))
    (loop for i below n do (setf (aref a i) (read)))
    a))

(defun solve (n x m)
  (setq x (- x (reduce #'+ m)))
  (+ n (floor (/ x (reduce #'min m)))))

(let* ((n (read))
       (x (read))
       (m (input n)))
  (princ (solve n x m)))

Measured memory_bytes: 16864
#include<stdio.h>
#include<string.h>
int main()
{
	char s[11],t[11];
	int a,b,c,i;
	scanf("%s %s",s,t);
	a=strlen(s);
	b=0;
	c=0;
	for(i=0;i<a;i++){
		b++;
		if(s[i]==t[i])
			c++;
	}
	if(b==c) printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

int main(){
    ll a,b;
    cin >> a >> b;
    if(a==b) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    int x=in.nextInt();
    int y=in.nextInt();
    int s=0;
    s= x==1 ? s+300000: x==2 ? s+200000: x==3 ? s+100000:s+0;
    s= y==1 ? s+300000: y==2 ? s+200000: y==3 ? s+100000:s+0;
    if(s==300000+300000)
    {
      System.out.println(s+400000);
    }
    else
    {
      System.out.println(s);
    }
  }
}
 

Measured memory_bytes: 35896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    ll N, M;
    cin >> N >> M;
    vector<int> S(M), C(M);
    rep(i, M){ 
        cin >> S[i] >> C[i];
    }
    int A[3];
    reps(x, 0, 1000){
        
        if (N == 1 && x >= 10)continue;
        if (N == 2 && (x >= 100 || x <= 9))continue;
        if (N == 3 && (x >= 1000 || x <= 99))continue;
        A[0] = x%10;
        A[1] = x%100/10;
        A[2] = x/100;
        int fail = 0;
        rep(i, M){
            if (A[N - S[i]] != C[i]){
                fail = 1;
                break;
                
            }
        }
        if (fail){
            continue;
        }
        cout << x;
        return 0;
    }    
    cout << -1;
    return 0;
}


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

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define INF INT_MAX
#define NINF INT_MIN
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "\n";
    err(++it, args...);
}

int main() {

	int n;
	cin >> n;
	int a[n], b[n], c[n];

	tik(i,0,n) {
		cin >> a[i] >> b[i] >> c[i];
	}

	//dp[i][k] = Maximum happiness we can obtain in the first i days given that on the ith day, activity k is performed
	int dp[n][3];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	tik(i,1,n) {
		dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i]; 
	}

	cout << max(dp[n-1][0], max(dp[n-1][1],dp[n-1][2]));
	
}



Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int a[200001],b[200001],n;
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
b[i]=a[i];}
sort(a,a+n);
int x=a[n-n/2];
int y=a[n-n/2-1];
for(int i=0;i<n;i++)
{
if(b[i]>=x)
cout<<y<<endl;
else
cout<<x<<endl;}
system("pause");
return 0;
}

Measured memory_bytes: 3960
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int comb(int a){
    if(a < 1) return 0;
    
    return a * (a-1)/2;
}

int main(){
    int n,m;
    cin >> n >> m;
    int ans = comb(n) + comb(m);
    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 384
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
MOD = 1000000007
fact = [1]
for i in range(1, n + 1):
    fact.append(fact[-1] * i % MOD)
def inv(i):
    return pow(fact[i], MOD - 2, MOD)
def max_min_a():
    a_sum = 0
    for i in range(k - 1, n):
        a_sum += a[i] * fact[i] * inv(i - k + 1) * inv(k - 1) % MOD
    return a_sum
max_a = max_min_a()
a = a[::-1]
min_a = max_min_a()
print(int((max_a - min_a) % MOD))

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12
#define MAX_N 100

int main(void) {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    int a[MAX_N], b[MAX_N], asum = 0, bsum = 0;
    REP(i, n) {
      cin >> a[i];
      asum += a[i];
    }
    REP(i, m) {
      cin >> b[i];
      bsum += b[i];
    }

    int minret = INF, reta = -1, retb = -1;
    REP(i, n) {
      REP(j, m) {
        int tempa = asum - a[i] + b[j], tempb = bsum - b[j] + a[i];
        if (tempa == tempb && minret > a[i] + b[j]) {
          reta = a[i];
          retb = b[j];
          minret = a[i] + b[j];
        }
      }
    }
    if (reta == -1)
      cout << -1 << endl;
    else
      cout << reta << " " << retb << endl;
  }

  return 0;
}

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

int main() {
    ll a,b,k;
    cin>>a>>b>>k;

    if (k<=a) {
        cout << a-k << " " << b << endl;
    } else if(k <= a+b) {
        cout << 0 << " " << b-(k-a) << endl;
    } else {
        cout << 0 << " " << 0 << endl;
    }
}


Measured memory_bytes: 256
import sys

n, m, r = [int(x) for x in sys.stdin.readline().split()]
b = 0
for i in range(m):
	a = (n * (i + 1)) % m
	if a == r:
		b = 1
		break
if b == 1:
	print('YES')
else:
	print('NO')

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
using namespace std;


ll llmin(ll x, ll y){
	if (x < y) return x;
	return y;
}

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}


int main(){
	ll n, z, w;
	cin >> n >> z >> w;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	if (n == 1) cout << abs(a[0] - w) << endl;
	else cout << llmax(abs(a[n-1] - w), abs(a[n-2] - a[n-1])) << endl;
	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
	int d, s;
	while (cin>>d){
		s = 0;
		for (int j = 1; j*d < 600; j++){
			s = s + d*d*d*j*j;
		}
		cout << s << endl;
	}
	return 0;
}

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

int main()
{
    string s;
    char buf;
    int m, h;
    
    while(1)
    {
        cin >> s;
        if(s == "-") break;
        cin >> m;
        for(int i=0;i<m;i++)
        {
            cin >> h;
            
            for(int j=0;j<h;j++)
            {
                buf = s[0];
                for(int k=0;k<s.size()-1;k++)
                {
                    s[k] = s[k+1];
                }
                s[s.size()-1] = buf;
            }
        }
        cout << s << endl;
    }

    return 0;
}



Measured memory_bytes: 3168
data class Point(val x: Double, val y: Double) {
    fun dist(o:Point): Double {
        return Math.sqrt((x-o.x)*(x-o.x) + (y-o.y)*(y-o.y))
    }
}
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val P = mutableListOf<Point>()
    for (i in 0 until n) {
        val l: List<Int> = readLine()!!.split(" ").map {it.toInt()}
        P.add(Point(l[0].toDouble(), l[1].toDouble()))
    }
    var s = 0.0
    for (i in 0 until n) {
        for (j in i+1 until n) {
            s += P[i].dist(P[j])
        }
    }
    s = s * 2 / n
    println(s)
}


Measured memory_bytes: 38240
def factorization(n):
  arr = []
  tmp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if tmp % i == 0:
      cnt = 0
      while tmp % i == 0:
        cnt += 1
        tmp //= i
      arr.append([i, cnt])
  if tmp != 1:
    arr.append([tmp, 1])
  if arr == [] and n != 1:
    arr.append([n, 1])
  return arr

n = int(input())
c = factorization(n)
ans = 0

for k, v in c:
  cnt = 1
  while v >= cnt:
    v -= cnt
    cnt += 1
  ans += (cnt - 1)

print(ans)


Measured memory_bytes: 9412
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(ll key, ll value){
      this->key = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

ll search(const int start, const int end, const vll& a, vvll& dp, const vvll& sum){
  if(start>=end) return dp[start][end]=0;
  if(dp[start][end]>=0) return dp[start][end];
  if(start+1==end) return dp[start][end] = a[start]+a[end];
  ll tmp=INFLL;
  rep(i, start, end){
    ll tmp1 = search(start, i, a, dp, sum);
    ll tmp2 = search(i+1, end, a, dp, sum);
    tmp = min(tmp, tmp1+tmp2);
  }
  return dp[start][end] = tmp+sum[start][end];
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  vll a(N);
  rep(i, 0, N){
    cin >> a[i];
  }

  vvll dp(N, vll(N, -1));
  vvll sum(N, vll(N, 0));

  rep(i, 0, N){
    sum[i][i] = a[i];
    rep(j, i+1, N){
      sum[i][j] = sum[i][j-1] + a[j];
    }
  }

  cout << search(0, N-1, a, dp, sum) << "\n";

  return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e5 + 10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;

void solve() {
    ll n,x,t;
    cin>>n>>x>>t;
    ll c=ceil(n*1.0/x)*t;
    cout<<c<<endl;
}

int main() {
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    vector<int> c(n);
    c[0] = 0;
    c[1] = abs(h[1] - h[0]);
    for(int i=2; i<n; i++){
        c[i] = min(c[i-1] + abs(h[i] - h[i-1]), c[i-2] + abs(h[i] - h[i-2]));
    }
    cout << c[n-1] << endl;
    return 0;
}

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

int dfs(int now, int n, int s) {
  if (n == 0 && s == 0) return 1;
  if (now < 10) return dfs(now + 1, n, s) + dfs(now + 1, n - 1, s - now);
  return 0;
}

int main() {
  while (true) {
    int n, s;
    cin >> n >> s;
    if (n == 0 && s == 0) return 0;

    int ans = dfs(0, n, s);
    cout << ans << endl;
  }
}

Measured memory_bytes: 3012
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define INF 1000000;
#include <map>
#include <math.h>

using ll = long long;
using namespace std;


int main(){
  string s1;
  cin >> s1;
  s1.at(5) = ' ';
  s1.at(13) = ' ';
 
  rep(i, 19) cout << s1.at(i);
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<int64_t> as(n);
	for (auto& a : as) {
		cin >> a;
	}
	sort(as.begin(), as.end());

	int i = 0;
	int j = n - 2;
	int64_t ans = 0;
	int64_t m= 2;
	while (i <= j) {
		if (i == j) {
			ans += (m - 1) * (as[i + 1] - as[i]);
		}
		else {
			int64_t al = as[i + 1] - as[i];
			int64_t ah = as[j + 1] - as[j];
			ans += m * al + m * ah;
			if (i + 1 == j) {
				ans -= min(al, ah);
			}
		}
		i++;
		j--;
		m += 2;
	}
	cout << ans << endl;

	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF bit(60)
#define pb push_back
#define mod 1000000007

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

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

#define FACSIZE 200002

ll invfac[FACSIZE];
ll fac[FACSIZE];

template <class T>
bool chmax(T &, const T &);
template <class T>
bool chmin(T &, const T &);
ll gcd(ll, ll);
ll powLL(ll x, ll y);

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
ll comb(ll, ll);
void make_fact(ll);
void make_invfact(ll);
void fact_init();

int main(void)
{

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

  if (n % 2 != 0)
  {
    cout << 0 << endl;
    return 0;
  }
  else
  {
    ll target = n;
    ll div = 10LL;
    while (div <= n)
    {
      ans += n / div;
      div *= 5LL;
    }
    cout << ans << endl;
  }

  return 0;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % mod;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % mod;
    return mod_mul(t, t);
  }
  else
  {
    ll t = mod_pow(x, r / 2) % mod;
    ll k = mod_mul(t, t);
    return (k % mod) * (x % mod);
  }
}
ll mod_add(ll a, ll b)
{
  return ((a % mod) + (b % mod)) % mod;
}

ll mod_mul(ll a, ll b)
{
  return ((a % mod) * (b % mod)) % mod;
}

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, mod - 2));
}

void fact_init()
{
  make_fact(FACSIZE - 1);
  make_invfact(FACSIZE);
}

void make_fact(ll n)
{
  fac[0] = 1;
  rep(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

ll comb(ll n, ll r)
{

  return mod_mul(mod_mul(fac[n], invfac[r]), invfac[n - 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;
}

ll qp(ll a, ll b)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * mod_mul(ans, a) % mod;
    a = 1LL * mod_mul(a, a) % mod;
  } while (b >>= 1LL);
  return ans;
}
ll qp(ll a, ll b, ll mo)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * (ans % mo) * (a % mo);
    a = 1LL * (a % mo) * (a % mo);
  } while (b >>= 1LL);
  return ans;
}
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
ll powLL(ll x, ll y)
{
  ll ans = 1LL;
  for (ll i = 0LL; i < y; i++)
    ans *= x;
  return ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

typedef long long ll;
using namespace std;

int pot (ll q, ll w){
	ll qw = q;
	q = 1;
	for (int i = 0; i<w; i++)
		q*= qw;
	return q;
}

ll a[10005];

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

ll n,m;

cin >> n >> m;

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

if (n<0)
	cout << "-1";
else
	cout << n;

return 0;
}



Measured memory_bytes: 3680
import java.io.*
import java.util.*

fun main(args: Array<String>) = Scanner(System.`in`).use {
    it.nextInt()
    val a = it.nextInt()
    val b = it.nextInt()
    val s = it.next()!!

    var c1 = 0
    var c2 = 0
    for (c in s) {
        if ((c == 'a') && (c1 < a+b)) {
            println("Yes")
            c1++
        } else if ((c == 'b') && (c1 < a+b) && (c2 < b)) {
            println("Yes")
            c1++
            c2++
        } else {
            println("No")
        }
    }
}

Measured memory_bytes: 40492
//ラブライブ！サンシャイン！！
//AT2274 
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=9223372036854775807ll;

struct line{
	ll k,b;
	line(ll k=0,ll b=0):k(k),b(b){}
	ll get(ll x){return k*x+b;}
}st[300010],u;

int tp;

double its(line a,line b){
	return (b.b-a.b)/double(a.k-b.k);
}

int t[300010],n;
ll s[300010],f[300010],g[300010];
void dp(ll*f){
	int i;
	for(int i=1;i<=n;i++) s[i]=s[i-1]+t[i];
	tp=1;
	st[1]=line(0,0);
	for(int i=1;i<=n;i++){
		while(tp>1&&st[tp].get(i)<=st[tp-1].get(i)) tp--;
		f[i]=max(st[tp].get(i)+((ll)i*i+i)/2-s[i],f[i-1]);
		u=line(-i,f[i]+((ll)i*i-i)/2+s[i]);
		while(tp>1&&its(u,st[tp-1])>=its(st[tp],st[tp-1])) tp--;
		st[++tp]=u;
	}
}
ll h[300010];
void solve(int l,int r){
	if(l==r){
		h[l]=1ll-t[l];
		return;
	}
	int mid,i,now;
	ll mx;
	mid=(l+r)>>1;
	solve(l,mid);
	solve(mid+1,r);
	tp=0;
	for(int i=l-1;i<mid;i++){
		u=line(-i,f[i]+((ll)i*i-i)/2+s[i]);
		while(tp>1&&its(u,st[tp-1])>=its(st[tp],st[tp-1])) tp--;
		st[++tp]=u;
	}
	now=1;
	mx=-inf;
	for(i=r;i>mid;i--){
		while(now<tp&&its(st[now],st[now+1])>=i)now++;
        mx=max(mx,st[now].get(i)+((ll)i*i+i)/2-s[i]+g[i+1]);
        h[i]=max(h[i],mx);
	}
	tp=0;
	for(i=mid+1;i<=r;i++){
        u=line(-i,g[i+1]+((ll)i*i+i)/2-s[i]);
        while(tp>1&&its(u,st[tp-1])>=its(st[tp],st[tp-1]))tp--;
        st[++tp]=u;
    }
    now=tp;
    mx=-inf;
    for(i=l-1;i<mid;i++){
        while(now>1&&its(st[now],st[now-1])<=i)now--;
        mx=max(mx,st[now].get(i)+((ll)i*i-i)/2+s[i]+f[i]);
        h[i+1]=max(h[i+1],mx);
    }
}
int main(){

	int i,m,x,y;
	cin>>n;
	for(i=1;i<=n;i++) scanf("%d",t+i);
	dp(f);
	reverse(t+1,t+n+1);
	dp(g);
	reverse(t+1,t+n+1);
	reverse(g+1,g+n+1);
	for(i=1;i<=n;i++)s[i]=s[i-1]+t[i];
    solve(1,n);
    scanf("%d",&m);
    while(m--){
        scanf("%d%d",&x,&y);
        printf("%lld\n",max(f[x-1]+g[x+1],h[x]+t[x]-y));
    }
}

Measured memory_bytes: 17792
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main (void){
        int x1,y1,x2,y2,x3,y3,x4,y4;
scanf("%d\n",&x1);
scanf("%d\n",&y1);
scanf("%d\n",&x2);
scanf("%d\n",&y2);
y4=y1+(x2-x1);
x4=x1-(y2-y1);
y3=y4+(y2-y1);
x3=x4+(x2-x1);
printf("%d %d %d %d\n",x3,y3,x4,y4 );
        return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long res = 2020;
        if(b - a >= 2019){
            res = 0;
        }else{
            for(long i = a; i < b; i++){
                for(long j = a + 1; j <= b; j++){
                    res = Math.min(res, (i * j) % 2019);
                }
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long;

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

	for (int i = 0; i < N; i++) {
		char S;
		cin >> S;
		if (S == 'Y') {
			cout << "Four" << endl;
			return 0;
		}
		
	}
	cout << "Three" << endl;
	return 0;
	
	


	
}




Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n, k, r, p, s;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  i64 ans = 0;
  for (i64 i = 0; i < k; i++)
  {
    vector<vector<i64>> dp(2, vector<i64>(3, 0));
    for (i64 j = i; j < n; j += k)
    {
      if (t[j] == 'r')
        dp[1] = {max(dp[0][1], dp[0][2]), max(dp[0][0], dp[0][2]), max(dp[0][0] + p, dp[0][1] + p)};
      else if (t[j] == 's')
        dp[1] = {max(dp[0][1] + r, dp[0][2] + r), max(dp[0][0], dp[0][2]), max(dp[0][0], dp[0][1])};
      else
        dp[1] = {max(dp[0][1], dp[0][2]), max(dp[0][0] + s, dp[0][2] + s), max(dp[0][0], dp[0][1])};
      swap(dp[0], dp[1]);
    }
    ans += max({dp[0][0], dp[0][1], dp[0][2]});
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long int lli;
typedef pair<int, int> ii;

int main() {
	ios_base::sync_with_stdio(false);

	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a*n, b) << endl;

	return 0;
}

Measured memory_bytes: 256
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    n = Z()
    output = []
    for i in range(1, n+1):
        if i%3 == 0: output.append(i)
        elif '3' in str(i): output.append(i)
    for i in output: print(' ' + str(i), end='')
    print('')

    return

if __name__ == '__main__':
    main()



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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    string st;
    cin >> st;

    vvi dp(2, vi(st.size()+1, 0));

    dp[0][0] = 1; // max
    //dp[1][0] = 1; // not 

    rep(i, st.size()) {
        if (st[i] == '1') {
            dp[0][i+1] = (dp[0][i+1] + dp[0][i] * 2) % MOD;
            dp[1][i+1] = (dp[1][i+1] + dp[0][i]) % MOD;
            dp[1][i+1] = (dp[1][i+1] + dp[1][i] * 3) % MOD;
        } else {
            dp[0][i+1] = (dp[0][i+1] + dp[0][i]) % MOD;
            dp[1][i+1] = (dp[1][i+1] + dp[1][i] * 3) % MOD;
        }
    }
    std::cout << (dp[0][st.size()] + dp[1][st.size()] ) % MOD << std::endl;

    return 0;
}


Measured memory_bytes: 2896
/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp*/
#include <iostream>
#include <stack>
#include <stdexcept>

using namespace std;

int calc(stack<string> *s){
    if((*s).size()>1) {
        string opr = (*s).top();
        (*s).pop();
        int opt[2];
        for (int j = 0; j < 2; j++) {
            try {
                opt[j] = stoi((*s).top());
            }catch(invalid_argument e){
                opt[j] = calc(s);
            }
            (*s).pop();
        }
        if (opr == "+") {
            (*s).push(to_string(opt[1] + opt[0]));
        } else if (opr == "-") {
            (*s).push(to_string(opt[1] - opt[0]));
        } else if (opr == "*") {
            (*s).push(to_string(opt[1] * opt[0]));
        } else if (opr == "/") {
            (*s).push(to_string(opt[1] / opt[0]));
        }
        return stoi((*s).top());
    }
    return 0;
}

int main(){
    stack<string> s;
    while(cin.peek()!='\n'){
        string i;
        cin >> i;
        s.push(i);
    }
    cout<<calc(&s)<<endl;
    return 0;
}

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

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

  temp = X;
  X=Y;
  Y = temp;

  temp = X;
  X=Z;
  Z = temp;
  
  cout << X << ' ' << Y << ' ' << Z << endl;

}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc164/abc164_e.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> pl;
typedef tuple<ll, ll, ll> tl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

ll N, M, S;
vector<ll> C;
vector<ll> D;

// [辺i][所持金S] のときの最短時間
ll dp[50][2500 + 1];

void solve(vector<vector<tl>>& g) {
  ll MAX = 2500;
  S = min(S, MAX);

  rep(i, 50) rep(j, 2501) dp[i][j] = LINF;
  dp[0][S] = 0;

  // 未確定なもののQueue; time, vertex, money
  priority_queue<tl, vector<tl>, greater<tl>> que;
  que.push(make_tuple(0, 0, S));

  while (!que.empty()) {
    // 構造化束縛 C++17
    auto [time, from, money] = que.top();
    // printf("time:%lld from:%lld s:%lld\n", time, from, money);
    que.pop();
    if (dp[from][money] < time) continue;

    // 換金（補充）
    if (money + C[from] <= MAX) {
      ll ntime = time + D[from];
      ll nmoney = money + C[from];
      if (dp[from][nmoney] > ntime) {
        // printf(" >> GET! time:%lld from:%lld s:%lld\n", ntime, from, nmoney);
        dp[from][nmoney] = ntime;
        que.push(make_tuple(ntime, from, nmoney));
      }
    }

    // 移動
    for (auto to_edge : g[from]) {
      auto [to, to_time, to_cost] = to_edge;

      // お金が足りないので通れない
      if (money < to_cost) continue;

      ll ntime = time + to_time;
      ll nmoney = money - to_cost;

      // printf("    to:%lld dp:%lld ntime:%lld\n", to, dp[to][nmoney], ntime);
      if (dp[to][nmoney] > ntime) {
        // printf(" >> GO! time:%lld to:%lld s:%lld\n", ntime, to, nmoney);
        dp[to][nmoney] = ntime;
        que.push(make_tuple(ntime, to, nmoney));
      }
    }
  }

  repi(i, 1, N) {
    ll ans = LINF;
    rep(j, MAX + 1) { ans = min(ans, dp[i][j]); }
    cout << ans << endl;
  }
}

/**
 * 拡張ダイクストラ
 * 辺の重みが変わる/補充 DPしながら最短経路
 * 各頂点で所持金がX円である状態を拡充する
 * https://drken1215.hatenablog.com/entry/2020/04/27/190000
 *
 * #graph #dijkstra #dp
 */
int main() {
  INPUT_FILE CIN_OPTIMIZE;

  cin >> N >> M >> S;

  vector<vector<tl>> g(N, vector<tl>(0));
  rep(i, M) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    // v, time, cost
    g[u].push_back(make_tuple(v, b, a));
    g[v].push_back(make_tuple(u, b, a));
  }

  C = vector<ll>(N, 0);
  D = vector<ll>(N, 0);
  rep(i, N) { cin >> C[i] >> D[i]; }

  solve(g);
}

Measured memory_bytes: 7296
<?php

    $s = trim(fgets(STDIN));
    $n = strlen($s);
    for($i=0; $i<26; $i++) $c[$i] = 0;
    for($i=0; $i<$n; $i++){
        $t[$i] = ord($s[$i])-ord('a');
    }
    
    $ans = 1000;
    for($c=0; $c<26; $c++){
        for($i=0; $i<$n; $i++) $u[$i] = $t[$i];
        $f = true;
        $x = $n;
        while($f){
            $f = false;
            for($i=0; $i<$x-1; $i++){
                if($u[$i] != $c){
                    $f = true;
                    if($u[$i+1] == $c) $u[$i] = $c;
                }
            }
            if($f) $x--;
            if(!$f && $u[$x-1] != $c) $x--;
        }
        if($n-$x<$ans) $ans = $n-$x;
    }
    echo $ans;
?>

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

template <class type> void printVector(vector<type> vec){
    stringstream ss;
    for(ll i=0;i<vec.size();i++)
    {
        ss<<vec[i]<<" ";
    }
    cout<<ss.str()<<endl;
}


int main()
{
    ll N,X,Y;
    cin>>N>>X>>Y;X--;Y--;

    Graph dist(N,vector<ll>(N,-1));

    for(ll i=0;i<N;i++)
    {
        queue<ll> que;
        dist[i][i]=0;
        que.push(i);

        while(!que.empty())
        {
            ll v=que.front();
            que.pop();

            vector<int> adjacency;
            if (v>0) adjacency.push_back(v-1);
            if (v<N-1) adjacency.push_back(v+1);
            if (v==X) adjacency.push_back(Y);
            if (v==Y) adjacency.push_back(X);
            for (auto nv : adjacency) {
                if (dist[i][nv] == -1) {
                    dist[i][nv] = dist[i][v] + 1;
                    que.push(nv);
                }
            }
        }
    }


    vector<ll> res(N, 0);
    for (ll i=0;i<N;++i) {
        for (ll j=i+1;j<N;++j)res[dist[i][j]]++;
    }

    for(ll i=1;i<N;i++)
    {
        cout<<res[i]<<endl;
    }
}

Measured memory_bytes: 34624
#include <stdio.h>
#define N 100
void insertionSort(int*,int);
int main(){
  int i,j,n,tmp;
  int A[N];

  scanf("%d",&n);
  for(i = 0; i < n; i++)
    scanf("%d",&A[i]);

  for(i = 0; i<n; i++) {
    if(i > 0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");

  insertionSort(A,n);
 
  return 0;
}

void insertionSort(int A[], int n)
{
  int i,j,v;

  for(i = 1; i < n; i++){
    v = A[i];
    j = i-1;
    while(j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  
    for(j = 0; j<n; j++) {
      if(j > 0) printf(" ");
      printf("%d",A[j]);
    }
    printf("\n");
  }
}

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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

const int inf = INT_MAX;
const long long INF = LLONG_MAX;

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 3e5 + 7;
vector <vi > adj(N);

bool vis[N];

int dp[100005][2];
int n;


void solve()
{
	int n, k;
	cin >> n >> k;
	vpii ans;

	loop(i, 0, n)
	{
		int x;
		cin >> x;
		double sum = x * (x + 1);
		sum /= 2;
		ans.pb({sum, x});

	}

	double res = 0;
	loop(i, 0, k)
	{
		int s = ans[i].ff;
		int x = ans[i].ss;
		res += double(s) / x;


	}
	double mx = res;
	//bug(mx);
	loop(i, k, n)
	{
		int rem = i - k;
		int a = ans[rem].ff;
		int b = ans[rem].ss;
		res -= double(a) / b;
		int s = ans[i].ff;
		int x = ans[i].ss;
		res += double(s) / x;
		mx = max(mx, res);

	}

	cout << setprecision(12) << fixed << mx;
	return;
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


	cout << setprecision(9) << fixed;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}


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

int main(){
    int N, T;
    cin >> N >> T;
    vector<int> c(N), t(N);
    for(int i=0; i<N; i++) cin >> c[i] >> t[i];
    
    int mi=1e9;
    for(int i=0; i<N; i++){
        if(t[i]<=T){
            mi = min(mi, c[i]);
        }
    }
    if(mi!=1e9)
        cout << mi << endl;
    else
        cout << "TLE" << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define ll long long
#define pb push_back
#define pf push_front			
#define mp make_pair
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pi 3.14159265358
#define xmod 1000000007
using namespace std;

int n,m,b[25],c,a[25],sum,x,ans;
int main(){
	scanf("%d%d%d",&n,&m,&c);
	for (int i=1;i<=m;i++){
		scanf("%d",&b[i]);
	}
	for (int i=1;i<=n;i++){
		sum=0;
		for (int j=1;j<=m;j++){
			scanf("%d",&x);
			sum+=x*b[j];
		}
		if (sum+c > 0)
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
def gcdf(a):
    a.sort()
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a) 
    
n,x=map(int,input().split())
xi=list(map(int,input().split()))

for i in range(n):
    if xi[i]>x:
        xi[i]=xi[i]-x
    else:
        xi[i]=x-xi[i]
    
gcdx=gcdf(xi)
print(gcdx)    

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

using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr2(i,s,n) for (int i = (n-1); i>=(int)(s);i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
const ll INF = 1001001000100010;
const ld PI = 3.14159265358979323846;



int main() {
int A,B;
cin>>A>>B;
cout<<A*B<<endl;

return 0;
}



Measured memory_bytes: 3636
#あっとのTECH LOG、ここからDFS
N, M, K = map(int, input().split())
F = [[] for _ in range(N)]
B = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    F[a].append(b)
    F[b].append(a)

for _ in range(K):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1
    B[c].append(d)
    B[d].append(c)


D = {}
parent = [-1] * N
visited = [False] * N
for root in range(N):
    if visited[root]:
        continue

    D[root] = set([root])
    stack = [root]
    while stack:
        n = stack.pop()
        visited[n] = True
        parent[n] = root

        for to in F[n]:
            if visited[to]:
                continue
            D[root].add(to)
            stack.append(to)

ans = [0] * N
for iam in range(N):
    group = D[parent[iam]]
    tmp_ans = len(group) - len(F[iam]) - 1
    for block in B[iam]:
        if block in group:
            tmp_ans -= 1
    ans[iam] = tmp_ans

print(*ans, sep=' ')

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

int main(void) {
  int n; scanf("%d", &n);
  vector<int> arr(n);
  bool ok = true;
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] % 2 == 0) {
      if (arr[i] % 3 != 0 && arr[i] % 5 != 0) {
        ok = false;
        break;
      }
    }
  }
  if (!ok) printf("DENIED\n");
  else printf("APPROVED\n");
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
  int n,k;
  cin>>n>>k;
  vector<LL> a(n);
  LL sm=0;
  FOR(i,0,n){
    cin>>a[i];
    sm+=a[i];
  }
  int lm=min(max((int)(sqrt(sm)*2),10),(int)(sm-1));
  auto v=divisor(sm);
  sort(v.rbegin(),v.rend());
  for(const auto& ans:v){
    if(sm%ans!=0)continue;
    vector<LL> b(n);
    int ff=1;
    FOR(i,0,n){
      b[i]=a[i]%ans;
      if(b[i]!=0)ff=0;
    }
    if(ff){
      cout<<ans<<endl;
      return 0;
    }

    sort(b.begin(),b.end());
    vector<LL> w(n+1,0);
    vector<LL> rw(n+1,0);
    //cerr<<"ans:"<<ans<<endl;
    w[0]=b[0];
    rw[n-1]=ans-b[n-1];
    FOR(i,1,n){
      w[i]=w[i-1]+b[i];
      //cerr<<w[i]<<" ";
    }
    //cerr<<endl;
    FORD(i,n-1,0){
      rw[i]=rw[i+1]+ans-b[i];
      //cerr<<rw[i]<<" ";
    }
    //cerr<<endl;
    FOR(i,0,n-1){
      if(w[i]-rw[i+1]==0&&k>=w[i]){
        //cerr<<"i:"<<i<<endl;
        cout<<ans<<endl;
        return 0;
      }
    }

  }

  cout<<1<<endl;

	return 0;
}


Measured memory_bytes: 256