akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

int dp[MX][3];

int main() {
  int n;
  scanf("%d",&n);
  rep(i,n) {
    vi a(3);
    cin>>a;
    rep(j,3)rep(k,3) if (j != k) {
      maxs(dp[i+1][j], dp[i][k]+a[j]);
    }
  }
  int ans = 0;
  rep(i,3) maxs(ans, dp[n][i]);
  cout<<ans<<endl;
  return 0;
}






















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

const long long MAX = 1000000000000000000;

int main() {
  ll x;
  cin >> x;
  ll a = 0, b = 0;

  ll base = 0;
  vector<ll> num;
  while (true) {
    ll tmp = pow(base, 5);
    if (tmp > MAX) break;
    num.push_back(tmp);
    base++;
  }

  int a_i, b_i;
  for(int i = 0; i < num.size(); ++i) {

    b = num[i];
    a = b+x;
    auto it = find(num.begin(),num.end(), a);
    if (num.end() != it) {
      a = it - num.begin();
      b = i;
      break;
    }
    a = -b+x;
    it = find(num.begin(),num.end(), a);
    if (num.end() != it) {
      a = it - num.begin();
      b = -i;
      break;
    }
  }

  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;

int a, b, c;
int main()
{
    stat();
    string s;
    cin >> s;
    bool a = false, b = false, cc = false;
    for (auto c : s) {
        if (c == 'a') { a = true; }
        if (c == 'b'){ b = true;}
        if (c == 'c'){ cc = true;
    }}
    if(a&&b&&cc){cout<<"Yes"<<endl;}else {cout<<"No"<<endl;}
    return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}


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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    char dif = 'A' - 'a';
    
    printf("%c%c%c\n", a[0] + dif, b[0] + dif, c[0] + dif);
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val cards = readLine()!!.split(" ").subList(0, n).map { it.toInt() }.sortedDescending()
    val alice = cards.filterIndexed { idx, _ -> idx % 2 == 0 }.sum()
    val bob = cards.filterIndexed { idx, _ -> idx % 2 != 0 }.sum()
    print(alice - bob)
}


Measured memory_bytes: 39152
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int R;
  cin >> R;
  cout << (2 * R * acos(-1)) << endl;
  return 0;
}


Measured memory_bytes: 3772
k, n = map(int, input().split())
a = list(map(int, input().split()))

a = sorted(a)
q = [an - ap for an, ap in zip(a[1:], a[:-1])]

nomal = max(a) - min(a)
abnomal = k - max(q)

print(min(nomal, abnomal))

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

void call(int n){

  for(int i=1;i<=n;i++){
    int x = i;
    if( x % 3 == 0){
        cout << " " << i;
        continue;
    }
//    bool flg = 0;
    while( x != 0 ){
    if(x % 10 == 3){
          cout << " " << i;
//          flg = 1;
          break;
        }
      x = x/10;    
    }
  }
  cout << endl;
//  int i = 1;
// CHECK_NUM:
//  int x = i;
//  if ( x % 3 == 0 ){
//    cout << " " << i;
//    goto END_CHECK_NUM;
//  }
// INCLUDE3:
//  if ( x % 10 == 3 ){
//    cout << " " << i;
//    goto END_CHECK_NUM;
//  }
//  x /= 10;
//  if ( x ) goto INCLUDE3;
// END_CHECK_NUM:
//  if ( ++i <= n ) goto CHECK_NUM;
//
//  cout << endl;
}

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


Measured memory_bytes: 3112
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        for(int i=0;i<M;i++){
            N -= sc.nextInt();
        }
        if(N>=0){
            System.out.println(N);
        } else {
            System.out.println(-1);
        }
    }
}


Measured memory_bytes: 46296
#include<iostream>
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
#include <map> 
#include<algorithm>
#include <numeric>
#include<deque>
#include<queue>
#include<string>
#include <iomanip>

using namespace std;
typedef long long ll;

int main(void){
    ll n;
    cin>>n;
    ll ans=((n-1)*n)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N,K=list(map(int,input().split()))

ans_=[0]*N

for k in range(0,2*K,2):
    k_ = int(input())
    A = list(map(int,input().split()))
    for a in A:
        ans_[a-1]+=1
        
ans=0
for a in ans_:
    if a == 0:
        ans+=1
        
print(ans)

Measured memory_bytes: 67880
#

# import sys
# input=sys.stdin.readline

def main():
    A,B=map(int,input().split())
    cnt=0
    for i in range(A,B+1):
        s=str(i)
        if s==s[::-1]:
            cnt+=1
    print(cnt)
    
if __name__=="__main__":
    main()


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n)cin>>a[i];

	vector<ll> left(n+1), right(n+1);
	left[0] = 0;
	right[n] = 0;
	rep(i,n){
		left[i+1] = __gcd(left[i],a[i]);
	}
	for(int i = n; i >= 1; i--){
		right[i-1] = __gcd(right[i],a[i-1]);
	}
	ll ans = 0;
	rep(i,n){
		chmax(ans, __gcd(left[i], right[i+1]));
	}
	cout << ans << endl;
}


Measured memory_bytes: 5612
(defparameter N (read))
(defparameter matrix
  (make-array '(9 9)))

(defun convert (num)
  (let* ((s-num (write-to-string num))
         (a (aref s-num 0))
         (b (aref s-num (1- (length s-num)))))
        (cons (digit-char-p a)
              (digit-char-p b))))

(defun calc-matrix (num M)
  (loop for i from 1 to num
        if (not (zerop (mod i 10)))
        do (let ((pair (convert i)))
                (incf (aref M 
                            (1- (car pair))
                            (1- (cdr pair)))))
        finally (return M)))

(defun answer (M)
  (loop with a = 0
   		for i from 0 below 9
        do (loop for j from 0 below 9
                 do (setf a (+ a (* (aref M i j)
                                    (aref M j i)))))
        finally (return a)))

(format t "~A" (answer (calc-matrix N matrix)))


Measured memory_bytes: 67936
#include<cstdio>

const int N=1e5+5;

int n,s,x[N]; long long p[N];

int main(){
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;++i){
		scanf("%d%d",&x[i],&p[i]);
	}
	int l=1,r=n,dir=-1; long long ans=0;
	while(1){
		if(s<=x[l]){ ans+=x[r]-s; break; }
		if(s>=x[r]){ ans+=s-x[l]; break; }
		if(p[l]>=p[r]){
			if(dir!=0) ans+=x[r]-x[l];
			p[l]+=p[r]; dir=0; --r;
		}
		else{
			if(dir!=1) ans+=x[r]-x[l];
			p[r]+=p[l]; dir=1; ++l;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    if ((b-a)%2==0){
        printf("Alice\n");
    } else {
        printf("Borys\n");
    }
	return 0 ;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	int maxv=0,maxn=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(maxv<a[i])
		{
			maxn=maxv;
			maxv=a[i];
		}
		else
		{
			if(a[i]>maxn)
			{
				maxn=a[i];
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]==maxv)
		{
			cout<<maxn<<endl;
		}
		else
		{
			cout<<maxv<<endl;
		}
	}
	return 0;
}

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

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007

const int mxn = 1e5+500;
int a[mxn];
int dp[mxn];



int solve(int n){
	memset(dp,INT_MAX,sizeof dp);

	dp[0] = 0;
	dp[1] = abs(a[0]-a[1]);

	for(int i=2;i<n;i++){
		dp[i] = min(dp[i-1] + abs(a[i-1]-a[i]), dp[i-2] + abs(a[i-2]-a[i]));
	}

	return dp[n-1];

}

int main(){
	NINJA;

	int n; cin >> n;
	fo(i,n) cin >> a[i];

	//memset(dp,-1,sizeof dp);
	cout << solve(n) << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
using namespace std;

int n,x,cnt;

void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>x;
    	if(i%2==1 && x%2==1) cnt++;
    }
    cout<<cnt<<endl;
}

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

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

int main(){
  int n;
  cin>>n;
  if(n%10==(n%100-n%10)/10 && n%10==(n-n%100)/100) cout<<n<<endl;
  else if(n/100>(n%100-n%10)/10) cout<<n/100*100+n/100*10+n/100<<endl;
  else if(n/100<(n%100-n%10)/10) cout<<(n/100+1)*100+(n/100+1)*10+n/100+1<<endl;
  else if(n%10>(n%100-n%10)/10) cout<<(n/100+1)*100+(n/100+1)*10+n/100+1<<endl;
  else cout<<n/100*100+n/100*10+n/100<<endl;
  return 0;
}

Measured memory_bytes: 256
/*
█████████───███─────────███───███─────────████████████───███████████████───████████████───████████████───█████████───────
█████████───███─────────███───███─────────████████████───███████████████───████████████───████████████───█████████───────
█████████───███─────────███───███─────────████████████───███████████████───████████████───████████████───█████████───────
███─────────███─────────███───███─────────███──────███───███───███───███───███──────███───███──────███───███─────────────
███─────────███─────────███───███─────────███──────███───███───███───███───███──────███───███──────███───███─────────────
███─────────███─────────███───███─────────███──────███───███───███───███───███──────███───███──────███───███─────────────
█████████──────███───███──────███─────────████████████───███───███───███───████████████───███──────███───█████████───────
█████████──────███───███──────███─────────████████████───███───███───███───████████████───███──────███───█████████───────
█████████──────███───███──────███─────────████████████───███───███───███───████████████───███──────███───█████████───────
███────────────███───███──────███─────────███──────███───███───███───███───███────────────███──────███─────────███───────
███────────────███───███──────███─────────███──────███───███───███───███───███────────────███──────███─────────███───────
███────────────███───███──────███─────────███──────███───███───███───███───███────────────███──────███─────────███───────
█████████─────────███─────────█████████───███──────███───███───███───███───███────────────████████████───█████████───────
█████████─────────███─────────█████████───███──────███───███───███───███───███────────────████████████───█████████───────
█████████─────────███─────────█████████───███──────███───███───███───███───███────────────████████████───█████████───────
*/
/**

**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fori(n) for ( int i = 0; i < (n);i++)
#define forj(n) for ( int j = 0; j < (n);j++)
#define fork(n) for ( int k = 0; k < (n);k++)
#define forghj(n) for ( int ghj = 0; ghj < (n);ghj++)
#define fori1(n) for ( int i = (n)-1; i >= 0;i--)
#define all(vector) (vector).begin(),(vector).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define INF 1e9+7
#define EPS 1e-6
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma GCC optimize "-O3"
int kek(int d) {
    int kol = 0;
    while (true) {
        if (d == 0) break;
        kol++;
        d /= 10;
    }
    if (kol % 2 == 1) return 1;
    else return 0;
}
int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += kek(i);
    }
    cout << ans;
}
/*
1
4
2 4 3 5
*/





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <utility>
#include <cstring>

using namespace std;

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

vector<string> field;
int W, H;
unsigned char memo[52][52][52][52];

struct State {
	unsigned char rx, ry, lx, ly;
	unsigned char index;
};

int main(){
	while(true){
		cin >> W >> H;
		if(W == 0 && H == 0){ break; }
		memset(memo, 0, sizeof(memo));
		field.resize(H + 2);
		field[0] = field[H + 1] = string(W * 2 + 3, '#');
		State init = { 0 };
		for(int i = 1; i <= H; ++i){
			string l1, l2;
			cin >> l1 >> l2;
			string line = "#" + l1 + "#" + l2 + "#";
			for(int j = 0; j < line.size(); ++j){
				if(line[j] == 'R'){
					init.rx = j; init.ry = i;
				}else if(line[j] == 'L'){
					init.lx = j; init.ly = i;
				}
			}
			field[i] = line;
		}
		stack<State> stk;
		stk.push(init);
		bool ok = false;
		while(!stk.empty()){
			State cur = stk.top();
			stk.pop();
			int rx = cur.rx, ry = cur.ry, lx = cur.lx, ly = cur.ly;
			if(cur.index == 0){
				if(memo[rx - W - 1][ry][lx][ly]){ continue; }
				memo[rx - W - 1][ry][lx][ly] = 1;
				if(field[ry][rx] == '%' && field[ly][lx] == '%'){
					ok = true;
					break;
				}else if(field[ry][rx] == '%' || field[ly][lx] == '%'){
					continue;
				}
			}
			int nrx = rx + dx[cur.index], nry = ry + dy[cur.index];
			int nlx = lx - dx[cur.index], nly = ly + dy[cur.index];
			if(field[nry][nrx] == '#'){
				nrx -= dx[cur.index];
				nry -= dy[cur.index];
			}
			if(field[nly][nlx] == '#'){
				nlx += dx[cur.index];
				nly -= dy[cur.index];
			}
			if(cur.index != 3){
				++cur.index;
				stk.push(cur);
			}
			State next = { nrx, nry, nlx, nly, 0 };
			stk.push(next);
		}
		cout << (ok ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 18000
import java.util.Scanner;
     
    class Main{
      public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int K = sc.nextInt();
        final int A = sc.nextInt();
        final int B = sc.nextInt();
        sc.close();
        String is_ok = "NG";
        for(int i=A;i<=B;i++){
          if(i%K == 0){
            is_ok = "OK";
          }
        }
        System.out.println(is_ok);
      }
    }

Measured memory_bytes: 35796
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;
using namespace std;
typedef pair<int, int> ii;
typedef priority_queue<int, vector<int>, greater<int> > heapq;
// #define int long long int

inline void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}

signed main() {
    int N; cin >> N;
    vector<int> A(N);
    for (auto&& a: A) cin >> a;

    vector<int> stock;
    stock.push_back(A[0]);
    for (int i = 1; i < N; i++) {
        auto it = lower_bound(stock.begin(), stock.end(), A[i]);
        if (it == stock.end()) { // はじめ
            stock[stock.size() - 1] = A[i];
        } else if (it == stock.begin()) { // A[i]が最小
            stock.insert(stock.begin(), A[i]);
        } else {
            --it;
            *it = A[i];
        }
    }

    cout << stock.size() << endl;
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
int main() {
    string S;
    cin >> S;
    if (S == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (S == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else if (S == "Rainy")
    {
        cout << "Sunny" << endl;
    }
    
}

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

#define ll long long
#define PB push_back
#define PF push_front
#define L size
#define vi vector<int>
#define MOD 1000000007
#define mp make_pair
#define fi first
#define se second


using namespace std;
ll fib(int n);
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k,min=INT_MAX;
    cin >> n >>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a,a+n);
    for(int i=0;i<=n-k;i++)
    {
        if(a[i+k-1]-a[i]<min)
            min = a[i+k-1]-a[i];
    }
    cout << min;

   
    
}
ll fib(int n)
{
    vector<ll> a;
    a.PB(0);a.PB(1);
    for(int i=2;i<=n+1;i++)
       a.PB(a[i-1]+a[i-2]);
    return a.back();
}

Measured memory_bytes: 4020
def main():
    N = int(input())
    A = list(map(int, input().split()))
    dp = [[0] * N for _ in range(N+1)]
    dp[1] = A
    for length in range(2, N+1):
        for idx in range(N - length + 1):
            dp[length][idx] = max(A[idx] - dp[length-1][idx+1],
                                  A[idx+length-1] - dp[length-1][idx])
    print(dp[N][0])


if __name__ == "__main__":
    main()


Measured memory_bytes: 111580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    int cnt=0;
    for(int R=0; R<=n; R++){
        for(int G=0; G<=n; G++){
            int B = (n-(r*R + G*g))/b;
            if(R*r + G*g + B*b == n && B >=0 ) cnt++;
        }
    }
    cout << cnt <<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 105
#define ll long long
int M,D,ans;
inline int rd()
{
	int f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
int main()
{
	M=rd(),D=rd();
	for(int m=4;m<=M;m++)
		for(int d1=2;d1<=9;d1++)
			for(int d2=2;d2<=9;d2++)
			{
				if(d1*10+d2>D) break;
				if(d1*d2==m) ans++;
			}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
int main()
{
long int k[20],i,j;
for(i=0;i<20;++i)
{
k[i]=pow(2,i);  
} 
  
double p,n,pp,l,cc,ans;
  ans=0;
int sw;
 scanf("%lf %lf",&n,&l);
  pp=1/n;
  p=0.5;
  
  for(j=1;j<=n;++j)
  {if(l/j<1) sw=0;
    else{
   for(i=0;i<19;++i)
   {
   if(k[i]<(l/j) && (l/j)<=k[i+1]) sw=i+1;
   }
    }
  ans=ans+pp*pow(p,sw);
    sw=0;
  }
  
  
  printf("%.9f",ans);

return 0;
}

Measured memory_bytes: 2456
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main (){
	long long a ; 
 	cin >> a; 
 	long long  cnt = 0;
 	while (a>0){
 	    a= a/2; cnt++;
 	}
    long long ans = pow(2, cnt)-1;
    cout << ans;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
B = []
S = [0]*n
for i in range(n-1, -1, -1):
  if sum(S[i::i+1])%2 ^ A[i]:
    B.append(i+1)
    S[i] ^= 1
print(len(B))
print(*B)

Measured memory_bytes: 14072
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] n = new int[4];
		for (int i=0; i<N; i++) {
			String t = sc.next();
			if (t.compareTo("P") ==0 ) n[0]++;
			if (t.compareTo("W") ==0 ) n[1]++;
			if (t.compareTo("G") ==0 ) n[2]++;
			if (t.compareTo("Y") ==0 ) n[3]++;
		}
		int res = 0;
		for (int i=0; i<4; i++) {
			if (n[i] >0) res++;  
		}
		if (res == 3)
			System.out.println("Three");
		else if (res == 4)
			System.out.println("Four");
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long T1, T2, A1, A2, B1, B2;
  cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
  long long CDA = A1 * T1 + A2 * T2; //Cycle Distance of A
  long long CDB = B1 * T1 + B2 * T2; //Cycle Distance of B
  CDA == CDB;
  if (CDA == CDB){
    cout << "infinity";
  } else {
    if (CDA < CDB){
      swap(A1,B1);
      swap(A2,B2);
      swap(CDA,CDB);
    }
    //1サイクル後は必ずAが先に出る
    long long CDD = CDA - CDB; //Cycle Distance Difference
    if (A1 > B1){
      cout << 0;
    } else {
      long long ADB = T1 * (B1 - A1); //Ahead Distance of B
      if (ADB % CDD == 0){
        cout << ADB / CDD * 2;
      } else {
        cout << ADB / CDD * 2 + 1;
      }
    }
  }
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))

def a():
    if n%3 > 0:
        if len(list(set(A))) == 1:
            return "Yes"
    else:
        B = list(set(A))
        if len(B) <= 3:
            c = 0
            t = 0
            for i in B:
                cou = A.count(i)
                # print("cou",cou)
                if cou % (n//3) == 0:
                    c += 1
                    for j in range(cou // (n//3)):
                        # print(t,i)
                        t ^= i
                # print(t)
            if c == len(B) and t == 0:
                return "Yes"
    return "No"

print(a())

Measured memory_bytes: 60784
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int64_t a,b,c;

int main()
{
    using std::endl;
    in.sync_with_stdio(false);
    out.sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);
    in >>a>>b>>c;
    auto v2 = c - a - b;
    if (v2 < 0) {
        out << "No" << endl;
        return 0;
    }
    if (4*a*b < v2 * v2) {
        out << "Yes" << endl;
        return 0;
    }
    out << "No" << endl;
    return 0;


    return 0;
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout<<(x)<<"\n"
#define REP(i, n) for(int i=0;i<n;i++)
#define endl "\n"
using ll = long long;
const int MOD = 998244353;

int main() {
  int n,k; cin >> n >> k;
  vector<int> l(k),r(k);
  REP(i,k) cin >> l[i] >> r[i];
  vector<ll> dp(n+1), dpsum(n+1);

  dp[1] = 1; // マス1から始まるため dp[1] = 1 にする
  dpsum[1] = 1; // dpの累積和

  for (int i = 2; i <= n; i++) {
    REP(j,k) {
      int li = max(i-r[j], 1);
      int ri = i-l[j];
      if (ri < 0) continue; // 右端が範囲外

      dp[i] += dpsum[ri]-dpsum[li-1];
      dp[i] = dp[i] < 0 ? dp[i]+MOD : dp[i]%MOD; // MOD
    }
    dpsum[i] = (dpsum[i-1]+dp[i]) % MOD;
  }

  COUT(dp[n]);
  return 0;
}

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

#define MAX_N 100000
#define INF 1LL<<60
typedef long long int ll;

ll dp[MAX_N][3];

int main() {
  int n, abc[3][MAX_N];

  std::cin >> n;
  for(int i = 0; i < n; ++i) {
    std::cin >> abc[0][i] >> abc[1][i] >> abc[2][i];
  }

  dp[0][0] = abc[0][0];
  dp[0][1] = abc[1][0];
  dp[0][2] = abc[2][0];
  for(int i = 1; i < n; ++i) {
    for(int j = 0; j < 3; ++j) {
      dp[i][j] = -INF;
      for(int x = 0; x < 3; ++x) {
        if(x == j) continue;
        dp[i][j] = std::max(dp[i][j], dp[i - 1][x] + abc[j][i]);
      }
    }
  }

  ll ans = -INF;
  for(int x = 0; x < 3; ++x) {
    ans = std::max(ans, dp[n - 1][x]);
  }

  std::cout << ans << std::endl;
}

Measured memory_bytes: 3712
MOD = 10 ** 9 + 7

n, k = map(int, input().split())
l = [0] * ((n + 1) // 2)
l[0] = n + 1
ans = 0

for i in range(1, (n + 1) // 2):
    l[i] = (l[i - 1] + (n - i * 2)) % MOD

for i in range(k, n + 1):
    if i <= (n + 1) // 2:
        ans += l[i - 1]
    else:
        ans += l[n - i]
    ans %= MOD

print((ans + 1) % MOD)

Measured memory_bytes: 12840
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    int mod2=0,mod4=0,modelse=0;
    vint a(n);
    rep(i,n){
        cin >> a[i];
        if(a[i]%4==0) mod4++;
        else if(a[i]%2==0) mod2++;
        else modelse++;
    }
    (mod2<1?yn(mod4+1>=modelse):yn(mod4>=modelse));
}

Measured memory_bytes: 3984
from math import gcd

K = int(input())
ans=0
array = [0] * 201

for X in range(1,K+1):
    for c in range(1,K+1):
        array[X] += gcd(X,c)

for a in range(1,K+1):
    for b in range(1,K+1):
        X = gcd(a,b)
        ans += array[X]

print(ans)

Measured memory_bytes: 9196
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int[][][] directedGraph(int n, int[] from, int[] to, int[] cost) {
		int[] cnt = new int[n];
		for (int i : from) cnt[i]++;

		int[][][] g = new int[n][][];
		for (int i=0; i<n; i++) g[i] = new int[cnt[i]][2];
		for (int i=0; i<from.length; i++) {
			int s = from[i];
			int t = to[i];

			g[s][--cnt[s]][0] = t;
			g[s][cnt[s]][1] = cost[i];
		}

		return g;
	}

	static int[][] floydWarshall(int[][][] g) {
		int n = g.length;
		int[][] d = new int[n][n];

		final int INF = (1<<31)-1;
		for (int i=0; i<n; i++) {
			Arrays.fill(d[i], INF);
			d[i][i] = 0;
		}

		for (int cur=0; cur<n; cur++) {
			for (int[] to : g[cur]) {
				int next = to[0];
				d[cur][next] = Math.min(d[cur][next], to[1]);
			}
		}

		for (int k=0; k<n; k++)
			for (int i=0; i<n; i++) if (d[i][k] != INF)
				for (int j=0; j<n; j++) if (d[k][j] != INF)
					d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);

		for (int i=0; i<n; i++) {
			if (d[i][i] < 0) {
				return null; // negative cycle
			}
		}

		return d;
	}


	static void solve() {
		int v = in.nextInt();
		int e = in.nextInt();
		int[] s = new int[e];
		int[] t = new int[e];
		int[] d = new int[e];
		for (int i=0; i<e; i++) {
			s[i] = in.nextInt();
			t[i] = in.nextInt();
			d[i] = in.nextInt();
		}
		int[][][] g = directedGraph(v, s, t, d);
		int[][] ans = floydWarshall(g);
		if (ans == null) {
			out.println("NEGATIVE CYCLE");
			return;
		}
		for (int i=0; i<v; i++) {
			for (int j=0; j<v-1; j++) {
				out.print((ans[i][j] == (1<<31)-1 ? "INF" : ans[i][j])+" ");
			}
			out.println(ans[i][v-1] == (1<<31)-1 ? "INF" : ans[i][v-1]);
		}
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 60164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k % 2 == 1){
    cout << b - a << endl;
  }
  else{
    cout << a - b << endl;
  }
}

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

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

E=dict()
O=dict()

for i in range(n):
    a=v[i]
    if i%2==0:
        if a in E:
            E[a]+=1
        else: 
            E[a]=1
    if i%2==1:
        if a in O:
            O[a]+=1
        else: 
            O[a]=1

ans=n-max(E.values())-max(O.values())

Emax=max(E.values())
Ekeys=[]
for k in E.keys():
    if E[k] == Emax: Ekeys.append(k)

Omax=max(O.values())
Okeys=[]
for k in O.keys():
    if O[k] == Omax: Okeys.append(k)

if len(Ekeys)==1 and Ekeys==Okeys:
    if ans==0:
        ans=int(n/2)
    else:
        E1=E.copy()
        del E1[Ekeys[0]]
        ans=n-max(E1.values())-max(O.values())

        O1=O.copy()
        del O1[Okeys[0]]
        ans1=n-max(E.values())-max(O1.values())

        if ans>ans1: ans=ans1




print(ans)

Measured memory_bytes: 22064
#include <bits/stdc++.h>
using namespace std;
 
const int INF= 1001001001;
vector<int> a;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
    long long n;
    cin >> n;
    long long ans = n - 1;
    for(int i = 2; i < (int)(sqrt(n) + 1); i++){
        if(n%i == 0){
            ans = min(i + n/i - 2, ans);
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>

typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN 200010
#define INF 1000000000

int a[MAXN];
int k, n;

int dist(int x, int y, bool dir) {
	if (dir) {
		if (y < x) {
			y += k;
		}
		return (k - y + x);
	} else {
		if (y > x) {
			x += k;
		}
		return (k - x + y);
	}
}

int solve(int pos) {
	int nnext = (pos + 1) % n;
	int pprev = (pos + n - 1) % n;
//	cout << nnext << " " << pprev << endl;
	int cur = min(dist(a[pos], a[nnext], true), dist(a[pos], a[pprev], false));
//	cout << cur << endl;
	return cur;
}

int main() {
	cin >> k >> n;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a[i] = t;
	}
	int ret = INF;
	for (int i = 0; i < n; i++) {
		ret = min(ret, solve(i));
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 4376
import bisect
n,m = map(int,input().split())
mod = 10**9+7

a = [int(input()) for i in range(m)]

#dp[i]:i段目に来る場合の数
dp = [0]*(n+1)
dp[0]=1
for i in range(1,n+1):
  k = bisect.bisect_left(a,i)
  k2 = bisect.bisect_right(a,i)
  if k == k2:
    dp[i] += dp[i-1]
    if i >= 2:
      dp[i] += dp[i-2]
    dp[i] = dp[i]%mod
print(dp[-1]%mod)


Measured memory_bytes: 7848
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();
		int C =sc.nextInt();
		int[][] ar=new int[C][100001];
		for(int i = 0; i<n; i++){
			int s = sc.nextInt()-1;
			int t = sc.nextInt()-1;
			int c = sc.nextInt()-1;
			for(int j=s; j<=t; j++){
				ar[c][j]=1;
			}
		}
		int ans=0;
		for(int i = 1; i<100001; i++){
			int max=0;
			for(int j = 0; j<C; j++){
				max+=ar[j][i];
			}
			ans=Math.max(ans,max);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 111156
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}


void func(void)
{
//DEBUG_OUT("----\n");
    int64 N, M;
    cin >> N >> M;

    int64 sum100 = (N-M)*pow(2, M) * 100;
    int64 sumM = M * pow(2, M) * 1900;

    int64 sum = sum100 + sumM;

    cout << sum << endl;
}



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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
	string s;
	int n = 0;
	char temp;

	cin >> s;
	temp = s[0];
	for (int i = 1; i < s.size(); i++)
	{
		if (s[i] != temp)
		{
			temp = s[i];
			n++;
		}
	}
	cout << n << endl;
}


Measured memory_bytes: 3816
n, k = input().split(' ')
n = int(n)
k = int(k)

if k == 1 or n == 0:
  print(0)
elif n < k :
  r1 = n
  r2 = n - k
  if r2 < 0:
    r2 *= -1
  print(min(r1,r2))
else:
  r1 = n % k
  r2 = r1 - k
  if r2 < 0:
    r2 *= -1
  print(min(r1,r2))

Measured memory_bytes: 3064
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<climits>
using namespace std;

int main(void)
{
	int N, K;
	cin >> N >> K;

	vector<int> h(N);
	for(int i=0; i<N; i++)
		cin >> h[i];

	vector<long long> dp(N, LLONG_MAX);
	dp[0] = 0;
	for(int i=0; i<N; i++){
		for(int j=1; j<=K; j++){
			if(i+j<N)
				dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
		}
	}

	cout << dp[N-1] << endl;

	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    vector<int> enqueued(n, 0);
    priority_queue<P> que; // val, index
    for (int i = 0; i < n; i++)
    {
        // a[i] < b[i] && a[i-1] + a[i+1] < b[i] - a[i]
        if (a[i] >= b[i])
            continue;
        ll sum = b[(i + 1) % n] + b[(i + n - 1) % n];
        if (sum <= b[i] - a[i])
        {
            que.push(P(b[i], i));
            enqueued[i] = 1;
        }
    }
    ll ret = 0;
    while (!que.empty())
    {
        auto p = que.top();
        que.pop();
        int i = p.second;
        enqueued[i] = 0;
        int nxt = (i + 1) % n, pre = (i + n - 1) % n;
        ll sum = b[nxt] + b[pre];
        ll cnt = (b[i] - a[i]) / sum;
        ret += cnt;
        b[i] -= cnt * sum;
        if (!enqueued[nxt])
        {
            int nxt2 = (i + 2) % n;
            sum = b[nxt2] + b[i];
            if (sum <= b[nxt] - a[nxt])
            {
                que.push(P(b[nxt], nxt));
                enqueued[nxt] = 1;
            }
        }
        if (!enqueued[pre])
        {
            int pre2 = (i + n - 2) % n;
            sum = b[pre2] + b[i];
            if (sum <= b[pre] - a[pre])
            {
                que.push(P(b[pre], pre));
                enqueued[pre] = 1;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (b[i] != a[i])
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 6388
N,A,B,C = map(int,(input().split()))
l = [int(input()) for i in range(N)]

def dfs(cur,a,b,c):
    if cur == N:
        if min(a,b,c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) -10*3 
        else:
            return 10**9
    c0 = dfs(cur+1,a,b,c)
    c1 = dfs(cur+1,a+l[cur],b,c) +10
    c2 = dfs(cur+1,a,b+l[cur],c) +10
    c3 = dfs(cur+1,a,b,c+l[cur]) +10
    return min(c0,c1,c2,c3)

print(dfs(0,0,0,0))

Measured memory_bytes: 43996
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int n , k ;
  int sum = 1;
  cin >> n >> k ;
  for(int i = 0; i < n; i++){
    if( sum < k){
      sum *= 2;
    }
    else{
      sum += k;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define NUM 1000000007 //10^9+7
#define ll long long int
int main(void){
	int i,j,n;
	ll ans=1;
	ll p[1001];
	for(i=0;i<1001;i++)p[i]=0;
	scanf("%d",&n);
	for(i=2;i<=n;i++){
		int k=i;
		for(j=2;j<=i;j++)//素因数分解
			while(k%j==0){
				p[j]++;
				k/=j;//ここで素数だけチェックできてる
			}
	}
	for(i=2;i<=n;i++)	ans=ans*(p[i]+1)%NUM;
	printf("%lld",ans);
	
	return 0;
}

Measured memory_bytes: 128
# abcde    s=input()    s='abcde'
# abcde    s=list(input())    s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)    a=int(input())    a=5
# 1 2    | x,y = s_inpl()   |    x=1,y=2
# 1 2 3 4 5 ... n 　    li = input().split()    li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　    li = inpl()    li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　    li = input().split('T')    li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
MAX_DIGIT = 50

############
############
############

N, M = l_inpl()

ans = 1

for k in range(1, int(M**0.5)+1):
    if k*N <= M:
        if M % k == 0:
            ans = max(ans, k)
            if k**2 == M:
                continue
            if (M//k)*N <= M:
                ans = max(ans, M//k)

print(ans)

Measured memory_bytes: 38768
#coding:utf-8
#1_10_B 2015.4.14

import math

a,b,C = map(int,input().split())
C = math.radians(C)
h = b * math.sin(C)
S = a * h / 2
L = a + b + math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(C))
print('{:.10f}\n{:.10f}\n{:.10f}'.format(S,L,h))

Measured memory_bytes: 6868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct base
{
    ll c[65];
    bool insert(ll x)
    {
        for(int i=62;i>=0;i--)
            if(x&(1ll<<i))
                if(!c[i]){c[i]=x;return 1;}
                else x^=c[i];
        return 0;
    }
}b;
string str;
ll a[205];
int main()
{
    int _;
    scanf("%d",&_);
    while(_--)
    {
        memset(b.c,0,sizeof(b.c));
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
        cin>>str;
        for(int i=n;i>=1;i--)
        {
            if(str[i-1]=='0')b.insert(a[i]);
            else if(b.insert(a[i])){puts("1");goto nxt;}
        }
        puts("0");
        nxt:;
    }
    return 0;
}

Measured memory_bytes: 3644
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

#define INF 100000000


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < c && c < b) {
		cout << "Yes" << endl;
		return 0;
	}
	else if (b < c && c < a) {
		cout << "Yes" << endl;
		return 0;
	}
	else cout << "No" << endl;
	return 0;
}

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

int		main(void)
{
	char	s[3];

	cin >> s[0] >> s[1] >> s[2];
	
	if (s[0] == s[1] && s[1] == s[2])
		cout << "No";
	else
		cout << "Yes";
}


Measured memory_bytes: 256