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

int score(const vector<vector<int>> &c, const vector<int> &t, int d)
{
  int weight[26];
  for (int k = 0; k < 26; k++)
  {
    weight[k] = 1;
  }

  int sum(0);
  for (int i = 0; i < d; i++)
  {
    int j = t[i] - 1;
    sum += c[i + 1][j];
    int penalty = 0;
    for (int k = 0; k < 26; k++)
    {
      if (j != k)
      {
        penalty += c[0][k] * weight[k];
        weight[k]++;
      }
      else
      {
        weight[k] = 1;
      }
    }
    sum -= penalty;
  }
  return sum;
}

int main()
{
  int d;
  cin >> d;
  vector<vector<int>> c;
  int weight[26];
  for (int k = 0; k < 26; k++)
  {
    weight[k] = 1;
  }
  for (int i = 0; i < d + 1; i++)
  {
    c.push_back(vector<int>());

    for (int j = 0; j < 26; j++)
    {
      int v;
      cin >> v;
      c[i].push_back(v);
    }
  }

  int max_sum(0);
  std::vector<int> max_js;
  int sum(0);
  for (int i = 0; i < d; i++)
  {
    int max_j = 0;
    int max_score = INT_MIN;

    for (int j = 0; j < 26; j++)
    {
      int score = c[i + 1][j];
      for (int k = 0; k < 26; k++)
      {
        if (j != k)
        {
          score -= c[0][k] * weight[k];
        }
      }
      if (max_score < score)
      {
        max_score = score;
        max_j = j;
      }
    }
    sum += max_score;
    for (int j = 0; j < 26; j++)
    {
      if (j != max_j)
      {
        weight[j]++;
      }
      else
      {
        weight[j] = 1;
      }
    }
    max_js.push_back(max_j);
  }

  max_sum = sum;
  vector<int> js;
  std::copy(max_js.begin(), max_js.end(), std::back_inserter(js));
  for (int t = 0; t < 1000; t++)
  {
    auto d_s = rand() % d;
    auto d_k = rand() % 26;
    js[d_s] = d_k;
    int sum = score(c, js, d);
    if (max_sum < sum)
    {
      for (auto j = 0; j < max_js.size(); j++)
      {
        max_js[j] = js[j];
      }
      max_sum = sum;
    }
  }
  for (auto j : js)
  {
    std::cout << j + 1 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstdlib>
#include<queue>
#include<map>
using namespace std;
long long v,s,t;
int main(){
	cin>>s>>t>>v;
	double time=(double)s*1.0/v;
	if(time<=t){
		cout<<"Yes";
		return 0;
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3628
n,m=map(int,input().split())

ac=(n-m)*100
tle=m*1900
time=0
cnt=1
time_ac=(ac+tle)*(1/2)**m
fault=(1-(1/2)**m)
while True:
    temp=cnt*time_ac*(fault**(cnt-1))
    if time==time+temp:
        print(round(time))
        break
    time+=temp
    cnt+=1


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		// 105
		// 135
		// 165
		// 189
		// 195
if(n>=195){
	System.out.println(5);
}else if(n>=189){
	System.out.println(4);
}else if(n>=165){
	System.out.println(3);
}else if(n>=135){
	System.out.println(2);
}else if(n>=105){
	System.out.println(1);
}else{
	System.out.println(0);
}

	}}

Measured memory_bytes: 21844
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int l=0, r=0, fstr=0;
    bool fst=false;
    rep(i,N){
        if(fst==false && S[i]=='('){
            fst=true;
        }
        if(S[i]=='('){
            if(r>0){
                fstr+=r;
                r=0;
            }
            l++;
        }
        if(S[i]==')'){
            if(fst==false){
                fstr++;
            }else{
                r++;
            }
        }
        if(l>0 && r>0){
            l--, r--;
        }
    }
    rep(i, r+fstr) cout << "(";
    cout << S;
    rep(i, l) cout << ")";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 3e5 + 5, mod = 1e9 + 7;

int kamr[N], kamc[N];
set<int> vr[N], vc[N];
vector<int> v;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, m, x;
    cin >> n >> m >> x;
    int mxr = 0, mxc = 0;
    while(x--){
        int r, c;
        cin >> r >> c;
        kamr[r]++;
        mxr = max(mxr, kamr[r]);
        kamc[c]++;
        mxc = max(mxc, kamc[c]);
        vr[r].insert(c);
        vc[c].insert(r);
    }
    for(int i = 1; i <= m; i++){
        if(kamc[i] == mxc){
            v.push_back(i);
        }
    }
    int ans = mxr + mxc - 1;
    bool found = 0;
    for(int i = 1; i <= n && !found; i++){
        if(kamr[i] == mxr){
            for(auto j: v){
                if(vr[i].find(j) == vr[i].end() || vc[j].find(i) == vc[j].end()){
                    found = 1;
                    break;
                }
            }
        }
    }
    cout << ans + found;


    return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 + 47;
char A[MAX][MAX];

void fill(int n, int m, int& a, int& b)
{
	FOR(i, 0, n)
	{
		FOR(j, 0, m)
		{
			if (a)
			{
				if (i + 1 != n && A[i][j] == '.' && A[i + 1][j] == '.')
				{
					a--;
					A[i][j] = '^';
					A[i + 1][j] = 'v';
				}

				continue;
			}

			if (b)
			{
				if (j + 1 != m && A[i][j] == '.' && A[i][j + 1] == '.')
				{
					b--;
					A[i][j] = '<';
					A[i][j + 1] = '>';
				}
			}
		}
	}
}

void fillHor(int n, int m, int& b)
{
	FOR(j, 0, m)
	{
		if (!b) return;

		if (A[n - 1][j] == '.' && A[n - 1][j + 1] == '.')
		{
			A[n - 1][j] = '<';
			A[n - 1][j + 1] = '>';
			b--;
		}
	}
}

void fillVer(int n, int m, int& a)
{
	FOR(i, 0, n)
	{
		if (!a) return;

		if (A[i][m - 1] == '.' && A[i + 1][m - 1] == '.')
		{
			A[i][m - 1] = '^';
			A[i + 1][m - 1] = 'v';
			a--;
		}
	}
}

//bool decreaseFirst(int n, int m, int a, int b)
//{
//	a -= (n - 3) / 2;
//	if (a < 0) a = 0;
//	b -= (m - 3) / 2;
//	if (b < 0) b = 0;
//
//	return (a *(LL) b) % 2;
//}

bool isException(int n, int m, int a, int b)
{
	a -= n / 2;
	if (a < 0) a = 0;
	b -= m / 2;
	if (b < 0) b = 0;

	return b % 2 != 0 && a % 2 != 0;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
	int n, m, a, b;
	cin >> n >> m >> b >> a;

	//if ((a % 2) ^ (b % 2) == 0) throw -1;
	//if (n % 2 && m % 2) throw -1;
	FOR(i, 0, n)
	{
		FOR(j, 0, m) A[i][j] = '.';
	}

	if (a && b && n % 2 && m % 2 && n >= 3 && m >= 3)
	{
//		if (decreaseFirst(n, m, a, b))
//		{
//			A[n - 1][m - 1] = 'v';
//			A[n - 2][m - 1] = '^';
//			a--;
//			A[n - 1][m - 2] = '>';
//			A[n - 1][m - 3] = '<';
//			b--;
//		}
//		else

		if (isException(n, m, a, b))
		{
			if (a)
			{
				A[n - 1][m - 1] = 'v';
				A[n - 2][m - 1] = '^';
				a--;
			}

			if (a)
			{
				A[n - 2][m - 3] = 'v';
				A[n - 3][m - 3] = '^';
				a--;
			}

			if (b)
			{
				A[n - 1][m - 3] = '<';
				A[n - 1][m - 2] = '>';
				b--;
			}

			if (b)
			{
				A[n - 3][m - 2] = '<';
				A[n - 3][m - 1] = '>';
				b--;
			}
		}
	}

	if (m % 2) fillVer(n, m, a);
	if (n % 2) fillHor(n, m, b);
	fill(n, m, a, b);

	if (a || b)
	{
//		FOR(i, 0, n)
//		{
//			FOR(j, 0, m) cout << A[i][j];
//
//			cout << "\n";
//		}
		cout << "NO\n";
		return 0;
	}

	cout << "YES\n";
	FOR(i, 0, n)
	{
		FOR(j, 0, m) cout << A[i][j];

		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int main(){
	while(true){
		int N,T,L,B;
		cin>>N>>T>>L>>B;
		bool l[101]={},b[101]={};
		if(N==0) break;
		rep(i,L){
			int x;
			cin>>x;
			l[x]=true;
		}
		rep(i,B){
			int x;
			cin>>x;
			b[x]=true;
		}
		double dp[102][101]={};
		dp[0][0]=1;
		rep(i,T){
			rep(j,N){
				rep1(k,6){
					int nxt=j+k;
					if(nxt>N) nxt=N*2-nxt;
					if(l[nxt]){
						dp[i+2][nxt]+=dp[i][j]/6;
					}else if(b[nxt]){
						dp[i+1][0]+=dp[i][j]/6;
					}else{
						dp[i+1][nxt]+=dp[i][j]/6;
					}
				}
			}
			dp[i+1][N]+=dp[i][N];
		}
		printf("%.12f\n",dp[T][N]);
	}
}

Measured memory_bytes: 1272
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

const int maxn = 1e5+100;

int n,k;
int a[maxn];

int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
		sort(a+1,a+1+n);
	int sum =0 ;
	for(int i=1;i<=k;i++) sum+=a[i];
		cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3596
#include<set>
#include<iostream>
using namespace std;
int	main(){

	/*int W;
	cin >> W;
	cout << 32*W << endl;*/

	/*int H,R;
	cin >> H >> R;

	if(H + R == 0){
		cout << "0" << endl;
	}

	else if(H + R > 0){
		cout << "1" << endl;
	}

	else {
		cout << "-1" << endl;
	}*/

	int E, Y;
	cin >> E >> Y;

	if(E == 0){
		if(Y <= 1911){
			cout << "M" << Y - 1867 << endl;
		}
		else if(Y <= 1925){
			cout << "T" << Y - 1911 << endl;
		}
		else if(Y <= 1988){
			cout <<"S" << Y -1925 << endl;
		}
		else{
			cout << "H" << Y- 1988 << endl;
		}


	}

	if(E == 1){
		cout << 1867 + Y << endl;
	}
	else if(E == 2){
		cout << 1911 +Y << endl;
	}
	else if(E == 3){
		cout << 1925 +Y << endl;
	}
	else if(E == 4){
		cout << 1988 +Y << endl;
	}

	return 0;
}


Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U> bool chmax(T &a, U b) { if (a <= b) {a = b; return 1;} return 0; }
template <class T, class U>  bool chmin(T &a, U b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T>  ostream &operator<<(ostream &os, vector<T> &v) { os << "{"; rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); } os << "}"; return os; }

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
    ll a,b,x,z=0,n,h,m,ans=0,sum=0,k,w,Max=-1,Min=1e9+1;
    bool ok = true;
    string s,t,u;
    cin >> a >> b >> x;
    n = b / x;
    m = a / x;
    if(a%x==0)
      pri(n - m +1);
    else
      pri(n - m);
    return 0;
}


Measured memory_bytes: 256
package main

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

func scanInput() (n int, nums []int) {
    //// NG
    //fmt.Scanf("%d", &n)
    //nums = make([]int, n)
    //for i := 0; i < n; i++ {
    //    fmt.Scanf("%d", &nums[i])
    //}

    // OK
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    scanner.Scan()
    n, _ = strconv.Atoi(scanner.Text())
    nums = make([]int, n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        nums[i], _ = strconv.Atoi(scanner.Text())
    }
    return
}

func maxHeapify(nums *[]int, length int, previousMax int) {
    parent := previousMax - 1
    left := 2*previousMax - 1
    right := 2*previousMax + 1 - 1

    if left > length-1 {
        return
    }

    largest := parent
    if left < length && (*nums)[parent] < (*nums)[left] {
        largest = left
    }
    if right < length && (*nums)[largest] < (*nums)[right] {
        largest = right
    }

    if largest != parent {
        (*nums)[largest], (*nums)[parent] = (*nums)[parent], (*nums)[largest]
        maxHeapify(nums, length, largest+1)
    }
}

func main() {
    length, nums := scanInput()

    for i := length / 2; i >= 1; i-- {
        maxHeapify(&nums, length, i)
    }
    for _, v := range nums {
        fmt.Printf(" %d", v)
    }
    fmt.Println("")
}



Measured memory_bytes: 10016
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t h, w;
    cin >> h >> w;

    if (w == 1 || h == 1) {
        cout << 1 << endl;
        return 0;
    }

    cout << /* even row */ ((h + 1) / 2) * ((w + 1) / 2) +
                    /* odd row */ ((h / 2) * (w / 2))
         << endl;
}

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

int main(){
    int X,Y;
    cin >> X >> Y;
    string ans = "No";

    for(int a = 0; a <= X; a++){
        int b = X - a;
        if(2*a + 4*b == Y) ans = "Yes";
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

// a^n
template<class T=int64_t>
T bin_pow(T a,T n,T mod=1e9+7){
    T ans=1;
    while(n>0){
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans%mod;
}

template<class T=int64_t>
T inv_mod(T a,T mod=1e9+7){
  return bin_pow(a,mod-2);
}

//a!
template<class T=int64_t>
T fact(T a,T mod=1e9+7){
    T ans=1;
    for(int i=2;i<=a;++i){
        ans=ans*i%mod;
    }
    return ans;
}

//nCr
template<class T=int64_t>
T comb(T n,T r,T mod=1e9+7){
    return fact(n)*inv_mod(fact(r)*fact(n-r)%mod)%mod;
}

int main()
{
  int64_t x,y;
  cin>>x>>y;
  double a=(2*y-x)/3.0,b=(2*x-y)/3.0;
  if(a<0 || b<0 || (x+y)%3!=0 )
  {
    cout<<0<<endl;
    return 0;
  }
  int64_t n=(int64_t)a,m=(int64_t)b;
  cout<<comb((n+m),n);
}

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

N=int(input())
A=factorization(N)
B=len(A)
k=0

for i in range(B):
    a=1
    while A[i][1]>=a*(a+1)/2:
        a+=1
    k=k+a-1
if N==1:
    print(0)
else:
    print(k)

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

int main(){
	int a[5];
	int ans = 0;
	for(int i = 0; i < 5; ++i){
		cin >> a[i];
		if(a[i] == 0) ans = i + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;


int main(){
  int n;cin>>n;
  vector<int> h(n);
  int mx=0,ans=0;
  rep(i,n){
    cin>>h[i];
    if(mx<=h[i]){
      ans ++;
      mx = max(mx,h[i]);
  }
  }
  cout << ans;
}




Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
a = [-1] + a
count = 0

for i in range(N//2, 0, -1):
    d = N//i
    for j in range(2,d+1):
        count += a[i*j]
    if a[i] % 2 != count % 2:
        a[i] = 1
    else:
        a[i] = 0
    count = 0
print(sum(a)+1)
for i in range(1,N+1):
    if a[i] == 1:
        print(i, end=' ')


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

int main() {
  string  S, T;
  cin  >> S >> T;

  int ans = 0;
  for (int i=0; i < S.size(); i++){
  	if (S.at(i) != T.at(i))
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3912
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define REP(i,n)    for(int i = 0; i < (int)n; i++)
#define MAX_N   100000
#define MAX_M   100000


void solve(){
    int r;
    cin >> r;
    cout << r * r << endl;
}

int main(){
    solve();
    return 0;
}

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

using namespace std;

int main() {

    string p;
    int next[6][2];

    memset(next, -1, sizeof(next));

    next[0][0] = 1;
    next[0][1] = 5;

    next[1][1] = 2;

    next[2][0] = 4;
    next[2][1] = 3;

    next[3][0] = 5;
    next[3][1] = 1;

    next[4][0] = 3;
    next[4][1] = 5;

    next[5][0] = 1;

    while(cin >> p, p != "#") {

        int now = 0;

        for(int i = 0; i < p.size(); ++i) {
            if(p[i] == '0') {
                now = next[now][0];
            } else {
                now = next[now][1];
            }
            if(now == -1) {
                break;
            }
        }

        if(now == 3) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define N 200010
using namespace std;
vector<int> book[N];
int main(){
	int n,m,i,a,b;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>a>>b;
		book[a-1].push_back(b-1);
	}
	for(i=0;i<book[0].size();i++)
	{
		if(find(book[book[0][i]].begin(),book[book[0][i]].end(),n-1)!=book[book[0][i]].end())
		{
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

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

int main(){
string ary[3]={"Sunny","Cloudy","Rainy"};
string S;
cin >>S;
if(S==ary[0]) cout <<ary[1];
else if(S==ary[1]) cout <<ary[2];
else  cout <<ary[0];

return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n, x;
    cin >> n >> x;

    vector<li> bs(n), ls(n), us(n);
    for (int i = 0; i < n; ++i) {
        cin >> bs[i] >> ls[i] >> us[i];
    }

    li v = 0;
    li ans = 0;
    vector<pair<li, li>> ubis(n);
    vector<li> ubs(n);
    for (int i = 0; i < n; ++i) {
        v += bs[i] * ls[i];
        ans += bs[i];
        ubis[i] = make_pair(bs[i] * ls[i] + (x - bs[i]) * us[i], i);
        ubs[i] = ubis[i].first;
    }
    sort(ubis.rbegin(), ubis.rend());

    li acc = 0;
    set<li> used;
    li next;
    for (int i = 0; i < n; ++i) {
        li nacc = acc + ubis[i].first;
        if (nacc >= v) {
            next = ubis[i].second;
            break;
        }
        acc = nacc;
        used.insert(ubis[i].second);
    }

    for (int i = 0; i < n; ++i) {
        li target;
        li cost = x * used.size();
        if (used.find(i) != used.end()) {
            target = v - (acc - ubs[i] + ubs[next]);
        } else {
            target = v - acc;
        }

        if (target > ubs[i]) {
            continue;
        } else if (target > bs[i] * ls[i]) {
            li rem_target = target - bs[i] * ls[i];
            cost += bs[i] + (rem_target + us[i] - 1) / us[i];
        } else if (target > 0) {
            cost += (target + ls[i] - 1) / ls[i];
        }
        ans = min(ans, cost);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9600
import sys
sys.setrecursionlimit(2147483647)

h,w=map(int,input().split())

#change[i][j]はiをjに変えるコスト
change=[list(map(int, input().split())) for i in range(10)]
test_case=[list(map(int, input().split())) for i in range(h)]
cost=[0]*10

for i in range(10):
    cost[i]=change[i][1]
#print(cost)
def DEF(start,backed,weight,non_used):
    global cost,change
    #print(backed,non_used)
    if non_used==[]:
        return 0

    for item in non_used:
        if weight+change[backed][item]+change[item][1]<cost[start]:
            cost[start]=weight+change[backed][item]+change[item][1]
        if weight+change[backed][item]<cost[start]:
            non_used2=[]
            for t in non_used:
                if t!=item:
                    non_used2.append(t)

            DEF(start,item,weight+change[backed][item],non_used2)

for item in range(10):
    if item!=1:

        temp=[]
        for i in range(10):
            if item!=i and i!=1:
                temp.append(i)
        #print("######",item,temp)
        DEF(item,item,0,temp)

result=0
for item in test_case:
    for item2 in item:
        if item2!=1 and item2!=-1:
            result+=cost[item2]

print(result)













Measured memory_bytes: 42076
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<pll,vector<pll>,greater<pll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
struct edge{ll to,cost;};
int main(){
  ll n,m,s,t;
  cin>>n>>m>>s>>t;
  s--;t--;
  vector<vector<edge>> at(n,vector<edge>(0));
  vector<vector<edge>> bt(n,vector<edge>(0));
  rep(i,m){
    ll u,v,a,b;
    cin>>u>>v>>a>>b;
    u--;v--;
    edge e;
    e.to=v;
    e.cost=a;
    at[u].pb(e);
    e.to=u;
    at[v].pb(e);
    e.cost=b;
    bt[v].pb(e);
    e.to=v;
    bt[u].pb(e);
  }
  PQR que;
  vll ad(n,INF);
  vll bd(n,INF);
  que.pu(pll(0,s));
  ad[s]=0;
  while(sz(que)){
    pll now=que.top();que.pop();
    ll v=now.S;
    if(ad[v]<now.F) continue;
    rep(i,sz(at[v])){
      edge e=at[v][i];
      if(ad[e.to]>ad[v]+e.cost){
        ad[e.to]=ad[v]+e.cost;
        que.pu(pll(ad[e.to],e.to));
      }
    }
  }
  que.pu(pll(0,t));
  bd[t]=0;
  while(sz(que)){
    pll now=que.top();que.pop();
    ll v=now.S;
    if(bd[v]<now.F) continue;
    rep(i,sz(bt[v])){
      edge e=bt[v][i];
      if(bd[e.to]>bd[v]+e.cost){
        bd[e.to]=bd[v]+e.cost;
        que.pu(pll(bd[e.to],e.to));
      }
    }
  }
  vector<pll> ab(n);
  rep(i,n){
    ab[i].F=ad[i]+bd[i];
    ab[i].S=i+1;
  }
  sort(all(ab));
  vector<pll> ans(0);
  ll cu=-1;
  rep(i,n){
    if(cu<ab[i].S){
      ans.pb(ab[i]);
      cu=ab[i].S;
    }
  }
  ll ccu=0;
  ll k=0;
  while(ccu<n){
    if(ccu==ans[k].S)k++;
    ll j=1e15;
    COUT(j-ans[k].F);
    ccu++;
  }
}


Measured memory_bytes: 22560
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define int long long
using namespace std;
map<int,int> mope;
signed main(){
	int n,ma,mb;
	vector<int> a,b,c;
	cin>>n>>ma>>mb;
	for(int i=0;i<n;i++){
		int ta,tb,tc;
		cin>>ta>>tb>>tc;
		a.pb(ta);b.pb(tb);c.pb(tc);
	}
	for(int i=-10000;i<=10000;i++){
		mope[i]=inf;
	}
	for(int i=n;i<40;i++){
		a.pb(0);b.pb(0);c.pb(0);
	}
	for(int i=1;i<(1<<20);i++){
		int cur = i;
		int as=0,bs=0,cs=0;
		for(int j=0;j<20;j++){
			if(cur%2==1){
				as += a[20+j];
				bs += b[20+j];
				cs += c[20+j];
			}
			cur = cur/2;
		}
		int vl = mb * as - ma * bs;
		if(mope[vl]>cs){ mope[vl]=cs; }
	}
	int ans=inf;
	for(int i=0;i<(1<<20);i++){
		int cur = i;
		int as=0,bs=0,cs=0;
		for(int j=0;j<20;j++){
			if(cur%2==1){
				as += a[j];
				bs += b[j];
				cs += c[j];
			}
			cur = cur/2;
		}
		int vl = ma * bs - mb * as;
		if( (cs>0 || mope[vl]>0) && mope[vl]+cs<ans)ans=mope[vl]+cs;
	}
	for(int i=1;i<(1<<min(n,(ll)20));i++){
		int cur = i;
		int as=0,bs=0,cs=0;
		for(int j=0;j<20;j++){
			if(cur%2==1){
				as += a[j];
				bs += b[j];
				cs += c[j];
			}
			cur = cur/2;
		}
		int vl = ma * bs - mb * as;
		if(vl==0 && ans>cs)ans=cs;
	}
	for(int i=1;i<(1<<min(max((ll)0,n-20),(ll)20));i++){
		int cur = i;
		int as=0,bs=0,cs=0;
		for(int j=0;j<20;j++){
			if(cur%2==1){
				as += a[j+20];
				bs += b[j+20];
				cs += c[j+20];
			}
			cur = cur/2;
		}
		int vl = ma * bs - mb * as;
		if(vl==0 && ans>cs)ans=cs;
	}
	if(ans == inf)ans=-1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1536
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
 
public class Main {
	static Scanner in;
	static char s[];
	public static void main(String[] args) throws FileNotFoundException {
//		in = new Scanner(new File("input.txt"));
		in = new Scanner(System.in);
		s = in.next().toCharArray();
		for(int i = 0;i < s.length;i++){
			if(i == 4) System.out.print(" ");
			System.out.print(s[i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 10188
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
char buf[20000];sz;
inline int rd()
{
	int ret=buf[sz++]-'0';
	if(buf[sz]>='0')
	{
		ret=ret*10+buf[sz++]-'0';
		if(buf[sz]>='0')
		{
			ret=ret*10+buf[sz++]-'0';
			if(buf[sz]>='0')
			{
				ret=ret*10+buf[sz++]-'0';
				if(buf[sz]>='0')
				{
					ret=ret*10+buf[sz++]-'0';
				}
			}
		}
	}
	sz++;
	return ret;
}
int d[3001],d2[3001];
const int mod=998244353;
main()
{
	read(0,buf,20000);
	int N=rd();
	int S=rd();
	int ans=0;
	for(int i=1;i<=N;i++)
	{
		d[S]=i;
		int A=rd();
		if(S>=A)
        {
			memcpy(d2+A,d+A,(S-A+1)*4);
			for(int j=0;j<=S-A;j++)
			{
				d[j]+=d2[j+A];
				d[j]-=mod*(d[j]>=mod);
			}
        }
		ans+=d[0];
		ans-=mod*(ans>=mod);
	}
	printf("%d",ans);
}

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

xyh = [[0, 0, 0] for i in range(N)]

for i in range(N):
    x, y, h = input().split(' ')
    xyh[i][0] = int(x)
    xyh[i][1] = int(y)
    xyh[i][2] = int(h)

finish = False
for cx in range(101):
    for cy in range(101):
        top = 0
        for x, y, h in xyh:
            if h != 0:
                top = abs(x-cx)+abs(y-cy)+h
        for x, y, h in xyh:
            finish = True
            if max(top - abs(x-cx)-abs(y-cy), 0) != h:
                finish = False
                break
        if finish == True:
            print ('{} {} {}'.format(cx, cy, top))
            exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int x,y;
    cin>>x>>y;
    for (int i = 0; i <= x; i++)
    {
        if(2*x+2*i == y)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define watch(x) cout << #x << " is " << x << endl
#define print(a, l, r) \
    for (int i = l; i < r; i++) cout << a[i] << (i == (r - 1) ? endl : " ");
const ll M = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int c = 0;
    int ans = 0;
    string s;
    cin >> s;
    int n = s.size();

    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            c++;
        } else {
            ans = max(ans, c);
            c = 0;
        }
    }
    if (c != 0) {
        ans = max(ans, c);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_int
  gets.chomp.to_i
end

A, B, C, K = get_ints

max = -1
if A >= K
  max = K
else
  if A + B >= K
    max = A
  elsif (K - A - B) > C
    max = A - C
  else
    max = A - (K - A - B)
  end
end

puts max


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

int main(){
  int n,k;cin>>n>>k;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  
  rep(j,k){
    vector<int>b(n,0);
    rep(i,n){
      int l=max(0,i-a[i]);
      int r=min(n-1,i+a[i]);
      b[l]++;
      if(r<n-1)b[r+1]--;
    }
    bool judge=1;
    rep(i,n){
      if(i>0)b[i]+=b[i-1];
      a[i]=b[i];
      if(b[i]!=n)judge=0;
    }
    if(judge)break;
  }
  rep(i,n)cout<<a[i]<<" ";  
}

Measured memory_bytes: 4840
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;
int main(){
	int N,point=0,ansplace,max=-10000,ans=0;
	cin>>N;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='W'){
			point--;
		}else{
			point++;
		}
		if(point>max){
			ansplace=i;
			max=point;
		}
	}
	if(ansplace==0){
		for(int i=ansplace+1;i<N;i++){
			if(s[i]=='E'){
				ans++;
			}
		}
	}else if(ansplace==s.size()-1){
		for(int i=ansplace-1;i>=0;i--){
			if(s[i]=='W'){
				ans++;
			}
		}
	}else{
		for(int i=ansplace+1;i<N;i++){
			if(s[i]=='E'){
				ans++;
			}
		}
		for(int i=ansplace-1;i>=0;i--){
			if(s[i]=='W'){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
n=I()
Bs=LI()
ans=Bs[0]+Bs[n-2]
for i in range(1,n-1):
    ans+=min(Bs[i],Bs[i-1])
print(ans)

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

using namespace std;

const int max_n = 2022, inf = 1000111222;

int n, m, cnt[max_n][max_n];
char s[max_n][max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) {
        scanf("%s", s[i]);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ) {
            if (s[i][j] == '.') {
                int l = j;
                while (j < m && s[i][j] == '.') {
                    ++j;
                }
                for (int pos = l; pos < j; ++pos) {
                    cnt[i][pos] += j - l;
                }
            } else {
                ++j;
            }
        }
    }
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ) {
            if (s[j][i] == '.') {
                int l = j;
                while (j < n && s[j][i] == '.') {
                    ++j;
                }
                for (int pos = l; pos < j; ++pos) {
                    cnt[pos][i] += j - l;
                }
            } else {
                ++j;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            ans = max(ans, cnt[i][j] - 1);
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 20096
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>

#define fs first
#define sc second
#define mp make_pair
#define pii pair<int,int>

using namespace std;

int n, a, b, vis[100005], ctr[10];
vector <int> v[100005];
queue <pii> q;

int main() {
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	q.push(mp(1, 1));
	q.push(mp(n, 2));
	vis[1] = vis[n] = 1;
	ctr[1] = 1;
	ctr[2] = 1;
	while(q.size()) {
		int skrg, idx;
		skrg = q.front().fs;
		idx = q.front().sc;
		q.pop();
		for(int i = 0; i < v[skrg].size(); i++) {
			if(vis[v[skrg][i]] == 0) {
				vis[v[skrg][i]] = 1;
				ctr[idx]++;
				q.push(mp(v[skrg][i], idx));
			}
		}
	}
	printf(ctr[1] <= ctr[2] ? "Snuke\n" : "Fennec\n");
	return 0;
}

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

const long long INF = 1e9+7;

int main() {
	int n;
	cin >> n;
	vector<bitset<60>> a(n);
	for(int i=0; i<n; i++){
		long tmp;
		cin >> tmp;
		bitset<60> data(tmp);
        a.at(i) = data;
	}
	long long ans;
	vector<long> num(60);
	for(int i=0; i<60; i++){
		int tmp=0;
		for(int j=0; j<n; j++){
			if(a.at(j).test(i)) tmp++;
		}
		num.at(i) = tmp;
	}
	for(int i=0; i<60; i++){
		long long mul1 = num.at(i)*(n-num.at(i))%INF;
		long long mul2 = (long long)pow(2, i) %INF;
		ans += mul1*mul2;
        ans %= INF;
	}
    cout << ans << endl;
}




Measured memory_bytes: 2560
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N, tk, ao;
    scan(N, tk, ao);
    tk--, ao--;
    auto adj = new int[][](N, 0);
    foreach (i ; 0 .. N - 1) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= bi;
        adj[bi] ~= ai;
    }

    auto par = new int[](N);
    par[] = -1;

    auto height = new int[](N);
    height[] = -1;

    auto depth = new int[](N);
    depth[] = -1;

    void dfs(int v, int p, int dep) {
        par[v] = p;
        depth[v] = dep;
        foreach (u ; adj[v]) if (u != p) {
            dfs(u, v, dep + 1);
            chmax(height[v], height[u]);
        }
        height[v] += 1;
    }

    dfs(ao, -1, 0);

    debug {
        writeln(par);
        writeln(depth);
        writeln(height);
    }

    int pos = tk;
    int upc = (depth[tk] + 1) / 2 - 1;
    int ans = upc;
    while (upc--) {
        pos = par[pos];
    }
    ans += height[pos] + (depth[tk] % 2 == 0);
    writeln(ans);
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

/*
   AtCoder contest code
   coder : yoichidon
 */

public class Main {
    public static String longer(String x, String y){
        if(x.length() > y.length()) return x;
        else return y;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();

        int A = S.length();
        int B = T.length();

        int[][] dp = new int[A+1][B+1];
        for(int a=0; a<=A; a++) dp[a][0]=0;
        for(int b=0; b<=B; b++) dp[0][b]=0;

        for(int a=1;a<=A;a++) for(int b=1;b<=B;b++){
            dp[a][b] = Math.max(dp[a-1][b], dp[a][b-1]);
            if(S.charAt(a-1)==T.charAt(b-1)) dp[a][b] = 1 + dp[a-1][b-1];
        }


        String ans = "";
        int a=A, b=B;
        while(a>0 && b>0){
            if(S.charAt(a-1)==T.charAt(b-1)){
                ans = S.charAt(a-1)+ans;
                a--;
                b--;
            }
            else if(dp[a-1][b]>dp[a][b-1]) a--;
            else b--;
        }
        System.out.println(ans);


    }
}


Measured memory_bytes: 87100
#include<bits/stdc++.h>
using namespace std;
const int N=2e5;
int f[N+10];
int sz[N+10];
int find(int x){
	return x==f[x]?x:f[x]=find(f[x]);
}
int merge(int u,int v){
	int uf=find(u);
	int vf=find(v);
	if(uf!=vf){
		sz[uf]+=sz[vf];
		sz[vf]=0;
		f[vf]=uf;
	}
	return sz[uf];
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)f[i]=i,sz[i]=1;
	int ans=0;
	while(m--){
		int a,b;
		cin>>a>>b;
		ans=max(ans,merge(a,b));
	}
	ans=*max_element(sz+1,sz+1+n);
	cout<<ans;
}

Measured memory_bytes: 5164
import sys
import heapq

# 自前の実装だと時間超過になったので、標準ライブラリの heapq を使う。

h = []
while True:
    command, *key = sys.stdin.readline().split()
    if command[0] == 'i': # insert k
        heapq.heappush(h, -int(key[0]))
    elif command[1] == 'x':   # extract
        print(-heapq.heappop(h))
    else:   # end
        break


Measured memory_bytes: 45572
function Main(input) {
	var lines = input.split("\n");
	var s = lines.splice(1, lines.length)
	var s_sorted = s.sort((a, b) => a > b ? 1 : -1)
	console.log(s_sorted.join(''))
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7628
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    private void run() {
        int n = sc.nextInt();
        char[] c = sc.next().toCharArray();

        for (int i = 0; i < c.length; i++) {
            int d  = (int)c[i] + n;
            if (d > 'Z') d -= 26;
            System.out.print(Character.toChars(d));
        }
    }
}



Measured memory_bytes: 24404
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))

A = list(map(lambda x:x*(-1), A))
heapq.heapify(A)

for _ in range(M):
    max = heapq.heappop(A)*(-1)
    heapq.heappush(A, (max // 2) * -1)

print(sum(A) * -1)




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

int main() {
    int K,N;
    cin >> K >> N;
    int A[N];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    int ans = A[0]+K-A[N-1];
    for(int i=0;i<N-1;i++){
        int dx=A[i+1]-A[i];
        ans=max(ans,dx);
    }
    cout << K- ans <<endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[202020];
ll S[202020];
int L[202020],R[202020];

ll hoge(int a,int b,int c,int d) {
	if(b<=a || c<=b || d<=c) return 1LL<<60;
	vector<ll> V={S[a],S[b]-S[a],S[c]-S[b],S[d]-S[c]};
	sort(ALL(V));
	//cout<<a<<" "<<b<<" "<<c<<" "<<d<<"   "<<V[0]<<" "<<V[1]<<" "<<V[2]<<" "<<V[3]<<endl;
	return V[3]-V[0];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i], S[i+1]=S[i]+A[i];
	
	L[2]=1;
	for(i=3;i<=N;i++) {
		L[i]=L[i-1];
		while(L[i]+1<i && S[L[i]+1]<=S[i]-S[L[i]+1]) L[i]++;
	}
	
	R[N-2]=N-1;
	for(i=N-3;i>=1;i--) {
		R[i]=R[i+1];
		while(R[i]-1>i && S[R[i]-1]-S[i]>=S[N]-S[R[i]-1]) R[i]--;
	}
	
	ll ret=1LL<<60;
	for(i=2;i<=N-2;i++) {
		ret=min(ret,hoge(L[i],i,R[i],N));
		ret=min(ret,hoge(L[i]+1,i,R[i],N));
		ret=min(ret,hoge(L[i],i,R[i]-1,N));
		ret=min(ret,hoge(L[i]+1,i,R[i]-1,N));
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 4224
k = int(input())

an = input().split()

for i in range(len(an)):
    an[i] = int(an[i])

ln = sorted(an)

ans = 0

for i in range(k):
    for j in range(i,k):    
        for l in range(j,k):
            a1 = int(ln[i])
            a2 = int(ln[j])
            a3 = int(ln[l])
            if a1!=a2 and a2 != a3:
                m = a1 + a2
                if a3 < m:
                    ans += 1

print(ans)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(a,b,c) for(int i=a;i<b;i+=c)  
typedef pair<ll , pair<ll, ll> > pi;
int pow(int x,int y){
    int res=1;
    while(y){
        if(y&1) res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}   
struct Compare {
    constexpr bool operator()(pi const & a,
                              pi const & b) const noexcept
    { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }
 
};
void prefix_function( string s,ll arr[] )
{
     long long border=0; arr[0]=0;
    for(long long i=1;i<s.size();i++)
    {
      while(border>0 && s[i]!=s[border])
        border=arr[border-1];
     
     if(s[i]==s[border])
         border++;
      else
       border=0;
      
      arr[i]=border;
    }
}
ll mod=998244353;
ll add( ll a , ll b)
{
    return (((a%mod)+(b%mod))%mod);
}
ll mul(ll a,ll b)
{
  return (((a%mod)*(b%mod))%mod);
}
//send mod-2 for a^-1 if mod is a prime number
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}
ll spf[1000005]; 
void sieve() 
{ 
	spf[1] = 1; 
	for (int i=2; i<1000005; i++) 

	
		spf[i] = i; 

	for (int i=4; i<1000005; i+=2) 
		spf[i] = 2; 

	for (int i=3; i*i<1000005; i++) 
	{ 
		
		if (spf[i] == i) 
		{ 
		 
			for (int j=i*i; j<1000005; j+=i) 

			
				if (spf[j]==j) 
					spf[j] = i; 
		} 
	} 
} 


int main()
{
    Fast
ll n;
sieve();
cin>>n;
ll gcd=0;
bool pairwise=true,setwise=false;
vector<ll>sura;
for(ll i=0;i<n;i++)
{
    ll k;
    cin>>k;
    gcd=__gcd(gcd,k);
    sura.push_back(k);
}

map<ll,bool>fi;
for(ll i=0;i<n;i++)
{
    ll x=sura[i];
    map<ll,bool>se;
    while (x != 1) 
	{ 
        if(fi[spf[x]] && !se[spf[x]])
        pairwise=false;
		se[spf[x]]=true;
        fi[spf[x]]=true;
		x = x / spf[x]; 
	} 

}
if(pairwise)
{
    cout<<"pairwise coprime"<<endl;
    return 0;
}
if(gcd==1)
{
    cout<<"setwise coprime"<<endl;
    return 0;
}
cout<<"not coprime"<<endl;




}



   
      
    
        



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

int main(){
  int x,y;
  cin >> x >> y;
  vector<int> a,b,c,t;
  a = {1,3,5,7,8,10,12};
  b = {4,6,9,11};
  c = {2};
  t = {0};

  for (int i=0; i<7; i++){
    if(a[i]==x){
      t = a;
    };
  };
  for (int i=0; i<4; i++){
    if(b[i]==x){
      t = b;
    };
  };
  bool ans=false;
  
  if(t[0] == 0 ){
    ans=false;
  }
  else if(t==a){
    for (int i=0; i<7; i++){
    	if(a[i]==y){
      		ans=true;
    	};
  	};
  }
  else if(t==b){
    for (int i=0; i<4; i++){
    	if(b[i]==y){
      		ans=true;
    	};
  	};
  };
  if(ans){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
}

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

int main(void){
    // Your code here!
    int N,L,aji[200],absmin = -1,id,sum=0;
    
    scanf("%d %d",&N,&L);
    
    for(int i = 0; i < N; i++)
    {
        aji[i] = L+i;
        sum += aji[i];
        if(i == 0)
        {
            absmin = abs(aji[i]);
            id = i;
        }
        else
        {
            if(abs(aji[i]) < absmin)
            {
                absmin = abs(aji[i]);
                id = i;
            }
        }
    }
    
    printf("%d\n", sum - aji[id]);
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
int main(){
    int cnt[101];
    memset(cnt,0,sizeof(cnt));
    int N;
    cin>>N;
    while(N--){
        int s;
        cin>>s;
        cnt[s]++;
    }
    for(int i=100;i>0;i--){
        cnt[i-1]+=cnt[i];
        if(cnt[i]>=i){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////


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

	ll N = S.size();
	vector<ll> a(N + 1,0);
	ll v = 1;

	repn(i, N) {
		ll c = S[N - i] - '0';
		a[i] = (a[i - 1] + v * c) % 2019;
		v = v * 10 % 2019;
	}

	ll cnt[2019] = {};
	rep(i, N + 1) { cnt[a[i]]++; }

	ll ans = 0;
	rep(i, 2019) ans += cnt[i] * (cnt[i] - 1) / 2;

	cout << ans << endl;


	system("PAUSE");
}


Measured memory_bytes: 5184
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i=0; i<n; i++) cin >> h[i];
    vector<int> dp(n, INT_MAX);
    
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    
    for (int i=2; i<n; i++) {
        for (int j=0; j<=k&&j<=i; j++)
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i]);
    }

    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    for(int i=0; i<=M; i++){
        for(int j=0; j<=N; j++){
            int num;
            num = j*M+i*N-2*i*j;
            if(num==K){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
}

Measured memory_bytes: 256